/* ============================================================
   CLINICAL DASHBOARD - MASTER STYLESHEET
   Version: 4.0 (The "Final Fix" Edition)
   ============================================================ */

/* --- GOOGLE FONTS --- */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@600;800&family=Lexend:wght@300;400;500;600;700&display=swap');

:root {
    /* --- OFFICIAL IMAGE PALETTE --- */
    --bg-main: #F4F4F4;
    /* Light Grey Background */
    --panel-bg: #ffffff;
    /* Pure White Panels */
    --header-deep: #005461;
    /* Deepest Teal */
    --accent-primary: #018790;
    /* Professional Teal */
    --accent-bright: #00B7B5;
    /* Interaction Teal */

    /* Text & UI Colors */
    --text-main: #002d34;
    /* High-contrast dark teal */
    --text-dim: #547176;
    /* Soft slate teal */
    --border-soft: #e2e8f0;
    /* Subtle borders */

    /* Functional Colors */
    --success: #10b981;
    /* The Green you wanted */
    --warning: #f59e0b;
    --danger: #ef4444;

    /* --- ALIASES & MISSING VARS (used in components/JS) --- */
    --accent-teal: #018790;       /* alias for accent-primary — used in labels */
    --accent-blue: #0ea5e9;       /* used in login modal, doctor badge, ID badge */
    --accent-gold: #f59e0b;       /* used in mandatory field markers (*) */
    --border-color: #e2e8f0;      /* alias for border-soft — used in encounter cards */
    --bg-card: #ffffff;           /* used in login modal content background */
    --text-bright: #002d34;       /* used in profile card body — high contrast */
}

/* --- BASE STYLES --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: 'Lexend', sans-serif;
    margin: 0;
    padding: 40px 20px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.dashboard {
    width: 100%;
    max-width: 1350px;
    margin: 0 auto;
    animation: fadeIn 0.6s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- HEADER SECTION --- */
header {
    text-align: center;
    margin-bottom: 50px;
    animation: slideDown 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

header h1 {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 2.6rem;
    letter-spacing: -1.5px;
    color: var(--header-deep);
    text-transform: none;
    margin-bottom: 2px;
}

header h1 span {
    color: var(--accent-primary);
}

/* --- GRID SYSTEM --- */
.split-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    align-items: start;
}

/* --- PANEL STYLING --- */
.panel {
    background: var(--panel-bg);
    border-radius: 24px;
    padding: 35px;
    box-shadow: 0 12px 40px -15px rgba(0, 84, 97, 0.1);
    border: 1px solid rgba(0, 183, 181, 0.08);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.panel:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 45px -10px rgba(0, 84, 97, 0.15);
}

/* FIXED: Brought the icon and text closer together */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    /* Changed from space-between */
    gap: 15px;
    /* Tightened the gap */
    margin-bottom: 30px;
}

.panel-header h3 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--accent-primary);
    position: relative;
    display: inline-block;
}

/* Add a subtle sweep animation under headers on load */
.panel-header h3::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 3px;
    background: var(--accent-bright);
    animation: sweepLine 1s ease-out 0.5s forwards;
}

@keyframes sweepLine {
    to {
        width: 100%;
    }
}

/* --- FORM & INPUTS --- */
input[type="text"],
textarea {
    width: 100%;
    background: #fdfdfd;
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    padding: 18px;
    color: var(--text-main);
    font-family: 'Lexend', sans-serif;
    font-size: 1rem;
    transition: all 0.25s ease;
    margin-bottom: 15px;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-bright);
    box-shadow: 0 0 0 5px rgba(0, 183, 181, 0.15), 0 8px 15px -5px rgba(0, 183, 181, 0.1);
    transform: translateY(-2px);
    /* Makes input pop out slightly when typing */
    background: #ffffff;
}

label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--accent-bright);
    margin-bottom: 10px;
}

/* Special Case: Active Patient Box */
#displayNameBox {
    background: rgba(0, 183, 181, 0.04) !important;
    border: 1.5px solid rgba(0, 183, 181, 0.15) !important;
    color: var(--header-deep) !important;
    font-weight: 600;
}

/* --- BUTTONS --- */
button {
    width: 100%;
    padding: 18px;
    border-radius: 14px;
    border: none;
    font-weight: 600;
    font-family: 'Lexend', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: white;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
    filter: brightness(1.05);
}

button:active {
    transform: translateY(1px);
}

