/* Нефродиета — visual system.
 *
 * The register is institutional, not consumer: this is shown to nephrologists
 * by a state research institute. So hairlines instead of shadows, flat fills
 * instead of gradients, squared corners instead of pills, and one accent used
 * sparingly. The quoted document fragment is set in a serif on purpose — it is
 * the thing the sceptical doctor actually believes, and it should read as a
 * page from the order rather than as app furniture.
 *
 * No web fonts: A8 requires the demo to work with no network, so every family
 * here is one the device already has.
 *
 * Replace the palette with the ИПИИР design system's own values; the theme
 * colour in manifest.webmanifest must be kept in step with --brand.
 */
:root {
  /* Ink and paper */
  --ink: #14181b;
  --ink-2: #454f55;
  --ink-3: #737f86;
  --bg: #f4f5f6;
  --surface: #ffffff;
  --surface-2: #fafbfb;

  /* Brand: deep, desaturated, institutional */
  --brand: #14454d;
  --brand-ink: #0c2f35;
  --brand-soft: #eaf0f1;
  --accent: #8a6a1f;          /* used only to mark the three stand questions */
  --accent-soft: #fbf6e9;

  /* Semantics */
  --ok: #1c5c40;
  --ok-soft: #eaf3ee;
  --no: #8c2f2f;
  --no-soft: #f8ecec;

  /* Hairlines, not shadows */
  --line: #dfe3e5;
  --line-strong: #c6ced2;

  /* Spacing scale */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  --radius: 4px;
  --radius-lg: 6px;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", "Droid Serif", serif;
}

* { box-sizing: border-box; }

/* An explicit display rule beats the hidden attribute, so restore it once,
   here, rather than remembering to guard every panel that uses flex. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ---- header ---- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  padding: var(--s3) var(--s5);
  padding-top: calc(var(--s3) + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.mark {
  width: 30px; height: 30px; flex: none;
  background: var(--brand);
  border-radius: var(--radius);
  position: relative;
}
/* A plain bar mark: no gradient, no glow. */
.mark::after {
  content: ""; position: absolute; inset: 9px 7px;
  border-left: 3px solid #fff; border-right: 3px solid #fff;
}
.top h1 {
  margin: 0; font-size: 16px; font-weight: 600;
  letter-spacing: .005em; color: var(--ink);
}
.sub {
  margin: 0; font-size: 12px; color: var(--ink-3);
  letter-spacing: .02em;
}
.top-actions { display: flex; gap: var(--s2); flex: none; }

button { font: inherit; cursor: pointer; border-radius: var(--radius); }
.primary {
  background: var(--brand); color: #fff; border: 1px solid var(--brand);
  padding: 10px 20px; font-weight: 550; letter-spacing: .01em;
}
.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.ghost {
  background: var(--surface); color: var(--ink-2); border: 1px solid var(--line-strong);
  padding: 8px 14px;
}
.ghost:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.small { padding: 6px 12px; font-size: 13.5px; }

/* ---- install prompt (F2) ---- */
.install {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s4); flex-wrap: wrap;
  margin: var(--s3) var(--s5) 0; padding: var(--s3) var(--s4);
  background: var(--accent-soft);
  border: 1px solid #e6dcc0;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.install-text { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.install-text strong { font-weight: 600; }
.install-text span { color: var(--ink-2); }
.install-actions { display: flex; gap: var(--s2); }

/* ---- layout (F3) ---- */
.screen {
  display: grid; grid-template-columns: 330px 1fr; gap: var(--s4);
  padding: var(--s4) var(--s5) var(--s5); align-items: start;
  height: calc(100% - 62px);
}
/* Grid items default to min-width:auto, so their content can push a track
   wider than the screen. Measured at 375px: the track came out 370 against
   351 available, and the page scrolled sideways. */
