/* ============================================================================
   Ladder (K3) — Application Design System v3
   Premium clinical aesthetic · neurodiverse-safe · sidebar-driven layout

   Palette, typography and the mark are the Brandbook.md spec. The previous
   version was a Tailwind/Material grab-bag: a saturated teal on a COOL grey
   canvas, where the brandbook calls for a deep teal on a WARM neutral, "low
   chroma, sensory-safe". Every semantic colour below is also contrast-checked
   against the surface it is actually painted on, because the badge and chip
   colours all failed WCAG AA at the 11.5px they are rendered at (chip--stable
   was 2.23:1).
   ============================================================================ */

@font-face {
  font-family: 'Inter';
  src: url('../fonts/inter.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* Fraunces is the heading face and, per the brandbook, "Ladder's
   differentiator". It was specified and then never loaded. */
@font-face {
  font-family: 'Fraunces';
  src: url('../fonts/fraunces.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* Dose values and drug names are tabular data and must align in a column. */
@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono.woff2') format('woff2');
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Brand — Brandbook.md */
  --color-primary: #1F5A5B;          /* Rung Teal */
  --color-primary-dark: #0E2F30;     /* Anvil */
  --color-primary-light: #DCE8E6;
  --color-primary-lighter: #EEF4F2;
  --color-primary-glow: rgba(31, 90, 91, 0.16);
  --color-secondary: #8DAA9D;        /* Meadow */
  /* Meadow at 2.5:1 against white fails AA when used as the light end of a
     primary→secondary gradient behind white button/label text. Darkened
     variant (5.06:1 on white) for that specific use only. */
  --color-secondary-contrast: #577568;
  --color-accent: #C8622E;           /* Ember — titration decision points */
  --color-accent-bg: #F7E6DC;
  --color-accent-ink: #8A3F17;

  --color-ink: #1B2321;              /* Charcoal */
  --color-slate: #5A6260;            /* body text — 6.0:1 on Paper */
  /* 4.6:1 on Paper. The old #8A9E9D was 2.82:1 and was used for the sign-out
     control and every input placeholder. */
  --color-muted: #6B7370;
  --color-canvas: #F6F3EC;           /* warm neutral */
  --color-white: #FFFFFF;            /* Paper */
  --color-border: #D9D5CC;           /* Stone */
  --color-border-subtle: #E8E4DB;

  /* Semantic. Foreground values are darkened from the previous Tailwind
     defaults purely to clear 4.5:1 on their own tinted backgrounds. */
  --color-stable: #1F6B4F;
  --color-stable-bg: #DFEDE6;
  --color-caution: #8A5A10;          /* Amber Muted, darkened for contrast */
  --color-caution-bg: #F6EBD5;
  --color-alert: #9E2B24;            /* Signal Red, darkened for contrast */
  --color-alert-bg: #F6E0DE;

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-size-h1: 26px;
  --font-size-h2: 17px;
  --font-size-body: 14px;
  --font-size-small: 13px;
  /* Was 11.5px — below the practical legibility floor for the chips, badges
     and severity labels that are the primary clinical signal in this UI. */
  --font-size-micro: 12.5px;
  --line-height: 1.6;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --shadow-xs: 0 1px 2px rgba(27, 35, 33, 0.04);
  --shadow-sm: 0 1px 3px rgba(27, 35, 33, 0.06), 0 1px 2px rgba(27, 35, 33, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(27, 35, 33, 0.07), 0 2px 4px -2px rgba(27, 35, 33, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(27, 35, 33, 0.08), 0 4px 6px -4px rgba(27, 35, 33, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(27, 35, 33, 0.1), 0 8px 10px -6px rgba(27, 35, 33, 0.05);
  --shadow-glow: 0 0 0 3px var(--color-primary-glow);
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 350ms cubic-bezier(0.4, 0, 0.2, 1);
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-xxl: 48px;
  --sidebar-width: 240px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  line-height: var(--line-height);
  color: var(--color-ink);
  background-color: var(--color-canvas);
  min-height: 100vh;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

::selection {
  background: var(--color-primary);
  color: var(--color-white);
}

a { color: var(--color-primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--color-primary-dark); text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: 3px; }

button {
  font-family: var(--font-family);
  cursor: pointer;
  border: none;
  background: none;
}
button:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

h1 {
  font-family: var(--font-display);
  font-size: var(--font-size-h1);
  font-weight: var(--font-weight-semibold);
  line-height: 1.2;
  color: var(--color-ink);
  letter-spacing: -0.01em;
}
h1:focus-visible, h2:focus-visible, [tabindex="-1"]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
  border-radius: 4px;
}

h2 {
  font-size: var(--font-size-h2);
  font-weight: var(--font-weight-semibold);
  line-height: 1.35;
  letter-spacing: -0.01em;
}

h3 { font-size: var(--font-size-body); font-weight: var(--font-weight-semibold); line-height: 1.4; }

/* ── Sidebar Navigation ──────────────────────────────────────────────────── */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--color-white);
  border-right: 1px solid var(--color-border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform var(--transition-normal);
}

.sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-accent) 50%, var(--color-primary-dark) 100%);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 20px 23px;
}

.sidebar__title {
  font-size: 19px;
  font-weight: var(--font-weight-bold);
  color: var(--color-primary-dark);
  letter-spacing: -0.02em;
}

.sidebar__nav {
  flex: 1;
  padding: 8px 12px 8px 15px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  font-size: var(--font-size-small);
  font-weight: var(--font-weight-medium);
  color: var(--color-slate);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  text-decoration: none;
  position: relative;
}

.sidebar__link:hover {
  background: var(--color-primary-lighter);
  color: var(--color-primary-dark);
  text-decoration: none;
}

.sidebar__link--active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: var(--font-weight-semibold);
  box-shadow: inset 0 0 0 1px rgba(31, 90, 91, 0.1);
}

.sidebar__link svg { flex-shrink: 0; opacity: 0.6; transition: opacity var(--transition-fast); }
.sidebar__link:hover svg { opacity: 0.85; }
.sidebar__link--active svg { opacity: 1; color: var(--color-primary); }

.sidebar__footer {
  padding: 16px 20px 16px 23px;
  border-top: 1px solid var(--color-border-subtle);
}

.sidebar__user {
  font-size: var(--font-size-micro);
  color: var(--color-slate);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__logout {
  font-size: var(--font-size-micro);
  color: var(--color-muted);
  padding: 4px 0;
  transition: color var(--transition-fast);
  font-weight: var(--font-weight-medium);
}

.sidebar__logout:hover { color: var(--color-alert); }

/* ── Mobile Header ────────────────────────────────────────────────────────── */

.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border-subtle);
  box-shadow: var(--shadow-xs);
  z-index: 150;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.mobile-header__toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.mobile-header__toggle:hover { background: var(--color-canvas); }

.mobile-header__toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--color-ink);
  border-radius: 2px;
  transition: all var(--transition-fast);
}