/* FIXED: Load Medical History Button is now TEAL */
#loadHistoryBtn,
.btn-lookup {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-bright)) !important;
    box-shadow: 0 4px 15px rgba(1, 135, 144, 0.2);
}

/* FIXED: Save Manual Changes Button is now GREEN */
#manualSaveBtn {
    background: var(--success) !important;
    color: white !important;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-bright));
}

.btn-secondary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-bright)) !important;
    color: white !important;
    border: none !important;
    box-shadow: 0 4px 15px rgba(1, 135, 144, 0.2);
}

.btn-voice {
    width: auto;
    background: #fff5f5;
    color: #c53030;
    border: 1px solid #feb2b2;
    padding: 10px 22px;
    font-size: 0.85rem;
    margin-bottom: 15px;
}

/* FIXED: Save Changes Button is now GREEN */
#saveBtn,
.btn-save {
    background: var(--success) !important;
    color: white !important;
    margin-top: 15px;
    min-height: 55px;
    /* Ensures it's big enough to show text */
    display: flex !important;
    visibility: visible !important;
}

/* --- DISPLAY BOXES --- */
.history-display,
.ai-box {
    background: #ffffff;
    border-radius: 18px;
    padding: 30px 35px;
    min-height: 400px;
    max-height: 600px;
    overflow-y: auto;
    border: 1px solid var(--border-soft);
    line-height: 1.9;
    font-size: 0.97rem;
    color: var(--text-main);
}

/* Styled bold labels */
.history-display strong,
.history-display b,
#aiAdviceBox strong {
    color: var(--header-deep) !important;
    font-weight: 700 !important;
    text-shadow: none !important;
    background: #d4edda !important;
    padding: 2px 8px !important;
    border-radius: 5px !important;
    text-transform: uppercase;
    font-size: 0.82rem;
    display: inline !important;
    letter-spacing: 0.4px;
}

/* Forced paragraph spacing */
.history-display p,
#aiAdviceBox p {
    margin-bottom: 1.2rem !important;
}

/* --- MARKDOWN STYLING FOR AI RESPONSES --- */
.history-display ul,
.history-display ol,
#aiAdviceBox ul,
#aiAdviceBox ol {
    margin-left: 20px;
    margin-bottom: 1.5rem;
    padding-left: 10px;
}

.history-display li,
#aiAdviceBox li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.history-display h1, .history-display h2, .history-display h4, .history-display h5,
#aiAdviceBox h1, #aiAdviceBox h2, #aiAdviceBox h4, #aiAdviceBox h5 {
    color: var(--text-main);
    margin-top: 1.5rem;
    margin-bottom: 0.8rem;
    font-weight: 600;
}

.history-display blockquote,
#aiAdviceBox blockquote {
    border-left: 4px solid var(--accent-bright);
    padding-left: 15px;
    color: var(--text-dim);
    margin-bottom: 1.5rem;
    background: rgba(0, 183, 181, 0.03);
    padding: 10px 15px;
    border-radius: 0 8px 8px 0;
}

/* Visit / Section Banner Headers */
/* Visit / Section Banner Headers */
.history-display h3,
#aiAdviceBox h3 {
    color: var(--accent-primary) !important;
    background: rgba(1, 135, 144, 0.06) !important;
    padding: 14px 20px !important;
    border-left: 5px solid var(--accent-bright) !important;
    border-radius: 4px 12px 12px 4px;
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 30px !important;
    margin-bottom: 16px !important;
    letter-spacing: 0.2px;
}

/* Historical Encounter Card Display */
#historyBox .encounter-card {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
    background: #f8fafb;
}
#historyBox .encounter-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--accent-teal);
    border-bottom: 1px solid var(--border-soft);
    padding-bottom: 8px;
    margin-bottom: 12px;
}
/* Grid of section-cards within an encounter */
.enc-sections-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.enc-section-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}
.enc-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--accent-teal);
    margin-bottom: 5px;
}
.enc-section-body {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-main);
}
#historyBox p {
    line-height: 1.6;
    margin-bottom: 8px !important;
}
body.dark-mode #historyBox .encounter-card {
    background: #1a2332;
    border-color: #3a4558;
}
body.dark-mode .enc-section-card {
    background: #1e293b;
    border-color: #475569;
}

