/* Град ИИ на телефоне. Цвета и темы — как у десктоп-клиента (client/ui/user.css), шрифт и таблицы — как в personal_chat.
   Тема: data-theme на <html> (system | light | dark). */
:root {
  --bg: #f4f7fa; --surface: #ffffff; --sunken: #edf2f6; --line: #dce5eb; --line-strong: #beced9;
  --text: #172b3a; --muted: #627789; --faint: #627789;
  --accent: #087f8c; --accent-ink: #066b78; --accent-soft: #e6f4f4; --ok: #168477; --warn: #94630c; --bad: #bf4545; --blue: #2f6bd8;
  --table-heading: #f2f6f8;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111d26; --surface: #192934; --sunken: #203340; --line: #2b4352; --line-strong: #456372;
  --text: #e6eef3; --muted: #a4b8c6; --faint: #a4b8c6;
  --accent: #55c5cb; --accent-ink: #75d5da; --accent-soft: #183b43; --ok: #70c9ac; --warn: #e2b75b; --bad: #f08787; --blue: #78a9f5;
  --table-heading: #203340;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #111d26; --surface: #192934; --sunken: #203340; --line: #2b4352; --line-strong: #456372;
    --text: #e6eef3; --muted: #a4b8c6; --faint: #a4b8c6;
    --accent: #55c5cb; --accent-ink: #75d5da; --accent-soft: #183b43; --ok: #70c9ac; --warn: #e2b75b; --bad: #f08787; --blue: #78a9f5;
    --table-heading: #203340;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
html { touch-action: manipulation; } /* без увеличения двойным касанием */
body {
  background: var(--bg); color: var(--text); overflow: hidden;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-underline-offset: 3px;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: transparent; border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 14px; min-height: 40px; }
button:disabled, button[aria-disabled="true"] { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
:root[data-theme="dark"] button.primary { color: #0c232b; }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] button.primary { color: #0c232b; } }
button.icon { border: 0; padding: 8px; min-height: 40px; min-width: 40px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
button.icon:active { background: var(--sunken); color: var(--text); }
button.link { border: 0; min-height: 0; padding: 6px 4px; color: var(--accent); }
input, textarea { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; outline: none; width: 100%; }
input:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--bad); min-height: 1.3em; font-size: 14px; }
code, pre { font-family: ui-monospace, Consolas, monospace; }

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 900px; margin: 0 auto; position: relative; }

/* ---------- вход: логотип, циферблат PIN ---------- */
.gate { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); text-align: center; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 750; letter-spacing: -.6px; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.brand em { color: var(--accent); font-style: normal; }
.gate h2 { margin: 6px 0 0; font-size: 20px; font-weight: 650; }
.gate p { margin: 0; max-width: 340px; }
.dots { display: flex; gap: 18px; margin: 10px 0 4px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); }
.dots i.on { background: var(--accent); border-color: var(--accent); }
.dots.shake { animation: shake .4s; }
.dots.shake i { border-color: var(--bad); }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 26px; margin-top: 8px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.keypad button { width: 76px; height: 76px; min-height: 0; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  font-size: 30px; font-weight: 400; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.keypad button small { font-size: 9px; letter-spacing: 2px; color: var(--muted); margin-top: 3px; height: 10px; }
.keypad button:active { background: var(--accent-soft); border-color: var(--accent); }
.keypad button.ghost { border: 0; background: none; box-shadow: none; color: var(--muted); }
.keypad button.ghost .ic { width: 28px; height: 28px; }
.gate .steps-list { text-align: left; margin: 4px 0; padding-left: 22px; max-width: 340px; }
.gate .steps-list li { margin: 6px 0; }
.gate .wide { width: 100%; max-width: 340px; }
.code-box { display: flex; gap: 8px; width: 100%; max-width: 340px; }

/* ---------- шапка ---------- */
.top { display: flex; align-items: center; gap: 4px; padding: 6px 8px; min-height: 56px; border-bottom: 1px solid var(--line); background: var(--bg); }
.top h1 { flex: 1; min-width: 0; margin: 0 4px; font-size: 17px; font-weight: 700; letter-spacing: -.3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- панель чатов ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 20, 28, .38); z-index: 20; animation: fade .15s; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(330px, 86vw); z-index: 21; background: var(--bg); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom)); animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(-100%); } }
@keyframes fade { from { opacity: 0; } }
.drawer .head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 14px; }
.side-new { display: flex; align-items: center; gap: 10px; width: 100%; margin: 0 0 8px; padding: 10px 13px; min-height: 46px; border: 1px solid #087f8c; border-radius: 11px; background: #087f8c; color: #fff; font-weight: 600; }
.sessions { flex: 1; overflow-y: auto; min-height: 0; }
.group { margin: 16px 8px 6px; font-size: 11px; font-weight: 650; letter-spacing: .4px; text-transform: uppercase; color: var(--muted); }
.sess-row { display: flex; align-items: center; border-radius: 10px; margin-bottom: 2px; }
.sess { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 8px 10px; border: 0; text-align: left; }
.sess .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess .ic { color: var(--muted); }
.sess-row .lock { color: var(--muted); opacity: .45; }
.sess-row .lock.on { color: var(--accent-ink); opacity: 1; }
.sess-row.doomed .sess, .sess-row.doomed .sess .ic { color: var(--bad); }
.sess .left { margin-left: auto; flex: none; font-size: 12px; }
.sess-row.active { background: var(--accent-soft); color: var(--accent-ink); }
.sess-row.active .ic { color: var(--accent); }
.side-foot { border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 2px; }
.foot-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; text-align: left; font-size: 15px; }
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; margin: 4px 0 6px; }
.seg button { flex: 1; border: 0; border-radius: 0; min-height: 38px; padding: 6px 4px; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 650; }
.ver { font-size: 12px; color: var(--muted); padding: 6px 10px 0; }

