/* ============================================================
   Civil Surgeon Intake — Design System (polish pass)
   Light-first clinical. OKLCH tokens, indigo→magenta accent pair.
   Sections:
     1. Tokens (light + dark)
     2. Base / reset
     3. Atmosphere (ambient bg)
     4. Typography
     5. Layout (topbar, nav, main)
     6. Components
        6a. Panels / cards
        6b. Buttons
        6c. Tables
        6d. Chips / badges
        6e. Findings
        6f. Forms + dropzone
        6g. Stepper
        6h. Stat cards
        6i. Case cards
        6j. Empty states
        6k. Progress + spinner
        6l. Callouts
        6m. Dropdown
        6n. Toast
     7. Utilities
     8. Animations + reduced motion
   ============================================================ */

/* ============================================================
   1. Tokens
   ============================================================ */

:root {
    /* Surfaces — light */
    --color-background:    oklch(98.5% 0.006 230);
    --color-surface:       oklch(100% 0 0);
    --color-surface-2:     oklch(97.5% 0.008 235);
    --color-surface-hover: oklch(95.5% 0.012 235);

    /* Text */
    --color-text:          oklch(20% 0.02 260);
    --color-text-muted:    oklch(42% 0.018 260);
    --color-text-subtle:   oklch(58% 0.015 260);
    --color-text-faint:    oklch(72% 0.012 260);

    /* Brand — indigo primary + magenta accent */
    --color-primary:       oklch(54% 0.18 275);
    --color-primary-hover: oklch(48% 0.19 275);
    --color-primary-soft:  oklch(96% 0.03 275);
    --color-primary-glow:  oklch(54% 0.18 275 / 0.28);
    --color-accent:        oklch(62% 0.22 335);
    --color-accent-soft:   oklch(96% 0.035 335);
    --color-accent-glow:   oklch(62% 0.22 335 / 0.24);

    /* Semantic */
    --color-ok:   oklch(55% 0.15 155);
    --color-ok-soft:   oklch(96% 0.04 155);
    --color-warn: oklch(66% 0.15  75);
    --color-warn-soft: oklch(96% 0.06  80);
    --color-bad:  oklch(55% 0.20  25);
    --color-bad-soft:  oklch(96% 0.04  25);
    --color-info: oklch(58% 0.14 250);
    --color-info-soft: oklch(96% 0.04 250);

    /* Borders */
    --color-border:        oklch(92% 0.008 240);
    --color-border-strong: oklch(86% 0.01  240);
    --color-border-subtle: oklch(95% 0.006 240);

    /* Radii */
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-2xl: 28px;
    --radius-full: 999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px 0 oklch(20% 0.02 260 / 0.04);
    --shadow-sm: 0 1px 3px 0 oklch(20% 0.02 260 / 0.07), 0 1px 2px -1px oklch(20% 0.02 260 / 0.05);
    --shadow-md: 0 6px 18px -4px oklch(20% 0.02 260 / 0.10), 0 2px 6px -2px oklch(20% 0.02 260 / 0.06);
    --shadow-lg: 0 24px 48px -16px oklch(20% 0.02 260 / 0.18);
    --shadow-glow-primary: 0 0 0 1px var(--color-primary-glow), 0 12px 32px -8px var(--color-primary-glow);
    --shadow-glow-accent:  0 0 0 1px var(--color-accent-glow),  0 12px 32px -8px var(--color-accent-glow);
    --ring: 0 0 0 3px oklch(54% 0.18 275 / 0.22);

    /* Motion */
    --ease-out-soft:    cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out-soft: cubic-bezier(0.65, 0, 0.35, 1);
    --dur-fast: 120ms;
    --dur: 200ms;
    --dur-slow: 320ms;

    /* Type */
    --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
    --font-feature: "rlig" 1, "calt" 1, "ss01" 1, "cv11" 1, "cv09" 1;

    /* Ambient glow intensities (consumed by .bg-ambient layers) */
    --ambient-glow-a: 0.14;
    --ambient-glow-b: 0.10;
    --ambient-grid:   0.06;

    /* ----- Legacy aliases (old names → new tokens) ----- */
    --bg:              var(--color-background);
    --bg-subtle:       var(--color-surface-hover);
    --surface:         var(--color-surface);
    --surface-2:       var(--color-surface-2);
    --surface-hover:   var(--color-surface-hover);
    --border:          var(--color-border);
    --border-strong:   var(--color-border-strong);
    --border-subtle:   var(--color-border-subtle);
    --text:            var(--color-text);
    --text-muted:      var(--color-text-muted);
    --text-subtle:     var(--color-text-subtle);
    --text-faint:      var(--color-text-faint);
    --primary:         var(--color-primary);
    --primary-hover:   var(--color-primary-hover);
    --primary-soft:    var(--color-primary-soft);
    --primary-foreground: oklch(100% 0 0);
    --accent:          var(--color-accent);
    --accent-soft:     var(--color-accent-soft);
    --ok:              var(--color-ok);
    --ok-soft:         var(--color-ok-soft);
    --warn:            var(--color-warn);
    --warn-soft:       var(--color-warn-soft);
    --bad:             var(--color-bad);
    --bad-soft:        var(--color-bad-soft);
    --info:            var(--color-info);
    --info-soft:       var(--color-info-soft);
    --ease:            var(--ease-out-soft);
}