.mobile-header__title {
  font-size: 16px;
  font-weight: var(--font-weight-bold);
  color: var(--color-primary-dark);
  letter-spacing: -0.01em;
}

/* ── App Body ─────────────────────────────────────────────────────────────── */

.app-body {
  margin-left: var(--sidebar-width);
  padding: var(--space-xl) 40px;
  min-height: 100vh;
  max-width: calc(1440px + var(--sidebar-width));
}

/* ── Card / Panel ─────────────────────────────────────────────────────────── */

.card {
  background: var(--color-white);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-normal), transform var(--transition-normal);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border-subtle);
}

.card__title { font-size: var(--font-size-h2); font-weight: var(--font-weight-semibold); }
.card__body { font-size: var(--font-size-body); line-height: var(--line-height); }

.panel {
  background: var(--color-white);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.panel__header {
  padding: 12px var(--space-lg);
  background: var(--color-canvas);
  border-bottom: 1px solid var(--color-border-subtle);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-micro);
  color: var(--color-slate);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel__body { padding: var(--space-lg); }

/* ── Status Chips ─────────────────────────────────────────────────────────── */

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 100px;
  font-size: var(--font-size-micro);
  font-weight: var(--font-weight-semibold);
  line-height: 1.8;
  white-space: nowrap;
}

.chip--titrating { background: var(--color-caution-bg); color: var(--color-caution); }
.chip--watch { background: var(--color-alert-bg); color: var(--color-alert); }
.chip--stable { background: var(--color-stable-bg); color: var(--color-stable); }
.chip--discontinued, .chip--switched { background: var(--color-border-subtle); color: var(--color-slate); }
.chip--urgent { background: var(--color-alert-bg); color: var(--color-alert); font-weight: var(--font-weight-bold); }
.chip--info { background: var(--color-primary-light); color: var(--color-primary); }

/* ── Severity Badges ──────────────────────────────────────────────────────── */

.severity-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-micro);
  font-weight: var(--font-weight-semibold);
}

.severity-badge--urgent { background: var(--color-alert-bg); color: var(--color-alert); }
.severity-badge--watch { background: var(--color-caution-bg); color: var(--color-caution); }
.severity-badge--info { background: var(--color-primary-light); color: var(--color-primary); }

.severity-dot { width: 7px; height: 7px; border-radius: 50%; }
.severity-dot--urgent { background: var(--color-alert); }
.severity-dot--watch { background: var(--color-caution); }
.severity-dot--info { background: var(--color-primary); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px 22px;
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  position: relative;
  letter-spacing: 0.005em;
}

.btn--primary {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary-contrast) 100%);
  color: var(--color-white);
  box-shadow: 0 1px 3px rgba(31, 90, 91, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.btn--primary:hover {
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
  box-shadow: 0 4px 12px rgba(31, 90, 91, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.btn--primary:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(31, 90, 91, 0.3);
}

.btn--secondary {
  background: var(--color-white);
  color: var(--color-primary);
  border: 1.5px solid var(--color-border);
  box-shadow: var(--shadow-xs);
}

.btn--secondary:hover {
  background: var(--color-primary-lighter);
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.btn--ghost { color: var(--color-slate); }
.btn--ghost:hover { background: var(--color-canvas); color: var(--color-ink); }

.btn--sm { padding: 7px 14px; font-size: var(--font-size-small); }
.btn--lg { padding: 14px 30px; font-size: 15px; font-weight: var(--font-weight-semibold); }
.btn--block { width: 100%; }

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ── Form Controls ────────────────────────────────────────────────────────── */

.form-group { margin-bottom: var(--space-lg); }

.form-label {
  display: block;
  font-size: var(--font-size-small);
  font-weight: var(--font-weight-medium);
  color: var(--color-slate);
  margin-bottom: 6px;
}

.form-input {
  display: block;
  width: 100%;
  padding: 11px 14px;
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  color: var(--color-ink);
  background: var(--color-white);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input::placeholder { color: var(--color-muted); }

.form-input:hover { border-color: var(--color-muted); }

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-glow), var(--shadow-xs);
}

select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23556B6A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ── Cockpit Layout ───────────────────────────────────────────────────────── */

.cockpit {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--space-lg);
  min-height: calc(100vh - 48px);
}

.cockpit__sidebar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding-right: 4px;
}

.cockpit__sidebar::-webkit-scrollbar { width: 4px; }
.cockpit__sidebar::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }

