/* Compass — Synapse Spark Foundation portfolio identity/entry-funnel service.
 *
 * This is the one UI every clinician, researcher, and internal-ops person in
 * the portfolio sees before anything else. Visual identity is aligned with
 * the Foundation's own marketing site (synapsespark.org) per 2026-08
 * direction — same palette, same brand mark, same typography — rather than
 * a separate neutral theme, so the sign-in experience reads as one
 * continuous Foundation product instead of a disconnected internal tool.
 *
 * Fonts are self-hosted (fonts/*.woff2, fetched from the same Google Fonts
 * family/weights the marketing site loads) rather than linked from
 * fonts.googleapis.com/fonts.gstatic.com, so the CSP below can stay
 * 'self'-only — no cross-origin font request, same reasoning the rest of
 * the portfolio's strict-CSP frontends already follow (see facet-p3's
 * styles.css), just achieving visual parity without loosening it.
 *
 * Theme-aware: a `prefers-color-scheme: dark` block follows the light
 * (default) rules below, plus an explicit [data-theme] override — this
 * predates the alignment pass and is kept, just re-derived from the new
 * light palette instead of ripped out.
 */

@font-face {
  font-family: 'Fraunces';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('fonts/fraunces-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Fraunces';
  font-style: italic;
  font-weight: 300 500;
  font-display: swap;
  src: url('fonts/fraunces-italic.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/inter-var.woff2') format('woff2');
}

:root {
  /* Foundation brand palette — kept in sync with website/styles.css.
     If that palette ever changes, mirror the change here too. */
  --paper: #F7F1E3;
  --paper-warm: #EFE5D0;
  --ink: #14121A;
  --ink-mute: #55524A;
  --ochre: #E89A2E;
  --rust: #C8492E;
  --plum: #3A1F42;
  --line: #D8CDB6;
  --white: #FFFDF7;
  --teal: #1E7A6D;

  /* Compass's own semantic roles, re-mapped onto the brand palette above
     (was: navy ink / compass-gold / verdant / rust — a bespoke neutral
     theme). Kept as separate named roles so component CSS below doesn't
     need to change, just what each role resolves to. */
  --ink-soft: var(--rust);
  --compass-gold: var(--ochre);
  --verdant: var(--teal);
  --verdant-deep: color-mix(in srgb, var(--teal) 75%, black);
  --ochre-deep: color-mix(in srgb, var(--ochre) 70%, black);
  --graphite: var(--ink);
  --ash: var(--ink-mute);
  --fog: var(--paper-warm);
  --surface: var(--white);
  --border: var(--line);
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 2px 8px rgba(26, 26, 31, 0.06);
  --shadow-lift: 0 14px 34px rgba(26, 26, 31, 0.12);

  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

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

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

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden;
}

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

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

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

.app-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: var(--ink); }
.brand-mark { flex: none; color: var(--ink); }
.brand-text { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.wordmark {
  font-family: var(--font-display); font-size: 1.2rem; font-weight: 500;
  line-height: 1.05; display: flex; flex-direction: column; letter-spacing: 0;
}
.wordmark small {
  font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ash); font-weight: 500;
}

.app-badge {
  background: color-mix(in srgb, var(--ochre) 16%, transparent);
  border: 1px solid var(--ochre);
  color: var(--ochre-deep);
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-info { font-size: 0.85rem; color: var(--ash); }

.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--ink);
  padding: 8px 16px;
}
.btn-ghost:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); border-color: var(--ink); }

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

.global-status {
  max-width: 920px;
  margin: 16px auto 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  border-left: 4px solid var(--rust);
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--ink);
}
.global-status.warn { border-left-color: var(--ochre-deep); background: color-mix(in srgb, var(--ochre) 10%, var(--white)); color: var(--ochre-deep); }
.global-status.info { border-left-color: var(--verdant); background: color-mix(in srgb, var(--verdant) 10%, var(--white)); color: var(--verdant-deep); }

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

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

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-top: 16px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.22s ease;
}

