/* ── Fonts (self-hosted) ─────────────────────────────────────────── */
@font-face { font-family: "Readex Pro"; font-weight: 500; font-display: swap; src: url(fonts/readex-pro-arabic-500-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "Readex Pro"; font-weight: 600; font-display: swap; src: url(fonts/readex-pro-arabic-600-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "Readex Pro"; font-weight: 500; font-display: swap; src: url(fonts/readex-pro-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Readex Pro"; font-weight: 600; font-display: swap; src: url(fonts/readex-pro-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "Plex Arabic"; font-weight: 500; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "Plex Arabic"; font-weight: 600; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Plex Arabic"; font-weight: 500; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Plex Arabic"; font-weight: 600; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Plex Mono"; font-weight: 400; font-display: swap; src: url(fonts/ibm-plex-mono-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Plex Mono"; font-weight: 500; font-display: swap; src: url(fonts/ibm-plex-mono-latin-500-normal.woff2) format("woff2"); }

/* ── Tokens ──────────────────────────────────────────────────────── */
:root {
  --bg: #F2F3F1;          /* slate mist */
  --surface: #FFFFFF;
  --surface-2: #F7F8F6;
  --ink: #16181A;         /* graphite */
  --ink-2: #3A3F43;
  --muted: #6B7176;
  --line: #E1E4E0;
  --line-2: #D2D6D1;
  --live: #1F7A6D;        /* verdigris — Hermes bronze */
  --live-soft: #E3F1EE;
  --warn: #A96A12;        /* amber — needs you */
  --warn-soft: #FBF1E0;
  --bad: #B4332A;
  --bad-soft: #FBE9E7;
  --term-bg: #16181A;
  --term-ink: #D9E2DF;
  --shadow: 0 1px 2px rgba(22,24,26,.04), 0 8px 24px -12px rgba(22,24,26,.12);
  --r-sm: 8px; --r: 12px; --r-lg: 18px;
  --f-display: "Readex Pro", "Plex Arabic", system-ui, sans-serif;
  --f-body: "Plex Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  --f-mono: "Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sidebar-w: 272px;
  --panel-w: 400px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121514; --surface: #1A1E1D; --surface-2: #161A19;
    --ink: #ECEFED; --ink-2: #C7CDCA; --muted: #8E9692;
    --line: #2A302E; --line-2: #37403D;
    --live: #3FB5A3; --live-soft: #173330;
    --warn: #E0A64B; --warn-soft: #33281A;
    --bad: #EB7B70; --bad-soft: #3A1F1C;
    --term-bg: #0C0E0E; --term-ink: #D9E2DF;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

/* ── Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.7 var(--f-body);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
code, pre, kbd { font-family: var(--f-mono); }
.noscript { padding: 2rem; }

.app {
  height: 100dvh; display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--panel-w);
  grid-template-areas: "side main panel";
}
.app.panel-closed { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 0; }
.app.panel-closed .panel { display: none; }
.app[data-view="agents"] { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); grid-template-areas: "side agents"; }
.app[data-view="agents"] .main, .app[data-view="agents"] .panel { display: none; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  grid-area: side; display: flex; flex-direction: column; min-height: 0;
  padding: 16px 12px 12px; gap: 12px; border-inline-end: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 6px; }
.brand-mark { inline-size: 34px; block-size: 34px; border-radius: 10px; background: var(--ink); display: grid; place-items: center; flex: none; }
.brand-mark svg { inline-size: 22px; block-size: 22px; fill: none; stroke: var(--live); stroke-width: 2.2; stroke-linecap: round; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-mark { background: #0C0E0E; box-shadow: inset 0 0 0 1px var(--line-2); } }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; flex: 1; }
.brand-text strong { font: 600 17px/1.2 var(--f-display); letter-spacing: -.01em; }
.conn { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ""; inline-size: 7px; block-size: 7px; border-radius: 50%; background: var(--muted); }
.conn[data-state="open"]::before { background: var(--live); }
.conn[data-state="closed"]::before { background: var(--bad); }

.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 10px 16px;
  background: var(--ink); color: var(--bg); font-weight: 500;
  transition: transform .12s ease, opacity .12s;
}
.btn-primary:hover { opacity: .9; }
.btn-primary:active { transform: scale(.98); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; inline-size: 100%;
  border: 0; background: transparent; padding: 8px 10px; border-radius: var(--r-sm); text-align: start;
}
.nav-item:hover, .nav-item[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow); }
.nav-ico { inline-size: 20px; text-align: center; color: var(--muted); font-family: var(--f-mono); }
.nav-count { margin-inline-start: auto; font: 500 12px var(--f-mono); color: var(--muted); }

.search input {
  inline-size: 100%; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: var(--r-sm); padding: 7px 10px; font-size: 14px;
}
.search input::placeholder { color: var(--muted); }

.task-list { flex: 1; overflow-y: auto; min-height: 0; margin-inline: -4px; padding-inline: 4px; }
.task-group { font-size: 12px; color: var(--muted); padding: 12px 10px 4px; }
.task {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center;
  inline-size: 100%; text-align: start; border: 0; background: transparent;
  padding: 8px 10px; border-radius: var(--r-sm);
}
.task:hover { background: rgba(127,127,127,.08); }
.task[aria-current="true"] { background: var(--surface); box-shadow: var(--shadow); }
.task-title { font-size: 14px; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.task-sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
.task-agents { font: 500 11px var(--f-mono); color: var(--live); background: var(--live-soft); border-radius: 999px; padding: 1px 7px; }
.task-running { inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--live); animation: pulse 1.6s ease-in-out infinite; }
.task-running.waiting { background: var(--warn); }
.skeleton { block-size: 44px; margin: 6px 4px; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--line) 0%, var(--surface-2) 50%, var(--line) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; opacity: .6; }
.empty-note { color: var(--muted); font-size: 13px; padding: 10px; }

.sidebar-foot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.spend { color: var(--muted); font-family: var(--f-mono); }
.foot-link { color: var(--muted); text-decoration: none; }
.foot-link:hover { color: var(--ink); }

/* ── Main / thread ───────────────────────────────────────────────── */
.main { grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid var(--line); min-block-size: 60px;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font: 600 16px/1.35 var(--f-display); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.meta b { font-family: var(--f-mono); font-weight: 500; color: var(--ink-2); }

.icon-btn { border: 0; background: transparent; inline-size: 34px; block-size: 34px; border-radius: 8px; font-size: 16px; }
.icon-btn:hover { background: rgba(127,127,127,.1); }
.chip-btn {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; font-size: 13px;
}
.chip-btn:hover { border-color: var(--line-2); }
.live-dot { inline-size: 7px; block-size: 7px; border-radius: 50%; background: var(--muted); }
.app.running .live-dot { background: var(--live); animation: pulse 1.6s ease-in-out infinite; }

.thread-wrap { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: smooth; }
.thread { max-inline-size: 780px; margin: 0 auto; padding: 28px 24px 16px; display: flex; flex-direction: column; gap: 22px; }

.welcome { padding: 10vh 4px 0; }
.welcome-kicker { margin: 0 0 6px; font: 500 13px var(--f-mono); color: var(--live); letter-spacing: .02em; }
.welcome-title { margin: 0; font: 600 clamp(26px, 3.4vw, 36px)/1.25 var(--f-display); letter-spacing: -.02em; }
.welcome-sub { margin: 10px 0 24px; color: var(--muted); }
.starters { display: flex; flex-wrap: wrap; gap: 8px; }
.starter { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 7px 14px; font-size: 14px; }
.starter:hover { border-color: var(--ink); }

.msg-user { align-self: flex-start; max-inline-size: 86%; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-lg); border-start-start-radius: 6px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.turn { display: flex; flex-direction: column; gap: 10px; }
.turn-head { display: flex; align-items: center; gap: 8px; font: 600 14px var(--f-display); }
.turn-head .avatar { inline-size: 22px; block-size: 22px; border-radius: 7px; background: var(--ink); display: grid; place-items: center; }
.turn-head .avatar svg { inline-size: 14px; block-size: 14px; fill: none; stroke: var(--live); stroke-width: 2.4; stroke-linecap: round; }
.turn-head .when { font: 400 12px var(--f-body); color: var(--muted); }
.thinking { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.thinking::before { content: ""; inline-size: 14px; block-size: 14px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--live); animation: spin .9s linear infinite; }

/* step list (Manus-style task progress) */
.steps { display: flex; flex-direction: column; gap: 4px; border-inline-start: 2px solid var(--line); padding-inline-start: 12px; margin-inline-start: 10px; }
.step {
  display: flex; align-items: center; gap: 8px; inline-size: fit-content; max-inline-size: 100%;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px;
  padding: 3px 11px 3px 9px; font-size: 13px; text-align: start;
}
.step:hover { border-color: var(--line-2); }
.step[aria-pressed="true"] { border-color: var(--ink); }
.step-ico { font-size: 12px; inline-size: 16px; text-align: center; flex: none; }
.step-verb { color: var(--muted); flex: none; }
.step-arg { font-family: var(--f-mono); font-size: 12px; color: var(--ink-2); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; direction: ltr; unicode-bidi: plaintext; min-width: 0; }
.step[data-state="running"] { border-color: var(--live); background: var(--live-soft); }
.step[data-state="running"] .step-ico { animation: pulse 1.2s ease-in-out infinite; }
.step[data-state="error"] { border-color: var(--bad); background: var(--bad-soft); }
.step[data-state="blocked"] { border-color: var(--warn); background: var(--warn-soft); }
.steps-more { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 2px 4px; text-align: start; }

.agent-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.agent-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; border-radius: 999px; padding: 2px 10px; background: var(--live-soft); color: var(--live); border: 1px solid transparent; }
.agent-chip[data-state="done"] { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.agent-chip[data-state="failed"] { background: var(--bad-soft); color: var(--bad); }

.answer { overflow-wrap: anywhere; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer h1, .answer h2, .answer h3 { font-family: var(--f-display); font-weight: 600; line-height: 1.35; margin: 1.2em 0 .4em; }
.answer h1 { font-size: 20px; } .answer h2 { font-size: 18px; } .answer h3 { font-size: 16px; }
.answer p { margin: .5em 0; }
.answer ul, .answer ol { padding-inline-start: 1.4em; margin: .5em 0; }
.answer a { color: var(--live); }
.answer code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-size: .88em; direction: ltr; unicode-bidi: isolate; }
.answer pre { background: var(--term-bg); color: var(--term-ink); border-radius: var(--r); padding: 12px 14px; overflow-x: auto; direction: ltr; text-align: left; font-size: 13px; line-height: 1.55; }
.answer pre code { background: none; border: 0; padding: 0; color: inherit; }
.answer table { border-collapse: collapse; display: block; overflow-x: auto; max-inline-size: 100%; font-size: 14px; margin: .6em 0; }
.answer th, .answer td { border: 1px solid var(--line); padding: 6px 10px; text-align: start; vertical-align: top; }
.answer th { background: var(--surface-2); font-weight: 600; }
.answer blockquote { margin: .6em 0; padding: 2px 12px; border-inline-start: 3px solid var(--line-2); color: var(--ink-2); }
.answer.streaming::after { content: ""; display: inline-block; inline-size: 8px; block-size: 1em; margin-inline-start: 2px; vertical-align: text-bottom; background: var(--live); animation: blink 1s steps(2) infinite; }

.turn-foot { display: flex; gap: 12px; font: 12px var(--f-mono); color: var(--muted); }

/* ask cards (clarify / approval / guard) */
.ask {
  border: 1px solid var(--warn); background: var(--warn-soft); border-radius: var(--r);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 10px;
}
.ask-kicker { font: 600 12px var(--f-display); color: var(--warn); }
.ask-q { font-weight: 500; }
.ask-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.ask-choice { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 5px 14px; }
.ask-choice:hover, .ask-choice[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--bg); }
.ask-row { display: flex; gap: 8px; }
.ask-row input { flex: 1; min-width: 0; border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--r-sm); padding: 6px 10px; }
.ask-row button { border: 0; background: var(--ink); color: var(--bg); border-radius: var(--r-sm); padding: 6px 14px; }
.ask.done { border-color: var(--line); background: var(--surface-2); }
.ask.done .ask-kicker { color: var(--muted); }
.ask-cmd { display: flex; align-items: center; gap: 8px; background: var(--term-bg); color: var(--term-ink); border-radius: var(--r-sm); padding: 6px 10px; direction: ltr; font: 13px var(--f-mono); }
.ask-cmd code { flex: 1; }
.ask-cmd button { border: 1px solid #3a4040; background: transparent; color: var(--term-ink); border-radius: 6px; padding: 2px 8px; font-size: 12px; }
.note-err { color: var(--bad); font-size: 13px; }
.ask-block { display: flex; flex-direction: column; gap: 8px; }
.ask-answer {
  align-self: flex-start; max-inline-size: 100%; background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-lg); border-start-start-radius: 6px; padding: 7px 12px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.ask-answer::before { content: "ردّك: "; color: var(--muted); font-size: 12px; }
.ask-answer.none { color: var(--muted); font-style: italic; }
.ask-answer.none::before { content: ""; }
.ask.busy { opacity: .75; }
.ask.busy .ask-kicker::after { content: ""; display: inline-block; inline-size: 10px; block-size: 10px; margin-inline-start: 8px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--warn); animation: spin .9s linear infinite; vertical-align: middle; }
.ask.expired { border-color: var(--bad); background: var(--bad-soft); }
.ask.expired .ask-kicker { color: var(--bad); }

/* composer */
.composer { padding: 10px 20px 18px; }
.composer-box {
  max-inline-size: 780px; margin: 0 auto; border: 1px solid var(--line-2); background: var(--surface);
  border-radius: 20px; padding: 10px 12px 8px 12px; box-shadow: var(--shadow);
  transition: border-color .15s;
}
.composer-box:focus-within { border-color: var(--ink); }
.composer textarea { inline-size: 100%; border: 0; outline: none; resize: none; background: transparent; max-block-size: 220px; line-height: 1.6; padding: 2px 4px; }
.composer-row { display: flex; align-items: center; gap: 8px; }
.hint { flex: 1; font-size: 12px; color: var(--muted); }
.btn-send { inline-size: 34px; block-size: 34px; border-radius: 50%; border: 0; background: var(--ink); color: var(--bg); display: grid; place-items: center; }
.btn-send svg { inline-size: 18px; block-size: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn-send:disabled { opacity: .35; cursor: default; }
.btn-stop { border: 1px solid var(--bad); color: var(--bad); background: transparent; border-radius: 999px; padding: 4px 14px; font-size: 13px; }

/* ── Panel (agent's computer) ────────────────────────────────────── */
.panel { grid-area: panel; display: flex; flex-direction: column; min-height: 0; border-inline-start: 1px solid var(--line); background: var(--bg); }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); min-block-size: 60px; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; flex: 1; }
.tab { flex: 1; border: 0; background: transparent; border-radius: 999px; padding: 5px 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 500; }
.tab-badge { font: 500 11px var(--f-mono); }
.tab-body { flex: 1; overflow-y: auto; min-height: 0; padding: 16px 14px; }

/* signature: the relay lineage */
.lineage { position: relative; }
.node { position: relative; padding-inline-start: 26px; }
.node::before { /* vertical relay line to children */
  content: ""; position: absolute; inset-inline-start: 8px; inset-block: 22px 0;
  inline-size: 2px; background: var(--line-2);
}
.node:not(.has-children)::before { display: none; }
.node.active-branch::before {
  background: repeating-linear-gradient(180deg, var(--live) 0 6px, transparent 6px 12px);
  background-size: 2px 12px; animation: relay 0.9s linear infinite;
}
.node-card {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 9px 12px; margin-block-end: 10px; box-shadow: var(--shadow);
}
.node-card::before { /* the joint on the relay line */
  content: ""; position: absolute; inset-inline-start: -23px; inset-block-start: 14px;
  inline-size: 12px; block-size: 12px; border-radius: 50%; background: var(--surface);
  border: 2px solid var(--line-2);
}
.node > .node-card::after { /* elbow from parent line */
  content: ""; position: absolute; inset-inline-start: -47px; inset-block-start: 19px; inline-size: 24px; block-size: 2px; background: var(--line-2);
}
.lineage > .node > .node-card::after { display: none; }
.node[data-state="running"] > .node-card { border-color: var(--live); }
.node[data-state="running"] > .node-card::before { border-color: var(--live); background: var(--live); box-shadow: 0 0 0 4px var(--live-soft); animation: pulse 1.6s ease-in-out infinite; }
.node[data-state="done"] > .node-card::before { border-color: var(--live); background: var(--surface); }
.node[data-state="failed"] > .node-card { border-color: var(--bad); }
.node[data-state="failed"] > .node-card::before { border-color: var(--bad); background: var(--bad); }
.node-children { padding-inline-start: 4px; }
.node-top { display: flex; align-items: center; gap: 8px; }
.node-name { font: 600 14px var(--f-display); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-kind { font-size: 11px; border-radius: 999px; padding: 1px 8px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.node-kind.k-root { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.node-kind.k-spec { background: var(--live-soft); color: var(--live); border-color: transparent; }
.node-goal { font-size: 13px; color: var(--ink-2); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.node-stats { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 5px; font: 11px var(--f-mono); color: var(--muted); }
.node-activity { margin-top: 5px; font-size: 12px; color: var(--live); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.node-open { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 0; margin-top: 4px; text-decoration: underline; text-underline-offset: 3px; }
.lineage-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--line-2); }
.lineage-legend span::before { content: "●"; margin-inline-end: 4px; }
.lg-run::before { color: var(--live); } .lg-done::before { color: var(--line-2); } .lg-fail::before { color: var(--bad); }

/* screen (live tool viewer) */
.screen { display: flex; flex-direction: column; gap: 10px; block-size: 100%; }
.screen-bar { display: flex; align-items: center; gap: 8px; }
.screen-status { flex: 1; font-size: 13px; color: var(--ink-2); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-btn[aria-pressed="true"] { border-color: var(--live); color: var(--live); }
.screen-window { flex: 1; min-block-size: 280px; border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; }
.screen-empty { margin: auto; padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }
.win-bar { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); font-size: 12px; color: var(--muted); }
.win-bar b { color: var(--ink); font-weight: 500; }
.win-dots { display: flex; gap: 5px; direction: ltr; }
.win-dots i { inline-size: 9px; block-size: 9px; border-radius: 50%; background: var(--line-2); }
.win-body { flex: 1; overflow: auto; }
.term { background: var(--term-bg); color: var(--term-ink); font: 12.5px/1.6 var(--f-mono); padding: 12px 14px; direction: ltr; text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; min-block-size: 100%; margin: 0; }
.term .prompt { color: #7FD4C4; }
.term .err { color: #F2A097; }
.doc { padding: 12px 14px; font-size: 13px; }
.doc .path { font: 12px var(--f-mono); color: var(--muted); direction: ltr; text-align: left; margin-bottom: 8px; overflow-wrap: anywhere; }
.doc pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.6 var(--f-mono); direction: ltr; text-align: left; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-family: var(--f-mono); overflow-wrap: anywhere; direction: ltr; text-align: left; }
.scrubber { display: flex; align-items: center; gap: 10px; }
.scrubber input { flex: 1; accent-color: var(--live); }
.scrub-label { font: 12px var(--f-mono); color: var(--muted); min-inline-size: 56px; text-align: end; }

/* plan */
.plan { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.plan li { display: flex; gap: 10px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; font-size: 14px; }
.plan li::before { content: ""; flex: none; margin-top: 5px; inline-size: 14px; block-size: 14px; border-radius: 50%; border: 2px solid var(--line-2); }
.plan li[data-status="in_progress"]::before { border-color: var(--live); border-top-color: transparent; animation: spin 1s linear infinite; }
.plan li[data-status="completed"] { color: var(--muted); }
.plan li[data-status="completed"]::before { border-color: var(--live); background: var(--live); box-shadow: inset 0 0 0 2px var(--surface); }
.plan li[data-status="cancelled"] { text-decoration: line-through; color: var(--muted); }
.plan .plan-empty { color: var(--muted); border-style: dashed; }
.plan .plan-empty::before { display: none; }

/* ── Agents page ─────────────────────────────────────────────────── */
.agents-view { grid-area: agents; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.agents-body { flex: 1; overflow-y: auto; padding: 24px; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 24px; align-content: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; }
.card h2 { margin: 0 0 4px; font: 600 16px var(--f-display); }
.card .sub { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.roster { display: flex; flex-direction: column; gap: 8px; }
.roster-item { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; align-items: center; padding: 10px 12px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); }
.roster-item .ri-ico { grid-row: span 2; inline-size: 32px; block-size: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--live-soft); color: var(--live); font: 600 14px var(--f-display); }
.roster-item.core .ri-ico { background: var(--ink); color: var(--bg); }
.ri-name { font: 600 14px var(--f-mono); direction: ltr; text-align: start; unicode-bidi: plaintext; }
.ri-desc { grid-column: 2; font-size: 12px; color: var(--muted); }
.ri-use { grid-row: span 2; font: 12px var(--f-mono); color: var(--muted); text-align: end; }
.stack { display: flex; flex-direction: column; gap: 24px; }

/* ── Overlays / toast ────────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(10,12,12,.4); z-index: 30; }
.toast { position: fixed; inset-inline-start: 50%; inset-block-end: 24px; transform: translateX(50%); background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; z-index: 60; box-shadow: var(--shadow); animation: rise .2s ease-out; }
.only-mobile { display: none; }

/* ── Motion ──────────────────────────────────────────────────────── */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes relay { to { background-position: 0 12px; } }
@keyframes rise { from { opacity: 0; transform: translate(50%, 8px); } }
.fade-in { animation: fadein .25s ease-out both; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  :root { --panel-w: 340px; --sidebar-w: 240px; }
}
@media (max-width: 960px) {
  .app, .app.panel-closed, .app[data-view="agents"] { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main"; }
  .app[data-view="agents"] { grid-template-areas: "agents"; }
  .only-mobile { display: inline-grid; place-items: center; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; inline-size: min(84vw, 320px); z-index: 40; background: var(--bg); transform: translateX(100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .app.sidebar-open .sidebar { transform: none; }
  .panel { position: fixed; inset-inline: 0; inset-block-end: 0; block-size: 78dvh; z-index: 40; border-radius: 18px 18px 0 0; border: 1px solid var(--line); box-shadow: var(--shadow); transform: translateY(100%); transition: transform .2s ease; display: flex !important; }
  .app.panel-open .panel { transform: none; }
  .app[data-view="agents"] .panel { display: none !important; }
  .agents-body { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .thread { padding: 20px 16px 12px; }
  .composer { padding: 8px 12px 14px; }
  .topbar { padding: 10px 12px; }
  .hint { display: none; }
}
@media (max-width: 960px) and (prefers-reduced-motion: no-preference) {
  .sidebar, .panel { will-change: transform; }
}

.mt { margin-top: 12px; }
.ri-strong { grid-column: 2; color: var(--ink); font-weight: 500; }

/* ── Forced theme / text size (settings) ─────────────────────────── */
:root[data-theme="dark"] {
  --bg: #121514; --surface: #1A1E1D; --surface-2: #161A19;
  --ink: #ECEFED; --ink-2: #C7CDCA; --muted: #8E9692;
  --line: #2A302E; --line-2: #37403D;
  --live: #3FB5A3; --live-soft: #173330;
  --warn: #E0A64B; --warn-soft: #33281A;
  --bad: #EB7B70; --bad-soft: #3A1F1C;
  --term-bg: #0C0E0E; --term-ink: #D9E2DF;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.6);
  color-scheme: dark;
}
:root[data-theme="dark"] .brand-mark { background: #0C0E0E; box-shadow: inset 0 0 0 1px var(--line-2); }
:root[data-size="sm"] body { font-size: 14px; }
:root[data-size="lg"] body { font-size: 16.5px; }

/* ── Settings page ───────────────────────────────────────────────── */
.app[data-view="settings"] { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); grid-template-areas: "side settings"; }
.app[data-view="settings"] .main, .app[data-view="settings"] .panel, .app[data-view="settings"] .agents-view { display: none; }
.app[data-view="agents"] .settings-view { display: none; }
.settings-view { grid-area: settings; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.settings-body { flex: 1; overflow-y: auto; padding: 24px; }
.settings-grid { max-inline-size: 980px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.set-section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.set-head { padding: 14px 18px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.set-head h2 { margin: 0; font: 600 16px var(--f-display); }
.set-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.set-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 320px); gap: 8px 24px; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-label { font-weight: 500; }
.set-help { font-size: 13px; color: var(--muted); margin-top: 2px; }
.set-control { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.set-control select, .set-control input[type="number"] {
  inline-size: 100%; border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--r-sm);
  padding: 7px 10px; font-size: 14px;
}
.set-status { font-size: 12px; color: var(--muted); min-inline-size: 42px; text-align: end; }
.set-status.ok { color: var(--live); }
.set-status.err { color: var(--bad); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 500; }
.switch { position: relative; inline-size: 42px; block-size: 24px; border-radius: 999px; border: 0; background: var(--line-2); flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; inset-block-start: 3px; inset-inline-start: 3px; inline-size: 18px; block-size: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch[aria-checked="true"] { background: var(--live); }
.switch[aria-checked="true"]::after { transform: translateX(-18px); }
.switch:disabled { opacity: .5; cursor: default; }
.locked-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; padding: 14px 18px; }
.locked { border: 1px dashed var(--line-2); border-radius: var(--r); padding: 10px 12px; }
.locked b { display: block; font-weight: 500; font-size: 14px; }
.locked span { font: 12px var(--f-mono); color: var(--muted); overflow-wrap: anywhere; }
.locked::before { content: "🔒"; float: inline-end; font-size: 12px; opacity: .6; }

/* image model cards */
.img-models { padding: 14px 18px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.img-model { position: relative; text-align: start; border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.img-model:hover { border-color: var(--line-2); }
.img-model[aria-pressed="true"] { border-color: var(--live); background: var(--live-soft); box-shadow: 0 0 0 1px var(--live) inset; }
.img-model[aria-pressed="true"]::after { content: "✓ مختار"; position: absolute; inset-block-start: 10px; inset-inline-end: 12px; font-size: 11px; color: var(--live); font-weight: 600; }
.im-vendor { font: 600 11px var(--f-mono); letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.im-name { font: 600 14px var(--f-display); padding-inline-end: 52px; }
.im-id { font: 11px var(--f-mono); color: var(--muted); direction: ltr; text-align: start; unicode-bidi: plaintext; }
.im-price { display: flex; align-items: baseline; gap: 6px; margin-top: 4px; }
.im-price strong { font: 600 20px var(--f-mono); letter-spacing: -.02em; }
.im-price span { font-size: 12px; color: var(--muted); }
.im-note { font-size: 12px; color: var(--muted); }
.im-tag { display: inline-block; font-size: 11px; border-radius: 999px; padding: 0 8px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); margin-inline-end: 4px; }
.im-tag.good { color: var(--live); border-color: transparent; background: var(--live-soft); }
.img-filter { display: flex; gap: 8px; align-items: center; padding: 12px 18px 0; flex-wrap: wrap; }
.set-note { padding: 10px 18px 14px; font-size: 12px; color: var(--muted); }
.set-links { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 18px; }
.set-links a { text-decoration: none; color: var(--ink); }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; padding: 14px 18px 0; }
.kpi { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; background: var(--surface-2); }
.kpi b { display: block; font: 600 20px var(--f-mono); }
.kpi span { font-size: 12px; color: var(--muted); }

/* generated images in the thread / screen */
.gen-image { display: flex; flex-direction: column; gap: 6px; max-inline-size: 420px; }
.gen-image img { inline-size: 100%; block-size: auto; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); }
.gen-image figcaption { display: flex; gap: 10px; font: 12px var(--f-mono); color: var(--muted); flex-wrap: wrap; }
.gen-image a { color: var(--live); }
.screen-img { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.screen-img img { max-inline-size: 100%; border-radius: var(--r-sm); border: 1px solid var(--line); }

@media (max-width: 960px) {
  .app[data-view="settings"] { grid-template-columns: minmax(0, 1fr); grid-template-areas: "settings"; }
  .set-row { grid-template-columns: minmax(0, 1fr); }
  .set-control { justify-content: flex-start; }
  .settings-body { padding: 14px; }
}