[data-theme="dark"] {
    --color-background:    oklch(16% 0.018 265);
    --color-surface:       oklch(20% 0.02  265);
    --color-surface-2:     oklch(23% 0.022 265);
    --color-surface-hover: oklch(27% 0.024 265);
    --color-text:          oklch(96% 0.01  250);
    --color-text-muted:    oklch(78% 0.015 250);
    --color-text-subtle:   oklch(64% 0.015 250);
    --color-text-faint:    oklch(50% 0.015 250);
    --color-primary:       oklch(68% 0.17 275);
    --color-primary-hover: oklch(74% 0.17 275);
    --color-primary-soft:  oklch(30% 0.08 275);
    --color-primary-glow:  oklch(68% 0.17 275 / 0.32);
    --color-accent:        oklch(72% 0.20 335);
    --color-accent-soft:   oklch(30% 0.09 335);
    --color-accent-glow:   oklch(72% 0.20 335 / 0.28);
    --color-ok-soft:       oklch(28% 0.06 155);
    --color-warn-soft:     oklch(30% 0.08 80);
    --color-bad-soft:      oklch(28% 0.09 25);
    --color-info-soft:     oklch(28% 0.06 250);
    --color-border:        oklch(30% 0.02  265);
    --color-border-strong: oklch(38% 0.022 265);
    --color-border-subtle: oklch(25% 0.02  265);

    --shadow-xs: 0 1px 2px 0 oklch(0% 0 0 / 0.30);
    --shadow-sm: 0 1px 3px 0 oklch(0% 0 0 / 0.40), 0 1px 2px -1px oklch(0% 0 0 / 0.30);
    --shadow-md: 0 6px 18px -4px oklch(0% 0 0 / 0.45), 0 2px 6px -2px oklch(0% 0 0 / 0.35);
    --shadow-lg: 0 24px 48px -16px oklch(0% 0 0 / 0.55);

    --ambient-glow-a: 0.22;
    --ambient-glow-b: 0.18;
    --ambient-grid:   0.07;

    --primary-foreground: oklch(100% 0 0);
}

/* Dark mode is explicit-opt-in via [data-theme="dark"] only.
   We intentionally do NOT auto-flip based on prefers-color-scheme —
   this is a clinical tool; light is the hard default. */

/* ============================================================
   2. Base / reset
   ============================================================ */

* { box-sizing: border-box; }

html {
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    color-scheme: light dark;
}

body {
    background: var(--color-background);
    color: var(--color-text);
    margin: 0;
    line-height: 1.55;
    font-size: 15px;
    font-feature-settings: var(--font-feature);
    transition: background var(--dur) var(--ease-out-soft), color var(--dur) var(--ease-out-soft);
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-xs); }

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

/* ============================================================
   3. Atmosphere — ambient background (opt-in)
   ============================================================ */

.bg-ambient {
    position: relative;
    isolation: isolate;
}
.bg-ambient::before,
.bg-ambient::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
}
.bg-ambient::before {
    background:
        radial-gradient(ellipse 70% 55% at 22% 18%, oklch(54% 0.18 275 / var(--ambient-glow-a)), transparent 60%),
        radial-gradient(ellipse 60% 45% at 82% 10%, oklch(62% 0.22 335 / var(--ambient-glow-b)), transparent 65%);
}
.bg-ambient::after {
    background-image:
        linear-gradient(to right, oklch(54% 0.18 275 / var(--ambient-grid)) 1px, transparent 1px),
        linear-gradient(to bottom, oklch(54% 0.18 275 / var(--ambient-grid)) 1px, transparent 1px);
    background-size: 48px 48px;
    -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 0%, black 30%, transparent 75%);
            mask-image: radial-gradient(ellipse 70% 60% at 50% 0%, black 30%, transparent 75%);
}
[data-theme="dark"] .bg-ambient::after {
    background-image:
        linear-gradient(to right, oklch(72% 0.08 275 / var(--ambient-grid)) 1px, transparent 1px),
        linear-gradient(to bottom, oklch(72% 0.08 275 / var(--ambient-grid)) 1px, transparent 1px);
}

/* ============================================================
   4. Typography
   ============================================================ */

h1, h2, h3, h4, h5 {
    letter-spacing: -0.015em;
    color: var(--color-text);
    margin: 0 0 0.4em;
    font-weight: 600;
    line-height: 1.25;
}
h1 {
    font-size: clamp(24px, 2.8vw, 32px);
    letter-spacing: -0.02em;
    margin-bottom: 0.3em;
}
h2 { font-size: 22px; letter-spacing: -0.02em; }
h3 { font-size: 16px; line-height: 1.3; }
h4 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-subtle);
    margin: 1.5em 0 0.6em;
}

.display {
    font-size: clamp(28px, 4vw, 44px);
    line-height: 1.05;
    font-weight: 600;
    letter-spacing: -0.03em;
}

.text-gradient {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
            background-clip: text;
    color: transparent;
}

.muted, .text-muted   { color: var(--color-text-muted); }
.subtle, .text-subtle { color: var(--color-text-subtle); }
.faint                { color: var(--color-text-faint); }
.small                { font-size: 13px; }
.tiny                 { font-size: 11.5px; letter-spacing: 0.04em; }
.mono {
    font-family: var(--font-mono);
    font-size: 0.88em;
    font-feature-settings: "zero" 1, "ss01" 1;
}

/* ============================================================
   5. Layout
   ============================================================ */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: color-mix(in oklab, var(--color-surface) 78%, transparent);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
            backdrop-filter: blur(14px) saturate(160%);
    border-bottom: 1px solid var(--color-border-subtle);
}
.topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    gap: 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--color-text);
    font-weight: 600;
    letter-spacing: -0.01em;
    font-size: 15px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    position: relative;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: oklch(100% 0 0);
    box-shadow:
        inset 0 1px 0 oklch(100% 0 0 / 0.2),
        0 2px 8px -2px var(--color-primary-glow);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text-main {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
            background-clip: text;
    color: transparent;
    font-weight: 600;
}
.brand small {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-subtle);
    letter-spacing: 0;
    margin-top: 1px;
}

.nav {
    display: flex;
    gap: 2px;
    margin-left: auto;
    align-items: center;
    position: relative;
}
.nav a {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-full);
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: 14px;
    font-weight: 500;
    transition:
        color var(--dur-fast) var(--ease-out-soft),
        background var(--dur-fast) var(--ease-out-soft);
    isolation: isolate;
}
.nav a:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
    text-decoration: none;
}
.nav a.active {
    color: var(--color-primary);
    view-transition-name: nav-pill;
}
.nav a.active::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    background: var(--color-primary-soft);
    box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--color-primary) 20%, transparent);
    view-transition-name: nav-pill;
}
.nav a svg { width: 15px; height: 15px; }

