/* ==========================================================================
   PREVENT Risk Calculator — component styles
   Layered on top of the deolifyhealth.com design system (css/site.css), whose
   tokens, header, footer and typography are used unchanged.

   Everything here is scoped under #calcApp so it cannot collide with the site
   stylesheet, which already defines .field, .section, .btn and .container.
   ========================================================================== */

#calcApp {
  /* Risk status uses two states only: calm (below the treatment threshold) and
     actionable. Both are drawn from colours already in the site vocabulary —
     the teal accent, and the amber used for preprint badges — darkened where
     needed to clear 4.5:1 against the page background. */
  --calc-calm: #0b7167;
  --calc-act: #b45309;
  --calc-act-line: rgba(180, 83, 9, .35);
  --calc-act-soft: rgba(251, 191, 36, .14);
  --calc-rule: var(--line);
}

/* Author-level flex rules must never override the native hidden state. */
#calcApp [hidden] { display: none !important; }

/* ---------- shared primitives ---------- */

#calcApp .c-sec { padding-top: clamp(30px, 4vw, 46px); }
#calcApp .c-sec > .head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  border-bottom: 1px solid var(--calc-rule); padding-bottom: 11px; margin-bottom: 22px;
}
#calcApp .c-sec > .head h2 { font-size: 1.3rem; }
#calcApp .c-sec > .head .note-inline { font-family: var(--font-body); font-size: 13px; color: var(--faint); font-weight: 400; }

#calcApp .subhead {
  font-family: var(--font-display); font-size: 1rem; font-weight: 600; color: #0f1b2d;
  margin: 26px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--calc-rule);
}
#calcApp .subhead:first-child { margin-top: 0; }

#calcApp .label {
  font-family: var(--font-display); font-size: 11px; font-weight: 600;
  letter-spacing: .13em; text-transform: uppercase; color: var(--faint);
}

#calcApp .prose { max-width: 74ch; color: var(--muted); font-size: 14.5px; }
#calcApp .prose strong { color: var(--text); }

/* ---------- intake form ---------- */

#calcApp #intake { max-width: 1100px; margin-inline: auto; }
#calcApp form { display: grid; gap: 18px; }
#calcApp fieldset {
  min-inline-size: 0; margin: 0; padding: clamp(20px, 2.5vw, 28px);
  background: var(--ink-700); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}
#calcApp fieldset:last-of-type { margin-bottom: 0; }
#calcApp legend {
  font-family: var(--font-display); font-size: 11.5px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--accent);
  float: left; padding: 0 0 11px; margin: 0 0 22px;
  border-bottom: 1px solid var(--calc-rule); width: 100%;
}
#calcApp legend + * { clear: both; }
#calcApp .fieldset-note { margin: -10px 0 18px; font-size: 13.5px; color: var(--faint); max-width: 72ch; }

#calcApp .grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px 24px; }

#calcApp .field { min-width: 0; margin-bottom: 0; }
#calcApp .field > label, #calcApp .field .lbl {
  display: block; font-family: var(--font-display); font-size: 13.5px; font-weight: 600;
  color: var(--text); margin-bottom: 7px;
}
#calcApp .field .req { color: var(--accent); margin-left: 2px; }
#calcApp .field .note { font-size: 12px; color: var(--faint); margin-top: 5px; line-height: 1.45; }

#calcApp input[type="text"], #calcApp input[type="number"], #calcApp select {
  width: 100%; padding: 11px 14px;
  font-family: var(--font-body); font-size: 15px; font-variant-numeric: tabular-nums;
  color: var(--text); background: var(--ink-800);
  border: 1px solid var(--line-strong); border-radius: 11px;
  transition: border-color .25s, box-shadow .25s;
}
#calcApp input[type="number"] { -moz-appearance: textfield; }
#calcApp input[type="number"]::-webkit-outer-spin-button,
#calcApp input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#calcApp input::placeholder { color: #9aa5b4; }
#calcApp input:focus, #calcApp select:focus {
  outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft);
}
#calcApp input.invalid { border-color: rgba(180, 45, 32, .55); box-shadow: 0 0 0 3px rgba(180, 45, 32, .10); }

