/* Prism (K2) — clinician CDS.
 *
 * Palette is BRANDBOOK.md's, and only BRANDBOOK.md's. The page previously stacked
 * three unrelated schemes: a Synapse Spark Foundation-branded strip (#F8F3E7 /
 * #0B1E3F / #F5A623 — the parent navy+amber the brandbook explicitly forbids as
 * Prism's primary), a generic blue (#2b6cb0) for every functional control, and
 * none of Prism's own colours anywhere. The parent lockup now lives where the
 * brandbook puts it: a portfolio badge at the foot of the page, never louder than
 * the Prism wordmark.
 *
 * Typography is a system stack rather than the brandbook's DM Sans / Inter /
 * JetBrains Mono webfonts: the app's CSP is default-src 'self' with no font-src,
 * and loading Google Fonts on a clinician-facing PHI surface would both break
 * under that policy and leak a third-party request per page view.
 */

:root {
  /* Brandbook palette */
  --prism-slate: #1E2D3D;
  --spectrum-teal: #2AA8A0;
  --refraction-amber: #E8A838;
  --indigo: #5B67CA;
  --clinical-white: #F8FAFB;
  --fog: #EDF1F4;
  --alert-red: #D94F4F;
  --ash: #6E7E8E;

  /* Derived shades. Spectrum Teal and Alert Red at full strength do not reach
     4.5:1 against white text (2.9:1 and 4.05:1), so filled controls use these
     darkened variants; the brand hues stay for borders, bars and accents. */
  --teal-deep: #1B7F79;
  --teal-deeper: #14655F;
  --red-deep: #B93B3B;
  --indigo-deep: #4A55B0;
  --slate-hover: #2C4055;

  --surface: #FFFFFF;
  --border: #DCE4EA;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(30, 45, 61, 0.08);

  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --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(--clinical-white);
  color: var(--prism-slate);
  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(--prism-slate);
  color: #fff;
  padding: 10px 16px;
  z-index: 10;
}
.skip-link:focus { left: 0; }

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

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

.app-header {
  background: var(--prism-slate);
  color: var(--clinical-white);
  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: 600;
  letter-spacing: 0.02em;
}

.nav-badge {
  background: rgba(42, 168, 160, 0.18);
  border: 1px solid var(--spectrum-teal);
  color: #7FD8D2;
  font-size: 0.68rem;
  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: #C3CFDA; }

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(248, 250, 251, 0.45);
  color: var(--clinical-white);
  padding: 6px 14px;
  font-size: 0.85rem;
}
.btn-ghost:hover { background: rgba(248, 250, 251, 0.12); }

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

.global-status {
  max-width: 820px;
  margin: 16px auto 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  border-left: 4px solid var(--spectrum-teal);
  background: var(--fog);
  color: var(--prism-slate);
}
.global-status.warn { border-left-color: var(--refraction-amber); background: #FDF4E3; }

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

.app { max-width: 820px; 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);
}

section .subsection {
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0;
  box-shadow: none;
  padding: 20px 0 0;
  margin-top: 24px;
}

h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--prism-slate);
}
h2:focus { outline: none; }
h2:focus-visible { outline: 3px solid var(--spectrum-teal); outline-offset: 4px; }

h3 { font-size: 0.98rem; font-weight: 600; margin-bottom: 8px; color: var(--prism-slate); }

.subsection-note, .field-hint, .note { color: var(--ash); font-size: 0.82rem; }
.note { margin-top: 10px; }
.empty { color: var(--ash); font-size: 0.9rem; padding: 8px 0; }

.back-link {
  background: none;
  border: none;
  color: var(--teal-deep);
  padding: 0 0 8px;
  font-size: 0.85rem;
  font-weight: 500;
}
.back-link:hover { color: var(--teal-deeper); text-decoration: underline; }

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

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

label { font-size: 0.87rem; font-weight: 500; color: var(--prism-slate); }

input[type=email],
input[type=password],
input[type=text],
input[type=number],
select,
textarea {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--prism-slate);
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--spectrum-teal); }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
legend { font-size: 0.87rem; font-weight: 600; padding: 0 6px; }

.radio-row { display: flex; flex-direction: column; gap: 8px; }
.radio, .checkbox { font-weight: 400; display: flex; align-items: flex-start; gap: 8px; }
.radio input, .checkbox input { width: auto; margin-top: 4px; }
.checkbox-field { max-width: none; }

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

.btn-secondary {
  background: var(--surface);
  color: var(--prism-slate);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--fog); }

