/*
 * styles.css — MaudeDash
 * ======================
 * A clinical-research aesthetic: quiet neutrals, one structural blue, and a
 * severity ramp reserved for the FDA harm categories so colour always carries
 * meaning. Light and dark are both first-class.
 */

/* ------------------------------------------------------------------- tokens */

:root {
  /* Brand */
  --brand-900: #072A42;
  --brand-800: #0B3C5D;
  --brand-700: #12507A;
  --brand-600: #1D6A96;
  --brand-500: #2E86B8;
  --brand-100: #DCEBF5;
  --brand-050: #F1F7FB;

  --accent-600: #0E8C7D;
  --accent-500: #12A594;
  --accent-100: #D6F2EE;

  /* FDA 21 CFR 803.3 harm ramp — ordered by clinical severity */
  --harm-death:         #8B1A1A;
  --harm-life:          #C0392B;
  --harm-hosp:          #D9740B;
  --harm-disability:    #7C3AED;
  --harm-congenital:    #0E7490;
  --harm-intervention:  #2563EB;
  --harm-other:         #64748B;
  --harm-serious:       #0B3C5D;

  --ok: #15803D;
  --warn: #B45309;
  --danger: #B91C1C;
  --signal: #9D174D;

  /* Surfaces (light) */
  --bg: #F6F8FA;
  --surface: #FFFFFF;
  --surface-2: #FBFCFD;
  --surface-3: #F1F4F7;
  --border: #DCE3EA;
  --border-strong: #C3CDD8;
  --text: #16232E;
  --text-2: #4A5C6C;
  --text-3: #74869A;
  --shadow: 0 1px 2px rgba(16, 35, 51, .05), 0 2px 8px rgba(16, 35, 51, .04);
  --shadow-lg: 0 4px 12px rgba(16, 35, 51, .08), 0 12px 32px rgba(16, 35, 51, .06);

  --sidebar-w: 310px;
  --radius: 8px;
  --radius-lg: 12px;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
          "Helvetica Neue", Arial, sans-serif;
}

/*
 * Dark palette. The inline script in <head> stamps data-theme on <html> before
 * first paint (from localStorage, else the OS preference), so this attribute
 * selector is the single source of truth — no duplicated token block and no
 * light-theme flash.
 */
:root[data-theme="dark"] {
    --bg: #0D1620;
    --surface: #141F2B;
    --surface-2: #18242F;
    --surface-3: #1E2C39;
    --border: #263542;
    --border-strong: #35485A;
    --text: #E4EBF1;
    --text-2: #A8B8C6;
    --text-3: #7A8B9B;
    --brand-100: #17324A;
    --brand-050: #112537;
    --accent-100: #10352F;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .25);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, .35), 0 12px 32px rgba(0, 0, 0, .3);
    --harm-death: #E05252;
    --harm-life: #EF6D5E;
    --harm-hosp: #F0A04B;
    --harm-disability: #A78BFA;
    --harm-congenital: #22A5C0;
    --harm-intervention: #5B94F5;
    --harm-other: #94A3B8;
    --harm-serious: #6BA8D4;
    --ok: #4ADE80;
    --warn: #FBBF24;
    --danger: #F87171;
    --signal: #F472B6;
}

/* ------------------------------------------------------------------- reset */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0 0 .75em; }
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre { font-family: var(--mono); font-size: .875em; }

/* Numerals line up in every table and metric. */
.num, table td, table th, .metric-value, .stat-value {
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ layout */

.app { display: flex; min-height: 100vh; }

/* ----- sidebar ----- */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 5;
}
.brand-logo { width: 34px; height: 34px; flex: 0 0 34px; }
.brand-text { min-width: 0; }
.brand-name {
  font-size: 16px; font-weight: 700; letter-spacing: -.02em;
  color: var(--text); line-height: 1.15;
}
.brand-name .dash { color: var(--accent-500); }
.brand-tag {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); font-weight: 600;
}

.sidebar-body { padding: 4px 18px 24px; }

.field { margin: 14px 0; }
.field > label {
  display: block; font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-2); margin-bottom: 5px;
}
.field .hint { font-size: 11.5px; color: var(--text-3); margin-top: 4px; line-height: 1.4; }

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 18%, transparent);
}
input::placeholder { color: var(--text-3); }

.checks { display: flex; flex-direction: column; gap: 7px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { margin: 2px 0 0; accent-color: var(--brand-600); flex: 0 0 auto; }
.check span { color: var(--text-2); }

.section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-3);
  margin: 22px 0 2px; padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* year range: two coupled sliders */