.topbar-tools {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: 4px;
    padding-left: 10px;
    border-left: 1px solid var(--color-border-subtle);
}

/* Theme toggle button */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition:
        background var(--dur-fast) var(--ease-out-soft),
        color var(--dur-fast) var(--ease-out-soft),
        transform var(--dur) var(--ease-out-soft);
}
.theme-toggle:hover { background: var(--color-surface-hover); color: var(--color-text); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun  { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }
.theme-toggle:active { transform: rotate(-15deg); }

main {
    max-width: 1180px;
    margin: 0 auto;
    padding: 32px 24px 80px;
}

/* ============================================================
   6a. Panels / cards
   ============================================================ */

.card, .panel {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 22px 26px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-xs);
    transition:
        box-shadow var(--dur) var(--ease-out-soft),
        border-color var(--dur) var(--ease-out-soft),
        transform var(--dur) var(--ease-out-soft);
}
.card-hover:hover,
.panel:hover {
    box-shadow: var(--shadow-sm);
}
.card-hover:hover {
    border-color: var(--color-border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.card-flush, .panel-flush { padding: 0; overflow: hidden; }
.card h2:first-child, .panel h2:first-child,
.card h3:first-child, .panel h3:first-child { margin-top: 0; }

.card-header, .panel-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border-subtle);
}
.card-body, .panel-body { padding: 20px; }

/* Accent variants — left bar */
.panel-accent-primary { border-left: 3px solid var(--color-primary); }
.panel-accent-warn    { border-left: 3px solid var(--color-warn); }
.panel-accent-bad     { border-left: 3px solid var(--color-bad); }

/* Gradient top stripe variants (settings cards) */
.stripe-primary,
.stripe-accent,
.stripe-info,
.stripe-warn {
    position: relative;
}
.stripe-primary::before,
.stripe-accent::before,
.stripe-info::before,
.stripe-warn::before {
    content: "";
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 2px;
    border-top-left-radius: inherit;
    border-top-right-radius: inherit;
}
.stripe-primary::before { background: linear-gradient(90deg, var(--color-primary), var(--color-accent)); }
.stripe-accent::before  { background: linear-gradient(90deg, var(--color-accent), var(--color-primary)); }
.stripe-info::before    { background: linear-gradient(90deg, var(--color-info), var(--color-primary)); }
.stripe-warn::before    { background: linear-gradient(90deg, var(--color-warn), var(--color-accent)); }

/* Highlight panel (legacy) */
.panel-highlight {
    border: 1px solid var(--color-primary);
    background:
        linear-gradient(180deg,
            var(--color-surface) 0%,
            color-mix(in oklab, var(--color-primary-soft) 80%, var(--color-surface)) 120%);
}

/* Glow card (signable state) */
.card-glow {
    border-color: color-mix(in oklab, var(--color-primary) 35%, var(--color-border));
    box-shadow: var(--shadow-glow-primary);
}

/* ============================================================
   6b. Buttons
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    position: relative;
    isolation: isolate;
    transition:
        background var(--dur-fast) var(--ease-out-soft),
        border-color var(--dur-fast) var(--ease-out-soft),
        color var(--dur-fast) var(--ease-out-soft),
        box-shadow var(--dur-fast) var(--ease-out-soft),
        transform var(--dur-fast) var(--ease-out-soft);

    /* Primary (default) — indigo→magenta gradient */
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
    color: oklch(100% 0 0);
    box-shadow:
        inset 0 1px 0 oklch(100% 0 0 / 0.16),
        var(--shadow-sm);
}
.btn:hover {
    filter: brightness(1.05);
    box-shadow:
        inset 0 1px 0 oklch(100% 0 0 / 0.2),
        var(--shadow-md);
    color: oklch(100% 0 0);
    text-decoration: none;
}
.btn:active { transform: translateY(1px); filter: brightness(0.97); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

/* Secondary — bordered surface */
.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border-strong);
    box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
    background: var(--color-surface-hover);
    border-color: color-mix(in oklab, var(--color-primary) 40%, var(--color-border-strong));
    color: var(--color-primary);
    filter: none;
}

/* Ghost — transparent, subtle hover */
.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
    border-color: transparent;
    box-shadow: none;
}
.btn-ghost:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
    filter: none;
    box-shadow: none;
}

/* Danger */
.btn-danger {
    background: var(--color-surface);
    border-color: color-mix(in oklab, var(--color-bad) 35%, var(--color-border-strong));
    color: var(--color-bad);
    box-shadow: var(--shadow-xs);
}
.btn-danger:hover {
    background: var(--color-bad-soft);
    border-color: var(--color-bad);
    color: var(--color-bad);
    filter: none;
}

/* Icon-only button */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-subtle);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--dur) ease, color var(--dur) ease;
}
.btn-icon:hover { background: var(--color-surface-hover); color: var(--color-text); }
.btn-icon-danger:hover { background: var(--color-bad-soft); color: var(--color-bad); }

/* Sizes */
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-lg { height: 44px; padding: 0 22px; font-size: 15px; border-radius: var(--radius-md); }

/* Disabled */
.btn[disabled], .btn:disabled {
    background: var(--color-surface-2);
    border-color: var(--color-border);
    color: var(--color-text-subtle);
    cursor: not-allowed;
    box-shadow: none;
    filter: none;
    background-image: none;
}

.btn-primary { /* explicit alias */
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
    color: oklch(100% 0 0);
    border-color: transparent;
}

form.inline { display: inline; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ============================================================
   6c. Tables
   ============================================================ */

table.data {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}
table.data th, table.data td {
    padding: 10px 14px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--color-border-subtle);
}
table.data th {
    font-weight: 500;
    color: var(--color-text-subtle);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--color-surface-2);
    border-bottom: 1px solid var(--color-border);
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background var(--dur-fast) var(--ease-out-soft); }
table.data tbody tr:hover { background: var(--color-surface-2); }

