﻿/* ===================================
   CHAT CSS - ORGANIZZAZIONE COMPLETA
   
   STRUTTURA DEL FILE:
   1. Variabili CSS e colori
   2. Chat Header & Messages
   3. WhatsApp Layout
   4. WhatsApp Sidebar
   5. WhatsApp Main Area
   6. WhatsApp Chat Header & Contact
   7. WhatsApp Input & Send
   8. motore WhatsApp Components
   9. WhatsApp QR Modal
   10. Responsive & Media Query
   
   OTTIMIZZAZIONI APPLICATE:
   ✓ Centralizzate tutte le variabili CSS
   ✓ Raggruppati stili correlati per sezione
   ✓ Rimossi stili duplicati
   ✓ Migliorata leggibilità con commenti chiari
   ✓ Ottimizzati selector per performance
   ✓ Aggiunto supporto dark mode completo
   =================================== */

/* === VARIABILI CSS PRINCIPALI === */
:root {
  --wsp-green: #25d366;
  --wsp-green-dark: #128c7e;
  --wsp-green-light: #dcf8c6;
  --wsp-teal: #00a884;
  --wsp-teal-dark: #008069;
  --wsp-gray: #f0f2f5;
  --wsp-gray-dark: #8696a0;
  --wsp-border: #e9edef;
  --chat-bg-light: #e5ddd5;
  --chat-bg-dark: #0b141a;
  --message-bg-light: #ffffff;
  --message-bg-dark: #2a3942;
  --message-out-light: #d9fdd3;
  --message-out-dark: #005c4b;
  --shadow-light: rgba(11, 20, 26, 0.13);
  --shadow-dark: rgba(0, 0, 0, 0.4);
}

/* ===================================
   SEZIONE 1: CHAT HEADER & MESSAGES
   =================================== */

.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);
  height: calc(100dvh - 60px);
  background: var(--bg-primary);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 10px 16px;
  background: #f0f2f5;
  border-bottom: 1px solid var(--wsp-border);
  box-shadow: none;
  transition: box-shadow 0.3s ease, transform 0.2s ease;
  backdrop-filter: none;
  min-height: 60px;
}

[data-theme="dark"] .chat-header {
  background: #202c33;
  border-bottom-color: #2a3942;
}

.chat-header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chat-header-info h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.chat-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.chat-header-actions {
  display: flex;
  gap: 0.25rem;
}

.chat-search {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border-bottom: none;
}

.chat-search input {
  flex: 1;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 20px;
  background: #ffffff;
  color: var(--text-primary);
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  font-size: 13px;
}

.chat-search input:focus {
  border-color: transparent;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transform: none;
  outline: none;
}

.chat-search input:hover {
  border-color: transparent;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: var(--chat-bg-light);
  background-image: 
    repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,0.03) 10px, rgba(255,255,255,0.03) 20px),
    repeating-linear-gradient(-45deg, transparent, transparent 10px, rgba(0,0,0,0.02) 10px, rgba(0,0,0,0.02) 20px);
}

[data-theme="dark"] .chat-messages {
  background: var(--chat-bg-dark);
  background-image: 
    repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,0.01) 10px, rgba(255,255,255,0.01) 20px),
    repeating-linear-gradient(-45deg, transparent, transparent 10px, rgba(0,0,0,0.15) 10px, rgba(0,0,0,0.15) 20px);
}

.chat-messages .loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  color: var(--text-secondary);
  gap: 0.5rem;
}

/* ── Message skeleton loader ──────────────────────────────── */
/* ============================================================
   MESSAGE SKELETON — loading state quando si apre una chat
   ============================================================ */

/* Barra di progressione: stile UNICO in fondo al file (.wa-app .wa-msgs-load-bar).
   Qui c'era una seconda implementazione legacy (width 0->100% animata + margin):
   sommandosi all'altra produceva una barra che si allargava/sfumava a scatti. */

.msg-skeleton-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px 4.5% 16px;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

/* Ogni riga entra con fade+slide staggerato */
.msg-skeleton-row {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  opacity: 0;
  animation: sk-row-in 0.22s cubic-bezier(0.2, 0, 0.38, 0.9) forwards;
  animation-delay: var(--sk-d, 0ms);
}
.msg-skeleton-row.right { justify-content: flex-end; }
.msg-skeleton-row.group-start { margin-top: 12px; }

