:root {
  --bg: #0b0d10; --bg-2: #101317; --surface: #14181d; --surface-2: #1a1f26; --border: #232a33; --border-2: #2e3742;
  --text: #e8ecf1; --muted: #8b96a5; --accent: #22c55e; --accent-h: #16a34a; --accent-ink: #04130a; --accent-soft: rgba(34,197,94,.14);
  --danger: #f0605d; --danger-soft: rgba(240,96,93,.14); --warn: #f5b942; --warn-soft: rgba(245,185,66,.14); --info: #5aa9ff; --info-soft: rgba(90,169,255,.14);
  --shadow: 0 10px 30px rgba(0,0,0,.45); --radius: 12px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f6f8; --bg-2: #eceff3; --surface: #ffffff; --surface-2: #f6f8fa; --border: #e3e8ee; --border-2: #d3dae3;
  --text: #16202b; --muted: #66758a; --accent: #16a34a; --accent-h: #15803d; --accent-ink: #ffffff; --accent-soft: rgba(22,163,74,.11);
  --danger: #d6403d; --danger-soft: rgba(214,64,61,.10); --warn: #b7791f; --warn-soft: rgba(217,150,30,.14); --info: #2b7fd9; --info-soft: rgba(43,127,217,.10);
  --shadow: 0 10px 30px rgba(20,30,50,.12);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h2 { font-size: 16px; } h3 { font-size: 14px; }
a { color: inherit; text-decoration: none; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); } .right { text-align: right; } .grow { flex: 1; }
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* shell */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 18px 14px; background: var(--bg-2); border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; padding: 4px 8px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; margin-top: -2px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.sidebar nav a:hover { background: var(--surface); color: var(--text); }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.me { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 0 4px; }
.me-mail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 28px; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); }
.topbar h1 { font-size: 18px; flex: 1; }
.menu-btn { display: none; }
.server-switch { display: flex; align-items: center; gap: 8px; padding: 0 10px; height: 36px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--muted); }
.server-switch select { border: 0; background: transparent; color: var(--text); font: inherit; font-weight: 500; padding: 0 4px; height: 100%; outline: none; max-width: 180px; }
.content { padding: 24px 28px 60px; display: flex; flex-direction: column; gap: 18px; max-width: 1280px; width: 100%; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; transition: background .12s, border-color .12s, transform .05s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface); color: var(--text); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.icon-btn.sm { width: 28px; height: 28px; flex: none; font-size: 15px; color: var(--muted); }
.icon-btn.sm:hover { color: var(--text); border-color: var(--border-2); }
.icon-btn.busy { animation: rot .7s linear infinite; }
input:not([type=checkbox]):not([type=radio]), select, textarea { width: 100%; height: 38px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--bg); color: var(--text); font: inherit; outline: none; transition: border-color .12s, box-shadow .12s; }
textarea { height: auto; padding: 9px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--muted); opacity: .7; }
select:disabled { opacity: .6; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 13px; }
.form small { color: var(--muted); font-weight: 400; font-size: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
form.inline { display: inline; }
.test-result.ok { color: var(--accent); } .test-result.bad { color: var(--danger); }

/* toggles */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-weight: 500; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch > span { width: 36px; height: 20px; border-radius: 20px; background: var(--border-2); position: relative; transition: background .15s; flex: none; }
.switch > span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.switch.sm { font-size: 13px; color: var(--muted); }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.setting:last-of-type { border-bottom: 0; }
.setting b { display: block; font-weight: 550; } .setting small { color: var(--muted); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-head code { display: block; margin-top: 4px; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 8px 12px; margin: 0; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }
.edit summary { cursor: pointer; color: var(--accent); font-weight: 550; margin-bottom: 12px; }
.edit .form { margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 550; text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table select { width: auto; height: 32px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); text-transform: capitalize; }
.pill.admin { background: var(--accent-soft); color: var(--accent); }
.avatar { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 24px; height: 24px; font-size: 12px; vertical-align: middle; margin-right: 6px; }
.flash { padding: 11px 14px; border-radius: 10px; border: 1px solid; font-weight: 500; }
.flash.ok { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent); }
.flash.err { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.empty { text-align: center; padding: 56px 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.empty-code { font-size: 56px; font-weight: 700; color: var(--border-2); }
.onboard { display: flex; flex-direction: column; gap: 8px; }
.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 4px; counter-reset: s; }
.steps li { counter-increment: s; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-weight: 550; }
.steps li::before { content: counter(s); display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border-2); font-size: 11px; }
.steps li + li::after { content: none; }
.steps li.on { color: var(--text); } .steps li.on::before { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.steps li.done { color: var(--accent); } .steps li.done::before { content: "✓"; border-color: var(--accent); }
.steps li:not(:last-child)::after { content: ""; width: 24px; height: 1px; background: var(--border-2); margin-left: 4px; }

/* auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 500px at 50% -10%, var(--accent-soft), transparent 60%), var(--bg); position: relative; }
.theme-float { position: absolute; top: 16px; right: 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 30px 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 21px; } .auth-card p { margin: 0; }
.auth-logo { width: 46px; height: 46px; border-radius: 13px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.auth-logo svg { width: 26px; height: 26px; }

/* instances */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 24px; font-weight: 650; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 12px; font-weight: 550; text-transform: uppercase; letter-spacing: .06em; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search { width: 260px; max-width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border-2); background: transparent; color: var(--muted); font: inherit; font-weight: 550; cursor: pointer; }
.chip:hover { color: var(--text); }
.chip.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.grid { 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: 14px; transition: border-color .12s, transform .12s; }
.inst:hover { border-color: var(--border-2); }
.inst.selected { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger) inset; }
.inst-top > input[type=checkbox], .bulk input[type=checkbox] { width: 16px; height: 16px; margin: 0; flex: none; accent-color: var(--accent); cursor: pointer; }
.bulk { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.bulk[hidden] { display: none; }
.bulk .check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 550; }
.bulk-list { max-height: 200px; overflow: auto; margin: 0 0 14px; padding: 8px 12px 8px 28px; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; font-size: 13px; }
.inst-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.inst-id { min-width: 0; flex: 1; }
.inst-id b { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inst-id span { color: var(--muted); font-size: 12.5px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inst-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.inst-actions .btn { flex: 1; min-width: 0; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.open { background: var(--accent-soft); color: var(--accent); }
.badge.connecting, .badge.qr-code { background: var(--warn-soft); color: var(--warn); }
.badge.closed { background: var(--surface-2); color: var(--muted); }
.badge.unknown { background: var(--warn-soft); color: var(--warn); }
.badge.suspended { background: var(--danger-soft); color: var(--danger); }
.badge.connecting::before, .badge.qr-code::before { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.skeleton { height: 128px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface), var(--surface-2), var(--surface)); background-size: 200% 100%; animation: sh 1.4s infinite; border: 1px solid var(--border); }
@keyframes sh { to { background-position: -200% 0; } }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 9px; padding: 8px 12px; font-size: 12.5px; }

/* overlay: modal + drawer */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(4,6,9,.6); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
.overlay[hidden] { display: none; }
.overlay.drawer { justify-content: flex-end; padding: 0; align-items: stretch; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
@keyframes pop { from { transform: scale(.97) translateY(6px); opacity: 0; } }
.modal { width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--border-2); border-radius: 16px; box-shadow: var(--shadow); padding: 22px; display: flex; flex-direction: column; gap: 16px; animation: pop .18s; }
.modal.wide { max-width: 620px; }
.drawer .modal { max-width: 560px; height: 100%; max-height: none; border-radius: 0; border-width: 0 0 0 1px; animation: slide .2s; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h2 { font-size: 17px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 -2px; }
.tab { background: none; border: 0; color: var(--muted); font: inherit; font-weight: 550; padding: 9px 12px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); } .tab.on { color: var(--accent); border-color: var(--accent); }
.qr-box { display: grid; place-items: center; gap: 12px; padding: 8px 0; text-align: center; }
.qr-box img { width: 264px; height: 264px; max-width: 100%; border-radius: 14px; background: #fff; padding: 10px; }
.qr-ph { width: 264px; height: 264px; max-width: 100%; border-radius: 14px; border: 1px dashed var(--border-2); display: grid; place-items: center; color: var(--muted); }
.pair { font: 600 30px/1 ui-monospace, Menlo, monospace; letter-spacing: .18em; padding: 16px 20px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border-2); user-select: all; }
.ol { text-align: left; color: var(--muted); font-size: 13px; margin: 0; padding-left: 18px; }
.events { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.events label { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.events input { width: auto; height: auto; }
.danger-zone { border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); border-radius: 12px; padding: 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0; }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-2); border-top-color: var(--accent); animation: rot .7s linear infinite; display: inline-block; }
@keyframes rot { to { transform: rotate(360deg); } }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface-2); border: 1px solid var(--border-2); border-left: 3px solid var(--accent); padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; animation: pop .18s; }
.toast.err { border-left-color: var(--danger); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .menu-btn { display: grid; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .row2, .row3, .events { grid-template-columns: 1fr; }
  .search { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
#app { display: flex; flex-direction: column; gap: 18px; }

/* ---------- playground ---------- */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; font-size: 12.5px !important; }
.pg { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.pg-line { display: flex; gap: 8px; }
.pg-line select { width: 110px; flex: none; font-weight: 600; }
.form label.pg-body-label { flex-direction: row; align-items: center; justify-content: space-between; margin-bottom: -8px; }
.pg-req textarea { min-height: 260px; line-height: 1.5; tab-size: 2; }
.pg-res { position: sticky; top: 18px; min-height: 200px; }
.pg-res-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pg-meta { display: flex; align-items: center; gap: 12px; font-size: 12.5px; }
.st { font-weight: 700; padding: 2px 9px; border-radius: 99px; }
.st.ok { background: var(--accent-soft); color: var(--accent); }
.st.warn { background: var(--warn-soft); color: var(--warn); }
.st.err { background: var(--danger-soft); color: var(--danger); }
.pg-out { position: relative; }
.pg-out pre { margin: 0; padding: 14px; max-height: 70vh; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; white-space: pre-wrap; word-break: break-word; }
.pg-copy { position: absolute; top: 6px; right: 6px; }
.pg-img { max-width: 100%; border-radius: 9px; background: #fff; padding: 8px; }
@media (max-width: 1100px) { .pg { grid-template-columns: 1fr; } .pg-res { position: static; } }