.cockpit__detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/* Patient List Item */
.patient-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 12px 14px;
  background: var(--color-white);
  border: 1.5px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.patient-item:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
  transform: translateX(2px);
}

.patient-item--active {
  border-color: var(--color-primary);
  background: var(--color-primary-lighter);
  box-shadow: 0 0 0 1px var(--color-primary), var(--shadow-sm);
}

.patient-item__info { flex: 1; min-width: 0; }

.patient-item__ref {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-body);
  color: var(--color-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.patient-item__meta {
  font-size: var(--font-size-micro);
  color: var(--color-slate);
  margin-top: 2px;
}

/* ── Patient Detail Header ────────────────────────────────────────────────── */

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--space-lg);
  background: var(--color-white);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.detail-header__left { display: flex; flex-direction: column; gap: var(--space-xs); }

.detail-header__title { font-size: 20px; font-weight: var(--font-weight-bold); letter-spacing: -0.01em; }

.detail-header__subtitle {
  font-size: var(--font-size-small);
  color: var(--color-slate);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.detail-header__right { display: flex; align-items: center; gap: var(--space-lg); }

.detail-header__metric { text-align: center; }

.detail-header__metric-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 28px;
  font-weight: var(--font-weight-bold);
  color: var(--color-primary);
  letter-spacing: -0.02em;
}

.detail-header__metric-label { font-size: var(--font-size-micro); color: var(--color-slate); }

/* ── Timeline Visualization ───────────────────────────────────────────────── */

.timeline-chart {
  background: var(--color-white);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  min-height: 280px;
  box-shadow: var(--shadow-sm);
}

.timeline-chart__title {
  font-size: var(--font-size-micro);
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-md);
}

.timeline-chart svg { width: 100%; overflow: visible; }

.timeline-dose-line { fill: none; stroke: var(--color-primary); stroke-width: 2.5; }
.timeline-dose-step { fill: var(--color-primary); }
.timeline-symptom-line { fill: none; stroke: var(--color-caution); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.timeline-se-marker { fill: var(--color-alert); opacity: 0.8; }
.timeline-adherence-band { opacity: 0.5; }
.timeline-adherence-band--taken { fill: var(--color-stable); }
.timeline-adherence-band--late { fill: var(--color-caution); }
.timeline-adherence-band--missed { fill: var(--color-alert); }
.timeline-axis { stroke: var(--color-border); stroke-width: 1; }
.timeline-axis-label { font-size: 11px; fill: var(--color-slate); font-family: var(--font-family); }

.timeline-legend {
  display: flex;
  gap: var(--space-lg);
  margin-top: 14px;
  font-size: var(--font-size-micro);
  color: var(--color-slate);
}

.timeline-legend__item { display: flex; align-items: center; gap: 6px; }
.timeline-legend__swatch { width: 14px; height: 3px; border-radius: 2px; }
.timeline-legend__swatch--dose { background: var(--color-primary); }
.timeline-legend__swatch--symptom { background: var(--color-caution); }
.timeline-legend__swatch--se { background: var(--color-alert); width: 8px; height: 8px; border-radius: 50%; }
.timeline-legend__swatch--adherence-ok { background: var(--color-stable); }
.timeline-legend__swatch--adherence-late { background: var(--color-caution); }
.timeline-legend__swatch--adherence-missed { background: var(--color-alert); }

/* ── Tolerability Flags ───────────────────────────────────────────────────── */

.flags-panel { display: flex; flex-direction: column; gap: 8px; }

.flag-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-small);
  transition: transform var(--transition-fast);
}

.flag-item:hover { transform: translateX(2px); }

.flag-item--urgent { background: var(--color-alert-bg); border-left: 3px solid var(--color-alert); }
.flag-item--watch { background: var(--color-caution-bg); border-left: 3px solid var(--color-caution); }
.flag-item--info { background: var(--color-primary-light); border-left: 3px solid var(--color-primary); }

.flag-item__text { flex: 1; }
.flag-item__type { font-weight: var(--font-weight-semibold); margin-bottom: 2px; }
.flag-item__detail { color: var(--color-slate); font-size: var(--font-size-micro); }

/* ── PK Dosing Alert Card ─────────────────────────────────────────────────── */

.pk-card {
  background: var(--color-white);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm), 0 0 0 4px var(--color-primary-glow);
}

.pk-card__header { display: flex; align-items: flex-start; gap: var(--space-md); margin-bottom: var(--space-md); }

.pk-card__icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--color-white);
  font-size: 14px;
  font-weight: var(--font-weight-bold);
}

.pk-card__title { font-family: var(--font-display); font-size: var(--font-size-h2); font-weight: var(--font-weight-semibold); color: var(--color-primary-dark); }
.pk-card__pkrationale { font-size: var(--font-size-small); color: var(--color-slate); margin-top: var(--space-sm); }
.pk-card__source {
  font-size: var(--font-size-micro);
  color: var(--color-slate);
  margin-top: var(--space-sm);
  border-top: 1px solid var(--color-border-subtle);
  padding-top: var(--space-sm);
}
.pk-card__source-note { font-style: italic; }
.pk-card__rationale { font-size: var(--font-size-body); color: var(--color-ink); line-height: var(--line-height); margin-bottom: var(--space-md); }
.pk-card__cpic { font-size: var(--font-size-small); color: var(--color-slate); margin-bottom: var(--space-md); }
.pk-card__cpic a { color: var(--color-primary); font-weight: var(--font-weight-medium); }

