/**
 * Estilos del Chatbot Municipal - Municipalidad de Chachapoyas
 * Separado para mejor organización
 * @author Omir
 * @version 2.0
 */

/* ========== VARIABLES ========== */
:root {
    --chatbot-primary: #1e4d7b;
    --chatbot-primary-dark: #0d2847;
    --chatbot-secondary: #2d6ba8;
    --chatbot-bg: #f8f9fa;
    --chatbot-white: #ffffff;
    --chatbot-shadow: 0 5px 30px rgba(0,0,0,0.3);
}

/* ========== WRAPPER PRINCIPAL ========== */
.chatbot-wrapper {
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 998;
    pointer-events: none;
}

.chatbot-wrapper > * {
    pointer-events: auto;
}

/* ========== CONTENEDOR PRINCIPAL ========== */
.chatbot-container {
    position: fixed;
    bottom: 30px;
    right: 110px;
    z-index: 999;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

/* ========== BOTÓN FLOTANTE CON ICONO DE ROBOT ========== */
.chatbot-button {
    width: 60px;
    height: 60px;
    background: var(--chatbot-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
    position: relative;
    border: none;
    outline: none;
    font-size: 32px;
}

.chatbot-button:hover {
    background: var(--chatbot-primary-dark);
    transform: scale(1.1);
}

/* Ocultar el SVG por defecto */
.chatbot-button svg {
    display: none;
}

/* Mostrar emoji de robot en el botón */
.chatbot-button::before {
    content: "🤖";
    font-size: 32px;
}

/* Animación de pulso */
.chatbot-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--chatbot-primary);
    opacity: 0.6;
    animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.3);
        opacity: 0.3;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* ========== VENTANA DEL CHATBOT ========== */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 550px;
    background: var(--chatbot-white);
    border-radius: 15px;
    box-shadow: var(--chatbot-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.chatbot-window.active {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== HEADER ========== */
.chatbot-header {
    background: linear-gradient(135deg, var(--chatbot-primary-dark), var(--chatbot-primary));
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.chatbot-header > div {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.chatbot-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

/* Botón limpiar historial */
.chatbot-clear-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 16px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 5px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-clear-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.chatbot-close {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    line-height: 1;
}

.chatbot-close:hover {
    transform: rotate(90deg);
}

/* ========== ÁREA DE MENSAJES ========== */
.chatbot-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--chatbot-bg);
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--chatbot-primary);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-primary-dark);
}

/* ========== MENSAJES ========== */
.chatbot-message {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    animation: fadeInMessage 0.3s ease;
}

