/* Nutrisoft — рабочее место нутрициолога.
   Язык оформления — лабораторный бланк: бумага, чернильный синий, статусы как в бланке анализов.
   Подпись интерфейса — полоса референса (.range): положение значения относительно нормы. Шрифты системные, ничего внешнего. */
:root {
  --paper: #f5f6f2; --panel: #ffffff; --ink: #172629; --ink-2: #47595d; --ink-3: #6f7f82;
  --line: #d6dcd5; --line-2: #e6eae4; --blue: #234a80; --blue-2: #1a3a66; --blue-soft: #e4ecf6;
  --low: #a35f00; --low-bg: #fbeed3; --high: #a3392a; --high-bg: #f8dcd5; --ok: #2c7048; --ok-bg: #dcefe2;
  --neutral: #55666a; --neutral-bg: #e8ece8; --focus: #2f6fd1; --shadow: 0 1px 2px rgb(23 38 41 / .06), 0 4px 14px rgb(23 38 41 / .05);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #12191b; --panel: #1a2326; --ink: #e6eeee; --ink-2: #a9bbbd; --ink-3: #82979a;
    --line: #2f3d40; --line-2: #263235; --blue: #7fa8e6; --blue-2: #a3c2f0; --blue-soft: #1d2f48;
    --low: #f0b45a; --low-bg: #3a2c12; --high: #f29a8b; --high-bg: #3d1f1a; --ok: #78c796; --ok-bg: #16301f;
    --neutral: #a9bbbd; --neutral-bg: #263235; --focus: #8bb4f2;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: .005em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
a { color: var(--blue); text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.num, td.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); } .small { font-size: .85rem; } .hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* каркас */
.topbar { display: flex; align-items: center; gap: 1.25rem; padding: .6rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; letter-spacing: .01em; }
.brand b { color: var(--blue); }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: var(--ink-2); text-decoration: none; padding: .25rem 0; border-bottom: 2px solid transparent; }
.topbar nav a[aria-current="page"] { color: var(--ink); border-color: var(--blue); }
.who { color: var(--ink-2); font-size: .9rem; }
.container { max-width: 1120px; margin: 0 auto; padding: 1.5rem 1.25rem 5rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.crumb { font-size: .9rem; margin-bottom: .35rem; display: inline-block; }
.meta { color: var(--ink-2); display: flex; gap: .5rem 1rem; flex-wrap: wrap; margin-top: .35rem; font-size: .9rem; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; overflow-x: auto; }
.tabs a { padding: .6rem 1rem; text-decoration: none; color: var(--ink-2); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink); border-color: var(--blue); font-weight: 600; }

/* карточки и формы */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.1rem; }
.card > h2, .card > h3 { margin-bottom: .75rem; }
.grid { display: grid; gap: .9rem 1.1rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field label, .label { font-size: .85rem; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: .8rem; color: var(--ink-3); }
.field .err, .err { color: var(--high); font-size: .85rem; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: .5rem .6rem; width: 100%; min-height: 38px; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
textarea { resize: vertical; min-height: 84px; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--blue); }
input.invalid, select.invalid { border-color: var(--high); background: var(--high-bg); }
.check { display: flex; align-items: center; gap: .5rem; font-size: .95rem; cursor: pointer; }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .4rem 1rem; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: .85rem; color: var(--ink-2); padding: 0; margin-bottom: .4rem; }
.actions select, .actions input { width: auto; flex: 0 1 260px; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }

.btn { font: inherit; font-weight: 600; border-radius: 6px; padding: .5rem 1rem; min-height: 38px; cursor: pointer; border: 1px solid transparent; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; }
.btn.primary { background: var(--blue); color: #fff; } .btn.primary:hover { background: var(--blue-2); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b1a2e; } }
.btn.secondary { background: var(--panel); color: var(--ink); border-color: var(--line); } .btn.secondary:hover { border-color: var(--ink-3); }
.btn.danger { background: var(--panel); color: var(--high); border-color: var(--high); } .btn.danger:hover { background: var(--high-bg); }
.btn.ghost { background: transparent; color: var(--blue); padding: .35rem .6rem; } .btn.ghost:hover { background: var(--blue-soft); }
.btn.sm { min-height: 30px; padding: .2rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; padding: .45rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .55rem .6rem; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr.link:hover { background: var(--blue-soft); cursor: pointer; }
td.num { text-align: right; white-space: nowrap; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--ink-2); }
.empty h3 { color: var(--ink); margin-bottom: .4rem; }

/* статусы */
.badge { max-width: 100%; display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--neutral-bg); color: var(--neutral); }
.badge.low, .badge.medium { background: var(--low-bg); color: var(--low); }
.badge.high, .badge.severe, .badge.extreme { background: var(--high-bg); color: var(--high); }
.badge.ok, .badge.normal { background: var(--ok-bg); color: var(--ok); }
.badge.mild, .badge.moderate { background: var(--low-bg); color: var(--low); }
.badge.warn { background: var(--low-bg); color: var(--low); }

