:root {
  --bg: #f4f6f8; --panel: #ffffff; --line: #e2e8f0; --text: #0f172a; --muted: #64748b;
  --accent: #0e7490; --accent-2: #0891b2; --accent-soft: #e0f2fe; --danger: #b91c1c;
  --in: #ffffff; --out: #dcf3f8; --bot: #eef2ff; --ok: #16a34a; --warn: #d97706;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --panel: #111a2b; --line: #1f2b40; --text: #e2e8f0; --muted: #8796ad;
    --accent: #22b8cf; --accent-2: #67e8f9; --accent-soft: #0c2a3a; --danger: #f87171;
    --in: #172236; --out: #0f3442; --bot: #1d2246; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
label > input, label > textarea, label > select, label > .row { margin-top: 5px; color: var(--text); }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 9px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; }
.btn:disabled { opacity: .6; cursor: wait; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.err { color: var(--danger); min-height: 1.2em; }
.msg { min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.msg.ok { color: var(--ok); } .msg.bad { color: var(--danger); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; } .row.wrap > input { flex: 1 1 180px; width: auto; }
.row.two > label { flex: 1; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.brand { display: flex; gap: 10px; align-items: center; padding: 6px 4px 16px; }
.brand b { display: block; } .brand small { color: var(--muted); font-size: 12px; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; flex: none; }
.brand.big .logo { width: 44px; height: 44px; font-size: 20px; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px; box-shadow: 0 10px 30px rgba(0,0,0,.06); }
.login-card .btn { width: 100%; margin-top: 18px; }

.app { display: flex; height: 100vh; height: 100dvh; }
.side { width: 210px; flex: none; background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--text); text-decoration: none; border: 0; background: none; text-align: left; cursor: pointer; width: 100%; }
.nav:hover { background: var(--bg); } .nav.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav span { flex: 1; } .linklike { margin-top: auto; color: var(--muted); }
.pill { font-style: normal; background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.on { background: var(--ok); } .dot.off { background: var(--danger); } .dot.wait { background: var(--warn); }
.dot.big { width: 14px; height: 14px; }
main { flex: 1; min-width: 0; overflow: hidden; display: flex; }
.view { flex: 1; min-width: 0; }
.view.pad { overflow-y: auto; padding: 22px; }
.view.pad > * { max-width: 820px; }
h2 { margin: 0 0 16px; } h3 { margin: 0 0 8px; font-size: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 18px; }

/* chats */
.chats { display: flex; height: 100%; }
.list { width: 340px; flex: none; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.list-head { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); }
.contacts { overflow-y: auto; flex: 1; }
.contact { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.contact:hover { background: var(--bg); } .contact.active { background: var(--accent-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.c-main { flex: 1; min-width: 0; }
.c-top { display: flex; justify-content: space-between; gap: 6px; }
.c-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-top time { color: var(--muted); font-size: 12px; flex: none; }
.c-bot { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); font-size: 13px; }
.c-bot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-bot .pill { flex: none; }
.empty { margin: auto; color: var(--muted); padding: 20px; text-align: center; }
.conv { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.conv-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.conv-head .who { flex: 1; min-width: 0; } .conv-head .who b, .conv-head .who small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-head small { color: var(--muted); }
.conv-head select { width: auto; padding: 6px 8px; }
.back { display: none; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.paused { background: #fef3c7; color: #92400e; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 2px 10px; border-radius: 10px; margin: 8px 0; }
.bubble { max-width: min(560px, 82%); padding: 8px 11px 6px; border-radius: 12px; background: var(--in); border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.bubble.out { align-self: flex-end; background: var(--out); }
.bubble.bot { background: var(--bot); }
.bubble .meta { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 3px; }
.bubble img, .bubble video { max-width: 100%; max-height: 320px; border-radius: 8px; display: block; margin-bottom: 4px; }
.bubble audio { width: 260px; max-width: 100%; }
.bubble a { color: var(--accent); }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px; background: var(--panel); border-top: 1px solid var(--line); }
.composer .grow { flex: 1; min-width: 0; }
.composer textarea { max-height: 160px; resize: none; }
.chip { font-size: 13px; background: var(--accent-soft); color: var(--accent); padding: 4px 10px; border-radius: 8px; margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; }
.chip button { border: 0; background: none; cursor: pointer; color: inherit; }
.info { width: 290px; flex: none; border-left: 1px solid var(--line); background: var(--panel); padding: 16px; overflow-y: auto; }

.qrbox { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.qrbox img { width: 260px; height: 260px; background: #fff; padding: 8px; border-radius: 12px; border: 1px solid var(--line); }
.qrbox ol { flex: 1; min-width: 220px; }
.switch { display: flex; gap: 10px; align-items: center; font-size: 15px; color: var(--text); }
.switch input { width: 20px; height: 20px; }
.tester { margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 6px; }
.tester .btn { margin-top: 8px; }
pre { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: inherit; }
.users { list-style: none; padding: 0; margin: 0 0 14px; }
.users li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 9; max-width: calc(100% - 32px); }

@media (max-width: 1100px) { .info { position: fixed; right: 0; top: 0; bottom: 0; z-index: 5; box-shadow: -10px 0 30px rgba(0,0,0,.15); } }
@media (max-width: 760px) {
  .app { flex-direction: column-reverse; }
  .side { width: 100%; flex-direction: row; padding: 4px; border-right: 0; border-top: 1px solid var(--line); justify-content: space-around; }
  .side .brand { display: none; }
  .nav { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; width: auto; position: relative; }
  .nav span { flex: none; } .linklike { margin-top: 0; }
  .nav .pill { position: absolute; top: 0; right: 0; }
  .nav .dot { position: absolute; top: 6px; right: 8px; }
  main { min-height: 0; }
  .view.pad { padding: 16px; }
  .list { width: 100%; border-right: 0; }
  .chats.open .list { display: none; }
  .chats:not(.open) .conv { display: none; }
  .back { display: inline-block; }
  .conv-head { flex-wrap: wrap; } .conv-head select { order: 5; flex: 1; }
  .row.two { flex-direction: column; align-items: stretch; }
  .info { width: 100%; }
}
