:root {
  --bg: #f6f5f2; --panel: #ffffff; --panel2: #f0eee9; --line: #e2dfd8; --text: #1d1d1b; --muted: #6d6a63;
  --accent: #c2410c; --accent-soft: #fdeee4; --ok: #15803d; --ok-soft: #e3f4e8; --warn: #a16207; --warn-soft: #fbf1d6;
  --bad: #b91c1c; --bad-soft: #fbe4e4; --blue: #1d4ed8; --blue-soft: #e4ebfc;
  --r: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a; --panel: #1c1f24; --panel2: #23272d; --line: #2e333a; --text: #e8e6e1; --muted: #9a978f;
    --accent: #fb923c; --accent-soft: #3a2518; --ok: #4ade80; --ok-soft: #173222; --warn: #facc15; --warn-soft: #33290f;
    --bad: #f87171; --bad-soft: #3a1b1b; --blue: #93b4ff; --blue-soft: #1c2640;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #14161a; --panel: #1c1f24; --panel2: #23272d; --line: #2e333a; --text: #e8e6e1; --muted: #9a978f;
    --accent: #fb923c; --accent-soft: #3a2518; --ok: #4ade80; --ok-soft: #173222; --warn: #facc15; --warn-soft: #33290f;
    --bad: #f87171; --bad-soft: #3a1b1b; --blue: #93b4ff; --blue-soft: #1c2640;
    --shadow: none;
    color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.sub { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); font-size: 13px; }
a { color: var(--blue); }

.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; letter-spacing: -.01em; }
.tabs { display: flex; gap: 2px; background: var(--panel2); padding: 3px; border-radius: 9px; }
.tabs button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.count:not(:empty) { background: var(--accent); color: #fff; border-radius: 99px; padding: 0 7px; font-size: 12px; margin-left: 4px; }
.runner { margin-left: auto; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.off { background: var(--bad); }

main { max-width: 1040px; margin: 0 auto; padding: 16px 20px 80px; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 0; max-width: 75ch; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { flex: 1 1 240px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 7px 11px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.chk { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); cursor: pointer; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 4px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 3px 11px; font-size: 13px; cursor: pointer; color: var(--muted); }
.chip[aria-pressed="true"] { border-color: var(--text); color: var(--text); font-weight: 600; }
.chip .n { opacity: .6; margin-left: 4px; }
.stats { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

button.ghost { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 11px; cursor: pointer; }
button.ghost:hover { border-color: var(--muted); }
button.primary { border: 0; background: var(--accent); color: #fff; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 600; }
button.small, .small { font-size: 12px; padding: 3px 8px; }
button.danger { color: var(--bad); }

.group { margin-top: 22px; }
.group > h2 { margin-top: 0; }
.subgroup { font-size: 13px; color: var(--muted); margin: 12px 0 6px 2px; font-weight: 600; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); margin: 6px 0; box-shadow: var(--shadow); }
.card > .head { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; cursor: pointer; }
.card > .head:hover { background: color-mix(in srgb, var(--panel2) 50%, transparent); border-radius: var(--r); }
.card .stufe { flex: none; width: 20px; text-align: center; }
.card .ttl { flex: 1; min-width: 0; }
.card .ttl b { font-weight: 600; }
.nr { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; font-size: 14px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.badge { font-size: 12px; border-radius: 6px; padding: 1px 7px; background: var(--panel2); color: var(--muted); white-space: nowrap; }
.badge.proj { background: var(--blue-soft); color: var(--blue); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.acc { background: var(--accent-soft); color: var(--accent); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.card .go { flex: none; }
.card .body { border-top: 1px solid var(--line); padding: 4px 16px 14px 44px; display: none; }
.card.open .body { display: block; }
.card .body .tools { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.md { font-size: 14.5px; overflow-wrap: anywhere; }
.md p { margin: 10px 0; }
.md em.meta { color: var(--muted); font-size: 13px; }
.md blockquote { margin: 10px 0; padding: 4px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md pre { background: var(--panel2); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font: 13px/1.45 var(--mono); white-space: pre-wrap; }
.md code { font: 13px var(--mono); background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md ul, .md ol { padding-left: 22px; margin: 8px 0; }
.md h4 { margin: 14px 0 4px; font-size: 14px; }

.job { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); margin: 8px 0; padding: 10px 14px; box-shadow: var(--shadow); }
.job[draggable="true"] { cursor: grab; }
.job.dragging { opacity: .4; }
.job.over { border-color: var(--accent); }
.job .line1 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.job .line1 .ttl { flex: 1; min-width: 200px; font-weight: 600; }
.job .grip { color: var(--muted); cursor: grab; user-select: none; }
.job .note { font-size: 13px; color: var(--warn); margin-top: 4px; }
.job .meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.job .btns { display: flex; gap: 6px; flex-wrap: wrap; }
.job .result { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; }
.log { margin-top: 10px; max-height: 420px; overflow-y: auto; background: var(--panel2); border-radius: 8px; padding: 8px 10px; font: 12.5px/1.5 var(--mono); }
.log div { white-space: pre-wrap; overflow-wrap: anywhere; padding: 1px 0; }
.log .tool { color: var(--blue); }
.log .toolerr, .log .error { color: var(--bad); }
.log .info { color: var(--muted); }
.log .text { color: var(--text); font-family: system-ui, sans-serif; font-size: 13.5px; margin: 4px 0; }
.empty { color: var(--muted); font-size: 14px; padding: 12px 2px; }
.resume { font: 12px var(--mono); background: var(--panel2); padding: 2px 6px; border-radius: 5px; cursor: copy; }

.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.acc { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.acc h3 { margin: 0; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.acc .lbl { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.win { margin: 10px 0; }
.win .top2 { display: flex; justify-content: space-between; font-size: 13px; }
.win .top2 span:last-child { color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: var(--panel2); overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.bar > i.mid { background: var(--warn); }
.bar > i.high { background: var(--bad); }
.acc .foot { font-size: 13px; color: var(--muted); margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.runnercard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 14px; }
table.chats { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--panel); border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); }
table.chats td, table.chats th { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.chats th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel2); }
table.chats td.cwd { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
dialog h3 { margin: 0; font-size: 17px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; }
dialog select, dialog textarea { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: var(--bg); font-weight: 400; }
dialog fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0; }
dialog legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
dialog .modes label { flex-direction: row; font-weight: 400; gap: 8px; align-items: baseline; margin: 4px 0; }
dialog .row { display: flex; gap: 18px; flex-wrap: wrap; }
dialog .row label { flex-direction: row; font-weight: 400; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.warn { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 12px; font-size: 14px; margin: 0; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }

@media (max-width: 640px) {
  .top { padding: 8px 16px; gap: 8px; }
  .runner { margin-left: 0; width: 100%; }
  main { padding: 12px 16px 80px; }
  .card .body { padding-left: 16px; }
  table.chats td.cwd { display: none; }
}

.acc-chatlist { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
