/* ==========================================================================
   WHATSAPP WEB PIXEL-PERFECT DARK THEME STYLESHEET
   Clinident Professional Dental Suite
   ========================================================================== */

:root {
  --wa-bg-deep: #0b141a;
  --wa-bg-sidebar: #111b21;
  --wa-bg-header: #202c33;
  --wa-bg-panel: #111b21;
  --wa-bg-input: #2a3942;
  --wa-bg-hover: #202c33;
  --wa-bg-active: #2a3942;
  
  --wa-msg-in: #202c33;
  --wa-msg-out: #005c4b;
  
  --wa-text-primary: #e9edef;
  --wa-text-secondary: #8696a0;
  --wa-text-muted: #667781;
  
  --wa-accent: #00a884;
  --wa-accent-hover: #06cf9c;
  --wa-tick-blue: #53bdeb;
  --wa-tick-grey: #8696a0;
  --wa-border: rgba(134, 150, 160, 0.15);
  --wa-badge-unread: #00a884;
}

/* Contenedor Principal WhatsApp Web */
.wa-container {
  display: grid;
  grid-template-columns: 360px 1fr 280px;
  gap: 0;
  border: 1px solid var(--wa-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  background: var(--wa-bg-deep);
  height: calc(100vh - 120px);
  max-height: calc(100vh - 120px);
  min-height: 500px;
  position: relative;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--wa-text-primary);
}

body.chat-mode {
  overflow: hidden;
}

body.chat-mode .ct {
  max-width: none;
  height: calc(100vh - 67px);
  padding: 0 24px 0;
  overflow: hidden;
}

body.chat-mode #v-chat,
body.chat-mode #v-chat.on {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body.chat-mode .wa-container {
  height: calc(100vh - 67px);
  max-height: calc(100vh - 67px);
  min-height: 0;
  border-top: 0;
  border-radius: 0 0 12px 12px;
}

@media (max-width: 1200px) {
  .wa-container {
    grid-template-columns: 330px 1fr 0px;
  }
  .wa-patient-drawer {
    display: none !important;
  }
}

@media (max-width: 850px) {
  body.chat-mode .ct {
    padding: 0 !important;
    height: calc(100vh - 54px - calc(58px + env(safe-area-inset-bottom, 0px))) !important;
    max-height: calc(100vh - 54px - calc(58px + env(safe-area-inset-bottom, 0px))) !important;
    overflow: hidden !important;
  }
  .wa-container {
    grid-template-columns: 1fr !important;
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
  }
  .wa-sidebar {
    display: flex !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    border-right: none !important;
  }
  .wa-sidebar.hide-mobile {
    display: none !important;
  }
  .wa-main-chat {
    display: none !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
  }
  .wa-main-chat.show-mobile {
    display: flex !important;
    flex-direction: column !important;
  }
  .wa-patient-drawer {
    display: none !important;
  }
  .wa-back-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    font-size: 24px;
    color: var(--wa-accent, #00d4ff) !important;
    cursor: pointer;
    border: none;
    margin-right: 6px;
    padding: 0;
    line-height: 1;
  }
  .wa-chat-item {
    padding: 12px 14px !important;
  }
  .wa-chat-name {
    font-size: 15px !important;
  }
  .wa-chat-last-msg {
    font-size: 13px !important;
  }
  .wa-search-input-box {
    height: 40px !important;
  }
  .wa-chip {
    padding: 6px 14px !important;
    font-size: 12.5px !important;
  }
}

/* ==========================================================================
   PANEL IZQUIERDO: SIDEBAR DE CHATS
   ========================================================================== */
.wa-sidebar {
  background: var(--wa-bg-sidebar);
  border-right: 1px solid var(--wa-border);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  min-height: 0;
  position: relative;
  z-index: 2;
}

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

.wa-sidebar-header .wa-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00a884, #005c4b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  cursor: pointer;
}

.wa-sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wa-icon-btn {
  background: transparent;
  border: none;
  color: var(--wa-text-secondary);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: background 0.15s ease, color 0.15s ease;
}

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

