/* =======================================
   DESIGN TOKENS (Light / Dark)
======================================= */
:root {
    color-scheme: light;

    /* Typography */
    --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
    --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;

    /* Surfaces */
    --bg: #f5f7fb;
    --bg-glow-1: rgba(0, 80, 157, 0.09);
    --bg-glow-2: rgba(0, 168, 140, 0.08);
    --nav-bg: rgba(245, 247, 251, 0.82);
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --border: #e3e8ef;
    --border-strong: #cdd6e2;

    /* Text */
    --text: #0f1f33;
    --text-muted: #56677c;
    --text-subtle: #8593a6;

    /* Brand */
    --brand: #00509d;
    --brand-strong: #003e7a;
    --brand-soft: rgba(0, 80, 157, 0.08);
    --accent: #00a88c;
    --accent-strong: #00806b;
    --accent-soft: rgba(0, 168, 140, 0.1);
    --grad: linear-gradient(135deg, #00509d 0%, #00897b 100%);
    --grad-text: linear-gradient(120deg, #00509d 0%, #00897b 100%);
    --focus-ring: rgba(0, 168, 140, 0.35);

    /* Status */
    --success: #0e8a6a;
    --warning: #c27c0e;
    --warning-soft: rgba(194, 124, 14, 0.1);
    --danger: #c0392b;
    --danger-soft: rgba(192, 57, 43, 0.08);

    /* Tags */
    --drug-fg: #00806b;
    --drug-bg: rgba(0, 184, 148, 0.1);
    --drug-border: rgba(0, 184, 148, 0.28);
    --disease-fg: #b45a12;
    --disease-bg: rgba(230, 126, 34, 0.1);
    --disease-border: rgba(230, 126, 34, 0.3);
    --rule-fg: #5b4bd6;
    --rule-bg: rgba(108, 92, 231, 0.1);

    /* Shape & depth */
    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 22px;
    --shadow-sm: 0 1px 2px rgba(15, 31, 51, 0.06);
    --shadow-md: 0 1px 3px rgba(15, 31, 51, 0.05), 0 6px 20px rgba(15, 31, 51, 0.06);
    --shadow-lg: 0 2px 6px rgba(15, 31, 51, 0.04), 0 18px 48px rgba(15, 31, 51, 0.1);
    --shadow-btn: 0 6px 18px rgba(0, 80, 157, 0.24);
}

[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0a111d;
    --bg-glow-1: rgba(64, 140, 255, 0.12);
    --bg-glow-2: rgba(45, 212, 180, 0.08);
    --nav-bg: rgba(10, 17, 29, 0.78);
    --surface: #101a2a;
    --surface-2: #0d1624;
    --border: #1f2c41;
    --border-strong: #2c3c57;

    --text: #e7edf5;
    --text-muted: #9fadc0;
    --text-subtle: #6f7e94;

    --brand: #6cb0ff;
    --brand-strong: #9ccaff;
    --brand-soft: rgba(108, 176, 255, 0.12);
    --accent: #2dd4b4;
    --accent-strong: #5ee3c8;
    --accent-soft: rgba(45, 212, 180, 0.12);
    --grad: linear-gradient(135deg, #1d68c4 0%, #0b8a77 100%);
    --grad-text: linear-gradient(120deg, #7ab8ff 0%, #3ddcbf 100%);
    --focus-ring: rgba(45, 212, 180, 0.4);

    --success: #34d399;
    --warning: #f5b544;
    --warning-soft: rgba(245, 181, 68, 0.12);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.1);

    --drug-fg: #5ee3c8;
    --drug-bg: rgba(45, 212, 180, 0.12);
    --drug-border: rgba(45, 212, 180, 0.3);
    --disease-fg: #f5b06a;
    --disease-bg: rgba(240, 163, 86, 0.12);
    --disease-border: rgba(240, 163, 86, 0.32);
    --rule-fg: #b3a9ff;
    --rule-bg: rgba(162, 155, 254, 0.14);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.3), 0 20px 50px rgba(0, 0, 0, 0.4);
    --shadow-btn: 0 6px 18px rgba(0, 0, 0, 0.35);
}

/* =======================================
   RESET & BASE
======================================= */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text);
    background:
        radial-gradient(1100px 520px at 0% -10%, var(--bg-glow-1), transparent 60%),
        radial-gradient(900px 480px at 100% -5%, var(--bg-glow-2), transparent 60%),
        var(--bg);
    background-repeat: no-repeat;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1,
h2,
h3 {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--text);
    line-height: 1.15;
    text-wrap: balance;
}

