/* One gap size between gallery photos, horizontally and vertically */
.gallery-grid {
    --gallery-gap: 1.5rem;
}

.gallery-grid .gallery-item {
    margin-bottom: var(--gallery-gap);
}

.gallery-grid .gallery-item img {
    display: block;
}

/* ---------- Admin gallery editor: drag and drop grid (change_gallery.js) ---------- */
.gallery-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem 1rem;
    margin-bottom: 1.25rem;
    padding: .75rem 1rem;
    background: var(--rv-subtle-bg, #f8f9fa);
    border-radius: var(--rv-radius);
}

.gallery-save-status {
    font-size: .875rem;
    transition: opacity .2s ease;
}

.gallery-save-status:empty {
    display: none;
}

.gallery-save-status.is-saving { color: var(--rv-text-muted); }
.gallery-save-status.is-saved  { color: var(--rv-ok-fg, #0f5132); }
.gallery-save-status.is-error  { color: var(--rv-danger-text-hover); font-weight: 500; }

.gallery-column-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: .5rem;
    padding-bottom: .375rem;
    border-bottom: 1px solid var(--rv-border);
}

/* One upload form for both columns */
.gallery-upload {
    margin-bottom: 1rem;
    padding: 1rem;
    border: 1px solid var(--rv-border);
    border-radius: var(--rv-radius);
}

.gallery-upload-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
}

.gallery-upload-row > .form-control {
    flex: 1 1 14rem;
    width: auto;
    min-width: 0;   /* file inputs have a large intrinsic width in Firefox */
}

.gallery-upload-row .btn {
    margin: 0;
    white-space: nowrap;
}

.gallery-upload-target .btn {
    text-transform: none;
}

/* Selected column in the "Левый / Правый" switch */
.btn-check:checked + .velach-outline-btn,
.btn-check:checked + .velach-outline-btn:hover {
    background-color: var(--rv-accent);
    border-color: var(--rv-accent);
    color: #fff;
}

.btn-check:focus-visible + .velach-outline-btn {
    box-shadow: 0 0 0 .2rem rgba(var(--rv-accent-rgb), .25);
}

.gallery-upload-preview:not(:empty) {
    margin-top: .75rem;
}

/* readFiles() sets an inline width of 100%; keep the preview a thumbnail */
.gallery-upload-preview canvas {
    width: auto !important;
    max-width: 100%;
    max-height: 10rem;
    border-radius: var(--rv-radius);
    border: 1px solid var(--rv-border);
}

.gallery-upload .form-error:not(:empty) {
    margin-top: .5rem;
}

@media (max-width: 575.98px) {
    .gallery-upload-target {
        width: 100%;
    }

    .gallery-upload-target .btn {
        flex: 1 1 50%;
        white-space: normal;
        padding-left: .5rem;
        padding-right: .5rem;
    }

    .gallery-upload-row > #gallery-add-button {
        width: 100%;
    }
}

.gallery-sortable {
    list-style: none;
    margin: 0;
    padding: .5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
    gap: .75rem;
    min-height: 10rem;
    border: 2px dashed transparent;
    border-radius: var(--rv-radius);
    transition: border-color .15s ease, background-color .15s ease;
}

/* Column the uploaded photo goes to */
.gallery-sortable.is-upload-target {
    border-color: rgba(var(--rv-accent-rgb), .35);
}

/* Drop target while dragging and the empty column */
.gallery-sortable:has(.gallery-tile-ghost),
.gallery-sortable.is-empty {
    border-color: var(--rv-border);
    background-color: var(--rv-subtle-bg, #fafafa);
}

.gallery-sortable.is-empty {
    place-items: center;
}

.gallery-sortable.is-empty::before {
    content: "Перетащите фото сюда";
    grid-column: 1 / -1;
    color: var(--rv-text-muted);
    font-size: .875rem;
}

.gallery-tile {
    --gallery-caption-height: 2.1rem;
    position: relative;
    border-radius: var(--rv-radius);
    overflow: hidden;
    background: var(--rv-subtle-bg, #f1f3f5);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
    cursor: grab;
    user-select: none;
    touch-action: manipulation;
    transition: box-shadow .15s ease, transform .15s ease;
}

.gallery-tile:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
}

.gallery-tile img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

/* Position in the column */
.gallery-tile-number {
    position: absolute;
    top: .375rem;
    left: .375rem;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 .375rem;
    border-radius: 1rem;
    background: rgba(0, 0, 0, .65);
    color: #fff;
    font-size: .75rem;
    font-weight: 600;
    line-height: 1.5rem;
    text-align: center;
}

.gallery-tile-grip {
    position: absolute;
    top: .375rem;
    right: .5rem;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
    opacity: .85;
}

.gallery-tile-actions {
    position: absolute;
    left: 0;
    right: 0;
    bottom: var(--gallery-caption-height);   /* over the photo, above its caption field */
    display: flex;
    justify-content: flex-end;
    gap: .25rem;
    padding: .375rem;
    background: linear-gradient(to top, rgba(0, 0, 0, .6), rgba(0, 0, 0, 0));
    opacity: 0;
    transition: opacity .15s ease;
}

.gallery-tile:hover .gallery-tile-actions,
.gallery-tile:focus-within .gallery-tile-actions {
    opacity: 1;
}

/* Touch screens have no hover: always show the buttons */
@media (hover: none) {
    .gallery-tile-actions { opacity: 1; }
}

.gallery-tile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: .375rem;
    background: color-mix(in srgb, var(--rv-card-bg) 92%, transparent);
    color: var(--rv-text) !important;
    font-size: .875rem;
    text-decoration: none;
    cursor: pointer;
}

.gallery-tile-btn:hover, .gallery-tile-btn:focus-visible {
    background: var(--rv-card-bg);
    outline: 2px solid var(--rv-accent);
    outline-offset: 0;
}

.gallery-tile-remove:hover, .gallery-tile-remove:focus-visible {
    background: var(--rv-danger-active);
    color: #fff !important;
    outline: 0;
}

/* SortableJS states */
.gallery-tile-chosen {
    cursor: grabbing;
}

.gallery-tile-ghost {
    opacity: .35;
    outline: 2px dashed var(--rv-accent);
    outline-offset: -2px;
}

.gallery-tile-drag {
    transform: rotate(2deg);
    box-shadow: 0 10px 24px rgba(0, 0, 0, .3);
}

/* What is on the photo (its alt text on the site): a field under the photo, green for a moment once saved */
.gallery-tile-caption {
    display: block;
    width: 100%;
    border: 0;
    border-top: 1px solid var(--rv-border);
    height: var(--gallery-caption-height);
    padding: 0 .6rem;
    font-size: .8rem;
    background: var(--rv-card-bg);
    color: var(--rv-text);
}
.gallery-tile-caption:focus { outline: 2px solid var(--rv-accent); outline-offset: -2px; }
.gallery-tile-caption.is-saved { background: var(--rv-ok-bg, #e8f5e9); transition: background 1.5s ease; }
.gallery-tile-caption.is-invalid { background: var(--rv-danger-tint-strong); }
.gallery-upload-caption { margin-top: .75rem; }
