:root {
  --bg: #f6f2e9;
  --surface: #fffdf8;
  --surface-2: #f0eadc;
  --ink: #1d2a26;
  --muted: #66736e;
  --line: #e4dccb;
  --brand: #07665c;
  --brand-ink: #ffffff;
  --brand-soft: #dcefea;
  --gold: #c48a1c;
  --gold-soft: #fbedcf;
  --ok: #1f7a4f;
  --ok-soft: #e0f2e8;
  --warn: #a36a07;
  --warn-soft: #fbefd5;
  --bad: #b23b3b;
  --bad-soft: #f8e1e1;
  --shadow: 0 1px 2px rgba(30, 40, 35, .06), 0 6px 24px rgba(30, 40, 35, .06);
  --radius: 14px;
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --display: "Amiri", "Traditional Arabic", serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111816; --surface: #18211e; --surface-2: #1f2a26; --ink: #e8efe9; --muted: #9aa8a2;
    --line: #2b3833; --brand: #3fae93; --brand-ink: #0b1311; --brand-soft: #1c3a32;
    --gold: #d9ae55; --gold-soft: #3a3020; --ok: #4cc28a; --ok-soft: #173327; --warn: #e2a63e;
    --warn-soft: #3a2e15; --bad: #e57373; --bad-soft: #3a1f1f; --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111816; --surface: #18211e; --surface-2: #1f2a26; --ink: #e8efe9; --muted: #9aa8a2;
  --line: #2b3833; --brand: #3fae93; --brand-ink: #0b1311; --brand-soft: #1c3a32;
  --gold: #d9ae55; --gold-soft: #3a3020; --ok: #4cc28a; --ok-soft: #173327; --warn: #e2a63e;
  --warn-soft: #3a2e15; --bad: #e57373; --bad-soft: #3a1f1f; --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.display { font-family: var(--display); font-weight: 700; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side {
  background: var(--brand); color: var(--brand-ink); padding: 22px 16px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
  background-image: radial-gradient(circle at 20% 0%, rgba(255,255,255,.10), transparent 45%);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 18px; border-bottom: 1px solid rgba(255,255,255,.15); margin-bottom: 10px; }
.brand-mark { width: 40px; height: 40px; flex: none; }
.brand b { font-family: var(--display); font-size: 22px; display: block; line-height: 1.1; }
.brand small { opacity: .75; font-size: 12px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: inherit;
  text-decoration: none; opacity: .85; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.08); opacity: 1; }
.nav a.on { background: rgba(255,255,255,.16); opacity: 1; }
.nav svg { width: 20px; height: 20px; flex: none; }
.side-foot { margin-top: auto; font-size: 13px; opacity: .85; padding: 10px 6px 0; border-top: 1px solid rgba(255,255,255,.15); }
.side-foot button { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; }

.main { padding: 26px 32px 60px; max-width: 1180px; width: 100%; }
.topbar { display: none; }
.tabbar { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-family: var(--display); font-size: 30px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }

.demo-banner {
  background: var(--gold-soft); color: var(--ink); border: 1px dashed var(--gold); border-radius: 10px;
  padding: 8px 12px; font-size: 13px; margin-bottom: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.demo-banner button { margin-inline-start: auto; }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 17px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack > * + * { margin-top: 16px; }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 4px; }