@keyframes sk-row-in {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* Bolla shimmer — incoming */
.msg-skeleton-bubble {
  border-radius: 8px 8px 8px 3px;
  background: linear-gradient(90deg, #eef0f2 20%, #e2e6e9 45%, #eef0f2 70%);
  background-size: 300% 100%;
  animation: sk-shimmer 1.1s ease-in-out infinite;
  animation-delay: var(--sk-d, 0ms);
  min-height: 36px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px 8px;
  box-sizing: border-box;
  box-shadow: 0 1px 2px rgba(0,0,0,0.07);
}

/* Bolla outgoing */
.msg-skeleton-row.right .msg-skeleton-bubble {
  border-radius: 8px 8px 3px 8px;
  background: linear-gradient(90deg, #d6f9ce 20%, #c6f4bc 45%, #d6f9ce 70%);
  background-size: 300% 100%;
  animation: sk-shimmer-green 1.1s ease-in-out infinite;
  animation-delay: var(--sk-d, 0ms);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

@keyframes sk-shimmer       { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@keyframes sk-shimmer-green { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* Linee di testo placeholder */
.msg-skeleton-line {
  height: 10px;
  border-radius: 6px;
  background: rgba(0,0,0,0.08);
}
.msg-skeleton-time {
  height: 8px;
  width: 38px;
  border-radius: 4px;
  background: rgba(0,0,0,0.05);
  align-self: flex-end;
  margin-top: 1px;
}

/* Media placeholder (image/video) */
.msg-skeleton-media {
  border-radius: 8px;
  background: linear-gradient(90deg, #ececec 20%, #dadada 45%, #ececec 70%);
  background-size: 300% 100%;
  animation: sk-shimmer 1.1s ease-in-out infinite;
  animation-delay: var(--sk-d, 0ms);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.msg-skeleton-row.right .msg-skeleton-media {
  background: linear-gradient(90deg, #c6f4bc 20%, #a8eaa0 45%, #c6f4bc 70%);
  animation: sk-shimmer-green 1.1s ease-in-out infinite;
  animation-delay: var(--sk-d, 0ms);
}

/* Date divider in skeleton */
.msg-skeleton-date-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 8px;
  opacity: 0;
  animation: sk-row-in 0.22s cubic-bezier(0.2, 0, 0.38, 0.9) forwards;
  animation-delay: var(--sk-d, 0ms);
}
.msg-skeleton-date-divider span {
  height: 10px;
  width: 120px;
  border-radius: 5px;
  background: rgba(0,0,0,0.08);
}

/* ---- Dark mode ---- */
[data-theme="dark"] .msg-skeleton-bubble {
  background: linear-gradient(90deg, #1e2b32 25%, #253540 50%, #1e2b32 75%);
  background-size: 400% 100%;
  animation: sk-shimmer-dark 1.3s ease-in-out infinite;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
[data-theme="dark"] .msg-skeleton-row.right .msg-skeleton-bubble {
  background: linear-gradient(90deg, #014236 25%, #01584a 50%, #014236 75%);
  background-size: 400% 100%;
  animation: sk-shimmer-dark-green 1.3s ease-in-out infinite;
}
[data-theme="dark"] .msg-skeleton-line { background: rgba(255,255,255,0.10); }
[data-theme="dark"] .msg-skeleton-time { background: rgba(255,255,255,0.06); }
[data-theme="dark"] .msg-skeleton-media {
  background: linear-gradient(90deg, #2a3942 25%, #3f5560 50%, #2a3942 75%);
  background-size: 400% 100%;
  animation: sk-shimmer-dark 1.3s ease-in-out infinite;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
[data-theme="dark"] .msg-skeleton-row.right .msg-skeleton-media {
  background: linear-gradient(90deg, #014236 25%, #01584a 50%, #014236 75%);
  background-size: 400% 100%;
  animation: sk-shimmer-dark-green 1.3s ease-in-out infinite;
}
[data-theme="dark"] .msg-skeleton-date-divider span { background: rgba(255,255,255,0.10); }
@keyframes sk-shimmer-dark       { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@keyframes sk-shimmer-dark-green { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* Fade-in rapido quando i messaggi reali sostituiscono lo skeleton */
.whatsapp-messages-container.wa-msgs-fade-in {
  animation: wa-msgs-appear 0.15s ease-out both;
}
@keyframes wa-msgs-appear {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0);   }
}

.date-separator {
  text-align: center;
  margin: 16px 0 10px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.date-separator::before {
  content: '';
  display: none;
}

.date-separator::after {
  content: attr(data-date);
  background: #e1f0d8;
  padding: 5px 12px 6px;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(11,20,26,0.1);
  font-size: 12px;
  font-weight: 500;
  color: #54656f;
  position: relative;
  z-index: 1;
  display: inline-block;
  letter-spacing: 0.1px;
  line-height: 1.4;
}

[data-theme="dark"] .date-separator::after {
  background: #182d21;
  color: #8696a0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.message {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.35rem;
  animation: messageIn 0.2s ease;
  padding: 0 0.5rem;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(5px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.message-incoming {
  align-self: flex-start;
  max-width: min(85%, 550px);
}

.message-incoming .message-sender {
  display: block;
}

.message-outgoing {
  align-self: flex-end;
  max-width: min(85%, 550px);
}

/* Mobile responsive: bigger messages on small screens */
@media (max-width: 480px) {
  .message-incoming,
  .message-outgoing {
    max-width: 90%;
  }
}

@media (max-width: 375px) {
  .message-incoming,
  .message-outgoing {
    max-width: 95%;
  }
}

.message-sender {
  font-size: 10px;
  font-weight: 400;
  color: #999999;
  margin-bottom: 1px;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-bubble {
  background: #ffffff;
  padding: 8px 10px 7px 10px;
  border-radius: 0 8px 8px 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.13);
  position: relative;
  word-wrap: break-word;
  width: fit-content;
  transition: box-shadow 0.15s ease;
  max-width: 100%;
}

.message-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  width: 0;
  height: 0;
  border-style: solid;
}

.message-incoming .message-bubble::before {
  left: -8px;
  top: 0;
  border-width: 0 9px 9px 0;
  border-color: transparent #ffffff transparent transparent;
}

[data-theme="dark"] .message-incoming .message-bubble::before {
  border-color: transparent #202c33 transparent transparent;
}

.message-outgoing .message-bubble::before {
  right: -8px;
  top: 0;
  border-width: 9px 9px 0 0;
  border-color: #d9fdd3 transparent transparent transparent;
}

[data-theme="dark"] .message-outgoing .message-bubble::before {
  border-color: #005c4b transparent transparent transparent;
}

.message-bubble:hover {
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.message-outgoing .message-bubble {
  background: #d9fdd3;
  color: #111b21;
  border-radius: 8px 0 8px 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.13);
}

[data-theme="dark"] .message-bubble {
  background: #202c33;
  color: #e9edef;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

[data-theme="dark"] .message-bubble:hover {
  box-shadow: 0 2px 5px rgba(0,0,0,0.35);
}

[data-theme="dark"] .message-outgoing .message-bubble {
  background: #005c4b;
  color: #e9edef;
}

[data-theme="dark"] .message-time {
  color: rgba(233, 237, 239, 0.6);
}

.message-text {
  font-size: 14.4px;
  line-height: 20px;
  color: #111b21;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  letter-spacing: 0.01em;
}

.message-outgoing .message-text {
  color: #111b21;
}

[data-theme="dark"] .message-text {
  color: #e9edef;
}

[data-theme="dark"] .message-outgoing .message-text {
  color: #e9edef;
}

.message-text a {
  color: #027eb5;
  text-decoration: none;
}

.message-text a:hover {
  text-decoration: underline;
}

.message-time {
  font-size: 11px;
  color: #667781;
  margin-top: 2px;
  text-align: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  float: right;
  margin-left: 8px;
  font-weight: 400;
}

[data-theme="dark"] .message-time {
  color: rgba(233, 237, 239, 0.6);
}

.message-media {
  margin-bottom: 0.5rem;
  border-radius: 8px;
  overflow: hidden;
}

.message-media img {
  max-width: 100%;
  display: block;
  cursor: pointer;
  transition: opacity 0.2s;
}

.message-media img:hover {
  opacity: 0.9;
}

.message-media video {
  max-width: 100%;
  display: block;
}

.message-audio audio {
  width: 100%;
  height: 40px;
}

.message-document {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

[data-theme="dark"] .message-document {
  background: rgba(255, 255, 255, 0.05);
}

.message-document i {
  font-size: 1.5rem;
  color: #667781;
}

.message-document a {
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.85rem;
}

.message-document a:hover {
  text-decoration: underline;
}

.message-quoted {
  background: rgba(102, 126, 234, 0.08);
  border-left: 4px solid #667eea;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.message-quoted:hover {
  background: rgba(102, 126, 234, 0.12);
}

[data-theme="dark"] .message-quoted {
  background: rgba(90, 103, 216, 0.12);
  border-left-color: #5a67d8;
}

[data-theme="dark"] .message-quoted:hover {
  background: rgba(90, 103, 216, 0.18);
}

.quoted-sender {
  font-size: 0.75rem;
  font-weight: 700;
  color: #667eea;
  margin-bottom: 0.25rem;
}

[data-theme="dark"] .quoted-sender {
  color: #a5b4fc;
}

.quoted-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-input {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--card-bg);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.chat-input input {
  flex: 1;
  padding: 0.875rem 1.25rem;
  border: 2px solid var(--border-color);
  border-radius: 28px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: all 0.3s ease;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

.chat-input input:focus {
  outline: none;
  border-color: #667eea;
  background: var(--bg-primary);
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1), inset 0 1px 3px rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}

.chat-send-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: #25D366; /* WhatsApp green */
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
}

.chat-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(37, 211, 102, 0.6);
}

.chat-send-btn:active {
  transform: scale(0.95) rotate(0deg);
}

.chat-send-btn i {
  transition: transform 0.3s ease;
}

.chat-send-btn:hover i {
  transform: none;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  text-align: center;
}

.empty-state i {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.empty-state p {
  font-size: 1.1rem;
  margin: 0.5rem 0;
}

.empty-state small {
  font-size: 0.9rem;
  opacity: 0.7;
}

.highlight-search {
  animation: highlight 0.5s ease;
}

@keyframes highlight {
  0%, 100% {
    background: transparent;
  }
  50% {
    background: rgba(255, 235, 59, 0.3);
  }
}

.media-viewer {
  max-width: 90vw;
  max-height: 90vh;
}

.media-viewer .modal-body {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  background: #000;
}

/* ===== Media Gallery Overlay ===== */
.mg-overlay {
  position: fixed; inset: 0; z-index: 99999;
  background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  user-select: none;
}
.mg-topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; z-index: 3;
  background: linear-gradient(180deg, rgba(0,0,0,.6) 0%, transparent 100%);
}
.mg-counter {
  color: #fff; font-size: 14px; font-weight: 500; opacity: .85;
}
.mg-tools {
  display: flex; gap: 6px;
}
.mg-btn {
  background: rgba(255,255,255,.12); border: none; border-radius: 50%;
  width: 40px; height: 40px; color: #fff; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.mg-btn:hover { background: rgba(255,255,255,.25); }
.mg-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  z-index: 3; background: rgba(255,255,255,.1); border: none;
  border-radius: 50%; width: 48px; height: 48px;
  color: #fff; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.mg-nav:hover { background: rgba(255,255,255,.25); }
.mg-prev { left: 16px; }
.mg-next { right: 16px; }
.mg-stage {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  overflow: hidden;
}
.mg-image {
  max-width: 90vw; max-height: 88vh;
  object-fit: contain;
  transition: transform .15s ease;
  cursor: default;
}
.mg-video {
  max-width: 90vw; max-height: 88vh;
  outline: none;
}

.mg-task-modal {
  position: fixed;
  inset: 0;
  z-index: 100001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0,0,0,0.6);
}

.mg-task-modal-card {
  width: 420px;
  max-width: 90vw;
  background: var(--bg-primary, #fff);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.mg-task-modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.mg-task-modal-header i {
  color: #25D366;
  font-size: 20px;
}

.mg-task-modal-header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text-primary, #111b21);
}

.mg-task-field {
  margin-bottom: 12px;
}

.mg-task-field label {
  font-size: 12px;
  color: var(--text-secondary, #667781);
  display: block;
  margin-bottom: 4px;
}

.mg-task-title,
.mg-task-desc {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color, #e9edef);
  border-radius: 8px;
  font-size: 14px;
  box-sizing: border-box;
  outline: none;
  background: var(--bg-secondary, #f0f2f5);
  color: var(--text-primary, #111b21);
}

.mg-task-desc {
  resize: vertical;
  min-height: 88px;
}

.mg-task-title:focus,
.mg-task-desc:focus {
  border-color: #25D366;
  box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.18);
}

.mg-task-attachment-row {
  margin-bottom: 16px;
  padding: 10px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary, #f0f2f5);
  color: var(--text-secondary, #667781);
  font-size: 13px;
}

.mg-task-attachment-row i {
  color: #25D366;
}

.mg-task-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.mg-task-cancel,
.mg-task-confirm {
  padding: 8px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.mg-task-cancel {
  border: 1px solid var(--border-color, #e9edef);
  background: transparent;
  color: var(--text-secondary, #667781);
}

.mg-task-confirm {
  border: none;
  background: #25D366;
  color: #fff;
  font-weight: 600;
}

.mg-task-confirm:disabled {
  opacity: 0.75;
  cursor: default;
}

@media (max-width: 600px) {
  .mg-nav { width: 36px; height: 36px; font-size: 16px; }
  .mg-prev { left: 6px; }
  .mg-next { right: 6px; }
  .mg-btn { width: 34px; height: 34px; font-size: 14px; }
  .mg-topbar { padding: 8px 10px; }
  .mg-task-modal-card {
    width: 100%;
    max-width: 96vw;
    padding: 16px;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .message {
    max-width: 85%;
  }
  
  .chat-header-info h3 {
    font-size: 1rem;
  }
  
  .chat-subtitle {
    font-size: 0.75rem;
  }
}

/* ===================================
   SEZIONE 2: WHATSAPP LAYOUT
   =================================== */

/* ---- WA Chat Navbar (inside whatsapp-layout) ---- */
.wa-chat-navbar {
  width: 68px;
  height: 100%;
  background: #e8e8e8;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  border-right: 1px solid #d1d7db;
}

[data-theme="dark"] .wa-chat-navbar {
  background: #222e35;
  border-right-color: #2a3942;
}

.wa-chat-nav-top {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 12px;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.wa-chat-nav-top::-webkit-scrollbar { width: 0; }

.wa-chat-nav-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  padding-bottom: 12px;
}

.wa-chat-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  color: #54656f;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  position: relative;
  padding: 0;
}

[data-theme="dark"] .wa-chat-nav-btn {
  color: #aebac1;
}

.wa-chat-nav-btn svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.wa-chat-nav-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .wa-chat-nav-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.wa-chat-nav-btn.active {
  background: rgba(0, 168, 132, 0.1);
  color: #00a884;
}

[data-theme="dark"] .wa-chat-nav-btn.active {
  background: rgba(0, 168, 132, 0.15);
  color: #00a884;
}

.wa-chat-nav-btn.active svg {
  fill: #00a884;
  color: #00a884;
}

/* Active indicator bar */
.wa-chat-nav-btn.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 24px;
  border-radius: 0 4px 4px 0;
  background: #00a884;
}

/* WA Chat Nav Avatar */
.wa-chat-nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #00a884;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  transition: opacity 0.15s;
  margin-top: 4px;
}

.wa-chat-nav-avatar:hover {
  opacity: 0.85;
}

.wa-chat-nav-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* Tooltip for nav buttons */
.wa-chat-nav-btn[title]:hover::after,
.wa-chat-nav-avatar[title]:hover::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: #333;
  color: #fff;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 100000;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.wa-chat-nav-avatar {
  position: relative;
}

.main-content:has(.whatsapp-layout) {
  padding: 0 !important;
  overflow: hidden !important;
  background: var(--chat-bg-light) !important;
  height: calc(100vh - 60px) !important;
  height: calc(100dvh - 60px) !important;
  max-height: calc(100vh - 60px) !important;
  max-height: calc(100dvh - 60px) !important;
}

[data-theme="dark"] .main-content:has(.whatsapp-layout) {
  background: var(--chat-bg-dark) !important;
}

.whatsapp-layout {
  display: flex;
  height: 100%;
  width: 100%;
  background: transparent;
  overflow: hidden;
  position: relative;
}

/* ===================================
   WHATSAPP SIDEBAR
   =================================== */

.whatsapp-sidebar {
  width: 420px;
  height: 100%;
  background: #ffffff;
  border-right: 1px solid #e9edef;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-shadow: none;
}

[data-theme="dark"] .whatsapp-sidebar {
  background: #111b21;
  border-right-color: #2a3942;
}

.whatsapp-sidebar-header {
  height: 54px;
  background: #f0f2f5;
  padding: 8px 14px 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: none;
  box-shadow: 0 1px 0 rgba(11,20,26,0.08);
  z-index: 2;
  flex-shrink: 0;
}

[data-theme="dark"] .whatsapp-sidebar-header {
  background: #202c33;
  border-bottom: none;
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
}

.whatsapp-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: #111b21;
  cursor: pointer;
  letter-spacing: -0.01em;
}

[data-theme="dark"] .whatsapp-user-info {
  color: #e9edef;
}

/* Total unread badge */
.wa-total-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  animation: badgePop 0.25s ease;
  height: 22px;
  padding: 0 7px;
  background: #25d366;
  color: #fff;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  margin-left: 4px;
}

@keyframes badgePop {
  0% { transform: scale(0); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.whatsapp-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #25d366;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

[data-theme="dark"] .whatsapp-user-avatar {
  background: #00a884;
  color: #fff;
}

.whatsapp-sidebar-actions {
  display: flex;
  gap: 8px;
}

.whatsapp-icon-btn {
  width: 36px !important;
  height: 36px !important;
  border-radius: 50% !important;
  border: none !important;
  background: transparent !important;
  color: #54656f !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: color 0.15s ease, background 0.15s ease !important;
  font-size: 16px !important;
  flex-shrink: 0 !important;
  margin-bottom: 0 !important;
}

.whatsapp-icon-btn:hover {
  background: rgba(11, 20, 26, 0.06) !important;
  color: #3b4a54 !important;
}

.whatsapp-icon-btn:active {
  transform: scale(0.95);
}

[data-theme="dark"] .whatsapp-icon-btn {
  color: #aebac1 !important;
}

[data-theme="dark"] .whatsapp-icon-btn:hover {
  background: rgba(255, 255, 255, 0.06) !important;
  color: #d1d7db !important;
}

.whatsapp-search-bar {
  padding: 6px 12px 8px 12px;
  background: #fff;
  border-bottom: none;
}

[data-theme="dark"] .whatsapp-search-bar {
  background: #1f2c34;
  border-bottom: none;
}

/* Chat Filter Tabs */
.chat-filter-tabs {
  display: flex;
  gap: 6px;
  padding: 6px 14px 8px;
  background: #fff;
  border-bottom: 1px solid #e9edef;
  overflow-x: auto;
  scrollbar-width: none;
}

.chat-filter-tabs::-webkit-scrollbar {
  display: none;
}

[data-theme="dark"] .chat-filter-tabs {
  background: #1f2c34;
  border-bottom: 1px solid rgba(233, 237, 239, 0.08);
}

.chat-filter-tab {
  padding: 5px 14px;
  border-radius: 18px;
  background: #f0f2f5;
  border: none;
  color: #54656f;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.chat-filter-tab:hover {
  background: #e9edef;
  color: #3b4a54;
}

.chat-filter-tab.active {
  background: #e7fcee;
  color: #00a884;
  font-weight: 600;
}

[data-theme="dark"] .chat-filter-tab {
  background: rgba(255,255,255,0.06);
  color: #8696a0;
}

[data-theme="dark"] .chat-filter-tab:hover {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chat-filter-tab.active {
  background: rgba(0,168,132,0.15);
  color: #00a884;
}

/* Filter tab count badges */
.filter-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(0,0,0,0.06);
  color: inherit;
  margin-left: 4px;
  opacity: 0.7;
}
.filter-tab-count:empty {
  display: none;
}
.filter-tab-count.has-count {
  background: #25d366;
  color: #fff;
  opacity: 1;
}
.chat-filter-tab.active .filter-tab-count {
  background: rgba(255,255,255,0.25);
  color: #fff;
  opacity: 1;
}
.chat-filter-tab.active .filter-tab-count.has-count {
  background: #fff;
  color: #00a884;
}
[data-theme="dark"] .filter-tab-count {
  background: rgba(255,255,255,0.08);
}

/* Encryption Badge */
.encryption-badge {
  padding: 10px 16px;
  background: transparent;
  border-top: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 12px;
  color: rgba(134,150,160,0.7);
  position: relative;
  z-index: 1;
}

.encryption-badge i {
  color: rgba(134,150,160,0.6);
  font-size: 12px;
}

.encryption-badge .highlight {
  color: #00a884;
  font-weight: 500;
}

[data-theme="light"] .encryption-badge {
  background: transparent;
  border-top: none;
  color: rgba(102,119,129,0.7);
}

[data-theme="light"] .encryption-badge i {
  color: rgba(102,119,129,0.6);
}

/* Connection Status Indicator */
.wsp-connection-status-bar {
  padding: 6px 16px;
  background: #fff;
  border-bottom: 1px solid #e9edef;
  border-top: none;
}

[data-theme="dark"] .wsp-connection-status-bar {
  background: #1f2c34;
  border-bottom-color: rgba(233,237,239,0.08);
  border-top: none;
}

.wsp-status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #667781;
}

[data-theme="dark"] .wsp-status-indicator {
  color: #aebac1;
}

.wsp-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.wsp-status-dot.connected {
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
  animation: pulse-wsp-green 2s ease-in-out infinite;
}

.wsp-status-dot.disconnected {
  background: #9ca3af;
  box-shadow: none;
  animation: none;
}

.wsp-status-dot.scanning {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
  animation: pulse-wsp-amber 2s ease-in-out infinite;
}

@keyframes pulse-wsp-green {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
  }
  50% {
    opacity: 0.7;
    box-shadow: 0 0 3px rgba(16, 185, 129, 0.3);
  }
}

@keyframes pulse-wsp-amber {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
  }
  50% {
    opacity: 0.7;
    box-shadow: 0 0 3px rgba(245, 158, 11, 0.3);
  }
}

.wsp-status-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Scheduled Messages Sidebar Section === */
.wa-scheduled-sidebar-section {
  border-bottom: 1px solid #e9edef;
  background: #f0fdf4;
}
[data-theme="dark"] .wa-scheduled-sidebar-section {
  background: #1a2e23;
  border-bottom-color: #2a3942;
}
.wa-scheduled-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.wa-scheduled-sidebar-header:hover {
  background: rgba(37, 211, 102, 0.08);
}
.wa-scheduled-sidebar-body {
  max-height: 220px;
  overflow-y: auto;
  padding: 0 8px 8px;
}
.wa-sched-sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  background: #fff;
  margin-bottom: 4px;
  border: 1px solid #e5e7eb;
}
[data-theme="dark"] .wa-sched-sidebar-item {
  background: #1f2c34;
  border-color: #2a3942;
}
.wa-sched-sidebar-item:hover {
  background: #dcfce7;
  border-color: #86efac;
}
[data-theme="dark"] .wa-sched-sidebar-item:hover {
  background: #22412e;
  border-color: #34d399;
}
.wa-sched-sidebar-item-main {
  flex: 1;
  min-width: 0;
}
.wa-sched-sidebar-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.wa-sched-sidebar-recipient {
  font-weight: 600;
  font-size: 0.78rem;
  color: #166534;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
[data-theme="dark"] .wa-sched-sidebar-recipient {
  color: #6ee7b7;
}
.wa-sched-sidebar-time {
  font-size: 0.68rem;
  color: #128c7e;
  white-space: nowrap;
  flex-shrink: 0;
}
[data-theme="dark"] .wa-sched-sidebar-time {
  color: #34d399;
}
.wa-sched-sidebar-text {
  font-size: 0.76rem;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
[data-theme="dark"] .wa-sched-sidebar-text {
  color: #d1d5db;
}
.wa-sched-sidebar-date {
  font-size: 0.67rem;
  color: #9ca3af;
  margin-top: 2px;
}
.wa-sched-sidebar-cancel {
  background: none;
  border: 1px solid #fca5a5;
  color: #dc2626;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  flex-shrink: 0;
  transition: all 0.2s;
  opacity: 0;
}
.wa-sched-sidebar-item:hover .wa-sched-sidebar-cancel {
  opacity: 1;
}
.wa-sched-sidebar-cancel:hover {
  background: #fef2f2;
  border-color: #ef4444;
}

.whatsapp-search-input-wrapper {
  background: #f0f2f5;
  border-radius: 8px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: none;
  transition: all 0.2s ease;
  border: 1.5px solid transparent;
}

.whatsapp-search-input-wrapper:focus-within {
  box-shadow: none;
  background: #fff;
  border-color: #00a884;
}

[data-theme="dark"] .whatsapp-search-input-wrapper {
  background: #202c33;
  box-shadow: none;
  border-color: transparent;
}

[data-theme="dark"] .whatsapp-search-input-wrapper:focus-within {
  box-shadow: none;
  background: #2a3942;
  border-color: #00a884;
}

.whatsapp-search-input-wrapper i {
  color: #8696a0;
  font-size: 14px;
}

.whatsapp-search-input-wrapper input {
  flex: 1;
  border: none;
  background: transparent;
  color: #111b21;
  font-size: 14px;
  outline: none;
}

[data-theme="dark"] .whatsapp-search-input-wrapper input {
  color: #e9edef;
}

.whatsapp-search-input-wrapper input::placeholder {
  color: #8696a0;
}

.whatsapp-chat-list {
  flex: 1;
  overflow-y: auto;
  background: #fff;
}

[data-theme="dark"] .whatsapp-chat-list {
  background: #111b21;
}

.chat-list-item {
  display: flex !important;
  align-items: center;
  padding: 8px 13px 8px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(233,237,239,0.6);
  transition: background 0.08s ease;
  position: relative;
  width: 100%;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.chat-list-item:hover {
  background: #f5f6f6;
}

.chat-list-item.active {
  background: #f0f2f5;
}

.chat-list-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #00a884;
  border-radius: 0 2px 2px 0;
}

[data-theme="dark"] .chat-list-item {
  border-bottom-color: rgba(233, 237, 239, 0.06);
}

[data-theme="dark"] .chat-list-item:hover {
  background: #202c33;
}

[data-theme="dark"] .chat-list-item.active {
  background: #2a3942;
}

[data-theme="dark"] .chat-list-item.active::before {
  background: #00a884;
}

.chat-list-item-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #00a884;
  display: flex !important;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 17px;
  margin-right: 12px;
  flex-shrink: 0;
  box-shadow: none;
  font-weight: 600;
  overflow: hidden;
  letter-spacing: 0.3px;
}

[data-theme="dark"] .chat-list-item-avatar {
  background: #00a884;
  color: #fff;
}

.chat-list-item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chat-list-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1px;
}

.chat-list-name {
  font-weight: 500;
  font-size: 15.5px;
  color: #111b21;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
  flex: 1;
  line-height: 21px;
  padding-right: 8px;
}

[data-theme="dark"] .chat-list-name {
  color: #e9edef;
}

/* Timestamp e preview messaggi */
.chat-list-time {
  font-size: 11px;
  color: #667781;
  white-space: nowrap;
  margin-left: 8px;
  font-weight: 400;
}

[data-theme="dark"] .chat-list-time {
  color: #8696a0;
}

.chat-list-item-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
  gap: 8px;
}

.chat-list-item-preview {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: #667781;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 18px;
  flex: 1;
  min-width: 0;
}

[data-theme="dark"] .chat-list-item-preview {
  color: #8696a0;
}

.chat-list-item-preview i {
  font-size: 14px;
  flex-shrink: 0;
}

.chat-list-item-preview .message-status {
  color: #8696a0;
  margin-right: 2px;
}

[data-theme="dark"] .chat-list-item-preview .message-status {
  color: #8696a0;
}

.chat-list-item-preview span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-list-unread {
  background: #25d366;
  color: white;
  border-radius: 12px;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 700;
  padding: 0 5px;
  box-shadow: none;
  margin-left: auto;
  flex-shrink: 0;
}

[data-theme="dark"] .chat-list-unread {
  background: #00a884;
}

.chat-list-unread-dot {
  min-width: 12px;
  width: 12px;
  height: 12px;
  padding: 0;
  border-radius: 50%;
  font-size: 0;
}

.chat-list-empty {
  padding: 40px 20px;
  text-align: center;
  color: #667781;
  font-size: 14px;
}

/* --- Load More Chat Button --- */
.chat-list-load-more {
  padding: 8px 12px;
  text-align: center;
}
.chat-load-more-btn {
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: #e9edef;
  color: #008069;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s;
}
.chat-load-more-btn:hover {
  background: #d9dee1;
}
[data-theme="dark"] .chat-load-more-btn {
  background: #233138;
  color: #00a884;
}
[data-theme="dark"] .chat-load-more-btn:hover {
  background: #2a3942;
}

/* ===================================
   WHATSAPP MAIN - AREA CONVERSAZIONE
   =================================== */

.whatsapp-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #efeae2;
  position: relative;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

[data-theme="dark"] .whatsapp-main {
  background: #0b141a;
}

/* WhatsApp Chat Header */
.whatsapp-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 8px 7px 14px;
  background: #f0f2f5;
  border-bottom: none;
  min-height: 54px;
  flex-shrink: 0;
  -webkit-font-smoothing: antialiased;
  box-shadow: 0 1px 0 rgba(11,20,26,0.08);
  z-index: 2;
}

[data-theme="dark"] .whatsapp-chat-header {
  background: #202c33;
  border-bottom-color: transparent;
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
}

.whatsapp-chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.whatsapp-contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #dfe5e7;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #54656f;
  font-size: 17px;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform 0.15s ease;
}

.whatsapp-contact-avatar:hover {
  transform: scale(1.04);
}

[data-theme="dark"] .whatsapp-contact-avatar {
  background: #182229;
  color: #8696a0;
}

/* Chat header info - name and status */
.whatsapp-chat-header-info {
  flex: 1;
  min-width: 0;
}

.whatsapp-chat-header-name {
  font-size: 15px;
  font-weight: 600;
  color: #111b21;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

[data-theme="dark"] .whatsapp-chat-header-name {
  color: #e9edef;
}

.whatsapp-chat-header-status {
  font-size: 12px;
  color: #667781;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}

[data-theme="dark"] .whatsapp-chat-header-status {
  color: #8696a0;
}

/* Online/Offline indicators */
.offline-indicator,
.online-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.offline-indicator {
  background: #8696a0;
}

.online-indicator {
  background: #25d366;
  box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.2);
  animation: onlinePulse 2.5s ease-in-out infinite;
}

@keyframes onlinePulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(37,211,102,0.2); }
  50% { box-shadow: 0 0 0 3px rgba(37,211,102,0.1); }
}

.whatsapp-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.whatsapp-status-badge {
  font-size: 12px;
  color: #00a884;
  font-weight: 500;
  margin-right: 8px;
}

.whatsapp-messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px 2.5% 12px;
  background-color: #efeae2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cg fill='none' stroke='%23c8c3ba' stroke-width='0.5' opacity='0.45'%3E%3Cpath d='M12 10h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Ccircle cx='42' cy='13' r='4'/%3E%3Cpath d='M42 10v3h2'/%3E%3Crect x='68' y='9' width='5' height='8' rx='1'/%3E%3Ccircle cx='70.5' cy='15' r='.6' fill='%23c8c3ba'/%3E%3Ccircle cx='100' cy='13' r='4'/%3E%3Cpath d='M98 11.5a1 1 0 0 1 2 0M102 11.5a1 1 0 0 1-2 0'/%3E%3Cpath d='M97.5 14.5c1.5 2 3.5 2 5 0'/%3E%3Cpath d='M130 10l1.5 3 3 .5-2 2 .5 3-3-1.5-3 1.5.5-3-2-2 3-.5z'/%3E%3Crect x='155' y='10' width='8' height='6' rx='1'/%3E%3Ccircle cx='159' cy='13' r='1.5'/%3E%3Cpath d='M157 10l1-2h2l1 2'/%3E%3Crect x='185' y='10' width='5' height='4.5' rx='.5'/%3E%3Cpath d='M186 10v-2c0-1.5 3-1.5 3 0v2'/%3E%3Cpath d='M215 8v8'/%3E%3Ccircle cx='214' cy='16' r='1.5'/%3E%3Cpath d='M215 8l3.5-1.5v2l-3.5 1.5'/%3E%3Cpath d='M238 13c0-2 2-3 3-1.5 1-1.5 3-.5 3 1.5s-3 4-3 4-3-2-3-4z'/%3E%3Cpath d='M14 40h4.5c.8 0 1.2.5 1.2 1.2v2.5c0 .8-.4 1.2-1.2 1.2h-1.5l-1.5 1.5v-1.5H14c-.8 0-1.2-.4-1.2-1.2v-2.5c0-.7.4-1.2 1.2-1.2z'/%3E%3Ccircle cx='45' cy='43' r='3.5'/%3E%3Cpath d='M48 46l3 3'/%3E%3Cpath d='M70 38c-3 0-5 3-5 3s2 3 5 3 5-3 5-3-2-3-5-3z'/%3E%3Ccircle cx='70' cy='41' r='1.2'/%3E%3Crect x='95' y='38' width='8' height='6' rx='1'/%3E%3Ccircle cx='98' cy='40.5' r='1'/%3E%3Cpath d='M95 43l2.5-2 2 1.5 1-1 2.5 1.5'/%3E%3Cpath d='M130 43c0-3 2-4.5 4-4.5s4 1.5 4 4.5'/%3E%3Crect x='130' y='42.5' width='2.5' height='3.5' rx='.5'/%3E%3Crect x='135.5' y='42.5' width='2.5' height='3.5' rx='.5'/%3E%3Ccircle cx='162' cy='41' r='4'/%3E%3Cellipse cx='162' cy='41' rx='2' ry='4'/%3E%3Cpath d='M158 41h8'/%3E%3Cpath d='M185 38h5c.3 0 .5.3.5.5v7l-3-2-3 2v-7c0-.2.2-.5.5-.5z'/%3E%3Crect x='213' y='38' width='6' height='6' rx='.5'/%3E%3Cpath d='M213 41h6M215 36v2M217 36v2'/%3E%3Cpath d='M240 36l-2 4.5h3l-2 4.5'/%3E%3Crect x='10' y='68' width='4' height='6' rx='2'/%3E%3Cpath d='M8 73c0 2 2.5 3 4 3s4-1 4-3M12 77v2'/%3E%3Cpath d='M42 68l-5.5 3 2 1.5 3.5-4.5zM38 72.5l1 3 1.5-2'/%3E%3Crect x='65' y='67' width='6' height='8' rx='1'/%3E%3Cpath d='M67 70h2M67 72h2'/%3E%3Ccircle cx='100' cy='71' r='2.5'/%3E%3Cpath d='M103 71h4.5M106 71v2'/%3E%3Cpath d='M130 66a3 3 0 0 0-3 3c0 2.5 3 5 3 5s3-2.5 3-5a3 3 0 0 0-3-3z'/%3E%3Ccircle cx='130' cy='69' r='1' fill='%23c8c3ba'/%3E%3Cpath d='M157 68l4.5 4.5M161.5 72.5c.7.7.3 2-.6 3s-2.2 1.3-3 .6'/%3E%3Cpath d='M188 69c1.5-1.5 3.5-1.5 5 0M191 74c-1.5 1.5-3.5 1.5-5 0M188.5 73.5l4.5-4.5'/%3E%3Cpath d='M215 68h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Ccircle cx='242' cy='71' r='4'/%3E%3Cpath d='M242 68v3h2'/%3E%3Cpath d='M12 100h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Crect x='38' y='97' width='5' height='8' rx='1'/%3E%3Ccircle cx='40.5' cy='103' r='.6' fill='%23c8c3ba'/%3E%3Ccircle cx='70' cy='101' r='4'/%3E%3Cpath d='M68 99.5a1 1 0 0 1 2 0M72 99.5a1 1 0 0 1-2 0'/%3E%3Cpath d='M67.5 103c1.5 2 3.5 2 5 0'/%3E%3Cpath d='M100 97l1.5 3 3 .5-2 2 .5 3-3-1.5-3 1.5.5-3-2-2 3-.5z'/%3E%3Crect x='125' y='97' width='8' height='6' rx='1'/%3E%3Ccircle cx='129' cy='100' r='1.5'/%3E%3Cpath d='M127 97l1-2h2l1 2'/%3E%3Crect x='155' y='97' width='5' height='4.5' rx='.5'/%3E%3Cpath d='M156 97v-2c0-1.5 3-1.5 3 0v2'/%3E%3Cpath d='M185 95v8'/%3E%3Ccircle cx='184' cy='103' r='1.5'/%3E%3Cpath d='M185 95l3.5-1.5v2l-3.5 1.5'/%3E%3Cpath d='M210 101c0-2 2-3 3-1.5 1-1.5 3-.5 3 1.5s-3 4-3 4-3-2-3-4z'/%3E%3Ccircle cx='242' cy='101' r='3.5'/%3E%3Cpath d='M245 104l3 3'/%3E%3Cpath d='M14 130h4.5c.8 0 1.2.5 1.2 1.2v2.5c0 .8-.4 1.2-1.2 1.2h-1.5l-1.5 1.5v-1.5H14c-.8 0-1.2-.4-1.2-1.2v-2.5c0-.7.4-1.2 1.2-1.2z'/%3E%3Cpath d='M40 126c-3 0-5 3-5 3s2 3 5 3 5-3 5-3-2-3-5-3z'/%3E%3Ccircle cx='40' cy='129' r='1.2'/%3E%3Crect x='65' y='126' width='8' height='6' rx='1'/%3E%3Ccircle cx='68' cy='128.5' r='1'/%3E%3Cpath d='M65 131l2.5-2 2 1.5 1-1 2.5 1.5'/%3E%3Cpath d='M100 131c0-3 2-4.5 4-4.5s4 1.5 4 4.5'/%3E%3Crect x='100' y='130.5' width='2.5' height='3.5' rx='.5'/%3E%3Crect x='105.5' y='130.5' width='2.5' height='3.5' rx='.5'/%3E%3Ccircle cx='132' cy='129' r='4'/%3E%3Cellipse cx='132' cy='129' rx='2' ry='4'/%3E%3Cpath d='M128 129h8'/%3E%3Cpath d='M155 126h5c.3 0 .5.3.5.5v7l-3-2-3 2v-7c0-.2.2-.5.5-.5z'/%3E%3Crect x='183' y='126' width='6' height='6' rx='.5'/%3E%3Cpath d='M183 129h6M185 124v2M187 124v2'/%3E%3Cpath d='M215 124l-2 4.5h3l-2 4.5'/%3E%3Crect x='237' y='127' width='6' height='8' rx='1'/%3E%3Cpath d='M239 130h2M239 132h2'/%3E%3Crect x='10' y='157' width='4' height='6' rx='2'/%3E%3Cpath d='M8 162c0 2 2.5 3 4 3s4-1 4-3M12 166v2'/%3E%3Cpath d='M42 157l-5.5 3 2 1.5 3.5-4.5zM38 161.5l1 3 1.5-2'/%3E%3Ccircle cx='70' cy='160' r='2.5'/%3E%3Cpath d='M73 160h4.5M76 160v2'/%3E%3Cpath d='M100 155a3 3 0 0 0-3 3c0 2.5 3 5 3 5s3-2.5 3-5a3 3 0 0 0-3-3z'/%3E%3Ccircle cx='100' cy='158' r='1' fill='%23c8c3ba'/%3E%3Cpath d='M127 157l4.5 4.5M131.5 161.5c.7.7.3 2-.6 3s-2.2 1.3-3 .6'/%3E%3Cpath d='M158 158c1.5-1.5 3.5-1.5 5 0M161 163c-1.5 1.5-3.5 1.5-5 0M158.5 162.5l4.5-4.5'/%3E%3Cpath d='M185 157h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Ccircle cx='215' cy='160' r='4'/%3E%3Cpath d='M213 158.5a1 1 0 0 1 2 0M217 158.5a1 1 0 0 1-2 0'/%3E%3Cpath d='M212.5 162c1.5 2 3.5 2 5 0'/%3E%3Crect x='238' y='157' width='5' height='8' rx='1'/%3E%3Ccircle cx='240.5' cy='163' r='.6' fill='%23c8c3ba'/%3E%3Cpath d='M12 190h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Cpath d='M42 187l1.5 3 3 .5-2 2 .5 3-3-1.5-3 1.5.5-3-2-2 3-.5z'/%3E%3Crect x='65' y='187' width='8' height='6' rx='1'/%3E%3Ccircle cx='69' cy='190' r='1.5'/%3E%3Cpath d='M67 187l1-2h2l1 2'/%3E%3Crect x='95' y='187' width='5' height='4.5' rx='.5'/%3E%3Cpath d='M96 187v-2c0-1.5 3-1.5 3 0v2'/%3E%3Cpath d='M130 185v8'/%3E%3Ccircle cx='129' cy='193' r='1.5'/%3E%3Cpath d='M130 185l3.5-1.5v2l-3.5 1.5'/%3E%3Cpath d='M155 191c0-2 2-3 3-1.5 1-1.5 3-.5 3 1.5s-3 4-3 4-3-2-3-4z'/%3E%3Ccircle cx='190' cy='191' r='4'/%3E%3Cellipse cx='190' cy='191' rx='2' ry='4'/%3E%3Cpath d='M186 191h8'/%3E%3Cpath d='M213 187h5c.3 0 .5.3.5.5v7l-3-2-3 2v-7c0-.2.2-.5.5-.5z'/%3E%3Crect x='238' y='187' width='6' height='6' rx='.5'/%3E%3Cpath d='M238 190h6M240 185v2M242 185v2'/%3E%3Cpath d='M12 220h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Ccircle cx='42' cy='223' r='3.5'/%3E%3Cpath d='M45 226l3 3'/%3E%3Crect x='65' y='218' width='4' height='6' rx='2'/%3E%3Cpath d='M63 223c0 2 2.5 3 4 3s4-1 4-3M67 227v2'/%3E%3Cpath d='M100 218c-3 0-5 3-5 3s2 3 5 3 5-3 5-3-2-3-5-3z'/%3E%3Ccircle cx='100' cy='221' r='1.2'/%3E%3Crect x='125' y='218' width='8' height='6' rx='1'/%3E%3Ccircle cx='128' cy='220.5' r='1'/%3E%3Cpath d='M125 223l2.5-2 2 1.5 1-1 2.5 1.5'/%3E%3Cpath d='M160 223c0-3 2-4.5 4-4.5s4 1.5 4 4.5'/%3E%3Crect x='160' y='222.5' width='2.5' height='3.5' rx='.5'/%3E%3Crect x='165.5' y='222.5' width='2.5' height='3.5' rx='.5'/%3E%3Cpath d='M188 220c1.5-1.5 3.5-1.5 5 0M191 225c-1.5 1.5-3.5 1.5-5 0M188.5 224.5l4.5-4.5'/%3E%3Cpath d='M215 218l-2 4.5h3l-2 4.5'/%3E%3Cpath d='M240 220l-5.5 3 2 1.5 3.5-4.5zM236 224.5l1 3 1.5-2'/%3E%3C/g%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 250px 250px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.whatsapp-messages-container::before {
  content: '';
  flex: 1 1 auto;
}

[data-theme="dark"] .whatsapp-messages-container {
  background-color: #0b141a;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cg fill='none' stroke='%23172a33' stroke-width='0.5' opacity='0.55'%3E%3Cpath d='M12 10h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Ccircle cx='42' cy='13' r='4'/%3E%3Cpath d='M42 10v3h2'/%3E%3Crect x='68' y='9' width='5' height='8' rx='1'/%3E%3Ccircle cx='70.5' cy='15' r='.6' fill='%23172a33'/%3E%3Ccircle cx='100' cy='13' r='4'/%3E%3Cpath d='M98 11.5a1 1 0 0 1 2 0M102 11.5a1 1 0 0 1-2 0'/%3E%3Cpath d='M97.5 14.5c1.5 2 3.5 2 5 0'/%3E%3Cpath d='M130 10l1.5 3 3 .5-2 2 .5 3-3-1.5-3 1.5.5-3-2-2 3-.5z'/%3E%3Crect x='155' y='10' width='8' height='6' rx='1'/%3E%3Ccircle cx='159' cy='13' r='1.5'/%3E%3Cpath d='M157 10l1-2h2l1 2'/%3E%3Crect x='185' y='10' width='5' height='4.5' rx='.5'/%3E%3Cpath d='M186 10v-2c0-1.5 3-1.5 3 0v2'/%3E%3Cpath d='M215 8v8'/%3E%3Ccircle cx='214' cy='16' r='1.5'/%3E%3Cpath d='M215 8l3.5-1.5v2l-3.5 1.5'/%3E%3Cpath d='M238 13c0-2 2-3 3-1.5 1-1.5 3-.5 3 1.5s-3 4-3 4-3-2-3-4z'/%3E%3Cpath d='M14 40h4.5c.8 0 1.2.5 1.2 1.2v2.5c0 .8-.4 1.2-1.2 1.2h-1.5l-1.5 1.5v-1.5H14c-.8 0-1.2-.4-1.2-1.2v-2.5c0-.7.4-1.2 1.2-1.2z'/%3E%3Ccircle cx='45' cy='43' r='3.5'/%3E%3Cpath d='M48 46l3 3'/%3E%3Cpath d='M70 38c-3 0-5 3-5 3s2 3 5 3 5-3 5-3-2-3-5-3z'/%3E%3Ccircle cx='70' cy='41' r='1.2'/%3E%3Crect x='95' y='38' width='8' height='6' rx='1'/%3E%3Ccircle cx='98' cy='40.5' r='1'/%3E%3Cpath d='M95 43l2.5-2 2 1.5 1-1 2.5 1.5'/%3E%3Cpath d='M130 43c0-3 2-4.5 4-4.5s4 1.5 4 4.5'/%3E%3Crect x='130' y='42.5' width='2.5' height='3.5' rx='.5'/%3E%3Crect x='135.5' y='42.5' width='2.5' height='3.5' rx='.5'/%3E%3Ccircle cx='162' cy='41' r='4'/%3E%3Cellipse cx='162' cy='41' rx='2' ry='4'/%3E%3Cpath d='M158 41h8'/%3E%3Cpath d='M185 38h5c.3 0 .5.3.5.5v7l-3-2-3 2v-7c0-.2.2-.5.5-.5z'/%3E%3Crect x='213' y='38' width='6' height='6' rx='.5'/%3E%3Cpath d='M213 41h6M215 36v2M217 36v2'/%3E%3Cpath d='M240 36l-2 4.5h3l-2 4.5'/%3E%3Crect x='10' y='68' width='4' height='6' rx='2'/%3E%3Cpath d='M8 73c0 2 2.5 3 4 3s4-1 4-3M12 77v2'/%3E%3Cpath d='M42 68l-5.5 3 2 1.5 3.5-4.5zM38 72.5l1 3 1.5-2'/%3E%3Crect x='65' y='67' width='6' height='8' rx='1'/%3E%3Cpath d='M67 70h2M67 72h2'/%3E%3Ccircle cx='100' cy='71' r='2.5'/%3E%3Cpath d='M103 71h4.5M106 71v2'/%3E%3Cpath d='M130 66a3 3 0 0 0-3 3c0 2.5 3 5 3 5s3-2.5 3-5a3 3 0 0 0-3-3z'/%3E%3Ccircle cx='130' cy='69' r='1' fill='%23172a33'/%3E%3Cpath d='M157 68l4.5 4.5M161.5 72.5c.7.7.3 2-.6 3s-2.2 1.3-3 .6'/%3E%3Cpath d='M188 69c1.5-1.5 3.5-1.5 5 0M191 74c-1.5 1.5-3.5 1.5-5 0M188.5 73.5l4.5-4.5'/%3E%3Cpath d='M215 68h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Ccircle cx='242' cy='71' r='4'/%3E%3Cpath d='M242 68v3h2'/%3E%3Cpath d='M12 100h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Crect x='38' y='97' width='5' height='8' rx='1'/%3E%3Ccircle cx='40.5' cy='103' r='.6' fill='%23172a33'/%3E%3Ccircle cx='70' cy='101' r='4'/%3E%3Cpath d='M68 99.5a1 1 0 0 1 2 0M72 99.5a1 1 0 0 1-2 0'/%3E%3Cpath d='M67.5 103c1.5 2 3.5 2 5 0'/%3E%3Cpath d='M100 97l1.5 3 3 .5-2 2 .5 3-3-1.5-3 1.5.5-3-2-2 3-.5z'/%3E%3Crect x='125' y='97' width='8' height='6' rx='1'/%3E%3Ccircle cx='129' cy='100' r='1.5'/%3E%3Cpath d='M127 97l1-2h2l1 2'/%3E%3Crect x='155' y='97' width='5' height='4.5' rx='.5'/%3E%3Cpath d='M156 97v-2c0-1.5 3-1.5 3 0v2'/%3E%3Cpath d='M185 95v8'/%3E%3Ccircle cx='184' cy='103' r='1.5'/%3E%3Cpath d='M185 95l3.5-1.5v2l-3.5 1.5'/%3E%3Cpath d='M210 101c0-2 2-3 3-1.5 1-1.5 3-.5 3 1.5s-3 4-3 4-3-2-3-4z'/%3E%3Ccircle cx='242' cy='101' r='3.5'/%3E%3Cpath d='M245 104l3 3'/%3E%3Cpath d='M14 130h4.5c.8 0 1.2.5 1.2 1.2v2.5c0 .8-.4 1.2-1.2 1.2h-1.5l-1.5 1.5v-1.5H14c-.8 0-1.2-.4-1.2-1.2v-2.5c0-.7.4-1.2 1.2-1.2z'/%3E%3Cpath d='M40 126c-3 0-5 3-5 3s2 3 5 3 5-3 5-3-2-3-5-3z'/%3E%3Ccircle cx='40' cy='129' r='1.2'/%3E%3Crect x='65' y='126' width='8' height='6' rx='1'/%3E%3Ccircle cx='68' cy='128.5' r='1'/%3E%3Cpath d='M65 131l2.5-2 2 1.5 1-1 2.5 1.5'/%3E%3Cpath d='M100 131c0-3 2-4.5 4-4.5s4 1.5 4 4.5'/%3E%3Crect x='100' y='130.5' width='2.5' height='3.5' rx='.5'/%3E%3Crect x='105.5' y='130.5' width='2.5' height='3.5' rx='.5'/%3E%3Ccircle cx='132' cy='129' r='4'/%3E%3Cellipse cx='132' cy='129' rx='2' ry='4'/%3E%3Cpath d='M128 129h8'/%3E%3Cpath d='M155 126h5c.3 0 .5.3.5.5v7l-3-2-3 2v-7c0-.2.2-.5.5-.5z'/%3E%3Crect x='183' y='126' width='6' height='6' rx='.5'/%3E%3Cpath d='M183 129h6M185 124v2M187 124v2'/%3E%3Cpath d='M215 124l-2 4.5h3l-2 4.5'/%3E%3Crect x='237' y='127' width='6' height='8' rx='1'/%3E%3Cpath d='M239 130h2M239 132h2'/%3E%3Crect x='10' y='157' width='4' height='6' rx='2'/%3E%3Cpath d='M8 162c0 2 2.5 3 4 3s4-1 4-3M12 166v2'/%3E%3Cpath d='M42 157l-5.5 3 2 1.5 3.5-4.5zM38 161.5l1 3 1.5-2'/%3E%3Ccircle cx='70' cy='160' r='2.5'/%3E%3Cpath d='M73 160h4.5M76 160v2'/%3E%3Cpath d='M100 155a3 3 0 0 0-3 3c0 2.5 3 5 3 5s3-2.5 3-5a3 3 0 0 0-3-3z'/%3E%3Ccircle cx='100' cy='158' r='1' fill='%23172a33'/%3E%3Cpath d='M127 157l4.5 4.5M131.5 161.5c.7.7.3 2-.6 3s-2.2 1.3-3 .6'/%3E%3Cpath d='M158 158c1.5-1.5 3.5-1.5 5 0M161 163c-1.5 1.5-3.5 1.5-5 0M158.5 162.5l4.5-4.5'/%3E%3Cpath d='M185 157h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Ccircle cx='215' cy='160' r='4'/%3E%3Cpath d='M213 158.5a1 1 0 0 1 2 0M217 158.5a1 1 0 0 1-2 0'/%3E%3Cpath d='M212.5 162c1.5 2 3.5 2 5 0'/%3E%3Crect x='238' y='157' width='5' height='8' rx='1'/%3E%3Ccircle cx='240.5' cy='163' r='.6' fill='%23172a33'/%3E%3Cpath d='M12 190h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Cpath d='M42 187l1.5 3 3 .5-2 2 .5 3-3-1.5-3 1.5.5-3-2-2 3-.5z'/%3E%3Crect x='65' y='187' width='8' height='6' rx='1'/%3E%3Ccircle cx='69' cy='190' r='1.5'/%3E%3Cpath d='M67 187l1-2h2l1 2'/%3E%3Crect x='95' y='187' width='5' height='4.5' rx='.5'/%3E%3Cpath d='M96 187v-2c0-1.5 3-1.5 3 0v2'/%3E%3Cpath d='M130 185v8'/%3E%3Ccircle cx='129' cy='193' r='1.5'/%3E%3Cpath d='M130 185l3.5-1.5v2l-3.5 1.5'/%3E%3Cpath d='M155 191c0-2 2-3 3-1.5 1-1.5 3-.5 3 1.5s-3 4-3 4-3-2-3-4z'/%3E%3Ccircle cx='190' cy='191' r='4'/%3E%3Cellipse cx='190' cy='191' rx='2' ry='4'/%3E%3Cpath d='M186 191h8'/%3E%3Cpath d='M213 187h5c.3 0 .5.3.5.5v7l-3-2-3 2v-7c0-.2.2-.5.5-.5z'/%3E%3Crect x='238' y='187' width='6' height='6' rx='.5'/%3E%3Cpath d='M238 190h6M240 185v2M242 185v2'/%3E%3Cpath d='M12 220h5c1 0 1.5.5 1.5 1.5v3c0 1-.5 1.5-1.5 1.5h-2l-1.5 2v-2h-1.5c-1 0-1.5-.5-1.5-1.5v-3c0-1 .5-1.5 1.5-1.5z'/%3E%3Ccircle cx='42' cy='223' r='3.5'/%3E%3Cpath d='M45 226l3 3'/%3E%3Crect x='65' y='218' width='4' height='6' rx='2'/%3E%3Cpath d='M63 223c0 2 2.5 3 4 3s4-1 4-3M67 227v2'/%3E%3Cpath d='M100 218c-3 0-5 3-5 3s2 3 5 3 5-3 5-3-2-3-5-3z'/%3E%3Ccircle cx='100' cy='221' r='1.2'/%3E%3Crect x='125' y='218' width='8' height='6' rx='1'/%3E%3Ccircle cx='128' cy='220.5' r='1'/%3E%3Cpath d='M125 223l2.5-2 2 1.5 1-1 2.5 1.5'/%3E%3Cpath d='M160 223c0-3 2-4.5 4-4.5s4 1.5 4 4.5'/%3E%3Crect x='160' y='222.5' width='2.5' height='3.5' rx='.5'/%3E%3Crect x='165.5' y='222.5' width='2.5' height='3.5' rx='.5'/%3E%3Cpath d='M188 220c1.5-1.5 3.5-1.5 5 0M191 225c-1.5 1.5-3.5 1.5-5 0M188.5 224.5l4.5-4.5'/%3E%3Cpath d='M215 218l-2 4.5h3l-2 4.5'/%3E%3Cpath d='M240 220l-5.5 3 2 1.5 3.5-4.5zM236 224.5l1 3 1.5-2'/%3E%3C/g%3E%3C/svg%3E");
}

/* ===================================
   SEZIONE 3: WHATSAPP INPUT & SEND
   =================================== */

/* ── Reply Preview Bar (above input) ── */
.wa-reply-preview-bar {
  display: flex;
  align-items: center;
  background: #f0f2f5;
  padding: 6px 10px 0 10px;
  gap: 0;
  position: sticky;
  bottom: 56px;
  z-index: 9998;
  width: 100%;
  box-sizing: border-box;
}
[data-theme="dark"] .wa-reply-preview-bar {
  background: #1f2c34;
}
.wa-reply-preview-content {
  flex: 1;
  display: flex;
  background: #fff;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
  min-height: 42px;
  max-height: 70px;
  cursor: pointer;
}
[data-theme="dark"] .wa-reply-preview-content {
  background: #1a2730;
}
.wa-reply-preview-accent {
  width: 4px;
  min-height: 100%;
  background: #00a884;
  border-radius: 4px 0 0 0;
  flex-shrink: 0;
}
.wa-reply-preview-body {
  flex: 1;
  padding: 6px 12px;
  overflow: hidden;
}
.wa-reply-preview-sender {
  font-size: 12.5px;
  font-weight: 600;
  color: #00a884;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-reply-preview-text {
  font-size: 12.5px;
  color: #667781;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}
[data-theme="dark"] .wa-reply-preview-text {
  color: #8696a0;
}
.wa-reply-preview-close {
  background: none;
  border: none;
  color: #8696a0;
  font-size: 18px;
  cursor: pointer;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
  flex-shrink: 0;
}
.wa-reply-preview-close:hover {
  color: #3b4a54;
}
[data-theme="dark"] .wa-reply-preview-close:hover {
  color: #e9edef;
}

.whatsapp-input-bar {
  background: #f0f2f5 !important;
  padding: 6px 10px !important;
  display: flex !important;
  align-items: flex-end !important;
  gap: 6px !important;
  border-top: none !important;
  box-shadow: none !important;
  flex-shrink: 0 !important;
  min-height: 58px !important;
  position: sticky !important;
  bottom: 0 !important;
  z-index: 9999 !important;
  width: 100% !important;
  margin: 0 !important;
  -webkit-font-smoothing: antialiased;
}

[data-theme="dark"] .whatsapp-input-bar {
  background: #1f2c34 !important;
  border-top-color: transparent;
  box-shadow: none !important;
}

.whatsapp-input-wrapper {
  flex: 1;
  background: #ffffff;
  border-radius: 10px;
  padding: 9px 14px;
  border: none;
  transition: background 0.15s ease;
  box-shadow: none;
  min-height: 40px;
  display: flex;
  align-items: center;
}

.whatsapp-input-wrapper:focus-within {
  border-color: transparent;
  box-shadow: none;
  background: #ffffff;
}

[data-theme="dark"] .whatsapp-input-wrapper {
  background: #2a3942;
  border-color: transparent;
  box-shadow: none;
}

[data-theme="dark"] .whatsapp-input-wrapper:focus-within {
  border-color: transparent;
  box-shadow: none;
  background: #2a3942;
}

.whatsapp-input-wrapper input,
.whatsapp-input-wrapper textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: #111b21;
  font-size: 14px;
  outline: none;
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
}

.whatsapp-input-wrapper textarea {
  resize: none;
  display: block;
  min-height: 20px;
  max-height: 120px;
  overflow-y: auto;
  padding: 0;
  margin: 0;
  vertical-align: middle;
}

[data-theme="dark"] .whatsapp-input-wrapper input,
[data-theme="dark"] .whatsapp-input-wrapper textarea {
  color: #e9edef;
}

.whatsapp-input-wrapper input::placeholder,
.whatsapp-input-wrapper textarea::placeholder {
  color: #8696a0;
  font-weight: 400;
}

.wa-edited-label {
  font-size: 0.68rem;
  color: #8696a0;
  margin-left: 4px;
  font-style: italic;
  white-space: nowrap;
}
.wa-edited-label i {
  font-size: 0.58rem;
  margin-right: 2px;
}
[data-theme="dark"] .wa-edited-label {
  color: #8696a0;
}

.whatsapp-send-btn {
  width: 36px !important;
  height: 36px !important;
  border-radius: 50% !important;
  border: none !important;
  background: transparent !important;
  color: #54656f !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: color 0.15s ease !important;
  box-shadow: none !important;
  flex-shrink: 0 !important;
  font-size: 18px !important;
  margin-bottom: 0 !important;
}

.whatsapp-send-btn:hover {
  color: #00a884 !important;
  background: transparent !important;
  box-shadow: none;
}

.whatsapp-send-btn:active {
  transform: scale(0.94);
}

.whatsapp-send-btn i {
  transition: transform 0.2s ease;
}

.whatsapp-send-btn:hover .fa-paper-plane {
  transform: translateX(1px) rotate(-5deg);
}

[data-theme="dark"] .whatsapp-send-btn {
  color: #8696a0 !important;
}

[data-theme="dark"] .whatsapp-send-btn:hover {
  color: #00a884 !important;
  background: rgba(0,168,132,0.08) !important;
}

/* Responsive WhatsApp */
@media (max-width: 1200px) {
  .whatsapp-sidebar {
    width: 380px;
  }
}

@media (max-width: 1024px) {
  .whatsapp-sidebar {
    width: 340px;
  }

  .wa-chat-navbar {
    width: 52px;
  }

  .wa-chat-nav-btn {
    width: 42px;
    height: 42px;
  }

  .whatsapp-messages-container {
    padding: 20px 5%;
  }
}

@media (max-width: 768px) {
  .wa-chat-navbar {
    display: none;
  }

  .whatsapp-sidebar {
    width: 100%;
    position: absolute;
    z-index: 10;
    transition: transform 0.3s ease;
    transform: translateX(0);
  }

  .whatsapp-sidebar.hidden {
    display: none;
  }

  .whatsapp-sidebar.slide-out {
    transform: translateX(-100%);
    pointer-events: none;
  }
  
  .whatsapp-messages-container {
    padding: 20px 10px;
  }
}

@media (max-width: 480px) {
  /* Chat sidebar full width */
  .whatsapp-sidebar {
    width: 100%;
  }

  /* Message bubbles wider */
  .wa-message-bubble,
  .message-bubble,
  .whatsapp-message-bubble {
    max-width: 90% !important;
  }

  /* Input bar compact */
  .whatsapp-input-bar,
  .wa-input-area {
    padding: 6px 8px !important;
    gap: 6px !important;
  }

  /* Message text smaller */
  .whatsapp-messages-container {
    padding: 12px 6px;
  }

  /* Attachment/emoji buttons smaller */
  .wa-input-btn,
  .message-action-btn {
    width: 34px !important;
    height: 34px !important;
    font-size: 1rem !important;
  }

  /* Chat header compact */
  .whatsapp-chat-header {
    padding: 8px 10px !important;
    min-height: 52px !important;
  }

  .whatsapp-chat-header .chat-name {
    font-size: 14px !important;
  }

  .whatsapp-chat-header .chat-status {
    font-size: 11px !important;
  }
}

/* ===================================
   SEZIONE 4: motore WhatsApp COMPONENTS
   =================================== */

:root {
  --wsp-green: #25d366;
  --wsp-green-dark: #1fa555;
  --wsp-green-light: #e8f5e9;
  --wsp-gray: #f0f0f0;
  --wsp-gray-dark: #8a8a8a;
}

/* Empty State */
.wsp-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
}

.wsp-empty-icon {
  font-size: 4rem;
  color: var(--wsp-green);
  margin-bottom: 1.5rem;
  opacity: 0.8;
}

.wsp-empty-icon i {
  display: block;
}

.wsp-empty-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #111;
  margin: 0 0 0.5rem 0;
}

.wsp-empty-desc {
  color: #999;
  margin: 0 0 2rem 0;
  font-size: 0.95rem;
}

/* Session Cards */
.wsp-session-card {
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  transition: all 0.2s ease;
}

.wsp-session-card:hover {
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.1);
  border-color: var(--wsp-green);
}

.wsp-session-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
  gap: 1rem;
}

.wsp-session-info h3 {
  margin: 0 0 0.5rem 0;
  color: #111;
  font-size: 1rem;
}

.wsp-session-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.wsp-session-status.status-working {
  background: var(--wsp-green-light);
  color: var(--wsp-green-dark);
}

.wsp-session-status.status-scan_qr_code {
  background: #fff3cd;
  color: #856404;
}

.wsp-session-status.status-starting {
  background: #cfe2ff;
  color: #084298;
}

.wsp-session-status.status-failed {
  background: #f8d7da;
  color: #842029;
}

.wsp-session-status.status-stopped {
  background: #e2e3e5;
  color: #383d41;
}

.wsp-session-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: none;
  background: var(--wsp-gray);
  color: #666;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: #ddd;
}

.btn-icon.btn-wsp {
  background: var(--wsp-green-light);
  color: var(--wsp-green-dark);
}

.btn-icon.btn-wsp:hover {
  background: var(--wsp-green);
  color: white;
}

.btn-wsp {
  background: var(--wsp-green);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-wsp:hover {
  background: var(--wsp-green-dark);
  transform: translateY(-2px);
}

.wsp-session-details {
  padding-top: 1rem;
  border-top: 1px solid #f0f0f0;
}

.wsp-detail-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  font-size: 0.9rem;
}

.wsp-detail-label {
  color: #666;
  font-weight: 500;
}

.wsp-detail-value {
  color: #111;
}

/* Modal Overlay */
.wsp-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.wsp-modal {
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 450px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: wsp-modal-slide-in 0.3s ease;
}

@keyframes wsp-modal-slide-in {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.wsp-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid #f0f0f0;
}

.wsp-modal-header h2 {
  margin: 0;
  color: #111;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.wsp-modal-header h2 i {
  color: var(--wsp-green);
}

.wsp-modal-close {
  background: none;
  border: none;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.wsp-modal-close:hover {
  background: var(--wsp-gray);
  color: #111;
}

.wsp-form {
  padding: 1.5rem;
}

.wsp-form-group {
  margin-bottom: 1.5rem;
}

.wsp-form-label {
  display: block;
  margin-bottom: 0.5rem;
  color: #111;
  font-weight: 500;
  font-size: 0.95rem;
}

.wsp-form-input {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.95rem;
  transition: all 0.2s ease;
  font-family: inherit;
}

.wsp-form-input:focus {
  outline: none;
  border-color: var(--wsp-green);
  box-shadow: 0 0 0 3px var(--wsp-green-light);
}

.wsp-form-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
}

.wsp-form-actions .btn {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.wsp-form-actions .btn-secondary {
  background: var(--wsp-gray);
  color: #111;
}

.wsp-form-actions .btn-secondary:hover {
  background: #ddd;
}

/* QR Code Modal */
.wsp-qr-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  backdrop-filter: blur(4px);
}

.wsp-qr-modal {
  background: white;
  border-radius: 16px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.35);
  animation: wsp-modal-slide-in 0.3s ease;
  overflow: hidden;
}

.wsp-qr-modal.wsp-modal-fade-out {
  animation: wsp-modal-fade-out 0.3s ease forwards;
}

@keyframes wsp-modal-fade-out {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

.wsp-qr-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, var(--wsp-green) 0%, var(--wsp-green-dark) 100%);
  color: white;
}

.wsp-qr-header h2 {
  margin: 0;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.wsp-qr-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.wsp-qr-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.wsp-qr-content {
  padding: 2rem;
}

.wsp-qr-container {
  display: flex;
  justify-content: center;
  margin-bottom: 2rem;
}

.wsp-qr-image {
  padding: 1rem;
  background: white;
  border: 2px solid var(--wsp-green);
  border-radius: 12px;
}

.wsp-qr-img {
  max-width: 300px;
  height: auto;
  display: block;
}

.wsp-qr-loading {
  text-align: center;
  padding: 3rem 1rem;
}

.wsp-spinner {
  width: 50px;
  height: 50px;
  margin: 0 auto 1rem;
  border: 4px solid var(--wsp-gray);
  border-top-color: var(--wsp-green);
  border-radius: 50%;
  animation: wsp-spin 1s linear infinite;
}

@keyframes wsp-spin {
  to {
    transform: rotate(360deg);
  }
}

.wsp-qr-loading p {
  color: #666;
  font-weight: 500;
}

.wsp-qr-instructions {
  background: var(--wsp-green-light);
  padding: 1.5rem;
  border-radius: 12px;
  border-left: 4px solid var(--wsp-green);
}

.wsp-qr-instructions p {
  margin: 0 0 1rem 0;
  color: #111;
  font-weight: 600;
  font-size: 0.95rem;
}

.wsp-qr-instructions ol {
  margin: 0;
  padding-left: 1.5rem;
  color: #333;
}

.wsp-qr-instructions li {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.wsp-qr-instructions strong {
  color: var(--wsp-green-dark);
}

/* ===================================
   SEZIONE 5: WHATSAPP QR MODAL
   =================================== */

.modal-overlay.whatsapp-qr-overlay {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
}

/* Modal WhatsApp QR */
.modal.whatsapp-qr-modal {
  background: linear-gradient(135deg, #ffffff 0%, #f5f5f5 100%);
  border: none;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(16, 185, 129, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
  max-width: 580px;
  overflow: hidden;
}

/* Modal Header WhatsApp */
.modal-header.whatsapp-qr-header {
  background: linear-gradient(135deg, #128C7E 0%, #25D366 100%);
  color: white;
  padding: 24px 28px;
  border-bottom: none;
  box-shadow: 0 4px 12px rgba(18, 140, 126, 0.2);
}

.modal-header.whatsapp-qr-header .modal-title {
  color: white;
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-header.whatsapp-qr-header .modal-title i {
  font-size: 22px;
}

.modal-close.whatsapp-qr-close {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
  transition: all 0.3s ease;
}

.modal-close.whatsapp-qr-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

/* Modal Body WhatsApp */
.modal-body.whatsapp-qr-body {
  padding: 28px;
  background: #ffffff;
}

/* Status Bar */
.whatsapp-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
  border-radius: 12px;
  margin-bottom: 24px;
  border: 1px solid #bbf7d0;
}

.whatsapp-status-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.whatsapp-status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  animation: pulse-green 2s ease-in-out infinite;
}

.whatsapp-status-dot.connected {
  background: #10b981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.whatsapp-status-dot.disconnected {
  background: #9ca3af;
  animation: none;
}

.whatsapp-status-dot.scanning {
  background: #f59e0b;
  animation: pulse-amber 2s ease-in-out infinite;
}

@keyframes pulse-green {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
  }
  50% {
    opacity: 0.7;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.8);
  }
}

@keyframes pulse-amber {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
  }
  50% {
    opacity: 0.7;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.8);
  }
}

.whatsapp-status-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.whatsapp-status-label {
  font-size: 11px;
  font-weight: 700;
  color: #10b981;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.whatsapp-status-value {
  font-size: 15px;
  font-weight: 700;
  color: #1f2937;
}

.whatsapp-status-refresh {
  padding: 8px 14px;
  background: white;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  color: #10b981;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.whatsapp-status-refresh:hover {
  background: #f0fdf4;
  transform: rotate(-180deg);
}

/* QR Code Section */
.whatsapp-qr-section {
  background: white;
  padding: 24px;
  border-radius: 12px;
  text-align: center;
  border: 2px dashed #e5e7eb;
  margin-bottom: 24px;
  transition: all 0.3s ease;
}

.whatsapp-qr-section.hidden {
  display: none;
}

.whatsapp-qr-container {
  margin: 0 auto;
  display: inline-block;
  position: relative;
}

.whatsapp-qr-image {
  width: 260px;
  height: 260px;
  display: block;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(18, 140, 126, 0.15);
  transition: all 0.3s ease;
}

.whatsapp-qr-image:hover {
  transform: scale(1.02);
  box-shadow: 0 12px 32px rgba(18, 140, 126, 0.25);
}

.whatsapp-qr-loading,
.whatsapp-qr-error {
  width: 260px;
  height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
  border-radius: 12px;
  border: 2px solid #bbf7d0;
}

.whatsapp-qr-error {
  background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
  border-color: #fca5a5;
}

.whatsapp-qr-loading i,
.whatsapp-qr-error i {
  font-size: 32px;
  margin-bottom: 12px;
}

.whatsapp-qr-loading i {
  color: #10b981;
}

.whatsapp-qr-error i {
  color: #ef4444;
}

.whatsapp-qr-loading p,
.whatsapp-qr-error p {
  margin: 0;
  color: #6b7280;
  font-size: 13px;
  text-align: center;
}

/* Instructions Box */
.whatsapp-instructions {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  padding: 14px 16px;
  border-radius: 10px;
  border-left: 4px solid #3b82f6;
  margin-top: 16px;
  text-align: left;
}

.whatsapp-instructions-title {
  font-size: 13px;
  color: #1e40af;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.whatsapp-instructions-content {
  font-size: 12px;
  color: #1e40af;
  line-height: 1.6;
  padding-left: 20px;
}

/* Account Info Card */
.whatsapp-account-info {
  display: none;
  padding: 16px 20px;
  background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
  border-radius: 12px;
  margin-bottom: 24px;
  border: 1.5px solid #6ee7b7;
  animation: slideIn 0.4s ease;
}

.whatsapp-account-info.visible {
  display: flex;
  align-items: center;
  gap: 14px;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.whatsapp-account-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 24px;
  color: white;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.whatsapp-account-details {
  flex: 1;
}

.whatsapp-account-name {
  font-weight: 700;
  font-size: 15px;
  color: #065f46;
  margin: 0;
}

.whatsapp-account-phone {
  font-size: 13px;
  color: #10b981;
  margin: 4px 0 0 0;
}

.whatsapp-account-check {
  font-size: 22px;
  color: #10b981;
}

/* Buttons Grid */
.whatsapp-buttons-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 24px;
}

.whatsapp-btn {
  padding: 14px 16px;
  font-weight: 700;
  border-radius: 10px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

/* Primary Green Button */
.whatsapp-btn.primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.whatsapp-btn.primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4);
}

.whatsapp-btn.primary:active:not(:disabled) {
  transform: translateY(0);
}

/* Secondary Blue Button */
.whatsapp-btn.secondary {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.whatsapp-btn.secondary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(14, 165, 233, 0.4);
}

.whatsapp-btn.secondary:active:not(:disabled) {
  transform: translateY(0);
}

/* Outline Button */
.whatsapp-btn.outline {
  background: white;
  border: 1.5px solid #e5e7eb;
  color: #6b7280;
  transition: all 0.3s ease;
}

.whatsapp-btn.outline:hover:not(:disabled) {
  border-color: #10b981;
  color: #10b981;
  background: #f0fdf4;
}

/* Danger Button */
.whatsapp-btn.danger {
  background: white;
  border: 1.5px solid #fecaca;
  color: #ef4444;
  transition: all 0.3s ease;
}

.whatsapp-btn.danger:hover:not(:disabled) {
  background: #fef2f2;
  border-color: #ef4444;
}

/* Disabled State */
.whatsapp-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loading State */
.whatsapp-btn.loading {
  pointer-events: none;
}

.whatsapp-btn.loading i {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Modal Footer */
.modal-footer.whatsapp-qr-footer {
  padding: 16px 28px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.whatsapp-footer-security {
  font-size: 12px;
  color: #9ca3af;
  display: flex;
  align-items: center;
  gap: 6px;
}

.whatsapp-footer-security i {
  color: #10b981;
}

/* Close Button */
.whatsapp-btn.close {
  background: white;
  border: 1.5px solid #e7e7e7;
  color: #666;
  cursor: pointer;
  border-radius: 6px;
  padding: 8px 12px;
  transition: all 0.2s ease;
}

.whatsapp-btn.close:hover {
  background: #f0f2f5;
  color: #111;
}

.whatsapp-btn.close:active {
  transform: scale(0.95);
}

/* ===================================
   FINE STILI
   =================================== */

/* ===================================
   NUOVE FUNZIONALIT\u00c0 WHATSAPP
   =================================== */

/* Messaggi eliminati */
.message-deleted {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(134, 150, 160, 0.08);
  border-radius: 8px;
  color: #667781;
  font-size: 13px;
  font-style: italic;
}

[data-theme="dark"] .message-deleted {
  background: rgba(134, 150, 160, 0.15);
  color: #8696a0;
}

.message-deleted i {
  opacity: 0.6;
  font-size: 14px;
}

/* Indicatori tipo media migliorati */
.media-type-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  color: #8696a0;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.media-type-indicator i {
  font-size: 11px;
  color: #00a884;
}

/* Stili contenuti media migliorati */
.message-media-image,
.message-media-video,
.message-media-audio,
.message-media-document {
  position: relative;
  margin-bottom: 8px;
}

.message-media-image img {
  max-width: 100%;
  max-height: 400px;
  border-radius: 8px;
  display: block;
  cursor: pointer;
  transition: opacity 0.2s;
}

.message-media-image img:hover {
  opacity: 0.95;
}

/* Facebook-style image loading skeleton (shimmer + spinner) */
.message-media-image.media-loading {
  min-width: 160px;
  min-height: 160px;
  border-radius: 8px;
  overflow: hidden;
  background: #e9edef;
}
.message-media-image.media-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: linear-gradient(90deg, #e4e9ec 25%, #f3f6f8 50%, #e4e9ec 75%);
  background-size: 400% 100%;
  animation: media-img-shimmer 1.4s ease-in-out infinite;
  z-index: 1;
  pointer-events: none;
}
.message-media-image.media-loading::before {
  content: "\f110"; /* fa-spinner */
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #8696a0;
  font-size: 20px;
  z-index: 2;
  animation: media-img-spin 0.8s linear infinite;
  pointer-events: none;
}
.message-media-image.media-loading img {
  opacity: 0;
}
.message-media-image.media-loading .media-type-indicator,
.message-media-image.media-loading .media-actions {
  opacity: 0;
}
.message-media-image img {
  transition: opacity 0.35s ease;
}
@keyframes media-img-shimmer {
  0%   { background-position: 400% 0; }
  100% { background-position: -400% 0; }
}
@keyframes media-img-spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}
[data-theme="dark"] .message-media-image.media-loading {
  background: #1e2d36;
}
[data-theme="dark"] .message-media-image.media-loading::after {
  background: linear-gradient(90deg, #1e2d36 25%, #2c4050 50%, #1e2d36 75%);
  background-size: 400% 100%;
}

.message-media-video video {
  max-width: 100%;
  max-height: 360px;
  border-radius: 6px;
  display: block;
  background: #0b141a;
}

/* Voice note styling — styling delegated to child .whatsapp-audio-player */
.message-media-audio.voice-note {
  background: transparent;
  padding: 0;
  border: none;
}

/* WhatsApp-style audio player */
.whatsapp-audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: transparent;
  border-radius: 8px;
  min-width: 280px;
}

[data-theme="dark"] .whatsapp-audio-player {
  background: transparent;
}

.audio-play-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #00a884;
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
  box-shadow: none;
}

.whatsapp-message.sent .audio-play-btn {
  background: #017561;
}

[data-theme="dark"] .audio-play-btn {
  background: #00a884;
}

.audio-play-btn:hover {
  transform: scale(1.06);
}

.audio-play-btn i {
  font-size: 13px;
  margin-left: 2px;
}

.audio-play-btn .fa-pause {
  margin-left: 0;
}

.audio-waveform {
  flex: 1;
  height: 28px;
  position: relative;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.audio-progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
  border-radius: 4px;
  overflow: hidden;
}

[data-theme="dark"] .audio-progress-bar {
  background: transparent;
}

.audio-progress-fill {
  height: 100%;
  background: rgba(0, 168, 132, 0.15);
  width: 0%;
  transition: width 0.1s linear;
}

.audio-waveform-bars {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1.5px;
  height: 100%;
  padding: 0 2px;
  z-index: 1;
  pointer-events: none;
}

.audio-waveform-bars .bar {
  width: 2.5px;
  background: #8696a0;
  border-radius: 1.5px;
  min-height: 3px;
  opacity: 0.45;
  transition: opacity 0.15s;
}

.whatsapp-message.sent .audio-waveform-bars .bar {
  background: #6b9080;
  opacity: 0.55;
}

[data-theme="dark"] .audio-waveform-bars .bar {
  background: #8696a0;
  opacity: 0.4;
}

.audio-duration {
  font-size: 11px;
  color: #667781;
  font-weight: 400;
  min-width: 36px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

[data-theme="dark"] .audio-duration {
  color: #8696a0;
}

/* Hide default audio element */
.whatsapp-audio-player audio {
  display: none;
}

.audio-player-container audio {
  width: 100%;
  height: 36px;
  outline: none;
}

/* PDF e documenti */
.message-media-document.pdf-document {
  background: rgba(231, 76, 60, 0.04);
  border-left: 3px solid #e74c3c;
  padding: 10px 12px;
  border-radius: 8px;
  transition: background 0.15s;
}

.message-media-document.pdf-document:hover {
  background: rgba(231, 76, 60, 0.06);
}

[data-theme="dark"] .message-media-document.pdf-document {
  background: rgba(231, 76, 60, 0.08);
}

[data-theme="dark"] .message-media-document.pdf-document:hover {
  background: rgba(231, 76, 60, 0.12);
}

.document-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.document-details {
  flex: 1;
  min-width: 0;
}

.document-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.document-size {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Azioni media (download, preview) */
.media-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  justify-content: flex-end;
}

.media-download-btn,
.media-preview-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.04);
  color: #8696a0;
  text-decoration: none;
  transition: all 0.15s ease;
  font-size: 11px;
  cursor: pointer;
  border: none;
}