/* Buscador y Filtros */
.wa-search-bar-wrap {
  padding: 8px 12px;
  background: var(--wa-bg-sidebar);
  border-bottom: 1px solid var(--wa-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

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

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

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

.wa-search-input-box input::placeholder {
  color: var(--wa-text-muted);
}

.wa-filter-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

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

.wa-chip {
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  background: var(--wa-bg-header);
  color: var(--wa-text-secondary);
  border: 1px solid var(--wa-border);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

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

.wa-chip.active {
  background: rgba(0, 168, 132, 0.2);
  color: var(--wa-accent);
  border-color: var(--wa-accent);
  font-weight: 600;
}

/* Lista de Chats */
.wa-chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.wa-chat-list::-webkit-scrollbar {
  width: 5px;
}

.wa-chat-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.wa-chat-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: background 0.12s ease;
  position: relative;
}

.wa-chat-item:hover {
  background: var(--wa-bg-hover);
}

.wa-chat-item.active {
  background: var(--wa-bg-active);
}

.wa-chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #2a3942;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #d1d7db;
  flex-shrink: 0;
  position: relative;
}

.wa-chat-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.wa-chat-avatar .wa-bot-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #005c4b;
  border: 2px solid var(--wa-bg-sidebar);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}

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

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

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

.wa-chat-time {
  font-size: 11.5px;
  color: var(--wa-text-secondary);
  white-space: nowrap;
}

.wa-chat-item.has-unread .wa-chat-time {
  color: var(--wa-accent);
  font-weight: 600;
}

.wa-chat-bottom-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.wa-chat-last-msg {
  font-size: 13px;
  color: var(--wa-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.wa-unread-badge {
  background: var(--wa-badge-unread);
  color: #111b21;
  border-radius: 12px;
  padding: 2px 7px;
  font-size: 11.5px;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}

/* ==========================================================================
   PANEL CENTRAL: CHAT PRINCIPAL & MENSAJES
   ========================================================================== */
.wa-main-chat {
  background: var(--wa-bg-deep);
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

.wa-chat-header {
  height: 60px;
  background: var(--wa-bg-header);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--wa-border);
  z-index: 10;
  flex-shrink: 0;
}

.wa-chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  cursor: pointer;
}

.wa-back-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--wa-text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

@media (max-width: 850px) {
  .wa-back-btn {
    display: inline-block;
  }
}

.wa-chat-header-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.wa-chat-header-status {
  font-size: 12px;
  color: var(--wa-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* DentiBot Mode Control Banner */
.wa-bot-banner {
  padding: 7px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  border-bottom: 1px solid var(--wa-border);
  z-index: 5;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.wa-bot-banner.mode-bot {
  background: rgba(0, 168, 132, 0.12);
  color: #00d4a7;
  border-bottom-color: rgba(0, 168, 132, 0.3);
}

.wa-bot-banner.mode-human {
  background: rgba(235, 94, 40, 0.15);
  color: #ff9f43;
  border-bottom-color: rgba(235, 94, 40, 0.3);
}

.wa-bot-toggle-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.wa-bot-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Canvas y Contenedor de Mensajes con Fondo de Doodles Oficial */
.wa-messages-container {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  background-color: var(--wa-bg-deep);
  background-image: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.015) 1px, transparent 1px),
                    radial-gradient(circle at 0% 0%, rgba(0, 168, 132, 0.03) 0%, transparent 60%);
  background-size: 24px 24px, 100% 100%;
}

.wa-messages-container::-webkit-scrollbar {
  width: 6px;
}

.wa-messages-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* Separador de Fecha Pegajoso */
.wa-date-divider {
  align-self: center;
  background: var(--wa-bg-header);
  color: var(--wa-text-secondary);
  font-size: 11.5px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  margin: 10px 0;
  user-select: none;
}

/* Burbujas de Mensaje */
.wa-msg-bubble {
  max-width: 68%;
  padding: 7px 11px 8px 11px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.45;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
}

@media (max-width: 600px) {
  .wa-msg-bubble {
    max-width: 85%;
  }
}

.wa-msg-bubble.incoming {
  background: var(--wa-msg-in);
  color: var(--wa-text-primary);
  align-self: flex-start;
  border-top-left-radius: 0;
}

.wa-msg-bubble.outgoing {
  background: var(--wa-msg-out);
  color: var(--wa-text-primary);
  align-self: flex-end;
  border-top-right-radius: 0;
}

.wa-msg-author {
  font-size: 12px;
  font-weight: 600;
  color: var(--wa-accent);
  margin-bottom: 2px;
}

.wa-msg-text {
  white-space: pre-wrap;
  user-select: text;
}

.wa-msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 11px;
  color: var(--wa-text-secondary);
  margin-top: 2px;
  margin-left: 12px;
  align-self: flex-end;
  user-select: none;
}

.wa-tick {
  font-size: 13px;
  line-height: 1;
}

.wa-tick.blue {
  color: var(--wa-tick-blue);
}

.wa-tick.grey {
  color: var(--wa-tick-grey);
}

/* Reproductor de Notas de Voz / Audio */
.wa-audio-player {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
  padding: 4px 0;
}

.wa-audio-avatar {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #2a3942;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.wa-audio-mic-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  font-size: 13px;
}

.wa-audio-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--wa-text-primary);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.wa-audio-play-btn:active {
  transform: scale(0.92);
}