.pk-card__boundary {
  background: var(--color-canvas);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px var(--space-md);
  font-size: var(--font-size-small);
  font-weight: var(--font-weight-semibold);
  color: var(--color-ink);
  text-align: center;
  margin-bottom: var(--space-md);
}

.pk-card__actions { display: flex; gap: var(--space-sm); justify-content: flex-end; }

/* ── Check-in Screen ──────────────────────────────────────────────────────── */

.checkin {
  max-width: 500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

.checkin__progress {
  display: flex;
  gap: 6px;
  margin-bottom: var(--space-sm);
}

.checkin__progress-dot {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: var(--color-border);
  transition: background var(--transition-normal);
}

.checkin__progress-dot--active {
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-secondary) 100%);
}

.checkin__progress-dot--done { background: var(--color-stable); }

.checkin__section { display: flex; flex-direction: column; gap: var(--space-md); }

.checkin__label {
  font-size: var(--font-size-h2);
  font-weight: var(--font-weight-semibold);
  color: var(--color-ink);
}

.face-buttons { display: flex; gap: 10px; justify-content: center; }

.face-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 76px;
  padding: var(--space-md) var(--space-sm);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-white);
  transition: all var(--transition-fast);
  min-height: 84px;
}

.face-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-lighter);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.face-btn--selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: 0 0 0 2px var(--color-primary), var(--shadow-md);
  transform: scale(1.04);
}

.face-btn__emoji { font-size: 28px; line-height: 1; }
.face-btn__label { font-size: var(--font-size-micro); color: var(--color-slate); text-align: center; }

.chip-select { display: flex; flex-wrap: wrap; gap: var(--space-sm); }

.chip-option {
  padding: 9px 18px;
  border: 1.5px solid var(--color-border);
  border-radius: 100px;
  font-size: var(--font-size-small);
  font-weight: var(--font-weight-medium);
  color: var(--color-slate);
  background: var(--color-white);
  transition: all var(--transition-fast);
  min-height: 44px;
  display: flex;
  align-items: center;
}

.chip-option:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xs);
}

.chip-option--selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: var(--font-weight-semibold);
  box-shadow: var(--shadow-xs);
}

.segmented-control {
  display: flex;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.segmented-btn {
  flex: 1;
  padding: 12px var(--space-md);
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-medium);
  color: var(--color-slate);
  background: var(--color-white);
  border-right: 1px solid var(--color-border);
  text-align: center;
  transition: all var(--transition-fast);
  min-height: 48px;
}

.segmented-btn:last-child { border-right: none; }
.segmented-btn:hover { background: var(--color-primary-lighter); color: var(--color-primary); }

.segmented-btn--selected {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary-contrast) 100%);
  color: var(--color-white);
}

.adherence-buttons { display: flex; gap: 10px; }

.adherence-btn {
  flex: 1;
  padding: var(--space-md);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-medium);
  color: var(--color-ink);
  background: var(--color-white);
  text-align: center;
  transition: all var(--transition-fast);
  min-height: 56px;
}

.adherence-btn:hover { border-color: var(--color-primary); transform: translateY(-1px); box-shadow: var(--shadow-xs); }
.adherence-btn--selected { border-color: var(--color-primary); background: var(--color-primary-light); color: var(--color-primary); }
.adherence-btn--taken.adherence-btn--selected { border-color: var(--color-stable); background: var(--color-stable-bg); color: var(--color-stable); }
.adherence-btn--late.adherence-btn--selected { border-color: var(--color-caution); background: var(--color-caution-bg); color: var(--color-caution); }
.adherence-btn--missed.adherence-btn--selected { border-color: var(--color-alert); background: var(--color-alert-bg); color: var(--color-alert); }

.checkin__submit { text-align: center; padding: var(--space-lg) 0; }

.checkin__confirm {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-xxl);
  animation: fadeIn 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

.checkin__confirm--visible { display: flex; }

.checkin__confirm-icon {
  width: 64px;
  height: 64px;
  background: var(--color-stable-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-stable);
  font-size: 32px;
  box-shadow: 0 0 0 8px rgba(16, 185, 129, 0.08);
}

.checkin__confirm-text { font-size: 15px; color: var(--color-slate); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Triage List ──────────────────────────────────────────────────────────── */

.triage-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--color-border-subtle);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.triage-row {
  display: grid;
  grid-template-columns: 1fr 120px 80px 1fr 100px;
  align-items: center;
  gap: var(--space-md);
  padding: 14px var(--space-lg);
  background: var(--color-white);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.triage-row:hover { background: var(--color-primary-lighter); }

.triage-row__header {
  font-size: var(--font-size-micro);
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: default;
  background: var(--color-canvas);
}

.triage-row__header:hover { background: var(--color-canvas); }
.triage-row__patient { font-weight: var(--font-weight-semibold); }

.triage-row__open {
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.triage-row__drug { font-size: var(--font-size-small); color: var(--color-slate); }
.triage-row__days { font-size: var(--font-size-small); color: var(--color-slate); text-align: center; }

.triage-row__alert {
  font-size: var(--font-size-small);
  color: var(--color-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Decision Log ─────────────────────────────────────────────────────────── */

.decision-log { display: flex; flex-direction: column; gap: 10px; }

.decision-log__entry {
  display: flex;
  gap: var(--space-md);
  padding: 12px;
  background: var(--color-canvas);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-small);
}

.decision-log__date { color: var(--color-slate); white-space: nowrap; font-size: var(--font-size-micro); }
.decision-log__text { flex: 1; color: var(--color-ink); font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: var(--font-size-small); }
.decision-log__form { display: flex; gap: var(--space-sm); }
.decision-log__input { flex: 1; }

/* ── Login Screen ─────────────────────────────────────────────────────────── */

.login {
  max-width: 420px;
  margin: 0 auto;
  padding-top: 12vh;
}

.login__header { text-align: center; margin-bottom: var(--space-xl); }

.login__logo { margin-bottom: var(--space-md); }

.login__title {
  font-size: 30px;
  font-weight: var(--font-weight-bold);
  color: var(--color-primary-dark);
  letter-spacing: -0.03em;
}

.login__subtitle {
  font-size: var(--font-size-small);
  color: var(--color-slate);
  margin-top: 6px;
}

.login .card {
  padding: var(--space-xl);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-xl);
}

.login__error {
  background: var(--color-alert-bg);
  color: var(--color-alert);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  font-size: var(--font-size-small);
  font-weight: var(--font-weight-medium);
  margin-bottom: var(--space-md);
  display: none;
}

.login__error--visible { display: block; animation: fadeIn 200ms ease; }

/* ── Settings ─────────────────────────────────────────────────────────────── */

.settings { max-width: 600px; margin: 0 auto; }
.settings__section { margin-bottom: var(--space-xl); }

.settings__label {
  font-size: var(--font-size-micro);
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-sm);
}

/* ── Cockpit Detail Grid ──────────────────────────────────────────────────── */

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: var(--space-lg);
}

