:root {
  --work: #0F9D6E; --personal: #1E6FD9; --line: var(--work);
  --bg: #F4F6F8; --panel: #FFFFFF; --ink: #15202B; --muted: #657786; --rule: #E3E8EC;
  --bubble-in: #EEF1F4; --danger: #C62828;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0F1419; --panel: #172028; --ink: #E7ECEF; --muted: #8B98A5; --rule: #26323C; --bubble-in: #22303B; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.center { text-align: center; }
.fill { flex: 1; display: flex; align-items: center; justify-content: center; }
.screen { height: 100%; }

#pair { display: flex; align-items: center; justify-content: center; padding: 24px; }
.pair-card { background: var(--panel); border-radius: 20px; padding: 32px 36px; max-width: 760px; width: 100%;
  box-shadow: 0 8px 30px rgba(0,0,0,.08); }
.pair-logo { width: 48px; height: 48px; }
.pair-card h1 { margin: 12px 0 4px; font-size: 26px; }
.lead { margin: 0 0 24px; color: var(--muted); }
.pair-body { display: flex; gap: 32px; align-items: center; flex-wrap: wrap; }
.pair-body ol { flex: 1; min-width: 240px; line-height: 2; padding-left: 20px; margin: 0; }
.qr-wrap { text-align: center; }
#qr { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; min-width: 240px; min-height: 240px; }
#qr img { display: block; width: 232px; height: 232px; image-rendering: pixelated; }
.fine { font-size: 13px; color: var(--muted); margin: 24px 0 0; }

#app { display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel);
  border-bottom: 1px solid var(--rule); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand img { width: 26px; height: 26px; }
.tabs { display: flex; gap: 8px; flex: 1; justify-content: center; }
.tab { border: 2px solid var(--c); color: var(--c); background: transparent; border-radius: 999px;
  padding: 6px 16px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.tab[aria-selected="true"] { background: var(--c); color: #fff; }
.tab .count { background: #fff; color: var(--c); border-radius: 999px; font-size: 12px; padding: 0 7px; }
.tab[aria-selected="false"] .count { background: var(--c); color: #fff; }
.top-right { display: flex; gap: 12px; align-items: center; font-size: 13px; }
.phone-status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); margin-right: 6px; }
.phone-status.online::before { background: #2E7D32; }
.phone-status.offline::before { background: var(--danger); }
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; }

.layout { flex: 1; display: flex; min-height: 0; }
.list-pane { width: 340px; border-right: 1px solid var(--rule); background: var(--panel); display: flex; flex-direction: column; }
#search { margin: 12px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--rule); background: var(--bg); color: var(--ink); font: inherit; }
.conversations { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conversations li { display: flex; gap: 12px; padding: 12px 14px; cursor: pointer; border-left: 4px solid transparent; }
.conversations li:hover { background: var(--bg); }
.conversations li.active { background: var(--bg); border-left-color: var(--line); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--line); color: #fff; flex: none;
  display: flex; align-items: center; justify-content: center; font-weight: 700; }
.row-main { flex: 1; min-width: 0; }
.row-top { display: flex; justify-content: space-between; gap: 8px; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-time { font-size: 12px; color: var(--muted); flex: none; }
.row-preview { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread .row-name, .unread .row-preview { color: var(--ink); font-weight: 700; }
.badge { background: var(--line); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; margin-left: 6px; }

.thread-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: var(--panel);
  border-bottom: 1px solid var(--rule); border-top: 3px solid var(--line); }
.thread-name { font-weight: 700; }
.thread-sub { font-size: 13px; color: var(--muted); }
.back { display: none; border: 0; background: none; font-size: 28px; color: var(--ink); }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
.msg { max-width: 68%; padding: 8px 12px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.35; }
.msg.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 6px; }
.msg.out { align-self: flex-end; background: var(--line); color: #fff; border-bottom-right-radius: 6px; }
.msg .sender { font-size: 12px; font-weight: 700; opacity: .8; display: block; }
.msg .attach { font-style: italic; opacity: .85; display: block; }
.meta { font-size: 11px; color: var(--muted); margin: 0 6px 6px; }
.meta.out { align-self: flex-end; }
.meta.in { align-self: flex-start; }
.meta.bad { color: var(--danger); font-weight: 600; }
.msg.pending { opacity: .7; }
.msg.failed { background: var(--danger); }
.composer { display: flex; gap: 10px; padding: 12px 16px 4px; background: var(--panel); border-top: 1px solid var(--rule); }
.composer textarea { flex: 1; resize: none; border-radius: 20px; border: 1px solid var(--rule); padding: 10px 14px;
  font: inherit; background: var(--bg); color: var(--ink); max-height: 160px; }
.composer button { background: var(--line); color: #fff; border: 0; border-radius: 20px; padding: 0 22px; font-weight: 600; }
.composer button:disabled { opacity: .5; cursor: default; }
.composer-note { font-size: 12px; margin: 0; padding: 0 20px 10px; background: var(--panel); min-height: 18px; }

@media (max-width: 760px) {
  .tabs { justify-content: flex-start; }
  .brand span, .top-right .phone-status { font-size: 12px; }
  .list-pane { width: 100%; border-right: 0; }
  .layout.open .list-pane { display: none; }
  .layout:not(.open) .thread-pane { display: none; }
  .back { display: block; }
}
.pair-note { color: var(--danger); font-weight: 600; margin: 8px 0 0; }
.pair-note:empty { display: none; }
#reply { overflow-y: auto; scrollbar-width: none; }
.alerts-btn { background: none; border: 1px solid var(--rule); border-radius: 14px; padding: 4px 10px; color: var(--muted); }
.alerts-btn.on { border-color: currentColor; color: var(--ink); }
