/* ============================================================
   WHATSAPP WEB PHONE TEST CONSOLE · MODERN DARK/LIGHT THEME
   ============================================================ */

:root {
  /* DARK THEME (Predeterminado) */
  --bg-app: #0c1317;
  --bg-sidebar: #111b21;
  --bg-sidebar-header: #202c33;
  --bg-chat-header: #202c33;
  --bg-chat: #0b141a;
  --bg-chat-subtle: #121b22;
  --bg-input: #202c33;
  --bg-search: #111b21;
  --bg-hover: #202c33;
  --bg-active: #2a3942;
  --border-color: #222d34;
  --border-light: rgba(255, 255, 255, 0.08);

  /* Texto */
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;

  /* Burbujas de Chat WhatsApp */
  --bubble-user: #005c4b;
  --bubble-user-text: #e9edef;
  --bubble-bot: #202c33;
  --bubble-bot-text: #e9edef;
  --bubble-time-user: #8be4d2;
  --bubble-time-bot: #8696a0;

  /* Acentos */
  --accent-green: #00a884;
  --accent-green-hover: #02906f;
  --accent-blue: #53bdeb;
  --badge-bot: #1f3844;
  --badge-bot-text: #53bdeb;
  --badge-transfer: #3f2a1d;
  --badge-transfer-text: #f59e0b;
  --call-card-bg: rgba(32, 44, 51, 0.95);
  --call-card-border: #2a3942;

  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
}

body.light-theme {
  --bg-app: #eae6df;
  --bg-sidebar: #ffffff;
  --bg-sidebar-header: #f0f2f5;
  --bg-chat-header: #f0f2f5;
  --bg-chat: #efeae2;
  --bg-chat-subtle: #e6e2db;
  --bg-input: #ffffff;
  --bg-search: #f0f2f5;
  --bg-hover: #f5f6f6;
  --bg-active: #e9edef;
  --border-color: #e9edef;
  --border-light: rgba(0, 0, 0, 0.08);

  --text-primary: #111b21;
  --text-secondary: #667781;
  --text-muted: #8696a0;

  --bubble-user: #d9fdd3;
  --bubble-user-text: #111b21;
  --bubble-bot: #ffffff;
  --bubble-bot-text: #111b21;
  --bubble-time-user: #667781;
  --bubble-time-bot: #8696a0;

  --call-card-bg: #ffffff;
  --call-card-border: #e2e8f0;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* LAYOUT PRINCIPAL */
.app-layout {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-app);
}

/* ============================================================
   BARRA LATERAL (LISTA DE CHATS)
   ============================================================ */
.sidebar {
  width: 380px;
  min-width: 320px;
  max-width: 440px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 10;
}

.sidebar-header {
  height: 60px;
  background-color: var(--bg-sidebar-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
}

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

.brand-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00a884, #008069);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 2px 8px rgba(0, 168, 132, 0.3);
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.sync-status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--accent-green);
  font-weight: 500;
}

.pulsing-dot {
  width: 7px;
  height: 7px;
  background-color: var(--accent-green);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.icon-btn.rotating svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* BUSCADOR */
.search-section {
  padding: 8px 12px;
  background-color: var(--bg-sidebar);
}

.search-box {
  background-color: var(--bg-search);
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: 36px;
  border: 1px solid var(--border-color);
  transition: border-color 0.2s;
}

.search-box:focus-within {
  border-color: var(--accent-green);
}

.search-icon {
  color: var(--text-muted);
  margin-right: 8px;
  flex-shrink: 0;
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13.5px;
  width: 100%;
  font-family: inherit;
}

.clear-search-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px;
}

/* CHIPS DE FILTRO */
.filter-chips {
  display: flex;
  gap: 6px;
  padding: 6px 12px 10px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border-color);
}

.filter-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  background-color: var(--bg-sidebar-header);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  font-family: inherit;
}

.chip:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.chip.active {
  background-color: var(--accent-green);
  color: #111b21;
  border-color: var(--accent-green);
}

/* BARRA DE ESTADÍSTICAS */
.stats-bar {
  display: flex;
  justify-content: space-between;
  padding: 6px 14px;
  font-size: 11px;
  color: var(--text-muted);
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
}

