﻿/* ================================
   AREA SUPERIOR (TOOLBAR)
================================ */

#wa-crm-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-right: 20px;
}

/* Icono WhatsApp */
.wa-icon {
    font-size: 22px;
    color: #25D366;
    cursor: pointer;
}

/* Interruptor disponible / ocupado */
.wa-switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}

.wa-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.wa-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #ccc;
    transition: .3s;
    border-radius: 34px;
}

.wa-slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    top: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

.wa-switch input:checked + .wa-slider {
    background-color: #25D366;
}

.wa-switch input:checked + .wa-slider::before {
    transform: translateX(22px);
}

/* Botón abrir panel + badge */
.wa-btn {
    position: relative;
    border: none;
    background: #075E54;
    color: #fff;
    padding: 6px 10px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 14px;
}

.wa-btn i {
    font-size: 16px;
}

.wa-badge {
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    background: #FF3B30;
    color: #fff;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* Para asegurar que el botón parezca clicable */
#wa-open.wa-btn {
    cursor: pointer;
}

/* ================================
   PANEL LATERAL WHATSAPP
================================ */

#wa-panel {
    position: fixed;
    top: 0;
    right: -480px;       /* oculto */
    width: 460px;        /* más ancho */
    height: 100vh;
    background: #fff;
    box-shadow: -4px 0 12px rgba(0,0,0,0.18);
    transition: right 0.3s ease-in-out;
    z-index: 99999;

    display: flex;
    flex-direction: column;
}

/* Abierto */
#wa-panel.wa-panel-open,
#wa-panel.activo,
#wa-panel.open {
    right: 0;
}

/* ================================
   CABECERA DEL PANEL
================================ */

#wa-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: #075E54;
    color: #fff;
    font-weight: 600;
    font-size: 15px;
}

.wa-close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
}

/* ================================
   LAYOUT (TU CONTENEDOR REAL)
   #wa-layout = 2 columnas
================================ */

#wa-layout {
    flex: 1 1 auto;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    min-height: 0;
}

/* ================================
   SIDEBAR IZQUIERDA  (CHATS)  ✅ MODIFICADO
================================ */

/* ✅ Variables solo para chats */
:root{
    --wa-sidebar-expanded: 310px;   /* tu ancho actual */
    --wa-sidebar-collapsed: 58px;   /* ancho colapsado */
}

#wa-sidebar {
    /* ANTES:
    width: 310px;
    min-width: 260px;
    */
    width: var(--wa-sidebar-expanded);
    min-width: var(--wa-sidebar-collapsed); /* permite colapsar */
    border-right: 1px solid #e5e5e5;
    background: #fff;
    display: flex;
    flex-direction: column;
    min-height: 0;

    /* ✅ transición suave */
    transition: width .22s ease;
}

/* ✅ Colapsar cuando NO está el ratón sobre el sidebar (solo escritorio) */
#wa-sidebar:not(:hover){
    width: var(--wa-sidebar-collapsed);
}

#wa-sidebar-header {
    padding: 10px;
    border-bottom: 1px solid #e5e5e5;
}

/* ✅ Buscador: ocultarlo cuando colapsa */
#wa-search {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    outline: none;
    font-size: 13px;

    transition: opacity .15s ease;
}

#wa-sidebar:not(:hover) #wa-search{
    opacity: 0;
    pointer-events: none;

    /* lo “aplasto” para que no deje hueco */
    height: 0;
    padding: 0;
    border: 0;
    margin: 0;
}

#wa-chat-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 6px 8px;
    background: #fafafa;

    transition: padding .15s ease;
}

#wa-sidebar:not(:hover) #wa-chat-list{
    padding: 6px 4px;
}

/* Items lista */
.wa-chat-item {
    padding: 10px 10px;
    border-radius: 8px;
    cursor: pointer;
    border-bottom: 1px solid #f1f1f1;
    background: transparent;

    /* ✅ mejor layout para badge sin float */
    position: relative;
    display: block;
}

.wa-chat-item:hover { background: #f0f0f0; }
.wa-chat-item.active { background: #eaf7f1; }

.wa-chat-name {
    font-weight: 600;
    font-size: 13px;

    /* ✅ evita saltos raros al colapsar */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-chat-meta {
    font-size: 12px;
    opacity: 0.75;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ✅ En colapsado oculto textos para dejar “icono / badge” */
#wa-sidebar:not(:hover) .wa-chat-name,
#wa-sidebar:not(:hover) .wa-chat-meta{
    display: none;
}

/* Badge dentro del item (contador no leídos)
   ⚠️ Aquí estaba el problema de colisión con el toolbar.
   No lo elimino: lo dejo comentado y lo reemplazo por una versión más específica.
*/
/*
.wa-chat-item .wa-badge {
    float: right;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #FF3B30;
    color: #fff;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 18px;
    margin-left: 8px;
}
*/

/* ✅ NUEVO: badge SOLO dentro del panel/lista de chats (NO toca el toolbar) */
#wa-chat-list .wa-chat-item .wa-badge{
    position: absolute;
    top: 10px;
    right: 10px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #FF3B30;
    color: #fff;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 18px;
}

/* ✅ En colapsado, centramos el badge */
#wa-sidebar:not(:hover) .wa-chat-item{
    padding: 12px 6px;
    text-align: center;
}

#wa-sidebar:not(:hover) #wa-chat-list .wa-chat-item .wa-badge{
    position: static;
    margin: 0 auto;
}

