@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&display=swap');

:root {
  --color-white: #ffffff;
  --color-off-white: #f0efec;
  --color-surface: #f7f6f3;
  --color-tranquil: #c3c4c2;
  --color-near-black: #1c1c1a;
  --color-happy: #f8d164;
  --color-text-primary: #1c1c1a;
  --color-text-secondary: #6b6b69;
  --color-text-hint: #9b9b99;
  --color-text-ghost: #c3c4c2;
  --border-light: 1px solid rgba(28,28,26,0.08);
  --border-medium: 1px solid rgba(28,28,26,0.12);
  --border-strong: 1px solid rgba(28,28,26,0.20);
  --border-inverse: 1px solid rgba(255,255,255,0.07);
  --font-sans: 'DM Sans', sans-serif;
  --space-xs: 8px;
  --space-sm: 16px;
  --space-md: 24px;
  --space-lg: 32px;
  --space-xl: 48px;
  --space-2xl: 64px;
  --space-3xl: 96px;
  --gutter: 48px;
  --nav-height: 60px;
  --max-width: 1400px;
  --transition-fast: 0.15s ease;
  /* Status pill + pair border tokens (Brief 3, 2026-04-25).  Promoted from
     patient.html inline styles so designer pages can pick up the same
     pills in a later cleanup.  Contrast verified: draft 9.3:1, prescribed
     7.3:1, translate 5.0:1 — all pass WCAG AA at >4.5:1 on white. */
  --color-status-draft-bg: #fff7d6;
  --color-status-draft-fg: #7a4a00;
  --color-status-prescribed-bg: #ecf6ec;
  --color-status-prescribed-fg: #2a6b2a;
  --color-status-translate-bg: #f0efec;
  --color-status-translate-fg: #5a5a58;
  --color-pair-border: var(--color-happy);
}

/* Sort toggle (Brief 3.1) — small inline pair used above scrollable
   lists (drafts on the patient screen, patient list on the Patients
   screen).  Active option underlined; inactive options dimmed at
   opacity 0.55.  Click to re-render with the new sort key. */
