/* ========== CHATBOT TINA - ESTILOS ENCAPSULADOS ========== */
/* Variables locales para el chat - NO afectan al resto */
.tina-chatbot-wrapper {
    --tina-primary: #e21013;
    --tina-secondary: #ffed00;
    --tina-light: #ffffff;
    --tina-dark: #212529;
    --tina-gray: #6c757d;
    --tina-light-gray: #f8f9fa;
    --tina-success: #28a745;
    --tina-shadow: 0 5px 25px rgba(0, 0, 0, 0.1);
    --tina-border-radius: 15px;
}

/* Contenedor principal - Posición fija */
.tina-chatbot-wrapper {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Montserrat', sans-serif;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    line-height: 1.5;
}

/* Botón flotante para abrir/cerrar */
.tina-chatbot-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--tina-primary), #ff6b6b);
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: var(--tina-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: tina-floatAnimation 3s ease-in-out infinite;
    padding: 0;
}

.tina-chatbot-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(226, 16, 19, 0.3);
}

.tina-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--tina-secondary);
    color: var(--tina-dark);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

/* Animación de flotación - Namespaced */
@keyframes tina-floatAnimation {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Contenedor del chat */
.tina-chatbot-container {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 350px;
    max-width: 95vw;
    height: 500px;
    max-height: 80vh;
    background: white;
    border-radius: var(--tina-border-radius);
    box-shadow: var(--tina-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e9ecef;
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.tina-chatbot-container.tina-show {
    display: flex;
    transform: translateY(0);
    opacity: 1;
}

/* ========== RESPONSIVE CORREGIDO - SIN SOLAPAMIENTOS ========== */

/* 1. MÓVILES MUY PEQUEÑOS (0px - 359px) */
@media screen and (max-width: 359px) {
    .tina-chatbot-wrapper {
        bottom: 10px;
        right: 10px;
        left: auto;
        width: auto;
    }
    
    .tina-chatbot-toggle-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
    
    .tina-chatbot-container {
        width: calc(100vw - 20px) !important;
        max-width: calc(100vw - 20px) !important;
        height: 70vh;
        max-height: 70vh;
        bottom: 65px;
        right: 10px;
        left: 10px;
        transform: none !important;
        border-radius: 12px;
    }
    
    .tina-chatbot-container.tina-show {
        transform: none !important;
        animation: tina-slideUpMobile 0.3s ease;
    }
    
    @keyframes tina-slideUpMobile {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    .tina-chatbot-header {
        padding: 12px 15px;
        border-radius: 12px 12px 0 0;
    }
    
    .tina-chatbot-avatar {
        width: 40px;
        height: 40px;
    }
    
    .tina-chatbot-name {
        font-size: 1rem;
    }
    
    .tina-chatbot-role {
        font-size: 0.8rem;
    }
    
    .tina-chatbot-body {
        padding: 12px;
        height: calc(100% - 150px);
    }
    
    .tina-message {
        max-width: 95%;
    }
    
    .tina-message-text {
        padding: 10px 12px;
        font-size: 0.85rem;
    }
    
    .tina-message-avatar {
        width: 28px;
        height: 28px;
    }
    
    .tina-suggestions-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .tina-suggestion-btn {
        padding: 8px;
        font-size: 0.78rem;
        line-height: 1.2;
    }
    
    .tina-suggestions-title {
        font-size: 0.8rem;
        margin-bottom: 8px;
    }
    
    .tina-chatbot-footer {
        padding: 12px;
    }
    
    .tina-input-group {
        flex-wrap: nowrap;
    }
    
    .tina-input-group .tina-form-control {
        font-size: 16px;
        padding: 10px 12px;
        min-width: 0;
        flex: 1;
    }
    
    .tina-input-group .tina-btn {
        width: 38px;
        height: 38px;
        font-size: 0.9rem;
        flex-shrink: 0;
    }
    
    .tina-chatbot-actions {
        flex-direction: row;
        justify-content: space-between;
        gap: 6px;
    }
    
    .tina-chatbot-actions .tina-btn {
        font-size: 0.75rem;
        padding: 6px 8px;
        flex: 1;
        min-width: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    
    .tina-chatbot-close-btn {
        width: 28px;
        height: 28px;
    }
    
    .tina-notification-badge {
        width: 18px;
        height: 18px;
        font-size: 0.65rem;
    }
}

/* 2. MÓVILES PEQUEÑOS (360px - 399px) */
@media screen and (min-width: 360px) and (max-width: 399px) {
    .tina-chatbot-wrapper {
        bottom: 12px;
        right: 12px;
    }
    
    .tina-chatbot-toggle-btn {
        width: 52px;
        height: 52px;
        font-size: 1.25rem;
    }
    
    .tina-chatbot-container {
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
        height: 68vh;
        max-height: 68vh;
        bottom: 68px;
        right: 12px;
        left: 12px;
        transform: none !important;
    }
    
    .tina-chatbot-container.tina-show {
        transform: none !important;
    }
    
    .tina-chatbot-header {
        padding: 14px 16px;
    }
    
    .tina-chatbot-body {
        padding: 14px;
    }
    
    .tina-message {
        max-width: 92%;
    }
    
    .tina-suggestions-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .tina-suggestion-btn {
        padding: 9px;
        font-size: 0.8rem;
    }
    
    .tina-chatbot-actions {
        flex-direction: row;
        gap: 8px;
    }
    
    .tina-chatbot-actions .tina-btn {
        font-size: 0.78rem;
        padding: 7px 10px;
    }
}

/* 3. MÓVILES MEDIANOS (400px - 479px) */
@media screen and (min-width: 400px) and (max-width: 479px) {
    .tina-chatbot-wrapper {
        bottom: 15px;
        right: 15px;
    }
    
    .tina-chatbot-toggle-btn {
        width: 54px;
        height: 54px;
        font-size: 1.3rem;
    }
    
    .tina-chatbot-container {
        width: calc(100vw - 30px);
        max-width: 420px;
        height: 65vh;
        max-height: 65vh;
        bottom: 72px;
        right: 15px;
        left: 50%;
        transform: translateX(-50%) translateY(20px) !important;
    }
    
    .tina-chatbot-container.tina-show {
        transform: translateX(-50%) translateY(0) !important;
    }
    
    .tina-chatbot-header {
        padding: 15px 18px;
    }
    
    .tina-chatbot-body {
        padding: 16px;
    }
    
    .tina-suggestions-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

/* 4. MÓVILES GRANDES (480px - 575px) */
@media screen and (min-width: 480px) and (max-width: 575px) {
    .tina-chatbot-wrapper {
        bottom: 18px;
        right: 18px;
    }
    
    .tina-chatbot-container {
        width: 420px;
        max-width: calc(100vw - 36px);
        height: 70vh;
        max-height: 70vh;
        bottom: 75px;
        right: 18px;
        left: 50%;
        transform: translateX(-50%) translateY(20px) !important;
    }
    
    .tina-chatbot-container.tina-show {
        transform: translateX(-50%) translateY(0) !important;
    }
    
    .tina-chatbot-header {
        padding: 16px 20px;
    }
}

/* 5. TABLETS PEQUEÑAS (576px - 679px) */
@media screen and (min-width: 576px) and (max-width: 679px) {
    .tina-chatbot-wrapper {
        bottom: 20px;
        right: 20px;
    }
    
    .tina-chatbot-container {
        width: 450px;
        max-width: calc(100vw - 40px);
        height: 75vh;
        max-height: 75vh;
        bottom: 80px;
        right: 20px;
        left: auto;
        transform: translateY(20px) !important;
    }
    
    .tina-chatbot-container.tina-show {
        transform: translateY(0) !important;
    }
}

/* 6. TABLETS (680px - 750px) */
@media screen and (min-width: 680px) and (max-width: 750px) {
    .tina-chatbot-container {
        width: 480px;
        height: 550px;
        max-height: 70vh;
        bottom: 85px;
    }
}

/* 7. TABLETAS GRANDES Y PEQUEÑOS DESKTOPS (751px - 991px) */
@media screen and (min-width: 751px) and (max-width: 991px) {
    .tina-chatbot-container {
        width: 400px;
        height: 550px;
        max-height: 75vh;
    }
}

/* 8. DESKTOP (992px en adelante) */
@media screen and (min-width: 992px) {
    .tina-chatbot-container {
        width: 380px;
        height: 600px;
        max-height: 80vh;
    }
    
    .tina-chatbot-container.tina-show {
        animation: tina-slideInUp 0.3s ease;
    }
    
    @keyframes tina-slideInUp {
        from {
            transform: translateY(20px);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
}

/* 9. LANDSCAPE EN MÓVILES */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .tina-chatbot-container {
        height: 85vh !important;
        max-height: 85vh !important;
        width: 75vw !important;
        max-width: 75vw !important;
        bottom: 65px !important;
        right: 10px !important;
    }
    
    .tina-chatbot-body {
        height: calc(100% - 140px) !important;
    }
    
    .tina-suggestions-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ========== ESTILOS INTERNOS (SIN CAMBIOS) ========== */

/* Header del chat */
.tina-chatbot-header {
    background: linear-gradient(135deg, var(--tina-primary), #ff6b6b);
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    position: relative;
}

.tina-chatbot-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.tina-chatbot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tina-chatbot-info {
    flex: 1;
}

.tina-chatbot-name {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tina-status-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
    display: inline-block;
}

.tina-status-badge.tina-online {
    background: rgba(40, 167, 69, 0.2);
    color: #28a745;
    border: 1px solid rgba(40, 167, 69, 0.3);
}

.tina-chatbot-role {
    margin: 2px 0 0 0;
    font-size: 0.85rem;
    opacity: 0.9;
}

.tina-chatbot-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    padding: 0;
}

.tina-chatbot-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* Cuerpo del chat */
.tina-chatbot-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--tina-light-gray);
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 0;
}

/* Scrollbar personalizado */
.tina-chatbot-body::-webkit-scrollbar {
    width: 6px;
}

.tina-chatbot-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.tina-chatbot-body::-webkit-scrollbar-thumb {
    background: var(--tina-primary);
    border-radius: 3px;
}

.tina-chatbot-body::-webkit-scrollbar-thumb:hover {
    background: #ff6b6b;
}

/* Estilos para mensajes */
.tina-message-wrapper {
    display: flex;
    flex-direction: column;
}

.tina-message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: tina-messageAppear 0.3s ease;
}

@keyframes tina-messageAppear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tina-message-incoming {
    align-self: flex-start;
}

.tina-message-outgoing {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.tina-message-outgoing .tina-message-content {
    align-items: flex-end;
}

.tina-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    margin-top: 5px;
}

.tina-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tina-message-content {
    display: flex;
    flex-direction: column;
}

.tina-message-text {
    background: white;
    padding: 12px 15px;
    border-radius: 15px;
    font-size: 0.9rem;
    line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    margin: 0;
    font-weight: 400;
}

.tina-message-incoming .tina-message-text {
    background: white;
    border-top-left-radius: 5px;
    color: var(--tina-dark);
}

.tina-message-outgoing .tina-message-text {
    background: linear-gradient(135deg, var(--tina-primary), #ff6b6b);
    color: white;
    border-top-right-radius: 5px;
}

.tina-message-time {
    font-size: 0.75rem;
    color: var(--tina-gray);
    margin-top: 4px;
    padding: 0 5px;
    display: block;
}

.tina-message-outgoing .tina-message-time {
    text-align: right;
}

/* Sugerencias de preguntas */
.tina-suggestions-wrapper {
    margin-top: 10px;
}

.tina-suggestions-title {
    font-size: 0.85rem;
    color: var(--tina-gray);
    margin-bottom: 10px;
    font-weight: 500;
    display: block;
}

.tina-suggestions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.tina-suggestion-btn {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.8rem;
    color: var(--tina-dark);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
    margin: 0;
    font-family: inherit;
    text-decoration: none;
    display: block;
    width: 100%;
}

.tina-suggestion-btn:hover {
    background: var(--tina-light-gray);
    border-color: var(--tina-primary);
    transform: translateY(-2px);
}

/* Footer del chat */
.tina-chatbot-footer {
    padding: 15px;
    background: white;
    border-top: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
}

/* Indicador de "escribiendo" */
.tina-typing-indicator {
    display: none;
    align-items: center;
    gap: 5px;
    font-size: 0.85rem;
    color: var(--tina-gray);
    padding: 5px 10px;
    background: var(--tina-light-gray);
    border-radius: 10px;
    width: fit-content;
    animation: tina-typingPulse 1.5s infinite;
}

.tina-typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--tina-primary);
    border-radius: 50%;
    display: inline-block;
    animation: tina-typingBounce 1.4s infinite ease-in-out both;
}

.tina-typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.tina-typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes tina-typingBounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

@keyframes tina-typingPulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Input y botones */
.tina-input-group {
    display: flex;
    gap: 8px;
    width: 100%;
}

.tina-input-group .tina-form-control {
    border-radius: 25px;
    border: 1px solid #dee2e6;
    padding: 10px 15px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    flex: 1;
    margin: 0;
    font-family: inherit;
    line-height: 1.5;
    background-color: white;
    color: var(--tina-dark);
    box-sizing: border-box;
}

.tina-input-group .tina-form-control:focus {
    border-color: var(--tina-primary);
    box-shadow: 0 0 0 0.25rem rgba(226, 16, 19, 0.25);
    outline: none;
}

.tina-input-group .tina-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    border: 1px solid transparent;
    font-family: inherit;
    text-align: center;
    cursor: pointer;
    user-select: none;
}

.tina-input-group .tina-btn-primary {
    background: linear-gradient(135deg, var(--tina-primary), #ff6b6b);
    border: none;
    color: white;
}

.tina-input-group .tina-btn-primary:hover {
    background: linear-gradient(135deg, #ff6b6b, var(--tina-primary));
    transform: scale(1.05);
}

.tina-input-group .tina-btn-outline-secondary {
    border-color: #dee2e6;
    background: white;
    color: var(--tina-gray);
}

.tina-input-group .tina-btn-outline-secondary:hover {
    border-color: var(--tina-primary);
    color: var(--tina-primary);
    background: white;
}

/* Acciones del chat */
.tina-chatbot-actions {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.tina-chatbot-actions .tina-btn {
    font-size: 0.8rem;
    padding: 5px 10px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    gap: 5px;
    border: 1px solid transparent;
    font-family: inherit;
    text-align: center;
    cursor: pointer;
    user-select: none;
}

.tina-chatbot-actions .tina-btn-outline-primary {
    border-color: var(--tina-primary);
    color: var(--tina-primary);
    background: transparent;
}

.tina-chatbot-actions .tina-btn-outline-primary:hover {
    background: var(--tina-primary);
    color: white;
}

.tina-chatbot-actions .tina-btn-outline-secondary {
    border-color: #dee2e6;
    color: var(--tina-gray);
    background: transparent;
}

.tina-chatbot-actions .tina-btn-outline-secondary:hover {
    border-color: var(--tina-primary);
    color: var(--tina-primary);
    background: transparent;
}

/* ========== MEJORAS ESPECÍFICAS PARA EL RANGO PROBLEMÁTICO ========== */

/* Rango específico 355px - 750px con ajustes finos */
@media screen and (min-width: 355px) and (max-width: 750px) {
    /* Asegurar que el contenedor no se salga de la pantalla */
    .tina-chatbot-container {
        box-sizing: border-box !important;
        overflow: hidden !important;
    }
    
    /* Asegurar que el botón flotante esté siempre visible */
    .tina-chatbot-toggle-btn {
        z-index: 10000;
        position: relative;
    }
    
    /* Ajustar el ancho máximo para que no se "pique" */
    .tina-chatbot-container {
        max-width: calc(100vw - 20px) !important;
        right: 10px !important;
        left: 10px !important;
        margin: 0 auto !important;
    }
    
    /* Corregir problemas de posición específicos */
    .tina-chatbot-wrapper {
        right: 0 !important;
        left: 0 !important;
        display: flex !important;
        justify-content: flex-end !important;
        padding-right: 15px !important;
    }
}

/* Soporte para navegadores móviles */
@supports (-webkit-touch-callout: none) {
    .tina-chatbot-body {
        -webkit-overflow-scrolling: touch;
    }
}

/* Estados táctiles para móviles */
@media (hover: none) and (pointer: coarse) {
    .tina-chatbot-toggle-btn:active {
        transform: scale(0.95);
    }
    
    .tina-suggestion-btn:active {
        transform: translateY(0);
        background-color: var(--tina-primary);
        color: white;
    }
}

/* Modo oscuro del sistema */
@media (prefers-color-scheme: dark) {
    .tina-chatbot-container {
        background: #2c2c2c;
        border-color: #444;
    }
    
    .tina-chatbot-body {
        background: #1a1a1a;
    }
    
    .tina-message-incoming .tina-message-text {
        background: #3a3a3a;
        color: #f0f0f0;
    }
    
    .tina-suggestion-btn {
        background: #3a3a3a;
        border-color: #444;
        color: #f0f0f0;
    }
    
    .tina-suggestion-btn:hover {
        background: #444;
    }
    
    .tina-chatbot-footer {
        background: #2c2c2c;
        border-color: #444;
    }
    
    .tina-typing-indicator {
        background: #3a3a3a;
        color: #ccc;
    }
    
    .tina-input-group .tina-form-control {
        background: #3a3a3a;
        border-color: #444;
        color: #f0f0f0;
    }
    
    .tina-input-group .tina-form-control::placeholder {
        color: #888;
    }
}

/* Estados de interacción */
.tina-chatbot-toggle-btn:focus,
.tina-chatbot-close-btn:focus,
.tina-suggestion-btn:focus,
.tina-input-group .tina-btn:focus {
    outline: 2px solid var(--tina-primary);
    outline-offset: 2px;
}

/* Aislamiento de estilos */
.tina-isolated {
    isolation: isolate;
}

/* Reset específico para elementos dentro del chat */
.tina-chatbot-wrapper *,
.tina-chatbot-wrapper *::before,
.tina-chatbot-wrapper *::after {
    box-sizing: border-box;
}