:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --text: #16181d;
  --muted: #5d6573;
  --line: #e2e5ea;
  --accent: #4f46e5;
  --accent-soft: #eceafd;
  --ok: #117a3d;
  --ok-soft: #e3f5ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --info: #1d5fae;
  --info-soft: #e4eefb;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #1e222b;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --line: #2a2f3a;
    --accent: #8b85ff;
    --accent-soft: #25234a;
    --ok: #4cc27f;
    --ok-soft: #13301f;
    --warn: #f0b04a;
    --warn-soft: #3a2b10;
    --bad: #ff7b6e;
    --bad-soft: #3d1714;
    --info: #74a8f0;
    --info-soft: #152b47;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* --- frame ---------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 56px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); letter-spacing: .5px; }
.brand:hover { text-decoration: none; }
.logo {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 14px;
}
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.topright { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.who { color: var(--muted); font-size: 13px; }
.main { max-width: 1240px; margin: 0 auto; padding: 24px 20px 80px; }

.killbar {
  background: var(--bad); color: #fff; padding: 10px 20px; font-weight: 600;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.killbar a { color: #fff; text-decoration: underline; }

/* --- building blocks ------------------------------------------------------------ */

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px;
}
.panel.flush { padding: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.pagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.two { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.fact .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.fact .v { font-weight: 600; }
.empty { color: var(--muted); padding: 12px 0; }
.error-box {
  background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px;
  white-space: pre-wrap;
}
.note-box {
  background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px;
}
.info-box {
  background: var(--info-soft); color: var(--info); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px;
}
pre.block {
  background: var(--panel-2); border-radius: 8px; padding: 12px; overflow-x: auto; margin: 0;
  font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word;
}

.chip, .badge, .pill {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; font-size: 12px;
  padding: 1px 9px; font-weight: 600; white-space: nowrap; line-height: 20px;
}
.badge { background: var(--bad); color: #fff; padding: 0 7px; margin-left: 4px; font-size: 11px; line-height: 18px; }
.chip { background: var(--panel-2); color: var(--muted); }
.chip.ok, .pill.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn, .pill.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad, .pill.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info, .pill.info { background: var(--info-soft); color: var(--info); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.pill { border: 1px solid transparent; }
.pill:hover { text-decoration: none; filter: brightness(.97); }

button, .button {
  font: inherit; font-weight: 600; font-size: 13px; border-radius: 8px; padding: 6px 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
button:hover { background: var(--panel-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.caution { background: var(--warn); border-color: var(--warn); color: #fff; }
button.link { border: none; background: none; color: var(--accent); padding: 4px; }
button.small { padding: 3px 9px; font-size: 12px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; min-width: 0;
}
textarea { width: 100%; resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; background: var(--panel-2); }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; }

/* --- fleet ------------------------------------------------------------------------ */

.cluster-card { cursor: pointer; transition: border-color .12s; }
.cluster-card:hover { border-color: var(--accent); }
.cluster-card .title { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.cluster-card .name { font-size: 16px; font-weight: 700; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 10px; font-size: 13px; }
.kv .k { color: var(--muted); }
.suggestion { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.suggestion:last-child { border-bottom: none; }

/* --- change controls --------------------------------------------------------------- */

.change { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.change select { max-width: 220px; }

/* --- approvals ----------------------------------------------------------------------- */

.gate { border-left: 4px solid var(--warn); }
.gate.decided { border-left-color: var(--line); }
.gate .brief { max-height: 460px; overflow: auto; }

/* --- markdown ------------------------------------------------------------------------ */

.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; }
.md h1 { font-size: 18px; }
.md h2 { font-size: 16px; }
.md h3, .md h4 { font-size: 14px; }
.md ul { margin: 4px 0 8px; padding-left: 22px; }
.md p { margin: 6px 0; }
.md code { background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.md pre { background: var(--panel-2); padding: 10px; border-radius: 8px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; }
.md blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }

/* --- runs ---------------------------------------------------------------------------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 70px 170px 200px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.timeline li:last-child { border-bottom: none; }
@media (max-width: 800px) { .timeline li { grid-template-columns: 1fr; gap: 2px; } }

/* --- assistant ----------------------------------------------------------------------- */

.chat { display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 420px; }
.chat .log { flex: 1; overflow-y: auto; padding: 16px; }
.chat .composer { border-top: 1px solid var(--line); padding: 12px; display: flex; gap: 8px; align-items: flex-end; }
.chat .composer textarea { min-height: 44px; max-height: 160px; }
.msg { max-width: 820px; margin-bottom: 14px; }
.msg .who { font-size: 12px; margin-bottom: 3px; }
.msg .bubble { padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.msg.user { margin-left: auto; }
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.user .who { text-align: right; }
.msg.assistant .bubble { background: var(--panel-2); border-bottom-left-radius: 4px; }
.msg .meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-top: 8px; background: var(--panel); }
.card.caution { border-color: var(--warn); }
.card.danger { border-color: var(--bad); }
.card .ctitle { font-weight: 700; margin-bottom: 4px; }
.card .cdetail { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.card .cresult { margin-top: 8px; font-size: 13px; }
.suggest-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 16px 12px; }
.suggest-chips button { font-weight: 500; }
.thinking { color: var(--muted); font-style: italic; }

/* --- activity ------------------------------------------------------------------------ */

.notice { display: grid; grid-template-columns: 18px 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.notice:last-child { border-bottom: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--muted); }
.dot.critical { background: var(--bad); }
.dot.warning { background: var(--warn); }
.dot.info { background: var(--info); }
.notice .ntitle { font-weight: 600; }
.notice .nbody { color: var(--muted); font-size: 13px; white-space: pre-wrap; }
.notice.unseen .ntitle::after { content: "new"; margin-left: 8px; font-size: 11px; color: var(--accent); }

/* --- toasts and jobs ------------------------------------------------------------------ */

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: 420px; }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 10px;
  padding: 10px 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
}
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }
.toast .ttitle { font-weight: 700; margin-bottom: 2px; }
.toast .tbody { font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.job-steps { list-style: none; padding: 0; margin: 6px 0 0; font-size: 12.5px; color: var(--muted); max-height: 140px; overflow-y: auto; }
.job-steps li::before { content: "› "; }

/* --- sign in ------------------------------------------------------------------------- */

.signin { max-width: 460px; margin: 10vh auto; }
.signin details { margin-top: 16px; }
.signin summary { cursor: pointer; color: var(--muted); margin-bottom: 10px; }
.signin > button.primary { width: 100%; padding: 10px; font-size: 14px; margin-top: 8px; }
.device-code {
  font-family: var(--mono); font-size: 30px; font-weight: 700; letter-spacing: 4px; text-align: center;
  background: var(--panel-2); border-radius: 10px; padding: 14px; margin: 8px 0 12px;
}
a.button { display: inline-block; text-decoration: none; }
a.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.signin .logo { width: 44px; height: 44px; font-size: 22px; border-radius: 11px; margin-bottom: 14px; }

/* --- modal --------------------------------------------------------------------------- */

.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; max-width: 900px; width: 100%; max-height: 88vh; overflow: auto; padding: 20px 22px; }

@media (max-width: 700px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .who { display: none; }
  .main { padding: 16px 12px 80px; }
  .kv { grid-template-columns: 110px 1fr; }
}
