:root {
  --bg: #f6f5f3;
  --panel: #ffffff;
  --ink: #1d1b19;
  --muted: #6f6a64;
  --line: #e6e2dc;
  --accent: #8b2c4a;
  --accent-soft: #f4e6eb;
  --ok: #1f7a4d;
  --ok-soft: #e3f3ea;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514; --panel: #201f1d; --ink: #eeebe7; --muted: #a29b93; --line: #34312e;
    --accent: #e07a9a; --accent-soft: #3a2129; --ok: #5cc890; --ok-soft: #173426;
    --warn: #e6b45a; --warn-soft: #3a2e15; --bad: #f2877d; --bad-soft: #3d1c19;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1em; }
code { background: var(--bg); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; font-size: 12px; word-break: break-all; }

#app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav a { padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); user-select: none; }
nav a:hover { background: var(--bg); color: var(--ink); }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main { padding: 28px 32px 60px; max-width: 1100px; width: 100%; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stat .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--muted); font-size: 12px; }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 12px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--ink); font-size: 13px; }
form.stack { gap: 12px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.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); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }

.item { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.item + .item { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.item .title { font-weight: 600; font-size: 15px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.flow { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: center; gap: 8px; text-align: center; }
.flow .node { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--bg); }
.flow .node b { display: block; }
.flow .arrow { color: var(--muted); font-size: 18px; }

.events { max-height: 360px; overflow: auto; font-size: 12px; }
.events div { padding: 6px 0; border-bottom: 1px dashed var(--line); display: grid; grid-template-columns: 130px 1fr; gap: 10px; }
.events .error-l { color: var(--bad); }
.events .warn-l { color: var(--warn); }

.log { display: grid; grid-template-columns: 320px 1fr; gap: 14px; min-height: 520px; }
.chatlist { overflow: auto; max-height: 70vh; padding: 0; }
.chatlist .c { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.chatlist .c:hover, .chatlist .c.active { background: var(--accent-soft); }
.chatlist .c .name { font-weight: 600; }
.chatlist .c .last { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bubbles { display: flex; flex-direction: column; gap: 8px; overflow: auto; max-height: 64vh; }
.bubble { max-width: 75%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { background: var(--bg); border: 1px solid var(--line); align-self: flex-start; }
.bubble.out { background: var(--accent-soft); align-self: flex-end; }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.bubble.failed { outline: 1px solid var(--bad); }

.qr { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 10px; }
.qr img { width: 264px; height: 264px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px; background: var(--panel); color: var(--ink); width: min(460px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }

.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: min(360px, 92vw); display: flex; flex-direction: column; gap: 14px; }

.toast { position: fixed; bottom: 22px; right: 22px; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: 420px; z-index: 10; box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); color: #fff; }

.notice { border-left: 3px solid var(--warn); background: var(--warn-soft); padding: 10px 14px; border-radius: 6px; font-size: 13px; }
.notice.info { border-color: var(--accent); background: var(--accent-soft); }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  nav { flex-direction: row; flex-wrap: wrap; }
  main { padding: 18px; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-2, .log { grid-template-columns: 1fr; }
  .flow { grid-template-columns: 1fr; }
  .flow .arrow { transform: rotate(90deg); }
}

.whoami { border-top: 1px solid var(--line); padding-top: 12px; }
.whoami #whoName { font-weight: 600; }
.readonly { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); border: 1px dashed var(--line); border-radius: 999px; padding: 3px 10px; }
.steps { counter-reset: s; display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; }
.steps li::before { content: counter(s); width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: 12px; }
