:root {
    --bg-main: #f0f2f5;
    --sidebar-bg: #0f172a;
    --sidebar-hover: rgba(255,255,255,0.06);
    --sidebar-active: #2563eb;
    --sidebar-text: #94a3b8;
    --sidebar-active-text: #ffffff;
    --primary: #2563eb;
    --primary-hover: color-mix(in srgb, var(--primary) 85%, black);
    --primary-light: color-mix(in srgb, var(--primary) 10%, white);
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --card-bg: #ffffff;
    --success: #10b981;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --error: #ef4444;
    --error-light: #fee2e2;
    --info: #3b82f6;
    --info-light: #dbeafe;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    line-height: 1.6;
    font-size: 14px;
}

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

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    overflow-y: auto;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.brand {
    padding: 28px 24px 20px;
    font-size: 18px;
    font-weight: 700;
    color: white;
    letter-spacing: -0.3px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-icon {
    width: 32px; height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

nav { padding: 16px 12px; flex: 1; }

.nav-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(148,163,184,0.5);
    padding: 16px 16px 8px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    border-radius: 8px;
    margin-bottom: 2px;
    transition: var(--transition);
    cursor: pointer;
}
.nav-item:hover { background: var(--sidebar-hover); color: white; }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-active-text); }
.nav-item .nav-icon { font-size: 18px; width: 22px; text-align: center; }

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 32px 40px;
    background: var(--bg-main);
    min-height: 100vh;
}
#page-content > * {
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
}
.topbar h2 { font-size: 22px; font-weight: 700; color: var(--text-main); }
.topbar-meta { color: var(--text-muted); font-size: 13px; }