.detail-grid__main { display: flex; flex-direction: column; gap: var(--space-lg); }
.detail-grid__rail { display: flex; flex-direction: column; gap: var(--space-lg); }

/* ── Empty State ──────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xxl);
  color: var(--color-slate);
  text-align: center;
}

.empty-state__icon { font-size: 48px; margin-bottom: var(--space-md); opacity: 0.25; }
.empty-state__title { font-size: var(--font-size-h2); font-weight: var(--font-weight-medium); margin-bottom: var(--space-xs); }
.empty-state__text { font-size: var(--font-size-small); }

/* ── Loading ──────────────────────────────────────────────────────────────── */

.loading { display: flex; align-items: center; justify-content: center; padding: var(--space-xxl); }

.loading__spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ────────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  padding: 14px var(--space-lg);
  background: var(--color-ink);
  color: var(--color-white);
  border-radius: var(--radius-lg);
  font-size: var(--font-size-small);
  font-weight: var(--font-weight-medium);
  box-shadow: var(--shadow-xl);
  z-index: 1000;
  animation: slideUp 350ms cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
  max-width: 400px;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Sidebar Admin Section ────────────────────────────────────────────────── */

.sidebar__divider {
  height: 1px;
  background: var(--color-border-subtle);
  margin: var(--space-sm) 0;
}

.sidebar__admin-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── Admin Layout ────────────────────────────────────────────────────────── */

.admin-page { max-width: 1100px; }

.admin-page > h1 {
  position: relative;
  padding-bottom: var(--space-sm);
}

/* ── Admin Stats Grid ────────────────────────────────────────────────────── */

.admin-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-lg);
}

.admin-stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-xl) var(--space-lg);
  min-height: 120px;
  position: relative;
  overflow: hidden;
}

.admin-stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
}

.admin-stat-card:nth-child(1)::before { background: var(--color-primary); }
.admin-stat-card:nth-child(2)::before { background: var(--color-stable); }
.admin-stat-card:nth-child(3)::before { background: var(--color-primary); }
.admin-stat-card:nth-child(4)::before { background: var(--color-caution); }
.admin-stat-card:nth-child(5)::before { background: var(--color-alert); }
.admin-stat-card:nth-child(6)::before { background: var(--color-stable); }

.admin-stat-card__value {
  font-size: 40px;
  font-weight: var(--font-weight-bold);
  line-height: 1.1;
  margin-bottom: var(--space-sm);
  letter-spacing: -0.03em;
}

.admin-stat-card__value--primary { color: var(--color-primary); }
.admin-stat-card__value--stable { color: var(--color-stable); }
.admin-stat-card__value--caution { color: var(--color-caution); }
.admin-stat-card__value--alert { color: var(--color-alert); }

.admin-stat-card__label {
  font-size: var(--font-size-small);
  font-weight: var(--font-weight-medium);
  color: var(--color-slate);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Admin Data Table ────────────────────────────────────────────────────── */

.admin-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--color-white);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  font-size: var(--font-size-small);
}

.data-table thead { background: var(--color-canvas); }

.data-table th {
  padding: 12px var(--space-md);
  font-size: var(--font-size-micro);
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  border-bottom: 2px solid var(--color-border-subtle);
  white-space: nowrap;
}

.data-table td {
  padding: 12px var(--space-md);
  border-bottom: 1px solid var(--color-border-subtle);
  color: var(--color-ink);
  vertical-align: middle;
}

.data-table tbody tr { transition: background var(--transition-fast); }
.data-table tbody tr:hover { background: var(--color-primary-lighter); }
.data-table tbody tr:last-child td { border-bottom: none; }

.data-table--striped tbody tr:nth-child(even) { background: var(--color-canvas); }
.data-table--striped tbody tr:nth-child(even):hover { background: var(--color-primary-lighter); }

.td-bold { font-weight: var(--font-weight-semibold); }
.td-nowrap { white-space: nowrap; }
.td-truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-changes { max-width: 320px; line-height: 1.4; }