h1 { font-family: var(--font-display); font-size: 1.5rem; font-weight: 500; margin-bottom: 8px; color: var(--ink); }
h2 { font-family: var(--font-display); font-size: 1.35rem; font-weight: 500; margin-bottom: 8px; color: var(--ink); }
h2:focus { outline: none; }
h2:focus-visible { outline: 3px solid var(--ochre); outline-offset: 4px; }
h3 { font-family: var(--font-display); font-size: 1.05rem; font-weight: 500; margin-bottom: 8px; color: var(--ink); }

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

.back-link, .link-btn {
  background: none;
  border: none;
  color: var(--rust);
  padding: 0;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.back-link:hover, .link-btn:hover { color: var(--ink); text-decoration: underline; }

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

form { display: flex; flex-direction: column; gap: 14px; }
.max-w { max-width: 420px; }
.max-w > .btn { display: flex; width: 100%; }
.field { display: flex; flex-direction: column; gap: 5px; }

label { font-size: 0.87rem; font-weight: 600; color: var(--ink); }

input[type=email], input[type=password], input[type=text], input[type=date],
select, textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--paper);
  color: var(--graphite);
  width: 100%;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--ochre);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ochre) 25%, transparent);
}

.checkbox-field { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-field input[type=checkbox] { width: auto; }
.checkbox-field label { font-weight: 500; }

.field-label { font-size: 0.87rem; font-weight: 600; color: var(--ink); }

.persona-fieldset { border: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.persona-fieldset legend { font-size: 0.87rem; font-weight: 600; color: var(--ink); padding: 0; margin-bottom: 2px; }
.persona-option {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; font-weight: 400; transition: border-color 0.18s ease, background 0.18s ease;
}
.persona-option:has(input:checked) { border-color: var(--ochre); background: color-mix(in srgb, var(--ochre) 8%, var(--surface)); }
.persona-option input[type=radio] { width: auto; margin-top: 3px; }
.persona-option-body { display: flex; flex-direction: column; gap: 2px; }
.persona-option-title { font-weight: 600; color: var(--ink); font-size: 0.92rem; }
.persona-option-desc { font-size: 0.82rem; color: var(--ash); }

.checkbox-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px 10px; margin-top: 4px;
}
.checkbox-grid .checkbox-field { gap: 6px; }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 22px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}
button:hover:not(:disabled), .btn:hover { background: var(--plum); transform: translateY(-1px); box-shadow: var(--shadow-lift); }
button:active:not(:disabled), .btn:active { transform: translateY(0); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button[aria-busy="true"] { cursor: progress; }

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn-secondary:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 6%, transparent); border-color: var(--ink); }

.btn-danger { background: var(--rust); }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--rust) 80%, black); }

/* Distinct call-to-action color from the default ink button (Sign in) —
   same size/shape, so "Create an account" reads as an equally valid path
   in rather than a secondary afterthought. */
.btn-accent { background: var(--teal); color: var(--white); }
.btn-accent:hover { background: var(--verdant-deep); }

.btn-small { padding: 7px 14px; font-size: 0.8rem; }

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

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

.info-msg {
  color: var(--verdant-deep);
  font-size: 0.9rem;
  background: color-mix(in srgb, var(--verdant) 10%, var(--white));
  border-left: 3px solid var(--verdant);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 8px;
}
.info-msg:empty { display: none; }

.warn-msg {
  color: var(--ochre-deep);
  font-size: 0.9rem;
  background: color-mix(in srgb, var(--ochre) 12%, var(--white));
  border-left: 3px solid var(--ochre);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 8px;
}
.warn-msg:empty { display: none; }

