/* ═══════════════════════════════════════════════════════
   Smart Classroom — Sakura-Mauve Design System v4.1
   FIX: topbar desktop layout — brand position + actions overflow
   ═══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

/* ══ CSS VARIABLES ══ */
:root {
  --primary:        #C084FC;
  --primary-dark:   #9333EA;
  --primary-mid:    #A855F7;
  --primary-light:  #F5F0FF;
  --primary-glow:   rgba(192,132,252,0.18);

  --secondary:      #F472B6;
  --secondary-light:#FDF2F8;

  --accent:         #FB923C;
  --accent-light:   #FFF4ED;

  --teal:           #2DD4BF;
  --teal-light:     #F0FDFB;

  --danger:         #F43F5E;
  --danger-light:   #FFF1F3;

  --success:        #22C55E;
  --success-light:  #F0FDF4;

  --bg:             #FAF8FF;
  --surface:        #FFFFFF;
  --surface2:       #F7F3FF;
  --card-bg:        #FFFFFF;
  --card-border:    #EDE6F8;

  --text-primary:   #2D1B4E;
  --text-secondary: #7C6A96;
  --text-muted:     #B8A8D0;

  --border:         #EDE6F8;
  --input-bg:       #F7F3FF;

  --shadow-sm: 0 2px 10px rgba(147,51,234,0.08);
  --shadow-md: 0 4px 20px rgba(147,51,234,0.13);
  --shadow-lg: 0 8px 32px rgba(147,51,234,0.18);

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

  --sidebar-w: 300px;
  --topbar-h:  60px;
}

/* ══ DARK MODE ══ */
[data-theme="dark"] {
  --primary-light:  rgba(192,132,252,0.12);
  --secondary-light:rgba(244,114,182,0.1);
  --accent-light:   rgba(251,146,60,0.1);
  --teal-light:     rgba(45,212,191,0.1);
  --danger-light:   rgba(244,63,94,0.1);
  --success-light:  rgba(34,197,94,0.1);
  --bg:             #0F0A1A;
  --surface:        #1A1030;
  --surface2:       #221540;
  --card-bg:        #1A1030;
  --card-border:    rgba(192,132,252,0.12);
  --text-primary:   #F0E8FF;
  --text-secondary: #C4B0E0;
  --text-muted:     #7C6A96;
  --border:         rgba(192,132,252,0.12);
  --input-bg:       rgba(0,0,0,0.3);
}

/* ══ RESET ══ */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html, body { height:100%; overflow-x:hidden; scroll-behavior:smooth; overscroll-behavior:none; overscroll-behavior-y:none; }
body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  transition: background .3s, color .3s;
  -webkit-font-smoothing: antialiased;
}
::-webkit-scrollbar { width:4px; height:4px; }
::-webkit-scrollbar-track { background:transparent; }
::-webkit-scrollbar-thumb { background:var(--border); border-radius:4px; }

/* ══ OVERLAY ══ */
.overlay {
  position:fixed; inset:0;
  background:rgba(45,27,78,0.38);
  backdrop-filter:blur(3px);
  z-index:90; opacity:0; pointer-events:none;
  transition:opacity .3s;
}
.overlay.active { opacity:1; pointer-events:all; }

/* ══ DRAWER / SIDEBAR ══ */
.drawer {
  position:fixed; top:0; left:0; bottom:0;
  width:var(--sidebar-w);
  background:var(--surface);
  z-index:100;
  transform:translateX(-100%);
  transition:transform .35s cubic-bezier(.4,0,.2,1);
  display:flex; flex-direction:column;
  border-radius:0 var(--radius-xl) var(--radius-xl) 0;
  overflow:hidden;
  box-shadow:var(--shadow-lg);
}
.drawer.open { transform:translateX(0); }

[dir="rtl"] .drawer {
  left:auto; right:0;
  border-radius:var(--radius-xl) 0 0 var(--radius-xl);
  transform:translateX(100%);
}
[dir="rtl"] .drawer.open { transform:translateX(0); }

