/* ================================================================
   منظومة البريد الداخلي — مديرية تربية كربلاء المقدسة
   v2.0 | karbala.edu.iq
================================================================ */

/* ── VARIABLES ── */
:root {
  --primary:        #1e3a5f;
  --primary-mid:    #1a4d8f;
  --primary-light:  #2563eb;
  --primary-glow:   rgba(37,99,235,0.15);
  --accent:         #b8860b;
  --accent-light:   #d4a017;
  --accent-pale:    rgba(212,160,23,0.12);

  --danger:         #dc2626;
  --danger-pale:    #fef2f2;
  --warning:        #d97706;
  --warning-pale:   #fffbeb;
  --success:        #16a34a;
  --success-pale:   #f0fdf4;
  --info:           #0284c7;

  --bg:             #eef2f7;
  --surface:        #ffffff;
  --surface2:       #f8fafc;
  --border:         #e2e8f0;
  --border2:        #cbd5e1;

  --text:           #1e293b;
  --text2:          #475569;
  --text3:          #94a3b8;

  --sidebar-w:      272px;
  --topbar-h:       60px;
  --shadow-xs:      0 1px 2px rgba(0,0,0,.06);
  --shadow-sm:      0 2px 6px rgba(0,0,0,.08);
  --shadow-md:      0 4px 14px rgba(0,0,0,.1);
  --shadow-lg:      0 8px 28px rgba(0,0,0,.13);
  --r-sm:           6px;
  --r-md:           10px;
  --r-lg:           14px;
  --r-xl:           18px;
  --t:              .18s ease;
  --font:           'Cairo', sans-serif;
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: var(--font); }
img { max-width: 100%; }

/* ══════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(175deg, #0d1f3c 0%, #1e3a5f 55%, #1a4d8f 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--t), width var(--t);
  overflow: hidden;
}
.sidebar.collapsed { transform: translateX(100%); }

/* Scrollable nav area */
.sidebar-nav-wrap {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.12) transparent;
}
.sidebar-nav-wrap::-webkit-scrollbar { width: 4px; }
.sidebar-nav-wrap::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.15);
  border-radius: 4px;
}

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.logo-emblem {
  width: 42px; height: 42px;
  background: var(--accent-pale);
  border: 1.5px solid rgba(212,160,23,.35);
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  color: var(--accent-light);
  flex-shrink: 0;
}
.logo-info { flex: 1; min-width: 0; }
.logo-title {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}
.logo-domain {
  display: block;
  font-size: 11px;
  color: rgba(255,255,255,.45);
  letter-spacing: .3px;
}
.sidebar-close {
  background: none; border: none;
  color: rgba(255,255,255,.4);
  font-size: 16px;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  transition: color var(--t), background var(--t);
  flex-shrink: 0;
}
.sidebar-close:hover { color: #fff; background: rgba(255,255,255,.1); }

/* User Card */
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  margin: 12px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--r-lg);
  flex-shrink: 0;
}
.user-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary-light) 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.2);
}
.user-info { flex: 1; min-width: 0; }
.user-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-dept {
  display: block;
  font-size: 11px;
  color: rgba(255,255,255,.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.badge-pill {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  flex-shrink: 0;
  min-width: 22px;
  text-align: center;
}

/* Compose Button */
.sidebar-compose { padding: 8px 12px; flex-shrink: 0; }
.compose-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, #a07010 100%);
  color: #fff;
  border-radius: var(--r-md);
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  width: 100%;
  transition: opacity var(--t), transform var(--t), box-shadow var(--t);
  box-shadow: 0 3px 10px rgba(180,130,0,.3);
}
.compose-btn:hover {
  opacity: .9;
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(180,130,0,.4);
}
.compose-btn i { font-size: 15px; }

/* Nav */
.sidebar-nav { padding: 4px 0 8px; }
.nav-group { margin-bottom: 4px; }
.nav-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(255,255,255,.28);
  padding: 10px 18px 4px;
}
.sidebar-nav ul { list-style: none; }
.sidebar-nav ul li a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 14px 9px 10px;
  margin: 1px 8px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  font-weight: 500;
  color: rgba(255,255,255,.68);
  transition: background var(--t), color var(--t);
  position: relative;
}
.sidebar-nav ul li a i {
  width: 18px;
  text-align: center;
  font-size: 14px;
  flex-shrink: 0;
  opacity: .75;
}
.sidebar-nav ul li a span { flex: 1; }
.sidebar-nav ul li a:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}
.sidebar-nav ul li a:hover i { opacity: 1; }
.sidebar-nav ul li a.active {
  background: var(--primary-glow);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent-light);
}
.sidebar-nav ul li a.active i { opacity: 1; }
.nav-count {
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  background: var(--primary-light);
  color: #fff;
  min-width: 20px;
  text-align: center;
}
.nav-count-gray  { background: rgba(255,255,255,.2); }
.nav-count-gold  { background: var(--accent); }
.nav-count-red   { background: var(--danger); }

