:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1b1c1f;
  --muted: #5f6368;
  --line: #dfe1e5;
  --accent: #0b57d0;
  --accent-text: #ffffff;
  --accent-soft: #d3e3fd;
  --ok: #137333;
  --warn: #b06000;
  --bad: #c5221f;
  --code-bg: #f1f3f4;
  --pill: #e8eaed;
  --codex: #10a37f;
  --claude: #d97757;
  --cursor: #6e56cf;
  --planner: #0b57d0;
  --you-bg: #0b57d0;
  --you-text: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --card: #1c1e22;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --line: #33363b;
    --accent: #8ab4f8;
    --accent-text: #0b1d3a;
    --accent-soft: #23324d;
    --ok: #81c995;
    --warn: #fdd663;
    --bad: #f28b82;
    --code-bg: #25282d;
    --pill: #2d3035;
    --codex: #3ccf9f;
    --claude: #f0a07f;
    --cursor: #a594f9;
    --planner: #8ab4f8;
    --you-bg: #2b4f8f;
    --you-text: #ffffff;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: inherit; text-decoration: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }
nav { margin-left: auto; display: flex; gap: 2px; }
.navbtn { color: inherit; text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.navbtn.active { background: var(--pill); font-weight: 600; }

main { max-width: 760px; margin: 0 auto; padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: 8px; }
.error { color: var(--bad); font-weight: 600; }
.ok-text { color: var(--ok); font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 18px; margin: 0 0 6px; }
.card h3 { font-size: 15px; margin: 0 0 6px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input[type=password], input[type=number], input[type=url], input[inputmode=numeric], textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}
textarea { min-height: 90px; resize: vertical; }
textarea.code { font: 13.5px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace; min-height: 200px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none; color: inherit; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.big { width: 100%; padding: 13px; font-size: 17px; }
.btn.small { padding: 6px 10px; font-size: 14px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 4px 0; font-weight: 500; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--pill); font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.pill.needs { background: #fde293; color: #3c2f00; }
.pill.busy { background: #c2e7ff; color: #001d35; }
.pill.done { background: #c4eed0; color: #072711; }
.pill.wait { background: #e9d2fd; color: #25003f; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 12px; cursor: pointer; font-size: 14px; font-weight: 600; }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip:disabled { opacity: .4; }
.chip.codex.on { background: var(--codex); border-color: var(--codex); color: #fff; }
.chip.claude.on { background: var(--claude); border-color: var(--claude); color: #fff; }
.chip.cursor.on { background: var(--cursor); border-color: var(--cursor); color: #fff; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.switch input { width: 22px; height: 22px; }

/* ---------- home ---------- */
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 8px; font-weight: 700; }
.job-item { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer; color: inherit; text-decoration: none; }
.job-item .title { font-weight: 700; margin: 4px 0 2px; }
.job-item .preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-item.needs { border-color: #f6c142; box-shadow: 0 0 0 1px #f6c142 inset; }
.fab { position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); border-radius: 999px; padding: 14px 20px; box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 5; }

/* ---------- job thread ---------- */
.jobhead { position: sticky; top: calc(46px + env(safe-area-inset-top)); z-index: 6; background: var(--bg); padding: 4px 0 8px; display: flex; align-items: center; gap: 8px; }
.jobhead .titles { flex: 1 1 auto; min-width: 0; }
.jobhead .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menuwrap { position: relative; }
.iconbtn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 6px 10px; cursor: pointer; font-weight: 700; }
.menu { position: absolute; right: 0; top: 44px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.25); padding: 6px; min-width: 230px; z-index: 20; }
.menu button, .menu a { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 10px 12px; border-radius: 8px; cursor: pointer; color: inherit; text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--pill); }

.thread { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.msg { max-width: 92%; border-radius: 16px; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); }
.msg .who { font-size: 13px; font-weight: 800; margin-bottom: 4px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.msg .who .time { font-weight: 500; color: var(--muted); margin-left: auto; }
.msg.you { align-self: flex-end; background: var(--you-bg); color: var(--you-text); border-color: transparent; border-bottom-right-radius: 4px; }
.msg.you .who, .msg.you .who .time { color: rgba(255,255,255,.85); }
.msg.left { align-self: flex-start; border-bottom-left-radius: 4px; border-left: 4px solid var(--line); }
.msg.planner { border-left-color: var(--planner); }
.msg.codex { border-left-color: var(--codex); }
.msg.claude { border-left-color: var(--claude); }
.msg.cursor { border-left-color: var(--cursor); }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.msg.undone { opacity: .55; }
.tag { font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--pill); color: var(--text); }
.tag.codex { background: var(--codex); color: #fff; }
.tag.claude { background: var(--claude); color: #fff; }
.tag.cursor { background: var(--cursor); color: #fff; }
.sys { align-self: center; font-size: 12.5px; color: var(--muted); text-align: center; max-width: 90%; }

pre.text, .live {
  white-space: pre-wrap; word-break: break-word; background: var(--code-bg); color: var(--text); border-radius: 10px; padding: 9px 11px;
  margin: 6px 0 0; font: 12.5px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace; max-height: 360px; overflow: auto;
}
pre.text.tall { max-height: none; }
.live { max-height: 200px; }
.files { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.files span { font: 12px ui-monospace, Consolas, monospace; background: var(--code-bg); border-radius: 6px; padding: 2px 6px; }
.typing::after { content: ' ●●●'; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.action { border: 2px solid var(--accent); }
.action.warn { border-color: var(--warn); }
.action h3 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.composer {
  position: sticky; bottom: 0; z-index: 6; background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 10px; margin-top: 8px; box-shadow: 0 -4px 16px rgba(0,0,0,.08);
}
.composer textarea { min-height: 44px; height: 44px; max-height: 40vh; border-radius: 12px; padding: 10px 12px; }
.composer textarea:focus { height: 110px; }
.composer .to { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
.composer .to .chips { flex-wrap: nowrap; }
.composer .to .chip { padding: 5px 10px; font-size: 13px; white-space: nowrap; }
.composer .opts { display: flex; gap: 6px; margin-bottom: 8px; }
.composer .opts select { padding: 7px 10px; font-size: 14px; }
.composer .sendrow { display: flex; gap: 8px; align-items: flex-end; }
.composer .hint { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #202124; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: 90vw; z-index: 40; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; padding: 16px; width: 100%; max-width: 380px; }
table.kv { border-collapse: collapse; width: 100%; font-size: 14px; }
table.kv td { padding: 5px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.qr svg { width: 240px; height: 240px; background: #fff; border-radius: 8px; }
code.secret { word-break: break-all; font-size: 15px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: var(--card); padding: 8px 12px; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 700; }
