* { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; }
body {
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #1f2933; background: #f4f6f8;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }
button, .btn {
  display: inline-block; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer;
  background: #2563eb; color: #fff; line-height: 1.3; text-decoration: none;
}
.btn:hover { text-decoration: none; }
button.ghost, .btn.ghost { background: #e5e9ef; color: #1f2933; }
button.danger { background: #fee2e2; color: #991b1b; }
button.tiny, .btn.tiny { padding: 2px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input:not([type=checkbox]), select {
  width: 100%; padding: 6px 8px; border: 1px solid #cbd2d9; border-radius: 6px; background: #fff;
}
label { display: block; margin-bottom: 10px; font-size: 13px; color: #52606d; }
label.check { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
label .help { display: block; font-size: 12px; color: #7b8794; }
fieldset { border: 1px solid #e5e9ef; border-radius: 6px; padding: 8px 12px; margin: 0 0 10px; }
legend { font-size: 13px; color: #52606d; padding: 0 4px; }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: #52606d; margin: 0 0 10px; }
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: #eef2f6; padding: 1px 4px; border-radius: 4px; }
pre { white-space: pre-wrap; word-break: break-all; }
.muted { color: #7b8794; }
.small { font-size: 12px; }
.ok { color: #166534; font-weight: 600; }

.top {
  display: flex; align-items: center; gap: 24px; padding: 10px 24px;
  background: #fff; border-bottom: 1px solid #d9e2ec;
}
.brand { font-weight: 700; }
.brand a { color: inherit; }
.brand .ws { font-weight: 400; color: #52606d; }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a { padding: 4px 10px; border-radius: 6px; color: #52606d; }
.top nav a.on { background: #dbeafe; color: #1e40af; }
.top nav a:hover { background: #f0f4f8; text-decoration: none; }
.top .user { display: flex; align-items: center; gap: 10px; }
.top .user select { width: auto; }
.banner { background: #fef3c7; color: #92400e; padding: 8px 24px; border-bottom: 1px solid #fde68a; }
main { max-width: 1080px; margin: 0 auto; padding: 20px 24px 40px; }
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.flash { padding: 10px 14px; border-radius: 6px; background: #dcfce7; color: #166534; margin-bottom: 14px; }
.flash.err { background: #fee2e2; color: #991b1b; }

.card { background: #fff; border: 1px solid #e5e9ef; border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.card.narrow { max-width: 520px; margin: 40px auto; }
.card.reveal { border-color: #86efac; background: #f0fdf4; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); margin-bottom: 16px; }
.cards .card { margin: 0; }
.grid2 { display: grid; gap: 16px; grid-template-columns: 2fr 1fr; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.actions { margin-top: 10px; }
.row.actions form { margin: 0; }
form.inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
form.inline label { margin: 0; flex: 1; min-width: 200px; }
form.inline button { margin-bottom: 1px; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; background: #e0e7ff; color: #3730a3; font-size: 12px; margin-right: 6px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; background: #e5e9ef; color: #52606d; }
.badge.st-connected { background: #dcfce7; color: #166534; }
.badge.st-connecting, .badge.st-new { background: #dbeafe; color: #1e40af; }
.badge.st-login_required, .badge.st-disconnected { background: #fef3c7; color: #92400e; }
.badge.st-logged_out, .badge.off { background: #fee2e2; color: #991b1b; }
.token { display: inline-block; padding: 6px 10px; font-size: 13px; user-select: all; word-break: break-all; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #eef2f6; vertical-align: top; }
th { font-size: 12px; color: #52606d; font-weight: 600; }
tr.off td { color: #9aa5b1; }
tr.bad td { background: #fff7f7; }
.qr { display: block; width: 260px; height: 260px; margin: 8px 0; padding: 8px; background: #fff; border: 1px solid #cbd2d9; border-radius: 6px; image-rendering: pixelated; }

/* ---- simulator ---- */
main:has(.sim-page) { max-width: 1480px; }
.sim { display: grid; gap: 16px; grid-template-columns: 240px minmax(0, 1fr) 380px; align-items: start; }
@media (max-width: 1100px) { .sim { grid-template-columns: 1fr; } }
.sim .card { margin: 0; }
.sim-chats .chat { display: block; padding: 8px; border-radius: 6px; color: inherit; cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.sim-chats .chat:hover { background: #f0f4f8; text-decoration: none; }
.sim-chats .chat.on { background: #dbeafe; }
.sim-chats .chat .t { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.sim-chats .chat .t time { font-weight: 400; color: #7b8794; font-size: 11px; white-space: nowrap; }
.sim-chats .chat .p { color: #7b8794; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sim-chat-head { padding-bottom: 8px; border-bottom: 1px solid #eef2f6; margin-bottom: 8px; }
.timeline { display: flex; flex-direction: column; gap: 8px; min-height: 240px; max-height: 60vh; overflow-y: auto; padding: 4px 2px; }
.msg { max-width: 78%; padding: 8px 10px; border-radius: 10px; background: #eef2f6; align-self: flex-start; }
.msg.out { background: #dbeafe; align-self: flex-end; }
.msg.api { border: 1px dashed #93c5fd; }
.msg.bad { background: #fee2e2; }
.msg .who { font-size: 11px; color: #52606d; display: flex; gap: 6px; flex-wrap: wrap; }
.msg .body { white-space: pre-wrap; word-break: break-word; margin: 2px 0; }
.msg .att a { font-size: 12px; }
.msg .ops { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.msg .ops button { padding: 0 6px; font-size: 11px; }
.sys { align-self: center; font-size: 12px; color: #52606d; background: #f8fafc; border: 1px solid #eef2f6; border-radius: 10px; padding: 2px 10px; }
.sys button { padding: 0 6px; font-size: 11px; margin-left: 6px; }
pre.json { font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: #f8fafc; border: 1px solid #eef2f6; border-radius: 6px; padding: 8px; margin: 4px 0; max-height: 320px; overflow: auto; }
.compose { border-top: 1px solid #eef2f6; padding-top: 10px; margin-top: 8px; }
.compose textarea { width: 100%; padding: 6px 8px; border: 1px solid #cbd2d9; border-radius: 6px; background: #fff; resize: vertical; }
.grid3 { display: grid; gap: 0 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid2.tight { grid-template-columns: 1fr 1fr; }
.grid2.tight, .grid3.tight { gap: 0 12px; }
.grid2.tight label, .grid3.tight label { min-width: 0; }
.compose .row label.check { white-space: nowrap; margin: 0 12px 8px 0; }
.row.nowrap { flex-wrap: nowrap; }
.row.nowrap select { width: 130px; flex: none; }
.tabs { margin-bottom: 8px; }
.tabs button.on { background: #dbeafe; color: #1e40af; }
.evt { border-bottom: 1px solid #eef2f6; padding: 6px 0; font-size: 12px; }
.evt .h { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.evt .h time { color: #7b8794; }
.evt .h button { margin-left: auto; }
