/* قياسي — لوحة التحكم. Tokens lifted from docs/design/project/assets/qiyasi.css (light theme). */

:root {
  --paper: #ECE7DC; --surface: #FCFAF5; --card: #FFFFFF;
  --ink: #1E2A2C; --muted: #6E7B7D; --faint: #9AA6A7;
  --line: #E8E2D6; --line-soft: #F0EBE0;
  --emerald: #15795B; --emerald-deep: #136A4A; --emerald-soft: #E2F0EA; --on-emerald: #FFF;
  --gold: #B07D12; --gold-soft: #F8EFD6;
  --terra: #B6543B; --terra-soft: #F4E1DA;
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --pill: 999px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: 'Readex Pro', -apple-system, 'Segoe UI', sans-serif;
  background: var(--paper); color: var(--ink);
  direction: rtl; min-height: 100%; font-size: 15px; line-height: 1.7;
}

/* layout: fixed sidebar (right) + content */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 232px; flex: 0 0 232px; background: var(--surface);
  border-left: 1px solid var(--line); padding: 24px 16px; position: sticky; top: 0;
  height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.logo { font-family: 'Aref Ruqaa', serif; font-weight: 700; font-size: 30px; color: var(--emerald); text-align: center; margin-bottom: 2px; }
.logo .ya { color: var(--gold); }
.logo-sub { text-align: center; color: var(--muted); font-size: 12px; margin-bottom: 20px; }

.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border: 0; background: transparent; border-radius: var(--r-md);
  font: inherit; color: var(--muted); cursor: pointer; text-align: right;
}
.nav-btn svg { flex: 0 0 auto; }
.nav-btn:hover { background: var(--line-soft); }
.nav-btn.on { background: var(--emerald-soft); color: var(--emerald-deep); font-weight: 600; }
.nav-badge { margin-right: auto; background: var(--gold-soft); color: var(--gold); border-radius: var(--pill); font-size: 11px; font-weight: 600; padding: 0 8px; }

.nav { display: flex; flex-direction: column; gap: 4px; }

/* top bar — hidden on desktop, shown on mobile (see media query) */
.topbar { display: none; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
.topbar .logo { font-family: 'Aref Ruqaa', serif; font-weight: 700; font-size: 24px; color: var(--emerald); }
.topbar .logo .ya { color: var(--gold); }
.topbar-title { color: var(--muted); font-weight: 600; font-size: 15px; }
.hamburger { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; background: transparent; color: var(--ink); border-radius: var(--r-md); cursor: pointer; }
.hamburger:hover { background: var(--line-soft); }
.scrim { display: none; position: fixed; inset: 0; background: rgba(20,32,28,.4); z-index: 45; }
.scrim.show { display: block; }

.main { flex: 1; padding: 28px 32px 60px; max-width: 1060px; }

/* analytics: panels + charts */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; }
.chart svg { overflow: visible; }
.chart-legend { display: flex; gap: 18px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 12px; height: 4px; border-radius: 2px; display: inline-block; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.split h2 { margin-top: 22px; }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar-row { display: grid; grid-template-columns: 120px 1fr 54px; gap: 10px; align-items: center; }
.hbar-label { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 12px; background: var(--line-soft); border-radius: var(--pill); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: var(--pill); transition: width .35s; }
.hbar-val { font-size: 13px; color: var(--muted); text-align: left; font-variant-numeric: tabular-nums; }
h1 { font-size: 22px; font-weight: 700; margin-bottom: 2px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
h2 { font-size: 16px; font-weight: 600; margin: 22px 0 10px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; }
.card .k { color: var(--muted); font-size: 12px; }
.card .v { font-size: 26px; font-weight: 700; }
.card .v small { font-size: 13px; color: var(--faint); font-weight: 400; }
.card.em .v { color: var(--emerald); }
.card.gd .v { color: var(--gold); }

.bar { height: 8px; background: var(--line-soft); border-radius: var(--pill); overflow: hidden; margin-top: 8px; }
.bar > div { height: 100%; background: var(--emerald); border-radius: var(--pill); transition: width .3s; }

.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: var(--pill); padding: 2px 11px; font-size: 12px; font-weight: 600; }
.pill.em { background: var(--emerald-soft); color: var(--emerald-deep); }
.pill.gd { background: var(--gold-soft); color: var(--gold); }
.pill.tr { background: var(--terra-soft); color: var(--terra); }
.pill.gh { background: var(--line-soft); color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 0; cursor: pointer;
  background: var(--emerald); color: var(--on-emerald); font: inherit; font-weight: 600;
  padding: 10px 20px; border-radius: var(--r-md);
}
.btn:hover { background: var(--emerald-deep); }
.btn.line { background: transparent; color: var(--emerald-deep); border: 1.5px solid var(--emerald); }
.btn.line:hover { background: var(--emerald-soft); }
.btn.terra { background: transparent; color: var(--terra); border: 1.5px solid var(--terra); }
.btn.terra:hover { background: var(--terra-soft); }
.btn.ghost { background: var(--line-soft); color: var(--muted); }
.btn.sm { padding: 6px 14px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }

.note { display: flex; gap: 10px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; color: var(--muted); font-size: 13px; margin: 14px 0; }
.note.gold { background: var(--gold-soft); border-color: transparent; color: var(--gold); }

/* review card */
.qcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 24px; margin-top: 14px; }
.qhead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.qid { font-size: 12px; color: var(--faint); margin-right: auto; }
.qtext { font-size: 18px; font-weight: 600; margin: 6px 0 16px; }
.passage { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; font-size: 14px; margin-bottom: 14px; }
.passage b { display: block; margin-bottom: 4px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { display: flex; gap: 10px; align-items: baseline; border: 1.5px solid var(--line); border-radius: var(--r-md); padding: 10px 14px; }
.choice.correct { border-color: var(--emerald); background: var(--emerald-soft); }
.choice .key { font-weight: 700; color: var(--muted); }
.choice.correct .key { color: var(--emerald-deep); }
.expl { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 12px; font-size: 14px; }
.expl .lbl { font-size: 12px; color: var(--faint); font-weight: 600; }
.actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* editor */
.editor { display: grid; gap: 10px; margin-top: 14px; }
.editor label { font-size: 12px; color: var(--muted); font-weight: 600; }
.editor textarea, .editor input, .editor select {
  font: inherit; width: 100%; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 12px; background: var(--surface); color: var(--ink); resize: vertical;
}
.editor textarea:focus, .editor input:focus, .editor select:focus { outline: 2px solid var(--emerald-soft); border-color: var(--emerald); }
.ed-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* table */
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--r-lg); overflow: hidden; border: 1px solid var(--line); font-size: 13.5px; }
th { text-align: right; background: var(--surface); color: var(--muted); font-weight: 600; font-size: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
td { padding: 9px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface); }
.num { font-variant-numeric: tabular-nums; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; align-items: center; }
.filters select, .filters input { font: inherit; border: 1.5px solid var(--line); border-radius: var(--r-sm); padding: 7px 12px; background: var(--card); color: var(--ink); }
.filters input { min-width: 220px; }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--r-lg); margin-top: 14px; }
.empty b { display: block; font-size: 16px; color: var(--ink); margin-bottom: 6px; }

