/* ARPI Treatment Effect Calculator
   Calm clinical palette with a single teal data series and clear status colors. */

:root {
  color-scheme: light;

  /* Surfaces and ink */
  --page: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f7fafb;
  --surface-tint: #f1f8f9;
  --field-bg: #ffffff;
  --border: #d7e0e6;
  --border-strong: #7f8e9a;
  --ink: #192735;
  --ink-2: #3c4e5e;
  --muted: #617080;

  /* Functional color */
  --series: #0b6b78;
  --series-strong: #075562;
  --series-soft: rgba(11, 107, 120, 0.13);
  --patient: #27445b;
  --good: #26744f;
  --bad: #b33a43;

  /* Chart chrome */
  --grid: #e4ebef;
  --axis: #a9b7c1;

  /* Feedback */
  --warn-bg: #fff7e6;
  --warn-border: #b76b00;
  --warn-ink: #4a3200;
  --error: #b33a43;

  /* Shape and motion */
  --radius: 12px;
  --radius-sm: 7px;
  --shadow: 0 10px 28px rgba(32, 53, 68, 0.07);
  --focus-ring: 0 0 0 3px rgba(11, 107, 120, 0.22);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

main {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 38px 0 48px;
}

/* ---------- Header ---------- */

.site-header {
  margin-bottom: 24px;
  padding: 0 0 22px;
  border-bottom: 1px solid var(--border);
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--series-strong);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 9px;
  font-size: clamp(1.55rem, 3.2vw, 2rem);
  font-weight: 760;
  letter-spacing: -0.025em;
}

.subtitle {
  max-width: 68ch;
  margin: 0;
  color: var(--ink-2);
  font-size: 0.96rem;
}

.development-note {
  max-width: 82ch;
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.development-note strong { color: var(--ink-2); }

.research-note {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 17px 0 0;
  padding: 9px 12px;
  border: 1px solid #c8dbdf;
  border-radius: 999px;
  background: var(--surface-tint);
  color: var(--ink-2);
  font-size: 0.8rem;
}

.research-note-label {
  color: var(--series-strong);
  font-weight: 750;
}

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.02fr);
  gap: 20px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card-wide { margin-top: 20px; }

.results-card {
  position: relative;
  overflow: hidden;
  border-top: 4px solid var(--series);
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.predictor-count,
.estimate-badge {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.estimate-badge {
  border-color: #b9d6da;
  background: var(--surface-tint);
  color: var(--series-strong);
}

h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
  font-weight: 750;
  letter-spacing: -0.012em;
}

.card-subtitle {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.82rem;
}

/* ---------- Form ---------- */

.field-group { border: 0; margin: 0 0 6px; padding: 0; }
.field-group + .field-group { margin-top: 16px; }

.field-group legend {
  padding: 0;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field { display: grid; gap: 6px; }

.field label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  color: var(--ink-2);
  font-size: 0.82rem;
  font-weight: 600;
}

.unit-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-tint);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 750;
  line-height: 1.1;
}

input {
  width: 100%;
  height: 42px;
  min-height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--field-bg);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  padding: 8px 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

input:hover { border-color: var(--series); background-color: var(--surface-tint); }

input[aria-invalid="true"] {
  border-color: var(--error);
  background: #fff8f8;
}

input:focus-visible,
button:focus-visible {
  outline: none;
  border-color: var(--series);
  box-shadow: var(--focus-ring);
}

.select-control {
  position: relative;
}

.select-native {
  display: none;
}

.select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 42px;
  padding: 8px 12px 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--field-bg);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.select-trigger:hover,
.select-trigger[aria-expanded="true"] {
  border-color: var(--series);
  background-color: var(--surface-tint);
}

.select-trigger::after {
  width: 7px;
  height: 7px;
  margin-left: 12px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  content: "";
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.15s ease;
}

.select-trigger[aria-expanded="true"]::after {
  transform: translateY(2px) rotate(225deg);
}

.select-menu {
  position: absolute;
  z-index: 10;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  display: grid;
  gap: 3px;
  padding: 4px;
  border: 1px solid #9fb6bd;
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: 0 12px 24px rgba(32, 53, 68, 0.16);
}

.select-menu[hidden] { display: none; }

.select-option {
  width: 100%;
  min-height: 36px;
  padding: 7px 9px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
}

.select-option:hover,
.select-option:focus-visible {
  background: var(--surface-tint);
  color: var(--series-strong);
}

.select-option[aria-selected="true"] {
  background: var(--series-soft);
  color: var(--series-strong);
  font-weight: 700;
}

.field-note {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.4;
}

.form-footer {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.form-helper,
.input-status,
.result-status {
  margin: 0;
  font-size: 0.78rem;
}

.form-helper { color: var(--muted); }

.input-status,
.result-status {
  min-height: 1.2em;
  color: var(--error);
  font-weight: 650;
}

/* ---------- Result tiles ---------- */

.results-stack { display: grid; gap: 14px; }

.result-status:not(:empty) + .results-stack { opacity: 0.34; }

.hero {
  border: 1px solid var(--border);
  border-top: 3px solid var(--series);
  border-radius: var(--radius);
  background: var(--surface-tint);
  padding: 18px 20px;
}

.tile-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.hero-value {
  margin: 0;
  font-size: clamp(2.1rem, 6vw, 2.85rem);
  font-weight: 780;
  line-height: 1.05;
  letter-spacing: 0;
  color: var(--ink);
}

.hero-ci,
.tile-ci {
  margin: 8px 0 0;
  color: var(--ink-2);
  font-size: 0.86rem;
}

.direction-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
  background: var(--surface);
  border: 1px solid var(--border);
}

