:root {
    /* === Colors === */
    --primary-color: #1a365d;
    --primary-hover: #2a4365;
    --primary-light: #e2e8f0;
    
    --accent-color: #3182ce;
    --success-color: #38a169;
    --warning-color: #dd6b20;
    --danger-color: #e53e3e;
    
    --text-main: #1a202c;
    --text-body: #4a5568;
    --text-muted: #718096;
    
    --bg-body: #ebf8ff;
    --bg-surface: #ffffff;
    --bg-subtle: #f7fafc;
    
    --border-color: #e2e8f0;
    
    /* === Shadows === */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    /* === Sizing === */
    --radius-md: 8px;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;
    
    /* === Transitions === */
    --transition-fast: all 0.15s ease-out;
    --transition-base: all 0.2s ease-in-out;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-body);
    line-height: 1.5;
    font-size: 15px; 
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.clinical-content {
    font-family: 'Source Serif 4', serif;
}

h1, h2, h3, h4 {
    color: var(--text-main);
    font-weight: 700;
    line-height: 1.2;
}

h2 { font-size: 1.5rem; margin-bottom: 1.5rem; letter-spacing: -0.02em; }

/* === Layout Structure === */
.layout {
    display: flex;
    min-height: 100vh;
}

.layout--no-sidebar .content {
    padding: 0;
}

.content {
    flex: 1;
    padding: 3.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.container-wide { width: 100%; max-width: 1400px; margin: 0 auto; }
.container-tight { width: 100%; max-width: 800px; margin: 0 auto; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    height: 100vh;
    position: sticky;
    top: 0;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-x: hidden;
    z-index: 1000;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    padding: 2rem 0.75rem;
}

.sidebar-toggle {
    position: absolute;
    top: 1.5rem;
    right: -12px;
    width: 24px;
    height: 24px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    z-index: 1001;
    transition: var(--transition-fast);
    color: var(--text-muted);
}

.sidebar-toggle:hover {
    color: var(--primary-color);
    background: var(--bg-subtle);
}

.sidebar.collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

.sidebar .logo {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--primary-color);
    margin-bottom: 2.5rem;
    padding: 0 1rem;
    letter-spacing: -0.04em;
    white-space: nowrap;
    display: flex;
    align-items: center;
}

.sidebar.collapsed .logo span {
    display: none;
}

.sidebar h2 {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-muted);
    margin: 1.5rem 1rem 0.75rem;
    white-space: nowrap;
}

.sidebar.collapsed h2 {
    display: none;
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar a {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--text-body);
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition-fast);
    margin-bottom: 4px;
    text-decoration: none;
    white-space: nowrap;
    background-color: transparent;
}

.sidebar.collapsed a {
    padding: 0.75rem;
    justify-content: center;
}

.sidebar.collapsed a span {
    display: none;
}

.sidebar a:hover {
    background-color: var(--bg-subtle);
    color: var(--primary-color);
}

