/* TrialFoundry mock-up — app layout and page-level patterns. Values come from tokens.css only. */

/* chart series (validated for colour-vision deficiency against surface-raised in each theme) */
:root, [data-theme="light"] { --chart-1: #00809b; --chart-2: #c27c0e; --chart-3: #8f5bc4; --chart-band: rgba(15, 92, 110, 0.07); }
[data-theme="dark"] { --chart-1: #1c98b8; --chart-2: #c48520; --chart-3: #a07ad8; --chart-band: rgba(98, 180, 199, 0.09); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --chart-1: #1c98b8; --chart-2: #c48520; --chart-3: #a07ad8; --chart-band: rgba(98, 180, 199, 0.09); } }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font-sans); font-size: 15px; line-height: 22px; background: var(--surface); color: var(--ink); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: var(--focus-width) solid var(--primary); outline-offset: 2px; }
h1, h2, h3, h4 { margin: 0; }
.mono { font-family: var(--font-mono); font-size: 13px; }
.muted { color: var(--ink-muted); }
.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.sr-only, .t1-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); grid-template-rows: 56px minmax(0, 1fr); min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-4); padding: 0 var(--space-5); background: var(--surface-raised); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.wordmark { font-weight: 600; font-size: 18px; letter-spacing: -0.01em; color: var(--ink); display: flex; align-items: center; gap: var(--space-2); }
.wordmark:hover { text-decoration: none; }
.wordmark-mark { width: 22px; height: 22px; border-radius: var(--radius-sm); background: var(--primary); display: grid; place-items: center; }
.wordmark-mark i { display: block; width: 4px; background: var(--on-primary); border-radius: 1px; margin: 0 1px; }
.topbar-org { display: flex; align-items: center; gap: var(--space-2); padding-left: var(--space-4); border-left: 1px solid var(--line); font-size: 13px; color: var(--ink-muted); }
.topbar-spacer { flex: 1; }
.demo-flag { font-size: 12px; font-weight: 500; line-height: 20px; color: var(--warning); background: var(--warning-soft); border-radius: var(--radius-sm); padding: 0 var(--space-2); }
.avatar { width: 32px; height: 32px; border-radius: var(--radius-full); background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.theme-toggle { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-md); overflow: hidden; }
.theme-toggle button { font: inherit; font-size: 12px; font-weight: 500; border: 0; background: transparent; color: var(--ink-muted); padding: 4px 10px; cursor: pointer; }
.theme-toggle button[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); }

