/* Estilos personalizados para el chat - Modo oscuro y claro */
:root {
    /* Colores modo oscuro */
    --bg-primary-dark: #0a0a0a;
    --bg-secondary-dark: #111111; 
    --bg-tertiary-dark: #1a1a1a;
    --bg-quaternary-dark: #222222;
    --border-color-dark: #2a2a2a;
    --text-primary-dark: #ffffff;
    --text-secondary-dark: #b3b3b3;
    --text-muted-dark: #666666;
    --message-sent-dark: #1f4e3d;
    --message-received-dark: #1a1a1a;
    --hover-bg-dark: #2a2a2a;
    
    /* Colores modo claro */
    --bg-primary-light: #f0f2f5;
    --bg-secondary-light: #ffffff;
    --bg-tertiary-light: #f8f9fa;
    --bg-quaternary-light: #e9ecef;
    --border-color-light: #e4e6ea;
    --text-primary-light: #111b21;
    --text-secondary-light: #667781;
    --text-muted-light: #8696a0;
    --message-sent-light: #d9fdd3;
    --message-received-light: #ffffff;
    --hover-bg-light: #f5f6f6;
    
    /* Colores comunes */
    --urutienda: #ffe802;
    --urutienda-hover: #e6d102;
    --urutienda-text: #000000;
    --urutienda-dark-2: #b5a933;
    --group-color: #8b5cf6;
    --group-color-dark: #7c3aed;
    
    /* Variables activas (por defecto modo oscuro) */
    --bg-primary: var(--bg-primary-dark);
    --bg-secondary: var(--bg-secondary-dark);
    --bg-tertiary: var(--bg-tertiary-dark);
    --bg-quaternary: var(--bg-quaternary-dark);
    --border-color: var(--border-color-dark);
    --text-primary: var(--text-primary-dark);
    --text-secondary: var(--text-secondary-dark);
    --text-muted: var(--text-muted-dark);
    --message-sent: var(--message-sent-dark);
    --message-received: var(--message-received-dark);
    --hover-bg: var(--hover-bg-dark);
    --chat-bg-image: url('../../images/chat-bg-dark.jpg');
}

/* Modo claro */
.light-theme {
    --bg-primary: var(--bg-primary-light);
    --bg-secondary: var(--bg-secondary-light);
    --bg-tertiary: var(--bg-tertiary-light);
    --bg-quaternary: var(--bg-quaternary-light);
    --border-color: var(--border-color-light);
    --text-primary: var(--text-primary-light);
    --text-secondary: var(--text-secondary-light);
    --text-muted: var(--text-muted-light);
    --message-sent: var(--message-sent-light);
    --message-received: var(--message-received-light);
    --hover-bg: var(--hover-bg-light);
    --chat-bg-image: url('../../images/chat-bg-light.jpg');
}

/* Scrollbar personalizada */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }  

/* Body con fondo negro en modo oscuro */
body {
    background: var(--bg-primary);
    margin: 0;
    padding: 0;
    transition: background-color 0.3s ease;
    height: 100svh;
    overflow: hidden;
}

/* Header móvil */
.mobile-header {
    display: none; /* Oculto por defecto en desktop */
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    position: relative;
    z-index: 200;
}

.mobile-left-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Cuando no hay hamburguesa, el logo se alinea a la izquierda */
.mobile-left-actions .mobile-logo-link {
    transition: all 0.3s ease;
}

.mobile-right-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-header-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    transition: all 0.2s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-header-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.mobile-header-btn.active {
    background: var(--urutienda);
    color: var(--urutienda-text);
    border-color: var(--urutienda);
}

.mobile-logo-link {
    text-decoration: none;
}

.header-logo-img {
    height: 32px;
    width: 32px;
    border-radius: 6px;
}

/* Overlay para drawer móvil */
.mobile-drawer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100svh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
}

.mobile-drawer-overlay.active {
    display: block;
}

/* Estados del hamburguesa en móvil */
.mobile-header-btn.hamburger-back {
    /* Cuando está en modo back (conversación activa) */
    transition: all 0.2s ease;
}

.mobile-header-btn.hamburger-back i:before {
    content: "\f12c"; /* Bootstrap icon arrow-left */
}

/* Layout principal */
.chat-container {
    height: 100svh;
    display: flex;
    background: var(--bg-primary);
    transition: background-color 0.3s ease;
}

