/* ═══════════════════════════════════════════
   SANETRIX — Healthcare SaaS Design System
   Dark Premium Theme
   ═══════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
    --bg-deepest: #0a0e1a;
    --bg-dark: #111827;
    --bg-surface: #1a1f2e;
    --bg-elevated: #1e2538;
    --bg-hover: #252d3f;

    --gradient-main: linear-gradient(135deg, #4fc3f7, #00e5ff, #69f0ae);
    --gradient-warm: linear-gradient(135deg, #4fc3f7, #7c4dff);
    --gradient-subtle: linear-gradient(135deg, rgba(79,195,247,.08), rgba(105,240,174,.08));

    --accent: #4fc3f7;
    --accent-cyan: #00e5ff;
    --accent-green: #69f0ae;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-on-gradient: #0a0e1a;

    --border: rgba(79, 195, 247, 0.12);
    --border-strong: rgba(79, 195, 247, 0.25);
    --glow: rgba(79, 195, 247, 0.1);
    --glow-strong: rgba(79, 195, 247, 0.25);

    --success: #69f0ae;
    --warning: #ffd54f;
    --danger: #ff5252;
    --info: #4fc3f7;

    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --header-height: 64px;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-sm: 0 2px 8px rgba(0,0,0,.25);
    --shadow-md: 0 4px 16px rgba(0,0,0,.35);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.45);
    --shadow-glow: 0 0 20px rgba(79,195,247,.15);

    --transition: all .25s cubic-bezier(.4,0,.2,1);
    --transition-fast: all .15s ease;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--bg-deepest);
}

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

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

a { color: var(--accent); text-decoration: none; transition: var(--transition-fast); }
a:hover { color: var(--accent-cyan); }
::selection { background: rgba(79,195,247,.3); color: var(--text-primary); }

/* ════════════════════════════
   LAYOUT: Sidebar + Content
   ════════════════════════════ */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;    /* fallback */
    height: 100dvh;   /* dynamic viewport — fixes iOS Safari 100vh bug (footer visible) */
    background: var(--bg-dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    z-index: 1000;
    transition: var(--transition);
    overflow: hidden;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-logo-img {
    width: 32px; height: 32px; border-radius: 6px; object-fit: contain;
}

.sidebar-brand .brand-logo-text {
    height: 22px; width: auto; object-fit: contain;
}

.sidebar-brand .brand-logo {
    font-size: 26px; font-weight: 700;
    background: var(--gradient-main);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; letter-spacing: -0.5px;
}

.sidebar-brand .brand-badge {
    font-size: 9px; padding: 2px 6px; border-radius: 4px;
    background: var(--gradient-main); color: var(--text-on-gradient);
    font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
}

.sidebar-nav { 
    flex: 1; 
    padding: 16px 12px; 
    overflow-y: auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 2px; }
.nav-section { margin-bottom: 24px; }

.nav-section-title {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 1.5px; color: var(--text-muted); padding: 0 12px 8px;
}

.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text-secondary); font-weight: 500; font-size: 13px;
    transition: var(--transition-fast); cursor: pointer;
    position: relative; text-decoration: none;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }

.nav-item.active {
    background: var(--gradient-subtle); color: var(--accent);
    border: 1px solid var(--border);
    position: relative;
}

.nav-item.active::before {
    content: ''; position: absolute; left: 0; top: 50%;
    transform: translateY(-50%); width: 3px; height: 60%;
    background: var(--gradient-main); border-radius: 0 3px 3px 0;
}

.nav-item i { width: 20px; text-align: center; font-size: 15px; }

.nav-item .nav-badge {
    margin-left: auto; background: var(--danger); color: #fff;
    font-size: 10px; font-weight: 700; padding: 2px 7px;
    border-radius: 10px; min-width: 18px; text-align: center;
}

.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); }

.sidebar-user {
    display: flex; align-items: center; gap: 12px;
    padding: 8px; border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}
.sidebar-user:hover { background: var(--bg-hover); }

.sidebar-user .user-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--gradient-main); display: flex;
    align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; color: var(--text-on-gradient); flex-shrink: 0;
}

.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { font-size: 11px; color: var(--text-muted); }

/* ── Main Content ── */
.main-content { flex: 1; margin-left: var(--sidebar-width); min-height: 100vh; transition: var(--transition); overflow-x: hidden; min-width: 0; }

.top-header {
    height: var(--header-height);
    background: rgba(17,24,39,.85); backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; position: sticky; top: 0; z-index: 900;
}

.header-left { display: flex; align-items: center; gap: 16px; }

.btn-sidebar-toggle {
    display: none; background: none; border: none;
    color: var(--text-secondary); font-size: 20px; cursor: pointer; padding: 4px 8px;
}

.header-search { position: relative; }

.header-search input {
    width: 320px; padding: 8px 16px 8px 40px;
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); color: var(--text-primary);
    font-size: 13px; font-family: var(--font); transition: var(--transition);
}
.header-search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.header-search input::placeholder { color: var(--text-muted); }
.header-search i.fa-magnifying-glass { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 13px; z-index: 2; }