a {
    color: var(--brand);
}

:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
    border-radius: 6px;
}

[hidden] {
    display: none !important;
}

/* =======================================
   NAVIGATION
======================================= */
nav {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem clamp(1rem, 4vw, 3rem);
    background: var(--nav-bg);
    border-bottom: 1px solid var(--border);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
}

nav .logo {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--font-display);
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--text);
    text-decoration: none;
}

.logo-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--grad);
    box-shadow: 0 4px 12px rgba(0, 80, 157, 0.25);
    flex-shrink: 0;
}

.logo-mark svg {
    width: 20px;
    height: 20px;
}

nav ul {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

nav ul a {
    display: inline-block;
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s ease, background-color 0.2s ease;
}

nav ul a:hover {
    color: var(--text);
    background: var(--surface-2);
}

nav ul a[aria-current="page"] {
    color: var(--brand);
    background: var(--brand-soft);
}

.theme-toggle {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    margin-left: 0.4rem;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.theme-toggle:hover {
    border-color: var(--border-strong);
    transform: rotate(-12deg);
}

#theme-icon {
    width: 20px;
    height: 20px;
}

/* =======================================
   LAYOUT & TYPOGRAPHY
======================================= */
.container {
    flex: 1;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: clamp(2.5rem, 6vw, 4.5rem) 1.25rem 3.5rem;
    text-align: center;
}

h1 {
    font-size: clamp(2.1rem, 5.2vw, 3.4rem);
    letter-spacing: -0.02em;
    margin-bottom: 0.9rem;
    font-variation-settings: "opsz" 96;
}

h1 .accent {
    font-style: italic;
    background: var(--grad-text);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    padding-right: 0.06em;
}

.subtitle {
    max-width: 38rem;
    margin: 0 auto 2rem;
    font-size: clamp(1rem, 2vw, 1.125rem);
    color: var(--text-muted);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--accent-soft);
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* =======================================
   BUTTONS
======================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.8rem 1.6rem;
    border: none;
    border-radius: 999px;
    background: var(--grad);
    color: #ffffff;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--shadow-btn);
    transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.06);
    box-shadow: 0 10px 26px rgba(0, 80, 157, 0.28);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    background: var(--surface-2);
    color: var(--text-subtle);
    border: 1px solid var(--border);
    box-shadow: none;
    transform: none;
    filter: none;
    cursor: not-allowed;
}

.btn.is-busy:disabled {
    background: var(--grad);
    color: #ffffff;
    border: none;
    opacity: 0.85;
    cursor: progress;
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    border-color: var(--brand);
    color: var(--brand);
    filter: none;
    box-shadow: var(--shadow-md);
}

.btn-primary {
    padding: 1rem 2.2rem;
    font-size: 1.05rem;
}

.btn-lg {
    min-width: 220px;
    padding: 0.95rem 2rem;
    font-size: 1rem;
}

.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* =======================================
   ENGINE STATUS PILL
======================================= */
.engine-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
}

.engine-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-subtle);
}

.engine-status[data-state="warming"] .engine-dot {
    background: var(--warning);
    animation: pulse 1.4s ease-in-out infinite;
}

.engine-status[data-state="ready"] .engine-dot {
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(14, 138, 106, 0.18);
}

.engine-status[data-state="offline"] .engine-dot {
    background: var(--danger);
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(0.8); }
}

/* =======================================
   UPLOAD CARD
======================================= */
.upload-card {
    max-width: 640px;
    margin: 0 auto;
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.upload-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 2.75rem 1.5rem;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
}

.upload-box:hover,
.upload-box.is-dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.upload-box.is-dragover {
    transform: scale(1.01);
}

.upload-box.has-file {
    border-style: solid;
    border-color: var(--accent);
}

.upload-icon {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin-bottom: 0.4rem;
    border-radius: 18px;
    background: var(--grad);
    color: #ffffff;
    font-size: 1.55rem;
    box-shadow: 0 10px 24px rgba(0, 80, 157, 0.25);
}

.upload-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.upload-hint {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.upload-label-text {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-subtle);
}

.file-name-display {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 100%;
    margin-top: 0.4rem;
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.file-name-display:empty {
    display: none;
}

.file-name-display i {
    color: var(--accent-strong);
}

.file-name-display .file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-name-display .file-size {
    font-weight: 500;
    color: var(--text-subtle);
    white-space: nowrap;
}

.upload-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 0 0.35rem;
}

