/* ======================================================
   AI20K-198 Clinical Reasoning Agent — Design System
   Premium dark/light theme with glassmorphism and gradients
   ====================================================== */

/* ---- CSS Variables (Dark Theme — Default) ---- */
:root {
    /* === DARK MEDICAL MODE === */
    --bg-primary: #090c18;
    --bg-secondary: #0f1322;
    --bg-card: rgba(15, 19, 34, 0.85);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --bg-glass-hover: rgba(255, 255, 255, 0.08);
    --bg-base: #090c18;

    --text-primary: #eef2ff;
    --text-secondary: #94a3b8;
    --text-muted: #4e6080;

    --accent-primary: #6C63FF;
    --accent-secondary: #00D2FF;
    --accent-danger: #FF6B6B;
    --accent-warning: #FFD93D;
    --accent-success: #4ADE80;

    --gradient-primary: linear-gradient(135deg, #6C63FF 0%, #00D2FF 100%);
    --gradient-warm: linear-gradient(135deg, #FF6B6B 0%, #FFD93D 100%);
    --gradient-cool: linear-gradient(135deg, #00D2FF 0%, #4ADE80 100%);

    --border-color: rgba(255, 255, 255, 0.07);
    --border-active: rgba(108, 99, 255, 0.5);

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.5);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.6);
    --shadow-glow: 0 0 30px rgba(108, 99, 255, 0.2);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Font */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Scrollbar */
    --scrollbar-thumb: rgba(255,255,255,0.12);
    --scrollbar-thumb-hover: rgba(255,255,255,0.22);

    /* Overlay */
    --overlay-bg: rgba(0, 0, 0, 0.65);

    /* Theme overlay flash */
    --theme-flash: rgba(9,12,24,0.95);
}

/* ---- Light Clinical Theme ---- */
[data-theme="light"] {
    /* === LIGHT CLINICAL MODE === */
    --bg-primary: #f4f6fb;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.92);
    --bg-glass: rgba(0, 0, 0, 0.025);
    --bg-glass-hover: rgba(0, 0, 0, 0.05);
    --bg-base: #f4f6fb;

    --text-primary: #0d1421;
    --text-secondary: #3d5068;
    --text-muted: #8fa0b5;

    --accent-primary: #5a52e8;
    --accent-secondary: #0096c7;
    --accent-danger: #e03131;
    --accent-warning: #f59f00;
    --accent-success: #2f9e44;

    --gradient-primary: linear-gradient(135deg, #5a52e8 0%, #0096c7 100%);
    --gradient-warm: linear-gradient(135deg, #e03131 0%, #f59f00 100%);
    --gradient-cool: linear-gradient(135deg, #0096c7 0%, #2f9e44 100%);

    --border-color: rgba(0, 0, 0, 0.08);
    --border-active: rgba(90, 82, 232, 0.4);

    --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.1);
    --shadow-glow: 0 0 24px rgba(90,82,232,0.12);

    --scrollbar-thumb: rgba(0,0,0,0.12);
    --scrollbar-thumb-hover: rgba(0,0,0,0.22);
    --overlay-bg: rgba(0, 0, 0, 0.45);
    --theme-flash: rgba(244,246,251,0.95);
}

/* ---- Theme Transition ---- */
body, body * {
    transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}

/* Exclude canvas and SVG from transition flicker */
canvas, svg * { transition: none !important; }

/* ---- Theme Transition Overlay (flash) ---- */
#theme-overlay {
    position: fixed; inset: 0; z-index: 99999;
    background: var(--theme-flash);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}
#theme-overlay.flash { opacity: 1; }

/* ---- Light theme specific body background ---- */
[data-theme="light"] body {
    background-color: #f4f6fb;
    background-image: linear-gradient(135deg, #f4f6fb 0%, #eef1f8 100%);
    background-attachment: fixed;
}
[data-theme="light"] .hero-bg-orbs .orb { opacity: 0.08; }

/* ---- Theme Toggle enhanced ---- */
.theme-toggle-pill {
    display: flex; align-items: center; gap: 0;
    background: var(--bg-glass); border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    overflow: hidden; cursor: pointer;
    transition: all 0.2s ease;
}
.theme-toggle-pill .tpill-opt {
    display: flex; align-items: center; gap: 5px;
    padding: 5px 11px; font-size: 11px; font-weight: 700;
    color: var(--text-muted); cursor: pointer;
    transition: all 0.2s ease; border-radius: var(--radius-full);
    margin: 2px;
}
.theme-toggle-pill .tpill-opt.active {
    background: var(--gradient-primary);
    color: #fff; box-shadow: 0 2px 8px rgba(108,99,255,0.3);
}
[data-theme="light"] .theme-toggle-pill .tpill-opt.active {
    background: var(--gradient-primary);
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-secondary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--accent-primary); }

::selection {
    background: rgba(108, 99, 255, 0.3);
    color: #fff;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ---- Utility ---- */
.hidden { display: none !important; }
.gradient-text {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ---- Pages ---- */
.page { display: none; min-height: 100vh; background: var(--bg-primary); }
.page.active { display: block; animation: fadeIn 0.4s ease; }

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

/* ---- Loading Screen ---- */
.loading-screen {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--bg-primary);
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.6s ease;
}
.loading-screen.fade-out { opacity: 0; pointer-events: none; }

.loader-container { text-align: center; }
.loader-text {
    margin-top: 24px; font-size: 14px; font-weight: 500;
    letter-spacing: 3px; text-transform: uppercase;
    color: var(--text-secondary);
    animation: pulse 2s ease-in-out infinite;
}

.dna-loader {
    width: 60px; height: 60px; position: relative; margin: 0 auto;
}
.dna-strand {
    position: absolute; width: 100%; height: 100%;
    border: 3px solid transparent; border-radius: 50%;
}
.dna-strand:nth-child(1) {
    border-top-color: var(--accent-primary);
    animation: spin 1.2s linear infinite;
}
.dna-strand:nth-child(2) {
    border-bottom-color: var(--accent-secondary);
    animation: spin 1.2s linear infinite reverse;
}

@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px;
    border: none; border-radius: var(--radius-md);
    font-family: var(--font-sans); font-size: 14px; font-weight: 600;
    cursor: pointer; transition: all var(--transition-normal);
    position: relative; overflow: hidden;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
    background: #534AB7; color: #fff;
    box-shadow: 0 4px 12px rgba(83, 74, 183, 0.25);
}
.btn-primary:hover { 
    background: #3C3489;
    box-shadow: 0 6px 20px rgba(83, 74, 183, 0.35); 
    transform: translateY(-1px); 
}

.btn-ghost {
    background: transparent; color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-ghost:hover { color: var(--text-primary); border-color: rgba(255,255,255,0.2); background: var(--bg-glass); }

.btn-glass {
    background: var(--bg-glass); color: var(--text-primary);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
}
.btn-glass:hover { background: var(--bg-glass-hover); border-color: rgba(255,255,255,0.15); }

.btn-accent {
    background: linear-gradient(135deg, #4ADE80, #00D2FF); color: #0a0e1a;
    box-shadow: 0 4px 15px rgba(0, 210, 255, 0.2);
}
.btn-accent:hover { box-shadow: 0 6px 25px rgba(0, 210, 255, 0.35); transform: translateY(-1px); }

.btn-danger {
    background: linear-gradient(135deg, #FF6B6B, #ee5a24); color: #fff;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.2);
}
.btn-danger:hover { box-shadow: 0 6px 25px rgba(255, 107, 107, 0.35); transform: translateY(-1px); }

.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-lg { padding: 14px 28px; font-size: 16px; border-radius: var(--radius-lg); }
.btn-full { width: 100%; justify-content: center; }

.btn-spinner {
    width: 16px; height: 16px;
    border: 2px solid transparent; border-top-color: currentColor;
    border-radius: 50%; animation: spin 0.6s linear infinite;
}

/* ---- Glass Card ---- */
.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 32px;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg);
}

/* ---- Forms ---- */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 600;
    color: var(--text-secondary); margin-bottom: 6px;
    letter-spacing: 0.3px;
}

.input-wrapper {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0 14px;
    transition: all var(--transition-fast);
}
[data-theme="light"] .input-wrapper {
    background: rgba(0,0,0,0.02);
}
.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}
.input-wrapper svg { color: var(--text-muted); flex-shrink: 0; }
.input-wrapper input {
    flex: 1; padding: 12px 0;
    background: transparent; border: none; outline: none;
    color: var(--text-primary); font-family: var(--font-sans); font-size: 14px;
}
.input-wrapper input::placeholder { color: var(--text-muted); }

.select-wrapper {
    position: relative;
}
.select-wrapper select {
    width: 100%; padding: 12px 14px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary); font-family: var(--font-sans); font-size: 14px;
    outline: none; cursor: pointer; appearance: none;
    transition: all var(--transition-fast);
}
[data-theme="light"] .select-wrapper select {
    background: rgba(0,0,0,0.02);
}
.select-wrapper select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}
.select-wrapper select option { background: var(--bg-secondary); }

