/* Стили модуля базы изображений (админка + публичная галерея).
   Переиспользует токены из variables.css и базовые классы. */

/* --- Dropzone-зона загрузки --- */
.img-dropzone {
    border: 2px dashed var(--border-strong, #c0c4cc);
    border-radius: var(--radius, 8px);
    padding: 24px;
    text-align: center;
    background: var(--surface-alt, #f7f8fa);
    cursor: pointer;
    transition: border-color .15s, background .15s;
    margin-bottom: 16px;
}
.img-dropzone.dz-drag-hover {
    border-color: var(--brand, #c01818);
    background: var(--brand-soft, #fde6e6);
}
.img-dropzone .img-dropzone__hint {
    color: var(--text, #333);
    line-height: 1.6;
}
/* Скрываем стандартные превью Dropzone: файлы и так появляются в галерее ниже
   (через prependCard). Превью с success/error-иконками и нерабочей ссылкой
   «Remove file» — лишний дублирующий шум. */
.img-dropzone .dz-preview { display: none !important; }
/* Лог недавних загрузок под подсказкой */
.img-dropzone__log {
    margin-top: 10px;
    text-align: center;
    font-size: 13px;
    line-height: 1.7;
    max-height: 120px;
    overflow-y: auto;
}
.img-dropzone__log-item {
    display: inline-block;
    margin: 2px 4px;
    padding: 2px 10px;
    border-radius: var(--radius, 8px);
    background: var(--success-soft, #e8f5e9);
    color: var(--success, #2e7d32);
    word-break: break-all;
}
.img-dropzone__log-item.is-error {
    background: var(--danger-soft, #fdecea);
    color: var(--danger, #c62828);
}

/* --- Тулбар --- */
.img-toolbar { flex-wrap: wrap; gap: 8px; align-items: center; }
.img-toolbar .btn { font-weight: 500; }
.img-toolbar__sort { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.img-toolbar__sort .muted { margin-right: 4px; }
.is-hidden { display: none !important; }

/* --- Баннер «архив устарел» (админка) --- */
.img-archive-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 8px 0 10px;
}
.img-archive-banner .btn { margin: 0; }

/* --- Информационная строка --- */
.img-info { margin: 8px 0 12px; font-size: 13px; }

/* --- Сетка галереи: фиксированно 5 колонок (адаптив ниже) --- */
.img-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
}
/* Адаптив: меньше колонок на узких экранах */
@media (max-width: 1100px) { .img-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 880px)  { .img-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 620px)  { .img-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* --- Компактная таблица (вид table) --- */
/* Контейнер .img-grid в table-режиме содержит <table>, отключаем grid-layout. */
.img-grid.img-view-table {
    display: block;
    grid-template-columns: none;
    /* На узких экранах таблица шире viewport → горизонтальный скролл здесь,
       а не на странице (иначе лайтбокс/липкие элементы уезжают за край). */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
/* Минимальные ширины ячеек, чтобы таблица не сжималась в нечитаемую кашу. */
.img-table { min-width: 640px; }
.img-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.img-table thead th {
    text-align: left;
    padding: 8px 10px;
    background: var(--surface-alt, #f0f2f5);
    border-bottom: 2px solid var(--border, #e0e3e8);
    font-weight: 600;
    position: sticky;
    top: 0;
}
/* Кликабельный заголовок сортировки — выглядит как текст ячейки. */
.img-table__sort {
    background: none;
    border: 0;
    padding: 0;
    margin: 0;
    font: inherit;
    font-weight: 600;
    color: var(--text-muted, #777);
    cursor: pointer;
    white-space: nowrap;
}
.img-table__sort:hover {
    color: var(--brand, #c01818);
}
.img-table__sort.is-active {
    color: var(--text, #222);
}
.img-table .img-row {
    border-bottom: 1px solid var(--border, #eef0f3);
    cursor: pointer;
    transition: background .1s;
}
.img-table .img-row:hover { background: var(--surface-alt, #f7f8fa); }
.img-table .img-row td {
    padding: 6px 10px;
    vertical-align: middle;
}
.img-table .img-row__num {
    width: 50px;
    color: var(--text-muted, #999);
    text-align: right;
    user-select: none;
}
.img-table .img-row__name {
    font-weight: 500;
    max-width: 0; /* позволяет ellipsis работать в ячейке таблицы */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.img-table .img-row__dim,
.img-table .img-row__size {
    white-space: nowrap;
    width: 130px;
}
.img-table .img-row__ext { width: 70px; }
/* Колонка URL: кликабельная «кнопка-ссылка», копирует адрес по клику. */
.img-table th.url { text-align: center; }
.img-table .img-row__url {
    max-width: 260px;
    padding: 2px 0;
    text-align: center;
}
.img-row__url .js-img-copy-url {
    background: none;
    border: 0;
    padding: 4px 8px;
    margin: 0;
    font: inherit;
    font-size: 12px;
    color: var(--text-muted, #777);
    cursor: pointer;
    max-width: 100%;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    border-radius: var(--radius, 8px);
    transition: color .1s, background .1s;
}
.img-row__url .js-img-copy-url:hover {
    color: var(--brand, #c01818);
    background: var(--brand-soft, #fde6e6);
    text-decoration: none;
}
.img-row__url .js-img-copy-url:active {
    transform: translateY(1px);
}

/* --- Всплывающая миниатюра (tooltip) в табличном виде --- */
/* Скрыт по умолчанию через display:none; показывается классом .is-visible. */
.img-tooltip {
    display: none;
    position: fixed;
    z-index: 9000;
    max-width: 260px;
    max-height: 260px;
    padding: 6px;
    border-radius: var(--radius, 8px);
    background: var(--surface, #fff);
    box-shadow: var(--shadow-2, 0 6px 20px rgba(0,0,0,.18));
    border: 1px solid var(--border, #e0e3e8);
    pointer-events: none;
}
.img-tooltip.is-visible { display: block; }
.img-tooltip img {
    display: block;
    max-width: 100%;
    max-height: 240px;
    border-radius: 4px;
}

/* --- Липкая панель массовых операций (внизу по центру) --- */
/* Появляется только когда есть выделение (управляется через .is-hidden). */
.img-bulk-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9000;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 10px 14px;
    border-radius: var(--radius, 8px);
    background: var(--surface, #fff);
    box-shadow: var(--shadow-2, 0 6px 20px rgba(0,0,0,.18));
    border: 1px solid var(--border, #e0e3e8);
}
.img-bulk-bar .btn { margin: 0; font-weight: 400; }
/* Счётчик выделенного рядом с «Скачать выбранные». */
.img-bulk-bar__count {
    font-size: 12px;
    color: var(--text-muted, #777);
    margin-right: 4px;
    user-select: none;
}
/* Кликабельные ячейки (имя/размеры) — открывают лайтбокс. */
.img-table .js-img-open:hover {
    color: var(--brand, #c01818);
    text-decoration: underline;
}
/* Выделение строк таблицы. */
.img-table .img-row.is-selected {
    background: var(--brand-soft, #fde6e6);
}
.img-table .img-row.is-selected td { border-color: var(--brand, #c01818); }

/* --- Переключатель вида --- */
.img-view-toggle {
    display: flex;
    gap: 4px;
}
.img-view-toggle .col-toggle__chip {
    font-size: 16px;
    line-height: 1;
    padding: 6px 10px;
}

/* --- Карточка изображения --- */
.img-card {
    position: relative;
    border: 2px solid var(--border, #e0e3e8);
    border-radius: var(--radius, 8px);
    overflow: hidden;
    background: var(--surface, #fff);
    transition: border-color .12s, box-shadow .12s, transform .05s;
    user-select: none;
}
.img-card:hover {
    border-color: var(--border-strong, #b0b4bc);
    box-shadow: var(--shadow-1, 0 2px 8px rgba(0,0,0,.08));
}
.img-card__media {
    position: relative;
    aspect-ratio: 1 / 1;
    background:
        linear-gradient(45deg, #f0f0f0 25%, transparent 25%) -8px 0,
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%) -8px 0,
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 16px 16px;
    background-color: #fafafa;
    cursor: pointer;
}
/* Preview растягивается на всю площадь media, края обрезаются (режим «обложка»). */
.img-card__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.img-card__check {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--brand, #c01818);
    color: #fff;
    font-size: 14px;
    line-height: 24px;
    text-align: center;
    opacity: 0;
    transform: scale(.6);
    transition: opacity .1s, transform .1s;
    pointer-events: none;
}
.img-card.is-selected {
    border-color: var(--brand, #c01818);
    box-shadow: 0 0 0 1px var(--brand, #c01818);
}
.img-card.is-selected .img-card__media { background-color: var(--brand-soft, #fde6e6); }
.img-card.is-selected .img-card__check { opacity: 1; transform: scale(1); }

.img-card__body {
    padding: 8px 10px;
}
/* Кликабельные имя/размер — открывают лайтбокс (обработчик в download.js). */
.js-img-open {
    cursor: pointer;
    transition: color .1s;
}
.js-img-open:hover {
    color: var(--brand, #c01818);
    text-decoration: underline;
}
.img-card__name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}
.img-card__meta {
    font-size: 11px;
    color: var(--text-muted, #777);
}

/* --- Рамка выделения --- */
.img-selection-box {
    position: fixed;
    border: 1px dashed var(--brand, #c01818);
    background: rgba(192, 24, 24, .1);
    pointer-events: none;
    z-index: 999;
}

/* --- Toast-уведомления --- */
.img-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    max-width: 360px;
    padding: 12px 16px;
    border-radius: var(--radius, 8px);
    background: var(--surface, #fff);
    box-shadow: var(--shadow-2, 0 6px 20px rgba(0,0,0,.18));
    border-left: 4px solid var(--brand, #c01818);
    font-size: 14px;
    line-height: 1.4;
}
.img-toast.is-success { border-left-color: var(--success, #0a7d28); }
.img-toast.is-error   { border-left-color: var(--danger, #c01818); }
.img-toast.is-info    { border-left-color: var(--info, #1e6ec0); }

/* --- PhotoSwipe контейнер поверх всего --- */
.pswp { z-index: 10001; }

/* Кнопка закрытия лайтбокса на мобильных: выше в safe-area, контрастнее. */
@media (max-width: 620px), (hover: none) {
    /* Учитываем чёлку/статус-бар: top-bar отступает от верхнего края. */
    .pswp__top-bar {
        top: env(safe-area-inset-top, 0);
    }
    /* Бóльшая и заметная тач-цель для кнопки закрытия. */
    .pswp__button--close {
        width: 56px;
        height: 56px;
        background: rgba(0, 0, 0, 0.35);
        border-radius: 0 0 0 12px;
    }
    .pswp__button--close .pswp__icn {
        top: 12px;
        left: 12px;
        width: 32px;
        height: 32px;
    }
}

/* --- Прогресс импорта --- */
.img-progress {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 10000;
    width: 340px;
    max-width: calc(100vw - 40px);
    padding: 14px 16px;
    border-radius: var(--radius, 8px);
    background: var(--surface, #fff);
    box-shadow: var(--shadow-2, 0 6px 20px rgba(0,0,0,.18));
    border: 1px solid var(--border, #e0e3e8);
}
.img-progress__head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}
.img-progress__title { font-weight: 600; font-size: 14px; }
.img-progress__count { font-size: 13px; color: var(--text-muted, #777); }
.img-progress__bar {
    height: 8px;
    background: var(--surface-alt, #eef0f3);
    border-radius: 4px;
    overflow: hidden;
}
.img-progress__fill {
    height: 100%;
    width: 0%;
    background: var(--brand, #c01818);
    transition: width .25s ease;
}
.img-progress__hint {
    font-size: 12px;
    color: var(--text-muted, #777);
    margin-top: 6px;
    min-height: 14px;
}
.img-progress__log {
    margin-top: 6px;
    font-size: 11px;
    color: var(--danger, #c01818);
    max-height: 60px;
    overflow-y: auto;
}

/* --- Блок действий на странице настроек (карточки одной высоты) --- */
.img-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-5);
}
@media (max-width: 600px) { .img-actions { grid-template-columns: 1fr; } }

.img-action {
    display: flex;
    flex-direction: column;
    padding: var(--space-5);
    /* Нейтрализуем глобальное .content-card + .content-card { margin-top },
       иначе соседняя карточка в сетке становится короче на величину отступа. */
    margin-top: 0;
}
.img-action h4 { margin: 0 0 8px; }
.img-action .muted { font-size: 13px; flex: 1 1 auto; }
/* Кнопка прижата к низу, текст переносится, чтобы не вылезать за карточку. */
.img-action .btn {
    white-space: normal;
    align-self: flex-start;
    margin-top: var(--space-3);
}

/* --- Публичная галерея (/img/): внутри общих шапки/подвала (portal/public/) --- */
body.img-public h1 {
    font-size: 20px;
    margin: 0 0 12px;
}