#calcApp .with-unit { display: flex; gap: 8px; }
#calcApp .with-unit input { flex: 1 1 auto; min-width: 0; }
#calcApp .with-unit select { flex: 0 0 auto; width: auto; font-size: 13px; padding: 11px 9px; color: var(--muted); }
#calcApp .unit-static { align-self: center; font-size: 13px; color: var(--faint); min-width: 52px; }

/* segmented control */
#calcApp .seg {
  position: relative; display: inline-flex; width: 100%; border: 0;
  border-radius: 11px; overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
#calcApp .seg input {
  position: absolute; left: 0; top: 0; width: 1px; height: 1px;
  margin: 0; padding: 0; opacity: 0; pointer-events: none;
}
#calcApp .seg label {
  display: flex; align-items: center; justify-content: center;
  flex: 1; margin: 0; text-align: center; padding: 10px 6px;
  font-family: var(--font-display); font-size: 13.5px; font-weight: 600;
  color: var(--muted); background: var(--ink-800); cursor: pointer; user-select: none;
  border-right: 1px solid var(--line-strong); transition: background .25s, color .25s;
}
#calcApp .seg label:last-of-type { border-right: 0; }
#calcApp .seg label:hover { background: var(--ink-500); }
#calcApp .seg input:checked + label { background: var(--accent); color: #fff; }
#calcApp .seg input:focus-visible + label { outline: 2px solid var(--accent-2); outline-offset: -2px; }

/* helper disclosures inside fields */
#calcApp details.helper { margin-top: 10px; border-top: 1px dashed var(--line-strong); }
#calcApp details.helper > summary {
  cursor: pointer; padding: 8px 0; font-family: var(--font-display); font-size: 12.5px;
  font-weight: 600; color: var(--accent); list-style: none;
}
#calcApp details.helper > summary::-webkit-details-marker { display: none; }
#calcApp details.helper > summary::before { content: "+ "; }
#calcApp details.helper[open] > summary::before { content: "\2212  "; }
#calcApp details.helper .inner { padding: 0 0 12px; }
#calcApp details.helper .out { font-size: 12.5px; color: var(--muted); margin-top: 9px; }
#calcApp details.helper .out b { color: var(--text); font-variant-numeric: tabular-nums; }

/* checkbox rows */
#calcApp .check-grid { display: grid; grid-template-columns: 1fr; gap: 4px; }
#calcApp .check { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; cursor: pointer; }
#calcApp .check input {
  width: 16px; height: 16px; margin: 2px 0 0; padding: 0;
  flex: 0 0 16px; border: 0; background: transparent; box-shadow: none;
  accent-color: var(--accent);
}
#calcApp .check .t { font-size: 13.5px; font-weight: 500; }
#calcApp .check .d { font-size: 12px; color: var(--faint); line-height: 1.4; }

#calcApp .actions {
  display: flex; flex-wrap: wrap; gap: 12px;
  margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--calc-rule);
}
#calcApp .btn-quiet {
  font-family: var(--font-display); font-weight: 600; font-size: 15px; cursor: pointer;
  padding: 13px 24px; border-radius: 100px; background: transparent;
  color: var(--text); border: 1px solid var(--line-strong);
  transition: border-color .3s, color .3s, transform .3s var(--ease);
}
#calcApp .btn-quiet:hover { border-color: var(--accent-line); color: #0f1b2d; transform: translateY(-2px); }

/* ---------- collapsed patient strip ---------- */

#calcApp .patient-strip {
  background: var(--ink-700); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 18px 22px; margin-top: clamp(20px, 3vw, 32px);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; flex-wrap: wrap;
}
#calcApp .patient-strip .who { min-width: 0; }
#calcApp .patient-strip .who .label { display: block; margin-bottom: 6px; }
#calcApp .patient-strip .facts { font-size: 14.5px; color: var(--text); }
#calcApp .patient-strip .facts b { font-weight: 600; }
#calcApp .patient-strip .facts .sep { color: var(--line-strong); margin: 0 8px; }
#calcApp .patient-strip .facts .flag { color: var(--calc-act); font-weight: 600; }
#calcApp .patient-strip .facts .model { display: block; margin-top: 5px; font-size: 12.5px; color: var(--faint); }
#calcApp .patient-strip .btn-quiet { padding: 9px 18px; font-size: 14px; }