/* Sidebar Footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.logout-link {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: rgba(255,255,255,.5);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  transition: color var(--t), background var(--t);
}
.logout-link:hover { color: #f87171; background: rgba(220,38,38,.15); }
.sidebar-ver { font-size: 11px; color: rgba(255,255,255,.2); }

/* ══════════════════════════════════════════
   LAYOUT WRAPPER
══════════════════════════════════════════ */
.layout-wrap {
  margin-right: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-right var(--t);
}
.layout-wrap.expanded { margin-right: 0; }

/* ══════════════════════════════════════════
   TOPBAR
══════════════════════════════════════════ */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-xs);
  gap: 12px;
}
.topbar-right, .topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-toggle {
  background: none; border: none;
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  font-size: 17px;
  color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t), color var(--t);
}
.topbar-toggle:hover { background: var(--bg); color: var(--text); }
.breadcrumb-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.breadcrumb-org { color: var(--text3); }
.breadcrumb-sep { color: var(--border2); font-size: 10px; }
.breadcrumb-page { color: var(--text); font-weight: 600; }

/* Topbar Search */
.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--r-xl);
  padding: 0 14px;
  height: 36px;
  transition: border-color var(--t), box-shadow var(--t);
}
.topbar-search:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.topbar-search i { color: var(--text3); font-size: 13px; }
.topbar-search input {
  border: none; background: none; outline: none;
  font-family: var(--font); font-size: 13px;
  color: var(--text); width: 180px;
}
.topbar-search input::placeholder { color: var(--text3); }

/* Icon Button */
.icon-btn {
  position: relative;
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  background: none; border: none;
  font-size: 16px;
  color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t), color var(--t);
}
.icon-btn:hover { background: var(--bg); color: var(--primary); }
.icon-badge {
  position: absolute;
  top: 2px; left: 2px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  width: 16px; height: 16px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}

/* Role Badge */
.role-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  font-size: 12px;
  color: var(--text2);
  font-weight: 600;
}
.role-badge i { color: var(--primary-light); font-size: 13px; }

/* Notifications Panel */
.notif-wrap { position: relative; }
.notif-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  z-index: 999;
  display: none;
  overflow: hidden;
}
.notif-panel.open { display: block; }
.notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.notif-header strong { color: var(--text); font-weight: 700; }
.notif-all-link { color: var(--primary-light); font-size: 12px; }
.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--t);
}
.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: #f0f5ff; }
.notif-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.notif-dot.blue  { background: var(--primary-light); }
.notif-dot.green { background: var(--success); }
.notif-body { flex: 1; min-width: 0; }
.notif-text { font-size: 12.5px; color: var(--text); line-height: 1.5; }
.notif-time { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ══════════════════════════════════════════
   MAIN CONTENT
══════════════════════════════════════════ */
.main-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* ══════════════════════════════════════════
   CARDS
══════════════════════════════════════════ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title i { color: var(--primary-light); }
.card-body { padding: 20px; }

/* ══════════════════════════════════════════
   STATS GRID
══════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t), transform var(--t);
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.stat-num {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}
.stat-label {
  font-size: 12px;
  color: var(--text3);
  margin-top: 4px;
  font-weight: 500;
}

/* ══════════════════════════════════════════
   TOOLBAR
══════════════════════════════════════════ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.toolbar-right { display: flex; align-items: center; gap: 8px; }

/* ══════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 600;
  border: 1.5px solid transparent;
  transition: all var(--t);
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary {
  background: var(--primary-light);
  color: #fff;
  border-color: var(--primary-light);
  box-shadow: 0 2px 8px rgba(37,99,235,.2);
}
.btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  box-shadow: 0 4px 14px rgba(37,99,235,.3);
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text2);
  border-color: var(--border2);
}
.btn-secondary:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--text3);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: #b91c1c;
  transform: translateY(-1px);
}
.btn-gold {
  background: linear-gradient(135deg, var(--accent) 0%, #a07010 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(180,130,0,.25);
}
.btn-gold:hover {
  opacity: .9;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(180,130,0,.35);
}
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-icon {
  width: 34px; height: 34px;
  padding: 0;
  border-radius: var(--r-sm);
  justify-content: center;
}

/* ══════════════════════════════════════════
   FORMS
══════════════════════════════════════════ */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border2);
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--t), box-shadow var(--t);
  outline: none;
}
.form-control:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-control::placeholder { color: var(--text3); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 100px; }
.form-hint { font-size: 12px; color: var(--text3); margin-top: 4px; }
.required { color: var(--danger); margin-right: 2px; }

