/* Раскладка: сверху сустав и протокол, слева бланк по отделам, справа липкая колонка с описанием и заключением */
:root {
  --bg: #F2F6F7; --paper: #F7FAFA; --surface: #FFFFFF; --ink: #172D34; --ink2: #52666E; --line: #D5E0E3;
  --accent: #0B6670; --accent-ink: #FFFFFF; --accent-weak: #E1EFEF;
  --dev: #9A4B00; --dev-ink: #FFFFFF; --dev-bg: #FBEBD3;
  --na: #5C6B70; --na-ink: #FFFFFF; --ok: #1F6B3A;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
/* Тёмная тема включается только кнопкой. Системная настройка не используется:
   приложение стартует светлым, чтобы бланк на экране совпадал с листом на печати. */
:root[data-theme="dark"] {
  --bg: #0E1517; --paper: #121C1F; --surface: #172226; --ink: #E4EEEF; --ink2: #9CAFB4; --line: #2A3A3F;
  --accent: #4DB6BF; --accent-ink: #06191B; --accent-weak: #143035;
  --dev: #E2A94B; --dev-ink: #1E1608; --dev-bg: #2D2412;
  --na: #9CAFB4; --na-ink: #0E1517; --ok: #6CC38A; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 15px; line-height: 1.5; padding-inline: 16px; padding-block: 20px 40px; }
h1, h2, p { margin: 0; }
.wrap { max-width: 1280px; margin-inline: auto; display: flex; flex-direction: column; gap: 16px; }

.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.brand { min-width: 0; max-width: 100%; }
.brand h1 { font-size: 21px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.35; text-wrap: balance; }
.brand p { color: var(--ink2); font-size: 13px; }
/* Меню суставов переносится по кнопкам, а не вылезает за край: раньше строка
   фиксированной ширины давала горизонтальную прокрутку всей странице. */
.joints { display: flex; flex: 1 1 100%; flex-wrap: wrap; gap: 0 2px; border-bottom: 1px solid var(--line); min-width: 0; max-width: 100%; }
.joints button { font: inherit; font-weight: 500; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 13px; color: var(--ink2); cursor: pointer; margin-bottom: -1px; }

@media (max-width: 1120px) {
  .joints { flex: 1 1 100%; }
}
@media (max-width: 560px) {
  .top { gap: 10px; }
  .brand h1 { font-size: 18px; }
  .brand p { font-size: 12px; }
  .joints button { padding: 7px 10px; font-size: 14px; }
}
.joints button:hover { color: var(--ink); }
.joints button[aria-current="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.protos { display: flex; flex-wrap: wrap; gap: 6px; }
.protos button { font: inherit; font-size: 13px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.protos button:hover { border-color: var(--accent); }
.protos button[aria-current="true"] { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 500; }

.note { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; font-size: 13px; }
.note.example { background: var(--dev-bg); }
.note b { font-weight: 600; }
.note .acts { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-out.stale #ai-text { opacity: 0.55; }

.btn { font: inherit; font-size: 13px; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 8px 13px; min-height: 38px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn.danger { border-color: var(--dev); color: var(--dev); }
.back-top { position: fixed; right: max(20px, env(safe-area-inset-right, 0px)); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 60; min-height: 44px; padding: 10px 16px; border-radius: 24px; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 16px rgb(0 0 0 / 18%); }
.back-top:hover { filter: brightness(1.08); }
:is(.btn, .protos button, .joints button, .chip, .clr):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 470px); gap: 20px; align-items: start; }
.form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.sec { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px 20px 8px; min-width: 0; box-shadow: 0 2px 8px rgb(16 48 58 / 3%); }
.sec-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; padding-block: 14px 4px; }
.sec-h h2 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink2); }
.sec-meta { font-size: 13px; color: var(--ink2); padding-bottom: 6px; }
.exam { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.exam input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.sec.off .sec-body { display: none; }
.sec-off { font-size: 13px; color: var(--ink2); padding-block: 4px 10px; }

.f { padding-block: 14px; border-top: 1px solid var(--line); min-width: 0; }
.sec-body > .f:first-child { border-top: 0; }
.fl { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 8px; }
.fl .lb { font-weight: 500; }
.fl .ax { font-size: 12px; color: var(--ink2); }
.fl .req { font-size: 12px; color: var(--dev); }
.clr { font: inherit; font-size: 12px; color: var(--ink2); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; margin-left: auto; }
.f-hint { font-size: 12px; color: var(--ink2); margin: -2px 0 8px; max-width: 70ch; }

.segs { display: flex; flex-wrap: wrap; gap: 6px; }
.seg { position: relative; display: inline-flex; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); font-size: 14px; }
.seg:hover span { border-color: var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg[data-k="n"] input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg[data-k="d"] input:checked + span { background: var(--dev); border-color: var(--dev); color: var(--dev-ink); }
.seg[data-k="a"] input:checked + span { background: var(--na); border-color: var(--na); color: var(--na-ink); }

.extras { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 10px; padding: 10px 12px; background: var(--paper); border: 1px dashed var(--line); border-radius: 6px; }
.sub { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink2); min-width: 0; max-width: 100%; }
.sub .row { display: flex; align-items: center; gap: 6px; }
.sub input, .sub select, textarea, .solo input { font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; }
input.num { width: 90px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
input.txt { width: 280px; max-width: 100%; }
.sub select { max-width: 100%; }
.solo { display: flex; align-items: center; gap: 6px; }
:is(input, select, textarea):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.u { font-size: 13px; color: var(--ink2); }
textarea { width: 100%; min-height: 96px; resize: vertical; line-height: 1.5; }

.panel { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 32px); overflow: auto; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; min-width: 0; box-shadow: 0 2px 8px rgb(16 48 58 / 3%); }
.card h2 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink2); margin-bottom: 8px; }
.prog { display: flex; align-items: center; gap: 10px; font-weight: 500; font-variant-numeric: tabular-nums; }
.bar { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.2s; }
.miss { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font: inherit; font-size: 12px; background: var(--dev-bg); color: var(--ink); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; cursor: pointer; }
.chip.soft { background: var(--paper); }
.sub-h { font-size: 12px; color: var(--ink2); margin-top: 12px; }
.blanks-wrap .miss { margin-top: 6px; }
.done { color: var(--ok); font-size: 13px; margin-top: 8px; }
pre.desc { margin: 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 12px; color: var(--ink); }
.hint { font-size: 12px; color: var(--ink2); margin-top: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.actions.first { margin-top: 0; }
.status { font-size: 12px; color: var(--ok); min-height: 18px; margin-top: 6px; }
.foot { font-size: 12px; color: var(--ink2); }
.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--dev); } to { box-shadow: 0 0 0 3px transparent; } }