/* ── Badges ──────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: var(--font-size-micro);
  font-weight: var(--font-weight-semibold);
  line-height: 1.8;
  white-space: nowrap;
}

.badge--active { background: var(--color-stable-bg); color: var(--color-stable); }
.badge--inactive { background: var(--color-border-subtle); color: var(--color-slate); }

.badge--role-admin { background: var(--color-accent-bg); color: var(--color-accent-ink); }
.badge--role-prescriber { background: var(--color-primary-lighter); color: var(--color-primary-dark); }
.badge--role-nurse { background: var(--color-stable-bg); color: var(--color-stable); }
.badge--role-pharmacist { background: var(--color-caution-bg); color: var(--color-caution); }
.badge--role-export { background: var(--color-border-subtle); color: var(--color-slate); }

.badge--table { background: var(--color-primary-light); color: var(--color-primary); }

.badge--action-insert { background: var(--color-stable-bg); color: var(--color-stable); }
.badge--action-update { background: var(--color-primary-lighter); color: var(--color-primary-dark); }
.badge--action-delete { background: var(--color-alert-bg); color: var(--color-alert); }
.badge--action-unknown { background: var(--color-border-subtle); color: var(--color-slate); }

/* ── Admin Toolbar ───────────────────────────────────────────────────────── */

.admin-toolbar {
  display: flex;
  align-items: flex-end;
  gap: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background: var(--color-white);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  box-shadow: var(--shadow-xs);
}

/* ── Admin Inline Form ───────────────────────────────────────────────────── */

.admin-form { margin-bottom: var(--space-lg); }

.admin-form__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 var(--space-lg);
}

.admin-form__actions {
  display: flex;
  justify-content: flex-end;
  padding-top: var(--space-sm);
}

/* ── Admin Action Buttons ────────────────────────────────────────────────── */

.admin-actions {
  display: flex;
  gap: var(--space-xs);
  white-space: nowrap;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 960px) {
  .cockpit { grid-template-columns: 1fr; }
  .cockpit__sidebar {
    max-height: none;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: visible;
    padding-bottom: var(--space-sm);
  }
  .patient-item { min-width: 200px; flex-shrink: 0; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid__rail { order: -1; }
  .triage-row { grid-template-columns: 1fr 1fr; gap: var(--space-sm); }
  .triage-row__header { display: none; }
  .admin-stats { grid-template-columns: repeat(2, 1fr); }
  .admin-form__grid { grid-template-columns: 1fr; }
  .admin-toolbar { flex-direction: column; align-items: stretch; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar--open { transform: translateX(0); box-shadow: var(--shadow-xl); }
  .mobile-header { display: flex; }
  .app-body {
    margin-left: 0;
    padding: 72px var(--space-md) var(--space-md);
  }
  .face-btn { width: 64px; min-height: 72px; }
  .face-btn__emoji { font-size: 24px; }
  .adherence-buttons { flex-direction: column; }
  .login { padding-top: 8vh; }
}

@media (max-width: 480px) {
  .face-buttons { gap: 6px; }
  .face-btn { width: 56px; padding: var(--space-sm) var(--space-xs); }
  .admin-stats { grid-template-columns: 1fr; }
}

/* ── Utility Classes ──────────────────────────────────────────────────────── */

.text-muted { color: var(--color-slate); }
.text-small { font-size: var(--font-size-small); }
.text-micro { font-size: var(--font-size-micro); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.hidden { display: none !important; }


/* ============================================================================
   Additions — accessibility affordances, dialog, responsive repairs
   ============================================================================ */

/* There was no visually-hidden utility at all, so there was no mechanism for
   adding accessible text anywhere in the app. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-md);
  top: -60px;
  z-index: 10000;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-primary);
  color: var(--color-white);
  border-radius: var(--radius-sm);
  font-weight: var(--font-weight-semibold);
  transition: top var(--transition-fast);
}
.skip-link:focus {
  top: var(--space-md);
  color: var(--color-white);
  text-decoration: none;
}

.noscript-notice {
  margin: var(--space-xl);
  padding: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-white);
  color: var(--color-ink);
}

/* ── Toasts ───────────────────────────────────────────────────────────────── */

.toast-region {
  position: fixed;
  bottom: var(--space-lg);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9500;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  align-items: center;
  pointer-events: none;
  max-width: min(520px, calc(100vw - 2 * var(--space-md)));
}
.toast-region .toast { position: static; transform: none; pointer-events: auto; }
.toast--error {
  background: var(--color-alert);
  color: var(--color-white);
}

/* ── Dialog / drawer ──────────────────────────────────────────────────────── */

.drawer-scrim,
.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: rgba(27, 35, 33, 0.42);
  z-index: 9000;
}
.sidebar-scrim { display: none; }

.drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100%;
  width: min(420px, 92vw);
  background: var(--color-white);
  box-shadow: var(--shadow-xl);
  z-index: 9999;
  padding: var(--space-lg);
  overflow: auto;
}
.drawer__close {
  position: absolute;
  top: var(--space-sm); right: var(--space-sm);
  width: 44px; height: 44px;
  font-size: 22px;
  line-height: 1;
  color: var(--color-slate);
  border-radius: var(--radius-sm);
}
.drawer__close:hover { background: var(--color-border-subtle); }
.drawer__title {
  font-family: var(--font-display);
  font-size: var(--font-size-h2);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-sm);
  padding-right: var(--space-xl);
}
.drawer__body { font-size: var(--font-size-body); color: var(--color-ink); margin-bottom: var(--space-md); }
.drawer__meta { font-size: var(--font-size-small); color: var(--color-slate); margin-bottom: var(--space-md); }
.drawer__boundary { font-size: var(--font-size-micro); color: var(--color-slate); font-style: italic; }

/* ── Forms ────────────────────────────────────────────────────────────────── */

.form-label--sm { font-size: var(--font-size-micro); }
.form-hint { font-size: var(--font-size-micro); color: var(--color-slate); margin-top: var(--space-xs); }
/* Brandbook: Signal Red is reserved for clinical urgency and is explicitly
   NOT to be used for validation errors — Slate is. */
