:root {
  --bg: #0e1116;
  --panel: #151a21;
  --panel-2: #1b222c;
  --panel-3: #232c38;
  --border: #28323f;
  --text: #e7edf3;
  --muted: #93a1b1;
  --faint: #6b7887;
  --accent: #4c8dff;
  --accent-2: #3b78e0;
  --danger: #ff6b6b;
  --ok: #4ec98a;
  --radius: 10px;
  --sidebar-w: 288px;
  --content-max: 900px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
a { color: var(--accent); }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 18px calc(24px + var(--safe-b)); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 26px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; min-height: 46px; padding: 12px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 16px;
}
.field input:focus { outline: none; border-color: var(--accent); }
button.primary {
  width: 100%; min-height: 46px; padding: 12px 14px; background: var(--accent); border: 0; border-radius: 10px;
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}
button.primary:hover { background: var(--accent-2); }
button.primary:disabled { opacity: .6; cursor: default; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---------- app shell (mobile-first) ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30;
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.overlay.show { opacity: 1; pointer-events: auto; }

/* sidebar: off-canvas drawer by default (mobile) */
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
  width: 68vw; max-width: 270px;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
  transform: translateX(-105%); transition: transform .2s ease;
  padding-top: var(--safe-t); padding-bottom: var(--safe-b);
}
.sidebar.open { transform: translateX(0); }