@keyframes fadeInMessage {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-message.bot {
    align-items: flex-start;
}

.chatbot-message.user {
    align-items: flex-end;
}

.message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chatbot-message.bot .message-bubble {
    background: var(--chatbot-white);
    color: #333;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border-bottom-left-radius: 4px;
}

.chatbot-message.user .message-bubble {
    background: var(--chatbot-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Enlaces dentro de mensajes */
.message-bubble a,
.chatbot-link {
    color: var(--chatbot-secondary);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px solid var(--chatbot-secondary);
    transition: all 0.2s;
}

.chatbot-message.user .message-bubble a {
    color: white;
    border-bottom-color: white;
}

.message-bubble a:hover {
    opacity: 0.8;
}

/* ========== BOTONES DE ACCIÓN ========== */
.chatbot-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background: white;
    border-radius: 12px;
    margin-top: 10px;
}

.chatbot-action-btn {
    padding: 10px 15px;
    background: var(--chatbot-primary);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    transition: all 0.3s;
    border: none;
    cursor: pointer;
}

.chatbot-action-btn:hover {
    background: var(--chatbot-primary-dark);
    transform: translateX(3px);
}

/* ========== OPCIONES RÁPIDAS ========== */
.chatbot-options {
    padding: 15px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 120px;
    overflow-y: auto;
}

.chatbot-options::-webkit-scrollbar {
    width: 4px;
}

.chatbot-options::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chatbot-options::-webkit-scrollbar-thumb {
    background: var(--chatbot-primary);
    border-radius: 2px;
}

.chatbot-option {
    padding: 8px 15px;
    background: #f0f0f0;
    border: 1px solid var(--chatbot-primary);
    color: var(--chatbot-primary);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.chatbot-option:hover {
    background: var(--chatbot-primary);
    color: white;
    transform: translateY(-2px);
}

/* ========== INPUT DE TEXTO ========== */
.chatbot-input-container {
    padding: 15px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
}

.chatbot-input {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
    font-family: inherit;
}

.chatbot-input:focus {
    border-color: var(--chatbot-primary);
}

.chatbot-send {
    width: 40px;
    height: 40px;
    background: var(--chatbot-primary);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.chatbot-send:hover {
    background: var(--chatbot-primary-dark);
    transform: scale(1.1);
}

.chatbot-send:active {
    transform: scale(0.95);
}

/* ========== ESTADOS DE CARGA ========== */
.chatbot-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.chatbot-typing span {
    width: 8px;
    height: 8px;
    background: var(--chatbot-primary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.chatbot-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ========== OCULTAR MASCOTA CUANDO CHATBOT ESTÁ ACTIVO ========== */
.chatbot-window.active ~ .mascot-container {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
    transition: all 0.3s ease;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .chatbot-container {
        bottom: 30px;
        right: 80px;
    }
    
    .chatbot-window {
        width: 90vw;
        height: 70vh;
        right: -60px;
        bottom: 70px;
    }
    
    .chatbot-button {
        width: 50px;
        height: 50px;
    }
    
    .chatbot-button::before {
        font-size: 26px;
    }
    
    .message-bubble {
        max-width: 85%;
    }

    .chatbot-header {
        padding: 12px 15px;
    }

    .chatbot-header h3 {
        font-size: 14px;
    }

    .chatbot-clear-btn {
        font-size: 14px;
        padding: 4px 8px;
    }

    .chatbot-options {
        padding: 10px;
        max-height: 100px;
    }

    .chatbot-option {
        font-size: 12px;
        padding: 6px 12px;
    }
}

@media (max-width: 480px) {
    .chatbot-window {
        width: 100vw;
        height: 100vh;
        right: 0;
        bottom: 0;
        border-radius: 0;
        position: fixed;
    }

    .chatbot-container {
        right: 70px;
        bottom: 25px;
    }
    
    .chatbot-button {
        width: 48px;
        height: 48px;
    }

    .chatbot-button::before {
        font-size: 24px;
    }
    
    .message-bubble {
        max-width: 90%;
        font-size: 13px;
    }

    .chatbot-input-container {
        padding: 12px;
    }

    .chatbot-input {
        font-size: 13px;
        padding: 8px 12px;
    }

    .chatbot-send {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .chatbot-header h3 {
        font-size: 13px;
    }

    .chatbot-clear-btn {
        font-size: 13px;
        padding: 3px 7px;
    }
}

/* ========== ESTADOS ESPECIALES ========== */

/* Mensaje de error */
.chatbot-error {
    background: #fee;
    border-left: 4px solid #dc3545;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 13px;
    color: #721c24;
}

/* Mensaje de éxito */
.chatbot-success {
    background: #d4edda;
    border-left: 4px solid #28a745;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 13px;
    color: #155724;
}

/* Mensaje de información */
.chatbot-info {
    background: #d1ecf1;
    border-left: 4px solid #17a2b8;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 13px;
    color: #0c5460;
}

/* ========== ANIMACIONES ADICIONALES ========== */

/* Efecto de entrada del chatbot */
@keyframes chatbotEntrance {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.chatbot-window.active {
    animation: chatbotEntrance 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Shake animation para errores */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.chatbot-error {
    animation: shake 0.5s;
}

/* ========== ACCESIBILIDAD ========== */

/* Focus visible para navegación por teclado */
.chatbot-button:focus-visible,
.chatbot-close:focus-visible,
.chatbot-clear-btn:focus-visible,
.chatbot-send:focus-visible,
.chatbot-option:focus-visible {
    outline: 3px solid var(--chatbot-secondary);
    outline-offset: 2px;
}

.chatbot-input:focus-visible {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 1px;
}

/* ========== MODO OSCURO (OPCIONAL) ========== */
@media (prefers-color-scheme: dark) {
    :root {
        --chatbot-bg: #1a1a1a;
        --chatbot-white: #2d2d2d;
    }

    .chatbot-messages {
        background: var(--chatbot-bg);
    }

    .chatbot-message.bot .message-bubble {
        background: var(--chatbot-white);
        color: #e0e0e0;
    }

    .chatbot-input {
        background: var(--chatbot-white);
        color: #e0e0e0;
        border-color: #444;
    }

    .chatbot-option {
        background: var(--chatbot-white);
        color: var(--chatbot-primary);
    }
}

/* ========== UTILIDADES ========== */

/* Ocultar elemento */
.chatbot-hidden {
    display: none !important;
}

/* Deshabilitar interacción */
.chatbot-disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

/* Cargando */
.chatbot-loading {
    position: relative;
}

.chatbot-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--chatbot-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ========== AJUSTES FINALES ========== */

/* Asegurar que el chatbot no se salga de la pantalla */
@media (max-height: 700px) {
    .chatbot-window {
        height: calc(100vh - 150px);
        max-height: 550px;
    }
}

/* Mejorar legibilidad en pantallas pequeñas */
@media (max-width: 360px) {
    .chatbot-container {
        right: 60px;
    }

    .chatbot-window {
        width: 95vw;
    }

    .chatbot-button {
        width: 45px;
        height: 45px;
    }

    .chatbot-button::before {
        font-size: 22px;
    }
}