:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #128c7e;
  --accent-text: #ffffff;
  --ok-bg: #e7f6ec;
  --ok-text: #14532d;
  --warn-bg: #fff7e0;
  --warn-text: #7a4b00;
  --err-bg: #fdecec;
  --err-text: #991b1b;
  --bubble-out: #d9fdd3;
  --bubble-out-text: #0b3d1e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #171a21;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: #2a2f3a;
    --accent: #25d366;
    --accent-text: #0b1f14;
    --ok-bg: #12291b;
    --ok-text: #bbf7d0;
    --warn-bg: #2b2210;
    --warn-text: #fde68a;
    --err-bg: #2d1414;
    --err-text: #fecaca;
    --bubble-out: #144d37;
    --bubble-out-text: #e7fbe9;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
p { margin: 0 0 12px; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; max-width: 1080px; margin: 0 auto; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand img { width: 30px; height: 30px; }
.shell { max-width: 1080px; margin: 0 auto; padding: 0 16px 32px; }

.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 780px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.stack { display: grid; gap: 16px; min-width: 0; }

.panel, .card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; }
.card { max-width: 440px; margin: 40px auto; padding: 28px; }
.hint { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); font-size: 14px; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: inherit; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--err-text); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.full { width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }

form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 500; }
input[type="text"], input[type="tel"], input[type="password"], textarea, select {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
}
textarea { resize: vertical; min-height: 72px; }
.choice { display: flex; gap: 8px; flex-wrap: wrap; }
.choice label { display: flex; align-items: center; gap: 6px; font-weight: 500; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; cursor: pointer; }

.banner { border-radius: 10px; padding: 10px 14px; font-size: 14px; margin-bottom: 16px; word-break: break-word; }
.banner.ok { background: var(--ok-bg); color: var(--ok-text); }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner.err { background: var(--err-bg); color: var(--err-text); }

.accounts { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.accounts button { width: 100%; text-align: left; display: grid; gap: 2px; border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; background: var(--card); color: var(--text); cursor: pointer; font-family: inherit; }
.accounts button.active { border-color: var(--accent); }
.accounts .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.accounts .sub { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.connected { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.pill.pairing, .pill.reconnecting { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.pill.logged_out, .pill.pairing_failed, .pill.blocked { background: var(--err-bg); color: var(--err-text); border-color: transparent; }

.pair { text-align: center; }
.pair .code { font-family: ui-monospace, Consolas, monospace; font-size: 34px; letter-spacing: 4px; font-weight: 700; margin: 12px 0; }
.pair img { width: 260px; height: 260px; max-width: 100%; background: #fff; padding: 8px; border-radius: 10px; }
.steps { text-align: left; font-size: 14px; margin: 12px 0 0; padding-left: 20px; }
.steps li { margin-bottom: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-size: 13px; background: var(--card); color: var(--text); cursor: pointer; font-family: inherit; }
.chip.active { border-color: var(--accent); background: var(--ok-bg); color: var(--ok-text); }

.thread { display: flex; flex-direction: column; gap: 8px; height: 420px; overflow-y: auto; padding: 12px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.bubble { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 14px; border: 1px solid var(--border); background: var(--card); align-self: flex-start; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-text); border-color: transparent; }
.bubble .text { white-space: pre-wrap; word-break: break-word; }
.bubble .meta { font-size: 11px; opacity: 0.7; margin-top: 4px; }
.composer { display: flex; gap: 8px; }
.composer textarea { min-height: 44px; flex: 1; }
.thread-head { justify-content: space-between; margin-bottom: 12px; }
.thread-head h2 { margin: 0; }
