/* ============================================================
   GBS — базовый слой: сброс, типографика, общие компоненты.
   Требует /css/tokens.css. Спецификация: CLAUDE.md → «Дизайн-код GBS».

   Правила для тех, кто это расширяет:
   — селекторы плоские, один класс, без вложенности и !important;
   — никакого `transition: all` — перечисляй свойства;
   — вокруг фотографии не бывает карточки: ни рамки, ни радиуса, ни тени;
   — янтарь только для времени, белый — цвет взаимодействия.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

/* Атрибут hidden проигрывает любому display в авторском CSS (.selbar, .fsec-count
   с inline-flex оставались на экране). Возвращаем ему силу — это нужно всем вьюхам. */
[hidden] { display: none !important; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--text-1);
  font-family: var(--font);
  font-size: var(--t-body);
  font-weight: 400;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg, video, canvas { display: block; max-width: 100%; }
img { border-radius: var(--r-frame); }

h1, h2, h3, h4, p, figure, blockquote { margin: 0; }

h1 { font-size: var(--t-h1); font-weight: 600; line-height: 1.15; letter-spacing: -.015em; }
h2 { font-size: var(--t-h2); font-weight: 600; line-height: 1.2; }
h3 { font-size: var(--t-h3); font-weight: 600; line-height: 1.25; }

a { color: var(--text-1); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: var(--text-3); }

button, input, select, textarea { font: inherit; color: inherit; }

hr { height: 1px; margin: 0; border: 0; background: var(--rule); }

/* --- Фокус виден всегда. outline:none без замены запрещён. --- */
:focus-visible {
  outline: 2px solid var(--text-1);
  outline-offset: 2px;
  border-radius: 2px;
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--text-1); color: var(--ground); }

/* --- Полосы прокрутки --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rule); border-radius: var(--r-ui); }
::-webkit-scrollbar-thumb:hover { background: var(--text-off); }
* { scrollbar-width: thin; scrollbar-color: var(--rule) transparent; }

/* ============================================================
   Каркас страницы
   ============================================================ */

.page      { width: 100%; max-width: var(--w-page); margin: 0 auto; padding: var(--s6) var(--s5) var(--s8); }
.page-app  { max-width: var(--w-app); }
.page-read { max-width: var(--w-read); }

.page-head { margin-bottom: var(--s6); }
.page-head h1 { margin-bottom: var(--s2); }
.page-sub  { color: var(--text-2); font-size: var(--t-lead); max-width: 62ch; }

/* Липкий заголовок группы (месяц/год в ленте) */
.group-head {
  position: sticky; top: 56px; z-index: var(--z-sticky);
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s4);
  padding: var(--s4) 0 var(--s3);
  background: linear-gradient(var(--ground) 70%, transparent);
}
.group-head .group-count { color: var(--text-3); font-size: var(--t-meta); }

/* Панель. Вокруг фотографий не применять. */
.sheet {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-ui);
}
.sheet-pad { padding: var(--s5); }

.rule-top { border-top: 1px solid var(--rule); }

/* ============================================================
   Текст
   ============================================================ */

.t-meta  { font-size: var(--t-meta); color: var(--text-2); }
.t-micro { font-size: var(--t-micro); color: var(--text-3); }
.t-dim   { color: var(--text-2); }
.t-quiet { color: var(--text-3); }
.num     { font-variant-numeric: tabular-nums; }
.measure { max-width: 68ch; }

/* Метаданные — отдельные элементы с отступом, не склейка через « · » */
.meta-row { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: baseline;
            font-size: var(--t-meta); color: var(--text-3); }

/* ============================================================
   Кнопки
   ============================================================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 40px; padding: 0 var(--s4);
  border: 1px solid transparent; border-radius: var(--r-ui);
  background: var(--raised); color: var(--text-1);
  font-size: var(--t-body); font-weight: 500; line-height: 1.35;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease),
              border-color var(--fast) var(--ease);
}
.btn:hover { background: var(--rule); }

.btn-primary { background: var(--text-1); color: var(--ground); }
.btn-primary:hover { background: #D8D8D4; }

.btn-quiet { background: transparent; color: var(--text-2); }
.btn-quiet:hover { background: transparent; color: var(--text-1); }

.btn-danger { background: transparent; color: var(--alarm); border-color: var(--alarm); }
.btn-danger:hover { background: var(--alarm); color: var(--ground); }

.btn-sm  { height: 32px; padding: 0 var(--s3); font-size: var(--t-meta); }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-block { width: 100%; }

.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--raised); color: var(--text-off); border-color: transparent;
  cursor: not-allowed;
}

/* Спиннер внутри кнопки — единственный допустимый спиннер действия */
.btn.is-busy { pointer-events: none; color: transparent; position: relative; }
.btn.is-busy::after {
  content: ''; position: absolute; width: 16px; height: 16px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: var(--r-round);
  color: var(--text-1); animation: gbs-spin .7s linear infinite;
}
.btn-primary.is-busy::after { color: var(--ground); }