.wa-audio-waveform-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.wa-audio-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  cursor: pointer;
}

.wa-audio-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--wa-accent);
  cursor: pointer;
}

.wa-audio-time {
  font-size: 11px;
  color: var(--wa-text-secondary);
}

/* Tarjetas de Fotos y Documentos */
.wa-img-card {
  max-width: 320px;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 4px;
  cursor: pointer;
}

.wa-img-card img {
  width: 100%;
  display: block;
  border-radius: 6px;
  transition: opacity 0.2s ease;
}

.wa-img-card img:hover {
  opacity: 0.92;
}

.wa-doc-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 4px;
  min-width: 220px;
}

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

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

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

.wa-doc-meta {
  font-size: 11.5px;
  color: var(--wa-text-secondary);
}

/* ==========================================================================
   BARRA DE ENTRADA Y HERRAMIENTAS INFERIOR
   ========================================================================== */
.wa-chat-footer {
  background: var(--wa-bg-header);
  padding: 10px 16px;
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--wa-border);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.wa-chat-input-wrapper {
  flex: 1;
  background: var(--wa-bg-input);
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  border: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.wa-chat-input-wrapper:focus-within {
  border-color: rgba(0, 168, 132, 0.4);
}

.wa-chat-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--wa-text-primary);
  font-size: 14px;
  resize: none;
  max-height: 100px;
  line-height: 1.4;
}

.wa-chat-input::placeholder {
  color: var(--wa-text-muted);
}

.wa-send-btn {
  background: var(--wa-accent);
  color: #111b21;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
}

.wa-send-btn:hover {
  background: var(--wa-accent-hover);
}

.wa-send-btn:active {
  transform: scale(0.92);
}

/* ==========================================================================
   PANEL DERECHO: CONTEXTO DEL PACIENTE
   ========================================================================== */
.wa-patient-drawer {
  background: var(--wa-bg-panel);
  border-left: 1px solid var(--wa-border);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
}

.wa-patient-drawer-header {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--wa-text-secondary);
  margin-bottom: 14px;
}

.wa-drawer-profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 16px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  border: 1px solid var(--wa-border);
  margin-bottom: 16px;
}

.wa-drawer-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00d4ff, #00e676);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #111b21;
  margin-bottom: 10px;
}

.wa-drawer-name {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}

.wa-drawer-phone {
  font-size: 13px;
  color: var(--wa-accent);
  margin-top: 2px;
}

.wa-drawer-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wa-drawer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--wa-border);
  color: var(--wa-text-primary);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.wa-drawer-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}
