/* ======================================================================
   WhatsApp Logger — WhatsApp Web inspired light theme
   Color reference: web.whatsapp.com light mode
   ====================================================================== */

:root {
  /* surfaces */
  --bg: #efeae2;             /* WA's beige messages-pane backdrop */
  --pane: #ffffff;
  --pane-2: #f0f2f5;         /* search bar / input bg */
  --pane-3: #e9edef;         /* hover / pill bg */
  --pane-4: #f5f6f7;
  --hover: #f0f2f5;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --divider: rgba(0, 0, 0, 0.06);

  /* text */
  --text: #111b21;
  --text-soft: #3b4a54;
  --muted: #667781;
  --muted-2: #8696a0;

  /* brand — WA green */
  --accent: #00a884;
  --accent-hover: #008069;
  --accent-pressed: #06cf9c;
  --accent-soft: rgba(0, 168, 132, 0.12);
  --accent-glow: rgba(0, 168, 132, 0.25);

  /* messaging */
  --bubble-me: #d9fdd3;       /* WA light-green outgoing bubble */
  --bubble-them: #ffffff;
  --bubble-text: #111b21;     /* dark text on both bubbles in light mode */
  --bubble-meta: rgba(0, 0, 0, 0.45);  /* timestamp + non-read ticks */
  --bubble-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);

  /* status */
  --success: #00a884;
  --warn: #ffb946;
  --danger: #d93640;

  /* effects */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 1px 0 rgba(11, 20, 26, 0.04), 0 2px 5px rgba(0, 0, 0, 0.2);
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-modal: 0 25px 60px rgba(0, 0, 0, 0.6);

  /* sizing */
  --topbar-h: 56px;
  --chats-w: 380px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ── Topbar ───────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--pane);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-left { min-width: 220px; }
.topbar-center { flex: 1; display: flex; justify-content: flex-start; }
.topbar-right { margin-left: auto; }

.brand-logo { color: var(--accent); }
.brand-text {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* ── Session picker (topbar dropdown) ─────────── */
.session-picker { position: relative; }
.session-picker-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 10px;
  background: var(--pane-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  min-width: 220px;
  transition: background .15s, border-color .15s;
}
.session-picker-btn:hover { background: var(--pane-3); border-color: var(--border-strong); }
.session-picker-btn .chevron { color: var(--muted); transition: transform .15s; }
.session-picker.open .session-picker-btn .chevron { transform: rotate(180deg); }
.session-picker-btn .session-picker-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  min-width: 0;
  line-height: 1.15;
}
.session-picker-btn #active-session-name { font-weight: 600; font-size: 14px; }
.session-picker-btn #active-session-phone { font-size: 11px; }

.session-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted-2);
  flex-shrink: 0;
}
.session-dot.connected { background: var(--success); box-shadow: 0 0 0 3px rgba(0, 217, 110, 0.15); }
.session-dot.qr_pending, .session-dot.reconnecting { background: var(--warn); }
.session-dot.disconnected { background: var(--danger); }

.session-picker-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 320px;
  background: var(--pane-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  padding: 6px;
  z-index: 60;
  max-height: 70vh;
  overflow-y: auto;
}
.session-picker-dropdown ul { list-style: none; padding: 0; margin: 0; }
.session-picker-dropdown li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s;
}
.session-picker-dropdown li:hover { background: var(--hover); }
.session-picker-dropdown li.active { background: var(--accent-soft); }
.session-picker-dropdown li .picker-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.session-picker-dropdown li .picker-name { font-weight: 600; font-size: 14px; color: var(--text); }
.session-picker-dropdown li .picker-meta { font-size: 11.5px; color: var(--muted); }
.session-picker-dropdown li .picker-actions {
  display: flex;
  gap: 4px;
}
.session-picker-dropdown li button {
  padding: 4px 9px;
  font-size: 11px;
  background: var(--pane-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.session-picker-dropdown li button:hover { background: var(--hover); border-color: var(--border-strong); }
.session-picker-dropdown li button.danger { background: rgba(241, 92, 109, 0.12); color: var(--danger); border-color: rgba(241, 92, 109, 0.3); }

.session-picker-dropdown .history-line {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.session-picker-dropdown .history-line.syncing { color: var(--accent); }

.add-session-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  margin-top: 6px;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--accent);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: background .15s;
}
.add-session-btn:hover { background: var(--accent-soft); }
.add-session-btn .plus { font-size: 18px; line-height: 1; }

/* ── Topbar right widgets ────────────────────── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--pane-3); color: var(--text); }

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 500;
  transition: background .12s, border-color .12s;
}
button.ghost:hover { background: var(--pane-3); border-color: var(--border-strong); }

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: background .12s, transform .08s;
}
button.primary:hover { background: var(--accent-hover); }
button.primary:active { transform: scale(0.98); }
button.primary:disabled { opacity: 0.55; cursor: not-allowed; }

.link {
  color: var(--text-soft);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
}
.link:hover { background: var(--pane-3); text-decoration: none; color: var(--text); }

/* ── Main app layout (2 column) ──────────────── */
#app {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  background: var(--bg);
}

