:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --border: #e4e3de;
  --text: #16161a;
  --text-2: #55545c;
  --muted: #8a8990;
  --brand: #5b4bff;
  --brand-ink: #ffffff;
  --brand-soft: #eeecff;
  --series-1: #2a78d6;
  --good: #0f8a4f; --good-soft: #e3f5ea;
  --warn: #a86400; --warn-soft: #fdf1dc;
  --bad: #c62f2f; --bad-soft: #fde7e7;
  --info: #2a62c9; --info-soft: #e5eefc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 2px 10px rgba(20, 20, 30, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111114; --surface: #1a1a1e; --surface-2: #232328; --border: #2e2e35;
    --text: #f0eff3; --text-2: #c2c1c9; --muted: #8e8d96;
    --brand: #8b7dff; --brand-ink: #0d0b1f; --brand-soft: #262245;
    --series-1: #3987e5;
    --good: #4cc98a; --good-soft: #15291f; --warn: #f0b54a; --warn-soft: #2d2412;
    --bad: #f07272; --bad-soft: #301818; --info: #7aa7ff; --info-soft: #172236;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111114; --surface: #1a1a1e; --surface-2: #232328; --border: #2e2e35;
  --text: #f0eff3; --text-2: #c2c1c9; --muted: #8e8d96;
  --brand: #8b7dff; --brand-ink: #0d0b1f; --brand-soft: #262245;
  --series-1: #3987e5;
  --good: #4cc98a; --good-soft: #15291f; --warn: #f0b54a; --warn-soft: #2d2412;
  --bad: #f07272; --bad-soft: #301818; --info: #7aa7ff; --info-soft: #172236;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.7 "IBM Plex Sans Arabic", Tahoma, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.12rem; } h3 { font-size: 1rem; }
code, .ltr { direction: ltr; unicode-bidi: plaintext; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .85em; word-break: break-all; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-inline-start: 1px solid var(--border);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 10px 18px; color: var(--text); }
.brand .dot { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; color: var(--brand-ink); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: var(--text-2); font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--brand-soft); color: var(--brand); }
.nav .badge { margin-inline-start: auto; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: 18px; padding: 12px; border-top: 1px solid var(--border); font-size: .85rem; color: var(--muted); }
.main { padding: 24px 28px 60px; min-width: 0; }
.topbar { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; color: var(--muted); }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 0 0 auto; width: 260px; z-index: 50; transform: translateX(100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.nav-open .side { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .main { padding: 16px 16px 60px; }
}

/* ---------- cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
@media (max-width: 1100px) { .g-side { grid-template-columns: minmax(0, 1fr); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .g2, .g3 { grid-template-columns: minmax(0, 1fr); } }
.stack > * + * { margin-top: 16px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--text-2); font-size: .88rem; }
.kpi .value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; margin-top: 4px; }
.kpi .sub { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.kpi a { color: inherit; }

/* ---------- tables */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: start; font-weight: 600; color: var(--text-2); font-size: .82rem; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.who { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); flex: none; object-fit: cover; display: grid; place-items: center; font-weight: 700; color: var(--text-2); font-size: .85rem; }

/* ---------- badges, pills, tabs */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); background: var(--surface); font-size: .9rem; }
.tabs a.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.tabs a:hover { text-decoration: none; }
.tabs .count { opacity: .7; margin-inline-start: 4px; }

/* ---------- forms */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; color: var(--text-2); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: .95rem;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.field { margin-bottom: 14px; }
.field .hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > .field { flex: 1 1 160px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: .83rem; border-radius: 8px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.inline { display: inline; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ---------- alerts, empty */
.alert { padding: 11px 14px; border-radius: 12px; margin-bottom: 14px; font-weight: 500; border: 1px solid transparent; }
.alert.ok { background: var(--good-soft); color: var(--good); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.err { background: var(--bad-soft); color: var(--bad); }
.alert ul { margin: 4px 0 0; padding-inline-start: 18px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty .big { font-size: 1.8rem; display: block; margin-bottom: 4px; }

/* ---------- chart */
.chart { position: relative; overflow-x: auto; }
.chart svg { width: 100%; min-width: 560px; height: 220px; display: block; overflow: visible; }
.chart .bar { fill: var(--series-1); }
.chart .bar-hit { fill: transparent; cursor: pointer; }
.chart .bar-hit:hover + .bar, .chart .bar.hl { filter: brightness(1.15); }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.tooltip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); padding: 6px 10px; border-radius: 8px; font-size: .8rem; white-space: nowrap; transform: translate(50%, -110%); opacity: 0; transition: opacity .1s; }
.tooltip.on { opacity: 1; }

/* ---------- conversation */
.chat { background: var(--surface-2); border-radius: 12px; padding: 14px; height: 520px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 14px; overflow-wrap: anywhere; font-size: .93rem; }
.bubble .text { white-space: pre-wrap; }
.bubble.in { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-start-start-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-start-end-radius: 4px; }
.bubble.out.failed { background: var(--bad-soft); color: var(--bad); border: 1px solid var(--bad); }
.bubble .meta { font-size: .72rem; opacity: .7; margin-top: 3px; }
.bubble img { max-width: 220px; border-radius: 10px; display: block; margin-top: 4px; }
.bubble .btns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.bubble .btns span { border: 1px solid currentColor; border-radius: 8px; padding: 1px 8px; font-size: .78rem; opacity: .85; }
.window { font-size: .82rem; padding: 6px 10px; border-radius: 8px; margin-bottom: 10px; }
.window.open { background: var(--good-soft); color: var(--good); }
.window.agent { background: var(--warn-soft); color: var(--warn); }
.window.closed { background: var(--bad-soft); color: var(--bad); }

/* ---------- builder rows */
.rows .item { display: grid; grid-template-columns: 120px 1fr 1fr 36px; gap: 8px; margin-bottom: 8px; }
.rows .item.qr { grid-template-columns: 1fr 1fr 36px; }
@media (max-width: 700px) { .rows .item, .rows .item.qr { grid-template-columns: 1fr; } }
.preview { background: var(--surface-2); border-radius: 12px; padding: 14px; }
.preview .bubble { max-width: 100%; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); display: block; }
details.box { border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; }
details.box summary { cursor: pointer; font-weight: 600; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps > li { counter-increment: s; position: relative; padding-inline-start: 40px; margin-bottom: 18px; }
.steps > li::before { content: counter(s); position: absolute; inset-inline-start: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.copy { display: flex; gap: 6px; align-items: center; }
.copy code { flex: 1; padding: 7px 10px; }
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.btn.disabled { opacity: .5; pointer-events: none; }
