:root {
  --bg: #f4f6f8; --panel: #fff; --text: #1d2733; --muted: #6b7785; --line: #e3e8ee;
  --brand: #1f9d6b; --brand-dark: #178055; --brand-soft: #e5f6ef;
  --danger: #d64545; --warn: #d9962b; --info: #2f7fd1;
  --bubble-in: #fff; --bubble-out: #d9f5e6; --chat-bg: #eef1ee;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c; --panel: #1a222b; --text: #e6ebf0; --muted: #8fa0b1; --line: #2a3541;
    --brand: #2bb67e; --brand-dark: #3ccb90; --brand-soft: #16372b;
    --bubble-in: #232d38; --bubble-out: #1c4a38; --chat-bg: #151c23;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Tahoma, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-dark); text-decoration: none; }

/* layout */
.shell { display: grid; grid-template-columns: 230px 1fr; height: 100vh; }
.side { background: var(--panel); border-inline-end: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 4px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 16px; }
.logo i { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: #fff; font-style: normal; font-size: 16px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); cursor: pointer; border: 0; background: none; text-align: start; width: 100%; }
.nav:hover { background: var(--bg); }
.nav.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.side .spacer { flex: 1; }
.main { overflow: auto; padding: 26px 30px; }
.main.flush { padding: 0; overflow: hidden; }
h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 22px; }

/* controls */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 13px; cursor: pointer; box-shadow: var(--shadow); }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }

/* cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0; font-size: 16px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.meta { color: var(--muted); font-size: 13px; margin: 6px 0 14px; word-break: break-word; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: 3px 9px; border-radius: 99px; background: var(--bg); color: var(--muted); }
.pill.connected { background: var(--brand-soft); color: var(--brand-dark); }
.pill.error { background: #fde8e8; color: var(--danger); }
.pill.warn { background: #fdf1dc; color: var(--warn); }
.pill.info { background: #e3f0fc; color: var(--info); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; border: 2px dashed var(--line); border-radius: 12px; }
.note { font-size: 12px; color: var(--muted); margin-top: 10px; }
.toast { position: fixed; bottom: 22px; inset-inline-start: 50%; transform: translateX(-50%); background: #1d2733; color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 50; max-width: 90vw; }
.toast.bad { background: var(--danger); }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(10, 16, 24, .5); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal { background: var(--panel); border-radius: 14px; padding: 24px; width: min(440px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.3); max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.qr { display: grid; place-items: center; padding: 14px; background: #fff; border-radius: 12px; margin: 14px 0; }
.qr img { width: 220px; height: 220px; }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; margin: 14px 0 4px; }
.tabs button { flex: 1; border: 0; background: none; padding: 7px; border-radius: 7px; cursor: pointer; }
.tabs button.active { background: var(--panel); box-shadow: var(--shadow); font-weight: 600; }

input[type=checkbox] { width: auto; }
.check { display: flex; gap: 8px; align-items: baseline; font-weight: 400; color: var(--text); font-size: 13px; margin: 6px 0; }
.check span { color: var(--muted); }
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 160px; }
.toolbar select { width: auto; }
.foot { font-size: 12px; color: var(--muted); padding: 8px 10px 0; display: flex; justify-content: space-between; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0 0; font-size: 13px; }
.kv span { color: var(--muted); } .kv b { font-weight: 600; word-break: break-word; }
.tablewrap { padding: 0; overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: start; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.click { cursor: pointer; } .table tr.click:hover { background: var(--bg); }
.table td.trunc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.json { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; max-height: 55vh; font: 12px/1.5 ui-monospace, Consolas, monospace; margin: 10px 0 0; white-space: pre-wrap; word-break: break-all; }
.reactions { display: flex; gap: 6px; margin-top: 12px; } .reactions .btn { font-size: 18px; padding: 4px 10px; }
.replybar { background: var(--brand-soft); padding: 6px 14px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.msg { position: relative; } .msg .quote { font-size: 12px; color: var(--muted); border-inline-start: 3px solid var(--brand); padding-inline-start: 6px; margin-bottom: 3px; }
.msg .more { position: absolute; top: 2px; inset-inline-end: 4px; border: 0; background: none; cursor: pointer; color: var(--muted); opacity: 0; font-size: 16px; line-height: 1; }
.msg:hover .more { opacity: 1; }
.presence.on { color: var(--brand-dark); font-weight: 600; }

/* login screen */
.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(400px, 100%); text-align: center; }
.login .card { text-align: start; margin-top: 20px; }

/* chat ui */
.chat { display: grid; grid-template-columns: 330px 1fr; height: 100vh; }
.chat.single { grid-template-columns: 1fr; }
.chats { background: var(--panel); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chats header { padding: 14px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.chats header strong { flex: 1; }
.chat-list { overflow: auto; flex: 1; }
.chat-item { display: flex; gap: 11px; padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--line); align-items: center; }
.chat-item:hover { background: var(--bg); }
.chat-item.active { background: var(--brand-soft); }
.chat-item .txt { min-width: 0; flex: 1; }
.chat-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .last { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.badge { background: var(--brand); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark); display: grid; place-items: center; font-weight: 700; flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.thread { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.thread header { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; gap: 12px; align-items: center; }
.thread header .t small { display: block; color: var(--muted); }
.msgs { flex: 1; overflow: auto; padding: 18px 8%; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 72%; padding: 7px 11px; border-radius: 12px; background: var(--bubble-in); box-shadow: var(--shadow); align-self: flex-start; white-space: pre-wrap; word-break: break-word; }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg .who { font-size: 12px; font-weight: 700; color: var(--brand-dark); }
.msg time { display: block; text-align: end; font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg img.media { max-width: 280px; max-height: 280px; border-radius: 8px; display: block; margin-bottom: 4px; }
.msg .file { display: inline-flex; gap: 6px; align-items: center; background: rgba(0,0,0,.05); border-radius: 8px; padding: 6px 9px; margin-bottom: 4px; cursor: pointer; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 14px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 140px; min-height: 40px; }
.placeholder { display: grid; place-items: center; color: var(--muted); height: 100%; text-align: center; }
.pad { padding: 20px; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { flex-direction: row; overflow: auto; border-inline-end: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .logo { padding: 0 8px; } .side .spacer { display: none; }
  .chat { grid-template-columns: 1fr; } .chats.hide-mobile, .thread.hide-mobile { display: none; }
  .main { padding: 18px 14px; } .msgs { padding: 14px 10px; } .msg { max-width: 88%; }
}
