﻿ 
* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
}

body, input, button, textarea, select {
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
}

.cb-body {
    height: 100vh;
    overflow: hidden;
}

.cb-app {
    display: flex;
    height: 100vh;
    width: 100%;
}

 
.cb-main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 370px;
    grid-template-rows: auto 1fr;
    height: 100vh;
    min-height: 0;
}
 

/*.cb-sidebar {
    width: 320px;
    background: #f7f9fc;
    border-right: 1px solid #dbe3ee;
    display: flex;
    flex-direction: column;
}*/

.cb-sidebar {
    width: 320px;
    background: #f7f9fc;
    border-right: 1px solid #dbe3ee;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-height: 0;
}

.cb-logo {
    background: linear-gradient(135deg, #2278bd, #1f5ea8);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 26px;
}

.cb-logo-icon {
    font-size: 28px;
}

.cb-menu {
    padding: 20px 16px 8px;
}

.cb-menu-item {
    display: block;
    color: #1f2a38;
    text-decoration: none;
    padding: 12px 14px;
    border-radius: 12px;
    font-weight: 600;
}

    .cb-menu-item.active {
        background: #e6eef9;
    }

.cb-filters {
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cb-filter {
    border: none;
    border-radius: 12px;
    padding: 14px;
    text-align: left;
    cursor: pointer;
    background: white;
    color: #1f2a38;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
}

    .cb-filter.active {
        background: linear-gradient(135deg, #2278bd, #356fd8);
        color: white;
    }

/*.cb-chat-list {
    flex: 1;*/ /* 🔥 ESTA ES LA CLAVE */
    /*overflow-y: auto;
    padding: 0 10px 20px;
}*/
.cb-chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 10px 20px;
}
.cb-chat-item {
    display: flex;
    gap: 12px;
    background: white;
    margin-bottom: 10px;
    border-radius: 14px;
    padding: 14px;
    cursor: pointer;
    border: 1px solid #e3e9f2;
}

    .cb-chat-item.selected {
        background: #fff3c8;
        border-color: #f0d26e;
    }

.cb-chat-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #dbe8f6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.cb-chat-info {
    flex: 1;
}

.cb-chat-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.cb-chat-bottom {
    color: #6b7a8f;
    margin-bottom: 6px;
}

.cb-chat-tags {
    display: flex;
    gap: 8px;
}

.tag, .badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

    .tag.bot {
        background: #d9f5d6;
        color: #2e7d32;
    }

    .tag.human {
        background: #dbeafe;
        color: #1d4ed8;
    }

    .tag.warning,
    .badge.warning {
        background: #ffe5a8;
        color: #8a5a00;
    }



.cb-topbar {
    grid-column: 1 / 3;
    background: white;
    border-bottom: 1px solid #dbe3ee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 22px;
}

.cb-search {
    width: 320px;
    border: 1px solid #d3dce8;
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 15px;
}

.cb-top-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

    .cb-top-actions a {
        text-decoration: none;
        color: #4a5565;
        font-weight: 600;
    }

.icon-btn {
    border: 1px solid #d3dce8;
    background: white;
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
}

/*.cb-center {
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    border-right: 1px solid #dbe3ee;
}*/

.cb-center {
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    border-right: 1px solid #dbe3ee;
    min-height: 0;
}

.cb-conversation-header {
    background: white;
    padding: 18px 24px;
    border-bottom: 1px solid #dbe3ee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

    .cb-conversation-header h2 {
        margin: 0;
        font-size: 36px;
    }

.cb-phone {
    color: #6b7a8f;
    margin-top: 4px;
}

.cb-header-actions {
    display: flex;
    gap: 10px;
}

/*.cb-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}*/
.cb-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
}

.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 18px;
}

    .msg-row.bot {
        justify-content: flex-start;
    }

    .msg-row.cliente {
        justify-content: flex-start;
    }

/*.msg-bubble {
    max-width: 620px;
    padding: 18px;
    border-radius: 18px;
    font-size: 16px;
    line-height: 1.45;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}*/
.msg-bubble {
    width: fit-content;
    max-width: 680px;
    padding: 18px;
    border-radius: 18px;
    font-size: 16px;
    line-height: 1.45;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
    overflow: hidden;
    word-break: break-word;
}

.msg-row.bot .msg-bubble {
    background: #e8f0fb;
}

.msg-row.cliente .msg-bubble {
    background: #f8f1dd;
}

.msg-author {
    font-weight: 700;
    margin-bottom: 8px;
}

.msg-time {
    color: #7b8798;
    font-size: 13px;
    min-width: 70px;
}

.file-card,
.file-preview {
    max-width: 100%;
    overflow: hidden;
}

.file-title {
    padding: 12px 14px;
    font-weight: 700;
}

.file-preview img {
    display: block;
    width: 100%;
    max-width: 520px;
}

