/* ============================================================
   ESTILOS COMPLETOS DE WHATSAPP CHAT VIEWER
   ============================================================ */

/* --- RESET Y BASE --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #0b141a;
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* ============================================================
   SIDEBAR PRINCIPAL (Izquierda)
   ============================================================ */
#sidebar {
    width: 320px;
    min-width: 320px;
    background: #111b21;
    border-right: 1px solid #2a3942;
    display: flex;
    flex-direction: column;
    height: 100vh;
    transition: transform 0.3s ease;
    z-index: 100;
}

#sidebar-header {
    padding: 20px 16px;
    background: #111b21;
    border-bottom: 1px solid #2a3942;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#sidebar-header h2 {
    color: #e9edef;
    font-size: 18px;
    font-weight: 600;
}

#sidebar-header .sidebar-toggle {
    display: none;
    background: transparent;
    border: none;
    color: #e9edef;
    font-size: 20px;
    cursor: pointer;
}

/* --- CHAT LIST --- */
#chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    list-style: none;
}

#chat-list li {
    padding: 12px 16px;
    color: #e9edef;
    cursor: pointer;
    border-bottom: 1px solid #2a3942;
    transition: background .2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

#chat-list li:hover {
    background: #202c33;
}

#chat-list li.active {
    background: #2a3942;
}

#chat-list li.loading {
    color: #8696a0;
    justify-content: center;
    cursor: default;
}

#chat-list li .chat-badge {
    background: #25d366;
    color: #fff;
    font-size: 11px;
    border-radius: 50%;
    padding: 2px 8px;
    margin-left: auto;
    min-width: 20px;
    text-align: center;
}

/* --- CHAT AVATAR --- */
.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #25d366;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
}

/* --- CHAT INFO --- */
.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-weight: 500;
    font-size: 16px;
    color: #e9edef;
}

.chat-preview {
    font-size: 13px;
    color: #8696a0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   SIDEBAR SECUNDARIO (Derecha - Toggle)
   ============================================================ */
.sidebar-toggle-btn {
    position: fixed;
    left: 10px;
    top: 10px;
    z-index: 1000;
    background: #111b21;
    border: 1px solid #2a3942;
    color: #e9edef;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.sidebar-toggle-btn:hover {
    background: #202c33;
}

#sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* ============================================================
   CHAT VIEW
   ============================================================ */
#chat-view {
    flex: 1;
    background: #0b141a;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* --- CHAT HEADER --- */
#chat-header {
    padding: 16px 20px;
    background: #111b21;
    border-bottom: 1px solid #2a3942;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 60px;
}

#chat-header .chat-avatar {
    width: 36px;
    height: 36px;
    font-size: 16px;
}

#chat-header h3 {
    color: #e9edef;
    font-size: 16px;
    font-weight: 500;
}

#chat-header .chat-status {
    color: #8696a0;
    font-size: 13px;
}

/* --- MESSAGES CONTAINER --- */
#messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 40px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* --- MESSAGES --- */
.message {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 8px;
    word-wrap: break-word;
    animation: fadeIn .3s ease;
}

.message.received {
    background: #202c33;
    color: #e9edef;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message.sent {
    background: #005c4b;
    color: #e9edef;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.system {
    background: #1f2c33;
    color: #8696a0;
    align-self: center;
    font-size: 13px;
    padding: 6px 16px;
    border-radius: 12px;
    font-style: italic;
}

.message .msg-user {
    font-size: 13px;
    font-weight: 600;
    color: #25d366;
    margin-bottom: 4px;
}

.message .msg-text {
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.message .msg-text .emoji {
    font-size: 18px;
}

.message .msg-time {
    font-size: 11px;
    color: #8696a0;
    text-align: right;
    margin-top: 4px;
}

/* --- IMAGES --- */
.msg-image {
    margin-top: 8px;
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    display: inline-block;
}

.msg-image img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    display: block;
    background: #1f2c33;
}

/* --- VIDEOS --- */
.msg-video {
    margin-top: 8px;
    border-radius: 8px;
    overflow: hidden;
    max-width: 100%;
}

