:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #eeeeec;
  --text: #1d1d1f;
  --dim: #6e6e73;
  --border: #dedede;
  --accent: #2f6f4e;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --warn: #9a6700;
  --ok: #2f7d32;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111213;
    --surface: #1a1b1d;
    --surface-2: #232427;
    --text: #ececee;
    --dim: #9a9aa0;
    --border: #2e2f33;
    --accent: #5fbf8a;
    --accent-text: #0d1a12;
    --danger: #ff8a80;
    --warn: #ffd166;
    --ok: #7bd389;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.dim { color: var(--dim); }
.error { color: var(--danger); min-height: 1.2em; }
.mono, code, pre { font-family: var(--mono); }
input, select, textarea, button {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
input, textarea { min-width: 0; }
textarea { width: 100%; resize: vertical; }
button { cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
.ghost-button { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: pointer; white-space: nowrap; }
.ghost-button:hover { border-color: var(--accent); }
.answer { line-height: 1.6; }
button.danger { color: var(--danger); }
button:disabled { opacity: .6; cursor: wait; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.row > input:first-child { flex: 1 1 220px; }
.check { display: inline-flex; gap: 6px; align-items: center; color: var(--dim); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }

header {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav button { border: none; background: transparent; color: var(--dim); white-space: nowrap; }
nav button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.badge { background: var(--warn); color: #000; border-radius: 10px; padding: 0 6px; font-size: 12px; }
main { max-width: 1100px; margin: 0 auto; padding: 16px 20px 40px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { margin: 0; }

.chat-log { display: flex; flex-direction: column; gap: 10px; min-height: 50vh; padding-bottom: 8px; }
.msg { max-width: 80%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg pre { background: var(--surface-2); padding: 8px 10px; border-radius: 6px; overflow-x: auto; margin: 6px 0; white-space: pre; }
.msg code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
.msg .katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.msg .katex { font-size: 1.08em; }
.msg a { color: var(--accent); }
.msg.glasses { font-family: var(--mono); background: #000; color: #3cfa44; border-color: #000; }
.msg.pending { color: var(--dim); font-style: italic; }
.msg.err { border-color: var(--danger); color: var(--danger); }
.chat-form { position: sticky; bottom: 0; background: var(--bg); padding-top: 8px; }
.chat-form .row { justify-content: flex-end; }
.chat-form .check { margin-right: auto; }

.list { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.list li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; display: flex; gap: 10px; align-items: flex-start; }
.list li .body { flex: 1; min-width: 0; }
.list li .meta { color: var(--dim); font-size: 13px; }
.list li .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.list li .actions button { padding: 4px 10px; font-size: 13px; }
.list.compact li { padding: 6px 10px; font-size: 13px; }
.list li.clickable { cursor: pointer; }
.list li.selected { border-color: var(--accent); }
.tag { display: inline-block; font-size: 12px; padding: 0 6px; border-radius: 6px; background: var(--surface-2); color: var(--dim); margin-right: 4px; }
.tag.high { background: var(--danger); color: #fff; }
.tag.private { background: var(--warn); color: #000; }
.status-sent, .status-acked { color: var(--ok); }
.status-failed, .status-dead { color: var(--danger); }

.split { display: grid; grid-template-columns: 280px 1fr; gap: 12px; margin-top: 12px; }
.detail pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.lens { background: #000; color: #3cfa44; font-family: var(--mono); border-radius: 8px; padding: 10px; white-space: pre-wrap; font-size: 13px; width: 100%; max-width: 576px; }
.blocks { display: flex; flex-direction: column; gap: 6px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.grid .wide { grid-column: 1 / -1; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
dt { color: var(--dim); }
dd { margin: 0; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td, th { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.bar > span { display: block; height: 100%; background: var(--accent); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 10; max-width: calc(100% - 32px); }

@media (max-width: 700px) {
  header { padding: 8px 12px; }
  main { padding: 12px 16px 32px; }
  .split { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
  .list li { flex-direction: column; }
  .list li .actions { justify-content: flex-start; }
}
