/* AI Support Line: tokens (primitives -> semantic), light and dark. Components use semantic tokens only. */
:root {
  --bg: #F6F6F3; --surface: #FFFFFF; --surface-2: #EFEFEA; --border: #DEDED8; --border-strong: #C9C9C1;
  --text: #17171A; --muted: #5E5E66; --faint: #8A8A92;
  --accent: #4338CA; --accent-ink: #FFFFFF; --accent-soft: #E6E5FB; --accent-line: #B9B6F3;
  --ok: #15803D; --ok-soft: #E3F4E8; --warn: #B45309; --warn-soft: #FBEEDB; --bad: #B91C1C; --bad-soft: #FBE4E4;
  --dot: #D2D2CA; --shadow: 0 1px 2px rgba(23, 23, 26, 0.05), 0 8px 24px -12px rgba(23, 23, 26, 0.12);
  --r-ctl: 6px; --r-panel: 12px;
  --display: "Bricolage Grotesque", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --sans: "Geist", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --arabic: "IBM Plex Sans Arabic", "Geist", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121214; --surface: #1A1A1E; --surface-2: #202026; --border: #2E2E36; --border-strong: #3C3C46;
  --text: #ECECEF; --muted: #9A9AA4; --faint: #6E6E78;
  --accent: #8B8CFF; --accent-ink: #121214; --accent-soft: #26264A; --accent-line: #4A4A8C;
  --ok: #4ADE80; --ok-soft: #17301F; --warn: #FBBF24; --warn-soft: #33270F; --bad: #F87171; --bad-soft: #3A1A1A;
  --dot: #2C2C34; --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -14px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214; --surface: #1A1A1E; --surface-2: #202026; --border: #2E2E36; --border-strong: #3C3C46;
    --text: #ECECEF; --muted: #9A9AA4; --faint: #6E6E78;
    --accent: #8B8CFF; --accent-ink: #121214; --accent-soft: #26264A; --accent-line: #4A4A8C;
    --ok: #4ADE80; --ok-soft: #17301F; --warn: #FBBF24; --warn-soft: #33270F; --bad: #F87171; --bad-soft: #3A1A1A;
    --dot: #2C2C34; --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -14px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body { margin: 0; font: 16px/1.5 var(--sans); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
[lang="ar"], [dir="rtl"] { font-family: var(--arabic); letter-spacing: 0; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; text-wrap: balance; margin: 0; }
code, .mono { font-family: var(--mono); font-size: 0.88em; }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
::selection { background: var(--accent-soft); color: var(--text); }
textarea { caret-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-ctl); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: var(--r-ctl); z-index: 10; }
.skip:focus { left: 8px; }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ---------------------------------------------------------------- header + intro */
.site { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1480px; margin: 0 auto; padding: 14px 24px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-height: 44px; }
.mark { width: 28px; height: 28px; }
.mark rect { fill: var(--text); }
.mark path { fill: none; stroke: var(--bg); stroke-width: 2.2; stroke-linecap: round; }
.brand-name { font-family: var(--display); font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
.site-nav { display: flex; align-items: center; gap: 4px 6px; flex-wrap: wrap; justify-content: flex-end; }
.site-nav > a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; color: var(--muted); text-decoration: none; font-size: 14.5px; border-radius: var(--r-ctl); }
.site-nav > a:hover { color: var(--text); background: var(--surface-2); }
.model { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); margin-inline-end: 6px; }
.model code { font-size: 12px; color: var(--text); }
.model-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: var(--r-ctl); background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .moon { display: none; }
:root[data-theme="dark"] .icon-btn .sun { display: none; }
:root[data-theme="dark"] .icon-btn .moon { display: block; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .icon-btn .sun { display: none; } :root:not([data-theme="light"]) .icon-btn .moon { display: block; } }

.brand-tag { color: var(--muted); font-size: 13.5px; margin-inline-start: 6px; padding-inline-start: 12px; border-inline-start: 1px solid var(--border); }