/* ── Topbar Action Buttons ─────────── */
.topbar-action-btn {
    background: var(--primary-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 14px;
    cursor: pointer;
    color: var(--text-main);
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.topbar-action-btn:hover { background: var(--primary); color: white; }
.topbar-kbd {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(0,0,0,0.08);
    color: var(--text-muted);
    font-family: monospace;
    letter-spacing: 0.5px;
}
.topbar-action-btn:hover .topbar-kbd { background: rgba(255,255,255,0.2); color: rgba(255,255,255,0.9); }

/* ─── Mobile Menu Button ─────────────── */
.mobile-menu-btn {
    display: none;
    background: var(--primary-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    font-size: 20px;
    cursor: pointer;
    color: var(--primary);
    transition: var(--transition);
    align-items: center;
    justify-content: center;
}
.mobile-menu-btn:hover { background: var(--primary); color: white; }

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.show { display: block; opacity: 1; }

/* ─── Cards & Panels ────────────────── */
.panel {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
}
.panel-header h3 { font-size: 16px; font-weight: 600; }

/* ─── Stats Grid ─────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}
.stat-card {
    background: white;
    padding: 22px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 4px; height: 100%;
}
.stat-card:nth-child(1)::before { background: var(--primary); }
.stat-card:nth-child(2)::before { background: var(--success); }
.stat-card:nth-child(3)::before { background: var(--warning); }
.stat-card:nth-child(4)::before { background: #8b5cf6; }

.stat-title {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-main); }

/* ─── Dashboard Grid ─────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

/* ─── Profile Layout ─────────────────── */
.profile-layout {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 24px;
}

/* ─── Recent Patient Item ────────────── */
.recent-patient-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ─── Welcome Banner ─────────────────── */
.welcome-banner {
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    color: white;
    padding: 18px 24px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
}

/* ─── Data Tables ────────────────────── */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; min-width: 500px; }
.data-table th {
    background: #f8fafc;
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}
.data-table tr:hover { background: #fafbfc; }
.data-table tr:last-child td { border-bottom: none; }

.actions-cell {
    white-space: nowrap;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

/* ─── Buttons ────────────────────────── */
.btn { display:inline-flex; align-items:center; gap:6px; padding:9px 18px; border-radius:8px; font-weight:600; cursor:pointer; font-size:13px; border:none; transition:var(--transition); text-decoration:none; white-space:nowrap; }
.btn-primary { background:var(--primary); color:white; }
.btn-primary:hover { background:var(--primary-hover); }
.btn-secondary { background:#f1f5f9; color:var(--text-main); border:1px solid var(--border); }
.btn-secondary:hover { background:#e2e8f0; }
.btn-success { background:var(--success); color:white; }
.btn-danger { background:var(--error); color:white; }
.btn-danger:hover { background:#dc2626; }
.btn-sm { padding:6px 12px; font-size:12px; }
.btn-lg { padding:12px 24px; font-size:15px; }
.btn:disabled { opacity:0.6; cursor:not-allowed; }

/* ─── Forms ──────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-main);
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
    background: white;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display:flex; gap:8px; margin-top:20px; padding-top:16px; border-top:1px solid var(--border); flex-wrap:wrap; }

/* ─── Auth ────────────────────────────── */
.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: white;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.auth-card h1 { font-size: 24px; margin-bottom: 4px; }
.auth-card .auth-subtitle { color: var(--text-muted); margin-bottom: 28px; font-size: 14px; }

/* ─── Badges ─────────────────────────── */
.badge { display:inline-block; padding:3px 10px; border-radius:20px; font-size:12px; font-weight:600; white-space:nowrap; }
.badge-success { background:var(--success-light); color:#166534; }
.badge-warning { background:var(--warning-light); color:#92400e; }
.badge-error { background:var(--error-light); color:#991b1b; }
.badge-info { background:var(--info-light); color:#1e40af; }
.badge-default { background:#f1f5f9; color:#475569; }

/* ─── Toast ──────────────────────────── */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 14px 24px;
    border-radius: 10px;
    color: white;
    font-weight: 500;
    font-size: 14px;
    z-index: 10000;
    animation: slideIn 0.3s ease;
    box-shadow: var(--shadow-md);
    max-width: 400px;
    transition: opacity 0.3s ease;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--error); }
.toast-info { background: var(--info); }

/* ─── Quick Actions ──────────────────── */
.quick-actions { display:grid; grid-template-columns:repeat(auto-fit, minmax(140px, 1fr)); gap:14px; }
.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 100px;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    font-size: 13px;
}
.quick-action-btn:hover { background:var(--primary); color:white; transform:translateY(-2px); box-shadow:var(--shadow-md); }
.quick-action-btn .qa-icon { font-size: 24px; }

/* ─── Modal ──────────────────────────── */
.modal-overlay {
    position:fixed; top:0; left:0; right:0; bottom:0;
    background:rgba(0,0,0,0.5);
    z-index:1000;
    display:flex; align-items:center; justify-content:center;
    animation: fadeIn 0.2s;
}
.modal-box {
    background:white;
    border-radius:16px;
    width:90%;
    max-width:600px;
    max-height:90vh;
    overflow-y:auto;
    box-shadow:0 25px 50px -12px rgba(0,0,0,0.25);
    animation: scaleIn 0.2s;
}
.modal-header {
    padding:20px 24px;
    border-bottom:1px solid var(--border);
    display:flex;
    justify-content:space-between;
    align-items:center;
}
.modal-header h3 { font-size:18px; }
.modal-close { cursor:pointer; font-size:24px; color:var(--text-muted); background:none; border:none; padding:4px; }
.modal-close:hover { color:var(--error); }
.modal-body { padding:24px; }

/* ─── Profile Card ───────────────────── */
.profile-header {
    text-align: center;
    padding: 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
.profile-avatar {
    width: 80px; height: 80px;
    background: linear-gradient(135deg, var(--primary-light), #dbeafe);
    color: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; font-weight: 700;
    margin: 0 auto 12px;
    border: 3px solid var(--primary-light);
}

/* ─── Tabs ────────────────────────────── */
.tabs { display:flex; border-bottom:2px solid var(--border); margin-bottom:20px; gap:4px; overflow-x:auto; -webkit-overflow-scrolling:touch; }
.tab-btn {
    padding:10px 20px;
    border:none;
    background:transparent;
    font-weight:600;
    font-size:13px;
    color:var(--text-muted);
    cursor:pointer;
    border-bottom:2px solid transparent;
    margin-bottom:-2px;
    transition: var(--transition);
    white-space:nowrap;
    flex-shrink: 0;
}
.tab-btn:hover { color:var(--primary); }
.tab-btn.active { color:var(--primary); border-bottom-color:var(--primary); }

/* ─── Empty State ────────────────────── */
.empty-state {
    text-align:center;
    padding:48px 24px;
    color:var(--text-muted);
}
.empty-state .empty-icon { font-size:48px; margin-bottom:12px; opacity:0.5; }
.empty-state p { font-size:15px; }

/* ─── Loader ─────────────────────────── */
.spinner {
    width:28px; height:28px;
    border:3px solid rgba(0,0,0,0.08);
    border-top-color:var(--primary);
    border-radius:50%;
    animation:spin 0.7s linear infinite;
    margin:40px auto;
}
.spinner-sm {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(0,0,0,0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.loader-container { display:flex; flex-direction:column; align-items:center; justify-content:center; min-height:60vh; gap:16px; color:var(--text-muted); }

/* ─── Pagination ─────────────────────── */
.pagination { display:flex; gap:6px; align-items:center; margin-top:16px; justify-content:center; flex-wrap:wrap; }
.pagination button {
    padding:6px 12px; border:1px solid var(--border); border-radius:6px;
    background:white; cursor:pointer; font-size:13px; transition:var(--transition);
}
.pagination button:hover { background:var(--primary-light); }
.pagination button.active { background:var(--primary); color:white; border-color:var(--primary); }
.pagination button:disabled { opacity:0.4; cursor:not-allowed; }

/* ─── Animations ─────────────────────── */
@keyframes spin { to { transform:rotate(360deg); } }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes scaleIn { from { transform:scale(0.95); opacity:0; } to { transform:scale(1); opacity:1; } }
@keyframes slideIn { from { transform:translateX(100px); opacity:0; } to { transform:translateX(0); opacity:1; } }

/* ─── Responsive: Tablet ─────────────── */
@media (max-width: 1024px) {
    .main-content { padding: 24px; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .profile-layout { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 16px; }
    .mobile-menu-btn { display: flex; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .quick-actions { grid-template-columns: 1fr 1fr; }
    .topbar h2 { font-size: 18px; }
    .stat-value { font-size: 22px; }
    .panel { padding: 16px; }
    .panel-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .topbar-kbd { display: none; }
}

@media (max-width: 480px) {
    .main-content { padding: 12px; }
    .stats-grid { grid-template-columns: 1fr; }
    .quick-actions { grid-template-columns: 1fr; }
    .auth-card { padding: 24px; }
    .tabs { gap: 0; }
    .tab-btn { padding: 8px 12px; font-size: 12px; }
}

/* ─── Print Styles ─────────────────────── */
@media print {
    body { background: white !important; font-size: 12pt; color: black; }
    .sidebar, .sidebar-overlay, .no-print, header, .toast, .pagination, #back-btn, .mobile-menu-btn { display: none !important; }
    .main-content { margin: 0 !important; padding: 0 !important; width: 100% !important; background: white; }
    .panel { box-shadow: none !important; border: 1px solid #ccc !important; break-inside: avoid; margin-bottom: 20px; }
    .print-grid { display: block !important; }
    .data-table { min-width: unset !important; }
    .data-table th, .data-table td { border: 1px solid #ddd !important; padding: 8px !important; }
    .stat-card { border: 1px solid #ccc !important; box-shadow: none !important; break-inside: avoid; margin-bottom: 15px; }
    .badge { border: 1px solid #999; color: black !important; background: transparent !important; }
    .tabs { display: none !important; }
    .tab-panel { display: block !important; margin-top: 20px; }
    .tab-panel h3, .tab-panel h4, .tab-panel::before { content: attr(id); display: block; text-transform: capitalize; font-size: 16px; font-weight: bold; margin-bottom: 10px; border-bottom: 1px solid #ccc; padding-bottom: 5px; }
    #tab-visits::before { content: "Visits History"; }
    #tab-appointments::before { content: "Appointments History"; }
    #tab-prescriptions::before { content: "Prescriptions History"; }
    #tab-billing::before { content: "Billing History"; }
    a { text-decoration: none; color: black !important; }
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    .welcome-banner { background: #eee !important; color: black !important; }
}

/* ─── Upload Area ─────────────────────── */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
    transition: var(--transition);
    background: #f8fafc;
    cursor: pointer;
}
.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.upload-area .upload-icon {
    font-size: 40px;
    margin-bottom: 12px;
    display: block;
}
.upload-area h5 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-main);
}
.upload-area p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ─── Patient Profile Info Grid ──────── */
.profile-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.profile-info-item {
    margin-bottom: 4px;
}
.profile-info-item label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 3px;
}

/* ─── Badge Secondary ────────────────── */
.badge-secondary { background: #f1f5f9; color: #475569; }

/* ─── Search Box ─────────────────────── */
.search-box { position: relative; }
.search-box .form-control {
    padding-left: 14px;
    min-width: 180px;
}

/* ─── Autocomplete Highlight ─────────── */
.autocomplete-item { transition: background 0.1s ease; }
.autocomplete-item:hover { background: #e0e7ff !important; }

/* ─── Actions Dropdown (mobile) ──────── */
@media (max-width: 768px) {
    .actions-cell {
        flex-direction: column;
        align-items: stretch;
    }
    .actions-cell .btn {
        width: 100%;
        justify-content: center;
        font-size: 11px;
        padding: 5px 8px;
    }
    .profile-info-grid {
        grid-template-columns: 1fr;
    }
    .search-box .form-control {
        min-width: 120px;
    }
}

/* ─── View All Link ──────────────────── */
.view-all-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    transition: var(--transition);
}
.view-all-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* ─── Focus Visible ──────────────────── */
.btn:focus-visible, .form-control:focus-visible, .tab-btn:focus-visible, .nav-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ─── Dark Mode ──────────────────────── */
[data-theme="dark"] {
    --bg-main: #0f172a;
    --sidebar-bg: #0b1120;
    --card-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.5);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.5);
    --primary-light: color-mix(in srgb, var(--primary) 25%, #1e293b);
    --info-light: #1e3a5f;
    --warning-light: #422006;
}
[data-theme="dark"] .data-table th { background: #0f172a; }
[data-theme="dark"] .data-table tr:hover { background: #334155; }
[data-theme="dark"] .form-control { background: #0f172a; color: #f8fafc; border-color: var(--border); }
[data-theme="dark"] .form-control:focus { border-color: var(--primary); }
[data-theme="dark"] .btn-secondary { background: #334155; color: #f8fafc; border-color: var(--border); }
[data-theme="dark"] .btn-secondary:hover { background: #475569; }
[data-theme="dark"] .stat-card { background: var(--card-bg); }
[data-theme="dark"] .modal-box { background: var(--card-bg); }
[data-theme="dark"] .panel { background: var(--card-bg); }
[data-theme="dark"] .topbar { background: var(--card-bg); border-color: var(--border); }
[data-theme="dark"] .welcome-banner { background: var(--primary-light); }
[data-theme="dark"] .profile-header { background: linear-gradient(135deg, var(--primary-light), #1e293b); }
[data-theme="dark"] .quick-action-btn { background: var(--card-bg); border-color: var(--border); color: var(--text-main); }
[data-theme="dark"] .quick-action-btn:hover { background: #334155; }
[data-theme="dark"] .tab-btn { background: var(--card-bg); color: var(--text-muted); border-color: var(--border); }
[data-theme="dark"] .tab-btn.active { color: var(--primary); border-color: var(--primary); }
[data-theme="dark"] #form-box, [data-theme="dark"] .autocomplete-results { background: var(--card-bg) !important; border-color: var(--border) !important; }
[data-theme="dark"] .autocomplete-item:hover { background: #334155 !important; }
[data-theme="dark"] .toast-success { background: #065f46; color: #d1fae5; }
[data-theme="dark"] .toast-error { background: #7f1d1d; color: #fee2e2; }
[data-theme="dark"] .toast-info { background: #1e3a5f; color: #dbeafe; }
[data-theme="dark"] .cal-header, [data-theme="dark"] .cal-day, [data-theme="dark"] .cal-appt { background: var(--card-bg); }
[data-theme="dark"] .calendar-grid { background: var(--border); }
[data-theme="dark"] .cal-day.empty { background: var(--bg-main); }
[data-theme="dark"] .cal-day.today { background: var(--info-light); }
[data-theme="dark"] .upload-area { background: #0f172a; border-color: var(--border); }
[data-theme="dark"] .recent-patient-item { border-color: var(--border); }
[data-theme="dark"] .auth-card { background: var(--card-bg); }
[data-theme="dark"] .nav-section-label { color: #64748b; }
[data-theme="dark"] #staff-form-box, [data-theme="dark"] #group-form-box, [data-theme="dark"] #field-form-box { background: var(--card-bg) !important; border-color: var(--border) !important; }
[data-theme="dark"] .topbar-action-btn { background: #334155; border-color: var(--border); color: var(--text-main); }
[data-theme="dark"] .topbar-action-btn:hover { background: var(--primary); color: white; }
[data-theme="dark"] .topbar-kbd { background: rgba(255,255,255,0.1); color: #94a3b8; }

/* ─── Calendar ───────────────────────── */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-top: 1px solid var(--border);
    border-left: 1px solid var(--border);
    background: #f8fafc;
}
.cal-header {
    text-align: center;
    padding: 10px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: white;
}
.cal-day {
    min-height: 120px;
    background: white;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 8px;
    display: flex;
    flex-direction: column;
}
.cal-day.empty { background: #f8fafc; }
.cal-day.today { background: var(--info-light); }
.cal-day-num {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    align-self: flex-end;
}
.cal-day.today .cal-day-num {
    background: var(--primary);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cal-day-content { flex: 1; display:flex; flex-direction:column; gap:4px; overflow-y:auto; max-height: 140px; }
.cal-appt {
    background: white;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition);
}
.cal-appt:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--primary); }
.cal-appt-time { font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
.cal-appt-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-main); font-weight: 500; }



/* ==========================================================================
   SMART BILLING UI
   ========================================================================== */

/* Smart Alerts */
.smart-alert {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.3s ease-out;
}
.smart-alert-icon { font-size: 24px; flex-shrink: 0; }
.smart-alert-body { flex: 1; }
.smart-alert-body strong { display: block; font-size: 15px; margin-bottom: 4px; }
.smart-alert-meta { font-size: 13px; opacity: 0.8; }
.smart-alert-warning { background: #fffbeb; border-left: 4px solid #f59e0b; color: #b45309; }
.smart-alert-info { background: #eff6ff; border-left: 4px solid #3b82f6; color: #1e3a8a; }

/* Finance Summary Card */
.finance-summary-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    margin-bottom: 24px;
}
.finance-summary-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.finance-stat {
    flex: 1;
    min-width: 120px;
    text-align: center;
    background: #f8fafc;
    padding: 16px;
    border-radius: 8px;
}
[data-theme="dark"] .finance-stat {
    background: #0f172a;
}
.finance-stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    font-weight: 600;
}
.finance-stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-main);
}
.finance-progress-wrap {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}
[data-theme="dark"] .finance-progress-wrap {
    background: #334155;
}
.finance-progress-bar {
    height: 100%;
    background: var(--primary);
    transition: width 0.5s ease-out;
}
.finance-progress-label {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

/* Invoice Detail / Modal Elements */
.invoice-detail-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}
[data-theme="dark"] .invoice-detail-card {
    background: #0f172a;
}
.invoice-detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.invoice-detail-row:last-child {
    border-bottom: none;
}
.invoice-detail-row span {
    color: var(--text-muted);
}

/* Payment Timeline */
.payment-timeline {
    position: relative;
    padding-left: 20px;
    margin: 16px 0;
}
.payment-timeline::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 7px;
    width: 2px;
    background: var(--border);
}
.timeline-item {
    position: relative;
    padding-bottom: 16px;
}
.timeline-item:last-child {
    padding-bottom: 0;
}
.timeline-dot {
    position: absolute;
    left: -20px;
    top: 4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid var(--card-bg);
}
.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.timeline-meta {
    font-size: 12px;
    color: var(--text-muted);
}

/* ==========================================================================
   PREMIUM PATIENT PROFILE STYLES
   ========================================================================== */
.profile-banner-premium {
    position: relative;
    height: 120px;
    background: linear-gradient(135deg, var(--primary) 0%, #3b82f6 100%);
    border-radius: var(--radius) var(--radius) 0 0;
    margin-bottom: 0px;
}
.profile-header-premium {
    background: var(--card-bg);
    border-radius: 0 0 var(--radius) var(--radius);
    border: 1px solid var(--border);
    border-top: none;
    padding: 24px;
    margin-bottom: 24px;
    position: relative;
    box-shadow: var(--shadow);
}
.profile-avatar-premium-wrapper {
    position: absolute;
    top: -50px;
    left: 24px;
}
html[dir="rtl"] .profile-avatar-premium-wrapper {
    left: auto;
    right: 24px;
}
.profile-avatar-premium {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light), #dbeafe);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: 700;
    border: 4px solid var(--card-bg);
    box-shadow: var(--shadow-md);
}
.profile-title-premium {
    margin-left: 140px;
    padding-top: 4px;
}
html[dir="rtl"] .profile-title-premium {
    margin-left: 0;
    margin-right: 140px;
}
.profile-title-premium h3 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.profile-title-premium p {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Stat Tiles */
.stat-tiles-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-tile-premium {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}
.stat-tile-premium:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.stat-tile-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.stat-tile-icon.visits { background: rgba(37, 99, 235, 0.1); color: var(--primary); }
.stat-tile-icon.balance { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.stat-tile-icon.last-visit { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.stat-tile-icon.files { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.stat-tile-content {
    display: flex;
    flex-direction: column;
}
.stat-tile-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stat-tile-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 2px;
}

/* Active Status Pulse Indicator */
.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}
.status-indicator.active {
    background: var(--success-light);
    color: #166534;
}
.status-indicator.inactive {
    background: #f1f5f9;
    color: #475569;
}
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success);
}
.status-indicator.inactive .pulse-dot {
    background-color: var(--text-muted);
}
.status-indicator.active .pulse-dot {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse 1.6s infinite;
}
@keyframes pulse {
    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); }
}

/* Medical Highlights */
.medical-highlights-box {
    background: #fffbeb;
    border-radius: var(--radius);
    border: 1px solid #fef3c7;
    border-left: 4px solid #f59e0b;
    padding: 16px 20px;
    margin-bottom: 24px;
}
[data-theme="dark"] .medical-highlights-box {
    background: #272115;
    border-color: #422006;
}
html[dir="rtl"] .medical-highlights-box {
    border-left: none;
    border-right: 4px solid #f59e0b;
}

/* Clinical Timeline */
.clinical-timeline-premium {
    position: relative;
    padding-left: 24px;
    margin: 16px 0;
}
html[dir="rtl"] .clinical-timeline-premium {
    padding-left: 0;
    padding-right: 24px;
}
.clinical-timeline-premium::before {
    content: '';
    position: absolute;
    top: 8px;
    bottom: 8px;
    left: 7px;
    width: 2px;
    background: var(--border);
}
html[dir="rtl"] .clinical-timeline-premium::before {
    left: auto;
    right: 7px;
}
.timeline-item-premium {
    position: relative;
    padding-bottom: 24px;
}
.timeline-item-premium:last-child {
    padding-bottom: 0;
}
.timeline-dot-premium {
    position: absolute;
    left: -24px;
    top: 4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid var(--card-bg);
    box-shadow: 0 0 0 2px var(--primary-light);
}
html[dir="rtl"] .timeline-dot-premium {
    left: auto;
    right: -24px;
}
.timeline-content-premium {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow);
}
.timeline-header-premium {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}
.timeline-actions {
    display: flex;
    gap: 6px;
}

/* ─── Right-To-Left (RTL) Overrides ─── */
html[dir="rtl"] body {
    text-align: right;
}

html[dir="rtl"] .sidebar {
    right: 0;
    left: auto;
}

html[dir="rtl"] .main-content {
    margin-left: 0;
    margin-right: 260px;
}

html[dir="rtl"] .topbar h2,
html[dir="rtl"] .panel-header h3,
html[dir="rtl"] .form-group label,
html[dir="rtl"] .stat-title,
html[dir="rtl"] .stat-value,
html[dir="rtl"] .recent-patient-item,
html[dir="rtl"] .data-table th,
html[dir="rtl"] .data-table td,
html[dir="rtl"] .timeline-item,
html[dir="rtl"] .empty-state,
html[dir="rtl"] .auth-card h1,
html[dir="rtl"] .auth-card .auth-subtitle {
    text-align: right;
}

html[dir="rtl"] .toast {
    right: auto;
    left: 20px;
    animation: slideInLeft 0.3s ease;
}

html[dir="rtl"] .stat-card::before {
    left: auto;
    right: 0;
}

html[dir="rtl"] .smart-alert-warning {
    border-left: none;
    border-right: 4px solid #f59e0b;
}

html[dir="rtl"] .smart-alert-info {
    border-left: none;
    border-right: 4px solid #3b82f6;
}

html[dir="rtl"] .payment-timeline {
    padding-left: 0;
    padding-right: 20px;
}

html[dir="rtl"] .payment-timeline::before {
    left: auto;
    right: 7px;
}

html[dir="rtl"] .timeline-dot {
    left: auto;
    right: -20px;
}

html[dir="rtl"] .calendar-grid {
    border-left: none;
    border-right: 1px solid var(--border);
}

html[dir="rtl"] .cal-header,
html[dir="rtl"] .cal-day {
    border-right: none;
    border-left: 1px solid var(--border);
}

html[dir="rtl"] .cal-day-num {
    align-self: flex-start;
}

/* Mobile responsive RTL overrides */
@media (max-width: 768px) {
    html[dir="rtl"] .sidebar {
        transform: translateX(100%);
    }
    html[dir="rtl"] .sidebar.open {
        transform: translateX(0);
    }
    html[dir="rtl"] .main-content {
        margin-right: 0;
        margin-left: 0;
    }
}

@keyframes slideInLeft {
    from { transform: translateX(-100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive Patient Profile Mobile Overrides */
@media (max-width: 576px) {
    .profile-banner-premium {
        height: 100px;
    }
    .profile-header-premium {
        padding: 70px 16px 20px;
        text-align: center;
    }
    .profile-avatar-premium-wrapper {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
        top: -50px;
    }
    .profile-title-premium {
        margin-left: 0 !important;
        margin-right: 0 !important;
        text-align: center !important;
    }
    .profile-title-premium h3 {
        justify-content: center;
        font-size: 20px;
        flex-direction: column;
        gap: 8px;
    }
}
