:root {
  --bg-app: #f4f6f8;
  --bg-panel: #ffffff;
  --border-color: #e5e7eb;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --primary-dark: #0f5132;
  --msg-admin-bg: #025c4c;
  --msg-admin-text: #ffffff;
  --msg-client-bg: #ffffff;
  --msg-client-text: #1e293b;
  --badge-online: #10b981;
  --btn-primary: #044b41;
  --btn-primary-hover: #033831;
}

header.topbar {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    background-color: #ffffff !important;
    border-bottom: 1px solid #e2e8f0 !important;
    padding: 10px 20px !important;
    width: 100% !important;
    height: 60px !important;
    box-sizing: border-box !important;
    position: relative !important;
    z-index: 99999 !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02) !important;
}

.topbar-actions {
    display: flex !important;
    align-items: center !important;
    gap: 15px !important;
    position: relative !important;
    z-index: 100000 !important;
}

/* Forzar que los elementos internos de la topbar respeten su espacio sin amontonarse */
header.topbar > div {
    display: flex !important;
    align-items: center !important;
    gap: 15px !important;
}

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

html, body.admin-body {
  height: auto !important;
  min-height: 100vh !important;
  overflow: visible !important;
  overflow-y: auto !important; 
  display: block !important; 
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
}


.layout-master {
  height: 70vh; 
  min-height: 500px;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden; 
  border-top: 1px solid var(--border-color); 
  border-bottom: 1px solid var(--border-color);
  margin: 10px 0; 
}


.topbar {
  height: 56px;
  min-height: 56px;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between; /* 💡 Esto acomoda los elementos de lado a lado sin amontonar */
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 99999;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 1; /* Permite que la barra de búsqueda se comprima si es necesario */
    min-width: 140px;
}

.search-box input {
  background-color: #f1f5f9;
  border: 1px solid transparent;
  border-radius: 20px;
  padding: 7px 16px 7px 36px;
  font-size: 13px;
  width: 260px;
  max-width: 100%;
  outline: none;
}

.search-box svg {
  position: absolute;
  left: 12px;
  fill: var(--text-light);
  width: 14px;
  height: 14px;
}



.icon-btn-top {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
}

.admin-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 1px solid var(--border-color);
  padding-left: 16px;
  flex-shrink: 0;
}

.admin-info {
  text-align: right;
  line-height: 1.2;
}

.admin-info .name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.admin-info .role {
  font-size: 11px;
  color: var(--text-muted);
}

.admin-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: #78074b;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: bold;
}

/* CONTENEDOR 3 COLUMNAS */
#panelAdmin {
  display: flex;
  flex: 1; 
  min-height: 0; 
  width: 100%;
  overflow: hidden;
}

/* COLUMNA IZQUIERDA */
#listaClientes {
  width: 310px;
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
  min-height: 0;
}

.header-seccion-chat {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-seccion-chat h2 {
  font-size: 16px;
  font-weight: 700;
}

#menuDesplegable {
    max-height: min(260px, calc(70vh - 140px)) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain;
}

#menuDesplegable > * {
    flex-shrink: 0 !important;
}

#menuDesplegable::-webkit-scrollbar {
    width: 6px;
}

#menuDesplegable::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.45);
    border-radius: 4px;
}

#totalClientes {
  font-size: 12px;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 12px;
}

.filtros-tabs {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.filtros-tabs button {
  background: none;
  border: none;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 12px;
}

.filtros-tabs button.active {
  background-color: #f1f5f9;
  color: var(--text-main);
  font-weight: 600;
}

#clientes {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto !important;
}

.cliente {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f8fafc;
  transition: background 0.15s;
}

.cliente:hover {
  background-color: #f8fafc;
}

.cliente.activo {
  background-color: #f1f5f9;
}

.cliente .estado {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: var(--badge-online);
  margin-right: 12px;
  flex-shrink: 0;
}

/* COLUMNA CENTRAL (CHAT) */
#chatAdmin {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0; 
  overflow: hidden;
  background-color: #ffffff;
  border-right: 1px solid var(--border-color);
}

#cabeceraChat {
  height: 60px;
  min-height: 60px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #ffffff;
  flex-shrink: 0;
}

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

.avatar-header {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text-muted);
}

#nombreCliente {
  font-size: 14px;
  font-weight: 600;
}

#estadoCliente {
  font-size: 12px;
  color: var(--badge-online);
  font-weight: 500;
}

.header-icons {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-muted);
  font-size: 15px;
}