textarea {
    width: 100%; padding: 12px 14px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary); font-family: var(--font-sans); font-size: 14px;
    outline: none; resize: vertical; min-height: 60px;
    transition: border-color var(--transition-fast);
}
[data-theme="light"] textarea {
    background: rgba(0,0,0,0.02);
}
textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}
textarea::placeholder { color: var(--text-muted); }

.form-error {
    margin-top: 8px; padding: 10px 14px;
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.3);
    border-radius: var(--radius-sm);
    color: var(--accent-danger); font-size: 13px;
}

/* ---- Orbs (background decoration) ---- */
.hero-bg-orbs { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.orb {
    position: absolute; border-radius: 50%;
    filter: blur(80px); opacity: 0.3;
}
[data-theme="light"] .orb { opacity: 0.15; }
.orb-1 {
    width: 500px; height: 500px; top: -200px; right: -100px;
    background: var(--accent-primary);
    animation: floatOrb 15s ease-in-out infinite;
}
.orb-2 {
    width: 400px; height: 400px; bottom: -100px; left: -100px;
    background: var(--accent-secondary);
    animation: floatOrb 20s ease-in-out infinite reverse;
}
.orb-3 {
    width: 300px; height: 300px; top: 40%; left: 50%;
    background: var(--accent-danger);
    animation: floatOrb 25s ease-in-out infinite;
    opacity: 0.15;
}

@keyframes floatOrb {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -30px) scale(1.05); }
    66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* ---- Pulse Loader ---- */
