/* Lapse — Opportunity UI. One compact hand-written stylesheet.
   Light, editorial, Tufte-restrained. System fonts, zinc neutrals, single amber accent.
   Modality hues: teal = small molecule, orange = biologic (always paired with shape in the chart). */

:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;          /* wells, table header */
  --ink: #18181b;              /* zinc-900 */
  --ink-2: #3f3f46;            /* zinc-700 */
  --ink-soft: #71717a;         /* zinc-500 */
  --ink-faint: #a1a1aa;        /* zinc-400 */
  --line: rgba(24, 24, 27, 0.08);
  --line-2: rgba(24, 24, 27, 0.14);

  --sm: #0d9488;               /* teal-600  small molecule */
  --sm-ink: #0f766e;
  --sm-soft: rgba(13, 148, 136, 0.12);
  --bio: #c2410c;              /* orange-700 biologic */
  --bio-ink: #9a3412;
  --bio-soft: rgba(194, 65, 12, 0.12);

  --accent: #b45309;           /* amber-700  selection + sweet spot */
  --accent-soft: rgba(180, 83, 9, 0.12);
  --accent-tint: rgba(180, 83, 9, 0.06);

  --radius: 10px;
  --maxw: 1600px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
.num, table, .stat-val, .score-big, .bar-val, .provenance, .updated-meta { font-variant-numeric: tabular-nums; }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff;
  padding: 8px 12px; border-radius: 6px; z-index: 20;
}
.skip-link:focus { left: 12px; top: 12px; }

/* ---- header ---- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 8px 16px; max-width: var(--maxw); margin: 0 auto; padding: 22px 20px 14px;
}
.brand-row { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 1.5rem; }
.tagline { color: var(--ink-soft); font-size: 0.9375rem; margin-top: 2px; }
.top-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; text-align: right; }
.updated-meta { color: var(--ink-2); font-size: 0.8125rem; font-weight: 500; }
.provenance { color: var(--ink-faint); font-size: 0.8125rem; }
.about-link {
  appearance: none; border: none; background: none; color: var(--ink-soft);
  font: inherit; font-size: 0.8125rem; line-height: 1; cursor: pointer;
  padding: 2px 0; text-decoration: underline; text-underline-offset: 3px;
}
.about-link:hover { color: var(--ink); }
.about-link:focus-visible, .modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

body.modal-open { overflow: hidden; }
.modal-shell[hidden] { display: none; }
.modal-shell {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
}
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(24, 24, 27, 0.3);
}
.about-modal {
  position: relative; width: min(100%, 38rem); max-height: min(86vh, 44rem); overflow: auto;
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px;
  box-shadow: 0 24px 80px rgba(24, 24, 27, 0.18); padding: 20px;
}
.modal-close {
  appearance: none; position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px; border: 1px solid var(--line-2); border-radius: 999px;
  background: var(--bg); color: var(--ink-soft); font: inherit; font-size: 1.125rem;
  line-height: 1; cursor: pointer;
}
.modal-close:hover { color: var(--ink); border-color: var(--ink-faint); }
.modal-kicker {
  color: var(--accent); font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; padding-right: 36px;
}
.about-modal h2 { margin-top: 5px; padding-right: 36px; font-size: 1.25rem; }
.about-modal h3 {
  color: var(--ink-soft); font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.04em; margin-top: 16px;
}
.about-modal p, .about-modal li { color: var(--ink-2); font-size: 0.9375rem; line-height: 1.52; }
.about-modal p { margin-top: 10px; }
.about-modal .modal-lede { color: var(--ink); font-weight: 500; }
.about-modal a { color: var(--accent); font-weight: 500; text-underline-offset: 3px; }
.about-modal a:hover { color: var(--ink); }
.about-modal ul { margin: 8px 0 0; padding-left: 18px; }
.about-modal li + li { margin-top: 6px; }
.score-rules {
  display: grid; gap: 8px; margin: 10px 0 0;
}
.score-rules div {
  display: grid; grid-template-columns: 5.5rem minmax(0, 1fr); gap: 10px;
  padding-top: 8px; border-top: 1px solid var(--line);
}
.score-rules dt {
  color: var(--ink); font-size: 0.8125rem; font-weight: 600;
}
.score-rules dd {
  margin: 0; color: var(--ink-2); font-size: 0.875rem; line-height: 1.5;
}

/* ---- sample banner ---- */
.banner {
  width: calc(100% - 40px); max-width: calc(var(--maxw) - 40px);
  margin: 6px auto 0; padding: 9px 14px;
  background: var(--accent-tint); color: var(--accent);
  border: 1px solid var(--accent-soft); border-radius: 8px;
  font-size: 0.8125rem; font-weight: 500;
}

