/* S31 · Страница врача: ожидание с QR и кодом → отчёт пациента. Токены — как в PDF-отчёте F26 и в приложении. */

@font-face { font-family: "Onest"; src: url("onest-regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Onest"; src: url("onest-semibold.ttf") format("truetype"); font-weight: 600; font-display: swap; }

:root {
  --bg: #ffffff;
  --text: #121212;
  --muted: #6b6b6b;
  --line: #e4e4e2;
  --surface: #f4f4f2;
  --accent: #121212;
  --accent-text: #ffffff;
  --green: #2f7429;
  --green-bg: #e7f0e5;
  --amber-bg: #fbefd3;
  --red-bg: #fbe3e1;
  --red-text: #b42a20;
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --text: #f2f2f0;
    --muted: #a3a3a0;
    --line: #2e2e2c;
    --surface: #1d1d1c;
    --accent: #f2f2f0;
    --accent-text: #111111;
    --green: #8fcf86;
    --green-bg: #1f2e1d;
    --amber-bg: #3a2f17;
    --red-bg: #3d1f1c;
    --red-text: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.45 "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.page { max-width: 980px; margin: 0 auto; padding: 0 20px 48px; }

/* region Шапка */

/* Липкий блок: строка шапки и под ней бейджи разделов отчёта (app.js переносит их сюда) — бейджи не уходят под шапку. */
.topbar {
  position: sticky; top: 0; z-index: 5;
  margin: 0 -20px 20px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 12px; padding: 14px 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 18px; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.session { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.timer strong { color: var(--text); font-weight: 600; }

button {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 0; border-radius: 999px; padding: 10px 18px;
  background: var(--surface); color: var(--text);
  transition: transform .1s ease, opacity .15s ease;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* endregion */

/* region Ожидание */

.waiting { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; align-items: start; padding-top: 12px; }
.waiting h1 { grid-column: 1 / -1; margin: 0; font-size: 30px; font-weight: 600; line-height: 1.2; }
.waiting .free { grid-column: 1 / -1; margin: -18px 0 0; color: var(--muted); }
.qr-card, .code-card { background: var(--surface); border-radius: var(--radius); padding: 24px; }
.qr { width: 100%; max-width: 320px; aspect-ratio: 1; margin: 0 auto 16px; background: #fff; border-radius: 12px; padding: 8px; }
.qr svg { width: 100%; height: 100%; display: block; }
.hint { margin: 0 0 6px; }
.code-card h2 { margin: 0 0 6px; font-size: 18px; }
.code-form { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.code-form input {
  font: 600 28px/1 "Onest", system-ui, sans-serif; letter-spacing: .28em; font-variant-numeric: tabular-nums;
  width: 10em; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
.message { margin: 12px 0 0; font-weight: 600; }
.message.error { color: var(--red-text); }

/* endregion */

/* region Состояния */

.notice { max-width: 560px; margin: 64px auto; text-align: center; }
.notice h1 { font-size: 26px; font-weight: 600; margin: 0 0 8px; }
.notice p { color: var(--muted); margin: 0 0 20px; }
.spinner { width: 28px; height: 28px; margin: 0 auto 16px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--text); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } button, .sections .chip { transition: none; } }
.banner { margin: 0 0 16px; padding: 10px 14px; border-radius: 12px; background: var(--amber-bg); font-weight: 600; }

/* endregion */

/* region Отчёт */

/* Бейджи разделов: вторая строка липкой шапки, на телефоне — прокрутка вбок. */
.sections {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 0 20px 12px;
}
.sections::-webkit-scrollbar { display: none; }
.sections .chip {
  flex: none; white-space: nowrap; text-decoration: none;
  padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--surface); color: var(--text);
  transition: background .15s ease, color .15s ease;
}
.sections .chip.active { background: var(--accent); color: var(--accent-text); }
.sections .chip:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
/* Высоту шапки вместе с бейджами задаёт app.js — `--topbar`. */
.report section { scroll-margin-top: calc(var(--topbar, 112px) + 16px); }

.report h1 { margin: 0; font-size: 26px; font-weight: 600; line-height: 1.2; }
.report h2 { margin: 32px 0 12px; font-size: 20px; font-weight: 600; }
.report h2.sub { font-size: 17px; margin-top: 24px; }
.report section > p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; }

.patient { display: flex; gap: 20px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.patient p { margin: 4px 0 0; }
.patient .download { margin-top: 12px; background: var(--bg); border: 1px solid var(--line); }
.patient-goal { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.label { color: var(--muted); font-size: 13px; }
.patient-goal .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric .value { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.15; }
.metric .note { color: var(--muted); font-size: 13px; }
.goal-days { margin-top: 10px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--green-bg); }
.goal-days strong { color: var(--green); font-size: 20px; }

.chart { background: var(--surface); border-radius: var(--radius); padding: 12px 12px 4px; overflow: hidden; }
.chart svg { width: 100%; height: auto; display: block; }
.chart-title { margin: 18px 0 8px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart .count { fill: var(--text); font-size: 9px; font-weight: 600; font-family: inherit; }
.chart .goal { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .avg-sys, .chart .point { fill: var(--text); }
.chart .avg-dia { fill: var(--bg); stroke: var(--text); stroke-width: .8; }
.chart .line { fill: none; stroke: var(--text); stroke-width: 1.6; stroke-linejoin: round; }

.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 0; margin: 12px 0 4px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.status-normal { background: #dadad8; box-shadow: inset 0 0 0 1px #b5b5b2; }
.status-elevated { background: #f5c86a; }
.status-high { background: #ff6257; }
.status-crisis { background: #ff3b30; }
.status-low { background: #7db4ee; }
.cal-taken { background: var(--green-bg); }
.cal-partial { background: var(--amber-bg); }
.cal-skipped { background: var(--red-bg); }
.cal-none { background: var(--bg); box-shadow: inset 0 0 0 1px var(--line); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot.filled { background: var(--text); }
.dot.hollow { box-shadow: inset 0 0 0 1.5px var(--text); }
.dash { display: inline-block; width: 14px; border-top: 1.5px dashed var(--muted); }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; background: var(--surface); }
th:first-child { border-radius: 10px 0 0 10px; }
th:last-child { border-radius: 0 10px 10px 0; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.status { white-space: nowrap; }
td.status .swatch { margin-right: 6px; vertical-align: -1px; border-radius: 50%; }
td.notes { color: var(--muted); }
tr:not(.day-start) td.date { color: transparent; }
td.skipped strong { color: var(--red-text); }

.meds { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.meds li { display: flex; flex-direction: column; gap: 4px; }
.meds strong { font-size: 16px; }

.calendars { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.calendar .weekdays, .calendar .days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.calendar .weekdays span { text-align: center; font-size: 11px; color: var(--muted); }
.calendar .days > span { min-height: 42px; border-radius: 8px; padding: 3px 4px; display: flex; flex-direction: column; font-size: 12px; }
.calendar .days .n { color: var(--muted); font-size: 11px; }
.calendar .days strong { align-self: center; font-size: 13px; }
.calendar .taken { background: var(--green-bg); }
.calendar .partial { background: var(--amber-bg); }
.calendar .skipped { background: var(--red-bg); }
.calendar .skipped strong { color: var(--red-text); }
.calendar .none { background: var(--bg); }
.calendar .out .n { opacity: .4; }

.disclaimer { margin-top: 32px; padding: 14px 16px; border-radius: 12px; background: var(--surface); color: var(--muted); font-size: 12.5px; }

/* endregion */

/* region Узкий экран: таблицы — карточками */

@media (max-width: 720px) {
  .page { padding: 0 16px 40px; }
  .topbar { margin: 0 -16px 16px; }
  .topbar-row { padding: 12px 16px; flex-wrap: wrap; }
  .sections { padding: 0 16px 10px; }
  /* Таймер строкой, обе кнопки — в один ряд: шапка не съедает треть экрана телефона. */
  .session { margin-left: 0; width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .session .timer { grid-column: 1 / -1; }
  .session button { padding: 9px 10px; font-size: 14px; line-height: 1.2; }
  .waiting { grid-template-columns: minmax(0, 1fr); }
  .waiting h1 { font-size: 24px; }
  .patient-goal { align-items: flex-start; text-align: left; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .metric .value { font-size: 24px; }
  .metric { padding: 12px 14px; }
  table.records, table.intakes, table.months { display: block; }
  table.records thead, table.intakes thead, table.months thead { display: none; }
  table.records tbody, table.intakes tbody, table.months tbody { display: grid; gap: 8px; }
  table.records tr, table.intakes tr, table.months tr { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface); }
  table.records td.notes { grid-column: 1 / -1; }
  table.records td, table.intakes td, table.months td { border: 0; padding: 0; }
  table.records td::before, table.intakes td::before, table.months td::before { content: attr(data-label); display: block; color: var(--muted); font-size: 12px; }
  table.records td.notes:empty { display: none; }
  tr:not(.day-start) td.date { color: inherit; }
  table.compare th, table.compare td { padding: 8px 6px; }
}

/* endregion */
