.image-gallery-uploader {
    display: grid;
    gap: 1rem;
    padding: clamp(1rem, 2.2vw, 1.4rem);
    border: 1px solid #dbe6ea;
    border-radius: 16px;
    background: linear-gradient(145deg, #f8fcfd 0%, #fff 54%, #fffaf1 100%);
    box-shadow: 0 14px 38px rgba(7, 24, 39, .07);
}

.image-gallery-uploader [hidden] {
    display: none !important;
}

.image-gallery-uploader__heading {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 1rem;
}

.image-gallery-uploader__heading h2,
.image-gallery-uploader__heading p,
.image-gallery-uploader__formats,
.image-gallery-uploader__limit,
.image-gallery-uploader__live {
    margin: 0;
}

.image-gallery-uploader__heading h2 {
    color: var(--ink);
    font-size: clamp(1.22rem, 2vw, 1.5rem);
}

.image-gallery-uploader__heading p {
    max-width: 42rem;
    margin-top: .35rem;
    color: var(--muted);
    line-height: 1.5;
}

.image-gallery-uploader__heading > strong {
    flex: 0 0 auto;
    padding: .45rem .7rem;
    border: 1px solid rgba(15, 123, 133, .25);
    border-radius: 999px;
    color: var(--primary-dark);
    background: #eef9fa;
    font-size: .82rem;
    white-space: nowrap;
}

.image-gallery-uploader__formats {
    color: #526775;
    font-size: .86rem;
    font-weight: 760;
}

.image-gallery-uploader__authentication {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .8rem;
    padding: .75rem .85rem;
    border: 1px solid #e5b451;
    border-radius: 11px;
    color: #623b00;
    background: #fff8e8;
}

.image-gallery-uploader__authentication p { margin: 0; line-height: 1.45; }
.image-gallery-uploader__authentication a { flex: 0 0 auto; }

.image-gallery-uploader__drop {
    display: grid;
    gap: .85rem;
    padding: .85rem;
    border: 1.5px dashed rgba(15, 123, 133, .4);
    border-radius: 13px;
    background: rgba(255, 255, 255, .84);
    transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
}

.image-gallery-uploader__drop.is-dragover {
    border-color: #0f7b85;
    background: #eefafb;
    box-shadow: inset 0 0 0 2px rgba(15, 123, 133, .1);
}

.image-gallery-uploader__grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .8rem;
    min-width: 0;
}

.image-gallery-tile,
.image-gallery-add {
    min-width: 0;
    border: 1px solid #dbe5e9;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(7, 24, 39, .06);
}

.image-gallery-tile {
    position: relative;
    display: block;
    overflow: visible;
    transition: opacity .18s ease, border-color .18s ease, transform .18s ease;
}

.image-gallery-tile:has(.image-gallery-tile__menu[open]) { z-index: 9; }

.image-gallery-tile.is-primary {
    border-color: #0f7b85;
    box-shadow: 0 0 0 2px rgba(15, 123, 133, .12), 0 10px 28px rgba(7, 24, 39, .09);
}

.image-gallery-tile.is-dragging {
    opacity: .58;
    transform: scale(.98);
}

.image-gallery-tile.is-removed {
    opacity: .64;
    border-style: dashed;
    background: #f4f6f7;
}

.image-gallery-tile.is-removed::after {
    content: "Odebere se po uložení";
    position: absolute;
    inset: .55rem .55rem auto;
    z-index: 4;
    padding: .35rem .5rem;
    border-radius: 7px;
    color: #fff;
    background: rgba(130, 32, 32, .9);
    font-size: .72rem;
    font-weight: 900;
    text-align: center;
}

.image-gallery-tile__media {
    position: relative;
    overflow: hidden;
    aspect-ratio: 4 / 3;
    background: #edf2f4;
    border-radius: 11px;
}

.image-gallery-tile__media img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-gallery-tile__position,
.image-gallery-tile__primary {
    position: absolute;
    z-index: 2;
    top: .45rem;
    padding: .28rem .48rem;
    border-radius: 999px;
    color: #fff;
    background: rgba(7, 24, 39, .82);
    font-size: .69rem;
    font-weight: 900;
    line-height: 1;
}