/* ---------- data tables ---------- */

#calcApp .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
#calcApp .table-wrap table.data { min-width: 470px; }
#calcApp .table-wrap.narrow table.data { min-width: 0; }

#calcApp table.data { width: 100%; border-collapse: collapse; }
#calcApp table.data th, #calcApp table.data td {
  padding: 13px 12px; border-bottom: 1px solid var(--calc-rule); text-align: left; vertical-align: baseline;
}
#calcApp table.data thead th {
  font-family: var(--font-display); font-size: 11px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; color: var(--faint);
  border-bottom: 1px solid var(--line-strong); padding-bottom: 9px;
}
#calcApp table.data th:first-child, #calcApp table.data td:first-child { padding-left: 0; }
#calcApp table.data th:last-child, #calcApp table.data td:last-child { padding-right: 0; }
#calcApp table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#calcApp table.data tbody tr:last-child th, #calcApp table.data tbody tr:last-child td { border-bottom: 0; }
#calcApp table.data .outcome { font-family: var(--font-display); font-weight: 600; color: #0f1b2d; font-size: 14.5px; }
#calcApp table.data .outcome small {
  display: block; font-family: var(--font-body); font-weight: 400; font-size: 12px;
  color: var(--faint); letter-spacing: 0; margin-top: 2px;
}

#calcApp .risk-primary { font-family: var(--font-display); font-size: 27px; font-weight: 700; color: #0f1b2d; }
#calcApp .risk-secondary { font-size: 17px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
#calcApp .risk-na { font-size: 13px; color: var(--faint); }

/* status markers */
#calcApp .status {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-display); font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
#calcApp .status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
#calcApp .status.calm { color: var(--calc-calm); }
#calcApp .status.calm::before { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#calcApp .status.act { color: var(--calc-act); }
#calcApp .status.act::before { background: #d97706; }
#calcApp .status.act.strong::before { box-shadow: 0 0 0 3px var(--calc-act-soft); }

/* ---------- context figures ---------- */

#calcApp .context { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
#calcApp .context > div {
  background: var(--ink-700); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px 26px;
}
#calcApp .context .label { display: block; margin-bottom: 10px; }
#calcApp .context .fig { font-family: var(--font-display); font-size: 2rem; font-weight: 700; color: #0f1b2d; line-height: 1; }
#calcApp .context .fig span { font-family: var(--font-body); font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 6px; }
#calcApp .context .exp { font-size: 13px; color: var(--muted); margin-top: 12px; line-height: 1.55; }

/* ---------- frequency ---------- */

#calcApp .freq .caption { font-size: 14.5px; color: var(--muted); margin-bottom: 12px; }
#calcApp .freq .caption b { color: var(--calc-act); font-weight: 600; }
#calcApp .dots { display: grid; grid-template-columns: repeat(25, 1fr); gap: 5px; max-width: 400px; }
#calcApp .dots i { aspect-ratio: 1; border-radius: 50%; background: var(--ink-500); }
#calcApp .dots i.on { background: var(--accent); }

/* ---------- recommendations ---------- */

#calcApp .rec { padding: 15px 0 15px 18px; border-left: 2px solid var(--line-strong); }
#calcApp .rec + .rec { border-top: 1px solid var(--calc-rule); }
#calcApp .rec.recommended { border-left-color: var(--accent); }
#calcApp .rec.reasonable, #calcApp .rec.consider { border-left-color: var(--calc-act-line); }
#calcApp .rec.lifestyle { border-left-color: var(--line-strong); }
#calcApp .rec .tag { display: block; margin-bottom: 6px; }
#calcApp .rec.recommended .tag { color: var(--calc-calm); }
#calcApp .rec.reasonable .tag, #calcApp .rec.consider .tag { color: var(--calc-act); }
#calcApp .rec p { font-size: 14.5px; color: var(--text); max-width: 76ch; }

