/* Раздел «Файлы» веб-чата: карточка вложения, панель «Файлы», превью.
 * Пара с assets/js/chat-files.js. Макет — docs/ux/chat_files_mockup.html,
 * ТЗ — docs/ux/chat_files_spec.md. Цвета, радиусы, тени — только токены --ic-*. */

/* ---------- Карточка вложения ---------- */
.ch-fcards { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; max-width: 85%; }
.ch-fc {
  position: relative; display: flex; align-items: center; gap: 12px;
  width: 296px; max-width: 100%; padding: 8px 12px 8px 8px;
  background: var(--ic-surface); border: 1px solid var(--ic-border); border-radius: var(--ic-r-md);
  color: var(--ic-fg); font: inherit; text-align: left; overflow: hidden;
  transition: border-color var(--ic-dur), box-shadow var(--ic-dur), opacity var(--ic-dur);
}
button.ch-fc { cursor: pointer; }
button.ch-fc:hover { border-color: var(--ic-border-strong); box-shadow: var(--ic-shadow-2); }
button.ch-fc:focus-visible { outline: 2px solid var(--ic-purple); outline-offset: 2px; }
.ch-fc.is-active { border-color: var(--ic-purple); box-shadow: 0 0 0 3px var(--ic-purple-50); }
.ch-fc.is-replaced { opacity: .6; }
.ch-fc__thumb {
  flex: 0 0 52px; height: 64px; border-radius: var(--ic-r-sm); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: var(--ic-purple-50); color: var(--ic-purple-700);
}
.ch-fc__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--ic-bg-alt); }
.ch-fc__thumb svg { width: 26px; height: 26px; }
.ch-fc__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
/* Заголовок паспорта несёт фамилию и развороты — до двух строк. */
.ch-fc__type { font-weight: 600; font-size: var(--ic-fs-body-sm); line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; }
.ch-fc__type.is-pending { color: var(--ic-fg-muted); font-weight: 500; }
.ch-fc__name { font-size: var(--ic-fs-caption); color: var(--ic-fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1em; }
.ch-fc__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 2px; }
.ch-fc__bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: var(--ic-purple); border-radius: 0 2px 2px 0; transition: width var(--ic-dur); }

.ch-fmt { font-family: var(--ic-font-mono); font-size: 11px; letter-spacing: .02em; color: var(--ic-fg-muted); background: var(--ic-bg-alt); border-radius: 5px; padding: 1px 5px; }
.ch-fsize { font-size: 12px; color: var(--ic-fg-soft); }

/* Статус-метки */
.ch-fst { display: inline-flex; align-items: center; gap: 4px; padding: 4px 7px; border-radius: var(--ic-r-pill); font-size: 12px; font-weight: 500; line-height: 1; white-space: nowrap; background: var(--ic-bg-alt); color: var(--ic-fg-muted); }
.ch-fst svg { width: 12px; height: 12px; flex: 0 0 auto; }
.ch-fst--ok { background: var(--ic-success-bg); color: var(--ic-success); }
.ch-fst--warn { background: var(--ic-warning-bg); color: var(--ic-warning); }
.ch-fst--bad { background: var(--ic-danger-bg); color: var(--ic-danger); }
.ch-fst--run { background: var(--ic-purple-50); color: var(--ic-purple-700); }
.ch-fspin { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: ch-fspin .8s linear infinite; }
@keyframes ch-fspin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ch-fspin { animation: none; } }

/* ---------- Кнопка «Файлы» в шапке ---------- */
.ch-files-btn { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; }
.ch-files-btn[hidden] { display: none; }
.ch-files-btn.is-open { background: var(--ic-bg-alt); }
.ch-files-btn__count { font-family: var(--ic-font-mono); font-size: 13px; }