.form-hint--error { color: var(--color-slate); font-weight: var(--font-weight-semibold); }
.form-input[aria-invalid="true"] { border-color: var(--color-slate); box-shadow: 0 0 0 3px rgba(90, 98, 96, 0.14); }
button[aria-busy="true"] { opacity: 0.75; cursor: progress; }

/* ── Login ────────────────────────────────────────────────────────────────── */

.login__boundary {
  margin-top: var(--space-lg);
  font-size: var(--font-size-micro);
  color: var(--color-slate);
  text-align: center;
  line-height: 1.5;
}

/* ── Patient list (now a real button) ─────────────────────────────────────── */

.patient-item {
  width: 100%;
  text-align: left;
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  color: inherit;
}
.patient-item__info { display: block; }
.patient-item__ref, .patient-item__meta { display: block; }
.patient-item[aria-current="true"] { box-shadow: inset 3px 0 0 var(--color-primary); }

/* ── Triage table ─────────────────────────────────────────────────────────── */

.triage-table-wrap { overflow-x: auto; }
.triage-list { width: 100%; border-collapse: collapse; }
.triage-list th { text-align: left; }
.triage-row__alert { display: flex; align-items: center; gap: var(--space-sm); }
/* The alert cell used to be nowrap+ellipsis and contained the "Why?" button,
   so the citation affordance was clipped out of existence on narrow screens. */
.triage-row__alert-text { min-width: 0; overflow-wrap: anywhere; }
.triage-row__why { flex: 0 0 auto; }

/* ── Portfolio badge ──────────────────────────────────────────────────────── */

.sidebar__portfolio {
  margin-top: var(--space-md);
  font-size: var(--font-size-micro);
  line-height: 1.45;
  color: var(--color-slate);
}
.sidebar__portfolio em { font-style: italic; }

/* ── Decision log ─────────────────────────────────────────────────────────── */

.decision-log__form { display: flex; flex-wrap: wrap; gap: var(--space-sm); align-items: flex-end; }
.decision-log__field { display: flex; flex-direction: column; gap: 2px; min-width: 120px; }
.decision-log__field--grow { flex: 1 1 220px; }
.decision-log__dose { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.decision-log__hint { margin-top: var(--space-sm); }

/* ── Check-in ─────────────────────────────────────────────────────────────── */

.checkin__heading { margin-bottom: var(--space-sm); }
.checkin__subject { color: var(--color-slate); margin-bottom: var(--space-lg); }
.checkin__section { border: 0; }
.checkin__remaining { margin-top: var(--space-sm); font-size: var(--font-size-micro); color: var(--color-slate); text-align: center; }
.checkin__confirm:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 4px; }

/* ── Admin ────────────────────────────────────────────────────────────────── */

.admin-toolbar__field { margin-bottom: 0; }
.admin-toolbar__select { max-width: 280px; }
.admin-toolbar__select--narrow { max-width: 110px; }
.badge--platform { background: var(--color-accent-bg); color: var(--color-accent-ink); }

/* ── Timeline legend ──────────────────────────────────────────────────────── */

.timeline-legend { flex-wrap: wrap; row-gap: var(--space-sm); }

/* ── Responsive repairs ───────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar-scrim { display: block; }
  body:not(:has(.sidebar--open)) .sidebar-scrim { display: none; }

  /* The banner that used to sit above the fixed chrome is gone, so these no
     longer have to subtract a phantom offset. */
  .cockpit, .cockpit__sidebar { max-height: none; min-height: 0; }

  /* Stacked cards with their column name restored — the header row is hidden
     at this width, which previously left five unlabelled values in a grid. */
  .triage-list, .triage-list tbody, .triage-list tr, .triage-list td { display: block; width: 100%; }
  .triage-list thead { display: none; }
  .triage-list tr.triage-row {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    padding: var(--space-sm);
    background: var(--color-white);
  }
  .triage-list td { display: flex; justify-content: space-between; gap: var(--space-md); padding: 4px 0; }
  .triage-list td::before {
    content: attr(data-label);
    font-weight: var(--font-weight-semibold);
    color: var(--color-slate);
    flex: 0 0 auto;
  }

  .detail-header, .pk-card__actions { flex-wrap: wrap; gap: var(--space-sm); }
}

@media (max-width: 480px) {
  .decision-log__form { flex-direction: column; align-items: stretch; }
  .decision-log__form .btn { width: 100%; }
}

/* ── Print ────────────────────────────────────────────────────────────────── */

/* ============================================================================
   PATIENT VIEW (js/patient.js)
   ----------------------------------------------------------------------------
   Added 2026-09-04. This view shipped using a class vocabulary that was never
   in this stylesheet -- .patient-card, .chip-grid, .status/.status--ok/
   .status--error, .checkin__subtitle, .timeline-list, .muted and .mono all
   had ZERO rules -- so the whole patient page rendered as unstyled default
   HTML inside a styled container. The clinician check-in looked right only
   because it uses .checkin__* and .face-btn, which do exist.
   The markup now reuses this file's own .card and .form-* systems; what
   remains below is only what is genuinely patient-specific, prefixed pc- so
   it cannot collide with the clinician vocabulary again.
   ========================================================================= */

.checkin__sub {
  color: var(--color-slate);
  font-size: var(--font-size-body);
  margin: calc(var(--space-sm) * -1) 0 var(--space-lg);
}

.patient-card { margin-bottom: var(--space-lg); }
.patient-card:last-child { margin-bottom: 0; }

/* Side-effect chips: a tap target, not a status pill, so it does not reuse
   .chip (which is a non-interactive label elsewhere in the app). */
.pc-fieldset { border: 0; padding: 0; margin-bottom: var(--space-lg); }

