/* Contenedor principal del chatbot */
.chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    isolation: isolate; /* Aísla el contexto de apilamiento */
}

.chatbot-image-container {
    position: relative;
    display: flex;
    justify-content: center;
    display: block;
    width: auto;
    height: auto;
}

#chatbot-image {
    width: 180px;
    height: 220px;
    cursor: pointer;
    border-radius: 15px;
    object-fit: cover;
    filter: drop-shadow(0 0 5px #D4AF37) drop-shadow(0 0 10px #D4AF37);
    animation: pulse 3s infinite;
    transition: all 0.3s ease;
}

#chatbot-image:hover {
    filter: drop-shadow(0 0 8px #D4AF37) drop-shadow(0 0 15px #D4AF37);
    transform: scale(1.05);
}

/* Estado bloqueado del chatbot */
#chatbot-image.blocked {
    opacity: 0.3;
    cursor: not-allowed;
    filter: grayscale(1) drop-shadow(0 0 5px #ff4444);
    animation: none;
}

#chatbot-image.blocked:hover {
    filter: grayscale(1) drop-shadow(0 0 5px #ff4444);
    transform: scale(1);
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.10);
    }
    100% {
        transform: scale(1);
    }
}

.chatbot-message {
    position: absolute;
    top: -70px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #D4AF37, #B8860B);
    color: #1a1f2e;
    padding: 10px 15px;
    border-radius: 15px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    opacity: 0;
    animation: fadeInOut 5s infinite;
    max-width: 180px;
    text-align: center;
    font-weight: 700;
    z-index: 1001;
    border: 2px solid #FFD700;
    transition: all 0.3s ease;
    pointer-events: none; /* No interfiere con clics */
}

.chatbot-message::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 8px;
    border-style: solid;
    border-color: #D4AF37 transparent transparent transparent;
}