@keyframes gbs-spin { to { transform: rotate(360deg); } }

@media (max-width: 768px) {
  .btn { height: 44px; }
  .btn-icon { width: 44px; }
}

/* ============================================================
   Поля
   ============================================================ */

.field-group { display: flex; flex-direction: column; gap: var(--s2); margin-bottom: var(--s4); }

.label { font-size: var(--t-meta); color: var(--text-2); }
.label-req::after { content: ' *'; color: var(--alarm); }

.field {
  width: 100%; height: 40px; padding: 0 var(--s3);
  background: var(--raised); color: var(--text-1);
  border: 1px solid var(--rule); border-radius: var(--r-ui);
  font-size: var(--t-body); line-height: 1.35;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
textarea.field { height: auto; min-height: 96px; padding: var(--s3); line-height: 1.5; resize: vertical; }
select.field { cursor: pointer; }

.field::placeholder { color: var(--text-off); }
.field:hover { border-color: var(--text-off); }
.field:focus {
  outline: none;
  border-color: var(--text-1);
  box-shadow: 0 0 0 3px rgba(237, 237, 234, .14);
}
.field:disabled { color: var(--text-off); cursor: not-allowed; }

.field-err { border-color: var(--alarm); }
.field-err:focus { border-color: var(--alarm); box-shadow: 0 0 0 3px var(--alarm-dim); }

.hint { font-size: var(--t-meta); color: var(--text-3); }
.err  { font-size: var(--t-meta); color: var(--alarm); }

@media (max-width: 768px) {
  .field { height: 44px; font-size: 16px; } /* 16px не даёт iOS зумить при фокусе */
}

/* Чекбокс / радио в строке */
.check-row { display: flex; align-items: center; gap: var(--s3); cursor: pointer; }
.check-row input { width: 18px; height: 18px; accent-color: var(--text-1); cursor: pointer; flex: none; }
.check-row span { font-size: var(--t-body); }

/* ============================================================
   Чипы, бейджи, аватары
   ============================================================ */

.chip {
  display: inline-flex; align-items: center; gap: var(--s2);
  height: 30px; padding: 0 var(--s3);
  background: var(--raised); color: var(--text-2);
  border: 1px solid transparent; border-radius: var(--r-ui);
  font-size: var(--t-meta); cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.chip:hover { color: var(--text-1); }
.chip.is-on { background: var(--text-1); color: var(--ground); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px var(--s2); border-radius: var(--r-ui);
  background: var(--raised); color: var(--text-3);
  font-size: var(--t-micro); font-weight: 500;
}
.badge-time  { background: var(--safelight-dim); color: var(--safelight); }
.badge-alarm { background: var(--alarm-dim); color: var(--alarm); }

.avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: var(--r-round); object-fit: cover;
  background: var(--raised); color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--t-meta); font-weight: 500;
}
.avatar-sm { width: 24px; height: 24px; font-size: var(--t-micro); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--t-body); }

/* ============================================================
   Кадр и контактный лист
   ============================================================ */

.sheet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--s1); }
.shelf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s5); }

/* На телефоне контактный лист всегда в три кадра (решение владельца 2026-09-13):
   две плитки в полэкрана читались как лента, а не как лист. Порог 600, а не 480, —
   иначе между 481 и 580 auto-fill возвращал те же два столбца.
   Полка альбомов остаётся в один столбец: альбом — предмет, ему нужен воздух. */
@media (max-width: 600px) {
  .sheet-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
  .shelf-grid { grid-template-columns: 1fr; }
}

