/* 2026-09-27: --paper, --ochre renamed to --facet-* — the old names collided with
   the Synapse brand tokens and silently redefined the portfolio's ground
   for this product (PRODUCT_TARGET_STATE_PLAN_2026-09-27 §3 L1). The
   product's own components are unchanged; brand tokens released. */
/* Facet (M1) — researcher console ("Side B": batch classification + audit
 * log over a clinic's patient population). Design tokens copied verbatim
 * from ../clinician/styles.css (BRANDBOOK.md's "mineral optics" palette) —
 * see that file for the full palette/typography rationale. System font
 * stacks only; this app's CSP has no font-src override for cross-origin
 * fonts, same as the clinician frontend.
 */

:root {
  /* 2026-09-27 Pass H: faces come from the Synapse semantic tokens — the surface
     class picks Atkinson (family) or Inter (clinical/research), headings are
     Fraunces everywhere (DD-46). A product-local face here overrode that. */
  --quartz-deep: #1F2A44;
  --quartz-mist: #EEF1F7;
  --slate-blue: #4C6A8C;
  --prism-amber: #E4A853;
  --verdant: #3D7A64;
  --facet-ochre: #B77A2B;
  --graphite: #1B1E23;
  --ash: #6B7280;
  --fog: #D9DEE5;
  --facet-paper: #FAFAF7;

  /* Verdant/Ochre at full strength don't reach 4.5:1 against white text, so
     filled controls use these darkened variants; the brand hues stay for
     borders, chips and accents. */
  --verdant-deep: #2E5F4D;
  --ochre-deep: #8C5F20;
  --quartz-hover: #16203380;

  --surface: #FFFFFF;
  --border: #DCE1E8;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(31, 42, 68, 0.08);

  --font-ui: var(--sy-face);
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-ui);
  background: var(--facet-paper);
  color: var(--graphite);
  line-height: 1.6;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--quartz-deep);
  color: #fff;
  padding: 10px 16px;
  z-index: 10;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid var(--slate-blue);
  outline-offset: 2px;
}

/* --------------------------------------------------------------- header --- */

.app-header {
  background: var(--quartz-deep);
  color: var(--facet-paper);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { flex: none; }
.brand-text { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }

.wordmark { font-size: 1.15rem; font-weight: 700; letter-spacing: 0.01em; }

.app-badge {
  background: rgba(228, 168, 83, 0.16);
  border: 1px solid var(--prism-amber);
  color: #F3CB8C;
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.header-right { display: flex; align-items: center; gap: 12px; }
.user-info { font-size: 0.85rem; color: #C7CFDB; }

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(250, 250, 247, 0.45);
  color: var(--facet-paper);
  padding: 6px 14px;
  font-size: 0.85rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.btn-ghost:hover { background: rgba(250, 250, 247, 0.12); }

/* ------------------------------------------------------- global status --- */

.global-status {
  max-width: 760px;
  margin: 16px auto 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  border-left: 4px solid var(--slate-blue);
  background: var(--quartz-mist);
  color: var(--quartz-deep);
}
.global-status.warn { border-left-color: var(--facet-ochre); background: #FBF0E1; }

/* ---------------------------------------------------------- structure --- */

.app { max-width: 760px; margin: 0 auto; padding: 16px 16px 40px; }

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}

h2 { font-size: 1.15rem; font-weight: 700; margin-bottom: 6px; color: var(--quartz-deep); }
h2:focus { outline: none; }
h2:focus-visible { outline: 3px solid var(--slate-blue); outline-offset: 4px; }
h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 8px; color: var(--quartz-deep); }

.section-note { color: var(--ash); font-size: 0.85rem; margin-bottom: 16px; }
.field-hint, .note { color: var(--ash); font-size: 0.85rem; }
.note { margin-top: 10px; }

.back-link {
  background: none;
  border: none;
  color: var(--slate-blue);
  padding: 0 0 8px;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.back-link:hover { color: var(--quartz-deep); text-decoration: underline; }

/* -------------------------------------------------------------- forms --- */

form { display: flex; flex-direction: column; gap: 14px; max-width: 460px; }
.field { display: flex; flex-direction: column; gap: 5px; }

label { font-size: 0.85rem; font-weight: 600; color: var(--quartz-deep); }

input[type=email],
input[type=password],
input[type=text] {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--graphite);
  width: 100%;
}
input:focus { border-color: var(--slate-blue); }

button {
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--quartz-deep);
  color: #fff;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover:not(:disabled) { background: #16203a; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button[aria-busy="true"] { cursor: progress; }

.btn-secondary {
  background: var(--surface);
  color: var(--quartz-deep);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--quartz-mist); }

.link-row { margin-top: 4px; font-size: 0.85rem; }
.link-row a { color: var(--slate-blue); font-weight: 600; text-decoration: none; }
.link-row a:hover { text-decoration: underline; }

.error {
  color: #9C3B1F;
  font-size: 0.85rem;
  margin-top: 8px;
}
.error:empty { display: none; }

.info-msg {
  color: var(--verdant-deep);
  font-size: 0.9rem;
  background: #E7F1EC;
  border-left: 3px solid var(--verdant);
  border-radius: 4px;
  padding: 10px 12px;
  margin-top: 8px;
}
.info-msg:empty { display: none; }

/* -------------------------------------------------------------- chips --- */

.chip {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.chip-determinate { background: #E1EEE7; color: var(--verdant-deep); }
.chip-indeterminate { background: #F7E7D2; color: var(--ochre-deep); }

/* --------------------------------------------------------- result view --- */

.lookup-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; max-width: none; }
.lookup-row .field { flex: 1 1 320px; }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  min-height: auto;
  color: var(--slate-blue);
  font-weight: 600;
  font-size: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover { color: var(--quartz-deep); }

/* ---------------------------------------------------------- patient list --- */

.patients-list { display: flex; flex-direction: column; gap: 8px; }

.patient-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-weight: 400;
  color: var(--graphite);
}
.patient-row:hover:not(:disabled) { background: var(--quartz-mist); border-color: var(--slate-blue); }
.patient-row-id { font-weight: 600; color: var(--quartz-deep); }
.patient-row-meta { font-size: 0.8rem; color: var(--ash); margin-left: auto; }

.result-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.result-subtype { font-size: 1.15rem; font-weight: 700; color: var(--quartz-deep); }
.result-confidence { font-size: 0.9rem; color: var(--ash); }

.result-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  background: var(--quartz-mist);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}
.result-meta dt { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ash); }
.result-meta dd { font-size: 0.85rem; word-break: break-all; }

