:root {
    --primary: #0a6e8a;
    --primary-light: #12a0c8;
    --primary-dark: #064d61;
    --accent: #00d4aa;
    --accent2: #ff6b6b;
    --accent3: #ffd166;
    --bg: #f0f4f8;
    --bg2: #e3edf5;
    --card: #ffffff;
    --sidebar: #071e2e;
    --sidebar-item: #0f3448;
    --text: #1a2e3b;
    --text-muted: #6b8fa6;
    --border: #d0e4ef;
    --success: #2ecc71;
    --warning: #f39c12;
    --danger: #e74c3c;
    --shadow: 0 4px 20px rgba(10,110,138,0.1);
    --shadow-lg: 0 8px 40px rgba(10,110,138,0.15);
    --radius: 14px;
    --radius-sm: 8px;
  }

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

  body {
    font-family: 'Cairo', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
  }

  /* ===== SIDEBAR ===== */
  .sidebar {
    width: 260px;
    min-height: 100vh;
    background: var(--sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: width 0.3s ease;
    box-shadow: -4px 0 20px rgba(0,0,0,0.3);
  }

  .sidebar-logo {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .logo-icon {
    width: 46px; height: 46px;
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
  }

  .logo-text h2 {
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
  }
  .logo-text span {
    color: var(--accent);
    font-size: 11px;
    font-weight: 400;
  }

  .sidebar-menu {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
  }

  .menu-section {
    margin-bottom: 8px;
  }
  .menu-section-label {
    font-size: 10px;
    font-weight: 600;
    color: rgba(255,255,255,0.25);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding: 10px 10px 6px;
  }

  .menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 3px;
    color: rgba(255,255,255,0.55);
    font-size: 14px;
    font-weight: 500;
    position: relative;
  }

  .menu-item:hover { background: var(--sidebar-item); color: #fff; }

  .menu-item.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    box-shadow: 0 4px 15px rgba(10,110,138,0.4);
  }

  .menu-item .icon { font-size: 18px; width: 22px; text-align: center; }

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

  .sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255,255,255,0.07);
  }

  .user-card {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    background: var(--sidebar-item);
    border-radius: 10px;
  }
  .user-avatar {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--accent), var(--primary-light));
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; color: #fff; font-weight: 700;
  }
  .user-info h4 { color: #fff; font-size: 13px; font-weight: 600; }
  .user-info span { color: rgba(255,255,255,0.4); font-size: 11px; }

  /* ===== MAIN CONTENT ===== */
  .main {
    margin-right: 260px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  /* ===== TOPBAR ===== */
  .topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  }

  .topbar-title h1 { font-size: 20px; font-weight: 700; color: var(--text); }
  .topbar-title p { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

  .topbar-actions { display: flex; align-items: center; gap: 12px; }

  .search-box {
    display: flex; align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 14px;
    gap: 8px;
    width: 240px;
    transition: all 0.2s;
  }
  .search-box:focus-within {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(18,160,200,0.1);
  }
  .search-box input {
    border: none; background: none; outline: none;
    font-family: 'Cairo', sans-serif;
    font-size: 13px; color: var(--text); flex: 1;
    text-align: right;
  }
  .search-box span { color: var(--text-muted); font-size: 14px; }

  .btn-icon {
    width: 38px; height: 38px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
    color: var(--text-muted);
    position: relative;
  }
  .btn-icon:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

  .notif-dot {
    position: absolute; top: 7px; right: 7px;
    width: 7px; height: 7px;
    background: var(--accent2);
    border-radius: 50%;
    border: 2px solid var(--card);
  }

  /* ===== PAGE CONTENT ===== */
  .page-content {
    flex: 1;
    padding: 24px 28px 110px; /* مساحة تحت عشان الزر العائم ميغطّيش على المحتوى */
    display: none;
  }
  .page-content.active { display: block; animation: fadeIn 0.3s ease; }

  @keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* ===== STATS CARDS ===== */
  .stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
    margin-bottom: 24px;
  }

  .stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
  }
  .stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

  .stat-card::before {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 80px; height: 80px;
    border-radius: 0 var(--radius) 0 80px;
    opacity: 0.1;
  }

  .stat-card.blue::before { background: var(--primary); }
  .stat-card.green::before { background: var(--success); }
  .stat-card.orange::before { background: var(--warning); }
  .stat-card.red::before { background: var(--danger); }

  .stat-icon {
    width: 46px; height: 46px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    margin-bottom: 14px;
  }

  .stat-card.blue .stat-icon { background: rgba(10,110,138,0.12); }
  .stat-card.green .stat-icon { background: rgba(46,204,113,0.12); }
  .stat-card.orange .stat-icon { background: rgba(243,156,18,0.12); }
  .stat-card.red .stat-icon { background: rgba(231,76,60,0.12); }

  .stat-card h3 { font-size: 28px; font-weight: 900; color: var(--text); line-height: 1; margin-bottom: 4px; }
  .stat-card p { font-size: 13px; color: var(--text-muted); font-weight: 400; }
  .stat-trend { font-size: 11px; margin-top: 8px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
  .stat-trend.up { color: var(--success); }
  .stat-trend.down { color: var(--danger); }

  /* ===== CARDS & SECTIONS ===== */
  .card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  .card-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .card-header h3 { font-size: 15px; font-weight: 700; color: var(--text); }
  .card-header p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

  .card-body { padding: 22px; }

  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
  .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; margin-bottom: 20px; }

  /* ===== BUTTONS ===== */
  .btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-family: 'Cairo', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
  }

  .btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    box-shadow: 0 4px 12px rgba(10,110,138,0.3);
  }
  .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(10,110,138,0.4); }

  .btn-success {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: #fff;
    box-shadow: 0 4px 12px rgba(46,204,113,0.3);
  }

  .btn-danger { background: linear-gradient(135deg, #c0392b, #e74c3c); color: #fff; }
  .btn-warning { background: linear-gradient(135deg, #e67e22, #f39c12); color: #fff; }
  .btn-secondary { background: linear-gradient(135deg, #8e44ad, #9b59b6); color: #fff; }
  .btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
  .btn-outline:hover { background: var(--primary); color: #fff; }
  .btn-sm { padding: 7px 14px; font-size: 12px; }
  .btn-xs { padding: 5px 10px; font-size: 11px; border-radius: 6px; }

  /* ===== TABLE ===== */
  .table-wrap { overflow-x: auto; }
  table { width: 100%; border-collapse: collapse; }
  thead tr { background: var(--bg); }
  th {
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: right;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }
  td {
    padding: 13px 16px;
    font-size: 13px;
    color: var(--text);
    border-bottom: 1px solid var(--bg);
    vertical-align: middle;
  }
  tbody tr:hover { background: var(--bg); }
  tbody tr:last-child td { border-bottom: none; }

  /* ===== STATUS BADGES ===== */
  .status {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
  }
  .status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
  .status-success { background: rgba(46,204,113,0.12); color: #1a9e4f; }
  .status-success::before { background: #2ecc71; }
  .status-warning { background: rgba(243,156,18,0.12); color: #c0850a; }
  .status-warning::before { background: #f39c12; }
  .status-danger { background: rgba(231,76,60,0.12); color: #b03a2e; }
  .status-danger::before { background: #e74c3c; }
  .status-info { background: rgba(10,110,138,0.1); color: var(--primary-dark); }
  .status-info::before { background: var(--primary-light); }

  /* ===== FORM ===== */
  .form-group { margin-bottom: 18px; }
  .form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 7px;
  }
  .form-label .required { color: var(--danger); margin-right: 3px; }
  .form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Cairo', sans-serif;
    font-size: 13px;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: all 0.2s;
    text-align: right;
  }
  .form-control:focus { border-color: var(--primary-light); background: #fff; box-shadow: 0 0 0 3px rgba(18,160,200,0.1); }
  select.form-control { cursor: pointer; }
  textarea.form-control { resize: vertical; min-height: 100px; }

  .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

  /* ===== MODAL ===== */
  .modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(7,30,46,0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
  }
  .modal-overlay.open { display: flex; animation: fadeIn 0.2s ease; }

  /* نوافذ التأكيد والتحذير وسبب الإلغاء فوق أي نافذة تانية دايماً */
  #confirmModal, #cancelReasonModal { z-index: 1100; }

  .modal {
    background: var(--card);
    border-radius: var(--radius);
    width: 90%;
    max-width: 620px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    animation: slideUp 0.3s ease;
  }
  @keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .modal-header h3 { font-size: 16px; font-weight: 700; }
  .modal-close {
    width: 32px; height: 32px;
    background: var(--bg);
    border: none; border-radius: 8px;
    cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    transition: all 0.2s;
  }
  .modal-close:hover { background: var(--danger); color: #fff; }
  .modal-body { padding: 24px; }
  .modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }

  /* ===== DASHBOARD SPECIFIC ===== */
  .appointments-today {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .appt-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg);
    border-radius: 10px;
    border-right: 3px solid transparent;
    transition: all 0.2s;
  }
  .appt-item:hover { border-right-color: var(--primary-light); background: rgba(18,160,200,0.05); }
  .appt-item.done { border-right-color: var(--success); }
  .appt-item.waiting { border-right-color: var(--warning); }
  .appt-item.next { border-right-color: var(--primary); background: rgba(10,110,138,0.05); }

  .appt-time {
    font-size: 13px; font-weight: 700; color: var(--primary);
    min-width: 50px; text-align: center;
  }
  .appt-info { flex: 1; }
  .appt-info strong { font-size: 13px; font-weight: 700; display: block; }
  .appt-info span { font-size: 11px; color: var(--text-muted); }
  .appt-num {
    font-size: 11px; font-weight: 700;
    background: var(--primary);
    color: #fff;
    padding: 3px 8px;
    border-radius: 6px;
  }

  /* ===== PATIENT CARD ===== */
  .patient-card-mini {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    background: var(--bg);
    border-radius: 10px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 8px;
  }
  .patient-card-mini:hover {
    border-color: var(--primary-light);
    box-shadow: 0 2px 10px rgba(10,110,138,0.1);
    transform: translateX(-3px);
  }
  .patient-avatar {
    width: 42px; height: 42px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 700; color: #fff;
    flex-shrink: 0;
  }
  .pa-blue { background: linear-gradient(135deg, var(--primary), var(--primary-light)); }
  .pa-green { background: linear-gradient(135deg, #27ae60, #2ecc71); }
  .pa-orange { background: linear-gradient(135deg, #e67e22, #f39c12); }
  .pa-purple { background: linear-gradient(135deg, #8e44ad, #9b59b6); }
  .pa-red { background: linear-gradient(135deg, #c0392b, #e74c3c); }

  .patient-info { flex: 1; }
  .patient-info strong { font-size: 14px; font-weight: 700; display: block; }
  .patient-info span { font-size: 11px; color: var(--text-muted); }
  .patient-meta { text-align: left; }
  .patient-meta small { font-size: 11px; color: var(--text-muted); display: block; }
  .patient-meta .pid { font-size: 12px; font-weight: 700; color: var(--primary); }

  /* ===== INVOICE ===== */
  .invoice-item {
    display: flex; align-items: center;
    gap: 12px; padding: 12px 0;
    border-bottom: 1px dashed var(--border);
  }
  .invoice-item:last-child { border-bottom: none; }
  .inv-desc { flex: 1; font-size: 13px; }
  .inv-qty { color: var(--text-muted); font-size: 12px; width: 40px; text-align: center; }
  .inv-price { font-weight: 700; font-size: 14px; color: var(--primary); width: 80px; text-align: left; }
  .inv-del { color: var(--danger); cursor: pointer; background: none; border: none; font-size: 16px; }

  .invoice-total {
    display: flex; justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    border-radius: var(--radius-sm);
    color: #fff;
    margin-top: 14px;
  }
  .invoice-total span { font-size: 13px; opacity: 0.8; }
  .invoice-total strong { font-size: 22px; font-weight: 900; }

  /* ===== CHARTS (CSS-based) ===== */
  .mini-chart {
    display: flex; align-items: flex-end;
    gap: 6px; height: 80px; padding: 0 4px;
  }
  .bar {
    flex: 1; border-radius: 4px 4px 0 0;
    background: linear-gradient(to top, var(--primary), var(--accent));
    opacity: 0.8;
    transition: opacity 0.2s;
    min-width: 18px;
  }
  .bar:hover { opacity: 1; }
  .bar.secondary { background: linear-gradient(to top, rgba(10,110,138,0.3), rgba(18,160,200,0.4)); }

  .chart-labels {
    display: flex; gap: 6px; padding: 4px 4px 0;
  }
  .chart-labels span {
    flex: 1; font-size: 10px; color: var(--text-muted);
    text-align: center; min-width: 18px;
  }

  .donut-wrap { position: relative; width: 120px; height: 120px; margin: 0 auto; }
  .donut-wrap svg { transform: rotate(-90deg); }
  .donut-center {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    font-weight: 700;
  }
  .donut-center strong { font-size: 22px; color: var(--text); }
  .donut-center span { font-size: 10px; color: var(--text-muted); }

  /* ===== CALENDAR ===== */
  .mini-calendar { user-select: none; }
  .cal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px;
  }
  .cal-header h4 { font-size: 14px; font-weight: 700; }
  .cal-nav {
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); font-size: 16px; padding: 4px 8px;
    border-radius: 6px; transition: all 0.2s;
  }
  .cal-nav:hover { background: var(--bg2); color: var(--primary); }
  .cal-grid {
    display: grid; grid-template-columns: repeat(7, 1fr);
    gap: 3px;
  }
  .cal-day-label {
    font-size: 10px; font-weight: 600; color: var(--text-muted);
    text-align: center; padding: 4px 0;
  }
  .cal-day {
    aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
    font-size: 12px; border-radius: 6px;
    cursor: pointer; transition: all 0.2s;
    position: relative;
  }
  .cal-day:hover { background: var(--bg2); }
  .cal-day.today { background: var(--primary); color: #fff; font-weight: 700; }
  .cal-day.has-appt::after {
    content: ''; position: absolute; bottom: 3px; right: 50%; transform: translateX(50%);
    width: 4px; height: 4px; background: var(--accent); border-radius: 50%;
  }
  .cal-day.other-month { color: var(--border); }

  /* ===== PRESCRIPTION ===== */
  .rx-item {
    display: flex; gap: 12px; align-items: center;
    padding: 10px 14px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
  }
  .rx-item .rx-name { flex: 1; font-weight: 600; font-size: 13px; }
  .rx-item .rx-dose { font-size: 12px; color: var(--primary); font-weight: 600; }
  .rx-item .rx-dur { font-size: 11px; color: var(--text-muted); }

  /* ===== NOTIFICATION TOAST ===== */
  .toast-container {
    position: fixed; top: 20px; left: 20px;
    z-index: 2147483647;
    pointer-events: none;
    display: flex; flex-direction: column; gap: 10px;
  }
  .toast {
    pointer-events: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-right: 4px solid var(--success);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    font-weight: 600;
    min-width: 260px;
    animation: slideLeft 0.3s ease;
    display: flex; align-items: center; gap: 10px;
  }
  .toast.error { border-right-color: var(--danger); }
  .toast.warning { border-right-color: var(--warning); }
  @keyframes slideLeft {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
  }

  /* ===== TABS ===== */
  .tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; margin-bottom: 20px; }
  .tab {
    flex: 1; padding: 9px; text-align: center;
    font-size: 13px; font-weight: 600;
    border-radius: 7px; cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
  }
  .tab.active { background: var(--card); color: var(--primary); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }

  /* ===== SCROLLBAR ===== */
  ::-webkit-scrollbar { width: 5px; height: 5px; }
  ::-webkit-scrollbar-track { background: var(--bg); }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--primary-light); }

  /* ===== PILL ===== */
  .pill {
    display: inline-flex; align-items: center;
    padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
  }
  .pill-primary { background: rgba(10,110,138,0.1); color: var(--primary-dark); }

  /* ===== REPORT CARDS ===== */
  .report-metric {
    text-align: center; padding: 20px;
    background: var(--bg);
    border-radius: var(--radius-sm);
  }
  .report-metric h2 { font-size: 32px; font-weight: 900; color: var(--primary); margin-bottom: 6px; }
  .report-metric p { font-size: 12px; color: var(--text-muted); }

  .progress-bar-wrap { margin: 8px 0; }
  .progress-bar-wrap label { font-size: 12px; color: var(--text-muted); margin-bottom: 5px; display: flex; justify-content: space-between; }
  .progress-bar { height: 8px; background: var(--bg2); border-radius: 20px; overflow: hidden; }
  .progress-fill { height: 100%; border-radius: 20px; }
  .pf-primary { background: linear-gradient(90deg, var(--primary), var(--primary-light)); }
  .pf-success { background: linear-gradient(90deg, #27ae60, #2ecc71); }
  .pf-warning { background: linear-gradient(90deg, #e67e22, #f39c12); }

  /* ===== SEARCHABLE PATIENT PICKER ===== */
  .patient-picker { position: relative; }
  .picker-input-wrap {
    display: flex; align-items: center;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    transition: all 0.2s;
    overflow: hidden;
  }
  .picker-input-wrap:focus-within {
    border-color: var(--primary-light);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(18,160,200,0.1);
  }
  .picker-search {
    flex: 1; border: none; background: none; outline: none;
    font-family: 'Cairo', sans-serif; font-size: 13px;
    color: var(--text); padding: 10px 14px; text-align: right;
  }
  .picker-clear {
    padding: 0 10px; cursor: pointer; color: var(--text-muted);
    font-size: 14px; background: none; border: none; display: none;
  }
  .picker-dropdown {
    position: absolute; top: calc(100% + 4px); right: 0; left: 0;
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
    z-index: 500; max-height: 220px; overflow-y: auto; display: none;
  }
  .picker-dropdown.open { display: block; animation: fadeIn 0.15s ease; }
  .picker-option {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; cursor: pointer; transition: background 0.15s;
  }
  .picker-option:hover { background: var(--bg); }
  .picker-option.selected { background: rgba(10,110,138,0.07); }
  .picker-option .po-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
  }
  .picker-option .po-info strong { font-size: 13px; font-weight: 700; display: block; }
  .picker-option .po-info span { font-size: 11px; color: var(--text-muted); }
  .picker-no-results { padding: 14px; font-size: 13px; color: var(--text-muted); text-align: center; }

  /* أجندة المواعيد */
  .agenda-slot {
    display: flex; gap: 14px; padding: 4px 0;
    border-bottom: 1px solid var(--bg); min-height: 56px;
  }
  .agenda-time {
    width: 60px; flex-shrink: 0; font-size: 12px; font-weight: 700;
    color: var(--text-muted); padding-top: 8px; text-align: left;
  }
  .agenda-events { flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
  .agenda-time-group { display: flex; gap: 8px; flex-wrap: wrap; }
  .agenda-time-group .agenda-event { flex: 1 1 0; min-width: 170px; }
  .agenda-event {
    border-radius: 9px; padding: 9px 12px; cursor: pointer;
    border-right: 3px solid; transition: transform 0.15s;
    display: flex; align-items: center; gap: 10px;
  }
  .agenda-event:hover { transform: translateX(-3px); }
  .agenda-event strong { font-size: 13px; font-weight: 700; }
  .agenda-event span { font-size: 11px; opacity: 0.85; }
  .agenda-empty-slot { flex:1; display:flex; align-items:center; }
  .agenda-add {
    font-size: 11px; color: var(--text-muted); cursor: pointer;
    padding: 6px 10px; border-radius: 7px; border: 1px dashed transparent;
    transition: all 0.15s; opacity: 0;
  }
  .agenda-slot:hover .agenda-add { opacity: 1; border-color: var(--border); }
  .agenda-add:hover { color: var(--primary); border-color: var(--primary-light); }

  /* أجندة المواعيد */
  .ev-pending { background: rgba(243,156,18,0.1); border-color: var(--warning); }
  .ev-confirmed { background: rgba(10,110,138,0.08); border-color: var(--primary); }
  .ev-done { background: rgba(46,204,113,0.1); border-color: var(--success); }
  .ev-cancelled { background: rgba(231,76,60,0.08); border-color: var(--danger); opacity: 0.6; }

  /* أزرار نتيجة المتابعة */
  .fu-outcome-btn {
    flex: 1; min-width: 90px; padding: 12px 8px; border-radius: 10px;
    border: 1.5px solid var(--border); background: var(--bg);
    font-family: 'Cairo', sans-serif; font-size: 13px; font-weight: 700;
    cursor: pointer; transition: all 0.2s; color: var(--text);
  }
  .fu-outcome-btn:hover { border-color: var(--primary-light); }
  .fu-outcome-btn.selected {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff; border-color: var(--primary);
    box-shadow: 0 3px 10px rgba(10,110,138,0.3);
  }

  /* البحث الشامل */
  .global-search-results {
    position: absolute; top: calc(100% + 8px); right: 0; left: 0;
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    max-height: 420px; overflow-y: auto; z-index: 700; display: none;
  }
  .global-search-results.open { display: block; }
  .gs-group-label {
    padding: 8px 14px; font-size: 11px; font-weight: 800; color: var(--text-muted);
    background: var(--bg); position: sticky; top: 0;
  }
  .gs-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    cursor: pointer; border-bottom: 1px solid var(--bg); transition: background 0.15s;
  }
  .gs-item:hover { background: var(--bg); }
  .gs-icon {
    width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 15px;
  }
  .gs-text strong { font-size: 13px; font-weight: 700; display: block; }
  .gs-text span { font-size: 11px; color: var(--text-muted); }
  .gs-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

  /* قوائم منسدلة (الجرس والملف الشخصي) */
  .dropdown-menu {
    position: absolute; top: calc(100% + 8px); left: 0;
    width: 290px; background: var(--card);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); z-index: 600;
    display: none; overflow: hidden;
    animation: fadeIn 0.15s ease;
  }
  .dropdown-menu.open { display: block; }
  .dropdown-head {
    padding: 12px 16px; font-size: 13px; font-weight: 700;
    border-bottom: 1px solid var(--border); background: var(--bg);
  }
  .dropdown-profile {
    display: flex; align-items: center; gap: 12px;
    padding: 16px; border-bottom: 1px solid var(--border);
  }
  .dropdown-item {
    padding: 12px 16px; font-size: 13px; font-weight: 600;
    cursor: pointer; transition: background 0.15s;
    display: flex; align-items: center; gap: 8px;
  }
  .dropdown-item:hover { background: var(--bg); color: var(--primary); }
  .notif-entry {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 16px; border-bottom: 1px solid var(--bg);
    cursor: pointer; transition: background 0.15s;
  }
  .notif-entry:hover { background: var(--bg); }
  .notif-entry .ne-icon {
    width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 16px;
  }
  .notif-entry .ne-text strong { font-size: 13px; font-weight: 700; display: block; }
  .notif-entry .ne-text span { font-size: 11px; color: var(--text-muted); }
  .notif-empty { padding: 30px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
  .notif-count-pill {
    margin-right: auto; background: var(--accent2); color: #fff;
    font-size: 11px; font-weight: 700; min-width: 22px; text-align: center;
    padding: 2px 7px; border-radius: 20px;
  }

  /* ===== PRINT STYLES ===== */
  @media print {
    body * { visibility: hidden !important; }
    #printArea, #printArea * { visibility: visible !important; }
    #printArea {
      position: fixed !important; top: 0; left: 0; right: 0;
      width: 100%; padding: 30px;
      background: #fff;
      font-family: 'Cairo', sans-serif;
      direction: rtl;
    }
  }
  .print-doc {
    font-family: 'Cairo', sans-serif;
    direction: rtl;
    padding: 30px;
    max-width: 750px;
    margin: 0 auto;
  }
  .print-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    border-bottom: 3px solid #0a6e8a; padding-bottom: 18px; margin-bottom: 20px;
  }
  .print-clinic h1 { font-size: 22px; font-weight: 900; color: #0a6e8a; }
  .print-clinic p { font-size: 12px; color: #555; margin-top: 4px; }
  .print-doc-title { text-align: left; }
  .print-doc-title h2 { font-size: 18px; font-weight: 700; }
  .print-doc-title span { font-size: 12px; color: #888; }
  .print-patient-box {
    background: #f0f4f8; padding: 14px 18px; border-radius: 8px;
    margin-bottom: 20px; display: flex; gap: 30px;
  }
  .print-patient-box div span { font-size: 11px; color: #666; display: block; }
  .print-patient-box div strong { font-size: 14px; font-weight: 700; }
  .print-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
  .print-table th { background: #0a6e8a; color: #fff; padding: 10px 12px; font-size: 13px; text-align: right; }
  .print-table td { padding: 10px 12px; font-size: 13px; border-bottom: 1px solid #e0e0e0; }
  .print-total { text-align: left; padding: 14px 18px; background: #071e2e; color: #fff; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
  .print-total span { font-size: 13px; opacity: 0.8; }
  .print-total strong { font-size: 22px; font-weight: 900; }
  .print-footer { margin-top: 30px; padding-top: 14px; border-top: 1px solid #ddd; text-align: center; font-size: 11px; color: #888; }

  /* ملخص اليوم */
  .ds-stats { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
  .ds-stat { flex: 1; min-width: 120px; background: #f4f8fa; border: 1px solid #e0e8ec; border-radius: 8px; padding: 10px 12px; text-align: center; }
  .ds-stat span { display: block; font-size: 11px; color: #666; margin-bottom: 4px; }
  .ds-stat strong { font-size: 17px; color: #0a6e8a; }
  .ds-section { font-size: 15px; color: #0a6e8a; margin: 18px 0 8px; padding-bottom: 5px; border-bottom: 2px solid #0a6e8a; }
  .ds-empty { color: #999; font-size: 13px; text-align: center; padding: 12px; background: #f9f9f9; border-radius: 8px; }
  .ds-badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; }
  .ds-done { background: #d5f4e6; color: #27ae60; }
  .ds-cancelled { background: #fadbd8; color: #c0392b; }
  .ds-postponed { background: #fdebd0; color: #e67e22; }
  .ds-confirmed { background: #d6eaf8; color: #2980b9; }
  .ds-pending { background: #fef9e7; color: #f39c12; }

  /* تقويم أعياد الميلاد */
  .bday-cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
  .bday-cal-weekdays > div { text-align: center; font-weight: 700; font-size: 12px; color: var(--text-muted); padding: 6px 0; }
  .bday-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
  .bday-cell { min-height: 78px; border: 1px solid var(--border); border-radius: 10px; padding: 6px; background: var(--card); display: flex; flex-direction: column; transition: all 0.15s; }
  .bday-cell.empty { background: transparent; border: none; }
  .bday-cell.has-bday { cursor: pointer; border-color: var(--primary); background: linear-gradient(135deg, rgba(10,110,138,0.06), rgba(10,110,138,0.02)); }
  .bday-cell.has-bday:hover { box-shadow: 0 4px 14px rgba(10,110,138,0.2); transform: translateY(-2px); }
  .bday-cell.is-today { outline: 2px solid var(--primary); outline-offset: 1px; }
  .bday-cell.is-past { opacity: 0.55; }
  .bday-cell-num { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
  .bday-cell.has-bday .bday-cell-num { color: var(--primary); }
  .bday-cell-cake { font-size: 18px; text-align: center; margin-top: auto; }
  .bday-cell-count { font-size: 10px; text-align: center; color: var(--primary); font-weight: 700; }
  .bday-cell-today-tag { font-size: 9px; color: #fff; background: var(--primary); border-radius: 4px; padding: 1px 4px; align-self: flex-start; margin-bottom: 2px; }
  .bday-list-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
  .bday-list-item:last-child { border-bottom: none; }
  .bday-list-date { background: var(--primary); color: #fff; border-radius: 8px; padding: 4px 10px; font-weight: 700; font-size: 13px; min-width: 54px; text-align: center; }
  .bday-list-date.passed { background: var(--text-muted); }
  .bday-list-date.is-today { background: #e67e22; }
  .print-rx-item { padding: 12px 0; border-bottom: 1px dashed #ddd; display: flex; gap: 20px; align-items: center; }
  .print-rx-item .med-name { font-weight: 700; font-size: 14px; flex: 1; }
  .print-rx-item .med-dose { font-size: 12px; color: #0a6e8a; font-weight: 600; }
  .print-rx-item .med-dur { font-size: 12px; color: #888; }
  .print-sig { margin-top: 40px; display: flex; justify-content: space-between; }
  .print-sig div { text-align: center; border-top: 1px solid #333; padding-top: 8px; width: 160px; font-size: 12px; }

  /* ===== MSG REMINDER ITEM ===== */
  .reminder-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; background: var(--bg);
    border-radius: 10px; border-right: 3px solid var(--primary-light);
  }
  .reminder-item .r-name { flex: 1; font-size: 13px; font-weight: 700; }
  .reminder-item .r-time { font-size: 11px; color: var(--text-muted); }
  .reminder-item .r-phone { font-size: 12px; color: var(--primary); font-weight: 600; }

  /* فلاتر المرضى */
  .patient-filter-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 7px 14px; border-radius: 20px;
    font-size: 12px; font-weight: 600; cursor: pointer;
    background: var(--bg); color: var(--text-muted);
    border: 1.5px solid var(--border); transition: all 0.2s;
    user-select: none;
  }
  .patient-filter-chip:hover { border-color: var(--primary-light); color: var(--primary); }
  .patient-filter-chip.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff; border-color: var(--primary);
    box-shadow: 0 3px 10px rgba(10,110,138,0.3);
  }
  .due-badge {
    display: inline-flex; align-items: center; gap: 4px;
    background: rgba(231,76,60,0.1); color: #b03a2e;
    font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  }
  .lapsed-badge {
    display: inline-flex; align-items: center; gap: 4px;
    background: rgba(243,156,18,0.12); color: #c0850a;
    font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  }

  /* عرض كروت المرضى (للموبايل) */
  .patients-card-view { display: none; padding: 14px; flex-direction: column; gap: 12px; }

  /* الزر العائم للإجراءات السريعة — تحت على الشمال */
  #fabWrap { position: fixed; bottom: 24px; left: 24px; z-index: 900; display: flex; flex-direction: column-reverse; align-items: flex-start; gap: 12px; pointer-events: none; }
  #fabMain {
    width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
    pointer-events: auto;
    background: var(--primary); color: #fff; font-size: 30px; font-weight: 300; line-height: 1;
    box-shadow: 0 6px 20px rgba(10,110,138,0.45); transition: transform 0.25s, background 0.2s;
    display: flex; align-items: center; justify-content: center;
  }
  #fabMain:hover { background: var(--primary-light); }
  #fabWrap.open #fabMain { transform: rotate(45deg); }
  #fabMenu { display: none; flex-direction: column-reverse; gap: 10px; align-items: flex-start;
    opacity: 0; transform: translateY(12px); transition: opacity 0.25s, transform 0.25s; pointer-events: none; }
  #fabWrap.open #fabMenu { display: flex; opacity: 1; pointer-events: auto; transform: translateY(0); }
  .fab-item { pointer-events: auto; }
  .fab-item {
    display: flex; align-items: center; gap: 10px; border: none; cursor: pointer; background: transparent; padding: 0;
  }
  .fab-label {
    background: #fff; color: var(--text); font-family: 'Cairo', sans-serif; font-weight: 700; font-size: 13px;
    padding: 8px 14px; border-radius: 10px; box-shadow: 0 3px 12px rgba(0,0,0,0.15); white-space: nowrap;
  }
  .fab-mini {
    width: 44px; height: 44px; border-radius: 50%; background: #fff; color: var(--primary);
    display: flex; align-items: center; justify-content: center; font-size: 20px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.2); flex-shrink: 0;
  }
  .fab-item:hover .fab-mini { background: var(--primary); }
  @media print { #fabWrap { display: none; } }
  .patients-table-view, .patients-card-view {
    max-height: 65vh;
    overflow-y: auto;
    padding-bottom: 70px;
    scrollbar-width: auto;
    scrollbar-color: var(--primary) #e8eef1;
  }
  .patients-table-view::-webkit-scrollbar,
  .patients-card-view::-webkit-scrollbar { width: 20px; transition: width 0.2s; }
  .patients-table-view:hover::-webkit-scrollbar,
  .patients-card-view:hover::-webkit-scrollbar { width: 30px; }
  .patients-table-view::-webkit-scrollbar-track,
  .patients-card-view::-webkit-scrollbar-track { background: #e8eef1; border-radius: 10px; }
  .patients-table-view::-webkit-scrollbar-thumb,
  .patients-card-view::-webkit-scrollbar-thumb {
    background: var(--primary); border-radius: 10px; border: 3px solid #e8eef1; min-height: 50px;
  }
  .patients-table-view:hover::-webkit-scrollbar-thumb,
  .patients-card-view:hover::-webkit-scrollbar-thumb {
    border-width: 4px; min-height: 70px;
  }
  .patients-table-view::-webkit-scrollbar-thumb:hover,
  .patients-card-view::-webkit-scrollbar-thumb:hover { background: var(--primary-light); }
  /* خلي رأس الجدول ثابت وانت بتنزل */
  .patients-table-view table thead th {
    position: sticky; top: 0; z-index: 2; background: var(--bg);
  }
  .pcard {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    background: var(--card);
  }
  .pcard-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
  .pcard-top .pcard-info { flex: 1; }
  .pcard-top .pcard-info strong { font-size: 15px; font-weight: 700; display: block; }
  .pcard-top .pcard-info span { font-size: 12px; color: var(--text-muted); }
  .pcard-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
  .pcard-meta .chip {
    font-size: 11px; padding: 4px 10px; border-radius: 20px;
    background: var(--bg); color: var(--text); font-weight: 600;
  }
  .pcard-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .pcard-actions .btn { justify-content: center; }

  /* زر القائمة للموبايل */
  .menu-toggle {
    display: none;
    width: 38px; height: 38px;
    background: var(--primary); color: #fff;
    border: none; border-radius: 10px;
    font-size: 18px; cursor: pointer;
    align-items: center; justify-content: center;
    margin-left: 4px;
  }
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(7,30,46,0.5);
    z-index: 99;
    backdrop-filter: blur(2px);
  }
  .sidebar-backdrop.open { display: block; }

  @media (max-width: 900px) {
    .menu-toggle { display: flex; }
    /* القائمة تفضل بعرضها الكامل وبأسمائها، بتطلع من جنب */
    .sidebar {
      width: 250px;
      transform: translateX(100%);
      transition: transform 0.3s ease;
    }
    .sidebar.open { transform: translateX(0); }
    /* الأسماء تفضل ظاهرة دايماً */
    .sidebar .logo-text,
    .sidebar .menu-item span,
    .sidebar .user-info,
    .menu-section-label,
    .badge { display: revert; }
    .main { margin-right: 0; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .search-box { display: flex; width: 100%; order: 10; margin-top: 8px; }
    .topbar-actions { flex-wrap: wrap; }
    .patient-search-box { display: flex !important; width: 100% !important; }
    .card-header { flex-wrap: wrap; gap: 10px; }
    /* قائمة المرضى: كروت بدل الجدول العريض */
    .patients-table-view { display: none; }
    .patients-card-view { display: flex; }
  }