/* =====================================================
   نظام إدارة مواعيد العيادة - Custom Styles
   ===================================================== */

/* Custom Properties */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #7c3aed;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0891b2;
    --sidebar-width: 260px;
    --navbar-height: 60px;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --admin-accent: #2563eb;
    --doctor-accent: #7c3aed;
    --patient-accent: #059669;
    --transition: all 0.25s ease;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.03);
    --radius: 12px;
    --radius-sm: 8px;
}

/* =====================================================
   ثيمات الألوان — UI Color Schemes
   يُحقن الثيم المحدد كـ <style> inline من header.php بعد هذا الملف
   (inline style يأتي لاحقاً في الـ cascade → يتغلب دائماً)
   html[data-ui-scheme] للمعاينة الفورية بالجافاسكريبت (specificity أعلى من :root)
   ===================================================== */

/* قيم افتراضية في :root (يُغيَّر بـ inline style من header.php) */
:root {
    --navbar-grad-from:      #1e40af;
    --navbar-grad-to:        #1d4ed8;
    --sidebar-active-from:   #1e40af;
    --sidebar-active-to:     #3b82f6;
    --sidebar-active-shadow: rgba(37,99,235,.35);
}

/* معاينة فورية بالجافاسكريبت — html[X] أعلى من :root (0,1,1 > 0,1,0) */
html[data-ui-scheme="blue"]   { --navbar-grad-from:#1e40af; --navbar-grad-to:#1d4ed8; --sidebar-active-from:#1e40af; --sidebar-active-to:#3b82f6; --sidebar-active-shadow:rgba(37,99,235,.35); }
html[data-ui-scheme="green"]  { --navbar-grad-from:#065f46; --navbar-grad-to:#059669; --sidebar-active-from:#065f46; --sidebar-active-to:#10b981; --sidebar-active-shadow:rgba(5,150,105,.35); }
html[data-ui-scheme="purple"] { --navbar-grad-from:#4c1d95; --navbar-grad-to:#7c3aed; --sidebar-active-from:#4c1d95; --sidebar-active-to:#a78bfa; --sidebar-active-shadow:rgba(124,58,237,.35); }
html[data-ui-scheme="rose"]   { --navbar-grad-from:#9f1239; --navbar-grad-to:#e11d48; --sidebar-active-from:#9f1239; --sidebar-active-to:#fb7185; --sidebar-active-shadow:rgba(225,29,72,.35); }
html[data-ui-scheme="orange"] { --navbar-grad-from:#7c2d12; --navbar-grad-to:#ea580c; --sidebar-active-from:#7c2d12; --sidebar-active-to:#fb923c; --sidebar-active-shadow:rgba(234,88,12,.35); }
html[data-ui-scheme="slate"]  { --navbar-grad-from:#0f172a; --navbar-grad-to:#334155; --sidebar-active-from:#1e293b; --sidebar-active-to:#475569; --sidebar-active-shadow:rgba(71,85,105,.4); }

/* تطبيق المتغيرات على المكونات */
.top-navbar,
.admin-theme .top-navbar,
.doctor-theme .top-navbar,
.patient-theme .top-navbar {
    background: linear-gradient(135deg, var(--navbar-grad-from) 0%, var(--navbar-grad-to) 100%) !important;
}

/* Base */
* { box-sizing: border-box; }

body {
    font-family: 'Tajawal', 'Segoe UI', sans-serif;
    background: var(--body-bg);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    padding-top: calc(var(--navbar-height) + 10px);
    overflow-x: hidden;
}

/* =====================================================
   Navbar
   ===================================================== */
.top-navbar {
    height: var(--navbar-height);
    box-shadow: var(--shadow);
    z-index: 1055;
    overflow: visible;
}
/* ألوان شريط التنقل تأتي من ثيم الألوان أعلاه */

/* =====================================================
   Sidebar
   ===================================================== */
.sidebar {
    position: fixed;
    top: var(--navbar-height);
    right: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--navbar-height));
    background: var(--sidebar-bg);
    overflow-y: auto;
    overflow-x: hidden;
    transition: var(--transition);
    z-index: 1040;
    display: flex;
    flex-direction: column;
    box-shadow: -2px 0 8px rgba(0,0,0,.15);
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }

.sidebar-header { border-bottom: 1px solid #334155; }

.sidebar-logo-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,.12);
    border-radius: 12px;
    padding: 8px 12px;
    max-width: 150px;
}

.user-avatar {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(255,255,255,.15);
}

.user-avatar-sm {
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .9rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.badge-role {
    background: rgba(255,255,255,.15);
    color: rgba(255,255,255,.9);
    font-size: .7rem;
    padding: 3px 8px;
    border-radius: 20px;
}

.sidebar-link {
    color: #c1cfe0;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 2px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    font-size: .82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #f8fafc;
}
.sidebar-link.active {
    background: linear-gradient(135deg, var(--sidebar-active-from, var(--primary)), var(--sidebar-active-to, var(--secondary)));
    color: white;
    box-shadow: 0 4px 12px var(--sidebar-active-shadow, rgba(37,99,235,.35));
}
.sidebar-link i { font-size: 1rem; min-width: 20px; flex-shrink: 0; }

.sidebar-section-label {
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #7a8fa6;
    padding: 12px 14px 3px;
    display: block;
}

/* ─── بوابات الرسائل — gateway section header ─── */
.sidebar-gateway-header {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 12px 0 4px;
    padding: 9px 16px;
    background: rgba(255,255,255,.06);
    border-style: solid;
    border-width: 1px 0 1px 3px;
    border-color: rgba(255,255,255,.09) rgba(255,255,255,.09) rgba(255,255,255,.09) var(--gw-color, #4b5563);
    border-radius: 0;
    cursor: default;
    user-select: none;
}
.sidebar-gateway-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--gw-color, #64748b);
    flex-shrink: 0;
    animation: gw-dot-pulse 2.5s ease-in-out infinite;
    box-shadow: 0 0 8px var(--gw-color, #64748b);
}
@keyframes gw-dot-pulse {
    0%, 100% { box-shadow: 0 0 5px var(--gw-color,#64748b); }
    50%       { box-shadow: 0 0 13px var(--gw-color,#64748b); }
}
.sidebar-gateway-icon {
    font-size: 1.1rem;
    color: var(--gw-color, #94a3b8);
    flex-shrink: 0;
    filter: drop-shadow(0 0 5px var(--gw-color, transparent));
}
.sidebar-gateway-name {
    font-size: .82rem;
    font-weight: 700;
    letter-spacing: .02em;
    color: #e2e8f0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* روابط فرعية تحت كل بوابة */
.sidebar-link-sub {
    padding-right: 22px !important;
    font-size: .78rem !important;
    color: #94a3b8;
    border-right: 2px solid transparent;
    margin-right: 10px;
    border-radius: 0 6px 6px 0 !important;
}
.sidebar-link-sub:hover {
    color: #e2e8f0 !important;
    background: rgba(255,255,255,.05) !important;
    border-right-color: #475569;
}
.sidebar-link-sub.active {
    color: white !important;
    background: rgba(99,102,241,.25) !important;
    border-right-color: #818cf8;
    box-shadow: none !important;
}

.sidebar-divider {
    margin: 4px 12px;
    border-color: #334155;
    opacity: 1;
}

.sidebar-footer { border-top: 1px solid #334155; }

/* =====================================================
   Dashboard – datetime bar & appointment rows
   ===================================================== */
.dashboard-datetime-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg, #1e293b);
    border: 1px solid var(--border-color, #334155);
    border-radius: 12px;
    padding: 10px 20px;
}
.datetime-date,
.datetime-clock {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}
.datetime-clock {
    font-size: 1.25rem;
    font-variant-numeric: tabular-nums;
    color: var(--primary, #6366f1);
}

/* ─── appointment list items (dashboard cards) ─── */
.appt-list-item {
    display: grid;
    grid-template-columns: 54px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 7px 14px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    transition: background .12s;
}
/* عرض كامل: عمودان للمعلومات */
.appt-list-item.appt-fw {
    grid-template-columns: 64px 1fr 1fr auto;
}
.appt-list-item:last-child { border-bottom: 0; }
.appt-list-item:hover { background: rgba(37,99,235,.04); }

/* حاوية بشريط تمرير عند تجاوز 10 سجلات */
.appt-scroll-10 {
    max-height: 520px;   /* ≈ 10 × 52px */
    overflow-y: auto;
}
.appt-scroll-10::-webkit-scrollbar { width: 5px; }
.appt-scroll-10::-webkit-scrollbar-track { background: transparent; }
.appt-scroll-10::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

.appt-badge-time {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5px 4px;
    border-radius: 9px;
    font-size: .73rem;
    font-weight: 800;
    text-align: center;
    line-height: 1.25;
    color: white;
    flex-shrink: 0;
    min-height: 38px;
}
.appt-badge-date {
    font-size: .58rem;
    font-weight: 600;
    letter-spacing: 0;
    opacity: .88;
    display: block;
    margin-bottom: 1px;
}
.appt-badge-time.s-pending   { background: linear-gradient(145deg,#818cf8,#6366f1); }
.appt-badge-time.s-confirmed { background: linear-gradient(145deg,#60a5fa,#2563eb); }
.appt-badge-time.s-completed { background: linear-gradient(145deg,#4ade80,#16a34a); }
.appt-badge-time.s-cancelled { background: linear-gradient(145deg,#d1d5db,#6b7280); }
.appt-badge-time.s-no_show   { background: linear-gradient(145deg,#c084fc,#7c3aed); }

.appt-info { min-width: 0; }
.appt-info .appt-name {
    font-size: .83rem;
    font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    color: var(--text-primary, #0f172a);
}
.appt-info .appt-sub {
    font-size: .7rem;
    color: var(--text-muted, #64748b);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 1px;
}

.appt-actions {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-shrink: 0;
}

/* action buttons — icon-only squares for tight spaces */
.btn-appt {
    height: 30px;
    min-width: 30px;
    border: none;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: .75rem;
    font-weight: 600;
    padding: 0 10px;
    text-decoration: none;
    flex-shrink: 0;
    transition: opacity .15s, transform .12s, box-shadow .15s;
    cursor: pointer;
    letter-spacing: .01em;
    white-space: nowrap;
}
.btn-appt:hover {
    opacity: .88;
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(0,0,0,.2);
    color: inherit !important;
}
.btn-appt:active { transform: translateY(0); }

.btn-appt-confirm  {
    background: linear-gradient(135deg,#34d399,#059669);
    color: white !important;
    box-shadow: 0 2px 8px rgba(5,150,105,.28);
}
.btn-appt-complete {
    background: linear-gradient(135deg,#4ade80,#16a34a);
    color: white !important;
    box-shadow: 0 2px 8px rgba(22,163,74,.22);
}
.btn-appt-noshow {
    background: linear-gradient(135deg,#94a3b8,#64748b);
    color: white !important;
}
.btn-appt-cancel {
    background: linear-gradient(135deg,#f87171,#dc2626);
    color: white !important;
    box-shadow: 0 2px 8px rgba(220,38,38,.28);
}
.btn-appt-edit {
    background: rgba(100,116,139,.1);
    color: #475569 !important;
    border: 1px solid rgba(100,116,139,.25);
}

.btn-xs {
    font-size: .72rem !important;
    padding: 2px 7px !important;
    border-radius: 5px !important;
    line-height: 1.4;
}

/* =====================================================
   Layout
   ===================================================== */
.layout-wrapper {
    display: flex;
    min-height: calc(100vh - var(--navbar-height));
}

.main-content {
    margin-right: var(--sidebar-width);
    flex: 1;
    padding: 24px;
    transition: var(--transition);
    min-height: calc(100vh - var(--navbar-height));
    overflow-x: hidden;
    max-width: calc(100vw - var(--sidebar-width));
}

.main-footer {
    margin-right: var(--sidebar-width);
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    transition: var(--transition);
    max-width: calc(100vw - var(--sidebar-width));
}

/* On mobile, no margin since sidebar overlays */
@media (max-width: 991.98px) {
    .main-content, .main-footer {
        margin-right: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }
}

/* =====================================================
   Mobile Sidebar Overlay
   ===================================================== */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(110%);
        width: 280px;
        z-index: 1050;
        box-shadow: -4px 0 20px rgba(0,0,0,.3);
    }
    .sidebar.show { transform: translateX(0); }
    .main-content, .main-footer {
        margin-right: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Overlay behind sidebar on mobile */
    body.sidebar-open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.45);
        z-index: 1045;
    }
}

.sidebar-collapsed .sidebar { transform: translateX(110%); }
.sidebar-collapsed .main-content,
.sidebar-collapsed .main-footer { margin-right: 0; }

/* =====================================================
   Cards
   ===================================================== */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--card-bg);
    transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-header {
    background: none;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    font-weight: 600;
}

/* Stats Cards */
.stat-card {
    border-radius: var(--radius);
    padding: 20px;
    color: white;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}
.stat-card::after {
    content: '';
    position: absolute;
    top: -20px;
    left: -20px;
    width: 100px;
    height: 100px;
    background: rgba(255,255,255,.08);
    border-radius: 50%;
}
.stat-card:hover { box-shadow: var(--shadow-lg); }
.stat-card .stat-icon {
    font-size: 2rem;
    opacity: .85;
}
.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}
.stat-card .stat-label {
    font-size: .8rem;
    opacity: .85;
    margin-top: 4px;
}
.stat-card-primary { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.stat-card-success { background: linear-gradient(135deg, #16a34a, #15803d); }
.stat-card-warning { background: linear-gradient(135deg, #d97706, #b45309); }
.stat-card-danger  { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.stat-card-info    { background: linear-gradient(135deg, #0891b2, #0e7490); }
.stat-card-purple  { background: linear-gradient(135deg, #7c3aed, #6d28d9); }

/* =====================================================
   Tables
   ===================================================== */
.table-container {
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.table {
    margin-bottom: 0;
    font-size: .875rem;
}
.table thead th {
    background: #f8fafc;
    font-weight: 600;
    font-size: .85rem;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
    padding: 12px 16px;
    white-space: nowrap;
}
.table tbody td {
    padding: 12px 16px;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
}
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }

/* =====================================================
   Badges
   ===================================================== */
.badge {
    font-size: .72rem;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 500;
}

/* =====================================================
   Forms
   ===================================================== */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1px solid #d1d5db;
    padding: 10px 14px;
    font-size: .875rem;
    transition: var(--transition);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-label {
    font-weight: 500;
    font-size: .875rem;
    color: var(--text-primary);
    margin-bottom: 6px;
}
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* =====================================================
   Buttons
   ===================================================== */
.btn {
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    padding: 8px 18px;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn:active { opacity: .9; }
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
}
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

/* =====================================================
   Page Header
   ===================================================== */
.page-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}
.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}
.breadcrumb {
    font-size: .8rem;
    margin-bottom: 0;
}
.breadcrumb-item.active { color: var(--text-muted); }

/* =====================================================
   Notifications Dropdown
   ===================================================== */
.notification-dropdown {
    width: 320px;
    max-width: calc(100vw - 16px);
    max-height: 420px;
    overflow-y: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 1056;
}
.notification-item.unread { background: #eff6ff; }
.notification-item:hover { background: #f8fafc; }
.notif-icon {
    width: 32px;
    height: 32px;
    background: #eff6ff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =====================================================
   Calendar
   ===================================================== */
.fc {
    font-family: inherit;
    font-size: .825rem;
}
.fc .fc-toolbar-title { font-size: 1.1rem; font-weight: 600; }
.fc .fc-daygrid-event {
    border-radius: 4px;
    font-size: .75rem;
    padding: 2px 6px;
}
.fc .fc-button-primary {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    border-radius: var(--radius-sm) !important;
    font-size: .8rem !important;
}
.fc .fc-col-header-cell-cushion {
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* =====================================================
   Auth Pages
   ===================================================== */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--navbar-grad-from) 0%, var(--navbar-grad-to) 60%, var(--secondary) 100%);
    padding: 24px 16px;
}
.auth-card {
    width: 100%;
    max-width: 440px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 25px 50px rgba(0,0,0,.25);
    overflow: hidden;
}
.auth-header {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    padding: 32px 24px;
    text-align: center;
    color: white;
}
.auth-logo {
    width: 64px;
    height: 64px;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    margin: 0 auto 12px;
}
/* عندما يكون الشعار صورة مخصصة: نُزيل الدائرة ونعرضها بشكل مستطيل */
.auth-logo.auth-logo-img {
    width: auto;
    max-width: 200px;
    height: auto;
    min-height: 56px;
    border-radius: 14px;
    padding: 8px 20px;
    background: rgba(255,255,255,.15);
}
.auth-logo.auth-logo-img img {
    display: block;
    max-height: 56px;
    max-width: 180px;
    object-fit: contain;
}
.auth-body { padding: 28px; }

/* =====================================================
   Schedule Grid
   ===================================================== */
.schedule-day-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    transition: var(--transition);
}
.schedule-day-card:hover { border-color: var(--primary); }
.schedule-day-card.active { border-color: var(--primary); background: #eff6ff; }
.day-label {
    font-weight: 600;
    font-size: .9rem;
    margin-bottom: 10px;
}

/* =====================================================
   Time Slots
   ===================================================== */
.time-slots-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    margin-top: 12px;
}
.time-slot-btn {
    border: 1.5px solid var(--border-color);
    background: white;
    border-radius: 8px;
    padding: 8px;
    text-align: center;
    font-size: .8rem;
    cursor: pointer;
    transition: var(--transition);
}
.time-slot-btn:hover {
    border-color: var(--primary);
    background: #eff6ff;
    color: var(--primary);
}
.time-slot-btn.selected {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}
.time-slot-btn.booked {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
    cursor: not-allowed;
    pointer-events: none;
}

/* =====================================================
   Progress & Loading
   ===================================================== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.spinner-border-lg { width: 3rem; height: 3rem; }

/* =====================================================
   Empty State
   ===================================================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 3.5rem; opacity: .4; margin-bottom: 16px; display: block; }
.empty-state h5 { font-weight: 600; margin-bottom: 8px; color: #334155; }

/* =====================================================
   Alert
   ===================================================== */
.alert {
    border: none;
    border-radius: var(--radius-sm);
    font-size: .875rem;
}
.alert-success { background: #f0fdf4; color: #15803d; }
.alert-danger   { background: #fef2f2; color: #b91c1c; }
.alert-warning  { background: #fffbeb; color: #92400e; }
.alert-info     { background: #eff6ff; color: #1d4ed8; }

/* =====================================================
   Doctor Card
   ===================================================== */
.doctor-card {
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
}
.doctor-card:hover {
    box-shadow: var(--shadow-lg);
}
.doctor-card .doctor-avatar {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 700;
    color: white;
    margin: 0 auto 12px;
}

/* =====================================================
   Appointment Card
   ===================================================== */
.appointment-card {
    border-radius: var(--radius);
    border-left: 4px solid var(--primary);
    padding: 16px;
    background: white;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}
.appointment-card:hover { box-shadow: var(--shadow); }
.appointment-card.status-pending   { border-left-color: #d97706; }
.appointment-card.status-confirmed { border-left-color: #2563eb; }
.appointment-card.status-completed { border-left-color: #16a34a; }
.appointment-card.status-cancelled { border-left-color: #dc2626; background: #fafafa; }

/* =====================================================
   Responsive
   ===================================================== */
@media (max-width: 576px) {
    .main-content { padding: 12px; }
    .stat-card { padding: 14px; }
    .stat-card .stat-value { font-size: 1.5rem; }
    .stat-card .stat-icon { font-size: 1.5rem; }
    .page-title { font-size: 1.1rem; }
    .page-header { margin-bottom: 16px; padding-bottom: 12px; }

    /* ── جداول: تحويل كل صف إلى بطاقة ── */

    /* 1. أزل overflow من الغلاف حتى يظهر الظل */
    .table-responsive {
        overflow: visible !important;
    }

    /* 2. table + tbody يصبحان block */
    .table-responsive .table,
    .table-responsive .table tbody {
        display: block !important;
        width: 100% !important;
        border: none !important;
    }

    /* 3. إخفاء رأس الجدول */
    .table-responsive .table thead {
        display: none !important;
    }

    /* 4. كل صف = بطاقة */
    .table-responsive .table tbody tr {
        display: block !important;
        border-radius: 14px !important;
        margin-bottom: 10px !important;
        background: var(--card-bg, #fff) !important;
        box-shadow: 0 2px 12px rgba(0,0,0,.09) !important;
        border: 1px solid var(--border-color, #e2e8f0) !important;
        overflow: hidden !important;
    }
    .table-responsive .table tbody tr:hover {
        background: var(--card-bg, #fff) !important;
    }

    /* 5. كل خلية = صف label + value */
    .table-responsive .table tbody td {
        display: grid !important;
        grid-template-columns: 80px 1fr !important;
        align-items: center !important;
        gap: 6px !important;
        padding: 9px 14px !important;
        border: none !important;
        border-bottom: 1px solid var(--border-color, #f1f5f9) !important;
        font-size: .83rem !important;
        min-height: 0 !important;
        vertical-align: unset !important;
    }
    .table-responsive .table tbody td:last-child {
        border-bottom: none !important;
    }

    /* 6. pseudo-element = التسمية */
    .table-responsive .table tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-muted, #64748b);
        font-size: .69rem;
        opacity: .85;
        white-space: nowrap;
        grid-column: 1;
        grid-row: 1 / -1;   /* يمتد عبر كل صفوف الشبكة لتجنب اختلاط مع العناصر المتعددة */
        align-self: center;
    }

    /* 7. خلية الإجراءات: بدون تسمية، أزرار أفقية */
    /* يستهدف: "إجراءات" و "الإجراءات" بـ *= */
    .table-responsive .table tbody td[data-label*="جراءات"] {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        padding: 10px 14px !important;
        border-bottom: none !important;
        background: #f8fafc !important;
    }
    .table-responsive .table tbody td[data-label*="جراءات"]::before {
        display: none !important;
    }
    .table-responsive .table tbody td[data-label*="جراءات"] .d-flex,
    .table-responsive .table tbody td[data-label*="جراءات"] > div,
    .table-responsive .table tbody td[data-label*="جراءات"] > form {
        display: inline-flex !important;
    }

    /* Action buttons smaller on mobile */
    .btn-icon { width: 32px; height: 32px; font-size: .85rem; }

    /* Card padding */
    .card-body { padding: 12px; }
    .card-header { padding: 12px 14px; }

    /* Forms */
    .form-control, .form-select { padding: 8px 12px; }

    /* Page header wraps gracefully */
    .page-header { flex-direction: column; align-items: flex-start !important; gap: 8px; }
    .page-header .btn { width: 100%; justify-content: center; }

    /* Breadcrumb smaller */
    .breadcrumb { font-size: .8rem; margin-bottom: 0; }

    /* Row cards in forms: full width on xs */
    .row > [class*="col-md-"] { width: 100%; }

    /* Sidebar toggle & top navbar */
    .navbar-brand .fw-bold { font-size: .9rem; }
    .navbar .btn-icon { width: 32px; height: 32px; font-size: .85rem; }

    /* Auth card on very small screens */
    .auth-card { padding: 16px !important; border-radius: 12px; }
    .auth-header { padding: 20px 16px 12px !important; }
}

/* =====================================================
   Dark Mode
   — Bootstrap 5.3 يتولّى تلوين مكوناته عبر data-bs-theme="dark" (يُفعَّل بـ JS)
   — نُعرِّف هنا فقط متغيراتنا المخصصة + المكونات غير البوتستراب
   ===================================================== */

/* متغيرات مخصصة + color-scheme */
[data-bs-theme="dark"] {
    color-scheme: dark;
    --body-bg:      #0f172a;
    --card-bg:      #1e293b;
    --text-primary: #e2e8f0;
    --text-muted:   #94a3b8;
    --border-color: #334155;
    --sidebar-bg:   #0f172a;
    --sidebar-hover:#1e293b;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
    --shadow:    0 4px 6px -1px rgba(0,0,0,.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.3);
}

/* جسم الصفحة */
[data-bs-theme="dark"] body { background: var(--body-bg); color: var(--text-primary); }

/* إشعارات */
[data-bs-theme="dark"] .notification-item.unread { background: #0d2044; }
[data-bs-theme="dark"] .notification-item:hover  { background: #1e3a5f; }
[data-bs-theme="dark"] .notif-icon { background: #1e3a5f; }
[data-bs-theme="dark"] .dropdown-header { background: #162032; }

/* بطاقات الإحصاء */
[data-bs-theme="dark"] .stat-card { background: #1e293b; }
[data-bs-theme="dark"] .stat-card-primary { background: linear-gradient(135deg, #1e3a8a, #1d4ed8); }
[data-bs-theme="dark"] .stat-card-success { background: linear-gradient(135deg, #065f46, #047857); }
[data-bs-theme="dark"] .stat-card-info    { background: linear-gradient(135deg, #0a4c6a, #0284c7); }
[data-bs-theme="dark"] .stat-card-danger  { background: linear-gradient(135deg, #7f1d1d, #b91c1c); }

/* أوقات الحجز */
[data-bs-theme="dark"] .time-slot-btn { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-bs-theme="dark"] .time-slot-btn:hover { background: #162032; border-color: var(--primary); color: #93c5fd; }
[data-bs-theme="dark"] .time-slot-btn.selected { background: var(--primary); color: #fff; }
[data-bs-theme="dark"] .time-slot-btn.booked { background: #3b0d0d; border-color: #7f1d1d; color: #fca5a5; }

/* جدول العمل */
[data-bs-theme="dark"] .schedule-day-card { border-color: #334155; }
[data-bs-theme="dark"] .schedule-day-card.active { background: #0d2044; border-color: var(--primary); }

/* بطاقة الموعد */
[data-bs-theme="dark"] .appointment-card { background: #1e293b; }

/* صفحات المصادقة */
[data-bs-theme="dark"] .auth-card  { background: #1e293b; }
[data-bs-theme="dark"] .auth-body  { color: #e2e8f0; }

/* العناوين والحالات */
[data-bs-theme="dark"] .page-title        { color: #e2e8f0; }
[data-bs-theme="dark"] .empty-state h5    { color: #94a3b8; }

/* تنبيهات — ألوانها الافتراضية فاتحة فنُعيد تعريفها */
[data-bs-theme="dark"] .alert-success { background: #052e16; color: #6ee7b7; border-color: #065f46; }
[data-bs-theme="dark"] .alert-danger  { background: #3b0d0d; color: #fca5a5; border-color: #7f1d1d; }
[data-bs-theme="dark"] .alert-warning { background: #2d1b00; color: #fcd34d; border-color: #78350f; }
[data-bs-theme="dark"] .alert-info    { background: #0c1d3a; color: #93c5fd; border-color: #1e3a5f; }

/* Scrollbar */
[data-bs-theme="dark"] ::-webkit-scrollbar-track { background: #0f172a; }
[data-bs-theme="dark"] ::-webkit-scrollbar-thumb { background: #334155; }
[data-bs-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #475569; }

/* CSS fallback لعدم التوافق مع JS (نادر) */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --body-bg:      #0f172a;
        --card-bg:      #1e293b;
        --text-primary: #e2e8f0;
        --text-muted:   #94a3b8;
        --border-color: #334155;
        --sidebar-bg:   #0f172a;
        --sidebar-hover:#1e293b;
    }
}

/* =====================================================
   Dashboard appointment list — responsive (tablet & mobile)
   ===================================================== */
@media (max-width: 767.98px) {
    .appt-list-item,
    .appt-list-item.appt-fw {
        display: grid !important;
        grid-template-columns: 52px 1fr;
        gap: 2px 10px;
        padding: 12px 14px;
    }
    .appt-list-item.appt-fw {
        grid-template-areas:
            "time info1"
            "time info2"
            "acts acts";
        grid-template-rows: auto auto auto;
    }
    .appt-list-item:not(.appt-fw) {
        grid-template-areas:
            "time info1"
            "acts acts";
        grid-template-rows: auto auto;
    }
    .appt-list-item .appt-badge-time  { grid-area: time;  align-self: center; }
    .appt-list-item .appt-info:nth-of-type(1) { grid-area: info1; align-self: center; }
    .appt-list-item .appt-info:nth-of-type(2) { grid-area: info2; }
    .appt-list-item .appt-actions {
        grid-area: acts;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 6px;
        padding-top: 9px;
        margin-top: 4px;
        border-top: 1px solid var(--border-color, #e2e8f0);
    }
    .btn-appt { padding: 5px 14px; font-size: .78rem; }
}

/* =====================================================
   Print
   ===================================================== */
@media print {
    .sidebar, .top-navbar, .btn, .sidebar-toggle { display: none !important; }
    .main-content { margin: 0 !important; padding: 0 !important; }
}
