/* quickchat v2 styles. Tokens first; a 4/8px spacing scale; 16px base text, nothing readable under 12px; focus rings everywhere;
   hover and active states never move layout; fixed-size scroll regions; works from 320px wide. Dark by default, light by preference. */
:root {
  --bg: #0e1417; --surface: #121b20; --raised: #182329; --border: #2a3d46; --text: #e9f4f7; --muted: #a3bcc4;
  --accent: #5fd0e0; --accent-ink: #04161a; --danger: #ff9a8f; --success: #7fe0a0; --warn-bg: #2a3512; --warn-text: #eef8cf;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45); --scrim: rgba(0, 0, 0, 0.6);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --radius: 12px;
  --side-w: 272px; --people-w: 248px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f7f8; --surface: #ffffff; --raised: #eef3f5; --border: #c5d3d8; --text: #14242b; --muted: #4a626b;
    --accent: #0a6f84; --accent-ink: #ffffff; --danger: #b3261e; --success: #1b7a43; --warn-bg: #fdf3c8; --warn-text: #3d3200;
    --shadow: 0 8px 24px rgba(20, 36, 43, 0.18); --scrim: rgba(20, 36, 43, 0.45);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.5em; margin-top: var(--s2); }
.hint { color: var(--muted); font-size: 14px; margin-top: var(--s2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ---- layout ---- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.content { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) var(--people-w); }
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.panel { flex: 1 1 auto; overflow-y: auto; padding: var(--s5) var(--s4); display: flex; justify-content: center; align-items: flex-start; }
.card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s5); display: flex; flex-direction: column; gap: var(--s2); }
.card h2 { font-size: 20px; line-height: 1.3; }
.card label { font-weight: 600; margin-top: var(--s2); }
.row { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }

/* ---- controls ---- */
button, .btn { font: inherit; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 var(--s4); border-radius: 10px; border: 1px solid var(--border); background: var(--raised); color: var(--text); font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { min-height: 32px; padding: 0 var(--s3); font-size: 14px; }
.btn:disabled, .icon-btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; flex: 0 0 40px; padding: 0; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--raised); border-color: var(--border); }
.icon-btn.solid { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.icon-btn.solid:hover { filter: brightness(1.08); }
.icon-btn svg, .brand-mark svg, .lock svg, .empty-mark svg { display: block; width: 20px; height: 20px; }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px var(--s3); width: 100%; }
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="checkbox"], input[type="radio"] { width: auto; }
.only-narrow, .only-mid { display: none; }

