:root {
  --bg: #060d16;
  --panel: #0d1826;
  --panel-2: #111f31;
  --line: #1e3149;
  --text: #dce7f3;
  --muted: #7d93ab;
  --accent: #38bdf8;
  --accent-dim: #0b5f80;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.mono, .pre { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* ── top bar ─────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 11px; }
.logo { width: 34px; height: 34px; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.brand-name span { color: var(--accent); }
.brand-sub { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.09em; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-label { font-size: 13px; color: var(--muted); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
}
.badge.ok   { color: var(--ok);   border-color: #135e43; }
.badge.warn { color: var(--warn); border-color: #6b4c10; }
.badge.bad  { color: var(--bad);  border-color: #6f2626; }

/* ── buttons ─────────────────────────────────────────────────────────── */

.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent-dim); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #04121d; }
.btn-danger  { background: #2a1113; border-color: #6f2626; color: var(--bad); }
.btn-block   { display: block; width: 100%; margin-bottom: 10px; }

/* ── layout ──────────────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 330px;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 56px);
}
@media (max-width: 1200px) { .layout { grid-template-columns: 1fr; height: auto; } }

.sidebar, .inspector { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  display: inline;
}
details.panel > summary { cursor: pointer; list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before { content: "▸ "; color: var(--muted); }
details.panel[open] > summary::before { content: "▾ "; }
details.panel > summary h2 { margin: 0; }
details.panel[open] > div, details.panel[open] > pre { margin-top: 10px; }

.hint { font-size: 11.5px; color: var(--muted); margin: 8px 0 0; }
.muted { color: var(--muted); }

/* ── controls ────────────────────────────────────────────────────────── */

.field { display: block; margin-top: 8px; font-size: 12px; color: var(--muted); }
.field span { display: block; margin-bottom: 4px; }
.field select {
  width: 100%;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
}

.mode-group { display: flex; flex-direction: column; gap: 3px; }
.mode-group label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.mode-group label:hover { background: var(--panel-2); }
.mode-group input { accent-color: var(--accent); }

.conversation-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.conversation-list li { font-size: 12.5px; }
.conversation-list button {
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
}
.conversation-list button:hover { background: var(--panel-2); }
.conversation-list button.active { border-color: var(--accent-dim); background: var(--panel-2); }
.conversation-list .meta { display: block; font-size: 10.5px; color: var(--muted); }

/* ── chat ────────────────────────────────────────────────────────────── */

.chat { display: flex; flex-direction: column; min-height: 0; gap: 12px; }

.transcript {
  flex: 1;
  min-height: 320px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.welcome { max-width: 620px; margin: auto; text-align: center; }
.welcome h1 { font-size: 21px; margin: 0 0 10px; }
.welcome p { color: var(--muted); font-size: 13.5px; }

.msg { max-width: 88%; padding: 11px 13px; border-radius: var(--radius); font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent-dim); color: #eaf6fd; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); }
.msg.system { align-self: center; max-width: 100%; font-size: 12.5px; }
.msg.system.denied  { background: #2a1f08; border: 1px solid #6b4c10; color: #f5d99a; }
.msg.system.failed  { background: #2a1113; border: 1px solid #6f2626; color: #f6b8b8; }
.msg.system.pending { background: #0b2436; border: 1px solid var(--accent-dim); color: #b9e6fb; }
.msg .msg-head { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 5px; }
.msg .msg-foot { font-size: 10.5px; color: var(--muted); margin-top: 7px; border-top: 1px solid rgba(255,255,255,0.07); padding-top: 5px; }

.composer { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px; }
.composer textarea {
  width: 100%;
  resize: vertical;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 9px; }
.composer-status { font-size: 12px; color: var(--muted); }
.composer-status.working::before { content: "● "; color: var(--accent); }

/* ── inspector ───────────────────────────────────────────────────────── */

.facts { margin: 0; font-size: 12.5px; }
.facts > div { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.facts dt { color: var(--muted); flex: 0 0 auto; }
.facts dd { margin: 0; text-align: right; word-break: break-all; }
.facts dd.mono { font-size: 11px; }

.approval-prompt { font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px; white-space: pre-wrap; }
.approval-actions { display: flex; gap: 8px; }
.approval-actions .btn { flex: 1; }

.routing-detail { font-size: 12.5px; }
.routing-detail h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 12px 0 5px; }
.routing-detail table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.routing-detail td { padding: 3px 4px; vertical-align: top; border-bottom: 1px solid rgba(255,255,255,0.05); }
.routing-detail td:first-child { color: var(--accent); white-space: nowrap; }
.routing-detail .reason { color: var(--warn); white-space: nowrap; }

.pre { font-size: 11px; white-space: pre-wrap; word-break: break-all; margin: 0; max-height: 260px; overflow-y: auto; }

.model-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.model-row .id { font-weight: 600; }
.model-row .why { color: var(--muted); font-size: 11px; text-align: right; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--muted); }

/* ── toast ───────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #2a1113;
  border: 1px solid #6f2626;
  color: #f6b8b8;
  padding: 10px 16px;
  border-radius: 9px;
  font-size: 13px;
  max-width: 640px;
  z-index: 50;
}
