:root {
  --bg: #0b0d10;
  --surface: #111418;
  --surface-2: #171b21;
  --surface-3: #1e232b;
  --border: #242a33;
  --border-strong: #323a46;
  --text: #e8edf3;
  --muted: #8d97a6;
  --faint: #5d6776;
  --accent: #2dd4bf;
  --accent-ink: #04211d;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --blue: #7ea2ff;
  --blue-soft: rgba(126, 162, 255, 0.13);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.13);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.13);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.13);
  --wa: #25d366;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: 'IBM Plex Sans Arabic', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sidebar: 240px;
  color-scheme: dark;
}
:root[data-theme='light'] {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f3f5f8;
  --surface-3: #e9edf2;
  --border: #e2e7ee;
  --border-strong: #cfd6df;
  --text: #0f1720;
  --muted: #5b6676;
  --faint: #8a94a3;
  --accent: #0d9488;
  --accent-ink: #ffffff;
  --accent-soft: rgba(13, 148, 136, 0.1);
  --blue: #3b63d9;
  --blue-soft: rgba(59, 99, 217, 0.1);
  --green: #059669;
  --green-soft: rgba(5, 150, 105, 0.1);
  --amber: #b45309;
  --amber-soft: rgba(180, 83, 9, 0.1);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.08);
  --shadow: 0 10px 30px rgba(15, 23, 32, 0.1);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