.msg-video video {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    background: #000;
}

/* --- AUDIO --- */
.msg-audio {
    background: #1f2c33;
    padding: 12px 16px;
    border-radius: 8px;
    margin-top: 8px;
    min-width: 250px;
}

.msg-audio .audio-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.msg-audio .play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #25d366;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .2s;
}

.msg-audio .play-btn:hover {
    background: #1fa855;
}

.msg-audio .play-btn.loading {
    opacity: 0.7;
    cursor: wait;
}

.msg-audio .play-btn.error {
    background: #e74c3c;
}

.msg-audio .audio-info {
    flex: 1;
    color: #e9edef;
    font-size: 13px;
}

.msg-audio .audio-progress {
    width: 100%;
    height: 4px;
    background: #3b4a54;
    border-radius: 2px;
    margin-top: 6px;
    cursor: pointer;
    position: relative;
}

.msg-audio .audio-progress .progress-bar {
    height: 100%;
    background: #25d366;
    border-radius: 2px;
    width: 0;
    transition: width .1s;
}

.msg-audio .audio-time {
    font-size: 11px;
    color: #8696a0;
    margin-top: 4px;
    display: flex;
    justify-content: space-between;
}

.msg-audio .transcription {
    color: #8696a0;
    font-size: 13px;
    padding: 8px 12px;
    background: #111b21;
    border-radius: 6px;
    border-left: 3px solid #25d366;
    margin-top: 8px;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

.msg-audio .transcription-label {
    color: #25d366;
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 2px;
}

/* --- FILES --- */
.msg-file {
    margin-top: 8px;
    padding: 12px 16px;
    background: #1f2c33;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: #e9edef;
    border: 1px solid #2a3942;
    transition: background .2s;
}

.msg-file:hover {
    background: #2a3942;
}

.msg-file .file-icon {
    font-size: 28px;
    color: #25d366;
    flex-shrink: 0;
}

.msg-file .file-info {
    flex: 1;
    min-width: 0;
}

.msg-file .file-name {
    font-size: 14px;
    font-weight: 500;
    color: #e9edef;
    word-break: break-all;
}

.msg-file .file-size {
    font-size: 12px;
    color: #8696a0;
}

.msg-file .file-download {
    color: #25d366;
    font-size: 18px;
}

/* --- PDF --- */
.pdf-viewer {
    margin-top: 8px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #2a3942;
}

.pdf-viewer iframe {
    width: 100%;
    height: 400px;
    border: none;
    background: #fff;
}

.pdf-viewer .pdf-controls {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: #111b21;
    border-top: 1px solid #2a3942;
    flex-wrap: wrap;
}

.pdf-viewer .pdf-controls button {
    padding: 6px 12px;
    background: #25d366;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.pdf-viewer .pdf-controls button:hover {
    background: #1fa855;
}

.pdf-viewer .pdf-controls a {
    color: #25d366;
    text-decoration: none;
    font-size: 12px;
    padding: 6px 12px;
    border: 1px solid #25d366;
    border-radius: 4px;
}

.pdf-viewer .pdf-controls a:hover {
    background: #25d366;
    color: #fff;
}

/* --- LIGHTBOX --- */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, .95);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 20px;
}

.lightbox.active {
    display: flex;
}

.lightbox img {
    max-width: 90%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
}

.lightbox .close-lightbox {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #fff;
    font-size: 40px;
    cursor: pointer;
    background: 0 0;
    border: none;
    z-index: 10;
}

.lightbox .lightbox-caption {
    color: #fff;
    margin-top: 16px;
    font-size: 14px;
    text-align: center;
    max-width: 80%;
}

.lightbox .lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #fff;
    font-size: 40px;
    cursor: pointer;
    padding: 16px;
    background: rgba(0, 0, 0, .5);
    border-radius: 50%;
    border: none;
    z-index: 10;
    transition: background .2s;
}

.lightbox .lightbox-nav:hover {
    background: rgba(255, 255, 255, .2);
}