/* ---------- переписка ---------- */
.feed { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px 12px 12px;
}
/* фон экрана чата и экранов входа: узор + оттенок (переменные ставит bgStyle); низ с полем ввода — прозрачный поверх, шапка своя */
.bgd .composer-wrap { background: transparent; }
.bgd, .gate { --tint: transparent; --tint-d: transparent;
  background: linear-gradient(var(--tint), var(--tint)), var(--bg-light) center top / cover fixed; }
:root[data-theme="dark"] :is(.bgd, .gate) { background-image: linear-gradient(var(--tint-d), var(--tint-d)), var(--bg-dark); }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] :is(.bgd, .gate) { background-image: linear-gradient(var(--tint-d), var(--tint-d)), var(--bg-dark); } }
.top h1 { cursor: text; }
.top .lock { color: var(--muted); }
.top .lock.on { color: var(--accent-ink); background: var(--accent-soft); }
.title-edit { flex: 1; min-width: 0; margin: 0 4px; font-size: 17px; font-weight: 700; padding: 6px 8px; border: 1px solid var(--accent); border-radius: 8px; background: var(--surface, var(--bg)); color: inherit; }
.messages { display: flex; flex-direction: column; gap: 18px; }
.empty { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 20px; color: var(--muted); }
.empty img { width: 56px; height: 56px; border-radius: 14px; }
/* Град: лента кадров 192×192, кадр выбирает app.js через background-position (как в десктопе) */
.grad { width: 72px; height: 72px; flex: none; background: no-repeat 0 0 / auto 100%; image-rendering: pixelated; }
.empty .grad { width: 160px; height: 160px; margin-bottom: -6px; }
.grad-row { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; margin: 2px 0 6px; }
.grad-row.leaving { animation: grad-leave .8s ease-in .4s forwards; overflow: hidden; }
@keyframes grad-leave { from { max-height: 90px; opacity: 1; } to { max-height: 0; opacity: 0; margin: 0; } }
.empty h2 { margin: 0; color: var(--text); font-size: 20px; }
.msg-user { align-self: flex-end; max-width: 88%; background: var(--accent-soft); border-radius: 14px 14px 4px 14px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
/* пузырь пользователя: заметнее фона чата — в светлой теме темнее, в тёмной светлее */
.msg-user { background: color-mix(in srgb, var(--accent) var(--ub, 16%), var(--surface)); }
:root[data-theme="dark"] .msg-user { --ub: 30%; }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] .msg-user { --ub: 30%; } }
.msg-user::before { content: "Вы"; display: block; margin-bottom: 3px; font-size: 11px; font-weight: 650; color: var(--muted); }
.msg-user .att { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.msg-ai { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 14px 10px; line-height: 1.65; overflow-wrap: anywhere; }
.message-author { font-size: 12px; font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.message-author img { width: 18px; height: 18px; border-radius: 5px; }
.msg-ai p { margin: 0 0 10px; }
.msg-ai p:last-child { margin-bottom: 0; }
.msg-ai h3, .msg-ai h4, .msg-ai h5 { margin: 16px 0 6px; line-height: 1.35; }
.msg-ai h3 { font-size: 18px; } .msg-ai h4 { font-size: 16px; }
.msg-ai ul, .msg-ai ol { margin: 4px 0 10px; padding-left: 22px; }
.msg-ai a { color: var(--accent); }
.msg-ai .md-figure img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); margin: 6px 0; }
.msg-ai :not(pre) > code { background: var(--sunken); border-radius: 4px; padding: 1px 4px; font-size: .9em; }
.msg-ai .err-text { color: var(--bad); margin-top: 8px; }
.typing { color: var(--muted); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* блок кода — как в десктоп-клиенте */
.code-block { margin: 10px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--sunken); overflow: hidden; }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 3px 6px 3px 12px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.code-block pre { margin: 0; padding: 10px 12px; overflow: auto; max-height: 420px; white-space: pre; font-size: 13px; line-height: 1.5; }
.code-block code { display: block; white-space: pre; tab-size: 4; }
.hl-kw { color: var(--accent-ink); font-weight: 600; }
.hl-str { color: var(--ok); }
.hl-com { color: var(--muted); font-style: italic; }
.hl-num, .hl-attr { color: var(--warn); }
.hl-pre, .hl-tag { color: var(--bad); }
.copy-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; min-height: 0; padding: 0; border: 1px solid transparent; border-radius: 7px; color: var(--muted); vertical-align: middle; }
.copy-btn .ic { width: 15px; height: 15px; }
.copy-btn:active { color: var(--accent); background: var(--accent-soft); }
.contact { white-space: nowrap; }
.contact .copy-btn { width: 26px; height: 26px; margin-left: 2px; }