.screen > * { min-width: 0; }
.case-wrap > * { min-width: 0; }
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden; max-height: 100%; display: flex; flex-direction: column;
}
.panel-toggle { display: none; }
.panel-body { overflow-y: auto; padding: var(--s2); }
.topic-title {
  font-size: 11px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-3); padding: var(--s4) var(--s3) var(--s2);
  border-top: 1px solid var(--line); margin-top: var(--s2);
}
.topic-title:first-child { border-top: none; margin-top: 0; padding-top: var(--s3); }
.q {
  display: block; width: 100%; text-align: left;
  border: 1px solid transparent; border-left: 2px solid transparent;
  background: transparent; color: var(--ink); padding: 9px var(--s3);
  font-size: 14.5px; line-height: 1.4; border-radius: 0 var(--radius) var(--radius) 0;
}
.q:hover { background: var(--brand-soft); border-left-color: var(--brand); }
.q.rec { background: var(--surface-2); border-color: var(--line); border-left-color: var(--accent); }
.q .tag {
  display: block; margin-top: 3px; font-size: 10px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; color: var(--accent);
}

/* ---- dialog ---- */
.dialog {
  display: flex; flex-direction: column; min-height: 0; height: 100%;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.thread { flex: 1; overflow-y: auto; padding: var(--s5); min-height: 0; }
.empty {
  color: var(--ink-2); max-width: 44ch; margin: 7% auto 0; text-align: center;
}
.empty p:first-child { font-size: 17px; line-height: 1.5; color: var(--ink); }
.empty .muted { color: var(--ink-3); font-size: 14px; margin-top: var(--s3); }

.msg { margin-bottom: var(--s5); }
.msg.user { text-align: right; }
.msg.user .bubble {
  background: var(--brand); color: #fff; display: inline-block;
  padding: 9px var(--s4); border-radius: var(--radius); max-width: 85%;
  text-align: left; font-size: 15px;
}
.msg.bot .bubble {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  padding: var(--s4) var(--s5); border-radius: 0 var(--radius) var(--radius) 0;
  max-width: 96%;
}
.bubble p { margin: 0 0 var(--s2); white-space: pre-wrap; }
.bubble p:last-child { margin-bottom: 0; }

/* The citation is the product. It is set apart and it is quiet. */
.source {
  margin-top: var(--s4); padding: var(--s3) var(--s4);
  background: var(--brand-soft);
  border-radius: var(--radius);
  font-size: 13px; line-height: 1.5; color: var(--brand-ink);
  letter-spacing: .005em;
}
.source + .source { margin-top: var(--s2); }

details.frag { margin-top: var(--s3); }
details.frag summary {
  cursor: pointer; font-size: 13px; color: var(--brand); user-select: none;
  padding: var(--s1) 0; letter-spacing: .01em;
}
details.frag summary:hover { color: var(--brand-ink); }
/* Serif: this is a page from the document, not interface text. */
details.frag .quote {
  margin-top: var(--s3); padding: var(--s4) var(--s5);
  background: var(--surface-2);
  border: 1px solid var(--line); border-left: 2px solid var(--line-strong);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-family: var(--serif); font-size: 15px; line-height: 1.7;
  color: var(--ink-2); max-height: 340px; overflow-y: auto;
  white-space: pre-wrap;
}
.badge {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .09em; padding: 2px 6px; border-radius: 2px; margin-right: var(--s2);
  background: var(--accent-soft); border: 1px solid #e6dcc0; color: var(--accent);
  vertical-align: 1px;
}
.refused .bubble { border-left-color: var(--accent); background: var(--surface-2); }
.thinking { color: var(--ink-3); font-size: 14px; font-style: italic; }

/* ---- composer (F3, F5) ---- */
.composer {
  border-top: 1px solid var(--line); padding: var(--s3) var(--s4);
  padding-bottom: calc(var(--s3) + env(safe-area-inset-bottom));
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.ctx {
  font-size: 12px; color: var(--brand); letter-spacing: .02em;
  margin-bottom: var(--s2); display: inline-block;
}
.ctx::before { content: "— "; }
.composer-row { display: flex; gap: var(--s2); }
#q {
  flex: 1; font: inherit; padding: 10px var(--s4);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); min-width: 0;
}
#q::placeholder { color: var(--ink-3); }
#q:focus { outline: none; border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }

/* ---- sheets (F6, training) ---- */
.sheet {
  position: fixed; inset: 0; background: rgba(12, 28, 32, .5);
  display: flex; align-items: center; justify-content: center;
  padding: var(--s5); z-index: 40;
}
.sheet-inner {
  background: var(--surface); border-radius: var(--radius-lg);
  width: min(960px, 100%); max-height: 88vh;
  display: flex; flex-direction: column;
  border: 1px solid var(--line-strong);
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line-strong);
}
.sheet-head h2 {
  margin: 0; font-size: 15px; font-weight: 650;
  letter-spacing: .02em; text-transform: uppercase; color: var(--ink-2);
}
.sheet-body { overflow-y: auto; padding: var(--s4) var(--s5) var(--s5); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px var(--s2); border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-3); font-weight: 700;
  border-bottom: 1px solid var(--line-strong);
}
td.num { text-align: right; white-space: nowrap; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.st {
  font-size: 11px; font-weight: 650; padding: 2px 7px; border-radius: 2px;
  white-space: nowrap; letter-spacing: .03em;
}
.st.fetched { background: var(--ok-soft); color: var(--ok); }
.st.missing { background: var(--no-soft); color: var(--no); }
.st.superseded { background: #eef0f1; color: var(--ink-3); }
.note { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; line-height: 1.5; }

/* ---- virtual patient (training) ---- */
.case { padding: var(--s4) 0; }
.case-title { margin: 0 0 var(--s1); font-size: 17px; font-weight: 650; letter-spacing: -.005em; }
.case-history { margin: 0 0 var(--s4); color: var(--ink-2); font-size: 14.5px; }
.labs {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0 var(--s5); margin-bottom: var(--s5);
  padding: var(--s3) var(--s4);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.lab {
  display: flex; justify-content: space-between; gap: var(--s3);
  font-size: 13.5px; padding: 5px 0; border-bottom: 1px solid var(--line);
}
.lab:last-child { border-bottom: none; }
.lab-name { color: var(--ink-3); }
.lab-value { color: var(--ink); font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

.decision { margin-bottom: var(--s5); padding-top: var(--s4); border-top: 1px solid var(--line); }
.decision:first-of-type { border-top: none; padding-top: 0; }
.decision-q { margin: 0 0 var(--s3); font-weight: 600; font-size: 15.5px; }
.options { display: flex; flex-direction: column; gap: var(--s1); }
.option {
  text-align: left; padding: 11px var(--s4); font-size: 14.5px; line-height: 1.4;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  min-height: 44px; border-radius: var(--radius);
}
.option:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-soft); }
.option:disabled { cursor: default; opacity: .6; }
.option.right { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); opacity: 1; font-weight: 550; }
.option.wrong { border-color: var(--no); background: var(--no-soft); color: var(--no); opacity: 1; }

.verdict {
  margin-top: var(--s4); padding: var(--s4);
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--brand); border-radius: 0 var(--radius) var(--radius) 0;
}
.verdict p { margin: 0 0 var(--s2); font-size: 14.5px; }
.verdict p:last-child { margin-bottom: 0; }
.verdict-head {
  font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
}
.verdict-head.ok { color: var(--ok); }
.verdict-head.no { color: var(--no); }
.verdict-why { color: var(--ink-2); }
.case-note {
  font-size: 12px; color: var(--ink-3); margin: var(--s5) 0 0;
  padding-top: var(--s3); border-top: 1px solid var(--line); font-style: italic;
}

