:root {
  --bg: #ffffff;
  --panel: #f6f7f9;
  --panel-2: #eceef2;
  --sidebar: #f1f3f6;
  --text: #1a1c20;
  --muted: #6b7280;
  --faint: #9aa2b1;
  --border: #dfe2e8;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.12);
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --flag: #d9730d;
  --user-bubble: #4f46e5;
  --assistant-bubble: #f0f1f4;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116;
    --panel: #171a21;
    --panel-2: #1e222c;
    --sidebar: #12141a;
    --text: #e7e9ee;
    --muted: #9aa2b1;
    --faint: #6b7280;
    --border: #262b36;
    --accent: #7c83ff;
    --accent-soft: rgba(124, 131, 255, 0.16);
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --flag: #f5a623;
    --user-bubble: #4f46e5;
    --assistant-bubble: #1e222c;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  height: 100dvh;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
a { color: var(--accent); }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; padding: 20px; }
.login-card { width: min(360px, 92vw); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 26px; display: flex; flex-direction: column; gap: 12px; }
.login-brand { font-size: 22px; font-weight: 800; }
.login-sub { margin: 0; color: var(--muted); font-size: 13px; }
.login-card input { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 11px 13px; }
.login-card button { background: var(--accent); color: #fff; border: none; border-radius: 10px; padding: 11px; font-weight: 700; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.ms-btn { display: flex; align-items: center; justify-content: center; gap: 10px; background: #fff; color: #1a1a1a; border: 1px solid #d0d3d9; border-radius: 10px; padding: 11px; font-weight: 600; text-decoration: none; }
.ms-btn:hover { background: #f3f4f6; }
.linkbtn { background: none !important; border: none !important; color: var(--muted) !important; font-weight: 500 !important; font-size: 13px; padding: 2px !important; text-decoration: underline; }
.login-err { color: var(--danger); font-size: 13px; min-height: 16px; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100dvh; }
.nav-toggle { display: none; position: fixed; top: 10px; left: 10px; z-index: 30; background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 9px; width: 38px; height: 38px; font-size: 18px; }

.sidebar { background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; gap: 6px; }
.side-brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; padding: 6px 8px 14px; }
.side-brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--accent-soft); }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item { display: flex; align-items: center; gap: 11px; background: transparent; border: none; color: var(--muted); border-radius: 10px; padding: 10px 11px; text-align: left; font-weight: 600; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; stroke-linecap: round; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.host-line { color: var(--faint); font-size: 11.5px; font-family: var(--mono); word-break: break-all; }
.logout { background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); border-radius: 9px; padding: 7px; font-size: 12.5px; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.main-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.main-head h1 { margin: 0; font-size: 17px; font-weight: 700; }
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
.usage-chip { margin-left: auto; margin-right: auto; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; white-space: nowrap; }
.view { flex: 1; overflow-y: auto; min-height: 0; }
/* Chat header: on desktop the primary/detail wrappers are transparent so their
   controls flow straight into the header flexbox; the ⋯ options toggle is a
   phone-only affordance (see the mobile block below). */
.head-primary, .head-detail { display: contents; }
.opts-toggle { display: none; }

/* ---------- Generic bits ---------- */
.btn { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 7px 12px; font-size: 13px; font-weight: 600; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }
.sel { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.sel select { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 13px; max-width: 44vw; }
.sel .modelinput { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 13px; min-width: 210px; max-width: 46vw; font-family: var(--mono); }
.sel .modelinput:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.sel .modelpick { max-width: 170px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.chip.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.sdot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; }
.sdot.ok { background: var(--ok); } .sdot.bad { background: var(--danger); } .sdot.warn { background: var(--warn); }
.muted { color: var(--muted); } .empty { color: var(--muted); text-align: center; padding: 40px; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: row; height: 100%; min-height: 0; position: relative; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.convos { flex: 0 0 300px; width: 300px; border-right: 1px solid var(--border); background: var(--sidebar); display: flex; flex-direction: column; gap: 10px; padding: 12px; overflow-y: auto; }
.convos .newconv { width: 100%; }
.convlist { display: flex; flex-direction: column; gap: 2px; }
.conv-item { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.conv-item:hover { background: var(--panel-2); color: var(--text); }
.conv-item.active { background: var(--accent-soft); color: var(--accent); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conv-del { background: transparent; border: none; color: var(--faint); font-size: 12px; padding: 2px 4px; opacity: 0; }
.conv-item:hover .conv-del { opacity: 1; }
/* Per-chat flag toggle in the list: hidden until hover, but always shown (in gold) once set. */
.conv-flag { background: transparent; border: none; color: var(--faint); font-size: 13px; line-height: 1; padding: 2px 3px; cursor: pointer; opacity: 0; }
.conv-item:hover .conv-flag { opacity: 0.7; }
.conv-flag.on, .conv-item:hover .conv-flag.on { opacity: 1; color: var(--flag); }
.conv-empty { color: var(--faint); font-size: 12.5px; padding: 8px 10px; }
/* "Flagged only" filter (chat list + Sessions board). */
.flagonly { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); cursor: pointer; user-select: none; }
.flagonly input { accent-color: var(--flag); }
/* Custom per-chat header input in the chat top bar. */
.chat-header { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; min-width: 150px; max-width: 30vw; }
.chat-header:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
/* Flag toggle button (chat bar + Sessions rows). */
.flag-btn { color: var(--faint); }
.flag-btn.on { color: var(--flag); border-color: color-mix(in srgb, var(--flag) 45%, transparent); }
.flag-btn.small { padding: 3px 8px; margin-left: 6px; }
/* Session-mode toggle (⟳ Orchestrator / 💬 Conversational) in the chat bar.
   Accent-lit when orchestrator (the default, running-mode); muted otherwise. */
.mode-btn { color: var(--muted); white-space: nowrap; }
.mode-btn.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.mode-btn:disabled { opacity: 0.65; cursor: default; }
/* Per-chat orchestrator glyph in the conversation list. */
.conv-mode { color: var(--accent); font-size: 12px; line-height: 1; flex: 0 0 auto; }
.chats-toggle { display: none; }
@media (max-width: 760px) {
  .chats-toggle { display: inline-block; }
  .convos { position: absolute; z-index: 20; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform 0.2s; box-shadow: 0 0 30px rgba(0,0,0,0.35); }
  .convos.open { transform: none; }
}
.thread { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { width: 100%; max-width: 1040px; margin: 0 auto; display: flex; }
.msg.user { justify-content: flex-end; }
.msg.assistant { flex-direction: column; align-items: flex-start; gap: 4px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--assistant-bubble); border-bottom-left-radius: 4px; }
.msg.error .bubble { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.msg-time { color: var(--faint); font-size: 11px; font-family: var(--mono); }
.msg.user { flex-wrap: wrap; }
.msg.user .msg-time { flex-basis: 100%; text-align: right; margin-top: 3px; }
/* Chained assistant messages: one turn's per-segment texts (history view) stack
   tightly with connected corners, so the chain reads as a sequence, not a blob. */
.msg.chained { gap: 3px; }
.msg.chained .bubble + .bubble { border-top-left-radius: 4px; }
.msg.chained .bubble:not(:last-of-type) { border-bottom-left-radius: 4px; }
.msg.chained .msg-time { margin-top: 3px; }
.chat-empty { margin: auto; color: var(--muted); text-align: center; max-width: 440px; padding: 20px; }
.composer { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.composer-bar { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 40vh; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 11px 14px; font: inherit; }
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.att-btn { align-self: flex-end; padding: 9px 11px; font-size: 15px; line-height: 1; }
.att-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.att-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 12px; max-width: 100%; }
.att-chip.image { border-color: var(--accent); }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.att-x { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 11px; padding: 0 2px; }
.att-x:hover { color: var(--accent); }
.att-hint { font-size: 12px; color: var(--muted); }
.queued-bar { display: flex; flex-direction: column; gap: 4px; }
.queued-chip { display: inline-flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px dashed var(--border); border-radius: 8px; padding: 5px 8px 5px 10px; font-size: 12px; }
.queued-tag { color: var(--muted); white-space: nowrap; }
.queued-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.queued-x { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 0 2px; }
.queued-x:hover { color: var(--accent); }

/* ---------- Status ---------- */
.pad { padding: 20px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 22px; font-weight: 800; margin-top: 4px; }
.tile .v small { font-size: 13px; font-weight: 600; color: var(--muted); }
.bars { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
@media (max-width: 640px) { .bars { grid-template-columns: 1fr; } }
.meter { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.meter .row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.track { height: 10px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.track > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.4s; }
.track > span.warn { background: var(--warn); } .track > span.bad { background: var(--danger); }
.svc { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }
.svc h2, .files h2, .projects h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); margin: 0 0 6px; }
.svc-row { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 11px 14px; }
.svc-row .nm { font-weight: 700; } .svc-row .meta { margin-left: auto; color: var(--muted); font-size: 12.5px; font-family: var(--mono); }

/* ---------- Projects ---------- */
.projects { padding: 20px; }
.sechead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.sechead h2 { margin: 0; }
.sechead-acts { display: flex; align-items: center; gap: 8px; flex: none; }
.pcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.pcard { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 15px; display: flex; flex-direction: column; gap: 10px; }
.pcard .top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pcard .nm { font-weight: 800; font-size: 15px; }
.pcard .cmt { font-family: var(--mono); font-size: 11.5px; color: var(--muted); word-break: break-word; }
.pcard .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.pcard .acts .btn { padding: 6px 10px; font-size: 12px; }

.files { margin-top: 26px; }
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-family: var(--mono); font-size: 12.5px; margin-bottom: 10px; }
.crumbs a { cursor: pointer; text-decoration: none; }
.crumbs .sep { color: var(--faint); }
.filelist { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.frow { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.frow:first-child { border-top: none; }
.frow:hover { background: var(--panel-2); }
.frow .fico { width: 16px; text-align: center; opacity: 0.8; }
.frow .fnm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frow .fsz { color: var(--faint); font-size: 12px; font-family: var(--mono); }
.frow .fsel { flex: none; width: 15px; height: 15px; margin: 0; cursor: pointer; accent-color: var(--danger); }
.frow .fsel-sp { flex: none; width: 15px; }
.frow .fico, .frow .fnm, .frow .fsz { cursor: pointer; }

/* ---------- Home launcher ---------- */
.applauncher { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 14px; }
.appcard { position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 22px 16px; text-align: center; cursor: pointer; transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s; }
.appcard:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.12); }
.appicon { font-size: 42px; line-height: 1; margin-bottom: 10px; }
.appname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appdesc { font-size: 12px; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.app-edit { position: absolute; top: 8px; right: 8px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); border-radius: 7px; width: 26px; height: 26px; opacity: 0; transition: opacity 0.15s; }
.appcard:hover .app-edit { opacity: 1; }

/* ---------- Mobile tab (one APK per app) ---------- */
.apklist { display: flex; flex-direction: column; gap: 12px; max-width: 640px; }
.apkcard { display: flex; align-items: center; gap: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 18px 20px; }
.apkcard .appicon { font-size: 36px; margin-bottom: 0; width: 44px; height: 44px; display: grid; place-items: center; flex-shrink: 0; }
.apkcard .appicon img { width: 44px; height: 44px; border-radius: 10px; }
.apkcard .apkmeta { flex: 1; min-width: 0; }
.apkcard .btn { flex-shrink: 0; text-decoration: none; display: inline-block; }
.apk-none { color: var(--faint); font-size: 13px; flex-shrink: 0; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal { width: min(440px, 94vw); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-weight: 700; }
.modal-head .x { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; width: 30px; height: 30px; }
.modal-body { padding: 16px; }
.modal-body .fld { max-width: none; }

/* ---------- Tabbed settings ---------- */
.settings { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.tabbar { display: flex; gap: 4px; padding: 10px 16px 0; border-bottom: 1px solid var(--border); overflow-x: auto; flex: 0 0 auto; }
.tab { background: transparent; border: 1px solid transparent; border-bottom: none; color: var(--muted); border-radius: 10px 10px 0 0; padding: 8px 14px; font-weight: 600; font-size: 13px; white-space: nowrap; margin-bottom: -1px; }
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: var(--text); background: var(--panel); border-color: var(--border); border-bottom-color: var(--panel); }
.tab-add { color: var(--accent); }
.settings .pad { flex: 1; overflow-y: auto; min-height: 0; }

.kvlist { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; max-width: 560px; }
.kvrow { display: flex; gap: 8px; }
.kv-key, .kv-val { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 8px 10px; font: inherit; }
.kv-key { flex: 0 0 40%; font-family: var(--mono); font-size: 13px; }
.kv-val { flex: 1; }
.kv-del { flex: 0 0 auto; padding: 8px 11px; }
.kv-eye, .kv-lock, .kv-copy { flex: 0 0 auto; padding: 8px 10px; opacity: .7; }
.kv-eye:hover, .kv-lock:hover, .kv-copy:hover { opacity: 1; }
.kv-lock.on { opacity: 1; border-color: var(--accent, #7c5cff); }
.kv-copy.copied { opacity: 1; border-color: var(--accent, #7c5cff); }
.kv-add { margin-bottom: 12px; }

/* Inline field + copy button (Hub settings secrets/env vars) */
.fld-inrow { display: flex; gap: 8px; align-items: stretch; }
.fld-inrow input { flex: 1; }
.copybtn { flex: 0 0 auto; padding: 8px 12px; opacity: .7; }
.copybtn:hover { opacity: 1; }
.copybtn.copied { opacity: 1; border-color: var(--accent, #7c5cff); }

/* ---------- Settings ---------- */
.seth { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); margin: 20px 0 12px; }
.seth:first-child { margin-top: 0; }
.fld { display: flex; flex-direction: column; gap: 5px; max-width: 540px; margin-bottom: 15px; }
.flabel { font-size: 13px; font-weight: 600; }
.fld input { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 9px 11px; font: inherit; }
.fld input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.psel { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 9px 11px; font: inherit; }
.psel:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.posture { margin: 4px 0 14px; padding: 11px 13px; border: 1px solid var(--border); border-radius: 11px; background: var(--panel-2); }
.posture .phead { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.posture ul { margin: 0 0 7px; padding-left: 18px; }
.posture li { font-size: 12.5px; color: var(--muted); margin: 3px 0; }
.posture.posture-off { border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 8%, var(--panel-2)); }
.posture.posture-off .phead { color: var(--warn); }
.fld.row { flex-direction: row; align-items: center; gap: 9px; cursor: pointer; }
.fld.row input[type="checkbox"] { flex: none; width: 16px; height: 16px; padding: 0; accent-color: var(--accent); }
.fhint { font-size: 12px; color: var(--muted); }
.setstatus { margin-bottom: 16px; }
.setactions { display: flex; align-items: center; gap: 14px; margin-top: 6px; }
.setmsg { font-size: 13px; }
.setmsg.ok { color: var(--ok); }
.setmsg.err { color: var(--danger); }

/* ---------- Console / drawer ---------- */
.drawer { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: none; align-items: flex-end; z-index: 40; }
.drawer.open { display: flex; }
.drawer-inner { background: var(--panel); border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; width: 100%; max-height: 80vh; display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.drawer-head .t { font-weight: 700; font-family: var(--mono); font-size: 13px; }
.drawer-head .x { margin-left: auto; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; width: 30px; height: 30px; }
.console { flex: 1; overflow: auto; margin: 0; padding: 14px 16px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; color: var(--text); background: var(--bg); }
.console .err { color: var(--danger); }
.console .dim { color: var(--muted); }
.spin { width: 15px; height: 15px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .nav-toggle { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 232px; z-index: 25; transform: translateX(-100%); transition: transform 0.2s; box-shadow: 0 0 40px rgba(0,0,0,0.35); }
  .sidebar.open { transform: none; }
  .main-head { padding: 10px 12px 10px 56px; gap: 8px; }
  .main-head h1 { font-size: 16px; }

  /* Chat, on a phone: a single compact control row (Chats · title · ⋯ · New)
     with everything else tucked behind the ⋯ toggle, so the thread + composer
     get the screen. The "Chat" title is dropped here — the native/app bar and
     the ⚙ hamburger already say where you are. */
  body[data-view="chat"] .main-head h1 { display: none; }
  .head-actions { flex-direction: column; align-items: stretch; gap: 8px; }
  .head-primary { display: flex; align-items: center; gap: 8px; width: 100%; }
  .head-primary .chats-toggle,
  .head-primary .opts-toggle { flex: none; }
  .head-primary .chat-header { flex: 1; min-width: 0; max-width: none; }
  .opts-toggle { display: inline-block; }
  .head-detail { display: none; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%;
    padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
  .head-actions.opts-open .head-detail { display: flex; }
  /* Selectors become full-width rows in the options panel so they're tappable. */
  .head-detail .sel { display: flex; width: 100%; align-items: center; gap: 8px; }
  .head-detail .sel > select,
  .head-detail .sel .modelinput { flex: 1; min-width: 0; max-width: none; }
  .head-detail .sel .modelpick { flex: 0 0 auto; max-width: 42%; }
  .head-detail .mode-btn,
  .head-detail .changes-btn,
  .head-detail .flag-btn { flex: 1 1 auto; }
  .head-detail .usage-chip { width: 100%; text-align: center; }

  /* Composer: give the textarea its own full-width row; the buttons sit beneath,
     Send pushed to the right, all comfortably tap-sized. */
  .composer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .composer-bar { flex-wrap: wrap; }
  .composer textarea { flex: 1 1 100%; }
  .composer-bar .att-btn { order: 1; margin-right: auto; }
  .composer-bar .btn.danger { order: 2; }
  .composer-bar .btn.primary { order: 3; }
  .composer-bar .btn { min-height: 42px; }
  .thread { padding: 14px 12px; }
  .bubble { max-width: 90%; }
}

/* ---- Agent mode: project selector + tool steps ---- */
.projsel { max-width: 180px; }
.toolstep {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  font: 12px/1.5 var(--mono);
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  max-width: 100%;
}
.toolstep .ts-label { min-width: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolstep .ts-badge { flex: none; color: var(--faint); font-size: 11px; }
.toolstep.expandable { cursor: pointer; }
.toolstep.expandable:hover .ts-badge { color: var(--accent); }
.substeps { display: none; flex-basis: 100%; flex-direction: column; gap: 2px; margin: 2px 0 4px; padding-left: 10px; border-left: 2px solid var(--border); }
.toolstep.open .substeps { display: flex; }
.substep { font: 11.5px/1.5 var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.substep::before { content: "· "; color: var(--faint); }
.substep[data-status="running"], .substep[data-status="pending"] { color: var(--text); }
.substep[data-status="running"]::before, .substep[data-status="pending"]::before { content: "▸ "; color: var(--accent); }
.substep[data-status="completed"]::before { content: "✓ "; color: var(--ok); }
.substep[data-status="error"]::before { content: "✕ "; color: var(--danger); }
.toolstep[data-status="running"], .toolstep[data-status="pending"] { border-color: var(--accent); color: var(--text); }
.toolstep[data-status="error"] { border-color: var(--danger); color: var(--danger); }

/* ---- Agent mode: permission asks + diff modal ---- */
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.permask { margin: 4px 0; padding: 8px 10px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent-soft); }
.permask[data-done] { border-color: var(--border); background: var(--panel-2); opacity: 0.8; }
.permask-t { font-size: 13px; margin-bottom: 6px; word-break: break-word; }
.permask-btns { display: flex; gap: 6px; }
.modal.wide { width: min(920px, 96vw); max-height: 88vh; display: flex; flex-direction: column; }
.modal.wide .modal-body { overflow: auto; flex: 1; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.modal-foot:empty { display: none; }
.diff-file { font: 12px/1.6 var(--mono); font-weight: 700; margin: 12px 0 4px; }
pre.diff { margin: 0 0 8px; padding: 8px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; font: 12px/1.5 var(--mono); }
.dl { display: block; white-space: pre; }
.dl.add { background: rgba(22,163,74,0.14); }
.dl.del { background: rgba(220,38,38,0.14); }
.dl.hunk { color: var(--muted); }

/* ---- Turn status (thinking word + timer) ---- */
.turnstatus { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); padding: 2px 2px 0; }
.turnstatus .ts-word { font-weight: 600; }
.turnstatus.working .ts-word {
  background: linear-gradient(90deg, var(--muted) 25%, var(--text) 50%, var(--muted) 75%);
  background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 2s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.turnstatus .ts-time { color: var(--faint); font-family: var(--mono); font-size: 11.5px; }
.turnstatus .ts-ico { font-weight: 700; }
.turnstatus.done { color: var(--faint); }
.turnstatus.done .ts-ico { color: var(--ok); }
.turnstatus.error .ts-ico { color: var(--danger); }
.turnstatus.stop .ts-ico { color: var(--warn); }
.spin.small { width: 12px; height: 12px; border-width: 2px; flex: none; }

/* ---- Conversation list: meta line, status badges, project filter ---- */
.convfilter { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 12.5px; width: 100%; }
.conv-item { align-items: flex-start; }
.conv-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.conv-meta { font-size: 11px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item.active .conv-meta { color: color-mix(in srgb, var(--accent) 70%, transparent); }
.conv-stat { flex: none; margin-top: 5px; font-size: 11px; line-height: 1; font-weight: 800; }
.conv-stat.working { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.conv-stat.done { color: var(--ok); }
.conv-stat.error { color: var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.conv-del { flex: none; }

/* ---- Sessions board ---- */
.ss-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.ss-search { flex: 1; min-width: 180px; max-width: 340px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 13px; }
.ss-search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.ss-ctx { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 7px 8px; font-size: 12.5px; }
.ss-count { color: var(--faint); font-size: 12.5px; margin-left: auto; }
.ss-scroll { overflow-x: auto; }
.ss-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ss-table th { text-align: left; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ss-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--muted); white-space: nowrap; vertical-align: middle; }
.ss-table tr.live td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.ss-title { color: var(--text); font-weight: 600; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.ss-sub { color: var(--faint); font-family: var(--mono); font-size: 11px; }
.ss-model { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.ss-pill { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--faint); }
.ss-pill.live { color: var(--accent); border-color: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.ss-pill.stopped { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.ss-pill.interrupted { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.ss-pill.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.ss-actions { text-align: right; }
.ss-actions .btn { margin-left: 6px; }

/* ---- Grouped tool output ---- */
.msg.assistant .toolgroup, .msg.assistant .permask { max-width: 85%; }
.bubble.errb { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.toolgroup { border: 1px solid var(--border); border-radius: 10px; background: var(--panel); overflow: hidden; min-width: 260px; }
.tg-head { display: flex; align-items: center; gap: 8px; width: 100%; background: transparent; border: none; color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 7px 11px; text-align: left; }
.tg-head:hover { color: var(--text); }
.tg-head .chev { margin-left: auto; transition: transform 0.15s; color: var(--faint); }
.toolgroup.open .chev { transform: rotate(90deg); }
.tg-body { display: none; flex-direction: column; gap: 3px; padding: 0 9px 8px; }
.toolgroup.open .tg-body { display: flex; }
.toolstep::before { content: "· "; color: var(--faint); }
.toolstep[data-status="running"]::before, .toolstep[data-status="pending"]::before { content: "▸ "; color: var(--accent); }
.toolstep[data-status="completed"]::before { content: "✓ "; color: var(--ok); }
.toolstep[data-status="error"]::before { content: "✕ "; }

/* ---- Agent questions ---- */
.qask { max-width: 85%; }
.qask-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.qask-q { font-size: 13.5px; font-weight: 600; }
.qask-opts { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; margin-bottom: 8px; }
.qask .qopt { text-align: left; }
.qask .qopt.sel { background: var(--accent); border-color: var(--accent); color: #fff; }
.qopt-d { font-size: 11.5px; color: var(--muted); margin: -1px 0 5px 2px; max-width: 520px; }
.qask-custom { width: 100%; max-width: 420px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 7px 10px; font: inherit; margin-bottom: 8px; }
.qask[data-done] .permask-t { margin: 0; }

/* ---- Markdown in assistant bubbles ---- */
.bubble.md { white-space: normal; }
.msg.assistant .bubble.md:empty { display: none; }
.bubble.md p { margin: 0 0 8px; }
.bubble.md > *:last-child { margin-bottom: 0; }
.bubble.md .md-h { font-weight: 700; margin: 10px 0 6px; }
.bubble.md .md-h:first-child { margin-top: 0; }
.bubble.md .md-h1 { font-size: 16.5px; }
.bubble.md .md-h2 { font-size: 15.5px; }
.bubble.md .md-h3 { font-size: 14.5px; }
.bubble.md ul, .bubble.md ol { margin: 0 0 8px; padding-left: 22px; }
.bubble.md li { margin: 2px 0; }
.bubble.md code { background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font: 12.5px var(--mono); }
.bubble.md blockquote { margin: 0 0 8px; padding: 2px 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.bubble.md hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.bubble.md a { color: var(--accent); }
.codewrap { margin: 8px 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg); }
.codebar { display: flex; justify-content: space-between; align-items: center; padding: 4px 10px; background: var(--panel-2); border-bottom: 1px solid var(--border); }
.codelang { font: 11px var(--mono); color: var(--faint); }
.codecopy { background: none; border: none; color: var(--muted); font-size: 11px; font-weight: 600; padding: 2px 4px; }
.codecopy:hover { color: var(--accent); }
pre.codeblock { margin: 0; padding: 10px 12px; overflow-x: auto; font: 12.5px/1.5 var(--mono); }
pre.codeblock code { background: none; border: none; padding: 0; font: inherit; }

/* Terminal — chat-style command runner */
.view.shell-view { overflow: hidden; }
.shell { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.shell-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.sh-msg { display: flex; flex-direction: column; max-width: min(900px, 92%); }
.sh-cmd { align-self: flex-end; align-items: flex-end; }
.sh-out { align-self: flex-start; }
.sh-body { margin: 0; padding: 10px 12px; border-radius: 12px; font: 12.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; overflow-x: auto; }
.sh-cmd .sh-body { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.sh-out .sh-body { background: var(--panel-2); color: var(--text); border-bottom-left-radius: 4px; min-width: 48px; }
.sh-meta { font-size: 11px; margin-top: 3px; color: var(--muted); font-family: var(--mono); }
.sh-meta.ok { color: var(--ok); }
.sh-meta.err { color: var(--danger); }
.sh-empty { color: var(--faint); }
.shell-composer { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.shell-cwd { width: 100%; font: 11.5px var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-input { flex: 1; resize: none; min-height: 42px; max-height: 220px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 10px 13px; font: 13px/1.5 var(--mono); }
.shell-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.shell-run { align-self: flex-end; height: 42px; }

/* ========================================================== */
/*  WIKI (OKF knowledge bundle)                               */
/* ========================================================== */
.wiki { display: flex; height: 100%; min-height: 0; }
.wiki-nav { width: 260px; flex: none; border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.wiki-search { margin: 12px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); color: var(--text); }
.wiki-list { overflow-y: auto; padding: 0 8px 12px; }
.wiki-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 8px 4px; }
.wiki-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.wiki-item:hover { background: var(--panel); }
.wiki-item.active { background: var(--accent-soft); }
.wiki-title { color: var(--text); font-size: 14px; }
.wiki-type { font-size: 10px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; white-space: nowrap; }
.wiki-main { flex: 1; min-width: 0; overflow-y: auto; padding: 18px 22px; }
.wiki-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.wiki-crumb { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.wiki-doc { max-width: 760px; line-height: 1.55; }
.wiki-rel { max-width: 760px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.wiki-rel-h { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 0 6px; }
.wiki-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.wiki-chip { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; }
.wiki-chip:hover { border-color: var(--accent); color: var(--accent); }
.wiki-graph { width: 100%; max-width: 820px; height: auto; display: block; margin: 0 auto; }
.wg-edge { stroke: var(--border); stroke-width: 1; }
.wg-node text.wg-label { font-size: 12px; fill: var(--text); }
.wg-node:hover text.wg-label { fill: var(--accent); }
.wg-node:hover circle { stroke: var(--accent); stroke-width: 2; }
@media (max-width: 720px) {
  .wiki-nav { width: 190px; }
}

/* Providers tab — per-provider cards: enable toggle + curated model list */
.prov { display: flex; flex-direction: column; gap: 14px; max-width: 880px; }
.pcard { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.pcard.off { opacity: 0.55; }
.phead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.phead h2 { margin: 0; font-size: 15px; font-weight: 700; }
.phead .spacer { flex: 1; }
.pswitch { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.pswitch input { accent-color: var(--accent); }
.pdesc { margin: 0; color: var(--muted); font-size: 12.5px; }
.pmodels-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); }
.mchips { display: flex; flex-wrap: wrap; gap: 6px; }
.mchip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-family: var(--mono); }
.mchip button { background: none; border: none; color: var(--faint); font-size: 12px; padding: 0 2px; cursor: pointer; }
.mchip button:hover:not(:disabled) { color: var(--danger); }
.mchip button:disabled { cursor: default; opacity: 0.4; }
.pcard > input[type="text"] { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 8px 10px; font-size: 13px; }
.mlist { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.mrow { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.mrow:last-child { border-bottom: none; }
.mrow .mname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow .mid { color: var(--faint); font-family: var(--mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40%; }
.msave { font-size: 12px; color: var(--ok); min-width: 60px; text-align: right; }
.linkchip { background: none; cursor: pointer; font: inherit; }
.linkchip:hover { border-color: var(--warn); }
