/* Visual UI Jarvis, срез 1. Тёмный, спокойный, один центр — орб. Состояние не кодируется только цветом:
   у каждого есть подпись (pill, подпись под орбом, aria-label). */
:root {
  --bg: #05080d;
  --bg-2: #0a1018;
  --line: #1a2533;
  --text: #e7edf4;
  --muted: #8f9cab;
  --accent: #5fd4ff;
  --accent-2: #2a8fd6;
  --warn: #f2bd5c;
  --off: #6b7684;
  --err: #ff8f8f;
  --owner: #13202e;
  --radius: 14px;
  --orb: min(56vw, 260px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --gut: 16px;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* атрибут hidden сильнее любых display в этом файле */
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  height: 100dvh; display: grid; grid-template-rows: auto 1fr auto auto;
  background: radial-gradient(120% 70% at 50% 0%, #0b1622 0%, var(--bg) 60%);
  overflow: hidden;
}
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
button svg { pointer-events: none; }   /* цель нажатия — сама кнопка (Safari не всегда поднимает событие от SVG) */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--bg-2); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }

/* ---------- верх */
.top {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 8px) var(--gut) 8px;
  border-bottom: 1px solid transparent;
}
/* имя — ровно на линии кнопок; канал («Telegram», «новый разговор») висит под ним и центровку не двигает (07.10) */
.top-title { flex: 1; min-width: 0; position: relative; display: flex; justify-content: center; align-items: center; line-height: 1.15; }
.top-title .name { font-weight: 600; letter-spacing: .08em; text-transform: uppercase; font-size: 13px; }
.top-title .channel { position: absolute; left: 0; right: 0; top: calc(50% + 9px); text-align: center; color: var(--muted);
  font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px;
  background: transparent; border: 1px solid transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--bg-2); }
a.icon-btn { color: inherit; }
#reload-btn { color: var(--muted); }
.state-pill { white-space: nowrap; }
@media (max-width: 430px) { .top { gap: 4px; } #reload-btn, #voice-link { width: 38px; } }
#reload-btn svg { width: 20px; height: 20px; }
#reload-btn.spin svg { animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #reload-btn.spin svg { animation: none; } }
.text-btn { background: none; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; cursor: pointer; min-height: 40px; }
.text-btn:hover { border-color: var(--accent-2); }
.state-pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; font-size: 13px;
}
.state-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
body[data-lex="ready"] .state-pill .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
body[data-lex="degraded"] .state-pill .dot { background: var(--warn); }
body[data-lex="unavailable"] .state-pill .dot, body[data-lex="offline"] .state-pill .dot {
  background: transparent; border: 1.5px solid var(--off);
}

/* ---------- центр: орб и разговор */
/* min-height: 0 — без него элемент строки 1fr растёт по содержимому, и на iPhone прокручивалась вся страница:
   перерисовка ленты на миг укорачивала её, и прокрутка улетала наверх (07.10) */
.main { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }
.stage { display: flex; flex-direction: column; align-items: center; padding: 6vh var(--gut) 8px; transition: padding .4s ease; }
.orb { width: var(--orb); aspect-ratio: 1; transition: width .45s ease; }
.orb svg { width: 100%; height: 100%; overflow: visible; }
.orb-label { margin: 14px 0 0; color: var(--muted); font-size: 15px; letter-spacing: .02em; text-align: center; min-height: 1.5em; }
body.has-turns .stage { display: none; }   /* в разговоре: состояние — плашка сверху и строка над вводом, орб — у ввода */
body.has-turns .stage .orb { display: none; }   /* в разговоре орб один — у поля ввода (вариант A) */
body.has-turns .orb-label { margin: 0; font-size: 14px; }