/* полоса референса — подпись интерфейса */
.range { display: block; width: 168px; height: 22px; }
.range .track { stroke: var(--line); stroke-width: 2; stroke-linecap: round; }
.range .band { fill: var(--ok-bg); stroke: var(--ok); stroke-width: 1; }
.range .tick { stroke: var(--ink-3); stroke-width: 1; }
.range .dot { stroke: var(--panel); stroke-width: 2; }
.range .dot.ok { fill: var(--ok); } .range .dot.low { fill: var(--low); } .range .dot.high { fill: var(--high); } .range .dot.none { fill: var(--neutral); }
.vals { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .8rem; }
.val { border: 1px solid var(--line); border-radius: var(--r); padding: .7rem .85rem; background: var(--panel); display: flex; flex-direction: column; gap: .3rem; }
.val .name { font-size: .85rem; color: var(--ink-2); }
.val .big { font-family: var(--mono); font-size: 1.45rem; font-variant-numeric: tabular-nums; }
.val .big small { font-size: .8rem; color: var(--ink-3); margin-left: .2rem; }
.val .foot { display: flex; justify-content: space-between; align-items: center; gap: .3rem .6rem; flex-wrap: wrap; font-size: .8rem; color: var(--ink-3); }

/* ввод анализов */
.lab-row td { vertical-align: top; }
.lab-row input, .lab-row select { min-width: 0; }
.lab-row td.c-name { min-width: 200px; } .lab-row td.c-val { width: 96px; } .lab-row td.c-unit { width: 120px; } .lab-row td.c-ref { width: 84px; }
.lab-row td.c-marker { min-width: 220px; } .lab-row .stat { margin-top: .3rem; font-size: .8rem; }
.lab-row.bad { background: var(--high-bg); }
.issues { color: var(--low); font-size: .8rem; margin-top: .25rem; }

