/* أساسيات عامة */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Cairo', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background:
    radial-gradient(1200px 800px at 100% -200px, #f0f3ff 0%, #f7f7f9 40%, #f6f7fb 100%),
    linear-gradient(180deg, rgba(79,70,229,0.06), rgba(34,211,238,0.04));
  color: #0f172a;
}

:root {
  --primary: #4F46E5; /* Indigo 600 */
  --primary-2: #7C3AED; /* Violet 600 */
  --accent: #22D3EE;  /* Cyan 400 */
  --primary-ink: #ffffff;
  --bg: #f6f7fb;
  --surface: rgba(255,255,255,0.8);
  --card: #ffffff;
  --border: #e5e7eb;
  --muted: #6b7280;
  --shadow: 0 10px 28px rgba(24,24,40,0.10);
  --shadow-lg: 0 18px 40px rgba(24,24,40,0.16);
  --radius: 16px;
  --header-h: 60px;
  --bottomnav-h: 66px;
  --mx: 50%;
  --my: 50%;
}

/* خلفية تقنية متحركة واحترافية بدون نص */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 500px at 85% -120px, rgba(79,70,229,0.14), transparent 60%),
    radial-gradient(800px 500px at -160px 100%, rgba(34,211,238,0.16), transparent 60%),
    repeating-linear-gradient(0deg, rgba(17,24,39,0.055) 0px, rgba(17,24,39,0.055) 1px, transparent 1px, transparent 22px),
    repeating-linear-gradient(90deg, rgba(17,24,39,0.045) 0px, rgba(17,24,39,0.045) 1px, transparent 1px, transparent 22px);
  background-size: auto, auto, 24px 24px, 24px 24px;
  background-position: center center, center center, 0 0, 0 0;
  animation: gridDrift 28s linear infinite;
  opacity: .60;
  z-index: 0;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  filter: blur(30px) saturate(120%);
  background:
    radial-gradient(520px 520px at calc(var(--mx)) calc(var(--my)), rgba(79,70,229,0.22), transparent 60%),
    radial-gradient(380px 380px at calc(100% - var(--mx)) calc(100% - var(--my)), rgba(34,211,238,0.18), transparent 60%),
    radial-gradient(440px 440px at 12% 86%, rgba(124,58,237,0.18), transparent 60%);
  opacity: .55;
}

/* تأكيد ترتيب الطبقات فوق الخلفية */
.topbar, .main, .sidebar { position: relative; z-index: 1; }

/* حركة الشبكة الخلفية */
@keyframes gridDrift {
  to { background-position: center center, center center, 0 24px, 24px 0; }
}

/* الهيدر المثبت مع دعم مساحة النوتش */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  background: linear-gradient(90deg, rgba(20,24,38,0.65), rgba(20,24,38,0.65)),
              radial-gradient(1200px 400px at 0% -200px, rgba(79,70,229,0.35), rgba(124,58,237,0.25));
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding-top: env(safe-area-inset-top);
  z-index: 1000;
  backdrop-filter: saturate(180%) blur(14px);
}
.topbar .wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding-inline: 12px;
}
.topbar .actions { display: flex; align-items: center; gap: 8px; }
.actions-group { display: flex; align-items: center; gap: 8px; }
.topbar .actions .divider { width: 1px; height: 28px; background: rgba(255,255,255,0.18); border-radius: 1px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .subtitle { font-size: 12px; color: #e5e7eb; opacity: 0.9; }
.brand strong { color: #fff; letter-spacing: 0.3px; }
.logo {
  width: 36px; height: 36px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #9AE6F0);
  color: #0f172a;
  font-weight: 800; font-size: 14px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.18);
}

.icon-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.12);
  color: #ffffff;
  width: 42px; height: 42px;
  border-radius: 12px;
  display: grid; place-items: center;
  transition: transform 180ms ease, box-shadow 200ms ease, background-color 200ms ease;
}
.icon-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 12px rgba(0,0,0,0.18); }
.icon-btn:active { transform: scale(0.97); }

