/* ═══════════════════════════════════════════════════════
   Medical Center — Clean & Modern Light Design System
   ═══════════════════════════════════════════════════════ */

:root {
  /* Colors - Premium Medical Light Palette */
  --bg:          #f8fafc; /* Crisp Slate Light Background */
  --bg2:         #ffffff; /* Pure White Container / Sidebar */
  --surface:     #ffffff;
  --card:        #ffffff;
  --card2:       #f1f5f9;
  --border:      #e2e8f0;
  --border2:     #cbd5e1;

  /* Brand Colors */
  --blue:        #2563eb; /* Royal Medical Blue */
  --blue-d:      #1d4ed8;
  --purple:      #7c3aed;
  --cyan:        #0284c7;
  --green:       #059669;
  --orange:      #d97706;
  --red:         #dc2626;
  --pink:        #db2777;

  /* Text Colors */
  --text:        #0f172a; /* Slate 900 - High Contrast & Readability */
  --text2:       #475569; /* Slate 600 - Muted Body Text */
  --muted:       #64748b; /* Slate 500 - Subdued Hints */

  /* Glows & Shadows */
  --glow-blue:   rgba(37, 99, 235, 0.15);
  --glow-purple: rgba(124, 58, 237, 0.15);
  --glow-green:  rgba(5, 150, 105, 0.15);
  --glow-orange: rgba(217, 119, 6, 0.15);
  --glow-red:    rgba(220, 38, 38, 0.15);
  --glow-cyan:   rgba(2, 132, 199, 0.15);

  --shadow-sm:   0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md:   0 4px 16px -2px rgba(15, 23, 42, 0.06), 0 2px 6px -1px rgba(15, 23, 42, 0.03);
  --shadow-lg:   0 12px 30px -4px rgba(15, 23, 42, 0.08), 0 4px 12px -2px rgba(15, 23, 42, 0.04);

  /* Radius */
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;
  --r-xl: 24px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans Arabic', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  direction: rtl;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Typography ────────────────────────────────────── */
h1,h2,h3,h4 { font-weight: 700; line-height: 1.3; color: var(--text); }
p { line-height: 1.7; color: var(--text2); }

/* ── Utilities ─────────────────────────────────────── */
.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.relative { position: relative; }
.overflow-hidden { overflow: hidden; }

/* ── Grid ──────────────────────────────────────────── */
.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; }

