/* لوحة إدارة Chat & Chart — هوية التطبيق: بنفسجي داكن #180839 وعاجي #FEF8F0. فاتح/داكن، عربي RTL وإنجليزي LTR. */
:root {
  --brand: #180839; --cream: #FEF8F0; --accent: #5b2bd9; --accent-2: #7c4dff;
  --bg: #FEF8F0; --surface: #ffffff; --surface-2: #f6efe4; --line: #e7dccb; --text: #180839; --muted: #6b6280;
  --ok: #16794a; --ok-bg: #e3f4ea; --warn: #9a5a00; --warn-bg: #fff1d6; --danger: #b3261e; --danger-bg: #fde7e5;
  --shadow: 0 1px 2px rgba(24, 8, 57, .06), 0 4px 16px rgba(24, 8, 57, .06);
  --radius: 12px; --side: 248px;
  font-family: "Segoe UI", "Noto Sans Arabic", Tahoma, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0821; --surface: #170f33; --surface-2: #1f1642; --line: #2e2457; --text: #f4eee4; --muted: #a79fc2;
    --accent: #9d7bff; --accent-2: #b39bff; --ok: #6fd3a0; --ok-bg: #12352a; --warn: #f2b45a; --warn-bg: #3a2a10;
    --danger: #ff8a80; --danger-bg: #3d1717; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0821; --surface: #170f33; --surface-2: #1f1642; --line: #2e2457; --text: #f4eee4; --muted: #a79fc2;
  --accent: #9d7bff; --accent-2: #b39bff; --ok: #6fd3a0; --ok-bg: #12352a; --warn: #f2b45a; --warn-bg: #3a2a10;
  --danger: #ff8a80; --danger-bg: #3d1717; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.55; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 1rem; margin: 0 0 10px; }
.skip { position: absolute; inset-inline-start: -999px; }
.skip:focus { inset-inline-start: 8px; top: 8px; z-index: 99; background: var(--surface); padding: 6px 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.muted { color: var(--muted); }
.small, small { font-size: .85rem; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* أزرار وحقول */
button { font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid transparent; padding: 8px 14px; min-height: 38px; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); color: #fff; }
button.danger { background: var(--danger); color: #fff; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--surface-2); }
button.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
button.icon { background: transparent; border: 0; font-size: 1.3rem; padding: 4px 10px; color: inherit; }
button.link { background: none; border: 0; color: var(--accent); padding: 6px 0; min-height: 0; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; min-height: 38px; width: 100%; }
textarea { resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { opacity: .7; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-weight: 600; font-size: .9rem; }
.field small { color: var(--muted); }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; white-space: nowrap; }
.form-err { color: var(--danger); margin: 6px 0; }
.form-ok { color: var(--ok); margin: 6px 0; }
.code { font-size: 1.4rem; letter-spacing: .3em; text-align: center; }

/* الدخول */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand), #2b1361 60%, var(--bg) 60%); }
.auth-card { width: min(420px, 100%); background: var(--surface); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.auth-brand h1 { font-size: 1.15rem; margin: 0; }
.auth-card form button.primary { width: 100%; margin-top: 4px; }
.auth-foot { margin-top: 14px; text-align: center; }
.mfa-setup { margin-bottom: 12px; }
.qr { width: 180px; height: 180px; display: block; margin: 8px auto; background: #fff; }
.logo { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--brand); color: var(--cream); font-weight: 700; font-size: .8rem; flex: none; }
.env { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 2px 10px; font-size: .82rem; }

/* الهيكل */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--brand); color: var(--cream); }
.top .brand { display: flex; align-items: center; gap: 10px; color: var(--cream); text-decoration: none; font-weight: 600; }
.top .logo { background: var(--cream); color: var(--brand); }
.top button.ghost { color: var(--cream); border-color: rgba(254,248,240,.3); }
.top button.ghost:hover { background: rgba(254,248,240,.1); }
.top .who { font-size: .85rem; opacity: .9; }
.menu-btn { display: none; }
.banner { background: var(--warn-bg); color: var(--warn); padding: 8px 16px; text-align: center; }
.layout { display: flex; min-height: calc(100vh - 54px); }
nav.side { width: var(--side); flex: none; padding: 12px 8px; border-inline-end: 1px solid var(--line); background: var(--surface); position: sticky; top: 54px; height: calc(100vh - 54px); overflow-y: auto; }
nav.side a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-radius: 9px; color: var(--text); text-decoration: none; }
nav.side a:hover { background: var(--surface-2); }
nav.side a.on { background: var(--accent); color: #fff; }
.badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 7px; min-width: 20px; text-align: center; }
main { flex: 1; min-width: 0; padding: 20px 24px 90px; }
main:focus { outline: none; }
.page { max-width: 1100px; }
nav.bottom { display: none; }
.scrim { display: none; }

/* محتوى */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--text); }
.stat b { font-size: 1.6rem; }
.stat.warn { border-color: var(--warn); background: var(--warn-bg); }
.stat.danger { border-color: var(--danger); background: var(--danger-bg); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input[type="search"] { flex: 1 1 260px; width: auto; }
.filters select { width: auto; }
.filters input[type="date"] { width: auto; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list:empty { display: none; }
.row { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; flex-wrap: wrap; }
.row:last-child { border-bottom: 0; }
.row[role="button"], .row[role="link"], a.row { cursor: pointer; }
.row:hover { background: var(--surface-2); }
.row.unread { font-weight: 600; }
.row.urgent { box-shadow: inset 3px 0 0 var(--warn); }
[dir="rtl"] .row.urgent { box-shadow: inset -3px 0 0 var(--warn); }
.row .grow { flex: 1 1 220px; min-width: 0; }
.row time { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.row.log { font-size: .88rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.dot.warn { background: var(--warn); }
.dot.danger { background: var(--danger); }
.chip { display: inline-block; font-size: .78rem; padding: 1px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.note { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.danger { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.state { padding: 28px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.state.error { color: var(--danger); }
.spin { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
.more { display: block; margin: 12px auto; }
dl.kv { display: grid; grid-template-columns: minmax(110px, max-content) 1fr; gap: 6px 14px; margin: 0 0 12px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { padding-inline-start: 18px; margin: 0; font-size: .9rem; }
.timeline time { color: var(--muted); }
.gallery { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { max-width: 220px; max-height: 220px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); }
pre.evidence { white-space: pre-wrap; background: var(--surface-2); padding: 8px; border-radius: 8px; font-size: .82rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* نوافذ */
.backdrop { position: fixed; inset: 0; background: rgba(14, 8, 33, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
.modal.wide { width: min(980px, 100%); }
.modal header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal footer { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); }
.act-target { font-weight: 600; }
.act-effect { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }
.act-effect.danger { background: var(--danger-bg); color: var(--danger); }
.toasts { position: fixed; bottom: 80px; inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60; pointer-events: none; }
.toast { background: var(--brand); color: var(--cream); padding: 10px 16px; border-radius: 10px; max-width: min(520px, 92vw); box-shadow: var(--shadow); }
.toast.err { background: var(--danger); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }

/* محرر المقال والكتاب والحملة */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 2fr auto; gap: 8px; margin-bottom: 8px; }
.article-preview { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.article-preview img { width: 100%; max-height: 220px; object-fit: cover; border-radius: 10px; margin-bottom: 8px; }
.article-preview h2 { margin: 6px 0; }
.cover-box img { max-height: 120px; }
.article-preview img.thumb { max-width: 100%; width: 100%; max-height: 220px; object-fit: cover; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card.book, .card.campaign { cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.card.book img, .card.campaign img { width: 100%; max-height: 260px; object-fit: cover; }
.cover-ph { display: grid; place-items: center; height: 160px; background: var(--surface-2); border-radius: 8px; font-size: 2rem; }
.book-preview img { max-width: 180px; }
.popup-preview { display: grid; place-items: center; }
.popup { width: 260px; background: var(--surface); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); text-align: center; padding-bottom: 12px; }
.popup img { width: 100%; display: block; }
.popup p { padding: 8px 12px 0; margin: 0; }
.btn-like { display: inline-block; margin-top: 10px; background: var(--accent); color: #fff; padding: 6px 16px; border-radius: 999px; }
.card.post.gone { opacity: .6; }
.post-head, .post-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.post-body { white-space: pre-wrap; margin: 8px 0; }
.handle-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.big { font-size: 1.4rem; }
.thread { display: flex; flex-direction: column; gap: 8px; }
.msg { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.msg.admin { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.msg.internal { border: 1px dashed var(--warn); }
.msg p { margin: 4px 0 0; white-space: pre-wrap; }
.perm-matrix { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.perm-matrix fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; }
.perm-matrix legend { font-weight: 600; padding: 0 4px; }
.perm-matrix fieldset.locked { background: var(--surface-2); }
.summary { padding-inline-start: 18px; margin: 0; }
.summary li { margin-bottom: 4px; }

/* الموبايل */
@media (max-width: 900px) {
  .menu-btn { display: inline-block; }
  .top .who { display: none; }
  nav.side { position: fixed; top: 54px; bottom: 0; inset-inline-start: 0; z-index: 30; transform: translateX(-105%); transition: transform .2s; height: auto; }
  [dir="rtl"] nav.side { transform: translateX(105%); }
  body.nav-open nav.side { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 54px 0 0; background: rgba(14,8,33,.4); z-index: 25; }
  main { padding: 16px 16px 96px; }
  nav.bottom { display: flex; position: fixed; bottom: 0; inset-inline: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  nav.bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-size: .74rem; color: var(--muted); text-decoration: none; position: relative; text-align: center; }
  nav.bottom a.on { color: var(--accent); font-weight: 600; }
  nav.bottom .badge { position: absolute; top: 2px; inset-inline-end: 18%; }
  .split, .grid2, .grid3 { grid-template-columns: 1fr; }
  .modal.wide { width: 100%; }
  .backdrop { padding: 0; place-items: end stretch; }
  .modal { max-height: 92vh; border-radius: 16px 16px 0 0; width: 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .top .env { display: none; }
  .top .brand span:last-child { display: none; }
}
