:root {
  color-scheme: light dark;
  --bg: #f6f7fb; --panel: #ffffff; --panel-2: #eef0f6; --rail: #e6e9f2;
  --text: #1a1d29; --muted: #5d6478; --line: #d9dde8;
  --accent: #4f46e5; --accent-text: #ffffff; --accent-soft: #e6e5fc;
  --danger: #c4261d; --ok: #1a7f4b; --warn-bg: #fff3c4; --warn-text: #5b4500;
  --radius: 12px; --shadow: 0 8px 28px rgb(20 24 40 / .18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c; --panel: #1b1e29; --panel-2: #242837; --rail: #0e1016;
    --text: #eceef6; --muted: #a2a9bf; --line: #323750;
    --accent: #8b87ff; --accent-text: #0f1020; --accent-soft: #2b2c55;
    --danger: #ff8a80; --ok: #6fdc9b; --warn-bg: #4a3d0a; --warn-text: #ffe9a0;
    --shadow: 0 8px 28px rgb(0 0 0 / .5);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 var(--font); background: var(--bg); color: var(--text); overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--accent); color: var(--accent-text); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { top: 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; }

/* beta banner */
#beta-banner { background: var(--warn-bg); color: var(--warn-text); font-size: 13px; text-align: center; padding: 0 12px; height: 28px; line-height: 28px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) { #beta-banner .long { display: none; } }
#app-root { height: calc(100% - 28px); }

/* buttons and fields */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 14px; min-height: 40px; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; display: inline-grid; place-items: center; font-size: 17px; }
.icon-btn:hover { background: var(--panel-2); }
input[type=text], input[type=password], textarea, select { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 12px; min-height: 42px; }
textarea { resize: vertical; }
label { font-weight: 600; font-size: 14px; }
.stack { display: grid; gap: 10px; } .row { display: flex; gap: 10px; align-items: center; } .row.end { justify-content: flex-end; } .grow { flex: 1; min-width: 0; }

/* avatar */
.avatar { width: var(--s); height: var(--s); border-radius: 50%; flex: none; display: inline-grid; place-items: center; overflow: hidden; background: var(--panel-2); font-weight: 700; font-size: calc(var(--s) * .42); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-fallback { background: hsl(var(--hue) 55% 42%); color: #fff; }

/* auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 20px; overflow: auto; }
.auth-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.02em; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); padding: 4px; border-radius: 12px; margin: 16px 0; }
.tab { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab[aria-selected=true] { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .15); }
.form-error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 0; }
.config-problem { max-width: 560px; }

/* layout */
.shell { height: 100%; display: grid; grid-template-columns: 72px 260px minmax(0, 1fr); }
.shell.members-open { grid-template-columns: 72px 260px minmax(0, 1fr) 240px; }
.rail { background: var(--rail); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 0; overflow-y: auto; }
.rail-btn { position: relative; width: 48px; height: 48px; border-radius: 16px; border: 0; background: var(--panel); cursor: pointer; font-weight: 800; font-size: 16px; display: grid; place-items: center; transition: border-radius .15s, background .15s; }
.rail-btn:hover, .rail-btn[aria-current=true] { border-radius: 24px; background: var(--accent); color: var(--accent-text); }
.rail-btn .dot { position: absolute; right: -2px; top: -2px; }
.rail-sep { width: 32px; height: 2px; background: var(--line); border-radius: 2px; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); min-height: 56px; }
.side-head h2 { font-size: 16px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-list { flex: 1; overflow-y: auto; padding: 8px; display: grid; gap: 2px; align-content: start; }
.side-label { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; padding: 10px 8px 4px; }
.item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; cursor: pointer; min-height: 40px; color: var(--muted); }
.item:hover { background: var(--panel-2); color: var(--text); }
.item[aria-current=true] { background: var(--accent-soft); color: var(--text); font-weight: 700; }
.item.unread { color: var(--text); font-weight: 700; }
.item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: none; border: 2px solid var(--panel); }
.me-bar { display: flex; align-items: center; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.me-name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.main-head { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 56px; }
.main-head h1 { font-size: 16px; margin: 0; }
.main-head .topic { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.menu-btn { display: none; }
.conn { font-size: 12px; color: var(--danger); font-weight: 700; }
.pane { flex: 1; overflow-y: auto; padding: 16px; }
.members-host { display: flex; flex-direction: column; min-height: 0; }
.members-host .members { flex: 1; }
.members { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 8px; }
.members h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 8px 4px; }
.member { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 6px 8px; border-radius: 9px; cursor: pointer; text-align: left; }
.member:hover { background: var(--panel-2); }
.badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); }
.badge.muted-b { background: var(--warn-bg); color: var(--warn-text); }