.status-message {
    min-height: 1.4em;
    max-width: 34rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.status-message.is-error {
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    color: var(--danger);
}

.status-message:empty {
    display: none;
}

/* Feature row under the upload card */
.feature-row {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem 1.75rem;
    margin-top: 2.25rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

.feature-row li {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.feature-row i {
    color: var(--accent);
}

/* Loader */
.loader {
    display: none;
    width: 28px;
    height: 28px;
    margin: 0 auto;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

/* =======================================
   ABOUT PAGE
======================================= */
.hero {
    position: relative;
    overflow: hidden;
    padding: clamp(3.5rem, 9vw, 6.5rem) 1.25rem;
    background: var(--grad);
    color: #ffffff;
    text-align: center;
}

.hero::before,
.hero::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}

.hero::before {
    width: 520px;
    height: 520px;
    top: -260px;
    right: -120px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.18), transparent 65%);
}

.hero::after {
    width: 420px;
    height: 420px;
    bottom: -240px;
    left: -100px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.12), transparent 65%);
}

.hero .container {
    position: relative;
    padding: 0;
}

.hero h1 {
    color: #ffffff;
    font-size: clamp(2.4rem, 6vw, 3.6rem);
}

.hero-subtitle {
    font-size: clamp(1.05rem, 2.2vw, 1.3rem);
    font-weight: 400;
    color: rgba(255, 255, 255, 0.88);
}

.main-content {
    flex: 1;
}

.main-content .container {
    padding-top: clamp(2.5rem, 6vw, 4rem);
}

.mission-section {
    margin-bottom: clamp(3rem, 7vw, 4.5rem);
}

.mission-card {
    position: relative;
    padding: clamp(1.75rem, 4vw, 2.75rem);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    text-align: left;
    overflow: hidden;
}

.mission-card::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    background: var(--grad);
}

.mission-card h2 {
    margin-bottom: 0.9rem;
    font-size: clamp(1.6rem, 3.5vw, 2rem);
}

.mission-card p {
    font-size: 1.075rem;
    line-height: 1.8;
    color: var(--text-muted);
}

.section-title {
    margin-bottom: 0.5rem;
    font-size: clamp(1.6rem, 3.5vw, 2.1rem);
}

.section-lead {
    margin-bottom: 2.25rem;
    color: var(--text-muted);
}

.steps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1.25rem;
    margin-bottom: clamp(3rem, 7vw, 4.5rem);
}

.step {
    padding: 2rem 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    text-align: left;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.step:hover {
    transform: translateY(-4px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-lg);
}

.step-icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    margin-bottom: 1.25rem;
    border-radius: 14px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 1.3rem;
}

.step-number {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-subtle);
}

.step h3 {
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
}

.step p {
    font-size: 0.975rem;
    color: var(--text-muted);
}

.cta-section {
    padding: clamp(2rem, 5vw, 3rem) 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    text-align: center;
}

.cta-section h2 {
    margin-bottom: 0.5rem;
    font-size: clamp(1.5rem, 3.2vw, 1.9rem);
}

.cta-section p {
    margin-bottom: 1.5rem;
    color: var(--text-muted);
}

/* =======================================
   RESULTS PAGE
======================================= */
.results {
    text-align: left;
}

.results-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.25rem;
    margin-bottom: 0.5rem;
}

.results-header h1 {
    margin-bottom: 0.35rem;
    font-size: clamp(1.9rem, 4.5vw, 2.6rem);
}

.results .subtitle {
    margin: 0;
    max-width: none;
    font-size: 1rem;
    overflow-wrap: anywhere;
}

.results-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.results-actions .btn {
    padding: 0.65rem 1.25rem;
    font-size: 0.9rem;
}

.result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1.25rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.chip i {
    font-size: 0.75rem;
}

.chip-type {
    color: var(--brand);
    background: var(--brand-soft);
    border-color: transparent;
}

.chip-urgency-routine {
    color: var(--success);
}

.chip-urgency-high {
    color: var(--warning);
}

.chip-urgency-urgent {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: transparent;
}