/* Sidebar delgada */
.main-sidebar {
    width: 60px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    transition: all 0.3s ease;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    margin-bottom: 30px;
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.sidebar-icon:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.sidebar-icon.active {
    background: var(--urutienda);
    color: var(--urutienda-text);
}

/* Tooltips */
.tooltip {
    position: absolute;
    left: 50px;
    background: var(--bg-quaternary);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 1000;
    border: 1px solid var(--border-color);
}

.sidebar-icon:hover .tooltip {
    opacity: 1;
    visibility: visible;
    left: 55px;
}

/* Chat list sidebar */
.chat-list-sidebar {
    width: 350px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.chat-list-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.chat-list-header h2 {
    color: var(--text-primary);
    margin: 0;
}

/* Título en modo claro debe ser negro - específico para sobrescribir text-white */
.light-theme .chat-list-header h2.text-white {
    color: #000000 !important;
}

.search-container {
    position: relative;
    margin-top: 15px;
}

.chat-search {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 16px 10px 40px;
    color: var(--text-primary);
    width: 100%;
    transition: border-color 0.2s ease;
}

.chat-search:focus {
    outline: none;
    border-color: var(--accent-green);
}

.chat-search::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
    pointer-events: none;
    z-index: 2;
}

.search-clear {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    z-index: 2;
    transition: color 0.2s ease;
}

.search-clear:hover {
    color: var(--text-primary);
}

.chats-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    border-left: 2px solid transparent;
    padding-left: 14px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-item:hover {
    background: var(--hover-bg);
}

.chat-item.active {
    background: #ffe80214;
    border-left: 2px solid var(--urutienda);
}

/* Chat item active en modo claro con fondo más intenso */
.light-theme .chat-item.active {
    background: #ffe80247;
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--urutienda);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--urutienda-text);
    font-weight: bold;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(255, 232, 2, 0.2);
}

.chat-avatar.group {
    background: linear-gradient(135deg, var(--group-color) 0%, var(--group-color-dark) 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.2);
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 16px;
    margin-bottom: 2px;
}

.chat-last-message {
    color: var(--text-secondary);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.chat-time {
    color: var(--text-muted);
    font-size: 12px;
}

.chat-unread {
    background: #25d366;
    border-radius: 50%;
    width: 12px;
    height: 12px;
    min-width: 8px;
    min-height: 8px;
    display: flex;
    border: 1px solid var(--bg-secondary);
}

/* Área principal de conversación */
.conversation-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-image: var(--chat-bg-image);
    background-repeat: repeat;
    background-size: 400px;
    background-attachment: local;
}

.conversation-header {
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.contact-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.contact-avatar-container {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    position: relative;
    cursor: pointer;
    overflow: hidden;
}

.contact-avatar-image {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    transition: transform 0.2s ease;
}

.contact-avatar-image:hover {
    transform: scale(1.05);
}

.contact-avatar-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--urutienda);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--urutienda-text);
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(255, 232, 2, 0.2);
}

.avatar-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    color: var(--text-secondary);
}

.contact-details h3 {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.contact-details p {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 2px 0 0 0;
}

.header-actions {
    display: flex;
}

.header-actions button {
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-actions button:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

/* Botón de recargar mensajes específico */
.refresh-messages-btn {
    background: var(--bg-tertiary) !important;
    border: none !important;
    color: var(--text-secondary) !important;
    padding: 8px !important;
    border-radius: 8px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    width: 36px !important;
    height: 36px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-right: 8px !important;
    font-size: 16px !important;
}

.refresh-messages-btn:hover {
    background: var(--hover-bg) !important;
    color: var(--text-primary) !important;
    transform: scale(1.05);
}

.refresh-messages-btn:active {
    transform: scale(0.95);
}

.refresh-messages-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed !important;
    transform: none;
}

/* Animación de rotación para cuando está recargando */
.refresh-messages-btn.loading i {
    animation: spin 1s linear infinite;
}

/* Área de mensajes */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 12px;
    word-wrap: break-word;
}

.message.sent {
    background: var(--message-sent);
    color: var(--text-primary);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.received {
    background: var(--message-received);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary-dark);
    margin-top: 4px;
    text-align: right;
}

.message.received .message-time {
    text-align: left;
    color: var(--text-muted);
}

/* Estilos de texto para mensajes que se adapten al tema */
.message.sent {
    color: var(--text-primary);
}

.message.received {
    color: var(--text-primary);
}