#calcApp .context-line { font-size: 14px; color: var(--muted); margin-bottom: 16px; max-width: 76ch; }
#calcApp .context-line strong { color: #0f1b2d; font-weight: 600; }

/* ---------- benefit ---------- */

#calcApp .benefit-note { font-size: 13px; color: var(--calc-act); padding: 4px 0 12px; max-width: 74ch; }
#calcApp .excluded { padding: 14px 0 14px 18px; border-left: 2px solid var(--line); }
#calcApp .excluded .who { font-family: var(--font-display); font-weight: 600; font-size: 14px; color: #0f1b2d; }
#calcApp .excluded p { font-size: 13.5px; color: var(--muted); margin-top: 4px; max-width: 76ch; }

#calcApp .method {
  background: var(--ink-700); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 16px 20px; margin-bottom: 24px;
  font-size: 14px; color: var(--muted); max-width: 80ch;
}
#calcApp .method strong { color: #0f1b2d; }
#calcApp .method code { font-family: var(--font-body); font-weight: 600; color: var(--accent); }

/* ---------- disclosures ---------- */

#calcApp details.more { border-top: 1px solid var(--calc-rule); }
#calcApp details.more > summary {
  cursor: pointer; list-style: none; padding: 16px 0;
  font-family: var(--font-display); font-size: 15.5px; font-weight: 600; color: #0f1b2d;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  transition: color .25s;
}
#calcApp details.more > summary::-webkit-details-marker { display: none; }
#calcApp details.more > summary::after {
  content: ""; width: 8px; height: 8px; flex: 0 0 auto;
  border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  transform: rotate(45deg) translate(-2px, -2px); transition: transform .3s var(--ease);
}
#calcApp details.more[open] > summary::after { transform: rotate(-135deg) translate(-3px, -3px); }
#calcApp details.more > summary:hover { color: var(--accent); }
#calcApp details.more .inner { padding: 2px 0 28px; }

/* a disclosure standing in for a section heading */
#calcApp details.more--section { border-top: 0; }
#calcApp details.more--section > summary {
  font-size: 1.3rem; padding: 0 0 11px; border-bottom: 1px solid var(--calc-rule);
}
#calcApp details.more--section > summary .count {
  font-family: var(--font-body); font-size: 13px; font-weight: 400; color: var(--faint);
}
#calcApp details.more--section[open] > summary { margin-bottom: 8px; }
#calcApp details.more--section .inner { padding-bottom: 0; }

/* ---------- references ---------- */

#calcApp .reflist { list-style: none; margin: 0; padding: 0; counter-reset: ref; }
#calcApp .reflist > li {
  position: relative; padding: 14px 0 14px 36px; border-bottom: 1px solid var(--calc-rule);
  font-size: 13.5px; color: var(--muted); line-height: 1.6;
}
#calcApp .reflist > li:last-child { border-bottom: 0; }
#calcApp .reflist > li::before {
  counter-increment: ref; content: counter(ref);
  position: absolute; left: 0; top: 15px;
  font-family: var(--font-display); font-weight: 600; font-size: 12.5px;
  color: var(--accent); font-variant-numeric: tabular-nums;
}
#calcApp .reflist .t { color: var(--text); font-weight: 500; }
#calcApp .reflist a { color: var(--accent); word-break: break-word; }
#calcApp .reflist a:hover { text-decoration: underline; }
#calcApp .reflist .role { display: block; margin-top: 4px; font-size: 12.5px; color: var(--faint); }

/* ---------- tooltip ---------- */

