:root {
  --bg: #f6f7f9; --panel: #ffffff; --panel-2: #f1f3f6; --hover: #eef0f4; --border: #e2e5ea; --border-2: #d3d7de;
  --text: #1c2026; --muted: #6a7280; --faint: #9aa1ad; --accent: #5b5bd6; --accent-weak: #ecebfd; --accent-text: #fff;
  --danger: #d6455d; --ok: #2f9e6a; --warn: #c98a0b;
  --ev-task: #3b82f6; --ev-decision: #8b5cf6; --ev-result: #16a34a; --ev-blocker: #dc2626; --ev-question: #d97706;
  --ev-milestone: #0d9488; --ev-note: #64748b; --ev-pin: #ca8a04;
  --radius: 10px; --shadow: 0 8px 30px rgba(20, 24, 31, .12);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --l: 52%; --s: 60%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --panel: #161920; --panel-2: #1c2029; --hover: #222733; --border: #262b36; --border-2: #323846;
    --text: #e6e8ec; --muted: #9aa2b1; --faint: #6b7383; --accent: #8b8bf5; --accent-weak: #25244a; --accent-text: #0f1115;
    --shadow: 0 8px 30px rgba(0, 0, 0, .45); --l: 66%; --s: 55%;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.hidden { display: none !important; }

/* ---------- controls */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border-2); background: var(--panel); white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.small { height: 26px; padding: 0 8px; font-size: 12.5px; border-radius: 6px; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 8px; border: 0;
  background: transparent; color: var(--muted); font-size: 16px; flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--accent); background: var(--accent-weak); }
input[type=text], input[type=password], input:not([type]), select, textarea {
  border: 1px solid var(--border-2); background: var(--panel); border-radius: 8px; padding: 7px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
select { padding-right: 24px; }
textarea { resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.field > input, label.field > textarea, label.field > select { color: var(--text); font-size: 14px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); font-size: 12px; color: var(--muted); white-space: nowrap; }
.chip.on { background: var(--accent-weak); border-color: transparent; color: var(--accent); font-weight: 600; }
button.chip:hover { border-color: var(--border-2); color: var(--text); }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent);
  color: var(--accent-text); font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.online { background: var(--ok); } .dot.waiting { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.idle { background: var(--warn); } .dot.offline { background: transparent; border: 1.5px solid var(--faint); }
.dot.human { background: var(--accent); }
.kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border: 1px solid var(--border-2); border-radius: 4px; }

/* ---------- layout */
#app { height: 100vh; height: 100dvh; display: grid; grid-template-columns: 290px minmax(0, 1fr) 360px; }
#app.no-panel { grid-template-columns: 290px minmax(0, 1fr) 0; }
#app.booting, #app.login { display: grid; grid-template-columns: 1fr; place-items: center; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.panel { background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.no-panel .panel { display: none; }
.scrim { display: none; }