.ps-sort { display: inline-flex; align-items: baseline; gap: 6px; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-text-primary); }
.ps-sort__btn { background: none; border: none; padding: 2px 4px; font: inherit; color: var(--color-text-primary); cursor: pointer; opacity: 0.55; }
.ps-sort__btn[aria-pressed="true"] { opacity: 1; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
.ps-sort__btn:hover { opacity: 1; }

/* Patient banner (Brief 3.1) — thin white strip at the top of each
   designer page identifying the patient and offering a one-click
   return path to /patient.html?id=<pid>.  Mounted via
   ThreeModes.renderPatientBanner({patientId}); designer pages each
   place a <div id="patientBanner" class="patient-banner"></div>
   above the design content. */
.patient-banner { max-width: var(--max-width); margin: 0 auto; width: 100%; box-sizing: border-box; background: var(--color-white); border-bottom: var(--border-light); padding: 10px var(--gutter); display: flex; align-items: center; gap: var(--space-md); flex-wrap: wrap; }
.patient-banner__back { font-size: 11px; font-weight: 400; letter-spacing: 0.09em; text-transform: uppercase; color: var(--color-text-primary); display: inline-flex; align-items: center; gap: 6px; transition: opacity var(--transition-fast); }
.patient-banner__back:hover { opacity: 0.6; }
.patient-banner__name { font-size: 14px; font-weight: 500; color: var(--color-text-primary); }
.patient-banner__ur { font-size: 11px; font-weight: 400; color: var(--color-text-secondary); margin-left: 8px; letter-spacing: 0.04em; }

/* Changelog (Brief 3.1) — per-lens edit history rendered by
   ThreeModes.renderChangelog into a designer-page <details> block.
   Compact, monospace-y diffs so "BOZR flat: 7.85 → 7.90" is
   instantly readable. */
.changelog { margin-top: var(--space-md); }
.changelog > summary { cursor: pointer; outline: none; user-select: none; font-size: 11px; font-weight: 500; letter-spacing: 0.09em; text-transform: uppercase; color: var(--color-text-primary); padding: 6px 0; }
.changelog-row { border-top: 1px solid rgba(28,28,26,0.08); padding: 8px 0; }
.changelog-row__header { display: flex; align-items: baseline; gap: 10px; font-size: 11px; color: var(--color-text-primary); flex-wrap: wrap; }
.changelog-row__kind { font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.changelog-row[data-kind="commit"] .changelog-row__kind { color: #2a6b2a; }
.changelog-row[data-kind="create"] .changelog-row__kind { color: #7a4a00; }
.changelog-row__date { font-variant-numeric: tabular-nums; }
.changelog-row__by { color: var(--color-text-secondary); }
.changelog-row__diff { margin: 6px 0 0 0; padding-left: 18px; font-size: 12px; line-height: 1.6; }
.changelog-row__diff code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; background: var(--color-surface); padding: 1px 4px; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font-sans); font-weight: 400; font-size: 16px; line-height: 1.6; color: var(--color-text-primary); background: var(--color-tranquil); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ── NAVIGATION ── */
/* `#nav` is the body-root wrapper that nav.js populates.  Sticky lives
   on the wrapper (not the inner .nav) because the wrapper's
   containing block is the body and spans the whole document height —
   the inner .nav's containing block would only be the wrapper's own
   60 px box, so its sticky un-sticks the moment the user scrolls
   past the nav's natural position.  Pages that use <nav id="nav"
   class="nav"> directly (the .app grid pages) get sticky from the
   id selector too — same end result. */
#nav { position: sticky; top: 0; z-index: 100; }
.nav { position: sticky; top: 0; z-index: 100; display: flex; align-items: center; justify-content: space-between; padding: 0 var(--gutter); height: var(--nav-height); background: var(--color-white); border-bottom: var(--border-medium); }
.nav__brand { display: flex; align-items: center; gap: 14px; }
.nav__logo { height: 36px; width: 36px; flex-shrink: 0; }
.nav__brand-divider { width: 1px; height: 28px; background: rgba(28,28,26,0.12); }
.nav__wordmark-link { display: flex; align-items: center; line-height: 0; }
.nav__wordmark { height: 34px; width: auto; }
.nav__links { display: flex; gap: 36px; align-items: center; }
.nav__link { font-size: 11px; font-weight: 400; letter-spacing: 0.09em; text-transform: uppercase; color: var(--color-text-secondary); transition: color var(--transition-fast); }
.nav__link:hover, .nav__link--active { color: var(--color-text-primary); }

/* Dropdown nav groups (Lens Designs / Tools).  Native <details>
   for click-toggle behaviour; absolute-positioned menu so the
   dropdown floats over page content instead of pushing it. */
.nav__dropdown { position: relative; display: flex; align-items: center; }
.nav__dropdown > summary { list-style: none; cursor: pointer; outline: none; user-select: none; display: inline-flex; align-items: center; gap: 4px; }
.nav__dropdown > summary::-webkit-details-marker { display: none; }
.nav__dropdown > summary::after { content: "▾"; font-size: 9px; opacity: 0.6; }
.nav__dropdown[open] > summary::after { content: "▴"; opacity: 1; }
.nav__dropdown-menu { position: absolute; right: 0; top: calc(100% + 8px); background: var(--color-white); border: var(--border-medium); min-width: 160px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); z-index: 110; display: flex; flex-direction: column; }
.nav__dropdown-link { display: block; padding: 10px 14px; font-size: 11px; font-weight: 400; letter-spacing: 0.09em; text-transform: uppercase; color: var(--color-text-secondary); transition: background var(--transition-fast), color var(--transition-fast); }
.nav__dropdown-link:hover { background: var(--color-surface); color: var(--color-text-primary); }
.nav__dropdown-link--active { background: var(--color-surface); color: var(--color-text-primary); }

/* ── PAGE HEADER ── */
.page-header { background: var(--color-white); padding: var(--space-2xl) var(--gutter) var(--space-xl); border-bottom: var(--border-medium); }
.page-header__eyebrow { font-size: 13px; font-weight: 500; text-transform: uppercase; color: var(--color-near-black); letter-spacing: 0.12em; margin-bottom: 14px; }
.page-header__title { font-size: 42px; font-weight: 600; line-height: 1.07; letter-spacing: -0.03em; color: var(--color-text-primary); max-width: 700px; }
.page-header__intro { font-size: 15px; font-weight: 300; color: var(--color-text-secondary); line-height: 1.75; max-width: 600px; margin-top: var(--space-md); }

/* ── CONTENT ── */
/* ── PAGE LAYOUT ── */
html, body { height: 100%; }
body { display: flex; flex-direction: column; }
.site-wrap { max-width: var(--max-width); margin: 0 auto; width: 100%; flex: 1; display: flex; flex-direction: column; }
.nav { max-width: var(--max-width); margin: 0 auto; width: 100%; }
.page-header { max-width: var(--max-width); margin: 0 auto; width: 100%; }
.content-body { background: var(--color-white); padding: var(--space-xl) var(--gutter); max-width: var(--max-width); margin: 0 auto; width: 100%; flex: 1; }
.content-body--surface { background: var(--color-surface); }
.footer { margin-top: auto; max-width: var(--max-width); margin-left: auto; margin-right: auto; width: 100%; position: sticky; bottom: 0; z-index: 100; }

/* ── BUTTONS ── */
.btn { display: inline-block; font-family: var(--font-sans); font-size: 11px; font-weight: 500; letter-spacing: 0.09em; text-transform: uppercase; padding: 13px 26px; border: none; cursor: pointer; transition: opacity var(--transition-fast); text-decoration: none; white-space: nowrap; }
.btn:hover { opacity: 0.85; }
.btn--yellow { background: var(--color-happy); color: var(--color-near-black); }
.btn--dark { background: var(--color-near-black); color: var(--color-off-white); }
.btn--outline { background: transparent; color: var(--color-near-black); border: 1px solid var(--color-near-black); }
.btn--ghost { background: transparent; color: var(--color-text-secondary); font-weight: 400; padding: 13px 0; display: inline-flex; align-items: center; gap: 10px; }
.btn--ghost::after { content: ''; display: inline-block; width: 20px; height: 1px; background: var(--color-text-hint); transition: width var(--transition-fast); }
.btn--ghost:hover::after { width: 28px; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── FORMS ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); max-width: 800px; }
.form-grid--full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 10px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-text-hint); }
.form-input, .form-select, .form-textarea { font-family: var(--font-sans); font-size: 14px; font-weight: 300; color: var(--color-text-primary); background: var(--color-surface); border: 1px solid rgba(28,28,26,0.15); padding: 12px 14px; width: 100%; border-radius: 0; appearance: none; outline: none; transition: border-color var(--transition-fast); }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--color-near-black); }
.form-textarea { min-height: 120px; resize: vertical; }
.form-note { font-size: 12px; font-weight: 300; color: var(--color-text-hint); line-height: 1.6; margin-top: var(--space-sm); max-width: 800px; }

