:root {
  --navy: #14284B;
  --accent: #1E9E63;
  --accent-soft: #D9F3E7;
  --ink: #14284B;
  --muted: #5A6B85;
  --soft: #F7F8FA;
  --paper: #FFFFFF;
  --line: rgba(20, 40, 75, 0.08);
  --radius: 28px;
  --shadow: 0 22px 60px rgba(20, 40, 75, 0.12);
  --font-ar: "IBM Plex Sans Arabic", system-ui, sans-serif;
  --font-display: "Fraunces", "IBM Plex Sans Arabic", Georgia, serif;
  --sidebar: 240px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-ar);
  background: var(--soft);
  min-height: 100vh;
  line-height: 1.65;
  opacity: 0;
  transition: opacity .4s ease;
}
body.ready { opacity: 1; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }

.atmosphere {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: linear-gradient(125deg, #e8eef7 0%, #f7f8fa 42%, #eef8f3 72%, #f6f3ea 100%);
  background-size: 200% 200%;
  animation: wash 18s ease-in-out infinite;
}
.mesh {
  position: absolute; inset: -20%;
  background:
    radial-gradient(40% 35% at 20% 20%, rgba(30,158,99,.16), transparent 70%),
    radial-gradient(35% 30% at 80% 15%, rgba(20,40,75,.12), transparent 65%),
    radial-gradient(45% 40% at 60% 85%, rgba(243,223,170,.35), transparent 70%);
  animation: mesh-drift 20s ease-in-out infinite;
}
.grid-fade {
  position: absolute; inset: 0;
  background-image: radial-gradient(rgba(20,40,75,0.11) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse at 50% 30%, #000 20%, transparent 75%);
  opacity: .45;
}
.blob {
  position: absolute; border-radius: 50%; filter: blur(48px); opacity: .5;
  animation: drift 16s ease-in-out infinite;
}
.blob-a { width: 300px; height: 300px; background: #b7d0ef; top: 4%; right: 8%; }
.blob-b { width: 340px; height: 340px; background: #9fe0c4; top: 30%; left: -4%; animation-delay: -5s; }
.blob-c { width: 260px; height: 260px; background: #f0dfb8; bottom: 8%; left: 45%; animation-delay: -9s; }

@keyframes wash { 0%,100%{background-position:0% 40%} 50%{background-position:100% 60%} }
@keyframes mesh-drift { 0%,100%{transform:translate3d(0,0,0) scale(1)} 50%{transform:translate3d(-2%,1.5%,0) scale(1.05)} }
@keyframes drift { 0%,100%{transform:translate3d(0,0,0) scale(1)} 50%{transform:translate3d(24px,-28px,0) scale(1.1)} }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 11px 18px; font-weight: 700;
  cursor: pointer; transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-dark { background: var(--navy); color: #fff; box-shadow: 0 12px 28px rgba(20,40,75,.22); }
.btn-accent { background: var(--accent); color: #fff; box-shadow: 0 12px 28px rgba(30,158,99,.28); }
.btn-ghost {
  background: rgba(255,255,255,.7); color: var(--navy);
  border: 1px solid var(--line); backdrop-filter: blur(10px);
}
.btn-danger { background: #B42318; color: #fff; }
.btn-sm { padding: 8px 12px; font-size: .85rem; border-radius: 12px; }
.btn.full { width: 100%; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 6px; color: var(--navy); }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(255,255,255,.9); color: var(--ink);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: rgba(30,158,99,.45);
  box-shadow: 0 0 0 3px rgba(30,158,99,.12);
}
.field textarea { min-height: 110px; resize: vertical; }
.form-note { margin: 12px 0 0; font-size: .9rem; font-weight: 600; color: var(--muted); }
.form-note.err { color: #B42318; }
.form-note.ok { color: var(--accent); }

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 700; font-size: 1.35rem;
  letter-spacing: -.03em; color: var(--navy);
}
.brand img { width: 44px; height: 44px; border-radius: 12px; }

/* —— Login —— */
.auth-page { min-height: 100vh; display: flex; flex-direction: column; }
.auth-back {
  position: fixed; top: 18px; left: 18px; z-index: 20;
  padding: 8px 14px; border-radius: 999px;
  background: rgba(255,255,255,.75); border: 1px solid var(--line);
  font-weight: 600; font-size: .9rem; backdrop-filter: blur(12px);
}
.auth-stage {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 48px 16px 40px;
}
.auth-frame { width: min(440px, 100%); }
.auth-brand { display: flex; justify-content: center; margin-bottom: 18px; }
.page-card {
  position: relative; border-radius: var(--radius);
  background: rgba(255,255,255,.78); border: 1px solid var(--line);
  box-shadow: var(--shadow); backdrop-filter: blur(18px) saturate(1.15);
  overflow: hidden;
}
.page-card-inner { padding: 28px 24px 24px; position: relative; z-index: 1; }
.page-card-inner h1 {
  margin: 0; font-family: var(--font-display); font-size: 1.75rem;
  letter-spacing: -.03em; line-height: 1.25;
}
.page-lead { margin: 8px 0 20px; color: var(--muted); font-size: .95rem; }

/* —— App shell —— */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 50; padding: 12px 16px 0;
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px 10px 16px; border-radius: 999px;
  background: rgba(255,255,255,.72); border: 1px solid var(--line);
  box-shadow: 0 14px 40px rgba(20,40,75,.08); backdrop-filter: blur(18px) saturate(1.2);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-brand img { width: 36px; height: 36px; border-radius: 10px; }
.topbar-brand strong {
  font-family: var(--font-display); font-size: 1.15rem; letter-spacing: -.02em;
  white-space: nowrap;
}
.topbar-brand span { display: block; font-size: .72rem; color: var(--muted); font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-chip {
  font-size: .82rem; font-weight: 600; color: var(--muted);
  padding: 6px 10px; border-radius: 999px; background: rgba(20,40,75,.04);
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.layout {
  flex: 1; max-width: 1280px; width: 100%; margin: 0 auto;
  display: grid; grid-template-columns: var(--sidebar) 1fr;
  gap: 18px; padding: 18px 16px 48px;
}
.sidebar {
  position: sticky; top: 78px; align-self: start;
  padding: 12px; border-radius: 24px;
  background: rgba(255,255,255,.7); border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(20,40,75,.06); backdrop-filter: blur(14px);
}
.nav-btn {
  width: 100%; text-align: right; background: transparent; border: 0;
  padding: 11px 12px; border-radius: 14px; font-weight: 600; color: var(--muted);
  cursor: pointer; transition: background .15s, color .15s;
}
.nav-btn:hover { background: rgba(20,40,75,.04); color: var(--navy); }
.nav-btn.on {
  background: linear-gradient(135deg, rgba(30,158,99,.14), rgba(20,40,75,.06));
  color: var(--navy); box-shadow: inset 0 0 0 1px rgba(30,158,99,.18);
}

.main { min-width: 0; }
.panel {
  border-radius: 24px; background: rgba(255,255,255,.78);
  border: 1px solid var(--line); box-shadow: 0 18px 48px rgba(20,40,75,.07);
  backdrop-filter: blur(16px); padding: 22px 20px; margin-bottom: 16px;
}
.panel h2 {
  margin: 0 0 6px; font-family: var(--font-display);
  font-size: clamp(1.35rem, 2.4vw, 1.75rem); letter-spacing: -.03em;
}
.panel > .lead { margin: 0 0 18px; color: var(--muted); font-size: .95rem; }

.hero-panel {
  padding: 28px 24px;
  background:
    radial-gradient(500px 180px at 10% 0%, rgba(30,158,99,.14), transparent 55%),
    radial-gradient(420px 160px at 90% 20%, rgba(20,40,75,.1), transparent 50%),
    rgba(255,255,255,.78);
}
.hero-panel h1 {
  margin: 0; font-family: var(--font-display);
  font-size: clamp(1.7rem, 3.5vw, 2.35rem); letter-spacing: -.04em; line-height: 1.2;
}
.hero-panel p { margin: 10px 0 0; color: var(--muted); max-width: 520px; }

.kpi-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 20px;
}
.kpi {
  padding: 14px 16px; border-radius: 18px;
  background: rgba(255,255,255,.65); border: 1px solid var(--line);
}
.kpi label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); }
.kpi b { display: block; margin-top: 4px; font-size: 1.55rem; font-family: var(--font-display); letter-spacing: -.03em; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 14px;
}
.toolbar .search {
  flex: 1; min-width: 180px; padding: 10px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(255,255,255,.9);
}
.toolbar select {
  padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(255,255,255,.9);
}

.table-wrap { overflow: auto; border-radius: 16px; border: 1px solid var(--line); }
table.data { width: 100%; border-collapse: collapse; background: rgba(255,255,255,.5); }
table.data th, table.data td {
  text-align: right; padding: 11px 12px; border-bottom: 1px solid var(--line);
  font-size: .9rem; vertical-align: middle;
}
table.data th {
  font-size: .78rem; text-transform: none; letter-spacing: 0;
  color: var(--muted); background: rgba(20,40,75,.03); font-weight: 700;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: rgba(30,158,99,.04); }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: 999px; font-size: .75rem; font-weight: 700;
}
.badge-ok { background: var(--accent-soft); color: #0d6b42; }
.badge-warn { background: #FEF3C7; color: #92400E; }
.badge-bad { background: #FEE4E2; color: #B42318; }
.badge-muted { background: rgba(20,40,75,.06); color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.muted { color: var(--muted); font-size: .9rem; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20,40,75,.35); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: min(520px, 100%); max-height: 90vh; overflow: auto;
  border-radius: 24px; background: rgba(255,255,255,.95);
  border: 1px solid var(--line); box-shadow: var(--shadow); padding: 22px;
}
.modal h3 {
  margin: 0 0 6px; font-family: var(--font-display);
  font-size: 1.35rem; letter-spacing: -.02em;
}
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; justify-content: flex-end; }

.mobile-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.88); border-top: 1px solid var(--line);
  backdrop-filter: blur(16px); overflow-x: auto; gap: 4px;
}
.mobile-nav .nav-btn { width: auto; white-space: nowrap; padding: 8px 12px; font-size: .82rem; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding-bottom: 88px; }
  .sidebar { display: none; }
  .mobile-nav { display: flex; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .admin-chip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .blob, .atmosphere, .mesh, body { animation: none; }
}
