:root {
  --bg: #eef1f5; --panel: #fff; --line: #d9dee6; --ink: #1d2733; --muted: #66727f;
  --brand: #1f5f8b; --brand-ink: #fff; --me: #1f5f8b; --them: #e8ecf1; --unread: #c62828; --sel: #e3eef7;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); display: flex; flex-direction: column; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 12px; color: var(--ink); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--unread); border-color: #e9b7b7; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; color: var(--ink); background: #fff; }

header.top { background: var(--brand); color: #fff; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
header.top h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: .2px; }
header.top .spacer { flex: 1; }
header.top input, header.top select { padding: 4px 8px; }
header.top button { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.35); }
header.top .pill { font-size: 12px; background: rgba(255,255,255,.15); padding: 2px 8px; border-radius: 10px; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: #f0b429; display: inline-block; }
.conn.ok { background: #4caf50; }

main.app { flex: 1; display: flex; min-height: 0; }
aside.list { width: 280px; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; flex-shrink: 0; }
aside.list .section { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 12px 14px 4px; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid #f0f2f5; cursor: pointer; }
.item:hover { background: #f6f8fa; }
.item.sel { background: var(--sel); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #cfd8e3; color: #2b3a4a; display: grid; place-items: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.item .meta { flex: 1; min-width: 0; }
.item .name { font-weight: 600; }
.item .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.unread .name::after { content: ""; }
.badge { background: var(--unread); color: #fff; border-radius: 10px; font-size: 12px; min-width: 20px; padding: 1px 6px; text-align: center; font-weight: 600; }

section.thread { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.thread-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.thread-head .back { display: none; }
.thread-head .title { font-weight: 600; font-size: 16px; }
.thread-head .sub { color: var(--muted); font-size: 12px; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 70%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.out { align-self: flex-end; background: var(--me); color: #fff; border-bottom-right-radius: 4px; }
.bubble.in { align-self: flex-start; background: var(--them); border-bottom-left-radius: 4px; }
.stamp { font-size: 11px; color: var(--muted); }
.stamp.out { align-self: flex-end; }
.stamp.in { align-self: flex-start; }
.empty { margin: auto; color: var(--muted); text-align: center; padding: 20px; }
form.compose { display: flex; gap: 8px; padding: 10px 12px; background: var(--panel); border-top: 1px solid var(--line); }
form.compose textarea { flex: 1; resize: none; height: 44px; max-height: 160px; }

.modal-bg { position: fixed; inset: 0; background: rgba(15,25,35,.45); display: grid; place-items: center; z-index: 10; }
.modal { background: #fff; border-radius: 10px; padding: 20px; width: min(460px, 92vw); max-height: 85vh; overflow-y: auto; }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.row input { flex: 1; min-width: 0; }
.hidden { display: none !important; }

@media (max-width: 700px) {
  aside.list { width: 100%; border-right: 0; }
  main.app.in-thread aside.list { display: none; }
  main.app:not(.in-thread) section.thread { display: none; }
  .thread-head .back { display: inline-block; }
  .bubble { max-width: 85%; }
}