/* Cards */
.card,
.detection-section {
    margin-top: 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.detection-section {
    padding: 1.25rem 1.5rem;
}

.card-header,
.section-heading {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.section-heading {
    margin-bottom: 1rem;
}

.card-header i,
.section-heading i,
.corrections-toggle .toggle-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 0.875rem;
    flex-shrink: 0;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1.25rem 1.5rem;
    padding: 1.25rem 1.5rem 1.5rem;
}

.grid-item {
    min-width: 0;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text);
    overflow-wrap: anywhere;
}

.grid-item .label {
    display: block;
    margin-bottom: 0.2rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-subtle);
}

.instructions-list {
    list-style: none;
    display: grid;
    gap: 0.6rem;
}

.instructions-list li {
    position: relative;
    padding-left: 1.5rem;
    color: var(--text);
}

.instructions-list li::before {
    content: '';
    position: absolute;
    left: 0.25rem;
    top: 0.62em;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
}

/* Tags */
.tag-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    display: inline-flex;
    align-items: baseline;
    gap: 0.45rem;
    max-width: 100%;
    padding: 0.4rem 0.9rem;
    border-radius: 1.1rem;
    font-size: 0.875rem;
    font-weight: 600;
    overflow-wrap: anywhere;
    cursor: default;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tag:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.tag i {
    font-size: 0.75rem;
    opacity: 0.85;
}

.tag-drug {
    color: var(--drug-fg);
    background: var(--drug-bg);
    border: 1px solid var(--drug-border);
}

.tag-disease {
    color: var(--disease-fg);
    background: var(--disease-bg);
    border: 1px solid var(--disease-border);
}