table.kv {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
table.kv td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--color-border-subtle);
    vertical-align: top;
}
table.kv tr:last-child td { border-bottom: none; }
table.kv td:first-child {
    font-weight: 500;
    color: var(--color-text-muted);
    width: 32%;
    white-space: nowrap;
}

/* ============================================================
   6d. Chips / badges
   ============================================================ */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--color-surface-hover);
    color: var(--color-text-muted);
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
    border: 1px solid transparent;
    white-space: nowrap;
}
.chip::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.75;
    flex-shrink: 0;
}
.chip .chip-icon {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}
.chip-icon + ::before { display: none; }

.chip-ok      { background: var(--color-ok-soft);      color: var(--color-ok); }
.chip-warn    { background: var(--color-warn-soft);    color: var(--color-warn); }
.chip-bad     { background: var(--color-bad-soft);     color: var(--color-bad); }
.chip-info    { background: var(--color-info-soft);    color: var(--color-info); }
.chip-primary { background: var(--color-primary-soft); color: var(--color-primary); }
.chip-plain::before { display: none; }

/* Animated "running" dot */
.chip-warn.chip-running::before { animation: pulse-dot 1.6s var(--ease-in-out-soft) infinite; }

/* Confidence */
.conf-high   { color: var(--color-ok);   font-weight: 500; }
.conf-medium { color: var(--color-warn); font-weight: 500; }
.conf-low    { color: var(--color-bad);  font-weight: 600; }
.missing     { color: var(--color-text-faint); font-style: italic; }

.source {
    font-family: var(--font-mono);
    font-size: 0.82em;
    color: var(--color-text-subtle);
}

/* ============================================================
   6e. Findings
   ============================================================ */

.finding {
    display: flex;
    gap: 12px;
    padding: 12px 14px;
    border-left: 4px solid var(--color-border);
    background: var(--color-surface-2);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin-bottom: 8px;
    font-size: 14px;
    line-height: 1.45;
}
.finding-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin-top: 1px;
}
.finding-body { flex: 1; min-width: 0; }
.finding.required    { border-left-color: var(--color-bad);  background: var(--color-bad-soft); }
.finding.recommended { border-left-color: var(--color-warn); background: var(--color-warn-soft); }
.finding.info        { border-left-color: var(--color-info); background: var(--color-info-soft); }
[data-theme="dark"] .finding.required,
[data-theme="dark"] .finding.recommended,
[data-theme="dark"] .finding.info { color: var(--color-text); }

/* ============================================================
   6f. Forms + dropzone
   ============================================================ */

label {
    display: block;
    margin-top: 14px;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
}
label.required::after { content: " *"; color: var(--color-bad); }

input[type=text], input[type=number], input[type=date],
input[type=email], input[type=tel], input[type=password],
input[type=search], input[type=url],
textarea, select {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    font: inherit;
    font-size: 14px;
    background: var(--color-surface);
    color: var(--color-text);
    transition:
        border-color var(--dur-fast) var(--ease-out-soft),
        box-shadow var(--dur-fast) var(--ease-out-soft),
        background var(--dur-fast) var(--ease-out-soft);
}
textarea {
    height: auto;
    min-height: 84px;
    padding: 10px 12px;
    resize: vertical;
    line-height: 1.5;
}
input:hover:not([disabled]), textarea:hover:not([disabled]), select:hover:not([disabled]) {
    border-color: color-mix(in oklab, var(--color-primary) 45%, var(--color-border-strong));
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--ring);
}
input[disabled], textarea[disabled], select[disabled] {
    background: var(--color-surface-2);
    color: var(--color-text-subtle);
    cursor: not-allowed;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 18px; }
@media (max-width: 720px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
.col-span-all { grid-column: 1 / -1; }

/* File input fallback */
input[type=file] {
    width: 100%;
    padding: 8px;
    height: auto;
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    font-size: 13px;
}
input[type=file]::file-selector-button {
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    margin-right: 10px;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    color: var(--color-text);
    transition:
        background var(--dur-fast) var(--ease-out-soft),
        border-color var(--dur-fast) var(--ease-out-soft);
}
input[type=file]::file-selector-button:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-primary);
}

/* Dropzone */
.dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 180px;
    padding: 28px 20px;
    border: 3px dashed var(--color-border-strong);
    background: var(--color-surface-2);
    border-radius: var(--radius-lg);
    text-align: center;
    transition:
        border-color var(--dur) var(--ease-out-soft),
        background var(--dur) var(--ease-out-soft),
        box-shadow var(--dur) var(--ease-out-soft);
    cursor: pointer;
}
.dropzone:hover,
.dropzone.is-dragover,
.dropzone:has(:focus-visible) {
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
}
.dropzone.is-dragover {
    box-shadow: var(--shadow-glow-primary);
}
.dropzone svg { width: 32px; height: 32px; color: var(--color-text-subtle); transition: color var(--dur) var(--ease-out-soft); }
.dropzone:hover svg,
.dropzone.is-dragover svg,
.dropzone:has(:focus-visible) svg { color: var(--color-primary); }
.dropzone input[type=file] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    border: none;
    padding: 0;
}
.dropzone-title { font-weight: 500; color: var(--color-text); }
.dropzone-hint  { font-size: 13px; color: var(--color-text-subtle); }

/* Doc list */
.doclist {
    list-style: none;
    padding: 0;
    margin: 0 0 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.doclist li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-mono);
    color: var(--color-text-muted);
}
.doclist svg {
    width: 14px;
    height: 14px;
    color: var(--color-text-subtle);
    flex-shrink: 0;
}

/* ============================================================
   6g. Stepper
   ============================================================ */