.lightbox .lightbox-nav.prev {
    left: 20px;
}

.lightbox .lightbox-nav.next {
    right: 20px;
}

/* --- EMPTY STATE --- */
.empty-state {
    color: #8696a0;
    text-align: center;
    margin: auto;
    font-size: 16px;
    padding: 40px;
}

.empty-state i {
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state.error {
    color: #e74c3c;
}

.empty-state .retry-btn {
    margin-top: 12px;
    padding: 8px 24px;
    background: #25d366;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.empty-state .retry-btn:hover {
    background: #1fa855;
}

/* --- LAZY PLACEHOLDER --- */
.lazy-placeholder {
    min-height: 100px;
    background: #1f2c33;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #8696a0;
    font-size: 14px;
    padding: 20px;
    margin-top: 8px;
}

.lazy-placeholder i {
    margin-right: 8px;
}

.lazy-placeholder.error {
    color: #e74c3c;
}

/* --- SCROLL TRIGGER --- */
.scroll-trigger-top {
    text-align: center;
    padding: 12px;
    color: #8696a0;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.3s ease;
    border-radius: 8px;
    margin: 5px 0;
}

.scroll-trigger-top:hover {
    background: rgba(37, 211, 102, 0.05);
}

/* --- ANIMATIONS --- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #111b21;
}

::-webkit-scrollbar-thumb {
    background: #2a3942;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3b4a54;
}

/* --- AUDIO DOWNLOAD BUTTON --- */
.msg-audio .audio-download-wrapper {
    margin-left: auto;
    display: flex;
    align-items: center;
}

.msg-audio .audio-download-btn {
    background: transparent;
    border: none;
    color: #25d366;
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 50%;
    transition: all 0.2s ease;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.msg-audio .audio-download-btn:hover {
    background: rgba(37, 211, 102, 0.1);
    transform: scale(1.1);
}

.msg-audio .audio-download-btn:active {
    transform: scale(0.9);
}

.msg-audio .audio-download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.msg-audio .audio-download-btn .fa-check {
    color: #25d366;
}

.message.received .msg-audio .audio-download-btn {
    color: #25d366;
}

.message.sent .msg-audio .audio-download-btn {
    color: #fff;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* --- Tablets y pantallas medianas --- */
@media(max-width: 1024px) {
    #sidebar {
        width: 280px;
        min-width: 280px;
    }
}

/* --- Móviles y pantallas pequeñas --- */
@media(max-width: 768px) {
    /* Botón toggle visible en móvil */
    .sidebar-toggle-btn {
        display: flex;
    }

    /* Sidebar oculto por defecto en móvil */
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        transform: translateX(-100%);
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.5);
        border-right: 1px solid #2a3942;
        border-radius: 0;
        z-index: 100;
    }

    /* Sidebar abierto */
    #sidebar.open {
        transform: translateX(0);
    }

    /* Overlay visible cuando sidebar está abierto */
    #sidebar-overlay.active {
        display: block;
    }

    /* Ajustes del chat view */
    #chat-view {
        margin-left: 0;
        width: 100%;
    }

    #messages-container {
        padding: 12px 16px;
    }

    .message {
        max-width: 85%;
    }

    .pdf-viewer iframe {
        height: 300px;
    }

    /* Mostrar toggle en header del sidebar */
    #sidebar-header .sidebar-toggle {
        display: block;
    }

    /* Ocultar el botón flotante cuando el sidebar está abierto */
    .sidebar-toggle-btn.hidden {
        display: none;
    }
}

@media(max-width: 480px) {
    #sidebar {
        width: 100%;
        max-width: 100%;
    }

    #messages-container {
        padding: 8px 12px;
    }
    
    .msg-audio {
        min-width: unset;
    }
    
    .lightbox .lightbox-nav {
        padding: 10px;
        font-size: 24px;
    }

    #chat-header {
        padding: 12px 16px;
    }

    #chat-header h3 {
        font-size: 14px;
    }

    .message {
        max-width: 90%;
    }
}