:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --text: #161a26;
  --muted: #5c6378;
  --border: #e2e5ee;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --ok: #0f7b4b;
  --ok-soft: #e6f6ee;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b24;
    --surface-2: #1e2330;
    --text: #e8eaf0;
    --muted: #9aa1b5;
    --border: #2a3040;
    --accent: #8b85ff;
    --accent-text: #0f1218;
    --accent-soft: #24234a;
    --ok: #5fd39a;
    --ok-soft: #12321f;
    --warn: #f3b25a;
    --warn-soft: #3a2a10;
    --bad: #ff8a7f;
    --bad-soft: #3d1715;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0; }
code, pre { font-family: var(--mono); font-size: .85rem; }
pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
  max-height: 420px;
  overflow: auto;
}
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 16px; }
.mt { margin-top: 16px; }
.mt-sm { margin-top: 12px; }
.mb-sm { margin-bottom: 12px; }
.grow { flex: 1; }
.grid.two-one { grid-template-columns: 2fr 1fr; }
.grid.wide-cards { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px 18px; }
.brand img { width: 28px; height: 28px; }
.brand strong { display: block; font-size: .95rem; }
.brand span { display: block; font-size: .75rem; color: var(--muted); }
.nav a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar .me { margin-top: auto; padding: 8px 10px; font-size: .85rem; color: var(--muted); }
.main { padding: 28px 32px 48px; max-width: 1200px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin-top: 4px; }

/* cards and grids */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card h2 { margin-bottom: 12px; }
.stat .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 600; margin-top: 4px; }
.stat .value.small { font-size: 1.05rem; overflow-wrap: anywhere; }
.stat .sub { font-size: .85rem; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.bar > span { display: block; height: 100%; background: var(--accent); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--surface-2); }
td.nowrap { white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* forms */
label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: 6px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.fields { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.field.wide { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; }
button, .button {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button:disabled { opacity: .55; cursor: not-allowed; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; }
.segmented button.on { background: var(--accent); color: var(--accent-text); }

/* transcript */
.transcript { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 78%; padding: 10px 13px; border-radius: 12px; background: var(--surface-2); }
.bubble.user { align-self: flex-end; background: var(--accent-soft); }
.bubble .who { font-size: .72rem; color: var(--muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .04em; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* sign-in */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { margin: 14px 0 4px; }
.login form > * + * { margin-top: 14px; }
.login button { width: 100%; padding: 10px; }
.error { color: var(--bad); font-size: .88rem; }
.notice {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--text);
  margin-bottom: 16px;
}
.notice.bad { background: var(--bad-soft); }
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-weight: 500;
  z-index: 10;
}
.result { border-left: 3px solid var(--accent); padding-left: 12px; }
.result + .result { margin-top: 16px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { padding-bottom: 0; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .sidebar .me { margin-top: 0; }
  .main { padding: 20px 16px 40px; }
  .bubble { max-width: 92%; }
  .grid.two-one { grid-template-columns: 1fr; }
}