html[lang='en'] body { --font: 'Inter', 'IBM Plex Sans Arabic', system-ui, sans-serif; font-family: var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
::selection { background: var(--accent-soft); }

.boot { display: grid; place-items: center; height: 100vh; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: #0f1a1a; display: grid; place-items: center; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }
.nav-label { font-size: 11px; color: var(--faint); padding: 14px 10px 4px; text-transform: uppercase; letter-spacing: 0.06em; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); display: grid; gap: 8px; }
.credit-pill { display: flex; justify-content: space-between; align-items: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 12.5px; }
.credit-pill b { color: var(--accent); }
.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar .grow { flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: 24px 28px 64px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 4px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 14px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.grow { flex: 1; }
.ltr { direction: ltr; unicode-bidi: plaintext; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card.pad-0 { padding: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head p { color: var(--muted); font-size: 12.5px; }
.stat { display: grid; gap: 6px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--faint); font-size: 12px; }
.clickable { cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.clickable:hover { border-color: var(--border-strong); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; text-decoration: none !important;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); background: var(--red-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 30px; }
.btn.call { background: var(--green); border-color: var(--green); color: #032014; }
.btn.hang { background: var(--red); border-color: var(--red); color: #fff; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 12.5px; font-weight: 550; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--faint); }
.input, .select, .textarea {
  width: 100%; min-height: 38px; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  font: inherit; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea, .input { unicode-bidi: plaintext; }
.textarea { resize: vertical; min-height: 110px; line-height: 1.6; }
.textarea.code { font-family: var(--mono); font-size: 12.5px; direction: ltr; text-align: left; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[dir='ltr'] { text-align: left; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px; background-size: 5px 5px; background-repeat: no-repeat; padding-inline-end: 30px; }
[dir='rtl'] .select { background-position: 16px 16px, 11px 16px; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 99px; transition: 0.15s; }
.switch span::after { content: ''; position: absolute; top: 2px; inset-inline-start: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: 0.15s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { background: var(--accent-ink); inset-inline-start: 18px; }
.range { width: 100%; accent-color: var(--accent); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; color: var(--muted); font: inherit; font-weight: 550; padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button { background: none; border: 0; font: inherit; font-weight: 550; color: var(--muted); padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: start; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 12px; color: var(--muted); font-weight: 550; background: var(--surface-2); }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 550; background: var(--surface-3); color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.wa { background: rgba(37, 211, 102, 0.13); color: var(--wa); }
.badge svg { width: 13px; height: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.dot.live { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- empty & misc ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); display: grid; gap: 10px; justify-items: center; }
.empty svg { width: 36px; height: 36px; color: var(--faint); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.codeblock { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; overflow-x: auto; direction: ltr; text-align: left; white-space: pre; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.codeblock .copy { position: absolute; top: 6px; right: 6px; }
.callout { border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; display: grid; gap: 6px; }
.callout.info { border-color: color-mix(in srgb, var(--blue) 35%, transparent); background: var(--blue-soft); }
.callout.warn { border-color: color-mix(in srgb, var(--amber) 35%, transparent); background: var(--amber-soft); }
.callout ol, .callout ul { margin: 4px 0 0; padding-inline-start: 20px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.avatar { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; font-weight: 700; }
.avatar svg { width: 19px; height: 19px; }
.avatar.wa { background: rgba(37, 211, 102, 0.13); color: var(--wa); }
.avatar.blue { background: var(--blue-soft); color: var(--blue); }

/* ---------- transcript ---------- */
.transcript { display: grid; gap: 10px; }
.bubble { max-width: 82%; padding: 10px 13px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { justify-self: end; background: var(--blue-soft); border-color: transparent; }
.bubble.assistant { justify-self: start; }
.bubble .meta { font-size: 11px; color: var(--faint); margin-bottom: 3px; }
.tool-row { justify-self: center; font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 99px; padding: 3px 12px; font-family: var(--mono); direction: ltr; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 100; display: grid; place-items: center; padding: 16px; animation: fade 0.12s; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px; box-shadow: var(--shadow); }
.modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 18px; inset-inline-end: 18px; display: grid; gap: 8px; z-index: 200; }
.toast { background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); max-width: 360px; animation: fade 0.15s; }
.toast.error { border-color: color-mix(in srgb, var(--red) 50%, transparent); }
.toast.ok { border-color: color-mix(in srgb, var(--green) 50%, transparent); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-side { background: radial-gradient(1200px 500px at 20% 10%, rgba(45, 212, 191, 0.18), transparent 60%), radial-gradient(900px 500px at 90% 90%, rgba(126, 162, 255, 0.14), transparent 60%), var(--surface); border-inline-end: 1px solid var(--border); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h1 { font-size: 34px; line-height: 1.25; max-width: 520px; }
.auth-side .features { display: grid; gap: 14px; margin-top: 28px; max-width: 460px; }
.auth-side .feature { display: flex; gap: 12px; align-items: flex-start; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: min(400px, 100%); display: grid; gap: 16px; }
.auth-card h2 { font-size: 22px; }

/* ---------- web call widget ---------- */
.callbox { display: grid; gap: 14px; justify-items: center; text-align: center; padding: 10px 0; }
.orb { width: 120px; height: 120px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--accent) 70%, white), var(--accent) 45%, #0b5d55); box-shadow: 0 0 0 0 var(--accent-soft); transition: transform 0.08s linear, box-shadow 0.08s linear; }
.orb.idle { filter: grayscale(0.7) brightness(0.7); }
.call-live-transcript { width: 100%; max-height: 280px; overflow-y: auto; text-align: start; }

/* ---------- chart ---------- */
.chart { width: 100%; height: 200px; }
.chart .bar { fill: var(--accent); opacity: 0.85; }
.chart .bar:hover { opacity: 1; }
.chart .axis { fill: var(--faint); font-size: 10px; font-family: var(--font); }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 3 4; }
.hbar { display: grid; gap: 8px; }
.hbar .item { display: grid; gap: 4px; }
.hbar .track { height: 7px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--accent); border-radius: 99px; }

.template-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; background: var(--surface-2); display: grid; gap: 6px; text-align: start; font: inherit; color: inherit; }
.template-card:hover, .template-card.active { border-color: var(--accent); }
.template-card .t { font-weight: 600; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: 270px; z-index: 50; transform: translateX(-105%); transition: transform 0.2s; }
  [dir='rtl'] .sidebar { transform: translateX(105%); }
  .shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .shell.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 18px 16px 64px; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .bubble { max-width: 92%; }
  .hide-sm { display: none !important; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 20px; }
  .page-head .btn { flex: 1; }
}
@media (max-width: 860px) { [data-resp='stack'] { grid-template-columns: 1fr !important; } }
