:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e1db;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e4effc;
  --bar: #2a78d6;
  --bar-dim: #b7d3f6;
  --good: #0ca30c; --good-ink: #006300; --good-soft: #e3f4e3;
  --warn: #fab219; --warn-ink: #8a5a00; --warn-soft: #fdf1d6;
  --bad: #d03b3b; --bad-ink: #a92b2b; --bad-soft: #fbe5e5;
  --wa: #128c4a;
  --heat-0: #f0efec; --heat-1: #cde2fb; --heat-2: #86b6ef; --heat-3: #3987e5; --heat-4: #1c5cab;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.03);
  --radius: 10px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #1b2c42;
    --bar: #3987e5; --bar-dim: #184f95;
    --good-ink: #5fd35f; --good-soft: #17301a; --warn-ink: #fab219; --warn-soft: #362a0e; --bad-ink: #f08a8a; --bad-soft: #3a1c1c;
    --heat-0: #232321; --heat-1: #184f95; --heat-2: #256abf; --heat-3: #3987e5; --heat-4: #86b6ef;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #1b2c42;
  --bar: #3987e5; --bar-dim: #184f95;
  --good-ink: #5fd35f; --good-soft: #17301a; --warn-ink: #fab219; --warn-soft: #362a0e; --bad-ink: #f08a8a; --bad-soft: #3a1c1c;
  --heat-0: #232321; --heat-1: #184f95; --heat-2: #256abf; --heat-3: #3987e5; --heat-4: #86b6ef;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 620; }
h3 { font-size: 13px; font-weight: 620; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 24px; height: 56px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; color: var(--text); }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav a { padding: 7px 12px; border-radius: 7px; color: var(--text-2); font-weight: 520; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.topbar-right { display: flex; gap: 8px; align-items: center; }

main { max-width: 1280px; margin: 0 auto; padding: 22px 20px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 13px; border-radius: 8px; font: 520 13.5px var(--font); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad-ink); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon { width: 16px; height: 16px; flex: none; }
input, select, textarea { font: 14px var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; outline: none; max-width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { width: 100%; min-height: 90px; resize: vertical; line-height: 1.5; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 560; margin-bottom: 5px; font-size: 13px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 11px; font: 520 13px var(--font); color: var(--text-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- layout ---------- */
.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-12 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.mt { margin-top: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.card-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-2); }
@media (max-width: 1080px) { .g-kpi { grid-template-columns: repeat(3, minmax(0,1fr)); } .g-21, .g-12, .g-3 { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .g-kpi { grid-template-columns: repeat(2, minmax(0,1fr)); } .g-2 { grid-template-columns: 1fr; } main { padding: 16px 16px 50px; } .topbar-inner { padding: 0 16px; gap: 12px; } .brand span { display: none; } }

/* ---------- KPI ---------- */
.kpi .label { font-size: 12.5px; color: var(--text-2); font-weight: 540; }
.kpi .value { font-size: 28px; font-weight: 680; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 15px; font-weight: 560; color: var(--text-2); }
.kpi .delta { font-size: 12.5px; margin-top: 2px; color: var(--text-3); }
.delta.up { color: var(--good-ink); } .delta.down { color: var(--bad-ink); }

/* ---------- insight list ---------- */
.insights { display: grid; gap: 10px; }
.insight { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 12px; border-radius: 9px; background: var(--surface-2); }
.insight .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-ink); }
.insight .ic.bad { background: var(--bad-soft); color: var(--bad-ink); }
.insight .ic.warn { background: var(--warn-soft); color: var(--warn-ink); }
.insight b { font-weight: 620; }
.insight p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }

/* ---------- bar charts ---------- */
.hbars { display: grid; gap: 9px; }
.hbar { display: grid; grid-template-columns: 150px 1fr 52px; gap: 10px; align-items: center; position: relative; }
.hbar .lbl { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .track { height: 12px; background: var(--surface-2); border-radius: 4px; position: relative; }
.hbar .fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar.weak .fill { background: var(--bad); }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; }
.hbar .tag { font-size: 11px; font-weight: 600; color: var(--bad-ink); margin-left: 6px; }
@media (max-width: 520px) { .hbar { grid-template-columns: 110px 1fr 44px; } }

.vbars { display: flex; gap: 14px; align-items: flex-end; height: 150px; padding: 0 4px; border-bottom: 1px solid var(--border); }
.vbar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; cursor: default; }
.vbar .col { width: min(56px, 70%); background: var(--bar); border-radius: 4px 4px 0 0; min-height: 2px; }
.vbar .v { font-size: 13px; font-weight: 620; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.vlabels { display: flex; gap: 14px; padding: 6px 4px 0; }
.vlabels div { flex: 1; text-align: center; font-size: 12px; color: var(--text-2); }
.vlabels small { display: block; color: var(--text-3); }

.tip { position: fixed; z-index: 100; pointer-events: none; background: var(--text); color: var(--surface); padding: 7px 10px; border-radius: 7px;
  font-size: 12.5px; line-height: 1.45; box-shadow: 0 4px 14px rgba(0,0,0,.18); max-width: 260px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 580; font-size: 12px; color: var(--text-2); 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.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--surface-2); }