.sidebar a.active {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.sidebar a i { 
    margin-right: 0.75rem; 
    font-size: 1.25rem; 
    flex-shrink: 0;
}

.sidebar.collapsed a i {
    margin-right: 0;
}

/* === Clinical Components === */
.card-clinical {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.card-clinical:hover {
    border-color: #cbd5e1;
    box-shadow: var(--shadow-md);
}

.card-clinical h3 {
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-clinical--primary { background: var(--primary-color); color: white; border: none; }
.card-clinical--primary h3 { color: rgba(255,255,255,0.7); }
.card-clinical--subtle { background: var(--bg-subtle); border: none; box-shadow: none; }
.card-clinical--warning { border-left: 4px solid var(--warning-color); background: #fffcf5; }
.card-clinical--accent { border-left: 4px solid var(--accent-color); background: #f8fbff; }

.header-clinical { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 3rem; }
.header-clinical h1 { font-size: 2.5rem; margin-bottom: 0.5rem; }
.header-clinical p { font-size: 1.1rem; color: var(--text-muted); }

/* === Dashboard Statistics === */
.stat-icon-bg {
    width: 48px;
    height: 48px;
    background: var(--bg-subtle);
    color: var(--primary-color);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1.25rem;
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
    margin-bottom: 0.5rem;
    font-family: 'Inter', sans-serif;
    letter-spacing: -0.02em;
}

.stat-trend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.text-success { color: var(--success-color); }

/* === Badges === */
.badge-clinical {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    color: var(--text-body);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge-clinical.primary { background: #eef2ff; border-color: #e0e7ff; color: #4338ca; }
.badge-clinical.success { background: #ecfdf5; border-color: #d1fae5; color: #059669; }
.badge-clinical.warning { background: #fffbeb; border-color: #fef3c7; color: #d97706; }

/* === Modals (Dialog) === */
dialog {
    border: none;
    border-radius: 12px;
    padding: 2rem;
    background: var(--bg-surface);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    margin: auto;
}

dialog::backdrop {
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
}

dialog .close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

dialog .close-btn:hover {
    color: var(--text-main);
}

/* === Documents & Previews === */
.doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.doc-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    transition: var(--transition-base);
    display: flex;
    flex-direction: column;
}

.doc-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-color);
}

.doc-preview-thumb {
    height: 140px;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: var(--text-muted);
    overflow: hidden;
    position: relative;
    cursor: pointer;
}

.doc-preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.doc-info {
    padding: 1rem;
    flex: 1;
}

.doc-name {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.doc-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.doc-actions {
    padding: 0.5rem 1rem;
    background: #f8fafc;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Document Preview Modal */
#doc-preview-modal {
    max-width: 90vw;
    width: 1000px;
    height: 80vh;
    padding: 0;
    overflow: hidden;
}

#doc-preview-modal .preview-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
}

#doc-preview-modal .preview-body {
    height: calc(80vh - 60px);
    background: #525659;
    display: flex;
    align-items: center;
    justify-content: center;
}

#doc-preview-modal iframe, #doc-preview-modal img {
    width: 100%;
    height: 100%;
    border: none;
    object-fit: contain;
}

/* === Tables === */
.card-clinical table {
    width: 100%;
}

.table-clean { 
    width: 100%;
    border-collapse: separate; 
    border-spacing: 0; 
}

.table-clean thead th {
    text-align: left;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: #f8fafc;
}

.table-clean tbody td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

/* For score alignment - tabular numbers */
.tabular-nums {
    font-variant-numeric: tabular-nums;
}

/* === Buttons === */
.btn, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 4px; 
    cursor: pointer;
    transition: var(--transition-fast);
    border: 1px solid transparent;
    text-decoration: none;
}

.btn-primary, button.primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover { background-color: var(--primary-hover); transform: translateY(-1px); }

.btn.secondary, button.secondary {
    background-color: white;
    border-color: var(--border-color);
    color: var(--text-body);
    box-shadow: var(--shadow-sm);
}

.btn.secondary:hover { background-color: var(--bg-subtle); border-color: #cbd5e1; }

.btn-white {
    background-color: white;
    color: var(--primary-color);
}
.btn-white:hover { background-color: var(--bg-subtle); }

.btn-outline-white {
    background-color: transparent;
    border-color: rgba(255,255,255,0.5);
    color: white;
}
.btn-outline-white:hover { border-color: white; background: rgba(255,255,255,0.1); }

/* Ghost button */
.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-body);
}

.btn-ghost:hover {
    background: var(--bg-subtle);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* === Forms === */
input[type="text"], input[type="email"], input[type="password"], input[type="datetime-local"], textarea, select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 0.2s;
    background: white;
}

input:focus, textarea:focus, select:focus { 
    outline: none; 
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(26, 54, 93, 0.1);
}

/* === Utilities === */
.hidden { display: none !important; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.flex-center { display: flex; align-items: center; gap: 1rem; }
.gap-xs { gap: 0.25rem; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.gap-lg { gap: 1.5rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-column { display: flex; flex-direction: column; }
.flex-wrap { display: flex; flex-wrap: wrap; gap: 1rem; }

.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 2rem; } .mt-4 { margin-top: 3rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 2rem; } .mb-4 { margin-bottom: 3rem; }

.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-muted { color: var(--text-muted); }
.font-bold { font-weight: 700; }

/* === Alerts === */
.alert {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border: 1px solid transparent;
}

.alert-warning {
    background-color: #fffbeb;
    border-color: #fef3c7;
    color: #92400e;
}

.alert-warning i {
    color: #d97706;
}

.alert-danger {
    background-color: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

.alert-info {
    background-color: #eff6ff;
    border-color: #dbeafe;
    color: #1e40af;
}

.d-none-mobile {
    display: flex;
}

/* === Mobile Responsiveness === */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
    background: var(--primary-color);
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
}

@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        left: 0;
        z-index: 1000;
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
        transition: transform 0.3s ease !important;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }

    .d-none-mobile {
        display: none !important;
    }
    
    .content {
        padding: 5rem 1.5rem 2rem;
    }
    
    .mobile-toggle {
        display: block;
    }
    
    .header-clinical {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
}

/* === Auth Pages (Centered Box) === */
.auth-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(circle at top left, #ebf8ff 0%, #ffffff 100%);
    padding: 2rem;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: var(--bg-surface);
    padding: 3rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    border-radius: 20px;
}

.auth-back-link {
    position: absolute;
    top: 2rem;
    left: 2rem;
    color: var(--text-muted);
    font-weight: 600;
    text-decoration: none;
    font-size: 0.9rem;
    transition: var(--transition-fast);
}

.auth-back-link:hover {
    color: var(--primary-color);
}

.auth-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.auth-footer {
    text-align: center;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

/* === Public Landing Page Styles === */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
}

.header .logo {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--primary-color);
    letter-spacing: -0.04em;
}

.header nav {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.header nav a {
    text-decoration: none;
    color: var(--text-body);
    font-weight: 600;
    font-size: 0.95rem;
    transition: var(--transition-fast);
}

.header nav a:hover {
    color: var(--primary-color);
}

.footer {
    padding: 4rem 0;
    margin-top: 5rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
    color: var(--text-muted);
}

.footer p {
    margin-bottom: 1rem;
}

.footer a {
    color: var(--text-muted);
    margin: 0 1rem;
    text-decoration: none;
    font-size: 0.85rem;
}

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