/* ── Search Results Dropdown ── */
.search-results {
    display: none; position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    min-width: 380px; max-height: 420px; overflow-y: auto;
    background: var(--bg-surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    z-index: 9999; padding: 6px 0;
}
.search-results.active { display: block; }
.search-results .sr-section { padding: 6px 14px 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.search-results .sr-item {
    display: flex; align-items: center; gap: 10px; padding: 8px 14px;
    cursor: pointer; transition: background .15s; text-decoration: none; color: var(--text-primary);
}
.search-results .sr-item:hover { background: var(--bg-hover); }
.search-results .sr-item .sr-icon {
    width: 32px; height: 32px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0;
}
.search-results .sr-item .sr-icon.patient { background: rgba(79,195,247,.12); color: var(--accent); }
.search-results .sr-item .sr-icon.appointment { background: rgba(105,240,174,.12); color: var(--success); }
.search-results .sr-item .sr-text { flex: 1; min-width: 0; }
.search-results .sr-item .sr-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-results .sr-item .sr-sub { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-results .sr-empty { padding: 20px 14px; text-align: center; color: var(--text-muted); font-size: 13px; }
.search-results .sr-loading { padding: 16px 14px; text-align: center; color: var(--text-muted); font-size: 12px; }

.header-right { display: flex; align-items: center; gap: 8px; }

.header-icon-btn {
    width: 38px; height: 38px; border-radius: 50%;
    border: 1px solid var(--border); background: transparent;
    color: var(--text-secondary); display: flex; align-items: center;
    justify-content: center; cursor: pointer; position: relative;
    transition: var(--transition-fast); font-size: 15px;
}
.header-icon-btn:hover { background: var(--bg-hover); color: var(--accent); border-color: var(--border-strong); }

.header-icon-btn .badge-dot {
    position: absolute; top: 6px; right: 6px; width: 8px; height: 8px;
    background: var(--danger); border-radius: 50%; border: 2px solid var(--bg-dark);
}
.header-icon-btn .badge-count {
    position: absolute; top: 2px; right: 0; min-width: 16px; height: 16px;
    background: var(--danger); border-radius: 8px; border: 2px solid var(--bg-dark);
    font-size: 9px; font-weight: 700; color: #fff; display: flex;
    align-items: center; justify-content: center; padding: 0 3px; line-height: 1;
}

/* ── Notification Dropdown ─────────────────────────────────────── */
.notif-dropdown { min-width: 340px; max-width: 380px; padding: 0 !important; overflow: hidden; }
.notif-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.notif-header-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.notif-mark-all { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 4px 6px; border-radius: var(--radius-sm); transition: var(--transition-fast); }
.notif-mark-all:hover { color: var(--accent); background: var(--bg-hover); }
.notif-item { display: flex; gap: 10px; padding: 10px 16px; text-decoration: none; color: var(--text-primary); transition: var(--transition-fast); border-bottom: 1px solid var(--border); }
.notif-item:hover { background: var(--bg-hover); }
.notif-item.notif-unread { background: rgba(var(--accent-rgb, 59, 130, 246), 0.06); }
.notif-icon { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-hover); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 13px; color: var(--accent); }
.notif-content { flex: 1; min-width: 0; }
.notif-title { font-size: 13px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-body { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.notif-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.notif-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px 16px; color: var(--text-muted); font-size: 13px; }
.notif-empty i { font-size: 24px; opacity: 0.5; }
.notif-footer { display: block; text-align: center; padding: 10px; font-size: 12px; font-weight: 600; color: var(--accent); text-decoration: none; border-top: 1px solid var(--border); transition: var(--transition-fast); }
.notif-footer:hover { background: var(--bg-hover); }
.notif-card-link { transition: var(--transition-fast); }
.notif-card-link:hover { background: var(--bg-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* ── Real-Time Connection Status (discreet dot) ───────────────── */
.rt-status { position: fixed; bottom: 12px; left: 12px; z-index: 9999; cursor: default; }
.rt-status-dot { display: block; width: 6px; height: 6px; border-radius: 50%; opacity: 0; transition: opacity 0.4s; }
.rt-status-dot.rt-connected { background: var(--success); opacity: .45; }
.rt-status-dot.rt-disconnected { background: var(--danger); opacity: 1; animation: rtPulse 1.5s infinite; }
.rt-status-dot.rt-reconnecting { background: var(--warning); opacity: 1; animation: rtPulse 1s infinite; }
@keyframes rtPulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

.page-content { padding: 24px; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 16px; }
.page-title { font-size: 24px; font-weight: 700; color: var(--text-primary); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.breadcrumb { display: flex; gap: 8px; font-size: 12px; color: var(--text-muted); list-style: none; padding: 0; margin: 0 0 8px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .separator { color: var(--text-muted); opacity: .5; }

/* ════════════════════ CARDS ════════════════════ */
.card {
    background: var(--bg-dark); border: 1px solid var(--border);
    border-radius: var(--radius-lg); overflow: hidden; transition: var(--transition);
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); background: rgba(0,0,0,.1); }
.card-glass { background: rgba(17,24,39,.6); backdrop-filter: blur(12px); }

/* ── Stat Cards ── */
.stat-card {
    background: var(--bg-dark); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px;
    position: relative; overflow: hidden; transition: var(--transition);
}
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--gradient-main); opacity: 0; transition: var(--transition); }
.stat-card:hover::before { opacity: 1; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-glow); border-color: var(--border-strong); }

.stat-icon { width: 44px; height: 44px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 18px; margin-bottom: 16px; }
.stat-icon.blue { background: rgba(79,195,247,.12); color: var(--accent); }
.stat-icon.green { background: rgba(105,240,174,.12); color: var(--success); }
.stat-icon.yellow { background: rgba(255,213,79,.12); color: var(--warning); }
.stat-icon.red { background: rgba(255,82,82,.12); color: var(--danger); }
.stat-icon.purple { background: rgba(124,77,255,.12); color: #7c4dff; }

.stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }
.stat-change { font-size: 11px; font-weight: 600; margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }

/* ════════════════════ BUTTONS ════════════════════ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 20px; border-radius: var(--radius-sm); font-family: var(--font);
    font-size: 13px; font-weight: 600; cursor: pointer; transition: var(--transition);
    border: 1px solid transparent; text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--gradient-main); color: var(--text-on-gradient); border: none; }
.btn-primary:hover { box-shadow: var(--shadow-glow); opacity: .9; color: var(--text-on-gradient); }

.btn-secondary { background: transparent; border: 1px solid var(--border-strong); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--accent); color: var(--accent); }

.btn-danger { background: rgba(255,82,82,.12); color: var(--danger); border: 1px solid rgba(255,82,82,.25); }
.btn-danger:hover { background: rgba(255,82,82,.2); }

.btn-success { background: rgba(105,240,174,.12); color: var(--success); border: 1px solid rgba(105,240,174,.25); }
.btn-success:hover { background: rgba(105,240,174,.2); }

.btn-ghost { background: transparent; color: var(--text-secondary); border: none; padding: 8px 12px; }
.btn-ghost:hover { color: var(--accent); background: var(--glow); }

.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }
.btn-icon { width: 38px; height: 38px; padding: 0; }
.btn-group { display: flex; gap: 8px; }

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

.form-control,
.form-input,
.form-select {
    width: 100%; padding: 10px 14px; background: var(--bg-surface);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text-primary); font-family: var(--font); font-size: 13px;
    transition: var(--transition);
    color-scheme: dark;
}
.form-control:focus, .form-input:focus, .form-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); background: var(--bg-elevated); }
.form-control::placeholder, .form-input::placeholder { color: var(--text-muted); }
.form-control:disabled, .form-input:disabled, .form-select:disabled { opacity: .5; cursor: not-allowed; }
textarea.form-control, textarea.form-input { resize: vertical; min-height: 100px; }

select.form-control,
.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%2394a3b8' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
    cursor: pointer;
}

/* Native date/time inputs */
input[type="date"],
input[type="datetime-local"],
input[type="time"] {
    color-scheme: dark;
}
input[type="date"].form-control,
input[type="date"].form-input,
input[type="datetime-local"].form-control,
input[type="datetime-local"].form-input,
input[type="time"].form-control,
input[type="time"].form-input {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
    cursor: pointer;
}

.form-check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.form-check input[type="checkbox"], .form-check input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 11px; color: var(--danger); margin-top: 4px; }

/* Input with icon */
.input-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 100%;
}
.input-icon i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    font-size: 14px;
    z-index: 1;
}
.input-icon input,
.input-icon .form-input,
.input-icon .form-control {
    padding-left: 38px;
    width: 100%;
}