/* ---- filters ---- */
.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  max-width: var(--maxw); margin: 12px auto 4px; padding: 12px 20px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.filter-group { display: flex; align-items: center; gap: 8px; min-width: 0; }
.filter-group[hidden] { display: none; }
.filter-label { color: var(--ink-soft); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  appearance: none; border: 1px solid var(--line-2); background: var(--bg);
  color: var(--ink-2); font: inherit; font-size: 0.8125rem; line-height: 1;
  padding: 8px 12px; border-radius: 999px; cursor: pointer;
  transition: transform 0.1s ease, background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.chip:hover { border-color: var(--ink-faint); }
.chip:active { transform: scale(0.96); }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip--sm[aria-pressed="true"] { background: var(--sm); border-color: var(--sm); }
.chip--bio[aria-pressed="true"] { background: var(--bio); border-color: var(--bio); }
.chip:focus-visible, .reset:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.reset {
  appearance: none; border: none; background: none; color: var(--ink-soft);
  font: inherit; font-size: 0.8125rem; cursor: pointer; padding: 6px 4px; margin-left: auto;
  text-decoration: underline; text-underline-offset: 2px;
}
.reset:hover { color: var(--ink); }

/* ---- layout ---- */
.layout {
  max-width: var(--maxw); margin: 0 auto; padding: 14px 20px 8px;
  display: flex; flex-direction: column; gap: 16px;
}
.region {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; background: var(--bg); min-width: 0;
}
.region-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.region-head h2 { font-size: 1rem; }
.region-sub { color: var(--ink-faint); font-size: 0.8125rem; margin-top: 1px; }
.count { color: var(--ink-soft); font-size: 0.8125rem; }
.search-box {
  display: flex; align-items: center; gap: 7px; margin-left: auto;
  min-width: min(100%, 18rem);
}
.search-label {
  color: var(--ink-soft); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
}
.search-input {
  width: 100%; min-width: 0; height: 32px; border: 1px solid var(--line-2);
  border-radius: 999px; background: var(--bg); color: var(--ink);
  font: inherit; font-size: 0.875rem; padding: 5px 12px;
}
.search-input:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.search-input::-webkit-search-cancel-button { cursor: pointer; }

.lower { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 880px) {
  .lower { grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr); }
}

/* ---- chart ---- */
.chart-region { padding-bottom: 8px; }
.chart-wrap { width: 100%; height: clamp(320px, 42vw, 520px); }
.chart-wrap svg { display: block; width: 100%; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); font-size: 0.8125rem; }
.legend-item svg { display: block; }

/* chart marks (styled here so JS stays structural) */
.bubble { cursor: pointer; }
.bubble .mark { transition: none; }
.axis-line { stroke: var(--line-2); stroke-width: 1; }
.tick-label, .now-label, .band-caption {
  paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round;
}
.tick-label { fill: var(--ink-faint); font-size: 11px; }
.axis-title { fill: var(--ink-soft); font-size: 11px; }
.now-line { stroke: var(--line-2); stroke-width: 1; }
.now-label { fill: var(--ink-soft); font-size: 11px; }
.threshold-line { stroke: rgba(24, 24, 27, 0.12); stroke-width: 1; stroke-dasharray: 2 3; }
.sweet-fill { fill: var(--accent-tint); }
.sweet-fill--soft { fill: var(--accent-tint); opacity: 0.5; }
.sweet-label { fill: var(--accent); font-size: 11px; font-weight: 500; }
.expired-band { fill: rgba(24, 24, 27, 0.022); }
.band-caption { fill: var(--ink-faint); font-size: 10.5px; }
.leader { stroke: var(--line-2); stroke-width: 1; fill: none; }
.dlabel-name { fill: var(--ink); font-size: 11.5px; font-weight: 500; }
.dlabel-meta { fill: var(--ink-soft); font-size: 10.5px; }
.gutter-label { fill: var(--ink-faint); font-size: 10.5px; }
.empty-msg { fill: var(--ink-soft); font-size: 13px; }