/* promo form */
.promo-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; margin-bottom: 16px; }
.promo-form label { font-size: 12px; color: var(--muted); font-weight: 600; display: block; margin-bottom: 4px; }
.promo-form input, .promo-form select { font: inherit; width: 100%; border: 1.5px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; background: var(--surface); }

/* الساحة: segmented control + broadcast composer */
.seg { display: inline-flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--pill); padding: 4px; margin: 6px 0 18px; flex-wrap: wrap; }
.seg-btn { display: inline-flex; align-items: center; gap: 7px; border: 0; background: transparent; font: inherit; color: var(--muted); cursor: pointer; padding: 8px 16px; border-radius: var(--pill); }
.seg-btn:hover { color: var(--ink); }
.seg-btn.on { background: var(--emerald-soft); color: var(--emerald-deep); font-weight: 600; }
.seg-btn svg { flex: 0 0 auto; }

.composer { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; }
.composer > label { font-size: 12px; color: var(--muted); font-weight: 600; display: block; margin-bottom: 8px; }
.composer textarea { font: inherit; width: 100%; border: 1.5px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; background: var(--surface); color: var(--ink); resize: vertical; }
.composer textarea:focus { outline: 2px solid var(--emerald-soft); border-color: var(--emerald); }
.composer-foot { display: flex; align-items: center; gap: 14px; margin-top: 12px; flex-wrap: wrap; }
.composer-foot .chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.composer-foot .counter { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.composer-foot .btn { margin-right: auto; }

.bc-list { display: grid; gap: 12px; }
.bc-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; }
.bc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.bc-head .qid { margin-right: auto; }
.bc-body { font-size: 15px; line-height: 1.7; }
.card.tr-card .v { color: var(--terra); }

/* ---- arena post: attached photo / question / result ---- */
.bc-img { display: block; width: 100%; max-width: 360px; border-radius: var(--r-md); margin: 10px 0 0; border: 1px solid var(--line); }
.bc-attach { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; margin-top: 10px; font-size: 13px; }
.bc-attach-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bc-attach-q { line-height: 1.7; color: var(--ink); }
.bc-attach-a { margin-top: 6px; color: var(--emerald-deep); background: var(--emerald-soft); border-radius: var(--r-sm); padding: 6px 9px; }
.bc-stats { display: flex; gap: 16px; margin-top: 10px; color: var(--muted); font-size: 13px; }
.bc-stats span { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }
.bc-stats svg { color: var(--terra); }
.bc-stats span + span svg { color: var(--muted); }

/* ---- chat moderation thread ---- */
.chat-thread { display: flex; flex-direction: column; gap: 6px; background: var(--surface); border-radius: var(--r-md); padding: 10px; }
.chat-msg { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 7px 10px; font-size: 13px; }
.chat-msg.held { border-color: var(--terra); background: var(--terra-soft); }
.chat-msg .chat-text { flex: 1; line-height: 1.6; }
.chat-msg .qid { margin-right: auto; }