/* ---- sidebar ---- */
.brand { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4); min-height: 56px; border-bottom: 1px solid var(--border); }
.brand-mark { color: var(--accent); display: inline-flex; }
.brand-name { font-weight: 700; font-size: 18px; flex: 1 1 auto; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s3) var(--s3) var(--s1) var(--s4); }
.side-head h2 { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.chan-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: var(--s1) var(--s2); overscroll-behavior: contain; }
.chan-group { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: var(--s3) var(--s2) var(--s1); }
.chan { display: flex; align-items: center; gap: var(--s2); width: 100%; min-height: 44px; padding: 0 var(--s2); border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--text); text-align: left; cursor: pointer; text-decoration: none; }
.chan:hover { background: var(--raised); }
.chan[aria-current="page"] { background: var(--raised); border-color: var(--border); }
.chan-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan.unread .chan-name { font-weight: 700; }
.chan-icon { color: var(--muted); display: inline-flex; flex: 0 0 auto; }
.chan-icon svg { width: 16px; height: 16px; display: block; }
.chan-count { flex: 0 0 auto; font-size: 12px; color: var(--muted); }
.dot { flex: 0 0 auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; }
.me-card { position: relative; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s3) var(--s3) var(--s4); border-top: 1px solid var(--border); }
.me-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.me-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-badge { font-size: 12px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.menu { position: absolute; left: var(--s3); right: var(--s3); bottom: calc(100% - 4px); z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--s1); }
.menu button { display: flex; width: 100%; min-height: 44px; align-items: center; padding: 0 var(--s3); border: 0; border-radius: 8px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.menu button:hover { background: var(--raised); }
.pending { margin: var(--s2); padding: var(--s3); border: 1px solid var(--accent); border-radius: var(--radius); background: var(--raised); display: flex; flex-direction: column; gap: var(--s2); }
.pending p { font-size: 14px; }

/* ---- avatars: a deterministic palette, white on each, all above 4.5:1 ---- */
.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; flex: 0 0 40px; border-radius: 50%; color: #ffffff; font-weight: 700; font-size: 16px; text-transform: uppercase; user-select: none; background: #4a58b8; }
.avatar.small { width: 32px; height: 32px; flex-basis: 32px; font-size: 14px; }
.av0 { background: #b3261e; } .av1 { background: #1b6e9c; } .av2 { background: #7a3fb0; } .av3 { background: #a1470f; }
.av4 { background: #1f7a4d; } .av5 { background: #b0306a; } .av6 { background: #4a58b8; } .av7 { background: #0f766e; }

/* ---- header ---- */
.top { display: flex; align-items: center; gap: var(--s3); min-height: 56px; padding: var(--s2) var(--s4); border-bottom: 1px solid var(--border); background: var(--surface); }
.top-title { flex: 1 1 auto; min-width: 0; }
.top-title h1 { display: flex; align-items: center; gap: var(--s2); font-size: 18px; line-height: 1.3; }
.top-title h1 span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lock { color: var(--muted); display: inline-flex; flex: 0 0 auto; }
.top-desc { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 21px; }
.top-actions { display: flex; align-items: center; gap: var(--s2); flex: 0 0 auto; }
.pill { font-size: 13px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px var(--s3); white-space: nowrap; }
.banner { padding: var(--s2) var(--s4); background: var(--warn-bg); color: var(--warn-text); font-size: 14px; }

/* ---- messages ---- */
.pane-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex; }
.pane { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--s3) 0 var(--s4); }
.msg { display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: var(--s3); padding: 2px var(--s4); position: relative; }
.msg.first { margin-top: var(--s3); padding-top: var(--s1); }
.msg:hover { background: var(--surface); }
.msg-main { min-width: 0; }
.msg .meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2); line-height: 1.4; }
.msg .name { font-weight: 700; }
.badge { font: 12px ui-monospace, Consolas, monospace; color: var(--muted); background: var(--raised); border-radius: 6px; padding: 0 6px; }
.msg time, .msg .stamp { font-size: 12px; color: var(--muted); }
.msg .gutter { position: relative; min-height: 1px; }
.msg .stamp { position: absolute; left: 0; right: 0; text-align: center; top: 4px; opacity: 0; }
.msg:hover .stamp { opacity: 1; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 68ch; }
.msg.pending-send { opacity: 0.7; }
.sys { text-align: center; color: var(--muted); font-size: 13px; padding: var(--s1) var(--s4); }
.date-sep, .new-div { display: flex; align-items: center; gap: var(--s3); font-size: 12px; color: var(--muted); margin: var(--s4) var(--s4) var(--s2); }
.date-sep::before, .date-sep::after, .new-div::before, .new-div::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--border); }
.new-div { color: var(--accent); font-weight: 700; }
.new-div::before, .new-div::after { background: var(--accent); }
.pic { display: block; margin-top: var(--s2); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--raised); overflow: hidden; width: 240px; height: 180px; cursor: zoom-in; }
.pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.note { display: flex; align-items: center; justify-content: center; width: 240px; height: 180px; margin-top: var(--s2); border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); font-size: 14px; text-align: center; padding: var(--s2); }
.earlier { display: flex; justify-content: center; padding: var(--s2); }
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2); text-align: center; padding: var(--s5); pointer-events: none; }
.empty-mark { color: var(--muted); }
.empty-mark svg { width: 40px; height: 40px; }
.jump { position: absolute; left: 50%; bottom: var(--s3); transform: translateX(-50%); min-height: 36px; padding: 0 var(--s4); border-radius: 999px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: var(--shadow); cursor: pointer; }
.status { height: 24px; padding: 0 var(--s4); color: var(--muted); font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.status.bad { color: var(--danger); }

/* ---- composer ---- */
.composer { display: flex; align-items: flex-end; gap: var(--s2); padding: var(--s2) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom)); }
.composer-box { position: relative; flex: 1 1 auto; min-width: 0; }
.composer textarea { resize: none; display: block; min-height: 40px; max-height: 144px; overflow-y: auto; padding: 8px var(--s3); line-height: 24px; }
.counter { position: absolute; right: var(--s3); bottom: 2px; font-size: 12px; color: var(--muted); pointer-events: none; }
.counter.hot { color: var(--danger); }