#calcApp .tip { position: relative; display: inline-block; }
#calcApp .tip > .anchor {
  border-bottom: 1px dotted var(--accent-line); color: var(--accent); cursor: help; font-weight: 600;
}
#calcApp .tip > .anchor::after {
  content: "?"; display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; margin-left: 5px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 9.5px; font-weight: 700; vertical-align: 1px;
}
#calcApp .tip > .pop {
  /* An invisible absolute panel still enlarges a horizontally scrollable table's vertical range. */
  display: none;
  position: absolute; z-index: 40; left: 0; top: calc(100% + 9px); width: min(400px, 84vw);
  background: var(--ink-700); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 17px 19px; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .2s var(--ease), transform .2s var(--ease), visibility .2s;
  font-weight: 400; color: var(--text); text-align: left;
}
#calcApp .tip:hover > .pop, #calcApp .tip:focus-within > .pop, #calcApp .tip.open > .pop {
  display: block; opacity: 1; visibility: visible; transform: translateY(0);
}
#calcApp .tip .pop h3 { font-size: 14.5px; margin-bottom: 4px; }
#calcApp .tip .pop .lead { font-size: 12.5px; color: var(--muted); margin-bottom: 11px; max-width: none; }
#calcApp .tip .pop table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#calcApp .tip .pop td { padding: 5px 0; border-bottom: 1px solid var(--calc-rule); }
#calcApp .tip .pop tr:last-child td { border-bottom: 0; }
#calcApp .tip .pop td:last-child { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 12px; }
#calcApp .tip .pop .foot { font-size: 12px; color: var(--faint); margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--calc-rule); }
/* On a phone the panel becomes a pinned sheet. Anchoring it to the trigger
   pushed it past the viewport edge whenever the trigger sat right of centre,
   and the trigger can also sit inside a horizontally scrolled table. */
@media (max-width: 620px) {
  #calcApp .tip > .pop {
    position: fixed; left: 16px; right: 16px; width: auto;
    top: auto; bottom: 16px;
    transform: translateY(10px);
    max-height: 62vh; overflow-y: auto;
    box-shadow: 0 -8px 40px -12px rgba(15, 23, 42, .3);
  }
  #calcApp .tip:hover > .pop, #calcApp .tip:focus-within > .pop, #calcApp .tip.open > .pop {
    transform: translateY(0);
  }
}

/* ---------- messages ---------- */

#calcApp .msg { padding: 14px 18px; margin-bottom: 20px; font-size: 14px; border-radius: var(--radius-sm); border: 1px solid; }
#calcApp .msg ul { margin: 7px 0 0; padding-left: 20px; }
#calcApp .msg.error { border-color: rgba(180, 45, 32, .35); background: rgba(220, 60, 45, .07); color: #a3271b; }
#calcApp .msg.warn { border-color: var(--calc-act-line); background: var(--calc-act-soft); color: var(--calc-act); }

/* ---------- narrow screens ---------- */

@media (max-width: 900px) {
  #calcApp .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  #calcApp fieldset { padding: 18px; }
  #calcApp .grid { grid-template-columns: 1fr; }
  #calcApp table.data th, #calcApp table.data td { padding: 10px 9px; }
  #calcApp .risk-primary { font-size: 22px; }
  #calcApp .dots { grid-template-columns: repeat(20, 1fr); }
  #calcApp .patient-strip { flex-direction: column; align-items: stretch; }
  #calcApp .patient-strip .btn-quiet { align-self: flex-start; }
}

/* ==========================================================================
   Print — the site chrome drops away, the report keeps its own masthead
   ========================================================================== */

.print-mast { display: none; }

@media print {
  body::before { display: none; }
  .site-header, .footer, .no-print { display: none !important; }
  #calcApp { font-size: 10.5pt; }
  #calcApp .c-sec { break-inside: avoid; padding-top: 18px; }
  #calcApp .patient-strip, #calcApp .context > div, #calcApp .method { box-shadow: none; }
  #calcApp .tip > .pop { display: none; }
  /* print the contents of collapsed disclosures */
  #calcApp details > summary { display: none; }
  #calcApp details > *:not(summary) { display: block !important; }
  #calcApp details.helper { display: none; }
  #calcApp details.more--section > summary { display: block; }
  #calcApp details.more--section > summary::after { display: none; }
  #calcApp .dots i, #calcApp .status::before {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  #calcApp a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 7.5pt; color: #666; }
  .print-mast { display: block !important; border-bottom: 2px solid var(--accent); padding-bottom: 10px; margin-bottom: 16px; }
  .print-mast strong { font-family: var(--font-display); font-size: 13pt; color: #0f1b2d; }
  .print-mast span { display: block; font-size: 9pt; color: var(--muted); margin-top: 3px; }
}