/* ── Cards ─────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
  transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease;
}
.card:hover {
  border-color: var(--border2);
  box-shadow: var(--shadow-lg);
}
.card-sm { padding: 14px 16px; border-radius: var(--r); }
.card-glass {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(226,232,240,0.8);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
}

/* ── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--r); font-family: inherit;
  font-size: .88rem; font-weight: 600; cursor: pointer; transition: all .2s ease;
  border: none; text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--blue), var(--blue-d));
  color: #ffffff; box-shadow: 0 4px 14px rgba(37,99,235,0.28);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(37,99,235,0.4); filter: brightness(1.05); }
.btn-success {
  background: linear-gradient(135deg, #059669, var(--green));
  color: #ffffff; box-shadow: 0 4px 14px rgba(5,150,105,0.28);
}
.btn-success:hover { box-shadow: 0 6px 20px rgba(5,150,105,0.4); filter: brightness(1.05); }
.btn-warning {
  background: linear-gradient(135deg, #d97706, var(--orange));
  color: #ffffff; box-shadow: 0 4px 14px rgba(217,119,6,0.28);
}
.btn-danger {
  background: linear-gradient(135deg, #dc2626, var(--red));
  color: #ffffff; box-shadow: 0 4px 14px rgba(220,38,38,0.28);
}
.btn-purple {
  background: linear-gradient(135deg, #7c3aed, var(--purple));
  color: #ffffff; box-shadow: 0 4px 14px rgba(124,58,237,0.28);
}
.btn-outline {
  background: #ffffff; border: 1px solid var(--border);
  color: var(--text); box-shadow: var(--shadow-sm);
}
.btn-outline:hover { border-color: var(--blue); color: var(--blue); background: #eff6ff; }
.btn-ghost { background: #f1f5f9; border: 1px solid var(--border); color: var(--text2); }
.btn-ghost:hover { background: #e2e8f0; color: var(--text); }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: var(--r-lg); }
.btn-sm { padding: 6px 14px; font-size: .78rem; border-radius: var(--r-sm); }
.btn-icon { padding: 9px; border-radius: var(--r); }

/* ── Inputs ────────────────────────────────────────── */
.input-group { margin-bottom: 16px; }
.input-label { display: block; font-size: .82rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.input {
  width: 100%; padding: 12px 16px; background: #ffffff;
  border: 1px solid var(--border); border-radius: var(--r);
  color: var(--text); font-family: inherit; font-size: .9rem;
  transition: border-color .2s, box-shadow .2s, background .2s; outline: none;
  box-shadow: var(--shadow-sm);
}
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(37,99,235,0.12); background: #ffffff; }
.input::placeholder { color: #94a3b8; }
.input-icon { position: relative; }
.input-icon .input { padding-right: 44px; }
.input-icon .icon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 1.1rem; }
select.input { cursor: pointer; }

/* ── Badges ────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 11px; border-radius: 99px; font-size: .74rem; font-weight: 700;
}
.badge-blue   { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.badge-green  { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.badge-orange { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.badge-red    { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-purple { background: #f5f3ff; color: #6d28d9; border: 1px solid #ddd6fe; }
.badge-cyan   { background: #f0fdfa; color: #0f766e; border: 1px solid #99f6e4; }
.badge-gray   { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }

/* ── Status Dots ───────────────────────────────────── */
.status-dot { width:8px; height:8px; border-radius:50%; display:inline-block; flex-shrink:0; }
.dot-green  { background:var(--green); box-shadow:0 0 6px rgba(5,150,105,0.5); }
.dot-orange { background:var(--orange); box-shadow:0 0 6px rgba(217,119,6,0.5); }
.dot-red    { background:var(--red); box-shadow:0 0 6px rgba(220,38,38,0.5); }
.dot-gray   { background:var(--muted); }

/* ── Sidebar ───────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 260px; background: #ffffff;
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 50;
  box-shadow: 2px 0 20px rgba(15,23,42,0.03);
}
.sidebar-logo {
  padding: 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.sidebar-logo-icon {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  box-shadow: 0 4px 12px rgba(37,99,235,0.25); color: #ffffff;
}
.sidebar-logo-text { font-size: .98rem; font-weight: 800; color: var(--text); }
.sidebar-logo-sub  { font-size: .74rem; color: var(--muted); }

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-section-title {
  font-size: .68rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); padding: 10px 8px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--r); margin-bottom: 3px;
  cursor: pointer; transition: all .2s ease; font-size: .88rem; font-weight: 600;
  color: var(--text2); text-decoration: none; border: 1px solid transparent;
}
.nav-item:hover { background: #f8fafc; color: var(--text); border-color: var(--border); }
.nav-item.active {
  background: #eff6ff; color: var(--blue);
  border-color: #bfdbfe; font-weight: 700;
}
.nav-item .nav-icon { font-size: 1.1rem; flex-shrink: 0; }
.nav-item .nav-badge {
  margin-right: auto; background: var(--red); color: #ffffff;
  font-size: .65rem; font-weight: 700; padding: 1px 7px; border-radius: 99px;
}

.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); background: #ffffff; }

/* ── Main Layout ───────────────────────────────────── */
.with-sidebar { margin-right: 260px; min-height: 100vh; background: var(--bg); }
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255,255,255,0.88); backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-title { font-size: 1.15rem; font-weight: 800; color: var(--text); }
.main-content { padding: 24px; }

/* ── Stats Cards ───────────────────────────────────── */
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 20px; position: relative; overflow: hidden;
  box-shadow: var(--shadow-md); transition: all .25s ease;
}
.stat-card:hover { transform: translateY(-3px); border-color: var(--border2); box-shadow: var(--shadow-lg); }
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.stat-card.blue::before   { background: linear-gradient(90deg, var(--blue), var(--purple)); }
.stat-card.green::before  { background: linear-gradient(90deg, var(--green), var(--cyan)); }
.stat-card.orange::before { background: linear-gradient(90deg, var(--orange), var(--red)); }
.stat-card.purple::before { background: linear-gradient(90deg, var(--purple), var(--pink)); }
.stat-card.cyan::before   { background: linear-gradient(90deg, var(--cyan), var(--blue)); }
.stat-value { font-size: 2.1rem; font-weight: 800; margin: 8px 0 4px; color: var(--text); }
.stat-label { font-size: .82rem; font-weight: 600; color: var(--text2); }
.stat-icon  {
  position: absolute; left: 18px; top: 18px;
  font-size: 2.2rem; opacity: .12;
}
.stat-change { font-size: .78rem; font-weight: 600; color: var(--green); margin-top: 4px; }
.stat-change.neg { color: var(--red); }