.input-group { display: flex; align-items: center; }
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group-append { padding: 10px 14px; background: var(--bg-elevated); border: 1px solid var(--border); border-left: none; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-muted); font-size: 13px; }

/* ════════════════════ TABLES ════════════════════ */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }

.table { width: 100%; border-collapse: collapse; }
.table th { padding: 12px 16px; background: var(--bg-surface); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
.table td { padding: 12px 16px; font-size: 13px; color: var(--text-primary); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: var(--transition-fast); }
.table tbody tr:hover { background: var(--glow); }
.table tbody tr:last-child td { border-bottom: none; }
.table-striped tbody tr:nth-child(even) { background: rgba(0,0,0,.15); }
.table-striped tbody tr:nth-child(even):hover { background: var(--glow); }

/* ════════════════════ BADGES ════════════════════ */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-primary { background: rgba(79,195,247,.12); color: var(--accent); border: 1px solid rgba(79,195,247,.25); }
.badge-success { background: rgba(105,240,174,.12); color: var(--success); border: 1px solid rgba(105,240,174,.25); }
.badge-warning { background: rgba(255,213,79,.12); color: var(--warning); border: 1px solid rgba(255,213,79,.25); }
.badge-danger { background: rgba(255,82,82,.12); color: var(--danger); border: 1px solid rgba(255,82,82,.25); }
.badge-info { background: rgba(79,195,247,.12); color: var(--info); border: 1px solid rgba(79,195,247,.25); }
.badge-neutral { background: rgba(148,163,184,.12); color: var(--text-secondary); border: 1px solid rgba(148,163,184,.25); }
.badge-default { background: var(--accent-green); color: #0a0e1a; }
[data-theme="light"] .badge-default { color: #ffffff; }

/* ════════════════════ MODAL ════════════════════ */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 2000; opacity: 0; visibility: hidden; transition: var(--transition); }
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal { background: var(--bg-dark); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 90%; max-width: 540px; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg); transform: translateY(20px) scale(.95); transition: var(--transition); }
.modal-overlay.active .modal { transform: translateY(0) scale(1); }

/* ── Calendar modals (modal-backdrop) ── */
@keyframes calModalIn { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-backdrop { position: fixed; inset: 0; z-index: 9000; background: rgba(0,0,0,.55); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-backdrop.cal-modal-hidden { display: none !important; }
.modal-backdrop .modal { transform: none; animation: calModalIn .18s ease-out; max-height: 90vh; overflow-y: auto; width: 100%; max-width: 480px; transition: none; }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; border: none; background: transparent; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition-fast); }
.modal-close:hover { background: var(--bg-hover); color: var(--danger); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ════════════════════ TOAST ════════════════════ */
.toast-container { position: fixed; top: 24px; right: 24px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg-dark); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px 20px; min-width: 320px; max-width: 420px; box-shadow: var(--shadow-md); display: flex; align-items: flex-start; gap: 12px; animation: slideIn .3s ease; }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info { border-left: 3px solid var(--info); }
.toast-icon { font-size: 18px; margin-top: 1px; flex-shrink: 0; }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-content { flex: 1; }
.toast-title { font-size: 13px; font-weight: 600; }
.toast-message { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.toast-close {
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); font-size: 18px; line-height: 1;
    padding: 2px 6px; border-radius: var(--radius-sm);
    opacity: .5; transition: opacity .2s, background .2s;
    flex-shrink: 0; margin-left: auto; margin-top: -2px;
    display: flex; align-items: center; justify-content: center;
}
.toast-close:hover { opacity: 1; background: rgba(255,255,255,.08); }
[data-theme="light"] .toast-close:hover { background: rgba(0,0,0,.06); }

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

/* ════════════════════ AVATAR ════════════════════ */
.avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; color: var(--text-on-gradient); background: var(--gradient-main); flex-shrink: 0; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-lg { width: 56px; height: 56px; font-size: 20px; }
.avatar-xl { width: 80px; height: 80px; font-size: 28px; }
.avatar-group { display: flex; }
.avatar-group .avatar { border: 2px solid var(--bg-dark); margin-left: -10px; }
.avatar-group .avatar:first-child { margin-left: 0; }

/* ════════════════════ TABS ════════════════════ */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-item { padding: 10px 16px; font-size: 13px; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: var(--transition-fast); background: none; border-top: none; border-left: none; border-right: none; font-family: var(--font); }
.tab-item:hover { color: var(--text-primary); }
.tab-item.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ════════════════════ EMPTY STATE ════════════════════ */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-state > i { font-size: 48px; color: var(--text-muted); opacity: .4; margin-bottom: 16px; display: block; }
.empty-state h3 { font-size: 17px; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 13px; color: var(--text-muted); max-width: 400px; margin: 0 auto 20px; }
.empty-state .btn { display: inline-flex; }
.empty-state .btn i { font-size: inherit; color: inherit; opacity: 1; margin-bottom: 0; display: inline; }

/* ════════════════════ DROPDOWN ════════════════════ */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; top: 100%; right: 0; background: var(--bg-dark); border: 1px solid var(--border); border-radius: var(--radius-md); min-width: 200px; padding: 6px; box-shadow: var(--shadow-lg); z-index: 1100; opacity: 0; visibility: hidden; transform: translateY(8px); transition: var(--transition-fast); }
.dropdown.open .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(4px); }
.dropdown-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: 13px; color: var(--text-secondary); border-radius: 6px; cursor: pointer; transition: var(--transition-fast); text-decoration: none; }
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-item i { width: 16px; text-align: center; }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ════════════════════ PAGINATION ════════════════════ */
.pagination { display: flex; align-items: center; gap: 4px; list-style: none; padding: 0; margin: 0; }
.pagination .page-link { padding: 6px 12px; border-radius: 6px; font-size: 13px; color: var(--text-muted); transition: var(--transition-fast); cursor: pointer; text-decoration: none; }
.pagination .page-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.pagination .active .page-link { background: var(--accent); color: var(--text-on-gradient); }