/* ── Chats pane ───────────────────────────────── */
#chats-pane {
  width: var(--chats-w);
  flex-shrink: 0;
  background: var(--pane);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chats-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--pane);
}
.chats-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.chats-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.new-chat-btn {
  width: 32px;
  height: 32px;
  color: var(--accent);
}
.new-chat-btn:hover { background: var(--accent-soft); color: var(--accent-pressed); }
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap .search-icon {
  position: absolute;
  left: 14px;
  color: var(--muted);
  pointer-events: none;
}
#chats-search {
  width: 100%;
  padding: 9px 14px 9px 38px;
  background: var(--pane-2);
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text);
  outline: none;
  transition: background .12s, border-color .12s;
}
#chats-search:focus {
  background: var(--pane-3);
  border-color: var(--border-strong);
}
#chats-search::placeholder { color: var(--muted-2); }

#chats-list {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}
#chats-list::-webkit-scrollbar { width: 6px; }
#chats-list::-webkit-scrollbar-thumb { background: var(--pane-3); border-radius: 3px; }

#chats-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--divider);
  transition: background .12s;
  position: relative;
}
#chats-list li:hover { background: var(--pane-4); }
#chats-list li.active { background: var(--pane-3); }
#chats-list li.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}

.chat-info { flex: 1; min-width: 0; }
.chat-name {
  font-weight: 600;
  font-size: 14.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-last {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-aside {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
  font-size: 11.5px;
}
.chat-time { color: var(--muted); white-space: nowrap; }

/* Unread state — WhatsApp-style green badge + bold chat name */
.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
#chats-list li.has-unread .chat-name { font-weight: 700; color: var(--text); }
#chats-list li.has-unread .chat-time { color: var(--accent); font-weight: 600; }
#chats-list li.has-unread.active .chat-name { font-weight: 600; }

/* ── Avatar (with profile picture or initials) ─ */
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 49px;
  height: 49px;
  border-radius: 50%;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  position: relative;
}
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.lg { width: 40px; height: 40px; font-size: 14px; }
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Messages pane (right) ────────────────────── */
#messages-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  /* WA-style beige with very subtle diagonal pattern */
  background:
    linear-gradient(rgba(239, 234, 226, 0.9), rgba(239, 234, 226, 0.9)),
    repeating-linear-gradient(45deg, transparent 0 18px, rgba(0,0,0,0.018) 18px 19px);
  min-width: 0;
}

#chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--pane);
  border-bottom: 1px solid var(--border);
  min-height: 62px;
}
#chat-header.empty { background: transparent; border-bottom: none; }
#chat-header.empty .chat-header-text h2 { color: var(--muted); }
#chat-header-avatar { display: flex; align-items: center; }
.chat-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.chat-header-text h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-text .muted {
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 60px;
  /* Instant jump (no animation) — WhatsApp behavior: opening a chat lands
     at the bottom immediately. User scrolls up themselves to read older. */
  scroll-behavior: auto;
}
#messages-list::-webkit-scrollbar { width: 8px; }
#messages-list::-webkit-scrollbar-thumb { background: var(--pane-3); border-radius: 4px; }

.empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 14px;
  text-align: center;
}
.empty .icon {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--pane-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
}

