/* ==========================================================================
   IDA customer-service monitoring dashboard
   Same tokens as the chat (petrol + signal amber, IBM Plex Sans Arabic).
   Chart series: text = series-1 blue, voice = series-2 orange (validated
   categorical slots); single-series charts use petrol.
   ========================================================================== */
:root {
  --bg: #eef2f4; --surface: #ffffff; --surface-2: #f6f8f9;
  --ink: #0c2233; --ink-2: #44596a; --ink-3: #6f8291;
  --line: #d6dfe5; --line-2: #b9c7d0; --grid: #e4eaee;
  --petrol: #0b5b6e; --petrol-d: #084657; --petrol-soft: #e1edf0;
  --amber: #f2a900; --amber-soft: #fff4d6; --amber-ink: #6b4a00;
  --s1: #2a78d6; --s2: #eb6834;
  --good: #0ca30c; --good-ink: #006300; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b; --crit-ink: #b42318;
  --nav: #0c2233; --nav-ink: #c9d7df; --nav-active: #ffffff;
  --shadow: 0 1px 2px rgba(12,34,51,.05), 0 6px 20px -12px rgba(12,34,51,.2);
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a161d; --surface: #0f212b; --surface-2: #132a36;
    --ink: #e5eef2; --ink-2: #a9bcc7; --ink-3: #7f95a2;
    --line: #20394a; --line-2: #2d4c60; --grid: #1a3140;
    --petrol: #2f97ad; --petrol-d: #4fb0c4; --petrol-soft: #123543;
    --amber: #f2b31d; --amber-soft: #2e2510; --amber-ink: #f5cf72;
    --s1: #3987e5; --s2: #d95926; --good-ink: #0ca30c; --crit-ink: #f2827a;
    --nav: #071118; --nav-ink: #9fb3bf;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -14px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a161d; --surface: #0f212b; --surface-2: #132a36;
  --ink: #e5eef2; --ink-2: #a9bcc7; --ink-3: #7f95a2;
  --line: #20394a; --line-2: #2d4c60; --grid: #1a3140;
  --petrol: #2f97ad; --petrol-d: #4fb0c4; --petrol-soft: #123543;
  --amber: #f2b31d; --amber-soft: #2e2510; --amber-ink: #f5cf72;
  --s1: #3987e5; --s2: #d95926; --good-ink: #0ca30c; --crit-ink: #f2827a;
  --nav: #071118; --nav-ink: #9fb3bf;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 400 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; border-radius: 6px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--ink-2); }
.mark { width: 38px; height: 38px; stroke: none; }
.mark.lg { width: 56px; height: 56px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 14px;
       border-radius: 9px; border: 1px solid transparent; background: none; cursor: pointer; font-weight: 500;
       font-size: 14px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn.ghost { background: var(--surface); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--line-2); background: var(--surface-2); }
.btn.primary { background: var(--petrol); color: #fff; }
.btn.primary:hover { background: var(--petrol-d); }
.btn.icon { width: 38px; padding: 0; }
.btn.block { width: 100%; }
.btn.sm { height: 32px; font-size: 13px; padding: 0 10px; }

/* ---------- login ---------- */
.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 16px;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--bg); }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
              padding: 30px 28px; box-shadow: var(--shadow); text-align: center; border-top: 4px solid var(--amber); }
.login-card h1 { font-size: 21px; margin: 14px 0 2px; }
.login-card .muted { margin: 0 0 20px; font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 14px; text-align: start; }
.login-form label, .dlg label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.login-form input, .dlg select, .dlg textarea, .toolbar input[type=search] {
  border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 11px; background: var(--surface); color: var(--ink); font-size: 15px; width: 100%; }