/* ══════════════════════════════════════════
   MESSAGE LIST
══════════════════════════════════════════ */
.message-list { list-style: none; }
.message-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--t);
  position: relative;
}
.message-item:last-child { border-bottom: none; }
.message-item:hover { background: var(--surface2); }
.message-item.unread { background: #f5f8ff; }
.message-item.unread::before {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary-light);
  border-radius: 0 2px 2px 0;
}
.msg-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.msg-body { flex: 1; min-width: 0; }
.msg-sender {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
}
.msg-subject {
  font-size: 13px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}
.message-item.unread .msg-subject {
  font-weight: 600;
  color: var(--text);
}
.msg-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  flex-shrink: 0;
}
.msg-time {
  font-size: 11.5px;
  color: var(--text3);
  text-align: left;
  line-height: 1.4;
}
.msg-badges { display: flex; align-items: center; gap: 5px; }

/* Priority Badges */
.priority-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}
.priority-urgent { background: #fef2f2; color: #dc2626; }
.priority-high   { background: #fffbeb; color: #d97706; }
.priority-normal { background: #eff6ff; color: #2563eb; }
.priority-low    { background: #f8fafc; color: #64748b; }

/* Star Button */
.star-btn {
  background: none; border: none;
  font-size: 16px;
  color: var(--border2);
  padding: 3px 5px;
  border-radius: 4px;
  transition: color var(--t), transform var(--t);
}
.star-btn:hover { color: var(--warning); transform: scale(1.2); }
.star-btn.starred { color: var(--warning); }

/* ══════════════════════════════════════════
   TABLE
══════════════════════════════════════════ */
.table { width: 100%; border-collapse: collapse; }
.table th {
  background: var(--surface2);
  padding: 11px 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text3);
  text-align: right;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  font-size: 13.5px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface2); }

/* ══════════════════════════════════════════
   PAGINATION
══════════════════════════════════════════ */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 16px;
  border-top: 1px solid var(--border);
}
.page-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all var(--t);
}
.page-btn:hover { background: var(--bg); color: var(--text); }
.page-btn.active {
  background: var(--primary-light);
  color: #fff;
  border-color: var(--primary-light);
}

/* ══════════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text3);
}
.empty-state > i {
  font-size: 52px;
  opacity: .25;
  display: block;
  margin-bottom: 16px;
}
.empty-state h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: 8px;
}
.empty-state p { font-size: 14px; margin-bottom: 20px; }

/* ══════════════════════════════════════════
   ALERTS / FLASH
══════════════════════════════════════════ */
#alertContainer {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 300px;
  max-width: 500px;
  pointer-events: none;
}
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  pointer-events: all;
  animation: slideIn .25s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.alert-success { background: var(--success-pale); color: #166534; border: 1px solid #bbf7d0; }
.alert-error   { background: var(--danger-pale);  color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-pale); color: #92400e; border: 1px solid #fde68a; }
.alert-close { margin-right: auto; background: none; border: none; color: inherit; opacity: .5; font-size: 15px; }
.alert-close:hover { opacity: 1; }

/* ══════════════════════════════════════════
   VIEW MESSAGE
══════════════════════════════════════════ */
.msg-view-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
}
.msg-view-subject {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.4;
}
.msg-view-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.msg-view-avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.msg-view-body {
  padding: 24px;
  font-size: 15px;
  line-height: 2;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.msg-view-actions {
  padding: 16px 24px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface2);
}
.msg-attachments {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.att-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  font-size: 12.5px;
  color: var(--text2);
  transition: all var(--t);
}
.att-chip:hover {
  background: var(--primary-glow);
  border-color: var(--primary-light);
  color: var(--primary-light);
}
.att-chip i { color: var(--primary-light); }

