:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef1f5; --text: #17202b; --muted: #5d6b7c;
  --border: #d9dfe7; --accent: #1f6feb; --accent-text: #ffffff; --ok: #1a7f37; --warn: #9a6700;
  --bad: #cf222e; --info: #0969da; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --surface: #161b22; --surface-2: #1f2630; --text: #e6edf3; --muted: #8d99a6;
    --border: #2d3642; --accent: #2f81f7; --accent-text: #ffffff; --ok: #3fb950; --warn: #d29922;
    --bad: #f85149; --info: #58a6ff; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #161b22; --surface-2: #1f2630; --text: #e6edf3; --muted: #8d99a6;
  --border: #2d3642; --accent: #2f81f7; --accent-text: #ffffff; --ok: #3fb950; --warn: #d29922;
  --bad: #f85149; --info: #58a6ff; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 8px; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err { color: var(--bad); min-height: 1em; margin: 6px 0 0; }
[hidden] { display: none !important; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow);
}
.row-between { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

label { display: block; margin: 8px 0; font-size: 14px; }
input:not([type=checkbox]), textarea, select {
  width: 100%; margin-top: 4px; padding: 10px; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: 18px; height: 18px; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.good { color: var(--ok); border-color: var(--ok); background: transparent; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .btn { width: 100%; margin-top: 8px; }

/* app shell */
#app { max-width: 820px; margin: 0 auto; padding: 0 16px calc(76px + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 0 10px; background: var(--bg);
}
.top-left, .top-right { display: flex; align-items: center; gap: 8px; }
.pill { padding: 4px 10px; border-radius: 999px; font-weight: 700; font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); }
.pill.working { color: var(--ok); border-color: var(--ok); }
.pill.waiting { color: var(--warn); border-color: var(--warn); }
.pill.paused, .pill.stopping { color: var(--bad); border-color: var(--bad); }
.pill.idle { color: var(--muted); }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
.conn.on { background: var(--ok); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex;
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; min-height: 56px; border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px;
  font-weight: 600; cursor: pointer; position: relative;
}
.tabs button.on { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; }

.status-text { font-size: 16px; color: var(--text); margin: 4px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.chip.on { border-color: var(--accent); color: var(--accent); }
#btnRun { margin-top: 8px; width: 100%; }

#shot { width: 100%; border-radius: 8px; border: 1px solid var(--border); display: block; }

/* feed */
.feed, .thread, .list { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 13.5px; }
.feed li:first-child { border-top: 0; }
.feed .ic { text-align: center; }
.feed .tx { overflow-wrap: anywhere; white-space: pre-wrap; }
.feed .tm { color: var(--muted); font-size: 12px; white-space: nowrap; }
.feed li.fail .tx { color: var(--bad); }
.feed li.say .tx { color: var(--text); background: var(--surface-2); border-radius: 8px; padding: 6px 8px; max-height: 12em; overflow: auto; }
.feed li.user .tx { color: var(--info); font-weight: 600; }
.feed li.stop .tx, .feed li.approval .tx { color: var(--warn); font-weight: 600; }
.feed li.control .tx, .feed li.security .tx { color: var(--muted); font-style: italic; }
#moreFeed { width: 100%; margin-top: 8px; }

/* inbox */
.q { border-left: 4px solid var(--warn); }
.q pre, .appr pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 6px 0 10px; max-height: 16em; overflow: auto; }
.q .opts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.q .free { display: flex; gap: 6px; }
.q .free input { margin: 0; }
.thread li { margin: 8px 0; display: flex; }
.thread .bubble { max-width: 88%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.thread li.user { justify-content: flex-end; }
.thread li.user .bubble { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.thread li.agent .bubble { background: var(--surface-2); border-bottom-left-radius: 4px; max-height: 22em; overflow: auto; }
.thread .meta { display: flex; align-items: center; gap: 6px; font-size: 11px; opacity: .75; margin-top: 4px; }
.thread .del { margin-left: auto; border: 0; background: none; color: inherit; font: inherit; font-size: 13px; padding: 2px 6px; cursor: pointer; opacity: .8; }
.thread .del:hover { opacity: 1; }
#qBar { margin: 0 0 8px; }
.compose {
  position: sticky; bottom: calc(60px + env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: flex-end;
  background: var(--bg); padding: 8px 0;
}
.compose textarea { margin: 0; }
.compose .btn { min-height: 46px; }

/* approvals */
.appr { border-left: 4px solid var(--bad); }
.appr .acts { display: flex; gap: 8px; }
.appr .acts .btn { flex: 1; }

/* bots */
.bot h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); vertical-align: middle; }
.dot.on { background: var(--ok); }
.ctrs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.ctr { background: var(--surface-2); border-radius: 8px; padding: 6px 8px; text-align: center; }
.ctr b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.ctr span { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.inrow { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.inrow input { margin: 0; min-width: 0; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.btnrow .btn { flex: 1; min-width: 90px; }
.queue { list-style: none; margin: 0; padding: 0; max-height: 28em; overflow: auto; }
.qrow { display: flex; gap: 8px; justify-content: space-between; align-items: center; padding: 7px 0; border-top: 1px solid var(--border); font-size: 13.5px; }
.qrow:first-child { border-top: 0; }
.qmain { min-width: 0; overflow-wrap: anywhere; }
.qacts { display: flex; gap: 4px; flex-shrink: 0; }
.qacts .btn { min-height: 32px; padding: 2px 8px; font-size: 12.5px; }
.st-applied { color: var(--ok); } .st-error, .st-failed { color: var(--bad); } .st-pending { color: var(--muted); }

/* runs / settings lists */
.list li { padding: 10px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.list a { color: var(--accent); text-decoration: none; font-weight: 600; cursor: pointer; }
.gate { display: grid; gap: 4px; }
.gate input[type=text] { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; padding: 6px 8px; }

/* markdown */
.md { overflow-wrap: anywhere; }
.md h1 { font-size: 19px; margin: 10px 0; }
.md h2 { font-size: 16px; margin: 16px 0 6px; }
.md h3 { font-size: 15px; margin: 12px 0 4px; }
.md ul { padding-left: 20px; }
.md .tbl { overflow-x: auto; }
.md table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 6px; text-align: left; vertical-align: top; }
.md pre { background: var(--surface-2); padding: 8px; border-radius: 8px; overflow-x: auto; }