/* ================================
   ZONA DERECHA (CONVERSACIÓN)
================================ */

#wa-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #fff;
}

#wa-main-header {
    flex: 0 0 auto;
    padding: 10px 12px;
    border-bottom: 1px solid #e5e5e5;
    background: #fff;
}

#wa-chat-title {
    font-weight: 600;
    font-size: 14px;
}

#wa-messages {
    flex: 1 1 auto;
    padding: 12px;
    overflow-y: auto;
    background: #f5f5f5;
}

/* Burbuja mensajes (recomendado usar estas clases desde JS) */
.wa-message {
    max-width: 82%;
    margin: 6px 0;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 13px;
    word-wrap: break-word;
}

.wa-message.incoming {
    background: #ffffff;
    align-self: flex-start;
}

.wa-message.outgoing {
    background: #DCF8C6;
    align-self: flex-end;
}

.wa-message-meta {
    font-size: 10px;
    color: #777;
    margin-top: 3px;
    text-align: right;
}

/* ================================
   BARRA DE ESCRITURA
================================ */

#wa-input-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #ddd;
    background: #fff;
}

#wa-input {
    flex: 1 1 auto;
    resize: none;
    border-radius: 8px;
    border: 1px solid #ccc;
    padding: 8px 10px;
    font-size: 14px;
    max-height: 90px;
    outline: none;
}

#wa-send {
    flex: 0 0 auto;
    background: #25D366;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ================================
   RESPONSIVE  ✅ Ajustado para que NO colapse en móvil
================================ */

@media (max-width: 768px) {
    #wa-panel { width: 100%; right: -100%; }
    #wa-panel.wa-panel-open,
    #wa-panel.activo,
    #wa-panel.open { right: 0; }

    /* ANTES:
    #wa-sidebar { width: 45%; min-width: 180px; }
    */

    #wa-sidebar { width: 45% !important; min-width: 180px !important; }

    /* ✅ En móvil, anulamos colapsado (no hay hover real) */
    #wa-sidebar:not(:hover){
        width: 45% !important;
    }

    #wa-sidebar:not(:hover) #wa-search{
        opacity: 1 !important;
        pointer-events: auto !important;
        height: auto !important;
        padding: 8px 10px !important;
        border: 1px solid #ddd !important;
        margin: 0 !important;
    }

    #wa-sidebar:not(:hover) .wa-chat-name,
    #wa-sidebar:not(:hover) .wa-chat-meta{
        display: block !important;
    }

    #wa-sidebar:not(:hover) #wa-chat-list .wa-chat-item .wa-badge{
        position: absolute !important;
        top: 10px !important;
        right: 10px !important;
        margin: 0 !important;
    }
}

/* ---- FIXES LAYOUT FLEX (evita recortes) ---- */
#wa-layout,
#wa-sidebar,
#wa-main,
#wa-messages {
  min-height: 0; /* clave para que el scroll esté donde toca */
}

#wa-main {
  min-width: 0;  /* clave para que la columna derecha pueda encoger */
}

/* Asegura que el panel no se coma padding al calcular tamaños */
#wa-panel,
#wa-layout,
#wa-sidebar,
#wa-main,
#wa-input-bar,
#wa-messages {
  box-sizing: border-box;
}

/* ---- INPUT BAR: que no se salga y el botón siempre visible ---- */
#wa-input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid #ddd;
  background: #fff;
  width: 100%;
}

#wa-input {
  flex: 1 1 auto;
  min-width: 0;          /* clave: permite encoger el textarea */
  width: 100%;
  border: 1px solid #ccc;
  border-radius: 10px;
  padding: 10px 12px;
  resize: none;
  outline: none;
}

/* Botón redondo y fijo, nunca debe encoger */
#wa-send {
  flex: 0 0 44px;         /* ancho fijo */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #25D366;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* segundas recomendaciones */
#wa-panel { overflow: visible; }
#wa-main  { overflow: hidden; } /* el recorte debe estar dentro, no en el panel */
#wa-messages {
  flex: 1 1 auto;
  overflow-y: auto;
}