/* ── Bubbles ──────────────────────────────────── */
.bubble {
  /* Shrink to content; the max-width keeps long messages from spanning
     the whole pane. Without fit-content, a "block" default would stretch
     short bubbles to 65% even when the text is one word. */
  width: fit-content;
  max-width: 65%;
  margin: 2px 0;
  padding: 6px 9px 8px;
  border-radius: var(--radius);
  color: var(--bubble-text, var(--text));
  font-size: 14.5px;
  line-height: 1.4;
  position: relative;
  box-shadow: var(--bubble-shadow);
  word-wrap: break-word;
  word-break: break-word;
  /* Minimum bubble width so the time stamp doesn't overlap a single emoji */
  min-width: 60px;
}
.bubble.me {
  background: var(--bubble-me);
  margin-left: auto;
  border-top-right-radius: 4px;
}
.bubble.them {
  background: var(--bubble-them);
  margin-right: auto;
  border-top-left-radius: 4px;
}
.bubble .sender {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-hover);
  margin-bottom: 2px;
}
.bubble .time {
  font-size: 11px;
  color: var(--bubble-meta);
  text-align: right;
  margin-top: 2px;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}
.bubble .ticks {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.bubble .ticks svg { display: block; }
.bubble .ticks.pending,
.bubble .ticks.sent,
.bubble .ticks.delivered { color: var(--bubble-meta); }
.bubble .ticks.read    { color: #53bdeb; }
.bubble .doc { background: rgba(0, 0, 0, 0.06); }
.bubble .doc a { color: var(--text); }
.bubble img, .bubble video {
  max-width: 100%;
  max-height: 350px;
  border-radius: 6px;
  display: block;
  margin-bottom: 4px;
  cursor: zoom-in;
}
.bubble audio {
  width: 100%;
  margin: 4px 0;
}
.bubble .doc {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 6px;
  margin-bottom: 4px;
}
.bubble .doc a {
  color: var(--text);
  font-weight: 500;
}
.bubble .muted-info {
  color: var(--muted);
  font-size: 12px;
}

.load-more {
  text-align: center;
  padding: 10px;
  color: var(--muted);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.date-separator {
  text-align: center;
  margin: 16px 0;
}
.date-separator span {
  display: inline-block;
  padding: 5px 12px;
  background: var(--pane-2);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

/* ── Composer ─────────────────────────────────── */
#composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--pane);
  border-top: 1px solid var(--border);
}
#composer-file { display: none; }
#composer-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--pane-2);
  border-radius: var(--radius);
  padding: 6px 12px;
}
#composer-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 6px 0;
  color: var(--text);
  font-size: 14.5px;
}
#composer-input::placeholder { color: var(--muted); }

#composer-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  background: var(--accent-soft);
  border-radius: 14px;
  font-size: 12.5px;
  color: var(--accent-pressed);
  max-width: 220px;
}
#composer-attach-chip #composer-attach-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#composer-attach-chip button {
  background: transparent;
  border: none;
  color: var(--accent-pressed);
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: var(--pane-3); cursor: not-allowed; }

/* ── Lightbox (image / video full-screen viewer) ── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 16px) 16px env(safe-area-inset-bottom, 16px);
  animation: fade-in .12s ease;
}
.lightbox-close, .lightbox-download {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0) + 16px);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: background .12s, transform .08s;
}
.lightbox-close { right: 16px; z-index: 2; }
.lightbox-download { right: 70px; z-index: 2; }
.lightbox-close:hover, .lightbox-download:hover { background: rgba(255, 255, 255, 0.22); }
.lightbox-close:active, .lightbox-download:active { transform: scale(0.92); }

#lightbox-content {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#lightbox-content img,
#lightbox-content video {
  max-width: 100%;
  max-height: calc(100dvh - 32px);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  object-fit: contain;
}
#lightbox-content video { width: auto; }

/* ── Profile detail modal ───────────────────── */
.profile-card {
  max-width: 360px;
  position: relative;
  text-align: center;
  padding-top: 32px;
}
.profile-close {
  position: absolute;
  top: 10px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--pane-3);
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.profile-close:hover { color: var(--text); background: var(--hover); }
#profile-pic {
  width: 160px;
  height: 160px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--pane-3);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  font-weight: 600;
  color: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
