/* site.css: base styles and shared components for cards.doctorarichai.com.
   Direction B "Teal Instrument" (see /BRAND.md). Every value comes from /assets/tokens.css, which must be linked first.
   No hex values in this file. Page files hold layout only. */

/* Deprecated aliases for token names used before tokens.css (2026-10). Do not use in new code; remove once no page references them. */
:root {
  --accent: var(--brand);
  --accent-strong: var(--brand-strong);
  --accent-soft: var(--brand-soft);
  --pink: var(--brand);
  --warn: var(--caution-fg);
  --warn-bg: var(--caution-bg);
  --font-sans: var(--font-body);
  --font-mono: var(--font-num);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
img { max-width: 100%; }
[hidden] { display: none !important; }
.wrap { max-width: var(--content-max); margin: 0 auto; padding-inline: var(--gutter); padding-block: var(--space-6) 40px; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { color: var(--link-hover); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-family: var(--font-num); font-variant-numeric: var(--num-figures); }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Page title ---------- */
.page-head { margin-bottom: var(--space-5); padding-bottom: var(--space-4); border-bottom: 1px solid var(--line); }
.crumb { font-family: var(--font-num); font-size: var(--fs-xs); color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin: 0 0 2px; }
h1 { font-family: var(--font-head); font-weight: var(--w-head); font-size: var(--fs-xl); line-height: 1.2; letter-spacing: -0.01em; color: var(--title-ink); margin: 0; text-wrap: balance; }
.sub { color: var(--muted); font-size: var(--fs-md); margin: 4px 0 0; }
.lede { color: var(--muted); font-size: var(--fs-base); margin: 4px 0 var(--space-6); max-width: 60ch; }

/* ---------- Section header: small caps label with a teal tick ---------- */
.sec, .group h2 {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-body); font-size: var(--fs-xs); font-weight: var(--w-section);
  text-transform: uppercase; letter-spacing: 0.1em; line-height: 1.3;
  color: var(--section-ink); margin: 0 0 var(--space-4);
}
.sec::before, .group h2::before { content: ""; flex: none; width: 3px; height: 12px; background: var(--section-mark); }
section.group { border-top: 1px solid var(--line-subtle); padding-block: var(--space-4) var(--space-5); }
section.group:first-of-type { border-top: 0; padding-top: 0; }

/* ---------- Form controls ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-4); align-items: end; }
.span-all { grid-column: 1 / -1; }
.f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.lab { font-size: var(--fs-sm); color: var(--ink); display: flex; justify-content: space-between; gap: 8px; }
.lab i { font-style: normal; color: var(--muted); font-family: var(--font-num); font-size: var(--fs-xs); white-space: nowrap; }
input, select, textarea { font: inherit; color: var(--ink); }
input:not([type="checkbox"]):not([type="radio"]), select {
  height: var(--control-h); width: 100%; min-width: 0;
  padding: 0 8px;
  background: var(--field); color: var(--ink);
  border: 1px solid var(--line-control); border-radius: var(--radius-sm);
  font-family: var(--font-num); font-size: var(--fs-base); font-variant-numeric: var(--num-figures);
}
select { font-family: var(--font-body); padding-right: 4px; }
input::placeholder { color: var(--muted); opacity: 1; }
input:disabled { color: var(--muted); border-style: dashed; cursor: not-allowed; }
input[aria-invalid="true"] { border-color: var(--danger-line); box-shadow: inset 0 0 0 1px var(--danger-line); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--link); }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: var(--fs-md); padding: 6px 8px; min-height: var(--control-h); border: 1px solid var(--line-control); border-radius: var(--radius-sm); background: var(--field); cursor: pointer; min-width: 0; }
.check input { width: 16px; height: 16px; margin: 2px 0 0; padding: 0; flex: none; }
.check small { display: block; color: var(--muted); font-size: var(--fs-sm); }
.calc-out { display: flex; align-items: center; min-height: var(--control-h); font-family: var(--font-num); font-size: var(--fs-base); font-variant-numeric: var(--num-figures); padding: 0 8px; border: 1px dashed var(--line-control); border-radius: var(--radius-sm); color: var(--muted); }
.hint { font-size: var(--fs-sm); color: var(--muted); margin: var(--space-3) 0 0; max-width: 72ch; }
textarea { width: 100%; background: var(--field); border: 1px solid var(--line-control); border-radius: var(--radius-sm); padding: 8px; font-family: var(--font-num); font-size: var(--fs-md); }
/* Phones: 16px text in fields stops iOS from zooming on focus; taller controls for touch. */
@media (max-width: 640px), (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px; }
  input:not([type="checkbox"]):not([type="radio"]), select, .calc-out { height: auto; min-height: 40px; }
  button, .btn { min-height: 40px; }
}

