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

:root {
  --brand:       #6366f1;
  --brand-d:     #4f46e5;
  --brand-l:     #eef2ff;
  --brand-glow:  rgba(99,102,241,.15);
  --success:     #10b981;
  --success-l:   #d1fae5;
  --danger:      #ef4444;
  --danger-l:    #fee2e2;
  --warn:        #f59e0b;
  --warn-l:      #fef3c7;
  --info:        #3b82f6;
  --info-l:      #dbeafe;
  --purple:      #8b5cf6;
  --purple-l:    #ede9fe;

  --bg:          #f5f6fa;
  --surface:     #ffffff;
  --surface-2:   #f9fafb;
  --border:      #e5e7eb;
  --border-2:    #d1d5db;
  --text:        #111827;
  --text-2:      #6b7280;
  --text-3:      #9ca3af;

  --sidebar-w:   260px;
  --topbar-h:    60px;
  --r-sm:        8px;
  --r:           12px;
  --r-lg:        16px;
  --r-xl:        20px;

  --shadow-sm:   0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:      0 4px 12px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:   0 10px 30px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.05);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }

h1 { font-size: 1.8rem; font-weight: 800; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
h4 { font-size: .95rem; font-weight: 600; }
p  { color: var(--text-2); font-size: .9rem; }

#app { display: flex; min-height: 100vh; }

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-w);
  background: #0f0f1a;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  z-index: 100;
  overflow: hidden;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}
#sidebar::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 200px; height: 200px;
  background: var(--brand-glow);
  border-radius: 50%;
  pointer-events: none;
}

.sidebar-logo {
  padding: 22px 18px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--brand), var(--purple));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.sidebar-logo-text .logo-title {
  color: #fff;
  font-size: .92rem;
  font-weight: 700;
  line-height: 1.2;
  display: block;
}
.sidebar-logo-text .logo-sub {
  color: rgba(255,255,255,.35);
  font-size: .7rem;
  display: block;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-section-label {
  color: rgba(255,255,255,.25);
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 10px 10px 5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: rgba(255,255,255,.55);
  cursor: pointer;
  transition: all .18s;
  font-size: .88rem;
  font-weight: 500;
  margin-bottom: 2px;
  border: none;
  background: none;
  width: 100%;
  text-align: right;
  position: relative;
}
.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: rgba(255,255,255,.9);
}
.nav-item.active {
  background: linear-gradient(135deg, rgba(99,102,241,.25), rgba(139,92,246,.15));
  color: #fff;
  font-weight: 600;
  border: 1px solid rgba(99,102,241,.3);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  right: 0; top: 20%; bottom: 20%;
  width: 3px;
  background: var(--brand);
  border-radius: 99px 0 0 99px;
}
.nav-icon {
  width: 28px; height: 28px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: rgba(255,255,255,.06);
  transition: background .18s;
}
.nav-item.active .nav-icon {
  background: rgba(99,102,241,.3);
}
.nav-item:hover .nav-icon {
  background: rgba(255,255,255,.1);
}

.sidebar-user {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--purple));
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: .85rem;
  font-weight: 700;
  flex-shrink: 0;
}
.user-info .user-name {
  color: rgba(255,255,255,.9);
  font-size: .85rem;
  font-weight: 600;
  display: block;
  line-height: 1.2;
}
.user-info .user-role {
  color: rgba(255,255,255,.35);
  font-size: .72rem;
  display: block;
}
.logout-btn {
  margin-right: auto;
  background: none;
  border: none;
  color: rgba(255,255,255,.3);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  font-size: 1rem;
  transition: all .18s;
}
.logout-btn:hover { color: var(--danger); background: rgba(239,68,68,.1); }

/* ── MAIN ── */
#main {
  margin-right: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── TOPBAR ── */
#topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.topbar-title {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
  color: var(--text);
}
.topbar-date {
  font-size: .8rem;
  color: var(--text-3);
  background: var(--surface-2);
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
}
#sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  font-size: 1rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  color: var(--text-2);
}

/* ── PAGE ── */
#page-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
}

/* ── CARDS ── */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
}
.card-body { padding: 20px; }

