:root { --line: #dfe3e8; --ink: #1c2530; --muted: #66707c; --brand: #0b63ce; --red: #c62828; --green: #1b7f3b; --amber: #a86400; --bg: #eef1f5; --mine: #dcebfd; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { min-height: 40px; padding: 0 14px; border: 0; border-radius: 8px; background: var(--brand); color: #fff; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
input:not([type=checkbox]), select, textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }
input:not([type=checkbox]), select { min-height: 40px; }
textarea { resize: none; }
.error { color: var(--red); margin: 0; min-height: 1.2em; }

.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login form { display: grid; gap: 12px; width: min(340px, 100%); padding: 24px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.login h1 { margin: 0; font-size: 20px; }

#app { display: flex; flex-direction: column; height: 100dvh; }
nav { display: flex; gap: 2px; align-items: center; padding: 6px 8px; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; flex: none; }
nav button { background: none; color: var(--muted); white-space: nowrap; padding: 0 10px; }
nav button.active { color: var(--brand); font-weight: 600; background: #e8f1fc; }
nav select { width: auto; margin-left: auto; flex: none; }
#health-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
#health-dot.ok { background: var(--green); }
#health-dot.bad { background: var(--red); }

.chat { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
#thread-pane { display: flex; flex-direction: column; min-height: 0; background: #fff; border-right: 1px solid var(--line); }
.filters { display: grid; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { min-height: 30px; padding: 0 10px; border-radius: 999px; background: var(--bg); color: var(--ink); font-size: 13px; white-space: nowrap; }
.chip.on { background: var(--brand); color: #fff; }
.sound { min-height: 30px; padding: 0 10px; border-radius: 999px; background: var(--bg); color: var(--ink); font-size: 13px; white-space: nowrap; margin-left: auto; }
#threads { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#threads li { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
#threads li.active { background: #e8f1fc; }
#threads li.empty { display: block; cursor: default; border: 0; }
.avatar { position: relative; overflow: hidden; flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; background: var(--brand); }
.avatar.group { background: var(--muted); }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#threads li.unread .t-name { font-weight: 800; }
#threads li.unread .t-preview { color: var(--ink); font-weight: 600; }
.count { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--red); color: #fff; font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; }
.t-body { min-width: 0; flex: 1; }
.t-top { display: flex; justify-content: space-between; gap: 8px; }
.t-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.t-preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 12px; color: #fff; background: var(--red); }
.tag.soft { background: var(--amber); }
.tag.grey { background: var(--muted); }

#message-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#message-pane header { display: flex; gap: 8px; align-items: center; padding: 6px 12px; min-height: 52px; background: #fff; border-bottom: 1px solid var(--line); flex: none; }
#thread-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#back { display: none; }
.banner { margin: 0; padding: 8px 12px; background: #fdecea; color: var(--red); font-size: 14px; flex: none; }
#messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.empty { color: var(--muted); text-align: center; margin: auto; }
.more { align-self: center; flex: none; }
.msg { max-width: min(560px, 85%); padding: 7px 10px; border-radius: 10px; background: #fff; border: 1px solid var(--line); align-self: flex-start; overflow-wrap: anywhere; }
.msg.self { align-self: flex-end; background: var(--mine); border-color: #c4dcf8; }
.msg.recalled { border: 2px solid var(--red); }
.m-head { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.m-text { white-space: pre-wrap; }
.msg img { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; margin-top: 4px; }
.msg a { color: var(--brand); }
.m-note { color: var(--muted); font-size: 13px; }

#quick-list { max-height: 200px; overflow-y: auto; background: #fff; border-top: 1px solid var(--line); flex: none; }
#quick-list button { display: block; width: 100%; height: auto; padding: 8px 12px; text-align: left; background: #fff; color: var(--ink); border-radius: 0; border-bottom: 1px solid var(--line); }
#quick-list button.sel { background: #e8f1fc; }
#quick-list b { color: var(--brand); margin-right: 6px; }
#preview { display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: #fff; border-top: 1px solid var(--line); flex: none; }
#preview img { height: 64px; border-radius: 6px; }
#composer { display: flex; gap: 6px; align-items: flex-end; padding: 8px; background: #fff; border-top: 1px solid var(--line); flex: none; }
#text { max-height: 140px; min-height: 40px; }
#send-error { padding: 0 12px 6px; background: #fff; flex: none; }

.page { flex: 1; overflow-y: auto; padding: 12px; max-width: 760px; width: 100%; margin: 0 auto; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cards li, .nick { padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.nick { margin-bottom: 10px; }
.nick h3 { margin: 0 0 4px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.state { font-size: 13px; font-weight: 600; padding: 1px 8px; border-radius: 999px; color: #fff; }
.state.good { background: var(--green); }
.state.warn { background: var(--amber); }
.state.bad { background: var(--red); }
.hint { color: var(--red); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 4px 12px; margin: 8px 0; }
.stats b { display: block; font-size: 16px; }
.stats span { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.linkbtn { display: inline-block; padding: 9px 14px; background: var(--brand); color: #fff; border-radius: 8px; text-decoration: none; }
#qr-box { padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; text-align: center; }
#qr-image { width: min(280px, 100%); }
.events { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.events li { padding: 4px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.events time { color: var(--muted); margin-right: 6px; }
.stack { display: grid; gap: 8px; margin-bottom: 16px; max-width: 420px; }
.stack-tight { display: grid; gap: 8px; }
.nicks { display: flex; gap: 10px; flex-wrap: wrap; }
.off { opacity: .55; }

@media (max-width: 720px) {
  .chat { grid-template-columns: 1fr; }
  .chat.open #thread-pane { display: none; }
  .chat:not(.open) #message-pane { display: none; }
  #thread-pane { border-right: 0; }
  #back { display: inline-block; }
}
