:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4ea;
  --text: #16191f;
  --muted: #5d6573;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefb;
  --ok: #1d7a4a;
  --ok-soft: #e4f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --err: #b42318;
  --err-soft: #fde8e6;
  --user: #16191f;
  --user-ink: #ffffff;
  --radius: 10px;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a20; --surface-2: #1f232b; --border: #2b303a;
    --text: #e8eaee; --muted: #9aa2b1; --accent: #6ea2ff; --accent-ink: #0b1220;
    --accent-soft: #1b2740; --ok: #5cc98d; --ok-soft: #15291f; --warn: #f0b45a;
    --warn-soft: #2e2414; --err: #ff8a7d; --err-soft: #331a18; --user: #e8eaee; --user-ink: #0f1115;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, system-ui, sans-serif;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
h1 { font-size: 16px; margin: 0; font-weight: 600; }
h2 { font-size: 13px; margin: 0; font-weight: 600; }
.sub { margin: 0; color: var(--muted); font-size: 12px; }
.identity { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.identity label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
.identity input { width: 150px; }

input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 9px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 7px;
  padding: 8px 14px; font-weight: 500; cursor: pointer;
}
button:disabled { opacity: .5; cursor: progress; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }

.layout {
  display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr);
  gap: 16px; padding: 16px 20px; height: calc(100vh - 64px);
}
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-h { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.hint { color: var(--muted); font-size: 11px; }

.chat { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 92%; }
.msg .who { font: 11px var(--mono); color: var(--muted); margin-bottom: 3px; }
.msg.user { align-self: flex-end; }
.msg.user .bubble { background: var(--user); color: var(--user-ink); }
.bubble { background: var(--surface-2); border-radius: var(--radius); padding: 10px 14px; overflow-x: auto; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; font-variant-numeric: tabular-nums; }
.bubble th { background: var(--surface); }
.bubble pre { background: var(--surface); padding: 10px; border-radius: 7px; overflow-x: auto; font: 12px/1.45 var(--mono); }
.bubble code { font-family: var(--mono); font-size: 12px; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 14px; margin: 10px 0 4px; }
.typing { color: var(--muted); font-style: italic; }

.suggestions { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 16px 8px; }
.chip {
  background: var(--accent-soft); color: var(--accent); border: 0; border-radius: 999px;
  padding: 5px 11px; font-size: 12px; font-weight: 500;
}
.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.composer textarea { resize: none; }

.side { display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 16px; min-height: 0; }
.activity { display: flex; flex-direction: column; min-height: 0; }
.activity-list { list-style: none; margin: 0; padding: 8px 10px; overflow-y: auto; font-size: 12px; flex: 1; }
.activity-list li { padding: 6px 8px; border-radius: 6px; margin-bottom: 4px; background: var(--surface-2); }
.activity-list li .k { font: 11px var(--mono); color: var(--muted); }
.activity-list li pre { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; font: 11px/1.4 var(--mono); max-height: 120px; overflow-y: auto; }
.activity-list li.route { background: var(--accent-soft); }
.activity-list li.blocked { background: var(--err-soft); color: var(--err); }
.activity-list li.ok { background: var(--ok-soft); }
.activity-list li.confirm-req { background: var(--warn-soft); color: var(--warn); }

.forms { padding-bottom: 6px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { background: none; color: var(--muted); border-radius: 0; border-bottom: 2px solid transparent; padding: 10px 12px; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.pane { display: none; padding: 12px 14px; gap: 8px; flex-direction: column; }
.pane.active { display: flex; }
.pane label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.status { margin: 0 14px 8px; font-size: 12px; min-height: 18px; }
.status.ok { color: var(--ok); } .status.err { color: var(--err); }
.table-wrap { max-height: 260px; overflow: auto; }
#recentTable { width: 100%; border-collapse: collapse; font-size: 12px; }
#recentTable th, #recentTable td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--border); }

.confirm { border: 1px solid var(--warn); background: var(--warn-soft); border-radius: var(--radius); padding: 12px 14px; }
.confirm-h { font-weight: 600; margin-bottom: 6px; color: var(--warn); }
.confirm dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 0 0 10px; font-size: 13px; }
.confirm dt { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.confirm dd { margin: 0; }
.confirm-actions { display: flex; gap: 8px; }
.confirm.done { opacity: .65; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; padding: 12px 16px; }
  .chat { height: 70vh; }
  .side { grid-template-rows: auto auto; }
  .activity-list { max-height: 260px; }
  .identity input { width: 120px; }
}
@media (max-width: 900px) {
  .suggestions { flex-wrap: nowrap; overflow-x: auto; }
  .chip { white-space: nowrap; }
}