/* messages */
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.log { flex: 1; overflow-y: auto; padding: 12px 0; }
.day { text-align: center; color: var(--muted); font-size: 12px; margin: 14px 0 6px; font-weight: 700; }
.msg { position: relative; display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 0 4px; padding: 2px 16px 2px 12px; }
.msg.first { margin-top: 12px; }
.msg:hover, .msg:focus-within { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.msg .gutter { padding-top: 2px; } .msg .gutter .t { display: none; font-size: 11px; color: var(--muted); }
.msg:not(.first):hover .gutter .t { display: block; }
.msg .head { display: flex; gap: 8px; align-items: baseline; }
.msg .who { font-weight: 700; } .msg .when, .msg .edited { color: var(--muted); font-size: 12px; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .reply-ref { color: var(--muted); font-size: 13px; border-left: 3px solid var(--line); padding-left: 8px; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.pending { opacity: .6; }
.actions { position: absolute; right: 12px; top: -14px; display: flex; opacity: 0; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 2px; z-index: 2; }
.msg:hover .actions, .msg:focus-within .actions { opacity: 1; pointer-events: auto; }
.actions button { border: 0; background: transparent; min-width: 34px; height: 32px; border-radius: 8px; cursor: pointer; }
.actions button:hover { background: var(--panel-2); }
.reactions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.react { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 1px 9px; cursor: pointer; font-size: 13px; min-height: 26px; }
.react[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent); }
.edit-box { display: grid; gap: 6px; }
.composer { padding: 0 16px 16px; }
.reply-bar { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 10px 10px 0 0; padding: 6px 12px; font-size: 13px; color: var(--muted); }
.reply-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-row { display: flex; gap: 8px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px; }
.compose-row textarea { border: 0; background: transparent; resize: none; max-height: 160px; min-height: 40px; }
.compose-row textarea:focus-visible { outline: none; }
.compose-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.notice { background: var(--panel-2); border-radius: 12px; padding: 12px 14px; color: var(--muted); text-align: center; }
.char { font-size: 12px; color: var(--muted); align-self: center; }
.char.over { color: var(--danger); font-weight: 700; }
.more { display: block; margin: 0 auto 8px; }

/* states */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); } .empty-title { font-weight: 700; color: var(--text); margin: 0 0 4px; font-size: 16px; }
.skeleton { padding: 8px 16px; display: grid; gap: 16px; } .sk-row { display: flex; gap: 12px; } .sk-av { width: 36px; height: 36px; border-radius: 50%; background: var(--panel-2); }
.sk-lines { flex: 1; display: grid; gap: 6px; align-content: start; } .sk-lines i { height: 12px; border-radius: 6px; background: var(--panel-2); width: 60%; } .sk-lines i + i { width: 85%; }
@media (prefers-reduced-motion: no-preference) { .sk-av, .sk-lines i { animation: pulse 1.2s ease-in-out infinite; } @keyframes pulse { 50% { opacity: .45; } } }

/* modal and toasts */
dialog.modal { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); padding: 0; width: min(440px, calc(100vw - 24px)); box-shadow: var(--shadow); max-height: calc(100vh - 32px); }
dialog.modal.wide { width: min(640px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgb(0 0 0 / .5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 0 18px; } .modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 14px 18px 18px; display: grid; gap: 12px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); } .list-row:last-child { border-bottom: 0; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--panel-2); padding: 3px 8px; border-radius: 8px; user-select: all; }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 1000; width: min(420px, calc(100vw - 24px)); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; pointer-events: auto; }
.toast.error { background: var(--danger); color: #fff; }
.scrim { display: none; }

/* phones and small windows: the side panels slide in */
@media (max-width: 860px) {
  .shell, .shell.members-open { grid-template-columns: minmax(0, 1fr); }
  .rail, .side { position: fixed; top: 28px; bottom: 0; z-index: 30; transform: translateX(calc(-100% - 80px)); visibility: hidden; transition: transform .2s, visibility 0s .2s; }
  .rail { left: 0; width: 72px; } .side { left: 72px; width: min(280px, calc(100vw - 72px)); }
  body.nav-open .rail, body.nav-open .side { transform: none; visibility: visible; transition: transform .2s, visibility 0s; }
  body.nav-open .scrim { display: block; position: fixed; inset: 28px 0 0 0; background: rgb(0 0 0 / .45); z-index: 20; }
  .menu-btn { display: inline-grid; }
  .members { position: fixed; right: 0; top: 28px; bottom: 0; width: min(280px, 86vw); z-index: 30; box-shadow: var(--shadow); }
  .msg { grid-template-columns: 44px minmax(0, 1fr); padding-right: 10px; }
  .actions { top: 0; right: 6px; } .actions .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
.picker { display: flex; border-right: 1px solid var(--line); margin-right: 2px; padding-right: 2px; }
hr { border: 0; border-top: 1px solid var(--line); width: 100%; }
details > summary { cursor: pointer; padding: 4px 0; }