.media-download-btn:hover,
.media-preview-btn:hover {
  background: rgba(0, 168, 132, 0.1);
  color: #00a884;
  transform: scale(1.05);
}

[data-theme="dark"] .media-download-btn,
[data-theme="dark"] .media-preview-btn {
  background: rgba(255, 255, 255, 0.06);
  color: #8696a0;
}

[data-theme="dark"] .media-download-btn:hover,
[data-theme="dark"] .media-preview-btn:hover {
  background: rgba(0, 168, 132, 0.15);
  color: #00a884;
}

/* Note indicator in chat flow */
.note-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #f59e0b;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.note-indicator i {
  font-size: 13px;
}

.note-bubble {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%) !important;
  border-left: 3px solid #f59e0b !important;
  color: #78350f !important;
}

[data-theme="dark"] .note-bubble {
  background: linear-gradient(135deg, #451a03 0%, #78350f 100%) !important;
  color: #fef3c7 !important;
}

/* Chat list unread indicators */
.chat-list-item.unread {
  background: #f0fdf4;
  border-left: 3px solid #25d366;
}

[data-theme="dark"] .chat-list-item.unread {
  background: rgba(37, 211, 102, 0.08);
}

.chat-list-item.unread:hover {
  background: #dcfce7;
}

[data-theme="dark"] .chat-list-item.unread:hover {
  background: rgba(37, 211, 102, 0.15);
}

.chat-list-item-avatar.unread-avatar {
  border: 2px solid #25d366;
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.2);
}

.chat-list-name.unread-name {
  font-weight: 700;
  color: #111b21;
}

[data-theme="dark"] .chat-list-name.unread-name {
  color: #e9edef;
}

.chat-list-time.unread-time {
  color: #25d366;
  font-weight: 600;
}

.chat-list-item-preview.unread-preview {
  font-weight: 600;
  color: #111b21;
}

[data-theme="dark"] .chat-list-item-preview.unread-preview {
  color: #e9edef;
}

/* Context menu */
.context-menu {
  animation: contextMenuFadeIn 0.15s ease;
}

@keyframes contextMenuFadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

[data-theme="dark"] .context-menu-item {
  color: #e9edef;
}

/* Media viewer modal enhancements */
.media-viewer-overlay {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.media-viewer-modal {
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===================================
   CONTACT INFO PANEL (right side)
   =================================== */

.wa-contact-info-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 100%;
  background: #f7f8fa;
  border-left: 1px solid #e9edef;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10020;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.wa-contact-info-panel.open {
  width: 340px;
}

[data-theme="dark"] .wa-contact-info-panel {
  background: #0b141a;
  border-left-color: rgba(42, 57, 66, 0.5);
}

.wa-cip-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  background: #fff;
  color: #111b21;
  min-height: 56px;
  box-sizing: border-box;
  border-bottom: 1px solid #e9edef;
}

[data-theme="dark"] .wa-cip-header {
  background: #1f2c34;
  color: #e9edef;
  border-bottom-color: rgba(233,237,239,0.08);
}

.wa-cip-close {
  background: none;
  border: none;
  color: #54656f;
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
}

.wa-cip-close:hover {
  background: rgba(11, 20, 26, 0.06);
  color: #111b21;
}

[data-theme="dark"] .wa-cip-close {
  color: #aebac1;
}

[data-theme="dark"] .wa-cip-close:hover {
  background: rgba(255,255,255,0.06);
  color: #e9edef;
}

.wa-cip-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.wa-cip-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding-bottom: 92px;
  scrollbar-width: thin;
  scrollbar-color: rgba(134,150,160,0.3) transparent;
}

.wa-cip-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  flex-shrink: 0;
  background: #f7f8fa;
  border-top: 1px solid rgba(233,237,239,0.8);
  padding: 8px 0;
  z-index: 10021;
}

[data-theme="dark"] .wa-cip-footer {
  background: #0b141a;
  border-top-color: rgba(233,237,239,0.08);
}

.wa-cip-body::-webkit-scrollbar {
  width: 4px;
}

.wa-cip-body::-webkit-scrollbar-thumb {
  background: rgba(134,150,160,0.3);
  border-radius: 10px;
}

.wa-cip-body::-webkit-scrollbar-track {
  background: transparent;
}

.wa-cip-avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 20px 24px;
  background: white;
}

[data-theme="dark"] .wa-cip-avatar-section {
  background: #111b21;
}

.wa-cip-avatar {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e8ebe4 0%, #dfe5e7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 18px;
  box-shadow: 0 2px 12px rgba(11, 20, 26, 0.08);
  transition: transform 0.2s ease;
}

.wa-cip-avatar:hover {
  transform: scale(1.02);
}

[data-theme="dark"] .wa-cip-avatar {
  background: linear-gradient(135deg, #1a252c 0%, #182229 100%);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.wa-cip-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.wa-cip-name {
  font-size: 18px;
  font-weight: 600;
  color: #111b21;
  text-align: center;
  margin-bottom: 2px;
  word-break: break-word;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

[data-theme="dark"] .wa-cip-name {
  color: #e9edef;
}

.wa-cip-phone {
  font-size: 13px;
  color: #667781;
  text-align: center;
  letter-spacing: 0.02em;
}

[data-theme="dark"] .wa-cip-phone {
  color: #8696a0;
}

.wa-cip-section {
  background: white;
  padding: 14px 20px;
  margin-top: 8px;
  border-top: 1px solid rgba(233,237,239,0.5);
  border-bottom: 1px solid rgba(233,237,239,0.5);
}

[data-theme="dark"] .wa-cip-section {
  background: #111b21;
  border-top-color: rgba(233,237,239,0.06);
  border-bottom-color: rgba(233,237,239,0.06);
}

.wa-cip-section-label {
  font-size: 12px;
  color: #00a884;
  font-weight: 500;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

[data-theme="dark"] .wa-cip-section-label {
  color: #00a884;
}

.wa-cip-about {
  font-size: 14px;
  color: #111b21;
  line-height: 1.5;
}

[data-theme="dark"] .wa-cip-about {
  color: #e9edef;
}

.wa-cip-detail {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: #111b21;
  padding: 6px 0;
  transition: background 0.12s;
  border-radius: 6px;
  margin: -2px -6px;
  padding-left: 6px;
  padding-right: 6px;
}

.wa-cip-detail:hover {
  background: rgba(11, 20, 26, 0.03);
}

[data-theme="dark"] .wa-cip-detail {
  color: #e9edef;
}

[data-theme="dark"] .wa-cip-detail:hover {
  background: rgba(255, 255, 255, 0.04);
}

.wa-cip-detail i {
  width: 20px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}

.wa-cip-detail span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-cip-danger {
  margin-top: 0;
  position: static;
  background: #fff;
  border-top-color: rgba(234,67,53,0.08);
}

[data-theme="dark"] .wa-cip-danger {
  background: #111b21;
}

.wa-cip-delete-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 6px;
  margin: -2px -6px;
  background: none;
  border: none;
  color: #e74c3c;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-radius: 6px;
  font-weight: 500;
}

.wa-cip-delete-btn:hover {
  background: rgba(231, 76, 60, 0.06);
  color: #c0392b;
}

[data-theme="dark"] .wa-cip-delete-btn:hover {
  background: rgba(231, 76, 60, 0.1);
  color: #ff6b6b;
}

.wa-cip-delete-btn i {
  font-size: 15px;
  width: 20px;
  text-align: center;
}

/* Responsive: su schermi piccoli il pannello copre tutto */
@media (max-width: 768px) {
  .wa-contact-info-panel.open {
    width: 100%;
  }
}

/* ---- Participants list items ---- */
#wa-cip-participants-list {
  max-height: min(38vh, 320px);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(134,150,160,0.3) transparent;
}
.wa-cip-participant {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(233,237,239,0.7);
  transition: background 0.12s;
  border-radius: 6px;
  margin: 0 -4px;
  padding-left: 4px;
  padding-right: 4px;
}

.wa-cip-participant:last-child {
  border-bottom: none;
}

.wa-cip-participant:hover {
  background: rgba(11, 20, 26, 0.03);
}

[data-theme="dark"] .wa-cip-participant {
  border-bottom-color: rgba(42,57,66,0.6);
}

[data-theme="dark"] .wa-cip-participant:hover {
  background: rgba(255,255,255,0.04);
}

.wa-cip-participant-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  overflow: hidden;
}

.wa-cip-participant-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.wa-cip-participant-info {
  flex: 1;
  min-width: 0;
}

.wa-cip-participant-name {
  font-size: 14px;
  font-weight: 500;
  color: #111b21;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

[data-theme="dark"] .wa-cip-participant-name {
  color: #e9edef;
}

.wa-cip-participant-phone {
  font-size: 12px;
  color: #8696a0;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-cip-participant-badge {
  font-size: 10px;
  color: #00a884;
  font-weight: 600;
  padding: 2px 7px;
  border: 1px solid #00a884;
  border-radius: 10px;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.wa-cip-participants-empty {
  color: #8696a0;
  font-size: 13px;
  padding: 8px 0;
  text-align: center;
}

.wa-cip-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8696a0;
  font-size: 13px;
  padding: 8px 0;
}

/* Avatar initials in info panel header */
.wa-cip-avatar-initials {
  font-weight: 700;
  font-size: 36px;
  color: #fff;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

/* ===================================
   CHAT MESSAGE SEARCH BAR
   =================================== */

.wa-chat-search-bar {
  background: #f0f2f5;
  border-bottom: 1px solid #e9edef;
  padding: 6px 12px;
  flex-shrink: 0;
  z-index: 10;
}

[data-theme="dark"] .wa-chat-search-bar {
  background: #202c33;
  border-bottom-color: #2a3942;
}

.wa-chat-search-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border-radius: 8px;
  padding: 4px 10px;
  border: 1px solid #e9edef;
}

[data-theme="dark"] .wa-chat-search-inner {
  background: #2a3942;
  border-color: #3b4a54;
}

.wa-chat-search-icon {
  color: #8696a0;
  font-size: 13px;
  flex-shrink: 0;
}

.wa-chat-search-inner input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  color: #111b21;
  padding: 6px 0;
}

[data-theme="dark"] .wa-chat-search-inner input {
  color: #e9edef;
}

.wa-chat-search-inner input::placeholder {
  color: #8696a0;
}

.wa-chat-search-count {
  font-size: 12px;
  color: #8696a0;
  white-space: nowrap;
  min-width: 40px;
  text-align: center;
}

.wa-chat-search-nav,
.wa-chat-search-close {
  background: none;
  border: none;
  color: #8696a0;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13px;
  transition: color 0.15s, background 0.15s;
}

.wa-chat-search-nav:hover,
.wa-chat-search-close:hover {
  color: #00a884;
  background: rgba(0,168,132,0.08);
}

[data-theme="dark"] .wa-chat-search-nav:hover,
[data-theme="dark"] .wa-chat-search-close:hover {
  background: rgba(0,168,132,0.15);
}

/* Search highlights */
.wa-search-highlight {
  background: rgba(255, 220, 0, 0.4);
  border-radius: 2px;
  padding: 0 1px;
}

.wa-search-highlight.active {
  background: rgba(255, 165, 0, 0.7);
  box-shadow: 0 0 0 2px rgba(255,165,0,0.3);
}

[data-theme="dark"] .wa-search-highlight {
  background: rgba(255, 220, 0, 0.25);
}

[data-theme="dark"] .wa-search-highlight.active {
  background: rgba(255, 165, 0, 0.5);
}

/* ===================================
   EMOJI PICKER
   =================================== */

.wa-emoji-picker {
  position: absolute;
  bottom: 50px;
  left: 0;
  width: 340px;
  height: 420px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  z-index: 10000;
  overflow: hidden;
  border: 1px solid #e0e0e0;
}

[data-theme="dark"] .wa-emoji-picker {
  background: #233138;
  border-color: #374950;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

.wa-emoji-search-wrap {
  padding: 8px 10px;
  border-bottom: 1px solid #e9edef;
  flex-shrink: 0;
}

[data-theme="dark"] .wa-emoji-search-wrap {
  border-bottom-color: #374950;
}

.wa-emoji-search {
  width: 100%;
  border: none;
  background: #f0f2f5;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: #111b21;
  outline: none;
  box-sizing: border-box;
}

.wa-emoji-search::placeholder {
  color: #8696a0;
}

[data-theme="dark"] .wa-emoji-search {
  background: #2a3942;
  color: #e9edef;
}

.wa-emoji-tabs {
  display: flex;
  border-bottom: 1px solid #e9edef;
  padding: 0 4px;
  flex-shrink: 0;
  overflow-x: auto;
  gap: 0;
}

[data-theme="dark"] .wa-emoji-tabs {
  border-bottom-color: #374950;
}

.wa-emoji-tab {
  flex: 1;
  min-width: 32px;
  padding: 6px 2px;
  font-size: 18px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  opacity: 0.5;
}

.wa-emoji-tab:hover {
  opacity: 0.8;
  background: rgba(0,0,0,0.04);
}

[data-theme="dark"] .wa-emoji-tab:hover {
  background: rgba(255,255,255,0.06);
}

.wa-emoji-tab.active {
  opacity: 1;
  border-bottom-color: #00a884;
}

.wa-emoji-grid {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 2px;
}

.wa-emoji-grid::-webkit-scrollbar {
  width: 6px;
}

.wa-emoji-grid::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 3px;
}

[data-theme="dark"] .wa-emoji-grid::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
}

.wa-emoji-item {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.12s, transform 0.12s;
  user-select: none;
}

.wa-emoji-item:hover {
  background: rgba(0,0,0,0.06);
  transform: scale(1.15);
}

[data-theme="dark"] .wa-emoji-item:hover {
  background: rgba(255,255,255,0.1);
}

/* ===================================
   IMAGE PREVIEW MODAL
   =================================== */

.wa-image-preview-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wa-image-preview-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
}

.wa-image-preview-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 90vw;
  max-height: 90vh;
  gap: 16px;
}

.wa-image-preview-close {
  position: absolute;
  top: -40px;
  right: -8px;
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 24px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s;
}

.wa-image-preview-close:hover {
  background: rgba(255,255,255,0.15);
}

.wa-image-preview-img {
  max-width: 70vw;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.wa-image-preview-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 500px;
}

.wa-image-preview-add-btn {
  width: 38px;
  height: 38px;
  background: #2a3942;
  border: none;
  border-radius: 50%;
  color: #8696a0;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.wa-image-preview-add-btn:hover {
  background: #374b56;
  color: #e9edef;
}

.wa-image-preview-caption {
  flex: 1;
  background: #2a3942;
  border: none;
  border-radius: 21px;
  padding: 10px 16px;
  color: #e9edef;
  font-size: 14px;
  outline: none;
}

.wa-image-preview-caption::placeholder {
  color: #8696a0;
}

.wa-image-preview-send {
  width: 46px !important;
  height: 46px !important;
  background: #00a884 !important;
  color: #fff !important;
  border-radius: 50% !important;
  border: none !important;
  font-size: 18px !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-shrink: 0 !important;
  transition: background 0.15s !important;
}

.wa-image-preview-send:hover {
  background: #00c49a !important;
}

/* Thumbnail strip for multi-file preview */
.wa-image-preview-strip {
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: center;
  justify-content: center;
  max-width: 70vw;
  overflow-x: auto;
  padding: 4px 0;
}
.wa-image-preview-thumb {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
  cursor: pointer;
  border: 2px solid transparent;
  opacity: 0.65;
  transition: opacity 0.15s, border-color 0.15s;
  flex-shrink: 0;
  background: #2a3942;
}
.wa-image-preview-thumb.active {
  border-color: #00a884;
  opacity: 1;
}
.wa-image-preview-thumb-video {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  opacity: 0.65;
  transition: opacity 0.15s, border-color 0.15s;
  flex-shrink: 0;
  background: #1b262c;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e9edef;
  font-size: 22px;
}
.wa-image-preview-thumb-video.active {
  border-color: #00a884;
  opacity: 1;
}