/* Segmented control built on native radios (stay keyboard-focusable) */
fieldset.seg { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.seg legend { font-size: var(--fs-sm); color: var(--ink); padding: 0; margin-bottom: 4px; }
fieldset.seg legend small { display: block; color: var(--muted); font-size: var(--fs-sm); }
.seg-opts { display: flex; flex-wrap: wrap; }
.seg-opts label { position: relative; flex: 1 1 0; min-width: 0; }
.seg-opts input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg-opts span { display: flex; align-items: center; justify-content: center; min-height: var(--control-h); text-align: center; font-size: var(--fs-md); padding: 0 10px; border: 1px solid var(--line-control); background: var(--field); color: var(--ink); white-space: nowrap; }
.seg-opts label + label span { margin-left: -1px; }
.seg-opts label:first-child span { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.seg-opts label:last-child span { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.seg-opts input:checked + span { background: var(--link); border-color: var(--link); color: var(--on-link); font-weight: var(--w-strong); position: relative; }
.seg-opts input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; position: relative; z-index: 1; }
.seg-opts label:hover span { border-color: var(--ink-2); }
.seg-opts label:hover input:checked + span { border-color: var(--link); }

/* ---------- Buttons: one primary per view ---------- */
button, .btn {
  font-family: var(--font-body); font-size: var(--fs-md); font-weight: 500; line-height: 1.2;
  min-height: var(--control-h); padding: 0 12px; cursor: pointer;
  border-radius: var(--radius-sm); border: 1px solid var(--line-control);
  background: var(--surface); color: var(--ink);
}
button:hover, .btn:hover { border-color: var(--ink-2); }
button.primary, .btn.primary { background: var(--btn-primary-bg); border-color: var(--btn-primary-bg); color: var(--btn-primary-ink); font-weight: var(--w-strong); }
button.primary:hover, .btn.primary:hover { background: var(--btn-primary-hover); border-color: var(--btn-primary-hover); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: var(--space-5); }
.status { font-size: var(--fs-sm); color: var(--muted); }

/* ---------- Result panel and big number ---------- */
.results { background: var(--surface); border: 1px solid var(--line); border-top: var(--panel-rule-w) solid var(--panel-rule); border-radius: var(--radius); padding: var(--space-5); min-width: 0; }
.results-head { display: flex; justify-content: space-between; gap: 8px; margin: calc(-1 * var(--space-5)) calc(-1 * var(--space-5)) var(--space-4); padding: 5px var(--space-5); background: var(--surface-2); border-bottom: 1px solid var(--line-subtle); font-family: var(--font-num); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.hero { display: flex; align-items: baseline; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; padding-bottom: var(--space-4); border-bottom: 1px solid var(--line-subtle); }
.hero .k { font-size: var(--fs-sm); color: var(--muted); }
.hero .v { font-family: var(--font-num); font-size: var(--fs-hero); font-weight: var(--w-hero); line-height: 1; color: var(--hero-ink); font-variant-numeric: var(--num-figures); letter-spacing: -0.01em; white-space: nowrap; }
.hero .v small { font-size: 0.5em; color: var(--muted); font-weight: 500; letter-spacing: 0; margin-left: 2px; }

/* ---------- Data tables: numbers right-aligned in mono, labels left in sans ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; margin-top: var(--space-4); font-size: var(--fs-md); }
table.tbl caption { text-align: left; font-size: var(--fs-xs); font-weight: var(--w-strong); text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); padding-bottom: 4px; }
table.tbl th { font-weight: 500; font-size: var(--fs-xs); color: var(--ink-2); text-align: right; padding: 5px 0 5px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td { text-align: right; padding: var(--space-3) 0 var(--space-3) 10px; border-bottom: 1px solid var(--line-subtle); font-family: var(--font-num); font-variant-numeric: var(--num-figures); color: var(--ink); vertical-align: middle; }
table.tbl th:first-child, table.tbl td:first-child { text-align: left; padding-left: 0; font-family: var(--font-body); }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl td.txt, table.tbl th.txt { text-align: left; font-family: var(--font-body); }
table.tbl tr.sel td { background: var(--selected-bg); }
table.tbl tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--link); padding-left: 8px; }

dl.kv { margin: var(--space-4) 0 0; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: var(--fs-md); }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-family: var(--font-num); text-align: right; font-variant-numeric: var(--num-figures); }
.tag { font-family: var(--font-body); font-size: var(--fs-xs); font-weight: var(--w-strong); background: var(--brand-soft); color: var(--brand-strong); border-radius: var(--radius-sm); padding: 1px 6px; margin-left: 6px; }
.pill { display: inline-block; vertical-align: middle; font-size: var(--fs-xs); font-weight: var(--w-strong); letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 1px 8px; }

/* ---------- Notices: info / caution / danger / success. Always an icon (drawn here) and a bold lead word. ---------- */
.notice, ul.notes li {
  --n-line: var(--info-line); --n-bg: var(--info-bg); --n-fg: var(--info-fg);
  --n-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='8.2' fill='none' stroke='black' stroke-width='1.8'/%3E%3Cpath d='M10 9v5' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='10' cy='6.2' r='1.2'/%3E%3C/svg%3E");
  display: flex; gap: 8px; align-items: flex-start;
  padding: 7px 10px; border-left: 4px solid var(--n-line); background: var(--n-bg); color: var(--n-fg);
  border-radius: var(--radius-sm); font-size: var(--fs-sm); line-height: 1.45;
}
.notice::before, ul.notes li::before { content: ""; flex: none; width: 15px; height: 15px; margin-top: 1px; background: currentColor; -webkit-mask: var(--n-icon) center / contain no-repeat; mask: var(--n-icon) center / contain no-repeat; }
.notice > :not(button) { flex: 1 1 0; min-width: 0; margin: 0; }
.notice b, ul.notes li b { font-weight: 700; }
.notice.caution, ul.notes li.caution {
  --n-line: var(--caution-line); --n-bg: var(--caution-bg); --n-fg: var(--caution-fg);
  --n-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 2.5 18.5 17h-17z' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'/%3E%3Cpath d='M10 8v4.2' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='10' cy='14.6' r='1.1'/%3E%3C/svg%3E");
}
.notice.danger, ul.notes li.danger {
  --n-line: var(--danger-line); --n-bg: var(--danger-bg); --n-fg: var(--danger-fg);
  --n-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M6.6 1.8h6.8l4.8 4.8v6.8l-4.8 4.8H6.6l-4.8-4.8V6.6z' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'/%3E%3Cpath d='M7.2 7.2l5.6 5.6M12.8 7.2l-5.6 5.6' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
}
.notice.success, ul.notes li.success {
  --n-line: var(--success-line); --n-bg: var(--success-bg); --n-fg: var(--success-fg);
  --n-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='8.2' fill='none' stroke='black' stroke-width='1.8'/%3E%3Cpath d='M6 10.3 8.7 13 14 7.5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.notice.banner { align-items: center; flex-wrap: wrap; margin: 0 0 var(--space-5); }
.notice.banner::before { margin-top: 0; }
.notice.banner > button { flex: none; margin-left: auto; }
ul.notes { margin: var(--space-4) 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
ul.notes li > * { flex: 1 1 0; min-width: 0; }

/* ---------- Risk chips: shared ramp, never color alone ---------- */
.catchip { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 22px; padding: 0 6px; border-radius: var(--radius-sm); font-family: var(--font-num); font-weight: 600; font-size: var(--fs-sm); font-variant-numeric: var(--num-figures); }
.r1 { background: var(--risk-1); color: var(--risk-1-on); }
.r2 { background: var(--risk-2); color: var(--risk-2-on); }
.r3 { background: var(--risk-3); color: var(--risk-3-on); }
.r4 { background: var(--risk-4); color: var(--risk-4-on); }
.r5 { background: var(--risk-5); color: var(--risk-5-on); }
.rchip { display: inline-flex; align-items: center; gap: 6px; border-radius: var(--radius-pill); padding: 3px 12px 3px 10px; font-weight: 700; font-size: var(--fs-md); letter-spacing: 0.01em; white-space: nowrap; }
.rchip .shape { font-size: 0.875em; line-height: 1; }
.rchip.low { background: var(--scd-low); color: var(--scd-low-on); }
.rchip.mid, .rchip.intermediate { background: var(--scd-mid); color: var(--scd-mid-on); }
.rchip.high { background: var(--scd-high); color: var(--scd-high-on); }

/* ---------- Reference text, footers ---------- */
details.method { margin-top: var(--space-6); border-top: 1px solid var(--line); padding-top: var(--space-4); max-width: 76ch; }
details.method summary { cursor: pointer; font-weight: 600; }
details.method pre { font-family: var(--font-num); font-size: var(--fs-md); line-height: 1.6; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow-x: auto; }
details.method h3 { font-size: var(--fs-md); font-weight: 600; margin: 18px 0 0; }
details.method p, details.method li { color: var(--muted); font-size: var(--fs-md); }
.foot { margin-top: var(--space-5); font-size: var(--fs-sm); color: var(--muted); max-width: 72ch; }

/* ---------- Results panel always in view ----------
   Desktop (>= 880px): every .app results panel is sticky; when taller than the viewport it scrolls inside itself so
   the headline result stays visible. Phones: /assets/ui.js adds the .dock summary bar below. */
@media (min-width: 880px) {
  .app > aside.results {
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + var(--space-5));
    max-height: calc(100vh - 2 * var(--space-5) - env(safe-area-inset-top, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}
aside.results:focus { outline: none; }
aside.results:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Info tip: an "i" button that opens a popover with the longer explanation ----------
   Markup: <button type="button" class="tip" aria-label="More about X" aria-controls="ID"></button>
           <div class="tip-pop" id="ID" hidden>…</div>   (a <small class="tip-pop"> inside a <legend> also works)
   Behaviour lives in /assets/ui.js. The popover text stays in the DOM (hidden) for screen readers and crawlers. */
.tip {
  position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 18px; height: 18px; min-height: 0; margin: 0 0 0 4px; padding: 0; vertical-align: -4px;
  border: 0; border-radius: 50%; background: transparent; color: var(--link); cursor: pointer;
  font-size: 0; line-height: 0; text-transform: none; letter-spacing: 0;
}
.tip::before {
  content: ""; width: 16px; height: 16px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='8.2' fill='none' stroke='black' stroke-width='1.8'/%3E%3Cpath d='M10 9v5' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='10' cy='6.2' r='1.2'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='8.2' fill='none' stroke='black' stroke-width='1.8'/%3E%3Cpath d='M10 9v5' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='10' cy='6.2' r='1.2'/%3E%3C/svg%3E") center / contain no-repeat;
}
.tip::after { content: ""; position: absolute; inset: -7px; } /* 32px hit area */
.tip:hover { color: var(--link-hover); background: var(--selected-bg); border-color: transparent; }
.tip[aria-expanded="true"] { background: var(--link); color: var(--on-link); }
@media (max-width: 640px), (pointer: coarse) {
  .tip { min-height: 0; }
  .tip::after { inset: -11px; } /* 40px hit area */
}
.tip-pop, fieldset.seg legend .tip-pop {
  position: fixed; z-index: 70; top: 0; left: 0; display: block;
  width: max-content; max-width: min(42ch, calc(100vw - 16px)); overflow: auto; overscroll-behavior: contain;
  margin: 0; padding: 10px 12px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-control); border-radius: var(--radius);
  font-family: var(--font-body); font-size: var(--fs-md); font-weight: 400; font-style: normal; line-height: 1.5;
  letter-spacing: normal; text-transform: none; text-align: left; white-space: normal;
}
.tip-pop p, .tip-pop ul { margin: 0; }
.tip-pop > :not(:first-child) { margin-top: 6px; }
.tip-pop ul { padding-left: 18px; }
.tip-pop .tip-k { display: block; font-size: var(--fs-xs); font-weight: var(--w-strong); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
/* Phones: the popover becomes a bottom sheet with a close button. */
.tip-pop.sheet, fieldset.seg legend .tip-pop.sheet {
  top: auto; left: 0; right: 0; bottom: 0; width: auto; max-width: none; max-height: 60vh;
  border-width: 1px 0 0; border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px 56px calc(16px + env(safe-area-inset-bottom, 0px)) var(--gutter);
  font-size: var(--fs-base);
}
.tip-close {
  position: fixed; z-index: 71; right: 8px; width: 40px; height: 40px; min-height: 40px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--fs-lg); line-height: 1; color: var(--ink); background: var(--surface);
}
@media (prefers-reduced-motion: no-preference) {
  .tip-pop:not([hidden]) { animation: tip-in 120ms ease-out; }
  @keyframes tip-in { from { opacity: 0; } to { opacity: 1; } }
}

/* ---------- Result dock (phones): compact sticky summary of the headline result ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-3) var(--gutter) calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  background: var(--surface); color: var(--ink);
  border-top: var(--panel-rule-w) solid var(--panel-rule);
}
.dock-txt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.dock-k { font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-width: 0; }
.dock-item { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.dock-item .dock-lbl { font-size: var(--fs-xs); color: var(--muted); }
.dock-v { font-family: var(--font-num); font-variant-numeric: var(--num-figures); font-size: var(--fs-xl); font-weight: var(--w-hero); line-height: 1.1; white-space: nowrap; }
.dock-item > :not(.dock-v):not(.dock-lbl) { font-size: var(--fs-sm); padding-block: 1px; }
.dock-btn { flex: none; }
body.has-dock { padding-bottom: calc(var(--dock-h, 64px) + env(safe-area-inset-bottom, 0px)); }
html.has-dock { scroll-padding-bottom: calc(var(--dock-h, 64px) + var(--space-4)); }
@media (min-width: 880px) {
  /* Desktop fallback only (see ui.js): align the dock's content with the page column. */
  .dock { padding-inline: max(var(--gutter), calc((100vw - var(--content-max)) / 2 + var(--gutter))); }
}