/* ---- urgent alerts banner (overview) ---- */
.note.urgent { background: var(--terra-soft); border-color: transparent; color: var(--terra); align-items: center; }
.note.urgent .btn { margin-right: auto; flex: 0 0 auto; }
.note.urgent b { color: var(--terra); }

.toast {
  position: fixed; bottom: 24px; right: 50%; transform: translateX(50%);
  background: var(--ink); color: #fff; border-radius: var(--pill); padding: 10px 22px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 50;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--terra); }

code { background: var(--line-soft); border-radius: 4px; padding: 1px 6px; font-size: 12.5px; direction: ltr; display: inline-block; }

/* ---- inputs ---- */
.inp { width: 100%; box-sizing: border-box; padding: 10px 13px; border: 1.5px solid var(--line); border-radius: var(--r-md); font: inherit; background: var(--card); color: var(--ink); }
.inp:focus { outline: none; border-color: var(--emerald); }

/* ---- clickable user rows ---- */
tr.rowlink { cursor: pointer; }
tr.rowlink:hover { background: var(--emerald-soft); }
tr.rowlink .chev { color: var(--faint); text-align: left; }

/* ---- modal + danger-confirm ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,32,28,.45); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.modal-box { background: var(--card); border-radius: var(--r-xl); padding: 22px 24px; width: 440px; max-width: 100%; max-height: 88vh; overflow: auto; box-shadow: 0 18px 50px rgba(0,0,0,.25); }
.modal-title { display: flex; align-items: center; gap: 9px; font-size: 18px; margin: 0 0 14px; }
.modal-title.terra { color: var(--terra); }
.modal-msg { color: var(--muted); font-size: 14px; line-height: 1.8; margin: 0 0 12px; }
.modal-msg.hint { font-size: 13px; }
.modal-sub { font-weight: 600; font-size: 13px; color: var(--muted); margin: 16px 0 8px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal-actions.wrap { flex-wrap: wrap; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.kv span { color: var(--muted); }
.kv b { font-weight: 600; text-align: left; }
.mini-sessions { display: flex; flex-direction: column; gap: 4px; }
.mini-sessions > div { display: flex; justify-content: space-between; gap: 10px; background: var(--surface); border-radius: var(--r-sm); padding: 6px 10px; font-size: 13px; }
.mini-sessions span { color: var(--muted); }

/* ---- login gate (public hosting) ---- */
body.locked { overflow: hidden; }
.login-overlay { position: fixed; inset: 0; background: var(--paper); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.login-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 34px 30px; width: 360px; max-width: 100%; text-align: center; box-shadow: 0 18px 50px rgba(0,0,0,.12); }
.login-box .logo { font-family: 'Aref Ruqaa', serif; font-weight: 700; color: var(--emerald); }
.login-lbl { display: block; text-align: right; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.login-err { color: var(--terra); font-size: 13px; margin-top: 10px; }

/* question figures (geometry SVG / data table) */
.qfig{display:flex;justify-content:center;margin:14px 0;color:var(--ink)}
.qfig svg{max-width:340px;width:100%;height:auto}
.qfig-table{border-collapse:collapse;width:100%;max-width:520px;border:1px solid var(--line);border-radius:var(--r-sm);overflow:hidden}
.qfig-table th,.qfig-table td{border:1px solid var(--line);padding:8px 14px;text-align:center;font-size:14px}
.qfig-table th{background:var(--emerald-soft);color:var(--emerald);font-weight:600}

/* ---------------- mobile / iPhone (drawer sidebar + reflow) ---------------- */
@media (max-width: 900px) {
  .topbar { display: flex; }
  .shell { display: block; }
  .side {
    position: fixed; top: 0; right: 0; height: 100dvh; width: 264px; max-width: 84vw;
    transform: translateX(100%); transition: transform .25s ease; z-index: 50;
    box-shadow: -10px 0 40px rgba(0,0,0,.18); overflow-y: auto;
  }
  .side.open { transform: translateX(0); }
  .main { padding: 18px 16px 72px; max-width: 100%; }
  h1 { font-size: 20px; }
  .split { grid-template-columns: 1fr; gap: 6px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .card .v { font-size: 22px; }
  /* tables scroll horizontally instead of overflowing the page */
  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .filters input { min-width: 0; flex: 1; }
  .promo-form { grid-template-columns: 1fr 1fr; }
  .modal-box { width: 100%; padding: 20px 18px; }
  .hbar-row { grid-template-columns: 84px 1fr 44px; gap: 8px; }
  .hbar-label { font-size: 12px; }
  .choices, .ed-choices { grid-template-columns: 1fr; }
  .seg { width: 100%; }
  .btn { padding: 11px 18px; } /* larger touch target */
  .btn.sm { padding: 8px 14px; }
}
@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .composer-foot { gap: 10px; }
  .composer-foot .btn { margin-right: 0; width: 100%; justify-content: center; }
}