@keyframes fadeInOut {
    0%, 100% {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    10%, 80% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* CHATBOX - AISLADO DEL FLUJO DE LA PÁGINA */
.chatbox {
    display: none;
    position: fixed; /* Cambiado de absolute a fixed */
    bottom: 20px;
    right: 20px;
    width: 420px;
    height: 800px;
    background: linear-gradient(145deg, #1a1f2e, #0f1219);
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    flex-direction: column;
    overflow: hidden;
    animation: fadeIn 0.3s ease;
    z-index: 1002;
    border: 2px solid rgba(212, 175, 55, 1.3);
    /* Asegurar que no afecte el scroll de la página */
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Resto del CSS se mantiene igual... */
.chat-header {
    display: flex;
    align-items: center;
    padding: 18px 20px;
    background: linear-gradient(135deg, #D4AF37, #B8860B);
    color: #1a1f2e;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    height: 70px;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><polygon points="50,10 61,35 88,35 67,55 73,82 50,68 27,82 33,55 12,35 39,35" fill="%23FFD700" opacity="0.3"/></svg>') repeat;
    opacity: 0.3;
    animation: twinkle 4s infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}

.chat-icon {
    width: 35px;
    height: 35px;
    margin-right: 12px;
    border-radius: 50%;
    border: 2px solid #1a1f2e;
    position: relative;
    z-index: 1;
}

.chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    flex-grow: 1;
    position: relative;
    z-index: 1;
}

#close-chat {
    background: none;
    border: none;
    color: #1a1f2e;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.3s ease;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    position: relative;
    z-index: 1;
}

#close-chat:hover {
    transform: scale(1.2);
    background-color: rgba(26, 31, 46, 0.2);
}

/* ÁREA DE MENSAJES */
.chat-messages {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    background-color: #1a1f2e;
    display: flex;
    flex-direction: column;
    gap: 15px;
    position: relative;
    min-height: 0;
    min-height: 450px;
}

/* Estrellas animadas en el fondo del chat */
.stars {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.star {
    position: absolute;
    background-color: #FFD700;
    border-radius: 50%;
    animation: twinkle-star 1s infinite;
}

@keyframes twinkle-star {
    0%, 100% { opacity: 0.2; transform: scale(0.8); }
    50% { opacity: 0.8; transform: scale(1.2); }
}

.message {
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 85%;
    word-wrap: break-word;
    line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    animation: messageAppear 0.3s ease;
    position: relative;
    z-index: 1;
}

@keyframes messageAppear {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-message {
    background: linear-gradient(135deg, #D4AF37, #c19b2f);
    color: #1a1f2e;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

.bot-message {
    background: linear-gradient(135deg, #2a3044, #3c445c);
    color: #f4f4f9;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    border-left: 3px solid #D4AF37;
}

.youtube-link {
    display: inline-block;
    margin-top: 10px;
    padding: 10px 15px;
    background: linear-gradient(135deg, #D4AF37, #c19b2f);
    color: #1a1f2e;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
    border: 1px solid #FFD700;
}

.youtube-link:hover {
    background: linear-gradient(135deg, #FFD700, #D4AF37);
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.3);
}

/* ÁREA DE OPCIONES */
.chat-options {
    display: flex;
    flex-direction: column;
    padding: 15px;
    background: linear-gradient(145deg, #1a1f2e, #151a28);
    height: 280px;
    overflow: hidden;
    border-top: 2px solid rgba(212, 175, 55, 0.3);
    position: relative;
    flex-shrink: 0;
}

/* Header de opciones */
.options-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(212, 175, 55, 0.3);
    font-size: 14px;
    font-weight: 600;
    color: #D4AF37;
    flex-shrink: 0;
}

.scroll-indicator {
    animation: bounce 2s infinite;
    font-size: 12px;
    opacity: 0.7;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-3px);
    }
    60% {
        transform: translateY(-2px);
    }
}

/* Contenedor de opciones con scroll */
.options-container {
    height: 220px;
    overflow-y: auto;
    padding-right: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

/* Aseguramos que los botones tengan tamaño consistente */
.options-container button {
    flex-shrink: 0;
    min-height: 50px;
    display: flex;
    align-items: center;
    margin: 0;
}

.chat-options button {
    padding: 12px 15px;
    background: linear-gradient(135deg, #2a3044, #3c445c);
    color: #f4f4f9;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    transition: all 0.3s ease;
    border-left: 4px solid #D4AF37;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
    position: relative;
    z-index: 1;
    width: 100%;
    line-height: 1.4;
}

.chat-options button:hover {
    background: linear-gradient(135deg, #D4AF37, #c19b2f);
    color: #1a1f2e;
    transform: translateX(5px);
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.25);
}

/* MODAL DE BLOQUEO MEJORADO */
.block-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

.block-content {
    background: linear-gradient(145deg, #1a1f2e, #0f1219);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 400px;
    border: 2px solid #ff4444;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.7);
    position: relative;
    animation: modalAppear 0.4s ease-out;
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.close-block-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    color: #ff4444;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close-block-modal:hover {
    transform: scale(1.2);
    background-color: rgba(255, 68, 68, 0.1);
}

.block-icon {
    font-size: 60px;
    margin-bottom: 20px;
    animation: blockPulse 2s infinite;
}

@keyframes blockPulse {
    0%, 100% { 
        transform: scale(1);
        color: #ff4444;
    }
    50% { 
        transform: scale(1.1);
        color: #ff6666;
    }
}

.block-content h3 {
    color: #ff4444;
    margin-bottom: 15px;
    font-size: 24px;
    font-weight: 700;
}

.block-content p {
    color: #f4f4f9;
    margin-bottom: 12px;
    line-height: 1.5;
}

.block-content small {
    color: #aaa;
    font-size: 12px;
    display: block;
    margin-top: 20px;
    line-height: 1.4;
}

#countdown {
    color: #ff4444;
    font-weight: bold;
    font-size: 22px;
    background: rgba(255, 68, 68, 0.1);
    padding: 5px 15px;
    border-radius: 8px;
    display: inline-block;
    margin: 0 5px;
}

.block-reason {
    background: rgba(255, 68, 68, 0.1);
    padding: 10px 15px;
    border-radius: 8px;
    border-left: 3px solid #ff4444;
    margin: 15px 0;
    font-style: italic;
}

/* Indicador de restricción en el chatbot */
.restriction-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 68, 68, 0.9);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    z-index: 1003;
    display: none;
    animation: restrictionPulse 2s infinite;
    box-shadow: 0 4px 12px rgba(255, 68, 68, 0.4);
    pointer-events: none;
}

@keyframes restrictionPulse {
    0%, 100% { 
        transform: translate(-50%, -50%) scale(1);
        box-shadow: 0 4px 12px rgba(255, 68, 68, 0.4);
    }
    50% { 
        transform: translate(-50%, -50%) scale(1.05);
        box-shadow: 0 6px 18px rgba(255, 68, 68, 0.6);
    }
}

/* Efecto de mensajes tipo máquina de escribir */
.typing-indicator {
    display: inline-block;
    position: relative;
}

.typing-indicator::after {
    content: '|';
    position: absolute;
    right: -5px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Estilos para enlaces */
.message a {
    color: #D4AF37;
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px dotted #D4AF37;
    transition: all 0.2s ease;
}

.message a:hover {
    color: #FFD700;
    border-bottom: 1px solid #FFD700;
}

/* Estilos responsivos */
@media (max-width: 768px) {
    .chatbot-container {
        bottom: 15px;
        right: 15px;
    }
    
    #chatbot-image {
        width: 160px;
        height: 200px;
    }
    
    .chatbox {
        width: 350px;
        height: 600px;
        bottom: 15px;
        right: 15px;
    }
    
    .chatbot-message {
        max-width: 150px;
        font-size: 14px;
        top: -60px;
    }
    
    /* Ajustes responsivos para áreas */
    .chat-messages {
        min-height: 320px;
    }
    
    .chat-options {
        height: 220px;
    }
    
    .options-container {
        height: 170px;
    }
    
    .block-content {
        margin: 20px;
        padding: 25px;
        max-width: 350px;
    }
}

@media (max-width: 480px) {
    .chatbot-container {
        bottom: 10px;
        right: 10px;
    }
    
    #chatbot-image {
        width: 140px;
        height: 170px;
    }
    
    .chatbox {
        width: calc(100vw - 40px);
        height: 550px;
        bottom: 10px;
        right: 20px;
        left: 20px;
        margin: 0 auto;
    }
    
    .chat-messages {
        padding: 15px;
        min-height: 280px;
    }
    
    .chat-options {
        height: 200px;
        padding: 12px;
    }
    
    .chat-options button {
        padding: 10px 12px;
        font-size: 13px;
        min-height: 45px;
    }
    
    .chatbot-message {
        max-width: 130px;
        font-size: 13px;
        top: -50px;
        padding: 8px 12px;
    }
    
    .options-container {
        height: 150px;
    }
    
    .block-content {
        margin: 15px;
        padding: 20px;
        max-width: 300px;
    }
    
    .block-content h3 {
        font-size: 20px;
    }
}

@media (max-width: 360px) {
    .chatbox {
        width: calc(100vw - 30px);
        height: 500px;
        right: 15px;
        left: 15px;
    }
    
    #chatbot-image {
        width: 120px;
        height: 150px;
    }
    
    /* Ajustes adicionales para pantallas muy pequeñas */
    .chat-messages {
        min-height: 250px;
    }
    
    .chat-options {
        height: 180px;
    }
    
    .options-container {
        height: 130px;
    }
    
    .block-content {
        max-width: 280px;
    }
}

/* Scrollbar personalizado */
.chat-messages::-webkit-scrollbar,
.options-container::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.options-container::-webkit-scrollbar-track {
    background: #2a3044;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb,
.options-container::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, #D4AF37, #B8860B);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.options-container::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(to bottom, #FFD700, #D4AF37);
}

/* Mejoras para el texto de mensajes */
.message {
    font-size: 14px;
    line-height: 1.5;
}

.bot-message strong {
    color: #D4AF37;
}

.bot-message ul {
    margin: 8px 0;
    padding-left: 20px;
}

.bot-message li {
    margin-bottom: 5px;
}

/* Animación de carga para mensajes del bot */
.bot-message.typing::after {
    content: '...';
    animation: typingDots 1.5s infinite;
}

@keyframes typingDots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Efectos de hover mejorados */
#chatbot-image:active {
    transform: scale(0.95);
}

.chat-options button:active {
    transform: translateX(5px) scale(0.98);
}

/* Mejoras de accesibilidad */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles para accesibilidad */
.chat-options button:focus {
    outline: 2px solid #D4AF37;
    outline-offset: 2px;
}

#close-chat:focus {
    outline: 2px solid #1a1f2e;
    outline-offset: 2px;
}

.close-block-modal:focus {
    outline: 2px solid #ff4444;
    outline-offset: 2px;
}

/* Mejora para el contraste de texto */
.user-message {
    font-weight: 600;
}

.bot-message {
    font-weight: 500;
}

/* Estilos para el scroll suave */
.chat-messages {
    scroll-behavior: smooth;
}

.options-container {
    scroll-behavior: smooth;
}

/* Indicador visual de que hay más opciones disponibles */
.options-container:after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 20px;
    background: linear-gradient(transparent, rgba(26, 31, 46, 0.8));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.options-container.scrollable:after {
    opacity: 1;
}

/* Efecto de escritura para mensajes del chatbot */
.typewriter {
    overflow: hidden;
    border-right: 2px solid #D4AF37;
    white-space: nowrap;
    margin: 0 auto;
    animation: typing 3.5s steps(40, end), blink-caret 0.75s step-end infinite;
}

@keyframes typing {
    from { width: 0 }
    to { width: 100% }
}

@keyframes blink-caret {
    from, to { border-color: transparent }
    50% { border-color: #D4AF37; }
}

/* Estilos para el tiempo restante en el indicador de bloqueo */
.time-remaining {
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    background: rgba(255, 68, 68, 0.8);
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 5px;
    display: inline-block;
    animation: timePulse 1s infinite;
}

@keyframes timePulse {
    0%, 100% { 
        transform: scale(1);
        background: rgba(255, 68, 68, 0.8);
    }
    50% { 
        transform: scale(1.05);
        background: rgba(255, 68, 68, 1);
    }
}

/* Ajustes para el indicador de restricción con tiempo */
.restriction-indicator {
    text-align: center;
    line-height: 1.3;
    font-size: 12px;
    padding: 10px 15px;
}