.range-row { display: flex; align-items: center; gap: 8px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--brand-600); min-width: 0; }
.range-val {
  font-family: var(--mono); font-size: 12px; color: var(--text);
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 6px; min-width: 46px; text-align: center;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; font: inherit; font-size: 13px; font-weight: 600;
  color: #fff; background: var(--brand-700);
  border: 1px solid var(--brand-800); border-radius: 6px;
  cursor: pointer; transition: background .12s, transform .06s;
  width: 100%;
}
.btn:hover { background: var(--brand-600); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary {
  color: var(--text); background: var(--surface-2);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-3); }
.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.btn-row .btn { width: auto; flex: 1; }

/* ----- main ----- */

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 15px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.vintage {
  font-size: 11.5px; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
}
.vintage .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok); flex: 0 0 6px;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0;
  color: var(--text-2); background: transparent;
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

.content { padding: 18px 22px 60px; flex: 1; }

/* ----- KPI band ----- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 13px;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-3);
  display: flex; align-items: center; gap: 4px;
}
.kpi-value {
  font-size: 21px; font-weight: 700; letter-spacing: -.02em;
  color: var(--text); margin-top: 3px; font-variant-numeric: tabular-nums;
}
.kpi-sub { font-size: 11px; color: var(--text-3); margin-top: 1px; }
.kpi.accent .kpi-value { color: var(--brand-700); }
.kpi.harm .kpi-value { color: var(--harm-death); }

/* ----- tabs ----- */

.tabgroups { border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabgroup-row { display: flex; gap: 4px; padding-bottom: 6px; flex-wrap: wrap; }
.tabgroup {
  display: flex; align-items: center; gap: 2px;
  padding: 2px; background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 8px;
}
.tabgroup-name {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-3);
  padding: 0 7px 0 5px; white-space: nowrap;
}
.tab {
  padding: 5px 10px; font-size: 12.5px; font-weight: 500;
  color: var(--text-2); background: transparent;
  border: none; border-radius: 6px; cursor: pointer; white-space: nowrap;
  font-family: inherit;
}
.tab:hover { background: var(--surface); color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--brand-700); color: #fff; font-weight: 600;
}

/* ----- panels & cards ----- */

.panel { display: none; }
.panel.active { display: block; animation: fade .16s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; } }

.panel-head { margin-bottom: 12px; }
.panel-head h2 { font-size: 17px; }
.panel-head .desc {
  font-size: 12.5px; color: var(--text-2); margin-top: 3px;
  max-width: 78ch; line-height: 1.5;
}

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 14px;
}
.card-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  margin-bottom: 10px; display: flex; align-items: center; gap: 8px;
}
.card-title .count { font-weight: 400; color: var(--text-3); font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
@media (max-width: 1100px) { .grid-2, .grid-2-1 { grid-template-columns: 1fr; } }

.chart { width: 100%; min-height: 300px; }

/* ----- tables ----- */

.table-wrap {
  overflow: auto; max-height: 560px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-3); color: var(--text-2);
  font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; text-align: left;
  padding: 8px 10px; border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
tbody td {
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--brand-050); }
td.right, th.right { text-align: right; }
td.narrative {
  max-width: 620px; min-width: 320px; white-space: pre-wrap;
  font-size: 12px; color: var(--text-2); line-height: 1.45;
}
td.mono { font-family: var(--mono); font-size: 11.5px; }

/* ----- type-ahead pickers ----- */