.frame {
  position: relative; display: block;
  aspect-ratio: 1; overflow: hidden;
  background: var(--raised);
  border: 0; border-radius: var(--r-frame); padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.frame img, .frame video { width: 100%; height: 100%; object-fit: cover; }

/* Наведение: проявляется скрим с подписью. Кадр не двигается и не подсвечивается. */
.frame-scrim {
  position: absolute; inset: auto 0 0 0; padding: var(--s5) var(--s2) var(--s2);
  background: linear-gradient(transparent, rgba(0, 0, 0, .78));
  color: var(--text-1); font-size: var(--t-micro);
  opacity: 0; transition: opacity var(--fast) var(--ease);
}
.frame:hover .frame-scrim, .frame:focus-visible .frame-scrim { opacity: 1; }

.frame.is-selected { box-shadow: inset 0 0 0 3px var(--text-1); }

/* Чекбокс проявляется при наведении — иначе войти в режим выбора нечем.
   В самом режиме невыделенные чекбоксы не показываются (§4). */
.frame-check {
  position: absolute; top: var(--s2); left: var(--s2);
  width: 20px; height: 20px; border-radius: 3px;
  background: transparent; border: 1px solid var(--text-1); color: transparent;
  display: none; align-items: center; justify-content: center;
  opacity: 0; transition: opacity var(--fast) var(--ease);
}
.frame:hover .frame-check,
.frame:focus-visible .frame-check { display: flex; opacity: .75; }
.frame.is-selected .frame-check {
  display: flex; opacity: 1;
  background: var(--text-1); color: var(--ground);
}

/* Сердце в углу кадра */
.frame-like {
  position: absolute; top: var(--s2); right: var(--s2);
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0;
  border: 0; border-radius: var(--r-round);
  background: rgba(0, 0, 0, .45); color: var(--text-1);
  cursor: pointer; opacity: 0;
  transition: opacity var(--fast) var(--ease);
}
.frame:hover .frame-like,
.frame-like:focus-visible { opacity: 1; }
.frame-like[aria-pressed="true"] { opacity: 1; }
.frame-like[aria-pressed="true"] svg { fill: currentColor; }

/* Кадр, у которого нет кадра: аудио, документы, архивы. */
.frame-file {
  display: flex; flex-direction: column; justify-content: flex-end; gap: var(--s1);
  padding: var(--s3);
  background: var(--raised);
  text-align: left;
}
.frame-file .ff-kind { font-size: var(--t-micro); color: var(--text-3); }
.frame-file .ff-name {
  font-size: var(--t-meta); color: var(--text-2);
  overflow: hidden; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}

.frame-scrim .fs-line { display: block; }

.frame-duration {
  position: absolute; right: var(--s2); bottom: var(--s2);
  padding: 1px 5px; border-radius: 3px;
  background: rgba(0, 0, 0, .68); color: var(--text-1);
  font-size: var(--t-micro);
}
/* Файл в очереди postprocessing */
.frame-processing::after {
  content: ''; position: absolute; inset: auto 0 0 0; height: 2px; background: var(--safelight);
}

/* ============================================================
   Панель выбора, меню, списки значений

   Жили в feed.css, пока лист был только на «Ленте». Теперь тот же
   контактный лист и тот же выбор есть на странице альбома (§19),
   поэтому компоненты переехали в общий слой.
   ============================================================ */

/* Липкая панель выбора (§5): счёт слева, действия справа. */
.selbar {
  position: fixed; inset: auto 0 0 0; z-index: var(--z-drawer);
  background: var(--surface);
  border-top: 1px solid var(--rule);
}
.selbar-in {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2);
  width: 100%; max-width: var(--w-app); margin: 0 auto;
  padding: var(--s3) var(--s5);
}
.selbar-count { font-size: var(--t-body); font-weight: 500; }

/* Меню: над кнопкой (menu-wrap) или по координатам курсора (ctx-menu). */
.menu-wrap { position: relative; }

.menu {
  position: absolute; z-index: var(--z-pop);
  min-width: 208px; padding: var(--s1);
  background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--r-float);
  box-shadow: var(--lift-1);
}
.menu-wrap .menu { bottom: calc(100% + var(--s2)); right: 0; }
.ctx-menu { position: fixed; }

.menu-item {
  display: block; width: 100%;
  padding: var(--s2) var(--s3);
  border: 0; border-radius: var(--r-ui);
  background: transparent; color: var(--text-1);
  font-size: var(--t-body); text-align: left; cursor: pointer;
  transition: background var(--fast) var(--ease);
}
.menu-item:hover { background: var(--raised); }
.menu-item-danger { color: var(--alarm); }
.menu-item-danger:hover { background: var(--alarm-dim); }

/* Список значений: фильтры в рейле, выбор людей в модалке. */
.opt-list { display: flex; flex-direction: column; max-height: 260px; overflow-y: auto; }