/* Wrapper per ogni thumb con pulsante X */
.wa-thumb-wrapper {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}
.wa-thumb-remove {
  position: absolute;
  top: -5px;
  right: -5px;
  z-index: 10;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: 1.5px solid rgba(255,255,255,0.5);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.wa-thumb-wrapper:hover .wa-thumb-remove {
  opacity: 1;
}
.wa-thumb-remove:hover {
  background: #e53e3e;
  border-color: #e53e3e;
}

/* ===================================
   FINE NUOVE FUNZIONALITÀ
   =================================== */

/* ===================================
   CONTEXT MENU
   =================================== */
@keyframes ctxMenuIn {
  from { opacity: 0; transform: scale(0.92) translateY(-4px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

.context-menu-item:hover {
  background: #f0f2f5;
}

[data-theme="dark"] .context-menu-item:hover {
  background: #202c33;
}

/* ===================================
   NEW CHAT DIALOG
   =================================== */
.wa-new-chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .15s ease-out;
}

.wa-new-chat-dialog {
  background: var(--bg-primary, #fff);
  border-radius: 14px;
  width: 400px;
  max-width: 92vw;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  animation: ctxMenuIn .18s ease-out;
  overflow: hidden;
}

.wa-new-chat-dialog .dialog-header {
  background: #00a884;
  color: #fff;
  padding: 18px 20px;
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.wa-new-chat-dialog .dialog-header i {
  font-size: 20px;
}

.wa-new-chat-dialog .dialog-body {
  padding: 20px;
}

.wa-new-chat-dialog .dialog-body label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary, #667781);
  margin-bottom: 6px;
  font-weight: 500;
}

.wa-new-chat-dialog .dialog-body input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border-color, #e0e0e0);
  border-radius: 8px;
  font-size: 15px;
  background: var(--bg-secondary, #f0f2f5);
  color: var(--text-primary, #111b21);
  outline: none;
  transition: border-color .2s;
  box-sizing: border-box;
}

.wa-new-chat-dialog .dialog-body input:focus {
  border-color: #00a884;
}

.wa-new-chat-dialog .dialog-body .hint {
  font-size: 12px;
  color: var(--text-secondary, #8696a0);
  margin-top: 6px;
}

.wa-new-chat-dialog .dialog-footer {
  padding: 12px 20px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.wa-new-chat-dialog .dialog-footer button {
  padding: 8px 20px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.wa-new-chat-dialog .btn-cancel {
  background: var(--bg-secondary, #f0f2f5);
  color: var(--text-primary, #111b21);
}

.wa-new-chat-dialog .btn-cancel:hover {
  background: var(--border-color, #e0e0e0);
}

.wa-new-chat-dialog .btn-start {
  background: #00a884;
  color: #fff;
}

.wa-new-chat-dialog .btn-start:hover {
  background: #00c49a;
}

.wa-new-chat-dialog .btn-start:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ===================================
   SELECTION MODE
   =================================== */
.selection-mode .chat-list-item {
  display: flex;
  align-items: center;
}

.selection-mode .chat-list-item.selected {
  background: rgba(0, 168, 132, 0.08);
}

[data-theme="dark"] .selection-mode .chat-list-item.selected {
  background: rgba(0, 168, 132, 0.12);
}

/* ===================================
   SHAKE ANIMATION (PIN LOCK)
   =================================== */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ==============================
   Compose Dialog (New Conversation)
   ============================== */
.wa-compose-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.18s ease;
}

.wa-compose-dialog {
  background: #ffffff;
  border-radius: 18px;
  width: 560px;
  max-width: 96vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 60px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.04);
  animation: composeSlideUp 0.25s cubic-bezier(0.34,1.56,0.64,1);
  overflow: hidden;
}

[data-theme="dark"] .wa-compose-dialog {
  background: #1a2332;
  box-shadow: 0 25px 70px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.06);
}

@keyframes composeSlideUp {
  from { transform: translateY(24px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0) scale(1);       opacity: 1; }
}

/* --- Header --- */
.compose-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  background: linear-gradient(135deg, #00a884 0%, #00c49a 100%);
  position: relative;
  overflow: hidden;
}
.compose-header::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  pointer-events: none;
}

[data-theme="dark"] .compose-header {
  background: linear-gradient(135deg, #0d503f 0%, #0a6b52 100%);
}

.compose-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  color: #ffffff;
  letter-spacing: 0.2px;
  z-index: 1;
}

[data-theme="dark"] .compose-header-left {
  color: #e2e8f0;
}

.compose-header-left .fab {
  color: rgba(255,255,255,0.9);
  font-size: 22px;
}

[data-theme="dark"] .compose-header-left .fab {
  color: #5eead4;
}

.compose-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  transition: all 0.15s;
  z-index: 1;
  line-height: 1;
}
.compose-close:hover {
  background: rgba(255,255,255,0.25);
  color: #ffffff;
}

[data-theme="dark"] .compose-close {
  background: rgba(255,255,255,0.08);
  color: #94a3b8;
}
[data-theme="dark"] .compose-close:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

/* --- Body --- */
.compose-body {
  padding: 20px 22px 12px;
  overflow-y: auto;
  flex: 1;
  position: relative;
}

/* Addressbook overlay panel: floats above body content */
/* .compose-addressbook-panel: stile UNICO piu' sotto ("Address book panel", card
   in-flow come i pannelli template/programmazione). Qui c'era una versione overlay
   (absolute inset:0) di una vecchia iterazione: fusa con la card produceva un
   pannello assoluto che copriva il body del compose con overflow:hidden. */

.compose-field {
  margin-bottom: 18px;
}

.compose-field > label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  color: #667781;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

[data-theme="dark"] .compose-field > label {
  color: #7e8fa0;
}

.compose-field > label i {
  font-size: 11px;
  color: #00a884;
}

/* --- Recipients wrapper --- */
.compose-recipients-wrapper {
  background: #f4f6f8;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 6px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  transition: all 0.2s ease;
  min-height: 44px;
}

[data-theme="dark"] .compose-recipients-wrapper {
  background: rgba(255,255,255,0.04);
  border-color: transparent;
}

.compose-recipients-wrapper:focus-within {
  border-color: #00a884;
  background: rgba(0,168,132,0.03);
  box-shadow: 0 0 0 3px rgba(0,168,132,0.08);
}
[data-theme="dark"] .compose-recipients-wrapper:focus-within {
  background: rgba(0,168,132,0.06);
  box-shadow: 0 0 0 3px rgba(0,168,132,0.12);
}

#compose-contact-search {
  background: none;
  border: none;
  color: #111b21;
  font-size: 14px;
  padding: 6px 4px;
  outline: none;
  flex: 1;
  min-width: 120px;
}

[data-theme="dark"] #compose-contact-search {
  color: #e2e8f0;
}

#compose-contact-search::placeholder {
  color: #8696a0;
  font-size: 13px;
}

[data-theme="dark"] #compose-contact-search::placeholder {
  color: #475569;
}

/* --- Chips --- */
.compose-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 8px;
  background: linear-gradient(135deg, rgba(0,168,132,0.1), rgba(0,168,132,0.06));
  border: 1px solid rgba(0,168,132,0.2);
  border-radius: 20px;
  font-size: 13px;
  color: #00805e;
  animation: chipPop 0.2s cubic-bezier(0.34,1.56,0.64,1);
  backdrop-filter: blur(4px);
}

@keyframes chipPop {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

[data-theme="dark"] .compose-chip {
  background: rgba(0,168,132,0.15);
  border-color: rgba(0,168,132,0.25);
  color: #5eead4;
}

/* destinatario gia' presente (o in procinto di essere tolto col Backspace): si fa notare */
.compose-chip-gia {
  animation: chipGia 1.1s ease;
  border-color: #f59e0b !important;
}

@keyframes chipGia {
  0%, 100% { background: linear-gradient(135deg, rgba(0,168,132,0.1), rgba(0,168,132,0.06)); }
  25%, 75% { background: rgba(245,158,11,0.28); }
}

.chip-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #00a884;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.chip-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.chip-remove {
  cursor: pointer;
  font-size: 10px;
  color: #8696a0;
  transition: all 0.15s;
  padding: 2px;
  border-radius: 50%;
}

.chip-remove:hover {
  color: #ef4444;
  background: rgba(239,68,68,0.1);
}

/* --- Contacts dropdown --- */
.compose-contacts-dropdown {
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 12px;
  max-height: 260px;
  overflow-y: auto;
  margin-top: 6px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.03);
}

[data-theme="dark"] .compose-contacts-dropdown {
  background: #1a2332;
  border-color: rgba(255,255,255,0.06);
  box-shadow: 0 10px 32px rgba(0,0,0,0.4);
}

.compose-contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.12s ease;
  border-bottom: 1px solid rgba(0,0,0,0.03);
  position: relative;
}

[data-theme="dark"] .compose-contact-item {
  border-bottom-color: rgba(255,255,255,0.03);
}

.compose-contact-item:last-child {
  border-bottom: none;
}

.compose-contact-item:hover {
  background: rgba(0,168,132,0.04);
}
.compose-contact-item:active {
  background: rgba(0,168,132,0.08);
}

[data-theme="dark"] .compose-contact-item:hover {
  background: rgba(255,255,255,0.04);
}

.compose-contact-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

.compose-contact-info {
  flex: 1;
  min-width: 0;
}

.compose-contact-name {
  font-size: 14px;
  font-weight: 600;
  color: #111b21;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="dark"] .compose-contact-name {
  color: #e2e8f0;
}

.compose-contact-detail {
  font-size: 12px;
  color: #8696a0;
  margin-top: 1px;
}

[data-theme="dark"] .compose-contact-detail {
  color: #64748b;
}

.compose-no-results {
  padding: 20px 16px;
  text-align: center;
  color: #8696a0;
  font-size: 13px;
  line-height: 1.5;
}
[data-theme="dark"] .compose-no-results {
  color: #64748b;
}

/* --- Message toolbar --- */
.compose-msg-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.compose-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: #f4f6f8;
  border: 1px solid transparent;
  border-radius: 20px;
  color: #667781;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

[data-theme="dark"] .compose-tool-btn {
  background: rgba(255,255,255,0.05);
  color: #94a3b8;
}

.compose-tool-btn:hover {
  background: rgba(0,168,132,0.08);
  border-color: rgba(0,168,132,0.2);
  color: #00a884;
}

[data-theme="dark"] .compose-tool-btn:hover {
  background: rgba(0,168,132,0.12);
  border-color: rgba(0,168,132,0.25);
  color: #5eead4;
}

.compose-tool-btn i {
  font-size: 12px;
}

/* Address book btn inline */
.compose-ab-btn {
  margin-top: 8px;
}

/* --- Spam warning --- */
/* .compose-spam-warning: stile UNICO piu' avanti (versione gradient ambra).
   La copia che stava qui era interamente sovrascritta proprieta' per proprieta'. */

/* --- Textarea --- */
#compose-message {
  width: 100%;
  background: #f4f6f8;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 14px 16px;
  color: #111b21;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 110px;
  outline: none;
  transition: all 0.2s ease;
  box-sizing: border-box;
  line-height: 1.5;
}

[data-theme="dark"] #compose-message {
  background: rgba(255,255,255,0.04);
  color: #e2e8f0;
}

#compose-message:focus {
  border-color: #00a884;
  background: rgba(0,168,132,0.03);
  box-shadow: 0 0 0 3px rgba(0,168,132,0.08);
}
[data-theme="dark"] #compose-message:focus {
  background: rgba(0,168,132,0.06);
  box-shadow: 0 0 0 3px rgba(0,168,132,0.12);
}

#compose-message::placeholder {
  color: #8696a0;
}

[data-theme="dark"] #compose-message::placeholder {
  color: #475569;
}

/* --- Template panel --- */
.compose-template-panel {
  background: #f8fffe;
  border: 1px solid rgba(0,168,132,0.12);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  animation: fadeIn 0.15s ease;
}

[data-theme="dark"] .compose-template-panel {
  background: rgba(0,168,132,0.04);
  border-color: rgba(0,168,132,0.12);
}

.compose-template-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  color: #4a5568;
  font-size: 13px;
  font-weight: 700;
}

[data-theme="dark"] .compose-template-header {
  color: #94a3b8;
}

.compose-template-header > span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.compose-template-header > span i {
  color: #00a884;
}

.compose-template-new {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  background: #00a884;
  border: none;
  border-radius: 20px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 2px 8px rgba(0,168,132,0.25);
}

[data-theme="dark"] .compose-template-new {
  background: #0d9b6e;
  box-shadow: 0 2px 8px rgba(0,168,132,0.2);
}

.compose-template-new:hover {
  background: #00c49a;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,168,132,0.3);
}

.compose-template-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.compose-template-item {
  padding: 12px 14px;
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 10px;
  transition: all 0.12s;
  cursor: default;
}

[data-theme="dark"] .compose-template-item {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.06);
}

.compose-template-item:hover {
  border-color: rgba(0,168,132,0.2);
  box-shadow: 0 2px 8px rgba(0,168,132,0.06);
}

[data-theme="dark"] .compose-template-item:hover {
  border-color: rgba(0,168,132,0.25);
  background: rgba(255,255,255,0.06);
}

.compose-template-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.template-name {
  font-size: 13px;
  font-weight: 700;
  color: #111b21;
}

[data-theme="dark"] .template-name {
  color: #e2e8f0;
}

.template-category {
  font-size: 10px;
  color: #fff;
  background: #00a884;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
[data-theme="dark"] .template-category {
  background: rgba(0,168,132,0.6);
}

.compose-template-body {
  font-size: 12px;
  color: #667781;
  line-height: 1.5;
  margin-bottom: 8px;
  padding: 6px 8px;
  background: rgba(0,0,0,0.02);
  border-radius: 6px;
  border-left: 3px solid rgba(0,168,132,0.3);
}

[data-theme="dark"] .compose-template-body {
  color: #94a3b8;
  background: rgba(255,255,255,0.02);
  border-left-color: rgba(0,168,132,0.4);
}

.compose-template-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.compose-template-actions button {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.template-use {
  background: #00a884;
  color: #fff;
}
.template-use:hover {
  background: #00c49a;
}
[data-theme="dark"] .template-use {
  background: #0d9b6e;
  color: #fff;
}
[data-theme="dark"] .template-use:hover {
  background: #11b584;
}

.template-delete {
  background: rgba(239,68,68,0.08);
  color: #ef4444;
}
.template-delete:hover {
  background: rgba(239,68,68,0.16);
}
[data-theme="dark"] .template-delete {
  background: rgba(239,68,68,0.12);
}
[data-theme="dark"] .template-delete:hover {
  background: rgba(239,68,68,0.25);
}

/* --- Email template variant (purple scheme) --- */
.email-template-variant {
  background: #faf5ff;
  border-color: rgba(124,58,237,0.12);
}
[data-theme="dark"] .email-template-variant {
  background: rgba(124,58,237,0.04);
  border-color: rgba(124,58,237,0.12);
}
.email-template-variant .compose-template-header > span i {
  color: #7c3aed;
}
.email-template-variant .compose-template-new {
  background: #7c3aed;
  box-shadow: 0 2px 8px rgba(124,58,237,0.25);
}
[data-theme="dark"] .email-template-variant .compose-template-new {
  background: #6d28d9;
  box-shadow: 0 2px 8px rgba(124,58,237,0.2);
}
.email-template-variant .compose-template-new:hover {
  background: #8b5cf6;
  box-shadow: 0 4px 12px rgba(124,58,237,0.3);
}
.email-template-variant .compose-template-item:hover {
  border-color: rgba(124,58,237,0.2);
  box-shadow: 0 2px 8px rgba(124,58,237,0.06);
}
[data-theme="dark"] .email-template-variant .compose-template-item:hover {
  border-color: rgba(124,58,237,0.25);
}
.email-template-variant .compose-template-body {
  border-left-color: rgba(124,58,237,0.3);
}
[data-theme="dark"] .email-template-variant .compose-template-body {
  border-left-color: rgba(124,58,237,0.4);
}
.email-template-variant .template-use {
  background: #7c3aed;
}
.email-template-variant .template-use:hover {
  background: #8b5cf6;
}
[data-theme="dark"] .email-template-variant .template-use {
  background: #6d28d9;
}
[data-theme="dark"] .email-template-variant .template-use:hover {
  background: #7c3aed;
}

/* --- Template popup overlay (centered modal) --- */
.template-popup-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
[data-theme="dark"] .template-popup-overlay {
  background: rgba(0,0,0,0.65);
}
.template-popup-dialog {
  background: #fff;
  border-radius: 16px;
  width: 460px;
  max-width: 92vw;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
  overflow: hidden;
  animation: scaleIn 0.18s ease;
}
[data-theme="dark"] .template-popup-dialog {
  background: #1e293b;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
@keyframes scaleIn {
  from { transform: scale(0.92); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.template-popup-dialog .compose-template-panel {
  border: none;
  border-radius: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.template-popup-dialog .compose-template-header {
  padding: 16px 20px;
  margin: 0;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: 14px;
}
[data-theme="dark"] .template-popup-dialog .compose-template-header {
  border-bottom-color: rgba(255,255,255,0.08);
}
.template-popup-dialog .compose-template-list {
  padding: 12px 16px;
  max-height: none;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.template-popup-close {
  background: none;
  border: none;
  font-size: 18px;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s;
  line-height: 1;
}
.template-popup-close:hover {
  background: rgba(0,0,0,0.06);
  color: #374151;
}
[data-theme="dark"] .template-popup-close:hover {
  background: rgba(255,255,255,0.08);
  color: #e2e8f0;
}

/* --- Schedule panel --- */
.compose-schedule-panel {
  background: #f0f4ff;
  border: 1px solid rgba(59,130,246,0.15);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  animation: fadeIn 0.15s ease;
}

[data-theme="dark"] .compose-schedule-panel {
  background: rgba(59,130,246,0.06);
  border-color: rgba(59,130,246,0.15);
}

.compose-schedule-panel label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 700;
  color: #3b82f6;
  margin-bottom: 10px;
}

.compose-schedule-panel label i {
  color: #3b82f6;
}

#compose-schedule-datetime {
  width: 100%;
  background: #ffffff;
  border: 2px solid rgba(59,130,246,0.2);
  border-radius: 10px;
  padding: 11px 14px;
  color: #111b21;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
  transition: all 0.2s;
}

[data-theme="dark"] #compose-schedule-datetime {
  background: rgba(255,255,255,0.04);
  border-color: rgba(59,130,246,0.25);
  color: #e2e8f0;
}

#compose-schedule-datetime:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.compose-schedule-clear {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  padding: 6px 12px;
  background: rgba(239,68,68,0.06);
  border: 1px solid rgba(239,68,68,0.15);
  border-radius: 20px;
  color: #ef4444;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

[data-theme="dark"] .compose-schedule-clear {
  background: rgba(239,68,68,0.08);
  border-color: rgba(239,68,68,0.18);
  color: #f87171;
}

.compose-schedule-clear:hover {
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.25);
}

/* --- Footer --- */
.compose-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-top: 1px solid rgba(0,0,0,0.06);
  background: #f8faf9;
}

[data-theme="dark"] .compose-footer {
  border-top-color: rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.15);
}

.compose-footer-info {
  font-size: 12px;
  color: #8696a0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.compose-footer-info i {
  color: #3b82f6;
}

.compose-footer-actions {
  display: flex;
  gap: 10px;
}

.compose-footer .btn-cancel {
  padding: 9px 20px;
  background: transparent;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  color: #667781;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

[data-theme="dark"] .compose-footer .btn-cancel {
  background: transparent;
  border-color: rgba(255,255,255,0.1);
  color: #94a3b8;
}

.compose-footer .btn-cancel:hover {
  background: #f0f2f5;
  border-color: #b5bec5;
  color: #111b21;
}

[data-theme="dark"] .compose-footer .btn-cancel:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.15);
  color: #fff;
}

.compose-footer .btn-send {
  padding: 9px 24px;
  background: linear-gradient(135deg, #00a884, #00c49a);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
  display: flex;
  align-items: center;
  gap: 7px;
  box-shadow: 0 3px 12px rgba(0,168,132,0.3);
  letter-spacing: 0.2px;
}

.compose-footer .btn-send:hover:not(:disabled) {
  background: linear-gradient(135deg, #00c49a, #00dab0);
  transform: translateY(-1px);
  box-shadow: 0 5px 18px rgba(0,168,132,0.35);
}

.compose-footer .btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.compose-footer .btn-send.scheduled {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 3px 12px rgba(59,130,246,0.3);
}

.compose-footer .btn-send.scheduled:hover:not(:disabled) {
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
  box-shadow: 0 5px 18px rgba(59,130,246,0.35);
}

.compose-loading {
  padding: 24px;
  text-align: center;
  color: #8696a0;
  font-size: 13px;
}
.compose-loading i {
  color: #00a884;
  margin-right: 6px;
}

/* --- Template create overlay --- */
.wa-template-create-overlay {
  position: fixed;
  inset: 0;
  z-index: 21000;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.12s ease;
}

.wa-template-create-dialog {
  background: #ffffff;
  border-radius: 16px;
  width: 440px;
  max-width: 94vw;
  box-shadow: 0 20px 50px rgba(0,0,0,0.18);
  overflow: hidden;
}

[data-theme="dark"] .wa-template-create-dialog {
  background: #1a2332;
  box-shadow: 0 20px 55px rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.06);
}

.wa-template-create-dialog .dialog-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, #00a884 0%, #00c49a 100%);
  font-weight: 700;
  font-size: 14px;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}

[data-theme="dark"] .wa-template-create-dialog .dialog-header {
  background: linear-gradient(135deg, #0d503f 0%, #0a6b52 100%);
  color: #e2e8f0;
}

.wa-template-create-dialog .dialog-header i {
  color: rgba(255,255,255,0.85);
}
[data-theme="dark"] .wa-template-create-dialog .dialog-header i {
  color: #5eead4;
}

.wa-template-create-dialog .dialog-body {
  padding: 18px 20px;
}

.wa-template-create-dialog label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #667781;
  margin-bottom: 6px;
  margin-top: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

[data-theme="dark"] .wa-template-create-dialog label {
  color: #7e8fa0;
}

.wa-template-create-dialog label:first-child {
  margin-top: 0;
}

.wa-template-create-dialog input,
.wa-template-create-dialog select,
.wa-template-create-dialog textarea {
  width: 100%;
  background: #f4f6f8;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  color: #111b21;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
  transition: all 0.2s;
}

[data-theme="dark"] .wa-template-create-dialog input,
[data-theme="dark"] .wa-template-create-dialog select,
[data-theme="dark"] .wa-template-create-dialog textarea {
  background: rgba(255,255,255,0.04);
  color: #e2e8f0;
}

.wa-template-create-dialog input:focus,
.wa-template-create-dialog select:focus,
.wa-template-create-dialog textarea:focus {
  border-color: #00a884;
  background: rgba(0,168,132,0.03);
  box-shadow: 0 0 0 3px rgba(0,168,132,0.06);
}

.wa-template-create-dialog .hint {
  font-size: 11px;
  color: #8696a0;
  margin-top: 4px;
  line-height: 1.4;
}

[data-theme="dark"] .wa-template-create-dialog .hint {
  color: #64748b;
}

.wa-template-create-dialog .dialog-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(0,0,0,0.06);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8faf9;
}

[data-theme="dark"] .wa-template-create-dialog .dialog-footer {
  border-top-color: rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.15);
}

/* Template dialog buttons */
.wa-template-create-dialog .btn-cancel,
.wa-template-create-dialog .btn-start {
  padding: 9px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.wa-template-create-dialog .btn-cancel {
  background: transparent;
  border: 1px solid #d1d5db;
  color: #667781;
}
.wa-template-create-dialog .btn-cancel:hover {
  background: #f0f2f5;
  color: #111b21;
}
[data-theme="dark"] .wa-template-create-dialog .btn-cancel {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  color: #94a3b8;
}
[data-theme="dark"] .wa-template-create-dialog .btn-cancel:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}

.wa-template-create-dialog .btn-start {
  background: linear-gradient(135deg, #00a884, #00c49a);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,168,132,0.25);
}
.wa-template-create-dialog .btn-start:hover {
  background: linear-gradient(135deg, #00c49a, #00dab0);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,168,132,0.3);
}

/* ==============================
   Compose Address Book Picker
   ============================== */

/* Spam warning banner */
.compose-spam-warning {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  margin-top: 10px;
  border-radius: 10px;
  background: linear-gradient(135deg, #fef3c7, #fde68a30);
  border: 1px solid rgba(245,158,11,0.35);
  color: #92400e;
  font-size: 12px;
  line-height: 1.5;
  animation: fadeIn 0.2s ease;
}
.compose-spam-warning i {
  color: #f59e0b;
  font-size: 18px;
  margin-top: 1px;
  flex-shrink: 0;
}
.compose-spam-warning strong {
  color: #b45309;
  font-weight: 700;
}
[data-theme="dark"] .compose-spam-warning {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.3);
  color: #fcd34d;
}
[data-theme="dark"] .compose-spam-warning strong {
  color: #fbbf24;
}

/* Address book panel */
.compose-addressbook-panel {
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 14px;
  margin-top: 10px;
  overflow: hidden;
  animation: fadeIn 0.15s ease;
  box-shadow: 0 6px 20px rgba(0,0,0,0.06);
}
[data-theme="dark"] .compose-addressbook-panel {
  background: #141e2b;
  border-color: rgba(255,255,255,0.06);
  box-shadow: 0 6px 22px rgba(0,0,0,0.3);
}

.compose-ab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(0,168,132,0.04);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  font-size: 13px;
  font-weight: 700;
  color: #111b21;
}
[data-theme="dark"] .compose-ab-header {
  border-bottom-color: rgba(255,255,255,0.06);
  color: #e2e8f0;
  background: rgba(0,168,132,0.06);
}
.compose-ab-header > span {
  display: flex;
  align-items: center;
  gap: 6px;
}
.compose-ab-header i {
  color: #00a884;
}
.compose-ab-close {
  background: none;
  border: none;
  color: #8696a0;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.compose-ab-close:hover {
  background: rgba(0,0,0,0.06);
  color: #111b21;
}
[data-theme="dark"] .compose-ab-close {
  color: #94a3b8;
}
[data-theme="dark"] .compose-ab-close:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

/* Tabs */
.compose-ab-tabs {
  display: flex;
  padding: 0 12px;
  background: rgba(0,0,0,0.01);
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
[data-theme="dark"] .compose-ab-tabs {
  border-bottom-color: rgba(255,255,255,0.06);
  background: transparent;
}
.compose-ab-tab {
  flex: 1;
  padding: 10px 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 12px;
  font-weight: 700;
  color: #8696a0;
  cursor: pointer;
  transition: all 0.18s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.compose-ab-tab:hover {
  color: #00a884;
  background: rgba(0,168,132,0.03);
}
.compose-ab-tab.active {
  color: #00a884;
  border-bottom-color: #00a884;
}
[data-theme="dark"] .compose-ab-tab {
  color: #64748b;
}
[data-theme="dark"] .compose-ab-tab:hover,
[data-theme="dark"] .compose-ab-tab.active {
  color: #5eead4;
  border-bottom-color: #5eead4;
}

/* Search */
.compose-ab-search {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(0,0,0,0.04);
}
[data-theme="dark"] .compose-ab-search {
  border-bottom-color: rgba(255,255,255,0.04);
}
.compose-ab-search input {
  width: 100%;
  background: #f4f6f8;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 9px 14px 9px 36px;
  font-size: 13px;
  color: #111b21;
  outline: none;
  box-sizing: border-box;
  transition: all 0.2s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%238696a0' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.656a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 14px;
  background-position: 12px center;
}
.compose-ab-search input:focus {
  border-color: #00a884;
  background-color: rgba(0,168,132,0.03);
}
.compose-ab-search input::placeholder {
  color: #8696a0;
}
[data-theme="dark"] .compose-ab-search input {
  background-color: rgba(255,255,255,0.04);
  border-color: transparent;
  color: #e2e8f0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23475569' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.656a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
}
[data-theme="dark"] .compose-ab-search input:focus {
  background-color: rgba(0,168,132,0.06);
}
[data-theme="dark"] .compose-ab-search input::placeholder {
  color: #475569;
}

/* Contacts list */
#compose-ab-contacts {
  max-height: 240px;
  overflow-y: auto;
}

/* Group */
.compose-ab-group {
  margin-bottom: 0;
}
.compose-ab-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(0,168,132,0.03);
  border-bottom: 1px solid rgba(0,0,0,0.04);
  cursor: default;
}
[data-theme="dark"] .compose-ab-group-header {
  background: rgba(0,168,132,0.04);
  border-bottom-color: rgba(255,255,255,0.04);
}

.compose-ab-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex: 1;
}
.compose-ab-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #00a884;
  cursor: pointer;
  flex-shrink: 0;
}

.compose-ab-group-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #4a5568;
}
[data-theme="dark"] .compose-ab-group-name {
  color: #94a3b8;
}
.compose-ab-group-name i {
  color: #00a884;
  font-size: 13px;
}
.compose-ab-group-count {
  background: rgba(0,168,132,0.1);
  color: #00a884;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  margin-left: 6px;
}
[data-theme="dark"] .compose-ab-group-count {
  background: rgba(0,168,132,0.15);
  color: #5eead4;
}

/* Items inside group */
.compose-ab-items {
  padding: 0;
}

/* Individual item */
.compose-ab-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px 9px 40px;
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid rgba(0,0,0,0.025);
}
[data-theme="dark"] .compose-ab-item {
  border-bottom-color: rgba(255,255,255,0.025);
}
.compose-ab-item:last-child {
  border-bottom: none;
}
.compose-ab-item:hover {
  background: rgba(0,168,132,0.03);
}
[data-theme="dark"] .compose-ab-item:hover {
  background: rgba(0,168,132,0.05);
}

.compose-ab-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: #00a884;
  cursor: pointer;
  flex-shrink: 0;
}

.compose-ab-item-info {
  flex: 1;
  min-width: 0;
}
.compose-ab-item-name {
  font-size: 13px;
  font-weight: 600;
  color: #111b21;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
[data-theme="dark"] .compose-ab-item-name {
  color: #e2e8f0;
}
.compose-ab-item-phone {
  font-size: 11px;
  color: #8696a0;
  margin-top: 1px;
}
[data-theme="dark"] .compose-ab-item-phone {
  color: #64748b;
}

/* Footer */
.compose-ab-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid rgba(0,0,0,0.06);
  background: #f8faf9;
}
[data-theme="dark"] .compose-ab-footer {
  border-top-color: rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.15);
}

.compose-ab-confirm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  background: linear-gradient(135deg, #00a884, #00c49a);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 2px 8px rgba(0,168,132,0.25);
}
.compose-ab-confirm:hover {
  background: linear-gradient(135deg, #00c49a, #00dab0);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,168,132,0.3);
}

/* Responsive */
@media (max-width: 600px) {
  .wa-compose-dialog {
    width: 100%;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
  }
  .compose-header { border-radius: 0; }
  .compose-footer { border-radius: 0; }
}

/* Disabled address book items (no phone number) */
.compose-ab-item-disabled {
  opacity: 0.5;
  cursor: not-allowed !important;
  pointer-events: none;
}
.compose-ab-item-disabled .compose-contact-avatar {
  filter: grayscale(1);
}
.compose-ab-no-phone {
  color: #ef4444 !important;
  font-size: 10px !important;
  display: flex;
  align-items: center;
  gap: 4px;
}
.compose-ab-no-phone i {
  font-size: 10px;
}
[data-theme="dark"] .compose-ab-no-phone {
  color: #f87171 !important;
}

/* Compose chips container */
.compose-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

/* Send button inner span */
.compose-footer .btn-send span {
  white-space: nowrap;
}

/* ─── Assign Conversation Dropdown ─── */
.wa-assign-dropdown {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,.15);
  width: 280px;
  max-height: 400px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  animation: waAssignFadeIn .15s ease;
}
@keyframes waAssignFadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.wa-assign-dd-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #e9edef;
  font-size: 0.9rem;
  font-weight: 600;
  color: #111b21;
}
[data-theme="dark"] .wa-assign-dd-header {
  border-bottom-color: #2a3942;
  color: #e9edef;
}
.wa-assign-dd-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #8696a0;
  font-size: 0.85rem;
  padding: 2px 4px;
  border-radius: 4px;
}
.wa-assign-dd-close:hover {
  color: #111b21;
  background: #f0f2f5;
}
[data-theme="dark"] .wa-assign-dd-close:hover {
  color: #e9edef;
  background: rgba(255,255,255,0.08);
}
.wa-assign-dd-body {
  overflow-y: auto;
  flex: 1;
  max-height: 340px;
}
.wa-assign-dd-current {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #f0fdf4;
  border-bottom: 1px solid #e9edef;
  font-size: 0.82rem;
  color: #111b21;
}
[data-theme="dark"] .wa-assign-dd-current {
  background: rgba(0,168,132,0.08);
  border-bottom-color: #2a3942;
  color: #e9edef;
}
.wa-assign-dd-unassign {
  background: none;
  border: none;
  cursor: pointer;
  color: #8696a0;
  margin-left: auto;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
}
.wa-assign-dd-unassign:hover {
  color: #dc2626;
  background: #fef2f2;
}
[data-theme="dark"] .wa-assign-dd-unassign:hover {
  background: rgba(220,38,38,0.12);
}
.wa-assign-dd-section-title {
  padding: 8px 16px 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8696a0;
  font-weight: 600;
}
[data-theme="dark"] .wa-assign-dd-section-title {
  color: #657983;
}
.wa-assign-dd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #111b21;
  transition: background .12s;
}
[data-theme="dark"] .wa-assign-dd-item {
  color: #e9edef;
}
.wa-assign-dd-item:hover {
  background: #f0f2f5;
}
[data-theme="dark"] .wa-assign-dd-item:hover {
  background: #2a3942;
}
.wa-assign-dd-item .fa-check {
  font-size: 0.75rem;
}

/* ============================================================
   WHATSAPP MAIN AREA — New class-based styles
   ============================================================ */

/* Empty state content — see whatsapp.css .whatsapp-empty-icon, .whatsapp-empty-title */