/* ---------------------------------------------------------------- console: chat + phone pinned left, both diagrams right */
.console { container: console / inline-size; display: grid; grid-template-columns: minmax(320px, 380px) minmax(0, 1fr); gap: 20px; max-width: 1760px; margin: 0 auto; padding: 4px 24px 20px; align-items: start; }
.side { position: sticky; top: 12px; min-width: 0; }
.side-inner { max-height: calc(100vh - 24px); display: flex; flex-direction: column; }
.side .chat { display: flex; flex-direction: column; min-height: 0; max-height: calc(100vh - 24px); }
.side .messages { flex: 1 1 auto; max-height: none; min-height: 120px; }
.stage { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; min-width: 0; align-items: start; }
/* wide screens: both diagrams side by side, so the agent and the call centre are watched at once */
@container console (min-width: 1500px) { .stage { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .stage .lists { grid-column: 1 / -1; } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-panel); padding: 18px; box-shadow: var(--shadow); }
.panel-title { font-size: 17px; letter-spacing: -0.01em; margin: 0 0 8px; }
.head-title { font-size: 16px; letter-spacing: -0.01em; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-inline-end: auto; }
.head-title span { font-family: var(--sans); font-weight: 400; font-size: 13.5px; color: var(--muted); }
.hint { margin: 0 0 14px; color: var(--muted); font-size: 14px; max-width: 60ch; }
.lists { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.panel-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 10px 14px; border-top: 1px solid var(--border); }
.foot-t { font-size: 13px; color: var(--muted); margin-inline-end: 2px; }
.steps { flex: 1 1 260px; }
.steps summary { cursor: pointer; font-size: 13.5px; color: var(--muted); min-height: 36px; display: flex; align-items: center; justify-content: flex-end; }
.steps[open] summary { color: var(--text); }
.steps .trace { max-height: 280px; overflow-y: auto; margin-top: 6px; }
.foot { max-width: 1760px; margin: 0 auto; padding: 4px 24px 28px; color: var(--faint); font-size: 13px; }