/* ---------- sidebar */
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; font-weight: 800; }
.brand .name { font-weight: 700; font-size: 15px; flex: 1; }
.side-head { display: flex; align-items: center; padding: 6px 10px 6px 16px; color: var(--muted); font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.side-head span { flex: 1; }
.rooms { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.room-item { border-radius: 8px; }
.room-row { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; cursor: pointer; user-select: none; }
.room-row:hover { background: var(--hover); }
.room-item.active > .room-row { background: var(--accent-weak); }
.room-row .caret { width: 14px; color: var(--faint); font-size: 10px; transition: transform .15s; flex: none; text-align: center; }
.room-item.open > .room-row .caret { transform: rotate(90deg); }
.room-row .rname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-item.archived .rname { color: var(--faint); text-decoration: line-through; }
.tree { padding: 2px 0 8px; }
.room-item:not(.open) .tree { display: none; }
.tree-row { display: flex; align-items: flex-start; gap: 7px; padding: 3px 8px 3px calc(28px + var(--depth, 0) * 14px); border-radius: 6px;
  font-size: 12.5px; min-width: 0; cursor: default; position: relative; }
.tree-row::before { content: ""; position: absolute; left: calc(20px + var(--depth, 0) * 14px); top: 0; bottom: 50%; width: 7px;
  border-left: 1px solid var(--border-2); border-bottom: 1px solid var(--border-2); border-bottom-left-radius: 4px; }
.tree-row:hover { background: var(--hover); }
.tree-row .who { flex: 1; min-width: 0; overflow-wrap: anywhere; line-height: 1.3; }
.tree-row .dot { margin-top: 5px; }
.tree-row .role { margin-top: 1px; font-size: 10.5px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; flex: none; }
.tree-row.role-head { color: var(--muted); font-size: 11px; }
.tree-empty { padding: 3px 8px 3px 30px; font-size: 12px; color: var(--faint); }
.side-foot { border-top: 1px solid var(--border); padding: 8px; display: flex; gap: 4px; align-items: center; }
.side-foot .me { flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 6px; min-width: 0; }

/* ---------- identity */
.ava { width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center; font-weight: 800; font-size: 14px;
  color: #fff; background: hsl(var(--h, 240) var(--s) 48%); position: relative; }
.ava.sm { width: 22px; height: 22px; border-radius: 6px; font-size: 10.5px; }
.ava.human { background: var(--text); color: var(--panel); }
.ava .kind { position: absolute; right: -3px; bottom: -3px; width: 14px; height: 14px; border-radius: 4px; background: var(--panel);
  color: hsl(var(--h) var(--s) 42%); font-size: 9px; display: grid; place-items: center; border: 1px solid var(--border); }
.idc { color: hsl(var(--h, 240) var(--s) var(--l)); font-weight: 700; }
.idc.human { color: var(--text); }
.sess { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.ident-line { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- room header */
.room-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel); min-height: 56px; }
.room-head .title { flex: 1; min-width: 0; }
.room-head h1 { margin: 0; font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-head .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.faces { display: flex; }
.faces .ava { margin-left: -6px; border: 2px solid var(--panel); width: 28px; height: 28px; font-size: 11px; border-radius: 9px; }
.menu-btn { display: none; }
.search { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--panel); }
.search input { flex: 1; }

/* ---------- messages */
.stream { flex: 1; overflow-y: auto; padding: 12px 0 8px; position: relative; overscroll-behavior: contain; }
.older { text-align: center; padding: 6px; }
.day { display: flex; align-items: center; gap: 10px; margin: 14px 18px 6px; color: var(--faint); font-size: 11.5px; font-weight: 600; }
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.msg { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 0 10px; padding: 6px 18px; position: relative; }
.msg:hover { background: color-mix(in srgb, var(--hover) 60%, transparent); }
.msg.cont { padding-top: 1px; }
.msg.cont .ava-col { visibility: hidden; height: 0; }
.msg.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 30% { background: var(--accent-weak); } 100% { background: transparent; } }
.msg-head { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; min-width: 0; }
.msg-head .handle { font-size: 14px; }
.msg-head .role { font-size: 11px; padding: 0 5px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.msg-head .meta { color: var(--muted); font-size: 12px; }
.msg-head time { color: var(--faint); font-size: 11.5px; }
.to { display: inline-flex; gap: 4px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.to .arrow { color: var(--faint); }
.to b { font-weight: 600; }
.body { overflow-wrap: anywhere; }
.idc, .to b, .msg-head .meta { overflow-wrap: anywhere; min-width: 0; }
.main { overflow-x: hidden; }
.body > :first-child { margin-top: 2px; } .body > :last-child { margin-bottom: 0; }
.body p { margin: 4px 0; }
.body pre { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: 12.5px; }
.body code { background: var(--panel-2); border-radius: 4px; padding: 1px 4px; font-size: 12.5px; }
.body pre code { background: none; padding: 0; }
.body blockquote { margin: 6px 0; padding: 2px 10px; border-left: 3px solid var(--border-2); color: var(--muted); }
.body table { border-collapse: collapse; margin: 6px 0; font-size: 13px; display: block; overflow-x: auto; }
.body th, .body td { border: 1px solid var(--border); padding: 4px 8px; }
.body img { max-width: 100%; }
.body .mention { color: var(--accent); background: var(--accent-weak); border-radius: 4px; padding: 0 3px; font-weight: 600; }
.quote { font-size: 12px; color: var(--muted); border-left: 2px solid var(--border-2); padding-left: 8px; margin: 2px 0 4px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quote:hover { color: var(--text); }
.actions { position: absolute; top: -12px; right: 16px; display: none; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow); padding: 2px; }
.msg:hover .actions { display: flex; }
.actions .icon-btn { width: 28px; height: 28px; font-size: 14px; }
.sys { text-align: center; color: var(--faint); font-size: 12px; padding: 4px 18px; }
.sys b { color: var(--muted); font-weight: 600; }

/* events */
.ev-card { border: 1px solid var(--border); border-left: 3px solid var(--evc, var(--ev-note)); border-radius: 8px; background: var(--panel);
  padding: 8px 10px; margin: 4px 0 2px; }
.ev-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ev-type { font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--evc); }
.ev-title { font-weight: 650; }
.ev-card .body { margin-top: 4px; }
.status { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; font-weight: 600; border: 1px solid transparent; }
.status.open { background: color-mix(in srgb, var(--ev-task) 14%, transparent); color: var(--ev-task); }
.status.in_progress { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.status.done { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.status.blocked { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.status.cancelled { background: var(--panel-2); color: var(--faint); text-decoration: line-through; }
select.status { padding: 1px 6px; height: auto; }
.upd { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.pin-mark { color: var(--ev-pin); font-size: 12px; }
.ev-task { --evc: var(--ev-task); } .ev-decision { --evc: var(--ev-decision); } .ev-result { --evc: var(--ev-result); }
.ev-blocker { --evc: var(--ev-blocker); } .ev-question { --evc: var(--ev-question); } .ev-milestone { --evc: var(--ev-milestone); }
.ev-note { --evc: var(--ev-note); } .ev-pinned { --evc: var(--ev-pin); } .ev-update { --evc: var(--ev-task); }

/* attachments in messages */
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.thumb { display: block; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: var(--panel-2); cursor: zoom-in; max-width: 320px; }
.thumb img { display: block; max-width: 100%; max-height: 240px; }
.files video { max-width: min(420px, 100%); max-height: 300px; border-radius: 8px; background: #000; }
.files audio { max-width: 100%; }
.file { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel);
  max-width: 340px; min-width: 200px; color: var(--text); }
.file:hover { text-decoration: none; border-color: var(--border-2); }
.file .ext { width: 34px; height: 38px; border-radius: 6px; background: var(--accent-weak); color: var(--accent); font: 700 10px var(--mono);
  display: grid; place-items: center; text-transform: uppercase; flex: none; }
.file .fn { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .fs { font-size: 12px; color: var(--muted); }

#pill-slot { position: sticky; bottom: 8px; height: 0; display: flex; justify-content: center; overflow: visible; z-index: 3; }
.new-pill { transform: translateY(-100%); background: var(--accent); color: var(--accent-text);
  border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 600; box-shadow: var(--shadow); }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 40px 20px; max-width: 420px; }
.empty h2 { color: var(--text); font-size: 18px; margin: 0 0 6px; }

/* ---------- composer */
.composer { border-top: 1px solid var(--border); background: var(--panel); padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
.comp-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; min-height: 26px; }
.comp-bar .lbl { font-size: 12px; color: var(--muted); }
.comp-box { display: flex; align-items: flex-end; gap: 6px; border: 1px solid var(--border-2); border-radius: 12px; padding: 4px 4px 4px 6px; background: var(--panel); }
.comp-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.comp-box textarea { flex: 1; border: 0; box-shadow: none !important; resize: none; max-height: 40vh; min-height: 36px; padding: 8px 4px; background: transparent; }
.comp-ev { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 40%); gap: 6px; margin-bottom: 6px; }
.comp-ev select { width: 100%; min-width: 0; }
.comp-ev input { width: 100%; }
.replying { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding: 4px 6px; margin-bottom: 6px;
  border-left: 3px solid var(--accent); background: var(--accent-weak); border-radius: 0 6px 6px 0; }
.replying span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.upl { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 8px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--border); font-size: 12.5px; max-width: 240px; }
.upl span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upl .bar { width: 40px; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; flex: none; }
.upl .bar i { display: block; height: 100%; background: var(--accent); }
.upl.err { border-color: var(--danger); color: var(--danger); }
.drop { position: absolute; inset: 0; background: color-mix(in srgb, var(--accent) 12%, transparent); border: 2px dashed var(--accent);
  border-radius: 12px; display: grid; place-items: center; font-weight: 700; color: var(--accent); z-index: 5; pointer-events: none; }

/* ---------- popovers */
.pop { position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  min-width: 220px; max-width: 340px; max-height: 320px; overflow-y: auto; padding: 4px; }
.pop-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; min-width: 0; }
.pop-item:hover, .pop-item.sel { background: var(--hover); }
.pop-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-sep { height: 1px; background: var(--border); margin: 4px 0; }
.pop-title { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; padding: 6px 8px 2px; }

/* ---------- right panel */
.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--border); }
.tab { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; font-size: 13px; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.tab .n { color: var(--faint); font-weight: 500; margin-left: 3px; }
.tab-body { flex: 1; overflow-y: auto; padding: 10px 12px 16px; }
.tab-body textarea { width: 100%; }
.filters { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.taskbar { display: flex; gap: 10px; font-size: 12px; color: var(--muted); margin-bottom: 10px; flex-wrap: wrap; }
.feed-item { cursor: pointer; margin-bottom: 8px; }
.feed-item .ev-card { margin: 0; }
.feed-item:hover .ev-card { border-color: var(--border-2); }
.feed-meta { display: flex; gap: 6px; align-items: center; font-size: 11.5px; color: var(--muted); margin-top: 4px; flex-wrap: wrap; }
.feed-body { font-size: 13px; color: var(--muted); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.feed-updates { margin-top: 6px; border-top: 1px dashed var(--border); padding-top: 4px; font-size: 12px; color: var(--muted); }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.media-grid .cell { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--panel-2); border: 1px solid var(--border); cursor: zoom-in; position: relative; }
.media-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid .vid { display: grid; place-items: center; height: 100%; font-size: 26px; color: var(--muted); }
.media-grid .cell .cap { position: absolute; left: 0; right: 0; bottom: 0; font-size: 10.5px; padding: 2px 5px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.65)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-list .file { max-width: none; margin-bottom: 6px; }
.section-t { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 6px; display: flex; align-items: center; gap: 8px; }
.section-t span { flex: 1; }
.role-node { border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin: 0 0 6px calc(var(--depth, 0) * 16px); background: var(--panel); }
.role-node .rtop { display: flex; align-items: center; gap: 6px; }
.role-node .rtop b { flex: 1; }
.role-node .rbrief { font-size: 12.5px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; }
.role-node .holders { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.member-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: start; padding: 8px 0; border-bottom: 1px solid var(--border); }
.ident-wrap { overflow-wrap: anywhere; line-height: 1.35; }
.member-ctl { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.member-ctl .icon-btn { width: 26px; height: 26px; }
.member-row:last-child { border-bottom: 0; }
.member-row select { max-width: 120px; padding: 3px 6px; font-size: 12.5px; }
.form-grid { display: grid; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.codebox { position: relative; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 40px 10px 10px;
  font: 12px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.codebox .icon-btn { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; }
.note { font-size: 12.5px; color: var(--muted); }
.warn-box { background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; }

/* ---------- modal, lightbox, toast, login */
.modal-wrap { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: min(720px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 14px 16px 18px; overflow-y: auto; }
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .88); display: flex; flex-direction: column; }
.lightbox .lb-top { display: flex; align-items: center; gap: 10px; color: #ddd; padding: 10px 14px; font-size: 13px; }
.lightbox .lb-top span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox .lb-top .icon-btn { color: #ddd; }
.lightbox .lb-img { flex: 1; display: grid; place-items: center; min-height: 0; padding: 0 50px 20px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; font-size: 22px; color: #fff; background: rgba(255,255,255,.08); border-radius: 50%; border: 0; }
.lightbox .nav.prev { left: 8px; } .lightbox .nav.next { right: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--panel); padding: 9px 16px;
  border-radius: 10px; box-shadow: var(--shadow); z-index: 70; font-size: 13.5px; max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); color: #fff; }
.login-card { width: min(360px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 26px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 20px; display: flex; align-items: center; gap: 10px; }
.login-card form { display: grid; gap: 12px; margin-top: 18px; }
.login-card .err { color: var(--danger); font-size: 13px; min-height: 18px; }
.conn { font-size: 11.5px; color: var(--warn); padding: 0 6px; }

/* ---------- mobile */
@media (max-width: 1100px) {
  #app, #app.no-panel { grid-template-columns: 270px minmax(0, 1fr); }
  .panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(380px, 92vw); z-index: 30; box-shadow: var(--shadow); }
  #app:not(.no-panel) .scrim { display: block; position: fixed; inset: 0; background: rgba(10, 12, 16, .35); z-index: 29; }
}
@media (max-width: 760px) {
  #app, #app.no-panel { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(310px, 88vw); z-index: 31; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  #app.side-open .sidebar { transform: none; }
  #app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(10, 12, 16, .35); z-index: 30; }
  .menu-btn { display: inline-grid; }
  .msg { padding: 6px 12px; grid-template-columns: 30px minmax(0, 1fr); gap: 0 8px; }
  .ava { width: 30px; height: 30px; }
  .faces { display: none; }
  .actions { right: 8px; }
  .composer { padding-left: 8px; padding-right: 8px; }
  .comp-ev { grid-template-columns: minmax(0, 1fr); }
  .media-grid { grid-template-columns: repeat(3, 1fr); }
}