.stat .s { font-size: 12px; color: var(--muted); }
.stat.accent { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.stat.accent .k, .stat.accent .s { color: inherit; opacity: .8; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent;
  background: var(--brand); color: var(--brand-ink); padding: 9px 16px; border-radius: 10px; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.gold { background: var(--gold); color: #fff; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 12px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { min-height: 80px; resize: vertical; }
.input[dir="ltr"] { text-align: left; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; cursor: pointer;
  font-size: 13px; user-select: none; transition: background .12s, border-color .12s;
}
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip.on.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.chip.on.warn { background: var(--warn); border-color: var(--warn); color: #fff; }

.badge { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.gold { background: var(--gold-soft); color: var(--gold); }

.section { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.section h3 { font-size: 15px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.section h3 .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.num { font-variant-numeric: tabular-nums; }

.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; }
.item .d { font-size: 13px; color: var(--muted); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--gold-soft); color: var(--gold); display: grid;
  place-items: center; font-weight: 700; flex: none; font-family: var(--display); font-size: 18px;
}
.clickable { cursor: pointer; border-radius: 10px; }
.clickable:hover { background: var(--surface-2); }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; padding-top: 6px; }
.bars div { flex: 1; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; opacity: .85; }
.bars div.zero { background: var(--line); }
.bars-x { display: flex; gap: 4px; font-size: 10px; color: var(--muted); }
.bars-x span { flex: 1; text-align: center; }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--brand); border-radius: 99px; }

.timeline .tl { border-inline-start: 2px solid var(--line); padding: 0 16px 16px; position: relative; }
.timeline .tl::before { content: ""; position: absolute; inset-inline-start: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline .tl.absent::before { background: var(--bad); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.media { border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 16/9; }
.media iframe { width: 100%; height: 100%; border: 0; }
.audio-box { background: var(--brand-soft); border-radius: 12px; padding: 16px; }
.audio-box audio { width: 100%; }

.q { padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.q + .q { margin-top: 10px; }
.q .opts { display: grid; gap: 6px; margin-top: 8px; }
.opt { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.opt:hover { border-color: var(--brand); }
.opt.right { background: var(--ok-soft); border-color: var(--ok); }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art {
  background: var(--brand); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  background-image: radial-gradient(circle at 80% 10%, rgba(255,255,255,.14), transparent 40%), radial-gradient(circle at 10% 90%, rgba(176,131,42,.35), transparent 45%);
  position: relative; overflow: hidden;
}
.login-art .pattern { position: absolute; inset: 0; opacity: .08; }
.login-art h1 { font-family: var(--display); font-size: 54px; line-height: 1.1; position: relative; }
.login-art .ayah { font-family: var(--display); font-size: 26px; line-height: 1.8; position: relative; max-width: 460px; }
.login-art .ayah small { display: block; font-family: var(--font); font-size: 13px; opacity: .7; }
.login-form { display: grid; place-items: center; padding: 32px 20px; }
.login-form form { width: 100%; max-width: 360px; }
.login-form h2 { font-family: var(--display); font-size: 30px; margin-bottom: 4px; }
.err { background: var(--bad-soft); color: var(--bad); padding: 8px 12px; border-radius: 10px; font-size: 14px; }

/* ---------- Modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 25, 20, .45); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h2 { font-family: var(--display); font-size: 24px; margin-bottom: 14px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 60; font-weight: 500; animation: fade .2s; max-width: 90vw; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar {
    display: flex; align-items: center; gap: 10px; background: var(--brand); color: var(--brand-ink); padding: 12px 16px;
    position: sticky; top: 0; z-index: 20;
  }
  .topbar b { font-family: var(--display); font-size: 20px; }
  .topbar .brand-mark { width: 30px; height: 30px; }
  .topbar .who { margin-inline-start: auto; font-size: 13px; opacity: .9; }
  .main { padding: 16px 16px 96px; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; inset-inline: 0; background: var(--surface); border-top: 1px solid var(--line);
    z-index: 20; padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-size: 11px; color: var(--muted); text-decoration: none; }
  .tabbar a.on { color: var(--brand); font-weight: 600; }
  .tabbar svg { width: 22px; height: 22px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-head h1 { font-size: 25px; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { padding: 28px 20px; min-height: auto; }
  .login-art h1 { font-size: 36px; }
  .login-art .ayah { font-size: 20px; margin-top: 16px; }
  .hide-m { display: none; }
}

/* =============================================================
   المرحلة الثالثة
   ============================================================= */
.nav a { position: relative; }
.nav-count {
  font-style: normal; margin-inline-start: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px;
  background: var(--gold); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center;
}
.bell { margin-inline-start: 8px; color: inherit; position: relative; display: grid; place-items: center; width: 34px; height: 34px; }
.bell svg { width: 22px; height: 22px; }
.bell .nav-count { position: absolute; top: -2px; inset-inline-end: -4px; margin: 0; }
.side { overflow-y: auto; }
.nav a { padding: 8px 12px; }

.points-big { font-size: 34px; font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; line-height: 1.1; }
.points-pill { margin-inline-start: auto; background: var(--gold-soft); color: var(--gold); border-radius: 999px; padding: 6px 14px; font-weight: 700; }
.points-pill .num { font-size: 20px; }

.medals { display: flex; flex-wrap: wrap; gap: 8px; }
.medal {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px 5px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: linear-gradient(180deg, var(--gold-soft), var(--surface)); border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent); color: var(--ink);
}
.medal i { font-style: normal; }

/* لوحة الشرف */
.podium-card { background: linear-gradient(180deg, var(--brand-soft), var(--surface) 70%); }
.podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; align-items: end; max-width: 620px; margin: 0 auto; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; text-decoration: none; color: inherit; min-width: 0; }
.pod b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.pod .avatar { width: 54px; height: 54px; font-size: 22px; border: 3px solid var(--surface); box-shadow: var(--shadow); }
.pod-1 .avatar { width: 66px; height: 66px; font-size: 26px; border-color: var(--gold); }
.pod-crown { font-size: 26px; line-height: 1; }
.pod-step {
  width: 100%; margin-top: 6px; border-radius: 12px 12px 4px 4px; background: var(--brand); color: var(--brand-ink);
  display: flex; flex-direction: column; justify-content: center; padding: 10px 4px;
}
.pod-step .num { font-size: 24px; font-weight: 700; line-height: 1.1; }
.pod-step small { opacity: .8; font-size: 11px; }
.pod-1 .pod-step { min-height: 110px; background: var(--gold); }
.pod-2 .pod-step { min-height: 82px; }
.pod-3 .pod-step { min-height: 62px; opacity: .9; }

/* الجدول الأسبوعي */
.week { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); gap: 8px; min-width: 860px; }
.wday { background: var(--surface-2); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.wday.today { outline: 2px solid var(--gold); }
.wday-h { font-weight: 700; font-size: 13px; text-align: center; padding: 2px 0 4px; }
.slot { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; font-size: 12px; gap: 1px; }
.slot b { font-size: 13px; }
.slot.mine { border-color: var(--brand); background: var(--brand-soft); }
.slot[role="button"] { cursor: pointer; }
.slot[role="button"]:hover { border-color: var(--brand); }
.empty-slot { text-align: center; color: var(--muted); background: transparent; border-style: dashed; }

.total-box { display: flex; align-items: center; gap: 10px; background: var(--brand-soft); border-radius: 12px; padding: 12px 14px; }
.total-box b { font-size: 26px; color: var(--brand); margin-inline-start: auto; }

/* خريطة الحفظ */
.juz-grid { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 8px; }
.juz {
  position: relative; border: 1px solid var(--line); border-radius: 12px; padding: 10px 4px 8px; cursor: pointer; overflow: hidden; color: var(--ink);
  background: linear-gradient(to top, color-mix(in srgb, var(--brand) 28%, var(--surface)) var(--p), var(--surface) var(--p));
  display: flex; flex-direction: column; align-items: center; gap: 2px; font: inherit;
}
.juz:hover { border-color: var(--brand); }
.juz.official { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.juz-n { font-family: var(--display); font-size: 20px; font-weight: 700; line-height: 1; }
.juz-p { font-size: 11px; color: var(--muted); }
.juz-tag { font-size: 10px; color: var(--gold); font-weight: 700; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); display: inline-block; }
.lg.m { background: var(--brand); border-color: var(--brand); }
.lg.x { background: var(--bad); border-color: var(--bad); }
.surah-list { max-height: 640px; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.srow { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 4px; border-bottom: 1px solid var(--line); border-radius: 8px; transition: background .3s; }
.srow.flash { background: var(--gold-soft); }
.sname { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; text-align: right; cursor: pointer; color: var(--ink); }
.sname:hover { color: var(--brand); }
.cells { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 2px; }
.cells i { width: 7px; height: 7px; border-radius: 2px; background: var(--surface-2); }
.cells i.m { background: var(--brand); }
.cells i.x { background: var(--bad); }
.mushaf-text { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.basmala { font-family: "Amiri Quran", var(--display); font-size: 22px; text-align: center; margin: 4px 0 12px; color: var(--brand); }
.quran { font-family: "Amiri Quran", var(--display); font-size: 23px; line-height: 2.3; text-align: justify; }
.ay { border-radius: 6px; padding: 0 2px; }
.ay.m { background: color-mix(in srgb, var(--brand) 16%, transparent); }
.ay.x { text-decoration: underline wavy var(--bad); text-underline-offset: 8px; text-decoration-thickness: 1.5px; }
.ayn { color: var(--gold); font-size: .8em; }

/* الإشعارات */
.notif { text-decoration: none; color: inherit; }
.notif-ic { font-size: 20px; width: 32px; text-align: center; flex: none; }
.dot-s { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot-s.ok { background: var(--ok); } .dot-s.warn { background: var(--warn); } .dot-s.bad { background: var(--bad); }
.dot-s.gold { background: var(--gold); } .dot-s.brand { background: var(--brand); }

.more-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.more-item {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 6px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; text-decoration: none; color: var(--ink); font-size: 13px; text-align: center; cursor: pointer;
}
.more-item svg { width: 26px; height: 26px; color: var(--brand); }

/* التقرير الشهري */
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 20px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid var(--brand); padding-bottom: 12px; gap: 12px; }
.sheet-brand { font-family: var(--display); font-size: 26px; font-weight: 700; color: var(--brand); }
.sheet-who { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.sheet-stats .stat { box-shadow: none; }
.sheet-h { font-size: 14px; margin: 0 0 8px; color: var(--brand); }
table.compact td, table.compact th { padding: 5px 6px; }
.recs { margin: 0; padding-inline-start: 18px; }
.recs li + li { margin-top: 4px; }
.juz-strip { display: grid; grid-template-columns: repeat(30, minmax(0, 1fr)); gap: 3px; margin-top: 8px; }
.juz-strip span {
  height: 34px; border-radius: 5px; border: 1px solid var(--line); display: grid; place-items: end center; font-size: 9px; color: var(--muted);
  background: linear-gradient(to top, var(--brand) var(--p), var(--surface-2) var(--p));
}
.juz-strip span.off { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.juz-strip i { font-style: normal; background: var(--surface); border-radius: 3px; padding: 0 2px; line-height: 1.3; margin-bottom: 2px; }
.sheet-sign { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; padding-top: 16px; font-size: 13px; color: var(--muted); text-align: center; }
.sheet-sign span { display: block; border-bottom: 1px dotted var(--muted); height: 34px; }

/* الشهادة */
.cert-wrap { overflow-x: auto; padding: 4px; }
.cert {
  --cg: #a87b22; --ci: #1f3b33;
  position: relative; min-width: 760px; max-width: 1000px; margin: 0 auto; aspect-ratio: 1.414; background: #fffaf0; color: var(--ci);
  border: 10px double var(--cg); outline: 2px solid var(--cg); outline-offset: -22px; padding: 56px 80px 40px; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; font-family: var(--display);
  background-image: radial-gradient(circle at 50% 45%, rgba(168,123,34,.10), transparent 60%);
}
.cert-corner { position: absolute; width: 88px; height: 88px; color: var(--cg); }
.cert-corner.tl { top: 26px; left: 26px; } .cert-corner.tr { top: 26px; right: 26px; transform: scaleX(-1); }
.cert-corner.bl { bottom: 26px; left: 26px; transform: scaleY(-1); } .cert-corner.br { bottom: 26px; right: 26px; transform: scale(-1); }
.cert-brand { font-size: 20px; color: var(--cg); letter-spacing: .02em; }
.cert-basmala { font-size: 22px; }
.cert-title { font-size: 56px; color: #0f5c4d; margin: 0; line-height: 1.2; }
.cert-line { font-size: 21px; margin: 0; line-height: 1.9; max-width: 640px; }
.cert-line.small { font-size: 16px; color: #5b6b65; }
.cert-name { font-size: 46px; font-weight: 700; color: var(--cg); border-bottom: 1px solid var(--cg); padding: 0 40px 4px; margin: 4px 0 6px; line-height: 1.4; }
.cert-ayah { font-size: 22px; color: #0f5c4d; margin: 6px 0 0; }
.cert-foot { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; width: 100%; margin-top: 18px; gap: 20px; font-family: var(--font); }
.cert-foot > div:not(.cert-seal) { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--cg); padding-top: 8px; font-size: 14px; }
.cert-foot span { color: #7a6a45; font-size: 12px; }
.cert-foot small { color: #7a6a45; font-size: 12px; }
.cert-seal svg { width: 86px; height: 86px; color: var(--cg); }

@media (max-width: 860px) {
  .juz-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .mushaf-text { position: static; max-height: none; }
  .sheet { padding: 16px; }
  .sheet-sign { grid-template-columns: 1fr; }
  .juz-strip { grid-template-columns: repeat(15, minmax(0, 1fr)); }
  .podium { gap: 6px; }
}

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff !important; }
  .side, .topbar, .tabbar, .demo-banner, .no-print, .toast { display: none !important; }
  .shell { display: block; }
  .main { padding: 0 !important; max-width: none; }
  .sheet { box-shadow: none; border: 0; padding: 0; }
  .cert-wrap { padding: 0; overflow: visible; }
  .cert { min-width: 0; width: 100%; max-width: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .juz-strip span, .stat, .badge, .chip, .medal { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.card h2 svg, .sheet h2 svg { width: 20px; height: 20px; flex: none; color: var(--brand); }

/* رسائل التذكير */
.rem h2 { margin: 0; }
.rem.off { opacity: .6; }
.rem-when { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0 10px; }
.rem-when b { font-size: 18px; }
.bubble { background: var(--brand-soft); color: var(--ink); border-radius: 16px 16px 16px 4px; padding: 10px 14px; line-height: 1.8; margin-bottom: 10px; overflow-wrap: anywhere; }
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; cursor: pointer; transition: background .2s; }
.switch span::before { content: ""; position: absolute; width: 20px; height: 20px; top: 3px; inset-inline-start: 3px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(-18px); }
.switch input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }

/* منع التمدد الأفقي على الموبايل */
.shell > div, .main, .grid > *, .stack > *, .card { min-width: 0; }
.page-head > * { min-width: 0; }

/* الهوية المخصصة */
.brand-img { object-fit: contain; border-radius: 8px; background: rgba(255,255,255,.92); padding: 3px; }
.cert { background-color: var(--cpaper, #fffaf0); color: var(--ci); }
.cert-title, .cert-ayah { color: var(--cgreen, #0f5c4d) !important; }
.cert-logo { max-height: 78px; max-width: 220px; object-fit: contain; }
.cert-seal img { width: 96px; height: 96px; object-fit: contain; }
.cert-sign { max-height: 54px; max-width: 180px; object-fit: contain; margin: 0 auto -4px; }
.cert.has-bg { border: 0; outline: 0; background-size: 100% 100%; background-repeat: no-repeat; }

/* تنبيه ميعاد التذكير */
.rem-alert {
  position: fixed; z-index: 55; inset-inline: 16px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); max-width: 520px; margin-inline: auto;
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px;
  background: var(--ink); color: var(--bg); box-shadow: 0 12px 40px rgba(0,0,0,.25); animation: fade .2s;
}
.rem-alert .btn.ghost { color: var(--bg); border-color: rgba(255,255,255,.3); }
@media (min-width: 861px) { .rem-alert { bottom: 24px; } }
.how-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.how-steps div { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.how-steps b { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.how-perm { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.send-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--gold-soft); border-radius: 12px; padding: 12px; }
a.btn.done { background: var(--ok-soft); color: var(--ok); }
@media (max-width: 860px) { .how-steps { grid-template-columns: 1fr; } }

/* =============================================================
   الشهادات (القوالب)
   ============================================================= */
.certx-wrap { overflow-x: auto; padding: 2px; }
.certx {
  position: relative; container-type: inline-size; width: 100%; max-width: 1100px; margin: 0 auto;
  aspect-ratio: 297 / 210; background: #fff; box-shadow: var(--shadow); overflow: hidden; color: #222;
}
.certx.port { aspect-ratio: 210 / 297; max-width: 760px; }
.certx-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; display: block; }
.cf { position: absolute; transform: translate(-50%, -50%); line-height: 1.55; text-wrap: balance; white-space: pre-line; }
.cf b { font-weight: 700; }
.cf-img { position: absolute; transform: translate(-50%, -50%); height: auto; }
.certx-grid { position: absolute; inset: 0; pointer-events: none; }
.certx-grid i { position: absolute; background: rgba(220, 40, 40, .45); }
.certx-grid .gx { top: 0; bottom: 0; width: 1px; }
.certx-grid .gy { left: 0; right: 0; height: 1px; }
.certx-grid b { position: absolute; font: 700 11px/1 system-ui, sans-serif; color: #fff; background: rgba(200, 30, 30, .85); padding: 2px 3px; border-radius: 3px; }
.certx-grid .gx b { top: 2px; transform: translateX(-50%); }
.certx-grid .gy b { right: 2px; transform: translateY(-50%); }
.honor-tools { margin-bottom: 16px; }
.login-logos { display: flex; align-items: center; justify-content: center; gap: 22px; margin-bottom: 8px; }
.login-logos img { height: 76px; width: auto; object-fit: contain; }
.brand-img { background: none !important; padding: 0 !important; border-radius: 0 !important; object-fit: contain; }

@media print {
  .certx-wrap { overflow: visible; padding: 0; }
  .certx { width: 297mm; height: 210mm; max-width: none; aspect-ratio: auto; box-shadow: none; margin: 0; break-inside: avoid; }
  .certx.port { width: 210mm; height: 297mm; }
  .certx-grid { display: none !important; }
}
.nav-count[hidden] { display: none !important; }

/* أي عنصر مخفي يفضل مخفي مهما كان شكله */
[hidden] { display: none !important; }

/* بوابة الطالب */
.rec-box { background: var(--gold-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 8px 0; line-height: 1.8; }
.exam-alert { border-color: var(--gold); background: linear-gradient(180deg, var(--gold-soft), var(--surface) 70%); }
.result { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.result + .result { margin-top: 12px; }
.rubric { display: grid; gap: 6px; }
.rubric > div { display: grid; grid-template-columns: minmax(110px, 1fr) 2fr auto; gap: 10px; align-items: center; }
.result > .btn { align-self: flex-start; }