/* орб: цвета через переменные состояния */
.orb { --o: var(--accent); --o2: var(--accent-2); --glow: .55; }
body[data-orb="degraded"] .orb { --o: var(--warn); --o2: #b07a1e; --glow: .35; }
body[data-orb="offline"] .orb { --o: var(--off); --o2: #3a434e; --glow: .1; }
.orb .c0 { stop-color: #ffffff; stop-opacity: .95; }
.orb .c1 { stop-color: var(--o); stop-opacity: .85; }
.orb .c2 { stop-color: var(--o2); stop-opacity: .25; }
body[data-orb="offline"] .orb .c0 { stop-color: #8a949f; stop-opacity: .5; }
body[data-orb="offline"] .orb .c1 { stop-opacity: .45; }
.orb .halo { fill: var(--o); opacity: calc(var(--glow) * .12); }
.orb .ring { stroke: var(--o); stroke-width: 1.2; opacity: .55; stroke-dasharray: 22 3 8 3 30 3 4 3 24 0; fill: none; }
.orb .ring.thin { stroke-width: .8; opacity: .35; stroke-dasharray: 2 2; }
.orb .sweep { stroke: var(--o); stroke-width: 2.4; fill: none; stroke-dasharray: 18 82; opacity: 0; transition: opacity .3s; }
.orb .core { filter: drop-shadow(0 0 calc(var(--glow) * 22px) var(--o)); transform-origin: 100px 100px; }
.orb .spin { transform-origin: 100px 100px; }
body[data-orb="offline"] .orb .ring { stroke-dasharray: 30 20; opacity: .3; }

@media (prefers-reduced-motion: no-preference) {
  .orb .core { animation: breathe 6s ease-in-out infinite; }
  .orb .r1 { animation: spin 90s linear infinite; }
  .orb .r2 { animation: spin 140s linear infinite reverse; }
  body[data-orb="running"] .orb .arc, body[data-orb="responding"] .orb .arc { animation: spin 1.6s linear infinite; }
  body[data-orb="running"] .orb .core { animation: breathe 2.2s ease-in-out infinite; }
  body[data-orb="responding"] .orb .core { animation: breathe 1.4s ease-in-out infinite; }
  body[data-orb="degraded"] .orb .r1 { animation-duration: 160s; }
  body[data-orb="offline"] .orb .core, body[data-orb="offline"] .orb .spin { animation: none; }
  .orb.tick .core { animation: tick .5s ease-out; }
  .orb.done .halo { animation: done 1.2s ease-out; }
}
body[data-orb="running"] .orb .sweep, body[data-orb="responding"] .orb .sweep { opacity: .9; }
body[data-orb="responding"] .orb { --glow: .8; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 0%, 100% { transform: scale(.965); } 50% { transform: scale(1); } }
@keyframes tick { 0% { transform: scale(1.03); } 100% { transform: scale(.98); } }
@keyframes done { 0% { opacity: .35; } 100% { opacity: calc(var(--glow) * .12); } }

/* ---------- разговор */
.conversation { max-width: 760px; margin: 0 auto; padding: 8px var(--gut) 24px; }
.turns { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.empty { color: var(--muted); text-align: center; margin: 12px 0; }
.turn { max-width: 100%; overflow-wrap: anywhere; }
.turn .meta { color: var(--muted); font-size: 12px; margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.turn.owner { align-self: flex-end; max-width: 86%; }
.turn.owner .body { background: var(--owner); border: 1px solid var(--line); padding: 10px 14px; border-radius: var(--radius) var(--radius) 4px var(--radius); white-space: pre-wrap; }
.turn.owner .meta { justify-content: flex-end; }
.turn.lex .body { font-size: 16.5px; line-height: 1.6; }
.turn.lex .body p { margin: 0 0 .7em; }
.turn.lex .body p:last-child { margin-bottom: 0; }
.turn.lex .body ul { margin: 0 0 .7em; padding-left: 1.2em; }
.turn.lex .body code { background: var(--bg-2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.turn.lex.streaming .body > :last-child::after, .turn.lex.streaming .body:empty::after { content: "▍"; color: var(--accent); margin-left: 2px; }
.turn.sched .meta::before { content: "по расписанию"; }
.fn {
  font: inherit; font-size: .72em; line-height: 1; color: var(--accent); background: none; border: 0; padding: 0 1px;
  cursor: pointer; vertical-align: baseline;
}
.fn:hover, .fn:focus-visible { text-decoration: underline; }
.foot { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.foot-title { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 4px; }
.foot ol { list-style: none; margin: 0 0 4px; padding: 0; display: grid; gap: 2px; }
.foot li { display: flex; gap: 8px; align-items: baseline; border-radius: 8px; padding: 2px 4px; transition: background-color .8s; }
.foot li.flash { background: rgba(95, 212, 255, .14); }
.foot-n { color: var(--accent); min-width: 1.2em; font-variant-numeric: tabular-nums; }
.ref {
  font: inherit; color: var(--muted); background: none; border: 0; padding: 4px 0; cursor: pointer; text-align: left;
  overflow-wrap: anywhere; min-height: 28px;
}
.ref:hover, .ref.open { color: var(--text); }
details.sources { margin-top: 8px; color: var(--muted); font-size: 13px; }
details.sources summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; }
details.sources li { overflow-wrap: anywhere; }
.card {
  margin-top: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg-2);
  font-size: 14px;
}
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.card .summary { white-space: pre-wrap; margin: 4px 0; }
.card .status { font-size: 13px; color: var(--warn); }
.note {
  align-self: stretch; border-left: 2px solid var(--off); padding: 6px 12px; color: var(--muted); font-size: 14px;
}
.note.err { border-color: var(--err); color: #ffd0d0; }
.note.run { border-color: var(--accent); color: var(--text); }
.note .actions { margin-top: 8px; display: flex; gap: 8px; }

/* ---------- ввод */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px var(--gut) calc(var(--safe-b) + 10px);
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  max-width: 792px; width: 100%; margin: 0 auto;
}
.composer textarea {
  flex: 1; resize: none; min-height: 48px; max-height: 38dvh; padding: 12px 14px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: inherit; font-size: 16px; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent-2); outline: none; box-shadow: 0 0 0 2px rgba(95, 212, 255, .2); }
.composer textarea:disabled { opacity: .5; }
.send, .stop {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--accent-2); background: #0d2133; cursor: pointer;
  display: grid; place-items: center; flex: none;
}
.send:disabled { opacity: .35; cursor: default; }
.stop { border-color: var(--line); }
/* Voice 2.0 шаг 3: режим разговора — кнопка рядом с орбом; включён — зелёная рамка */
.conv { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: transparent;
        font-size: 20px; line-height: 1; cursor: pointer; align-self: center; }
.conv[aria-pressed="true"] { border-color: #2f8f5b; background: rgba(47, 143, 91, .18); }
.stop svg { fill: currentColor; stroke: none; width: 18px; height: 18px; }

/* ---------- голос: орб у поля ввода — держи и говори */
.talk {
  width: 56px; height: 56px; flex: none; padding: 0; border: 0; background: transparent; cursor: pointer; border-radius: 50%;
  touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
.talk svg { width: 100%; height: 100%; overflow: visible; }
.talk:disabled { opacity: .35; cursor: default; }
body[data-voice="listening"] .talk, body[data-voice="cancel"] .talk, body[data-voice="starting"] .talk { transform: scale(1.35); transition: transform .15s ease-out; }
body[data-voice="listening"] .talk .core { filter: drop-shadow(0 0 18px var(--o)); }
body[data-voice="cancel"] .talk { --o: var(--off); --o2: #3a434e; }
@media (prefers-reduced-motion: no-preference) {
  body[data-voice="listening"] .talk .core { animation: listen 1s ease-in-out infinite; }
  body[data-voice="recognizing"] .talk .arc { animation: spin 1.2s linear infinite; }
}
body[data-voice="recognizing"] .talk .sweep { opacity: .9; }
@keyframes listen { 0%, 100% { transform: scale(.92); } 50% { transform: scale(1.04); } }
.listen {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; text-align: center; pointer-events: none;
  padding: 56px var(--gut) calc(var(--safe-b) + 110px);
  background: linear-gradient(to top, var(--bg) 72%, rgba(5, 8, 13, 0));
}
.composer { position: relative; z-index: 11; }
.status-line {
  margin: 0 auto; max-width: 792px; width: 100%; box-sizing: border-box; padding: 6px var(--gut) 0; font-size: 13px;
  color: var(--muted); text-align: center;
}
.listen-title { font-size: 22px; margin: 0 0 6px; }
.listen-hint { font-size: 13px; color: var(--muted); margin: 0; }
body[data-voice="listening"] .main, body[data-voice="cancel"] .main { opacity: .15; transition: opacity .2s; }
body[data-voice] .status-line { visibility: hidden; }
.turn .via { display: inline-flex; align-items: center; gap: 4px; }
.turn .via svg { width: 13px; height: 13px; }

/* ---------- история */
.history {
  position: fixed; inset: 0 auto 0 0; width: min(88vw, 340px); background: var(--bg-2); border-right: 1px solid var(--line);
  z-index: 20; padding: calc(var(--safe-t) + 8px) 0 var(--safe-b); display: flex; flex-direction: column;
}
.history-head { display: flex; align-items: center; gap: 8px; padding: 0 12px 8px 16px; }
.history-head h2 { flex: 1; font-size: 15px; margin: 0; font-weight: 600; }
.history-list { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; }
.history-list button {
  width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: 10px; padding: 10px;
  cursor: pointer; display: grid; gap: 2px; min-height: 52px;
}
.history-list button:hover, .history-list button[aria-current="true"] { background: #0f1823; border-color: var(--line); }
.history-list .h-top { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.history-list .h-prev { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.history-empty { color: var(--muted); padding: 12px; font-size: 14px; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 15; }

/* ---------- состояние */
.sheet {
  border: 1px solid var(--line); border-radius: 18px; background: var(--bg-2); color: var(--text);
  width: min(92vw, 420px); padding: 18px 18px 14px;
}
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
.sheet h2 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.sheet-headline { font-size: 18px; margin: 0 0 10px; }
.notes, .abilities { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.notes li { border-left: 2px solid var(--warn); padding-left: 10px; }
.abilities li { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 6px 0; }
.abilities .ok { color: var(--accent); }
.abilities .partial { color: var(--warn); }
.abilities .off { color: var(--off); }
.sheet-foot { color: var(--muted); font-size: 12px; }

/* ---------- desktop: история — постоянная колонка */
@media (min-width: 1024px) {
  :root { --gut: 24px; --orb: 280px; }
  body { grid-template-columns: 300px 1fr; grid-template-rows: auto 1fr auto auto; }
  .top { grid-column: 1 / -1; }
  .main { grid-column: 2; }
  .status-line { grid-column: 2; }
  .composer { grid-column: 2; }
  .listen { left: 300px; }
  .history { position: static; grid-column: 1; grid-row: 2 / span 3; width: auto; z-index: auto; padding-top: 0; display: flex !important; }
  .history[hidden] { display: flex !important; }
  #history-btn, #history-close, .scrim { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  .main { scroll-behavior: auto; }
  .stage, .orb { transition: none; }
}

/* ---------- привязка устройства */
body.pair { display: grid; place-items: center; grid-template-rows: 1fr; }
.pair-main { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 24px var(--gut); max-width: 420px; text-align: center; }
.pair-main .orb { width: 140px; }
.pair-main h1 { margin: 0; font-size: 15px; letter-spacing: .1em; text-transform: uppercase; }
.pair-main p { color: var(--muted); margin: 0; }
.pair-code { font: 600 34px/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .12em; color: var(--text) !important; }
.pair-btn { min-height: 48px; padding: 10px 20px; }

/* ---------- оценка ответа (R06) */
.rate { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.rate-row { display: flex; gap: 8px; flex-wrap: wrap; }
.rate-btn { min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line, #1a2533); background: transparent; color: var(--muted, #8f9cab); font-size: 13px; }
.rate-btn[aria-pressed="true"] { color: var(--text); border-color: var(--accent); background: rgba(95, 212, 255, .08); }
.rate-btn.wrong[aria-pressed="true"] { border-color: var(--warn); background: rgba(242, 189, 92, .08); }
.rate-btn:disabled { opacity: .5; }
.rate-note { margin: 0; font-size: 13px; color: var(--muted, #8f9cab); }
.rate-why { display: flex; gap: 8px; }
.rate-why input { flex: 1; min-width: 0; min-height: 40px; box-sizing: border-box; border-radius: 20px; border: 1px solid var(--line, #1a2533); background: transparent; color: var(--text); padding: 0 14px; font-size: 16px; }
.rate-why button { min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--accent); background: transparent; color: var(--text); font-size: 14px; }

/* ---------- лента уведомлений (S6′ 6.5) */
.bell { position: relative; }
.bell svg { width: 22px; height: 22px; }
.badge { position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--bg); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.feed { width: min(96vw, 560px); max-height: min(86vh, 900px); display: none; }
.feed[open] { display: flex; flex-direction: column; }
.feed-head { display: flex; align-items: center; justify-content: space-between; }
.feed-head form { margin: 0; }
.feed-list { list-style: none; margin: 0 0 10px; padding: 0; overflow-y: auto; display: grid; gap: 10px; }
.feed-empty { color: var(--muted); }
.note-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--bg); }
.note-card[data-display="pending"] { border-color: var(--accent-2); }
.note-card[data-display="superseded"], .note-card[data-display="expired"], .note-card[data-display="acknowledged"] { opacity: .62; }
.note-meta { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.note-kind { color: var(--text); font-weight: 600; }
.note-chip { margin-left: auto; border: 1px solid var(--line); border-radius: 8px; padding: 1px 7px; }
.note-card[data-display="pending"] .note-chip { color: var(--accent); border-color: var(--accent-2); }
.note-card[data-display="expired"] .note-chip, .note-card[data-display="superseded"] .note-chip { color: var(--warn); }
.note-title { margin: 6px 0 4px; font-weight: 600; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: 14px; max-height: 40vh; overflow-y: auto; }
.note-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.note-actions .text-btn { min-height: 36px; padding: 6px 12px; }

/* ---------- «Сейчас» (S5′): что требует решения — отдельно от ленты уведомлений */
.now-btn { position: relative; }
.now-btn svg { width: 22px; height: 22px; }
.badge.urgent { background: var(--warn); }
@media (max-width: 430px) { .top .icon-btn { width: 36px; } }
.now { width: min(96vw, 600px); max-height: min(90vh, 960px); display: none; }
.now[open] { display: flex; flex-direction: column; }
.now-lead { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.now-sources { list-style: none; margin: 4px 0 0; padding: 0; font-size: 12px; color: var(--muted); display: grid; gap: 2px; }
.att-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--bg); }
.att-card[data-urgency="high"] { border-color: var(--warn); }
.att-urg { margin-left: auto; border-radius: 8px; padding: 1px 7px; border: 1px solid var(--line); }
.att-card[data-urgency="high"] .att-urg { color: var(--warn); border-color: var(--warn); }
.att-why { margin: 4px 0; font-size: 14px; }
.att-basis { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.att-unc { margin: 6px 0; padding-left: 10px; border-left: 2px solid var(--warn); font-size: 12px; color: var(--warn); list-style: none; }
.att-ev { margin: 6px 0; font-size: 13px; }
.att-ev summary { cursor: pointer; color: var(--muted); }
.att-ev li { margin: 4px 0; overflow-wrap: anywhere; }
.att-ev .src { color: var(--muted); font-size: 12px; }
.att-note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.att-msg { font-size: 13px; margin: 6px 0 0; color: var(--warn); }
.att-answer { display: grid; gap: 6px; margin-top: 8px; }
.att-answer textarea { width: 100%; min-height: 70px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2);
  color: var(--text); padding: 8px; font: inherit; }
.att-seg { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.att-seg .text-btn { min-height: 34px; padding: 4px 12px; }
.kn-group { margin: 0 0 12px; }
.kn-group h3 { margin: 10px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kn-group h3 .text-btn { min-height: 30px; padding: 2px 10px; font-size: 12px; }
.kn-badge { border-radius: 8px; padding: 1px 7px; border: 1px solid var(--line); font-size: 11px; }
.kn-badge[data-n="conflict"] { color: var(--warn); border-color: var(--warn); }
.kn-badge[data-n="change"] { color: var(--accent); border-color: var(--accent); }
.kn-badge[data-s="high"] { color: var(--accent); border-color: var(--accent); }
.kn-reject { flex-wrap: wrap; }
.kn-overview { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.kn-topic { margin: 0 0 12px; }
.kn-topic-title { margin: 4px 0 6px; font-size: 16px; font-weight: 600; text-transform: none; letter-spacing: 0; color: inherit; }
.kn-statements { margin-top: 8px; }
.kn-statements > .att-card { background: var(--bg-2); }
.kn-more, .kn-bulk { margin-top: 6px; }
.kn-quote { margin: 4px 0; padding-left: 8px; border-left: 2px solid var(--line); font-size: 13px; overflow-wrap: anywhere; }
.kn-legacy { margin: 8px 0; }
.kn-other { grid-template-columns: 1fr auto; align-items: center; }
.kn-other input { min-width: 0; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2);
  color: inherit; font: inherit; padding: 6px 10px; }
.kn-legacy summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.att-proposal { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: 13px; margin: 6px 0;
  padding: 8px 10px; border: 1px dashed var(--accent-2); border-radius: 10px; background: var(--bg-2); }

/* WM3: исправления и переход к источнику */
.kn-corr { margin: 0 0 16px; }
.kn-corr h3 { font-size: 15px; margin: 8px 0 4px; }
.open-src { margin-left: 8px; font-size: 13px; }
.src-excerpt { margin: 6px 0 4px; max-width: 100%; overflow-x: auto; }
.src-excerpt pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; line-height: 1.45; margin: 0;
  padding: 8px 10px; border-radius: 8px; background: var(--surface-2, rgba(127,127,127,.08)); }
.src-line.hit { font-weight: 600; background: rgba(255, 200, 0, .18); }

/* ---------------------------------------------------------------- V1: визуальные ответы */
.view { margin: 10px 0 2px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg-2);
  max-width: 100%; box-sizing: border-box; overflow: hidden; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.view-title { font-size: 15px; margin: 0; }
.view-expanded .view-title { font-size: 19px; }
.view-narrative { color: var(--muted); margin: 6px 0; font-size: 14px; }
.view-loading { color: var(--muted); font-size: 14px; margin: 4px 0; }
.view-error { color: #ffb4a8; font-size: 14px; margin: 4px 0; }
.view-warn { color: #f2b84b; font-size: 13px; margin: 6px 0; }
.view-prov { color: var(--muted); font-size: 12px; margin: 6px 0 0; overflow-wrap: anywhere; }
.view-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin: 8px 0; }
.view-f { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.view-f select, .dtable-search { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; font: inherit; font-size: 14px; min-height: 36px; max-width: 100%; }
.view-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.view-comp { min-width: 0; }
.view-comp-title { font-size: 14px; margin: 4px 0; }
.view-alt summary { color: var(--muted); font-size: 13px; cursor: pointer; margin-top: 6px; }
.view-alt-text { white-space: pre-wrap; font-size: 13px; margin: 6px 0 0; font-family: inherit; }
.chart { margin: 0; }
.chart-svg, .diagram-svg { width: 100%; height: auto; display: block; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .tick { fill: var(--muted); font-size: 11px; }
.chart-svg .pt, .chart-svg .bar { cursor: pointer; }
.chart-svg .pt:focus, .chart-svg .bar:focus { outline: none; stroke: #fff; stroke-width: 2; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; padding: 0; margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.chart-point { font-size: 13px; margin: 4px 0 0; }
.dtable-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.dtable-count { color: var(--muted); font-size: 12px; }
.dtable-scroll { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.dtable table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.dtable th, .dtable td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.dtable td.t-number { text-align: right; white-space: nowrap; }
.dtable td.t-date, .dtable td.t-status { white-space: nowrap; }
@media (max-width: 600px) {
  .dtable .c-extra { display: none; }
  .dtable td.c-main { min-width: 8em; }
  .dtable-count[data-hidden]::after { content: " " attr(data-hidden); }
}
@media (max-width: 360px) {
  .dtable th, .dtable td { padding: 6px 4px; }
  .dtable td.c-main { min-width: 7em; }
}
.th-btn, .row-btn { background: none; border: 0; color: inherit; font: inherit; padding: 0; cursor: pointer; text-align: left; }
.th-btn { color: var(--muted); font-weight: 600; }
.row-btn { color: var(--text); text-decoration: underline dotted; }
.row-detail dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 4px 0; font-size: 13px; }
.row-detail dt { color: var(--muted); }
.row-detail dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.tl-item { position: relative; padding: 0 0 12px 14px; }
.tl-item::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.tl-old::before { background: var(--muted); }
.tl-old .tl-text { color: var(--muted); }
.tl-date { font-size: 12px; color: var(--muted); }
.tl-meta { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0; }
.tl-text { margin: 2px 0; font-size: 14px; }
.tl-src { color: var(--muted); font-size: 12px; margin: 2px 0; overflow-wrap: anywhere; }
.vcards { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.diagram-svg .edge { stroke: var(--accent-2); stroke-width: 1.5; }
.diagram-svg .edge-guess { stroke: var(--muted); stroke-dasharray: 5 4; }
.diagram-svg .node circle { fill: var(--bg); stroke: var(--accent); stroke-width: 2; }
.diagram-svg .node-person circle { stroke: #f2b84b; }
.diagram-svg .node-old circle { stroke: var(--muted); }
.diagram-svg text { fill: var(--text); font-size: 11px; }
.diagram-list { font-size: 13px; margin: 6px 0 0; padding-left: 18px; }
.diagram-list .guess { color: var(--muted); }
.view-full { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; padding: 0; border: 0; background: var(--bg);
  color: var(--text); box-sizing: border-box; }
.view-full::backdrop { background: rgba(0, 0, 0, .6); }
.view-full-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line); }
.view-full-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.view-full-body { padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); max-width: 1200px; margin: 0 auto; box-sizing: border-box; }
.view-full #view-msg { margin: 8px 16px 0; }
.view-chip { display: flex; align-items: center; gap: 8px; margin: 0 16px 6px; padding: 6px 10px; border: 1px solid var(--accent-2);
  border-radius: 10px; font-size: 13px; background: var(--bg-2); }
.view-chip[hidden] { display: none; }
.view-chip-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.mode-switch { display: flex; gap: 0; margin: 0 16px 6px; border: 1px solid var(--line); border-radius: 999px; width: max-content; overflow: hidden; }
.mode-switch[hidden] { display: none; }
.mode-switch button { background: none; border: 0; color: var(--muted); padding: 6px 16px; min-height: 36px; font: inherit; font-size: 14px; cursor: pointer; }
.mode-switch button[aria-pressed="true"] { background: var(--accent-2); color: #fff; }
body[data-mode="work"] .composer { box-shadow: 0 0 0 1px var(--accent-2); border-radius: 16px; }
.to-work { margin-top: 6px; font-size: 13px; min-height: 34px; padding: 4px 10px; }
.work-area { display: grid; gap: 10px; margin: 0 0 10px; }
.work-area:empty { display: none; }
.work-card { padding: 12px; border: 1px solid var(--accent-2); border-radius: 14px; background: var(--bg-2); }
.work-steps { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.work-step { border-left: 2px solid var(--line); padding-left: 10px; }
.work-step.st-running { border-left-color: var(--accent); }
.work-step-n { font-size: 13px; margin-right: 6px; }
.work-outcome { font-size: 13px; margin: 4px 0; white-space: pre-wrap; }
.work-question { color: #f2b84b; font-size: 14px; }
@media (max-width: 480px) {
  .view { padding: 10px; }
  .view-full-body { padding: 10px 12px calc(24px + env(safe-area-inset-bottom)); }
}

/* стабилизация 10.10.2026: узкий экран (iPhone SE 1-го поколения, 320 px; масштаб «Крупнее» на 375) — поле ввода
   сжимается (у textarea своя ширина по cols, без min-width: 0 кнопка отправки уходила за край), в шапке у плашки
   состояния остаётся точка, подпись — для экранного диктора */
.composer textarea { min-width: 0; }
.composer > button { flex-shrink: 0; }
@media (max-width: 360px) {
  .top { gap: 2px; }
  .top .icon-btn { width: 32px; }
  .state-pill #state-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .state-pill { padding-left: 8px; padding-right: 8px; }
  .empty { overflow-wrap: anywhere; }
}
/* кнопки сортировки в заголовке таблицы были 20 px — по ним трудно попасть пальцем (стабилизация 10.10.2026) */
.dtable .th-btn, .dtable .row-btn { min-height: 36px; padding-top: 6px; padding-bottom: 6px; }

/* Deep Drafting 1.0 — карточка подготовки ответа */
.draft-card h4 { margin: 12px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.draft-items { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.draft-item .att-basis { margin: 2px 0 0; }
.draft-item.st-answered .kn-badge { border-color: var(--accent-2); }
.draft-item.st-owner_decision .kn-badge, .draft-item.st-unresolved .kn-badge { border-color: #e0b04a; }
.draft-ready.r-ready { border-color: var(--accent-2); color: var(--accent-2); }
.draft-ready.r-needs_input, .draft-ready.r-insufficient_data { border-color: #e0b04a; color: #e0b04a; }
.draft-body { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 6px 0; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); }
.draft-why { margin: 0; padding-left: 18px; color: var(--muted); }
.draft-input { display: grid; gap: 8px; margin-top: 10px; }
.draft-input label { display: grid; gap: 4px; }
.draft-input input { min-height: 40px; min-width: 0; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2);
  color: inherit; font: inherit; font-size: 16px; padding: 6px 10px; }
.draft-facts ul { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 6px; }
.draft-facts .fact-no { opacity: .75; }
.draft-card button { min-height: 36px; }

/* 10.10.2026, снимок владельца с iPhone: в шапке не помещались иконки, плашка состояния уезжала за край.
   До 1023 px состояние — в меню за левой кнопкой (над разговорами), на самой кнопке — точка цвета состояния. */
.state-menu { display: none; }
@media (max-width: 1023px) {
  .top .state-pill { display: none; }
  .state-menu { display: inline-flex; align-self: flex-start; margin: 0 16px 10px; }
  #history-btn { position: relative; }
  #history-btn::after { content: ""; position: absolute; top: 7px; right: 3px; width: 8px; height: 8px; border-radius: 50%;
    background: var(--off); }
  body[data-lex="ready"] #history-btn::after { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
  body[data-lex="degraded"] #history-btn::after { background: var(--warn); }
  body[data-lex="unavailable"] #history-btn::after, body[data-lex="offline"] #history-btn::after {
    background: transparent; border: 1.5px solid var(--off); }
}
@media (max-width: 360px) {
  /* 320 px со всеми иконками приложения «Домой» (обновить, голос, знания, панели): 38-пиксельные обновить/голос и
     поля 16 px давали шапку 335 px — горизонтальная прокрутка всей страницы */
  #reload-btn, #voice-link { width: 32px; }
  .top { padding-left: 10px; padding-right: 10px; }
}

.draft-eval select { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: inherit;
  font: inherit; font-size: 16px; padding: 4px 8px; }

/* Owner-requested D38 raster preview; no automatic animation. */
.note-media { margin: 12px 0 0; max-width: 100%; }
.note-media img, .note-media canvas { display: block; max-width: 100%; height: auto; border-radius: 8px; }
.note-media figcaption { font-size: 12px; overflow-wrap: anywhere; opacity: .7; }

/* D38: upload controls stay on their own compact row, hidden when feature is off. */
.composer { flex-wrap: wrap; }
.incoming-row { flex: 0 0 100%; min-width: 0; display: flex; align-items: center; gap: 8px; }
.incoming-row[hidden] { display: none; }
#incoming-list { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; font-size: 12px; }
.incoming-chip { max-width: 260px; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 10px; padding: 4px 6px; }
.incoming-chip button { margin-left: 6px; color: var(--text); background: transparent; border: 0; }