.drawer-header {
  background:linear-gradient(145deg,#9333EA 0%,#C084FC 50%,#F472B6 100%);
  padding:52px 24px 28px;
  position:relative; overflow:hidden;
}
.drawer-header::before {
  content:''; position:absolute;
  width:180px; height:180px; border-radius:50%;
  background:rgba(255,255,255,0.1);
  top:-60px; right:-40px;
}
.drawer-header::after {
  content:''; position:absolute;
  width:90px; height:90px; border-radius:50%;
  background:rgba(255,255,255,0.07);
  bottom:-25px; left:20px;
}
.drawer-close {
  position:absolute; top:16px; right:16px;
  width:32px; height:32px;
  background:rgba(255,255,255,0.22);
  border:none; border-radius:50%;
  color:#fff; cursor:pointer; font-size:15px;
  display:flex; align-items:center; justify-content:center;
  z-index:1; transition:background .2s;
}
[dir="rtl"] .drawer-close { right:auto; left:16px; }
.drawer-close:hover { background:rgba(255,255,255,0.35); }
.drawer-avatar {
  width:62px; height:62px;
  background:rgba(255,255,255,0.22);
  border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  font-size:26px; margin-bottom:12px;
  position:relative; z-index:1;
  border:2px solid rgba(255,255,255,0.45);
  overflow:hidden;
}
.drawer-avatar img { width:100%; height:100%; object-fit:cover; border-radius:50%; }
.drawer-name { color:#fff; font-size:17px; font-weight:700; position:relative; z-index:1; }
.drawer-role {
  display:inline-flex; align-items:center; gap:5px;
  background:rgba(255,255,255,0.2);
  color:rgba(255,255,255,0.92);
  font-size:12px; font-weight:500;
  padding:3px 10px; border-radius:20px;
  margin-top:6px; position:relative; z-index:1;
}
.drawer-role::before {
  content:''; width:6px; height:6px;
  background:#86efac; border-radius:50%; display:inline-block;
}

.drawer-nav { flex:1; overflow-y:auto; padding:16px 12px; scrollbar-width:none; }
.drawer-nav::-webkit-scrollbar { display:none; }

.nav-group-label {
  font-size:10px; font-weight:700;
  text-transform:uppercase; letter-spacing:1.2px;
  color:var(--text-muted);
  padding:8px 12px 6px; margin-top:8px;
}
.nav-item {
  display:flex; align-items:center; gap:13px;
  padding:11px 14px; border-radius:var(--radius-sm);
  cursor:pointer; font-size:14px; font-weight:500;
  color:var(--text-secondary);
  transition:all .2s; margin-bottom:2px;
  text-decoration:none;
}
.nav-item:hover { background:var(--surface2); color:var(--text-primary); }
.nav-item.active { background:var(--primary-light); color:var(--primary-dark); font-weight:600; }
.nav-icon {
  width:36px; height:36px; border-radius:10px;
  display:flex; align-items:center; justify-content:center;
  font-size:18px; flex-shrink:0;
  background:var(--surface2); transition:background .2s;
}
.nav-item.active .nav-icon { background:var(--primary-light); }
.nav-badge {
  margin-left:auto;
  background:var(--danger); color:#fff;
  font-size:10px; font-weight:700;
  padding:1px 7px; border-radius:20px;
}
[dir="rtl"] .nav-badge { margin-left:0; margin-right:auto; }

.drawer-footer { padding:12px 12px 24px; border-top:1px solid var(--border); }
.drawer-lang-btn {
  display:flex; align-items:center; gap:10px;
  padding:11px 14px; border-radius:var(--radius-sm);
  cursor:pointer; font-size:14px; font-weight:500;
  color:var(--text-secondary);
  background:var(--surface2); margin-bottom:8px;
  border:1px solid var(--border); transition:background .2s;
}
.emergency-btn {
  display:flex; align-items:center; justify-content:center; gap:8px;
  padding:13px; border-radius:var(--radius-sm);
  background:linear-gradient(135deg,#F43F5E,#E11D48);
  color:#fff; font-size:14px; font-weight:700;
  cursor:pointer; margin-bottom:8px;
  box-shadow:0 4px 14px rgba(244,63,94,0.35);
  transition:opacity .2s; border:none; width:100%;
}
.emergency-btn:active { opacity:.85; }
.logout-btn {
  display:flex; align-items:center; gap:10px;
  padding:11px 14px; border-radius:var(--radius-sm);
  cursor:pointer; font-size:14px; font-weight:500;
  color:var(--danger); transition:background .2s;
  background:none; border:none; width:100%;
}
.logout-btn:hover { background:var(--danger-light); }

/* ══ TOPBAR ══ */
.topbar {
  background:var(--surface);
  padding:0 20px;
  display:flex;
  align-items:center;
  gap:12px;
  position:sticky;
  top:0;
  z-index:80;
  box-shadow:0 1px 0 var(--border);
  height:var(--topbar-h);
  width:100%;
  /* ✅ FIX: منع الأيقونات من الخروج خارج الشاشة */
  overflow:hidden;
}
.topbar-menu {
  width:40px; height:40px;
  background:var(--surface2);
  border:1px solid var(--border);
  border-radius:12px;
  display:flex; align-items:center; justify-content:center;
  cursor:pointer; font-size:18px; color:var(--text-primary);
  flex-shrink:0; transition:background .2s; border:none;
}
.topbar-menu:active { background:var(--primary-light); color:var(--primary-dark); }

/* ✅ FIX: topbar-brand لا يأخذ margin auto — بيدفع الـ actions للخارج */
.topbar-brand {
  font-size:17px;
  font-weight:800;
  color:var(--text-primary);
  letter-spacing:-.3px;
  flex-shrink:0;
  /* لا margin auto هنا */
}
.topbar-brand span { color:var(--primary-dark); }

/* ✅ FIX: topbar-actions تأخذ margin-left:auto دائماً وتكون flex-shrink:0 */
.topbar-actions {
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:8px;
  flex-shrink:0; /* ✅ مهم جداً — منع الضغط على العناصر */
}
[dir="rtl"] .topbar-actions {
  margin-left:0;
  margin-right:auto;
  flex-direction:row-reverse;
}
.topbar-btn {
  width:38px; height:38px;
  background:var(--surface2); border:1px solid var(--border);
  border-radius:12px;
  display:flex; align-items:center; justify-content:center;
  cursor:pointer; font-size:17px; position:relative;
  transition:background .2s;
  flex-shrink:0;
}
.topbar-btn:active { background:var(--primary-light); }
.topbar-notif-dot {
  position:absolute; top:6px; right:6px;
  width:7px; height:7px;
  background:var(--danger); border-radius:50%;
  border:1.5px solid var(--surface);
}
.topbar-avatar {
  width:38px; height:38px;
  background:linear-gradient(135deg,#9333EA,#F472B6);
  border-radius:12px;
  display:flex; align-items:center; justify-content:center;
  font-size:14px; font-weight:700; color:#fff;
  cursor:pointer; overflow:hidden; flex-shrink:0;
}
.topbar-avatar img { width:100%; height:100%; object-fit:cover; }

/* ══ MAIN CONTENT ══ */
.main { padding:20px 16px 100px; overscroll-behavior:none; transition:margin-left .35s; }

/* ══ WELCOME CARD ══ */
.welcome-card {
  background:linear-gradient(145deg,#9333EA 0%,#C084FC 55%,#F472B6 100%);
  border-radius:var(--radius-lg);
  padding:22px 20px;
  margin-bottom:20px;
  position:relative; overflow:hidden;
  box-shadow:0 8px 28px rgba(147,51,234,0.28);
}
.welcome-card::before {
  content:''; position:absolute;
  width:160px; height:160px; border-radius:50%;
  background:rgba(255,255,255,0.09);
  top:-50px; right:-30px;
}
.welcome-card::after {
  content:''; position:absolute;
  width:80px; height:80px; border-radius:50%;
  background:rgba(255,255,255,0.07);
  bottom:-20px; left:30px;
}
.welcome-label { font-size:13px; font-weight:500; color:rgba(255,255,255,0.78); margin-bottom:3px; position:relative; z-index:1; }
.welcome-name { font-size:22px; font-weight:800; color:#fff; position:relative; z-index:1; margin-bottom:14px; }
.welcome-chips { display:flex; gap:8px; flex-wrap:wrap; position:relative; z-index:1; }
.welcome-chip {
  background:rgba(255,255,255,0.2);
  color:#fff; font-size:12px; font-weight:600;
  padding:4px 12px; border-radius:20px;
  backdrop-filter:blur(4px);
  border:1px solid rgba(255,255,255,0.22);
}

/* ══ SECTION HEADER ══ */
.section-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; margin-top:4px; }
.section-title { font-size:15px; font-weight:700; color:var(--text-primary); }
.section-link { font-size:13px; font-weight:600; color:var(--primary-dark); cursor:pointer; text-decoration:none; }

/* ══ STATS GRID ══ */
.stats-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:20px; }
.stat-card {
  background:var(--surface);
  border-radius:var(--radius-md);
  padding:18px 16px;
  box-shadow:var(--shadow-sm);
  border:1px solid var(--border);
  position:relative; overflow:hidden;
  transition:transform .2s, box-shadow .2s;
  cursor:pointer;
}
.stat-card:active { transform:scale(.97); }
.stat-card.wide { grid-column:span 2; display:flex; align-items:center; gap:16px; }
.stat-card.wide .stat-icon { margin-bottom:0; }
.stat-card.wide .stat-info { flex:1; }
.stat-icon {
  width:46px; height:46px; border-radius:14px;
  display:flex; align-items:center; justify-content:center;
  font-size:22px; margin-bottom:12px; flex-shrink:0;
}
.stat-value { font-size:32px; font-weight:800; line-height:1; margin-bottom:4px; letter-spacing:-1px; }
.stat-label { font-size:12px; font-weight:500; color:var(--text-secondary); }
.stat-trend {
  position:absolute; top:14px; right:14px;
  font-size:10px; font-weight:700;
  padding:2px 7px; border-radius:20px;
}
[dir="rtl"] .stat-trend { right:auto; left:14px; }

/* Card colour roles */
.card-violet .stat-icon { background:var(--primary-light); }
.card-violet .stat-value { color:var(--primary-dark); }
.card-pink .stat-icon { background:var(--secondary-light); }
.card-pink .stat-value { color:#DB2777; }
.card-orange .stat-icon { background:var(--accent-light); }
.card-orange .stat-value { color:var(--accent); }
.card-teal .stat-icon { background:var(--teal-light); }
.card-teal .stat-value { color:#0D9488; }
.card-mauve .stat-icon { background:var(--primary-light); }
.card-mauve .stat-value { color:var(--primary); }
.card-red .stat-icon { background:var(--danger-light); }
.card-red .stat-value { color:var(--danger); }

/* ══ CHART CARD ══ */
.chart-card {
  background:var(--surface);
  border-radius:var(--radius-md);
  padding:18px;
  box-shadow:var(--shadow-sm);
  border:1px solid var(--border);
  margin-bottom:20px;
}
.chart-placeholder {
  height:120px;
  background:var(--surface2);
  border-radius:var(--radius-sm);
  display:flex; align-items:flex-end; gap:6px;
  padding:12px; margin-top:14px; overflow:hidden;
}
.bar { flex:1; border-radius:4px 4px 0 0; animation:barGrow .8s ease both; transform-origin:bottom; }
@keyframes barGrow { from{transform:scaleY(0);opacity:0} to{transform:scaleY(1);opacity:1} }
.chart-labels { display:flex; gap:6px; margin-top:6px; }
.chart-label { flex:1; text-align:center; font-size:10px; font-weight:500; color:var(--text-muted); }

/* ══ QUICK ACTIONS ══ */
.quick-actions { display:grid; grid-template-columns:repeat(4,1fr); gap:10px; margin-bottom:20px; }
.action-btn { display:flex; flex-direction:column; align-items:center; gap:7px; cursor:pointer; transition:transform .15s; text-decoration:none; }
.action-btn:active { transform:scale(.92); }
.action-icon { width:54px; height:54px; border-radius:16px; display:flex; align-items:center; justify-content:center; font-size:24px; box-shadow:var(--shadow-sm); }
.action-label { font-size:11px; font-weight:600; color:var(--text-secondary); text-align:center; line-height:1.3; }

/* ══ AI ALERT ══ */
.ai-alert {
  background:linear-gradient(135deg,var(--primary-light),#F5F0FF);
  border:1px solid rgba(168,85,247,0.18);
  border-radius:var(--radius-md);
  padding:14px 16px;
  display:flex; align-items:center; gap:12px;
  margin-bottom:20px; cursor:pointer; transition:transform .15s;
}
[data-theme="dark"] .ai-alert { background:rgba(147,51,234,0.12); }
.ai-alert:active { transform:scale(.98); }
.ai-alert-icon { width:40px; height:40px; background:linear-gradient(135deg,#9333EA,#C084FC); border-radius:12px; display:flex; align-items:center; justify-content:center; font-size:20px; flex-shrink:0; }
.ai-alert-title { font-size:13px; font-weight:700; color:var(--primary-dark); margin-bottom:2px; }
.ai-alert-sub { font-size:11px; color:var(--text-secondary); }
.ai-alert-arrow { color:var(--primary-dark); font-size:18px; margin-left:auto; }
[dir="rtl"] .ai-alert-arrow { margin-left:0; margin-right:auto; transform:scaleX(-1); }

/* ══ ACTIVITY ══ */
.activity-card { background:var(--surface); border-radius:var(--radius-md); padding:18px; box-shadow:var(--shadow-sm); border:1px solid var(--border); margin-bottom:12px; }
.activity-item { display:flex; align-items:center; gap:13px; padding:10px 0; border-bottom:1px solid var(--border); }
.activity-item:last-child { border-bottom:none; padding-bottom:0; }
.activity-item:first-child { padding-top:0; }
.activity-dot { width:38px; height:38px; border-radius:12px; display:flex; align-items:center; justify-content:center; font-size:18px; flex-shrink:0; }
.activity-text { flex:1; }
.activity-title { font-size:13px; font-weight:600; color:var(--text-primary); margin-bottom:2px; }
.activity-sub { font-size:11px; color:var(--text-muted); }
.activity-time { font-size:10px; font-weight:500; color:var(--text-muted); white-space:nowrap; }

/* ══ GENERIC CARD ══ */
.card {
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-md);
  padding:18px;
  box-shadow:var(--shadow-sm);
  margin-bottom:16px;
}
.card h2, .card h3 { color:var(--text-primary); margin-bottom:12px; }

/* ══ TABLE ══ */
.table-wrap { overflow-x:auto; border-radius:var(--radius-sm); }
table { width:100%; border-collapse:collapse; font-size:13px; }
th { background:var(--surface2); color:var(--text-secondary); font-weight:600; font-size:11px; text-transform:uppercase; letter-spacing:.5px; padding:10px 14px; text-align:left; }
[dir="rtl"] th { text-align:right; }
td { padding:12px 14px; color:var(--text-primary); border-bottom:1px solid var(--border); }
tr:last-child td { border-bottom:none; }
tr:hover td { background:var(--surface2); }

/* ══ FORM INPUTS ══ */
.input {
  width:100%; padding:13px 16px;
  background:var(--input-bg);
  border:1.5px solid var(--border);
  border-radius:var(--radius-sm);
  color:var(--text-primary);
  font-size:14px; font-family:inherit;
  outline:none; transition:border-color .2s;
  margin-bottom:12px;
}
.input:focus { border-color:var(--primary); }
.input::placeholder { color:var(--text-muted); }

select.input { cursor:pointer; }

/* ══ BUTTONS ══ */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  padding:12px 20px; border-radius:var(--radius-sm);
  font-size:14px; font-weight:700; font-family:inherit;
  cursor:pointer; border:none; transition:all .2s;
}
.btn-primary { background:linear-gradient(135deg,#9333EA,#C084FC); color:#fff; box-shadow:0 4px 14px rgba(147,51,234,.3); }
.btn-primary:active { opacity:.88; }
.btn-danger  { background:linear-gradient(135deg,#F43F5E,#E11D48); color:#fff; box-shadow:0 4px 14px rgba(244,63,94,.3); }
.btn-success { background:linear-gradient(135deg,#22C55E,#16A34A); color:#fff; }
.btn-outline { background:transparent; border:1.5px solid var(--border); color:var(--text-secondary); }
.btn-outline:hover { border-color:var(--primary); color:var(--primary-dark); }
.btn-block { width:100%; }

/* ══ BOTTOM NAV ══ */
.bottom-nav {
  position:fixed; bottom:0; left:0; right:0;
  background:var(--surface);
  border-top:1px solid var(--border);
  display:flex; padding:8px 0 max(16px,env(safe-area-inset-bottom));
  z-index:70;
  box-shadow:0 -4px 20px rgba(147,51,234,0.08);
}
.nav-tab {
  flex:1; display:flex; flex-direction:column; align-items:center; gap:3px;
  cursor:pointer; position:relative; padding:4px 0;
  color:var(--text-muted); font-size:10px; font-weight:600;
  transition:color .2s; text-decoration:none; background:none; border:none;
}
.nav-tab.active { color:var(--primary-dark); }
.nav-tab-icon { font-size:20px; transition:transform .2s; }
.nav-tab.active .nav-tab-icon { transform:translateY(-2px); }
.nav-tab-dot {
  position:absolute; top:2px; right:calc(50% - 14px);
  width:6px; height:6px;
  background:var(--danger); border-radius:50%;
  border:1.5px solid var(--surface);
}

/* ══ BADGE ══ */
.badge {
  display:inline-block; padding:2px 8px; border-radius:20px;
  font-size:10px; font-weight:700;
}
.badge-violet { background:var(--primary-light); color:var(--primary-dark); }
.badge-teal   { background:var(--teal-light);    color:#0D9488; }
.badge-orange { background:var(--accent-light);  color:var(--accent); }
.badge-pink   { background:var(--secondary-light);color:#DB2777; }
.badge-red    { background:var(--danger-light);  color:var(--danger); }
.badge-green  { background:var(--success-light); color:var(--success); }

/* ══ LOADER ══ */
#global-loader {
  position:fixed; inset:0;
  background:var(--bg);
  display:flex; align-items:center; justify-content:center;
  flex-direction:column; gap:16px;
  z-index:9999; transition:opacity .4s;
}
#global-loader.hidden { opacity:0; pointer-events:none; }
.loader-icon { width:64px; height:64px; border-radius:20px; animation:pulse 1.5s ease infinite; }
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.08)} }
.loader-ring {
  width:40px; height:40px;
  border:3px solid var(--primary-light);
  border-top-color:var(--primary);
  border-radius:50%;
  animation:spin .8s linear infinite;
}
@keyframes spin { to{transform:rotate(360deg)} }

/* ══ TOAST ══ */
#toast-container {
  position:fixed; top:calc(var(--topbar-h) + 8px); right:16px;
  z-index:9998; display:flex; flex-direction:column; gap:8px;
}
[dir="rtl"] #toast-container { right:auto; left:16px; }
.toast {
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius-sm); padding:12px 16px;
  display:flex; align-items:center; gap:10px;
  box-shadow:var(--shadow-md); font-size:13px; font-weight:600;
  color:var(--text-primary); min-width:220px; max-width:320px;
  animation:slideIn .3s ease;
}
@keyframes slideIn { from{transform:translateX(100%);opacity:0} to{transform:translateX(0);opacity:1} }

/* ══ FADE IN ══ */
.fade-in { animation:fadeIn .5s ease both; }
@keyframes fadeIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }
.fade-in:nth-child(1){animation-delay:.05s}
.fade-in:nth-child(2){animation-delay:.1s}
.fade-in:nth-child(3){animation-delay:.15s}
.fade-in:nth-child(4){animation-delay:.2s}
.fade-in:nth-child(5){animation-delay:.25s}

/* ══ PAGE-SPECIFIC ══ */

/* Login */
.login-page {
  min-height:100vh; display:flex; align-items:center; justify-content:center;
  padding:24px;
  background:linear-gradient(160deg, var(--primary-light) 0%, var(--bg) 60%);
}
.login-card {
  background:var(--surface); border-radius:var(--radius-lg);
  padding:32px 24px; width:100%; max-width:420px;
  box-shadow:var(--shadow-lg); border:1px solid var(--border);
}
.login-logo { text-align:center; margin-bottom:28px; }
.login-logo img { width:64px; height:64px; border-radius:18px; }
.login-title { font-size:22px; font-weight:800; color:var(--text-primary); text-align:center; margin-bottom:6px; }
.login-sub   { font-size:13px; color:var(--text-muted); text-align:center; margin-bottom:24px; }
.login-tabs  { display:flex; gap:8px; margin-bottom:24px; background:var(--surface2); border-radius:12px; padding:4px; }
.login-tab   { flex:1; padding:9px; text-align:center; border-radius:10px; cursor:pointer; font-size:13px; font-weight:600; color:var(--text-muted); transition:.2s; }
.login-tab.active { background:var(--primary); color:#fff; }
.field-label { font-size:12px; font-weight:600; color:var(--text-secondary); margin-bottom:6px; display:block; }
.alert { padding:12px 16px; border-radius:var(--radius-sm); font-size:13px; font-weight:600; margin-bottom:14px; display:none; }
.alert-error   { background:var(--danger-light); color:var(--danger); }
.alert-success { background:var(--success-light); color:var(--success); }
.alert-info    { background:var(--primary-light); color:var(--primary-dark); }

/* Messages */
.messages-layout {
  position:fixed; top:var(--topbar-h); left:0; right:0; bottom:60px;
  display:flex; background:var(--bg);
}
.conv-panel { width:320px; min-width:280px; background:var(--surface); border-right:1px solid var(--border); display:flex; flex-direction:column; flex-shrink:0; }
[dir="rtl"] .conv-panel { border-right:none; border-left:1px solid var(--border); }
.conv-panel-hdr { padding:14px 16px; border-bottom:1px solid var(--border); display:flex; align-items:center; gap:10px; }
.conv-panel-hdr h2 { flex:1; font-size:16px; font-weight:700; color:var(--text-primary); margin:0; }
.conv-search-wrap { padding:10px 12px; border-bottom:1px solid var(--border); position:relative; }
.conv-search-inp { width:100%; padding:8px 12px 8px 32px; background:var(--surface2); border:1.5px solid var(--border); border-radius:24px; color:var(--text-primary); font-size:13px; outline:none; }
.conv-list { flex:1; overflow-y:auto; }
.conv-item { display:flex; align-items:center; gap:12px; padding:14px 16px; cursor:pointer; border-bottom:1px solid var(--border); transition:background .15s; }
.conv-item:hover, .conv-item.active { background:var(--surface2); }
.conv-av { width:42px; height:42px; background:linear-gradient(135deg,#9333EA,#C084FC); border-radius:14px; display:flex; align-items:center; justify-content:center; font-size:16px; font-weight:700; color:#fff; flex-shrink:0; }
.conv-info { flex:1; min-width:0; }
.conv-name { font-size:14px; font-weight:600; color:var(--text-primary); }
.conv-last { font-size:12px; color:var(--text-muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-top:2px; }
.conv-meta { display:flex; flex-direction:column; align-items:flex-end; gap:4px; }
.conv-time { font-size:10px; color:var(--text-muted); }
.chat-area { flex:1; display:flex; flex-direction:column; overflow:hidden; }
.chat-welcome { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px; color:var(--text-muted); }
#activeChatWrap { display:none; flex:1; flex-direction:column; overflow:hidden; }
.chat-hdr { padding:12px 16px; border-bottom:1px solid var(--border); display:flex; align-items:center; gap:12px; background:var(--surface); }
.chat-msgs { flex:1; overflow-y:auto; padding:16px; display:flex; flex-direction:column; gap:8px; }
.msg { max-width:72%; padding:10px 14px; border-radius:18px; font-size:13px; line-height:1.5; position:relative; }
.msg.sent { background:linear-gradient(135deg,#9333EA,#C084FC); color:#fff; border-radius:18px 4px 18px 18px; margin-left:auto; }
.msg.recv { background:var(--surface2); color:var(--text-primary); border-radius:4px 18px 18px 18px; margin-right:auto; }
[dir="rtl"] .msg.sent { margin-left:0; margin-right:auto; border-radius:4px 18px 18px 18px; }
[dir="rtl"] .msg.recv { margin-right:0; margin-left:auto; border-radius:18px 4px 18px 18px; }
.msg-time { font-size:9px; opacity:.6; margin-top:4px; display:block; text-align:right; }
.msg-sname { font-size:10px; font-weight:700; margin-bottom:4px; opacity:.7; }
.chat-inp-area { padding:10px 14px; border-top:1px solid var(--border); display:flex; gap:10px; align-items:flex-end; background:var(--surface); }
.chat-inp { flex:1; padding:10px 14px; background:var(--surface2); border:1.5px solid var(--border); border-radius:20px; color:var(--text-primary); font-size:13px; resize:none; outline:none; max-height:120px; font-family:inherit; }
.send-btn { width:40px; height:40px; background:linear-gradient(135deg,#9333EA,#C084FC); border:none; border-radius:50%; color:#fff; font-size:16px; cursor:pointer; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.date-sep { text-align:center; margin:8px 0; }
.date-sep span { background:var(--surface2); color:var(--text-muted); font-size:11px; font-weight:600; padding:3px 12px; border-radius:20px; }
.fab-new { width:36px; height:36px; background:linear-gradient(135deg,#9333EA,#C084FC); border:none; border-radius:12px; color:#fff; cursor:pointer; font-size:16px; display:flex; align-items:center; justify-content:center; }
.empty-convs { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px; padding:40px 20px; color:var(--text-muted); font-size:14px; }
.nc-ov { position:fixed; inset:0; background:rgba(45,27,78,.45); backdrop-filter:blur(4px); z-index:200; display:none; align-items:center; justify-content:center; }
.nc-ov.on { display:flex; }
.nc-box { background:var(--surface); border-radius:var(--radius-lg); padding:28px; width:90%; max-width:380px; position:relative; }
.nc-x { position:absolute; top:14px; right:14px; background:var(--surface2); border:none; border-radius:50%; width:28px; height:28px; cursor:pointer; font-size:13px; color:var(--text-primary); }
.nc-inp { width:100%; padding:12px 16px; background:var(--input-bg); border:1.5px solid var(--border); border-radius:var(--radius-sm); color:var(--text-primary); font-size:14px; outline:none; margin-bottom:10px; }
.nc-lbl { font-size:12px; font-weight:600; color:var(--text-secondary); margin-bottom:6px; display:block; }
.nc-div { text-align:center; color:var(--text-muted); font-size:12px; margin:8px 0; }
.nc-err { color:var(--danger); font-size:12px; display:none; margin-bottom:8px; }
.nc-load { color:var(--primary); font-size:12px; display:none; margin-bottom:8px; }
.nc-btns { display:flex; gap:8px; margin-top:16px; }
.nc-btn { flex:1; padding:12px; border-radius:var(--radius-sm); font-weight:700; font-size:13px; cursor:pointer; border:none; }
.nc-ok { background:linear-gradient(135deg,#9333EA,#C084FC); color:#fff; }
.nc-cancel { background:var(--surface2); color:var(--text-secondary); }
@media(max-width:768px) {
  .conv-panel { position:absolute; top:0; left:0; bottom:0; width:100%; z-index:5; transition:transform .3s; }
  .conv-panel.hide { transform:translateX(-100%); }
  [dir="rtl"] .conv-panel.hide { transform:translateX(100%); }
}

/* Notifications page */
.notif-item { display:flex; align-items:flex-start; gap:12px; padding:14px 16px; border-bottom:1px solid var(--border); cursor:pointer; transition:background .15s; }
.notif-item:hover { background:var(--surface2); }
.notif-icon-wrap { width:40px; height:40px; border-radius:12px; display:flex; align-items:center; justify-content:center; font-size:18px; flex-shrink:0; }
.notif-body { flex:1; }
.notif-title { font-size:13px; font-weight:600; color:var(--text-primary); margin-bottom:3px; }
.notif-sub   { font-size:11px; color:var(--text-muted); }
.notif-time  { font-size:10px; color:var(--text-muted); white-space:nowrap; margin-top:2px; }

/* Cam page */
.cam-card { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md); padding:18px; margin-bottom:14px; box-shadow:var(--shadow-sm); }
.cam-preview { width:100%; border-radius:var(--radius-sm); border:2px solid var(--border); background:#000; display:none; }
.cam-placeholder { width:100%; height:220px; border-radius:var(--radius-sm); border:2px dashed var(--border); display:flex; flex-direction:column; align-items:center; justify-content:center; gap:10px; color:var(--text-muted); }
.cam-status-row { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:14px; }
.cam-badge { background:var(--surface2); border:1px solid var(--border); color:var(--text-secondary); padding:5px 12px; border-radius:20px; font-size:12px; font-weight:600; }

/* RTL support */
[dir="rtl"] { text-align:right; }
[dir="rtl"] .nav-item { flex-direction:row-reverse; }
[dir="rtl"] .stat-trend { right:auto; left:14px; }
[dir="rtl"] .topbar { flex-direction:row-reverse; }
[dir="rtl"] .activity-item { flex-direction:row-reverse; }

/* ══════════════════════════════════════════
   DESKTOP LAYOUT — Persistent Sidebar
══════════════════════════════════════════ */
@media (min-width: 1024px) {
  body { overflow-x: hidden; }

  /* Sidebar always visible on desktop */
  .drawer {
    transform: translateX(0) !important;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    border-radius: 0 !important;
    box-shadow: 1px 0 0 var(--border) !important;
    z-index: 90;
  }
  [dir="rtl"] .drawer {
    left: auto; right: 0;
    transform: translateX(0) !important;
    border-radius: 0 !important;
    box-shadow: -1px 0 0 var(--border) !important;
  }

  /* Overlay hidden on desktop */
  .overlay { display: none !important; }

  /* ✅ FIX: Topbar على الـ desktop — fixed بعد الـ sidebar */
  .topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-w);
    right: 0;
    width: calc(100% - var(--sidebar-w));
    margin: 0;
    padding: 0 24px;
    z-index: 80;
    /* ✅ FIX: منع الـ overflow من إخفاء الأيقونات */
    overflow: visible;
  }
  [dir="rtl"] .topbar {
    left: 0;
    right: var(--sidebar-w);
  }

  /* ✅ FIX: topbar-brand على الـ desktop — لا يأخذ margin auto */
  .topbar-brand {
    font-size: 18px;
    margin: 0 !important; /* إلغاء أي margin auto */
    flex-shrink: 0;
  }

  /* ✅ FIX: topbar-actions تملأ باقي المساحة من اليمين */
  .topbar-actions {
    margin-left: auto !important;
    margin-right: 0 !important;
    gap: 10px !important;
    flex-shrink: 0 !important;
    display: flex !important;
    align-items: center !important;
  }
  [dir="rtl"] .topbar-actions {
    margin-left: 0 !important;
    margin-right: auto !important;
  }

  /* Main content shifted right of sidebar */
  .main {
    margin-left: var(--sidebar-w);
    margin-right: 0;
    padding-top: calc(var(--topbar-h) + 20px);
    max-width: none;
  }
  [dir="rtl"] .main {
    margin-left: 0;
    margin-right: var(--sidebar-w);
  }

  /* ✅ FIX: محتوى الصفحة يكون في المنتصف بشكل جميل */
  .main > * {
    max-width: 860px;
  }

  /* Messages layout fix */
  .messages-layout {
    top: var(--topbar-h);
    left: var(--sidebar-w);
    right: 0;
    bottom: 0;
  }
  [dir="rtl"] .messages-layout {
    left: 0;
    right: var(--sidebar-w);
  }

  /* Bottom nav hidden on desktop */
  .bottom-nav { display: none !important; }

  /* Drawer close button hidden on desktop */
  .drawer-close { display: none; }

  /* Menu button hidden on desktop */
  .topbar-menu { display: none !important; }

  /* ✅ FIX: حجم الـ topbar-btn على الـ desktop */
  .topbar-btn {
    width: 40px;
    height: 40px;
  }
  .topbar-avatar {
    width: 40px;
    height: 40px;
  }
}

/* Sidebar collapsed state on desktop */
@media (min-width: 1024px) {
  body.sidebar-collapsed .drawer {
    transform: translateX(-100%) !important;
  }
  [dir="rtl"] body.sidebar-collapsed .drawer {
    transform: translateX(100%) !important;
  }
  body.sidebar-collapsed .main {
    margin-left: 0;
  }
  [dir="rtl"] body.sidebar-collapsed .main {
    margin-right: 0;
  }
  body.sidebar-collapsed .topbar {
    left: 0;
    width: 100%;
  }
  [dir="rtl"] body.sidebar-collapsed .topbar {
    right: 0;
    left: 0;
  }
  body.sidebar-collapsed .topbar-menu {
    display: flex !important;
  }
}

/* ══ DARK THEME FIXES ══ */
[data-theme="dark"] .input,
[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]),
[data-theme="dark"] textarea,
[data-theme="dark"] select {
  color: var(--text-primary) !important;
  background: var(--input-bg) !important;
  border-color: rgba(192,132,252,0.25) !important;
}
[data-theme="dark"] select option {
  background: #1A1030 !important;
  color: #F0E8FF !important;
}
[data-theme="dark"] table th,
[data-theme="dark"] table td {
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}
[data-theme="dark"] .stat-info h3,
[data-theme="dark"] .stat-value { color: var(--text-primary) !important; }
[data-theme="dark"] .field-label { color: var(--text-secondary) !important; }
[data-theme="dark"] .nav-item { color: var(--text-secondary) !important; }
[data-theme="dark"] .nav-item:hover,
[data-theme="dark"] .nav-item.active { color: var(--primary-dark) !important; }
[data-theme="dark"] .rank-other { color: var(--text-primary) !important; }

/* ══ ATTENDANCE PAGE FIX - camera below scan ══ */
.attendance-grid {
  display: flex !important;
  flex-direction: column !important;
  gap: 14px;
}
@media (min-width: 768px) {
  .attendance-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
  }
}