.access-request-banner {
  font-size: 0.9rem; border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 10px; border-left: 3px solid;
}
.access-request-pending { color: var(--ochre-deep); background: color-mix(in srgb, var(--ochre) 12%, var(--white)); border-left-color: var(--ochre); }
.access-request-approved { color: var(--verdant-deep); background: color-mix(in srgb, var(--verdant) 10%, var(--white)); border-left-color: var(--verdant); }
.access-request-rejected { color: var(--rust); background: color-mix(in srgb, var(--rust) 10%, var(--white)); border-left-color: var(--rust); }

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

.chip {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.chip-role { background: color-mix(in srgb, var(--verdant) 16%, var(--white)); color: var(--verdant-deep); }
.chip-staff { background: color-mix(in srgb, var(--ochre) 18%, var(--white)); color: var(--ochre-deep); }
.chip-muted { background: var(--fog); color: var(--ash); }

/* --------------------------------------------------------------- tiles --- */

.picker-section { margin-top: 28px; }
.picker-section:first-child { margin-top: 0; }
.section-rail {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px;
  border-left: 4px solid var(--rust); padding-left: 10px;
}
.section-rail.ops { border-left-color: var(--ochre); }
.section-rail h2 { margin-bottom: 0; }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.tile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.tile:hover:not(:disabled) { box-shadow: var(--shadow-lift); border-color: var(--ochre); transform: translateY(-2px); }
.tile:disabled { cursor: not-allowed; opacity: 0.75; background: var(--paper); }

.tile-identity { display: flex; flex-direction: column; gap: 4px; }
.tile-identity-header { display: flex; align-items: center; gap: 10px; }
.tile-icon { flex: none; width: 28px; height: 28px; display: inline-flex; }
.tile-icon svg { width: 100%; height: 100%; }
.tile-description { font-size: 0.8rem; color: var(--ash); line-height: 1.4; margin: 0; }

.tile-product { font-family: var(--font-display); font-size: 1.1rem; font-weight: 500; color: var(--ink); }
.tile-role { font-size: 0.8rem; color: var(--ash); }
.tile-status { font-size: 0.78rem; color: var(--rust); min-height: 1em; }
.tile-caption { font-size: 0.78rem; color: var(--ash); }

/* Item 3 (persona dashboards) — "your data here" line, filled in once
   GET /api/dashboard/summary resolves for a tile (picker.js's
   applySummaries()). Deliberately a plain line, not a colored chip/badge —
   this is descriptive ("3 studies · 42 participants"), not a status signal
   like .tile-status, so it shouldn't compete visually with real alerts. */
.tile-summary {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--verdant-deep);
  padding-top: 2px;
  border-top: 1px dashed var(--border);
  margin-top: 2px;
}

/* "My Health" cross-product dashboard (2026-08-15 unified-login rollout) —
   patient-persona tiles only (picker.js's renderPatientDetail()). Recreates
   each render rather than persisting state, so no separate hidden/visible
   toggle is needed — the block simply doesn't exist until there's real
   per-product data to show. */
.tile-health-detail {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
  margin-top: 2px;
}
.tile-recommendations {
  margin: 0;
  padding-left: 18px;
  font-size: 0.82rem;
  color: var(--ink);
}
.tile-recommendations li { margin: 2px 0; }
.tile-health-boundary { font-size: 0.72rem; color: var(--ash); font-style: italic; margin: 0; }
.tile-clinicians { font-size: 0.8rem; color: var(--ash); margin: 0; }

.tile.ops { border-left: 4px solid var(--ochre); }

details.request-access {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper-warm);
  padding: 4px 16px 16px;
}
details.request-access summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
  padding: 12px 0;
  font-size: 0.92rem;
}
details.request-access[open] summary { padding-bottom: 4px; }

