:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #14212b;
  --muted: #5b6b78;
  --line: #dde3e8;
  --brand: #0e5a6b;
  --brand-ink: #ffffff;
  --brand-soft: #e3f0f2;
  --accent: #f2b705;
  --accent-soft: #fff4cc;
  --good: #1f7a4d;
  --good-soft: #e2f3ea;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 33, 43, 0.06), 0 4px 16px rgba(16, 33, 43, 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f171d;
    --surface: #17222a;
    --ink: #e7eef2;
    --muted: #9aabb7;
    --line: #2a3843;
    --brand: #3aa7bd;
    --brand-ink: #06161b;
    --brand-soft: #16343c;
    --accent: #f2c233;
    --accent-soft: #3a3214;
    --good: #5cc08d;
    --good-soft: #143326;
    --bad: #f08a82;
    --bad-soft: #3a1a18;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'IBM Plex Sans Arabic', system-ui, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
body.has-ad { padding-bottom: 92px; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.35; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.hidden { display: none !important; }

/* ---------- الهيكل ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.topbar nav { display: flex; gap: 6px; }
.wrap { max-width: 960px; margin: 0 auto; padding: 20px 16px 40px; }
.narrow { max-width: 460px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.stack > * + * { margin-top: 16px; }

/* ---------- الأزرار والحقول ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 18px;
  border: 1px solid var(--brand); border-radius: 10px;
  background: var(--brand); color: var(--brand-ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #2b2100; }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.sm { min-height: 34px; padding: 4px 12px; font-size: 0.9rem; }
.btn.block { width: 100%; }
.link-btn { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

label { display: block; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
input[dir='ltr'] { text-align: left; }
.field + .field { margin-top: 14px; }
.otp-input { letter-spacing: 0.6em; text-align: center; font-size: 1.4rem; direction: ltr; }

.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--accent-soft); color: #7a5b00; }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
@media (prefers-color-scheme: dark) { .chip.warn { color: var(--accent); } }

.notice { padding: 12px 14px; border-radius: 10px; background: var(--brand-soft); }
.notice.good { background: var(--good-soft); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.warn { background: var(--accent-soft); }

/* ---------- الصفحة الرئيسية للزائر ---------- */
.hero { padding: 36px 0 8px; }
.hero h1 { font-size: clamp(1.6rem, 4.5vw, 2.4rem); }
.hero .lead { font-size: 1.1rem; color: var(--muted); max-width: 640px; }
.road {
  height: 10px; border-radius: 5px; margin: 22px 0;
  background: repeating-linear-gradient(90deg, var(--accent) 0 34px, transparent 34px 56px), var(--ink);
  background-size: 100% 3px, 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
}
.product h2 { display: flex; align-items: center; gap: 8px; }
.product ul { margin: 0; padding-inline-start: 1.2em; }
.product li + li { margin-top: 4px; }
.price { font-size: 1.6rem; font-weight: 700; }
.price small { font-size: 0.9rem; font-weight: 500; color: var(--muted); }

/* ---------- لوحة المشترك ---------- */
.plan-card { display: flex; flex-direction: column; gap: 10px; }
.plan-card .actions { margin-top: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.tile {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px; border-radius: 12px; border: 1px dashed var(--line);
  background: var(--bg);
}
.tile b { font-size: 1rem; }
.tile.locked { opacity: 0.6; }

table.list { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.list th, table.list td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
table.list th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.table-scroll { overflow-x: auto; }
table.kv { width: 100%; border-collapse: collapse; margin: 16px 0; }
table.kv th, table.kv td { padding: 10px 6px; border-bottom: 1px solid var(--line); text-align: start; }
table.kv th { width: 35%; color: var(--muted); font-weight: 600; }

/* ---------- شريط الإعلان ---------- */
.ad-bar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 8px 44px 8px 8px;
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
}
.ad-bar a { display: block; max-width: 728px; width: 100%; }
.ad-bar img { display: block; width: 100%; max-height: 76px; object-fit: contain; border-radius: 8px; }
.ad-bar .ad-label { position: absolute; top: 4px; inset-inline-start: 10px; font-size: 0.7rem; color: var(--muted); }
.ad-bar .ad-close { position: absolute; top: 50%; inset-inline-end: 8px; transform: translateY(-50%); width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; font-size: 1rem; }

/* ---------- نافذة منبثقة ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(5, 12, 16, 0.55); }
.modal .card { width: 100%; max-width: 480px; max-height: 92vh; overflow: auto; }

.toast { position: fixed; z-index: 50; top: 72px; inset-inline: 16px; margin: 0 auto; max-width: 480px; padding: 12px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); text-align: center; }

/* ---------- لوحة التحكم ---------- */
.admin-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.admin-side { background: var(--surface); border-inline-end: 1px solid var(--line); padding: 16px 10px; }
.admin-side button { display: block; width: 100%; text-align: start; padding: 10px 12px; margin-bottom: 4px; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; cursor: pointer; }
.admin-side button.on { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.admin-main { padding: 20px; min-width: 0; }
.stat { padding: 16px; }
.stat .num { font-size: 1.6rem; font-weight: 700; }
@media (max-width: 760px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-side { display: flex; overflow-x: auto; gap: 4px; padding: 8px; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .admin-side button { width: auto; white-space: nowrap; margin: 0; }
  .admin-side .side-title { display: none; }
}

/* ---------- صفحات مستقلة: الفاتورة والدفع التجريبي ---------- */
.invoice main, .mock-pay main { margin-top: 40px; }
@media print {
  .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 0; }
}