/* --- LOADER --- */
.loader {
    width: 45px;
    height: 45px;
    border: 4px solid rgba(0, 183, 181, 0.1);
    border-top-color: var(--accent-bright);
    border-radius: 50%;
    animation: spin 1s infinite cubic-bezier(0.55, 0.15, 0.45, 0.85), pulseLight 2s infinite ease-in-out;
    margin: 50px auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulseLight {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 183, 181, 0.4);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(0, 183, 181, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 183, 181, 0);
    }
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 20px;
}

#historyBox {
    display: block !important;
}

/* --- QUICK CLINICAL QUERIES --- */
.quick-queries-section {
    margin-bottom: 20px;
}

.quick-queries-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--accent-bright);
    text-transform: uppercase;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.quick-queries-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-soft);
}

.quick-queries-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.qq-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: #f1f5f9;
    border: 1px solid var(--border-soft);
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s ease;
    width: auto;
    white-space: nowrap;
}

.qq-chip:hover {
    background: rgba(0, 183, 181, 0.08);
    border-color: var(--accent-bright);
    color: var(--accent-primary);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 183, 181, 0.12);
    filter: none;
}

.qq-chip:active {
    transform: translateY(0);
}

/* =========================================
   NEW UI ENHANCEMENTS (Dark Mode & Status)
   ========================================= */

/* --- VITALS DASHBOARD --- */
.vitals-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.vital-input-group {
    display: flex;
    align-items: center;
    background: #f8fafb;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    padding: 6px 10px;
    flex: 1 1 20%;
}

.vital-input-group .vital-icon {
    font-size: 1rem;
    margin-right: 6px;
}

.vital-input-group input {
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    font-size: 0.82rem !important;
    font-weight: 600 !important;
    color: var(--text-main) !important;
    width: 100% !important;
    min-width: 40px;
}

.vital-input-group input:focus {
    box-shadow: none !important;
    outline: none !important;
}

/* Theme Toggle Button */
.theme-toggle {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15); /* Adds a highlighted look */
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    font-size: 1.2rem;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); /* Soft shadow */
    backdrop-filter: blur(4px); /* Glassmorphism effect */
}
.theme-toggle:hover {
    transform: translateY(-50%) rotate(15deg) scale(1.1);
    background: rgba(255, 255, 255, 0.3); /* Brighter on hover */
    border-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

/* Status Badges */
.status-badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.status-badge.urgent {
    background: rgba(239, 68, 68, 0.15);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.status-badge.stable {
    background: rgba(16, 185, 129, 0.15);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.status-badge.review {
    background: rgba(245, 158, 11, 0.15);
    color: #d97706;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* --- STRUCTURED CLINICAL NOTES --- */
.structured-notes {
    display: flex;
    flex-direction: column;
    gap: 8px; /* Tighter gap */
    margin-bottom: 20px;
}
.note-section {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px; /* Sharper radius */
    padding: 10px 12px;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03); /* Subtle depth */
}
.note-section:focus-within {
    border-color: var(--accent-primary);
    background: #fff;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15); /* Sleek focus ring */
}
.note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.note-header label {
    margin-bottom: 0;
    font-size: 0.65rem; /* Ultra sleek, smaller label */
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
    color: var(--accent-teal);
}
.mini-mic {
    background: #f1f5f9;
    border: 1px solid var(--border-soft);
    color: var(--accent-blue);
    font-size: 0.70rem;
    font-weight: 700;
    cursor: pointer;
    padding: 3px 8px;
    border-radius: 4px; /* Flatter button */
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}
.mini-mic:hover {
    background: var(--accent-bright);
    color: white;
    border-color: var(--accent-bright);
}
.note-input, .note-area {
    width: 100%;
    border: none !important;
    background: transparent !important;
    padding: 4px 2px !important; /* Top and side padding to completely prevent all edge clipping */
    font-size: 0.85rem !important; /* Smaller text size */
    line-height: 1.5;
    color: var(--text-main) !important;
    resize: vertical;
}

/* Vitals Grid Specific */
.vitals-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.vital-input-group {
    display: flex;
    align-items: center;
    background: #f1f5f9;
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    padding: 4px 8px;
    flex: 1 1 20%;
}
.vital-input-group .vital-icon {
    font-size: 0.85rem;
    margin-right: 4px;
}
.vital-input-group input {
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    font-size: 0.8rem !important;
    color: var(--text-main) !important;
    width: 100% !important;
    min-width: 40px;
}
.vital-input-group input:focus {
    box-shadow: none !important;
    outline: none !important;
}
.note-input:focus, .note-area:focus {
    box-shadow: none !important;
    outline: none !important;
}

/* --- DARK MODE PREFERENCES --- */
body.dark-mode {
    --bg-main: #0f172a;
    --panel-bg: #1e293b;
    --header-deep: #38bdf8;
    --accent-primary: #0ea5e9;
    --accent-bright: #0284c7;
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --border-soft: #334155;

    /* Dark mode overrides for alias variables */
    --text-bright: #f1f5f9;       /* was near-black, now light for dark bg */
    --border-color: #334155;      /* match border-soft in dark mode */
    --bg-card: #1e293b;           /* dark card background */
    --accent-teal: #2dd4bf;       /* brighter teal for dark mode labels */
}

body.dark-mode input[type="text"],
body.dark-mode textarea {
    background: rgba(0,0,0,0.2);
    color: var(--text-main);
    border: 1px solid var(--border-soft);
}

body.dark-mode input[type="text"]::placeholder,
body.dark-mode textarea::placeholder {
    color: #64748b;
}

body.dark-mode .history-display,
body.dark-mode .ai-box {
    background: #0f172a;
    border-color: var(--border-soft);
}

body.dark-mode .quick-query-btn,
body.dark-mode .qq-chip {
    background: #334155;
    border-color: #475569;
}

body.dark-mode .qq-icon {
    background: #1e293b;
}

body.dark-mode #displayNameBox {
    background: rgba(14, 165, 233, 0.1) !important;
    border: 1px solid rgba(14, 165, 233, 0.3) !important;
    color: var(--accent-primary) !important;
}

body.dark-mode .history-display strong,
body.dark-mode .history-display b,
body.dark-mode #aiAdviceBox strong {
    background: rgba(16, 185, 129, 0.15) !important;
    color: #34d399 !important;
}

body.dark-mode .history-display blockquote,
body.dark-mode #aiAdviceBox blockquote {
    background: rgba(14, 165, 233, 0.05);
    border-left: 4px solid var(--accent-primary);
}