td.r, th.r { text-align: right; }
.summary-cell { max-width: 420px; color: var(--text-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* heat cells */
.heat { display: inline-block; min-width: 34px; padding: 3px 6px; border-radius: 5px; text-align: center; font-variant-numeric: tabular-nums; font-size: 12.5px; font-weight: 600; }
.h0 { background: var(--heat-0); color: var(--text-3); } .h1 { background: var(--heat-1); color: #0d366b; } .h2 { background: var(--heat-2); color: #0d366b; }
.h3 { background: var(--heat-3); color: #fff; } .h4 { background: var(--heat-4); color: #fff; }
:root[data-theme="dark"] .h1, :root[data-theme="dark"] .h2 { color: #fff; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .h1, :root:where(:not([data-theme="light"])) .h2 { color: #fff; } :root:where(:not([data-theme="light"])) .h4 { color: #0d366b; } }
:root[data-theme="dark"] .h4 { color: #0d366b; }
.activity { display: grid; gap: 4px; }
.activity-row { display: grid; grid-template-columns: 150px repeat(14, minmax(14px, 1fr)); gap: 3px; align-items: center; }
.activity-row .cell { height: 22px; border-radius: 4px; display: grid; place-items: center; font-size: 11px; font-weight: 600; }
.activity-row .name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 580; white-space: nowrap; background: var(--surface-2); color: var(--text-2); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-good { background: var(--good-soft); color: var(--good-ink); }
.b-warn { background: var(--warn-soft); color: var(--warn-ink); }
.b-bad { background: var(--bad-soft); color: var(--bad-ink); }
.b-info { background: var(--accent-soft); color: var(--accent-ink); }
.b-wa { background: #e2f4ea; color: var(--wa); }
:root[data-theme="dark"] .b-wa { background: #13301f; color: #5fd38f; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .b-wa { background: #13301f; color: #5fd38f; } }
.score { display: inline-grid; place-items: center; min-width: 38px; height: 26px; padding: 0 7px; border-radius: 7px; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 13px; }
.score.big { min-width: 64px; height: 50px; font-size: 24px; border-radius: 11px; }

/* ---------- banners ---------- */
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 13px 15px; border-radius: 10px; background: var(--accent-soft); color: var(--text); margin-bottom: 16px; border: 1px solid var(--border); }
.banner.warn { background: var(--warn-soft); }
.banner p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
.banner .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- call detail ---------- */
.call-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.meta-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
audio { width: 100%; margin-top: 14px; height: 40px; }
.list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.list li { padding-left: 18px; position: relative; }
.list li::before { content: ""; position: absolute; left: 3px; top: 9px; width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
.obj { border: 1px solid var(--border); border-radius: 9px; padding: 12px; }
.obj + .obj { margin-top: 10px; }
.obj .better { margin-top: 8px; padding: 9px 11px; background: var(--good-soft); border-radius: 7px; font-size: 13px; }
.obj .better b { color: var(--good-ink); }
.ts { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--accent-ink); cursor: pointer; font-weight: 600; background: none; border: 0; padding: 0; }
.transcript { display: grid; gap: 2px; max-height: 620px; overflow-y: auto; }
.seg-line { display: grid; grid-template-columns: 48px 1fr; gap: 10px; padding: 7px 8px; border-radius: 7px; }
.seg-line:hover { background: var(--surface-2); }
.seg-line.playing { background: var(--accent-soft); }
.seg-line .who { font-weight: 640; font-size: 12.5px; }
.seg-line .who.rep { color: var(--accent-ink); }
.seg-line .who.cust { color: var(--text-2); }
.seg-line .txt { unicode-bidi: plaintext; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.metric .k { font-size: 12px; color: var(--text-2); } .metric .v { font-size: 18px; font-weight: 660; font-variant-numeric: tabular-nums; }
.ratio { height: 10px; border-radius: 4px; overflow: hidden; display: flex; gap: 2px; background: var(--surface); margin-top: 6px; }
.ratio .a { background: var(--bar); } .ratio .b { background: var(--bar-dim); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { background: none; border: 0; padding: 8px 12px; font: 560 13.5px var(--font); color: var(--text-2); border-bottom: 2px solid transparent; cursor: pointer; margin-bottom: -1px; }
.tabs button.on { color: var(--accent-ink); border-color: var(--accent); }

/* ---------- misc ---------- */
.empty { padding: 40px 20px; text-align: center; color: var(--text-2); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.copy { display: flex; gap: 6px; align-items: center; }
.copy input { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; background: var(--surface-2); min-width: 0; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; font-size: 13.5px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; }
.modal-back { position: fixed; inset: 0; background: rgba(10,10,10,.42); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; padding: 22px; width: min(540px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 18px 50px rgba(0,0,0,.25); }
.modal h2 { font-size: 17px; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 9px; z-index: 200; font-weight: 540; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.report h2 { margin: 0 0 10px; }
.prio { display: grid; grid-template-columns: 32px 1fr; gap: 12px; padding: 14px 0; border-top: 1px solid var(--border); }
.prio:first-of-type { border-top: 0; padding-top: 0; }
.prio .n { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.prio p { margin: 4px 0 0; }
.drop { border: 2px dashed var(--border); border-radius: 12px; padding: 26px; text-align: center; color: var(--text-2); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
svg text { font-family: var(--font); }
