:root {
  --bg: #0F1613;
  --surface: #161F1B;
  --surface-raised: #1C2622;
  --border: #263630;
  --text: #EAEFEA;
  --text-muted: #8FA39A;
  --accent: #2E9B6F;
  --accent-dim: #1F6E4E;
  --accent-soft: rgba(46, 155, 111, 0.12);
  --warn: #E0A63D;
  --warn-soft: rgba(224, 166, 61, 0.12);
  --danger: #D9604F;
  --danger-soft: rgba(217, 96, 79, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --radius: 12px;
}

:root[data-theme="light"] {
  --bg: #F6F8F6;
  --surface: #FFFFFF;
  --surface-raised: #EEF2EF;
  --border: #DDE6E0;
  --text: #142019;
  --text-muted: #5C6E65;
  --accent: #22885E;
  --accent-dim: #1B6E4C;
  --accent-soft: rgba(34, 136, 94, 0.10);
  --warn: #B87A16;
  --warn-soft: rgba(184, 122, 22, 0.10);
  --danger: #C24631;
  --danger-soft: rgba(194, 70, 49, 0.10);
}

* { box-sizing: border-box; }
::selection { background: var(--accent); color: #06120C; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  transition: background .15s ease, color .15s ease;
  -webkit-font-smoothing: antialiased;
}

svg { display: block; }

/* ================= LOGIN ================= */
#login-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 50; overflow: hidden; }
#login-screen.hidden { display: none; }

.login-bg { position: absolute; inset: 0; overflow: hidden; }
.orb { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .32; animation: orb-float 14s ease-in-out infinite; }
.orb-1 { width: 380px; height: 380px; background: var(--accent); top: -100px; left: -80px; }
.orb-2 { width: 320px; height: 320px; background: #2E7A9B; bottom: -110px; right: -70px; animation-delay: -5s; }
.orb-3 { width: 260px; height: 260px; background: #7A4FD1; top: 45%; left: 62%; animation-delay: -9s; opacity: .2; }
@keyframes orb-float { 0%, 100% { transform: translate(0,0) scale(1); } 50% { transform: translate(28px,-22px) scale(1.07); } }
@media (prefers-reduced-motion: reduce) { .orb { animation: none; } }

.login-box {
  position: relative; z-index: 1;
  width: 350px; padding: 38px 32px;
  background: rgba(22,31,27,0.72);
  backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 18px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,0.03) inset;
  text-align: center;
  animation: rise .35s ease-out;
}
:root[data-theme="light"] .login-box { background: rgba(255,255,255,0.78); border-color: rgba(0,0,0,0.06); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.login-mark {
  width: 54px; height: 54px; margin: 0 auto 16px; border-radius: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  display: flex; align-items: center; justify-content: center; color: #06120C;
  box-shadow: 0 10px 26px -6px var(--accent);
}
.login-mark svg { width: 26px; height: 26px; }
.login-box h1 { font-size: 20px; margin: 0 0 6px; }
.login-box p { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; }

.login-tabs { display: flex; background: var(--surface-raised); border-radius: 9px; padding: 3px; margin-bottom: 16px; }
.login-tab { all: unset; cursor: pointer; flex: 1; text-align: center; padding: 8px 0; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); transition: background .15s ease, color .15s ease; }
.login-tab.active { background: var(--accent); color: #06120C; }

.field input, .field textarea, .field select { text-align: left; }
.login-box .field input { text-align: center; }
.login-box .field { margin-bottom: 12px; }

/* ================= APP SHELL ================= */
#app { display: none; }
#app.visible { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 14px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent-dim)); display: flex; align-items: center; justify-content: center; color: #06120C; flex-shrink: 0; }
.brand-mark svg { width: 17px; height: 17px; }
.brand-name { font-weight: 600; font-size: 14.5px; }
.brand-sub { color: var(--text-muted); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }

.icon-btn {
  all: unset; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px; color: var(--text-muted);
  background: var(--surface-raised); border: 1px solid var(--border);
  transition: color .12s ease, border-color .12s ease, transform .08s ease;
  flex-shrink: 0;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { color: var(--text); border-color: var(--accent-dim); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.ghost { background: transparent; border: none; margin-left: auto; }
.icon-btn.ghost:hover { color: var(--danger); }

.account-switcher { position: relative; padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.account-current { all: unset; cursor: pointer; display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 10px; background: var(--surface-raised); border: 1px solid var(--border); border-radius: 9px; font-size: 12.5px; font-weight: 600; box-sizing: border-box; transition: border-color .12s ease; }
.account-current:hover { border-color: var(--accent-dim); }
.account-current .chev { width: 14px; height: 14px; margin-left: auto; color: var(--text-muted); flex-shrink: 0; }
.account-current-text { display: flex; flex-direction: column; min-width: 0; align-items: flex-start; }
.account-current-text #account-current-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.account-current-text #account-current-phone { font-size: 10.5px; color: var(--text-muted); font-weight: 400; }
.account-current-text #account-current-phone:empty { display: none; }
.account-dropdown { position: absolute; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-top: 6px; padding: 6px; box-shadow: 0 20px 50px -15px rgba(0,0,0,.5); z-index: 20; animation: pop-in .12s ease-out; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.account-item { display: flex; align-items: center; gap: 8px; padding: 8px 9px; border-radius: 7px; cursor: pointer; font-size: 12.5px; }
.account-item:hover { background: var(--surface-raised); }
.account-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.account-item .acc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-item .acc-remove { all: unset; cursor: pointer; color: var(--text-muted); padding: 2px; display: flex; }
.account-item .acc-remove:hover { color: var(--danger); }
.account-item .acc-remove svg { width: 13px; height: 13px; }
.account-add { all: unset; cursor: pointer; display: flex; align-items: center; gap: 6px; width: 100%; box-sizing: border-box; padding: 9px; margin-top: 4px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--accent); font-weight: 600; }
.account-add svg { width: 14px; height: 14px; }

nav.tabs { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav.tabs button { all: unset; cursor: pointer; padding: 10px 11px; border-radius: 8px; color: var(--text-muted); font-size: 13.2px; display: flex; align-items: center; gap: 10px; transition: background .12s ease, color .12s ease; }
nav.tabs button:hover { background: var(--surface-raised); color: var(--text); }
nav.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); }
nav.tabs button svg { width: 16px; height: 16px; flex-shrink: 0; }
nav.tabs button span:not(.nav-badge) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 20px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; margin-left: auto; }

.theme-toggle { all: unset; cursor: pointer; display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 8px; color: var(--text-muted); font-size: 12.5px; transition: background .12s ease, color .12s ease; margin-top: 8px; }
.theme-toggle:hover { background: var(--surface-raised); color: var(--text); }
.theme-toggle svg { width: 15px; height: 15px; flex-shrink: 0; }

.status-pill { padding: 10px 11px; border-radius: 8px; background: var(--surface-raised); font-size: 11.5px; display: flex; align-items: center; gap: 8px; color: var(--text-muted); margin-top: 8px; }
.status-pill span:not(.dot) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.footer-credit { text-align: center; font-size: 10.5px; color: var(--text-muted); padding: 10px 4px 2px; opacity: .8; display: flex; align-items: center; justify-content: center; gap: 4px; }
.heart {
  width: 9px; height: 9px; background: var(--accent); display: inline-block; position: relative;
  transform: rotate(-45deg); margin: 0 2px; animation: heartbeat 1.8s ease-in-out infinite;
}
.heart::before, .heart::after { content: ""; width: 9px; height: 9px; background: var(--accent); border-radius: 50%; position: absolute; }
.heart::before { top: -4.5px; left: 0; }
.heart::after { left: 4.5px; top: 0; }
@keyframes heartbeat { 0%, 100% { transform: rotate(-45deg) scale(1); } 25% { transform: rotate(-45deg) scale(1.18); } 40% { transform: rotate(-45deg) scale(1); } }
@media (prefers-reduced-motion: reduce) { .heart { animation: none; } }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex-shrink: 0; transition: background .2s ease; }
.dot.on { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dot.mid { background: var(--warn); }

main.content { flex: 1; padding: 32px 40px; max-width: 920px; }

.panel { display: none; }
.panel.active { display: block; animation: panel-in .18s ease-out; }
@keyframes panel-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .panel.active { animation: none; } }

h2.panel-title { font-size: 22px; margin: 0 0 4px; font-weight: 650; }
p.panel-desc { color: var(--text-muted); margin: 0 0 26px; font-size: 13.5px; max-width: 68ch; }
.panel-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.panel-header-actions { display: flex; gap: 8px; flex-shrink: 0; }

.section { border-left: 2px solid var(--border); padding-left: 20px; margin-bottom: 28px; }
.section.accent { border-left-color: var(--accent); }
.section h3 { font-size: 14px; margin: 0 0 14px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.field input[type=text], .field input[type=password], .field input[type=time], .field textarea, .field select {
  width: 100%; background: var(--surface-raised); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 7px; font-family: inherit; font-size: 13.5px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field input:focus, .field textarea:focus, .field select:focus, .search-input:focus, .modal-box input:focus, .modal-box textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { min-height: 80px; resize: vertical; }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }
.hint { color: var(--text-muted); font-size: 12px; margin: -4px 0 12px; line-height: 1.5; }
.hint a { color: var(--accent); }
.hint code { background: var(--surface-raised); padding: 1px 6px; border-radius: 4px; font-family: var(--mono); }
.muted-inline { color: var(--text-muted); font-size: 12.5px; margin-left: 10px; }
.mono { font-family: var(--mono); font-size: 13px; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); gap: 16px; }
.toggle-row:last-child { border-bottom: none; }
.toggle-row .label { font-size: 13.5px; }
.toggle-row .sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--border); border-radius: 20px; cursor: pointer; transition: background .15s; }
.switch .track::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }

button.btn {
  all: unset; cursor: pointer; background: var(--accent); color: #06120C; padding: 10px 18px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; transition: background .12s ease, transform .08s ease, opacity .12s ease;
  white-space: nowrap;
}
button.btn:hover { background: #38b380; }
button.btn:active { transform: scale(.98); }
button.btn.btn-block { width: 100%; text-align: center; }
button.btn.btn-xs { padding: 5px 10px; font-size: 11.5px; }
button.btn.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.btn.secondary:hover { border-color: var(--accent); color: var(--accent); }
button.btn.danger { background: var(--danger); color: #2a0f0b; }
button.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.banner { padding: 10px 14px; border-radius: 8px; font-size: 12.5px; margin-bottom: 16px; display: none; }
.banner.show { display: block; animation: banner-in .15s ease-out; }
@keyframes banner-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: translateY(0); } }
.banner.ok { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-dim); }
.banner.err { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }

/* ================= STAT CARDS ================= */
.greeting-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.greeting-row .panel-title { margin-bottom: 4px; }
.greeting-row .panel-desc { margin-bottom: 0; }

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.pill-row .pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-raised); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 20px; font-size: 12px; color: var(--text-muted);
}
.pill-row .pill.good { background: var(--accent-soft); border-color: var(--accent-dim); color: var(--accent); }
.pill-row .pill .pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 30px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; transition: transform .15s ease, border-color .15s ease; }
.stat-card:hover { transform: translateY(-2px); border-color: var(--accent-dim); }
.stat-card .num { font-size: 24px; font-weight: 700; font-family: var(--mono); }
.stat-card .lbl { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.health-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; font-size: 13px; }
.health-box .ok-line { color: var(--accent); }
.health-box .err-line { color: var(--danger); margin-top: 6px; }