/* ════════════════════ PROGRESS ════════════════════ */
.progress-bar { width: 100%; height: 6px; background: var(--bg-surface); border-radius: 3px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--gradient-main); border-radius: 3px; transition: width .5s ease; }

/* ════════════════════ AUTH PAGES ════════════════════ */
.auth-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--bg-deepest); padding: 20px; position: relative; overflow: hidden;
}
.auth-page::before {
    content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(circle at 30% 40%, rgba(79,195,247,.06) 0%, transparent 50%),
                radial-gradient(circle at 70% 60%, rgba(105,240,174,.04) 0%, transparent 50%);
    animation: authBg 20s ease-in-out infinite;
}
@keyframes authBg { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-3%, -3%); } }

.auth-card {
    background: var(--bg-dark); border: 1px solid var(--border);
    border-radius: var(--radius-xl); padding: 40px; width: 100%; max-width: 440px;
    position: relative; z-index: 1; box-shadow: var(--shadow-lg);
}

.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo-img { width: 72px; height: 72px; border-radius: 16px; margin-bottom: 12px; object-fit: contain; }
.auth-logo-text { height: 36px; width: auto; object-fit: contain; display: block; margin: 0 auto; }
.auth-logo h1 { font-size: 32px; font-weight: 700; background: var(--gradient-main); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.auth-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.auth-divider { display: flex; align-items: center; gap: 16px; margin: 24px 0; color: var(--text-muted); font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.auth-footer { text-align: center; margin-top: 24px; font-size: 13px; color: var(--text-muted); }
.auth-footer a { color: var(--accent); font-weight: 600; }

.auth-error { background: rgba(255,82,82,.1); border: 1px solid rgba(255,82,82,.2); border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 20px; color: var(--danger); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.auth-success { background: rgba(105,240,174,.1); border: 1px solid rgba(105,240,174,.2); border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 20px; color: var(--success); font-size: 13px; display: flex; align-items: center; gap: 8px; }

/* ════════════════════ UTILITIES ════════════════════ */
.text-gradient { background: var(--gradient-main); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-accent { color: var(--accent) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }

.fw-400 { font-weight: 400; } .fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; }
.fs-xs { font-size: 11px; } .fs-sm { font-size: 12px; } .fs-md { font-size: 14px; } .fs-lg { font-size: 16px; } .fs-xl { font-size: 20px; }

.d-flex { display: flex; } .d-grid { display: grid; } .d-none { display: none; } .d-block { display: block; }
.flex-1 { flex: 1; } .flex-wrap { flex-wrap: wrap; }
.align-center { align-items: center; } .justify-between { justify-content: space-between; } .justify-center { justify-content: center; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }

.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mt-32 { margin-top: 32px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.p-0 { padding: 0; } .p-8 { padding: 8px; } .p-16 { padding: 16px; } .p-24 { padding: 24px; }

.rounded { border-radius: var(--radius-sm); } .rounded-lg { border-radius: var(--radius-lg); } .rounded-full { border-radius: 9999px; }
.w-full { width: 100%; } .text-center { text-align: center; } .text-right { text-align: right; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ════════════════════ SPINNER ════════════════════ */
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { position: absolute; inset: 0; background: rgba(10,14,26,.7); display: flex; align-items: center; justify-content: center; z-index: 100; border-radius: inherit; }

/* ════════════════════ LAYOUT HELPERS ════════════════════ */

/* Settings pages: 240px sidebar + main content */
.settings-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 24px;
}

/* Two-column detail grids (Doctor/Patient detail pages) */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* Password requirements grid */
.req-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-top: 12px;
}

/* Quick links row (profile page) */
.quick-links {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
}
.quick-links > * { flex: 1; min-width: 200px; }

/* ════════════════════ MOBILE ZOOM PREVENTION ════════════════════ */
/* Prevent iOS zoom on input focus (requires font-size >= 16px) */
@media screen and (max-width: 768px) {
    input, textarea, select, button:not(.dropdown-item) { font-size: 16px !important; }
    input:focus, textarea:focus, select:focus { font-size: 16px !important; }
}

/* Disable pinch-to-zoom and double-tap zoom — applied to ALL elements */
*,
*::before,
*::after {
    touch-action: manipulation;
    -ms-touch-action: manipulation;
}
html {
    touch-action: manipulation;
    -ms-touch-action: manipulation;
}
/* ════════════════════ FORM ROW ════════════════════ */
.form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.form-row > * { flex: 1; min-width: 200px; }

/* ════════════════════ ANDROID KEYBOARD OPEN ════════════════════ */
:root { --keyboard-height: 0px; }

/* When keyboard is open, reduce bottom padding on page content and push sticky elements up */
body.keyboard-open .page-content {
    padding-bottom: calc(var(--keyboard-height) + 8px) !important;
}

/* Modal: when keyboard open, shrink modal max-height and ensure it scrolls */
body.keyboard-open .modal-overlay {
    align-items: flex-start;
    padding-top: 12px;
}
body.keyboard-open .modal {
    max-height: calc(100vh - var(--keyboard-height) - 24px) !important;
    overflow-y: auto;
    margin-bottom: 0;
}

/* Fixed-position footers / action bars at the bottom: push above keyboard */
body.keyboard-open .modal-footer,
body.keyboard-open .form-actions,
body.keyboard-open .card-footer,
body.keyboard-open .action-bar {
    padding-bottom: calc(var(--keyboard-height) + 8px);
}

/* Sticky action buttons at bottom of forms */
body.keyboard-open [style*="position: sticky"][style*="bottom"],
body.keyboard-open [style*="position:sticky"][style*="bottom"] {
    bottom: var(--keyboard-height) !important;
}

/* ════════════════════ RESPONSIVE ════════════════════ */
@media (max-width: 1024px) {
    .header-search input { width: 220px; }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    /* ── Compact header on mobile ── */
    :root { --header-height: 48px; }

    /* ── Prevent page from being wider than viewport ── */
    html, body { overflow-x: hidden; }
    .main-content { overflow-x: hidden; }

    /* ── Sidebar ── */
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .btn-sidebar-toggle { display: flex; }

    /* ── Header: fixed on mobile so it doesn't scroll away ── */
    .top-header {
        position: fixed; left: 0; right: 0; top: 0;
        padding-top: env(safe-area-inset-top, 0px);

        height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
        transition: box-shadow .3s ease, background .3s ease;
    }
    .top-header.scrolled {
        background: rgba(17,24,39,.97);
        box-shadow: 0 2px 16px rgba(0,0,0,.35);
    }
    .header-search { display: none; }
    .header-right { gap: 4px; }
    .header-icon-btn { width: 34px; height: 34px; font-size: 14px; }
    .header-left, .header-right { margin-top: 0; }

    /* ── Page Content: extra top padding to clear fixed header ── */
    .page-content { padding: 16px; padding-top: calc(var(--header-height) + env(safe-area-inset-top, 0px) + 16px); overflow-x: hidden; }

    /* ── Card-body & card: horizontal scroll for wide content (grids, tables) ── */
    .card-body, .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* ── CLASS-based grids collapse to single column (layout grids) ── */
    .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; }

    /* ── Settings layout collapses to single column ── */
    .settings-layout { grid-template-columns: 1fr !important; gap: 16px; }
    .settings-layout > .card:first-child { position: static !important; }
    .card[style*="sticky"] { position: static !important; }

    /* Two-column detail grid collapses */
    .detail-grid { grid-template-columns: 1fr !important; }
    /* Span resets on mobile (used in doctor details) */
    .detail-grid > [style*="grid-row"] { grid-row: auto !important; }

    /* Password requirements: single column on mobile */
    .req-grid { grid-template-columns: 1fr !important; }

    /* Quick links stack on mobile */
    .quick-links { flex-direction: column; }
    .quick-links > * { min-width: unset; }

    /* Form rows stack on mobile */
    .form-row { flex-direction: column; gap: 0; }
    .form-row > * { min-width: unset; }

    /* ── Tables: scrollable horizontally ── */
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table { min-width: 600px; }
    .table th, .table td { padding: 10px 12px; font-size: 12px; }

    /* ── Sessions: card layout on mobile ── */
    .sessions-desktop { display: none !important; }
    .sessions-mobile { display: block !important; }

    /* ── Cards: prevent text overflow ── */
    .card, .card-body { overflow-wrap: break-word; word-break: break-word; }

    /* ── Tabs: horizontal scroll on mobile ── */
    .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; padding-bottom: 2px; }
    .tab-item, .tab { white-space: nowrap; flex-shrink: 0; padding: 10px 14px; }

    /* ── Modals ── */
    .modal { width: 95% !important; max-width: 95vw !important; margin: 10px; }

    /* ── Auth pages ── */
    .auth-card { padding: 28px 20px; }
    .auth-card .grid-2 { grid-template-columns: 1fr !important; }

    /* ── Toast: full-width friendly on mobile ── */
    .toast-container { right: 12px; left: 12px; top: 12px; }
    .toast { min-width: unset; max-width: 100%; }

    /* ── Buttons: stack when wrapped ── */
    .btn-group { flex-wrap: wrap; }
    .d-flex.gap-8, .d-flex.gap-12 { flex-wrap: wrap; }

    /* ── Dropdowns ── */
    .dropdown-menu { min-width: 180px; right: 0; }

    /* ── Notification dropdown: full-width centered on mobile viewport ── */
    .notif-dropdown {
        position: fixed !important;
        top: calc(var(--header-height) + env(safe-area-inset-top, 0px) + 4px) !important;
        left: 12px !important;
        right: 12px !important;
        width: auto !important;
        min-width: unset !important;
        max-width: unset !important;
        max-height: 70vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        transform: none !important;
        opacity: 0;
        visibility: hidden;
        transition: opacity .2s, visibility .2s;
    }
    .dropdown.open .notif-dropdown {
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
    }

    /* ── Card headers: wrap on small screens ── */
    .card-header { flex-wrap: wrap; gap: 8px; }

    /* ── Avatar section in profile ── */
    .d-flex[style*="gap:20px"] { flex-wrap: wrap; }

    /* ── Inline d-flex items with min-width that overflow ── */
    div[style*="min-width:160px"],
    div[style*="min-width:200px"],
    div[style*="min-width:250px"] { min-width: unset !important; width: 100%; }

    /* ── Flex rows for filter bars ── */
    .d-flex.flex-wrap { gap: 8px; }
    .d-flex.flex-wrap > * { min-width: unset !important; }

    /* ── Pagination ── */
    .pagination { flex-wrap: wrap; justify-content: center; }

    /* ── Stat values ── */
    .stat-value { font-size: 22px; }

    /* ── Fix inline select/input widths ── */
    select[style*="width:140px"],
    select[style*="width:120px"],
    input[style*="width:140px"],
    input[style*="width:120px"],
    input[style*="max-width:200px"],
    input[style*="max-width:300px"],
    .form-control[style*="max-width"] { width: 100% !important; max-width: 100% !important; }

    /* ── Images: constrain to screen ── */
    img[style*="max-width"] { max-width: 100% !important; height: auto !important; }

    /* ── Subdomain URL row in PublicProfile ── */
    .d-flex.align-center.gap-8 { flex-wrap: wrap; }

    /* ── Settings sidebar nav on mobile: horizontal tabs ── */
    .settings-layout > .card:first-child .card-body nav {
        flex-direction: row !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 4px !important;
        padding-bottom: 4px;
    }
    .settings-layout > .card:first-child .card-body nav .nav-item {
        white-space: nowrap;
        flex-shrink: 0;
        padding: 8px 14px !important;
        font-size: 13px !important;
    }
    .settings-layout > .card:first-child .card-body nav .nav-item.active::before {
        left: 50%; top: auto; bottom: 0;
        transform: translateX(-50%);
        width: 60%; height: 3px;
        border-radius: 3px 3px 0 0;
    }

    /* ── COMPREHENSIVE: flex-wrap for ALL d-flex gap helpers ── */
    .d-flex.gap-4, .d-flex.gap-6, .d-flex.gap-16, .d-flex.gap-20, .d-flex.gap-24 {
        flex-wrap: wrap;
    }

    /* ── COMPREHENSIVE: inline style flex rows — ALL gap values ── */
    div[style*="display:flex"][style*="gap:"],
    div[style*="display: flex"][style*="gap:"],
    div[style*="display:flex"][style*="gap: "],
    div[style*="display: flex"][style*="gap: "] {
        flex-wrap: wrap !important;
    }

    /* ── space-between flex rows — may collide on mobile ── */
    div[style*="display:flex"][style*="space-between"],
    div[style*="display: flex"][style*="space-between"] {
        flex-wrap: wrap !important;
        gap: 8px;
    }

    /* ── Inline flex on non-div elements (form, span, label) ── */
    form[style*="display:flex"],
    span[style*="display:flex"],
    label[style*="display:flex"],
    form[style*="display: flex"],
    span[style*="display: flex"],
    label[style*="display: flex"] {
        flex-wrap: wrap !important;
    }

    /* ── Fixed-width modal-like containers (not .modal class) ── */
    div[style*="width:640px"],
    div[style*="width:600px"],
    div[style*="width:500px"],
    div[style*="width: 640px"],
    div[style*="width: 600px"],
    div[style*="width: 500px"] {
        width: 95% !important;
        max-width: 95vw !important;
    }

    /* ── AI nav tabs ── */
    .ai-nav {
        flex-wrap: wrap !important;
    }

    /* ── Calendar min-height ── */
    #calendar {
        min-height: 480px !important;
    }

    /* ── Context menu min-width on mobile ── */
    div[style*="min-width:210px"] {
        min-width: unset !important;
        max-width: 210px;
    }

    /* ── Inline min-width on ANY element (catches remaining gaps) ── */
    div[style*="min-width:300px"],
    div[style*="min-width:350px"],
    div[style*="min-width:400px"],
    div[style*="min-width: 300px"],
    div[style*="min-width: 350px"],
    div[style*="min-width: 400px"] {
        min-width: unset !important;
        width: 100% !important;
    }

    /* ── Font-size for large inline text that overflows ── */
    div[style*="font-size:1.5rem"],
    div[style*="font-size: 1.5rem"] {
        font-size: 1.2rem !important;
    }
    div[style*="font-size:2rem"],
    div[style*="font-size: 2rem"] {
        font-size: 1.5rem !important;
    }

    /* ── Subscription/Billing inline flex rows ── */
    div[style*="display:flex"][style*="justify-content:space-between"][style*="font-size:0.8rem"],
    div[style*="display: flex"][style*="justify-content: space-between"][style*="font-size"] {
        flex-direction: column !important;
        gap: 4px;
    }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr !important; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .top-header { padding-left: 12px; padding-right: 12px; }
    .page-title { font-size: 20px; }
    .page-subtitle { font-size: 12px; }

    /* ── Calendar even shorter on phones ── */
    #calendar {
        min-height: 360px !important;
    }

    /* Stat cards tighter */
    .stat-card { padding: 14px; }
    .stat-value { font-size: 20px; }
    .stat-icon { width: 36px; height: 36px; font-size: 16px; margin-bottom: 12px; }

    /* Cards tighter padding */
    .card-body { padding: 14px; }
    .card-header { padding: 12px 14px; }

    /* Buttons full width */
    .btn { width: 100%; justify-content: center; }
    .btn-sm { width: auto; }
    .btn-ghost { width: auto; }
    .btn-icon { width: 38px; }
    .d-flex.gap-12 > .btn,
    .d-flex.gap-8 > .btn { width: auto; flex: 0 0 auto; }

    /* Search forms: keep input dominant, button compact */
    form.d-flex .btn,
    form[style*="display:flex"] .btn,
    form[style*="display: flex"] .btn { width: auto !important; flex: 0 0 auto !important; }

    /* ── space-between rows → stack on very small screens ── */
    div[style*="display:flex"][style*="space-between"],
    div[style*="display: flex"][style*="space-between"] {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    /* ── Inline flex-direction:row → column on phones ── */
    div[style*="display:flex"][style*="align-items:center"][style*="gap:16px"],
    div[style*="display:flex"][style*="align-items:center"][style*="gap:20px"],
    div[style*="display: flex"][style*="align-items: center"][style*="gap: 16px"],
    div[style*="display: flex"][style*="align-items: center"][style*="gap: 20px"] {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    /* Badge wrapping */
    .d-flex.align-center.gap-12 { flex-wrap: wrap; gap: 6px; }

    /* Avatar section */
    .avatar-xl, div[style*="width:80px"][style*="height:80px"] { 
        width: 60px !important; height: 60px !important; font-size: 20px !important; 
    }

    /* Form labels */
    .form-label { font-size: 11px; }
    .form-control, .form-input, .form-select { padding: 10px 12px; }

    /* Header icons fewer */
    .header-right .header-icon-btn:not(:first-child):not(:last-child) { display: none; }
    #userDropdown { display: flex; }
}

/* ── Extra small (very narrow phones) ── */
@media (max-width: 360px) {
    .page-content { padding: 12px; }
    .sidebar-brand .brand-logo { font-size: 22px; }
    .page-title { font-size: 18px; }
    .auth-card { padding: 20px 16px; }
}

/* ── iPhone safe area insets (notch / Dynamic Island / home indicator) ── */
@supports (padding: env(safe-area-inset-top)) {
    /* Header & sidebar */
    .top-header { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
    .sidebar { padding-top: env(safe-area-inset-top); }
    .sidebar-footer { padding-bottom: max(16px, env(safe-area-inset-bottom)); }


    /* Main content — ensure bottom of pages is never behind the home indicator */
    .page-content { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
    .main-content { padding-bottom: env(safe-area-inset-bottom); }

    /* Fixed-position elements at the bottom */
    .rt-status { bottom: max(12px, env(safe-area-inset-bottom)); }

    /* Modals — add bottom safe-area to footer/body so buttons aren't behind home bar */
    .modal-footer { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
    .sntx-alert-modal { padding-bottom: max(28px, env(safe-area-inset-bottom)) !important; }

    /* Auth pages — centered layout but need safe padding */
    .auth-page { padding-bottom: max(20px, env(safe-area-inset-bottom)); }

    /* Toast container — offset from top safe area */
    .toast-container { top: max(24px, env(safe-area-inset-top)); right: max(24px, env(safe-area-inset-right)); }

    /* html/body: prevent iOS overscroll bounce from showing gap behind home indicator */
    html { 
        background: var(--bg-deepest, #0a0e1a);
    }
    body { min-height: 100vh; }

    @media (max-width: 480px) {
        .top-header { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
        .page-content { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
    }
}

/* ── iOS scroll bounce fix — prevent rubber-band from showing bg behind content ── */
/* Also: -webkit-fill-available as fallback for iOS Safari <15.4 (no dvh support) */
@supports (-webkit-touch-callout: none) {
    html, body { overscroll-behavior-y: none; }
    .main-content { -webkit-overflow-scrolling: touch; }
    .sidebar { height: -webkit-fill-available; height: 100dvh; }
}

/* ── Sidebar overlay ── */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 999; }
@media (max-width: 768px) { .sidebar-overlay.active { display: block; } }

/* ════════════════════ ANIMATIONS ════════════════════ */
.fade-in { animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.scale-in { animation: scaleIn .3s ease; }
@keyframes scaleIn { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }

/* ════════════════════ SANETRIX ALERT/CONFIRM MODALS ════════════════════ */
.sntx-alert-overlay { z-index: 5000; }
.sntx-alert-modal {
    max-width: 420px !important;
    text-align: center;
    padding: 36px 32px 28px !important;
    border: 1px solid var(--border-strong) !important;
}
.sntx-alert-icon { font-size: 52px; margin-bottom: 18px; line-height: 1; }
.sntx-alert-title { font-size: 18px; font-weight: 700; color: var(--text-primary); margin-bottom: 10px; }
.sntx-alert-message { font-size: 14px; color: var(--text-secondary); margin-bottom: 28px; line-height: 1.6; }
.sntx-alert-actions { display: flex; gap: 10px; justify-content: center; }
.sntx-alert-actions .btn { min-width: 120px; }
@media (max-width: 480px) {
    .sntx-alert-modal { padding: 28px 20px 24px !important; width: 92% !important; }
    .sntx-alert-icon { font-size: 44px; }
    .sntx-alert-actions { flex-direction: column-reverse; }
    .sntx-alert-actions .btn { width: 100%; min-width: unset; }
}

/* ═══ Hide legacy inline TempData alert divs (replaced by toast system) ═══ */
.alert.alert-success,
.alert.alert-danger,
.alert.alert-info,
.alert.alert-warning { display: none !important; }

/* ─ Responsive helpers ─ */
@media (max-width: 480px) { .hide-xs { display: none !important; } }

/* ════════════════════ LOADING STATES ════════════════════ */
.spinner {
    display: inline-block; width: 20px; height: 20px;
    border: 2px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .6s linear infinite;
}
.spinner-lg { width: 40px; height: 40px; border-width: 3px; }
.spinner-sm { width: 14px; height: 14px; border-width: 2px; }

.page-loader {
    position: fixed; inset: 0; background: rgba(10,14,26,.85);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 9999; opacity: 1; transition: opacity .3s ease;
}
.page-loader.hidden { opacity: 0; pointer-events: none; }
.page-loader .spinner { width: 48px; height: 48px; border-width: 3px; }
.page-loader .loader-text { margin-top: 16px; color: var(--text-secondary); font-size: 14px; }

.btn-loading { position: relative; pointer-events: none; opacity: .7; }
.btn-loading::after {
    content: ''; position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite;
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
    background-size: 200% 100%; animation: skeleton-shimmer 1.5s infinite;
    border-radius: var(--radius-sm); min-height: 20px;
}
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-text:last-child { width: 60%; }
.skeleton-avatar { width: 48px; height: 48px; border-radius: 50%; }
.skeleton-card { height: 120px; }

@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ════════════════════ LIGHT THEME ════════════════════ */
[data-theme="light"] {
    --bg-deepest: #f0f2f5;
    --bg-dark: #ffffff;
    --bg-surface: #ffffff;
    --bg-elevated: #f8f9fa;
    --bg-hover: #e9ecef;

    --gradient-main: linear-gradient(135deg, #0288d1, #0097a7, #388e3c);
    --gradient-warm: linear-gradient(135deg, #0288d1, #5e35b1);
    --gradient-subtle: linear-gradient(135deg, rgba(2,136,209,.06), rgba(56,142,60,.06));

    --accent: #0288d1;
    --accent-cyan: #0097a7;
    --accent-green: #388e3c;

    --text-primary: #1a1a2e;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --text-on-gradient: #ffffff;

    --border: rgba(0,0,0,.1);
    --border-strong: rgba(0,0,0,.2);
    --glow: rgba(2,136,209,.06);
    --glow-strong: rgba(2,136,209,.12);

    --success: #388e3c;
    --warning: #f57f17;
    --danger: #d32f2f;
    --info: #0288d1;

    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
    --shadow-glow: 0 0 12px rgba(2,136,209,.08);
}

[data-theme="light"] .sidebar {
    background: #ffffff;
    border-right: 1px solid var(--border);
}
[data-theme="light"] .top-header {
    background: rgba(255,255,255,.9);
    border-bottom: 1px solid var(--border);
}
[data-theme="light"] .top-header.scrolled {
    background: rgba(255,255,255,.98);
    box-shadow: 0 2px 16px rgba(0,0,0,.1);
}
[data-theme="light"] .card {
    background: #ffffff;
    border: 1px solid var(--border);
}
[data-theme="light"] .nav-item:hover { background: var(--bg-hover); }
[data-theme="light"] .nav-item.active { background: rgba(2,136,209,.08); color: var(--accent); }
[data-theme="light"] .badge { border: 1px solid var(--border); }
[data-theme="light"] .table tr:hover td { background: var(--bg-hover); }
[data-theme="light"] .form-control,
[data-theme="light"] .form-input,
[data-theme="light"] .form-select { background: #ffffff; border-color: #d1d5db; color: var(--text-primary); color-scheme: light; }
[data-theme="light"] .form-control:focus,
[data-theme="light"] .form-input:focus,
[data-theme="light"] .form-select:focus { border-color: var(--accent); }
[data-theme="light"] input[type="date"],
[data-theme="light"] input[type="datetime-local"],
[data-theme="light"] input[type="time"] { color-scheme: light; }
[data-theme="light"] input[type="date"]::-webkit-calendar-picker-indicator,
[data-theme="light"] input[type="datetime-local"]::-webkit-calendar-picker-indicator,
[data-theme="light"] input[type="time"]::-webkit-calendar-picker-indicator { filter: none; }
[data-theme="light"] .page-loader { background: rgba(240,242,245,.9); }

/* ── Light theme: auth pages ── */
[data-theme="light"] .auth-page { background: linear-gradient(140deg, #e8f5e9 0%, #e3f2fd 35%, #f3e5f5 70%, #fff3e0 100%); }
[data-theme="light"] .auth-card { background: rgba(255,255,255,.92); border-color: rgba(0,0,0,.08); box-shadow: 0 8px 32px rgba(0,0,0,.08); }
[data-theme="light"] .auth-card:hover { box-shadow: 0 12px 40px rgba(0,0,0,.12); }
[data-theme="light"] #themeToggleBtn { background: rgba(255,255,255,.9) !important; border-color: rgba(0,0,0,.1) !important; color: var(--text-secondary) !important; }
[data-theme="light"] #themeToggleBtn:hover { background: #fff !important; box-shadow: 0 2px 8px rgba(0,0,0,.1); }