.stepper {
    display: flex;
    gap: 0;
    padding: 14px 20px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: 22px;
    overflow-x: auto;
    box-shadow: var(--shadow-xs);
    list-style: none;
}
.step {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--color-text-subtle);
    white-space: nowrap;
    position: relative;
    flex: 0 0 auto;
}
.step + .step::before {
    content: "";
    width: 24px;
    height: 1px;
    background: var(--color-border);
    margin-right: 10px;
    transition: background var(--dur) var(--ease-out-soft);
}
.step.done + .step.done::before,
.step.done + .step.active::before {
    background: linear-gradient(90deg, var(--color-ok), var(--color-primary));
}
.step-index {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--color-surface-hover);
    color: var(--color-text-subtle);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
    border: 1.5px solid transparent;
    transition:
        background var(--dur) var(--ease-out-soft),
        color var(--dur) var(--ease-out-soft),
        box-shadow var(--dur) var(--ease-out-soft);
}
.step.active {
    color: var(--color-primary);
    font-weight: 500;
    view-transition-name: stepper-active;
}
.step.active .step-index {
    background: var(--color-primary);
    color: oklch(100% 0 0);
    box-shadow: 0 0 0 4px var(--color-primary-soft);
    position: relative;
}
.step.active .step-index::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1.5px solid var(--color-primary);
    opacity: 0.45;
    animation: pulse-ring 1.6s var(--ease-in-out-soft) infinite;
}
.step.done { color: var(--color-text-muted); }
.step.done .step-index {
    background: var(--color-ok-soft);
    color: var(--color-ok);
    border-color: color-mix(in oklab, var(--color-ok) 55%, transparent);
}
.step.done .step-index::before {
    content: "✓";
    font-size: 13px;
    font-weight: 700;
}
.step.done .step-index-num { display: none; }

/* ============================================================
   6h. Stat cards
   ============================================================ */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.stat {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 18px 22px;
    box-shadow: var(--shadow-xs);
    transition:
        box-shadow var(--dur) var(--ease-out-soft),
        transform var(--dur) var(--ease-out-soft),
        border-color var(--dur) var(--ease-out-soft);
    overflow: hidden;
}
.stat:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--color-border-strong);
    transform: translateY(-1px);
}
.stat-label {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-subtle);
    font-weight: 500;
    margin-bottom: 6px;
}
.stat-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--color-text);
    letter-spacing: -0.02em;
    line-height: 1.1;
}
.stat-accent {
    background:
        linear-gradient(135deg,
            var(--color-primary-soft) 0%,
            var(--color-surface) 100%);
    border-color: color-mix(in oklab, var(--color-primary) 18%, var(--color-border));
}
.stat-accent .stat-value { color: var(--color-primary); }

/* New: gradient top-stripe stat (for "In review" style) */
.stat-gradient::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    border-top-left-radius: inherit;
    border-top-right-radius: inherit;
}
.stat-gradient .stat-value {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
            background-clip: text;
    color: transparent;
}

/* ============================================================
   6i. Case cards
   ============================================================ */

.case-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
.case-card {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    padding: 14px 18px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: inherit;
    transition:
        border-color var(--dur-fast) var(--ease-out-soft),
        box-shadow var(--dur-fast) var(--ease-out-soft),
        transform var(--dur-fast) var(--ease-out-soft);
    box-shadow: var(--shadow-xs);
}
.case-card:hover {
    border-color: var(--color-border-strong);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
    text-decoration: none;
    color: inherit;
}
.case-card:hover .case-card-name { color: var(--color-primary); }
.case-card-main { min-width: 0; flex: 1; }
.case-card-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--color-text);
    margin-bottom: 3px;
    transition: color var(--dur-fast) var(--ease-out-soft);
}
.case-card-meta {
    font-size: 12px;
    color: var(--color-text-subtle);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.case-card-meta span { display: inline-flex; align-items: center; gap: 4px; }
.case-card-meta svg { width: 12px; height: 12px; }
.case-card-meta .mono {
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border-subtle);
}
@media (max-width: 640px) {
    .case-card { flex-direction: column; align-items: flex-start; }
}

/* Case card — delete modal */
.delete-modal {
    border: none;
    border-radius: var(--radius-lg);
    padding: 0;
    max-width: 400px;
    width: calc(100% - 32px);
    box-shadow: var(--shadow-lg);
    background: var(--color-surface);
    color: var(--color-text);
    animation: modal-in var(--dur) var(--ease-out-soft);
}
.delete-modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
    animation: fade-in var(--dur) ease;
}
.delete-modal-content {
    padding: 24px;
}
@keyframes modal-in {
    from { opacity: 0; transform: scale(0.95) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ============================================================
   6j. Empty states
   ============================================================ */

.empty {
    padding: 56px 20px;
    text-align: center;
    color: var(--color-text-subtle);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
}
.empty-icon {
    width: 48px;
    height: 48px;
    color: var(--color-text-faint);
    margin: 0 auto 12px;
    display: block;
}
.empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
}
.empty-hint {
    font-size: 14px;
    max-width: 40ch;
    margin: 0 auto 16px;
}

/* ============================================================
   6k. Progress + spinner
   ============================================================ */

.progress-outer {
    width: 100%;
    height: 8px;
    background: var(--color-surface-hover);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: 10px 0 6px;
    view-transition-name: extract-progress;
}
.progress-inner {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    transition: width var(--dur-slow) var(--ease-out-soft);
    min-width: 4px;
    border-radius: inherit;
    position: relative;
    overflow: hidden;
}
.progress-inner::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image: linear-gradient(
        90deg,
        transparent 0%,
        oklch(100% 0 0 / 0.35) 50%,
        transparent 100%
    );
    animation: shimmer 1.6s linear infinite;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: -3px;
    margin-right: 8px;
}

/* htmx indicator */
.htmx-request .hide-while-loading { display: none; }
.show-while-loading { display: none; }
.htmx-request .show-while-loading { display: inline; }

/* ============================================================
   6l. Callouts
   ============================================================ */

