:root {
  color-scheme: light dark;
  --accent: #2aabee;
  --accent-2: #4cc2ff;
  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --text: #101820;
  --muted: #718190;
  --line: #dde6ee;
  --bubble-in: #ffffff;
  --bubble-out: #d8f2ff;
  --danger: #ef4444;
  --shadow: 0 16px 40px rgba(20, 40, 60, .16);
}

[data-theme="dark"] {
  --bg: #0e1621;
  --surface: #17212b;
  --surface-2: #202b36;
  --text: #ecf3f8;
  --muted: #8fa2b4;
  --line: #243341;
  --bubble-in: #212d38;
  --bubble-out: #1f526d;
  --shadow: 0 16px 40px rgba(0, 0, 0, .36);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, rgba(42,171,238,.22), transparent 36%), var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { border: 0; cursor: pointer; }
.phone-shell {
  width: min(100vw, 460px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.splash { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 12px; color: var(--muted); padding: 24px; }
.login-screen { background: var(--surface); text-align:center; }
.login-screen h1 { color: var(--text); margin: 0; }
.login-screen p { max-width: 320px; margin: 0; }
.login-form { width: min(100%, 330px); display:grid; gap: 10px; margin-top: 8px; }
.login-form input { width:100%; border:1px solid var(--line); color: var(--text); background: var(--surface-2); border-radius: 14px; padding: 13px 14px; outline: none; }
.login-form .primary { width:100%; padding: 13px 14px; }
.login-error { color: var(--danger); font-weight:700; }
.logo { width: 76px; height: 76px; display:grid; place-items:center; border-radius: 24px; background: var(--accent); color:#fff; font-weight:800; font-size: 28px; }
.app { min-height: 100vh; display: flex; flex-direction: column; background: var(--surface); }
.topbar { padding: max(12px, env(safe-area-inset-top)) 14px 10px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.topbar h1 { margin: 0; font-size: 22px; flex: 1; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; background: transparent; color: var(--accent); font-size: 20px; }
.icon-btn:hover { background: var(--surface-2); }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tab { white-space: nowrap; padding: 8px 13px; border-radius: 999px; color: var(--muted); background: var(--surface-2); font-weight: 600; }
.tab.active { background: var(--accent); color: #fff; }
.content { flex: 1; overflow-y: auto; padding-bottom: 78px; background: var(--bg); }
.chat-row { display: flex; gap: 12px; padding: 12px 14px; background: var(--surface); border-bottom: 1px solid var(--line); align-items: center; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #7c3aed); color: #fff; display:grid; place-items:center; font-weight: 800; flex: 0 0 auto; }
.chat-main { min-width: 0; flex: 1; }
.chat-title { display: flex; gap: 6px; align-items: center; font-weight: 700; }
.chat-title span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { margin-left: auto; display:flex; gap:4px; align-items:center; white-space: nowrap; }
.badge-pill { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent); border-radius: 999px; padding: 2px 6px; font-size: 11px; font-weight: 900; }
.chat-last { margin-top: 4px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-meta { display: grid; justify-items: end; gap: 8px; color: var(--muted); font-size: 12px; }
.unread { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--accent); color: #fff; display:grid; place-items:center; font-size: 12px; font-weight: 800; }
.bottom-nav { position: absolute; left: 0; right: 0; bottom: 0; padding: 7px 8px max(7px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 1fr); background: color-mix(in srgb, var(--surface) 94%, transparent); border-top: 1px solid var(--line); backdrop-filter: blur(12px); }
.nav-item { background: transparent; color: var(--muted); border-radius: 14px; padding: 7px 3px; display:grid; gap: 2px; justify-items:center; font-size: 11px; font-weight: 700; }
.nav-item strong { font-size: 20px; line-height: 1; }
.nav-item.active { color: var(--accent); background: var(--surface-2); }
.chat-view { background: var(--bg); padding-bottom: 72px; }
.chat-header { position: sticky; top: 0; z-index: 5; padding: max(10px, env(safe-area-inset-top)) 10px 9px; background: var(--surface); border-bottom: 1px solid var(--line); display:flex; align-items:center; gap:10px; }
.chat-header .avatar { width: 42px; height: 42px; font-size: 14px; }
.chat-header-main { min-width:0; flex:1; }
.chat-header-main h1 { margin:0; font-size:17px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-header-main small { color: var(--muted); display:block; margin-top:2px; }
.back-btn { font-size: 30px; line-height: 1; }
.messages { padding: 14px; display: grid; gap: 10px; }
.bubble { max-width: 82%; padding: 10px 12px 7px; border-radius: 18px; line-height: 1.35; box-shadow: 0 1px 0 rgba(0,0,0,.04); }
.bubble.in { justify-self: start; background: var(--bubble-in); border-bottom-left-radius: 5px; }
.bubble.out { justify-self: end; background: var(--bubble-out); border-bottom-right-radius: 5px; }
.bubble-time { margin-top: 4px; text-align:right; color: var(--muted); font-size: 10px; }
.chat-empty-card { margin: 26px auto; width:min(100%, 360px); background: var(--surface); border:1px solid var(--line); border-radius:22px; padding:18px; text-align:center; box-shadow: 0 8px 22px rgba(20,40,60,.08); }
.chat-empty-icon { width:58px; height:58px; border-radius:20px; display:grid; place-items:center; margin:0 auto 10px; background:var(--surface-2); font-size:26px; }
.chat-empty-card p { color:var(--muted); margin:8px 0 12px; line-height:1.35; }
.last-preview { margin:12px 0; padding:12px; border-radius:14px; text-align:left; background:var(--surface-2); color:var(--text); line-height:1.35; }
.last-preview span { display:block; color:var(--muted); font-size:12px; font-weight:800; margin-bottom:4px; }
.composer { position:absolute; left: 0; right:0; bottom:0; padding: 8px 10px max(8px, env(safe-area-inset-bottom)); display:flex; gap:8px; align-items:flex-end; background: var(--surface); border-top:1px solid var(--line); }
.composer-main { flex:1; min-width:0; display:grid; gap:4px; }
.composer input, .search-input { width:100%; border:1px solid var(--line); color: var(--text); background: var(--surface-2); border-radius: 999px; padding: 11px 14px; outline: none; }
.send-status, .chat-status { font-size: 12px; color: var(--muted); padding: 0 4px; }
.chat-status { justify-self:center; background: var(--surface); border:1px solid var(--line); border-radius:999px; padding: 6px 10px; }
.send-status.ok, .chat-status.ok { color:#16a34a; }
.send-status.error, .chat-status.error { color: var(--danger); }
.composer-disabled { color: var(--muted); }
.composer-disabled input { opacity:.9; }
.composer-disabled button { opacity:.65; cursor:not-allowed; }
.send-disabled { background: var(--surface-2); color: var(--muted); border-radius:999px; padding: 10px 12px; font-weight:800; }
.send-btn { background: var(--accent); color: white; border-radius:999px; min-width:42px; padding: 10px 12px; font-weight:900; }
.send-btn:disabled { opacity:.55; cursor:wait; }
.panel { margin: 10px; border-radius: 18px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); }
.panel-title { padding: 14px 16px; color: var(--muted); font-weight: 800; text-transform: uppercase; font-size: 12px; letter-spacing: .04em; }
.menu-row { display:flex; align-items:center; gap:12px; padding: 14px 16px; border-top: 1px solid var(--line); background: var(--surface); color: var(--text); width: 100%; text-align: left; }
.menu-row small { display:block; color: var(--muted); margin-top: 3px; }
.menu-row .grow { flex:1; }
.primary { background: var(--accent); color: white; padding: 9px 12px; border-radius: 12px; font-weight:800; }
.secondary { background: var(--surface-2); color: var(--text); padding: 9px 12px; border-radius: 12px; font-weight:800; }
.search-wrap { padding: 12px; background: var(--surface); border-bottom:1px solid var(--line); }
.empty { color: var(--muted); text-align:center; padding: 36px 20px; }
.platform-dot { width: 10px; height:10px; border-radius:50%; background: var(--muted); display:inline-block; }
.platform-dot.online { background: #22c55e; box-shadow: 0 0 0 4px color-mix(in srgb, #22c55e 18%, transparent); }
.qr-shot { width:100%; border-radius: 14px; border:1px solid var(--line); margin-top: 10px; display:block; }
.qr-row { display:block; }
.qr-box { position:relative; width:100%; }
.qr-box.stale .qr-shot { filter: grayscale(.9) blur(1px); opacity:.56; }
.qr-overlay { position:absolute; inset:10px 0 0; display:grid; place-items:center; border-radius:14px; background:rgba(0,0,0,.42); color:#fff; font-weight:900; letter-spacing:.02em; }
.qr-warning { width:100%; margin:0; color:var(--muted); text-align:center; }
@media (min-width: 700px) { body { padding: 22px 0; } .phone-shell { min-height: calc(100vh - 44px); border-radius: 34px; } }