/* ---- detail panel ---- */
.detail-region { background: var(--bg-soft); }
.detail-empty { color: var(--ink-soft); font-size: 0.9375rem; padding: 18px 4px; }
.detail-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.detail-name { font-size: 1.375rem; font-weight: 600; letter-spacing: -0.02em; }
.score-big { font-size: 1.75rem; font-weight: 600; line-height: 1; }
.score-big small { font-size: 0.8125rem; color: var(--ink-faint); font-weight: 500; }
.modality-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 5px; }
.mod-badge, .class-chip, .window-pill {
  display: inline-flex; align-items: center; font-size: 0.75rem; font-weight: 500;
  line-height: 1.3; padding: 3px 10px; border-radius: 999px; white-space: normal;
  border: 1px solid transparent;
}
.mod-badge { gap: 6px; }
.mod-badge--sm { background: var(--sm-soft); color: var(--sm-ink); }
.mod-badge--bio { background: var(--bio-soft); color: var(--bio-ink); }
.class-chip { background: var(--bg); border-color: var(--line-2); color: var(--ink-soft); }
.window-pill { background: var(--bg); border-color: var(--line-2); color: var(--ink-soft); }
.window-pill--soon { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.drug-desc { margin-top: 11px; font-size: 0.9375rem; line-height: 1.45; color: var(--ink-2); }
.mod-dot { width: 8px; height: 8px; border-radius: 999px; }
.mod-dot--sm { background: var(--sm); }
.mod-dot--bio { background: var(--bio); border-radius: 1px; transform: rotate(45deg); }
.why-line {
  margin-top: 12px; padding: 9px 11px; border-left: 3px solid var(--accent);
  background: var(--accent-tint); border-radius: 0 6px 6px 0; font-size: 0.9375rem; color: var(--ink-2);
}
.why-line.outside { border-left-color: var(--ink-faint); background: var(--bg); color: var(--ink-soft); }
.outside-note { display: block; font-size: 0.75rem; color: var(--ink-faint); margin-top: 4px; }

.bars { margin-top: 14px; display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 5.5rem 1fr 2.25rem; align-items: center; gap: 8px; }
.bar-label { font-size: 0.8125rem; color: var(--ink-soft); }
.bar-track { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-fill--timing { background: var(--ink-2); }
.bar-fill--market { background: var(--ink-2); }
.bar-fill--competition { background: var(--ink-2); }
.bar-val { font-size: 0.8125rem; color: var(--ink-2); text-align: right; }
.bar-na { color: var(--ink-faint); font-style: italic; }

.stats { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 6px 22px; padding-top: 12px; border-top: 1px solid var(--line); }
.stat { display: flex; flex-direction: column; gap: 1px; }
.stat-label { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-faint); }
.stat-val { font-size: 0.9375rem; color: var(--ink); font-weight: 500; }

.breakdown { margin-top: 12px; max-width: 100%; overflow: hidden; }
.breakdown summary { cursor: pointer; color: var(--ink-soft); font-size: 0.8125rem; list-style: none; }
.breakdown summary::-webkit-details-marker { display: none; }
.breakdown summary::before { content: "▸ "; color: var(--ink-faint); }
.breakdown[open] summary::before { content: "▾ "; }
.breakdown dl {
  margin: 8px 0 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px;
  max-width: 100%;
  font-size: 0.8125rem;
}
.breakdown dt { color: var(--ink-soft); min-width: 0; padding-top: 6px; }
.breakdown dd {
  margin: 0; min-width: 0; color: var(--ink-2); text-align: left;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere; word-break: break-word;
}

/* ---- worklist table ---- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  text-align: left; font-weight: 600; color: var(--ink-soft); font-size: 0.75rem;
  white-space: nowrap; padding: 6px 10px; border-bottom: 1px solid var(--line-2);
}
thead th.num { text-align: right; }
tbody td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; transition: background-color 0.12s ease; }
tbody tr:hover { background: var(--bg-soft); }
tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
tbody tr.selected { background: var(--accent-tint); }
tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tbody tr.dimmed { opacity: 0.4; }
.th-sort {
  appearance: none; padding: 0; border: none; background: none;
  font: inherit; color: inherit; text-align: inherit; cursor: pointer;
}
.th-sort:hover { color: var(--ink); }
.th-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.th-sort[data-dir="asc"]::after { content: " ↑"; }
.th-sort[data-dir="desc"]::after { content: " ↓"; }
.cell-drug { display: flex; align-items: center; gap: 8px; }
.cell-drug .mod-dot { flex: none; }
.cell-company { color: var(--ink-soft); max-width: 16rem; overflow: hidden; text-overflow: ellipsis; }
.stat-val { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.competitors-line { margin-top: 10px; font-size: 0.8125rem; color: var(--ink-2); display: flex; gap: 8px; align-items: baseline; }
.competitors-line .stat-label { flex: none; }
.competitors-none { color: var(--ink-faint); font-style: italic; }
.competitors-list { min-width: 0; }

@media (max-width: 1000px) {
  .col-company { display: none; }
}
.drug-name { font-weight: 500; }
.score-cell { font-weight: 600; }
.empty-row td { text-align: center; color: var(--ink-soft); padding: 20px; font-style: italic; }

/* ---- footer ---- */
.foot { max-width: var(--maxw); margin: 8px auto 28px; padding: 14px 20px 0; border-top: 1px solid var(--line); }
.foot p { color: var(--ink-faint); font-size: 0.8125rem; max-width: 80ch; }

.ta-select {
  appearance: none; border: 1px solid var(--line-2); background: var(--bg);
  color: var(--ink-2); font: inherit; font-size: 0.8125rem; line-height: 1;
  padding: 8px 12px; border-radius: 999px; cursor: pointer;
}
.ta-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.view-switch { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 10px; }
tbody tr.rollup { cursor: default; }
.cell-targets { white-space: normal; }
#worklist.is-originators, #worklist.is-competitors { table-layout: fixed; }
#worklist.is-originators th:nth-child(1) { width: 34%; }
#worklist.is-originators th:nth-child(2) { width: 7%; }
#worklist.is-originators th:nth-child(3) { width: 11%; }
#worklist.is-originators th:nth-child(4) { width: 14%; }
#worklist.is-competitors th:nth-child(1) { width: 22%; }
#worklist.is-competitors th:nth-child(2) { width: 8%; }
#worklist.is-competitors th:nth-child(4) { width: 12%; }
#worklist.is-originators td:nth-child(1), #worklist.is-competitors td:nth-child(1) {
  overflow: hidden; text-overflow: ellipsis;
}
.target-link {
  appearance: none; border: none; background: none; padding: 0; font: inherit;
  color: var(--ink); cursor: pointer; border-bottom: 1px dotted var(--line-2);
}
.target-link .mod-dot { display: inline-block; margin-right: 4px; }
.target-link:hover { color: var(--accent); border-bottom-color: var(--accent); }
.target-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.target-usd { color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.target-sep { color: var(--ink-faint); padding: 0 5px; }

/* ---- KPI strip ---- */
.kpis {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 32px;
  max-width: var(--maxw); margin: 0 auto; padding: 10px 20px 6px;
}
.kpi { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kpi-val { font-size: 1.375rem; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi-label { color: var(--ink-faint); font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-note { margin-left: auto; color: var(--ink-faint); font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.04em; }
.csv-link { margin-left: auto; }

/* ---- print: clean one-pager ---- */
@media print {
  .filters, .kpi-note, .search-box, .csv-link, .reset, .skip-link, .about-link, .modal-shell, .banner { display: none !important; }
  body { font-size: 12px; }
  .topbar { padding-top: 0; }
  .chart-region, .detail-region { break-inside: avoid; }
  .chart-wrap { height: 360px; }
  .lower { grid-template-columns: 1fr; }
  .table-scroll { overflow-x: visible; }
  .col-sub, .col-market, .col-window, .col-company { display: table-cell !important; }
  tbody tr { break-inside: avoid; }
  .foot { break-inside: avoid; }
}

/* ---- responsive: hide low-priority table columns on narrow screens ---- */
@media (max-width: 560px) {
  .col-sub, .col-window { display: none; }
}
@media (max-width: 440px) {
  .col-market { display: none; }
  .topbar { padding-top: 16px; }
}
@media (max-width: 700px) {
  .region-head { flex-direction: column; }
  .legend { margin-top: 2px; }
  .search-box { width: 100%; margin-left: 0; }
  .top-meta { align-items: flex-start; text-align: left; }
}

@media (prefers-reduced-motion: no-preference) {
  .bar-fill { transition: width 0.2s ease; }
}
