/* ===========================================================================
   media.css — вкладка «Медиа»: категории слева, сетка стопкадров справа.

   Layout — как у вкладки «Чат» (боковой столбец + основная область).
   ТЗ: TZ/2026-10-12-cam-harvester.md §8.4.
   =========================================================================== */
.media {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 0;
}

/* --- Левый столбец: категории, сгруппированные по источнику --------------- */
.media__side {
  flex: 0 0 240px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  min-height: 0;
}

.media__side-scroll {
  overflow-y: auto;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.media__side-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.media__side-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 8px;
}

.media__side-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.media__cat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--text-muted);
  text-align: left;
  cursor: pointer;
}

.media__cat:hover { background: var(--bg-elev-2); color: var(--text); }

.media__cat--active {
  background: var(--accent-weak);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
}

.media__cat-name {
  flex: 1 1 auto;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.media__cat-count {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--text-faint);
}

/* Кнопка переименования (инлайн, для админа). */
.media__cat-rename {
  flex: 0 0 auto;
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}

.media__cat-rename:hover { color: var(--accent); background: var(--bg-elev-2); }

/* --- Основная область: тулбар + сетка ------------------------------------- */
.media__main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.media__toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.media__period {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.media__chips {
  display: inline-flex;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px;
}

.media__btn {
  border: none;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 16px;
  cursor: pointer;
}

.media__btn:hover { color: var(--text); background: var(--bg-elev-2); }

.media__btn--active {
  background: var(--accent-weak);
  color: var(--accent);
}

.media__custom {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.media__custom input {
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}

/* «Скачать архив» — прижимается вправо тулбара; виден только при
   выбранной категории (media.js; ZIP — /api/media/category/<id>/archive,
   ТЗ §8.6 ревизия п.4). */
.media__archive {
  margin-left: auto;
  white-space: nowrap;
  font-size: 12px;
}

.media__scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  min-height: 0;
}

/* --- Сетка стопкадров ------------------------------------------------------ */
.media__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.media__item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.media__item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.media__item img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #10141a;
}

.media__item-time {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 6px 5px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media__empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

/* --- Lightbox --------------------------------------------------------------- */
.media-lightbox {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-lightbox[hidden] { display: none; }

.media-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 16, 0.88);
}

.media-lightbox__img {
  position: relative;
  max-width: calc(100vw - 96px);
  max-height: calc(100vh - 96px);
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.media-lightbox__bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 56px 10px 16px;
  color: #dfe5ee;
  font-size: 13px;
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
}

.media-lightbox__title {
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.media-lightbox__nav,
.media-lightbox__close {
  position: absolute;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #e8edf5;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-lightbox__nav:hover,
.media-lightbox__close:hover { background: rgba(255, 255, 255, 0.2); }

.media-lightbox__nav--prev { left: 16px; top: 50%; transform: translateY(-50%); }
.media-lightbox__nav--next { right: 16px; top: 50%; transform: translateY(-50%); }
.media-lightbox__close { top: 12px; right: 12px; }

/* --- Мобильная раскладка ----------------------------------------------------- */
@media (max-width: 720px) {
  .media { flex-direction: column; }
  .media__side {
    flex: 0 0 auto;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
