:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #f0f2f4;
  --border: #dde1e5;
  --text: #1c2329;
  --muted: #66727d;
  --accent: #134e5e;
  --accent-text: #ffffff;
  --pass: #1f8a4c;
  --pass-bg: #e3f4ea;
  --warn: #b26a00;
  --warn-bg: #fdf0db;
  --fail: #c2362b;
  --fail-bg: #fbe5e3;
  --info: #3d6a99;
  --info-bg: #e5eef8;
  --code-bg: #f3f4f6;
  --diff-add: #e3f4ea;
  --diff-del: #fbe5e3;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161a; --surface: #1a1f24; --surface-2: #222930; --border: #2f373f; --text: #e4e8eb;
    --muted: #93a0ab; --accent: #4fa3b8; --accent-text: #0b1114; --pass: #4cc483; --pass-bg: #173326;
    --warn: #e5a443; --warn-bg: #3a2c14; --fail: #f07167; --fail-bg: #3d1d1b; --info: #7fb0e0;
    --info-bg: #1b2a3a; --code-bg: #20262c; --diff-add: #173326; --diff-del: #3d1d1b;
  }
}
:root[data-theme="dark"] {
  --bg: #12161a; --surface: #1a1f24; --surface-2: #222930; --border: #2f373f; --text: #e4e8eb;
  --muted: #93a0ab; --accent: #4fa3b8; --accent-text: #0b1114; --pass: #4cc483; --pass-bg: #173326;
  --warn: #e5a443; --warn-bg: #3a2c14; --fail: #f07167; --fail-bg: #3d1d1b; --info: #7fb0e0;
  --info-bg: #1b2a3a; --code-bg: #20262c; --diff-add: #173326; --diff-del: #3d1d1b;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; display: flex; flex-direction: column; }
button, select, textarea, input { font: inherit; color: inherit; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 600; letter-spacing: .2px; }
.session-ctl { display: flex; gap: 8px; align-items: center; }
.session-ctl select { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; max-width: 280px; }
.health { margin-left: auto; font-size: 12px; color: var(--muted); }
.health .bad { color: var(--fail); }

.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 44%); min-height: 0; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; } }

.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.empty { padding: 32px 24px; max-width: 640px; margin: 0 auto; }
.empty h2 { font-size: 18px; font-weight: 600; margin: 0 0 8px; }
.empty-actions { display: flex; gap: 8px; margin: 14px 0; }
.muted { color: var(--muted); }

.msg { max-width: 100%; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); padding: 8px 12px; border-radius: 12px 12px 2px 12px; max-width: 80%; white-space: pre-wrap; }
.msg.assistant { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); }
.msg.assistant .md > :first-child { margin-top: 0; }
.msg.assistant .md > :last-child { margin-bottom: 0; }
.msg.system { align-self: center; font-size: 12px; color: var(--muted); }
.msg.error { border-color: var(--fail); color: var(--fail); }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border); padding: 3px 8px; text-align: left; }
.md code { background: var(--code-bg); padding: 1px 4px; border-radius: 4px; font-family: var(--mono); font-size: 12.5px; }
.md pre { background: var(--code-bg); padding: 8px; border-radius: 6px; overflow-x: auto; }
.md pre code { padding: 0; }