/* ================= CONNECTION ================= */
.connection-layout { display: flex; gap: 32px; align-items: flex-start; flex-wrap: wrap; }
.connection-steps { flex: 1; min-width: 260px; }
.connection-steps ol { padding-left: 18px; color: var(--text-muted); font-size: 13.5px; }
.connection-steps li { margin-bottom: 8px; }

.qr-box { width: 260px; height: 260px; background: #fff; border-radius: 14px; display: flex; align-items: center; justify-content: center; overflow: hidden; box-shadow: 0 20px 50px -20px rgba(0,0,0,.6), 0 0 0 1px var(--border); flex-shrink: 0; }
.qr-box img { width: 100%; height: 100%; }
.qr-placeholder { color: #8a97a3; font-size: 12px; text-align: center; padding: 20px; }
.qr-spinner { display: flex; flex-direction: column; align-items: center; gap: 12px; color: #667; font-size: 12px; }
.spinner { width: 30px; height: 30px; border: 3px solid #e4e4e4; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= AVATARS ================= */
.avatar { width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-dim)); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; flex-shrink: 0; overflow: hidden; text-transform: uppercase; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.small { width: 34px; height: 34px; font-size: 12px; }

/* ================= ENGINE CARDS ================= */
.engine-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.engine-card { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; background: var(--surface); transition: border-color .12s ease, background .12s ease; }
.engine-card:hover { border-color: var(--accent-dim); }
.engine-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.engine-card input { margin-top: 3px; accent-color: var(--accent); }
.engine-title { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.engine-sub { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.tag { font-size: 10.5px; color: var(--text-muted); background: var(--surface-raised); border: 1px solid var(--border); padding: 2px 7px; border-radius: 20px; font-weight: 500; }

/* ================= GEMINI KEYS / USAGE ================= */
.key-row { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.key-row input[type=text], .key-row input[type=password] { background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 7px 9px; border-radius: 6px; font-size: 12.5px; }
.key-row .kr-label { flex: 1.2; min-width: 0; }
.key-row .kr-key { flex: 2; min-width: 0; }
.key-row .kr-limit { width: 70px; flex-shrink: 0; }
.key-row .kr-enabled { flex-shrink: 0; accent-color: var(--accent); width: 16px; height: 16px; }
.key-row .kr-remove { all: unset; cursor: pointer; color: var(--danger); font-size: 16px; flex-shrink: 0; padding: 0 4px; }

.usage-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; background: var(--surface-raised); border-radius: 8px; margin-bottom: 6px; font-size: 12px; gap: 10px; }
.usage-row .usage-bar-track { flex: 1; height: 5px; background: var(--border); border-radius: 10px; overflow: hidden; }
.usage-row .usage-bar-fill { height: 100%; background: var(--accent); transition: width .3s ease; }
.usage-row.exhausted .usage-bar-fill { background: var(--danger); }
.usage-row.cooldown .usage-bar-fill { background: var(--warn); }
.usage-row .usage-label { color: var(--text-muted); flex-shrink: 0; white-space: nowrap; }
.usage-row .usage-err { color: var(--danger); font-size: 10.5px; display: block; margin-top: 2px; }

/* ================= FAQ / LISTS ================= */
.list-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.list-header h3 { font-size: 14px; margin: 0; }
.search-input { background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 8px 12px; border-radius: 7px; font-size: 13px; font-family: inherit; }
#faq-search { width: 220px; }

.faq-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.faq-item { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; cursor: default; }
.faq-item .q { font-size: 13px; font-weight: 600; }
.faq-item .a { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }
.faq-item .src-tag { font-size: 10px; color: var(--text-muted); background: var(--surface-raised); padding: 1px 6px; border-radius: 20px; margin-left: 6px; }
.faq-item button { all: unset; cursor: pointer; color: var(--danger); font-size: 12px; flex-shrink: 0; }
.faq-item.clickable { cursor: pointer; }
.faq-item.clickable:hover { border-color: var(--accent-dim); }
.mod-item .reason { color: var(--warn); font-size: 11.5px; margin-top: 4px; }

.change-log { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.change-log .change-row { font-size: 11.5px; color: var(--text-muted); display: flex; gap: 8px; }
.change-log .change-row .change-date { flex-shrink: 0; font-family: var(--mono); }

/* ================= CHATS ================= */
.chats-layout { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; height: 560px; box-shadow: 0 20px 50px -30px rgba(0,0,0,.5); }
.chat-sidebar { width: 270px; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; }
.chat-sidebar-controls { display: flex; gap: 6px; padding: 10px; }
.chat-sidebar-controls .search-input { flex: 1; min-width: 0; }
.chat-sidebar-controls select { background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); border-radius: 7px; font-size: 12px; padding: 0 6px; flex-shrink: 0; }
.filter-tabs { display: flex; gap: 6px; padding: 0 10px 10px; overflow-x: auto; scrollbar-width: none; }
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tab {
  all: unset; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border);
  color: var(--text-muted); background: var(--surface-raised); transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.filter-tab:hover { border-color: var(--accent-dim); }
.filter-tab.active { background: var(--accent); color: #06120C; border-color: var(--accent); font-weight: 600; }
.filter-count {
  background: var(--warn); color: #241400; font-size: 10px; font-weight: 700;
  min-width: 15px; height: 15px; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; padding: 0 4px;
}
.filter-tab.active .filter-count { background: rgba(6,18,12,.25); color: #06120C; }

.chat-list { flex: 1; overflow-y: auto; }
.chat-list-item { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; align-items: center; gap: 10px; transition: background .1s ease; }
.chat-list-item:hover { background: var(--surface-raised); }
.chat-list-item.active { background: var(--accent-soft); }
.chat-list-item .chat-list-text { min-width: 0; flex: 1; }
.chat-list-item .name-row { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.chat-list-item .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list-item .preview { font-size: 12px; color: var(--text-muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-badge { background: var(--accent); color: #06120C; font-size: 10px; font-weight: 700; min-width: 17px; height: 17px; border-radius: 20px; display: flex; align-items: center; justify-content: center; padding: 0 4px; flex-shrink: 0; margin-left: auto; }

.tag-pill { display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.group-pill { display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 20px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.human-pill { display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 20px; background: var(--danger-soft); color: var(--danger); font-weight: 600; }

.chat-window { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); gap: 10px; }
.chat-header-left { display: flex; align-items: center; gap: 10px; cursor: pointer; border-radius: 8px; padding: 2px 6px; margin: -2px -6px; transition: background .12s ease; min-width: 0; }
.chat-header-left:hover { background: var(--surface-raised); }
.chat-header-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-header-phone { font-size: 11px; color: var(--text-muted); }
.chat-header select { background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 5px 9px; border-radius: 6px; font-size: 12px; }
.handover-btn { font-size: 11.5px; padding: 7px 12px; white-space: nowrap; flex-shrink: 0; }
.handover-btn.assigned-human { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }

.assignment-banner { background: var(--warn-soft); border-bottom: 1px solid var(--warn); color: var(--warn); font-size: 12px; padding: 8px 14px; text-align: center; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.assignment-banner button { all: unset; cursor: pointer; text-decoration: underline; font-weight: 600; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.chat-messages.wa-bg { background: #0B141A; background-image: radial-gradient(circle at 25% 15%, rgba(255,255,255,0.02) 0, transparent 45%); }
:root[data-theme="light"] .chat-messages.wa-bg { background: #E9EDEF; }

.bubble { max-width: 72%; padding: 7px 10px 8px; border-radius: 9px; font-size: 13.5px; box-shadow: 0 1px 2px rgba(0,0,0,.15); word-wrap: break-word; }
.bubble.in { background: #202C33; align-self: flex-start; border-top-left-radius: 2px; color: #E9EDEF; }
.bubble.out { background: #025C4C; align-self: flex-end; border-top-right-radius: 2px; color: #E9FBF3; }
:root[data-theme="light"] .bubble.in { background: #FFFFFF; color: #111; }
:root[data-theme="light"] .bubble.out { background: #D9FDD3; color: #111; }
.bubble .sent-by { font-size: 10.5px; font-weight: 700; opacity: .7; margin-bottom: 2px; }
.bubble .translated { display: block; margin-top: 5px; padding-top: 5px; border-top: 1px dashed rgba(255,255,255,.15); font-size: 11.5px; font-style: italic; opacity: .75; }
:root[data-theme="light"] .bubble .translated { border-top-color: rgba(0,0,0,.1); }
.bubble .bubble-time { display: block; text-align: right; font-size: 10px; opacity: .55; margin-top: 3px; }
.bubble img.bubble-media, .bubble video.bubble-media { max-width: 100%; border-radius: 6px; display: block; margin-bottom: 4px; }
.bubble img.bubble-media { cursor: pointer; }
.bubble audio.bubble-media { display: block; margin-bottom: 4px; width: 230px; max-width: 100%; }
.bubble .placeholder-line { font-style: italic; opacity: .7; font-size: 12.5px; }

.empty-state { color: var(--text-muted); font-size: 13px; padding: 30px; text-align: center; }

.media-preview { margin: 10px 12px 0; padding: 10px; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; }
.media-preview img, .media-preview video { max-width: 100%; max-height: 220px; border-radius: 6px; display: block; margin: 0 auto 8px; }
.media-preview input { width: 100%; background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 6px; font-size: 12.5px; margin-bottom: 8px; }

.recording-bar { margin: 10px 12px 0; padding: 10px 14px; border-radius: 10px; background: var(--danger-soft); border: 1px solid var(--danger); display: flex; align-items: center; gap: 10px; font-size: 13px; font-family: var(--mono); flex-wrap: wrap; }
.recording-bar button { margin-left: auto; }
.recording-bar button + button { margin-left: 8px; }
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: rec-pulse 1s ease-in-out infinite; }
@keyframes rec-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

.quick-replies { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px; }
.quick-replies:not(:empty) { padding-top: 10px; }
.qr-chip { all: unset; cursor: pointer; font-size: 11.5px; padding: 5px 10px; border-radius: 20px; border: 1px solid var(--border); color: var(--text-muted); background: var(--surface-raised); transition: border-color .12s ease, color .12s ease; }
.qr-chip:hover { border-color: var(--accent); color: var(--accent); }
.quick-reply-manage { display: flex; gap: 8px; padding: 10px 12px 0; }
.quick-reply-manage input { background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 7px 10px; border-radius: 6px; font-size: 12.5px; flex: 1; }

.assist-panel { margin: 10px 12px 0; padding: 10px; border: 1px solid var(--accent-dim); background: var(--accent-soft); border-radius: 10px; }
.assist-panel textarea { width: 100%; background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 6px; font-size: 13px; font-family: inherit; min-height: 54px; resize: vertical; }
.assist-row { display: flex; gap: 8px; margin-top: 8px; }
.assist-row input { flex: 1; background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 6px; font-size: 12.5px; }

.chat-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); align-items: center; }
.chat-input-row input { flex: 1; background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 10px 12px; border-radius: 8px; font-size: 13.5px; }

.progress-track { height: 8px; background: var(--surface-raised); border-radius: 20px; overflow: hidden; margin-top: 10px; }
.progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width .3s ease; }

.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-col .bar { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; transition: height .3s ease; }
.bar-col .bar-label { font-size: 10.5px; color: var(--text-muted); }
.bar-col .bar-count { font-size: 11px; font-family: var(--mono); color: var(--text-muted); }

.tag-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.tag-row:last-child { border-bottom: none; }

/* ================= TEAM ================= */
.checkbox-list { display: flex; flex-direction: column; gap: 8px; background: var(--surface-raised); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.checkbox-row input { accent-color: var(--accent); width: 15px; height: 15px; }

.team-list { display: flex; flex-direction: column; gap: 10px; }
.team-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.team-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.team-card-name { font-size: 13.5px; font-weight: 600; }
.team-card-username { font-size: 11.5px; color: var(--text-muted); }
.team-card-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.team-card-actions { display: flex; gap: 8px; margin-top: 10px; }
.team-card.disabled { opacity: .55; }

/* ================= MODALS ================= */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-box { width: 380px; max-width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.6); animation: rise .2s ease-out; }
.modal-box h3 { margin: 0 0 6px; font-size: 16px; }
.modal-box input[type=text], .modal-box textarea { width: 100%; box-sizing: border-box; background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 9px 11px; border-radius: 8px; font-size: 13.5px; margin-top: 10px; font-family: inherit; }
.modal-box textarea { min-height: 60px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.profile-modal-box { text-align: center; }
.profile-modal-avatar { width: 96px; height: 96px; font-size: 34px; margin: 0 auto 14px; }
.profile-modal-phone { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.profile-modal-about { font-size: 13px; color: var(--text); background: var(--surface-raised); padding: 10px 14px; border-radius: 10px; }

/* ================= RESPONSIVE ================= */
@media (max-width: 900px) {
  main.content { padding: 26px; }
}

@media (max-width: 760px) {
  #app.visible { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; overflow-x: auto; overflow-y: visible; padding: 10px; gap: 6px; align-items: center; }
  .brand { display: none; }
  .account-switcher { border: none; padding: 0; margin: 0; flex-shrink: 0; width: 170px; }
  nav.tabs { flex-direction: row; flex: none; }
  nav.tabs button span:not(.nav-badge) { display: none; }
  nav.tabs button { padding: 10px; }
  .theme-toggle { margin-top: 0; flex-shrink: 0; padding: 10px; }
  .theme-toggle span { display: none; }
  .status-pill, .footer-credit { display: none; }
  main.content { padding: 18px; max-width: 100%; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .field-row { flex-direction: column; gap: 0; }
  .connection-layout { flex-direction: column; align-items: center; text-align: center; }
  .connection-steps { text-align: left; width: 100%; }
  .qr-box { width: 220px; height: 220px; }

  .chats-layout { flex-direction: column; height: auto; }
  .chat-sidebar { width: 100%; max-height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
  .chat-messages { min-height: 280px; max-height: 50vh; }
  .bubble { max-width: 88%; }
  .chat-header { flex-wrap: wrap; }
  .panel-header-row { flex-direction: column; align-items: stretch; }
  .panel-header-actions { justify-content: flex-end; }
  .list-header { flex-direction: column; align-items: stretch; gap: 8px; }
  #faq-search { width: 100%; }
  .engine-card { flex-direction: column; }
  .assist-row { flex-direction: column; }
  .key-row { flex-wrap: wrap; }
}

@media (max-width: 420px) {
  .stat-grid { grid-template-columns: 1fr; }
  .qr-box { width: 190px; height: 190px; }
}

.assist-draft-row { display: flex; gap: 8px; align-items: flex-start; }
.assist-draft-row textarea { flex: 1; }
.assist-recording { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 13px; }
.assist-recording .btn { padding: 6px 12px; }
.assist-recording .btn:first-of-type { margin-left: auto; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #e5484d; animation: recpulse 1s infinite; }
@keyframes recpulse { 50% { opacity: .3; } }

/* Ad spaces — fixed size, only in spare room, never inside an open chat */
.ad-slot { display: none; }
.ad-slot.has-ad { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 18px auto 4px; max-width: 100%; contain: layout paint; }
.ad-slot .ad-label { font-size: 10px; letter-spacing: .02em; color: var(--text-muted); opacity: .7; }
.ad-slot iframe { border: 0; display: block; max-width: 100%; background: transparent; border-radius: 8px; }
.empty-state .ad-slot.has-ad { margin-top: 28px; }
@media (max-width: 900px) { .empty-state .ad-slot { display: none !important; } }
.ad-admin-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin: 12px 0; background: var(--surface-raised); }
.ad-admin-card h4 { margin: 0 0 2px; font-size: 14px; }
.ad-admin-card .where { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.ad-admin-card .ad-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ad-admin-card textarea { width: 100%; min-height: 84px; font-family: var(--mono); font-size: 12px; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 8px; resize: vertical; }
.ad-admin-card select { background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 6px 8px; }
@media (max-width: 700px) { .ad-admin-card .ad-grid { grid-template-columns: 1fr; } }

/* ===== Roomier chats, mobile chat view, installable chat app ===== */
.banner.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }
.sidebar .banner { margin: 6px 0 0; font-size: 11.5px; }
main.content.wide { max-width: 1280px; }
.chats-layout { height: clamp(520px, calc(100dvh - 210px), 900px); }
.chat-sidebar { width: 320px; flex-shrink: 0; }
.chat-window { min-width: 0; }
.chat-list-text .name-row .name-phone { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-left: 6px; }
.chat-back { display: none; }
.chat-list-more { display: block; width: calc(100% - 20px); margin: 8px 10px 14px; }
.chat-list-item { contain: content; }

@media (max-width: 760px) {
  main.content.wide { max-width: 100%; }
  .chats-layout { flex-direction: row; height: calc(100dvh - 190px); min-height: 420px; position: relative; }
  .chat-sidebar { width: 100%; max-height: none; border-bottom: none; }
  .chat-window { display: none; width: 100%; }
  .chats-layout.chat-open .chat-sidebar { display: none; }
  .chats-layout.chat-open .chat-window { display: flex; }
  .chat-messages { min-height: 0; max-height: none; }
  .chat-header { flex-wrap: nowrap; }
  .chat-back { display: inline-flex; flex-shrink: 0; }
  .chat-header select { max-width: 96px; }
}

/* Installed chat app: just the chats, with a slim top bar */
body.chat-app #app.visible { flex-direction: column; }
body.chat-app .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 20; flex-direction: row; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; overflow: visible; border-right: none; border-bottom: 1px solid var(--border); }
body.chat-app .sidebar nav.tabs, body.chat-app .status-pill, body.chat-app .footer-credit, body.chat-app #btn-install-app, body.chat-app #install-hint { display: none !important; }
body.chat-app .brand { display: flex; order: 3; padding: 0; margin: 0 0 0 auto; border: none; }
body.chat-app .brand > div { display: none; }
body.chat-app .account-switcher { flex: 1; min-width: 0; margin: 0; padding: 0; border: none; max-width: 320px; }
body.chat-app .theme-toggle { margin: 0; padding: 8px; width: auto; flex-shrink: 0; }
body.chat-app .theme-toggle span { display: none; }
body.chat-app main.content { padding: 12px; max-width: 100%; }
body.chat-app #panel-chats .panel-title, body.chat-app #panel-chats .panel-desc { display: none; }
body.chat-app #panel-chats .panel-header-row { margin-bottom: 8px; }
body.chat-app .chats-layout { height: calc(100dvh - 130px); border-radius: 12px; }
@media (min-width: 761px) { body.chat-app main.content { margin: 0 auto; } }
@media (display-mode: standalone) { body { overscroll-behavior-y: contain; } }

/* Chat search, ready-reply picker, set-number */
.chat-find { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.chat-find input { flex: 1; min-width: 0; background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.bubble.search-hit { outline: 2px solid var(--warn); outline-offset: 1px; }
.bubble.search-current { outline: 2px solid var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.slash-picker { margin: 0 12px 6px; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; max-height: 190px; overflow-y: auto; box-shadow: 0 12px 30px -16px rgba(0,0,0,.6); }
.slash-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.slash-item:last-child { border-bottom: none; }
.slash-item.active, .slash-item:hover { background: var(--accent-soft); }
.slash-item b { font-size: 13px; }
.slash-item span { display: block; font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-set-number { margin-top: 14px; text-align: left; }
.profile-set-number .assist-row { margin-top: 8px; }
.profile-set-number input { flex: 1; background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 6px; }
.chat-header-phone.needs-number { color: var(--warn); }

/* Open chat fills the phone / installed app, WhatsApp-style */
@media (max-width: 760px) {
  body.chat-is-open .sidebar { display: none; }
  body.chat-is-open #panel-chats .panel-header-row { display: none; }
  body.chat-is-open main.content { padding: 0; }
  body.chat-is-open .chats-layout { border-radius: 0; border-left: none; border-right: none; }
}
body.chat-app .panel-header-actions #btn-export-csv { display: none; }
body.chat-app #panel-chats .panel-header-row { margin-bottom: 8px; justify-content: flex-end; }
body.chat-app #panel-chats .panel-header-row > div:first-child { display: none; }

body.chat-app main.content { width: 100%; margin: 0; align-self: stretch; }
.chat-header-left { flex: 1; }
.profile-tag-row { display: none; margin-top: 12px; text-align: left; }
.profile-tag-row select { width: 100%; background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 6px; }
@media (max-width: 760px) {
  .chat-header { padding: 8px 10px; gap: 6px; }
  .chat-header #chat-tag-select { display: none; }
  .profile-tag-row { display: block; }
  #btn-handover { padding: 8px 10px; font-size: 12.5px; white-space: nowrap; }
}

/* ===== Composer: panels float OVER the messages so the chat never gets squeezed ===== */
.chat-window { position: relative; min-height: 0; }
.chat-messages { min-height: 0; }
.chat-composer { position: relative; flex-shrink: 0; background: var(--surface); }
.composer-pop { position: absolute !important; left: 0; right: 0; bottom: 100%; z-index: 8; margin: 0 !important; border-radius: 14px 14px 0 0 !important; max-height: min(52%, 420px); max-height: min(52dvh, 420px); overflow-y: auto; background: var(--surface) !important; border: 1px solid var(--border); border-bottom: none; box-shadow: 0 -14px 34px -18px rgba(0,0,0,.55); animation: pop-up .14s ease-out; }
@keyframes pop-up { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.quick-reply-manage.composer-pop { flex-wrap: wrap; padding: 12px; }
.quick-reply-manage .qr-manage-list { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.qr-manage-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; }
.qr-manage-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slash-item.manage { color: var(--accent); font-weight: 600; }
.recording-bar.composer-pop { border-radius: 14px 14px 0 0; }
.chat-input-row { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
#btn-new-chat-mini { display: none; flex-shrink: 0; }
.version-stamp { font-size: 10.5px; color: var(--text-muted); opacity: .7; text-align: center; margin-top: 6px; }
main.content.wide { max-width: min(1600px, 100%); }
body.chat-app #btn-new-chat-mini { display: inline-flex; }
body.chat-app #panel-chats .panel-header-row { display: none; }
@media (max-width: 760px) {
  #btn-new-chat-mini { display: inline-flex; }
  #panel-chats .panel-header-row { display: none; }
  .composer-pop { max-height: 46dvh; }
  body.chat-app main.content, main.content.wide { padding: 8px; }
  .chat-input-row { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .chat-input-row .btn { padding: 10px 12px; }
}

/* ===== WhatsApp-style details ===== */
.group-sender { font-size: 12.5px; font-weight: 700; margin-bottom: 2px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.group-sender-phone { font-weight: 400; font-size: 10.5px; color: var(--text-muted); }
.bubble { position: relative; }
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble a { color: #2b7bd6; text-decoration: underline; }
.bubble-copy { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; padding: 4px; border: none; border-radius: 6px; background: var(--surface); color: var(--text-muted); cursor: pointer; opacity: 0; transition: opacity .12s; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.bubble:hover .bubble-copy, .bubble-copy:focus-visible { opacity: 1; }
.bubble-copy.done { color: var(--accent); }
.bubble-copy svg { width: 100%; height: 100%; }
@media (hover: none) { .bubble-copy { display: none; } }
.day-sep { align-self: center; margin: 8px 0 4px; }
.day-sep span { background: var(--surface); color: var(--text-muted); font-size: 11.5px; padding: 4px 12px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.unread-divider { align-self: stretch; text-align: center; font-size: 11.5px; color: var(--accent); background: var(--accent-soft); padding: 5px 10px; border-radius: 8px; margin: 6px 0; }
.scroll-down { position: absolute; right: 16px; bottom: 76px; z-index: 6; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 6px 18px -6px rgba(0,0,0,.5); }
.scroll-down svg { width: 20px; height: 20px; }
.scroll-badge { position: absolute; top: -6px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--accent); color: #06120C; font-size: 11px; font-weight: 700; align-items: center; justify-content: center; }
.chat-window.drop-hover::after { content: 'Drop a photo or video to send'; position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--accent) 18%, transparent); border: 2px dashed var(--accent); border-radius: 12px; font-weight: 600; pointer-events: none; }
.chat-input-row textarea { flex: 1; min-width: 0; resize: none; max-height: 140px; background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); padding: 10px 12px; border-radius: 18px; font-size: 13.5px; font-family: inherit; line-height: 1.35; }
.chat-input-row textarea:focus { outline: none; border-color: var(--accent); }
.chat-input-row { align-items: flex-end; }
.emoji-picker { display: none; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 2px; padding: 8px; }
.emoji-picker[style*="block"] { display: grid !important; }
.emoji-btn { font-size: 22px; line-height: 1; padding: 6px; border: none; background: transparent; border-radius: 8px; cursor: pointer; }
.emoji-btn:hover { background: var(--accent-soft); }
.chat-list-item { align-items: center; }
.chat-list-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; min-width: 44px; }
.chat-list-time { font-size: 11px; color: var(--text-muted); }
.chat-list-time.unread { color: var(--accent); font-weight: 600; }
.pin-mark { color: var(--text-muted); } .pin-mark svg { width: 15px; height: 15px; }
.profile-members { margin-top: 14px; text-align: left; }
.members-title { font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.members-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.member-row:last-child { border-bottom: none; }
.member-row .avatar { width: 34px; height: 34px; font-size: 12px; flex-shrink: 0; color: #fff; }
.member-name { font-size: 13.5px; font-weight: 600; display: flex; gap: 6px; align-items: center; }
.member-phone { font-size: 11.5px; color: var(--text-muted); }
.admin-pill { font-size: 10px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 200; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 760px) { .scroll-down { bottom: 70px; } }
body.chat-app .version-stamp { display: none; }

/* stickers: no bubble, like WhatsApp */
.bubble.sticker-bubble { background: transparent !important; box-shadow: none !important; padding: 2px 4px; }
.bubble-sticker { width: 150px; height: 150px; object-fit: contain; display: block; }
.slash-item code, .qr-manage-row code { font-family: inherit; font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 1px 6px; border-radius: 6px; }
.quick-reply-manage input { flex: 1 1 140px; }

.newchat-box { width: min(480px, 94vw); }
.newchat-results { max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; margin: 10px 0; }
.newchat-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.newchat-row:last-child { border-bottom: none; }
.newchat-row:hover, .newchat-row.active { background: var(--accent-soft); }
.newchat-text { min-width: 0; display: flex; flex-direction: column; }
.newchat-text b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.newchat-text span { font-size: 12px; color: var(--text-muted); }
.newchat-picked { font-size: 12.5px; font-weight: 600; color: var(--accent); margin-bottom: 8px; }

#btn-exit-chat-mode { display: none; }
body.chat-app #btn-exit-chat-mode { display: inline-flex; margin: 0; padding: 8px; width: auto; flex-shrink: 0; }
body.chat-app #btn-exit-chat-mode span, body.chat-app #btn-fullscreen-chat { display: none !important; }
@media (max-width: 760px) {
  body.chat-app.chat-is-open .sidebar { display: none; }
  body.chat-app.chat-is-open main.content { padding: 0; }
  body.chat-app.chat-is-open .chats-layout { height: 100dvh !important; border-radius: 0; border: none; }
}
.older-btn { display: block; margin: 8px auto; }