/* ---------- Панель «Файлы» ---------- */
.ch-main { position: relative; }
.ch-files {
  position: absolute; top: 56px; right: 16px; z-index: 70;
  width: 392px; max-height: calc(100% - 72px);
  display: flex; flex-direction: column;
  background: var(--ic-surface); border: 1px solid var(--ic-border);
  border-radius: var(--ic-r-lg); box-shadow: var(--ic-shadow-3);
}
.ch-files[hidden], .ch-files-backdrop[hidden] { display: none; }
.ch-files__grab { display: none; }
.ch-files__head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 8px 16px; }
.ch-files__title { margin: 0; font-family: var(--ic-font-display); font-size: 17px; font-weight: 600; }
.ch-files__x { width: 32px; height: 32px; border: 0; border-radius: var(--ic-r-sm); background: transparent; color: var(--ic-fg-muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.ch-files__x:hover { background: var(--ic-bg-alt); color: var(--ic-fg); }
.ch-files__seg { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; margin: 0 16px 8px; padding: 3px; background: var(--ic-bg-alt); border-radius: var(--ic-r-pill); }
.ch-files__seg button { border: 0; background: transparent; border-radius: var(--ic-r-pill); padding: 6px 10px; font: inherit; font-size: 13px; font-weight: 500; color: var(--ic-fg-muted); cursor: pointer; }
.ch-files__seg button.is-on { background: var(--ic-surface); color: var(--ic-fg); box-shadow: var(--ic-shadow-1); }
.ch-files__scroll { overflow-y: auto; padding: 0 8px 8px; min-height: 80px; }
.ch-files__grp { padding: 6px 0 4px; }
.ch-files__grp + .ch-files__grp { border-top: 1px solid var(--ic-bg-alt); margin-top: 4px; }
.ch-files__cap { display: flex; justify-content: space-between; padding: 4px 8px 6px; font-size: 12px; font-weight: 500; color: var(--ic-fg-soft); }
.ch-files__empty { padding: 18px 12px; color: var(--ic-fg-muted); font-size: var(--ic-fs-body-sm); text-align: center; }
.ch-frow { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px; border: 0; background: transparent; border-radius: var(--ic-r-md); text-align: left; font: inherit; color: var(--ic-fg); cursor: pointer; }
.ch-frow:hover { background: var(--ic-bg-tinted); }
.ch-frow:focus-visible { outline: 2px solid var(--ic-purple); outline-offset: -2px; }
.ch-frow__ico { flex: 0 0 36px; height: 44px; border-radius: var(--ic-r-sm); overflow: hidden; display: flex; align-items: center; justify-content: center; background: var(--ic-purple-50); color: var(--ic-purple-700); }
.ch-frow__ico img { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--ic-bg-alt); }
.ch-frow__ico svg { width: 20px; height: 20px; }
.ch-frow__body { flex: 1; min-width: 0; }
.ch-frow__sub { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-frow__title { font-size: 14px; font-weight: 500; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; }
.ch-frow__sub { font-size: 12px; color: var(--ic-fg-soft); }
.ch-frow__right { flex: 0 0 auto; }
.ch-files__foot { display: flex; gap: 8px; align-items: flex-start; padding: 10px 16px 14px; border-top: 1px solid var(--ic-bg-alt); font-size: 12px; color: var(--ic-fg-muted); }
.ch-files__foot svg { flex: 0 0 14px; margin-top: 2px; color: var(--ic-fg-soft); }
.ch-files-backdrop { position: fixed; inset: 0; z-index: 69; background: rgba(9, 40, 82, .35); }

/* ---------- Превью ---------- */
.ch-app.has-fpv { grid-template-columns: 264px minmax(0, 1fr) minmax(360px, 460px); }
.ch-fpv { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100vh; border-left: 1px solid var(--ic-border); background: var(--ic-surface); }
.ch-fpv[hidden] { display: none; }
.ch-fpv__head { display: flex; align-items: flex-start; gap: 8px; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--ic-bg-alt); }
.ch-fpv__back { display: none; }
.ch-fpv__hgroup { flex: 1; min-width: 0; }
.ch-fpv__title { margin: 0 0 4px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-family: var(--ic-font-display); font-size: 17px; font-weight: 600; line-height: 1.25; }
.ch-fpv__sub { font-size: 12.5px; color: var(--ic-fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-fpv__acts { display: flex; gap: 8px; padding: 12px 20px; border-bottom: 1px solid var(--ic-bg-alt); }
.ch-fbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--ic-r-pill); border: 1px solid var(--ic-border-strong); background: var(--ic-surface); color: var(--ic-fg); font: inherit; font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer; }
.ch-fbtn:hover { background: var(--ic-bg-alt); }
.ch-fbtn svg { width: 16px; height: 16px; }
.ch-fbtn--primary { background: var(--ic-purple); border-color: var(--ic-purple); color: #fff; }
.ch-fbtn--primary:hover { background: var(--ic-purple-600); }
.ch-fpv__canvas { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 20px; background: var(--ic-bg-tinted); }
.ch-fpv__canvas img { max-width: 100%; height: auto; border-radius: 6px; box-shadow: var(--ic-shadow-2); background: var(--ic-surface); }
.ch-fpv__canvas iframe { width: 100%; height: 100%; min-height: 420px; border: 0; border-radius: 6px; background: var(--ic-surface); box-shadow: var(--ic-shadow-2); }
.ch-fpv__none { margin: auto; text-align: center; color: var(--ic-fg-muted); font-size: var(--ic-fs-body-sm); }
.ch-fpv__none svg { width: 40px; height: 40px; color: var(--ic-purple-700); display: block; margin: 0 auto 10px; }
.ch-fpv__info { padding: 14px 20px 18px; border-top: 1px solid var(--ic-bg-alt); font-size: 13.5px; display: flex; flex-direction: column; gap: 8px; }
.ch-fpv__info dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.ch-fpv__info dt { color: var(--ic-fg-soft); }
.ch-fpv__info dd { margin: 0; }
.ch-fnote { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--ic-r-md); font-size: 13px; background: var(--ic-bg-tinted); color: var(--ic-fg-muted); }
.ch-fnote--warn { background: var(--ic-warning-bg); color: var(--ic-fg); }
.ch-fnote svg { flex: 0 0 16px; margin-top: 1px; }

/* ---------- Телефон ---------- */
@media (max-width: 800px) {
  .ch-fcards { max-width: 100%; }
  .ch-fc { width: 100%; }
  .ch-files-btn__label { display: none; }
  .ch-files {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto;
    max-height: 84vh; border-radius: 20px 20px 0 0; border-bottom: 0;
  }
  .ch-files__grab { display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--ic-border-strong); margin: 8px auto 0; }
  .ch-app.has-fpv { grid-template-columns: minmax(0, 1fr); }
  .ch-fpv { position: fixed; inset: 0; z-index: 120; height: auto; border-left: 0; }
  .ch-fpv__head { padding: 10px 12px; }
  .ch-fpv__back { display: inline-flex; }
  .ch-fpv__close { display: none; }
  .ch-fpv__acts { order: 10; display: grid; grid-template-columns: 1fr 1fr; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--ic-bg-alt); border-bottom: 0; }
  .ch-fpv__acts .ch-fbtn { height: 44px; }
  .ch-fpv__canvas { padding: 16px; }
  .ch-fpv__info { padding: 12px 16px; }
}
