:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #98a0b1;
  --brand: #8b72e8;
  --brand-ink: #ffffff;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --err: #ff5d5d;
  --info: #5aa9ff;
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f8;
    --panel: #ffffff;
    --panel-2: #f0f2f6;
    --line: #dde1ea;
    --text: #1b1f29;
    --muted: #5d6578;
    --brand-ink: #ffffff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--info); }
.noscript { padding: 24px; text-align: center; }
.hidden { display: none !important; }
.ltr { direction: ltr; unicode-bidi: plaintext; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

/* ── controls ── */
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 700; }
.btn.danger { border-color: var(--err); color: var(--err); }
.btn.small { padding: 4px 10px; font-size: 13px; }
input[type=text], input[type=password], input[type=search], input[type=email], textarea, select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 13px; }

/* ── login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .sub { margin: 0 0 18px; color: var(--muted); }
.login-card .btn.primary { width: 100%; margin-top: 18px; padding: 11px; }
.error { background: color-mix(in srgb, var(--err) 14%, transparent); border: 1px solid var(--err); color: var(--err); border-radius: 10px; padding: 9px 12px; margin-top: 14px; }
.note { background: color-mix(in srgb, var(--info) 12%, transparent); border: 1px solid var(--info); border-radius: 10px; padding: 9px 12px; margin-top: 14px; }

/* ── shell ── */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-inline-end: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.side .brand { font-weight: 800; font-size: 18px; padding: 4px 10px 12px; }
.side .brand span { color: var(--brand); }
.tab { text-align: start; background: none; border: 0; border-radius: 10px; padding: 9px 12px; cursor: pointer; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--brand); }
[dir=rtl] .tab.active { box-shadow: inset -3px 0 0 var(--brand); }
.side .who { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 10px 0; font-size: 13px; }
.side .who b { display: block; overflow: hidden; text-overflow: ellipsis; }
.main { padding: 20px; min-width: 0; }
.main h2 { margin: 0 0 14px; font-size: 20px; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.bar .grow { flex: 1 1 200px; min-width: 120px; }
.bar select { width: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.bad b { color: var(--err); }
.stat.good b { color: var(--ok); }

.badge { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 12px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); }
.badge.debug { color: var(--muted); }
.badge.info { color: var(--info); border-color: color-mix(in srgb, var(--info) 50%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.badge.error { color: var(--err); border-color: color-mix(in srgb, var(--err) 50%, transparent); }
.badge.count { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 700; }
.chip { cursor: pointer; user-select: none; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ── lists / tables ── */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--panel-2); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.scroll { overflow-x: auto; }

/* ── support chat ── */
.chat { display: grid; grid-template-columns: 320px 1fr; gap: 12px; height: calc(100vh - 110px); min-height: 420px; }
.convs, .thread { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.convs .list { overflow-y: auto; flex: 1; }
.conv { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover, .conv.active { background: var(--panel-2); }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .last { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .head { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.thread .msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; background: var(--panel-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.staff { align-self: flex-start; background: color-mix(in srgb, var(--brand) 22%, var(--panel-2)); }
.msg.customer { align-self: flex-end; }
.msg.system { align-self: center; color: var(--muted); font-size: 13px; background: none; border: 1px dashed var(--line); }
.msg small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.thread form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.thread form textarea { min-height: 44px; height: 44px; }

/* ── reports ── */
.report .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.quote { border-inline-start: 3px solid var(--warn); padding: 6px 10px; background: var(--panel-2); border-radius: 6px; margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── logs ── */
.logs { display: grid; grid-template-columns: 250px 1fr; gap: 12px; }
.cats { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; align-self: start; position: sticky; top: 12px; }
.cats .tab { padding: 7px 10px; }
.cats .sep { margin: 8px 6px 4px; color: var(--muted); font-size: 12px; }
.cats .tab.console { background: color-mix(in srgb, var(--brand) 12%, transparent); }
.cats .src { padding-inline-start: 22px; font-size: 13px; }
.logrow { border-bottom: 1px solid var(--line); padding: 7px 4px; cursor: pointer; }
.logrow:hover { background: var(--panel-2); }
.logrow .line { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.logrow .time { color: var(--muted); font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.logrow .msgtext { overflow-wrap: anywhere; flex: 1 1 300px; }
.logrow.is-console .msgtext { font-family: var(--mono); font-size: 13px; }
.logrow.l-error { box-shadow: inset 3px 0 0 var(--err); }
.logrow.l-warn { box-shadow: inset 3px 0 0 var(--warn); }
[dir=rtl] .logrow.l-error { box-shadow: inset -3px 0 0 var(--err); }
[dir=rtl] .logrow.l-warn { box-shadow: inset -3px 0 0 var(--warn); }
pre.detail { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; font: 12px/1.5 var(--mono); max-height: 360px; margin: 8px 0 0; direction: ltr; text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── modal ── */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.modal h3 { margin: 0 0 8px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 18px; inset-inline-start: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; z-index: 30; }
.toast.err { border-color: var(--err); color: var(--err); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side .brand { width: 100%; padding-bottom: 4px; }
  .side .who { margin: 0; border: 0; padding: 0 8px; width: 100%; }
  .chat, .logs { grid-template-columns: 1fr; height: auto; }
  .convs .list { max-height: 260px; }
  .thread { min-height: 420px; }
  .cats { position: static; }
  .main { padding: 14px 16px; }
}

/* numbers */
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row-wrap { display: flex; gap: 6px; flex-wrap: wrap; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 190px; margin-top: 8px; direction: ltr; }
.cbar { flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column; align-items: stretch; justify-content: flex-end; text-align: center; }
.cbar .col { flex: 1 1 auto; display: flex; align-items: flex-end; }
.cbar .fill { width: 100%; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 0; }
.cbar .fill.stack { background: none; display: flex; flex-direction: column-reverse; overflow: hidden; }
.cbar .part { min-height: 2px; }
.cbar .part.ok { background: var(--ok); }
.cbar .part.bad { background: var(--err); }
.cbar .part.rest { background: var(--muted); }
.cbar .val { font-size: 11px; color: var(--muted); height: 16px; overflow: hidden; }
.cbar .lab { font-size: 10px; color: var(--muted); height: 14px; overflow: hidden; }