.ra-tile {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ra-tile-title { font-weight: 700; font-size: 0.92rem; color: var(--ink); }
.ra-tile-note { font-size: 0.8rem; color: var(--ash); }
.ra-tile-status { font-size: 0.82rem; margin: 0; min-height: 1em; color: var(--rust); }
.ra-tile-status-ok { color: var(--verdant-deep); font-weight: 600; }

/* ------------------------------------------------------------ QR / MFA --- */

.qr-wrap {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  background: var(--paper-warm); border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.qr-wrap img { width: 176px; height: 176px; background: var(--white); border-radius: var(--radius-sm); }
.qr-meta { flex: 1 1 220px; min-width: 200px; }
.secret-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px;
}
.secret-value {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; font-size: 0.85rem; word-break: break-all; font-family: var(--font-mono);
}

.backup-codes {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px; margin: 12px 0;
}
.backup-code {
  background: var(--paper-warm); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px; text-align: center; font-size: 0.88rem; font-family: var(--font-mono);
}

/* -------------------------------------------------------------- tables --- */

.table-wrap { overflow-x: auto; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--ash); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: var(--paper-warm); }
td.wrap { white-space: normal; word-break: break-word; }

.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 4px; }
.filter-row .field { flex: 1 1 160px; }

.tab-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.tab-btn {
  background: var(--surface); color: var(--ink); border: 1.5px solid var(--border);
  border-radius: 999px; padding: 8px 16px; font-size: 0.85rem;
}
.tab-btn.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

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

.app-footer { max-width: 1040px; margin: 0 auto; padding: 0 16px 40px; }
.footer-note { font-size: 0.78rem; color: var(--ash); padding-bottom: 12px; }
.portfolio-badge {
  background: var(--paper-warm); color: var(--ink);
  border-left: 3px solid var(--ochre);
  border-radius: var(--radius-sm); padding: 14px 16px; font-size: 0.8rem;
}
.portfolio-badge-sub { display: block; margin-top: 4px; font-style: italic; color: var(--ash); }

@media (max-width: 560px) {
  section { padding: 20px 16px; }
  .app-header { padding: 12px 14px; }
  .qr-wrap { flex-direction: column; align-items: flex-start; }
}

/* ---------------------------------------------------------- dark theme --- */

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14121A;
    --paper-warm: #1D1A24;
    --ink: #F7F1E3;
    --ink-mute: #B8AF9C;
    --line: #3A3542;
    --white: #201C29;
    --graphite: var(--ink);
    --ash: var(--ink-mute);
    --fog: #2B2734;
    --surface: var(--white);
    --border: var(--line);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 14px 34px rgba(0, 0, 0, 0.5);
    --ochre-deep: color-mix(in srgb, var(--ochre) 80%, white);
    --verdant-deep: color-mix(in srgb, var(--teal) 75%, white);
  }
}

:root[data-theme="dark"] {
  --paper: #14121A;
  --paper-warm: #1D1A24;
  --ink: #F7F1E3;
  --ink-mute: #B8AF9C;
  --line: #3A3542;
  --white: #201C29;
  --graphite: var(--ink);
  --ash: var(--ink-mute);
  --fog: #2B2734;
  --surface: var(--white);
  --border: var(--line);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lift: 0 14px 34px rgba(0, 0, 0, 0.5);
  --ochre-deep: color-mix(in srgb, var(--ochre) 80%, white);
  --verdant-deep: color-mix(in srgb, var(--teal) 75%, white);
}

:root[data-theme="light"] {
  --paper: #F7F1E3;
  --paper-warm: #EFE5D0;
  --ink: #14121A;
  --ink-mute: #55524A;
  --line: #D8CDB6;
  --white: #FFFDF7;
  --graphite: var(--ink);
  --ash: var(--ink-mute);
  --fog: var(--paper-warm);
  --surface: var(--white);
  --border: var(--line);
  --shadow: 0 2px 8px rgba(26, 26, 31, 0.06);
  --shadow-lift: 0 14px 34px rgba(26, 26, 31, 0.12);
  --ochre-deep: color-mix(in srgb, var(--ochre) 70%, black);
  --verdant-deep: color-mix(in srgb, var(--teal) 75%, black);
}