/* опросник */
details.sec { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); margin-bottom: .6rem; }
details.sec > summary { cursor: pointer; padding: .7rem 1rem; display: flex; justify-content: space-between; gap: 1rem; align-items: center; list-style: none; font-weight: 600; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary > span:first-child { flex: 1; }
details.sec > summary::before { content: "▸"; color: var(--ink-3); margin-right: -.5rem; transition: transform .12s; display: inline-block; }
details.sec[open] > summary::before { transform: rotate(90deg); }
details.sec .count { font-weight: 400; font-size: .85rem; color: var(--ink-2); }
details.sec .count.done { color: var(--ok); }
.sec-body { padding: .25rem 1rem 1rem; border-top: 1px solid var(--line-2); }
.scale { display: flex; gap: .4rem 1rem; flex-wrap: wrap; padding: .6rem 0; font-size: .85rem; color: var(--ink-2); }
.scale span b { font-family: var(--mono); color: var(--ink); margin-right: .25rem; }
.q { display: grid; grid-template-columns: 2.2rem 1fr auto; gap: .5rem .8rem; padding: .55rem 0; border-bottom: 1px solid var(--line-2); align-items: center; }
.q:last-child { border-bottom: 0; }
.q .n { color: var(--ink-3); font-family: var(--mono); font-size: .85rem; }
.q .opts { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: flex-end; }
.q .opts.own { flex-direction: column; align-items: stretch; justify-content: flex-start; grid-column: 2 / 4; }
.opt { position: relative; }
.opt input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
.opt span { display: inline-flex; min-width: 40px; height: 36px; padding: 0 .6rem; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 6px; font-family: var(--mono); background: var(--panel); }
.opt:hover span { border-color: var(--ink-3); }
.opt input:checked + span { background: var(--blue); border-color: var(--blue); color: #fff; }
@media (prefers-color-scheme: dark) { .opt input:checked + span { color: #0b1a2e; } }
.opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.opts.own .opt span { justify-content: flex-start; width: 100%; font-family: var(--sans); height: auto; min-height: 34px; padding: .3rem .7rem; }
.opts.own .opt b { font-family: var(--mono); margin-right: .5rem; }
.stickybar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: .6rem 1.25rem; display: flex; gap: 1rem; align-items: center; justify-content: space-between; z-index: 15; box-shadow: 0 -4px 14px rgb(23 38 41 / .06); }
.progress { flex: 1; max-width: 360px; height: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--blue); width: 0; transition: width .2s; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login .card { width: 100%; max-width: 380px; padding: 1.75rem; }
.login h1 { margin-bottom: .25rem; } .login h1 b { color: var(--blue); } .login .brand-line { color: var(--ink-2); margin-bottom: 1.25rem; }
.login .field { margin-bottom: .9rem; }

/* окна и уведомления */
dialog { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); color: var(--ink); padding: 1.25rem; max-width: 560px; width: calc(100% - 2rem); box-shadow: 0 12px 40px rgb(0 0 0 / .25); }
dialog::backdrop { background: rgb(10 20 22 / .5); }
dialog h3 { margin-bottom: .6rem; }
#toasts { position: fixed; right: 1rem; top: 4rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; max-width: min(420px, calc(100vw - 2rem)); }
.toast { background: var(--ink); color: var(--paper); padding: .6rem .9rem; border-radius: 6px; box-shadow: var(--shadow); }
.toast.error { background: var(--high); color: #fff; }
.alert { padding: .7rem .9rem; border-radius: 6px; border: 1px solid var(--line); background: var(--neutral-bg); margin-bottom: 1rem; }
.alert.error { background: var(--high-bg); border-color: var(--high); color: var(--high); }
.alert.warn { background: var(--low-bg); border-color: var(--low); color: var(--low); }
.alert ul { margin: .25rem 0 0 1.1rem; padding: 0; }
dl.kv { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: .45rem 1rem; margin: 0; }
dl.kv dt { color: var(--ink-2); } dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.tag { display: inline-block; background: var(--neutral-bg); border-radius: 4px; padding: 0 .4rem; margin: 0 .25rem .25rem 0; font-size: .85rem; }
@media (max-width: 640px) { .q { grid-template-columns: 1.8rem 1fr; } .q .opts { grid-column: 2; justify-content: flex-start; } dl.kv { grid-template-columns: 1fr; gap: 0; } dl.kv dd { margin-bottom: .5rem; } }
@media (max-width: 640px) {
  .topbar { padding: .5rem .8rem; gap: .75rem; } .who { display: none; }
  .container { padding: 1rem .8rem 5rem; } h1 { font-size: 1.4rem; }
}

/* протокол */
.steps { counter-reset: step; }
.issue { display: flex; gap: .6rem; padding: .35rem 0; align-items: baseline; }
.issue .badge { flex: none; }
.issues-box details { margin-top: .5rem; }
.edit-card { border: 1px solid var(--line-2); border-radius: var(--r); padding: .8rem .9rem; margin-bottom: .7rem; background: var(--paper); }
.edit-card .row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.edit-card .grid { margin-top: .4rem; }
fieldset[disabled] input, fieldset[disabled] select, fieldset[disabled] textarea { background: var(--neutral-bg); color: var(--ink-2); }
.suspect { border: 1px solid var(--low); background: var(--low-bg); border-radius: var(--r); padding: .7rem .9rem; margin-bottom: .6rem; }
.suspect q { font-weight: 600; } .suspect .ctx { font-family: var(--mono); font-size: .85rem; color: var(--ink-2); margin: .3rem 0; overflow-wrap: anywhere; }
.scrubbed { white-space: pre-wrap; background: var(--paper); border: 1px dashed var(--line); border-radius: 6px; padding: .5rem .7rem; font-size: .9rem; }
.verdict-ok { color: var(--ok); } .spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -.15em; margin-right: .4rem; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