.cb-composer {
    background: white;
    border-top: 1px solid #dbe3ee;
    padding: 16px;
    display: flex;
    gap: 12px;
    align-items: center;
}

    .cb-composer input {
        flex: 1;
        border: 1px solid #d3dce8;
        border-radius: 14px;
        padding: 14px 16px;
        font-size: 15px;
    }

.attach-btn, .send-btn {
    border: none;
    border-radius: 14px;
    padding: 14px 18px;
    cursor: pointer;
}

.attach-btn {
    background: #f0f4f8;
}

.send-btn, .action-btn {
    background: #2278bd;
    color: white;
}

.cb-right {
    background: #f8fafc;
    padding: 18px;
    overflow-y: auto;
}

.cb-card {
    background: white;
    border: 1px solid #dbe3ee;
    border-radius: 18px;
    padding: 18px;
    margin-bottom: 16px;
}

.cb-badges {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.card-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cart-item {
    padding: 14px 0;
    border-bottom: 1px solid #edf1f5;
}

.cart-name {
    font-weight: 700;
    margin-bottom: 6px;
}

.cart-prices {
    display: flex;
    justify-content: space-between;
    color: #4a5565;
}

.cart-total {
    padding-top: 16px;
    font-size: 18px;
}

.action-btn {
    width: 100%;
    margin-top: 16px;
    padding: 14px;
    border: none;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

@media (max-width: 1200px) {
    .cb-main {
        grid-template-columns: 1fr;
    }

    .cb-right {
        display: none;
    }

    .cb-topbar {
        grid-column: 1 / 2;
    }
}

.msg-html-content {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

    .msg-html-content > div {
        display: flex !important;
        align-items: flex-start;
        gap: 14px;
        width: 100% !important;
        max-width: 100% !important;
        padding: 12px !important;
        border: 1px solid #d9e1ea !important;
        border-radius: 12px !important;
        background: #fff !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    .msg-html-content img {
        width: 96px !important;
        min-width: 96px !important;
        max-width: 96px !important;
        height: 96px !important;
        object-fit: contain !important;
        display: block !important;
        float: none !important;
        margin: 0 !important;
        border-radius: 8px !important;
        background: #fff !important;
        flex-shrink: 0 !important;
    }

    .msg-html-content > div > div:last-child {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }

    .msg-html-content strong {
        display: block !important;
        font-size: 15px !important;
        line-height: 1.35 !important;
        margin-bottom: 6px !important;
        color: #1f2a38 !important;
        white-space: normal !important;
        word-break: break-word !important;
    }

    .msg-html-content span,
    .msg-html-content em {
        display: block !important;
        white-space: normal !important;
        word-break: break-word !important;
        line-height: 1.35 !important;
    }

    .msg-html-content em {
        margin-top: 6px !important;
        color: #6b7a8f !important;
    }

    .msg-html-content * {
        box-sizing: border-box !important;
    }


/* ===== NUEVO FORMATO LIMPIO ===== */
.wa-product-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    width: 100%;
    max-width: 100%;
    padding: 12px;
    border: 1px solid #d9e1ea;
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
}

.wa-product-img {
    flex: 0 0 88px;
}

    .wa-product-img img {
        width: 88px;
        height: 88px;
        object-fit: contain;
        display: block;
        border-radius: 8px;
        background: #fff;
    }

.wa-product-info {
    flex: 1 1 auto;
    min-width: 0;
}

.wa-product-title {
    font-weight: 700;
    font-size: 15px;
    line-height: 1.35;
    color: #1f2a38;
    margin-bottom: 8px;
    word-break: break-word;
}

.wa-product-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 14px;
}

.wa-product-ref {
    color: #2278bd;
    font-weight: 600;
}

.wa-product-stock {
    color: #2e7d32;
    font-weight: 600;
}

.wa-product-out {
    color: #c62828;
    font-weight: 700;
}

.wa-product-footer {
    color: #6b7a8f;
    font-size: 13px;
}

/* ===== COMPATIBILIDAD CON MENSAJES VIEJOS ===== */
.msg-html-content {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

    .msg-html-content > div {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .msg-html-content img {
        max-width: 88px !important;
        width: 88px !important;
        min-width: 88px !important;
        height: 88px !important;
        object-fit: contain !important;
        display: block !important;
        float: none !important;
        margin: 0 !important;
        border-radius: 8px !important;
        background: #fff !important;
    }

    .msg-html-content > div[style] {
        display: flex !important;
        align-items: flex-start !important;
        gap: 14px !important;
        overflow: hidden !important;
    }

        .msg-html-content > div[style] > div:last-child {
            flex: 1 1 auto !important;
            min-width: 0 !important;
            overflow: hidden !important;
        }

    .msg-html-content strong,
    .msg-html-content span,
    .msg-html-content em {
        display: block;
        word-break: break-word;
        white-space: normal;
    }

.cb-chat-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cb-delete-chat-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    color: #c62828;
    padding: 2px 4px;
}

    .cb-delete-chat-btn:hover {
        transform: scale(1.08);
    }

.cb-extra {
    color: #6b7a8f;
    font-size: 13px;
    margin-top: 6px;
    word-break: break-word;
}

/* ============================= */
/* CHAT PENDIENTE (NO LEÍDO) */
/* ============================= */

.cb-chat-item.pending-unread {
    background: #e9fff3; /* verde muy suave */
    border-left: 5px solid #25d366; /* verde WhatsApp */
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.15);
    position: relative;
    transition: all 0.2s ease;
}

    /* Hover elegante */
    .cb-chat-item.pending-unread:hover {
        background: #dfffee;
    }

    /* Nombre del chat */
    .cb-chat-item.pending-unread .cb-chat-top strong {
        color: #0f5132;
        font-weight: 700;
    }

    /* Texto secundario */
    .cb-chat-item.pending-unread .cb-chat-bottom span {
        color: #198754;
        font-weight: 600;
    }

    /* ============================= */
    /* INDICADOR LATERAL (BRILLO) */
    /* ============================= */

    /*.cb-chat-item.pending-unread::before {
        content: "";
        position: absolute;
        left: 0;
        top: 6px;
        bottom: 6px;
        width: 4px;
        background: linear-gradient(180deg, #25d366, #128c7e);
        border-radius: 4px;
    }*/

    /* ============================= */
    /* PUNTO DE NUEVO MENSAJE */
    /* ============================= */

    .cb-chat-item.pending-unread::after {
        content: "●";
        position: absolute;
        bottom: 12px;
        right: 12px;
        color: #25d366;
        font-size: 20px;
        animation: pulseDot 1.5s infinite;
    }

/* ============================= */
/* ANIMACIÓN SUAVE */
/* ============================= */

@keyframes pulseDot {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.4);
        opacity: 0.6;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================= */
/* ENTRADA DE NUEVO CHAT */
/* ============================= */

.cb-chat-item.pending-unread {
    animation: fadeInChat 0.3s ease;
}

@keyframes fadeInChat {
    from {
        transform: translateY(-5px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.msg-row.operador {
    justify-content: flex-end;
}

    .msg-row.operador .msg-bubble {
        background: #dbeafe;
    }

.msg-status {
    margin-top: 8px;
    font-size: 12px;
    color: #6b7a8f;
}

.tag.talk-human {
    background: #fde2e2;
    color: #b71c1c;
}

.cb-chat-item.needs-human {
    background: #fff5f5;
    border-left: 5px solid #e53935;
    box-shadow: 0 2px 10px rgba(229, 57, 53, 0.18);
    animation: pulseHumanAlert 1.4s infinite;
}

@keyframes pulseHumanAlert {
    0% {
        box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.32);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(229, 57, 53, 0.08);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(229, 57, 53, 0);
    }
}

.cb-chat-more-info {
    padding: 8px 14px 16px;
}

.cb-chat-remaining {
    text-align: center;
    font-size: 13px;
    color: #6b7a8f;
    background: #eef3f8;
    border: 1px dashed #d3dce8;
    border-radius: 12px;
    padding: 10px 12px;
}

.msg-row {
    display: flex;
    margin-bottom: 18px;
}

    .msg-row.bot {
        justify-content: flex-start;
    }

    .msg-row.cliente {
        justify-content: flex-start;
    }

    .msg-row.operador {
        justify-content: flex-end;
    }

.msg-bubble {
    width: fit-content;
    max-width: 680px;
    padding: 14px 16px 10px;
    border-radius: 18px;
    font-size: 16px;
    line-height: 1.45;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
    overflow: hidden;
    word-break: break-word;
}

.msg-row.bot .msg-bubble {
    background: #e8f0fb;
}

.msg-row.cliente .msg-bubble {
    background: #f8f1dd;
}

.msg-row.operador .msg-bubble {
    background: #dfeafb;
}

.msg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.msg-author {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    margin-bottom: 2px;
}

.msg-author-icon {
    font-size: 16px;
    line-height: 1;
}

.msg-text {
    white-space: pre-wrap;
    word-break: break-word;
}
 

.msg-meta-inside {
    margin-top: 8px;
    font-size: 12px;
    color: #7b8798;
    text-align: right;
    line-height: 1.3;
     
}
.msg-row.bot .msg-meta-inside {
    border-top: 1px dotted rgba(0,0,0,0.1);
}

.msg-row.cliente .msg-meta-inside {
    border-top: 1px dotted rgba(0,0,0,0.1);
}

.msg-row.operador .msg-meta-inside {
    border-top: 1px dotted rgba(0,0,0,0.1);
}