/* ---- case pages ---- */
.case-wrap { display: grid; grid-template-columns: 240px 1fr; gap: var(--s5); min-height: 0; }
.case-list {
  display: flex; flex-direction: column; gap: 1px; max-height: 64vh; overflow-y: auto;
  padding-right: var(--s2); border-right: 1px solid var(--line);
}
.case-pick {
  display: flex; align-items: flex-start; gap: var(--s2); text-align: left; width: 100%;
  padding: 9px var(--s2); border: 1px solid transparent; border-left: 2px solid transparent;
  background: transparent; color: var(--ink-2); font-size: 13px; line-height: 1.35;
  min-height: 44px; border-radius: 0;
}
.case-pick:hover { background: var(--brand-soft); color: var(--ink); }
.case-pick.active {
  background: var(--brand-soft); border-left-color: var(--brand);
  color: var(--ink); font-weight: 600;
}
.case-num {
  flex: none; width: 20px; height: 20px; border-radius: 2px; background: var(--line);
  color: var(--ink-2); font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.case-pick.active .case-num { background: var(--brand); color: #fff; }
.case-right { display: flex; flex-direction: column; min-width: 0; }
.case-nav {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding-bottom: var(--s3); border-bottom: 1px solid var(--line-strong);
}
.case-counter {
  font-size: 11px; color: var(--ink-3); white-space: nowrap;
  text-transform: uppercase; letter-spacing: .09em; font-weight: 650;
}
.case-nav button:disabled { opacity: .35; cursor: default; }
.case-view { overflow-y: auto; max-height: 64vh; padding-right: var(--s2); }

/* ---- narrow screen: the list becomes a collapsible top panel (F3) ---- */
@media (max-width: 860px) {
  .screen { grid-template-columns: 1fr; height: auto; padding: var(--s3); gap: var(--s3); }
  .panel { max-height: none; }
  .panel-toggle {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    background: var(--surface); border: none; padding: var(--s4);
    font-size: 15px; font-weight: 600; color: var(--ink); border-radius: var(--radius-lg);
  }
  .panel-body { display: none; max-height: 52vh; }
  .panel.open .panel-body { display: block; }
  .panel.open .chev { transform: rotate(180deg); }
  .chev { transition: transform .15s; color: var(--ink-3); }
  .dialog { height: auto; min-height: 60vh; }
  .thread { padding: var(--s4); }
  .msg.bot .bubble { padding: var(--s3) var(--s4); }
  .top { padding: var(--s2) var(--s3); padding-top: calc(var(--s2) + env(safe-area-inset-top)); gap: var(--s2); }
  .sub { display: none; }        /* the strapline crowds the buttons on a phone */
  .mark { width: 26px; height: 26px; }
  .mark::after { inset: 7px 6px; border-left-width: 2px; border-right-width: 2px; }
  .install { margin: var(--s2) var(--s3) 0; }

  /* A finger is not a cursor. Measured on the live page at 375px, the header
     buttons came out 36px tall against the 44px both Apple and Google ask for,
     and this is a stand where people tap once and expect it to land. */
  .ghost, .primary, .small, .panel-toggle {
    min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  }
  details.frag summary { padding: 10px 0; }
  #q { min-height: 44px; }
  .brand { flex: 0 1 auto; overflow: hidden; }
  .top-actions .ghost { padding: 8px 10px; font-size: 13px; }

  .labs { grid-template-columns: 1fr; }
  .sheet { padding: 0; align-items: flex-end; }
  .sheet-inner { max-height: 94vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; width: 100%; }
  .sheet-body { padding: var(--s3) var(--s4) var(--s5); }
  .sheet-head { padding: var(--s3) var(--s4); }

  .case-wrap { grid-template-columns: 1fr; gap: var(--s3); }
  .case-list {
    flex-direction: row; overflow-x: auto; max-height: none; padding-bottom: var(--s2);
    border-right: none; border-bottom: 1px solid var(--line-strong); gap: var(--s1);
  }
  .case-pick {
    flex: none; width: auto; justify-content: center; min-width: 44px;
    border-left: none; border-bottom: 2px solid transparent;
  }
  .case-pick.active { border-left: none; border-bottom-color: var(--brand); }
  .case-name { display: none; }          /* on a phone the number is the label */
  .case-view { max-height: none; }
  .detail-quote, details.frag .quote { padding: var(--s3) var(--s4); font-size: 14.5px; }
}

/* Below this width three buttons and the wordmark genuinely do not both fit,
   and squeezing the name left it as "Н…а". The mark stays; the name is on the
   home-screen icon anyway. */
@media (max-width: 520px) {
  .top h1 { display: none; }
}