/* ÁREA DE MENSAJES SCROLLEABLE */
#mensajes {
  flex: 1; 
  min-height: 0;
  overflow-y: auto; 
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #f8fafc;
  background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
  background-size: 20px 20px;
}

.divider-fecha {
  align-self: center;
  background: #e2e8f0;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 10px;
  margin: 4px 0;
}

.mensaje {
  max-width: 65%;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  border-radius: 12px;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.mensaje.cliente {
  align-self: flex-start;
  background-color: var(--msg-client-bg);
  color: var(--msg-client-text);
  border-top-left-radius: 2px;
  border: 1px solid #edf2f7;
}

.mensaje.admin {
  align-self: flex-end;
  background-color: var(--msg-admin-bg);
  color: var(--msg-admin-text);
  border-top-right-radius: 2px;
}

#vistaPreviaArchivos {
  background-color: #ffffff;
  padding: 8px 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ESTILOS DEL MODAL DE WHATSAPP */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.modal-contenido {
  background: #ffffff;
  border-radius: 12px;
  width: 90%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.btn-cerrar-modal {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
}

.campo-form {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
}

.campo-form label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 5px;
}

.campo-form input, 
.campo-form textarea {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}

.campo-form input:focus, 
.campo-form textarea:focus {
  border-color: #25D366;
  box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.15);
}

.campo-form small {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
}

.modal-acciones {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.btn-wa {
  background: #25D366;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-wa:hover {
  background: #1ebc59;
}

/* FOOTER FIJO AL FONDO */
#escribir {
  height: 64px;
  min-height: 64px;
  background-color: #ffffff;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  flex-shrink: 0; 
}

.btn-adjunto {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
}

#mensajeAdmin {
  flex: 1;
  height: 40px;
  background-color: #f1f5f9;
  border: 1px solid transparent;
  border-radius: 20px;
  padding: 0 16px;
  font-size: 13.5px;
  outline: none;
}

#btnEnviar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background-color: var(--btn-primary);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#btnEnviar svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* COLUMNA DERECHA */
#panelDetalles {
  width: 330px;
  background-color: var(--bg-panel);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
}

.detalles-header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.detalles-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.perfil-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

#detalleInicial {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background-color: #e0f2fe;
  color: #0369a1;
  font-size: 26px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

#detalleNombre {
  font-size: 15px;
  font-weight: 700;
  margin-top: 10px;
}

.sub-perfil {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.perfil-acciones {
  display: flex;
  gap: 10px;
  width: 100%;
}

.btn-secundario, .btn-primario-sm {
  flex: 1;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secundario {
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-primario-sm {
  background: var(--btn-primary);
  border: 1px solid var(--btn-primary);
  color: #ffffff;
}

.datos-lista {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}

.dato-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.dato-item label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  display: block;
}

.dato-item span {
  font-size: 12.5px;
  color: var(--text-main);
  word-break: break-all;
}

.seccion-tags {
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}

.tags-cloud {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  background: #f1f5f9;
  color: var(--text-muted);
}

.tag.highlight {
  background-color: #e0f2fe;
  color: #0369a1;
  font-weight: 600;
}


.btn-wa {
    background-color: #25D366;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.3s;
}
.btn-wa:hover {
    background-color: #128C7E;
}

/* Panel Lateral Flotante */
.panel-wa-lateral {
    position: fixed;
    top: 0;
    right: -400px; 
    width: 350px;
    height: 100vh;
    background-color: #f0f2f5;
    box-shadow: -4px 0 15px rgba(0,0,0,0.1);
    transition: right 0.4s ease; 
    display: flex;
    flex-direction: column;
    z-index: 9999;
}

/* Clase que JS agregará para mostrar el panel */
.panel-wa-lateral.abierto {
    right: 0; 
}

/* Cabecera del Panel */
.wa-header {
    background-color: #075E54;
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.btn-cerrar {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
}

/* Área de los mensajes */
.wa-chat-area {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png'); /* Fondo tipo WA */
}

/* Input para responder */
.wa-input-area {
    background: white;
    padding: 15px;
    display: flex;
    gap: 10px;
}
.wa-input-area input {
    flex: 1;
    padding: 10px;
    border-radius: 20px;
    border: 1px solid #ccc;
    outline: none;
}
.wa-input-area button {
    background: #25D366;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 50%;
    cursor: pointer;
}

/* Transición suave para la barra lateral */
#panelLateral, .sidebar-chats, #contenedor-lateral { 
    transition: all 0.3s ease-in-out;
    width: 320px;
}

/* Estado cuando se oculta */
.sidebar-colapsado {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    opacity: 0;
    border: none !important;
}

.chat-container, #vista-whatsapp, #vista-chat {
    flex: 1; 
    transition: all 0.3s ease-in-out;
}


/* Asegurar que la vista de WhatsApp use la altura real disponible */
#vista-whatsapp {
    flex-direction: column;
    height: calc(100vh - 65px);
    min-height: 0;
    overflow: hidden;
    flex: 1 1 0;
    width: auto;
    margin-right: 16px;
    box-sizing: border-box;
}