/* ── Tables ────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); border: 1px solid var(--border); background: #ffffff; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; }
thead { background: #f8fafc; }
th {
  padding: 12px 16px; text-align: right; font-size: .75rem;
  font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text2); border-bottom: 1px solid var(--border);
}
td {
  padding: 14px 16px; font-size: .88rem; border-bottom: 1px solid var(--border);
  vertical-align: middle; color: var(--text);
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #f8fafc; }

/* ── Modal ─────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.45);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .25s ease;
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
  background: #ffffff; border: 1px solid var(--border);
  border-radius: var(--r-xl); padding: 28px; width: 100%; max-width: 520px;
  transform: scale(.96) translateY(16px); transition: transform .25s ease;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px -10px rgba(15,23,42,0.2);
}
.modal-backdrop.open .modal { transform: none; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.15rem; font-weight: 800; color: var(--text); }
.modal-close {
  background: #f1f5f9; border: 1px solid var(--border); color: var(--muted); cursor: pointer;
  font-size: 1.1rem; transition: all .2s ease; width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { color: var(--red); background: #fef2f2; border-color: #fecaca; }

/* ── Toasts ────────────────────────────────────────── */
.toast-container {
  position: fixed; top: 84px; left: 24px; z-index: 300;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  padding: 14px 20px; border-radius: var(--r); font-size: .88rem; font-weight: 600;
  border: 1px solid; display: flex; align-items: center; gap: 10px;
  backdrop-filter: blur(16px); min-width: 280px; max-width: 380px;
  animation: slideInLeft .3s ease; box-shadow: var(--shadow-lg);
}
.toast-success { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.toast-error   { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.toast-info    { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.toast-warn    { background: #fffbeb; border-color: #fde68a; color: #b45309; }

/* ── Queue Number Display ──────────────────────────── */
.queue-number {
  display: inline-flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 14px; font-size: 1.3rem;
  font-weight: 800; font-family: 'JetBrains Mono', monospace;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #ffffff; box-shadow: 0 4px 16px rgba(37,99,235,0.3);
}

/* ── Loading ───────────────────────────────────────── */
.spinner {
  width: 22px; height: 22px; border: 2px solid rgba(37,99,235,0.2);
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin .7s linear infinite; flex-shrink: 0;
}
.loading-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,0.85);
  backdrop-filter: blur(8px); z-index: 999;
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 16px;
}
.loading-overlay .spinner { width: 44px; height: 44px; border-width: 3px; color: var(--blue); }

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

/* ── Divider ───────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ── Animations ────────────────────────────────────── */
@keyframes fadeUp    { from{opacity:0;transform:translateY(16px)} to{opacity:1;transform:none} }
@keyframes fadeIn    { from{opacity:0} to{opacity:1} }
@keyframes slideInLeft { from{opacity:0;transform:translateX(-20px)} to{opacity:1;transform:none} }
@keyframes spin      { to{transform:rotate(360deg)} }
@keyframes pulse     { 0%,100%{opacity:1} 50%{opacity:.5} }

.fade-up { animation: fadeUp .4s ease both; }
.animate-pulse { animation: pulse 2s infinite; }

/* ── Responsive & Patient App Styling ───────── */
.bottom-nav {
  display: none;
}

@media (max-width: 1024px) {
  .sidebar { width: 230px; }
  .with-sidebar { margin-right: 230px; }
  .grid-4 { grid-template-columns: repeat(2,1fr); }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(100%); transition: transform .3s ease; }
  .sidebar.open { transform: none; }
  .with-sidebar { margin-right: 0; }
  .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }

  /* Mobile patient app navbar */
  body.role-patient {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }
  body.role-patient .sidebar,
  body.role-patient #sidebarToggle,
  body.role-patient #sidebarOverlay {
    display: none !important;
  }
  body.role-patient .with-sidebar {
    margin-right: 0 !important;
  }
  body.role-patient .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
  }
  body.role-patient .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    color: var(--text2);
    text-decoration: none;
    font-size: 0.72rem;
    font-weight: 600;
    transition: all 0.25s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }
  body.role-patient .bottom-nav-icon {
    font-size: 1.25rem;
    margin-bottom: 2px;
    transition: transform 0.2s ease;
  }
  body.role-patient .bottom-nav-item.active {
    color: var(--blue);
  }
  body.role-patient .bottom-nav-item.active .bottom-nav-icon {
    transform: scale(1.1);
    color: var(--blue);
  }
  body.role-patient .bottom-nav-item.active::after {
    content: '';
    position: absolute;
    bottom: 5px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--blue);
    box-shadow: 0 0 8px var(--blue);
  }
}

/* ── Desktop Optimization for Center Views ─────────── */
@media (min-width: 1025px) {
  .with-sidebar {
    margin-right: 260px;
    display: flex;
    flex-direction: column;
  }
  .main-content {
    max-width: 1600px;
    width: 100%;
    align-self: center;
    padding: 32px;
  }
  table th, table td {
    padding: 14px 20px;
  }
  .grid-4 {
    gap: 20px;
  }
}