/* Back button in header */
.wa-back-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 8px 6px 0;
  color: var(--text-primary, #111b21);
  font-size: 18px;
  line-height: 1;
}
[data-theme="dark"] .wa-back-btn { color: #e9edef; }

/* Header badge buttons */
.wa-hdr-badge-btn { position: relative; }

.wa-hdr-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  color: #fff;
  border-radius: 8px;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  pointer-events: none;
}
.wa-hdr-badge--amber { background: #f59e0b; }
.wa-hdr-badge--green { background: #25d366; }

.wa-hdr-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: #25d366;
  border-radius: 50%;
  border: 2px solid var(--wa-header-bg, #fff);
  pointer-events: none;
}
[data-theme="dark"] .wa-hdr-dot { border-color: #1f2c34; }

/* Image preview counter pill */
.wa-image-preview-counter {
  position: absolute;
  top: -36px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 12px;
  padding: 2px 12px;
  font-size: 13px;
  z-index: 2;
  white-space: nowrap;
}

/* Image preview video */
.wa-image-preview-video {
  max-width: 100%;
  max-height: 60vh;
}

/* Enter-chat overlay */
.wa-enter-chat-overlay {
  display: flex;
  position: absolute;
  inset: 0;
  z-index: 10;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary, #f0f2f5);
  border-radius: inherit;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
[data-theme="dark"] .wa-enter-chat-overlay { background: #1f2c34; }

.wa-enter-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #128c7e, #25d366);
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 8px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(18,140,126,0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.wa-enter-chat-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(18,140,126,0.35);
}

/* Input normal elements wrapper */
.wa-input-elements {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.wa-input-action-wrap { position: relative; }

/* Plus menu */
.wa-plus-menu {
  position: absolute;
  bottom: 52px;
  /* Ancorato al BORDO SINISTRO del pulsante "+": con left:50% + translateX(-50%) il riquadro
     sporgeva di un centinaio di pixel sulla colonna delle conversazioni, che lo copriva. Cosi'
     si apre verso destra e resta tutto dentro il pannello della chat. */
  left: 0;
  transform: none;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  padding: 10px 8px;
  z-index: 2200;
  min-width: 188px;
  animation: waMenuSlideUp 0.2s ease;
}
[data-theme="dark"] .wa-plus-menu {
  background: #233138;
  box-shadow: 0 4px 24px rgba(0,0,0,0.45);
}
.wa-plus-menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  justify-items: center;
}
.wa-plus-menu-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  width: 60px;
  border-radius: 10px;
  padding: 5px 2px;
  transition: background 0.15s ease;
}
.wa-plus-menu-item:hover { background: rgba(0,0,0,0.05); }
[data-theme="dark"] .wa-plus-menu-item:hover { background: rgba(255,255,255,0.06); }
.wa-plus-menu-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.wa-plus-menu-icon i {
  color: #fff;
  font-size: 14px;
}
.wa-plus-menu-item span {
  font-size: 10.5px;
  line-height: 1.2;
  color: #667781;
  text-align: center;
}
[data-theme="dark"] .wa-plus-menu-item span { color: #8696a0; }

/* Toolbar accent buttons (template, schedule) */
.wa-toolbar-btn--purple { color: #7c3aed !important; }
.wa-toolbar-btn--teal   { color: #128c7e !important; }

/* ---- Folder search results in chat list ---- */
.folder-search-section {
  padding: 4px 8px 2px;
}
.folder-search-header {
  font-size: 0.7rem;
  font-weight: 600;
  color: #8696a0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 4px 4px;
}
.folder-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
  transition: background 0.15s;
}
.folder-search-item:hover { background: var(--hover-bg, #f0f2f5); }
.folder-search-item.active { background: #e7f8ee; }
.folder-search-item-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.folder-search-item-name {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary, #111b21);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-search-item-count {
  font-size: 0.72rem;
  background: #e5e7eb;
  color: #6b7280;
  border-radius: 8px;
  padding: 1px 7px;
  flex-shrink: 0;
}
[data-theme="dark"] .folder-search-item:hover { background: #2a3942; }
[data-theme="dark"] .folder-search-item.active { background: #1a3329; }
[data-theme="dark"] .folder-search-item-name { color: #e9edef; }
[data-theme="dark"] .folder-search-item-count { background: #374151; color: #9ca3af; }
[data-theme="dark"] .folder-search-header { color: #657983; }


/* ===================================
   WHATSAPP MESSAGE BUBBLES (merged from whatsapp.css)
   =================================== */


/* ============================================
   DATE DIVIDER
   ============================================ */
.whatsapp-date-divider {
  text-align: center;
  margin: 18px 0 10px;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Il testo della data sta in <span>; lo stile della pillola va sullo span.
   (Niente ::before con attr(data-date): genererebbe una pillola vuota
   fantasma accanto a quella reale, perché il markup non ha più data-date.) */
.whatsapp-date-divider span {
  display: inline-block;
  background: rgba(225, 245, 254, 0.93);
  color: #54656f;
  padding: 5px 13px 6px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(11, 20, 26, 0.10);
  letter-spacing: 0.01em;
  backdrop-filter: blur(2px);
}

[data-theme="dark"] .whatsapp-date-divider span {
  background: rgba(12, 22, 28, 0.88);
  color: rgba(233, 237, 239, 0.6);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

/* ============================================
   MESSAGE BUBBLES
   ============================================ */
.whatsapp-message {
  display: flex;
  margin-bottom: 2px;
  padding: 0 4.5% 0 3.5%;
}

/* Only animate newly appended messages (SSE), not bulk renders */
.whatsapp-message.wa-new-msg {
  animation: messageSlideIn 0.16s cubic-bezier(0.2, 0, 0.38, 0.9);
}

.whatsapp-message.calendar-message-selected .whatsapp-message-bubble {
  outline: 2px solid #0f766e;
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12), 0 2px 10px rgba(11, 20, 26, 0.12);
}

.whatsapp-message.calendar-message-focus .whatsapp-message-bubble {
  animation: calendarMessagePulse 1.4s ease-out;
}

.whatsapp-message.received {
  justify-content: flex-start;
}

.whatsapp-message.sent {
  justify-content: flex-end;
}

.whatsapp-message-bubble {
  max-width: 68%;
  min-width: 76px;
  padding: 7px 10px 8px 12px;
  border-radius: 8px;
  position: relative;
  box-shadow: 0 1px 2px rgba(11, 20, 26, 0.12), 0 1px 0.5px rgba(11, 20, 26, 0.06);
  word-wrap: break-word;
  overflow-wrap: break-word;
  transition: box-shadow 0.12s ease;
  will-change: auto;
}

.whatsapp-message-bubble:hover {
  box-shadow: 0 2px 6px rgba(11, 20, 26, 0.15), 0 1px 1px rgba(11, 20, 26, 0.06);
}

/* Badge REAZIONI: emoji attaccata al messaggio (overlay), stile WhatsApp.
   Uso interno: la reazione marca il messaggio (es. "confermato" al cliente). */
.wa-reactions {
  position: absolute;
  bottom: -11px;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 1px 5px;
  border-radius: 11px;
  background: #fff;
  border: 1px solid rgba(11, 20, 26, 0.12);
  box-shadow: 0 1px 2px rgba(11, 20, 26, 0.18);
  font-size: 0.82rem;
  line-height: 1.15;
  z-index: 3;
  cursor: default;
  white-space: nowrap;
}
.wa-msg.out .wa-reactions { right: 6px; }
.wa-msg.in .wa-reactions { left: 6px; }
.wa-reactions b { font-size: 0.66rem; font-weight: 600; color: #667781; margin-left: 2px; }
/* spazio extra sotto una bolla reagita: il badge non tocca la bolla successiva */
.wa-msg-wrap:has(.wa-reactions) { margin-bottom: 13px; }
@media (prefers-color-scheme: dark) {
  .wa-reactions { background: #233138; border-color: rgba(255, 255, 255, 0.12); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); }
  .wa-reactions b { color: #8696a0; }
}
body.dark .wa-reactions, .dark .wa-reactions, [data-theme="dark"] .wa-reactions {
  background: #233138; border-color: rgba(255, 255, 255, 0.12); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.whatsapp-message-bubble::after {
  content: '';
  display: table;
  clear: both;
}

/* Received message */
.whatsapp-message.received .whatsapp-message-bubble {
  background: #ffffff;
  color: #111b21;
  border-top-left-radius: 3px;
  box-shadow: 0 1px 2px rgba(11,20,26,0.10), 0 1px 1px rgba(11,20,26,0.06);
}

/* Sent message — flat WhatsApp green */
.whatsapp-message.sent .whatsapp-message-bubble {
  background: #d9fdd3;
  color: #111b21;
  border-top-right-radius: 3px;
  box-shadow: 0 1px 2px rgba(11,20,26,0.10), 0 1px 1px rgba(11,20,26,0.05);
}

/* Consecutive messages — tight spacing within a group */
.whatsapp-message + .whatsapp-message {
  margin-top: 1px;
}

/* First message of a new sender group — extra breathing room */
.whatsapp-message:not(.no-tail) + .whatsapp-message {
  margin-top: 10px;
}

/* Dark mode bubbles */
[data-theme="dark"] .whatsapp-message-bubble {
  box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 1px rgba(0,0,0,0.2);
}

[data-theme="dark"] .whatsapp-message.received .whatsapp-message-bubble {
  background: #1e2b32;
  color: #e9edef;
}

[data-theme="dark"] .whatsapp-message.sent .whatsapp-message-bubble {
  background: #005c4b;
  color: #e9edef;
}

@keyframes calendarMessagePulse {
  0% { box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.38); }
  65% { box-shadow: 0 0 0 10px rgba(15, 118, 110, 0); }
  100% { box-shadow: inherit; }
}

/* SVG Tail decorations (WhatsApp Web style) */
.wa-msg-tail {
  position: absolute;
  top: 0;
  display: block;
  width: 8px;
  height: 13px;
  z-index: 1;
}

.whatsapp-message.received .wa-msg-tail {
  left: -8px;
  color: #ffffff;
}

.whatsapp-message.sent .wa-msg-tail {
  right: -8px;
  color: #d9fdd3;
}

[data-theme="dark"] .whatsapp-message.received .wa-msg-tail {
  color: #1e2b32;
}

[data-theme="dark"] .whatsapp-message.sent .wa-msg-tail {
  color: #005c4b;
}

/* ── Typing bubble (tre pallini animati stile WhatsApp) ── */
.wa-typing-bubble {
  display: flex;
  align-items: center;
  margin: 2px 0 6px 12px;
  align-self: flex-start;
}
.wa-typing-bubble .whatsapp-message-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  min-width: 52px;
}
.wa-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8696a0;
  animation: wa-typing-bounce 1.2s infinite ease-in-out;
}
.wa-typing-dot:nth-child(1) { animation-delay: 0s; }
.wa-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.wa-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes wa-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}
[data-theme="dark"] .wa-typing-dot { background: #aebac1; }

/* No-tail consecutive messages: restore full rounded corners */
.whatsapp-message.no-tail.received .whatsapp-message-bubble {
  border-top-left-radius: 8px;
  box-shadow: 0 1px 1.5px rgba(11,20,26,0.08), 0 0.5px 0.5px rgba(11,20,26,0.04);
}

.whatsapp-message.no-tail.sent .whatsapp-message-bubble {
  border-top-right-radius: 8px;
  box-shadow: 0 1px 1.5px rgba(11,20,26,0.08), 0 0.5px 0.5px rgba(11,20,26,0.04);
}

/* Consecutive messages - tighter spacing */
.whatsapp-message.no-tail {
  margin-bottom: 1px;
}

/* Message status icons (SVG checkmarks) */
.wa-msg-status {
  display: inline-flex;
  align-items: center;
  margin-left: 3px;
  vertical-align: middle;
}

.wa-msg-status svg {
  display: block;
}

/* Sender name (in group chats) */
.whatsapp-message-sender {
  font-size: 11.5px;
  font-weight: 600;
  margin-bottom: 1px;
  color: #00a884;
  letter-spacing: 0;
  line-height: 1.3;
}

.wa-sender-phone {
  font-weight: 400;
  opacity: 0.7;
  font-size: 12px;
  letter-spacing: 0;
}

[data-theme="dark"] .whatsapp-message-sender {
  color: #53bdeb;
}

/* Message text */
.whatsapp-message-text {
  font-size: 14.35px;
  line-height: 20px;
  white-space: pre-wrap;
  word-wrap: break-word;
  letter-spacing: 0.006em;
  display: inline;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', 'Inter', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-weight: 400;
  color: #111b21;
}

/* Invisible spacer to reserve room for meta (time + status) */
.whatsapp-message-text::after {
  content: '';
  display: inline-block;
  width: 72px;
  height: 0;
}

.whatsapp-message.received .whatsapp-message-text::after {
  width: 50px;
}

.whatsapp-message-text a {
  color: #027eb5;
  text-decoration: none;
  word-break: break-all;
  border-bottom: 1px solid transparent;
  transition: border-color 0.12s;
}

.whatsapp-message-text a:hover {
  text-decoration: none;
  border-bottom-color: currentColor;
}

.whatsapp-message.sent .whatsapp-message-text a {
  color: #025d4b;
}

/* WhatsApp mention (@name) */
.wa-mention {
  color: #027eb5;
  font-weight: 500;
  cursor: default;
}

.whatsapp-message.sent .wa-mention {
  color: #025d4b;
}

[data-theme="dark"] .wa-mention {
  color: #53bdeb;
}

/* Schedule modal: collapse 2-column layout to 1 column on narrow screens */
@media (max-width: 620px) {
  .sched-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
}

[data-theme="dark"] .whatsapp-message-text {
  color: #e9edef;
}

[data-theme="dark"] .whatsapp-message-text a {
  color: #53bdeb;
}

[data-theme="dark"] .whatsapp-message.sent .whatsapp-message-text a {
  color: #7ee8c7;
}

/* Message meta (time + status) */
.whatsapp-message-meta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  float: right;
  margin: 2px 0 -5px 6px;
  padding-left: 2px;
  height: 15px;
  position: relative;
}

.whatsapp-message-time {
  font-size: 11px;
  color: rgba(17, 27, 33, 0.42);
  line-height: 15px;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.whatsapp-message.sent .whatsapp-message-time {
  color: rgba(17, 27, 33, 0.38);
}

[data-theme="dark"] .whatsapp-message-time {
  color: rgba(233, 237, 239, 0.42);
}

[data-theme="dark"] .whatsapp-message.sent .whatsapp-message-time {
  color: rgba(233, 237, 239, 0.50);
}

/* Message status ticks (legacy - now using .wa-msg-status for SVG) */
.whatsapp-message-status {
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  color: rgba(17, 27, 33, 0.40);
}

[data-theme="dark"] .whatsapp-message-status {
  color: rgba(233, 237, 239, 0.50);
}

/* Quoted message */
.whatsapp-quoted-message {
  background: rgba(0, 0, 0, 0.05);
  border-left: 4px solid #25d366;
  padding: 4px 8px 5px 9px;
  border-radius: 5px;
  margin-bottom: 5px;
  cursor: pointer;
  max-height: 60px;
  overflow: hidden;
  transition: background 0.1s;
}

.whatsapp-quoted-message:hover {
  background: rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .whatsapp-quoted-message {
  background: rgba(255, 255, 255, 0.05);
  border-left-color: #00a884;
}

[data-theme="dark"] .whatsapp-quoted-message:hover {
  background: rgba(255, 255, 255, 0.08);
}

.whatsapp-quoted-sender {
  font-size: 12px;
  font-weight: 700;
  color: #00a884;
  margin-bottom: 1px;
  line-height: 1.3;
}

.whatsapp-quoted-text {
  font-size: 12.5px;
  color: rgba(17, 27, 33, 0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(320px, 65vw);
  line-height: 1.35;
}

[data-theme="dark"] .whatsapp-quoted-text {
  color: rgba(233, 237, 239, 0.55);
}

/* Deleted message */
.whatsapp-message-deleted {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(17, 27, 33, 0.42);
  font-style: italic;
  font-size: 13.5px;
}

[data-theme="dark"] .whatsapp-message-deleted {
  color: rgba(233, 237, 239, 0.42);
}

/* ============================================
   EMPTY STATE
   ============================================ */
.whatsapp-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  color: #667781;
  text-align: center;
  background: linear-gradient(180deg, #f7f8fa 0%, #f0f2f5 40%, #e8ebe4 100%);
  border-left: 1px solid rgba(209, 215, 219, 0.4);
  padding: 40px;
  position: relative;
  overflow: hidden;
}

.whatsapp-empty-state::before {
  content: '';
  position: absolute;
  top: -100px;
  right: -100px;
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(37,211,102,0.04) 0%, transparent 65%);
  pointer-events: none;
}

.whatsapp-empty-state::after {
  content: '';
  position: absolute;
  bottom: -80px;
  left: -60px;
  width: 240px;
  height: 240px;
  background: radial-gradient(circle, rgba(0,168,132,0.035) 0%, transparent 65%);
  pointer-events: none;
}

[data-theme="dark"] .whatsapp-empty-state {
  background: linear-gradient(180deg, #1a252c 0%, #141e24 50%, #111b21 100%);
  border-left-color: rgba(42, 57, 66, 0.4);
  color: #8696a0;
}

.whatsapp-empty-icon {
  margin-bottom: 28px;
  position: relative;
  z-index: 1;
}

.whatsapp-empty-icon i {
  font-size: 80px;
  background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 3px 10px rgba(37,211,102,0.15));
}

[data-theme="dark"] .whatsapp-empty-icon i {
  filter: drop-shadow(0 3px 14px rgba(37,211,102,0.12));
}

.whatsapp-empty-title {
  font-size: 28px;
  font-weight: 300;
  color: #41525d;
  margin-bottom: 12px;
  letter-spacing: -0.3px;
  position: relative;
  z-index: 1;
}

[data-theme="dark"] .whatsapp-empty-title {
  color: #e9edef;
}

.whatsapp-empty-text {
  font-size: 13.5px;
  color: #8696a0;
  max-width: 420px;
  line-height: 1.6;
  position: relative;
  z-index: 1;
}

.whatsapp-empty-subtitle {
  font-size: 13px;
  color: #8696a0;
  text-align: center;
  line-height: 1.6;
  margin: 0;
  position: relative;
  z-index: 1;
}
[data-theme="dark"] .whatsapp-empty-subtitle { color: #657983; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .whatsapp-message-bubble {
    max-width: 85%;
  }
}

@media (max-width: 1024px) {
  .whatsapp-message-bubble {
    max-width: 75%;
  }
}

/* ============================================
   ANIMATION
   ============================================ */
@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Scrollbar styling */
.whatsapp-chat-list,
.whatsapp-messages-container {
  scrollbar-width: thin;
  scrollbar-color: rgba(134,150,160,0.25) transparent;
}

.whatsapp-chat-list::-webkit-scrollbar,
.whatsapp-messages-container::-webkit-scrollbar {
  width: 3px;
}

.whatsapp-chat-list::-webkit-scrollbar-thumb,
.whatsapp-messages-container::-webkit-scrollbar-thumb {
  background: rgba(134, 150, 160, 0.25);
  border-radius: 10px;
  transition: background 0.2s;
}

.whatsapp-chat-list:hover::-webkit-scrollbar-thumb,
.whatsapp-messages-container:hover::-webkit-scrollbar-thumb {
  background: rgba(134, 150, 160, 0.45);
}

.whatsapp-chat-list::-webkit-scrollbar-thumb:active,
.whatsapp-messages-container::-webkit-scrollbar-thumb:active {
  background: rgba(134, 150, 160, 0.65);
}

[data-theme="dark"] .whatsapp-chat-list,
[data-theme="dark"] .whatsapp-messages-container {
  scrollbar-color: rgba(134,150,160,0.15) transparent;
}

[data-theme="dark"] .whatsapp-chat-list:hover::-webkit-scrollbar-thumb,
[data-theme="dark"] .whatsapp-messages-container:hover::-webkit-scrollbar-thumb {
  background: rgba(134, 150, 160, 0.30);
}

.whatsapp-chat-list::-webkit-scrollbar-track,
.whatsapp-messages-container::-webkit-scrollbar-track {
  background: transparent;
}

/* Note bubble in WhatsApp view */
.whatsapp-message .note-bubble {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%) !important;
  border-left: 3px solid #f59e0b !important;
  color: #78350f !important;
}

[data-theme="dark"] .whatsapp-message .note-bubble {
  background: linear-gradient(135deg, #451a03 0%, #78350f 100%) !important;
  color: #fef3c7 !important;
}

/* ============================================
   PLUS MENU (WhatsApp-style attach popup)
   ============================================ */
@keyframes waMenuSlideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#wa-plus-icon {
  transition: transform 0.25s ease;
}

.wa-plus-menu-item:hover > div:first-child {
  transform: scale(1.1);
  transition: transform 0.15s ease;
}

.wa-plus-menu-item > div:first-child {
  transition: transform 0.15s ease;
}

[data-theme="dark"] #wa-plus-menu {
  background: #233138 !important;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4) !important;
}

[data-theme="dark"] .wa-plus-menu-item span {
  color: #aebac1 !important;
}

/* ============================================
   NUOVI ELEMENTI — chat.js v2
   ============================================ */

/* Avatar fallback colorato */
.whatsapp-avatar-fallback {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  letter-spacing: 0.02em;
  user-select: none;
}
.whatsapp-avatar-img {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

/* Skeleton pulse animation */
.skeleton-pulse {
  animation: skeletonPulse 1.4s ease-in-out infinite;
}
@keyframes skeletonPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}
[data-theme="dark"] .skeleton-pulse { background: #2a3942 !important; }

/* Message wrapper */
.message-wrapper {
  display: flex;
  margin: 2px 16px;
  position: relative;
}
.message-wrapper.message-incoming { justify-content: flex-start; }
.message-wrapper.message-outgoing { justify-content: flex-end; }

/* Message meta (ora + spunta) */
.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
}
.message-tick {
  font-size: 0.75rem;
  line-height: 1;
}

/* Image message */
.message-image-wrap { max-width: 280px; }
.message-image {
  max-width: 100%;
  border-radius: 6px;
  display: block;
  cursor: zoom-in;
}

/* Video message */
.message-video-wrap { max-width: 280px; }
.message-video { max-width: 100%; border-radius: 6px; display: block; }

/* Audio message */
.message-audio-wrap {
  display: flex;
  align-items: center;
  min-width: 180px;
  padding: 4px 0;
}

/* Document message */
.message-document-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  text-decoration: none;
  color: inherit;
  min-width: 200px;
  max-width: 280px;
}
.message-doc-icon {
  font-size: 1.6rem;
  color: #128c7e;
  flex-shrink: 0;
}
[data-theme="dark"] .message-doc-icon { color: #00a884; }
.message-doc-info { display: flex; flex-direction: column; overflow: hidden; }
.message-doc-name {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-doc-ext {
  font-size: 0.7rem;
  color: #8696a0;
  margin-top: 2px;
}

/* Sticker */
.message-sticker { max-width: 160px; border-radius: 4px; }

/* Location */
.message-location {
  padding: 6px 4px;
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  min-width: 180px;
}

/* Contact */
.message-contact {
  display: flex;
  align-items: center;
  padding: 6px 4px;
  min-width: 180px;
}

/* Quoted message */
.message-quoted {
  border-left: 4px solid #25d366;
  padding: 4px 8px;
  margin-bottom: 6px;
  border-radius: 0 4px 4px 0;
  background: rgba(0,0,0,0.04);
  cursor: pointer;
}
.message-quoted-sender {
  font-size: 0.75rem;
  font-weight: 600;
  color: #25d366;
  margin-bottom: 2px;
}
.message-quoted-text {
  font-size: 0.8rem;
  color: #667781;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
[data-theme="dark"] .message-quoted { background: rgba(255,255,255,0.06); }
[data-theme="dark"] .message-quoted-text { color: #aebac1; }

/* Media placeholder (quando URL non disponibile) */
.message-media-placeholder {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(0,0,0,0.05);
  border-radius: 6px;
  color: #8696a0;
  font-size: 0.85rem;
  min-width: 120px;
}
.message-media-placeholder i { font-size: 1.2rem; }

/* Message caption */
.message-caption {
  font-size: 0.85rem;
  margin-top: 4px;
  word-break: break-word;
}

/* Load older button */
.wa-load-older-btn {
  padding: 7px 22px;
  border: 1px solid rgba(11,20,26,0.11);
  border-radius: 20px;
  background: rgba(255,255,255,0.93);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #54656f;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.10), 0 0.5px 1px rgba(0,0,0,0.06);
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  letter-spacing: 0.01em;
}
.wa-load-older-btn:hover {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.13);
  transform: translateY(-1px);
}
.wa-load-older-btn:active { transform: translateY(0); }
[data-theme="dark"] .wa-load-older-btn {
  background: rgba(30,43,50,0.92);
  border-color: rgba(255,255,255,0.08);
  color: #aebac1;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
[data-theme="dark"] .wa-load-older-btn:hover {
  background: rgba(42,57,66,0.95);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* Chat preview row */
.whatsapp-chat-preview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
}
.whatsapp-chat-preview {
  font-size: 0.8rem;
  color: #667781;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
[data-theme="dark"] .whatsapp-chat-preview { color: #8696a0; }

/* ── Contenteditable message input ── */
.whatsapp-message-input {
  flex: 1;
  border: none;
  background: transparent;
  color: #111b21;
  font-size: 14px;
  outline: none;
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  line-height: 20px;
  min-height: 20px;
  max-height: 120px;
  overflow-y: auto;
  word-break: break-word;
  white-space: pre-wrap;
  -webkit-font-smoothing: antialiased;
}
.whatsapp-message-input:empty::before {
  content: attr(data-placeholder);
  color: #8696a0;
  pointer-events: none;
  display: block;
}
[data-theme="dark"] .whatsapp-message-input { color: #e9edef; }

/* ── Empty state deve occupare tutto lo spazio disponibile ── */
#wa-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ── Bottone back mobile ── */
.wa-back-btn {
  background: none;
  border: none;
  color: #54656f;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 10px 4px 0;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
[data-theme="dark"] .wa-back-btn { color: #aebac1; }

/* ── Separatore data ── */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 14px 0 6px;
}
.date-separator::after {
  content: attr(data-date);
  background: #fff;
  color: #54656f;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  letter-spacing: 0.02em;
}
[data-theme="dark"] .date-separator::after {
  background: #182229;
  color: #8696a0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ── Avatar in chat-list-item-avatar conta come il wrapper ── */
.chat-list-item-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 12px;
  overflow: hidden;
  border-radius: 50%;
}
.chat-list-item-avatar .whatsapp-avatar-fallback,
.chat-list-item-avatar .whatsapp-avatar-img {
  width: 46px;
  height: 46px;
}

/* ══════════════════════════════════════════════════════════════
   SCHERMATA QR CODE — connessione sessione WhatsApp
   ══════════════════════════════════════════════════════════════ */

.wa-qr-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #efeae2;
  padding: 24px 16px;
  overflow-y: auto;
}
[data-theme="dark"] .wa-qr-screen { background: #0b141a; }

.wa-qr-card {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px 28px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}
[data-theme="dark"] .wa-qr-card {
  background: #1f2c34;
  box-shadow: 0 4px 24px rgba(0,0,0,0.35);
}

.wa-qr-wa-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #25d366;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 32px;
  flex-shrink: 0;
}

.wa-qr-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #111b21;
  margin: 0;
}
[data-theme="dark"] .wa-qr-title { color: #e9edef; }

.wa-qr-desc {
  font-size: 0.88rem;
  color: #667781;
  margin: 0;
  line-height: 1.5;
}
[data-theme="dark"] .wa-qr-desc { color: #8696a0; }

.wa-qr-wrap {
  width: 232px;
  height: 232px;
  border: 2px solid #e9edef;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
[data-theme="dark"] .wa-qr-wrap {
  border-color: #2a3942;
  background: #111b21;
}

.wa-qr-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: #8696a0;
  font-size: 0.82rem;
}
.wa-qr-spinner i { font-size: 28px; color: #25d366; }

.wa-qr-img {
  width: 220px;
  height: 220px;
  border-radius: 8px;
  display: block;
}

.wa-qr-err {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: #ef4444;
  font-size: 0.82rem;
}
.wa-qr-err i { font-size: 24px; }

.wa-qr-steps {
  text-align: left;
  font-size: 0.82rem;
  color: #667781;
  margin: 0;
  padding-left: 18px;
  line-height: 1.9;
  width: 100%;
}
[data-theme="dark"] .wa-qr-steps { color: #8696a0; }
.wa-qr-steps strong { color: #111b21; font-weight: 600; }
[data-theme="dark"] .wa-qr-steps strong { color: #e9edef; }

.wa-qr-status-row {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
}

.wa-qr-refresh-btn {
  padding: 10px 24px;
  border-radius: 24px;
  border: none;
  background: #25d366;
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, transform 0.1s;
}
.wa-qr-refresh-btn:hover { background: #1fa855; }
.wa-qr-refresh-btn:active { transform: scale(0.97); }
.wa-qr-refresh-btn i { font-size: 0.8rem; }

@media (max-width: 480px) {
  .wa-qr-card { padding: 24px 16px 20px; }
  .wa-qr-wrap { width: 200px; height: 200px; }
  .wa-qr-img  { width: 188px; height: 188px; }
}

/* ══════════════════════════════════════════════════════════════
   WhatsApp Web QR — layout a due colonne (wa-qrw-*)
   ══════════════════════════════════════════════════════════════ */

.wa-qrw-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 32px rgba(0,0,0,0.12);
  width: 740px;
  max-width: 96vw;
  padding: 32px 36px 36px;
  position: relative;
}
[data-theme="dark"] .wa-qrw-card {
  background: #1f2c34;
  box-shadow: 0 4px 32px rgba(0,0,0,0.4);
}

.wa-qrw-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid #e9edef;
}
[data-theme="dark"] .wa-qrw-header { border-color: #2a3942; }

.wa-qrw-brand {
  font-size: 1.15rem;
  font-weight: 500;
  color: #41525d;
  letter-spacing: 0.01em;
}
[data-theme="dark"] .wa-qrw-brand { color: #aebac1; }

.wa-qrw-body {
  display: flex;
  gap: 52px;
  align-items: flex-start;
}

.wa-qrw-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.wa-qrw-qrbox {
  width: 264px;
  height: 264px;
  border: 1px solid #e9edef;
  border-radius: 10px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
[data-theme="dark"] .wa-qrw-qrbox {
  border-color: #2a3942;
  background: #111b21;
}

.wa-qrw-right {
  flex: 1;
  padding-top: 8px;
}

.wa-qrw-title {
  font-size: 1.35rem;
  font-weight: 300;
  color: #111b21;
  margin: 0 0 20px;
  line-height: 1.3;
}
[data-theme="dark"] .wa-qrw-title { color: #e9edef; }

.wa-qrw-steps {
  list-style: decimal;
  padding-left: 20px;
  margin: 0 0 24px;
  color: #41525d;
  font-size: 0.9rem;
  line-height: 1.7;
}
[data-theme="dark"] .wa-qrw-steps { color: #8696a0; }
.wa-qrw-steps li { margin-bottom: 8px; }
.wa-qrw-steps strong { color: #111b21; font-weight: 600; }
[data-theme="dark"] .wa-qrw-steps strong { color: #e9edef; }

/* Flash overlay "Connesso!" */
.wa-qrw-connected {
  position: absolute;
  inset: 0;
  background: rgba(37,211,102,0.93);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: qrw-fade-in 0.18s ease;
  z-index: 10;
}

.wa-qrw-connected-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: #fff;
}
.wa-qrw-connected-inner i { font-size: 56px; }
.wa-qrw-connected-inner span { font-size: 1.4rem; font-weight: 600; }

@keyframes qrw-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Responsive: stack verticale su schermi stretti */
@media (max-width: 620px) {
  .wa-qrw-card { padding: 20px 16px 24px; }
  .wa-qrw-body { flex-direction: column; align-items: center; gap: 24px; }
  .wa-qrw-qrbox { width: 220px; height: 220px; }
  .wa-qrw-right { text-align: center; }
  .wa-qrw-steps { text-align: left; }
}

/* ============================================================
   NEW WHATSAPP UI  (wa- prefix)
   chat.js rewrite — clean, no conflicts with legacy .whatsapp-*
   ============================================================ */

/* Layout — fills the fixed .main-content.fullscreen parent */
.wa-layout {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--chat-bg-light, #e5ddd5);
  position: relative;
}
[data-theme="dark"] .wa-layout {
  background: var(--chat-bg-dark, #0b141a);
}

/* ── Sidebar ── */
.wa-sidebar {
  width: 380px;
  min-width: 280px;
  max-width: 420px;
  height: 100%;
  background: #fff;
  border-right: 1px solid #e9edef;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease;
  z-index: 10;
}
[data-theme="dark"] .wa-sidebar {
  background: #111b21;
  border-right-color: #2a3942;
}
.wa-sidebar--hidden {
  transform: translateX(-100%);
  position: absolute;
  top: 0; left: 0; bottom: 0;
}

/* Sidebar Header */
.wa-sidebar-header {
  height: 56px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 16px;
  background: #f0f2f5;
  border-bottom: 1px solid #e9edef;
  flex-shrink: 0;
}
[data-theme="dark"] .wa-sidebar-header {
  background: #202c33;
  border-bottom-color: #2a3942;
}
.wa-sidebar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: #111b21;
}
[data-theme="dark"] .wa-sidebar-title { color: #e9edef; }
.wa-sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #25d366;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.wa-sidebar-actions { display: flex; gap: 4px; }

/* Icon Button (shared) */
.wa-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #54656f;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: background 0.15s;
  flex-shrink: 0;
}
.wa-icon-btn:hover { background: rgba(11,20,26,.08); }
[data-theme="dark"] .wa-icon-btn { color: #aebac1; }
[data-theme="dark"] .wa-icon-btn:hover { background: rgba(255,255,255,.08); }

/* Search Bar */
.wa-search-bar {
  padding: 6px 12px 8px;
  background: #fff;
  flex-shrink: 0;
}
[data-theme="dark"] .wa-search-bar { background: #1f2c34; }
.wa-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.wa-search-icon {
  position: absolute;
  left: 12px;
  color: #54656f;
  font-size: 13px;
  pointer-events: none;
}
[data-theme="dark"] .wa-search-icon { color: #8696a0; }
.wa-search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: none;
  border-radius: 8px;
  background: #f0f2f5;
  color: #111b21;
  font-size: 14px;
  outline: none;
}
[data-theme="dark"] .wa-search-input {
  background: #2a3942;
  color: #e9edef;
}
.wa-search-input::placeholder { color: #8696a0; font-size: 13.5px; }

/* Filter Tabs */
.wa-filter-tabs {
  display: flex;
  gap: 6px;
  padding: 4px 12px 8px;
  background: #fff;
  border-bottom: 1px solid #e9edef;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.wa-filter-tabs::-webkit-scrollbar { display: none; }
[data-theme="dark"] .wa-filter-tabs { background: #1f2c34; border-bottom-color: rgba(233,237,239,.08); }
.wa-filter-tab {
  padding: 5px 14px;
  border-radius: 16px;
  background: #f0f2f5;
  border: none;
  color: #54656f;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.wa-filter-tab:hover { background: #e9edef; }
.wa-filter-tab.active { background: #e7fcee; color: #00a884; font-weight: 600; }
[data-theme="dark"] .wa-filter-tab { background: rgba(255,255,255,.06); color: #8696a0; }
[data-theme="dark"] .wa-filter-tab.active { background: rgba(0,168,132,.15); color: #00a884; }

/* Status Bar */
.wa-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 16px;
  font-size: 12px;
  color: #667781;
  background: #fff;
  border-bottom: 1px solid #e9edef;
  flex-shrink: 0;
}
[data-theme="dark"] .wa-status-bar {
  background: #1f2c34;
  border-bottom-color: rgba(233,237,239,.08);
  color: #8696a0;
}
.wa-status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-status-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.wa-status-dot--connected { background: #10b981; box-shadow: 0 0 6px rgba(16,185,129,.5); animation: waDotPulse 2s ease-in-out infinite; }
.wa-status-dot--scanning  { background: #f59e0b; box-shadow: 0 0 6px rgba(245,158,11,.5);  animation: waDotPulse 2s ease-in-out infinite; }
.wa-status-dot--disconnected { background: #9ca3af; }
@keyframes waDotPulse {
  0%,100% { opacity:1; }
  50%      { opacity:.5; }
}

/* Chat List */
.wa-chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
.wa-chat-list::-webkit-scrollbar { width: 4px; }
.wa-chat-list::-webkit-scrollbar-thumb { background: rgba(134,150,160,.3); border-radius: 2px; }

.wa-list-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: #8696a0;
  gap: 8px;
  font-size: 14px;
}
.wa-list-placeholder i { font-size: 36px; opacity: .3; }

/* Chat Item */
.wa-chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(134,150,160,.1);
  transition: background 0.1s;
  user-select: none;
}
.wa-chat-item:hover { background: #f5f6f6; }
.wa-chat-item.active { background: #f0f2f5; }
[data-theme="dark"] .wa-chat-item:hover { background: #182229; }
[data-theme="dark"] .wa-chat-item.active { background: #2a3942; }

.wa-chat-item-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  flex-shrink: 0; position: relative;
  background: #dfe5e7;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.wa-avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.wa-avatar-fallback {
  width: 100%; height: 100%; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600; color: #fff;
}
.wa-group-badge {
  position: absolute; bottom: 0; right: 0;
  background: #fff; color: #54656f;
  border-radius: 50%; width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px;
}
[data-theme="dark"] .wa-group-badge { background: #111b21; color: #aebac1; }

.wa-chat-item-body { flex: 1; min-width: 0; }
.wa-chat-item-row {
  display: flex; align-items: baseline;
  justify-content: space-between; gap: 6px;
}
.wa-chat-item-name {
  font-size: 15px; font-weight: 500;
  color: #111b21; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
[data-theme="dark"] .wa-chat-item-name { color: #e9edef; }
.wa-chat-item-time {
  font-size: 11px; color: #667781; flex-shrink: 0;
}
[data-theme="dark"] .wa-chat-item-time { color: #8696a0; }
.wa-chat-item-preview {
  font-size: 13px; color: #667781;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
[data-theme="dark"] .wa-chat-item-preview { color: #8696a0; }
.wa-no-msgs { color: #c9c9c9; font-style: italic; font-size: 12px; }
.wa-unread-badge {
  background: #25d366; color: #fff;
  border-radius: 10px; min-width: 18px; height: 18px;
  padding: 0 5px; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── Main Area ── */
.wa-main {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Empty State */
.wa-empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; color: #8696a0; text-align: center;
  gap: 12px;
}
.wa-empty-icon {
  width: 72px; height: 72px; border-radius: 50%;
  background: rgba(0,168,132,.1);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; color: #00a884;
}
.wa-empty-title { font-size: 18px; font-weight: 500; color: #41525d; margin: 0; }
[data-theme="dark"] .wa-empty-title { color: #d1d7db; }

/* ── QR Screen ── */
.wa-qr-screen {
  flex: 1; display: flex; align-items: center; justify-content: center;
  height: 100%; background: #f0f2f5;
}
[data-theme="dark"] .wa-qr-screen { background: #0b141a; }

.wa-qr-card {
  background: #fff; border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,.12);
  max-width: 680px; width: 90%; overflow: hidden;
}
[data-theme="dark"] .wa-qr-card { background: #1f2c34; }

.wa-qr-card-header {
  background: #00a884; color: #fff;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 24px; font-size: 18px; font-weight: 600;
}
.wa-qr-card-header i { font-size: 24px; }

.wa-qr-card-body {
  display: flex; gap: 32px; padding: 32px 28px;
  align-items: flex-start;
}
.wa-qr-box-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  flex-shrink: 0;
}
.wa-qr-box {
  width: 216px; height: 216px; border-radius: 12px;
  border: 4px solid #e9edef;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
[data-theme="dark"] .wa-qr-box { border-color: #2a3942; }
.wa-qr-box img { width: 100%; height: 100%; object-fit: contain; display: block; }
.wa-qr-loading {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  color: #8696a0; font-size: 13px;
}
.wa-qr-loading i { font-size: 28px; color: #25d366; }
.wa-qr-error {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: #ef4444; font-size: 13px; text-align: center; padding: 12px;
}
.wa-qr-error i { font-size: 24px; }
.wa-qr-refresh-btn {
  padding: 8px 18px; background: #25d366; color: #fff;
  border: none; border-radius: 20px; cursor: pointer;
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
  transition: background 0.15s;
}
.wa-qr-refresh-btn:hover { background: #22c55e; }
.wa-qr-instructions { flex: 1; min-width: 0; }
.wa-qr-instructions h2 {
  font-size: 17px; font-weight: 600; color: #111b21;
  margin: 0 0 16px;
}
[data-theme="dark"] .wa-qr-instructions h2 { color: #e9edef; }
.wa-qr-instructions ol {
  padding-left: 20px; margin: 0;
  color: #41525d; font-size: 14px; line-height: 1.75;
}
[data-theme="dark"] .wa-qr-instructions ol { color: #8696a0; }
.wa-qr-instructions li { margin-bottom: 6px; }
.wa-qr-instructions strong { color: #111b21; font-weight: 600; }
[data-theme="dark"] .wa-qr-instructions strong { color: #e9edef; }

/* ── Chat Panel ── */
.wa-chat-panel {
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden;
  position: relative;
}

/* Chat Header */
.wa-chat-header {
  height: 56px; min-height: 56px; flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px 0 16px;
  background: #f0f2f5;
  border-bottom: 1px solid #e9edef;
}
[data-theme="dark"] .wa-chat-header {
  background: #202c33; border-bottom-color: #2a3942;
}
.wa-back-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: transparent;
  color: #54656f; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.wa-back-btn:hover { background: rgba(11,20,26,.08); }
[data-theme="dark"] .wa-back-btn { color: #aebac1; }
[data-theme="dark"] .wa-back-btn:hover { background: rgba(255,255,255,.08); }
.wa-chat-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: #dfe5e7; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; color: #fff;
}
.wa-chat-header-info { flex: 1; min-width: 0; }
.wa-chat-name { font-size: 15px; font-weight: 600; color: #111b21; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
[data-theme="dark"] .wa-chat-name { color: #e9edef; }
.wa-chat-status { font-size: 12px; color: #667781; }
[data-theme="dark"] .wa-chat-status { color: #8696a0; }
.wa-chat-header-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Reply Bar */
.wa-reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; background: #f0f2f5;
  border-bottom: 2px solid #25d366;
  flex-shrink: 0;
}
[data-theme="dark"] .wa-reply-bar { background: #1f2c34; }
.wa-reply-content {
  flex: 1; min-width: 0;
  border-left: 4px solid #25d366; padding-left: 10px;
}
.wa-reply-sender { font-size: 12px; font-weight: 600; color: #25d366; margin-bottom: 2px; }
.wa-reply-text { font-size: 13px; color: #667781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
[data-theme="dark"] .wa-reply-text { color: #8696a0; }
.wa-reply-close {
  width: 28px; height: 28px; border-radius: 50%;
  border: none; background: transparent; color: #8696a0;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.wa-reply-close:hover { background: rgba(134,150,160,.15); }

/* Messages Wrapper */
.wa-messages-wrap {
  flex: 1; overflow: hidden; display: flex; flex-direction: column;
  position: relative;
}
.wa-messages {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 12px 16px;
  background: var(--chat-bg-light, #e5ddd5);
  display: flex; flex-direction: column;
  scroll-behavior: smooth;
}
[data-theme="dark"] .wa-messages {
  background: var(--chat-bg-dark, #0b141a);
}
.wa-messages::-webkit-scrollbar { width: 5px; }
.wa-messages::-webkit-scrollbar-thumb { background: rgba(134,150,160,.3); border-radius: 3px; }

/* Date Separator */
.wa-date-sep {
  display: flex; justify-content: center;
  margin: 16px 0 12px; user-select: none;
}
.wa-date-sep span {
  background: rgba(225,245,254,.92); color: #54656f;
  font-size: 12px; font-weight: 500; padding: 4px 12px;
  border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
[data-theme="dark"] .wa-date-sep span {
  background: rgba(32,44,51,.9); color: #8696a0;
}

/* Loading / Error / Empty states */
.wa-msgs-loading {
  display: flex; align-items: center; justify-content: center;
  flex: 1; color: #8696a0; font-size: 24px;
}
.wa-msgs-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; flex: 1;
  color: #8696a0; text-align: center; gap: 8px;
}
.wa-msgs-empty i { font-size: 40px; opacity: .3; }
.wa-msgs-empty p { font-size: 14px; margin: 0; }
.wa-msgs-empty small { font-size: 12px; opacity: .6; }
.wa-msgs-error {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; flex: 1;
  color: #8696a0; text-align: center; gap: 12px;
}
.wa-msgs-error i { font-size: 36px; color: #ef4444; opacity: .6; }
.wa-retry-btn {
  padding: 8px 18px; background: #25d366; color: #fff;
  border: none; border-radius: 20px; cursor: pointer;
  font-size: 13px; font-weight: 600;
}

/* ── Message ── */
.wa-message {
  display: flex; flex-direction: column;
  max-width: 68%; margin-bottom: 2px;
  position: relative;
  animation: waMsgIn .18s ease;
}
@keyframes waMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.wa-message--in  { align-self: flex-start; }
.wa-message--out { align-self: flex-end; }

.wa-msg-sender {
  font-size: 11px; font-weight: 600; color: #25d366;
  margin-bottom: 2px; padding: 0 4px;
}

.wa-bubble {
  padding: 6px 10px 4px;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
  position: relative; word-break: break-word;
  max-width: 100%;
}
.wa-message--in  .wa-bubble { background: #fff; border-radius: 0 8px 8px 8px; }
.wa-message--out .wa-bubble { background: #d9fdd3; border-radius: 8px 0 8px 8px; }
[data-theme="dark"] .wa-message--in  .wa-bubble { background: #202c33; }
[data-theme="dark"] .wa-message--out .wa-bubble { background: #005c4b; }

/* Tail for incoming */
.wa-message--in .wa-bubble::before {
  content: ''; position: absolute; top: 0; left: -8px;
  border: 8px solid transparent; border-right-color: #fff; border-top-color: #fff;
  border-top-width: 0; border-right-width: 8px;
}
[data-theme="dark"] .wa-message--in .wa-bubble::before {
  border-right-color: #202c33;
}
/* Tail for outgoing */
.wa-message--out .wa-bubble::after {
  content: ''; position: absolute; top: 0; right: -8px;
  border: 8px solid transparent; border-left-color: #d9fdd3; border-top-color: #d9fdd3;
  border-top-width: 0; border-left-width: 8px;
}
[data-theme="dark"] .wa-message--out .wa-bubble::after {
  border-left-color: #005c4b;
}

/* Add a small top margin when same sender continues */
.wa-message + .wa-message--in,
.wa-message + .wa-message--out { margin-top: 1px; }
.wa-message--in + .wa-message--out,
.wa-message--out + .wa-message--in { margin-top: 8px; }

/* Message text */
.wa-msg-text {
  font-size: 14.2px; line-height: 20px;
  color: #111b21; white-space: pre-wrap;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}
[data-theme="dark"] .wa-msg-text { color: #e9edef; }
.wa-msg-text a { color: #027eb5; text-decoration: none; }
.wa-msg-text a:hover { text-decoration: underline; }
.wa-msg-text code { font-family: monospace; background: rgba(0,0,0,.06); border-radius: 3px; padding: 1px 4px; font-size: 13px; }
[data-theme="dark"] .wa-msg-text code { background: rgba(255,255,255,.08); }

/* Meta (time + ticks) */
.wa-msg-meta {
  display: flex; align-items: center; gap: 4px;
  justify-content: flex-end; margin-top: 2px;
}
.wa-msg-time { font-size: 11px; color: #667781; white-space: nowrap; }
[data-theme="dark"] .wa-msg-time { color: rgba(233,237,239,.6); }
.wa-msg-check { font-size: 11px; color: #53bdeb; }

/* Quoted message */
.wa-quoted {
  border-left: 3px solid #25d366; padding: 4px 8px;
  margin-bottom: 6px; border-radius: 0 4px 4px 0;
  background: rgba(0,0,0,.04); cursor: pointer;
}
[data-theme="dark"] .wa-quoted { background: rgba(255,255,255,.06); }
.wa-quoted-sender { font-size: 11.5px; font-weight: 600; color: #25d366; margin-bottom: 2px; }
.wa-quoted-body { font-size: 12.5px; color: #667781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
[data-theme="dark"] .wa-quoted-body { color: #8696a0; }

/* Media */
.wa-msg-media { margin-bottom: 4px; border-radius: 6px; overflow: hidden; }
.wa-msg-media img { max-width: 280px; display: block; cursor: pointer; border-radius: 6px; }
.wa-msg-media img:hover { opacity: .92; }
.wa-msg-media video { max-width: 280px; display: block; border-radius: 6px; }
.wa-msg-audio audio { width: 220px; height: 36px; }
.wa-msg-doc {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; background: rgba(0,0,0,.05); border-radius: 6px;
  font-size: 13px; margin-bottom: 4px;
}
[data-theme="dark"] .wa-msg-doc { background: rgba(255,255,255,.06); }
.wa-msg-doc i { color: #667781; font-size: 16px; }
.wa-msg-doc a { color: #027eb5; text-decoration: none; }
.wa-msg-doc a:hover { text-decoration: underline; }
.wa-msg-media-placeholder {
  font-size: 13px; color: #667781; padding: 4px 0; margin-bottom: 4px;
}

/* Reply button (visible on hover) */
.wa-msg-reply-btn {
  position: absolute; top: 50%; right: -30px;
  transform: translateY(-50%);
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(255,255,255,.9); border: none;
  color: #54656f; font-size: 11px; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
  transition: background 0.15s;
}
.wa-message--out .wa-msg-reply-btn { right: auto; left: -30px; }
.wa-message:hover .wa-msg-reply-btn { display: flex; }
.wa-msg-reply-btn:hover { background: #fff; color: #111b21; }
[data-theme="dark"] .wa-msg-reply-btn { background: rgba(32,44,51,.9); color: #aebac1; }
[data-theme="dark"] .wa-msg-reply-btn:hover { background: #2a3942; color: #e9edef; }

/* ── Input Bar ── */
.wa-input-bar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 16px 12px;
  background: #f0f2f5;
  border-top: 1px solid #e9edef;
  flex-shrink: 0;
}
[data-theme="dark"] .wa-input-bar { background: #202c33; border-top-color: #2a3942; }
.wa-input-wrap { flex: 1; display: flex; }
.wa-textarea {
  flex: 1; padding: 9px 14px;
  border: none; border-radius: 20px;
  background: #fff; color: #111b21;
  font-size: 14.5px; line-height: 20px;
  font-family: inherit; resize: none; outline: none;
  max-height: 120px; min-height: 40px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
[data-theme="dark"] .wa-textarea { background: #2a3942; color: #e9edef; }
.wa-textarea::placeholder { color: #8696a0; }
.wa-send-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: none; background: #25d366; color: #fff;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; font-size: 17px;
  flex-shrink: 0; transition: background 0.15s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(37,211,102,.4);
}
.wa-send-btn:hover { background: #22c55e; transform: scale(1.06); }
.wa-send-btn:active { transform: scale(.95); }
.wa-send-btn:disabled { background: #9ca3af; box-shadow: none; cursor: not-allowed; transform: none; }

/* Highlight animation for scrollToMessage */
.wa-message--highlight .wa-bubble {
  animation: waMsgHighlight 1.4s ease;
}
@keyframes waMsgHighlight {
  0%,100% { box-shadow: 0 1px 2px rgba(0,0,0,.12); }
  30%      { box-shadow: 0 0 0 4px rgba(37,211,102,.4); }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .wa-layout { position: relative; }
  .wa-sidebar {
    position: absolute; top: 0; left: 0; bottom: 0;
    width: 100%; max-width: 100%; z-index: 20;
    transition: transform .25s ease;
  }
  .wa-sidebar--hidden { transform: translateX(-100%); }
  .wa-message { max-width: 82%; }
  .wa-msg-reply-btn { display: flex !important; right: -28px; }
  .wa-message--out .wa-msg-reply-btn { right: auto; left: -28px; }
}
@media (max-width: 480px) {
  .wa-qr-card-body { flex-direction: column; align-items: center; padding: 20px 16px; }
  .wa-qr-box { width: 200px; height: 200px; }
  .wa-qr-instructions { text-align: center; }
  .wa-qr-instructions ol { text-align: left; }
}

/* ============================================
   SCROLL-TO-BOTTOM FAB
   ============================================ */
.wa-scroll-fab {
  position: absolute;
  bottom: 82px;
  right: 18px;
  z-index: 40;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 2px 12px rgba(11,20,26,0.22), 0 1px 4px rgba(11,20,26,0.12);
  color: #667781;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  opacity: 0.93;
}
.wa-scroll-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 18px rgba(11,20,26,0.28);
  opacity: 1;
}
.wa-scroll-fab-badge {
  position: absolute;
  top: -5px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background: #25d366;
  color: #fff;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}
[data-theme="dark"] .wa-scroll-fab {
  background: #2a3942;
  color: #aebac1;
}

/* Ensure chat main area has relative positioning for the FAB */
.whatsapp-main {
  position: relative;
}

/* ============================================
   STICKY DATE DIVIDERS
   ============================================ */
.whatsapp-date-divider {
  top: 6px;
  z-index: 10;
  /* existing styles are already in the file — this just adds sticky */
}

/* ============================================
   RIGHE DI SISTEMA (chiamate, crittografia, eventi gruppo, in-attesa)
   ============================================ */
.wa-app .wa-msg-wrap.system {
  display: flex;
  justify-content: center;
  margin: 6px 0;
}
.wa-app .wa-system-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 80%;
  padding: 5px 12px;
  border-radius: 8px;
  background: #ffffffcc;
  color: #54656f;
  font-size: 0.78rem;
  box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}
.wa-app .wa-system-row i {
  font-size: 0.72rem;
  color: #8696a0;
}
.wa-app .wa-system-row .wa-system-row-time {
  margin-left: 6px;
  font-size: 0.68rem;
  color: #8696a0;
}
[data-theme="dark"] .wa-app .wa-system-row {
  background: #182229cc;
  color: #aebac1;
  box-shadow: 0 1px 1px rgba(0,0,0,0.3);
}
[data-theme="dark"] .wa-app .wa-system-row i,
[data-theme="dark"] .wa-app .wa-system-row .wa-system-row-time {
  color: #8696a0;
}

/* Bottone CTA dei messaggi interattivi (annunci WhatsApp) */
.wa-app .wa-interactive-cta {
  display: block;
  margin-top: 8px;
  padding: 7px 10px;
  border-top: 1px solid rgba(134,150,160,0.25);
  text-align: center;
  color: #00a884;
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
}
.wa-app a.wa-interactive-cta:hover {
  text-decoration: underline;
}
[data-theme="dark"] .wa-app .wa-interactive-cta {
  color: #00a884;
  border-top-color: rgba(134,150,160,0.35);
}

/* Riquadro freno anti-spam sopra la barra di input */
.wa-app .wa-spam-cooldown {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 12px 4px;
  padding: 9px 12px;
  background: #fef3cd;
  border: 1px solid #f0d58c;
  border-radius: 10px;
  color: #7a5d00;
  font-size: 0.8rem;
  line-height: 1.35;
}
.wa-app .wa-spam-cooldown i {
  color: #d97706;
  flex-shrink: 0;
}
[data-theme="dark"] .wa-app .wa-spam-cooldown {
  background: #3a3117;
  border-color: #6b5a1e;
  color: #e8d48b;
}

/* Menzioni @nome nelle bolle (stile WhatsApp) */
.wa-app .wa-mention {
  color: #00a884;
  font-weight: 500;
  cursor: default;
}
[data-theme="dark"] .wa-app .wa-mention {
  color: #53bdeb;
}

/* ============================================
   BUBBLE MAX-WIDTH — clamp for large screens
   ============================================ */
/* clamp spostato su .wa-app .wa-msg (qui perdeva sempre per specificita') */

/* ============================================
   TYPING INDICATOR IN HEADER
   ============================================ */
.wa-hdr-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #25d366;
  font-size: 12px;
  font-weight: 500;
}
.wa-hdr-typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #25d366;
  animation: wa-hdr-typing-bounce 1.2s ease-in-out infinite;
}
.wa-hdr-typing-dot:nth-child(1) { animation-delay: 0s; }
.wa-hdr-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.wa-hdr-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes wa-hdr-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ===================================
   CHAT.JS REBUILD — WhatsApp Web UI
   REGOLA: ogni selettore è scoped sotto
   .wa-app così vince i conflitti con il
   vecchio CSS (cascade: specificity > order)
   =================================== */

/* ── ROOT ─────────────────────────── */
.wa-app {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;       /* parent è #main-content.fullscreen con height fissa */
  overflow: hidden;
  background: #fff;
  font-family: inherit;
  position: relative; /* ancora per la maniglia di resize della sidebar */
}
[data-theme="dark"] .wa-app { background: #0b141a; }

/* ── Maniglia ridimensionamento colonna conversazioni ── */
.wa-app .wa-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 9px;
  margin-left: -4px;            /* centrata sul bordo destro della sidebar */
  cursor: col-resize;
  z-index: 30;
  background: transparent;
  touch-action: none;
}
.wa-app .wa-resize-handle::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 1px;
  background: transparent;
  transition: width 0.12s ease, background 0.12s ease;
}
.wa-app .wa-resize-handle:hover::after,
.wa-app .wa-resize-handle.resizing::after {
  width: 3px;
  background: #25d366;
}
@media (max-width: 768px) {
  .wa-app .wa-resize-handle { display: none; }
}

/* ── SIDEBAR ───────────────────────── */
.wa-app .wa-sidebar {
  width: 380px;
  /* Da computer la colonna non scende sotto i 360px: sotto quella misura i pulsanti in cima
     (WhatsApp, modelli, menu, programmati, stato, nuova chat) si stringono e alcuni escono fuori. */
  min-width: 360px;
  max-width: 460px;
  height: 100%;
  background: #fff;
  border-right: 1px solid #e9edef;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}
[data-theme="dark"] .wa-app .wa-sidebar { background: #111b21; border-right-color: #2a3942; }

.wa-app .wa-sidebar-header {
  height: 56px; min-height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 0 12px;
  background: #f0f2f5; border-bottom: 1px solid #e9edef; flex-shrink: 0;
}
[data-theme="dark"] .wa-app .wa-sidebar-header { background: #202c33; border-bottom-color: #2a3942; }
.wa-app .wa-sidebar-header-left {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; overflow: hidden;
}
.wa-app .wa-sidebar-header-actions { display: flex; gap: 2px; flex-shrink: 0; }
.wa-app .wa-sidebar-title {
  font-weight: 600; font-size: 15px; color: #111b21;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
[data-theme="dark"] .wa-app .wa-sidebar-title { color: #e9edef; }
.wa-app .wa-sidebar-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: #25d366; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0;
}

/* icon-btn scoped — vince l'old definition */
.wa-app .wa-icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: transparent; color: #54656f; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; transition: background 0.15s; flex-shrink: 0;
}
.wa-app .wa-icon-btn:hover { background: rgba(11,20,26,.08); }
[data-theme="dark"] .wa-app .wa-icon-btn { color: #aebac1; }
[data-theme="dark"] .wa-app .wa-icon-btn:hover { background: rgba(255,255,255,.08); }

/* search */
.wa-app .wa-search-bar { padding: 6px 12px 8px; background: #fff; flex-shrink: 0; }
[data-theme="dark"] .wa-app .wa-search-bar { background: #1f2c34; }
.wa-app .wa-search-input-wrap { position: relative; display: flex; align-items: center; }
.wa-app .wa-search-icon { position: absolute; left: 10px; color: #54656f; font-size: 12px; pointer-events: none; }
[data-theme="dark"] .wa-app .wa-search-icon { color: #8696a0; }
.wa-app .wa-search-input {
  width: 100%; padding: 8px 32px 8px 30px; border: none; border-radius: 8px;
  background: #f0f2f5; color: #111b21; font-size: 14px; outline: none; line-height: 1.3;
}
[data-theme="dark"] .wa-app .wa-search-input { background: #2a3942; color: #e9edef; }
.wa-app .wa-search-input::placeholder { color: #8696a0; font-size: 13.5px; }
.wa-app .wa-search-clear {
  position: absolute; right: 8px; border: none; background: transparent;
  color: #8696a0; cursor: pointer; font-size: 12px; padding: 2px;
  display: flex; align-items: center; justify-content: center;
}

/* pulsante FILTRA nella barra di ricerca + finestrella dei filtri (data / stato / etichette) */
.wa-app .wa-search-bar > .wa-search-input-wrap { flex: 1; min-width: 0; }
.wa-app .wa-search-bar { display: flex; align-items: center; gap: 6px; }
.wa-app .wa-search-filter {
  position: relative; flex: 0 0 auto; width: 32px; height: 32px; border: none; border-radius: 8px;
  background: #f0f2f5; color: #54656f; cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center; transition: background .15s, color .15s;
}
.wa-app .wa-search-filter:hover { background: #e4e7ea; }
.wa-app .wa-search-filter.active { background: #e7fcee; color: #00a884; }
[data-theme="dark"] .wa-app .wa-search-filter { background: #2a3942; color: #8696a0; }
[data-theme="dark"] .wa-app .wa-search-filter.active { background: rgba(0,168,132,.18); color: #00a884; }
.wa-app .wa-search-filter-dot {
  position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%;
  background: #f59e0b; box-shadow: 0 0 0 2px #fff;
}
[data-theme="dark"] .wa-app .wa-search-filter-dot { box-shadow: 0 0 0 2px #1f2c34; }
.wa-chat-filter-popup {
  background: #fff; border: 1px solid #e9edef; border-radius: 12px;
  box-shadow: 0 10px 34px rgba(0,0,0,.18); animation: contextMenuFadeIn .15s ease; font-size: 13px;
}
[data-theme="dark"] .wa-chat-filter-popup { background: #1f2c34; border-color: #2a3942; color: #e9edef; }
.wa-chat-filter-popup .wa-cf-sez { padding: 9px 12px; border-bottom: 1px solid #f3f4f6; }
[data-theme="dark"] .wa-chat-filter-popup .wa-cf-sez { border-bottom-color: #2a3942; }
.wa-chat-filter-popup .wa-cf-tit {
  font-size: .64rem; font-weight: 700; color: #9ca3af; text-transform: uppercase;
  letter-spacing: .5px; margin-bottom: 7px;
}
.wa-chat-filter-popup .wa-cf-lbl { display: block; font-size: .66rem; color: #6b7280; margin-bottom: 2px; }
[data-theme="dark"] .wa-chat-filter-popup .wa-cf-lbl { color: #8696a0; }
.wa-chat-filter-popup .wa-cf-input {
  width: 100%; padding: 5px 7px; margin-bottom: 7px; border: 1px solid #d1d5db; border-radius: 7px;
  font-size: .74rem; color: #374151; background: #fff; box-sizing: border-box;
}
[data-theme="dark"] .wa-chat-filter-popup .wa-cf-input { background: #2a3942; border-color: #3b4a54; color: #e9edef; }
.wa-chat-filter-popup .wa-cf-stati { display: flex; gap: 6px; }
.wa-chat-filter-popup .wa-cf-stato {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: 5px 4px; border: 1px solid #e5e7eb; border-radius: 8px; background: #fff;
  color: #6b7280; font-size: .71rem; cursor: pointer; white-space: nowrap;
}
.wa-chat-filter-popup .wa-cf-stato.sel { border-color: #00a884; background: #e7fcee; color: #00795c; font-weight: 700; }
[data-theme="dark"] .wa-chat-filter-popup .wa-cf-stato { background: #2a3942; border-color: #3b4a54; color: #8696a0; }
[data-theme="dark"] .wa-chat-filter-popup .wa-cf-stato.sel { background: rgba(0,168,132,.18); color: #25d366; border-color: #00a884; }
.wa-chat-filter-popup .wa-cf-etichetta {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 5px 7px; margin-bottom: 2px;
  border: none; border-radius: 7px; background: transparent; cursor: pointer; text-align: left;
  font-size: .78rem; color: #374151;
}
[data-theme="dark"] .wa-chat-filter-popup .wa-cf-etichetta { color: #e9edef; }
.wa-chat-filter-popup .wa-cf-etichetta:hover { background: rgba(0,0,0,.05); }
.wa-chat-filter-popup .wa-cf-etichetta .wa-cf-spunta { display: none; color: #00a884; font-size: .72rem; }
.wa-chat-filter-popup .wa-cf-etichetta.sel { background: rgba(0,168,132,.12); font-weight: 700; }
.wa-chat-filter-popup .wa-cf-etichetta.sel .wa-cf-spunta { display: inline; }
.wa-chat-filter-popup .wa-cf-pallino { width: 13px; height: 13px; border-radius: 4px; flex: 0 0 auto; }
.wa-chat-filter-popup .wa-cf-nome { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-chat-filter-popup .wa-cf-vuoto { padding: 10px; text-align: center; color: #9ca3af; font-size: .76rem; }
/* OBBLIGATORIA: .wa-cf-etichetta e' display:flex e batterebbe il nascondimento del browser,
   quindi senza questa riga le etichette escluse dalla ricerca resterebbero a schermo */
.wa-chat-filter-popup [hidden] { display: none !important; }
.wa-chat-filter-popup .wa-cf-tit-riga { display: flex; align-items: center; gap: 6px; }
.wa-chat-filter-popup .wa-cf-tit-testo { flex: 1; min-width: 0; }
.wa-chat-filter-popup .wa-cf-conta {
  background: #00a884; color: #fff; border-radius: 9px; min-width: 16px; padding: 0 5px;
  line-height: 16px; font-size: .62rem; text-align: center; font-weight: 700;
}
.wa-chat-filter-popup .wa-cf-lente {
  border: none; background: transparent; color: #6b7280; cursor: pointer;
  padding: 2px 5px; border-radius: 6px; font-size: .74rem; line-height: 1;
}
.wa-chat-filter-popup .wa-cf-lente:hover { background: rgba(0,0,0,.06); }
.wa-chat-filter-popup .wa-cf-lente.on { color: #00a884; background: rgba(0,168,132,.12); }
.wa-chat-filter-popup .wa-cf-cerca { margin-bottom: 6px; }
.wa-chat-filter-popup .wa-cf-etichette { max-height: 190px; overflow-y: auto; }
[data-theme="dark"] .wa-chat-filter-popup .wa-cf-lente { color: #8696a0; }
[data-theme="dark"] .wa-chat-filter-popup .wa-cf-lente:hover { background: rgba(255,255,255,.08); }
/* pallino del filtro che diventa pillola col numero quando le etichette sono piu' d'una */
.wa-app .wa-search-filter-dot.wa-conta {
  width: auto; min-width: 13px; height: 13px; border-radius: 7px; padding: 0 3px;
  font-size: 8px; line-height: 13px; font-weight: 700; color: #fff; text-align: center; background: #f59e0b;
}
.wa-chat-filter-popup .wa-cf-piede { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 12px; }
.wa-cf-btn, .wa-cf-btn-ghost {
  padding: 6px 14px; border-radius: 8px; font-size: .78rem; font-weight: 600; cursor: pointer; border: none;
}
.wa-cf-btn { background: #00a884; color: #fff; }
.wa-cf-btn:hover { background: #017561; }
.wa-cf-btn-ghost { background: transparent; color: #6b7280; border: 1px solid #e5e7eb; }
.wa-cf-btn-ghost:hover { background: rgba(0,0,0,.04); }
[data-theme="dark"] .wa-cf-btn-ghost { color: #8696a0; border-color: #3b4a54; }

/* filter chips */
.wa-app .wa-filters {
  display: flex; gap: 6px; padding: 4px 12px 8px;
  background: #fff; border-bottom: 1px solid #e9edef;
  flex-shrink: 0; overflow-x: auto; scrollbar-width: none;
}
.wa-app .wa-filters::-webkit-scrollbar { display: none; }
[data-theme="dark"] .wa-app .wa-filters { background: #1f2c34; border-bottom-color: rgba(233,237,239,.08); }
.wa-app .wa-filter-chip {
  padding: 5px 14px; border-radius: 16px; background: #f0f2f5; border: none;
  color: #54656f; font-size: 12.5px; font-weight: 500; cursor: pointer;
  white-space: nowrap; transition: background 0.15s, color 0.15s;
}
.wa-app .wa-filter-chip:hover { background: #e9edef; }
.wa-app .wa-filter-chip.active { background: #e7fcee; color: #00a884; font-weight: 600; }
[data-theme="dark"] .wa-app .wa-filter-chip { background: rgba(255,255,255,.06); color: #8696a0; }
[data-theme="dark"] .wa-app .wa-filter-chip.active { background: rgba(0,168,132,.15); color: #00a884; }

/* folder tabs */
.wa-app .wsp-folder-tabs {
  padding: 6px 12px 0; border-bottom: 1px solid #e9edef;
  background: #fff; flex-shrink: 0; overflow: visible;
}
.wa-app .wsp-folder-tabs > div::-webkit-scrollbar { display: none; }
/* barra cartelle: elenco scorrevole + frecce che compaiono solo quando serve */
.wa-app .wsp-folder-bar { display: flex; align-items: center; gap: 6px; padding-bottom: 6px; }
.wa-app .wsp-folder-scroll {
  display: flex; gap: 6px; align-items: center; overflow-x: auto; scroll-behavior: smooth;
  flex: 1; min-width: 0; scrollbar-width: none; overscroll-behavior-x: contain;
}
.wa-app .wsp-folder-scroll::-webkit-scrollbar { display: none; }
.wa-app .wsp-folder-arrow {
  display: flex; align-items: center; justify-content: center; width: 22px; height: 24px;
  border: none; border-radius: 6px; background: rgba(0,0,0,.05); color: #54656f;
  cursor: pointer; font-size: .7rem; flex: 0 0 auto;
}
.wa-app .wsp-folder-arrow:hover { background: rgba(0,0,0,.12); }
[data-theme="dark"] .wa-app .wsp-folder-arrow { background: rgba(255,255,255,.08); color: #8696a0; }
[data-theme="dark"] .wa-app .wsp-folder-tabs { background: #1f2c34; border-bottom-color: rgba(233,237,239,.08); }
.wa-app .wsp-folder-tab {
  display: flex; align-items: center; gap: 6px; padding: 5px 12px;
  border: none; border-radius: 6px; font-size: 0.8rem; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: background 0.15s, color 0.15s;
  background: transparent; color: #667781; flex-shrink: 0;
}
.wa-app .wsp-folder-tab:hover { background: #f0f2f5; }
.wa-app .wsp-folder-tab.active { background: #e7fcee; color: #00a884; font-weight: 600; }
[data-theme="dark"] .wa-app .wsp-folder-tab { color: #8696a0; }
[data-theme="dark"] .wa-app .wsp-folder-tab:hover { background: rgba(255,255,255,.06); }
[data-theme="dark"] .wa-app .wsp-folder-tab.active { background: rgba(0,168,132,.15); color: #00a884; }
.wa-app .wsp-folder-new-btn {
  display: flex; align-items: center; justify-content: center; padding: 5px 10px;
  border: 1px dashed #d1d5db; border-radius: 6px; background: transparent;
  cursor: pointer; font-size: 0.8rem; color: #9ca3af; flex-shrink: 0; transition: 0.15s;
}
.wa-app .wsp-folder-new-btn:hover { border-color: #25d366; color: #25d366; }

/* bulk bar */
.wa-app .wa-bulk-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: #25d366; color: #fff; flex-shrink: 0;
}
.wa-app .wa-bulk-bar .wa-icon-btn { color: #fff !important; }
.wa-app .wa-bulk-bar .wa-icon-btn:hover { background: rgba(255,255,255,.2) !important; }
.wa-app .wa-bulk-actions { display: flex; gap: 4px; margin-left: auto; }
.wa-app #wa-bulk-count { flex: 1; font-size: 14px; font-weight: 600; }

/* chat list */
.wa-app .wa-chat-list { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.wa-app .wa-chat-list::-webkit-scrollbar { width: 4px; }
.wa-app .wa-chat-list::-webkit-scrollbar-thumb { background: rgba(134,150,160,.3); border-radius: 2px; }
.wa-app .wa-chat-list-loading { display: flex; justify-content: center; padding: 24px; }
/* Sentinel infinite-scroll: altezza minima così rientra nello scrollHeight ed è raggiungibile */
.wa-app .wa-chat-list-sentinel { min-height: 8px; }
.wa-app .wa-empty-list {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 20px; color: #8696a0; gap: 10px;
}
.wa-app .wa-empty-list i { font-size: 40px; opacity: 0.4; }
.wa-app .wa-empty-list p { font-size: 14px; margin: 0; }
/* Indicatore "sincronizzazione conversazioni" mentre motore WhatsApp popola la lista dopo il QR */
.wa-app .wa-chat-list-syncing {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 12px; color: #8696a0; font-size: 13px;
}
.wa-app .wa-chat-list-syncing .wa-spinner { width: 18px; height: 18px; border-width: 2px; }
.wa-app .wa-list-syncing-full {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 20px; color: #8696a0; gap: 14px; text-align: center;
}
.wa-app .wa-list-syncing-full p { font-size: 14px; margin: 0; }

/* chat item */
.wa-app .wa-chat-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  cursor: pointer; border-bottom: 1px solid rgba(134,150,160,.12);
  transition: background 0.1s; user-select: none; position: relative;
}
.wa-app .wa-chat-item:hover { background: #f5f6f6; }
.wa-app .wa-chat-item.active { background: #f0f2f5; }
[data-theme="dark"] .wa-app .wa-chat-item:hover { background: #182229; }
[data-theme="dark"] .wa-app .wa-chat-item.active { background: #2a3942; }
.wa-app .wa-chat-item.selected { background: #d9fdd3 !important; }
[data-theme="dark"] .wa-app .wa-chat-item.selected { background: #0d2b22 !important; }

/* avatar in chat-item: 48px (override vecchio .wa-chat-avatar da 40px) */
.wa-app .wa-chat-item .wa-chat-avatar {
  width: 48px !important; height: 48px !important; border-radius: 50%;
  overflow: hidden; flex-shrink: 0; background: #e9edef;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff;
  position: relative; /* le iniziali e l'immagine si sovrappongono in assoluto */
}
.wa-app .wa-chat-avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.wa-app .wa-chat-avatar-initials {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff; background: #25d366; border-radius: 50%;
}
[data-theme="dark"] .wa-app .wa-chat-avatar-initials { background: #00a884; }
/* Nel chat-item iniziali (sotto) e immagine (sopra) si sovrappongono: se l'img va in errore
   e si nasconde, riappaiono le iniziali sottostanti invece di un cerchio vuoto. */
.wa-app .wa-chat-item .wa-chat-avatar-initials,
.wa-app .wa-chat-item .wa-chat-avatar-img { position: absolute; inset: 0; }

/* chat item info */
.wa-app .wa-chat-info { flex: 1; min-width: 0; }
.wa-app .wa-chat-row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.wa-app .wa-chat-row2 { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 2px; }
.wa-app .wa-chat-item .wa-chat-name {
  font-size: 14.5px; font-weight: 600; color: #111b21;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
[data-theme="dark"] .wa-app .wa-chat-item .wa-chat-name { color: #e9edef; }
.wa-app .wa-chat-time { font-size: 11px; color: #8696a0; flex-shrink: 0; }
.wa-app .wa-chat-snippet {
  font-size: 13px; color: #667781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
[data-theme="dark"] .wa-app .wa-chat-snippet { color: #8696a0; }
.wa-app .wa-no-msg { color: #aaa; font-style: italic; font-size: 12px; }
.wa-app .wa-unread-badge {
  background: #25d366; color: #fff; border-radius: 10px; min-width: 18px; height: 18px;
  padding: 0 5px; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.wa-app .wa-chat-checkbox {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid #8696a0;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: transparent; font-size: 11px; transition: all 0.15s;
}
.wa-app .wa-chat-checkbox.checked { background: #25d366; border-color: #25d366; color: #fff; }

/* ── MAIN AREA ─────────────────────── */
.wa-app .wa-main {
  flex: 1; height: 100%; display: flex; flex-direction: column;
  overflow: hidden; position: relative; background: #fff; min-width: 0;
}
[data-theme="dark"] .wa-app .wa-main { background: #0b141a; }

.wa-app .wa-empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; background: #f8f9fa; color: #8696a0; text-align: center; gap: 16px; padding: 40px;
}
[data-theme="dark"] .wa-app .wa-empty-state { background: #111b21; }
.wa-app .wa-empty-icon { font-size: 72px; color: #25d366; opacity: 0.6; line-height: 1; }
.wa-app .wa-empty-state h2 { margin: 0; font-size: 1.4rem; font-weight: 400; color: #41525d; }
[data-theme="dark"] .wa-app .wa-empty-state h2 { color: #aebac1; }
.wa-app .wa-empty-state p { margin: 0; font-size: 14px; }

/* ── CHAT HEADER ───────────────────── */
.wa-app .wa-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 0 12px; height: 56px; min-height: 56px; flex-shrink: 0;
  background: #f0f2f5; border-bottom: 1px solid #e9edef; position: relative;
}
[data-theme="dark"] .wa-app .wa-header { background: #202c33; border-bottom-color: #2a3942; }
.wa-app .wa-header-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.wa-app .wa-header-actions { display: flex; gap: 2px; flex-shrink: 0; }
.wa-app .wa-header-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #dfe5e7; color: #fff;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0; font-size: 15px;
}
.wa-app .wa-header-info { flex: 1; min-width: 0; }
.wa-app .wa-header-name {
  font-size: 15px; font-weight: 600; color: #111b21;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2;
}
[data-theme="dark"] .wa-app .wa-header-name { color: #e9edef; }
.wa-app .wa-header-sub {
  font-size: 12px; color: #667781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2;
}
[data-theme="dark"] .wa-app .wa-header-sub { color: #8696a0; }
.wa-app .wa-mobile-back { display: none; }

.wa-app .wa-header-dropdown {
  position: absolute; right: 8px; top: 56px; background: #fff;
  border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,.18);
  min-width: 200px; overflow: hidden; z-index: 999;
}
[data-theme="dark"] .wa-app .wa-header-dropdown { background: #233138; }
.wa-app .wa-hdr-item { padding: 10px 16px; cursor: pointer; font-size: 13.5px; color: #111b21; transition: background 0.1s; }
.wa-app .wa-hdr-item:hover { background: #f5f6f6; }
[data-theme="dark"] .wa-app .wa-hdr-item { color: #e9edef; }
[data-theme="dark"] .wa-app .wa-hdr-item:hover { background: #2a3942; }

.wa-app .wa-msg-search-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: #fff; border-bottom: 1px solid #e9edef; flex-shrink: 0;
}
[data-theme="dark"] .wa-app .wa-msg-search-bar { background: #202c33; border-bottom-color: #2a3942; }
.wa-app .wa-msg-search-input {
  flex: 1; padding: 7px 12px; border: none; border-radius: 8px;
  background: #f0f2f5; color: #111b21; font-size: 14px; outline: none;
}
[data-theme="dark"] .wa-app .wa-msg-search-input { background: #2a3942; color: #e9edef; }
.wa-app .wa-msg-search-count { font-size: 12px; color: #667781; min-width: 38px; text-align: center; white-space: nowrap; }
[data-theme="dark"] .wa-app .wa-msg-search-count { color: #8696a0; }

/* Calendario conversazione */
/* Calendario conversazione: riempie tutta la finestra (prima restava una colonnina
   stretta al centro con meta' spazio vuoto ai lati) */
.wa-cal { width: 100%; max-width: none; min-width: 0; }
.wa-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.wa-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.wa-cal-wd { text-align: center; font-size: 11px; font-weight: 600; color: #8696a0; padding: 4px 0; }
.wa-cal-cell {
  position: relative; aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; font-size: 13px; color: #111b21; user-select: none;
}
[data-theme="dark"] .wa-cal-cell { color: #e9edef; }
.wa-cal-cell.empty { visibility: hidden; }
.wa-cal-cell.has-msgs { background: rgba(37,211,102,.14); cursor: pointer; font-weight: 600; }
.wa-cal-cell.has-msgs:hover { background: rgba(37,211,102,.3); }
.wa-cal-badge {
  position: absolute; top: 2px; right: 3px; background: #25d366; color: #fff;
  font-size: 9px; line-height: 1; padding: 2px 4px; border-radius: 8px; font-weight: 700;
}
.wa-cal-day { margin-top: 14px; }
.wa-cal-day-head { font-size: 13px; font-weight: 600; color: #111b21; margin-bottom: 8px; text-transform: capitalize; }
[data-theme="dark"] .wa-cal-day-head { color: #e9edef; }
.wa-cal-msglist { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.wa-cal-msg { display: flex; flex-direction: column; gap: 2px; padding: 6px 9px; border-radius: 8px; background: #f0f2f5; }
.wa-cal-msg.out { background: rgba(37,211,102,.12); align-self: flex-end; max-width: 85%; }
.wa-cal-msg.in { align-self: flex-start; max-width: 85%; }
[data-theme="dark"] .wa-cal-msg { background: #2a3942; }
[data-theme="dark"] .wa-cal-msg.out { background: rgba(37,211,102,.18); }
.wa-cal-msg-meta { font-size: 10.5px; color: #8696a0; }
.wa-cal-msg-body { font-size: 13px; color: #111b21; word-break: break-word; }
[data-theme="dark"] .wa-cal-msg-body { color: #e9edef; }
/* Finestra larga: mese a sinistra e messaggi del giorno a destra, cosi' lo spazio e' tutto usato */
@media (min-width: 760px) {
  .wa-cal {
    display: grid; align-items: start; gap: 4px 22px;
    grid-template-columns: minmax(300px, 1fr) minmax(280px, 1fr);
    grid-template-areas: "head day" "grid day";
  }
  .wa-cal-head { grid-area: head; }
  .wa-cal-grid { grid-area: grid; gap: 6px; }
  .wa-cal-day { grid-area: day; margin-top: 0; border-left: 1px solid #e9edef; padding-left: 18px; min-height: 320px; }
  [data-theme="dark"] .wa-cal-day { border-left-color: #2a3942; }
  .wa-cal-msglist { max-height: 52vh; }
  .wa-cal-cell { font-size: 14px; }
}
.wa-cal-empty { color: #8696a0; font-size: 13px; text-align: center; padding: 26px 10px; }

/* ── MESSAGES — padding:0 annulla il vecchio CSS ─── */
.wa-app .wa-messages {
  display: block !important;
  flex: 1 1 0% !important;
  height: 0 !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden;
  overflow-anchor: none; /* previene scroll-anchoring automatico del browser */
  scroll-behavior: auto !important; /* disabilita smooth-scroll: evita interferenze con JS scroll */
  padding: 0 !important;
  position: relative;
  -webkit-overflow-scrolling: touch;
  background-color: #e5ddd5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Cg fill='none' stroke='%23c9bfb5' stroke-width='0.6' opacity='0.5'%3E%3Ccircle cx='20' cy='20' r='6'/%3E%3Ccircle cx='60' cy='60' r='6'/%3E%3Ccircle cx='60' cy='20' r='6'/%3E%3Ccircle cx='20' cy='60' r='6'/%3E%3Cpath d='M14 20 Q20 10 26 20 Q20 30 14 20Z'/%3E%3Cpath d='M54 60 Q60 50 66 60 Q60 70 54 60Z'/%3E%3Cpath d='M54 20 Q60 10 66 20 Q60 30 54 20Z'/%3E%3Cpath d='M14 60 Q20 50 26 60 Q20 70 14 60Z'/%3E%3C/g%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 80px 80px;
}
[data-theme="dark"] .wa-app .wa-messages {
  background-color: #0b141a;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Cg fill='none' stroke='%231a2c35' stroke-width='0.8' opacity='0.6'%3E%3Ccircle cx='20' cy='20' r='6'/%3E%3Ccircle cx='60' cy='60' r='6'/%3E%3Ccircle cx='60' cy='20' r='6'/%3E%3Ccircle cx='20' cy='60' r='6'/%3E%3Cpath d='M14 20 Q20 10 26 20 Q20 30 14 20Z'/%3E%3Cpath d='M54 60 Q60 50 66 60 Q60 70 54 60Z'/%3E%3Cpath d='M54 20 Q60 10 66 20 Q60 30 54 20Z'/%3E%3Cpath d='M14 60 Q20 50 26 60 Q20 70 14 60Z'/%3E%3C/g%3E%3C/svg%3E");
}
.wa-app .wa-messages::-webkit-scrollbar { width: 5px; }
.wa-app .wa-messages::-webkit-scrollbar-thumb { background: rgba(134,150,160,.4); border-radius: 3px; }
.wa-app .wa-scroll-bottom-btn {
  position: absolute;
  right: 24px;
  bottom: 88px;
  z-index: 10;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
  color: #54656f;
  box-shadow: 0 2px 8px rgba(11, 20, 26, 0.22);
  cursor: pointer;
}

.wa-app .wa-scroll-bottom-btn:hover {
  background: #f0f2f5;
}

[data-theme="dark"] .wa-app .wa-scroll-bottom-btn {
  background: #202c33;
  color: #d1d7db;
}
.wa-app .wa-msgs-load-bar {
  height: 3px; background: linear-gradient(90deg,#25d366,#128c7e);
  overflow: hidden; position: sticky; top: 0; z-index: 5;
}
.wa-app .wa-msgs-load-bar::after {
  content: ''; position: absolute; inset: 0; background: inherit;
  animation: waBarAnim 1.2s ease-in-out infinite;
}
@keyframes waBarAnim { 0% { transform:translateX(-100%); } 100% { transform:translateX(100%); } }

/* Inner: flex container per allineare messaggi left/right */
.wa-app .wa-messages-inner {
  padding: 14px 10% 14px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 2px; /* stacco tra bolle stesso gruppo (come WhatsApp Web) */
}
@media (max-width: 900px) { .wa-app .wa-messages-inner { padding: 10px 4% 10px; } }


/* .wa-load-more-btn: stile UNICO piu' sotto ("Load more / inizio cronologia").
   La vecchia regola .wa-app .wa-load-more-btn qui vinceva per specificita' e
   rompeva il design a pillola (padding/colore diversi + underline in hover). */
.wa-app .wa-no-msgs { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 40px 20px; color: #8696a0; font-size: 13px; text-align: center; }
.wa-app .wa-no-msgs i { font-size: 28px; opacity: 0.4; }

.wa-app .whatsapp-date-divider {
  display: flex; align-items: center; justify-content: center;
  padding: 12px 0 8px;
}
.wa-app .whatsapp-date-divider span {
  background: #d1e8f5;
  color: #1a6a99;
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
  padding: 4px 14px; border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
  user-select: none;
}
[data-theme="dark"] .wa-app .whatsapp-date-divider span {
  background: rgba(17,38,50,.9);
  color: #82c4e8;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

/* bubbles — raggruppamento e code stile WhatsApp Web:
   .first = prima bolla di un blocco (coda + stacco dal blocco precedente)
   .follow = bolla consecutiva stesso mittente (attaccata, niente coda) */
.wa-app .wa-msg-wrap { display: flex; margin-bottom: 0; }
.wa-app .wa-msg-wrap.first { margin-top: 10px; }
.wa-app .wa-msg-wrap.out { justify-content: flex-end; }
.wa-app .wa-msg-wrap.in  { justify-content: flex-start; }
.wa-app .wa-msg {
  /* clamp per schermi larghi: senza il tetto a 520px le bolle diventavano
     lenzuoli su monitor wide (la vecchia regola .whatsapp-message-bubble
     perdeva sempre per specificita' contro questa) */
  max-width: min(68%, 520px); min-width: 80px; border-radius: 8px;
  padding: 6px 8px 4px; position: relative; word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,.13); margin: 0;
}
.wa-app .wa-msg.in  { background: var(--message-bg-light,#fff); align-self: flex-start; }
.wa-app .wa-msg.out { background: var(--message-out-light,#d9fdd3); align-self: flex-end; }
/* Origine invio: automazione = blu, automazione AI = viola, invio massivo = ambra
   (etichetta nel footer + colore bolla diverso dal verde manuale) */
.wa-app .wa-msg.out.wa-origin-auto  { background: #dbeafe; }
.wa-app .wa-msg.out.wa-origin-ai    { background: #ede9fe; }
.wa-app .wa-msg.out.wa-origin-bulk  { background: #fef3c7; }
.wa-app .wa-msg.out.wa-origin-sched { background: #ccfbf1; }
.wa-app .wa-msg-origin {
  display: inline-flex; align-items: center; gap: 4px; margin-right: 6px;
  font-size: 10px; font-weight: 700; letter-spacing: .2px; white-space: nowrap;
  padding: 1px 6px; border-radius: 8px; line-height: 14px;
}
.wa-app .wa-origin-auto .wa-msg-origin { color: #1d4ed8; background: rgba(29,78,216,.10); }
.wa-app .wa-origin-ai   .wa-msg-origin { color: #6d28d9; background: rgba(109,40,217,.10); }
.wa-app .wa-origin-bulk .wa-msg-origin { color: #b45309; background: rgba(180,83,9,.12); }
.wa-app .wa-origin-sched .wa-msg-origin { color: #0f766e; background: rgba(15,118,110,.12); }
[data-theme="dark"] .wa-app .wa-msg.out.wa-origin-sched { background: #124b45; }
[data-theme="dark"] .wa-app .wa-origin-sched .wa-msg-origin { color: #5eead4; background: rgba(94,234,212,.14); }
[data-theme="dark"] .wa-app .wa-msg.out.wa-origin-auto { background: #1e3a5f; }
[data-theme="dark"] .wa-app .wa-msg.out.wa-origin-ai   { background: #3b2a6b; }
[data-theme="dark"] .wa-app .wa-msg.out.wa-origin-bulk { background: #5a3d0f; }
[data-theme="dark"] .wa-app .wa-origin-auto .wa-msg-origin { color: #93c5fd; background: rgba(147,197,253,.14); }
[data-theme="dark"] .wa-app .wa-origin-ai   .wa-msg-origin { color: #c4b5fd; background: rgba(196,181,253,.14); }
[data-theme="dark"] .wa-app .wa-origin-bulk .wa-msg-origin { color: #fcd34d; background: rgba(252,211,77,.14); }
.wa-app .wa-msg-menu-btn {
 position: absolute; top: 3px; left: 3px; right: auto; z-index: 3;
  width: 28px; height: 28px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 50%; color: #54656f; background: rgba(255,255,255,.72);
  cursor: pointer;
  /* RESTA RAGGIUNGIBILE: sparisce solo 1,6 s dopo che il mouse se ne va (prima svaniva
     subito e, attraversando lo spazio fra nuvoletta e pulsante, non si faceva in tempo a
     cliccarlo). Si usa visibility, non pointer-events, cosi' resta cliccabile per tutto
     il tempo in cui si vede. */
  opacity: 0; visibility: hidden;
  transition: opacity .28s ease 1.6s, visibility 0s linear 1.9s, background .12s ease;
}
/* la zona sensibile e' l'intera RIGA del messaggio (come su WhatsApp Web): cosi' il vuoto
   fra bolla e pulsante non interrompe piu' il passaggio del mouse */
.wa-app .wa-msg-wrap:hover .wa-msg-menu-btn,
.wa-app .wa-msg:hover .wa-msg-menu-btn,
.wa-app .wa-msg:focus-within .wa-msg-menu-btn,
.wa-app .wa-msg.menu-aperto .wa-msg-menu-btn {
  opacity: 1; visibility: visible;
  transition: opacity .1s ease 0s, visibility 0s linear 0s, background .12s ease;
}
/* ponte invisibile fra il pulsante e la nuvoletta: il puntatore non "cade" nel vuoto */
.wa-app .wa-msg-menu-btn::after {
  content: ''; position: absolute; top: -6px; bottom: -6px; right: -12px; width: 12px;
}
.wa-app .wa-msg-menu-btn:hover,
.wa-app .wa-msg-menu-btn:focus-visible {
  background: rgba(255,255,255,.96); outline: 2px solid #00a884; outline-offset: 1px;
}
[data-theme="dark"] .wa-app .wa-msg-menu-btn { color: #d9e1e5; background: rgba(17,27,33,.68); }
[data-theme="dark"] .wa-app .wa-msg-menu-btn:hover,
[data-theme="dark"] .wa-app .wa-msg-menu-btn:focus-visible { background: rgba(17,27,33,.92); }
@media (hover: none), (pointer: coarse) {
  .wa-app .wa-msg-menu-btn { opacity: 1; visibility: visible; transition: none; }
}
/* angolo "tagliato" + coda SOLO sulla prima bolla del blocco */
.wa-app .wa-msg-wrap.first .wa-msg.in  { border-radius: 0 8px 8px 8px; }
.wa-app .wa-msg-wrap.first .wa-msg.out { border-radius: 8px 0 8px 8px; }
.wa-app .wa-msg-wrap.first .wa-msg.in::before,
.wa-app .wa-msg-wrap.first .wa-msg.out::before {
  content: ''; position: absolute; top: 0; width: 0; height: 0;
  border-top: 8px solid var(--message-bg-light,#fff);
}
.wa-app .wa-msg-wrap.first .wa-msg.in::before {
  left: -8px; border-left: 8px solid transparent;
}
.wa-app .wa-msg-wrap.first .wa-msg.out::before {
  right: -8px; border-right: 8px solid transparent;
  border-top-color: var(--message-out-light,#d9fdd3);
}
[data-theme="dark"] .wa-app .wa-msg.in  { background: var(--message-bg-dark,#2a3942); }
[data-theme="dark"] .wa-app .wa-msg.out { background: var(--message-out-dark,#005c4b); }
[data-theme="dark"] .wa-app .wa-msg-wrap.first .wa-msg.in::before  { border-top-color: var(--message-bg-dark,#2a3942); }
[data-theme="dark"] .wa-app .wa-msg-wrap.first .wa-msg.out::before { border-top-color: var(--message-out-dark,#005c4b); }
.wa-app .wa-msg-text { padding-left: 34px; font-size: 14.2px; color: #111b21; line-height: 1.4; overflow-wrap: anywhere; word-break: break-word; }
[data-theme="dark"] .wa-app .wa-msg-text { color: #e9edef; }
.wa-app .wa-msg-text code { background: rgba(0,0,0,.07); border-radius: 3px; padding: 0 4px; font-family: monospace; font-size: 12px; }
/* Contenuto testo stile WhatsApp Web: blocco monospazio, righe "> citazione", emoji grandi, "Leggi altro" */
.wa-app .wa-msg-text .wa-mono-block { display: block; margin: 4px 0; padding: 6px 8px; background: rgba(0,0,0,.06); border-radius: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; white-space: pre-wrap; overflow-x: auto; }
[data-theme="dark"] .wa-app .wa-msg-text .wa-mono-block { background: rgba(255,255,255,.08); }
.wa-app .wa-msg-text .wa-quote-line { display: inline-block; border-left: 3px solid #cbd5e1; padding-left: 8px; color: #54656f; }
[data-theme="dark"] .wa-app .wa-msg-text .wa-quote-line { border-left-color: #3b4a54; color: #aebac1; }
.wa-app .wa-msg-text.wa-msg-emoji { font-size: 2.2rem; line-height: 1.15; padding-top: 2px; }
.wa-app .wa-msg-text.wa-msg-clamped { max-height: 400px; overflow: hidden; position: relative; }
.wa-app .wa-msg-text.wa-msg-clamped::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 48px; background: linear-gradient(rgba(217,253,211,0), var(--message-out-light, #d9fdd3)); pointer-events: none; }
.wa-app .wa-msg.in .wa-msg-text.wa-msg-clamped::after { background: linear-gradient(rgba(255,255,255,0), var(--message-bg-light, #fff)); }
[data-theme="dark"] .wa-app .wa-msg.out .wa-msg-text.wa-msg-clamped::after { background: linear-gradient(rgba(0,92,75,0), var(--message-out-dark, #005c4b)); }
[data-theme="dark"] .wa-app .wa-msg.in .wa-msg-text.wa-msg-clamped::after { background: linear-gradient(rgba(32,44,51,0), var(--message-bg-dark, #202c33)); }
.wa-app .wa-read-more { display: inline-block; margin: 4px 0 0 34px; background: none; border: none; padding: 0; color: #027eb5; font-size: 13px; font-weight: 600; cursor: pointer; }
.wa-app .wa-read-more:hover { text-decoration: underline; }
.wa-app .wa-msg-text a[href^="mailto:"] { color: #027eb5; }
.wa-app .wa-msg-footer { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 2px; }
/* Bolle di SOLO TESTO: orario in linea con l'ultima riga (stile WhatsApp Web).
   Il footer diventa assoluto in basso a dx; lo spazio sull'ultima riga e'
   riservato da .wa-footer-spacer (inline-block iniettato in fondo al testo,
   larghezza calcolata in JS su orario+spunte+eventuale "Modificato").
   Se la riga e' piena lo spacer va a capo da solo e la bolla si alza. */
.wa-app .wa-msg.inline-footer { padding-bottom: 7px; }
.wa-app .wa-msg.inline-footer .wa-msg-footer {
  position: absolute; bottom: 3px; right: 8px; margin: 0;
}
.wa-app .wa-footer-spacer { display: inline-block; height: 11px; vertical-align: baseline; }
.wa-app .wa-msg-time { font-size: 10.5px; color: rgba(17,27,33,.5); white-space: nowrap; }
[data-theme="dark"] .wa-app .wa-msg-time { color: rgba(233,237,239,.5); }
.wa-app .msg-ack { display: flex; align-items: center; font-size: 12px; }
.wa-app .wa-revoked { color: #8696a0; font-style: italic; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.wa-app .wa-msg-edited { font-size: 10px; color: rgba(17,27,33,.45); font-style: italic; }
[data-theme="dark"] .wa-app .wa-msg-edited { color: rgba(233,237,239,.45); }

/* Bolla-nota privata in-thread (gialla) */
.wa-app .wa-note-bubble {
  max-width: 68%; min-width: 120px; align-self: flex-end;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-left: 4px solid #f59e0b;
  border-radius: 8px 0 8px 8px;
  padding: 8px 10px 5px; margin: 2px 0; position: relative; word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,.13);
}
.wa-app .wa-note-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  color: #92400e; margin-bottom: 5px;
}
.wa-app .wa-note-head .wa-note-author {
  font-weight: 500; text-transform: none; letter-spacing: 0; opacity: .85; font-size: 10.5px;
}
.wa-app .wa-note-body { font-size: 14px; color: #3b2f12; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.wa-app .wa-note-footer { gap: 6px; }
.wa-app .wa-note-footer .wa-icon-btn { color: #92400e; width: 26px; height: 26px; font-size: 12px; }
.wa-app .wa-note-footer .wa-icon-btn:hover { background: rgba(146,64,14,.12); }
.wa-app .wa-note-footer .wa-msg-time { color: rgba(146,64,14,.65); }
/* In dark mode la nota resta gialla ma con testo scuro per leggibilità */
[data-theme="dark"] .wa-app .wa-note-body { color: #3b2f12; }

.wa-app .wa-quote {
  border-left: 4px solid #25d366; padding: 4px 8px; margin-bottom: 6px;
  border-radius: 4px; background: rgba(37,211,102,.08); cursor: pointer;
}
.wa-app .wa-quote-author { font-size: 11.5px; font-weight: 600; color: #25d366; margin-bottom: 2px; }
.wa-app .wa-quote-text { font-size: 12px; color: #667781; }
[data-theme="dark"] .wa-app .wa-quote-text { color: #8696a0; }

/* media */
.wa-app .wa-media-wrap { position: relative; max-width: 300px; }
.wa-app .wa-media-img { width: 100%; max-width: 300px; border-radius: 6px; cursor: zoom-in; display: block; }
.wa-app .wa-media-video { width: 100%; max-width: 300px; border-radius: 6px; display: block; }
.wa-app .wa-media-caption { font-size: 13px; margin-top: 4px; }
.wa-app .wa-media-dl {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0,0,0,.5); border: none; color: #fff; cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .2s;
}
.wa-app .wa-media-wrap:hover .wa-media-dl { opacity: 1; }
.wa-app .wa-media-err { color: #8696a0; font-size: 13px; padding: 8px; }
/* ── Placeholder caricamento media (immagine/video) ─────────────────────────
   Mentre il proxy scarica il file, la wrap ha la classe .wa-media-loading e
   mostra uno shimmer con icona + spinner. All'onload dell'<img>/<video> la
   classe viene tolta e il media appare in dissolvenza. Niente bolla bianca vuota. */
.wa-app .wa-media-img, .wa-app .wa-media-video { opacity: 1; transition: opacity .25s ease; }
.wa-app .wa-media-wrap.wa-media-loading {
  min-width: 200px; min-height: 180px; background: #dfe5e7; border-radius: 6px; overflow: hidden;
}
/* Spazio RISERVATO con le proporzioni reali, quando il motore le manda. Il riquadro sta sul
   MEDIA e non sul contenitore: il contenitore ospita anche la didascalia ed ha overflow:hidden,
   quindi fissargli l'altezza tagliava il testo sotto la foto. object-fit:contain e non cover:
   ritagliare una foto per farla stare in un rapporto nominale e' peggio che mostrarla intera. */
.wa-app .wa-media-img[style*="aspect-ratio"],
.wa-app .wa-media-video[style*="aspect-ratio"] {
  width: 100%; height: auto; object-fit: contain; background: #dfe5e7; border-radius: 6px;
}
.wa-app .wa-media-caption .wa-mono-block { margin: 4px 0 0; }
.wa-app .wa-msg-text a.wa-phone { color: #027eb5; text-decoration: none; border-bottom: 1px dotted rgba(2,126,181,.5); }
.wa-app .wa-media-wrap.wa-media-loading .wa-media-img,
.wa-app .wa-media-wrap.wa-media-loading .wa-media-video { opacity: 0; }
.wa-app .wa-media-ph { display: none; }
.wa-app .wa-media-wrap.wa-media-loading .wa-media-ph {
  display: flex; position: absolute; inset: 0; align-items: center; justify-content: center;
  background: linear-gradient(90deg, #dfe5e7 25%, #eef2f3 50%, #dfe5e7 75%);
  background-size: 400% 100%; animation: wa-media-shimmer 1.4s ease infinite;
}
.wa-app .wa-media-ph-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 34px; color: rgba(255,255,255,.6); }
.wa-app .wa-media-ph-spin {
  position: relative; z-index: 1; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.55); border-top-color: #25d366; animation: waSpin .7s linear infinite;
}
@keyframes wa-media-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.wa-app .wa-sticker { transition: opacity .25s ease; }
.wa-app .wa-sticker.wa-sticker-loading { opacity: 0; }
[data-theme="dark"] .wa-app .wa-media-wrap.wa-media-loading { background: #1e2d36; }
[data-theme="dark"] .wa-app .wa-media-wrap.wa-media-loading .wa-media-ph {
  background: linear-gradient(90deg, #1e2d36 25%, #2c4050 50%, #1e2d36 75%); background-size: 400% 100%;
}
[data-theme="dark"] .wa-app .wa-media-ph-icon { color: #4a5e68; }
.wa-app .wa-audio-wrap { display: flex; align-items: center; gap: 10px; min-width: 220px; max-width: 300px; padding: 4px 2px; }
.wa-app .wa-audio-play-btn { background: #25d366; border: none; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; color: #fff; flex-shrink: 0; display: flex; align-items: center; justify-content: center; transition: opacity .15s, background .2s; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.wa-app .wa-audio-play-btn:hover { opacity: .87; }
.wa-app .wa-audio-body { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.wa-app .wa-audio-track { position: relative; height: 30px; cursor: pointer; }
.wa-app .wa-audio-bars { position: absolute; inset: 0; display: flex; align-items: center; gap: 2px; pointer-events: none; overflow: hidden; }
.wa-app .wa-audio-bars span {
  flex: 1; min-width: 2px; border-radius: 2px; background: #c8d4d8;
  transition: background .07s ease-out;
  transform-origin: center;
}
.wa-app .wa-audio-bars span.played {
  background: #25d366;
  animation: audio-bar-played 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes audio-bar-played {
  from { transform: scaleY(0.7); }
  to { transform: scaleY(1); }
}
.wa-msg.out .wa-audio-bars span { background: rgba(17,27,33,.2); }
.wa-msg.out .wa-audio-bars span.played { background: rgba(17,27,33,.55); }
[data-theme="dark"] .wa-app .wa-audio-bars span { background: #3b4a54; }
[data-theme="dark"] .wa-app .wa-audio-bars span.played { background: #00a884; }
[data-theme="dark"] .wa-msg.out .wa-audio-bars span { background: rgba(255,255,255,.15); }
[data-theme="dark"] .wa-msg.out .wa-audio-bars span.played { background: rgba(255,255,255,.55); }
.wa-app .wa-audio-seek { position: absolute; inset: -6px 0; width: 100%; height: calc(100% + 12px); opacity: 0; cursor: pointer; z-index: 1; margin: 0; padding: 0; }
.wa-app .wa-audio-meta { display: flex; justify-content: space-between; align-items: center; }
.wa-app .wa-audio-cur, .wa-app .wa-audio-dur { font-size: .68rem; color: #8696a0; min-width: 28px; }
.wa-msg.out .wa-audio-cur, .wa-msg.out .wa-audio-dur { color: rgba(17,27,33,.55); }
[data-theme="dark"] .wa-app .wa-audio-cur, [data-theme="dark"] .wa-app .wa-audio-dur { color: #8696a0; }
.wa-app .wa-sticker { width: 120px; height: 120px; object-fit: contain; }
.wa-app .wa-doc-wrap { display: flex; align-items: center; gap: 10px; padding: 8px; background: rgba(0,0,0,.04); border-radius: 6px; min-width: 200px; }
[data-theme="dark"] .wa-app .wa-doc-wrap { background: rgba(255,255,255,.06); }
.wa-app .wa-doc-icon { font-size: 24px; color: #25d366; flex-shrink: 0; }
.wa-app .wa-doc-info { flex: 1; min-width: 0; }
.wa-app .wa-doc-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-app .wa-doc-meta { display: block; font-size: 11px; color: #8696a0; margin-top: 1px; text-transform: uppercase; letter-spacing: .3px; }
[data-theme="dark"] .wa-app .wa-doc-meta { color: #8696a0; }
.wa-app .wa-doc-dl { color: #25d366; font-size: 16px; }
.wa-app .wa-contact-card { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 4px 2px; }
.wa-app .wa-contact-card i { font-size: 2rem; color: #8696a0; flex-shrink: 0; }
.wa-app .wa-location { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; padding: 4px 2px; }
.wa-app .wa-location i { margin-top: 2px; flex-shrink: 0; }
.wa-app .wa-location a { color: #00a884; text-decoration: none; }
.wa-app .wa-location a:hover { text-decoration: underline; }
.wa-app .wa-reaction-msg { padding: 2px 4px; line-height: 1; }
.wa-app .wa-poll { font-size: 13px; min-width: 160px; }
.wa-app .wa-poll-option {
  margin-top: 4px; padding: 6px 10px; border-radius: 6px;
  background: rgba(0,0,0,.04); color: #3b4a54; font-size: 12.5px;
}
[data-theme="dark"] .wa-poll-option { background: rgba(255,255,255,.08); color: #d1d7db; }
[data-theme="dark"] .wa-contact-card { color: #d1d7db; }
[data-theme="dark"] .wa-contact-card i { color: #8a9297; }
[data-theme="dark"] .wa-location { color: #d1d7db; }
[data-theme="dark"] .wa-location i { color: #8a9297; }
[data-theme="dark"] .wa-location a { color: #31a24c; }
[data-theme="dark"] .wa-app .wa-media-wrap { box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.wa-app .wa-call-log { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #667781; padding: 2px 0; }
.wa-app .wa-system-msg { font-size: 12px; color: #8696a0; font-style: italic; padding: 2px 0; }

/* ── INPUT AREA ────────────────────── */
.wa-app .wa-input-area { flex-shrink: 0; background: #f0f2f5; border-top: 1px solid #e9edef; }
[data-theme="dark"] .wa-app .wa-input-area { background: #202c33; border-top-color: #2a3942; }

.whatsapp-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  animation: send-btn-pulse 1.2s ease-in-out infinite;
}
.whatsapp-send-btn:disabled i {
  animation: spin 0.8s linear infinite;
}
@keyframes send-btn-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 0.85; }
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.wa-app .wa-reply-preview {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: #fff; border-bottom: 1px solid #f0f2f5;
}
[data-theme="dark"] .wa-app .wa-reply-preview { background: #233138; border-bottom-color: #2a3942; }
.wa-app .wa-reply-bar { width: 4px; border-radius: 2px; background: #25d366; align-self: stretch; flex-shrink: 0; }
.wa-app .wa-reply-content { flex: 1; min-width: 0; }
.wa-app .wa-reply-name { font-size: 12px; font-weight: 600; color: #25d366; margin-bottom: 2px; }
.wa-app .wa-reply-text { font-size: 12px; color: #667781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
[data-theme="dark"] .wa-app .wa-reply-text { color: #8696a0; }

.wa-app .wa-file-preview { background: #fff; border-bottom: 1px solid #e9edef; padding: 10px 12px; }
[data-theme="dark"] .wa-app .wa-file-preview { background: #1f2c34; border-bottom-color: #2a3942; }
.wa-app .wa-file-preview-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.wa-app .wa-file-thumb { position: relative; flex-shrink: 0; width: 80px; text-align: center; background: #f0f2f5; border-radius: 8px; padding: 8px; }
.wa-app .wa-file-thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; }
.wa-app .wa-file-name { font-size: 10px; color: #667781; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-app .wa-file-remove {
  position: absolute; top: -4px; right: -4px; width: 18px; height: 18px; border-radius: 50%;
  background: #ef4444; border: none; color: #fff; cursor: pointer; font-size: 10px;
  display: flex; align-items: center; justify-content: center;
}
.wa-app .wa-file-caption-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.wa-app .wa-file-caption-input { flex: 1; padding: 7px 12px; border: none; border-radius: 8px; background: #f0f2f5; color: #111b21; font-size: 14px; outline: none; }
[data-theme="dark"] .wa-app .wa-file-caption-input { background: #2a3942; color: #e9edef; }
.wa-app .wa-send-file-btn, .wa-app .wa-cancel-file-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.wa-app .wa-send-file-btn { background: #25d366; color: #fff; }
.wa-app .wa-cancel-file-btn { background: #f0f2f5; color: #667781; }

.wa-app .wa-recording-preview { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; gap: 12px; }
.wa-app .wa-rec-indicator { display: flex; align-items: center; gap: 10px; flex: 1; justify-content: center; }
.wa-app .wa-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #ef4444; animation: waRecBlink .8s ease-in-out infinite; }
@keyframes waRecBlink { 0%,100% { opacity:1; } 50% { opacity:.3; } }
.wa-app #wa-rec-time { font-size: 16px; font-weight: 700; color: #ef4444; font-variant-numeric: tabular-nums; }
.wa-app .wa-discard-rec { color: #ef4444 !important; }
.wa-app .wa-send-rec-btn {
  width: 44px; height: 44px; border-radius: 50%; background: #25d366; border: none;
  color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 17px; transition: background .15s;
}
.wa-app .wa-send-rec-btn:hover { background: #128c7e; }

.wa-app .wa-input-row { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; }
.wa-app .wa-input-wrap { flex: 1; }
.wa-app .wa-input {
  width: 100%; min-height: 42px; max-height: 150px; resize: none; border: none;
  border-radius: 22px; background: #fff; padding: 10px 16px;
  font-size: 14.5px; color: #111b21; outline: none; line-height: 1.4;
  overflow-y: auto; display: block; box-sizing: border-box;
}
[data-theme="dark"] .wa-app .wa-input { background: #2a3942; color: #e9edef; }
.wa-app .wa-input::placeholder { color: #8696a0; }
.wa-app .wa-action-btn {
  width: 46px; height: 46px; border-radius: 50%; background: #25d366; border: none;
  color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0; transition: background .2s;
}
.wa-app .wa-action-btn:hover { background: #128c7e; }
.wa-app .wa-attach-btn { cursor: pointer; }

/* ── ELEMENTI GLOBALI (fuori da .wa-app) ─────────── */

/* context menu — appendato al body */
.wa-ctx-menu {
  background: #fff; border-radius: 8px; box-shadow: 0 4px 24px rgba(0,0,0,.2);
  min-width: 180px; overflow: hidden; z-index: 10000;
  animation: waCtxIn .1s ease;
}
@keyframes waCtxIn { from { opacity:0; transform:scale(.95); } to { opacity:1; transform:scale(1); } }
[data-theme="dark"] .wa-ctx-menu { background: #233138; }
.wa-ctx-item { padding: 10px 16px; cursor: pointer; font-size: 13.5px; color: #111b21; transition: background 0.1s; }
.wa-ctx-item:hover { background: #f5f6f6; }
[data-theme="dark"] .wa-ctx-item { color: #e9edef; }
[data-theme="dark"] .wa-ctx-item:hover { background: #2a3942; }
.wa-ctx-danger { color: #ef4444 !important; }

/* QR modal */
.wa-qr-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; backdrop-filter: blur(2px);
}
.wa-qr-overlay > div { animation: waModalIn .2s ease; }
.wa-qr-modal {
  background: #fff; border-radius: 14px; overflow: hidden;
  max-width: 460px; width: 100%; box-shadow: 0 24px 64px rgba(0,0,0,.32);
  animation: waModalIn .2s ease;
}
@keyframes waModalIn { from { opacity:0; transform:scale(.96) translateY(8px); } to { opacity:1; transform:scale(1); } }
[data-theme="dark"] .wa-qr-modal { background: #1f2c34; }
.wa-qr-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid #e9edef;
}
[data-theme="dark"] .wa-qr-modal-header { border-bottom-color: #2a3942; color: #e9edef; }
.wa-qr-modal-title { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.wa-qr-body { padding: 20px; }
.wa-qr-code-wrap { display: flex; align-items: center; justify-content: center; min-height: 200px; margin-bottom: 16px; }
.wa-qr-loading { display: flex; flex-direction: column; align-items: center; gap: 12px; color: #667781; font-size: 14px; }
.wa-qr-img { width: 220px; height: 220px; object-fit: contain; border-radius: 8px; }
.wa-qr-instructions { font-size: 13px; color: #667781; line-height: 1.6; }
.wa-qr-instructions ol { margin: 6px 0 0 18px; padding: 0; }
.wa-qr-instructions li { margin-bottom: 4px; }
.wa-qr-status { margin-top: 10px; font-size: 13px; text-align: center; min-height: 18px; }

/* media viewer */
.wa-media-viewer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 20000;
  display: flex; align-items: center; justify-content: center;
}
.wa-media-viewer-inner {
  position: relative; max-width: 90vw; max-height: 90vh;
  display: flex; align-items: center; justify-content: center;
}
.wa-media-viewer-inner img,
.wa-media-viewer-inner video { max-width: 100%; max-height: 85vh; border-radius: 8px; object-fit: contain; }
.wa-mv-close, .wa-mv-dl {
  position: absolute; top: -48px; width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,.15); border: none; color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; text-decoration: none; transition: background .15s;
}
.wa-mv-close:hover, .wa-mv-dl:hover { background: rgba(255,255,255,.25); }
.wa-mv-close { right: 0; }
.wa-mv-dl { right: 46px; }

/* modal fallback */
.wa-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.wa-modal {
  background: #fff; border-radius: 14px; overflow: hidden;
  max-width: 520px; width: 100%; max-height: 85vh;
  display: flex; flex-direction: column; box-shadow: 0 24px 64px rgba(0,0,0,.28);
  animation: waModalIn .2s ease;
}
[data-theme="dark"] .wa-modal { background: #1f2c34; }
.wa-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid #e9edef;
  font-weight: 600; font-size: 15px; flex-shrink: 0; color: #111b21;
}
[data-theme="dark"] .wa-modal-header { border-bottom-color: #2a3942; color: #e9edef; }
.wa-modal-body { flex: 1; overflow-y: auto; padding: 16px; }
.wa-modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid #e9edef; flex-shrink: 0; }
[data-theme="dark"] .wa-modal-footer { border-top-color: #2a3942; }

/* spinner */
.wa-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid #e9edef; border-top-color: #25d366;
  animation: waSpin .7s linear infinite; display: inline-block;
}
@keyframes waSpin { to { transform:rotate(360deg); } }

/* ── RESPONSIVE ────────────────────── */
@media (max-width: 768px) {
  .wa-app { flex-direction: column; }
  .wa-app .wa-sidebar { width: 100%; max-width: none; min-width: auto; border-right: none; height: auto; max-height: 100%; }
  .wa-app .wa-main { display: none; }
  .wa-app .wa-main.chat-open { display: flex; position: fixed; inset: 0; z-index: 200; }
  .wa-app .wa-mobile-back { display: flex !important; }
  .wa-app .wa-messages-inner { padding: 10px 3% 10px; }
  .wa-app .wa-msg { max-width: 85%; }
}

/* ── Record preview (nuovo input-bar) ────────── */
.record-preview {
  display: none;
  align-items: center;
  gap: 8px;
  flex: 1;
  padding: 4px 0;
}

/* ── Toolbar buttons (template / schedule) ───── */
.wa-toolbar-btn {
  flex-shrink: 0;
}
.wa-toolbar-btn--purple { color: #7c3aed !important; }
.wa-toolbar-btn--teal   { color: #128c7e !important; }

/* ── Sidebar more menu ───────────────────────── */
.wa-sidebar-more-menu {
  animation: waCtxIn .12s ease;
}

/* ── whatsapp-sidebar-header scoping ─────────── */
.wa-app .whatsapp-sidebar-header {
  height: 56px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 12px;
  flex-shrink: 0;
}

.wa-app .whatsapp-sidebar-header.wa-email-style-header {
  height: 64px;
  min-height: 64px;
  gap: 0.45rem;
  padding: 0.7rem 0.9rem;
  background: var(--card-bg, #fff);
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  box-shadow: none;
}
.wa-app .wa-email-style-header .wa-sidebar-header-left {
  gap: 0.45rem;
}
.wa-app .wa-email-style-header .wa-sidebar-title {
  color: var(--text-primary, #111827);
  font-size: 1rem;
  font-weight: 700;
}
.wa-app .wa-email-style-header .wa-email-style-back-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary, #5b6070);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.85rem;
}
.wa-app .wa-email-style-header .wa-email-style-back-btn:hover {
  background: var(--bg-tertiary, #f3f4f6);
  color: var(--primary, #6366f1);
}
.wa-app .wa-email-style-header .whatsapp-sidebar-actions {
  gap: 0.45rem;
  margin-left: auto;
  flex-shrink: 0;
}
.wa-app .wa-email-style-header .whatsapp-sidebar-actions > div {
  display: inline-flex;
}
.wa-app .wa-email-style-header .whatsapp-icon-btn.wa-email-style-action {
  width: 38px !important;
  height: 38px !important;
  min-width: 38px;
  padding: 0 !important;
  border: 1px solid var(--border-color, #e0e0e0) !important;
  border-radius: 12px !important;
  background: var(--card-bg, #fff) !important;
  color: var(--text-secondary, #5b6070) !important;
  box-shadow: none !important;
  font-size: 0.85rem !important;
}
.wa-app .wa-email-style-header .whatsapp-icon-btn.wa-email-style-action:hover {
  border-color: var(--primary, #6366f1) !important;
  background: var(--bg-tertiary, #f3f4f6) !important;
  color: var(--primary, #6366f1) !important;
}
.wa-app .wa-email-style-header #wsp-new-chat-btn {
  background: #25d366 !important;
  border-color: #25d366 !important;
  color: #fff !important;
  box-shadow: 0 6px 16px rgba(37, 211, 102, 0.3) !important;
}

.wa-app .wa-email-style-header #wsp-new-chat-btn:hover {
  background: #1da851 !important;
  border-color: #1da851 !important;
  color: #fff !important;
}
[data-theme="dark"] .wa-app .whatsapp-sidebar-header.wa-email-style-header {
  background: var(--card-bg, #202c33);
  border-bottom-color: var(--border-color, #2a3942);
}
[data-theme="dark"] .wa-app .wa-email-style-header .wa-sidebar-title {
  color: var(--text-primary, #e9edef);
}
[data-theme="dark"] .wa-app .wa-email-style-header .wa-email-style-back-btn {
  color: var(--text-secondary, #aebac1);
}
[data-theme="dark"] .wa-app .wa-email-style-header .wa-email-style-back-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .wa-app .wa-email-style-header .whatsapp-icon-btn.wa-email-style-action {
  background: var(--card-bg, #202c33) !important;
  border-color: var(--border-color, #3b4a54) !important;
  color: var(--text-secondary, #aebac1) !important;
}
[data-theme="dark"] .wa-app .wa-email-style-header .whatsapp-icon-btn.wa-email-style-action:hover {
  background: rgba(255, 255, 255, 0.08) !important;
}
[data-theme="dark"] .wa-app .wa-email-style-header #wsp-new-chat-btn {
  background: #25d366 !important;
  border-color: #25d366 !important;
  color: #fff !important;
}
[data-theme="dark"] .wa-app .wa-email-style-header #wsp-new-chat-btn:hover {
  background: #1da851 !important;
  border-color: #1da851 !important;
  color: #fff !important;
}
@media (max-width: 480px) {
  .wa-app .whatsapp-sidebar-header.wa-email-style-header {
    height: 56px;
    min-height: 56px;
    padding: 0.55rem 0.6rem;
    gap: 0.25rem;
  }
  .wa-app .wa-email-style-header .wa-sidebar-avatar {
    display: none;
  }
  .wa-app .wa-email-style-header .whatsapp-sidebar-actions {
    gap: 0.25rem;
  }
  .wa-app .wa-email-style-header .whatsapp-icon-btn.wa-email-style-action {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px;
    border-radius: 10px !important;
  }
}

/* ── Gruppo: nome mittente nella bolla ────────── */
.wa-group-author {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-height: 28px;
  padding-left: 34px;
  margin-bottom: 3px;
  line-height: 1.2;
}
.wa-group-author-name {
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.wa-group-author-phone {
  font-size: 11px;
  color: #8696a0;
  font-weight: 400;
  white-space: nowrap;
}
[data-theme="dark"] .wa-group-author-phone { color: #8696a0; }

/* ── Load more / inizio cronologia ───────────── */
.wa-load-more-wrap {
  display: flex;
  justify-content: center;
  padding: 10px 0 6px;
}
.wa-load-more-btn {
  background: rgba(255,255,255,0.85);
  border: none;
  border-radius: 16px;
  padding: 6px 18px;
  font-size: 13px;
  font-weight: 500;
  color: #128c7e;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, box-shadow 0.15s;
}
.wa-load-more-btn:hover { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.16); }
.wa-load-more-btn:disabled { cursor: default; opacity: 0.7; }
[data-theme="dark"] .wa-load-more-btn { background: rgba(32,44,51,0.9); color: #25d366; }
[data-theme="dark"] .wa-load-more-btn:hover { background: #2a3942; }

/* media legacy senza payload: bolla discreta, non testo pieno */
.wa-app .wa-media-gone {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: #8696a0; font-style: italic;
  padding: 2px 0;
}
.wa-app .wa-media-gone i { opacity: .6; }
.wa-app .wa-media-gone span { opacity: .75; }
[data-theme="dark"] .wa-app .wa-media-gone { color: #8696a0; }

.wa-msgs-start {
  text-align: center;
  padding: 14px 0 6px;
  font-size: 12px;
  color: #8696a0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  opacity: 0.8;
}


/* ── Message views eye button ───────────────────────────── */
.wa-views-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0 3px;
  cursor: pointer;
  color: #aaa;
  font-size: 11px;
  line-height: 1;
  opacity: 0;
  transition: opacity .2s, color .15s;
  vertical-align: middle;
}
.wa-msg:hover .wa-views-btn,
.wa-msg.out:hover .wa-views-btn {
  opacity: 1;
}
.wa-views-btn:hover {
  color: #128c7e;
}
.wa-msg.out .wa-views-btn:hover {
  color: #25d366;
}

/* ── Messaggi programmati nella conversazione ── */
.wa-app .wa-sched-divider {
  text-align: center;
  margin: 10px 0 6px;
}
.wa-app .wa-sched-divider span {
  background: #fff3cd;
  color: #856404;
  font-size: .72rem;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: 10px;
  border: 1px solid #ffc107;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
[data-theme="dark"] .wa-app .wa-sched-divider span {
  background: #332d00;
  color: #ffc107;
  border-color: #6b5300;
}
.wa-app .wa-sched-bubble {
  position: relative;
  background: #fffde7;
  border: 1.5px dashed #ffc107;
  border-radius: 10px;
  padding: 8px 36px 8px 12px;
  margin: 4px 0;
  max-width: 75%;
  align-self: flex-end;
  margin-left: auto;
}
[data-theme="dark"] .wa-app .wa-sched-bubble {
  background: #2a2500;
  border-color: #6b5300;
}
.wa-app .wa-sched-bubble-when {
  font-size: .68rem;
  color: #856404;
  font-weight: 600;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
}
[data-theme="dark"] .wa-app .wa-sched-bubble-when { color: #ffc107; }
.wa-app .wa-sched-bubble-body {
  font-size: .85rem;
  color: #374151;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
[data-theme="dark"] .wa-app .wa-sched-bubble-body { color: #e2e8f0; }
.wa-app .wa-sched-bubble-del {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: .75rem;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color .15s;
}
.wa-app .wa-sched-bubble-del:hover { color: #ef4444; }


/* ══ FONT MONTSERRAT — vista WhatsApp + tutti i suoi modal/menu appesi al body
   (i controlli form non ereditano il font: forzato con :is) ══ */
.wa-app,
div[class^="wa-"], div[class*=" wa-"],
div[class^="wsp-"], div[class*=" wsp-"],
div[class^="mg-"], div[class*=" mg-"],
.context-menu, .message-views-popup, .template-popup-overlay, .compose-chip {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.wa-app :is(button, input, textarea, select),
div[class^="wa-"] :is(button, input, textarea, select),
div[class*=" wa-"] :is(button, input, textarea, select),
div[class^="wsp-"] :is(button, input, textarea, select),
div[class^="mg-"] :is(button, input, textarea, select),
.context-menu :is(button, input, textarea, select),
.message-views-popup :is(button, input, textarea, select),
.template-popup-overlay :is(button, input, textarea, select) {
  font-family: inherit;
}

/* ══ MONTSERRAT OVUNQUE nelle viste WhatsApp (.page-chat) e Chat interna
   (.page-internal-chat) — regola PER-ELEMENTO: vince sull ereditarieta' e su
   ogni stack residuo. Escluse le icone (i/svg) e i blocchi di codice. ══ */
#main-content.page-chat :not(i):not(svg):not(code):not(pre),
#main-content.page-internal-chat :not(i):not(svg):not(code):not(pre) {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
#main-content.page-chat, #main-content.page-internal-chat {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

/* ══ Loader di INVIO dedicato: mentre si invia, l'icona sparisce e al suo posto
   ruota un anello di caricamento — mai piu' microfono che "gira" ══ */
.whatsapp-send-btn.wa-sending i { display: none !important; }
.whatsapp-send-btn.wa-sending::after {
  content: ''; display: block; width: 15px; height: 15px;
  border: 2px solid rgba(84,101,111,.25); border-top-color: #00a884;
  border-radius: 50%; animation: waSendLoad .6s linear infinite;
}
@keyframes waSendLoad { to { transform: rotate(360deg); } }

/* ══ Card CONTATTO stile WhatsApp (vCard): avatar, nome, numero, azioni ══ */
.wa-app .wa-contact-card2 { min-width: 230px; max-width: 300px; padding: 2px 0; }
.wa-app .wa-contact-card2-top { display: flex; align-items: center; gap: 11px; padding: 6px 6px 9px; }
.wa-app .wa-contact-avatar { width: 42px; height: 42px; border-radius: 50%; background: #6a7175; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: .85rem; flex-shrink: 0; }
.wa-app .wa-contact-name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-app .wa-contact-phone { font-size: .8rem; color: #8696a0; }
.wa-app .wa-contact-actions { display: flex; border-top: 1px solid rgba(134,150,160,.28); }
.wa-app .wa-contact-actions button { flex: 1; background: none; border: none; color: #00a884; font-weight: 600; font-size: .82rem; padding: 9px 4px; cursor: pointer; border-radius: 0 0 8px 8px; }
.wa-app .wa-contact-actions button + button { border-left: 1px solid rgba(134,150,160,.28); }
.wa-app .wa-contact-actions button:hover { background: rgba(0,168,132,.08); }

/* Bozza nella lista conversazioni (come WhatsApp): l'etichetta e' colorata,
   il testo resta quello normale dell'anteprima. */
.wa-chat-draft { color: #e11d48; font-weight: 600; margin-right: 3px; }
[data-theme="dark"] .wa-chat-draft { color: #fb7185; }

/* ── Contenuto della nuvoletta: allineamento e misure omogenee ─────────────
   L'intestazione di gruppo (nome + numero) aveva un rientro di 34px, pensato
   per un avatar che nella bolla non c'e': il nome partiva spostato rispetto
   al testo del messaggio. Ora nome, testo, citazioni e orario condividono lo
   stesso margine sinistro, la stessa famiglia di caratteri e interlinee coerenti. */
.wa-msg .wa-group-author {
  padding-left: 0;
  min-height: 0;
  margin-bottom: 2px;
  line-height: 1.25;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}
.wa-msg .wa-group-author-name { font-size: 13px; font-family: inherit; }
.wa-msg .wa-group-author-phone { font-size: 11.5px; font-family: inherit; }
/* menzioni: stesso testo del messaggio, cambia solo il colore */
.wa-msg-text .wa-mention {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  font-weight: 500;
  color: #027eb5;
}
.wa-msg.out .wa-msg-text .wa-mention { color: #056162; }
[data-theme="dark"] .wa-msg-text .wa-mention { color: #53bdeb; }
[data-theme="dark"] .wa-msg.out .wa-msg-text .wa-mention { color: #7ad3f5; }
/* citazione e didascalie allineate al testo, senza salti di dimensione */
.wa-msg .wa-quote { margin-bottom: 4px; }
.wa-msg .wa-quote-author { font-size: 12.5px; font-weight: 600; }
.wa-msg .wa-quote-text { font-size: 13px; line-height: 18px; }

/* Transcript surface polish. */
.wa-app .wa-messages {
  background-color: #eef4f2;
  background-image:
    linear-gradient(rgba(15, 118, 110, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 118, 110, 0.026) 1px, transparent 1px);
  background-size: 24px 24px;
}
.wa-app .wa-messages-inner {
  padding: 18px clamp(18px, 8vw, 120px) 24px;
  gap: 3px;
}
.wa-app .whatsapp-date-divider {
  padding: 18px 0 10px;
}
.wa-app .whatsapp-date-divider span {
  background: #f8fbfa;
  border: 1px solid #d7e4df;
  border-radius: 6px;
  box-shadow: none;
  color: #5a6b66;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0;
  padding: 4px 10px;
  backdrop-filter: none;
}
.wa-app .wa-msg-wrap {
  margin-bottom: 3px;
}
.wa-app .wa-msg-wrap.first {
  margin-top: 14px;
}
.wa-app .wa-msg {
  max-width: min(72%, 640px);
  min-width: 90px;
  padding: 9px 11px 7px;
  border: 1px solid transparent;
  border-radius: 10px;
  box-shadow: 0 1px 1px rgba(15, 23, 42, 0.06);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.wa-app .wa-msg:hover {
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.09);
}
.wa-app .wa-msg.in {
  background: #ffffff;
  border-color: #dfe9e5;
}
.wa-app .wa-msg.out {
  background: #ddf6e7;
  border-color: #c5e9d6;
}
.wa-app .wa-msg.out.wa-origin-auto {
  background: #e7f2fc;
  border-color: #c9e0f3;
}
.wa-app .wa-msg.out.wa-origin-ai {
  background: #f0ebfb;
  border-color: #dbd0f5;
}
.wa-app .wa-msg.out.wa-origin-bulk {
  background: #fff3d7;
  border-color: #f2db9f;
}
.wa-app .wa-msg.out.wa-origin-sched {
  background: #d6f7f0;
  border-color: #a7e3da;
}
.wa-app .wa-msg-wrap.first .wa-msg.in {
  border-radius: 0 10px 10px 10px;
}
.wa-app .wa-msg-wrap.first .wa-msg.out {
  border-radius: 10px 0 10px 10px;
}
.wa-app .wa-msg-wrap.first .wa-msg.in::before {
  border-top-color: #ffffff;
}
.wa-app .wa-msg-wrap.first .wa-msg.out::before {
  border-top-color: #ddf6e7;
}
.wa-app .wa-msg-wrap.first .wa-msg.out.wa-origin-auto::before {
  border-top-color: #e7f2fc;
}
.wa-app .wa-msg-wrap.first .wa-msg.out.wa-origin-ai::before {
  border-top-color: #f0ebfb;
}
.wa-app .wa-msg-wrap.first .wa-msg.out.wa-origin-bulk::before {
  border-top-color: #fff3d7;
}
.wa-app .wa-msg-wrap.first .wa-msg.out.wa-origin-sched::before {
  border-top-color: #d6f7f0;
}
/* Pulsante azioni FUORI dalla nuvoletta, a sinistra: non copre mai il messaggio e non sposta
   il contenuto della bolla (e' in posizione assoluta, nel margine gia' esistente della colonna
   messaggi). Compare al passaggio del mouse, come su WhatsApp Web. */
.wa-app .wa-msg-menu-btn {
  top: 50%;
  transform: translateY(-50%);
  left: -34px;
  right: auto;
  width: 28px;
  height: 28px;
  background: transparent;
  box-shadow: none;
  color: #8696a0;
  font-size: 12px;
}
/* Sui messaggi RICEVUTI il pulsante va a destra della nuvoletta.
   A sinistra non ci sta piu': la foto profilo occupa 28px + 6px di margine, cioe' esattamente
   i 34px in cui il pulsante si posiziona (left: -34px) — misurati 27px di sovrapposizione
   orizzontale e 25 verticale. Spostarlo soltanto piu' in alto non basterebbe: l'avatar e'
   ancorato in basso (align-items: flex-end) ed e' alto 28px, quindi su una nuvoletta di una
   riga (~44px) resterebbero comunque una quindicina di pixel accavallati — ed e' proprio il
   caso piu' frequente (43 nuvolette corte contro 4 alte, in una schermata).
   A destra della bolla ricevuta non c'e' niente, quindi il problema sparisce a ogni altezza. */
.wa-app .wa-msg.in .wa-msg-menu-btn {
  left: auto;
  right: -34px;
}
/* Il "ponte" invisibile che tiene agganciato il puntatore mentre passa dal pulsante alla
   nuvoletta deve puntare verso la bolla: ora che il pulsante e' a destra, va a sinistra.
   Senza girarlo, il pulsante svanirebbe mentre ci si sta andando sopra — il fastidio che quel
   ponte era stato aggiunto per togliere. */
.wa-app .wa-msg.in .wa-msg-menu-btn::after {
  right: auto;
  left: -12px;
}

.wa-app .wa-msg.out .wa-msg-menu-btn {
  background: transparent;
}
.wa-app .wa-msg-menu-btn:hover,
.wa-app .wa-msg-menu-btn:focus-visible {
  background: rgba(15, 23, 42, 0.08);
  color: #3b4a54;
  outline-color: #0f766e;
}
.wa-app .wa-msg-text {
  padding-left: 0;
  padding-right: 28px;
  font-size: 14px;
  line-height: 1.5;
}
.wa-app .wa-msg-footer {
  min-height: 14px;
  gap: 5px;
  margin-top: 5px;
  padding-top: 4px;
  border-top: 1px solid rgba(15, 23, 42, 0.07);
}
.wa-app .wa-msg.inline-footer .wa-msg-footer {
  min-height: 0;
  margin: 0;
  padding-top: 0;
  border-top: 0;
  right: 9px;
  bottom: 4px;
}
.wa-app .wa-msg-time {
  font-size: 10px;
  color: rgba(39, 57, 51, 0.58);
}
.wa-app .wa-views-btn {
  border-radius: 4px;
  color: #5f756d;
  padding: 1px 3px;
}
.wa-app .wa-views-btn:hover {
  background: rgba(15, 118, 110, 0.1);
  color: #0f766e;
}
.wa-app .wa-media-wrap {
  max-width: 360px;
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 8px;
  background: #e8efed;
}
.wa-app .wa-media-img,
.wa-app .wa-media-video {
  max-width: 360px;
  border-radius: 0;
}
.wa-app .wa-quote {
  border-left-color: #0f766e;
  background: rgba(15, 118, 110, 0.07);
  border-radius: 4px;
}

@media (max-width: 900px) {
  .wa-app .wa-messages-inner {
    padding: 12px 16px 18px;
  }
}
@media (max-width: 600px) {
  .wa-app .wa-msg {
    max-width: 88%;
  }
}
[data-theme="dark"] .wa-app .wa-messages {
  background-color: #111b19;
  background-image:
    linear-gradient(rgba(110, 231, 183, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(110, 231, 183, 0.035) 1px, transparent 1px);
}
[data-theme="dark"] .wa-app .whatsapp-date-divider span {
  background: #1a2925;
  border-color: #30433d;
  box-shadow: none;
  color: #a9bcb5;
}
[data-theme="dark"] .wa-app .wa-msg.in {
  background: #202d2a;
  border-color: #34443e;
}
[data-theme="dark"] .wa-app .wa-msg.out {
  background: #075b48;
  border-color: #08745b;
}
[data-theme="dark"] .wa-app .wa-msg-wrap.first .wa-msg.in::before {
  border-top-color: #202d2a;
}
[data-theme="dark"] .wa-app .wa-msg-wrap.first .wa-msg.out::before {
  border-top-color: #075b48;
}
[data-theme="dark"] .wa-app .wa-msg-wrap.first .wa-msg.out.wa-origin-auto::before {
  border-top-color: #1e3a5f;
}
[data-theme="dark"] .wa-app .wa-msg-wrap.first .wa-msg.out.wa-origin-ai::before {
  border-top-color: #3b2a6b;
}
[data-theme="dark"] .wa-app .wa-msg-wrap.first .wa-msg.out.wa-origin-bulk::before {
  border-top-color: #5a3d0f;
}
[data-theme="dark"] .wa-app .wa-msg-menu-btn {
  background: transparent;
  color: #8696a0;
  box-shadow: none;
}
[data-theme="dark"] .wa-app .wa-msg-menu-btn:hover,
[data-theme="dark"] .wa-app .wa-msg-menu-btn:focus-visible {
  background: rgba(233, 237, 239, 0.12);
  color: #e9edef;
}
[data-theme="dark"] .wa-app .wa-msg-footer {
  border-top-color: rgba(226, 232, 240, 0.1);
}
[data-theme="dark"] .wa-app .wa-msg-time {
  color: rgba(225, 237, 232, 0.62);
}
[data-theme="dark"] .wa-app .wa-media-wrap {
  background: #182622;
  border-color: #35443e;
}

/* ============================================================
   Foto profilo accanto alla nuvoletta (solo gruppi, messaggi altrui)
   e icona dell'attivita' collegata al messaggio.
   ============================================================ */

/* Il contenitore della nuvoletta e' gia' flex: l'avatar e' un fratello della bolla.
   align-items:flex-end lo tiene appoggiato in basso, come su WhatsApp, anche quando
   la nuvoletta e' alta (media, messaggi lunghi). */
.wa-app .wa-msg-wrap.in { align-items: flex-end; }

.wa-app .wa-msg-avatar {
  position: relative;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  margin: 0 6px 2px 0;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
}

/* Le nuvolette successive dello stesso autore non ripetono la foto ma tengono lo spazio,
   altrimenti si disallineerebbero rispetto alla prima. */
.wa-app .wa-msg-avatar.continua {
  visibility: hidden;
  cursor: default;
}

.wa-app .wa-msg-avatar-iniziali {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
}

/* L'immagine sta SOPRA le iniziali: se non arriva (il backend risponde 204 quando la foto
   non c'e') l'onerror la toglie dal documento e restano visibili le iniziali colorate. */
.wa-app .wa-msg-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* Icona dell'attivita' nata da questo messaggio: sta nel piede della nuvoletta, accanto
   all'occhio di "chi ha visto". Il colore lo mette il JS in base allo stato. */
.wa-app .wa-msg-task {
  background: none;
  border: none;
  padding: 0 2px;
  margin: 0;
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1;
  opacity: 0.85;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.wa-app .wa-msg-task:hover {
  opacity: 1;
  transform: scale(1.15);
}

/* Nelle nuvolette col piede in linea il contenuto sta tutto sulla stessa riga del testo:
   qui l'icona non deve allargare la riga piu' del necessario. */
.wa-app .wa-msg.inline-footer .wa-msg-task { font-size: 0.72rem; }

/* Bacchetta magica dei campi dinamici nella barra di scrittura.
   Le altre due tinte (purple, teal) sono dichiarate due volte nel file e vince la seconda:
   questa si mette qui in fondo, che e' l'unico punto in cui non verra' sovrascritta. */
.wa-toolbar-btn--indigo { color: #6366f1 !important; }