/* LISTA DE CONTACTOS */
.contacts-list {
  flex: 1;
  overflow-y: auto;
  background-color: var(--bg-sidebar);
}

.contact-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.15s ease;
}

.contact-item:hover {
  background-color: var(--bg-hover);
}

.contact-item.active {
  background-color: var(--bg-active);
}

.avatar-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #2a3942;
  color: #00a884;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  border: 1px solid var(--border-light);
}

.contact-body {
  flex: 1;
  min-width: 0;
}

.contact-row.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}

.contact-name {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.contact-row.bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.contact-preview {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.contact-meta-tags {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.contact-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.contact-badge.audio {
  background: transparent;
  padding: 0;
  font-size: 13px;
}

.contact-badge.calls {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.contact-badge.route.bot {
  background: var(--badge-bot);
  color: var(--badge-bot-text);
}

.contact-badge.route.transfer {
  background: var(--badge-transfer);
  color: var(--badge-transfer-text);
}

/* ============================================================
   PANEL PRINCIPAL DE CHAT
   ============================================================ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: var(--bg-chat);
  position: relative;
  overflow: hidden;
}

/* ESTADO VACÍO */
.empty-chat-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 30px;
  color: var(--text-secondary);
  background-color: var(--bg-chat);
}

.whatsapp-phone-mockup {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(0, 168, 132, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  border: 1px solid rgba(0, 168, 132, 0.2);
}

.empty-chat-state h2 {
  font-size: 22px;
  color: var(--text-primary);
  margin-bottom: 10px;
  font-weight: 700;
}

.empty-chat-state p {
  font-size: 14px;
  max-width: 480px;
  line-height: 1.5;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.empty-features {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.feature-tag {
  background: var(--bg-sidebar-header);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ENCABEZADO DEL CHAT ACTIVO */
.chat-header {
  height: 60px;
  background-color: var(--bg-chat-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 5;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.back-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px;
}

.contact-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #2a3942;
  color: #00a884;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.contact-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.contact-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.meta-dot {
  color: var(--text-muted);
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.call-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.call-selector-wrapper select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

/* BARRA DE PESTAÑAS DE LLAMADAS */
.call-tabs-bar {
  background-color: var(--bg-sidebar-header);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  flex-shrink: 0;
}

.call-tab-chip {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.call-tab-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.call-tab-chip.active {
  background: var(--accent-green);
  color: #111b21;
  border-color: var(--accent-green);
}

/* ============================================================
   CUERPO DE CHAT Y BURBUJAS WHATSAPP
   ============================================================ */
.chat-messages-scroll {
  flex: 1;
  overflow-y: auto;
  position: relative;
  background-color: var(--bg-chat);
  background-image: 
    radial-gradient(circle at 25px 25px, rgba(255, 255, 255, 0.02) 2%, transparent 0%),
    radial-gradient(circle at 75px 75px, rgba(255, 255, 255, 0.02) 2%, transparent 0%);
  background-size: 100px 100px;
}

.messages-container {
  padding: 24px 36px 48px 36px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 980px;
  margin: 0 auto;
  width: 100%;
}

/* ============================================================
   TARJETA DIVISORIA DE LA LLAMADA (CALL DIVIDER CARD)
   ============================================================ */
.call-divider-card {
  background: var(--call-card-bg);
  border: 1px solid var(--call-card-border);
  border-left: 4px solid var(--accent-green);
  border-radius: 14px;
  padding: 16px 20px;
  margin: 28px 0 16px 0;
  box-shadow: var(--shadow-md);
  position: relative;
}

.call-divider-card:first-child {
  margin-top: 8px;
}

.call-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.call-card-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.call-index-badge {
  background: var(--accent-green);
  color: #111b21;
  font-weight: 700;
  font-size: 12.5px;
  padding: 3px 10px;
  border-radius: 8px;
}

.call-route-badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 8px;
}

.call-route-badge.bot {
  background: var(--badge-bot);
  color: var(--badge-bot-text);
}

.call-route-badge.transfer {
  background: var(--badge-transfer);
  color: var(--badge-transfer-text);
}

.call-meta-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.meta-pill {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 500;
}

.meta-pill.sid {
  font-family: monospace;
  color: var(--text-muted);
}

/* CAJA DE RESUMEN DE DOOBOT */
.call-summary-box {
  background: rgba(0, 168, 132, 0.08);
  border: 1px solid rgba(0, 168, 132, 0.2);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 10px;
  display: flex;
  gap: 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}

.summary-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.summary-content strong {
  color: var(--accent-green);
  display: block;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 3px;
}

/* REPRODUCTOR / ENLACE DE AUDIO DE LA LLAMADA */
.call-audio-container {
  margin-top: 10px;
}

.twilio-link-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(0, 168, 132, 0.08);
  border: 1px solid rgba(0, 168, 132, 0.22);
  border-radius: 9px;
  padding: 8px 14px;
  flex-wrap: wrap;
}

.twilio-link-card .audio-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-green);
  margin-bottom: 0;
}

.audio-direct-link.twilio-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--accent-green);
  border: 1px solid var(--accent-green);
  color: #111b21;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 7px;
  text-decoration: none;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.audio-direct-link.twilio-btn:hover {
  background: var(--accent-green-hover);
  border-color: var(--accent-green-hover);
  color: #ffffff;
  transform: translateY(-1px);
}

.no-audio-notice {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 0;
}

/* ============================================================
   BURBUJAS DE CONVERSACIÓN (WHATSAPP CHAT BUBBLES)
   ============================================================ */
.message-row {
  display: flex;
  width: 100%;
  margin: 4px 0;
}

/* USUARIO A LA DERECHA (ESTILO WHATSAPP) */
.message-row.user-row {
  justify-content: flex-end;
}

/* DOOBOT A LA IZQUIERDA (ESTILO WHATSAPP) */
.message-row.bot-row {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 72%;
  min-width: 120px;
  padding: 8px 12px 6px 12px;
  border-radius: 8px;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.45;
}

/* Burbuja Usuario: Verde Oscuro WhatsApp, pegada a la derecha */
.message-bubble.user-bubble {
  background-color: var(--bubble-user);
  color: var(--bubble-user-text);
  border-top-right-radius: 2px;
}

/* Burbuja Bot: Pizarra/Gris Oscuro WhatsApp, pegada a la izquierda */
.message-bubble.bot-bubble {
  background-color: var(--bubble-bot);
  color: var(--bubble-bot-text);
  border-top-left-radius: 2px;
}

.message-sender {
  font-size: 11.5px;
  font-weight: 700;
  margin-bottom: 3px;
  letter-spacing: 0.2px;
}

.message-sender.sender-bot {
  color: #53bdeb; /* Celeste brillante */
}

.message-sender.sender-user {
  color: #8be4d2; /* Verde agua brillante */
}

.message-text {
  font-size: 14px;
  line-height: 1.45;
  color: inherit;
  white-space: pre-wrap;
}

.message-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: 11px;
}

.message-bubble.user-bubble .message-time {
  color: var(--bubble-time-user);
  opacity: 0.85;
}

.message-bubble.bot-bubble .message-time {
  color: var(--bubble-time-bot);
  opacity: 0.85;
}

.message-check {
  color: #53bdeb;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: -1px;
}

.raw-transcript-box {
  background: var(--bg-sidebar-header);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.raw-header {
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  font-size: 12px;
}

.no-turns-box {
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  margin: 6px 0;
}

/* ============================================================
   TOASTS DE NOTIFICACIÓN
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}

.toast-item {
  background: #202c33;
  color: #e9edef;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: slideUp 0.3s ease-out;
}

.toast-item.success {
  border-left: 4px solid var(--accent-green);
}

.toast-item.error {
  border-left: 4px solid #ef4444;
}

.toast-item.info {
  border-left: 4px solid var(--accent-blue);
}

.toast-item.fade-out {
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.4s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   RESPONSIVE DESIGN (MÓVIL / TABLET)
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    max-width: 100%;
  }
  .chat-area {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
  }
  .app-layout.mobile-chat-open .sidebar {
    display: none;
  }
  .app-layout.mobile-chat-open .chat-area {
    display: flex;
  }
  .back-btn {
    display: flex;
  }
  .messages-container {
    padding: 16px 14px;
  }
  .message-bubble {
    max-width: 88%;
  }
}
