/* ab-phr — visual system matched to the Evidently dashboard:
   light grey page, white section cards, navy header + tab bar, tabular numerals. */

:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --ink: #2b3440;
  --soft: #5a6b7b;
  --faint: #98a3af;
  --hairline: #e4e8ee;
  --navy: #1f4e79;
  --navy-2: #4472c4;
  --tab-bar: #163d61;
  --gold: #ffc000;
  --green: #70ad47;
  --red: #c0392b;
  --sans: "Source Sans 3", "Segoe UI", tahoma, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.container { max-width: 1280px; margin: 0 auto; padding: 20px; }

/* ---------- gate ---------- */
#gate {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
}
.gate-card {
  background: var(--card);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 28px 32px;
  width: 22rem;
  display: flex; flex-direction: column; gap: 14px;
}
.gate-card h1 { color: var(--navy); font-size: 1.35em; font-weight: 700; }
.gate-card input[type="password"] {
  font-size: 1em; padding: 9px 11px;
  border: 1.5px solid #c8d1e0; border-radius: 6px;
  font-family: var(--sans);
}
.gate-card input:focus { outline: 2px solid var(--navy-2); border-color: var(--navy-2); }
button {
  font-family: var(--sans); font-weight: 600; font-size: 0.92em;
  padding: 9px 16px;
  background: var(--navy); color: #fff;
  border: none; border-radius: 6px;
  cursor: pointer;
}
button:hover { background: var(--navy-2); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.gate-error { color: var(--red); font-size: 0.85em; min-height: 1.2em; }

/* ---------- header + tabs ---------- */
#app { display: none; }
#app.ready { display: block; }

header {
  background: linear-gradient(135deg, #1f4e79 0%, #2d6a9f 55%, #4472c4 100%);
  color: #fff;
  padding: 22px 28px 18px;
  border-radius: 10px 10px 0 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  display: flex; align-items: baseline; gap: 24px; flex-wrap: wrap;
}
header h1 { font-size: 1.6em; font-weight: 700; letter-spacing: -0.01em; }
header .range-ctl {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  font-size: 0.82em; opacity: 0.92;
}
.range-ctl input[type="date"] {
  font-family: var(--sans); font-size: 0.95em;
  border: none; border-radius: 4px; padding: 4px 6px;
  background: rgba(255,255,255,0.92); color: var(--ink);
}

.tab-nav {
  display: flex;
  background: var(--tab-bar);
  border-radius: 0 0 10px 10px;
  overflow: hidden;
  margin-bottom: 22px;
}
.tab-btn {
  padding: 12px 26px;
  background: transparent;
  border: none; border-radius: 0;
  color: rgba(255,255,255,0.6);
  font-size: 0.9em; font-weight: 600;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}
.tab-btn:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.9); }
.tab-btn.active { background: rgba(255,255,255,0.1); color: #fff; border-bottom-color: var(--gold); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- section cards ---------- */
.section {
  background: var(--card);
  padding: 22px 24px;
  border-radius: 10px;
  margin-bottom: 22px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.section-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  border-bottom: 2px solid var(--hairline); padding-bottom: 10px; margin-bottom: 14px; }
.section-head h2 { color: var(--navy); font-size: 1.15em; font-weight: 700; }
.section-key { color: var(--soft); font-size: 0.86em; }

.controls { display: flex; flex-wrap: wrap; gap: 12px 22px; align-items: end; margin-bottom: 12px; }
.ctl { display: flex; flex-direction: column; gap: 5px; }
.ctl label {
  font-size: 0.74em; font-weight: 600; color: var(--navy);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.ctl select, .ctl input[type="range"] {
  font-family: var(--sans); font-size: 0.92em;
  border: 1px solid #c8d1e0; border-radius: 6px;
  background: #fff; color: var(--ink);
  padding: 6px 8px; min-width: 10rem;
}
select[multiple] { min-height: 7.4rem; }
.ctl .readout { font-size: 0.82em; color: var(--soft); font-variant-numeric: tabular-nums; }
.ctl-check { flex-direction: row; align-items: center; gap: 7px; font-size: 0.88em; color: var(--ink); }
.ctl-check input { accent-color: var(--navy); }

.chart-box { position: relative; height: 360px; }
.chart-box.tall { height: 420px; }
.stat-line { font-size: 0.95em; color: var(--ink); padding: 4px 0 8px; font-variant-numeric: tabular-nums; }
.stat-line strong { color: var(--navy); font-size: 1.12em; }

/* ---------- week vignette ---------- */
.week-pager {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  font-size: 0.86em; color: var(--soft); font-variant-numeric: tabular-nums;
}
.week-pager button { padding: 3px 11px; font-size: 0.95em; background: #f0f2f5; color: var(--ink); border: 1px solid #c8d1e0; }
.week-pager button:hover:not(:disabled) { background: var(--hairline); }
.vignette {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}
.day-card {
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px 11px 12px;
  min-height: 9rem;
  min-width: 0;
}
.day-card h3 {
  color: var(--navy); font-size: 0.85em; font-weight: 700;
  padding-bottom: 6px; margin-bottom: 7px;
  border-bottom: 1px solid var(--hairline);
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 7px; }
.chip {
  font-size: 0.72em; font-variant-numeric: tabular-nums;
  background: #f0f4fa; color: var(--navy);
  border-radius: 999px; padding: 2px 8px; white-space: nowrap;
}
.day-entry {
  font-size: 0.8em; line-height: 1.4;
  display: flex; flex-wrap: wrap; gap: 1px 6px; align-items: baseline;
  padding: 2px 4px 2px 6px;
  border-left: 3px solid transparent;
  overflow-wrap: anywhere; min-width: 0;
}
.day-entry .t { font-size: 0.86em; color: var(--faint); flex: none; min-width: 2.4rem; font-variant-numeric: tabular-nums; }
.day-entry .lbl { font-weight: 600; }
.day-entry .soft, .soft { color: var(--soft); font-weight: 400; }
.day-entry.sym { border-left-color: var(--red); background: #fdf3f1; }
.day-entry.sleep { border-left-color: var(--navy-2); }
.day-entry.vital { border-left-color: var(--gold); }
.empty { font-size: 0.8em; font-style: italic; }

/* ---------- day in the life ---------- */
.tl-window {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.82em; color: var(--soft); margin: 4px 0 2px;
}
.win-chip {
  padding: 3px 12px; font-size: 0.95em;
  background: #f0f2f5; color: var(--ink); border: 1px solid #c8d1e0;
}
.win-chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.tl-row { display: flex; align-items: center; gap: 14px; margin: 26px 0 26px; }
.tl-marker {
  position: absolute; top: -4px; bottom: -4px;
  border-left: 2px dashed var(--ink); opacity: 0.75;
}
.tl-marker em {
  position: absolute; top: -16px; transform: translateX(-50%);
  font-style: normal; font-weight: 600; font-size: 0.68em;
  color: var(--ink); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tl-row-label {
  flex: none; width: 4.2rem; text-align: right;
  font-size: 0.78em; font-weight: 600; color: var(--navy);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.tl-band {
  position: relative; flex: 1; height: 44px;
  background: #f7f8fa;
  border: 1px solid var(--hairline); border-radius: 6px;
}
.tl-ticks { position: absolute; inset: 0; }
.tl-tick {
  position: absolute; top: 0; height: 100%;
  font-size: 0.66em; color: var(--faint); font-variant-numeric: tabular-nums;
}
.tl-tick i { display: block; width: 1px; height: 100%; background: var(--hairline); }
.tl-tick { display: flex; flex-direction: column; align-items: center; }
.tl-tick:last-child { transform: translateX(-100%); align-items: flex-end; }
.tl-block {
  position: absolute; top: 7px; height: 22px;
  border-radius: 4px; opacity: 0.85;
  display: flex; align-items: center; overflow: hidden;
}
.tl-block span {
  color: #fff; font-size: 0.7em; font-weight: 600; padding-left: 7px; white-space: nowrap;
}
.tl-dot {
  position: absolute; top: 11px; width: 13px; height: 13px;
  border-radius: 50%; border: 2px solid #fff;
  transform: translateX(-50%);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.12);
}
.plan-editor { border-top: 1px solid var(--hairline); padding-top: 16px; margin-top: 6px; }
.plan-editor input[type="time"], .plan-editor input[type="number"] {
  font-family: var(--sans); font-size: 0.9em;
  border: 1px solid #c8d1e0; border-radius: 6px;
  background: #fff; color: var(--ink); padding: 5px 7px;
  font-variant-numeric: tabular-nums; width: 7rem;
}
.plan-editor input[type="number"] { width: 4.5rem; }
.plan-editor button { align-self: end; }
table.deltas { margin-top: 10px; max-width: 46rem; }
.gap { color: var(--red); font-weight: 600; font-size: 0.9em; }
.gap.ok { color: var(--green); }

/* ---------- correlation matrix ---------- */
.matrix-wrap { overflow-x: auto; }
table.matrix { border-collapse: collapse; font-size: 0.8em; }
table.matrix th { font-weight: 600; padding: 4px 8px; text-align: right; color: var(--soft); white-space: nowrap; }
table.matrix thead th {
  writing-mode: vertical-rl; transform: rotate(200grad);
  text-align: left; vertical-align: bottom; padding: 6px 2px;
}
table.matrix td {
  text-align: center; font-variant-numeric: tabular-nums;
  min-width: 3.1rem; padding: 6px 4px;
  border: 1px solid #fff;
  cursor: pointer;
}
table.matrix td:hover { outline: 2px solid var(--navy); }
table.matrix td.thin { color: var(--faint); background: #f6f7f9; cursor: default; }
table.matrix td.muted { color: var(--faint); background: #fbfbfc; }

/* trends small multiples + lag profile */
.mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
  gap: 16px 22px;
}
.mini { position: relative; height: 150px; padding-top: 16px; }
.mini-label {
  position: absolute; top: 0; left: 2px;
  font-size: 0.78em; font-weight: 600; color: var(--navy);
}
.mini-label i { color: var(--soft); font-weight: 400; }
.ccf-box { position: relative; height: 170px; max-width: 34rem; }

/* ---------- coverage ---------- */
table.plain { border-collapse: collapse; font-size: 0.88em; width: 100%; }
table.plain th, table.plain td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--hairline); }
table.plain th { font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.04em; color: var(--soft); border-bottom: 2px solid #dfe3e8; }
table.plain td.num { font-variant-numeric: tabular-nums; }
table.plain tr:hover td { background: #f8f9fc; }
.covbar { background: var(--hairline); height: 8px; border-radius: 4px; min-width: 8rem; position: relative; overflow: hidden; }
.covbar i { position: absolute; inset: 0 auto 0 0; background: var(--navy-2); border-radius: 4px; }

@media (max-width: 900px) {
  .vignette { grid-template-columns: 1fr; }
  .day-card { min-height: 0; }
  .tab-btn { padding: 10px 14px; font-size: 0.82em; }
}

/* ---------- P0.1 day drawer ---------- */
.day-drawer {
  position: fixed; bottom: 0; left: 0; right: 0; max-height: 60vh;
  background: #fff; border-top: 2px solid var(--navy, #1F4E79);
  border-radius: 12px 12px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  transform: translateY(100%); transition: transform .25s ease;
  z-index: 100; overflow-y: auto; padding: 1rem;
}
.day-drawer.open { transform: translateY(0); }
.day-drawer-close { position: absolute; top: 8px; right: 12px; }
.day-drawer h3 { margin: 0 0 .75rem; }
.day-drawer .metric-delta { font-variant-numeric: tabular-nums; }
.day-drawer .metric-delta.up { color: #2e7d32; }
.day-drawer .metric-delta.down { color: #c0392b; }
.day-drawer .metric-delta.flat { color: #888; }
@media (min-width: 900px) {
  .day-drawer { left: auto; width: 380px; top: 0; bottom: 0; max-height: none; border-radius: 0; border-top: none; border-left: 2px solid var(--navy); transform: translateX(100%); }
  .day-drawer.open { transform: translateX(0); }
}

/* ---------- P0.2 brush zoom ---------- */
.brush-overlay { position: absolute; top: 0; bottom: 0; background: rgba(31,78,121,.12); pointer-events: none; z-index: 5; }
.reset-chip { font-size: .75rem; cursor: pointer; }

/* ---------- P0.5 findings card ---------- */
.findings-card { border-left: 4px solid #1F4E79; padding: .75rem 1rem; margin-bottom: 1rem; background: #fff; border-radius: 0 8px 8px 0; }
.finding-row { padding: .25rem 0; cursor: pointer; }
.finding-row:hover { background: #f8f9fa; }
.finding-arrow { font-weight: 600; }
.finding-arrow.up { color: #2e7d32; }
.finding-arrow.down { color: #c0392b; }

/* ---------- P0.6 mobile layout ---------- */
@media (max-width: 600px) {
  .container { padding: 12px; }
  header { flex-direction: column; align-items: stretch; gap: 10px; padding: 16px 16px 14px; }
  header .range-ctl { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .range-ctl input[type="date"] { flex: 1 1 0; min-width: 0; }
  /* tab bar scrolls horizontally instead of clipping the last tabs (was a dead
     .tab-bar selector — the element is .tab-nav) */
  .tab-nav { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .tab-nav::-webkit-scrollbar { display: none; }
  .tab-btn { flex: 0 0 auto; white-space: nowrap; padding: 11px 15px; }
  .section { padding: 16px 14px; }
  .section-head { gap: 8px; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
  .ctl, .controls > label { min-width: 0; }
  .ctl select, .ctl input[type="range"] { min-width: 0; width: 100%; }
  .controls .ctl:has(select[multiple]) { grid-column: 1 / -1; }
  .chart-box, .chart-box.tall { height: clamp(240px, 60vw, 360px); }
  input, select { font-size: 16px; }   /* ≥16px stops iOS zoom-on-focus */
}
.chip-select { display: flex; flex-wrap: wrap; gap: 4px; }
.chip-select .chip-opt { padding: 4px 10px; border-radius: 12px; border: 1px solid #ccc; background: #fff; cursor: pointer; font-size: .8rem; transition: all .15s; }
.chip-select .chip-opt[aria-pressed="true"] { background: #163d61; color: #fff; border-color: #163d61; }
.matrix-wrap th:first-child { position: sticky; left: 0; background: #fff; z-index: 2; }

/* ---------- P1.3 hypothesis builder ---------- */
.hyp-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: .75rem; }
.hyp-verdict { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .75rem; font-weight: 600; }
.hyp-verdict.supported { background: #e8f5e9; color: #2e7d32; }
.hyp-verdict.not-supported { background: #fce4ec; color: #c0392b; }
.hyp-verdict.insufficient { background: #f5f5f5; color: #888; }
.hyp-delete { cursor: pointer; color: #888; }
.hyp-delete:hover { color: #c0392b; }

/* ---------- P1.4 sleep architecture ---------- */
.sleep-raster { max-height: 300px; overflow-y: auto; }
.sleep-raster-row { display: flex; align-items: center; height: 6px; margin: 1px 0; }
.sleep-raster-bar { height: 100%; background: rgba(31,78,121,.7); border-radius: 2px; }
.duration-hist { max-width: 400px; }
.recommended-band { background: rgba(46,125,50,.08); }

/* ---------- P1.5 comparison periods ---------- */
.compare-table { width: 100%; border-collapse: collapse; }
.compare-table th, .compare-table td { padding: 6px 10px; text-align: right; font-variant-numeric: tabular-nums; }
.compare-table th { text-align: left; }
.compare-table .muted-row { opacity: .5; }

/* ---------- P1.6 copy link ---------- */
.copy-link-btn { font-size: .75rem; padding: 2px 8px; border-radius: 4px; cursor: pointer; background: transparent; border: 1px solid #ccc; }
.copy-link-btn:hover { background: #f0f2f5; }

/* ---------- P1.7 sparklines ---------- */
.sparkline-row { display: flex; gap: 1rem; flex-wrap: wrap; padding: .5rem 0; margin-bottom: .5rem; border-bottom: 1px solid #eee; }
.sparkline-item { display: flex; align-items: center; gap: 6px; }
.sparkline-label { font-size: .75rem; color: #5a6b7b; min-width: 50px; }
.sparkline-value { font-size: .8rem; font-variant-numeric: tabular-nums; font-weight: 600; }
.sparkline-svg { display: block; }

/* ---------- P2.1 print ---------- */
@media print {
  #gate, nav, .tab-nav, .range-ctl, .controls, .day-drawer, .hyp-form, button, .chip, .win-chip, .reset-chip { display: none !important; }
  body { background: #fff !important; }
  .section { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
  .findings-card { break-inside: avoid; }
  h1 { font-size: 18pt; color: #1F4E79; }
  h2 { font-size: 14pt; }
  canvas { max-height: 200px; }
}

/* ---------- P2.5 accessibility ---------- */
:focus-visible { outline: 2px solid #4472C4; outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.skip-link:focus { position: static; width: auto; height: auto; overflow: visible; padding: 8px; background: #1F4E79; color: #fff; }

/* ---------- P2.6 tab transitions ---------- */
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.tab-panel.active { animation: fadeSlideIn .15s ease; }
@media (prefers-reduced-motion: reduce) { .tab-panel.active { animation: none; } }

/* ---------- Advisor tab ---------- */
.adv-meta { display: flex; gap: 16px; font-size: 0.82em; color: var(--soft); margin-bottom: 8px; }
.adv-disclaimer { font-size: 0.82em; color: var(--soft); border-left: 3px solid #e67e22;
  padding: 6px 12px; margin-bottom: 16px; background: rgba(230,126,34,0.06); border-radius: 0 6px 6px 0; }
.adv-card { background: #fff; border: 1px solid #dfe3e8; border-radius: 8px;
  padding: 12px 16px; margin-bottom: 12px; }
.adv-card h3 { margin: 0 0 8px; font-size: 1.05em; color: var(--navy); font-weight: 700; }
.adv-table { width: 100%; border-collapse: collapse; font-size: 0.88em; font-variant-numeric: tabular-nums; }
.adv-table th { text-align: left; color: var(--soft); font-weight: 600; border-bottom: 1px solid #dfe3e8;
  padding: 4px 8px 4px 0; font-size: 0.85em; }
.adv-table td { padding: 4px 8px 4px 0; }
.adv-row.ns td { color: var(--soft); }
.adv-dir { font-weight: 600; }
.adv-ci { font-size: 0.85em; color: var(--soft); }
.adv-badge { display: inline-block; font-size: 0.72em; font-weight: 700; color: #fff;
  padding: 1px 6px; border-radius: 3px; text-transform: uppercase; letter-spacing: 0.04em; }
.adv-blend { position: relative; height: 6px; background: #e0e4e8; border-radius: 3px;
  margin-top: 8px; overflow: hidden; }
.adv-blend-pop { height: 100%; background: var(--navy-2); border-radius: 3px 0 0 3px; }
.adv-blend-label { position: absolute; top: -16px; right: 0; font-size: 0.72em; color: var(--soft); }
.adv-safety { font-size: 0.82em; color: #c0392b; margin-bottom: 6px; }
.adv-diag { margin-top: 16px; font-size: 0.85em; }
.adv-diag h4 { color: #c0392b; margin: 0 0 4px; font-size: 0.95em; }
.adv-diag ul { margin: 0; padding-left: 18px; color: var(--soft); }
.adv-overrides { margin-top: 12px; font-size: 0.85em; }
.adv-overrides h4 { color: var(--navy); margin: 0 0 4px; font-size: 0.95em; }
.adv-overrides ul { margin: 0; padding-left: 18px; }
.adv-empty { text-align: center; padding: 40px 20px; color: var(--soft); }
.adv-empty code { display: block; margin: 8px auto; font-size: 0.9em;
  background: #f5f5f5; padding: 6px 12px; border-radius: 4px; width: fit-content; }