#profile-pic img { width: 100%; height: 100%; object-fit: cover; }
#profile-pic.placeholder { cursor: default; }
#profile-name {
  font-size: 20px;
  margin: 0 0 4px;
  font-weight: 600;
  color: var(--text);
}
#profile-jid {
  margin: 0 0 18px;
  font-size: 13px;
  word-break: break-all;
}
.profile-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-top: 4px;
}
.profile-stats .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.profile-stats .stat-num {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.profile-stats .stat-label {
  font-size: 11.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Make bubble media + chat header avatar visibly clickable */
.bubble img, .bubble video { cursor: zoom-in; }
#chat-header-avatar { cursor: pointer; }

/* ── VNC pair modal (wwebjs fresh pair) ────── */
#vnc-pair-modal .modal-card.vnc-pair-card {
  max-width: 1200px;
  width: 92vw;
  padding: 18px;
  display: flex;
  flex-direction: column;
}
.vnc-pair-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.vnc-pair-header h3 { margin: 0; font-size: 16px; }
#vnc-pair-status { font-size: 12.5px; margin: 0 0 12px; }
#vnc-pair-frame-wrap {
  flex: 1;
  min-height: 60vh;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
#vnc-pair-frame {
  width: 100%;
  height: 100%;
  border: 0;
  min-height: 60vh;
  background: #000;
}
@media (max-width: 768px) {
  #vnc-pair-modal .modal-card.vnc-pair-card {
    width: 100%;
    height: 100%;
    max-width: 100%;
    border-radius: 0;
    padding: 12px;
  }
  #vnc-pair-frame-wrap, #vnc-pair-frame { min-height: 70vh; }
}