/* ---- people ---- */
.people { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--border); }
.people-head { display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: 0 var(--s3) 0 var(--s4); }
.people-head h2 { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.people-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 var(--s2) var(--s4); overscroll-behavior: contain; }
.person { display: flex; align-items: center; gap: var(--s2); min-height: 48px; padding: var(--s1) var(--s2); border-radius: 10px; }
.person-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.person-text .badge { align-self: flex-start; background: transparent; padding: 0; }
.person-tags { flex: 0 0 auto; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s1); max-width: 92px; }
.person:hover { background: var(--raised); }
.person-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person.away .avatar { opacity: 0.6; }
.person.away .person-name { color: var(--muted); }
.tag { flex: 0 0 auto; font-size: 12px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 6px; padding: 0 5px; }
.people-group { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: var(--s3) var(--s2) var(--s1); }

/* ---- dialogs, menus, toasts, lightbox ---- */
.dlg { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dlg::backdrop { background: var(--scrim); }
.dlg-in { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s5); }
.dlg-in h2 { font-size: 20px; }
.dlg-in h3 { font-size: 14px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-top: var(--s4); }
.dlg-in label { font-weight: 600; margin-top: var(--s2); }
.dlg-in .row { justify-content: flex-end; }
.dlg-in .row.split { justify-content: space-between; }
.list-row { display: flex; align-items: center; gap: var(--s2); min-height: 44px; border-bottom: 1px solid var(--border); }
.list-row .grow { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.list-row .sub { display: block; font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: var(--s2); font-weight: 400 !important; min-height: 40px; }
.check input { width: 20px; height: 20px; }
.toasts { position: fixed; right: var(--s4); bottom: var(--s4); z-index: 40; display: flex; flex-direction: column; gap: var(--s2); max-width: min(360px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--raised); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s3) var(--s4); box-shadow: var(--shadow); font-size: 14px; }
.lightbox { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.92); }
.lightbox img { max-width: 96vw; max-height: 90vh; object-fit: contain; }
.lightbox .icon-btn { position: absolute; top: var(--s3); right: var(--s3); }
.scrim { position: fixed; inset: 0; z-index: 25; background: var(--scrim); }

/* before you have a name there is nothing to list or manage yet */
.app[data-view="loading"] :is(.side-head, .chan-list, .me-card, #infoBtn, #peopleBtn, #onlineCount),
.app[data-view="join"] :is(.side-head, .chan-list, .me-card, #infoBtn, #peopleBtn, #onlineCount),
.app[data-view="closed"] :is(.side-head, .chan-list, .me-card, #infoBtn, #peopleBtn, #onlineCount),
.app[data-view="nochan"] :is(#infoBtn, #peopleBtn) { visibility: hidden; }

/* ---- narrower screens ---- */
@media (max-width: 1000px) {
  .content { grid-template-columns: minmax(0, 1fr); }
  .only-mid { display: inline-flex; }
  .people { position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; width: min(300px, 86vw); transform: translateX(100%); visibility: hidden; transition: transform 0.18s ease, visibility 0.18s; box-shadow: var(--shadow); }
  .app[data-people="open"] .people { transform: none; visibility: visible; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .only-narrow { display: inline-flex; }
  .side { position: fixed; top: 0; left: 0; bottom: 0; z-index: 30; width: min(300px, 86vw); transform: translateX(-100%); visibility: hidden; transition: transform 0.18s ease, visibility 0.18s; box-shadow: var(--shadow); }
  .app[data-side="open"] .side { transform: none; visibility: visible; }
  .top { padding: var(--s2) var(--s3); gap: var(--s2); }
  .pill { display: none; }
  .msg { padding-left: var(--s3); padding-right: var(--s3); }
  .composer { padding-left: var(--s3); padding-right: var(--s3); }
  .status { padding: 0 var(--s3); }
  .icon-btn { width: 44px; height: 44px; flex-basis: 44px; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 36px; }
}
@media (max-width: 360px) {
  .msg { grid-template-columns: 32px minmax(0, 1fr); column-gap: var(--s2); }
  .msg .avatar { width: 32px; height: 32px; flex-basis: 32px; font-size: 14px; }
  .pic, .note { width: 100%; max-width: 240px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; animation: none !important; }
}