/* ══════════════════════════════════════════
   COMPOSE
══════════════════════════════════════════ */
.recipient-field-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 6px 12px;
  border: 1.5px solid var(--border2);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: text;
  position: relative;
  transition: border-color var(--t), box-shadow var(--t);
}
.recipient-field-wrap:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.recipient-input {
  border: none; outline: none;
  font-family: var(--font); font-size: 14px;
  color: var(--text); background: none;
  min-width: 140px; flex: 1;
}
.recipient-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  background: var(--primary-glow);
  border: 1px solid rgba(37,99,235,.2);
  color: var(--primary-light);
  border-radius: var(--r-xl);
  font-size: 12.5px;
  font-weight: 600;
}
.recipient-tag button {
  background: none; border: none;
  color: var(--primary-light);
  font-size: 16px; line-height: 1;
  padding: 0 0 0 2px;
  opacity: .6;
}
.recipient-tag button:hover { opacity: 1; }
.autocomplete-dropdown {
  position: absolute;
  top: 100%; right: 0; left: 0;
  background: var(--surface);
  border: 1.5px solid var(--border2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  max-height: 220px;
  overflow-y: auto;
  display: none;
}
.ac-item {
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--t);
  border-bottom: 1px solid var(--border);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--surface2); }
.ac-name { font-size: 13.5px; font-weight: 600; color: var(--text); }
.ac-email { font-size: 12px; color: var(--text3); margin-top: 2px; }

/* ══════════════════════════════════════════
   ORG CHART (Departments Page)
══════════════════════════════════════════ */
.org-chart { overflow-x: auto; }
.org-level { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.org-node {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  min-width: 180px;
  max-width: 240px;
  transition: box-shadow var(--t), border-color var(--t), transform var(--t);
  position: relative;
  cursor: default;
}
.org-node:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary-light);
  transform: translateY(-2px);
}
.org-node.level-gm {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(37,99,235,.3);
}
.org-node.level-deputy {
  background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
  color: #fff;
  border-color: transparent;
}
.org-node.level-dept {
  border-right: 3px solid var(--primary-light);
}
.org-node.level-unit {
  border-right: 3px solid var(--warning);
}
.org-node-icon {
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  background: rgba(255,255,255,.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  margin-bottom: 10px;
}
.org-node-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 6px;
}
.org-node-code {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  opacity: .5;
  text-transform: uppercase;
}
.org-node-count {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0,0,0,.1);
  color: rgba(255,255,255,.8);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
}
.org-node.level-dept .org-node-count {
  background: var(--primary-glow);
  color: var(--primary-light);
}
.org-connector {
  width: 2px;
  background: var(--border2);
  margin: 0 auto 0;
  height: 24px;
}
.org-connector-h {
  height: 2px;
  background: var(--border2);
  flex: 1;
}