.alert { background: color-mix(in srgb, var(--crit) 10%, transparent); color: var(--crit-ink); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.hint { font-size: 12.5px; color: var(--ink-3); margin: 16px 0 0; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100dvh; }
.nav { background: var(--nav); color: var(--nav-ink); display: flex; flex-direction: column; padding: 18px 14px;
       position: sticky; top: 0; height: 100dvh; }
.nav-brand { display: flex; gap: 10px; align-items: center; padding: 0 6px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.nav-brand strong { display: block; color: #fff; font-size: 15px; line-height: 1.35; }
.nav-brand span { font-size: 12px; }
.nav-list { display: flex; flex-direction: column; gap: 2px; margin-top: 14px; }
.nav-list a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--nav-ink);
              text-decoration: none; font-size: 14.5px; position: relative; }
.nav-list a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-list a.active { background: rgba(255,255,255,.1); color: var(--nav-active); font-weight: 600; }
.nav-list a.active::before { content: ""; position: absolute; inset-inline-start: -14px; top: 8px; bottom: 8px; width: 3px;
                             border-radius: 3px; background: var(--amber); }
.badge { margin-inline-start: auto; background: var(--amber); color: #1c1400; font-size: 12px; font-weight: 700;
         min-width: 22px; height: 20px; border-radius: 10px; display: grid; place-items: center; padding: 0 6px; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.live-box { display: flex; align-items: center; gap: 9px; padding: 10px; border-radius: 9px; background: rgba(255,255,255,.05);
            font-size: 13px; margin-bottom: 6px; }
.live-box b { color: #fff; font-variant-numeric: tabular-nums; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: #2fd07f; box-shadow: 0 0 0 0 rgba(47,208,127,.6);
         animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(47,208,127,0); } 100% { box-shadow: 0 0 0 0 rgba(47,208,127,0); } }
.nav-ext { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--nav-ink);
           text-decoration: none; font-size: 13.5px; background: none; border: 0; cursor: pointer; width: 100%; }
.nav-ext:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-foot form { margin: 0; }

.main { min-width: 0; padding: 0 clamp(16px, 2.4vw, 32px) 40px; }
.bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 18px 0 14px; position: sticky; top: 0; z-index: 10;
       background: var(--bg); border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.bar h1 { font-size: 21px; margin: 0; margin-inline-end: auto; letter-spacing: -.01em; }
.menu-btn { display: none; }
.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 6px; cursor: pointer; font-size: 13.5px; color: var(--ink-2); white-space: nowrap; }
.seg button:hover { background: var(--surface-2); color: var(--ink); }
.seg button[aria-checked="true"] { background: var(--ink); color: var(--bg); font-weight: 500; }
.seg b { font-weight: 600; font-variant-numeric: tabular-nums; opacity: .75; margin-inline-start: 3px; }
.updated { font-size: 12.5px; color: var(--ink-3); min-width: 120px; }
.export { position: relative; }
.menu { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line);
        border-radius: 10px; box-shadow: var(--shadow); padding: 5px; min-width: 210px; z-index: 20; }
