/* Docs: спокойный вид, как у заметок. Выделение рамкой, без цветных полос сбоку. */
:root {
  --bg: #f7f7f5;
  --card: #fff;
  --text: #1f1f1d;
  --muted: #6b6b66;
  --line: #e3e2de;
  --accent: #2f6fed;
  --error: #c4352b;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #191919; --card: #232322; --text: #ececea; --muted: #9b9b96; --line: #353533; --error: #ff7a6e; }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 8px; }
.loading, .hint { color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.auth { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
input {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; width: 100%;
}
input:focus { outline: none; border-color: var(--accent); }
.pin { text-align: center; font-size: 28px; letter-spacing: 12px; }
button {
  font: inherit; border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: 8px; padding: 10px 14px; cursor: pointer;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.link { background: none; border: none; color: var(--muted); padding: 4px; text-decoration: underline; }
.error { color: var(--error); margin: 0; font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }

.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }

/* Плитки мелкие: на главной — полоски по категориям, листаются вбок; на странице категории — сетка */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 12px; }
@media (max-width: 480px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 8px; } }
.tile { min-width: 0; }
.thumb {
  aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card) center / cover no-repeat;
}
.tile .title { margin: 6px 0 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .date { margin: 0; font-size: 12px; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 60px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-title { color: var(--text); font-size: 18px; margin: 0 0 6px; }

dialog { border: none; padding: 0; background: transparent; color: var(--text); width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog .card { display: grid; gap: 12px; }
[hidden] { display: none !important; }

/* --- загрузка, поиск, фильтр --- */
.upload.button {
  display: inline-flex; align-items: center; font-size: 16px; color: #fff; background: var(--accent);
  border: 1px solid var(--accent); border-radius: 8px; padding: 10px 14px; cursor: pointer;
}
.search { margin: 0; }

/* Полоска категории: заголовок-кнопка «Врачи 3 ›» и ряд плиток с прокруткой вбок */
.section-head {
  all: unset; cursor: pointer; display: flex; align-items: baseline; gap: 8px; margin: 18px 0 8px; font-size: 18px; font-weight: 600;
}
.section-head:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.section-count { color: var(--muted); font-weight: 400; font-size: 15px; }
.section-more { color: var(--muted); font-weight: 400; }
.strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: 112px; gap: 12px; overflow-x: auto;
  scroll-snap-type: x proximity; padding-bottom: 6px; margin: 0 -16px; padding-inline: 16px; scroll-padding-inline: 16px;
  scrollbar-width: thin;
}
.strip .tile { scroll-snap-align: start; }
@media (max-width: 480px) { .strip { grid-auto-columns: 96px; gap: 8px; } }
.back { margin-bottom: 6px; }
.list-title { font-size: 20px; margin: 8px 0 4px; }
.month { font-size: 14px; font-weight: 600; color: var(--muted); margin: 18px 0 8px; text-transform: none; }
.pending { display: grid; gap: 6px; margin-bottom: 14px; }
.failed { display: flex; gap: 10px; align-items: center; justify-content: space-between; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--error); }
button.small { padding: 4px 10px; font-size: 13px; }
button.danger { color: var(--error); }

/* плитка — кнопка: открывается с клавиатуры тоже */
button.tile { all: unset; cursor: pointer; display: grid; gap: 2px; min-width: 0; }
button.tile:focus-visible .thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.thumb { position: relative; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge { position: absolute; right: 5px; bottom: 5px; font-size: 11px; background: rgb(0 0 0 / .6); color: #fff;
  min-width: 18px; text-align: center; padding: 1px 6px; border-radius: 999px; }
.tile .title { margin: 5px 0 0; font-size: 13px; line-height: 1.25; overflow: hidden; white-space: normal; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .date { margin: 0; font-size: 11px; color: var(--muted); display: block; }

/* --- документ --- */
.fields { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 12px 0 16px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; }
label.inline { display: flex; align-items: center; gap: 8px; color: var(--muted); }
select { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-width: 60vw; }
.text summary { cursor: pointer; color: var(--muted); }
.text pre { white-space: pre-wrap; font-size: 13px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 340px; overflow: auto; }
/* --- телефон --- */
/* без зума и сдвига вбок: двойное касание не увеличивает, страница не шире экрана */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body { overflow-x: hidden; overscroll-behavior-x: none; }
/* поле меньше 16px iPhone увеличивает при касании — поэтому 16px везде */
input, textarea, select { font-size: 16px; }

.top .actions { flex-wrap: nowrap; gap: 8px; }
.upload.button svg, button.icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.upload.button { gap: 6px; }
button.icon { padding: 9px; line-height: 0; }

@media (max-width: 480px) {
  main { padding: 12px 12px 32px; }
  .strip { margin: 0 -12px; padding-inline: 12px; scroll-padding-inline: 12px; }
  .top { gap: 8px; margin-bottom: 14px; }
  .top h1 { font-size: 22px; }
  .top button:not(.icon), .top .upload.button { padding: 8px 12px; font-size: 15px; }
  .upload.button { padding: 9px; }
  .upload.button .label { display: none; }   /* на телефоне — круглая кнопка «+» */
  .upload.button { border-radius: 999px; }
  label.inline { flex-direction: column; align-items: stretch; gap: 4px; }
  select { max-width: none; width: 100%; }
  input.narrow { width: 100%; }
  .model-head { gap: 4px 10px; }
  .fields { gap: 2px 12px; font-size: 15px; }   /* две колонки: подпись слева, значение справа, без лишних строк */
  .chat-form textarea { min-height: 84px; }
  .bubble { max-width: 100%; }
}

/* --- вопрос к документам --- */
.chat-log { display: grid; gap: 10px; margin: 16px 0; }
.bubble { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); max-width: 760px; white-space: pre-wrap; }
.bubble.q { justify-self: end; background: var(--card); border-color: var(--accent); }
.bubble.a { justify-self: start; background: var(--card); }
.bubble .strip.mini { margin: 10px 0 0; padding-inline: 0; grid-auto-columns: 84px; }
.doc-link { color: var(--accent); text-decoration: none; border-bottom: 1px solid currentColor; }
.small-print { font-size: 12px; margin: 8px 0 0; }
.chat-form { position: sticky; bottom: 0; display: grid; gap: 8px; padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); }
.chat-form textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; resize: vertical;
}
.chat-form .row { justify-content: flex-end; }