.callout {
    display: flex;
    gap: 12px;
    padding: 14px 18px 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-border-strong);
    background: var(--color-surface-2);
    margin-bottom: 18px;
    align-items: flex-start;
    font-size: 14px;
}
.callout svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.callout-body { flex: 1; min-width: 0; }
.callout-title { font-weight: 600; margin-bottom: 2px; }

.callout-warn {
    background: var(--color-warn-soft);
    border-color: color-mix(in oklab, var(--color-warn) 25%, transparent);
    border-left-color: var(--color-warn);
    color: var(--color-text);
}
.callout-bad {
    background: var(--color-bad-soft);
    border-color: color-mix(in oklab, var(--color-bad) 25%, transparent);
    border-left-color: var(--color-bad);
    color: var(--color-text);
}
.callout-ok {
    background: var(--color-ok-soft);
    border-color: color-mix(in oklab, var(--color-ok) 25%, transparent);
    border-left-color: var(--color-ok);
    color: var(--color-text);
}
.callout-info {
    background: var(--color-info-soft);
    border-color: color-mix(in oklab, var(--color-info) 25%, transparent);
    border-left-color: var(--color-info);
    color: var(--color-text);
}

/* ============================================================
   6m. Dropdown (<details>-based)
   ============================================================ */

.dropdown {
    position: relative;
}
.dropdown > summary {
    list-style: none;
    cursor: pointer;
}
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown > summary::marker { content: ""; }

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 200px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 6px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: fade-in-up var(--dur) var(--ease-out-soft) both;
}
.dropdown[open] > summary {
    background: var(--color-surface-hover);
}
.dropdown-menu a,
.dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--color-text);
    background: transparent;
    border: 0;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
    font: inherit;
    font-weight: 500;
    transition: background var(--dur-fast) var(--ease-out-soft), color var(--dur-fast) var(--ease-out-soft);
}
.dropdown-menu a:hover,
.dropdown-menu button:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
    text-decoration: none;
}
.dropdown-menu svg { width: 14px; height: 14px; color: var(--color-text-subtle); }
.dropdown-divider {
    height: 1px;
    background: var(--color-border-subtle);
    margin: 4px 0;
}
/* Let a <form> in the dropdown pass its child through the flex column
   so the button sits in the same slot as sibling <a> items. */
.dropdown-form { display: contents; }
.dropdown-menu .dropdown-form button { width: 100%; }

/* ============================================================
   6n. Toast
   ============================================================ */

.toast {
    position: fixed;
    top: 80px;
    right: 16px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 14px;
    color: var(--color-text);
    min-width: 240px;
    max-width: 400px;
    animation: fade-in-up var(--dur-slow) var(--ease-out-soft) both;
}
.toast svg { width: 16px; height: 16px; color: var(--color-primary); flex-shrink: 0; }
.toast-ok   { border-left-color: var(--color-ok);   }
.toast-warn { border-left-color: var(--color-warn); }
.toast-bad  { border-left-color: var(--color-bad);  }
.toast.is-leaving { animation: fade-out-up var(--dur) var(--ease-out-soft) forwards; }

/* ============================================================
   7. Utilities
   ============================================================ */

.divider {
    border: 0;
    border-top: 1px solid var(--color-border-subtle);
    margin: 24px 0;
}
.row         { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.gap-sm      { gap: 6px; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }
.mt-4 { margin-top: 24px; }
.mb-0 { margin-bottom: 0 !important; }
.pad-lg { padding: 28px 32px; }

/* ============================================================
   8. Animations
   ============================================================ */

@keyframes fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}
@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}
@keyframes fade-out-up {
    to { opacity: 0; transform: translateY(-8px); }
}
@keyframes shimmer {
    from { transform: translateX(-100%); }
    to   { transform: translateX(100%); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-dot {
    0%, 100% { transform: scale(0.95); opacity: 0.55; }
    50%      { transform: scale(1.10); opacity: 1; }
}
@keyframes pulse-ring {
    0%   { transform: scale(0.95); opacity: 0.7; }
    70%  { transform: scale(1.25); opacity: 0; }
    100% { transform: scale(1.25); opacity: 0; }
}
@keyframes glow {
    0%, 100% { box-shadow: var(--shadow-glow-primary); }
    50%      { box-shadow: var(--shadow-glow-accent); }
}

.fade-in {
    animation: fade-in 280ms var(--ease-out-soft) both;
}

/* Stagger helper — parent sets data-stagger via app.js, children get --stagger-i */
.stagger-in {
    animation: fade-in-up 400ms var(--ease-out-soft) both;
    animation-delay: calc(var(--stagger-i, 0) * 60ms + 40ms);
}
/* Fallback when templates use --i instead of --stagger-i */
[style*="--i"] .stagger-in,
.stagger-in[style*="--i"] {
    animation-delay: calc(var(--i, 0) * 60ms + 40ms);
}

/* Default subtle entrance for common surfaces (retained from legacy) */
.panel, .card, .stepper, .stats {
    animation: fade-in 280ms var(--ease-out-soft) both;
}

/* Signable finalize panel */
.card-glow.card-glow-animated {
    animation: glow 2.4s var(--ease-in-out-soft) infinite;
}

/* Reduced motion — disable all animations + ambient decoration */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .bg-ambient::before,
    .bg-ambient::after { display: none; }
    .step.active .step-index::after { display: none; }
}

/* View-transition names used by htmx swaps (fallback if browser lacks support is harmless) */
::view-transition-old(extract-progress),
::view-transition-new(extract-progress) {
    animation-duration: var(--dur-slow);
    animation-timing-function: var(--ease-out-soft);
}
::view-transition-old(nav-pill),
::view-transition-new(nav-pill) {
    animation-duration: var(--dur);
}

/* ============================================================
   6f (adjunct) — Inline field correction (Feature 1, wave 2)
   Click-to-edit affordance shared by demographics, labs, doses.
   ============================================================ */

.field-edit {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
    cursor: text;
    padding: 2px 8px 2px 6px;
    margin: -2px -4px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: inherit;
    text-align: left;
    border-radius: var(--radius-sm);
    transition:
        background var(--dur-fast) var(--ease-out-soft),
        box-shadow var(--dur-fast) var(--ease-out-soft),
        color var(--dur-fast) var(--ease-out-soft);
    max-width: 100%;
}
.field-edit:hover,
.field-edit:focus-visible {
    background: var(--color-surface-hover);
    outline: none;
    box-shadow: var(--ring);
}
.field-edit-value {
    min-width: 0;
    word-break: break-word;
}
.field-edit-icon {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    color: var(--color-text-faint);
    opacity: 0;
    transition: opacity var(--dur-fast) var(--ease-out-soft);
}
.field-edit:hover .field-edit-icon,
.field-edit:focus-visible .field-edit-icon {
    opacity: 1;
}

/* Low-confidence extracted values keep their yellow tint */
.field-edit.conf-low {
    background: var(--color-warn-soft);
    color: var(--color-text);
}
.field-edit.conf-low:hover,
.field-edit.conf-low:focus-visible {
    background: color-mix(in oklab, var(--color-warn-soft) 80%, var(--color-surface-hover));
}

/* Verified (surgeon-confirmed) — flips green with a ✓ marker */
.field-edit.conf-verified {
    background: var(--color-ok-soft);
    color: var(--color-ok);
    font-weight: 500;
}
.field-edit.conf-verified::after {
    content: "✓";
    margin-left: 4px;
    color: var(--color-ok);
    font-weight: 700;
}
.field-edit.conf-verified:hover,
.field-edit.conf-verified:focus-visible {
    background: color-mix(in oklab, var(--color-ok-soft) 80%, var(--color-surface-hover));
}

/* Edit-mode form swapped in by htmx */
.field-edit-form {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    width: 100%;
}
.field-edit-input {
    height: 32px;
    padding: 2px 8px;
    font-size: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-primary);
    box-shadow: var(--ring);
    background: var(--color-surface);
    color: var(--color-text);
    width: 100%;
    min-width: 0;
}
textarea.field-edit-input {
    min-height: 60px;
    height: auto;
    padding: 6px 8px;
    line-height: 1.4;
    resize: vertical;
}
.field-edit-error {
    display: inline-block;
    margin-top: 4px;
    padding: 4px 8px;
    font-size: 12px;
}