.image-gallery-tile__position { left: .45rem; }
.image-gallery-tile__primary { right: .45rem; background: #0f7b85; }

.image-gallery-tile__body {
    position: absolute;
    z-index: 3;
    right: 3.35rem;
    bottom: .45rem;
    left: .45rem;
    display: grid;
    gap: .34rem;
    min-width: 0;
    padding: .42rem .5rem;
    border-radius: 8px;
    background: rgba(7, 24, 39, .84);
    backdrop-filter: blur(5px);
}

.image-gallery-tile.is-ready .image-gallery-tile__body { display: none; }

.image-gallery-tile__body strong {
    overflow: hidden;
    color: #fff;
    font-size: .8rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-gallery-tile__error {
    display: -webkit-box;
    overflow: hidden;
    margin: 0;
    color: #fff;
    font-size: .72rem;
    font-weight: 720;
    line-height: 1.25;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

.image-gallery-tile__status {
    width: fit-content;
    padding: .2rem .42rem;
    border-radius: 999px;
    color: #425563;
    background: #edf2f4;
    font-size: .7rem;
    font-weight: 850;
}

.image-gallery-tile__status.is-ready { color: #0b684e; background: #e7f8f0; }
.image-gallery-tile__status.is-uploading,
.image-gallery-tile__status.is-verifying { color: #075985; background: #e8f5ff; }
.image-gallery-tile__status.is-error { color: #991b1b; background: #feecec; }

.image-gallery-tile__progress {
    overflow: hidden;
    height: 5px;
    border-radius: 99px;
    background: #e4ecef;
}

.image-gallery-tile__progress span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #0f7b85, #19a4af);
    transition: width .12s linear;
}

.image-gallery-tile__menu {
    position: absolute;
    z-index: 7;
    right: .45rem;
    bottom: .45rem;
    color: var(--ink);
}

.image-gallery-tile__menu > summary {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .72);
    border-radius: 11px;
    color: #fff;
    background: rgba(7, 24, 39, .88);
    box-shadow: 0 6px 18px rgba(7, 24, 39, .22);
    font-weight: 950;
    letter-spacing: .08em;
    list-style: none;
    cursor: pointer;
}

.image-gallery-tile__menu > summary::-webkit-details-marker { display: none; }
.image-gallery-tile__menu[open] > summary { color: var(--navy); background: #fff; }

.image-gallery-tile__menu .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.image-gallery-tile__menu-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + .4rem);
    display: grid;
    width: min(220px, calc(100vw - 3rem));
    gap: .38rem;
    padding: .55rem;
    border: 1px solid #d7e1e5;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 16px 38px rgba(7, 24, 39, .24);
}

.image-gallery-tile__filename {
    display: block;
    overflow: hidden;
    padding: .2rem .25rem .35rem;
    color: #526775;
    font-size: .72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-gallery-tile__move-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .35rem;
}

.image-gallery-tile__menu button {
    min-width: 0;
    min-height: 42px;
    padding: .48rem .55rem;
    border: 1px solid #d7e1e5;
    border-radius: 8px;
    color: #173342;
    background: #f7fafb;
    font: inherit;
    font-size: .76rem;
    font-weight: 820;
    line-height: 1.2;
    cursor: pointer;
}

.image-gallery-tile__menu button:hover:not(:disabled) { border-color: #0f7b85; background: #eef9fa; }
.image-gallery-tile__menu button:disabled { opacity: .5; cursor: default; }
.image-gallery-tile__menu button.is-danger { color: #9f2525; background: #fff5f5; }

.image-gallery-add {
    position: relative;
    display: grid !important;
    min-height: 0;
    aspect-ratio: 4 / 3;
    place-content: center;
    gap: .35rem !important;
    padding: 1rem;
    border: 1.5px dashed rgba(15, 123, 133, .5);
    color: #0b5f67;
    background: linear-gradient(145deg, #f2fbfc, #fff);
    text-align: center;
    cursor: pointer;
}

.image-gallery-add:hover { border-color: #0f7b85; background: #eaf8f9; }
.image-gallery-add__icon {
    width: 2rem;
    height: 2rem;
    margin-inline: auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
}
.image-gallery-add > strong { font-size: .94rem; }
.image-gallery-add > small { color: var(--muted); font-size: .76rem; }
.image-gallery-add input,
.image-gallery-uploader__camera input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.image-gallery-uploader__camera {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: var(--muted);
    font-size: .8rem;
}

.image-gallery-uploader__camera label { position: relative; margin: 0; cursor: pointer; }
.image-gallery-uploader__limit { color: #8a4b05; font-weight: 850; }
.image-gallery-uploader__live { min-height: 1.2em; color: #0b684e; font-size: .84rem; font-weight: 760; }
.image-gallery-uploader__live.is-error { color: #a11d1d; }

.image-gallery-card-preview {
    border-top: 1px solid #dfe8eb;
    padding-top: .8rem;
}

.image-gallery-card-preview summary {
    color: var(--primary-dark);
    font-weight: 900;
    cursor: pointer;
}

.image-gallery-card-preview__card {
    display: grid;
    width: min(100%, 280px);
    gap: .5rem;
    margin-top: .7rem;
    padding: .55rem;
    border: 1px solid #dbe5e9;
    border-radius: 11px;
    background: #fff;
}

.image-gallery-card-preview__media {
    display: grid;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    place-items: center;
    border-radius: 8px;
    color: #637783;
    background: #edf2f4;
    font-size: .77rem;
    text-align: center;
}

.image-gallery-card-preview__media img { width: 100%; height: 100%; object-fit: cover; }
.image-gallery-card-preview__card > strong { padding: 0 .25rem .2rem; color: var(--ink); font-size: .9rem; }

.image-gallery-preview-dialog {
    width: min(92vw, 980px);
    max-width: 980px;
    padding: 2.8rem 1rem 1rem;
    border: 0;
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .34);
}

.image-gallery-preview-dialog::backdrop { background: rgba(3, 14, 24, .72); }
.image-gallery-preview-dialog img { display: block; max-width: 100%; max-height: 78vh; margin: auto; object-fit: contain; }
.image-gallery-preview-dialog button {
    position: absolute;
    top: .55rem;
    right: .65rem;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: #173342;
    font-size: 1.4rem;
    cursor: pointer;
}

.image-gallery-editor-dialog {
    width: min(94vw, 760px);
    max-width: 760px;
    max-height: min(94dvh, 900px);
    padding: 0;
    overflow: auto;
    border: 0;
    border-radius: 20px;
    color: var(--ink);
    background: #fff;
    box-shadow: 0 28px 90px rgba(2, 17, 29, .38);
}

.image-gallery-editor-dialog::backdrop {
    background: rgba(3, 14, 24, .76);
    backdrop-filter: blur(3px);
}

.image-gallery-editor__panel {
    display: grid;
    gap: 1rem;
    padding: clamp(1rem, 3vw, 1.5rem);
}

.image-gallery-editor__header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 1rem;
}

.image-gallery-editor__header p,
.image-gallery-editor__header h2,
.image-gallery-editor__panel > p,
.image-gallery-editor__status {
    margin: 0;
}

.image-gallery-editor__header p {
    color: #087d82;
    font-size: .76rem;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.image-gallery-editor__header h2 {
    margin-top: .15rem;
    font-size: clamp(1.3rem, 3vw, 1.75rem);
}

.image-gallery-editor__panel > p {
    color: #526775;
    line-height: 1.45;
}

.image-gallery-editor__close {
    display: grid;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    place-items: center;
    border: 1px solid #d6e2e6;
    border-radius: 12px;
    color: #173342;
    background: #f6fafb;
    font-size: 1.45rem;
    cursor: pointer;
}

.image-gallery-editor__stage {
    position: relative;
    width: min(100%, 620px);
    aspect-ratio: var(--gallery-editor-aspect, 4 / 3);
    justify-self: center;
    overflow: hidden;
    border: 4px solid #fff;
    border-radius: 16px;
    background: #132a38;
    box-shadow: 0 0 0 1px #b9ccd2, 0 14px 34px rgba(7, 24, 39, .18);
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.image-gallery-editor__stage.is-dragging { cursor: grabbing; }

.image-gallery-editor__stage canvas {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.image-gallery-editor__stage > span {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(90deg, transparent 33.1%, rgba(255,255,255,.55) 33.3%, transparent 33.5%, transparent 66.4%, rgba(255,255,255,.55) 66.6%, transparent 66.8%),
        linear-gradient(transparent 33.1%, rgba(255,255,255,.55) 33.3%, transparent 33.5%, transparent 66.4%, rgba(255,255,255,.55) 66.6%, transparent 66.8%);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.72);
}

.image-gallery-editor__controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .8rem;
}

.image-gallery-editor__controls label {
    display: grid;
    gap: .4rem;
    margin: 0;
    color: #263b53;
    font-size: .84rem;
    font-weight: 820;
}

.image-gallery-editor__controls select {
    min-height: 46px;
    padding: .6rem .75rem;
    border: 1px solid #c8d7dc;
    border-radius: 10px;
    color: #173342;
    background: #f8fbfc;
    font: inherit;
}

.image-gallery-editor__rotate {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .65rem;
}

.image-gallery-editor__rotate button {
    display: flex;
    min-height: 46px;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    border: 1px solid #c8d7dc;
    border-radius: 10px;
    color: #173342;
    background: #f8fbfc;
    font: inherit;
    font-size: .82rem;
    font-weight: 850;
    cursor: pointer;
}

.image-gallery-editor__rotate svg {
    width: 1.2rem;
    height: 1.2rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.image-gallery-editor__zoom {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 46px;
    align-items: center;
    gap: .65rem;
    padding: .25rem .65rem;
    border: 1px solid #c8d7dc;
    border-radius: 10px;
    background: #f8fbfc;
}

.image-gallery-editor__zoom input { width: 100%; }
.image-gallery-editor__zoom output { min-width: 3.3rem; color: #087d82; text-align: right; }
.image-gallery-editor__status { min-height: 1.3em; color: #0b684e; font-size: .82rem; font-weight: 760; }
.image-gallery-editor__status.is-error { color: #a11d1d; }

.image-gallery-editor__actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .7rem;
}

.image-gallery-editor__actions .button {
    width: 100%;
    min-height: 48px;
}

body.image-gallery-editor-open { overflow: hidden; }

.image-gallery-uploader :is(button, summary, label, input, select, [tabindex]):focus-visible {
    outline: 3px solid rgba(15, 123, 133, .32);
    outline-offset: 3px;
}

@media (max-width: 1100px) {
    .image-gallery-uploader__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .image-gallery-uploader { padding: .85rem; border-radius: 13px; }
    .image-gallery-uploader__heading { display: grid; gap: .65rem; }
    .image-gallery-uploader__heading > strong { justify-self: start; }
    .image-gallery-uploader__drop { gap: .65rem; padding: .65rem; }
    .image-gallery-uploader__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
    .image-gallery-uploader__authentication { align-items: stretch; flex-direction: column; }
    .image-gallery-uploader__authentication a { min-height: 44px; display: grid; place-items: center; }
    .image-gallery-tile__menu > summary { width: 44px; height: 44px; }
    .image-gallery-tile__menu button { min-height: 44px; }
    .image-gallery-tile:nth-child(odd) .image-gallery-tile__menu-panel { right: auto; left: 0; }
    .image-gallery-add {
        min-height: 0;
        gap: .25rem !important;
        padding: .6rem;
    }
    .image-gallery-add__icon { width: 1.5rem; height: 1.5rem; }
    .image-gallery-add > strong { font-size: .84rem; line-height: 1.2; }
    .image-gallery-add > small { display: none; }
    .image-gallery-add:only-child {
        grid-column: 1 / -1;
        grid-template-columns: auto minmax(0, 1fr);
        min-height: 3.75rem;
        aspect-ratio: auto;
        place-content: initial;
        align-content: center;
        align-items: center;
        justify-content: initial;
        column-gap: .7rem !important;
        padding: .75rem .9rem;
        text-align: left;
    }
    .image-gallery-add:only-child .image-gallery-add__icon {
        grid-row: 1 / 3;
        grid-column: 1;
        width: 1.65rem;
        height: 1.65rem;
        margin: 0;
    }
    .image-gallery-add:only-child > strong { grid-row: 1; grid-column: 2; font-size: .94rem; }
    .image-gallery-add:only-child > small { grid-row: 2; grid-column: 2; display: block; }
    .image-gallery-uploader__camera { align-items: stretch; flex-direction: column; }
    .image-gallery-uploader__camera label { min-height: 44px; display: grid; place-items: center; }
    .image-gallery-uploader__drag-hint { display: none; }
    .image-gallery-card-preview__card { width: min(100%, 250px); }
    .image-gallery-editor-dialog {
        width: calc(100vw - 1rem);
        max-height: calc(100dvh - 1rem);
        border-radius: 16px;
    }
    .image-gallery-editor__panel { gap: .75rem; padding: .85rem; }
    .publication-form .image-gallery-editor__close {
        width: 44px;
        min-width: 44px;
        height: 44px;
        min-height: 44px;
        padding: 0;
    }
    .image-gallery-editor__panel > p { font-size: .8rem; }
    .image-gallery-editor__stage { width: min(100%, 500px); border-radius: 12px; }
    .image-gallery-editor__controls { grid-template-columns: 1fr; gap: .65rem; }
    .image-gallery-editor__rotate { grid-column: auto; }
}

@media (max-width: 339px) {
    .image-gallery-uploader__grid { grid-template-columns: 1fr; }
    .image-gallery-tile .image-gallery-tile__menu-panel { right: 0; left: auto; }
}

@media (prefers-reduced-motion: reduce) {
    .image-gallery-tile,
    .image-gallery-uploader__drop,
    .image-gallery-tile__progress span { transition: none; }
}