/* --- модели ИИ --- */
.stack { display: grid; gap: 10px; margin: 12px 0; }
.model { display: grid; gap: 6px; }
.model-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.ok { color: #2e9e5b; }
input.narrow { width: 120px; }
.log { display: grid; gap: 4px; margin-top: 8px; font-size: 13px; color: var(--muted); }
details > summary { cursor: pointer; }

/* --- нейронка на странице документа --- */
#doc-ai h2 { margin: 0; }
#doc-ai p { margin: 0; }
.summary { font-size: 16px; }
.redacted { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.redacted-img { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
label.check input { width: auto; }

/* --- поиск и кнопка нейронки справа --- */
.search-row { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }
.search-row .search { flex: 1; min-width: 0; }
.ai-btn { flex: none; width: 46px; height: 46px; padding: 0; border-radius: 12px; display: grid; place-items: center; line-height: 0; }
.ai-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.ai-btn .spark { fill: currentColor; stroke-width: 1; }

/* --- загрузка: крутилка, заготовки плиток, перелив миниатюры --- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
.spinner { display: inline-block; width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; vertical-align: -3px; }
.loading-block { display: flex; gap: 10px; align-items: center; color: var(--muted); margin: 18px 0 10px; }
.skeleton .thumb, .thumb.wait { background: var(--line); animation: shimmer 1.2s ease-in-out infinite; }
.skeleton .thumb { display: block; }

/* --- нейронка: свёрнутый блок «идёт» / «готово» --- */
.ai-run { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.ai-run > summary { display: flex; gap: 10px; align-items: center; list-style: none; }
.ai-run > summary::-webkit-details-marker { display: none; }
.ai-run > summary::after { content: "›"; margin-left: auto; color: var(--muted); transition: transform .15s; }
.ai-run[open] > summary::after { transform: rotate(90deg); }
.ai-run[open] { display: grid; gap: 10px; }
.check { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #2e9e5b; color: #fff;
  font-size: 12px; flex: none; }

/* --- приклеить к другому документу: строки с миниатюрой --- */
.merge { margin: 12px 0; padding: 12px 14px; }
.merge[open] { display: grid; gap: 10px; }
.merge-list { display: grid; gap: 6px; max-width: 460px; max-height: 360px; overflow-y: auto; }
.merge-row { all: unset; box-sizing: border-box; cursor: pointer; display: flex; gap: 12px; align-items: center;
  padding: 6px; border: 1px solid var(--line); border-radius: 8px; }
.merge-row:hover, .merge-row:focus-visible { border-color: var(--accent); }
.merge-row .thumb { width: 56px; flex: none; }
.merge-info { display: grid; gap: 2px; min-width: 0; }
.merge-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merge-info .hint { font-size: 13px; }

/* --- чаты --- */
.chat-list { display: grid; gap: 6px; margin: 16px 0; }
.chat-list-title { margin: 0; }
.chat-list > .hint { margin: 0 0 6px; font-size: 13px; }
.chat-row { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); padding: 4px 6px 4px 0; }
.chat-open { all: unset; box-sizing: border-box; cursor: pointer; flex: 1; min-width: 0; display: grid; gap: 2px; padding: 8px 12px; }
.chat-open:focus-visible { outline: 2px solid var(--accent); border-radius: 8px; }
.chat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-open .hint { font-size: 13px; }
.thinking { display: flex; gap: 8px; align-items: center; }

/* --- голос: пульсирующий кружок и кнопка-квадрат «стоп» --- */
.composer { align-items: center; }
.mic svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mic .i-stop { display: none; fill: currentColor; stroke: none; }
.mic.recording { background: var(--error); border-color: var(--error); color: #fff; }
.mic.recording .i-mic { display: none; }
.mic.recording .i-stop { display: block; }
.rec { display: inline-flex; gap: 8px; align-items: center; color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(220 30 30 / .55); } 70% { box-shadow: 0 0 0 12px rgb(220 30 30 / 0); } 100% { box-shadow: 0 0 0 0 rgb(220 30 30 / 0); } }
.rec-dot { width: 16px; height: 16px; border-radius: 50%; background: #dc1e1e; animation: pulse 1.2s ease-out infinite; }
.rec.busy .rec-dot { background: var(--accent); animation: shimmer 1s ease-in-out infinite; }

/* --- медицина: подразделы-папки («стопка» листов под обложкой последнего обращения) --- */
/* слои стопки — тени с рамкой: псевдоэлементы прятались бы под фоном полоски */
.folder .thumb { overflow: visible; box-shadow: 4px -4px 0 -1px var(--card), 4px -4px 0 0 var(--line),
  8px -8px 0 -1px var(--card), 8px -8px 0 0 var(--line); }
.folder .thumb img { border-radius: 7px; }
.folder { padding: 8px 8px 0 0; }
.grid.folders { gap: 16px 12px; }
.folder .title { font-weight: 600; }
.list-sub { margin: 0 0 4px; font-size: 13px; }
.ai-queue { display: flex; gap: 8px; align-items: center; margin: 0; }
.topic-select { padding: 4px 8px; max-width: 100%; }

/* --- листы документа: галерея карточек --- */
.sheets { display: grid; gap: 10px; margin: 0 0 16px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
@media (max-width: 480px) { .gallery { grid-template-columns: repeat(3, 1fr); gap: 8px; } }
.sheet-card { all: unset; cursor: pointer; display: grid; gap: 2px; min-width: 0; }
.sheet-card .thumb { background: #fff; }   /* миниатюра квадратная, по верху листа: как плитки документов */
.sheet-card:focus-visible .thumb, .sheet-card:hover .thumb { border-color: var(--accent); }
.sheet-card .title { font-size: 13px; margin-top: 5px; }
.sheet-card .date { font-size: 11px; color: var(--muted); }
.redacted-btn { all: unset; cursor: zoom-in; display: block; }

/* --- лист на весь экран --- */
body.no-scroll { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 50; background: #111; color: #eee; display: grid;
  grid-template-rows: auto 1fr auto; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.viewer-bar { display: flex; gap: 14px; align-items: center; padding: 10px 14px; }
.viewer-count { flex: 1; font-size: 15px; }
.viewer-orig { color: #9fc0ff; font-size: 15px; }
.viewer-close { background: none; border: none; color: #eee; font-size: 30px; line-height: 1; padding: 0 6px; }
.viewer-stage { position: relative; display: grid; place-items: center; min-height: 0; overflow: hidden; }
.viewer-img { position: absolute; inset: 0 0 4px; display: flex; align-items: center; justify-content: center; }   /* высота задана: картинка не вылезает под подвал */
.viewer-img img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; display: block; }
.viewer-img .spinner { position: absolute; display: none; }
.viewer-img.wait .spinner { display: inline-block; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 1; width: 44px; height: 64px; padding: 0;
  font-size: 34px; line-height: 1; background: rgb(0 0 0 / .45); border: none; color: #fff; border-radius: 10px; }
.viewer-nav.prev { left: 8px; }
.viewer-nav.next { right: 8px; }
.viewer-foot { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; padding: 8px 14px 12px; }
.viewer-foot .text { flex: 1; min-width: 0; }
.viewer-foot .text pre { max-height: 30vh; color: var(--text); }
.viewer-foot .viewer-split { color: #eee; border-color: #555; flex: none; }
@media (max-width: 480px) { .viewer-nav { width: 36px; height: 54px; font-size: 28px; } }

/* --- крутилка нейронки в шапке и подсказка под ней --- */
.ai-status { position: relative; }
#ai-status-btn { display: inline-flex; gap: 6px; align-items: center; padding: 9px 10px; line-height: 1; font-size: 14px; color: var(--muted); }
#ai-status-btn[aria-expanded="true"] { border-color: var(--accent); }
.ai-pop { position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; width: min(340px, calc(100vw - 24px));
  padding: 14px; display: grid; gap: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / .25); font-size: 14px; }
.ai-pop p { margin: 0; }
.ai-pop-now { all: unset; cursor: pointer; display: flex; gap: 8px; align-items: flex-start; line-height: 1.35; }
.ai-pop-now .spinner { margin-top: 2px; }
.ai-pop-list { margin: 0; padding-left: 18px; display: grid; gap: 2px; }
.ai-pop-list button.link { padding: 0; text-align: left; color: var(--text); text-decoration: none; }
.ai-pop-list button.link:hover { text-decoration: underline; }
.spinner.small { width: 12px; height: 12px; border-width: 2px; }

/* --- подраздел медицины: строки с диагнозом вместо мелких плиток --- */
.rows { display: grid; gap: 8px; }
.doc-row { all: unset; box-sizing: border-box; cursor: pointer; display: flex; gap: 12px; align-items: center;
  padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.doc-row:hover, .doc-row:focus-visible { border-color: var(--accent); }
.doc-row .thumb { width: 64px; flex: none; }
.doc-row-info { display: grid; gap: 2px; min-width: 0; }
.doc-row-title { font-weight: 600; line-height: 1.3; }
.doc-row-about { color: var(--muted); font-size: 14px; line-height: 1.3; }
.doc-row-meta { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.todo-badge { border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: 0 8px; font-size: 12px; }

/* --- суть и дела из документа --- */
.ai-sub { font-size: 15px; margin: 4px 0 0; color: var(--muted); font-weight: 600; }
.summary { line-height: 1.5; }
.todo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.todo-item { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; color: var(--text); font-size: 15px; line-height: 1.35; }
.todo-list input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }
.todo-list li.done span { color: var(--muted); text-decoration: line-through; }
.ai-mark { position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent);
  display: grid; place-items: center; box-shadow: 0 1px 3px rgb(0 0 0 / .3); }
.ai-mark svg { width: 15px; height: 15px; fill: #fff; }