/* ── STAT CARDS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  padding: 18px 20px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, transform .2s;
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-icon-wrap {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}
.stat-content { flex: 1; min-width: 0; }
.stat-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-label {
  font-size: .78rem;
  color: var(--text-2);
  font-weight: 500;
  margin-top: 3px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  font-family: 'Cairo', sans-serif;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,.35);
}
.btn-primary:hover { background: var(--brand-d); box-shadow: 0 4px 12px rgba(99,102,241,.45); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-2);
}
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: .8rem; border-radius: 6px; }
.btn-lg { padding: 11px 24px; font-size: 1rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── FORMS ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-label.required::after { content: ' *'; color: var(--danger); }
.form-control {
  width: 100%;
  padding: 9px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-family: 'Cairo', sans-serif;
  font-size: .92rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  direction: rtl;
}
.form-control:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow);
}
.form-hint { font-size: .78rem; color: var(--text-3); margin-top: 4px; }
.form-error { font-size: .78rem; color: var(--danger); margin-top: 4px; font-weight: 600; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead { background: var(--surface-2); }
thead th {
  padding: 11px 16px;
  text-align: right;
  font-weight: 700;
  color: var(--text-2);
  font-size: .78rem;
  border-bottom: 1.5px solid var(--border);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: .04em;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .12s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody td { padding: 12px 16px; color: var(--text); vertical-align: middle; }

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
}
.badge-green  { background: var(--success-l); color: #065f46; }
.badge-red    { background: var(--danger-l);  color: #991b1b; }
.badge-gold   { background: var(--warn-l);    color: #92400e; }
.badge-blue   { background: var(--info-l);    color: #1e40af; }
.badge-purple { background: var(--purple-l);  color: #5b21b6; }
.badge-gray   { background: var(--bg);        color: var(--text-2); border: 1px solid var(--border); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalIn .22s cubic-bezier(.34,1.56,.64,1);
}
@keyframes modalIn {
  from { opacity:0; transform: scale(.92) translateY(16px); }
  to   { opacity:1; transform: scale(1)  translateY(0); }
}
.modal-header {
  padding: 20px 24px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  background: var(--surface-2);
  border-radius: 0 0 var(--r-xl) var(--r-xl);
}

/* ── TOAST ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  font-size: .88rem;
  font-weight: 600;
  min-width: 240px;
  max-width: 340px;
  animation: toastIn .25s cubic-bezier(.34,1.56,.64,1);
  color: #fff;
}
@keyframes toastIn {
  from { opacity:0; transform: translateX(-20px); }
  to   { opacity:1; transform: translateX(0); }
}
.toast-icon {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
  flex-shrink: 0;
}
.toast-success { background: #065f46; }
.toast-error   { background: #991b1b; }
.toast-info    { background: #1e3a8a; }

/* ── PAGE HEADER ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header h2 { margin: 0; }
.page-header p { margin: 2px 0 0; font-size: .85rem; }
.page-header-actions { display: flex; gap: 8px; align-items: center; }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-2);
}
.empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: .3;
  display: block;
}
.empty-state h4 { color: var(--text); margin-bottom: 6px; font-size: 1rem; }

/* ── SPINNER ── */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  margin: 60px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── LOGIN ── */
#login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f0f1a;
  padding: 20px;
  position: relative;
  overflow: hidden;
}
#login-page::before {
  content: '';
  position: absolute;
  top: -200px; right: -200px;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(99,102,241,.2) 0%, transparent 70%);
  pointer-events: none;
}
#login-page::after {
  content: '';
  position: absolute;
  bottom: -200px; left: -200px;
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(139,92,246,.15) 0%, transparent 70%);
  pointer-events: none;
}
.login-card {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.1);
  backdrop-filter: blur(20px);
  border-radius: var(--r-xl);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  position: relative;
  z-index: 1;
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo-icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--brand), var(--purple));
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  margin: 0 auto 16px;
  box-shadow: 0 8px 24px rgba(99,102,241,.4);
}
.login-logo h1 {
  color: #fff;
  font-size: 1.4rem;
  margin-bottom: 4px;
}
.login-logo p { color: rgba(255,255,255,.4); font-size: .85rem; }
.login-card .form-label { color: rgba(255,255,255,.7); }
.login-card .form-control {
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.1);
  color: #fff;
}
.login-card .form-control::placeholder { color: rgba(255,255,255,.25); }
.login-card .form-control:focus {
  border-color: var(--brand);
  background: rgba(255,255,255,.08);
}

/* ── GAMIFICATION ── */
.points-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, var(--warn), #f97316);
  color: #fff;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: .8rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(245,158,11,.4);
}
.task-card {
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 16px;
  transition: all .2s;
  box-shadow: var(--shadow-sm);
}
.task-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.task-card.status-completed { border-color: var(--success); background: linear-gradient(to bottom, rgba(16,185,129,.03), var(--surface)); }
.task-card.status-failed { border-color: var(--danger); }
.task-card.status-submitted { border-color: var(--warn); background: linear-gradient(to bottom, rgba(245,158,11,.03), var(--surface)); }

/* ── PROGRESS BAR ── */
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--brand), var(--purple));
  transition: width .4s ease;
}

/* ── BRANCH CARDS ── */
.branch-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: all .2s;
  box-shadow: var(--shadow-sm);
}
.branch-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.branch-card-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.branch-avatar {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

/* ── SECTION DIVIDER ── */
.section-title {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 16px 0 8px;
}

/* ── UTILITY ── */
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger) !important; }
.text-warn    { color: var(--warn) !important; }
.text-brand   { color: var(--brand) !important; }
.text-muted   { color: var(--text-3) !important; }
.text-bold    { font-weight: 700 !important; }
.text-center  { text-align: center; }
.hidden  { display: none !important; }
.w-full  { width: 100%; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.flex  { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── MOBILE ── */
@media (max-width: 768px) {
  #sidebar-toggle { display: block; }
  #sidebar { transform: translateX(100%); }
  #sidebar.open { transform: translateX(0); box-shadow: -10px 0 40px rgba(0,0,0,.3); }
  #main { margin-right: 0; }
  #page-content { padding: 16px; }
  .form-grid-2, .form-grid-3, .grid-2 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .login-card { padding: 28px 20px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
}