.sidebar-top { padding: 12px 12px 10px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
.navtab {
  flex: 1; min-height: 40px; border: 1px solid var(--border); background: transparent; color: var(--muted);
  border-radius: 9px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px;
}
.navtab.active { background: var(--panel-3); color: var(--text); border-color: transparent; }
.sidebar-actions { padding: 10px 12px; display: flex; gap: 8px; }
.btn-new {
  flex: 1; min-height: 42px; border: 0; border-radius: 9px; background: var(--accent); color: #fff;
  font-weight: 600; cursor: pointer;
}
.btn-new:hover { background: var(--accent-2); }
.sidebar-search { padding: 0 12px 8px; }
.search-row { display: flex; gap: 6px; align-items: stretch; }
.search-row input { flex: 1; min-width: 0; }
.search-row .iconbtn { flex: 0 0 auto; min-height: 42px; width: 42px; }
.sidebar-search input {
  width: 100%; min-height: 42px; padding: 10px 12px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 9px; color: var(--text); font-size: 16px;
}
.scope-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; margin-top: 8px; padding: 2px; border-radius: 8px; background: var(--panel-2); }
.scope-tabs button { min-height: 34px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.scope-tabs button.active { background: var(--panel-3); color: var(--text); }
.classifier-note { padding: 0 12px 7px; color: var(--faint); font-size: 11px; }
.session-list { list-style: none; margin: 0; padding: 2px 8px 10px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.session-group { padding: 7px 9px 3px; color: var(--faint); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.session-list li {
  padding: 5px 8px; border-radius: 7px; cursor: pointer; margin-bottom: 1px; min-height: 42px;
}
.session-list li:hover { background: var(--panel-2); }
.session-list li.active { background: var(--panel-3); }
.session-list li.active .row1 { color: var(--text); }
.row1 { display: flex; align-items: center; gap: 7px; min-height: 32px; }
.row1 .title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; color: var(--text); }
.row1 .row-time { flex: 0 0 auto; color: var(--faint); font-size: 10px; }
.row1 .row-action { min-width: 30px; min-height: 30px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--faint); cursor: pointer; }
.row1 .row-action:hover { color: var(--text); background: var(--panel-3); }
.row1 .dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; background: transparent; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
/* One colour language on both surfaces: the header light IS the open session's
   row light (yellow = running/background work, green = finished and unviewed,
   red = needs attention, no light = viewed). */
.row1 .dot.running, .status .dot.running { background: #f4c45e; box-shadow: 0 0 0 3px rgba(244,196,94,.16); animation: pulse 1.2s infinite; }
.row1 .dot.delegated-running, .status .dot.delegated-running { background: #f4c45e; box-shadow: 0 0 0 3px rgba(244,196,94,.16), 0 0 0 5px rgba(244,196,94,.08); animation: pulse 1.6s infinite; }
.row1 .dot.awaiting-handoff, .status .dot.awaiting-handoff { background: #f4c45e; box-shadow: 0 0 0 2px rgba(244,196,94,.14); }
.row1 .dot.attention-required, .status .dot.attention-required { background: var(--danger); box-shadow: 0 0 0 3px rgba(244,100,100,.16); }
.row1 .dot.finished-unchecked, .status .dot.finished-unchecked { background: var(--ok); box-shadow: 0 0 0 3px rgba(78,201,138,.18); }
.row1 .dot.checked, .status .dot.checked { background: transparent; }
.status .dot.bad { background: var(--danger); animation: none; }
.status .dot.bad, .status .dot.attention-required { box-shadow: 0 0 0 3px rgba(244,100,100,.16); }
.list-note { padding: 12px; color: var(--muted); font-size: 12px; text-align: center; }

.runtime-controls {
  flex: 0 0 auto; display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) auto;
  align-items: end; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.runtime-controls label { min-width: 0; color: var(--muted); font-size: 10px; }
.runtime-controls label span { display: block; margin: 0 0 3px 2px; }
.runtime-controls select, .runtime-controls button {
  width: 100%; min-width: 0; height: 36px; padding: 0 9px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel-2); color: var(--text); font-size: 12px;
}
.runtime-controls button { width: auto; cursor: pointer; }
.control-status { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }
.control-status:empty { display: none; }
.runtime-controls select:disabled, .runtime-controls button:disabled { opacity: .5; cursor: default; }
.context-usage { grid-column: 1 / -1; min-width: 0; padding: 1px 2px 0; }
.context-usage-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 10px; }
.context-usage-line strong { color: var(--text); font-size: 11px; font-weight: 600; white-space: nowrap; }
.context-meter { height: 4px; margin-top: 4px; overflow: hidden; border-radius: 2px; background: var(--border); }
.context-meter span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--ok); transition: width .2s ease, background .2s ease; }
.context-usage.warn .context-meter span { background: #f4c45e; }
.context-usage.danger .context-meter span { background: var(--danger); }
.task-tree-status { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; min-width: 0; padding: 3px 2px 0; }
.task-tree-status[hidden] { display: none; }
.task-tree-status > div { min-width: 0; }
.task-tree-status strong, .task-tree-status small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-tree-status strong { color: var(--text); font-size: 11px; font-weight: 600; }
.task-tree-status small { margin-top: 1px; color: var(--muted); font-size: 10px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* header */
.header {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; padding-top: calc(10px + var(--safe-t));
  border-bottom: 1px solid var(--border); background: var(--panel);
}
.header .hamburger {
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--text); font-size: 20px;
  border-radius: 9px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex: 0 0 44px;
}
.header .htitle { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
/* Thumb-reachable drawer toggle: pinned to the left edge, vertically centred.
   The header hamburger stays; this is an extra shortcut where the sidebar is
   off-canvas (mobile). */
.edge-toggle {
  position: fixed; left: 0; top: 50%; transform: translateY(-50%); z-index: 40;
  width: 26px; height: 64px; padding: 0; margin: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2); color: var(--muted); font-size: 14px;
  border: 1px solid var(--border); border-left: 0; border-radius: 0 10px 10px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.edge-toggle[hidden] { display: none; }
.edge-toggle:active { color: var(--text); background: var(--panel-3); }
.header .grow { flex: 1; min-width: 0; }
.status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.status.reconnecting .txt { color: #f4c45e; }
.live-run-strip { flex: 0 0 auto; min-height: 32px; display: flex; align-items: center; gap: 12px; padding: 5px 14px; border-bottom: 1px solid var(--border); background: var(--panel); }
.live-run-strip[hidden] { display: none; }
.run-counters { min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.live-sync-status { flex: 0 0 auto; color: #f4c45e; font-size: 11px; }
@keyframes pulse { 50% { opacity: .35; } }
.iconbtn {
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 16px;
  border-radius: 9px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.iconbtn:hover { background: var(--panel-2); color: var(--text); }
.iconbtn.active { color: #f4c45e; background: var(--panel-2); }
#hideBtn.active { color: var(--danger); }

.history-tools {
  min-height: 38px; padding: 5px 12px; border-bottom: 1px solid var(--border); background: var(--bg);
  display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px;
}
.history-tools .grow { flex: 1; }
.history-tools button, .history-tools select {
  min-height: 30px; border: 1px solid var(--border); border-radius: 7px; background: var(--panel-2); color: var(--text); padding: 3px 9px; cursor: pointer;
}
.history-tools button:disabled { opacity: .55; cursor: default; }

/* messages */
.messages {
  flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 2px; padding: 14px 12px 20px;
  scroll-behavior: auto;
}
.msgs-inner { width: 100%; max-width: var(--content-max); margin: 0 auto; display: flex; flex-direction: column; gap: 2px; }
.spacer { width: 100%; flex: 0 0 auto; }
.loadearlier { display: flex; justify-content: center; padding: 8px 0 14px; }
.loadearlier button {
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 16px; font-size: 12px; cursor: pointer; min-height: 36px;
}
.skeleton { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.skeleton .sk { height: 44px; border-radius: 10px; background: linear-gradient(90deg, var(--panel-2), var(--panel-3), var(--panel-2)); background-size: 200% 100%; animation: sk 1.2s infinite; }
.skeleton .sk.w60 { width: 60%; } .skeleton .sk.w40 { width: 40%; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.msg { padding: 10px 2px; }
.msgs-inner > .msg + .msg { margin-top: 4px; }
.msg .head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.msg .who { font-size: 12px; font-weight: 600; color: var(--muted); }
.msg .acts { display: flex; align-items: center; gap: 8px; margin-top: 8px; min-height: 20px; }
.msg .elapsed { font-size: 11px; color: var(--muted); }
.code-footer { justify-content: flex-end; border-top: 1px solid var(--border); border-bottom: 0; }
.msg .acts button {
  min-height: 30px; padding: 3px 10px; font-size: 12px; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 7px; cursor: pointer;
}
.msg .acts button:hover { color: var(--text); }
.msg .acts button.resend { color: #ffd0d0; border-color: rgba(255,107,107,.45); }
.msg.user { border-left: 3px solid var(--accent); padding-left: 12px; background: rgba(76,141,255,.06); border-radius: 0 8px 8px 0; }
.msg.user .who { color: #a9c6ff; }
.msg.assistant .who { color: #9fb0c3; }
.msg.error .body { color: var(--danger); }

.body { word-wrap: break-word; overflow-wrap: anywhere; }
.message-attachment-summary { margin-top: 7px; color: var(--muted); font-size: 12px; }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 10px; }
.body h1, .body h2, .body h3, .body h4, .body h5, .body h6 { margin: 14px 0 8px; line-height: 1.3; }
.body h1 { font-size: 20px; } .body h2 { font-size: 18px; } .body h3 { font-size: 16px; }
.body ul, .body ol { margin: 0 0 10px; padding-left: 22px; }
.body li { margin: 2px 0; }
.body blockquote { margin: 0 0 10px; padding: 4px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.body code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: var(--panel-3); padding: 1px 5px; border-radius: 5px; }
.body hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.body a { text-decoration: underline; text-underline-offset: 2px; }
.tablewrap { overflow-x: auto; margin: 0 0 10px; }
.body table { border-collapse: collapse; font-size: 13px; }
.body th, .body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.body th { background: var(--panel-3); }
.codeblock { margin: 0 0 10px; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: #0b0e13; }
.codebar { display: flex; align-items: center; justify-content: space-between; padding: 5px 10px; background: var(--panel-2); border-bottom: 1px solid var(--border); }
.codebar .lang { font-size: 11px; color: var(--faint); }
.codebar .copy { min-height: 30px; padding: 3px 10px; font-size: 12px; color: var(--muted); background: transparent; border: 1px solid var(--border); border-radius: 7px; cursor: pointer; }
.codeblock pre { margin: 0; padding: 12px; overflow-x: auto; }
.codeblock pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.streaming .body::after { content: "▋"; color: var(--accent); animation: blink 1s steps(2) infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }

.jump {
  position: sticky; bottom: 8px; align-self: center; margin-top: -40px;
  background: var(--panel-3); color: var(--text); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 14px; font-size: 12px; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.4); display: none;
}
.jump.show { display: block; }

/* composer */
.composer {
  flex: 0 0 auto; border-top: 1px solid var(--border); background: var(--panel);
  padding: 10px 12px calc(10px + var(--safe-b));
}
.composer-inner { max-width: var(--content-max); margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer .attach {
  width: 46px; height: 46px; flex: 0 0 46px; padding: 0; border: 1px solid var(--border);
  border-radius: 10px; background: var(--panel-2); color: var(--text); font-size: 26px;
  line-height: 1; cursor: pointer;
}
.attachment-tray {
  max-width: var(--content-max); margin: 0 auto 8px; display: flex; gap: 8px; overflow-x: auto;
  padding: 4px 6px 2px; -webkit-overflow-scrolling: touch;
}
.attachment-tray[hidden] { display: none; }
.attachment-preview { position: relative; flex: 0 0 72px; width: 72px; height: 72px; }
.attachment-preview img { width: 100%; height: 100%; object-fit: cover; overflow: hidden; font-size: 0; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; display: block; }
.attachment-preview .attachment-status {
  position: absolute; left: 4px; right: 4px; bottom: 4px; padding: 2px 3px;
  border-radius: 4px; background: rgba(0,0,0,.72); color: #fff; font-size: 9px; text-align: center;
}
.attachment-preview button {
  position: absolute; top: -6px; right: -6px; width: 25px; height: 25px; padding: 0;
  border: 1px solid var(--border); border-radius: 50%; background: var(--panel-3); color: var(--text);
  font-size: 17px; line-height: 1; cursor: pointer;
}
.composer textarea {
  flex: 1; min-width: 0; resize: none; height: 46px; min-height: 46px; max-height: 46px; padding: 12px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text); font: inherit; font-size: 16px; line-height: 1.45;
  overflow-y: auto;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer .send, .composer .stop {
  min-height: 46px; padding: 0 18px; border: 0; border-radius: 10px; color: #fff; font-weight: 600; cursor: pointer; flex: 0 0 auto;
}
.composer .send { background: var(--accent); }
.composer .send:hover { background: var(--accent-2); }
.composer .stop { background: var(--danger); }
.composer button:disabled { opacity: .5; cursor: default; }
.composer-meta { max-width: var(--content-max); margin: 6px auto 0; display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); min-height: 14px; }
.composer-meta .warn { color: var(--danger); }

/* workflow */
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; }
.placeholder h2 { color: var(--text); margin: 0 0 6px; }

.workflow { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 14px calc(20px + var(--safe-b)); }
.wf-screen { max-width: var(--content-max); margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.wf-head { display: flex; align-items: center; gap: 10px; }
.wf-title { margin: 0; font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-head-actions { display: flex; gap: 6px; }
.wf-btn {
  min-height: 38px; padding: 0 12px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.wf-btn:hover { background: var(--panel-3); }
.wf-btn:disabled { opacity: .5; cursor: default; }
.wf-btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.wf-btn-primary:hover { background: var(--accent-2); }
.wf-btn-danger { color: var(--danger); }
.wf-btn-mini { min-height: 30px; padding: 0 9px; font-size: 12px; border-radius: 7px; }
.wf-empty { color: var(--muted); font-size: 13px; padding: 18px 4px; line-height: 1.6; }

.wf-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.wf-row { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.wf-row-main { display: block; width: 100%; text-align: left; background: none; border: 0; color: inherit; padding: 10px 12px; cursor: pointer; }
.wf-row-main:hover { background: var(--panel-2); }
.wf-row-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.wf-row-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-row-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; font-size: 11px; color: var(--faint); }
.wf-row-badge { margin-top: 6px; display: inline-block; font-size: 11px; color: #ffcf6b; border: 1px solid #6b5324; background: #33280f; border-radius: 999px; padding: 1px 9px; }

.wf-chip { font-size: 10px; letter-spacing: .3px; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.wf-chip-running { color: #ffd479; border-color: #6b5324; background: #33280f; }
.wf-chip-waiting_approval { color: #9fc6ff; border-color: #2b4a79; background: #16243a; }
.wf-chip-completed { color: var(--ok); border-color: #2c5b45; background: #13301f; }
.wf-chip-failed { color: var(--danger); border-color: #6b2c2c; background: #331515; }
.wf-chip-cancelled { color: var(--faint); }

.wf-form { display: flex; flex-direction: column; gap: 10px; }
.wf-import { display: flex; flex-direction: column; gap: 8px; padding: 2px 0 12px; border-bottom: 1px solid var(--border); }
.wf-import-input { min-height: 180px; }
.wf-import .wf-btn { align-self: flex-start; }
.wf-field { display: flex; flex-direction: column; gap: 5px; }
.wf-field-label { font-size: 11px; color: var(--muted); }
.wf-input {
  width: 100%; min-height: 40px; padding: 9px 10px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px; font: inherit; font-size: 14px;
}
textarea.wf-input { resize: vertical; min-height: 62px; line-height: 1.5; }
.wf-input:focus { outline: none; border-color: var(--accent); }
.wf-section-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.wf-steps { display: flex; flex-direction: column; gap: 8px; }
.wf-step-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.wf-step-top { display: flex; align-items: center; }
.wf-step-index { flex: 1; font-size: 12px; color: var(--muted); }
.wf-step-tools { display: flex; gap: 6px; }
.wf-note { font-size: 12px; color: var(--faint); }

.wf-statusbar { display: flex; flex-direction: column; gap: 6px; }
.wf-goal { font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.wf-run-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wf-run-id { font-size: 11px; color: var(--faint); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.wf-timeline { display: flex; flex-direction: column; gap: 8px; }
.wf-tl-row { background: var(--panel); border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius); padding: 10px 12px; }
.wf-tl-running { border-left-color: #ffd479; }
.wf-tl-waiting_approval { border-left-color: #4c8dff; }
.wf-tl-completed { border-left-color: var(--ok); }
.wf-tl-failed { border-left-color: var(--danger); }
.wf-tl-cancelled { border-left-color: var(--faint); }
.wf-tl-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.wf-tl-index { width: 20px; height: 20px; flex: 0 0 20px; border-radius: 50%; background: var(--panel-3); color: var(--muted); font-size: 11px; display: grid; place-items: center; }
.wf-tl-title { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-tl-mode { font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .3px; }
.wf-tl-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 5px; font-size: 11px; color: var(--faint); }
.wf-tl-error { color: var(--danger); word-break: break-word; }
.wf-tl-actions { display: flex; gap: 8px; margin-top: 8px; }

.wf-events { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.wf-event-list { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); max-height: 260px; overflow-y: auto; }
.wf-event { display: flex; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); font-size: 12px; align-items: baseline; }
.wf-event:last-child { border-bottom: 0; }
.wf-event-time { color: var(--faint); white-space: nowrap; font-size: 11px; }
.wf-event-type { color: var(--accent); white-space: nowrap; font-size: 11px; }
.wf-event-msg { color: var(--muted); min-width: 0; word-break: break-word; }

/* ---------- rescue ---------- */
.gateway-degraded {
  flex: 0 0 auto; min-height: 42px; padding: 6px 12px; border-bottom: 1px solid #6b5324;
  background: #33280f; color: #ffd479; display: flex; align-items: center; justify-content: center; gap: 12px;
}
.gateway-degraded button { min-height: 32px; border: 1px solid #8b6a28; border-radius: 7px; background: transparent; color: #ffd479; padding: 0 10px; cursor: pointer; }
.rescue-view { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 12px calc(24px + var(--safe-b)); }
.rescue-inner { width: 100%; max-width: 780px; margin: 0 auto; }
.rescue-heading { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.rescue-heading > div { flex: 1; min-width: 0; }
.rescue-heading h1 { margin: 0; font-size: 18px; }
.rescue-heading p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.rescue-status { margin: 0; }
.rescue-status > div { display: grid; grid-template-columns: minmax(130px, 1fr) auto; gap: 16px; padding: 10px 2px; border-bottom: 1px solid var(--border); }
.rescue-status dt { color: var(--muted); }
.rescue-status dd { margin: 0; font: 600 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); }
.rescue-status dd.ready, .rescue-status dd.online { color: var(--ok); }
.rescue-status dd.down, .rescue-status dd.unavailable { color: var(--danger); }
.rescue-status dd.running { color: #ffd479; }
.rescue-actions { display: flex; flex-direction: column; gap: 9px; padding: 16px 0; }
.rescue-actions label { color: var(--muted); font-size: 12px; }
.rescue-actions textarea { width: 100%; min-height: 96px; resize: vertical; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); color: var(--text); font: inherit; font-size: 16px; line-height: 1.45; }
.rescue-actions textarea:focus { outline: none; border-color: var(--accent); }
.rescue-actions button, .rescue-dialog-actions button { min-height: 44px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); color: var(--text); padding: 0 14px; cursor: pointer; font-weight: 600; }
.rescue-actions > #rescueCheck { align-self: flex-start; }
.rescue-action-row { display: flex; gap: 8px; }
.rescue-action-row button { flex: 1; }
.rescue-actions .rescue-auto { background: #5b341e; border-color: #8f5433; color: #ffe0cc; }
.rescue-actions .rescue-restart { background: #4a2525; border-color: #9a4f4f; color: #ffdede; }
.rescue-actions button:disabled { opacity: .5; cursor: default; }
.rescue-note { margin: 0; color: var(--faint); font-size: 11px; }
.rescue-run-state { padding: 9px 0; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.rescue-console { min-height: 220px; max-height: 46vh; overflow: auto; margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: #090c10; color: #d8e0e8; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.rescue-stepup { width: min(92vw, 390px); max-height: 76dvh; margin: 12dvh auto auto; border: 1px solid var(--border); border-radius: 8px; padding: 0; background: var(--panel); color: var(--text); }
.rescue-stepup::backdrop { background: rgba(0,0,0,.72); }
.rescue-stepup form { padding: 20px; }
.rescue-stepup h2 { margin: 0 0 6px; font-size: 17px; }
.rescue-stepup p { margin: 0 0 16px; color: var(--muted); font-size: 12px; }
.rescue-stepup label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.rescue-stepup input { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); color: var(--text); font-size: 16px; }
.rescue-dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.rescue-dialog-actions .primary { background: var(--accent); border-color: transparent; }
.rescue-dialog-actions .danger { background: #7b3030; border-color: #a74a4a; color: #fff0f0; }

@media (min-width: 769px) {
  .workflow { padding: 18px 24px 24px; }
}

/* account */
.account { flex: 0 0 auto; border-top: 1px solid var(--border); padding: 10px 12px calc(10px + var(--safe-b)); display: grid; gap: 8px; }
.account-header { display: flex; align-items: center; gap: 8px; }
.account .notify-toggle { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; white-space: nowrap; cursor: pointer; }
.account .notify-toggle input { accent-color: var(--accent); }
.account .who { flex: 1; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account button { min-height: 36px; padding: 0 10px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 13px; }
.notification-summary { width: 100%; min-width: 0; display: flex; align-items: center; gap: 9px; text-align: left; }
.notification-summary:hover { border-color: var(--accent); }
.notification-icon { font-size: 15px; line-height: 1; }
.notification-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; }
.notification-copy strong, .notification-copy small { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notification-copy strong { font-size: 13px; font-weight: 600; color: var(--text); }
.notification-copy small, .notification-test-result { color: var(--muted); font-size: 11px; }
.notification-chevron { color: var(--faint); font-size: 21px; line-height: 1; }
.notification-settings { display: grid; gap: 8px; padding: 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; }
.notification-settings-title { font-size: 12px; font-weight: 600; color: var(--text); }
.notification-setting-row { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }
.notification-setting-row strong { color: var(--ok); font-weight: 600; }
.notification-test { width: 100%; background: var(--accent); border-color: transparent; color: #fff; }
.notification-test:disabled { opacity: .55; cursor: default; }
.notification-clear { width: 100%; background: transparent !important; color: var(--muted) !important; }
.notification-recent { display: grid; gap: 5px; border-top: 1px solid var(--border); padding-top: 8px; }
.notification-recent ul { display: grid; gap: 6px; list-style: none; padding: 0; margin: 0; }
.notification-recent li { display: grid; gap: 1px; min-width: 0; }
.notification-recent li strong, .notification-recent li small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notification-recent li strong { color: var(--text); font-size: 11px; }
.notification-recent li small { color: var(--muted); font-size: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  background: var(--panel-3); border: 1px solid var(--border); color: var(--text); padding: 8px 14px; border-radius: 9px;
  font-size: 13px; z-index: 50; opacity: 0; transition: opacity .2s ease; pointer-events: none;
}
.toast.show { opacity: 1; }

@media (max-width: 768px) {
  .sidebar-top { gap: 5px; }
  .navtab { font-size: 12px; padding: 0 5px; }
  .messages { padding-left: 32px; }
  .header { gap: 4px; }
  .header .status .txt { display: none; }
  .header .iconbtn { width: 38px; height: 40px; }
  .history-tools { min-height: 36px; }
}

/* ---------- desktop ---------- */
@media (min-width: 769px) {
  .overlay { display: none; }
  .sidebar {
    position: static; transform: none; width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    max-width: none; padding-top: 0; padding-bottom: 0;
  }
  .header { padding-top: 10px; }
  .header .hamburger { display: none; }
  .edge-toggle { display: none; }
  .history-tools { padding-left: 24px; padding-right: 24px; }
  .messages { padding: 18px 24px 24px; }
  .rescue-view { padding: 20px 24px 28px; }
  .composer { padding: 12px 24px calc(12px + 0px); }
  .msg .acts { opacity: 1; }
  .msg:hover .acts, .msg:focus-within .acts { opacity: 1; }
}