.sidenav { background: var(--surface-raised); border-right: 1px solid var(--line); padding: var(--space-4) var(--space-3); overflow-y: auto; position: sticky; top: 56px; height: calc(100vh - 56px); }
.nav-section { margin-bottom: var(--space-5); }
.nav-heading { font-size: 12px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); padding: 0 var(--space-3); margin-bottom: var(--space-2); }
.nav-link { display: flex; align-items: center; gap: var(--space-2); padding: 6px var(--space-3); border-radius: var(--radius-md); color: var(--ink); font-size: 14px; line-height: 20px; position: relative; }
.nav-link:hover { background: var(--surface-sunken); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-link .mono { font-size: 12px; color: var(--ink-muted); }
.nav-link[aria-current="page"] .mono { color: var(--primary); }
.nav-modules { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 var(--space-3); }
.nav-modules .t1-module.dim { opacity: .55; }

.main { padding: var(--space-6) var(--space-6) var(--space-7); min-width: 0; }
.page { max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-6); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.page-head h1 { font-size: 28px; line-height: 36px; font-weight: 600; }
.page-sub { margin: 4px 0 0; color: var(--ink-muted); font-size: 14px; }
.crumbs { font-size: 13px; color: var(--ink-muted); margin-bottom: var(--space-2); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.head-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.section-title { font-size: 17px; line-height: 24px; font-weight: 600; margin-bottom: var(--space-3); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); flex-wrap: wrap; }
.section-head .section-title { margin: 0; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-4); }
.kpi { background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5); }
.kpi-label { font-size: 12px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); }
.kpi-value { font-size: 32px; line-height: 40px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-note { font-size: 13px; color: var(--ink-muted); }
.kpi-note .t1-status { font-size: 13px; }

/* ---------- stage pipeline (dashboard) ---------- */
.pipeline { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.pipe-col { background: var(--surface-raised); padding: var(--space-3); min-height: 120px; display: flex; flex-direction: column; gap: var(--space-2); }
.pipe-head { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.pipe-name { font-size: 12px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); }
.pipe-count { font-family: var(--font-mono); font-size: 13px; color: var(--ink-muted); }
.pipe-chip { display: block; border: 1px solid var(--line); border-radius: var(--radius-md); padding: 6px var(--space-2); background: var(--surface); color: var(--ink); font-size: 12px; line-height: 16px; }
.pipe-chip:hover { border-color: var(--primary); text-decoration: none; }
.pipe-chip b { font-family: var(--font-mono); font-weight: 600; display: block; font-size: 12px; }
.pipe-chip span { color: var(--ink-muted); }

/* ---------- stage stepper ---------- */
.stepper { display: flex; gap: 3px; align-items: center; }
.stepper i { display: block; height: 6px; flex: 1; min-width: 10px; border-radius: 2px; background: var(--line); }
.stepper i.done { background: var(--primary); opacity: .45; }
.stepper i.now { background: var(--primary); }
.stepper-label { font-size: 12px; color: var(--ink-muted); margin-top: 4px; }
.stepper-wrap { min-width: 132px; }

.stage-track { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-2); }
.stage-step { border-top: 4px solid var(--line); padding-top: var(--space-2); font-size: 13px; color: var(--ink-muted); }
.stage-step.done { border-top-color: var(--primary); color: var(--ink); opacity: .75; }
.stage-step.now { border-top-color: var(--primary); color: var(--primary); font-weight: 600; }
.stage-step small { display: block; font-size: 12px; font-weight: 400; color: var(--ink-muted); }

/* ---------- enrolment bar ---------- */
.meter { min-width: 120px; }
.meter-bar { height: 6px; border-radius: 3px; background: var(--surface-sunken); overflow: hidden; margin-top: 4px; }
.meter-bar > span { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
.meter-text { font-family: var(--font-mono); font-size: 12px; line-height: 16px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: flex-end; }
.filters .t1-field { min-width: 160px; }
.filters .grow { flex: 1; min-width: 220px; }
.select, .textarea { font: inherit; font-size: 15px; line-height: 22px; border-radius: var(--radius-md); border: 1px solid var(--line-strong); background: var(--surface-raised); color: var(--ink); }
.select { height: 36px; padding: 0 32px 0 var(--space-3); appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-muted) 50%), linear-gradient(135deg, var(--ink-muted) 50%, transparent 50%); background-position: calc(100% - 16px) 15px, calc(100% - 11px) 15px; background-size: 5px 5px; background-repeat: no-repeat; }
.textarea { padding: var(--space-2) var(--space-3); min-height: 72px; resize: vertical; width: 100%; }
.select:focus-visible, .textarea:focus-visible { outline: var(--focus-width) solid var(--primary); outline-offset: 2px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { font: inherit; font-size: 14px; font-weight: 500; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: var(--space-2) var(--space-3); color: var(--ink-muted); cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab .count { font-family: var(--font-mono); font-size: 12px; margin-left: 4px; }

/* ---------- layout helpers ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-5); }
.grid-main-side { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); margin: 0; font-size: 14px; }
.dl dt { color: var(--ink-muted); }
.dl dd { margin: 0; }
.notice { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: 14px; background: var(--info-soft); color: var(--ink); border: 1px solid transparent; }
.notice b { color: var(--info); }
.notice.warning { background: var(--warning-soft); }
.notice.warning b { color: var(--warning); }
.notice.danger { background: var(--danger-soft); }
.notice.danger b { color: var(--danger); }
.empty { padding: var(--space-7) var(--space-5); text-align: center; color: var(--ink-muted); }
.empty h3 { color: var(--ink); font-size: 17px; margin-bottom: var(--space-2); }

/* funnel */
.funnel { display: flex; flex-direction: column; gap: var(--space-3); }
.funnel-row { display: grid; grid-template-columns: 110px 1fr 56px; gap: var(--space-3); align-items: center; font-size: 14px; }
.funnel-bar { height: 20px; border-radius: 0 4px 4px 0; background: var(--chart-1); }
.funnel-bar.soft { background: var(--primary-soft); border: 1px solid var(--primary); }

/* table extras */
.table-tools { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-top: var(--space-3); font-size: 13px; color: var(--ink-muted); flex-wrap: wrap; }
.pager { display: flex; gap: var(--space-2); align-items: center; }
.t1-table td .sub { display: block; font-size: 12px; color: var(--ink-muted); line-height: 16px; }
.t1-table td .title { font-weight: 500; font-size: 14px; }
.flag { font-family: var(--font-mono); font-size: 12px; font-weight: 600; margin-left: 4px; }
.flag-h, .flag-l { color: var(--danger); }
.cell-oor { background: var(--danger-soft); }
.cell-q { box-shadow: inset 0 0 0 2px var(--warning); }
.cell-empty { color: var(--ink-muted); }
.pivot td, .pivot th { white-space: nowrap; }
.pivot td.measure { position: sticky; left: 0; background: var(--surface-raised); z-index: 1; }
.pivot th:first-child { position: sticky; left: 0; z-index: 2; }
.legend-inline { display: flex; gap: var(--space-4); flex-wrap: wrap; font-size: 12px; color: var(--ink-muted); }
.legend-inline span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }

/* visit timeline */
.visit-line { display: flex; gap: 0; overflow-x: auto; padding-bottom: var(--space-2); }
.visit { flex: 1; min-width: 96px; position: relative; padding-top: 22px; font-size: 12px; text-align: center; }
.visit::before { content: ""; position: absolute; top: 7px; left: 0; right: 0; height: 2px; background: var(--line); }
.visit:first-child::before { left: 50%; }
.visit:last-child::before { right: 50%; }
.visit .dot { position: absolute; top: 1px; left: 50%; transform: translateX(-50%); width: 14px; height: 14px; border-radius: var(--radius-full); background: var(--surface-raised); border: 2px solid var(--line-strong); }
.visit.done .dot { background: var(--primary); border-color: var(--primary); }
.visit.missed .dot, .visit.notdone .dot { background: var(--surface-raised); border-color: var(--danger); }
.visit .vcode { font-family: var(--font-mono); font-weight: 600; display: block; }
.visit .vstate { color: var(--ink-muted); }
.visit.missed .vstate, .visit.notdone .vstate { color: var(--danger); }

/* ---------- charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text, .chart .tick { fill: var(--ink-muted); font-family: var(--font-sans); font-size: 11px; }
.chart .axis .num-tick { font-family: var(--font-mono); }
.chart .baseline { stroke: var(--line-strong); stroke-width: 1; }
.chart .zero { stroke: var(--ink-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .ref-band { fill: var(--chart-band); }
.chart .ref-line { stroke: var(--ink-muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ci { stroke-width: 1.5; }
.chart .pt { stroke: var(--surface-raised); stroke-width: 2; }
.chart .dlabel { font-size: 12px; font-weight: 500; fill: var(--ink); }
.chart .dlabel-muted { font-size: 11px; fill: var(--ink-muted); font-family: var(--font-mono); }
.chart .s1 { stroke: var(--chart-1); fill: var(--chart-1); }
.chart .s2 { stroke: var(--chart-2); fill: var(--chart-2); }
.chart .s3 { stroke: var(--chart-3); fill: var(--chart-3); }
.chart .series-line.s1, .chart .series-line.s2, .chart .series-line.s3 { fill: none; }
.chart .bar { stroke: var(--surface-raised); stroke-width: 2; }
.chart .cross { stroke: var(--ink-muted); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .bar-hit { fill: transparent; }
.chart-legend { display: flex; gap: var(--space-4); flex-wrap: wrap; font-size: 12px; color: var(--ink-muted); margin-bottom: var(--space-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .key { width: 16px; height: 3px; border-radius: 2px; }
.chart-legend .key.box { height: 12px; width: 12px; border-radius: 3px; }
.chart-legend .key.dash { background: repeating-linear-gradient(90deg, var(--ink-muted) 0 4px, transparent 4px 7px); height: 1px; }
.k1 { background: var(--chart-1); } .k2 { background: var(--chart-2); } .k3 { background: var(--chart-3); }
.tooltip { position: absolute; pointer-events: none; z-index: 10; background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-overlay); padding: var(--space-2) var(--space-3); font-size: 12px; line-height: 18px; min-width: 150px; opacity: 0; transition: opacity 80ms; }
.tooltip.on { opacity: 1; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 2px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip .tt-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-muted); }
.tooltip .tt-row b { font-family: var(--font-mono); font-weight: 500; color: var(--ink); }
.chart-foot { display: flex; justify-content: space-between; gap: var(--space-3); align-items: center; margin-top: var(--space-2); font-size: 12px; color: var(--ink-muted); flex-wrap: wrap; }
.linkbtn { font: inherit; font-size: 12px; background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; }
.linkbtn:hover { text-decoration: underline; }
.chart-table { margin-top: var(--space-3); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); }
.stat { border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-3); background: var(--surface); }
.stat .kpi-label { font-size: 11px; }
.stat-value { font-size: 22px; line-height: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- forms (intake) ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4) var(--space-5); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { border-top: 1px solid var(--line); padding-top: var(--space-4); margin-top: var(--space-2); }
.form-section h4 { font-size: 14px; font-weight: 600; margin-bottom: var(--space-3); }
.check { display: flex; gap: var(--space-2); align-items: flex-start; font-size: 14px; }
.check input { margin-top: 4px; accent-color: var(--primary); width: 16px; height: 16px; }
.input-unit { position: relative; }
.input-unit .t1-input { padding-right: 84px; width: 100%; }
.input-unit .unit { position: absolute; right: var(--space-3); top: 7px; font-size: 12px; color: var(--ink-muted); font-family: var(--font-mono); pointer-events: none; }
.t1-field .t1-input { width: 100%; }
.range-hint { font-size: 12px; color: var(--ink-muted); }
.warn-msg { font-size: 13px; line-height: 20px; color: var(--warning); }
.dropzone { border: 2px dashed var(--line-strong); border-radius: var(--radius-lg); padding: var(--space-6); text-align: center; color: var(--ink-muted); background: var(--surface); }
.dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.code { font-family: var(--font-mono); font-size: 12px; line-height: 18px; background: var(--surface-sunken); border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-3); overflow-x: auto; white-space: pre; margin: 0; }
.toast { position: fixed; bottom: var(--space-5); right: var(--space-5); background: var(--surface-raised); border: 1px solid var(--line); box-shadow: var(--shadow-overlay); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); font-size: 14px; z-index: 50; display: flex; gap: var(--space-3); align-items: center; max-width: 420px; }

/* ---------- responsive ---------- */
.t1-card { min-width: 0; }
.t1-card-head { flex-wrap: wrap; }
.select { max-width: 100%; }
.scroll-x { overflow-x: auto; }
.t1-table-wrap, .scroll-x, .visit-line { position: relative; }

@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-main-side { grid-template-columns: minmax(0, 1fr); }
  .pipeline { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidenav { display: none; }
  .main { padding: var(--space-5) var(--space-4); }
  .grid-2, .grid-3, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .pipeline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-track { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .topbar-org, .demo-flag { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .sidenav, .topbar, .head-actions, .tabs { display: none !important; } .shell { display: block; } }