.opt {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; min-height: 36px;
  padding: var(--s1) var(--s2);
  border: 0; border-radius: var(--r-ui);
  background: transparent; color: var(--text-2);
  font-size: var(--t-body); text-align: left; cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.opt:hover { background: var(--raised); color: var(--text-1); }
.opt.is-on { color: var(--text-1); }

.opt-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt-mark { flex: none; width: 16px; color: var(--text-1); opacity: 0; }
.opt.is-on .opt-mark { opacity: 1; }

.chip-row { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* Карта внутри модалки или секции фильтра. Кадр не скругляется — и карта тоже. */
.geo-map {
  width: 100%; height: 220px;
  border: 1px solid var(--rule); border-radius: var(--r-frame);
  background: var(--raised);
}

@media (max-width: 768px) {
  .selbar-in { padding: var(--s3) var(--s4); }

  /* Меню в панели выбора шириной 208 px не помещалось: кнопка «Изменить»
     после переноса строки стоит у левого края, а меню растёт влево от неё —
     половина пунктов уезжала за экран. Якорем становится сама панель. */
  .selbar .menu-wrap { position: static; }
  .selbar .menu { left: var(--s4); right: var(--s4); min-width: 0; }
}

/* ============================================================
   Пустые состояния и скелетоны
   ============================================================ */

.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--s4);
  padding: var(--s8) var(--s5); text-align: center;
}
.empty p { font-size: var(--t-lead); color: var(--text-1); max-width: 46ch; }

.skeleton {
  background: var(--raised);
  border-radius: var(--r-frame);
  animation: gbs-pulse 1.2s var(--ease) infinite;
}
.skeleton-ui { border-radius: var(--r-ui); }
@keyframes gbs-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

/* ============================================================
   Тосты
   ============================================================ */

.toast-stack {
  position: fixed; right: var(--s5); bottom: var(--s5); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--s2);
  max-width: min(380px, calc(100vw - var(--s5) * 2));
}
.toast {
  display: flex; align-items: center; gap: var(--s3);
  min-width: 220px; padding: var(--s3) var(--s4);
  background: var(--surface); color: var(--text-1);
  border: 1px solid var(--rule); border-left: 3px solid var(--text-1);
  border-radius: var(--r-float); box-shadow: var(--lift-1);
  font-size: var(--t-body);
  animation: gbs-toast-in var(--base) var(--ease);
}
.toast-err  { border-left-color: var(--alarm); }
.toast-time { border-left-color: var(--safelight); }
.toast-action { margin-left: auto; }

@keyframes gbs-toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 768px) {
  .toast-stack { right: var(--s3); left: var(--s3); bottom: var(--s3); max-width: none; }
}

/* ============================================================
   Модалки
   ============================================================ */

.modal-scrim {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center; padding: var(--s5);
  background: var(--scrim);
  animation: gbs-fade var(--base) var(--ease);
}
.modal {
  width: 100%; max-width: var(--w-read); max-height: 88vh; overflow-y: auto;
  padding: var(--s5);
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r-float); box-shadow: var(--lift-2);
}
.modal-head { margin-bottom: var(--s5); }
.modal-head h3 { margin-bottom: var(--s2); }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: var(--s3);
  margin-top: var(--s6);
}
.modal-foot .modal-foot-left { margin-right: auto; }

@keyframes gbs-fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 768px) {
  .modal-scrim { padding: 0; align-items: flex-end; }
  .modal { max-width: none; max-height: 92vh; border-radius: var(--r-float) var(--r-float) 0 0; }
  .modal-foot { flex-direction: column-reverse; align-items: stretch; }
  .modal-foot .btn { width: 100%; }
  .modal-foot .modal-foot-left { margin-right: 0; }
}

/* ============================================================
   Утилиты (только раскладочные)
   ============================================================ */

.row     { display: flex; align-items: center; gap: var(--s3); }
.row-tight { display: flex; align-items: center; gap: var(--s2); }
.col     { display: flex; flex-direction: column; gap: var(--s3); }
.spacer  { flex: 1 1 auto; }
.wrap    { flex-wrap: wrap; }
.hidden  { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ============================================================
   Кадр в просмотре (см. public/js/photo-source.js)
   ============================================================ */

/* Пока едет превью, на экране висит миниатюра из сетки: размытие честно
   говорит, что кадр ещё не в полном качестве, и убирает «лесенку» на 300px,
   растянутых на весь экран. */
img[data-photo-quality] { transition: filter var(--base) var(--ease); }
img.photo-loading { filter: blur(12px); }