.ac-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 3px); z-index: 30;
  max-height: 296px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.ac-item {
  padding: 7px 10px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.on { background: var(--brand-050); }
.ac-main { display: flex; align-items: baseline; gap: 7px; }
.ac-code {
  font-family: var(--mono); font-size: 11.5px; font-weight: 700;
  color: var(--brand-700); background: var(--brand-100);
  padding: 1px 5px; border-radius: 4px; flex: 0 0 auto;
}
.ac-label { font-size: 12.5px; color: var(--text); line-height: 1.3; }
.ac-meta {
  font-size: 11px; color: var(--text-3); margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* ----- sortable table headers ----- */

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: var(--brand-100); color: var(--text); }
th.sortable:focus-visible {
  outline: 2px solid var(--brand-500); outline-offset: -2px;
}
th.sorted { color: var(--brand-700); }
:root[data-theme="dark"] th.sorted { color: var(--brand-500); }

/* ----- badges & notes ----- */

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 20px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; white-space: nowrap;
}
.badge-signal { background: var(--signal); color: #fff; }
.badge-none { background: var(--surface-3); color: var(--text-3); }
.badge-warn { background: var(--warn); color: #fff; }
.badge-ok { background: var(--ok); color: #fff; }

.note {
  display: flex; gap: 9px; padding: 10px 12px;
  border-radius: var(--radius); font-size: 12.5px; line-height: 1.5;
  border: 1px solid; margin-bottom: 12px;
}
.note-icon { flex: 0 0 auto; font-size: 13px; line-height: 1.35; }
.note-info { background: var(--brand-050); border-color: var(--brand-100); color: var(--text-2); }
.note-warn {
  background: color-mix(in srgb, var(--warn) 9%, transparent);
  border-color: color-mix(in srgb, var(--warn) 32%, transparent);
  color: var(--text-2);
}
.note-caveat {
  background: var(--surface-3); border-color: var(--border);
  color: var(--text-2); font-size: 12px;
}
.note strong { color: var(--text); }

/* ----- empty / loading states ----- */

.empty {
  text-align: center; padding: 52px 24px; color: var(--text-3);
}
.empty-icon { font-size: 30px; opacity: .5; margin-bottom: 10px; }
.empty h3 { font-size: 15px; color: var(--text-2); margin-bottom: 6px; }
.empty p { font-size: 13px; max-width: 52ch; margin: 0 auto .5em; }

.examples {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; margin-top: 16px;
}
.example {
  padding: 7px 12px; font-size: 12.5px; text-align: left;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 20px;
  cursor: pointer; font-family: inherit;
}
.example:hover { border-color: var(--brand-500); background: var(--brand-050); }
.example b { color: var(--brand-700); font-weight: 600; }

.spinner {
  width: 15px; height: 15px; flex: 0 0 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand-600);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading {
  display: flex; align-items: flex-start; justify-content: center; gap: 11px;
  padding: 44px 24px; color: var(--text-2); font-size: 13.5px; text-align: left;
}
.loading .spinner { margin-top: 2px; }
.loading-detail {
  font-size: 12.5px; color: var(--text-3); margin-top: 5px;
  max-width: 56ch; line-height: 1.5;
}

.busy {
  position: fixed; bottom: 16px; right: 18px; z-index: 60;
  display: none; align-items: center; gap: 9px;
  padding: 9px 14px; font-size: 12.5px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 20px; box-shadow: var(--shadow-lg);
}
.busy.on { display: flex; }

/* ----- boot screen ----- */

.boot {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; padding: 24px;
  background: var(--bg); text-align: center;
}
.boot.hidden { display: none; }
.boot-logo { width: 60px; height: 60px; }
.boot-name { font-size: 25px; font-weight: 700; letter-spacing: -.025em; }
.boot-name .dash { color: var(--accent-500); }
.boot-sub { font-size: 13px; color: var(--text-2); max-width: 50ch; }
.boot-status {
  display: flex; align-items: center; gap: 9px;
  font-size: 12.5px; color: var(--text-3); margin-top: 4px;
}
.boot-error {
  max-width: 62ch; padding: 14px; text-align: left;
  font-size: 12.5px; line-height: 1.55;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--danger); border-radius: var(--radius);
}
.boot-error h3 { color: var(--danger); font-size: 13.5px; margin-bottom: 6px; }
.boot-error pre {
  margin: 8px 0 0; padding: 8px; overflow-x: auto;
  background: var(--surface-3); border-radius: 5px; font-size: 11px;
}

/* ----- modal ----- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  display: none; align-items: center; justify-content: center; padding: 24px;
  background: rgba(7, 42, 66, .45); backdrop-filter: blur(2px);
}
.modal-backdrop.on { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  max-width: 760px; width: 100%; max-height: 86vh; overflow-y: auto;
}
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface);
}
.modal-head h2 { font-size: 15px; flex: 1; }
.modal-body { padding: 18px; font-size: 13px; line-height: 1.6; color: var(--text-2); }
.modal-body h3 {
  font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3); margin: 18px 0 7px;
}
.modal-body h3:first-child { margin-top: 0; }
.modal-body dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; }
.modal-body dt { color: var(--text-3); font-size: 12px; }
.modal-body dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; }
.cite {
  padding: 11px; font-family: var(--mono); font-size: 11.5px; line-height: 1.6;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); white-space: pre-wrap;
  word-break: break-word;
}

/* ----- methods / STROBE prose ----- */

.prose { max-width: 82ch; font-size: 13.5px; line-height: 1.68; color: var(--text-2); }
.prose h3 { color: var(--text); font-size: 14px; margin: 20px 0 8px; }
.prose strong { color: var(--text); }
.prose pre {
  padding: 11px; overflow-x: auto; font-size: 11.5px; line-height: 1.55;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
}

/* ----- word cloud ----- */

.cloud {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 4px 11px; padding: 18px; line-height: 1.35;
  min-height: 240px;
}
.cloud span { cursor: default; }

/* ----- responsive ----- */

.sidebar-toggle { display: none; }

@media (max-width: 880px) {
  .app { flex-direction: column; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow-lg); height: 100vh;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; }
  .content { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); }
  .kpi-value { font-size: 18px; }
}

/* Wide content must scroll inside its own box, never the page. */
.scroll-x { overflow-x: auto; }

@media print {
  .sidebar, .topbar, .tabgroups, .busy { display: none !important; }
  .content { padding: 0; }
  .card { break-inside: avoid; box-shadow: none; }
}
