:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #16191f;
  --muted: #6b7280;
  --faint: #9aa1ac;
  --accent: #2f6fed;
  --accent-hover: #2459c9;
  --accent-soft: #eaf1fe;
  --ok: #17803d;
  --ok-soft: #e7f6ec;
  --warn: #a15c07;
  --warn-soft: #fdf3e2;
  --danger: #c4302b;
  --danger-soft: #fdecec;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
p { margin: 0; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; overflow-x: auto; margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 2px 8px; font-weight: 650; font-size: 14px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo { width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; }
.account-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.account-box .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 6px;
  color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .ico { width: 16px; text-align: center; opacity: .75; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.sidebar-footer { margin-top: auto; }
.content { padding: 28px 36px 48px; max-width: 1000px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-head p { margin-top: 4px; color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }
.back { display: inline-block; color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 360px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 16px 18px; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card-head p { color: var(--muted); font-size: 12.5px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); background: #fafbfc; border-radius: 0 0 var(--radius) var(--radius); display: flex; gap: 8px; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }

/* ---------- forms ---------- */
.field { display: block; }
.field > .label { display: block; font-weight: 500; margin-bottom: 5px; }
.field > .hint { display: block; color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.input, .textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 6px; padding: 7px 10px; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.textarea { resize: vertical; min-height: 120px; line-height: 1.55; }
.textarea.tall { min-height: 380px; }
.input-group { display: flex; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .addon {
  border: 1px solid var(--border-strong); border-left: 0; background: var(--bg); color: var(--muted);
  padding: 7px 10px; border-radius: 0 6px 6px 0; white-space: nowrap;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 500;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 6px; cursor: pointer; white-space: nowrap; line-height: 1.4;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: #f1b5b2; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
form.inline { display: inline; margin: 0; }

/* ---------- switch ---------- */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input {
  appearance: none; -webkit-appearance: none; width: 32px; height: 18px; border-radius: 9px; margin: 0;
  background: var(--border-strong); position: relative; cursor: pointer; transition: background .15s; flex-shrink: 0;
}
.switch input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }

/* ---------- status ---------- */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--faint); flex-shrink: 0; }
.dot.running { background: #22a352; box-shadow: 0 0 0 3px #d6f2e0; }
.dot.connecting { background: #e5a00d; }
.dot.error { background: var(--danger); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

.status-hero { display: flex; align-items: center; gap: 14px; }
.status-hero .state { font-size: 16px; font-weight: 600; }
.status-hero .actions { margin-left: auto; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--border); }
.stat { padding: 12px 18px; }
.stat + .stat { border-left: 1px solid var(--border); }
.stat .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--muted); font-size: 12px; }

/* ---------- alerts ---------- */
.alert { padding: 10px 14px; border-radius: 6px; background: var(--accent-soft); color: #1f4fb3; border: 1px solid #cfdefc; }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: #c4e8d1; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: #f4dcb1; }
.alert.error { background: var(--danger-soft); color: var(--danger); border-color: #f5c6c4; }
.flashes { margin-bottom: 16px; }
.flashes .alert + .alert { margin-top: 8px; }

/* ---------- checklist ---------- */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; align-items: center; gap: 12px; padding: 11px 18px; }
.checklist li + li { border-top: 1px solid var(--border); }
.checklist .mark {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 11px;
  border: 1.5px solid var(--border-strong); color: transparent; flex-shrink: 0;
}
.checklist li.done .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.checklist li.done .t { color: var(--muted); }
.checklist .t { font-weight: 500; }
.checklist .d { color: var(--muted); font-size: 12.5px; }
.checklist .go { margin-left: auto; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; }
.list-item + .list-item { border-top: 1px solid var(--border); }
.list-item .main { min-width: 0; flex: 1; }
.list-item .title { font-weight: 600; color: var(--text); }
.list-item .sub { color: var(--muted); font-size: 12.5px; }
.list-item.off .title, .list-item.off .avatar { opacity: .5; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 600; font-size: 13px; flex-shrink: 0;
}
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }
.empty { padding: 32px 18px; text-align: center; color: var(--muted); }
.empty .t { color: var(--text); font-weight: 600; margin-bottom: 4px; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 96px 130px 84px 1fr; gap: 10px; padding: 8px 18px; align-items: baseline; }
.feed li + li { border-top: 1px solid var(--border); }
.feed .time { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.feed .who { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .text { white-space: pre-wrap; word-break: break-word; }
.feed li.k-error .text { color: var(--danger); }
.feed li.k-system .text, .feed li.k-skip .text { color: var(--muted); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a { padding: 5px 12px; border-radius: 999px; color: var(--muted); font-weight: 500; font-size: 13px; }
.tabs a:hover { background: var(--surface); text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); }

/* ---------- steps ---------- */
.steps { display: flex; gap: 6px; margin-bottom: 18px; }
.steps .s { flex: 1; font-size: 12px; color: var(--faint); padding-top: 8px; border-top: 3px solid var(--border); }
.steps .s.on { color: var(--accent); border-color: var(--accent); font-weight: 500; }
.steps .s.done { color: var(--muted); border-color: #9ec0fa; }

/* ---------- preview ---------- */
.bubble { background: var(--accent-soft); border-radius: 12px 12px 4px 12px; padding: 8px 12px; max-width: 90%; margin-left: auto; white-space: pre-wrap; width: fit-content; }
.bubble.them { background: var(--bg); border-radius: 12px 12px 12px 4px; margin-left: 0; color: var(--muted); }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-flex; }
.htmx-request.btn { opacity: .7; pointer-events: none; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

details.danger-zone summary { cursor: pointer; color: var(--muted); font-size: 12.5px; list-style: none; }
details.danger-zone summary::-webkit-details-marker { display: none; }
details.danger-zone[open] summary { margin-bottom: 10px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .content { padding: 20px 16px 40px; }
  .split, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .feed li { grid-template-columns: 70px 1fr; }
  .feed .who, .feed .kind { display: none; }
}