.menu a { display: block; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.menu a:hover { background: var(--surface-2); }

.notice { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.notice span { flex: 1; min-width: 240px; }
.notice.warn { background: color-mix(in srgb, var(--crit) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--crit) 30%, transparent); }
.notice.demo { background: var(--amber-soft); color: var(--amber-ink); border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 2px; }
.kpi .k-label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.kpi .k-val { font-size: 28px; font-weight: 600; line-height: 1.25; letter-spacing: -.02em; }
.kpi .k-val small { font-size: 15px; font-weight: 500; color: var(--ink-2); margin-inline-start: 2px; }
.kpi .k-delta { font-size: 12.5px; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 0 5px; align-items: center; }
.kpi .k-delta span { white-space: nowrap; }
.k-delta .up-good, .k-delta .down-good { color: var(--good-ink); font-weight: 600; }
.k-delta .up-bad, .k-delta .down-bad { color: var(--crit-ink); font-weight: 600; }
.pos { color: var(--good-ink); font-weight: 600; } .neg { color: var(--crit-ink); font-weight: 600; }
.kpi.accent { border-top: 3px solid var(--amber); }

/* ---------- panels ---------- */
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.g-wide { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); }
.g-wide-r { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 16px; min-width: 0; }
.panel.flush { padding: 0; overflow: hidden; }
.panel > header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.panel > header.mt { margin-top: 18px; }
.panel h2 { font-size: 15px; margin: 0; font-weight: 600; margin-inline-end: auto; }
.panel .sub { font-size: 12.5px; color: var(--ink-3); }
.link { font-size: 13px; color: var(--petrol); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.chart-box { position: relative; height: 200px; }
.chart-box.tall { height: 290px; }
.chart-box.loading canvas, .barlist.loading, .tbl.loading { opacity: .45; transition: opacity .2s; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

/* HTML bar list (topics / languages) */
.barlist { display: flex; flex-direction: column; gap: 9px; }
.bl-row { display: grid; grid-template-columns: minmax(0, 11.5em) minmax(0, 1fr) 3.2em; align-items: center; gap: 10px; font-size: 13.5px; }
.bl-row .bl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bl-track { height: 10px; background: var(--surface-2); border-radius: 0 4px 4px 0; position: relative; display: flex; }
[dir="rtl"] .bl-track { border-radius: 4px 0 0 4px; }
.bl-fill { height: 100%; background: var(--petrol); border-radius: inherit; min-width: 2px; }
.bl-fill.gap { background: var(--serious); }
.bl-val { text-align: end; font-variant-numeric: tabular-nums; font-weight: 600; }
.bl-row .bl-meta { grid-column: 2 / 4; font-size: 12px; color: var(--ink-3); margin-top: -6px; }
.bl-row:hover .bl-fill { filter: brightness(1.12); }

.status-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.st { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; display: flex; flex-direction: column; }
.st b { font-size: 20px; font-variant-numeric: tabular-nums; }
.st span { font-size: 12.5px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }

/* status pills (icon + label, never color alone) */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; padding: 2px 9px 2px 8px;
        border-radius: 20px; border: 1px solid var(--line); white-space: nowrap; background: var(--surface); }
.pill i { width: 8px; height: 8px; border-radius: 50%; }
.pill.new i { background: var(--crit); } .pill.in_progress i { background: var(--warn); }
.pill.resolved i { background: var(--good); } .pill.closed i { background: var(--ink-3); }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 5px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.chip.voice { background: color-mix(in srgb, var(--s2) 14%, transparent); }
.chip.text { background: color-mix(in srgb, var(--s1) 12%, transparent); }

/* tables */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: start; font-weight: 500; color: var(--ink-3); font-size: 12.5px; padding: 9px 12px; border-bottom: 1px solid var(--line);
          background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink-2); }
.tbl td.q { max-width: 46ch; }
.tbl .clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tbl.clickable tbody tr { cursor: pointer; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tbody tr.sel td { background: var(--petrol-soft); }
.tbl .empty-row td { text-align: center; color: var(--ink-3); padding: 28px; }
.tbl button.rowbtn { all: unset; cursor: pointer; color: var(--petrol); font-weight: 500; white-space: nowrap; }
.tbl button.rowbtn:focus-visible { outline: 3px solid var(--amber); }

/* toolbars */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 360px; height: 38px; }
.check { display: inline-flex; gap: 7px; align-items: center; font-size: 14px; color: var(--ink-2); }
.count { font-size: 13px; color: var(--ink-3); margin-inline-start: auto; }
.intro { color: var(--ink-2); max-width: 80ch; margin: 0 0 14px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-3); }