/* план — как в десктоп-клиенте */
.plan-block { margin: 0 0 12px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.plan-title { font-size: 12px; color: var(--muted); cursor: pointer; margin-bottom: 10px; list-style-position: inside; }
.steps { list-style: none; margin: 0 0 6px; padding: 0; }
.steps li { position: relative; display: flex; gap: 10px; align-items: flex-start; padding: 0 0 16px; flex-wrap: wrap; }
.steps li:not(:last-child)::before { content: ""; position: absolute; left: 10px; top: 22px; bottom: 1px; border-left: 1px solid var(--line-strong); }
.steps .st { width: 21px; height: 21px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface); flex: none; margin-top: 1px; position: relative; z-index: 1;
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px; color: #fff; }
.steps .done .st { border-color: #087f8c; background: #087f8c; }
.steps .done .st::after { content: "✓"; }
.steps .running .st { border-color: var(--accent); border-top-color: transparent; animation: spin .9s linear infinite; }
.steps .error .st { border-color: var(--bad); background: var(--bad); }
.steps .error .st::after { content: "✕"; }
.steps .skipped { color: var(--faint); }
.steps .skipped .st::after { content: "–"; color: var(--muted); }
.steps .t { flex: 1 1 100px; min-width: 0; font-size: 13px; line-height: 1.5; }
.steps .d { flex: 1 1 100%; padding-left: 31px; margin-top: -2px; font-size: 11px; color: var(--muted); }

/* таблица — как в personal_chat: рамка, панель, прокрутка вбок, липкая шапка */
.table-frame { max-width: 100%; min-width: 0; margin: 14px 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; white-space: normal; }
.table-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table-label { margin-right: auto; padding: 0 4px; font-size: 12px; color: var(--muted); }
.table-tools button { min-height: 32px; padding: 4px 10px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; border-color: var(--line); }
.table-tools .ic { width: 15px; height: 15px; }
.table-scroll { width: 100%; max-width: 100%; overflow: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
.table-dialog .table-scroll { height: 100%; }
.msg-ai table, .table-dialog table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; line-height: 1.55; table-layout: auto; }
.msg-ai td, .msg-ai th, .table-dialog td, .table-dialog th { min-width: 9rem; max-width: min(26rem, calc(100vw - 100px)); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 10px 12px; text-align: left; vertical-align: top; overflow-wrap: break-word; word-break: normal; }
.msg-ai th, .table-dialog th { position: sticky; top: 0; z-index: 1; background: var(--table-heading); font-weight: 600; }
.msg-ai :is(td, th):last-child, .table-dialog :is(td, th):last-child { border-right: 0; }
.msg-ai tr:last-child td, .table-dialog tr:last-child td { border-bottom: 0; }
.msg-ai :is(td, th):first-child { max-width: 9rem; }
.table-hint { margin: 0; padding: 6px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
dialog.table-dialog { width: calc(100vw - 12px); max-width: 1400px; height: calc(100dvh - 12px); max-height: none; padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text); overflow: hidden; }
dialog.table-dialog[open] { display: flex; flex-direction: column; gap: 10px; }
dialog.notice { width: min(320px, calc(100vw - 48px)); padding: 20px 20px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: inherit;
  text-align: center; box-shadow: 0 12px 40px rgba(0, 0, 0, .25); }
dialog.notice h2 { margin: 0 0 8px; font-size: 18px; }
dialog.notice p { margin: 0 0 16px; color: var(--muted); font-size: 14.5px; line-height: 1.5; }
dialog.notice button { min-width: 120px; min-height: 42px; border-radius: 10px; }
dialog.notice::backdrop, dialog.table-dialog::backdrop { background: rgba(10, 20, 28, .45); }
.table-dialog .dialog-head { display: flex; align-items: center; gap: 8px; }
.table-dialog .dialog-head h2 { margin: 0 auto 0 0; font-size: 17px; }
.table-dialog .dialog-body { flex: 1; min-height: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.table-dialog td, .table-dialog th { max-width: min(32rem, calc(100vw - 64px)); }
.html-dialog .dialog-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.html-dialog .dialog-body iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
/* встроенный просмотр файлов */
.table-dialog .dialog-body.viewer { overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.viewer.html { overflow: hidden; }
.viewer.pdf { background: var(--soft, #e9eef2); padding: 8px; touch-action: pan-x pan-y; }
.viewer .pages { display: flex; flex-direction: column; gap: 8px; margin: 0 auto; }
.viewer .page { width: 100%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.viewer .page canvas { width: 100%; height: 100%; display: block; }
.zoom-pct { font-size: 12px; color: var(--muted); min-width: 38px; text-align: center; }
.viewer.img { display: flex; align-items: center; justify-content: center; background: #111; }
.viewer.img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer.docx { background: #fff; color: #111; }
.viewer .docx-page { padding: 12px; }
.viewer .docx-page section.docx { padding: 0 !important; width: auto !important; min-height: 0 !important; box-shadow: none !important; }
.viewer.text, .viewer.md, .viewer.csv, .viewer.json, .viewer.code { padding: 10px; }
.viewer pre.plain { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.5 ui-monospace, Consolas, monospace; }
.viewer > p { padding: 12px; }

/* файлы от ИИ и вложения */
.files { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
/* свои сценарии */
.table-dialog .dialog-body.sheet-body { overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; border: 0; display: flex; flex-direction: column; gap: 10px; }
.sheet-body > button.primary { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; }
.mine-list { display: flex; flex-direction: column; gap: 8px; }
.mine-row { display: flex; align-items: center; gap: 4px; }
.mine-pick, .mine-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; overflow-wrap: anywhere; }
.mine-pick { min-height: 48px; }
.mine-form { display: flex; flex-direction: column; gap: 10px; }
.mine-form textarea { resize: vertical; min-height: 160px; }
.mine-form .check { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; }
.mine-form .check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.mine-form .check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.mine-form .err-text { color: var(--bad); margin: 0; }
.mine-form .err-text:empty { display: none; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.file-row { display: flex; gap: 6px; align-items: stretch; }
.file-row .file-card { flex: 1; min-width: 0; }
.file-attach { flex: none; width: 48px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--accent); display: grid; place-items: center; }
.file-card { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 56px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); text-align: left; }
.file-card .info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.file-card .n { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .meta { font-size: 12px; color: var(--muted); }
.file-card > .ic { color: var(--accent); }
.file-card.gone { opacity: .55; }
.file-card.gone > .ic { color: var(--muted); }
.fi { position: relative; display: inline-flex; flex: none; width: 32px; height: 34px; font-style: normal; color: var(--muted); }
.fi .ic { width: 32px; height: 34px; stroke-width: 1.3; }
.fi-image { flex: none; width: 32px; height: 32px; object-fit: contain; }
.fi b { position: absolute; left: 50%; top: 55%; transform: translate(-50%, -50%); padding: 2px 4px; border-radius: 3px; white-space: nowrap;
  font: 700 9px/1 -apple-system, "Segoe UI", sans-serif; color: #fff; background: var(--fi, #5f6b7a); box-shadow: 0 0 0 1.5px var(--surface); }
.fi[data-ext="pdf"] { --fi: #d14b4b; }
.fi[data-ext="doc"], .fi[data-ext="docx"], .fi[data-ext="rtf"] { --fi: #2f6fe4; }
.fi[data-ext="xls"], .fi[data-ext="xlsx"], .fi[data-ext="csv"] { --fi: #2e9d64; }
.fi[data-ext="html"], .fi[data-ext="htm"] { --fi: #c5761a; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 3px 4px 3px 9px; font-size: 13px; min-height: 32px; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { min-height: 26px; min-width: 26px; padding: 0; border: 0; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.chip .ic { width: 15px; height: 15px; }

/* кнопки под ответом */
.answer-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.answer-actions button { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 11px; font-size: 13px; border-color: var(--line); border-radius: 9px; color: var(--muted); }
.answer-actions .ic { width: 16px; height: 16px; }
.long-hint { flex-basis: 100%; font-size: 12.5px; color: var(--muted); padding: 8px 10px; border-radius: 9px; background: var(--accent-soft); }
.answer-actions button.done { color: var(--accent-ink); background: var(--accent-soft); border-color: transparent; }

/* форма уточнения */
.ask { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.ask fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ask legend { font-weight: 600; margin-bottom: 4px; }
.ask label { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; }
.ask label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.ask input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

/* ---------- поле ввода ---------- */
.composer-wrap { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); }
.composer { border: 1px solid var(--line-strong); border-radius: 18px; background: var(--surface); padding: 8px 8px 8px 12px; box-shadow: 0 2px 10px rgba(16, 40, 56, .06); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea { border: 0; padding: 4px 2px; min-height: 28px; max-height: 40vh; resize: none; background: none; display: block; line-height: 1.45; }
.composer textarea:focus-visible { outline: none; }
.composer .chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0 6px; }
.composer .chips:empty { display: none; }
/* слева режимы (переносятся на вторую строку), справа контекст и отправка — всегда в первой строке */
.composer .bar { display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 6px 4px; margin-top: 6px; }
.composer .bar .left, .composer .bar .right, .composer .bar .cloud-row { display: flex; align-items: center; gap: 4px; min-height: 40px; }
.composer .bar .left { flex-wrap: wrap; }
.composer .bar .cloud-row { grid-column: 1 / -1; }
.composer .bar .tool { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 6px 11px; border-color: var(--line); border-radius: 12px; font-size: 14px; color: var(--muted); }
.composer .bar .tool.on { color: var(--accent-ink); background: var(--accent-soft); border-color: transparent; }
[hidden] { display: none !important; }
.composer .bar .tool.icon-only { padding: 0; width: 36px; min-height: 36px; justify-content: center; }
.composer .bar .ctx-meter { width: 34px; min-width: 34px; }
.composer .bar select.tool { border: 1px solid var(--line); background: transparent; max-width: 9rem; }
.sources { margin-top: 10px; font-size: 14px; border-top: 1px solid var(--line); padding-top: 6px; }
.sources summary { cursor: pointer; color: var(--muted); }
.sources ol { margin: 6px 0 0; padding-left: 1.4em; }
.sources a { color: var(--accent-ink); overflow-wrap: anywhere; }
/* пирамида контекста у кнопки отправки — как в десктопе */
.ctx-pct { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; margin-right: -4px; }
.ctx-meter { flex: none; width: 38px; height: 38px; min-width: 38px; min-height: 38px; padding: 0; border: 0; display: inline-flex; align-items: center; justify-content: center; }
.ctx-meter svg { width: 26px; height: 24px; display: block; overflow: visible; }
.ctx-meter path { fill: none; stroke: var(--accent); stroke-width: 1.2; stroke-linejoin: round; }
.ctx-meter path.on { fill: var(--accent); }
.ctx-meter.lv-yellow { --lv: #d9a400; } .ctx-meter.lv-orange { --lv: #e46f12; } .ctx-meter.lv-red { --lv: var(--bad); }
.ctx-meter[class*="lv-"] path { stroke: var(--lv); } .ctx-meter[class*="lv-"] path.on { fill: var(--lv); }
.ctx-pct.lv-yellow { color: #b98b00; } .ctx-pct.lv-orange { color: #e46f12; } .ctx-pct.lv-red { color: var(--bad); font-weight: 600; }
.ctx-meter.blink svg { animation: ctx-blink 2s ease-in-out infinite; }
@keyframes ctx-blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .ctx-meter.blink svg { animation: none; } }
.send { width: 44px; height: 44px; min-height: 0; padding: 0; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.send .ic { width: 22px; height: 22px; stroke-width: 2.2; }
.send:disabled { background: var(--line-strong); opacity: 1; }
.send.stop { background: var(--text); color: var(--bg); }
.note { text-align: center; font-size: 11px; color: var(--muted); margin-top: 6px; }

#toast { position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; max-width: calc(100vw - 32px);
  padding: 9px 14px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
#toast.error { background: var(--bad); color: #fff; }

/* пузырь ответа ИИ: отделён от фона чата — в светлой теме белый с тенью, в тёмной темнее фона */
.msg-ai { box-shadow: 0 1px 4px rgba(20, 40, 60, .08); }
:root[data-theme="dark"] .msg-ai { background: color-mix(in srgb, #000 30%, var(--surface)); box-shadow: none; }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] .msg-ai { background: color-mix(in srgb, #000 30%, var(--surface)); box-shadow: none; } }
/* кнопки под полем ввода в тёмной теме — контур светлее, чтобы читался на узоре */
:root[data-theme="dark"] .composer .bar :is(.tool, select.tool):not(.on) { border-color: color-mix(in srgb, var(--line-strong) 70%, #fff); }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] .composer .bar :is(.tool, select.tool):not(.on) { border-color: color-mix(in srgb, var(--line-strong) 70%, #fff); } }

/* поле ввода в 2 строки, в его конце — пирамида контекста ровно над «Отправить» (той же ширины) */
.composer .line { display: grid; grid-template-columns: 1fr 44px; gap: 6px; align-items: start; }
.composer .line textarea { min-height: calc(2 * 1.45em + 8px); }
.composer .line .ctx { display: flex; flex-direction: column; align-items: center; gap: 0; }
.composer .line .ctx-meter { width: 44px; height: 38px; min-width: 44px; min-height: 38px; }
.composer .line .ctx-meter svg { width: 34px; height: 32px; }
.composer .line .ctx-pct { margin: -2px 0 0; font-size: 11px; line-height: 1; }
.composer .bar .right { gap: 6px; }
/* «Диалог»: красная точка записи; включён — плавно мигает и растёт с громкостью голоса (--lvl 0…1) */
.dialog { --lvl: 0; width: 44px; height: 44px; min-height: 0; padding: 0; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface); display: inline-flex; align-items: center; justify-content: center; }
.dialog .dot { width: 14px; height: 14px; border-radius: 50%; background: #e5484d; transition: transform .08s linear, box-shadow .08s linear; }
.dialog.on { border-color: #e5484d; background: color-mix(in srgb, #e5484d 10%, var(--surface)); }
.dialog.on .dot { animation: rec-pulse 1.6s ease-in-out infinite; transform: scale(calc(1 + var(--lvl) * .8)); box-shadow: 0 0 0 calc(var(--lvl) * 9px) color-mix(in srgb, #e5484d 22%, transparent); }
.dialog.on.wait .dot { animation-duration: .7s; background: #f08a8d; }
/* идёт озвучка: плашка «Озвучиваю», медленно мигает целиком; точка не реагирует на микрофон (он на паузе) */
.dialog.speak { width: auto; padding: 0 14px 0 12px; gap: 7px; border-radius: 22px; color: #e5484d; font-size: 14px; font-weight: 600; animation: say-blink 2.4s ease-in-out infinite; }
.dialog.on.speak .dot { animation: none; transform: none; box-shadow: none; width: 12px; height: 12px; border-radius: 3px; }   /* ■ — прервать озвучку */
@keyframes say-blink { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .dialog.speak { animation: none; } }
@keyframes rec-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dialog.on .dot { animation: none; } }
.composer .bar .tool.mic.on { color: #e5484d; background: color-mix(in srgb, #e5484d 12%, transparent); border-color: transparent; }
/* «Конфиденциально» в чате, где оно уже было: не снимается */
.composer .bar .tool.locked.on { box-shadow: inset 0 0 0 1px var(--accent); }
/* приватный чат: ниндзя вместо «+» в новом чате и у названия */
.top .icon.ninja.on { color: var(--accent-ink); background: var(--accent-soft); }
.pv-badge { display: inline-flex; color: var(--muted); margin-right: -4px; }
.pv-badge[hidden] { display: none; }
.pv-badge .ic { width: 18px; height: 18px; }
.answer-actions button.busy .ic { animation: rec-pulse 1s ease-in-out infinite; }
.settings .voice-name, .settings .voice-pick { margin: 2px 8px 6px; width: calc(100% - 16px); }
.settings .voice-pick { padding: 9px 10px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; }
.messages .tokens { font-size: 12px; color: var(--muted); margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
/* окно «Настройки»: подписи вплотную к своим переключателям */
.settings { display: flex; flex-direction: column; gap: 2px; }
.settings > .small.muted { margin-top: 8px; }
.settings > .foot-row { border-radius: 10px; }

/* ---------- разделы: нижняя панель, список задач ---------- */
.nav { display: flex; border-top: 1px solid var(--line); background: var(--bg); padding-bottom: env(safe-area-inset-bottom); }
.nav-btn { flex: 1; border: 0; border-radius: 0; min-height: 52px; padding: 6px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); }
.nav-btn.on { color: var(--accent-ink); }
.nav-btn .ic { width: 22px; height: 22px; }
.nav-btn { position: relative; }
.nav-grad { width: 26px; height: 26px; object-fit: contain; margin: -2px 0; }
.nav-count { position: absolute; top: 3px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 10px; font-weight: 700; line-height: 18px; text-align: center; }
.sec { flex: 1; min-height: 0; display: flex; position: relative; }
.sec-list { flex: 1; min-width: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 12px 12px 20px; }
.pad { padding: 12px 14px; margin: 0; }
.sec .chips { display: flex; gap: 6px; padding: 2px 0 10px; overflow-x: auto; scrollbar-width: none; }
.sec .chip { flex: none; min-height: 40px; padding: 4px 14px; border-radius: 20px; font-size: 14px; color: var(--muted); }
.sec .chip .kind-ico { width: 20px; height: 20px; }
.sec .chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.task-pick { flex: none; width: 22px; height: 22px; margin: 14px 0 0; accent-color: var(--accent); }
.due { flex: none; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--sunken); color: var(--muted); white-space: nowrap; }
.due.bad { color: var(--bad); }
.due.warn { color: var(--warn); }
.batch:not(:empty) { padding: 8px 12px; border-top: 1px solid var(--line); background: var(--bg); }
.batch button { width: 100%; }
.sec-list .batch:not(:empty) { position: sticky; bottom: -20px; margin: 0 -12px -20px; }

/* ---------- разделы: шапка, строки по view, плашки, поиск, таблица, календарь ---------- */
.sec-top { gap: 10px; padding: 6px 8px 6px 12px; }
.sec-top .avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; }
.sec-top .avatar .ic { width: 26px; height: 26px; }
.sec-top .who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.sec-top .who strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec-top .who small { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec h1.sec-h { margin: 4px 0 12px; font-size: 24px; letter-spacing: -.6px; display: flex; align-items: center; gap: 10px; }
.sec h1.sec-h .count { min-width: 28px; height: 28px; padding: 0 8px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-ink); font-size: 16px; display: grid; place-items: center; }
.sec-back { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--accent-ink); padding: 6px 4px; min-height: 40px; font-size: 14px; }
.srch { position: relative; display: block; margin: 0 0 10px; }
.srch > .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 19px; height: 19px; color: var(--muted); pointer-events: none; }
.srch input { width: 100%; min-height: 46px; padding: 8px 12px 8px 40px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); font-size: 15px; }
.recs { display: flex; flex-direction: column; gap: 10px; }
.grp { margin: 8px 2px 0; font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.grp.bad { color: var(--bad); }
.rec-row { display: flex; gap: 8px; align-items: flex-start; }
.rec { flex: 1; min-width: 0; display: flex; gap: 12px; align-items: flex-start; text-align: left; padding: 13px 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); min-height: 44px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.rec.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.rec.picked { background: var(--accent-soft); }
.rec-ico { flex: none; width: 40px; height: 40px; display: grid; place-items: center; }
.rec-ico img, .card-hero img { width: 40px; height: 40px; object-fit: contain; }
.rec-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.rec-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rec-badge { font-size: 14px; letter-spacing: -.2px; }
.rec-title { font-size: 15px; font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.rec-sub { font-size: 13px; overflow-wrap: anywhere; }
.rec-line { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
.rec-line > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-line .ic, .rec-when .ic { flex: none; width: 15px; height: 15px; }
.rec-foot { display: flex; align-items: center; gap: 10px; margin-top: 2px; font-size: 13px; color: var(--muted); }
.rec-when { display: inline-flex; align-items: center; gap: 5px; }
.rec-value { margin-left: auto; font-weight: 700; color: var(--text); font-size: 14px; }
.tone { display: inline-flex; align-items: center; font-size: 12px; font-weight: 650; line-height: 1.3; padding: 3px 8px; border-radius: 7px; background: var(--sunken); color: var(--muted); white-space: nowrap; }
.tone-ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.tone-warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.tone-bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, transparent); }
.tone-info { color: var(--blue); background: color-mix(in srgb, var(--blue) 13%, transparent); }
.vtable-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.vtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.vtable th, .vtable td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.vtable th { font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--table-heading); }
.vtable .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vtable tfoot td { font-weight: 700; border-bottom: 0; }
.card-hero { display: flex; gap: 12px; align-items: flex-start; margin: 0 0 12px; }
.card-hero .card-title { margin: 0 0 6px; }
.card-meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 0; }
.card-meta:empty { display: none; }
details.more { border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; background: var(--surface); }
details.more summary { min-height: 44px; display: flex; align-items: center; font-size: 14px; font-weight: 600; color: var(--accent-ink); cursor: pointer; }
details.more[open] { padding-bottom: 8px; }
.grad-mini { width: 20px; height: 20px; object-fit: contain; display: block; }   /* как .ic соседних кнопок: одна линия и размер */
.visas { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.visa-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.visa-row p { margin: 0 0 3px; font-size: 14px; }
.visa-dept { font-weight: 600; }
.visa-ico { flex: none; width: 30px; height: 30px; object-fit: contain; }
.visa-dot { flex: none; width: 30px; height: 30px; border-radius: 50%; border: 2px dashed var(--line-strong); }
.picker { display: flex; flex-direction: column; gap: 8px; }
.pick-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.pick-btn { flex: 1 1 30%; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 6px 8px; font-size: 13px; }
.pick-btn .ic { width: 18px; height: 18px; }
.picked { display: flex; gap: 6px; flex-wrap: wrap; }
.picked:empty { display: none; }
.act-files { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.cal { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); padding: 8px; margin: 0 0 12px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 6px; }
.cal-head strong { font-size: 16px; }
.cal-head button:last-child .ic { transform: scaleX(-1); }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.cal-week span { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-day { position: relative; min-height: 44px; min-width: 0; padding: 0; border: 0; border-radius: 10px; background: none; font-size: 15px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.cal-day.today { font-weight: 800; color: var(--accent-ink); }
.cal-day.marked::after { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-day .cal-n { position: absolute; top: 2px; right: 3px; font-size: 10px; color: var(--muted); }
.cal-day.on { background: var(--accent); color: var(--bg); }
.cal-day.on::after { background: var(--bg); }
.cal-day.on .cal-n { color: var(--bg); }
.day-filter { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 4px 4px 12px; margin: 0 0 10px; border: 1px solid var(--accent); border-radius: 12px; color: var(--accent-ink); font-size: 14px; }
.day-filter button { border: 0; background: none; color: var(--accent-ink); min-height: 40px; }
.tabs { display: flex; gap: 8px; margin: 0 0 12px; }
.tabs button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 46px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); color: var(--muted); font-weight: 600; font-size: 15px; }
.tabs button.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent-ink); }
.tabs .ic { width: 19px; height: 19px; }
/* «Мой день» 1С:ДО */
.day { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); padding: 16px; margin: 0 0 12px; }
.day .date { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.day .hello { margin: 0 0 12px; font-size: 20px; font-weight: 650; letter-spacing: -.4px; }
.day-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.day-main .big { font-size: 20px; letter-spacing: -.5px; line-height: 1.25; margin: 0; }
.day-main .big b { font-size: 40px; letter-spacing: -1.4px; margin-right: 6px; }
.ring { flex: none; width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--sunken) 0); }
.ring span { width: 56px; height: 56px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: 14px; font-weight: 700; }
.day-stats { display: flex; gap: 8px; margin: 14px 0 0; }
.day-stats button { flex: 1; min-width: 0; min-height: 56px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 12px; color: var(--muted); text-align: left; }
.day-stats b { font-size: 20px; color: var(--text); }
.day-stats .bad b { color: var(--bad); }
.day-stats .warn b { color: var(--warn); }
.day-stats .ok b { color: var(--ok); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0 0 12px; }
.tile { min-height: 104px; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); text-align: left; }
.tile img { width: 40px; height: 40px; object-fit: contain; }
.tile b { font-size: 28px; letter-spacing: -1px; }
.tile span { font-size: 14px; color: var(--muted); }
.tile.cal-tile { width: 100%; min-height: 64px; flex-direction: row; align-items: center; justify-content: flex-start; gap: 12px; margin: 0 0 12px; }
.cal-btn { flex: none; width: 52px; height: 52px; border: 1px solid var(--line); border-radius: 15px; background: var(--bg); display: grid; place-items: center; padding: 0; }
.cal-btn img { width: 40px; height: 40px; object-fit: contain; }
/* контакт контрагента */
.contact { display: flex; gap: 14px; align-items: center; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); padding: 16px; margin: 0 0 12px; }
.contact .avatar { flex: none; width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; }
.contact .avatar .ic { width: 34px; height: 34px; }
.contact p { margin: 0; }
.contact .name { font-size: 17px; font-weight: 700; }
.contact .org { font-size: 14px; }
/* приёмка и обсуждение (Технадзор) */
.acc { width: 100%; border-collapse: collapse; font-size: 14px; }
.acc th, .acc td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.acc th { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.acc .n { text-align: right; white-space: nowrap; }
.acc input { width: 100%; min-width: 64px; min-height: 40px; border: 1px solid var(--line-strong); border-radius: 9px; padding: 6px 8px; background: var(--surface); font-size: 15px; }
.acc input[aria-invalid="true"] { border-color: var(--bad); }
.acc .err-text { margin: 4px 0 0; font-size: 12px; }
.acc tfoot td { font-weight: 700; border-bottom: 0; }
.acc-sum { display: flex; justify-content: space-between; gap: 10px; margin: 10px 0 0; padding: 12px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; }
.comments { display: flex; flex-direction: column; gap: 8px; }
.comment { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.comment p { margin: 0 0 4px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment .file-row { margin-top: 6px; }
.comment-new { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.comment-new textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 10px; background: var(--surface); }
/* ---------- карточка задачи: на телефоне поверх списка ---------- */
.sec-card { display: none; position: absolute; inset: 0; z-index: 2; background: var(--bg); flex-direction: column; overflow: hidden; }
.sec-card.open { display: flex; }
.card-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; min-height: 52px; border-bottom: 1px solid var(--line); }
.card-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 12px 14px; }
.card-title { margin: 0 0 12px; font-size: 17px; font-weight: 650; line-height: 1.35; }
.card-block { margin: 0 0 14px; }
.card-block h3 { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.kv { display: flex; gap: 10px; justify-content: space-between; margin: 0; padding: 4px 0; font-size: 14px; }
.kv span:first-child { min-width: 0; overflow-wrap: anywhere; }
.kv span:last-child { text-align: right; overflow-wrap: anywhere; }
.remark { padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.remark p { margin: 0; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.card-actions button { flex: 1 1 45%; }
.card-actions button.primary { flex-basis: 100%; }
.sec .card-actions button:not(.primary) { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 6px 8px; font-size: 13px; line-height: 1.2; }
.card-actions p { margin: 0; }
.act-form { display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; }
.act-form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.act-form label.act-check { flex-direction: row; align-items: center; }
.act-form textarea, .act-form select, .act-form input:not([type=checkbox]) { width: 100%; border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 10px; background: var(--surface); }
.act-form p { margin: 0; }
.sec .err-text, .act-form .err-text { color: var(--bad); }
/* нижняя панель сама несёт отступ безопасной зоны — над ней он не нужен */
#app:has(.nav) .composer-wrap { padding-bottom: 8px; }
.sec .card-actions { padding-bottom: 10px; }
/* компактные окна разделов (подтверждение, форма действия): высота по содержимому, снизу экрана */
/* height: fit-content, а не auto: у dialog inset 0, и auto растягивает окно на всю высоту */
dialog.table-dialog.compact { height: fit-content; max-height: 85dvh; margin: auto auto 6px; }
dialog.table-dialog.compact .dialog-body { flex: 0 1 auto; }

/* ---------- второй экран карточки и лента процесса ---------- */
.sec-side { display: none; position: absolute; inset: 0; z-index: 3; background: var(--bg); flex-direction: column; overflow: hidden; }
.sec-side.open { display: flex; }
.proc { margin-top: 8px; padding-left: 4px; }
.stage { border-left: 2px solid var(--accent); padding: 0 0 6px 12px; margin-left: 10px; }
.stage-head { margin: 0 0 6px -24px; display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.stage-n { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--bg); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; }
.step { display: flex; gap: 10px; padding: 8px 10px; margin: 0 0 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 13px; }
.step.mine { border-color: var(--accent); }
.step p { margin: 0; }
.step-body { min-width: 0; overflow-wrap: anywhere; }
.step-kind { flex: none; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.step-kind.k { border-radius: 8px; background: var(--blue); color: var(--bg); font-weight: 700; }
.step-who { font-size: 14px; font-weight: 600; }
.mine-tag { margin-left: 8px; padding: 1px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-ink); font-size: 11px; font-weight: 600; }
.late { color: var(--bad); }
.late-tag { font-size: 11px; }
.proc .st::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.proc .st.ok::before { background: var(--ok); }
.proc .st.bad::before { background: var(--bad); }
.proc .st.blue::before { background: var(--blue); }
.proc .st.accent::before { background: var(--accent); }
.cond { overflow-wrap: anywhere; margin: 0 0 6px 22px; padding: 8px 10px; border-radius: 10px; background: var(--sunken); color: var(--warn); font-size: 13px; }
.proc.conditional .stage { border-left-style: dashed; }
.hist { display: flex; flex-direction: column; margin: 0; padding: 4px 0; font-size: 14px; }
.hist { overflow-wrap: anywhere; }
.hist .muted { font-size: 12px; }

/* ---------- от 768 px: список слева, карточка справа ---------- */
@media (min-width: 768px) {
  #app:has(.sec) { max-width: 1200px; }
  .sec-list { flex: 0 0 360px; border-right: 1px solid var(--line); }
  .sec-card { position: relative; inset: auto; display: flex; flex: 1; min-width: 0; }
  .sec-card:empty::before { content: 'Выберите запись слева'; margin: auto; color: var(--muted); }
  .sec-card .card-head > button[aria-label="Назад к списку"] { display: none; }
  dialog.table-dialog.compact { width: 480px; margin: auto; }
}
.step-open { margin-top: 6px; padding: 4px 12px; border: 1px solid var(--line); border-radius: 14px; background: none; color: var(--accent-ink); font-size: 13px; font-weight: 600; }
.note-row { display: flex; align-items: center; gap: 8px; } .note-row p { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.note-add { display: flex; gap: 6px; margin-top: 8px; } .note-add input:first-child { width: 4.5em; flex: none; } .note-add input:nth-child(2) { flex: 1; min-width: 0; }
.versions { margin: 2px 0 8px 12px; font-size: 13px; } .versions summary { color: var(--muted); cursor: pointer; padding: 4px 0; }
.ver-row { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-top: 1px solid var(--line); } .ver-row p { flex: 1; min-width: 0; margin: 0; }
.ver-row button { padding: 4px 10px; font-size: 13px; }
.cmp-dialog { display: flex; flex-direction: column; } .cmp-dialog[open] { display: flex; }
.cmp { flex: 1; min-height: 0; display: grid; grid-template-rows: 1fr 1fr; gap: 6px; }
.cmp-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; } .cmp-col .cmp-pane { flex: 1; min-height: 0; overflow: auto; }
.cmp-label { margin: 0; padding: 2px 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
@media (orientation: landscape) { .cmp { grid-template-rows: none; grid-template-columns: 1fr 1fr; } }
.cmp-tabs { margin: 0 8px 6px; } .cmp-diff { flex: 1; min-height: 0; overflow: auto; padding: 8px 12px; }
.diff p { margin: 0 0 8px; line-height: 1.45; } .diff-same { color: var(--muted); font-size: 12px; font-style: italic; }
.diff del { background: color-mix(in srgb, #d9534f 18%, transparent); text-decoration: line-through; }
.diff ins { background: color-mix(in srgb, #2e9d5b 20%, transparent); text-decoration: underline; }
.net-bar { margin: 0; padding: 6px 12px; background: color-mix(in srgb, #e0a100 22%, var(--surface)); color: var(--text, inherit); font-size: 13px; font-weight: 600; text-align: center; }

/* заявки на снабжение */
.rq-form { display: flex; flex-direction: column; gap: 12px; }
.rq-field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.rq-field > span:first-child { color: var(--muted); font-weight: 600; }
.rq-field select, .rq-receipt select, .act-check + select { width: 100%; min-height: 46px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 10px; background: var(--surface); }
.rq-field input, .rq-field textarea { min-height: 46px; }
[aria-invalid="true"] { border-color: var(--bad) !important; }
.rq-field .err-text:empty, .rq-item .err-text:empty { display: none; }
.rq-item, .rq-party { border: 1px solid var(--line); border-radius: 13px; background: var(--surface); padding: 10px 12px; margin: 0 0 8px; display: flex; flex-direction: column; gap: 6px; }
.rq-item p, .rq-party p { margin: 0; }
.rq-item-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rq-item-top strong { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.rq-detail { font-size: 14px; color: var(--muted); }
.rq-qty { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rq-qty.two { grid-template-columns: repeat(2, 1fr); }
.rq-qty > div { background: var(--sunken); border-radius: 9px; padding: 6px 4px; text-align: center; display: flex; flex-direction: column; }
.rq-qty b { font-size: 16px; }
.rq-qty span { font-size: 11px; color: var(--muted); }
.rq-qty .full b { color: var(--ok); }
.rq-decision summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.rq-lines { margin: 0; padding-left: 18px; font-size: 14px; }
.rq-party-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.rq-party-actions button { flex: 1 1 200px; min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.rq-notice { border-radius: 11px; background: var(--accent-soft); color: var(--accent-ink); padding: 10px 12px; font-size: 14px; margin: 0 0 12px; }
.rq-notice p { margin: 4px 0 0; }
.rq-notice.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--text); }
.rq-limit { font-size: 13px; color: var(--muted); }
.rq-limit.warn { color: var(--bad); }
.rq-types { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 0 0 12px; }
.rq-type { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-height: 84px; text-align: left; background: var(--surface); border-color: var(--line); border-radius: 13px; }
.rq-type small { color: var(--muted); }
.rq-stepper { display: flex; gap: 6px; margin: 0 0 8px; }
.rq-stepper span { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.rq-stepper span.on { background: var(--accent); }
.rq-step { margin: 0; display: flex; align-items: center; gap: 6px; }
.rq-add { min-height: 46px; border-style: dashed; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--accent-ink); }
.rq-nav { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; margin-top: 8px; }
.rq-nav button { flex: 1; min-height: 48px; }
.rq-pick { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.rq-opt { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; min-height: 52px; }
.rq-opt span { display: flex; flex-direction: column; }
.rq-draft { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; margin: 0 0 12px; border-color: var(--accent); background: var(--accent-soft); }
.rq-draft span { display: flex; flex-direction: column; }
.rq-draft small { color: var(--muted); }
.rq-receipt > button { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; }
.sec-requests .tabs { gap: 6px; }
.sec-requests .tabs button { min-width: 0; padding: 8px 6px; font-size: 14px; gap: 5px; }