.disclaimer {
  border: 1px solid var(--facet-ochre);
  border-left: 4px solid var(--facet-ochre);
  border-radius: var(--radius);
  background: #FBF0E1;
  color: var(--ochre-deep);
  padding: 12px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.indeterminate-note {
  border: 1px solid var(--facet-ochre);
  border-radius: var(--radius);
  background: #FDF6EC;
  color: var(--ochre-deep);
  padding: 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.probabilities { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.prob-row { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
.prob-label { flex: 0 0 190px; color: var(--graphite); }
.prob-bar { flex: 1; height: 8px; background: var(--fog); border-radius: 4px; overflow: hidden; }
.prob-bar-fill { height: 100%; background: var(--slate-blue); border-radius: 4px; }
.prob-value { flex: 0 0 46px; text-align: right; color: var(--ash); }

.implications-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.implication-col h4 { font-size: 0.85rem; color: var(--slate-blue); margin-bottom: 6px; }
.implication-col ul { padding-left: 18px; font-size: 0.85rem; }
.implication-col li { margin-bottom: 4px; }

.result-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }

.fhir-view {
  background: var(--quartz-mist);
  border-radius: var(--radius);
  padding: 12px;
  overflow-x: auto;
  font-size: 0.78rem;
  max-height: 420px;
}

/* -------------------------------------------------------------- footer --- */

.app-footer { max-width: 760px; margin: 0 auto; padding: 0 16px 40px; }

.footer-disclaimer { font-size: 0.78rem; color: var(--ash); padding-bottom: 12px; }

.portfolio-badge {
  background: var(--quartz-deep);
  color: var(--facet-paper);
  border-left: 3px solid var(--prism-amber);
  border-radius: 4px;
  padding: 12px 14px;
  font-size: 0.78rem;
}
.portfolio-badge-sub { display: block; margin-top: 4px; font-style: italic; color: #C7CFDB; }

@media (max-width: 560px) {
  section { padding: 18px 14px; }
  .app-header { padding: 12px 14px; }
  .prob-label { flex-basis: 120px; }
}

/* ------------------------------------------------------------- tab nav --- */

.tab-nav { display: flex; gap: 8px; margin-top: 16px; }
.tab-btn {
  background: var(--surface);
  color: var(--quartz-deep);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 600;
}
.tab-btn:hover:not(:disabled) { background: var(--quartz-mist); }
.tab-btn[aria-current="page"] { background: var(--quartz-deep); color: #fff; border-color: var(--quartz-deep); }

/* ------------------------------------------------------------ checkbox --- */

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--graphite);
  font-weight: 400;
}
.checkbox-field input[type=checkbox] { width: 16px; height: 16px; }

select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--graphite);
  width: 100%;
}

/* ---------------------------------------------------------- batch runs --- */

.patient-row-static { cursor: default; }
.patient-row-static:hover { background: var(--surface); border-color: var(--border); }

/* ------------------------------------------------------------ audit log --- */

.audit-filter-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; max-width: none; }
.audit-filter-row .field { flex: 0 1 200px; }

.audit-list { overflow-x: auto; }

.audit-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.audit-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  color: var(--ash);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.audit-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.audit-details { max-width: 360px; overflow-wrap: anywhere; }