.print-sheet { display: none; }

@media (max-width: 960px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .panel { position: static; max-height: none; overflow: visible; }
  .sec { padding-inline: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .bar i { transition: none; }
  .flash { animation: none; }
}


/* ---------- голосовой режим ---------- */
.voice-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
body.voice-on { padding-bottom: 240px; }
.vcur { box-shadow: 0 0 0 3px var(--accent); border-radius: 6px; background: var(--accent-weak); }
.f.vcur { margin-inline: -10px; padding-inline: 10px; }
.sec.vcur { background: var(--surface); }
.vbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 420px); gap: 12px 24px;
  background: var(--surface); border-top: 2px solid var(--accent); box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.12);
  padding: 14px max(16px, env(safe-area-inset-right, 0px)) calc(14px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.v-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.v-state { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink2); }
.v-state i { width: 10px; height: 10px; border-radius: 50%; background: var(--na); }
.vbar[data-state="listen"] .v-state i { background: #D23B2E; animation: vpulse 1.4s ease-in-out infinite; }
.vbar[data-state="speak"] .v-state i { background: var(--accent); }
.vbar[data-state="pause"] .v-state i { background: var(--dev); }
@keyframes vpulse { 50% { box-shadow: 0 0 0 6px rgba(210, 59, 46, 0.2); } }
.v-prompt { font-size: 22px; font-weight: 600; line-height: 1.25; text-wrap: balance; }
.v-opts { font-size: 14px; color: var(--ink2); }
.v-heard { font-family: var(--mono); font-size: 13px; color: var(--ink); min-height: 1.4em; overflow-wrap: anywhere; }
.v-feedback { font-size: 13px; color: var(--ok); min-height: 1.4em; }
.v-feedback.warn { color: var(--dev); }
.v-side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.v-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.v-check { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.v-check input { accent-color: var(--accent); margin: 0; }
.v-help summary { font-size: 13px; cursor: pointer; color: var(--accent); }
.v-help p { font-size: 12px; color: var(--ink2); margin-top: 4px; }
.vbar[data-mode="dictate"] { border-top-color: var(--dev); }
.vbar[data-mode="dictate"] .v-prompt { color: var(--dev); }
#concl { min-height: 120px; }
.v-priv { font-size: 12px; color: var(--ink2); }
@media (max-width: 760px) { .vbar { grid-template-columns: minmax(0, 1fr); } body.voice-on { padding-bottom: 360px; } .v-prompt { font-size: 18px; } }
@media (prefers-reduced-motion: reduce) { .vbar[data-state="listen"] .v-state i { animation: none; } }


/* ---------- помощник ИИ ---------- */
.card.ai h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ai-badge { font-size: 10px; font-weight: 600; letter-spacing: 0.05em; text-transform: none; color: var(--accent); background: var(--accent-weak); border-radius: 999px; padding: 1px 8px; }
.ai-badge.off { color: var(--ink2); background: var(--paper); border: 1px solid var(--line); }
.card.ai { border-left: 3px solid var(--accent); }
#ai-text { min-height: 84px; font-size: 14px; }
#ai-text:disabled { opacity: 0.7; }
.ai-out { margin-top: 12px; }
.ai-out .sub-h { margin-top: 0; }
.ai-note { font-size: 14px; line-height: 1.65; color: var(--ink2); margin-top: 10px; overflow-wrap: anywhere; }
#ai-finding-text { font-family: var(--sans); font-size: 15px; line-height: 1.7; margin-top: 8px; border-color: transparent; background: var(--accent-weak); }
#ai-additional-list { padding-left: 20px; font-size: 14px; line-height: 1.65; }
#ai-additional-list li + li { margin-top: 14px; }
#ai-additional-list .btn { display: block; margin-top: 8px; }

@media (max-width: 560px) {
  body { padding-inline: 12px; }
  .joints { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; padding-bottom: 3px; }
  .joints button { flex: 0 0 auto; min-height: 44px; }
  .btn, .protos button { min-height: 44px; }
  .seg span { min-height: 44px; display: inline-flex; align-items: center; }
  .sub input, .sub select, textarea, .solo input { min-height: 44px; font-size: 16px; }
  .note { padding: 12px; gap: 12px; }
  .note .acts { width: 100%; }
  .note .acts .btn { flex: 1 1 auto; }
  .card { padding: 16px; }
}
.ai-meta { font-size: 11.5px; color: var(--ink2); margin-top: 6px; font-variant-numeric: tabular-nums; }
.ai-gate { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; padding: 8px 10px; border: 1px dashed var(--line); border-radius: 6px; background: var(--paper); }
.ai-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.ai-check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.hint.warn { color: var(--dev); }
.status.warn { color: var(--dev); }
.ai-set { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.ai-set summary { font-size: 13px; cursor: pointer; color: var(--accent); }
.ai-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.ai-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 12px; color: var(--ink2); }
.ai-row input, .ai-row select { font: inherit; font-size: 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; flex: 1 1 160px; min-width: 0; }
.ai-row input[type="number"] { flex: 0 0 90px; }
.ai-consent { margin-top: 10px; }
.ai-set .status { color: var(--ok); }
.ai-set .status.warn { color: var(--dev); }
.ai-set .hint { max-width: 60ch; }
.ai-log-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 200px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.ai-log-list:empty { display: none; }
.ai-log-i { font-size: 11.5px; line-height: 1.45; color: var(--ink2); padding: 6px 10px; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.ai-log-i:first-child { border-top: 0; }
.ai-log-i.ins { color: var(--ink); }
.ai-log-i.ins::before { content: "✓ "; color: var(--ok); }


/* ---------- мой голос ---------- */
#btn-studio[aria-pressed="true"] { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); }
.studio { background: var(--surface); border: 1px solid var(--accent); border-radius: 8px; padding: 14px 18px; display: flex; flex-direction: column; gap: 12px; }
.studio.recording { border-color: #D23B2E; box-shadow: 0 0 0 2px rgba(210, 59, 46, 0.25); }
.st-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.st-head h2 { font-size: 16px; font-weight: 600; margin-right: auto; }
.st-scope { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink2); }
.st-scope select { font: inherit; font-size: 13px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); }
.st-prog { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 220px; font-variant-numeric: tabular-nums; }
.st-prog .bar { flex: 1; min-width: 80px; }
.st-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 340px); gap: 18px; }
.st-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.st-group { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink2); }
.st-phrase { font-size: 26px; font-weight: 600; line-height: 1.25; text-wrap: balance; min-height: 1.3em; }
.st-meter { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.st-meter i { display: block; height: 100%; width: 0; background: var(--ok); }
.st-btns { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.st-rec.on { background: #D23B2E; border-color: #D23B2E; color: #fff; }
.st-pos { font-size: 13px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.st-msg { font-size: 13px; color: var(--ok); min-height: 1.4em; }
.st-msg.warn { color: var(--dev); }
.st-tip { font-size: 12px; color: var(--ink2); max-width: 70ch; }
.st-list { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); min-width: 0; }
.st-g { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink2); padding: 8px 10px 4px; }
.st-i { display: flex; align-items: flex-start; gap: 8px; padding: 0 10px; }
.st-i i { flex: none; margin-top: 10px; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--na); }
.st-i.done i { background: var(--ok); border-color: var(--ok); }
.st-i.local i { background: var(--dev); border-color: var(--dev); }
.st-storage { font-size: 12px; color: var(--ok); max-width: 70ch; }
.st-storage.warn { color: var(--dev); }
.st-i button { font: inherit; font-size: 13px; text-align: left; background: none; border: 0; color: var(--ink); padding: 4px 0; cursor: pointer; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.st-i.cur { background: var(--accent-weak); }
.st-i.cur button { color: var(--accent); font-weight: 500; }
@media (max-width: 860px) { .st-body { grid-template-columns: minmax(0, 1fr); } .st-phrase { font-size: 20px; } }

/* настройки голоса в панели режима */
.v-voice { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.v-voice label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.v-voice select { font: inherit; font-size: 12px; max-width: 100%; min-width: 0; flex: 1; padding: 3px 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); }
.v-voice input[type="range"] { flex: 1; accent-color: var(--accent); }
.v-voice input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
.v-mine { font-size: 12px; color: var(--ink2); }
.linkish { font: inherit; font-size: 12px; background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }

@media print {
  .back-top { display: none !important; }
  .vbar, .studio { display: none !important; }
  @page { margin: 18mm 16mm; }
  body { background: #fff; color: #000; padding: 0; }
  .wrap { display: none; }
  .print-sheet { display: block; font-family: var(--sans); font-size: 11.5pt; line-height: 1.45; color: #000; }
  .print-sheet pre { font-family: inherit; white-space: pre-wrap; margin: 0; }
  .print-sheet .p-concl { margin-top: 14pt; }
  .print-sheet .p-concl h3 { font-size: 11.5pt; margin: 0 0 4pt; }
  .print-sheet .p-sign { margin-top: 28pt; display: flex; justify-content: space-between; gap: 24pt; }
  .print-sheet .p-foot { margin-top: 18pt; font-size: 9pt; color: #444; }
}