/* Vaccination dose rows */
.dose-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.dose-row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid var(--color-border-subtle);
}
.dose-row:last-child { border-bottom: 0; }

/* Reduced-motion branch: the :hover→background transition is already
   <= 120ms, which the global reduced-motion override clamps to 0.01ms
   without extra work here. The focus-visible ring is non-animated. */


/* ============================================================
   6c (adjunct) — Part 5 drug/mental screening + Part 6 ROS grid
   Scoped to the In-office exam card. OKLCH tokens only so dark
   mode inherits for free. JS (screeningToggle IIFE in app.js)
   adds/removes .is-abnormal / .is-positive / .is-class-a on the
   row when the radio changes.
   ============================================================ */

/* Drug & mental screening rows */
.screening-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}
.screening-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px 14px;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    background: var(--color-surface-2);
    border-left-width: 3px;
    border-left-color: var(--color-border-subtle);
    transition: background var(--dur-fast) var(--ease-out-soft),
                border-left-color var(--dur-fast) var(--ease-out-soft);
}
.screening-label { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.screening-answers { display: flex; gap: 14px; flex-wrap: wrap; }
.screening-answers label {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    font-size: 13px;
    margin: 0;
    cursor: pointer;
}
.screening-row.is-positive {
    border-left-color: var(--color-warn);
    background: var(--color-warn-soft);
}
.screening-row.is-class-a {
    border-left-color: var(--color-bad);
    background: var(--color-bad-soft);
}
.hide-unless-positive { display: none; }
.screening-row.is-positive .hide-unless-positive,
.screening-row.is-class-a  .hide-unless-positive { display: block; }

/* Review of systems table — leans on .table.data tokens */
.ros-table { margin-top: 6px; }
.ros-row td { vertical-align: middle; }
.ros-radios {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 13px;
}
.ros-radios label {
    margin: 0;
    display: inline-flex;
    gap: 5px;
    align-items: center;
    cursor: pointer;
}
.ros-findings-row { }
.ros-findings-row.hide-unless-abnormal { display: none; }
.ros-row.is-abnormal td:first-child {
    border-left: 3px solid var(--color-warn);
}
.ros-row.is-abnormal + .ros-findings-row {
    background: var(--color-warn-soft);
}
.ros-findings-row textarea {
    width: 100%;
    min-height: 48px;
}


/* ============================================================
   §6a adjunct — PDF preview (Feature 5, wave 2)
   In-app iframe wrapper for the filled I-693 draft. Dark-mode
   parity: tokens only, no hard-coded colors. The iframe content
   is the PDF itself (light by nature) — only the surrounding
   chrome adapts.
   ============================================================ */
.pdf-preview {
    width: 100%;
    height: 900px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    box-shadow: var(--shadow-sm);
    display: block;
}
.pdf-preview-wrap {
    animation: fade-in var(--dur, 240ms) var(--ease-out-soft, ease-out) both;
}
@media (max-width: 640px) {
    .pdf-preview { height: 70vh; }
}


/* ============================================================
   a11y utilities — fieldset reset + visually-hidden legend
   Wraps radio groups in <fieldset><legend> so screen readers
   announce "group: <label>" without altering the visual layout.
   Token-only (no hard-coded colors) so dark-mode parity is free.
   ============================================================ */
.fieldset-bare {
    border: 0;
    padding: 0;
    margin: 0;
    min-width: 0;
}
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.toast-warn {
    background: oklch(0.65 0.18 55);
    color: oklch(100% 0 0);
}

/* ============================================================
   6m. File-chip preview + upload indicator + JS-only visibility
   ============================================================ */

/* Hide elements flagged .js-hidden when JS ran and added .js-on
   to <html>. Without JS, these elements remain visible (graceful
   degradation path — the submit button shows and plain POST works). */
.js-on .js-hidden { display: none !important; }

.file-chips {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.file-chips:empty { display: none; }

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm, 6px);
    font-size: 13px;
    color: var(--color-text);
    max-width: 100%;
}
.file-chip-name {
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-size: 12.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 40ch;
}
.file-chip-size {
    color: var(--color-text-subtle);
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
}
.file-chip-error {
    background: color-mix(in oklab, var(--color-bad) 12%, var(--color-surface-2));
    border-color: color-mix(in oklab, var(--color-bad) 45%, var(--color-border));
}

