/* Estilos del widget del chatbot */
#opbro-widget {
    position: fixed;
    z-index: 9999;
}

#opbro-widget.opbro-right {
    right: 20px;
}

#opbro-widget.opbro-left {
    left: 20px;
}

/* Icono del chat - SIN bordes ni fondo cuando hay imagen personalizada */
.opbro-trigger {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #1c242c;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.opbro-trigger:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}


.opbro-trigger.has-custom-icon:hover {
    box-shadow: none !important;
}

/* Tooltip emergente */
.opbro-tooltip {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: #1c242c;
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    white-space: nowrap;
    margin-bottom: 10px;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.opbro-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 20px;
    border: 6px solid transparent;
    border-top-color: #1c242c;
}

/* Ventana del chat - ALTURA FIJA Y RESPONSIVE */
.opbro-chat {
    position: absolute;
    bottom: 80px;
    width: 350px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 40px rgba(0,0,0,0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#opbro-widget.opbro-right .opbro-chat {
    right: 0;
}

#opbro-widget.opbro-left .opbro-chat {
    left: 0;
}

/* Header fijo */
.opbro-header {
    background: #1c242c;
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.opbro-bot-name {
    font-weight: 600;
}

.opbro-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

/* Formulario de contacto */
.opbro-contact-form {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

.opbro-contact-form input {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.opbro-button {
    padding: 12px;
    background: #1c242c;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

.opbro-button:hover {
    opacity: 0.9;
}

/* Interfaz del chat - Layout fijo con scroll */
.opbro-chat-interface {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Área de mensajes - SCROLL INTERNO */
.opbro-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

.opbro-message {
    padding: 10px 14px;
    border-radius: 12px;
    max-width: 70%;
    word-wrap: break-word;
    word-break: break-word;
}

.opbro-message-user {
    background: #1c242c;
    color: white;
    align-self: flex-end;
    margin-left: auto;
}

.opbro-message-bot {
    background: #f1f1f1;
    color: #333;
    align-self: flex-start;
}

.opbro-message-admin {
    background: #0073aa;
    color: white;
    align-self: flex-start;
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    opacity: 0.9;
}

.message-text {
    line-height: 1.4;
    word-wrap: break-word;
}

.message-attachment {
    margin-top: 8px;
}

.message-attachment img {
    max-width: 100%;
    border-radius: 8px;
}

.opbro-typing {
    padding: 10px 14px;
    background: #f1f1f1;
    border-radius: 12px;
    max-width: 70%;
    align-self: flex-start;
}

.opbro-typing span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    margin: 0 2px;
    animation: typing 1.4s infinite;
}

.opbro-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.opbro-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Contenedor de input - FIJO EN LA PARTE INFERIOR */
.opbro-input-container {
    display: flex;
    padding: 15px;
    border-top: 1px solid #eee;
    gap: 8px;
    flex-shrink: 0;
    background: white;
    align-items: center;
}

#opbro-message-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    min-height: 40px;
}

.opbro-send-btn {
    padding: 10px 20px;
    background: #1c242c;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    flex-shrink: 0;
}

.opbro-send-btn:hover {
    opacity: 0.9;
}

.opbro-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Botón de adjuntar */
.opbro-attach-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    opacity: 0.7;
    flex-shrink: 0;
}

.opbro-attach-btn:hover {
    opacity: 1;
}

/* Preview de archivo */
.opbro-file-preview {
    padding: 10px 15px;
    border-top: 1px solid #eee;
    background: #f9f9f9;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.opbro-file-preview img {
    max-width: 60px;
    max-height: 60px;
    border-radius: 4px;
}

.opbro-file-preview-remove {
    margin-left: auto;
    background: #dc3232;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

/* Adjuntos en mensajes */
.message-attachment {
    margin-top: 8px;
}

.message-attachment img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
}

.message-attachment a {
    color: inherit;
    text-decoration: underline;
}

/* Tema oscuro */
.opbro-theme-dark .opbro-chat {
    background: #2d3748;
}

.opbro-theme-dark .opbro-message-bot {
    background: #4a5568;
    color: white;
}

.opbro-theme-dark .opbro-input-container {
    background: #2d3748;
    border-top-color: #4a5568;
}

.opbro-theme-dark #opbro-message-input {
    background: #4a5568;
    border-color: #4a5568;
    color: white;
}

.opbro-theme-dark .opbro-contact-form input {
    background: #4a5568;
    border-color: #4a5568;
    color: white;
}

/* RESPONSIVE - Mobile */
@media (max-width: 480px) {
    .opbro-chat {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        bottom: 0;
        right: 0 !important;
        left: 0 !important;
        border-radius: 0;
    }
    
    #opbro-widget.opbro-right,
    #opbro-widget.opbro-left {
        bottom: 10px;
        right: 10px;
    }
    
    .opbro-trigger {
        width: 56px;
        height: 56px;
    }
    
    .opbro-tooltip {
        font-size: 12px;
        padding: 6px 10px;
    }
    
    .opbro-message {
        max-width: 85%;
    }
}

/* Tablet */
@media (max-width: 768px) and (min-width: 481px) {
    .opbro-chat {
        width: calc(100vw - 40px);
        height: 80vh;
        max-height: 600px;
    }
}

/* Scrollbar personalizado */
.opbro-messages::-webkit-scrollbar {
    width: 6px;
}

.opbro-messages::-webkit-scrollbar-track {
    background: transparent;
}

.opbro-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.opbro-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Botón cerrar sesión */
.opbro-close-session-container {
    padding: 8px 15px;
    background: #f9f9f9;
    border-top: 1px solid #e0e0e0;
}

.opbro-close-session-btn {
    width: 100%;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #d32f2f;
    color: #d32f2f;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.opbro-close-session-btn:hover {
    background: #d32f2f;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(211, 47, 47, 0.2);
}

.opbro-close-session-btn:active {
    transform: translateY(0);
}

/* Badge de notificación en botón flotante */
.opbro-trigger {
    position: relative;
}

.opbro-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #d63638;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.opbro-badge.hidden {
    display: none;
}

