:root {
  --bg: #f5f6f8; --surface: #ffffff; --text: #1b1f24; --muted: #667080; --border: #e2e5ea;
  --accent: #128c7e; --accent-text: #ffffff; --danger: #c62828; --warn: #b26a00; --ok: #1b873f;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1216; --surface: #171b21; --text: #e6e9ee; --muted: #93a0b0; --border: #2a313a;
    --accent: #25d366; --accent-text: #08130c; --danger: #ef5350; --warn: #ffb74d; --ok: #4caf50; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
code { font-size: .9em; background: var(--border); padding: 1px 5px; border-radius: 4px; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 400; color: var(--muted); font-size: 13px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); display: inline-block; }
.top-actions { display: flex; gap: 8px; }
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; }
.card.narrow { max-width: 420px; margin: 60px auto; }
h1, h2, h3 { margin: 0 0 12px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
.muted { color: var(--muted); } .center { text-align: center; } .error { color: var(--danger); }
input, select { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
button { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 500; }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); font-weight: 500; }
button.small { padding: 5px 10px; font-size: 13px; }
form { display: flex; flex-direction: column; gap: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; }
.form-actions { display: flex; }
.list-header { display: flex; justify-content: space-between; align-items: baseline; margin: 8px 0 10px; }
.instances { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.inst { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.inst-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.inst-name { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.inst-meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.st-open { color: var(--ok); } .st-qr, .st-connecting { color: var(--warn); } .st-close, .st-logged_out { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 32px)); padding: 18px 20px; }
dialog::backdrop { background: rgba(0,0,0,.5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 0; }
.qr-box img { width: 280px; max-width: 100%; background: #fff; padding: 8px; border-radius: 8px; }
.pairing { font-size: 28px; font-weight: 700; letter-spacing: 4px; font-family: ui-monospace, monospace; }
.msgs { max-height: 50vh; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.msg { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; overflow-wrap: anywhere; }
.msg.me { border-color: var(--accent); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; max-width: calc(100vw - 32px); z-index: 10; }
@media (max-width: 480px) { .brand small { display: none; } }