/* ── TABLES ── */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-hint); padding: 10px 14px; border-bottom: var(--border-medium); }
.table td { padding: 12px 14px; border-bottom: var(--border-light); font-size: 14px; font-weight: 300; }
.table tr:hover td { background: var(--color-surface); }
.table .clickable { cursor: pointer; }

/* ── CARDS ── */
.card { background: var(--color-white); border-bottom: var(--border-medium); padding: var(--space-md) var(--gutter); }
.card--surface { background: var(--color-surface); }
.card-title { font-size: 10px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-text-hint); margin-bottom: 12px; }

/* ── SIDEBAR DEFINITION LIST ── */
.sidebar-dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin-top: 10px; }
.sidebar-dl__term { font-size: 11px; font-weight: 500; color: var(--color-text-hint); letter-spacing: 0.04em; padding-top: 2px; }
.sidebar-dl__def { font-size: 12px; font-weight: 300; color: var(--color-text-secondary); line-height: 1.5; padding-bottom: 6px; border-bottom: var(--border-light); }
.sidebar-dl__def:last-child { border-bottom: none; }

/* ── BADGES ── */
.badge { display: inline-block; padding: 2px 8px; font-size: 10px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.badge--base { background: rgba(248,209,100,0.2); color: #8a6d20; }

/* ── STATUS MESSAGES ── */
.form-message { padding: var(--space-md); margin-bottom: var(--space-lg); font-size: 14px; font-weight: 300; line-height: 1.65; border-left: 3px solid transparent; }
.form-message--success { background: #eaf3de; color: #27500a; border-left-color: #639922; }
.form-message--error { background: #fcebeb; color: #791f1f; border-left-color: #e24b4a; }
.form-message--info { background: var(--color-surface); color: var(--color-text-secondary); border-left-color: var(--color-text-ghost); }

/* ── INFO STRIP + FOOTER ── */
.info-strip { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--color-near-black); max-width: var(--max-width); margin: 0 auto; width: 100%; }
.info-strip__cell { padding: 26px var(--gutter); border-right: var(--border-inverse); }
.info-strip__cell:last-child { border-right: none; }
.info-strip__label { font-size: 10px; font-weight: 500; text-transform: uppercase; color: var(--color-text-hint); letter-spacing: 0.14em; margin-bottom: 6px; }
.info-strip__value { font-size: 15px; font-weight: 300; color: var(--color-off-white); letter-spacing: -0.01em; }
.info-strip__sub { font-size: 11px; color: var(--color-happy); margin-top: 3px; }

.footer { background: var(--color-near-black); border-top: var(--border-inverse); padding: var(--space-md) var(--gutter); display: flex; align-items: center; justify-content: space-between; text-transform: uppercase; }
.footer__copy { font-size: 11px; color: var(--color-happy); letter-spacing: 0.04em; }
.footer__links { display: flex; gap: var(--space-md); }
.footer__link { font-size: 11px; color: var(--color-happy); letter-spacing: 0.04em; transition: color var(--transition-fast); }
.footer__link:hover { color: var(--color-off-white); }
/* Live local-timezone date + clock, injected into the footer by nav.js
   (initFooterClock).  tabular-nums keeps the seconds from jittering width. */
.footer__clock { font-size: 11px; color: var(--color-happy); letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }

/* ── METRIC CARDS (designer) ── */
.metric-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: rgba(28,28,26,0.08); margin-bottom: var(--space-md); }
.metric-card { background: var(--color-white); padding: var(--space-md); }
.mc-label { font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.14em; color: var(--color-text-ghost); margin-bottom: 10px; }
.mc-value { font-size: 24px; font-weight: 600; color: var(--color-text-primary); font-variant-numeric: tabular-nums; }
.mc-unit { font-size: 10px; font-weight: 500; color: var(--color-text-hint); letter-spacing: 0.14em; margin-left: 4px; }

/* ── WORKING STEPS (designer) ── */
.wsteps { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: rgba(28,28,26,0.08); margin-bottom: var(--space-md); }
.wstep { background: var(--color-white); padding: var(--space-md); }
.wstep-title { font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.14em; color: var(--color-text-ghost); margin-bottom: var(--space-sm); padding-bottom: var(--space-xs); border-bottom: var(--border-light); }
.wstep-line { font-size: 14px; font-weight: 300; padding: 4px 0; display: flex; justify-content: space-between; border-bottom: var(--border-light); }
.wstep-line:last-child { border-bottom: none; }
.wstep-line .wk { color: var(--color-text-secondary); }
.wstep-line .wv { color: var(--color-text-primary); font-weight: 500; }
.wstep-line .wv.hi1 { color: var(--color-near-black); }
.wstep-line .wv.hi2 { color: #8a6d20; }
.wstep-line .wv.pass { color: #27500a; }
.wstep-line .wv.fail { color: #791f1f; }

/* ── POWER MAP CARDS ── */
.maps-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: rgba(28,28,26,0.08); margin-bottom: var(--space-md); }
.map-card { background: var(--color-white); padding: var(--space-md); text-align: center; position: relative; }
.map-card canvas { border: none; margin: 0 auto; cursor: crosshair; }
.map-legend { display: flex; justify-content: center; gap: 6px; margin-top: var(--space-xs); font-size: 9px; color: var(--color-text-hint); }
.map-legend span { display: inline-flex; align-items: center; gap: 2px; }
.map-readout { position: absolute; top: 10px; left: 10px; background: rgba(28,28,26,0.88); color: var(--color-off-white); font-size: 10px; line-height: 1.5; padding: 6px 10px; pointer-events: none; display: none; white-space: pre; z-index: 10; }

/* ── MODE TABS (designer sidebar) ── */
.mode-tabs { display: flex; gap: 0; margin-bottom: var(--space-sm); }
.mode-tab { flex: 1; background: var(--color-surface); border: 1px solid rgba(28,28,26,0.15); border-right: none; color: var(--color-text-secondary); font-family: var(--font-sans); font-size: 11px; font-weight: 500; padding: 10px 4px; text-align: center; cursor: pointer; letter-spacing: 0.09em; text-transform: uppercase; transition: all var(--transition-fast); }
.mode-tab:last-child { border-right: 1px solid rgba(28,28,26,0.15); }
.mode-tab:hover { background: var(--color-off-white); }
.mode-tab.active { background: var(--color-near-black); color: var(--color-off-white); border-color: var(--color-near-black); }

/* ── ANIMATIONS ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.anim-fade-up { animation: fadeUp 0.5s ease forwards; }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  :root { --gutter: 28px; }
  .page-header__title { font-size: 32px; }
  .info-strip { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .maps-row { grid-template-columns: 1fr; }
  .metric-row { grid-template-columns: repeat(2, 1fr); }
  .wsteps { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  :root { --gutter: 20px; --nav-height: 56px; }
}

/* ── Brief 42 — append-only clinician notes (designer panel +
   save-modal existing-notes list + patient-card hover popup). ── */
.notes-panel {
  /* Align to the working bands (.content-body): capped at --max-width and
     centred, with gutter horizontal padding so the note content lines up with
     the design output above it.  Previously margin:gutter with no max-width let
     it stretch to the full viewport (wider than the working panel on wide
     screens). */
  max-width: var(--max-width);
  width: 100%;
  box-sizing: border-box;
  margin: 0 auto;
  padding: 10px var(--gutter);
  background: var(--color-surface);
  border-left: 3px solid rgba(28,28,26,0.18);
  font-size: 12px;
  line-height: 1.5;
  color: var(--color-text-primary);
}
.notes-panel-header,
.modal-notes-header,
.card-notes-popup-header {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--color-text-hint);
  margin-bottom: 6px;
}
.notes-panel-body,
.modal-notes-body,
.card-notes-popup-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.note-entry {
  padding: 6px 0;
  border-bottom: 1px solid rgba(28,28,26,0.06);
}
.note-entry:last-child { border-bottom: none; }
.note-meta {
  font-size: 10px;
  color: var(--color-text-hint);
  margin-bottom: 2px;
  font-family: var(--font-mono, ui-monospace, monospace);
}
.note-migrated {
  font-style: italic;
  color: var(--color-text-hint);
}
.note-text {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Save-modal existing-notes list — compact, scrolls when many. */
.modal-notes-header { margin-top: var(--space-sm); }
.modal-notes-body {
  max-height: 180px;
  overflow-y: auto;
  padding: 6px 10px;
  background: var(--color-surface);
  border-left: 2px solid rgba(28,28,26,0.15);
  font-size: 11px;
}

/* Patient-card chip + hover popup. */
.ps-card { position: relative; }
.card-notes-chip {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--color-near-black);
  color: var(--color-off-white);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 8px;
  pointer-events: none;
  z-index: 2;
}
.card-notes-popup {
  position: absolute;
  top: 0;
  left: calc(100% + 8px);
  width: 280px;
  max-height: 320px;
  overflow-y: auto;
  padding: 10px 12px;
  background: var(--color-off-white);
  border: 1px solid rgba(28,28,26,0.15);
  box-shadow: 0 4px 12px rgba(28,28,26,0.10);
  font-size: 11px;
  line-height: 1.5;
  color: var(--color-text-primary);
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
}
.ps-card:hover > .card-notes-popup {
  opacity: 1;
  visibility: visible;
}