/* Botones de acciones en header */
.opbro-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.opbro-icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    color: white;
}

.opbro-icon-btn:hover {
    background: rgba(255,255,255,0.1);
}

.opbro-icon-btn svg {
    display: block;
}

/* Modales */
.opbro-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.opbro-modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    animation: slideUp 0.3s;
}

.opbro-modal-small {
    max-width: 400px;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.opbro-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e1e8ed;
}

.opbro-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1c242c;
}

.opbro-modal-close {
    background: transparent;
    border: none;
    font-size: 28px;
    color: #657786;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.opbro-modal-close:hover {
    background: #f1f3f5;
}

.opbro-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.opbro-loading {
    text-align: center;
    color: #657786;
    padding: 20px;
}

/* FAQ Item */
.opbro-faq-item {
    margin-bottom: 15px;
    border: 1px solid #e1e8ed;
    border-radius: 8px;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.opbro-faq-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.opbro-faq-question {
    background: #f8f9fa;
    padding: 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: #1c242c;
    user-select: none;
}

.opbro-faq-question:hover {
    background: #e9ecef;
}

.opbro-faq-icon {
    font-size: 20px;
    transition: transform 0.3s;
}

.opbro-faq-item.open .opbro-faq-icon {
    transform: rotate(180deg);
}

.opbro-faq-answer {
    padding: 0 15px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s, padding 0.3s;
    color: #495057;
    line-height: 1.6;
}

.opbro-faq-item.open .opbro-faq-answer {
    max-height: 500px;
    padding: 15px;
}

/* WhatsApp Options */
.opbro-whatsapp-option {
    background: #f8f9fa;
    border: 1px solid #e1e8ed;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.opbro-whatsapp-option:hover {
    background: #25D366;
    color: white;
    border-color: #25D366;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.opbro-whatsapp-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.opbro-whatsapp-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.opbro-whatsapp-name {
    font-weight: 600;
    font-size: 16px;
    color: #1a1a1a;
}

.opbro-whatsapp-name strong {
    display: flex;
    align-items: center;
    gap: 6px;
}

.opbro-whatsapp-phone {
    font-size: 14px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 6px;
}

.opbro-whatsapp-address {
    font-size: 13px;
    opacity: 0.75;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    line-height: 1.4;
}

.opbro-whatsapp-option:hover .opbro-whatsapp-name,
.opbro-whatsapp-option:hover .opbro-whatsapp-phone,
.opbro-whatsapp-option:hover .opbro-whatsapp-address {
    color: white;
    opacity: 1;
}

/* Responsive */
@media (max-width: 480px) {
    .opbro-modal-content {
        width: 95%;
        max-height: 90vh;
    }
    
    .opbro-modal-header h3 {
        font-size: 16px;
    }
    
    .opbro-faq-question {
        font-size: 14px;
        padding: 12px;
    }
    
    .opbro-faq-answer {
        font-size: 13px;
    }
}

/* ===== MEJORAS RESPONSIVE MÓVIL ===== */

/* Prevenir zoom al hacer focus en inputs en iOS */
@media (max-width: 480px) {
    input, textarea, select {
        font-size: 16px !important;
    }
}

/* Asegurar que el chat ocupe toda la pantalla en móvil */
@media (max-width: 480px) {
    .opbro-chat {
        position: fixed !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        bottom: 0 !important;
        top: 0 !important;
        right: 0 !important;
        left: 0 !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    
    /* Mensajes más anchos en móvil */
    .opbro-message {
        max-width: 90% !important;
        font-size: 14px;
    }
    
    /* Texto más legible */
    .message-text {
        line-height: 1.5;
    }
    
    /* Links más fáciles de tocar */
    .message-text a {
        padding: 4px 8px;
        display: inline-block;
        margin: 2px 0;
    }
    
    /* Header responsive */
    .opbro-header {
        padding: 12px 15px;
    }
    
    .opbro-bot-name {
        font-size: 16px;
    }
    
    /* Input más grande para tocar fácilmente */
    #opbro-message-input {
        font-size: 16px !important;
        padding: 12px 15px;
        min-height: 44px;
    }
    
    /* Botón enviar más grande */
    .opbro-send-btn {
        padding: 12px 18px;
        min-width: 60px;
        font-size: 14px;
    }
    
    /* Contenedor de input con mejor espaciado */
    .opbro-input-container {
        padding: 12px;
        gap: 10px;
    }
    
    /* Botón flotante más accesible */
    .opbro-trigger {
        width: 60px;
        height: 60px;
        bottom: 20px;
        right: 20px;
    }
    
    #opbro-widget.opbro-right {
        right: 15px;
        bottom: 15px;
    }
    
    #opbro-widget.opbro-left {
        left: 15px;
        bottom: 15px;
    }
    
    /* Scrollbar visible en móvil */
    .opbro-messages::-webkit-scrollbar {
        width: 8px;
    }
    
    /* Productos más legibles */
    .opbro-message-bot strong {
        font-size: 15px;
    }
    
    /* Evitar que el contenido se salga */
    .opbro-messages {
        padding: 12px;
        word-break: break-word;
        overflow-wrap: break-word;
    }
    
    /* Modal responsive */
    .opbro-modal-content {
        width: 100% !important;
        height: 100% !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
    
    .opbro-modal-header {
        padding: 15px;
    }
    
    .opbro-modal-body {
        padding: 15px;
    }
    
    /* WhatsApp options responsive */
    .opbro-whatsapp-option {
        padding: 12px;
        font-size: 14px;
    }
    
    .opbro-whatsapp-name {
        font-size: 15px !important;
    }
    
    .opbro-whatsapp-phone,
    .opbro-whatsapp-address {
        font-size: 13px !important;
    }
}

/* Landscape móvil */
@media (max-width: 896px) and (max-height: 480px) and (orientation: landscape) {
    .opbro-chat {
        height: 100vh !important;
    }
    
    .opbro-messages {
        padding: 10px;
    }
    
    .opbro-header {
        padding: 10px 15px;
    }
    
    .opbro-input-container {
        padding: 10px;
    }
}

/* Tablet portrait */
@media (min-width: 481px) and (max-width: 768px) {
    .opbro-chat {
        width: 400px;
        max-width: calc(100vw - 40px);
        height: 600px;
        max-height: calc(100vh - 120px);
    }
    
    .opbro-message {
        max-width: 80%;
        font-size: 14px;
    }
}

/* Tablet landscape y desktop pequeño */
@media (min-width: 769px) and (max-width: 1024px) {
    .opbro-chat {
        width: 380px;
        height: 550px;
    }
}

/* Prevenir problemas con viewport en iOS */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 480px) {
        .opbro-chat {
            height: -webkit-fill-available !important;
        }
        
        .opbro-messages {
            max-height: -webkit-fill-available;
        }
    }
}