/* ---------------------------------------------------------------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-size: 15px; font-weight: 500; min-height: 44px; min-width: 44px; padding: 0 16px; border-radius: var(--r-ctl); cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); transition: background-color 140ms var(--ease-out), border-color 140ms var(--ease-out), transform 100ms var(--ease-out); }
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); border-color: transparent; }
.linkbtn { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; padding: 4px; }

/* ---------------------------------------------------------------- call panel */
.call-panel { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; margin: -18px -18px 18px; padding: 16px 18px; border-bottom: 1px solid var(--border); border-radius: var(--r-panel) var(--r-panel) 0 0; background: var(--surface-2); }
.call-panel[data-state="live"], .call-panel[data-state="calling"] { background: var(--ok-soft); }
.call-panel[data-state="error"] { background: var(--bad-soft); }
.call-info { flex: 1 1 180px; min-width: 0; }
.call-title { margin: 0; font-weight: 600; display: flex; flex-wrap: wrap; gap: 2px 10px; }
.call-title [lang="ar"] { color: var(--muted); font-weight: 500; }
.call-status { margin: 2px 0 0; font-size: 13.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0 10px; }
.call-btns { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.btn.call { background: var(--ok); border-color: var(--ok); color: #fff; }
:root[data-theme="dark"] .btn.call { color: #0B1F12; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.call { color: #0B1F12; } }
.btn.call:hover:not(:disabled) { background: var(--ok); border-color: var(--ok); filter: brightness(1.08); }
.btn.call span + span { opacity: 0.85; }
.btn.hang { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.hang:hover:not(:disabled) { background: var(--bad); filter: brightness(1.08); }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); }
.call-timer { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ok); min-width: 3.5em; font-size: 14px; }
.call-panel [hidden] { display: none; }

/* ---------------------------------------------------------------- chat */
.messages { list-style: none; margin: 10px 0 0; padding: 0 2px; display: flex; flex-direction: column; gap: 10px; min-height: 200px; max-height: 44vh; overflow-y: auto; scroll-behavior: smooth; }
.msg { display: flex; flex-direction: column; max-width: 90%; animation: rise 220ms var(--ease-out); }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.agent { align-self: flex-start; align-items: flex-start; }
.msg .bubble { padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.msg.user .bubble { background: var(--text); color: var(--bg); border-end-end-radius: 4px; }
.msg.agent .bubble { background: var(--surface-2); border-end-start-radius: 4px; }
.msg.intro .bubble { color: var(--muted); background: transparent; border: 1px dashed var(--border-strong); }
.msg[dir="rtl"] .bubble, .bubble[dir="rtl"] { line-height: 1.75; }
.msg.thinking .bubble { color: var(--muted); }
.msg.thinking .bubble::after { content: ""; display: inline-block; width: 1.2em; text-align: start; animation: dots 1.2s steps(4) infinite; }
.msg.phone .bubble { background: var(--ok-soft); }
.msg.user.phone .bubble { color: var(--text); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.badge.human { background: var(--warn-soft); color: var(--warn); }
.badge.ticket { background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums; }
.badge.err { background: var(--bad-soft); color: var(--bad); }
.badge.phone { background: var(--ok-soft); color: var(--ok); }
.badge.phone svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 12px; }
.chip { font: inherit; font-size: 13.5px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 8px 13px; min-height: 40px; cursor: pointer; text-align: start; max-width: 100%; transition: border-color 140ms var(--ease-out), background-color 140ms var(--ease-out); }
.chip:hover:not(:disabled) { border-color: var(--accent-line); background: var(--accent-soft); }
.chip:active:not(:disabled) { transform: scale(0.98); }
.chip-risk { border-color: var(--warn); border-style: dashed; }
.chip-risk:hover:not(:disabled) { border-color: var(--warn); background: var(--warn-soft); }
.chip:disabled { opacity: 0.5; cursor: not-allowed; }
.cf-chip { font: inherit; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; min-height: 36px; padding: 6px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: border-color 140ms var(--ease-out), background-color 140ms var(--ease-out); }
.cf-chip::before { content: ""; width: 0; height: 0; border-style: solid; border-width: 4.5px 0 4.5px 7px; border-color: transparent transparent transparent currentColor; opacity: 0.7; }
.cf-chip:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.cf-chip:active { transform: scale(0.98); }

.composer { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); transition: border-color 140ms var(--ease-out), box-shadow 140ms var(--ease-out); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea { min-height: 56px; resize: vertical; font: inherit; font-size: 16px; color: var(--text); background: transparent; border: 0; padding: 12px 14px 4px; }
.composer textarea:focus-visible { outline: none; }
.composer textarea::placeholder { color: var(--faint); }
.composer-row { display: flex; align-items: center; gap: 8px; padding: 6px; }
.composer .attach { cursor: pointer; padding: 0 10px; font-size: 14px; }
.kbd-hint { flex: 1; margin: 0; font-size: 12.5px; color: var(--faint); text-align: end; }
.shot-chip { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.status { min-height: 1.5em; margin: 8px 0 0; font-size: 13.5px; color: var(--muted); }
.status.error { color: var(--bad); }

/* ---------------------------------------------------------------- outage switches */
.switches { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; user-select: none; transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track { width: 32px; height: 18px; border-radius: 999px; background: var(--bad); position: relative; flex: none; transition: background-color 150ms var(--ease-out); }
.track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform 150ms var(--ease-out); }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 3px; }
.sw-label { font-size: 13.5px; font-weight: 500; }
.sw-state { font-size: 12px; font-family: var(--mono); color: var(--ok); }
.switch.down { border-color: var(--bad); background: var(--bad-soft); }
.switch.down .sw-state { color: var(--bad); }

/* ---------------------------------------------------------------- trace (Steps tab) */
.trace { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0; }
.trace-empty, .empty { color: var(--muted); font-size: 14px; padding: 6px 0; }
.step { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 2px 10px; align-items: baseline; padding: 10px 4px; border-bottom: 1px solid var(--border); animation: rise 200ms var(--ease-out); }
.step .n { color: var(--faint); font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.step .tool { font-family: var(--mono); font-weight: 500; font-size: 13.5px; color: var(--accent); }
.step .meta { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.step .args { grid-column: 2 / 4; font-family: var(--mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.step .note { grid-column: 2 / 4; font-size: 14px; color: var(--text); overflow-wrap: anywhere; }
.step .ok { color: var(--ok); }
.step .bad { color: var(--bad); }
.step.risk { background: var(--warn-soft); border-radius: 8px; padding-inline: 10px; }
.step.risk .tool { color: var(--warn); }
.step.error .tool { color: var(--bad); }
.step.turn { padding: 6px 4px; }
.step.turn .tool { color: var(--faint); font-weight: 400; font-family: var(--sans); font-size: 12.5px; }
.step.final .tool { color: var(--text); }
.step .checks { grid-column: 2 / 4; margin: 4px 0 0; padding-inline-start: 16px; font-size: 13px; }
.step .checks li.viol { color: var(--bad); }
.step .checks li.rep { color: var(--accent); }

/* ---------------------------------------------------------------- approval + ticket rows */
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 0; border-top: 1px solid var(--border); animation: rise 220ms var(--ease-out); }
.row:first-child { border-top: 0; padding-top: 4px; }
.row .main { flex: 1 1 200px; min-width: 0; }
.row .title { overflow-wrap: anywhere; display: flex; gap: 8px; align-items: baseline; font-size: 15px; }
.row .title .num { font-family: var(--mono); font-size: 12.5px; color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.row .title bdi { flex: 1; min-width: 0; }
.row .title bdi[dir="rtl"], .row .title bdi:dir(rtl) { text-align: right; }
.row .sub { font-size: 12.5px; color: var(--muted); font-family: var(--mono); overflow-wrap: anywhere; }
.row.pending { background: var(--warn-soft); border-radius: 10px; padding: 12px; border-top-color: transparent; }
.row .acts { display: flex; gap: 8px; }
.btn.approve { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.reject { background: transparent; border-color: var(--border-strong); color: var(--text); }
:root[data-theme="dark"] .btn.approve { color: #0B1F12; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.approve { color: #0B1F12; } }
.pill { font-size: 12px; font-family: var(--mono); padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.approved { color: var(--ok); background: var(--ok-soft); }
.pill.pending { color: var(--warn); background: var(--warn-soft); }
.pill.rejected { color: var(--bad); background: var(--bad-soft); }
.pill.high, .pill.critical { color: var(--bad); }

@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1080px) {
  .console { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; }
  .side-inner, .side .chat { max-height: none; }
  .side .messages { max-height: 50vh; }
}
@media (max-width: 760px) {
  .site { padding: 8px 16px; }
  .model, .brand-tag { display: none; }
  .console { padding: 0 12px 12px; gap: 14px; }
  .stage { gap: 14px; }
  .panel { padding: 14px; }
  .call-panel { margin: -14px -14px 14px; padding: 12px 14px; }
  .lists { grid-template-columns: 1fr; gap: 14px; }
  .msg { max-width: 94%; }
  .kbd-hint { display: none; }
  .composer-row { justify-content: space-between; }
  .step { grid-template-columns: 24px minmax(0, 1fr); }
  .step .meta, .step .args, .step .note, .step .checks { grid-column: 2; }
  .call-btns .btn { flex: 1 1 auto; }
  .foot { padding: 4px 12px 20px; }
}
/* in a call on a phone, the page scrolls to the diagram: keep Mute / Hang up on screen */
@media (max-width: 900px) {
  .call-panel[data-state="live"] .call-btns, .call-panel[data-state="calling"] .call-btns {
    position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 40;
    padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  }
  body:has(.call-panel[data-state="live"]), body:has(.call-panel[data-state="calling"]) { padding-bottom: 88px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