.tools { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.tool { font-size: 12px; font-family: var(--mono); color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 3px 8px; display: flex; gap: 6px; align-items: baseline; overflow: hidden; }
.tool .name { color: var(--text); font-weight: 600; }
.tool .sum { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool.err { color: var(--fail); }
.tool.running .name::after { content: " …"; }
details.thinking { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
details.thinking pre { white-space: pre-wrap; font-family: inherit; margin: 4px 0 0; max-height: 200px; overflow-y: auto; }

.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--surface); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--bg); max-height: 160px; }
.btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.icon { padding: 6px 9px; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.ok { background: var(--pass); color: #fff; border-color: var(--pass); }
.btn.danger { color: var(--fail); }

.panel { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.tabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--border); background: var(--surface); }
.tabs button { border: none; background: none; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.badge { background: var(--warn); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 6px; margin-left: 2px; }
.tab-body { flex: 1; overflow-y: auto; padding: 14px; }
.tab { display: none; }
.tab.active { display: block; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.card h4 { margin: 10px 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th, table.data td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }

.status { display: inline-block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; padding: 1px 7px; border-radius: 9px; }
.status.pass, .status.finished, .status.applied { background: var(--pass-bg); color: var(--pass); }
.status.warn, .status.pending, .status.queued, .status.running { background: var(--warn-bg); color: var(--warn); }
.status.fail, .status.failed, .status.rejected, .status.timed_out, .status.lost, .status.conflict { background: var(--fail-bg); color: var(--fail); }
.status.info, .status.cancelled, .status.stale { background: var(--info-bg); color: var(--info); }
.items { list-style: none; padding: 0; margin: 0; }
.items li { display: grid; grid-template-columns: 12px 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.items li:last-child { border-bottom: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; }
.dot.pass { background: var(--pass); } .dot.warn { background: var(--warn); } .dot.fail { background: var(--fail); } .dot.info { background: var(--info); }
.items .check { font-weight: 600; }
.items details { font-size: 12px; color: var(--muted); }
.items details pre { white-space: pre-wrap; font-family: var(--mono); font-size: 11.5px; max-height: 220px; overflow: auto; background: var(--code-bg); padding: 6px; border-radius: 6px; }

.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--accent); }
pre.diff { font-family: var(--mono); font-size: 12px; background: var(--code-bg); border-radius: 6px; padding: 8px; overflow-x: auto; margin: 6px 0; }
pre.diff .add { background: var(--diff-add); display: block; }
pre.diff .del { background: var(--diff-del); display: block; }
pre.diff .hunk { color: var(--info); display: block; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.chart-wrap { position: relative; height: 240px; margin-top: 8px; }
.placeholder { color: var(--muted); padding: 20px 4px; text-align: center; }
.report-body { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; }
.drop-hint { position: fixed; inset: 0; background: rgba(19,78,94,.12); border: 3px dashed var(--accent); display: none; align-items: center; justify-content: center; font-size: 18px; font-weight: 600; pointer-events: none; z-index: 10; }
body.dragging .drop-hint { display: flex; }
.media { margin: 6px 0 8px; }
.media img { max-width: 100%; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: zoom-in; display: block; }
.media .cap { font-size: 12px; color: var(--muted); margin-top: 3px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.gallery .item { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
.gallery img { width: 100%; border-radius: 6px; background: #fff; cursor: zoom-in; display: block; }
.gallery .t { font-size: 12px; margin-top: 4px; }
.gallery .cube { height: 120px; border-radius: 6px; background: linear-gradient(135deg, var(--info-bg), var(--surface-2)); display: flex; align-items: center; justify-content: center; font-size: 30px; }
.report-body img { max-width: 100%; }
details.analysis { font-size: 12px; }
details.analysis summary { cursor: pointer; color: var(--muted); }
details.analysis pre { white-space: pre-wrap; font-family: var(--mono); font-size: 11.5px; max-height: 320px; overflow: auto; background: var(--code-bg); padding: 8px; border-radius: 6px; margin: 4px 0 0; }

/* sign-in */
.user-ctl { display: flex; align-items: center; gap: 8px; margin-left: 12px; font-size: 12.5px; }
.user-ctl[hidden], .login[hidden] { display: none; }
.login { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 28px 32px; max-width: 380px; width: 100%; text-align: center; }
.login-card h1 { font-size: 18px; margin: 0 0 6px; }
.login-card #googleBtn { display: flex; justify-content: center; margin: 18px 0 6px; min-height: 44px; }
.login-msg { color: var(--fail); font-size: 13px; min-height: 1.2em; margin: 8px 0 0; }