/* Área de input */
.message-input-area {
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.input-actions {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-actions:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.message-input {
    flex: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 12px 16px;
    color: var(--text-primary);
    resize: none;
    min-height: 20px;
    max-height: 72px; /* Aproximadamente 3 líneas */
    line-height: 1.4;
    overflow-y: hidden; /* Ocultar scroll hasta que sea necesario */
    transition: all 0.2s ease;
}

.message-input:focus {
    outline: none;
    border-color: var(--urutienda);
}

/* Message input en modo claro debe tener borde negro en focus */
.light-theme .message-input:focus {
    border-color: #000000;
}

.message-input::placeholder {
    color: var(--text-muted);
}

/* Cuando supera las 3 líneas, mostrar scroll */
.message-input.scrollable {
    overflow-y: auto;
}

.send-button {
    background: var(--urutienda) !important;
    color: var(--urutienda-text) !important;
    border: none !important;
    border-radius: 50% !important;
    width: 40px !important;
    height: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    transition: background-color 0.2s ease !important;
    box-shadow: none !important;
    outline: none !important;
}

.send-button:hover {
    background: var(--urutienda-hover);
}

.send-button:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* Voice controls - totalmente transparente */
.voice-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.stop-button {
    background: #dc3545 !important;
    color: white !important;
    border: none !important;
    border-radius: 50% !important;
    width: 40px !important;
    height: 40px !important;
    /* NO display aquí - se controla desde JS */
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    box-shadow: none !important;
    outline: none !important;
}

/* Cuando esté visible, usar flex */
.stop-button[style*="inline-flex"] {
    display: inline-flex !important;
}

.stop-button:hover {
    background: #c82333;
    transform: scale(1.05);
}

.stop-button:active {
    transform: scale(0.95);
}

.send-button.recording {
    animation: recording-pulse 1.5s ease-in-out infinite;
}

@keyframes recording-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* Estado vacío */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-align: center;
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Estados de mensaje */
.message[data-status="sending"] {
    opacity: 0.7;
}

.message[data-status="failed"] {
    border-left: 3px solid #dc3545;
}

.message-failed {
    background: var(--bg-tertiary) !important;
    opacity: 0.8;
}

.message-failed .message-time {
    color: #dc3545;
}

/* Input deshabilitado durante envío */
.message-input:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* ACK Icons estilo WhatsApp */
.ack-icon {
    font-size: 0.75rem;
    margin-left: 4px;
    display: inline-block;
}

.ack-pending {
    color: var(--text-muted);
    font-size: 0.7rem;
}

.ack-sent {
    color: var(--text-muted);
    font-weight: bold;
}

.ack-delivered {
    color: var(--text-muted);
    font-weight: bold;
    letter-spacing: -2px;
}

.ack-read {
    color: #4fc3f7; /* Azul claro tipo WhatsApp */
    font-weight: bold;  
    letter-spacing: -2px;
}

.ack-played {
    color: #4fc3f7;
    font-size: 0.7rem;
}

/* Responsive */
@media (max-width: 1024px) {
    .chat-list-sidebar {
        width: 300px;
    }
}

@media (max-width: 768px) {
    /* Mostrar header móvil */
    .mobile-header {
        display: flex !important;
    }

    /* Ocultar main sidebar completamente en móvil */
    .main-sidebar {
        display: none;
    }

    /* Chat container sin altura reducida inicialmente */
    .chat-container {
        height: calc(100svh - 60px);
        position: relative;
    }

    /* Chat sidebar como drawer que ocupa todo el ancho */
    .chat-list-sidebar {
        position: fixed;
        top: 60px;
        left: 0; /* Visible por defecto en chat */
        width: 100vw;
        height: calc(100svh - 60px);
        z-index: 160;
        transition: left 0.3s ease;
    }

    /* En macros.php: ocultar chat sidebar completamente */
    .macros-page .chat-list-sidebar {
        display: none;
    }

    /* Cuando el chat sidebar está cerrado en chat */
    .chat-page .chat-list-sidebar.mobile-closed {
        left: -100vw;
    }

    /* Conversation area inicialmente oculta en móvil */
    .conversation-area {
        position: fixed;
        top: 60px;
        left: 100vw; /* Fuera de vista inicialmente */
        width: 100vw;
        height: calc(100svh - 60px);
        z-index: 160;
        transition: left 0.3s ease;
    }

    /* Cuando se selecciona un chat, mostrar conversation */
    .conversation-area.mobile-active {
        left: 0;
    }

    /* El hamburguesa cambia a flecha cuando hay conversación activa */

    /* Macros content ocupa todo el espacio */
    .macros-content {
        width: 100%;
        margin-left: 0;
    }

    /* Ajustes de elementos */
    .message {
        max-width: 85%;
    }

    .conversation-header {
        padding: 12px 16px;
    }
    
    .message-input-area {
        padding: 12px 16px;
    }
}

@media (max-width: 480px) {
    /* Header móvil más compacto */
    .mobile-header {
        padding: 0 12px;
    }
    
    .mobile-header-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .header-logo-img {
        height: 28px;
        width: 28px;
    }
    
    .mobile-left-actions {
        gap: 10px;
    }
    
    .mobile-right-actions {
        gap: 6px;
    }
    
    /* Chat sidebar ocupa todo el ancho */
    .chat-list-sidebar {
        width: 100vw;
    }
    
    /* Conversation adjustments */
    .contact-avatar-container {
        width: 35px;
        height: 35px;
    }
    
    .message {
        max-width: 90%;
        padding: 6px 10px;
    }
    
    .conversation-header {
        padding: 10px 12px;
    }
    
    .message-input-area {
        padding: 10px 12px;
    }
}