.direction-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.dir-good { color: var(--good); }
.dir-bad { color: var(--bad); }
.dir-null { color: var(--muted); }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.tile {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  padding: 14px 15px;
}

.tile-value {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ink);
}

.warning {
  display: none;
  margin-top: 4px;
  padding: 11px 14px;
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-sm);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 0.83rem;
}

.warning.visible { display: block; }

/* ---------- Chart ---------- */

.chart-figure { margin: 0; }

.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
}

.segmented button {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented button:hover { color: var(--ink); }

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--series-strong);
  box-shadow: 0 1px 3px rgba(32, 53, 68, 0.11);
}

.chart-wrap {
  position: relative;
  overflow: visible;
  overflow-anchor: none;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fcfdfd;
}

.chart-wrap svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.viz-band { fill: var(--series-soft); stroke: none; }
.viz-line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-grid { stroke: var(--grid); stroke-width: 1; }
.viz-axis { stroke: var(--axis); stroke-width: 1; }
.viz-ref { stroke: var(--axis); stroke-width: 1; }
.viz-tick { fill: var(--muted); font-size: 13px; }
.viz-tick-num { fill: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.viz-axis-title { fill: var(--ink-2); font-size: 13px; font-weight: 650; }
.viz-ref-label { fill: var(--muted); font-size: 12px; }
.viz-favor-good { fill: var(--good); font-size: 12px; font-weight: 650; }
.viz-favor-bad { fill: var(--bad); font-size: 12px; font-weight: 650; }

.viz-patient-guide { stroke: var(--patient); stroke-width: 1.4; stroke-dasharray: 3 3; }
.viz-patient-dot { fill: var(--patient); stroke: var(--surface); stroke-width: 2; }
.viz-patient-callout-bg { fill: var(--surface); stroke: var(--border); stroke-width: 1; }
.viz-patient-label { fill: var(--patient); font-size: 12.5px; font-weight: 700; }
.viz-patient-label-sub { fill: var(--ink-2); font-size: 12px; }

.viz-crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; }
.viz-hover-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; opacity: 0; }

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 140px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.8rem;
  color: var(--ink);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -112%);
  transition: opacity 0.1s ease;
}

.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-value { font-weight: 700; font-size: 0.95rem; }
.chart-tooltip .tt-ci { color: var(--ink-2); font-size: 0.76rem; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- Model information ---------- */

.transparency-intro {
  max-width: 84ch;
  margin: 8px 0 16px;
  color: var(--ink-2);
  font-size: 0.88rem;
}

.model-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}

.model-facts > div {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.model-facts dt {
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 700;
}

.model-facts dd {
  margin: 0;
  color: var(--ink-2);
  font-size: 0.8rem;
}

.validation-callout {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-left: 3px solid var(--series);
  background: var(--surface-soft);
  color: var(--ink-2);
  font-size: 0.82rem;
}

.validation-callout strong { color: var(--ink); }

.privacy-callout {
  padding: 13px 15px;
  border: 1px solid #c8dbdf;
  border-radius: var(--radius-sm);
  background: var(--surface-tint);
  color: var(--ink-2);
  font-size: 0.84rem;
}

.privacy-callout strong {
  display: block;
  margin-bottom: 2px;
  color: var(--series-strong);
}

.formula-details {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.formula-details summary {
  padding: 13px 15px;
  color: var(--series-strong);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 700;
  touch-action: manipulation;
}

.formula-details[open] summary { border-bottom: 1px solid var(--border); }

.formula-content {
  padding: 16px;
  color: var(--ink-2);
  font-size: 0.84rem;
}

.formula-content > :first-child { margin-top: 0; }
.formula-content > :last-child { margin-bottom: 0; }

.formula-content h3 {
  margin: 20px 0 8px;
  color: var(--ink);
  font-size: 0.9rem;
}

.formula-block {
  margin: 14px 0;
  padding: 12px 14px;
  border-left: 3px solid var(--series);
  background: var(--surface-soft);
  overflow-wrap: anywhere;
}

.formula-block p { margin: 0; }
.formula-block p + p { margin-top: 7px; }

.formula-content code {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
}

.formula-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  -webkit-overflow-scrolling: touch;
}

.formula-table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.formula-table caption {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: left;
}

.formula-table th,
.formula-table td {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

.formula-table th:first-child { text-align: left; }
.formula-table thead th { background: var(--surface-soft); color: var(--ink); }
.formula-table tbody th { color: var(--ink-2); font-weight: 600; }

/* ---------- Status blocks ---------- */

#loading,
#error {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow);
}

#error { display: none; color: var(--error); border-color: var(--error); }

.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  max-width: 1px;
  height: 1px;
  max-height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

table.sr-only,
.sr-only thead,
.sr-only tbody,
.sr-only tr,
.sr-only th,
.sr-only td,
.sr-only caption {
  max-width: 1px;
  padding: 0;
  border: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  main { width: min(100% - 28px, 760px); padding-top: 26px; }
  .layout,
  .input-grid,
  .kpi-row { grid-template-columns: 1fr; }

  .card { padding: 20px; }
  .card-wide { margin-top: 16px; }
  .chart-head { align-items: flex-start; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding-inline: 8px; }
}

@media (max-width: 600px) {
  .model-facts { grid-template-columns: 1fr; }
  .results-card .card-heading {
    align-items: flex-start;
    flex-direction: column;
  }
  .results-card .card-heading > div { width: 100%; }
}

@media (max-width: 430px) {
  .research-note { border-radius: var(--radius-sm); }
  .card-heading { gap: 10px; }
  .predictor-count,
  .estimate-badge { font-size: 0.68rem; }
  .chart-wrap { margin-inline: -4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