/* Área de mensajes con scroll fluido */
#area-mensajes-wa {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
}

/* Scroll en la lista izquierda de contactos */
#lista-numeros-wa, 
#clientes {
    overflow-y: auto !important;
    min-height: 0 !important;
    height: calc(100vh - 140px) !important;
    -webkit-overflow-scrolling: touch;
}



header.topbar {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    overflow: visible !important;
    padding: 0 12px !important;
}

/* Cuando la ventana se reduce (menos de 950px o modo móvil) */
@media screen and (max-width: 950px) {

    /* Reducir el botón verde de notificaciones para no saturar la barra */
    #btnPermisoNotificaciones {
        font-size: 11px !important;
        padding: 5px 8px !important;
        white-space: nowrap !important;
        max-width: 140px !important;
        text-overflow: ellipsis !important;
        overflow: hidden !important;
    }

    /* Reducir o contraer la barra de búsqueda superior */
    #buscadorGlobal,
    div:has(> #buscadorGlobal) {
        max-width: 130px !important;
        font-size: 11px !important;
    }

    /* Ocultar texto secundario del admin para ahorrar espacio horizontal */
    .info-admin span:not(:first-child),
    header span:contains("Super Admin") {
        display: none !important;
    }

    /* Cabecera interna del chat ajustada */
 /* Corregido: Afecta únicamente a la cabecera interna del chat de WhatsApp, no a los headers de Telmedia */
#header-chat-wa {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    overflow: visible !important; 
    padding: 0 12px !important;
}

    #header-chat-wa strong {
        font-size: 13px !important;
    }

    #btnToggleDetalles {
        padding: 5px 8px !important;
        font-size: 11px !important;
    }
}

/*=====================*/
/* Contenedor de notificaciones emergentes */
#contenedorNotificacionesAdmin {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 99999;
}

.tarjeta-solicitud-admin {
    background: #375F85;
    color: #ffffff;
    width: 350px;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    border-left: 6px solid #10b981;
    animation: aparecerNotif 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tarjeta-solicitud-admin .notif-top {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    opacity: 0.85;
    margin-bottom: 6px;
    text-transform: uppercase;
    font-weight: bold;
}

.tarjeta-solicitud-admin .notif-nombre {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 2px;
}

.tarjeta-solicitud-admin .notif-telefono {
    font-size: 12px;
    color: #e2e8f0;
    margin-bottom: 8px;
}

.tarjeta-solicitud-admin .notif-acciones {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.btn-atender-ahora {
    flex: 1;
    background: #10b981;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    font-size: 12px;
}

.btn-atender-ahora:hover { background: #059669; }

.btn-cerrar-notif {
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
}

@keyframes aparecerNotif {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.modal-usuarios-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal-usuarios-caja {
    background: #ffffff;
    color: #1f2937;
    width: 95%;
    max-width: 680px;
    border-radius: 12px;
    padding: 20px 24px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25);
    max-height: 88vh;
    overflow-y: auto;
}

.modal-usuarios-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 12px;
    margin-bottom: 16px;
}

.modal-usuarios-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.btn-cerrar-usuarios {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #6b7280;
}

.form-usuarios-crud {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.campo-crud {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
}

.campo-crud input,
.campo-crud select {
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
}

.botones-crud {
    grid-column: span 3;
    display: flex;
    gap: 10px;
}

.btn-crud-guardar {
    background: #2563eb;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

.btn-crud-cancelar {
    background: #6b7280;
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
}

.tabla-usuarios {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.tabla-usuarios th,
.tabla-usuarios td {
    padding: 10px;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
}

.tabla-usuarios th {
    background: #f9fafb;
    font-weight: 600;
}

@media (max-width: 600px) {
    .form-usuarios-crud {
        grid-template-columns: 1fr;
    }
    .botones-crud {
        grid-column: span 1;
    }
}