.pulse-loader {
    width: 40px; height: 40px; margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--gradient-primary);
    animation: pulseScale 1.5s ease-in-out infinite;
}
@keyframes pulseScale {
    0%, 100% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 1; }
}

/* ---- Theme Toggle Button ---- */
.theme-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 38px; height: 38px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    cursor: pointer; color: var(--text-secondary);
    font-size: 18px;
    transition: all var(--transition-normal);
}
.theme-toggle:hover {
    color: var(--accent-warning);
    border-color: rgba(255, 217, 61, 0.3);
    background: rgba(255, 217, 61, 0.08);
    transform: rotate(15deg);
}

/* ---- Toast Notifications ---- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 320px;
    max-width: 420px;
    padding: 14px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
    pointer-events: auto;
    animation: toastSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.toast.toast-removing {
    animation: toastSlideOut 0.35s cubic-bezier(0.4, 0, 1, 1) forwards;
}

.toast-icon {
    width: 22px; height: 22px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 700;
    margin-top: 1px;
}

.toast-body {
    flex: 1;
}
.toast-title {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 2px;
}
.toast-message {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.toast-close {
    background: none; border: none;
    color: var(--text-muted); cursor: pointer;
    font-size: 18px; padding: 0; line-height: 1;
    flex-shrink: 0;
    transition: color var(--transition-fast);
}
.toast-close:hover { color: var(--text-primary); }

.toast-progress {
    position: absolute;
    bottom: 0; left: 0;
    height: 3px;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    animation: toastProgress linear forwards;
}

/* Toast variants */
.toast-success { border-left: 4px solid var(--accent-success); }
.toast-success .toast-icon { background: rgba(74, 222, 128, 0.15); color: var(--accent-success); }
.toast-success .toast-title { color: var(--accent-success); }
.toast-success .toast-progress { background: var(--accent-success); }

.toast-error { border-left: 4px solid var(--accent-danger); }
.toast-error .toast-icon { background: rgba(255, 107, 107, 0.15); color: var(--accent-danger); }
.toast-error .toast-title { color: var(--accent-danger); }
.toast-error .toast-progress { background: var(--accent-danger); }

.toast-warning { border-left: 4px solid var(--accent-warning); }
.toast-warning .toast-icon { background: rgba(255, 217, 61, 0.15); color: var(--accent-warning); }
.toast-warning .toast-title { color: var(--accent-warning); }
.toast-warning .toast-progress { background: var(--accent-warning); }

.toast-info { border-left: 4px solid var(--accent-secondary); }
.toast-info .toast-icon { background: rgba(0, 210, 255, 0.15); color: var(--accent-secondary); }
.toast-info .toast-title { color: var(--accent-secondary); }
.toast-info .toast-progress { background: var(--accent-secondary); }

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastSlideOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100%); }
}

@keyframes toastProgress {
    from { width: 100%; }
    to { width: 0%; }
}

/* ---- Confirm Dialog / Modal ---- */
.modal-overlay {
    position: fixed; inset: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(4px);
    z-index: 9000;
    display: flex; align-items: center; justify-content: center;
    animation: modalFadeIn 0.25s ease;
}
.modal-overlay.modal-removing {
    animation: modalFadeOut 0.2s ease forwards;
}

.modal-dialog {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 32px;
    width: 100%;
    max-width: 400px;
    margin: 0 16px;
    box-shadow: var(--shadow-lg);
    animation: modalScaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-overlay.modal-removing .modal-dialog {
    animation: modalScaleOut 0.2s ease forwards;
}

.modal-icon {
    width: 56px; height: 56px;
    margin: 0 auto 20px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-size: 24px;
}
.modal-icon.modal-icon-warning {
    background: rgba(255, 217, 61, 0.12);
    color: var(--accent-warning);
}
.modal-icon.modal-icon-danger {
    background: rgba(255, 107, 107, 0.12);
    color: var(--accent-danger);
}

.modal-title {
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
}

.modal-message {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 28px;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    gap: 12px;
}
.modal-actions .btn {
    flex: 1;
    justify-content: center;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes modalFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}
@keyframes modalScaleIn {
    from { opacity: 0; transform: scale(0.9) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes modalScaleOut {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.9); }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    :root { font-size: 14px; }
    .glass-card { padding: 24px; }
    .hero-title { font-size: 2rem !important; }
    .features-grid { grid-template-columns: 1fr !important; }
    .case-layout { flex-direction: column !important; }
    .nav-actions { gap: 8px; }
    .hero-stats { flex-direction: column; gap: 16px !important; }

    #toast-container {
        top: 10px; right: 10px; left: 10px;
    }
    .toast { min-width: auto; max-width: 100%; }
}
