:root {
  --bg: #090d16;
  --bg-card: #111726;
  --bg-card-hover: #161f33;
  --bg-input: #0d121f;
  --border: #1f2a40;
  --border-focus: #3b82f6;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.15);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* ─── Login Screen ────────────────────────────────────────────────────────── */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.brand-crest {
  font-size: 48px;
  margin-bottom: 12px;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.muted {
  color: var(--text-muted);
  font-size: 14px;
}

.input-group {
  text-align: left;
  margin-top: 18px;
}

.input-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.input-group input,
.sidebar-header input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.input-group input:focus,
.sidebar-header input:focus {
  border-color: var(--border-focus);
}

.primary-btn {
  width: 100%;
  padding: 12px 16px;
  margin-top: 24px;
  background: var(--primary);
  border: none;
  border-radius: 8px;
  color: white;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
}

/* ─── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand .icon {
  font-size: 24px;
}

.brand .title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.brand .tag {
  font-size: 11px;
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 600;
}

.nav-tabs {
  display: flex;
  gap: 8px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text);
  background: var(--bg-input);
}

.tab-btn.active {
  color: white;
  background: var(--primary);
}

.user-strip {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.ghost-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* ─── Page Sections ──────────────────────────────────────────────────────── */
.app-container {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.page-section {
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.section-header {
  margin-bottom: 24px;
}

.section-header h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}

/* ─── Devices Grid (Dual QR) ─────────────────────────────────────────────── */
.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 24px;
}

.device-card {
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.badge-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.acc-num {
  background: var(--primary);
  color: white;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
}

.card-head h3 {
  font-size: 17px;
  font-weight: 600;
}

.status-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 99px;
}

.status-connected {
  background: var(--green-glow);
  color: var(--green);
  border: 1px solid var(--green);
}

.status-waiting {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid #f59e0b;
}

.status-disconnected {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.account-details {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.detail-row .lbl {
  color: var(--text-muted);
}

.val-mono {
  font-family: var(--font-mono);
  color: #38bdf8;
  font-size: 14px;
}

.val-green {
  color: var(--green);
  font-weight: 500;
}

.qr-container {
  text-align: center;
  padding: 12px;
}

.qr-frame {
  width: 260px;
  height: 260px;
  margin: 0 auto 14px;
  background: white;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.qr-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.qr-placeholder {
  color: #334155;
  font-size: 14px;
  font-weight: 500;
}

.qr-instruct {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.card-actions {
  margin-top: auto;
  padding-top: 14px;
}

.danger-btn {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  width: 100%;
  transition: all 0.2s;
}

.danger-btn:hover {
  background: var(--danger);
  color: white;
}

/* ═════════════════════════════════════════════════════════════════════════════
   CONVERSATIONS PANEL: 100% NATIVE LADY JANE CLEAN WHITE WHATSAPP THEME
   ═════════════════════════════════════════════════════════════════════════════ */
#tab-chats {
  padding-top: 16px;
}

#tab-chats .account-switcher-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  background: #ffffff !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 12px;
  padding: 12px 18px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04) !important;
}

#tab-chats .switcher-label {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a !important;
}

#tab-chats .switcher-buttons {
  display: flex;
  gap: 10px;
}

#tab-chats .switch-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  background: #f8fafc !important;
  border: 1px solid #cbd5e1 !important;
  color: #334155 !important;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
}

#tab-chats .switch-btn .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}

#tab-chats .switch-btn .phone-tag {
  font-family: var(--font-mono);
  font-size: 12px;
  opacity: 0.85;
}

#tab-chats .switch-btn:hover {
  background: #f1f5f9 !important;
  color: #0f172a !important;
  border-color: #94a3b8 !important;
}

#tab-chats .switch-btn.active {
  background: #0f172a !important;
  border-color: #0f172a !important;
  color: #ffffff !important;
}

#tab-chats .switch-btn.active .dot {
  background: var(--green);
}

#tab-chats .chat-split-container {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  height: calc(100vh - 190px);
  min-height: 520px;
}

/* Sidebar in Clean White */
#tab-chats .chat-sidebar {
  background: #ffffff !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05) !important;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

#tab-chats .sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #e2e8f0 !important;
  background: #ffffff !important;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#tab-chats .sidebar-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a !important;
}

#tab-chats .sidebar-header input {
  background: #f8fafc !important;
  border: 1px solid #cbd5e1 !important;
  color: #0f172a !important;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
}

#tab-chats .sidebar-header input:focus {
  border-color: #0284c7 !important;
  background: #ffffff !important;
}

#tab-chats .conversations-scroll {
  overflow-y: auto;
  flex: 1;
  background: #ffffff !important;
}

#tab-chats .chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9 !important;
  background: #ffffff !important;
  cursor: pointer;
  transition: background 0.15s ease;
}

#tab-chats .chat-item:hover {
  background: #f8fafc !important;
}

#tab-chats .chat-item.active {
  background: #f1f5f9 !important;
  border-left: 4px solid #0f172a !important;
}

#tab-chats .chat-item-name {
  font-size: 14px;
  font-weight: 600;
  color: #0f172a !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#tab-chats .chat-item-time {
  font-size: 11px;
  color: #94a3b8 !important;
}

#tab-chats .chat-item-snippet {
  font-size: 13px;
  color: #64748b !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#tab-chats .unread-badge {
  background: #10b981;
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 99px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