.upload-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 13px;
    color: var(--color-text-subtle);
}
/* htmx toggles .htmx-request on the element with hx-post (the form)
   while the request is in flight. Show the indicator only then. */
.htmx-request #upload-indicator,
.htmx-request.upload-indicator,
#upload-form.htmx-request #upload-indicator {
    display: inline-flex;
}
.upload-indicator .spinner {
    margin-right: 0;
    width: 14px;
    height: 14px;
}

/* ============================================================
   Login page
   Centered single-card layout, reuses existing input styling.
   ============================================================ */
.login-body { min-height: 100vh; }
.login-main {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 32px 20px;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: 32px 30px 28px;
    box-shadow:
        0 10px 30px -10px oklch(20% 0.02 260 / 0.12),
        0 2px 6px -2px oklch(20% 0.02 260 / 0.06);
}
.login-brand {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 22px;
}
.login-brand .brand-text { line-height: 1.15; }
.login-title {
    margin: 0 0 6px;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.015em;
}
.login-sub { margin: 0 0 20px; font-size: 14px; }
.login-form label:first-of-type { margin-top: 2px; }
.login-submit {
    width: 100%;
    margin-top: 20px;
    justify-content: center;
}
.login-foot {
    margin-top: 22px;
    text-align: center;
}

/* ============================================================
   How-it-works (home page walkthrough)
   ============================================================ */
.how-it-works {
    margin: 6px 0 28px;
}
.how-head {
    text-align: center;
    margin-bottom: 20px;
}
.how-title {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.how-sub {
    margin: 0;
    font-size: 14px;
}
.how-steps {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}
@media (max-width: 900px) {
    .how-steps { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
    .how-steps { grid-template-columns: 1fr; }
}
.how-step {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 18px 16px 16px;
    transition: transform var(--dur-fast) var(--ease-out-soft),
                box-shadow var(--dur-fast) var(--ease-out-soft),
                border-color var(--dur-fast) var(--ease-out-soft);
}
.how-step:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px -8px oklch(20% 0.02 260 / 0.12);
    border-color: color-mix(in oklab, var(--color-primary) 30%, var(--color-border));
}
.how-step-num {
    position: absolute;
    top: -10px;
    left: 14px;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 4px 10px -3px var(--color-primary-glow);
}
.how-step-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: var(--color-primary-soft);
    color: var(--color-primary);
    margin-bottom: 10px;
    margin-top: 4px;
}
.how-step-icon svg { width: 16px; height: 16px; }
.how-step-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    color: var(--color-text);
}
.how-step-desc {
    font-size: 13px;
    line-height: 1.5;
    color: var(--color-text-muted);
}

/* ============================================================
   Onboarding tour
   ============================================================ */

.tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    pointer-events: auto;
    animation: tour-fade-in 300ms var(--ease-out-soft) both;
}

.tour-spotlight {
    position: absolute;
    z-index: 9998;
    border-radius: var(--radius-md);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    pointer-events: none;
    transition: top 300ms var(--ease-out-soft),
                left 300ms var(--ease-out-soft),
                width 300ms var(--ease-out-soft),
                height 300ms var(--ease-out-soft);
}

.tour-tooltip {
    position: absolute;
    z-index: 9999;
    max-width: 340px;
    width: calc(100vw - 32px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-lg);
    animation: tour-fade-in 260ms var(--ease-out-soft) both;
}
.tour-tooltip::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
}

.tour-step-label {
    display: inline-block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-subtle);
    font-weight: 500;
    margin-bottom: 6px;
}
.tour-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 6px;
    line-height: 1.3;
}
.tour-body {
    font-size: 14px;
    color: var(--color-text-muted);
    line-height: 1.55;
    margin: 0 0 18px;
}

.tour-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.tour-actions .tour-skip {
    background: transparent;
    border: 0;
    color: var(--color-text-subtle);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: color var(--dur-fast) var(--ease-out-soft),
                background var(--dur-fast) var(--ease-out-soft);
}
.tour-actions .tour-skip:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
}
.tour-actions .tour-next {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 16px;
    border: 0;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: oklch(100% 0 0);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: inset 0 1px 0 oklch(100% 0 0 / 0.16), var(--shadow-sm);
    transition: filter var(--dur-fast) var(--ease-out-soft),
                box-shadow var(--dur-fast) var(--ease-out-soft);
}
.tour-actions .tour-next:hover {
    filter: brightness(1.05);
    box-shadow: inset 0 1px 0 oklch(100% 0 0 / 0.2), var(--shadow-md);
}

.tour-leaving {
    animation: tour-fade-out 200ms var(--ease-out-soft) forwards;
}

@keyframes tour-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes tour-fade-out {
    from { opacity: 1; }
    to   { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .tour-overlay,
    .tour-spotlight,
    .tour-tooltip,
    .tour-leaving {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================================
   How-it-works collapsible (details/summary)
   ============================================================ */
.how-it-works-toggle {
    list-style: none;
    cursor: pointer;
}
.how-it-works-toggle::-webkit-details-marker { display: none; }
.how-it-works-toggle::marker { content: ""; }
.how-it-works-toggle .how-toggle-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    vertical-align: -2px;
    margin-left: 6px;
    color: var(--color-text-subtle);
    transition: transform var(--dur) var(--ease-out-soft);
}
details.how-it-works-details[open] .how-toggle-icon {
    transform: rotate(180deg);
}
