/* ===== Tokens ===== */
:root {
  --bg: #f5f6fb;
  --bg-2: #eaeefe;
  --surface: rgba(255, 255, 255, 0.85);
  --surface-solid: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.08);
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --danger: #e11d48;
  --ok: #059669;
  --shadow: 0 18px 40px -22px rgba(15, 23, 42, 0.35);
  --radius: 22px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --bg-2: #111a33;
    --surface: rgba(20, 27, 48, 0.8);
    --surface-solid: #141b30;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.14);
    --shadow: 0 18px 40px -22px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b1020;
  --bg-2: #111a33;
  --surface: rgba(20, 27, 48, 0.8);
  --surface-solid: #141b30;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.14);
  --shadow: 0 18px 40px -22px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Cairo", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 480px at 8% -8%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 60%),
    radial-gradient(800px 480px at 105% 0%, color-mix(in srgb, var(--brand-2) 14%, transparent), transparent 60%);
  background-attachment: fixed;
  line-height: 1.7;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.3; }
p { margin: 0; }
button, input, select, textarea { font: inherit; }

/* ===== Public: topbar / hero ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.logo {
  width: 36px; height: 36px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 10px 24px -10px var(--brand);
}

.admin-link {
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.92rem;
  padding: 8px 14px; border-radius: 12px; transition: background .25s, color .25s;
}
.admin-link:hover { background: var(--surface-solid); color: var(--text); }

.page { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

.hero {
  padding: 56px 0 28px;
  text-align: center;
  animation: fadeUp .8s var(--ease) backwards;
}
.eyebrow {
  display: inline-block; padding: 6px 14px; border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  color: var(--brand); font-weight: 700; font-size: .85rem; margin-bottom: 14px;
}
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 800; letter-spacing: -0.02em; }
.grad {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lead { color: var(--muted); max-width: 620px; margin: 14px auto 0; font-size: 1.05rem; }

.controls {
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center;
  margin-top: 28px;
}

.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.segmented button {
  border: 0; background: transparent; color: var(--muted);
  padding: 9px 16px; border-radius: 12px; cursor: pointer;
  font-weight: 700; font-size: .95rem; transition: background .3s var(--ease), color .3s;
  display: inline-flex; align-items: center; gap: 6px;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; box-shadow: 0 8px 20px -10px var(--brand);
}
.count {
  font-size: .75rem; min-width: 22px; height: 22px; padding: 0 6px;
  display: inline-grid; place-items: center; border-radius: 999px;
  background: color-mix(in srgb, currentColor 16%, transparent);
}

.search input {
  width: min(320px, 100%); padding: 12px 16px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; outline: none;
  box-shadow: var(--shadow); transition: border-color .25s, box-shadow .25s;
}
.search input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }

/* ===== Public: content / cards ===== */
.content { padding: 20px 0 60px; min-height: 320px; }
.group { margin-top: 28px; }
.group h2 {
  font-size: 1.35rem; font-weight: 800; margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px;
}
.group h2::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }

.c-indigo { --accent: #4f46e5; }
.c-emerald { --accent: #059669; }
.c-amber { --accent: #d97706; }
.c-rose { --accent: #e11d48; }
.c-sky { --accent: #0284c7; }
.c-violet { --accent: #7c3aed; }
.c-slate { --accent: #475569; }

.card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  transition: transform .4s var(--ease), box-shadow .4s var(--ease), border-color .4s;
  animation: rise .7s var(--ease) backwards;
  animation-delay: calc(min(var(--i, 0), 12) * 70ms);
}
.card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 35%, transparent));
}
.card:hover {
  transform: translateY(-6px);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: 0 30px 60px -28px color-mix(in srgb, var(--accent) 60%, transparent);
}

.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.icon {
  width: 58px; height: 58px; border-radius: 18px;
  display: grid; place-items: center; font-size: 28px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  transition: transform .5s var(--ease);
}
.card:hover .icon { transform: scale(1.08) rotate(-4deg); }

.badge {
  padding: 4px 12px; border-radius: 999px; font-size: .78rem; font-weight: 700;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
  white-space: nowrap;
}

.card h3 { font-size: 1.2rem; font-weight: 800; margin-top: 18px; }
.subtitle { color: var(--accent); font-weight: 600; font-size: .92rem; margin-top: 2px; }
.desc { color: var(--muted); margin-top: 10px; font-size: .95rem; }

.steps { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 9px; }
.steps li { position: relative; padding-inline-start: 28px; font-size: .93rem; }
.steps li::before {
  content: "✓"; position: absolute; inset-inline-start: 0; top: 2px;
  width: 19px; height: 19px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px; font-weight: 800;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; margin-top: 28px; }
.skeleton {
  height: 240px; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-solid) 25%, var(--border) 50%, var(--surface-solid) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}

.empty { text-align: center; padding: 60px 16px; color: var(--muted); animation: fadeUp .6s var(--ease) backwards; }
.empty .big { font-size: 46px; margin-bottom: 8px; }

.footer { text-align: center; color: var(--muted); font-size: .9rem; padding: 24px 16px 36px; border-top: 1px solid var(--border); }

/* ===== Buttons / forms ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 14px; padding: 11px 18px; cursor: pointer;
  font-weight: 700; color: var(--text); text-decoration: none;
  transition: transform .2s var(--ease), box-shadow .3s, background .3s, opacity .3s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:disabled { opacity: .6; cursor: wait; transform: none; }
.btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; box-shadow: 0 12px 26px -12px var(--brand);
}
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-solid); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn.sm { padding: 7px 12px; font-size: .85rem; border-radius: 11px; }
.btn.block { width: 100%; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: .9rem; font-weight: 700; color: var(--muted); }
input, select, textarea {
  width: 100%; color: var(--text); background: var(--surface-solid);
  border: 1px solid var(--border); border-radius: 14px; padding: 11px 14px;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent);
}

.error { color: var(--danger); font-size: .92rem; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }

/* Toggle */
.toggle { position: relative; display: inline-block; width: 46px; height: 27px; flex-shrink: 0; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle i {
  position: absolute; inset: 0; border-radius: 99px;
  background: var(--border); transition: background .3s;
}
.toggle i::before {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px;
  width: 21px; height: 21px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
  transition: transform .35s var(--ease);
}
.toggle input:checked + i { background: var(--ok); }
.toggle input:checked + i::before { transform: translateX(-19px); }
.toggle input:focus-visible + i { box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 25%, transparent); }
.switch-field { flex-direction: row; align-items: center; justify-content: space-between; }

/* ===== Admin ===== */
.admin-body { background-color: var(--bg); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.login-card {
  width: min(420px, 100%);
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: 28px; padding: 36px 28px; box-shadow: var(--shadow);
  text-align: center; animation: pop .5s var(--ease) backwards;
}
.login-card .field { text-align: start; }
.login-card .btn.block { margin-top: 6px; }
.login-icon { font-size: 44px; margin-bottom: 6px; }
.login-card h1 { font-size: 1.6rem; font-weight: 800; }
.login-card .muted { margin: 8px 0 22px; font-size: .95rem; }
.back-link { display: inline-block; margin-top: 16px; color: var(--muted); text-decoration: none; font-size: .92rem; }
.back-link:hover { color: var(--brand); }

.dash { min-height: 100vh; }
.dash-top {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.dash-top .brand div { display: flex; flex-direction: column; line-height: 1.3; }
.dash-top small { font-weight: 600; font-size: .82rem; }
.top-actions { display: flex; gap: 8px; }

.dash-main { max-width: 980px; margin: 0 auto; padding: 24px 16px 60px; animation: fadeUp .5s var(--ease) backwards; }
.dash-toolbar { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; margin-bottom: 20px; }

.admin-list { display: grid; gap: 12px; }
.row {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: 18px; padding: 14px 18px; box-shadow: var(--shadow);
  transition: transform .3s var(--ease), opacity .3s;
  animation: rise .5s var(--ease) backwards;
  animation-delay: calc(min(var(--i, 0), 12) * 40ms);
}
.row:hover { transform: translateX(-3px); }
.row.is-off { opacity: .55; }
.row-icon {
  width: 50px; height: 50px; border-radius: 15px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 23px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.row-body { flex: 1; min-width: 0; }
.row-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-title strong { font-size: 1.02rem; }
.row-body p { font-size: .9rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip {
  font-size: .75rem; font-weight: 700; padding: 2px 10px; border-radius: 999px;
  background: var(--bg-2); color: var(--muted);
}
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 16px;
  background: rgba(2, 6, 23, .55); backdrop-filter: blur(6px);
  animation: fade .25s ease both;
}
.modal-box {
  width: min(640px, 100%); max-height: 92vh; overflow: auto;
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: 26px; padding: 24px; box-shadow: var(--shadow);
  animation: pop .35s var(--ease) both;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { font-size: 1.25rem; font-weight: 800; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 12px; border: 1px solid var(--border);
  background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-2); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.full { grid-column: 1 / -1; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 6px; }

.toast {
  position: fixed; bottom: 22px; inset-inline: 0; margin-inline: auto; width: max-content; max-width: calc(100% - 32px);
  padding: 12px 20px; border-radius: 14px; z-index: 100;
  background: var(--text); color: var(--surface-solid); font-weight: 700;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(20px); pointer-events: none;
  transition: opacity .3s var(--ease), transform .3s var(--ease);
}
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--danger); color: #fff; }

/* ===== Animations ===== */
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .hero { padding-top: 36px; }
  .grid, .skeleton-grid { grid-template-columns: 1fr; }
  .segmented { width: 100%; justify-content: center; }
  .segmented button { flex: 1; justify-content: center; padding: 9px 10px; font-size: .88rem; }
  .search input { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .row { flex-wrap: wrap; }
  .row-actions { width: 100%; justify-content: flex-start; }
  .row-body p { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
