@layer ui {
/* Полоса миниатюр и просмотр во весь экран (ritm#39). Значения — из tokens.css,
   кроме фона просмотра: снимок смотрят на чёрном в любой теме. */

.files {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.files::-webkit-scrollbar {
  display: none;
}

.file-item {
  position: relative;
  flex: none;
  width: 64px;
  scroll-snap-align: start;
}

/* Полосу тянут мышью, как свайпом на телефоне (см. viewer.js): пока тянут,
   курсор говорит об этом, а выделение текста и перенос картинки не мешают. */
.files.is-drag {
  cursor: grabbing;
  scroll-snap-type: none;
  user-select: none;
}

.files.is-drag img {
  pointer-events: none;
}

/* Снимки и кнопка загрузки — 64 px вместо 96 (замечание владельца 10.09): в
   карточке эта полоса стояла выше всех прочих строк и съедала экран, а понять
   по миниатюре, что на снимке, можно и в две трети роста. */
.file-thumb {
  display: block;
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
}

.file-drop {
  position: absolute;
  top: 2px;
  right: 2px;
  margin: 0;
}

/* Крестики на плитках карточки — в режиме «Изменить» (аудит 23.09, B13): полосу
   листают и открывают, не задевая их. Без скрипта режима нет — видны сразу. */
.has-js .card:not(.is-editing) [data-files-edit] .file-drop {
  display: none;
}

html:not(.has-js) [data-files-toggle],
.files-edit-on,
.card.is-editing .files-edit-off {
  display: none;
}

.card.is-editing .files-edit-on {
  display: inline;
}

/* Плитка файла — в размер миниатюры (ritm#299): иконка вида сверху, метка
   расширения под ней. Показать документ мы не можем, и серый квадрат вместо
   снимка ничего не сказал бы; пара «что это» и «чем открывать» — говорит. */
.file-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 64px;
  height: 64px;
  color: var(--text-secondary);
  text-decoration: none;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.file-tile:hover {
  color: var(--accent);
  border-color: var(--line-accent);
}

.file-tile .ic {
  width: 22px;
  height: 22px;
}

.file-tile-ext {
  max-width: 58px;
  overflow: hidden;
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Пропавший файл: плитка тише остальных и с пунктиром — по ней видно, что
   дело не в связи, а в том, что файла больше нет. */
.file-tile-gone {
  color: var(--text-muted);
  background: none;
  border-style: dashed;
}

/* Имя — одной строкой под плиткой; у снимка его нет: миниатюра говорит сама. */
.file-name {
  display: block;
  width: 64px;
  margin-top: 2px;
  overflow: hidden;
  font-size: var(--text-xs);
  line-height: 1.25;
  color: var(--text-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-drop .file-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--on-accent);
  background: rgba(12, 16, 12, 0.55);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.file-drop .file-x .ic {
  width: 14px;
  height: 14px;
}

/* Подтверждение прямо на плитке: удаление файла не отменить, а крестик у
   миниатюры мал и стоит под большим пальцем. Тем же приёмом спрашивает шторка
   мысли — «спросили на месте, не уводя с экрана» (ritm#260). Без скрипта
   спрашивать нечем, и форма уходит сразу: `.file-ask` показывается только по
   классу, который ставит скрипт. */
.file-ask {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 2px;
  padding: 3px;
  background: rgba(12, 16, 12, 0.72);
  border-radius: var(--radius-md);
}

/* Спрашиваем поверх самой плитки, не задевая подпись под ней: имя файла — как
   раз то, по чему человек проверяет, что удаляет. */
.file-drop.is-asking {
  top: 0;
  right: 0;
  left: 0;
  height: 64px;
}

.file-drop.is-asking .file-ask {
  display: flex;
}

.file-drop.is-asking .file-x {
  display: none;
}

.file-ask button {
  padding: 3px 2px;
  font: inherit;
  font-size: 10px;
  line-height: 1.1;
  color: var(--on-accent);
  cursor: pointer;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: var(--radius-sm);
}

/* Через `.file-ask`: соседнее правило `.file-ask button` весит больше одного
   класса, и без этого красная кнопка оставалась серой. */
.file-ask .file-ask-yes {
  background: var(--status-bad);
  border-color: var(--status-bad);
}

/* Строка загрузки: полоса плиток до конца запроса не меняется, а сказать, что
   идёт работа, надо — иначе большой файл выглядит как ничего не произошло. */
.file-busy {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Кнопка загрузки — иконка, а не надпись: она стоит в ряду миниатюр, и слово
   там читается как подпись к снимку (замечание владельца 06.09). */
.file-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 64px;
  height: 64px;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}

.file-add:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.file-add .ic {
  width: 20px;
  height: 20px;
}

/* Подпись для чтения с экрана места не занимает: общий класс `.sr` растягивается
   (`flex: 1`), и в этой кнопке он уводил иконку влево от центра — владелец
   говорил об этом трижды (07.09). Текст остаётся в разметке для чтения вслух. */
.file-add .file-add-text {
  flex: none;
  width: 0;
  overflow: hidden;
}

/* Пока файлы уходят — иконка гаснет и дышит, чтобы было видно, что идёт работа. */
.file-add.is-busy {
  color: var(--text-muted);
  border-style: solid;
  animation: ritm-file-busy 1.2s ease-in-out infinite;
}

@keyframes ritm-file-busy {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .file-add.is-busy {
    animation: none;
  }
}

.file-add input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-add.is-busy {
  color: var(--text-muted);
}

/* Миниатюры на карточке доски — маленькие: они подсказка, а не галерея. */
.bcard-files {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: var(--space-1);
}

.bcard-files img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--radius-sm, 6px);
  background: var(--surface-sunken);
}

.bcard-files-more {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Скрепка в строке признаков — там же, где счётчик обсуждения, и в его размере:
   это пометка «тут есть файлы», а не отдельный элемент (ritm#299). */
.thought-clip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.thought-clip .ic,
.bcard-clip .ic {
  width: 13px;
  height: 13px;
}

/* Полоса вложений в шторке мысли идёт под самой записью и прижата вправо, как
   и она: в переписке правая сторона — своя, левая — агента, и файлы, которые
   прислал человек, не должны выглядеть ответом агента. `width: fit-content` с
   `max-width: 100%` оставляет длинной полосе обычную прокрутку — прижатие
   вправо у прокручиваемого ряда прячет начало за краем. */
.tsheet-files {
  width: fit-content;
  max-width: 100%;
  margin: 0 0 var(--space-2) auto;
}

/* --- просмотр во весь экран -------------------------------------------------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
}

/* display: flex выше сильнее браузерного [hidden] { display: none }: без этого
   правила крестик снимал атрибут, а просмотр так и висел на экране — владелец
   видел это как «карусель не закрывается» (06.09, те же грабли, что у шторки). */
.viewer[hidden] {
  display: none;
}

body.viewer-open {
  overflow: hidden;
}

.viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Верх просмотра — ниже выреза экрана, а на весь экран в Telegram и ниже его
   кнопок (ritm#482): крестик справа лежал ровно под «⌄ ⋯». `--tg-top` ставит
   app.css, вне Telegram его нет. */
.viewer-count {
  position: absolute;
  top: calc(var(--space-4) + max(env(safe-area-inset-top, 0px), var(--tg-top, 0px)));
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.85);
}

.viewer-nav,
.viewer-close {
  position: absolute;
  min-width: 44px;
  min-height: 44px;
  font: inherit;
  font-size: var(--text-xl);
  color: rgba(255, 255, 255, 0.85);
  background: none;
  border: 0;
  cursor: pointer;
}

.viewer-prev {
  left: var(--space-2);
}

.viewer-next {
  right: var(--space-2);
}

.viewer-close {
  top: calc(var(--space-2) + max(env(safe-area-inset-top, 0px), var(--tg-top, 0px)));
  right: var(--space-2);
  font-size: var(--text-lg);
}

/* --- раздел «Файлы» (ritm#302) ------------------------------------------------

   Сетка плиток вместо списка строк: у файла главное — что это, а «что это»
   видно по миниатюре и по виду, а не по имени. На телефоне три в ряд, на
   десктопе шире — плитка одна и та же, меняется только сколько их помещается. */

.files-head {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.files-sum {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}

.files-count {
  font-weight: 600;
}

.files-space {
  color: var(--text-secondary);
}

.files-space-tight {
  color: var(--status-warn);
}

.files-bar {
  height: 6px;
  overflow: hidden;
  background: var(--surface-sunken);
  border-radius: 999px;
}

.files-bar-fill {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.files-bar-tight .files-bar-fill {
  background: var(--status-warn);
}

.files-warn {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--status-warn);
}

.files-shares {
  margin: 0;
}

.files-add {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.files-add-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  cursor: pointer;
}

.files-add-label input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.files-pick-note {
  margin: 0 0 var(--space-2);
  color: var(--text-secondary);
}

/* Чипы отбора — одним прокручиваемым рядом: их восемь, и в две строки они
   съедают первый экран. */
.files-chips {
  display: flex;
  gap: var(--space-1);
  padding-bottom: 2px;
  margin: var(--space-2) 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.files-chips::-webkit-scrollbar {
  display: none;
}

.files-chips .chip {
  flex: none;
  text-decoration: none;
}

.files-chips .chip.is-on {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

.files-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

/* Поиск здесь — по краю карточки и чипов: общая строка поиска отступает внутрь
   (под шапкой экрана так и надо), а в «Файлах» от этого рвался левый край. */
.files-screen .findrow,
.findrow.fsheet-find {
  padding-left: 0;
  padding-right: 0;
}

.files-screen .findrow-box,
.findrow.fsheet-find .findrow-box {
  max-width: none;
}

/* Сегмент порядка — по ширине подписей, как «День / Неделя / Месяц» в
   календаре: общие правила .seg растягивают пункты поровну и дают поля по
   краям — в строке с «Выбрать» пункты сжимались до 41 px. */
.files-tools .seg {
  flex: none;
  margin: 0;
}

.files-tools .seg-item {
  flex: none;
  padding: 0 var(--space-3);
}

.files-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.file-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.file-cell-btn {
  display: block;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
}

.file-cell-thumb,
.file-cell-tile,
.file-cell .file-tile-gone {
  width: 100%;
  height: 84px;
}

.file-cell-name,
.file-cell-meta {
  display: block;
  width: 100%;
  overflow: hidden;
  font-size: var(--text-xs);
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-cell-meta {
  color: var(--text-muted);
}

/* Отметка выбора — поверх плитки, в размер пальца. */
.file-mark {
  position: absolute;
  top: 4px;
  left: 4px;
  display: inline-flex;
  cursor: pointer;
}

.file-mark input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.file-mark-box {
  display: block;
  width: 22px;
  height: 22px;
  background: var(--surface-raised);
  border: 2px solid var(--line-strong);
  border-radius: 6px;
}

.file-mark input:checked + .file-mark-box {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 3px var(--surface-raised);
}

.files-more {
  grid-column: 1 / -1;
  justify-self: center;
  margin-top: var(--space-2);
}

.files-empty {
  margin-top: var(--space-4);
}

/* Панель выбора висит над нижним меню, пока что-то отмечено. */
.files-batch {
  position: sticky;
  /* Прилипание считается от поля экрана (16px), а панель должна стоять в 8px от
     меню: отрицательная поправка на это поле. Без неё под панелью оставалась
     полоса с подписями плиток (аудит 23.09). */
  bottom: calc(var(--space-2) - var(--space-4) + env(safe-area-inset-bottom, 0px));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  margin-top: var(--space-3);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
}

.files-batch-count {
  flex: 1;
  color: var(--text-secondary);
}

.files-batch-drop {
  background: var(--status-bad);
  border-color: var(--status-bad);
}

/* --- шторка файла --------------------------------------------------------- */

.fsheet {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: 0 var(--space-4) var(--space-4);
}

.fsheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.fsheet-title {
  min-width: 0;
  overflow: hidden;
  font-size: var(--text-lg);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fsheet-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  background: var(--surface-sunken);
  border-radius: var(--radius-md);
}

.fsheet-img {
  max-width: 100%;
  max-height: 240px;
  border-radius: var(--radius-md);
}

.fsheet-tile {
  width: 96px;
  height: 96px;
}

.fsheet-gone {
  margin: 0;
  padding: var(--space-4);
  color: var(--text-muted);
}

.fsheet-props {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
}

.fsheet-props > div {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
}

/* Подпись — одной строкой: длинное название задачи или заметки справа
   сжимало её до «В / задаче» в две строки. Переносится значение. */
.fsheet-props dt {
  flex: none;
  white-space: nowrap;
  color: var(--text-muted);
}

.fsheet-props dd {
  min-width: 0;
  margin: 0;
  text-align: right;
  overflow-wrap: anywhere;
}

.fsheet-rename {
  display: flex;
  gap: var(--space-2);
}

.fsheet-name-input {
  flex: 1;
  min-width: 0;
}

.fsheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.fsheet-drop {
  position: relative;
}

.fsheet-drop-btn {
  color: var(--status-bad);
  background: none;
  border-color: var(--status-bad);
}

/* Подтверждение в шторке — той же формой, что на плитке, только в строку. */
.fsheet-ask {
  position: static;
  flex-direction: row;
  gap: var(--space-1);
  padding: 0;
  background: none;
}

.fsheet-drop.is-asking .fsheet-ask {
  display: inline-flex;
}

.fsheet-drop.is-asking .fsheet-drop-btn {
  display: none;
}

.fsheet-ask button {
  padding: 6px 10px;
  font-size: var(--text-sm);
  color: var(--text);
  border-color: var(--line-strong);
}

.fsheet-ask .file-ask-yes {
  color: var(--on-accent);
}

.fsheet-attach {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.fsheet-attach-title {
  color: var(--text-secondary);
}

.fsheet-task-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2);
  font: inherit;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.fsheet-task-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* «Из файлов» стоит рядом с «Добавить» и выглядит так же: обе кнопки про одно
   — положить сюда файл, только берут его из разных мест. */
.file-add-pick {
  text-decoration: none;
}

/* Под кнопками «добавить» — подпись, как имя под файлом (аудит 23.09, B14):
   откуда возьмётся файл. Мышью его берут с компьютера, пальцем — с телефона. */
.file-add-item {
  flex: none;
  min-width: 64px;
  scroll-snap-align: start;
}

/* Подпись здесь — целиком, а не многоточием, как у имени файла: «С телефона» в
   64 px не влезает. Колонка раздаётся под неё, плитка остаётся 64 px, а вторая
   строка сделала бы полосу выше (замечание владельца 10.09). */
.file-form .file-name,
.file-add-item .file-name {
  width: auto;
  overflow: visible;
}

.file-cap-mouse {
  display: none;
}

@media (pointer: fine) {
  .file-cap-touch {
    display: none;
  }

  .file-cap-mouse {
    display: inline;
  }
}

/* Ссылки в свойствах файла — акцентом без подчёркивания, как везде в
   приложении: синяя подчёркнутая ссылка выглядит чужой. */
.fsheet-props a {
  color: var(--accent);
  text-decoration: none;
}
}