/* Collapsible sections */
.corrections-toggle {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    padding: 0;
    border: none;
    background: none;
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.corrections-toggle:hover .corrections-chevron {
    opacity: 1;
}

.corrections-count {
    display: inline-grid;
    place-items: center;
    min-width: 24px;
    height: 24px;
    padding: 0 0.45rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.75rem;
    font-weight: 700;
}

.corrections-chevron {
    margin-left: auto;
    font-size: 0.8rem;
    opacity: 0.55;
    transition: transform 0.25s ease, opacity 0.2s ease;
}

.corrections-toggle[aria-expanded="true"] .corrections-chevron {
    transform: rotate(180deg);
}

.corrections-body {
    margin-top: 1rem;
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Extracted text */
.text-content {
    max-height: 520px;
    overflow-y: auto;
    padding: 1.25rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.75;
    color: var(--text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.corrections-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.corrections-table th {
    padding: 0.7rem 1rem;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: left;
    color: var(--text-subtle);
    white-space: nowrap;
}

.corrections-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: top;
}

.corrections-table tbody tr:last-child td {
    border-bottom: none;
}

.corrections-table tbody tr:hover td {
    background: var(--surface-2);
}

.corrections-table code {
    padding: 0.15rem 0.45rem;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text);
}

.correction-type {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: var(--surface-2);
    color: var(--text-muted);
}

.correction-type-ocrrule {
    background: var(--rule-bg);
    color: var(--rule-fg);
}

.correction-type-drug {
    background: var(--drug-bg);
    color: var(--drug-fg);
}

.correction-type-disease {
    background: var(--disease-bg);
    color: var(--disease-fg);
}

/* Legacy content box */
.content-box {
    max-width: 800px;
    margin: 20px auto;
    padding: 20px;
    background: var(--surface);
    text-align: left;
}

/* =======================================
   FOOTER
======================================= */
footer {
    margin-top: auto;
    padding: 1.5rem 1.25rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-subtle);
}

/* =======================================
   RESPONSIVE
======================================= */
@media (max-width: 640px) {
    nav {
        padding: 0.7rem 1rem;
    }

    nav .logo {
        font-size: 1.25rem;
    }

    nav ul a {
        padding: 0.4rem 0.65rem;
        font-size: 0.9rem;
    }

    .theme-toggle {
        width: 36px;
        height: 36px;
        margin-left: 0.15rem;
    }

    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .upload-card {
        padding: 0.9rem;
    }

    .upload-box {
        padding: 2rem 1rem;
    }

    .btn-lg {
        width: 100%;
    }

    .results-header {
        align-items: flex-start;
    }

    .detection-section {
        padding: 1.1rem 1.1rem;
    }

    .card-header {
        padding: 0.9rem 1.1rem;
    }

    .card-grid {
        padding: 1.1rem;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 380px) {
    nav .logo .logo-mark {
        display: none;
    }
}

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

/* ===============================
   PRESCRIPTION REVIEW FORM
=============================== */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.btn-sm {
    margin-top: 0.9rem;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.rx-form .field input,
.rx-form .field textarea {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
    resize: vertical;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.rx-form .field input:focus,
.rx-form .field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.rx-form .grid-item .label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.rx-form .needs-review input,
.rx-form .needs-review textarea {
    border-color: var(--warning);
    background: var(--warning-soft);
}

.rx-table td {
    padding: 0.45rem 0.5rem;
    vertical-align: middle;
}

.rx-table input {
    min-width: 6.5rem;
}

.rx-table td:first-child input {
    min-width: 9rem;
}

@media (max-width: 640px) {
    .rx-form .field-wide {
        grid-column: 1 / -1;
    }
}

.rx-table td:first-child input {
    font-weight: 600;
}

.row-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.row-actions .label {
    margin-right: 0.35rem;
}

.icon-btn {
    padding: 0.4rem 0.5rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-subtle);
    cursor: pointer;
}

.icon-btn:hover,
.icon-btn:focus-visible {
    background: var(--danger-soft);
    color: var(--danger);
}

.badge {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    white-space: nowrap;
    padding: 0.1rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font: inherit;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.badge-ai {
    border-color: var(--border);
    background: var(--brand-soft);
    color: var(--brand);
}

.badge-review {
    border-color: var(--warning);
    background: var(--warning-soft);
    color: var(--warning);
    cursor: pointer;
}

.badge-review:hover,
.badge-review:focus-visible {
    background: var(--warning);
    color: var(--surface);
}

.badge-ok {
    background: var(--accent-soft);
    color: var(--success);
}

.review-banner {
    display: flex;
    gap: 0.8rem;
    align-items: flex-start;
    margin: 0 0 1.5rem;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    background: var(--warning-soft);
    color: var(--text);
    font-size: 0.92rem;
    line-height: 1.5;
}

.review-banner[hidden] {
    display: none;
}

.review-banner > i {
    margin-top: 0.2rem;
    color: var(--warning);
}

.chip-ai {
    color: var(--brand);
}

@media print {
    nav,
    footer,
    .results-actions,
    .review-banner,
    #addMedicineBtn,
    .row-actions,
    #rawTextToggle,
    #rawTextBody,
    #correctionsSection,
    .result-meta {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .rx-form .field input,
    .rx-form .field textarea {
        border: none;
        padding: 0;
        background: none;
    }
}

/* ===============================
   ON-DEVICE AI CARD
=============================== */

.ai-card {
    margin-bottom: 1.5rem;
    border-color: var(--brand);
}

.ai-card-body {
    padding: 1rem 1.5rem 1.25rem;
    font-size: 0.95rem;
    line-height: 1.55;
}

.ai-card-body p {
    margin: 0 0 0.75rem;
}

.ai-card-body .ai-note {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.ai-card-body .status-message {
    margin-top: 0.75rem;
}

@media print {
    .ai-card {
        display: none !important;
    }
}

/* The extracted record is read-only: show fields as text, not as inputs */
.rx-form .field input[readonly],
.rx-form .field textarea[readonly] {
    padding-left: 0;
    padding-right: 0;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    resize: none;
    cursor: default;
}

.rx-form .needs-review input[readonly],
.rx-form .needs-review textarea[readonly] {
    padding-left: 0.5rem;
    border-color: var(--warning);
    background: var(--warning-soft);
}

.rx-table td:first-child input[readonly] {
    font-weight: 600;
}

.rx-table .empty-row {
    padding: 0.9rem 0.5rem;
    color: var(--text-muted);
}

/* ===============================
   TOKEN CHECK
=============================== */

.token-card {
    margin-bottom: 1.5rem;
}

.token-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 1rem 1.5rem;
    padding: 1.25rem 1.5rem 0.75rem;
}

.token-stat .label {
    display: block;
    margin-bottom: 0.2rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-subtle);
}

.token-stat strong {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
}

.token-bar {
    height: 8px;
    margin: 0.25rem 1.5rem 0.75rem;
    border-radius: 999px;
    background: var(--warning-soft);
    overflow: hidden;
}

.token-bar span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: var(--accent);
}

.token-note {
    margin: 0 1.5rem 0.75rem;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.token-details {
    margin: 0 1.5rem 0.75rem;
    font-size: 0.9rem;
}

.token-details summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
}

.token-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding-top: 0.6rem;
}

.token-chip {
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text);
}

.token-more {
    align-self: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}