/* ── Backend picker (Yeni Numara modal) ────── */
.backend-picker { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.backend-option {
  display: flex;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  text-align: left;
}
.backend-option:hover { background: var(--pane-3); border-color: var(--border-strong); }
.backend-option input[type="radio"] { margin-top: 2px; accent-color: var(--accent); }
.backend-option input[type="radio"]:checked + .backend-option-body { color: var(--text); }
.backend-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.backend-option-body { flex: 1; }
.backend-name { font-weight: 600; font-size: 14px; margin-bottom: 3px; }
.backend-desc { font-size: 12px; line-height: 1.4; }
.badge-mini {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--pane-3);
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  margin-left: 4px;
  vertical-align: middle;
}
.badge-mini.accent { background: var(--accent); color: #fff; }

/* Session picker item — backend badge next to picker-meta */
.session-backend-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-left: 5px;
  vertical-align: middle;
}
.session-backend-badge.baileys { background: rgba(0, 168, 132, 0.12); color: var(--accent-hover); }
.session-backend-badge.wwebjs { background: rgba(139, 92, 246, 0.15); color: #8b5cf6; }

/* ── Modal ────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in .15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--pane);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 28px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-modal);
  animation: pop-in .18s cubic-bezier(.2,.9,.4,1.2);
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-card h3 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.modal-card p { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }
.modal-card input, .modal-card select {
  width: 100%;
  padding: 10px 14px;
  background: var(--pane-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  margin-bottom: 10px;
  transition: border-color .12s, background .12s;
}
.modal-card input:focus, .modal-card select:focus {
  border-color: var(--accent);
  background: var(--pane-3);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.modal-actions button {
  padding: 8px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--pane-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
}
.modal-actions button:hover { background: var(--pane-3); }
.modal-actions button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.modal-actions button.primary:hover { background: var(--accent-hover); }

.error-msg {
  background: rgba(241, 92, 109, 0.12);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 10px;
  border: 1px solid rgba(241, 92, 109, 0.25);
  text-align: left;
}

/* ── QR modal ─────────────────────────────────── */
#qr-image-wrap {
  width: 240px;
  height: 240px;
  margin: 16px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 12px;
  padding: 12px;
}
#qr-image-wrap img { width: 100%; height: 100%; display: block; }
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--pane-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
.spinner-mini {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#qr-close {
  margin-top: 6px;
  padding: 8px 22px;
  background: var(--pane-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
#qr-close:hover { background: var(--pane-3); }

/* ── Login page ──────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(0, 168, 132, 0.15), transparent 60%),
    radial-gradient(circle at 85% 85%, rgba(0, 168, 132, 0.08), transparent 50%),
    var(--bg);
}
.login-card {
  background: var(--pane);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 38px 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  animation: pop-in .25s cubic-bezier(.2,.9,.4,1.2);
}
.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  margin: 0 auto 8px;
  box-shadow: 0 0 0 6px rgba(0, 168, 132, 0.06);
}
.login-card h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.01em;
  color: var(--text);
}
.login-card p.muted {
  margin: 0 0 12px;
  text-align: center;
  font-size: 13.5px;
}
.login-card input {
  padding: 11px 14px;
  background: var(--pane-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  font-size: 14.5px;
  transition: border-color .12s, background .12s;
}
.login-card input:focus {
  border-color: var(--accent);
  background: var(--pane-3);
}
.login-card input::placeholder { color: var(--muted-2); }
.login-card button.primary {
  margin-top: 6px;
  padding: 11px 16px;
  font-size: 14.5px;
}

/* ── Users / Companies pages ─────────────────── */
.users-page { background: var(--bg); min-height: 100vh; }
.users-main {
  max-width: 1000px;
  margin: 32px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.card {
  background: var(--pane);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.card-header {
  padding: 16px 20px;
  background: var(--pane);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.data-table, #users-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td,
#users-table th, #users-table td {
  padding: 14px 20px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}
.data-table th, #users-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(0, 0, 0, 0.15);
}
.data-table tr:last-child td, #users-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover, #users-table tr:hover { background: var(--pane-4); }

.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-cell .name { font-weight: 600; line-height: 1.25; }

.data-table td.num { font-variant-numeric: tabular-nums; font-weight: 600; }
.count-pill {
  display: inline-block;
  min-width: 28px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--pane-3);
  color: var(--text);
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 600;
}
.count-pill.zero { color: var(--muted-2); background: transparent; }
.data-table td.actions, .data-table th.actions { text-align: right; }
.data-table td.actions .row-actions { justify-content: flex-end; }

.badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge.super_admin { background: rgba(0, 168, 132, 0.15); color: var(--accent); }
.badge.admin { background: rgba(0, 168, 132, 0.15); color: var(--accent); }
.badge.agent { background: var(--pane-3); color: var(--muted); }

.row-actions { display: flex; gap: 6px; }
.row-actions button {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--pane-2);
  color: var(--text);
  cursor: pointer;
  transition: background .12s;
}
.row-actions button:hover:not(:disabled) { background: var(--pane-3); }
.row-actions button:disabled { opacity: 0.4; cursor: not-allowed; }
.row-actions button.danger { color: var(--danger); border-color: rgba(241, 92, 109, 0.3); }
.row-actions button.danger:hover:not(:disabled) { background: rgba(241, 92, 109, 0.12); }

.form-grid {
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
}
.form-grid input {
  padding: 9px 14px;
  background: var(--pane-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
}
.form-grid input:focus { border-color: var(--accent); }
.form-grid button {
  padding: 9px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.form-grid button:hover { background: var(--accent-hover); }
#my-pw-msg { padding: 0 20px 18px; font-size: 13px; }

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* ── Sync badge ──────────────────────────────── */
.session-history.done {
  color: var(--success);
  font-weight: 500;
}
.session-history.syncing {
  color: var(--accent);
  font-weight: 500;
}

/* ── Mobile ──────────────────────────────────── */
.mobile-only { display: none !important; }
.desktop-only { display: inline; }

@media (max-width: 768px) {
  :root {
    --chats-w: 100%;
    --topbar-h: 54px;
  }
  .mobile-only { display: inline-flex !important; }
  .desktop-only { display: none !important; }

  /* Account for iPhone notch / safe area */
  html, body { height: 100%; height: 100dvh; }
  body { overflow: hidden; }

  /* ── Topbar: 1 row, 3 zones, no overflow ── */
  .topbar {
    padding: 0 8px;
    gap: 6px;
    padding-top: env(safe-area-inset-top, 0);
    height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  }
  .topbar-left { min-width: 0; gap: 4px; flex-shrink: 0; }
  .topbar-center { flex: 1; min-width: 0; }
  .topbar-right { gap: 2px; flex-shrink: 0; }
  .brand-text { display: none; }
  .brand-logo { width: 24px; height: 24px; }

  /* Session picker becomes full-width inside its zone */
  .session-picker-btn {
    min-width: 0;
    width: 100%;
    padding: 6px 8px 6px 8px;
    font-size: 13px;
  }
  .session-picker-btn .session-picker-text { line-height: 1.1; }
  .session-picker-btn #active-session-name { font-size: 13.5px; }
  .session-picker-btn #active-session-phone { font-size: 10.5px; }

  /* Dropdown becomes a bottom-sheet on mobile */
  .session-picker-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 75dvh;
    border-radius: 16px 16px 0 0;
    padding: 12px 12px env(safe-area-inset-bottom, 12px);
    box-shadow: 0 -10px 30px rgba(0,0,0,0.5);
    animation: slide-up .2s ease;
  }
  @keyframes slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .session-picker-dropdown li { padding: 12px; }

  /* Hide non-essentials on mobile */
  .topbar-right .link { display: none; }
  #me-label { display: none !important; }
  #logout-btn { padding: 6px 10px; font-size: 12.5px; }

  /* ── App layout: chats default, messages slide-in ── */
  #app {
    position: relative;
    height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top, 0px));
  }
  #chats-pane { width: 100%; border-right: none; }

  /* Chats list ── bigger touch targets */
  .chats-header { padding: 10px 12px; }
  #chats-search { padding: 10px 14px 10px 38px; }
  #chats-list li {
    padding: 11px 14px;
    gap: 12px;
    min-height: 64px;
  }
  .avatar { width: 46px; height: 46px; }
  .chat-name { font-size: 14.5px; }
  .chat-last { font-size: 13px; }

  /* Messages pane — slides in from right. Fully opaque so the chat list
     beneath doesn't show through. */
  #messages-pane {
    position: absolute;
    inset: 0;
    transform: translateX(100%);
    transition: transform .25s ease;
    z-index: 5;
    background:
      linear-gradient(var(--bg), var(--bg)),
      repeating-linear-gradient(45deg, transparent 0 18px, rgba(0,0,0,0.018) 18px 19px);
  }
  body[data-view="messages"] #messages-pane { transform: translateX(0); }

  #chat-header {
    padding: 8px 10px;
    gap: 8px;
    min-height: 56px;
  }
  #chat-back { width: 32px; height: 32px; }
  .chat-header-text h2 { font-size: 15px; }
  .chat-header-text .muted { font-size: 11.5px; }

  #messages-list {
    padding: 12px 12px env(safe-area-inset-bottom, 12px);
  }
  .bubble {
    max-width: 82%;
    font-size: 14.5px;
  }
  .bubble img, .bubble video { max-height: 280px; }

  /* Composer — keyboard-friendly */
  #composer {
    padding: 8px 10px env(safe-area-inset-bottom, 8px);
    gap: 6px;
  }
  #composer-input-wrap { padding: 4px 12px; }
  #composer-input { padding: 8px 0; font-size: 16px; }  /* 16px = no iOS zoom */
  .send-btn { width: 40px; height: 40px; }
  #composer-attach { width: 38px; height: 38px; }

  /* ── Modals ── full-width bottom sheet style ── */
  .modal { padding: 0; align-items: flex-end; }
  .modal-card {
    width: 100%;
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 22px 20px env(safe-area-inset-bottom, 22px);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
    animation: slide-up .22s ease;
  }
  .modal-card input, .modal-card select { font-size: 16px; }
  #qr-image-wrap { width: 220px; height: 220px; }
  .modal-actions button { flex: 1; padding: 12px; }

  /* ── Users / Companies pages ── stack on mobile ── */
  .users-main {
    margin: 12px auto;
    padding: 0 10px;
    gap: 14px;
  }
  .card-header { padding: 13px 14px; }
  .data-table, #users-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .data-table th, .data-table td,
  #users-table th, #users-table td {
    padding: 12px 14px;
  }
  .form-grid {
    grid-template-columns: 1fr;
    padding: 14px;
  }
  .row-actions { gap: 4px; }
  .row-actions button { padding: 6px 10px; }

  /* Login page polish */
  .auth-page { padding: 16px; }
  .login-card { padding: 30px 24px 26px; }

  /* Sound toggle hidden on mobile to save space */
  #sound-toggle { display: none !important; }

  /* Hamburger removed — session picker covers number switching, back button
     covers nav. Re-enable later if we add a left drawer for admin shortcuts. */
  #mobile-menu { display: none !important; }

  /* Lightbox — keep buttons reachable with thumb; download moves to bottom
     so it doesn't fight with the close button on narrow screens. */
  .lightbox-close { top: calc(env(safe-area-inset-top, 0) + 12px); right: 12px; }
  .lightbox-download {
    top: auto;
    bottom: calc(env(safe-area-inset-bottom, 0) + 16px);
    right: 16px;
    background: var(--accent);
  }
  .lightbox-download:hover { background: var(--accent-hover); }

  /* Profile modal as bottom sheet with smaller hero pic on narrow screens */
  #profile-pic { width: 128px; height: 128px; font-size: 44px; margin-bottom: 14px; }
  #profile-name { font-size: 18px; }
}

/* ── Extra small (small phones) ── */
@media (max-width: 380px) {
  .topbar { padding: 0 6px; }
  .brand-logo { display: none; }
  .session-picker-btn #active-session-phone { display: none; }
  #logout-btn { padding: 5px 8px; font-size: 12px; }
}
