:root, :root[data-theme="dark"] {
  --bg: #0b0f14; --surface: #11161d; --surface2: #1a212b; --line: #243040; --text: #e6edf3; --dim: #9aa7b4;
  --primary: #14b8a6; --primary-ink: #00201c; --ok: #22c55e; --warn: #f59e0b; --err: #f87171; --info: #60a5fa; --sim: #c084fc;
  --shadow: 0 8px 30px #0008;
}
:root[data-theme="light"] {
  --bg: #f4f6f9; --surface: #fff; --surface2: #eef2f6; --line: #d9e0e8; --text: #0f172a; --dim: #5b6673; --primary: #0f766e; --primary-ink: #fff;
  --ok: #15803d; --warn: #b45309; --err: #dc2626; --info: #2563eb; --sim: #7e22ce; --shadow: 0 8px 30px #0f172a22;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) { --bg: #f4f6f9; --surface: #fff; --surface2: #eef2f6; --line: #d9e0e8; --text: #0f172a; --dim: #5b6673; --primary: #0f766e;
    --primary-ink: #fff; --ok: #15803d; --warn: #b45309; --err: #dc2626; --info: #2563eb; --sim: #7e22ce; --shadow: 0 8px 30px #0f172a22; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif; }
a { color: var(--primary); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 0 0 8px; color: var(--dim); font-weight: 600; }

.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-inline-end: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 8px 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 50%; border: 4px solid var(--primary); flex: none; }
.nav { flex: 1; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; color: var(--text); margin-bottom: 2px; }
.nav a:hover { background: var(--surface2); text-decoration: none; }
.nav a.active { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); font-weight: 600; }
.nav .sec { color: var(--dim); font-size: 12px; padding: 12px 12px 4px; text-transform: uppercase; letter-spacing: .04em; }
.side-foot { border-top: 1px solid var(--line); padding: 12px 8px 0; font-size: 13px; color: var(--dim); display: flex; flex-direction: column; gap: 8px; }
.side-foot .row { display: flex; gap: 6px; flex-wrap: wrap; }
.main { padding: 22px 26px 60px; min-width: 0; }
.topline { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topline h1 { flex: 1; }
.crumb { color: var(--dim); font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.kpi .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--dim); font-size: 13px; }
.kpi.accent { border-color: color-mix(in srgb, var(--primary) 50%, var(--line)); }
.two { grid-template-columns: 1fr 1fr; } .three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1150px) { .two, .three { grid-template-columns: 1fr; } }
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } .side { position: static; height: auto; } .main { padding: 16px; } }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--dim); font-weight: 600; white-space: nowrap; background: var(--surface); }
th.sortable { cursor: pointer; user-select: none; } th.sortable:hover { color: var(--text); }
th .arrow { margin-inline-start: 4px; color: var(--primary); }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface2); }
.scroll { overflow-x: auto; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--dim); } .small { font-size: 12.5px; } .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.empty { color: var(--dim); padding: 18px; text-align: center; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, currentColor 13%, transparent); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.t-ok { color: var(--ok); } .t-warn { color: var(--warn); } .t-err { color: var(--err); } .t-info { color: var(--info); } .t-sim { color: var(--sim); } .t-dim { color: var(--dim); }

button { font: inherit; border: 1px solid var(--line); background: var(--surface2); color: var(--text); padding: 7px 14px; border-radius: 10px; cursor: pointer; }
button:hover:not(:disabled) { filter: brightness(1.12); }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
button.ghost { background: transparent; } button.sm { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .45; cursor: not-allowed; }
input, select, textarea { font: inherit; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; min-width: 0; }
textarea { width: 100%; min-height: 80px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
label { display: block; font-size: 12.5px; color: var(--dim); margin-bottom: 4px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 10px; }
.form-row > div { display: flex; flex-direction: column; }
.form-row input[type=number] { width: 110px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 13px; }
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { border: none; background: transparent; padding: 9px 12px; border-radius: 10px 10px 0 0; color: var(--dim); }
.tab.on { color: var(--primary); box-shadow: inset 0 -2px 0 var(--primary); font-weight: 600; }
.kv { display: grid; grid-template-columns: minmax(130px, 200px) 1fr; gap: 6px 14px; }
.kv .k { color: var(--dim); }
details.box { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; }
details.box summary { cursor: pointer; font-weight: 600; }
.timeline { border-inline-start: 2px solid var(--line); padding-inline-start: 14px; }
.timeline .ev { position: relative; padding-bottom: 12px; }
.timeline .ev::before { content: ""; position: absolute; inset-inline-start: -21px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }

.chart { width: 100%; height: 230px; display: block; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--dim); font-size: 10px; }
.chart .s0 { fill: var(--primary); } .chart .s1 { fill: var(--info); } .chart .s2 { fill: var(--warn); } .chart .s3 { fill: var(--sim); } .chart .s4 { fill: var(--ok); } .chart .s5 { fill: var(--err); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--dim); margin-top: 6px; flex-wrap: wrap; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; }
.sw.s0 { background: var(--primary); } .sw.s1 { background: var(--info); } .sw.s2 { background: var(--warn); } .sw.s3 { background: var(--sim); } .sw.s4 { background: var(--ok); } .sw.s5 { background: var(--err); }

.login { max-width: 380px; margin: 12vh auto; padding: 0 16px; }
.login .card { padding: 26px; }
.login input { width: 100%; margin-bottom: 12px; }
.login button { width: 100%; }
.error { color: var(--err); font-size: 13.5px; min-height: 20px; }
#toasts { position: fixed; bottom: 18px; inset-inline-start: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; max-width: 380px; box-shadow: var(--shadow); }
.toast.err { border-color: var(--err); }
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 20px; max-width: 460px; width: 92vw; box-shadow: var(--shadow); }
dialog::backdrop { background: #0009; }
dialog .actions { justify-content: flex-end; margin-top: 16px; }
.code-box { font: 700 28px ui-monospace, Consolas, monospace; letter-spacing: .2em; text-align: center; padding: 14px; border: 1px dashed var(--primary); border-radius: 12px; margin: 10px 0; direction: ltr; }
.live { font-size: 12.5px; }
.perm-grid { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.pager { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.bar { height: 8px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.bar .w0 { width: 0 } .bar .w10 { width: 10% } .bar .w20 { width: 20% } .bar .w30 { width: 30% } .bar .w40 { width: 40% } .bar .w50 { width: 50% }
.bar .w60 { width: 60% } .bar .w70 { width: 70% } .bar .w80 { width: 80% } .bar .w90 { width: 90% } .bar .w100 { width: 100% }
.grow { flex: 1; min-width: 220px; }
.form-row > .chips { flex-direction: row; align-self: flex-end; margin-bottom: 4px; }