body.dark-mode .vital-input-group {
    background: #1e293b;
    border-color: #475569;
}

body.dark-mode .note-section {
    background: #1e293b;
    border-color: #475569;
}
body.dark-mode .note-section:focus-within {
    background: #0f172a;
}
body.dark-mode .vital-input-group {
    background: #0f172a;
    border-color: #475569;
}

body.dark-mode .theme-toggle:hover {
    background: rgba(255,255,255,0.1);
}

/* ===== REGISTRATION MODAL FIELDS ===== */
.reg-field {
    display: flex;
    flex-direction: column;
}
.reg-field label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--accent-teal);
    margin-bottom: 5px;
}
.reg-field input,
.reg-field select,
.reg-area {
    border: 1px solid var(--border-color);
    border-radius: 7px;
    padding: 8px 10px;
    font-size: 0.85rem;
    color: var(--text-main);
    background: #fff;
    width: 100%;
    font-family: inherit;
    resize: vertical;
    transition: border 0.2s;
}
.reg-field input:focus,
.reg-field select:focus,
.reg-area:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15);
}
body.dark-mode #regModal > div {
    background: #1e293b;
}
body.dark-mode .reg-field input,
body.dark-mode .reg-field select,
body.dark-mode .reg-area {
    background: #0f172a;
    border-color: #475569;
    color: #e2e8f0;
}

/* ===== PATIENT ID BADGE ===== */
.patient-id-badge {
    display: inline-block;
    margin-top: 10px;
    padding: 4px 14px;
    background: rgba(45, 212, 191, 0.1);
    border: 1px solid rgba(45, 212, 191, 0.3);
    border-radius: 99px; /* Pill shape */
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 13px;
    font-weight: 600;
    color: #2dd4bf;
    letter-spacing: 0.02em;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    transition: all 0.2s ease;
}

body.dark-mode .patient-id-badge {
    background: rgba(45, 212, 191, 0.15);
    border-color: rgba(45, 212, 191, 0.4);
    color: #5eead4;
}

.patient-id-badge::before {
    content: "ID";
    font-size: 11px;
    opacity: 0.8;
    margin-right: 10px;
    padding-right: 10px;
    border-right: 1px solid currentColor;
    font-weight: 700;
}

/* ===== DOCTOR IDENTITY BADGE ===== */
.doctor-badge {
    position: absolute;
    top: 50%;
    right: 80px;
    transform: translateY(-50%);
    background: rgba(var(--bg-card-rgb), 0.5);
    backdrop-filter: blur(4px);
    border: 1px solid var(--border-color);
    padding: 6px 14px;
    border-radius: 99px;
    font-size: 0.75rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 10;
}

