/* White-label Chat — Android-inspired Material design */
:root {
  --primary: #2563EB;
  --secondary: #8B5CF6;
  --primary-weak: color-mix(in srgb, var(--primary) 12%, transparent);
  --primary-soft: color-mix(in srgb, var(--primary) 20%, var(--surface));
  --on-primary: #fff;
  --bg: #F3F5FA;
  --surface: #FFFFFF;
  --surface-2: #F7F8FC;
  --surface-3: #EEF1F7;
  --text: #111827;
  --muted: #6B7280;
  --border: #E5E7EB;
  --bubble-in: #FFFFFF;
  --bubble-out: var(--primary);
  --bubble-out-text: #fff;
  --chat-bg: #EEF2F8;
  --ok: #16A34A;
  --warn: #D97706;
  --bad: #DC2626;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --rail-w: 84px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0B1120;
  --surface: #111827;
  --surface-2: #162033;
  --surface-3: #1F2A3F;
  --text: #E5E7EB;
  --muted: #94A3B8;
  --border: #243049;
  --bubble-in: #1F2A3F;
  --chat-bg: #0D1526;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
#app { height: 100%; }
a { color: var(--primary); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; }
h2 { font-size: 1.35rem; }
h4 { font-size: 1rem; }
code { background: var(--surface-3); padding: 2px 6px; border-radius: 6px; font-size: .85em; word-break: break-all; }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.block { display: block; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ellipsis-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.danger-text { color: var(--bad); }
.warn-text { color: var(--warn); }
.primary-text { color: var(--primary); }
.ic { flex: none; vertical-align: middle; }

.boot, .empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; height: 100%; color: var(--muted); text-align: center; padding: 24px; }
.empty.small { height: auto; padding: 40px 16px; }
.empty .ic { opacity: .5; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--primary-weak); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); padding: 9px 16px; border-radius: 999px; font-weight: 600; font-size: .92rem; transition: background .15s, box-shadow .15s; white-space: nowrap; }
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: 0 2px 6px color-mix(in srgb, var(--primary) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.outline { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { padding: 6px 12px; font-size: .82rem; }
.btn.block { width: 100%; padding: 12px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.danger { color: var(--bad); }
.icon-btn.light { color: #fff; }
.icon-btn.light:hover { background: rgba(255,255,255,.15); }
.link-btn { background: none; border: 0; color: var(--primary); font-weight: 600; padding: 0 4px; }

.chip { border: 1px solid var(--border); background: var(--surface); padding: 6px 14px; border-radius: 999px; font-size: .85rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.chip.active { background: var(--primary-weak); color: var(--primary); border-color: transparent; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--surface-3); color: var(--muted); text-transform: capitalize; }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.pill.off { background: var(--surface-3); color: var(--muted); }
.role-chip { display: inline-block; padding: 2px 10px; border-radius: 8px; background: var(--primary-weak); color: var(--primary); font-size: .75rem; font-weight: 700; text-transform: capitalize; }
.tag { font-size: .7rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--surface-3); color: var(--muted); }
.tag.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--primary); color: #fff; font-size: .72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

/* Avatars */
.avatar { position: relative; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff; font-weight: 700; flex: none; overflow: visible; background: var(--surface-3); }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar.group { background: var(--primary-weak); color: var(--primary); }
.presence { position: absolute; right: 0; bottom: 0; width: 28%; height: 28%; min-width: 10px; min-height: 10px; border-radius: 50%; background: #9CA3AF; border: 2px solid var(--surface); }
.presence.on { background: #22C55E; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 30%; color: #fff; font-weight: 800; background: linear-gradient(135deg, var(--primary), var(--secondary)); }
.brand-mark.sm { width: 32px; height: 32px; font-size: 16px; }
.brand-logo { object-fit: contain; border-radius: 22%; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .copy-row input, .conn-select {
  width: 100%; border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 11px 14px; font-weight: 400; color: var(--text); outline: none; transition: border .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); background: var(--surface); }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 16px; }
.field.inline input { width: 110px; }
.field small, .switch-row small { display: block; font-weight: 400; color: var(--muted); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; cursor: pointer; }
.switch-row + .switch-row { border-top: 1px solid var(--border); }
.switch-row input { display: none; }
.switch-row i { flex: none; width: 44px; height: 26px; border-radius: 13px; background: #CBD5E1; position: relative; transition: background .2s; }
.switch-row i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch-row input:checked + i { background: var(--primary); }
.switch-row input:checked + i::after { transform: translateX(18px); }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--surface-3); border-radius: 999px; padding: 0 14px; color: var(--muted); margin-bottom: 8px; }
.search-box input { flex: 1; border: 0; background: transparent; padding: 10px 0; outline: none; min-width: 0; }

/* Auth */
.auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(circle at 20% 0%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 50%), radial-gradient(circle at 100% 100%, color-mix(in srgb, var(--secondary) 18%, transparent), transparent 50%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 28px; padding: 32px 28px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 14px; }
.auth-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 4px; }
.auth-brand .brand-mark { border-radius: 30%; }
.auth-brand h1 { font-size: 1.6rem; margin: 6px 0 0; }
.get-app { display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; font-size: .9rem; }
.powered { text-align: center; color: var(--muted); font-size: .75rem; margin: 4px 0 0; }

/* Shell */
.shell { display: flex; height: 100%; }
.rail { width: var(--rail-w); flex: none; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; }
.rail-brand { margin-bottom: 12px; }
.rail-brand img { object-fit: contain; border-radius: 12px; }
.rail-item { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; width: 68px; padding: 8px 0; border-radius: 16px; color: var(--muted); font-size: .7rem; font-weight: 600; }
.rail-item .ic { padding: 4px 18px; box-sizing: content-box; border-radius: 16px; transition: background .15s; }
.rail-item:hover .ic { background: var(--surface-3); }
.rail-item.active { color: var(--primary); }
.rail-item.active .ic { background: var(--primary-weak); }
.rail-me { margin-top: auto; }
.nav-badge { position: absolute; top: 2px; right: 8px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .65rem; font-style: normal; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.view { flex: 1; min-width: 0; height: 100%; overflow: hidden; display: flex; flex-direction: column; }
.view-calls, .view-profile, .view-people { overflow-y: auto; }
.bottom-nav { display: none; }
.offline-bar { position: fixed; top: 0; left: 50%; transform: translateX(-50%); background: var(--warn); color: #fff; padding: 4px 16px; border-radius: 0 0 12px 12px; font-size: .8rem; font-weight: 600; z-index: 50; }

/* Chat layout */
.chat-layout { display: flex; height: 100%; min-height: 0; }
.conv-pane { width: 360px; flex: none; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); padding: 14px 12px 0; min-height: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 8px; }
.pane-head h2 { margin: 0; display: flex; align-items: center; gap: 10px; }
.pane-brand { display: none; }
.empty-brand { display: inline-flex; margin-bottom: 4px; }
.conv-list { flex: 1; overflow-y: auto; margin: 0 -12px; padding: 0 6px 12px; }
.conv-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border: 0; background: transparent; border-radius: 16px; text-align: left; }
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--primary-weak); }
.ci-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ci-top, .ci-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ci-top b { flex: 1; font-weight: 650; }
.ci-top time { font-size: .75rem; color: var(--muted); flex: none; }
.ci-top time.hl { color: var(--primary); font-weight: 700; }
.ci-bottom .preview { flex: 1; color: var(--muted); font-size: .88rem; }
.preview.typing, .typing { color: var(--primary) !important; font-style: italic; }