.pc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.pc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--color-border);
  border-radius: 100px;
  background: var(--color-white);
  color: var(--color-ink);
  font-size: var(--font-size-small);
  cursor: pointer;
  /* 44px min target: this is filled in one-handed on a phone. */
  min-height: 44px;
}

.pc-chip:hover { border-color: var(--color-muted); }

/* :has() gives the selected state without JS. Browsers without it simply
   show the checkbox, which is still perfectly usable -- the checkbox is
   never hidden, so this degrades rather than breaking. */
.pc-chip:has(input:checked) {
  background: var(--color-primary-lighter);
  border-color: var(--color-primary);
  color: var(--color-primary-dark);
  font-weight: var(--font-weight-semibold);
}

.pc-chip:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Status line under the form. Never colour alone -- the text says what
   happened; the colour only reinforces it. */
.pc-status {
  margin-top: var(--space-md);
  font-size: var(--font-size-small);
  line-height: 1.5;
}
.pc-status:empty { margin-top: 0; }
.pc-status--ok { color: var(--color-stable); font-weight: var(--font-weight-semibold); }
.pc-status--error { color: var(--color-alert); font-weight: var(--font-weight-semibold); }

.pc-timeline-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.pc-timeline-list li {
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border-subtle);
  font-size: var(--font-size-small);
  color: var(--color-slate);
}
.pc-timeline-list li:last-child { border-bottom: none; }

.pc-muted { color: var(--color-muted); font-size: var(--font-size-small); }

.pc-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: var(--font-weight-semibold);
  color: var(--color-ink);
}

/* Patient settings definition list (js/patient.js renderPatientSettings). */
.ps-dl {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr;
  gap: var(--space-sm) var(--space-md);
  margin: 0;
  font-size: var(--font-size-small);
}
.ps-dl dt { color: var(--color-muted); }
.ps-dl dd { margin: 0; color: var(--color-ink); font-weight: var(--font-weight-semibold); }

.ps-quiet-fields { display: flex; flex-wrap: wrap; gap: var(--space-sm); align-items: center; }
.ps-quiet-fields .form-input { width: auto; }

@media print {
  .sidebar, .mobile-header, .sidebar-scrim, .toast-region,
  .skip-link, .drawer, .drawer-scrim, .btn { display: none !important; }
  .app-body { margin-left: 0 !important; max-width: none !important; padding: 0 !important; }
  .card, .panel, .pk-card { break-inside: avoid; box-shadow: none; border: 1px solid var(--color-border); }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 10px; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   My care team — claim-and-consent, patient side (2026-09-05).
   Built on the existing .card / .patient-card shell; only the row layout and
   the one-time code display are new.
   ───────────────────────────────────────────────────────────────────────── */

.ct-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--color-border-subtle);
}
.ct-row:last-child { border-bottom: 0; }

.ct-name {
  font-weight: var(--font-weight-semibold);
  color: var(--color-ink);
}

.ct-meta {
  font-size: var(--font-size-small);
  color: var(--color-muted);
}

/* Keeps the two buttons together when the row wraps on a narrow screen, so
   "No" never ends up under the next clinician's name. */
.ct-actions { display: flex; gap: var(--space-sm); flex-shrink: 0; }

/* A pending request is the only thing on this page that needs an answer. */
.ct-pending { border-left: 3px solid var(--color-caution); }

/* Said BEFORE the patient answers: in exclusive mode, confirming replaces the
   clinician they already have. */
.ct-warn {
  margin: var(--space-md) 0 0;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-caution-bg);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-small);
  color: var(--color-ink);
}

/* The claim code. Shown once — only its hash is stored — so it has to be
   unmissable, readable aloud, and selectable in full. */
.ct-code {
  display: block;
  margin: var(--space-md) 0;
  padding: var(--space-md);
  background: var(--color-accent-bg);
  border: 1px dashed var(--color-accent);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: var(--font-weight-bold);
  /* Wide tracking because these characters get read out over a phone, and a
     tight monospace run of 8 is where a B becomes an 8. */
  letter-spacing: 0.22em;
  text-align: center;
  color: var(--color-ink);
  user-select: all;
}

/* A pending clinician request, shown on the patient's landing view. Uses the
   caution token rather than alert: someone asking to join a care team is not
   an error, but it is the one thing on the page that needs an answer. */
.pc-claim-alert {
  margin: 0 0 var(--space-lg);
  padding: var(--space-md);
  background: var(--color-caution-bg);
  border-left: 3px solid var(--color-caution);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-small);
  color: var(--color-ink);
}
.pc-claim-alert a { margin-left: var(--space-xs); font-weight: var(--font-weight-semibold); }

/* ─── Patient roster (admin, step 4) ──────────────────────────────────────── */

.roster-tabs {
  display: flex;
  gap: var(--space-xs);
  flex-wrap: wrap;
  margin-bottom: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

/* A count on the tab itself, so a backlog is visible without clicking in. */
.roster-count {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 0.35em;
  margin-left: var(--space-xs);
  border-radius: var(--radius-sm);
  background: var(--color-caution-bg);
  color: var(--color-ink);
  font-size: var(--font-size-micro);
  font-weight: var(--font-weight-semibold);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.admin-hint {
  margin: 0 0 var(--space-md);
  font-size: var(--font-size-small);
  color: var(--color-muted);
  max-width: 70ch;
}

/* The destination picker sits inline in a table cell, so it must not stretch
   the column to the width of the longest clinician name. */
.roster-dest {
  display: inline-block;
  width: auto;
  min-width: 14ch;
  max-width: 28ch;
  margin-right: var(--space-xs);
}