/* السايد بار والطبقة */
.sidebar {
  position: fixed;
  top: 0; bottom: 0; right: 0;
  width: 300px;
  background: var(--surface);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
  border-left: 1px solid rgba(24,24,40,0.08);
  box-shadow: var(--shadow-lg);
  transform: translateX(104%);
  transition: transform 240ms cubic-bezier(.22,.61,.36,1), box-shadow 200ms ease;
  z-index: 1100;
  padding-top: calc(env(safe-area-inset-top) + 10px);
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px;
}
.sidebar-actions { display: flex; gap: 8px; padding: 0 12px 8px; }
.sidebar-section-title { font-size: 12px; color: #374151; margin: 4px 12px 6px; opacity: 0.85; }
.nav { display: flex; flex-direction: column; padding: 10px; gap: 4px; }
.nav-item {
  position: relative;
  display: block;
  padding: 12px 16px;
  margin: 2px 6px;
  border-radius: 12px;
  color: #0f172a;
  text-decoration: none;
  transition: background-color 160ms ease, box-shadow 200ms ease, transform 160ms ease;
  overflow: hidden;
}
.nav-item:hover { background: #f3f6ff; transform: translateY(-1px); box-shadow: 0 10px 18px rgba(24,24,40,0.08); }
.nav-item.active { 
  background: linear-gradient(135deg, rgba(79,70,229,0.12), rgba(124,58,237,0.12)); 
  color: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(79,70,229,0.28);
}

.overlay {
  position: fixed; inset: 0;
  background: radial-gradient(800px 400px at 50% -100px, rgba(79,70,229,0.25), rgba(0,0,0,0.35));
  opacity: 0; pointer-events: none;
  transition: opacity 220ms ease;
  z-index: 1050;
}

body.sidebar-open .sidebar { transform: translateX(0); }
body.sidebar-open #overlay { opacity: 1; pointer-events: auto; }

/* المحتوى الرئيسي */
.main {
  padding-top: calc(var(--header-h) + env(safe-area-inset-top));
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--bottomnav-h));
}
.hero {
  padding: 22px 16px;
  animation: fadeUp 420ms ease both;
}
.hero h1 { margin: 0 0 8px; font-size: clamp(28px, 5.2vw, 42px); color: #0b1220; letter-spacing: .2px; }
.hero p { margin: 0; color: var(--muted); font-size: 16px; }
.hero-actions { margin-top: 16px; display: flex; gap: 10px; }

.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer;
  padding: 12px 16px; border-radius: 14px; font-weight: 700;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  transition: transform 160ms ease, box-shadow 220ms ease, filter 220ms ease;
  position: relative; overflow: hidden;
}
.btn-primary { 
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); 
  color: var(--primary-ink); 
  box-shadow: 0 14px 28px rgba(79,70,229,0.25);
}
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.06); box-shadow: 0 18px 38px rgba(79,70,229,0.32); }
.btn-accent { 
  background: linear-gradient(135deg, var(--accent), #7dd3fc); 
  color: #0f172a; 
  box-shadow: 0 14px 28px rgba(34,211,238,0.25);
}
.btn-accent:hover { transform: translateY(-1px); filter: brightness(1.06); box-shadow: 0 18px 38px rgba(34,211,238,0.32); }
.btn-outline { background: #ffffff; border-color: var(--border); color: #0f172a; }
.btn-outline:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(24,24,40,0.10); }

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 0 16px 20px;
  max-width: 1100px;
  margin-inline: auto;
}
@media (min-width: 640px) {
  .grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 980px) {
  .grid { grid-template-columns: 1fr 1fr 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px;
  transition: transform 180ms ease, box-shadow 220ms ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card h3 { margin: 0 0 8px; font-size: 18px; }
.card p { margin: 0 0 10px; color: var(--muted); }
.link { color: #374151; text-decoration: underline; }

/* صفحات المصادقة */
.auth-card {
  margin: 20px auto;
  max-width: 680px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  animation: fadeUp 420ms ease both;
}
.auth-card h1 { margin: 0 0 12px; font-size: 22px; }
.form { display: grid; gap: 12px; }
.form-field { display: grid; gap: 6px; }
.form-field label { font-size: 14px; color: #111827; }
.form-field input {
  appearance: none; outline: none;
  width: 100%;
  padding: 12px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  font-size: 16px;
  transition: box-shadow 180ms ease, border-color 160ms ease;
}
.form-field input:focus { border-color: rgba(79,70,229,0.45); box-shadow: 0 0 0 4px rgba(79,70,229,0.18); }
.muted { color: var(--muted); font-size: 14px; }

/* تحسينات لمس وبطاريات */
button, .btn, .icon-btn, .nav-item { touch-action: manipulation; }

/* Bottom Navigation */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottomnav-h);
  background: rgba(255,255,255,0.85);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  z-index: 1000;
}
.bottomnav-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 clamp(8px, 3vw, 16px);
}
.bottom-item {
  flex: 1;
  display: grid;
  place-items: center;
  gap: 4px;
  text-decoration: none;
  color: var(--muted);
  height: 100%;
}
.bottom-item .icon { font-size: 20px; line-height: 1; }
.bottom-item .label { font-size: 12px; }
.bottom-item.active { color: var(--primary); }
.bottom-item.active .icon { transform: translateY(-1px); }

/* مؤثر Ripple بسيط */
.btn .ripple, .nav-item .ripple {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  animation: ripple 600ms ease-out;
  pointer-events: none;
  background: rgba(255,255,255,0.55);
}

@keyframes ripple {
  to { transform: translate(-50%, -50%) scale(6); opacity: 0; }
}

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

/* احترام تفضيل تقليل الحركة */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* --- الثيم الداكن --- */
body.theme-dark {
  color: #e5e7eb;
  background:
    radial-gradient(1200px 800px at 100% -200px, #0b1020 0%, #0d1324 40%, #0e1528 100%),
    linear-gradient(180deg, rgba(79,70,229,0.10), rgba(34,211,238,0.08));
  --surface: rgba(16,18,26,0.62);
  --card: rgba(17,24,39,0.82);
  --border: rgba(255,255,255,0.08);
  --muted: #cbd5e1;
  --shadow: 0 10px 28px rgba(0,0,0,0.38);
  --shadow-lg: 0 24px 50px rgba(0,0,0,0.50);
}
body.theme-dark::after {
  opacity: .55;
}
body.theme-dark::before {
  opacity: .50;
  filter: blur(34px) saturate(140%);
}

body.theme-dark .nav-item { color: #e5e7eb; }
body.theme-dark .nav-item:hover { background: rgba(255,255,255,0.06); box-shadow: 0 10px 18px rgba(0,0,0,0.22); }
body.theme-dark .nav-item.active { 
  background: linear-gradient(135deg, rgba(79,70,229,0.16), rgba(124,58,237,0.16)); 
  color: #a5b4fc;
  box-shadow: inset 0 0 0 1px rgba(79,70,229,0.38);
}

/* Bottom nav dark mode */
body.theme-dark .bottomnav {
  background: rgba(16,18,26,0.62);
  border-top-color: rgba(255,255,255,0.08);
}
body.theme-dark .bottom-item { color: #9aa4b2; }
body.theme-dark .bottom-item.active { color: #a5b4fc; }

body.theme-dark .card, body.theme-dark .auth-card { background: var(--card); border-color: var(--border); }
body.theme-dark .card p, body.theme-dark .muted { color: var(--muted); }
body.theme-dark .link { color: #d1d5db; }
body.theme-dark .btn-outline { background: transparent; border-color: rgba(255,255,255,0.18); color: #e5e7eb; }
body.theme-dark .hero h1 { color: #f1f5f9; }
body.theme-dark .hero p { color: var(--muted); }

body.theme-dark .form-field label { color: #e5e7eb; }
body.theme-dark .form-field input, body.theme-dark textarea {
  background: rgba(255,255,255,0.06);
  color: #f8fafc;
  border-color: rgba(255,255,255,0.14);
}
body.theme-dark .form-field input:focus, body.theme-dark textarea:focus {
  border-color: rgba(79,70,229,0.45);
  box-shadow: 0 0 0 4px rgba(79,70,229,0.22);
}
body.theme-dark .sidebar-section-title { color: #e5e7eb; opacity: 0.7; }