/* Chat Main View in Clean White */
#tab-chats .chat-main {
  background: #ffffff !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05) !important;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

#tab-chats .chat-main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid #e2e8f0 !important;
  background: #ffffff !important;
}

#tab-chats .contact-meta h3 {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a !important;
}

#tab-chats .contact-sub {
  font-size: 12px;
  color: #64748b !important;
}

#tab-chats .pill-indicator {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 99px;
  background: #f1f5f9 !important;
  color: #0f172a !important;
  border: 1px solid #cbd5e1 !important;
  font-weight: 600;
}

#tab-chats .messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #efeae2 !important; /* Authentic WhatsApp light wallpaper tone */
  border-top: 1px solid #f1f5f9;
}

#tab-chats .empty-state, 
#tab-chats .empty-chat-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #64748b !important;
  font-size: 14px;
  text-align: center;
  padding: 30px;
}

/* ─── Authentic WhatsApp Message Bubbles (Phone WhatsApp Style) ─────────── */
#tab-chats .msg-bubble {
  max-width: 68%;
  padding: 6px 9px 8px;
  font-size: 14px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  word-break: break-word;
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.13) !important;
}

/* Incoming Bubble (Solid Crisp White) */
#tab-chats .msg-in {
  align-self: flex-start !important;
  background: #ffffff !important;
  color: #111b21 !important;
  border-radius: 0 8px 8px 8px !important;
}

/* Outgoing Bubble (WhatsApp Light Green) */
#tab-chats .msg-out {
  align-self: flex-end !important;
  background: #d9fdd3 !important;
  color: #111b21 !important;
  border-radius: 8px 0 8px 8px !important;
}

#tab-chats .msg-sender {
  font-size: 12px;
  font-weight: 700;
  color: #128c7e !important;
  margin-bottom: 2px;
}

#tab-chats .msg-text {
  color: #111b21 !important;
  font-size: 14.2px;
  line-height: 1.45;
  padding: 2px 2px;
}

#tab-chats .msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 11px;
  color: #667781 !important;
  margin-top: 2px;
  margin-left: 12px;
  user-select: none;
}

.wa-ticks {
  color: #53bdeb;
  font-size: 12px;
  font-weight: bold;
}

/* Quoted Reply Box inside bubble */
.msg-quoted {
  background: rgba(0, 0, 0, 0.05);
  border-left: 4px solid #00a884;
  border-radius: 6px;
  padding: 5px 8px;
  margin-bottom: 4px;
  font-size: 12px;
}

.msg-out .msg-quoted {
  background: rgba(0, 0, 0, 0.04) !important;
  border-left-color: #008069 !important;
}

.msg-quoted-sender {
  font-weight: 700;
  color: #008069;
  margin-bottom: 2px;
}

.msg-quoted-text {
  color: #54656f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Media Rendered Seamlessly Inside WhatsApp Chat ───────────────────────── */
.wa-image-box {
  margin: 2px 0 4px;
  border-radius: 6px;
  overflow: hidden;
  max-width: 320px;
}

.wa-image-box img {
  width: 100%;
  max-height: 340px;
  object-fit: cover;
  display: block;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.wa-image-box img:hover {
  opacity: 0.95;
}

/* WhatsApp Voice Message Player (Native In-Chat Experience) */
.wa-voice-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
  min-width: 260px;
}

.wa-voice-mic {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #00a884;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.wa-voice-player {
  flex: 1;
}

.wa-voice-player audio {
  width: 100%;
  height: 34px;
}

/* WhatsApp In-Chat Video Player */
.wa-video-box {
  margin: 2px 0 4px;
  border-radius: 6px;
  overflow: hidden;
  max-width: 320px;
}

.wa-video-box video {
  width: 100%;
  max-height: 320px;
  display: block;
  border-radius: 6px;
}

/* WhatsApp In-Chat Document Box */
.wa-doc-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 6px;
  color: #111b21;
  text-decoration: none;
  font-size: 13px;
  margin: 2px 0 4px;
  transition: background 0.15s;
}

.wa-doc-box:hover {
  background: rgba(0, 0, 0, 0.08);
}

.wa-doc-icon {
  font-size: 24px;
}

.wa-doc-info {
  flex: 1;
  min-width: 0;
}

.wa-doc-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-doc-sub {
  font-size: 11px;
  color: #667781;
}

.wa-doc-arrow {
  font-size: 16px;
  opacity: 0.7;
}

/* ─── Lightbox Overlay ────────────────────────────────────────────────────── */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.lightbox-content img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}

.lightbox-close-btn {
  position: absolute;
  top: 20px;
  right: 25px;
  background: transparent;
  border: none;
  color: white;
  font-size: 36px;
  cursor: pointer;
}

/* WhatsApp Chat Reply Bar */
.chat-reply-form {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #f0f2f5 !important;
  border-top: 1px solid #e2e8f0;
}

#chat-reply-input {
  flex: 1;
  background: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: 24px;
  padding: 10px 18px;
  font-size: 14.5px;
  color: #111b21 !important;
  outline: none;
  transition: border-color 0.15s;
}

#chat-reply-input:focus {
  border-color: #00a884 !important;
}

.chat-reply-submit {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #00a884 !important;
  color: white !important;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.chat-reply-submit:hover {
  background: #008f6f !important;
  transform: scale(1.05);
}

.chat-reply-submit:active {
  transform: scale(0.95);
}