.thread-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); position: relative; min-height: 0; }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); min-height: 64px; }
.thread-head .back { display: none; }
.th-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.th-info small { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-text { color: var(--ok); }
.th-actions { display: flex; gap: 2px; }
.th-actions .icon-btn { color: var(--primary); }
.banner { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); padding: 8px 16px; font-size: .85rem; text-align: center; }
.banner.muted { background: var(--surface-2); }

.messages { flex: 1; overflow-y: auto; padding: 16px 6% 8px; display: flex; flex-direction: column; gap: 3px; min-height: 0; }
.day { text-align: center; margin: 10px 0; }
.day span, .sys span { background: var(--surface); color: var(--muted); font-size: .75rem; padding: 4px 12px; border-radius: 10px; box-shadow: var(--shadow); }
.sys { text-align: center; margin: 6px 0; }
.load-older { text-align: center; margin-bottom: 8px; }
.msg { display: flex; }
.msg.out { justify-content: flex-end; }
.bubble { max-width: min(560px, 78%); background: var(--bubble-in); padding: 7px 10px 6px; border-radius: 18px 18px 18px 6px; box-shadow: var(--shadow); position: relative; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); border-radius: 18px 18px 6px 18px; }
.msg.out .bubble a { color: #fff; text-decoration: underline; }
.msg + .msg.in .bubble, .msg + .msg.out .bubble { margin-top: 2px; }
.sender { font-size: .78rem; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.text { white-space: pre-wrap; }
.text.deleted { font-style: italic; opacity: .7; display: flex; gap: 6px; align-items: center; }
.meta { float: right; display: inline-flex; align-items: center; gap: 3px; font-size: .68rem; opacity: .75; margin: 6px 0 -2px 10px; }
.tick.read { color: #7DD3FC; }
.msg.in .tick.read { color: var(--primary); }
.tick.failed { color: #FCA5A5; font-weight: 800; }
.msg-media { display: block; border: 0; padding: 0; background: none; margin: -3px -6px 4px; border-radius: 14px; overflow: hidden; max-width: 320px; }
.msg-media img { display: block; width: 100%; max-height: 360px; object-fit: cover; min-width: 160px; min-height: 100px; background: var(--surface-3); }
.msg-video { display: block; max-width: 320px; width: 100%; border-radius: 12px; margin: -2px -4px 4px; background: #000; }
.voice { display: flex; align-items: center; gap: 6px; min-width: 240px; }
.voice audio { height: 36px; flex: 1; min-width: 0; }
.voice .dur { font-size: .75rem; opacity: .8; }
.file-card { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; background: color-mix(in srgb, currentColor 8%, transparent); color: inherit !important; text-decoration: none !important; min-width: 220px; max-width: 320px; }
.file-ic { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, currentColor 12%, transparent); }
.file-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-meta small { opacity: .75; }
.call-bubble { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bubble-in); border-radius: 18px; box-shadow: var(--shadow); min-width: 240px; }
.msg.out .call-bubble { background: var(--primary-soft); }
.call-bubble span:nth-child(2) { flex: 1; display: flex; flex-direction: column; }
.call-bubble small { color: var(--muted); font-size: .75rem; }
.call-ic { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.call-bubble.missed .call-ic { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.typing-bubble { display: flex; gap: 4px; padding: 12px 14px; }
.typing-bubble i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing-bubble i:nth-child(2) { animation-delay: .2s; }
.typing-bubble i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); position: relative; }
.input-wrap { flex: 1; background: var(--surface-3); border-radius: 24px; padding: 2px 16px; display: flex; min-width: 0; }
.input-wrap textarea { flex: 1; border: 0; background: transparent; resize: none; outline: none; padding: 9px 0; max-height: 140px; line-height: 1.4; }
.fab-send { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 40%, transparent); }
.attach-wrap { position: relative; }
.menu { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 6px; display: flex; flex-direction: column; min-width: 210px; z-index: 40; border: 1px solid var(--border); }
.menu button { display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 11px 14px; border-radius: 10px; text-align: left; }
.menu button:hover { background: var(--surface-3); }
.menu button.danger { color: var(--bad); }
.attach-menu { position: absolute; bottom: 52px; left: 0; }
.menu.popup { position: fixed; }
.composer.recording > :not(.rec-bar) { visibility: hidden; }
.rec-bar { position: absolute; inset: 0; display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface); }
.rec-bar .fab-send { margin-left: auto; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bad); animation: blink 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 700; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 80; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 96vw; max-height: 88vh; object-fit: contain; }
.lb-bar { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }

/* Pages */
.page { padding: 20px 24px 40px; width: 100%; }
.page.narrow { max-width: 760px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.head-actions { display: flex; gap: 8px; align-items: center; }
.card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; border: 1px solid var(--border); }
.list-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.lr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lr-main small { color: var(--muted); display: flex; align-items: center; gap: 4px; text-transform: none; }
.profile-card { display: flex; align-items: center; gap: 20px; }
.avatar-edit { position: relative; cursor: pointer; }
.avatar-edit .cam { position: absolute; right: 0; bottom: 0; width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; border: 3px solid var(--surface); }
.seg { display: flex; gap: 6px; background: var(--surface-3); padding: 4px; border-radius: 14px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 10px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; }
.seg button.active { background: var(--surface); box-shadow: var(--shadow); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.online { background: #22C55E; } .dot.away { background: #F59E0B; } .dot.offline { background: #9CA3AF; }
.list-actions { padding: 6px; }
.row-btn { display: flex; align-items: center; gap: 14px; width: 100%; padding: 13px 12px; border: 0; background: none; border-radius: 12px; text-align: left; font-weight: 600; color: var(--text); }
.row-btn small { margin-left: auto; color: var(--muted); font-weight: 400; }
.row-btn:hover { background: var(--surface-3); }
.row-btn.danger { color: var(--bad); }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }

/* Admin */
.admin { display: flex; height: 100%; min-height: 0; }
.admin-nav { width: 230px; flex: none; background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.admin-nav.dark { background: #0F172A; color: #CBD5E1; border-color: #1E293B; }
.admin-nav.dark a { color: #94A3B8; }
.admin-nav.dark a.active, .admin-nav.dark a:hover { background: rgba(255,255,255,.08); color: #fff; }
.admin-brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 16px; font-size: 1.05rem; }
.admin-brand > span { display: inline-flex; }
.admin-brand img { object-fit: contain; border-radius: 8px; }
.admin-nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.admin-nav a:hover { background: var(--surface-3); color: var(--text); }
.admin-nav a.active { background: var(--primary-weak); color: var(--primary); }
.admin-main { flex: 1; overflow-y: auto; padding: 22px 26px 60px; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); }
.stat small { color: var(--muted); font-weight: 600; display: block; }
.stat b { font-size: 1.45rem; }
.stat-ic { width: 44px; height: 44px; border-radius: 14px; background: var(--primary-weak); color: var(--primary); display: flex; align-items: center; justify-content: center; flex: none; }
.stat.warn .stat-ic { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.stat.ok .stat-ic { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card, .grid-2 + .grid-2 { margin-top: 16px; }
.chart-title { font-weight: 700; margin-bottom: 10px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 170px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 4px; }
.bar { width: 100%; max-width: 28px; min-height: 3px; border-radius: 8px 8px 3px 3px; background: linear-gradient(180deg, var(--primary), var(--secondary)); position: relative; }
.bar span { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: .68rem; color: var(--muted); }
.bar-col small { font-size: .68rem; color: var(--muted); }
.table-wrap { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.inactive td { opacity: .55; }
.table .btn + .btn { margin-left: 6px; }
.cell-user { display: flex; align-items: center; gap: 10px; }
.cell-user span { display: flex; flex-direction: column; min-width: 0; }
.cell-user small { color: var(--muted); }
.mode-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mode-card { border: 2px solid var(--border); border-radius: var(--radius); padding: 16px; background: var(--surface); cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.mode-card input { accent-color: var(--primary); width: 18px; height: 18px; }
.mode-card small { color: var(--muted); }
.mode-card.selected { border-color: var(--primary); background: var(--primary-weak); }
.theme-cards { display: flex; gap: 10px; }
.theme-card { flex: 1; border: 2px solid var(--border); border-radius: 14px; padding: 10px; text-align: center; cursor: pointer; color: var(--text); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.theme-card input { display: none; }
.theme-card.selected { border-color: var(--primary); }
.tc-preview { width: 44px; height: 30px; border-radius: 8px; border: 1px solid var(--border); }
.tc-preview.light { background: #fff; } .tc-preview.dark { background: #111827; } .tc-preview.system { background: linear-gradient(90deg, #fff 50%, #111827 50%); }
.color-field { display: flex; align-items: center; gap: 10px; }
.color-field input[type=color] { width: 52px; height: 40px; padding: 2px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.logo-drop { display: flex; align-items: center; gap: 16px; padding: 14px; border: 2px dashed var(--border); border-radius: 16px; transition: border-color .15s, background .15s; }
.logo-drop.over { border-color: var(--primary); background: var(--primary-weak); }
.logo-drop-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.logo-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.logo-preview { flex: none; object-fit: contain; border-radius: 18px; background: var(--surface-3); }
#apk-notice { margin-top: 10px; }
#apk-notice span { flex: 1; }
.phone-preview { width: 240px; margin: 10px auto; border-radius: 26px; border: 8px solid #111827; overflow: hidden; background: var(--chat-bg); }
.pp-bar { background: var(--primary); color: #fff; padding: 14px; display: flex; align-items: center; gap: 10px; }
.pp-bar .brand-logo { background: #fff; border-radius: 8px; }
.pp-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 160px; }
.pp-in, .pp-out { padding: 8px 12px; border-radius: 14px; font-size: .82rem; max-width: 80%; }
.pp-in { background: var(--bubble-in); }
.pp-out { background: var(--primary); color: #fff; align-self: flex-end; }
.pp-btn { margin: 12px; padding: 10px; border-radius: 999px; color: #fff; text-align: center; font-weight: 700; background: linear-gradient(90deg, var(--primary), var(--secondary)); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.media-tile { position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden; background: var(--surface-3); }
.media-tile img { width: 100%; height: 100%; object-fit: cover; }
.media-tile span { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 8px; font-size: .72rem; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.6)); }
.progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin: 10px 0; }
.progress div { height: 100%; width: 40%; background: var(--primary); border-radius: 3px; animation: indet 1.4s infinite ease-in-out; }
@keyframes indet { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
.log { max-height: 300px; overflow: auto; background: #0F172A; color: #E2E8F0; padding: 12px; border-radius: 10px; font-size: .75rem; white-space: pre-wrap; }
.copy-row { display: flex; gap: 8px; margin: 10px 0; }
.notice { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 14px; background: var(--surface-2); font-size: .88rem; }
.notice.danger { background: color-mix(in srgb, var(--bad) 10%, var(--surface)); color: var(--bad); font-weight: 600; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.conn-select { width: auto; min-width: 220px; }
.cert-box { background: var(--surface-2); border-radius: 12px; padding: 12px; font-size: .85rem; }
.cert-box p { margin: 0 0 8px; }
.super-msgs { display: flex; flex-direction: column; max-height: 60vh; overflow-y: auto; }
.sm-row { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.sm-row p { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; }
.tabs-inline { display: flex; gap: 8px; margin-bottom: 12px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 70; animation: fade .15s; }
.modal { width: 100%; max-width: 480px; max-height: 92vh; display: flex; flex-direction: column; background: var(--surface); border-radius: 24px; box-shadow: var(--shadow-lg); animation: pop .18s; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 12px 8px 22px; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 4px 22px 16px; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 22px 20px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.pick-list { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow-y: auto; }
.pick-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border: 0; border-radius: 12px; background: none; text-align: left; cursor: pointer; }
.pick-item:hover { background: var(--surface-3); }
.pick-item.selected { background: var(--primary-weak); }
.pick-item span { display: flex; flex-direction: column; }
.pick-item small { color: var(--muted); text-transform: capitalize; }
.pick-item input { accent-color: var(--primary); width: 18px; height: 18px; }

/* Toasts */
#banners { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 12px; z-index: 95; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 24px)); }
.notif-banner { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 12px 14px; border: 0; border-left: 4px solid var(--primary); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); animation: pop .2s; }
.notif-banner span { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#toasts { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; width: max-content; max-width: 92vw; }
.toast { background: #1F2937; color: #fff; padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: .9rem; opacity: 0; transform: translateY(10px); transition: all .25s; text-align: center; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--bad); }
.toast.success { background: var(--ok); }

/* Calls */
#call-root { position: fixed; inset: 0; z-index: 90; }
.call-screen { position: absolute; inset: 0; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: calc(48px + env(safe-area-inset-top)) 20px calc(36px + env(safe-area-inset-bottom)); background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--primary) 70%, #0F172A), #0B1120 70%); overflow: hidden; }
.call-screen.video { background: #000; }
.call-center { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; z-index: 2; }
.call-center h2 { font-size: 1.6rem; margin: 10px 0 0; }
.call-center p { margin: 0; opacity: .85; font-variant-numeric: tabular-nums; }
.call-screen.video.connected .call-center { position: absolute; top: calc(18px + env(safe-area-inset-top)); left: 18px; align-items: flex-start; text-align: left; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.call-screen.video.connected .call-center h2 { font-size: 1.15rem; margin: 0; }
.call-screen .avatar { box-shadow: 0 0 0 10px rgba(255,255,255,.08), 0 0 0 22px rgba(255,255,255,.04); }
#call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.call-screen.peer-video-off #call-remote { opacity: .15; }
.pip { position: absolute; right: 16px; top: calc(16px + env(safe-area-inset-top)); width: 120px; height: 170px; object-fit: cover; border-radius: 16px; border: 2px solid rgba(255,255,255,.7); background: #111; z-index: 3; box-shadow: var(--shadow-lg); }
.call-screen.video:not(.connected) .pip { inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; z-index: 0; opacity: .55; }
.mirror { transform: scaleX(-1); }
.peer-muted { display: inline-flex; align-items: center; gap: 4px; background: rgba(0,0,0,.4); padding: 2px 10px; border-radius: 10px; font-size: .8rem; margin-top: 6px !important; }
.call-controls { display: flex; gap: 18px; z-index: 3; flex-wrap: wrap; justify-content: center; background: rgba(15, 23, 42, .45); padding: 14px 18px; border-radius: 28px; backdrop-filter: blur(10px); margin-top: auto; }
.call-screen.incoming .call-controls { gap: 70px; background: none; }
.cc { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .75rem; opacity: .95; }
.round { width: 58px; height: 58px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff; display: flex; align-items: center; justify-content: center; transition: transform .1s, background .15s; }
.round:active { transform: scale(.94); }
.round.on { background: #fff; color: #111827; }
.round.red { background: #EF4444; }
.round.green { background: #22C55E; }
.round.pulse { animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.6); } 100% { box-shadow: 0 0 0 22px rgba(34,197,94,0); } }
body.in-call { overflow: hidden; }

/* Responsive: Android-style mobile layout */
@media (max-width: 899px) {
  .shell { flex-direction: column; }
  .rail { display: none; }
  .view { flex: 1; min-height: 0; }
  .bottom-nav { display: flex; flex: none; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottom-nav a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .7rem; font-weight: 600; flex: 1; padding: 2px 0; }
  .bottom-nav a .ic { padding: 4px 18px; box-sizing: content-box; border-radius: 16px; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav a.active .ic { background: var(--primary-weak); }
  .bottom-nav .nav-badge { right: calc(50% - 26px); }
  .shell:has(.chat-layout.has-active) .bottom-nav, .shell:has(.chat-layout.has-active) .offline-bar { display: none; }
  .conv-pane { width: 100%; border-right: 0; }
  .pane-brand { display: inline-flex; }
  .thread-pane { display: none; }
  .chat-layout.has-active .conv-pane { display: none; }
  .chat-layout.has-active .thread-pane { display: flex; }
  .thread-head { padding: 8px 6px; background: var(--primary); color: #fff; border: 0; padding-top: calc(8px + env(safe-area-inset-top)); }
  .thread-head .back { display: inline-flex; color: #fff; }
  .thread-head .th-actions .icon-btn, .thread-head .icon-btn { color: #fff; }
  .thread-head .th-info small { color: rgba(255,255,255,.85); }
  .thread-head .online-text, .thread-head .typing { color: #fff !important; }
  .messages { padding: 12px 10px 8px; }
  .bubble { max-width: 85%; }
  .admin { flex-direction: column; }
  .admin-nav { width: 100%; flex-direction: row; padding: 8px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); gap: 4px; flex: none; }
  .admin-nav a { flex: none; padding: 8px 12px; }
  .admin-nav a span { white-space: nowrap; }
  .admin-brand { display: none; }
  .admin-main { padding: 16px 14px 40px; }
  .grid-2, .mode-cards, .row-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px; gap: 10px; }
  .stat b { font-size: 1.15rem; }
  .stat-ic { width: 36px; height: 36px; }
  .page { padding: 16px 14px 40px; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 24px 24px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .profile-card { flex-direction: column; text-align: center; }
  .call-controls { gap: 12px; padding: 12px; }
  .round { width: 54px; height: 54px; }
  #toasts { bottom: 80px; }
}
