:root {
  --bg: #0f1115; --panel: #171a21; --panel-2: #1f232c; --line: #2a2f3a;
  --text: #e8eaf0; --muted: #9aa3b2; --accent: #7c5cff; --accent-2: #6847f5;
  --good: #34c38f; --bad: #f46a6a; --warn: #f1b44c; --radius: 10px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb; --panel: #ffffff; --panel-2: #f0f2f7; --line: #e2e5ee;
    --text: #151821; --muted: #5d6577; --accent: #6544f0; --accent-2: #5333e0;
    --good: #148a5c; --bad: #d23c3c; --warn: #a86a00; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 "IBM Plex Sans Arabic", -apple-system, "Segoe UI", sans-serif; }
[hidden] { display: none !important; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { margin: 0; }

/* shell */
.shell { display: flex; min-height: 100vh; }
.nav { width: 220px; flex: none; padding: 20px 14px; background: var(--panel); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.logo { font-weight: 700; font-size: 18px; margin: 4px 8px 14px; color: var(--accent); }
.nav [data-view] { text-align: start; background: none; color: var(--muted); border: 0; padding: 9px 12px; border-radius: 8px; font-weight: 500; }
.nav [data-view]:hover { background: var(--panel-2); color: var(--text); }
.nav [data-view].active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.ws { margin: 0 4px 12px; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 8px; }
main { flex: 1; min-width: 0; padding: 28px 32px 60px; }
.view { display: none; max-width: 1180px; }
.view.active { display: block; }
.view-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0 0 2px; }
h2 { font-size: 16px; margin: 0 0 12px; display: flex; align-items: center; }
h3 { font-size: 15px; margin: 0 0 6px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.top-gap { margin-top: 12px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 16px 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.chart-box { position: relative; height: 320px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.media-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.seg { display: flex; gap: 18px; flex-wrap: wrap; }

.pill { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: var(--panel-2); white-space: nowrap; }
.pill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.pill.good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: end; white-space: nowrap; }
th:first-child, td:first-child { text-align: start; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
table.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.kpi td { font-variant-numeric: tabular-nums; }
table.plain td, table.plain th { text-align: start; white-space: normal; }
.delta { font-size: 11px; margin-inline-start: 4px; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.na { color: var(--muted); opacity: .7; font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 8px; }

button, .button {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:hover, .button:hover { background: var(--accent-2); }
button:disabled { opacity: .55; cursor: progress; }
button.secondary, .button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
button.secondary:hover, .button.secondary:hover { background: var(--line); }
button.small, .button.small { padding: 5px 10px; font-size: 13px; }
button.link { background: none; color: var(--muted); padding: 0; font-weight: 500; }
button.link:hover { color: var(--text); background: none; }
a { color: var(--accent); }

input, select, textarea { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; width: 100%; min-width: 0; }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
label.check input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 16px; margin-bottom: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.row select, .row input:not([type=checkbox]):not([type=radio]), .card-head select { width: auto; min-width: 180px; flex: 1; }

.step .num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; margin-inline-end: 8px; }
audio, video { width: 100%; margin-top: 12px; border-radius: 8px; }
video { max-height: 560px; background: #000; }

.post { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.post .meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.post .stats { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.post .stats b { color: var(--text); }

.result { background: var(--panel-2); border-radius: 8px; padding: 14px; margin-top: 14px; white-space: pre-wrap; }
.result h3 { margin-top: 10px; }
.result code { word-break: break-all; font-size: 13px; }
ul.tight { margin: 4px 0 8px; padding-inline-start: 18px; }
.variation { border-inline-start: 3px solid var(--accent); padding: 6px 10px; margin: 8px 0; background: var(--panel-2); border-radius: 6px; display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }

.broll-row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.broll-row img, .broll-row .thumb-empty { width: 54px; height: 72px; object-fit: cover; border-radius: 6px; background: var(--panel-2); }
.broll-row label { width: 80px; }
.media { background: var(--panel-2); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.media img, .media .thumb-empty { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 6px; background: var(--line); display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.tabs { margin-bottom: 12px; }
.qitem { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast { position: fixed; bottom: 24px; inset-inline-end: 24px; max-width: min(420px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line); border-inline-start: 4px solid var(--accent); padding: 12px 16px; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.25); z-index: 10; }
#toast.error { border-inline-start-color: var(--bad); }

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .nav { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .nav .logo { width: 100%; margin-bottom: 4px; }
  .ws { width: 100%; }
  .nav-foot { margin: 0; flex-direction: row; width: 100%; }
  main { padding: 18px 16px 48px; }
}