.doctor-badge strong {
    color: var(--accent-blue);
    font-weight: 600;
}

.doctor-badge .status-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

body.dark-mode .doctor-badge {
    background: rgba(30, 41, 59, 0.7);
    border-color: rgba(255, 255, 255, 0.1);
}

/* ===== SOURCE ATTRIBUTION TAGS ===== */
.source-tag {
    display: inline-block;
    font-size: 10px;
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 12px;
    font-weight: 500;
    vertical-align: middle;
    border: 1px solid rgba(59, 130, 246, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

body.dark-mode .source-tag {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
}

/* ===== LOGIN MODAL ENHANCEMENTS ===== */
#loginModal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#loginModal .modal-content {
    background: var(--bg-card);
}

body.dark-mode #loginModal .modal-content {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

@keyframes fadeIn {
    from { opacity: 0; backdrop-filter: blur(0px); }
    to { opacity: 1; backdrop-filter: blur(15px); }
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

#loginDocId, #loginClinicName {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(0,0,0,0.05);
    color: var(--text-main);
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

#loginDocId:focus, #loginClinicName:focus {
    border-color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.05);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* --- MULTI-MATCH SELECTION UI --- */
.selection-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: none; /* Initially hidden */
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.selection-content {
    background: var(--panel-bg);
    width: 100%;
    max-width: 500px;
    border-radius: 24px;
    padding: 30px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-soft);
    animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalPop {
    from { transform: scale(0.9) translateY(20px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.selection-header {
    text-align: center;
    margin-bottom: 25px;
}

.selection-header h2 {
    color: var(--header-deep);
    font-size: 1.4rem;
    margin-bottom: 8px;
}

.selection-header p {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.selection-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 5px;
}

.selection-item {
    background: #f8fafc;
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.selection-item:hover {
    border-color: var(--accent-bright);
    background: rgba(0, 183, 181, 0.05);
    transform: translateX(5px);
}

.selection-item .patient-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.selection-item .patient-name {
    font-weight: 600;
    color: var(--accent-primary);
    font-size: 1.05rem;
    text-transform: capitalize;
}

.selection-item .patient-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-weight: 500;
}

.selection-item .select-arrow {
    font-size: 1.2rem;
    color: var(--accent-bright);
    opacity: 0.5;
}

.selection-item:hover .select-arrow {
    opacity: 1;
    transform: translateX(3px);
}

body.dark-mode .selection-item {
    background: #1e293b;
    border-color: #475569;
}

body.dark-mode .selection-item:hover {
    background: rgba(14, 165, 233, 0.1);
}

/* ===== CLINICAL DASHBOARD STAT CARDS ===== */
.dash-stat-card {
    background: var(--panel-bg);
    border: 1px solid rgba(45, 212, 191, 0.15);
    border-radius: 16px;
    padding: 25px 20px;
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    overflow: hidden;
}

.dash-stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-bright));
    border-radius: 16px 16px 0 0;
}

.dash-stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(45, 212, 191, 0.1);
}

.dash-stat-icon {
    font-size: 2rem;
    margin-bottom: 12px;
}

.dash-stat-value {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--accent-bright);
    letter-spacing: -1px;
    margin-bottom: 6px;
    font-family: 'Outfit', sans-serif;
}

.dash-stat-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
}

body.dark-mode .dash-stat-card {
    background: #1a2332;
    border-color: rgba(45, 212, 191, 0.1);
}

/* --- AUTOCOMPLETE DROPDOWN --- */
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--panel-bg);
    border: 1px solid var(--border-soft);
    border-top: none;
    border-radius: 0 0 14px 14px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
    z-index: 999;
    max-height: 280px;
    overflow-y: auto;
    animation: dropdownSlide 0.2s ease;
}
@keyframes dropdownSlide {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}
.autocomplete-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover {
    background: rgba(0, 183, 181, 0.06);
}
.autocomplete-item .ac-name {
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text-main);
}
.autocomplete-item .ac-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 2px;
}
.autocomplete-item .ac-id {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--accent-bright);
    white-space: nowrap;
}
.autocomplete-loading {
    padding: 14px 18px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-dim);
}
body.dark-mode .autocomplete-dropdown {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
}
body.dark-mode .autocomplete-item:hover {
    background: rgba(14, 165, 233, 0.08);
}