.btn-danger { background: var(--red-deep); }
.btn-danger:hover:not(:disabled) { background: #9C3131; }

.link-btn {
  background: none;
  border: none;
  color: var(--teal-deep);
  padding: 6px 0 0;
  font-size: 0.82rem;
  font-weight: 500;
}
.link-btn:hover:not(:disabled) { background: none; color: var(--teal-deeper); text-decoration: underline; }

.error {
  color: var(--red-deep);
  font-size: 0.85rem;
  margin-top: 8px;
}
.error:empty { display: none; }

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

.chip {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.chip-ok { background: #DDF0EE; color: #14655F; }
.chip-warn { background: #FBEBCF; color: #7A5410; }
.chip-danger { background: #F7DFDF; color: #8E2F2F; }
.chip-muted { background: var(--fog); color: var(--ash); }
.chip-band-high { background: #DDF0EE; color: #14655F; }
.chip-band-moderate { background: #FBEBCF; color: #7A5410; }
.chip-band-indeterminate { background: #F7DFDF; color: #8E2F2F; }

/* ------------------------------------------------------------ patients --- */

.patient-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }

.patient-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--spectrum-teal);
  border-radius: var(--radius);
  color: var(--prism-slate);
  font-weight: 400;
}
.patient-row:hover:not(:disabled) { background: var(--fog); }
.patient-id { font-family: var(--font-mono); font-weight: 600; }
.patient-ref { font-size: 0.8rem; color: var(--ash); }
.patient-date { font-size: 0.78rem; color: var(--ash); margin-left: auto; }

.add-patient {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--clinical-white);
}
.add-patient summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.add-patient form { margin-top: 14px; }

/* -------------------------------------------------------- patient record --- */

.record-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  background: var(--fog);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}
.record-meta dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ash); }
.record-meta dd { font-size: 0.9rem; }

.record-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

.consent-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.consent-row:last-child { border-bottom: none; }
.consent-copy { flex: 1 1 260px; }
.consent-title { font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.consent-desc { font-size: 0.82rem; color: var(--ash); }
.consent-meta { font-size: 0.75rem; color: var(--ash); }

/* ------------------------------------------------------------- history --- */

.history-entry {
  border: 1px solid var(--border);
  border-left: 3px solid var(--indigo);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.history-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.history-date { font-size: 0.82rem; color: var(--ash); }
.history-model { font-size: 0.75rem; color: var(--ash); margin-left: auto; }
.history-body p { font-size: 0.9rem; }
.history-meta { font-size: 0.78rem; color: var(--ash); }
.history-reason { color: var(--ash); }
.outcome-strip { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.history-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------ recommendation --- */

.disclaimer {
  background: #FDF4E3;
  border: 1px solid var(--refraction-amber);
  border-radius: 6px;
  padding: 12px;
  font-size: 0.82rem;
  color: #6B4A0C;
  margin-bottom: 16px;
}

.confidence-banner {
  padding: 12px;
  border-radius: 6px;
  font-size: 0.98rem;
  font-weight: 600;
  margin-bottom: 16px;
  text-align: center;
  border: 1px solid transparent;
}
.confidence-banner.high { background: #DDF0EE; color: #14655F; border-color: var(--spectrum-teal); }
.confidence-banner.moderate { background: #FBEBCF; color: #7A5410; border-color: var(--refraction-amber); }
.confidence-banner.indeterminate { background: #F7DFDF; color: #8E2F2F; border-color: var(--alert-red); }

.indeterminate {
  border: 1px solid var(--alert-red);
  border-radius: var(--radius);
  background: #FDF6F6;
  padding: 14px;
  margin-bottom: 16px;
}

.ranked-paths { list-style: none; margin-bottom: 16px; }

.path-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--surface);
}
.path-card.top { border-left: 4px solid var(--spectrum-teal); background: #F4FAFA; }
.path-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.path-name { font-weight: 600; }
.path-prob { font-size: 1.1rem; font-weight: 700; color: var(--teal-deeper); }
.path-bar { height: 8px; background: var(--fog); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.path-bar-fill { height: 100%; background: var(--spectrum-teal); border-radius: 4px; transition: width 0.4s; }
.path-card.top .path-bar-fill { background: var(--teal-deep); }

.explainability {
  background: var(--fog);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.factor-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.factor-source { color: var(--ash); font-size: 0.78rem; }
.factor-direction { font-weight: 700; }
.factor-direction.positive { color: var(--teal-deeper); }
.factor-direction.negative { color: var(--red-deep); }
.counterfactual {
  margin-top: 12px;
  padding: 10px;
  background: #FDF4E3;
  border-left: 3px solid var(--refraction-amber);
  border-radius: 4px;
  font-size: 0.85rem;
  font-style: italic;
  color: #6B4A0C;
}
.counterfactual:empty { display: none; }
.calibration-note { margin-top: 10px; font-size: 0.78rem; color: var(--ash); }

/* ------------------------------------------------------------ decision --- */

.decision-panel { border-top: 1px solid var(--border); padding-top: 16px; }

/* Accept / Adjust / Override are deliberately identical in size and weight —
   BRANDBOOK: override is a first-class action and must be as prominent as
   accept, never a secondary or hidden control. */
.decision-actions { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }

.action-btn {
  flex: 1 1 120px;
  padding: 12px;
  background: var(--surface);
  color: var(--prism-slate);
  border: 2px solid var(--border);
  font-weight: 600;
}
.action-btn:hover:not(:disabled) { background: var(--fog); }
.action-btn.accept { border-color: var(--spectrum-teal); }
.action-btn.adjust { border-color: var(--indigo); }
.action-btn.override { border-color: var(--prism-slate); }
.action-btn.accept[aria-pressed="true"] { background: var(--teal-deep); border-color: var(--teal-deep); color: #fff; }
.action-btn.adjust[aria-pressed="true"] { background: var(--indigo-deep); border-color: var(--indigo-deep); color: #fff; }
.action-btn.override[aria-pressed="true"] { background: var(--prism-slate); border-color: var(--prism-slate); color: #fff; }
.action-btn[aria-pressed="true"]:hover:not(:disabled) { filter: brightness(1.1); }

.decision-recorded {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--spectrum-teal);
  border-left: 4px solid var(--spectrum-teal);
  border-radius: var(--radius);
  background: #F4FAFA;
}

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

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

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

.portfolio-badge {
  background: var(--prism-slate);
  color: var(--clinical-white);
  border-left: 3px solid var(--spectrum-teal);
  border-radius: 4px;
  padding: 12px 14px;
  font-size: 0.78rem;
}
.portfolio-badge-sub {
  display: block;
  margin-top: 4px;
  font-style: italic;
  color: #B9C6D2;
}

@media (max-width: 560px) {
  section { padding: 18px 14px; }
  .app-header { padding: 12px 14px; }
  .patient-date { margin-left: 0; }
}