/* conversations split */
.split { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.transcript { position: sticky; top: 92px; max-height: calc(100dvh - 110px); overflow: auto; }
.transcript .empty { color: var(--ink-3); text-align: center; padding: 40px 10px; margin: 0; }
.tr-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tr-head h3 { margin: 0; font-size: 15px; margin-inline-end: auto; }
.tr-msg { margin: 0 0 12px; }
.tr-msg .meta { font-size: 12px; color: var(--ink-3); display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 3px; }
.tr-msg .body.md { white-space: normal; }
.tr-msg .body.md p { margin: 0 0 .5em; } .tr-msg .body.md > :last-child { margin-bottom: 0; }
.tr-msg .body.md table { border-collapse: collapse; margin: .3em 0 .6em; font-size: 13px; }
.tr-msg .body.md th, .tr-msg .body.md td { border: 1px solid var(--line); padding: 4px 8px; }
.tr-msg .body.md ul, .tr-msg .body.md ol { margin: 0 0 .5em; padding-inline-start: 1.3em; }
.tr-msg .body { white-space: pre-wrap; padding: 9px 12px; border-radius: 10px; font-size: 14px; overflow-wrap: anywhere; }
.tr-msg.user .body { background: var(--petrol-soft); }
.tr-msg.assistant .body { background: var(--surface-2); border: 1px solid var(--line); }
.tr-msg.na .body { border-inline-start: 3px solid var(--serious); }
.flag-na { color: var(--crit-ink); font-weight: 600; }

/* feedback */
.fb-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.fb { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.fb .fb-top { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--ink-3); }
.fb .fb-rate { font-weight: 600; display: inline-flex; gap: 5px; align-items: center; }
.fb .fb-rate.down { color: var(--crit-ink); } .fb .fb-rate.up { color: var(--good-ink); }
.fb .fb-rate svg { width: 15px; height: 15px; }
.fb .fb-q { font-weight: 600; font-size: 14.5px; }
.fb .fb-a { font-size: 13.5px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.fb .fb-c { font-size: 13.5px; background: var(--amber-soft); color: var(--amber-ink); padding: 6px 10px; border-radius: 8px; }
.fb button { align-self: flex-start; }

/* dialog */
.dlg { border: 0; padding: 0; border-radius: 14px; width: min(600px, calc(100vw - 24px)); background: var(--surface); color: var(--ink);
       box-shadow: 0 30px 80px -20px rgba(0,0,0,.45); }
.dlg::backdrop { background: rgba(8,22,30,.5); }
.dlg-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 16px; margin: 0; flex: 1; }
.dlg-body { padding: 14px 18px; display: flex; flex-direction: column; gap: 12px; }
.dlg-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 14px 14px; }
.spacer { flex: 1; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

/* tooltip + toast */
.tip { position: fixed; z-index: 70; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 12.5px;
       padding: 6px 10px; border-radius: 8px; max-width: 260px; box-shadow: var(--shadow); }
.tip b { font-size: 14px; font-variant-numeric: tabular-nums; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
         padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 80; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1080px) {
  .g-wide, .g-wide-r, .g-3, .split { grid-template-columns: minmax(0, 1fr); }
  .transcript { position: static; max-height: none; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .nav { position: fixed; inset-block: 0; inset-inline-start: 0; width: 260px; z-index: 40; transform: translateX(110%); transition: transform .2s; }
  [dir="ltr"] .nav { transform: translateX(-110%); }
  .nav.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .menu-btn { display: inline-flex; }
  .bar { position: static; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .updated { display: none; }
}
@media (max-width: 480px) {
  .filters { width: 100%; }
  .seg { overflow-x: auto; max-width: 100%; }
  .kpi .k-val { font-size: 23px; }
  .status-strip { grid-template-columns: repeat(2, 1fr); }
  .fb-list { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ترجمة عربية للأسئلة غير العربية */
.tr-ar { margin-top: 4px; font-size: .92em; font-weight: 400; color: var(--ink-2); }
.tr-msg .tr-ar { padding: 6px 10px; border-inline-start: 3px solid var(--petrol); border-radius: 4px; background: var(--petrol-soft); }
.tr-tag { display: inline-block; font-size: .78em; font-weight: 600; padding: 0 6px; border-radius: 999px;
          background: rgba(127,127,127,.15); margin-inline-end: 4px; }