/* ══════════════════════════════════════════
   LOGIN PAGE
══════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0d1f3c 0%, #1e3a5f 50%, #1a4d8f 100%);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  text-align: center;
  margin-bottom: 30px;
}
.login-logo-icon {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: var(--accent-light);
  margin: 0 auto 14px;
  box-shadow: 0 8px 24px rgba(37,99,235,.3);
}
.login-title { font-size: 20px; font-weight: 800; color: var(--text); }
.login-subtitle { font-size: 13px; color: var(--text3); margin-top: 4px; }

/* ══════════════════════════════════════════
   MOBILE
══════════════════════════════════════════ */
/* ══════════════════════════════════════════
   MOBILE — شاشات أصغر من 768px
══════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Safe Area (iPhone notch) ── */
  body { padding-bottom: env(safe-area-inset-bottom); }

  /* ── Sidebar يتحول لقائمة منسدلة جانبية ── */
  .sidebar {
    transform: translateX(100%);
    box-shadow: var(--shadow-lg);
    width: min(280px, 85vw);
    z-index: 300;
  }
  .sidebar.open { transform: translateX(0); }

  /* ── Overlay خلف الـ Sidebar ── */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 299;
  }
  .sidebar-overlay.active { display: block; }

  /* ── Layout ── */
  .layout-wrap { margin-right: 0; }
  .main-content {
    padding: 12px;
    padding-bottom: 80px; /* مساحة لـ Bottom Nav */
  }

  /* ── Topbar ── */
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-search { display: none; }
  .breadcrumb-bar { display: none; }
  .role-badge { display: none; }
  .topbar-right { gap: 6px; }
  .topbar-left { gap: 6px; }

  /* ── Stats Grid ── */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px 12px; gap: 10px; }
  .stat-num { font-size: 20px; }
  .stat-icon { width: 40px; height: 40px; font-size: 16px; }

  /* ── Message List ── */
  .message-item { padding: 12px; gap: 10px; }
  .msg-avatar { width: 36px; height: 36px; font-size: 14px; }
  .msg-subject { font-size: 12.5px; }
  .msg-sender { font-size: 13px; }
  .msg-time { font-size: 11px; }
  .msg-meta { gap: 4px; }
  .star-btn { font-size: 14px; }

  /* ── Message View ── */
  .msg-view-subject { font-size: 15px; }
  .msg-view-meta { flex-wrap: wrap; gap: 10px; }
  .msg-view-body { padding: 16px; font-size: 14px; }
  .msg-view-actions { flex-wrap: wrap; gap: 6px; padding: 12px; }

  /* ── Compose ── */
  .form-control { font-size: 16px; } /* يمنع zoom في iOS */

  /* ── Tables ── */
  .table th, .table td { padding: 8px 10px; font-size: 12px; }

  /* ── Cards ── */
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }

  /* ── Toolbar ── */
  .toolbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .toolbar-right { width: 100%; justify-content: flex-end; }

  /* ── Pagination ── */
  .pagination { flex-wrap: wrap; gap: 4px; padding: 12px 8px; }

  /* ── Bottom Navigation Bar ── */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--primary);
    border-top: 1px solid rgba(255,255,255,.1);
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 16px rgba(0,0,0,.2);
  }
  .bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 10px 4px;
    color: rgba(255,255,255,.55);
    font-size: 9.5px;
    font-family: var(--font);
    text-decoration: none;
    transition: color .15s, background .15s;
    position: relative;
  }
  .bottom-nav a.active,
  .bottom-nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
  .bottom-nav a i { font-size: 19px; }
  .bottom-nav .bnav-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 18px);
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    border: 1.5px solid var(--primary);
  }

  /* ── Notif Panel ── */
  .notif-panel {
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    top: var(--topbar-h);
    border-radius: 0 0 var(--r-xl) var(--r-xl);
    max-height: 60vh;
    overflow-y: auto;
  }

  /* ── Admin Tables horizontal scroll ── */
  .card { overflow-x: auto; }

  /* ── Compose CC/BCC ── */
  .recipient-field-wrap { min-height: 46px; }

  /* ── Org Chart ── */
  .org-level { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 8px; }
  .org-node { min-width: 150px; font-size: 12px; }

  /* Hide sidebar scrollbar on mobile */
  .sidebar-nav-wrap { scrollbar-width: none; }
  .sidebar-nav-wrap::-webkit-scrollbar { display: none; }
}

/* ── Tablet 769–1024 ── */
@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-w: 230px; }
  .main-content { padding: 18px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .bottom-nav { display: none; }
}

/* ── Desktop ── */
@media (min-width: 1025px) {
  .bottom-nav { display: none; }
  .sidebar-overlay { display: none !important; }
}

/* ══════════════════════════════════════════
   SCROLLBAR
══════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ══════════════════════════════════════════
   PRINT
══════════════════════════════════════════ */
@media print {
  .sidebar, .topbar, .msg-view-actions, .toolbar { display: none !important; }
  .layout-wrap { margin-right: 0; }
  .main-content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
