/* Variables globales */
:root {
    --transition-speed: 0.3s;
    --bg-dark: #f0f2f5;
    --bg-darker: #ffffff;
    --text-light: #1a1b1e;
    --text-gray: #4b5563;
    --primary-blue: #3b82f6;
    --accent-dark: #2563eb;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --overlay-color: rgba(255, 255, 255, 0.85);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Arial, sans-serif;
    transition: background-color var(--transition-speed),
                color var(--transition-speed),
                border-color var(--transition-speed),
                box-shadow var(--transition-speed);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-image {
    height: 40px;
    width: auto;
    object-fit: contain;
}

body {
    min-height: 100vh;
    background-image: url('./images/Fondo.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    color: var(--text-light);
    perspective: 1000px;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--overlay-color);
    z-index: 0;
}

header, .circles-container, .bottom-section {
    position: relative;
    z-index: 1;
}

header {
    background-color: var(--bg-darker);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 10;
}

.logo {
    color: var(--text-light);
    font-weight: bold;
    font-size: 1.2rem;
}

.search-bar {
    display: flex;
    align-items: center;
}

.search-bar input {
    padding: 0.8rem;
    border: none;
    border-radius: 20px;
    width: 250px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-light);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.search-bar input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.3);
}

.circle a.circle-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-decoration: none;
    color: inherit;
    transition: all 0.4s ease;
}

.circle a.circle-link:hover {
    transform: translateY(-5px);
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent-dark);
    box-shadow: 0 5px 15px rgba(37, 99, 235, 0.2);
}

.circle a.circle-link i {
    font-size: 2rem;
    color: var(--primary-blue);
}

.circle a.circle-link span {
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
}

.circles-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5rem;
    min-height: 30vh;
    padding: 5rem;
    margin: 2rem auto;
    max-width: 1200px;
    flex-wrap: wrap;
}

.circle {
    width: 150px;
    height: 150px;
    border: 2px solid var(--primary-blue);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(59, 130, 246, 0.1);
    cursor: pointer;
    transition: all 0.4s ease;
    position: relative;
    overflow: hidden;
    margin: 1rem;
}

.circle:hover {
    transform: translateY(-5px);
    border-color: var(--accent-dark);
    background: rgba(59, 130, 246, 0.2);
    box-shadow: 0 5px 15px rgba(37, 99, 235, 0.2);
}

.circle i {
    font-size: 2rem;
    margin-bottom: 0.4rem;
    color: var(--primary-blue);
}

.circle span {
    text-align: center;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-light);
}

.bottom-section {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 3rem;
    background: var(--bg-darker);
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.2);
}

.feature-cards {
    display: flex;
    justify-content: space-around;
    max-width: 1400px;
    margin: 0 auto;
    gap: 3rem;
}

.feature-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 280px;
    text-decoration: none;
    color: inherit;
}

.feature-title {
    color: var(--text-light);
    font-size: 1.3rem;
    font-weight: bold;
    margin-bottom: 0.8rem;
    text-align: center;
}

.feature-description {
    color: var(--text-gray);
    font-size: 0.95rem;
    text-align: center;
    margin-bottom: 1.5rem;
}

.feature-icon {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--primary-blue);
    transition: all 0.3s ease;
}

.feature-icon:hover {
    transform: scale(1.15);
    border-color: var(--accent-dark);
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.3);
}

.feature-icon i {
    font-size: 2.5rem;
    color: var(--primary-blue);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logout-button {
    background-color: transparent;
    border: 1px solid var(--primary-blue);
    color: var(--primary-blue);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
}

.logout-button:hover {
    background-color: var(--primary-blue);
    color: white;
}

#userName {
    font-weight: 500;
    color: var(--text-light);
}

/* MÓVILES - Interfaz tipo aplicación */
@media screen and (max-width: 768px) {
    body {
        height: 100vh;
        overflow: hidden;
        background: #f0f2f5; /* Fallback color */
    }

    /* Eliminar el overlay ::before en móvil */
    body::before {
        display: none;
    }

    /* Header más compacto */
    header {
        padding: 0.75rem 1rem;
        height: 65px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }

    .logo-container {
        flex: 1;
    }

    .logo-image {
        height: 28px;
    }

    .logo {
        font-size: 0.9rem;
    }

    .search-bar {
        display: none;
    }

    .user-info {
        gap: 0.5rem;
    }

    .logout-button {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .logout-button span {
        display: none;
    }

    /* Container principal con imagen de fondo y overlay integrado */
    .main-app-container {
        height: 100vh;
        padding-top: 65px;
        padding-bottom: 20px;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(4, 1fr);
        gap: 1.5rem;
        padding-left: 2rem;
        padding-right: 2rem;
        position: relative;
        z-index: 1;
        align-content: center;
        justify-items: center;
        
        /* Aplicar imagen de fondo directamente aquí */
        background-image: 
            linear-gradient(rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.9)),
            url('./images/Fondo.jpg');
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
        background-attachment: local;
    }

    /* Eliminar estructura anterior de circles-container */
    .circles-container {
        display: contents; /* Los elementos se distribuyen directamente en el grid parent */
    }

    .circle {
        width: 120px;
        height: 120px;
        margin: 0;
        background: rgba(255, 255, 255, 0.15);
        border: 1px solid rgba(255, 255, 255, 0.3);
        box-shadow: 
            0 8px 32px rgba(0, 0, 0, 0.1),
            inset 0 1px 0 rgba(255, 255, 255, 0.5);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        position: relative;
        overflow: hidden;
    }

    .circle::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(135deg, 
            rgba(255, 255, 255, 0.1) 0%, 
            rgba(255, 255, 255, 0.05) 50%, 
            rgba(255, 255, 255, 0.1) 100%);
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .circle:hover::before,
    .circle:active::before {
        opacity: 1;
    }

    .circle:hover,
    .circle:active {
        transform: translateY(-2px) scale(1.02);
        background: rgba(255, 255, 255, 0.25);
        border-color: rgba(59, 130, 246, 0.4);
        box-shadow: 
            0 12px 40px rgba(0, 0, 0, 0.15),
            0 4px 20px rgba(59, 130, 246, 0.2),
            inset 0 1px 0 rgba(255, 255, 255, 0.6);
    }

    .circle i {
        font-size: 2.2rem;
        margin-bottom: 0.5rem;
        color: var(--primary-blue);
        filter: drop-shadow(0 2px 4px rgba(59, 130, 246, 0.3));
        z-index: 2;
        position: relative;
    }

    .circle span {
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--text-light);
        text-align: center;
        line-height: 1.2;
        padding: 0 0.3rem;
        text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
        z-index: 2;
        position: relative;
    }

    /* Sección inferior integrada en el grid */
    .bottom-section {
        display: contents; /* Los elementos se distribuyen directamente en el grid parent */
    }

    .feature-cards {
        display: contents; /* Los elementos se distribuyen directamente en el grid parent */
    }

    .feature-card {
        width: 120px;
        height: 120px;
        align-items: center;
        display: flex;
        flex-direction: column;
        justify-content: center;
        background: rgba(255, 255, 255, 0.15);
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 50%;
        box-shadow: 
            0 8px 32px rgba(0, 0, 0, 0.1),
            inset 0 1px 0 rgba(255, 255, 255, 0.5);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        text-decoration: none;
        color: inherit;
        margin: 0;
        position: relative;
        overflow: hidden;
    }

    .feature-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(135deg, 
            rgba(255, 255, 255, 0.1) 0%, 
            rgba(255, 255, 255, 0.05) 50%, 
            rgba(255, 255, 255, 0.1) 100%);
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .feature-card:hover::before,
    .feature-card:active::before {
        opacity: 1;
    }

    .feature-card:hover,
    .feature-card:active {
        transform: translateY(-2px) scale(1.02);
        background: rgba(255, 255, 255, 0.25);
        border-color: rgba(59, 130, 246, 0.4);
        box-shadow: 
            0 12px 40px rgba(0, 0, 0, 0.15),
            0 4px 20px rgba(59, 130, 246, 0.2),
            inset 0 1px 0 rgba(255, 255, 255, 0.6);
    }

    .feature-icon {
        width: auto;
        height: auto;
        border: none;
        background: none;
        margin: 0;
        box-shadow: none;
        backdrop-filter: none;
        border-radius: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 0.5rem;
        z-index: 2;
        position: relative;
    }

    .feature-icon i {
        font-size: 2.2rem;
        color: var(--primary-blue);
        filter: drop-shadow(0 2px 4px rgba(59, 130, 246, 0.3));
    }

    .feature-title {
        font-size: 0.75rem;
        font-weight: 600;
        margin: 0;
        line-height: 1.2;
        color: var(--text-light);
        text-align: center;
        padding: 0 0.3rem;
        text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
        z-index: 2;
        position: relative;
    }

    .feature-description {
        display: none;
    }

    /* Chatbot igual que los demás botones en el grid */
    .flomay-chat-container {
        position: static;
        bottom: auto;
        right: auto;
        z-index: 1;
        margin: 0;
    }

    .flomay-chat-button {
        width: 120px;
        height: 120px;
        padding: 0;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.15);
        border: 1px solid rgba(255, 255, 255, 0.3);
        box-shadow: 
            0 8px 32px rgba(0, 0, 0, 0.1),
            inset 0 1px 0 rgba(255, 255, 255, 0.5);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0;
        gap: 0.5rem;
        color: var(--text-light);
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        position: relative;
        overflow: hidden;
    }

    .flomay-chat-button::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(135deg, 
            rgba(255, 255, 255, 0.1) 0%, 
            rgba(255, 255, 255, 0.05) 50%, 
            rgba(255, 255, 255, 0.1) 100%);
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .flomay-chat-button:hover::before,
    .flomay-chat-button:active::before {
        opacity: 1;
    }

    .flomay-chat-button:hover,
    .flomay-chat-button:active {
        transform: translateY(-2px) scale(1.02);
        background: rgba(255, 255, 255, 0.25);
        border-color: rgba(59, 130, 246, 0.4);
        box-shadow: 
            0 12px 40px rgba(0, 0, 0, 0.15),
            0 4px 20px rgba(59, 130, 246, 0.2),
            inset 0 1px 0 rgba(255, 255, 255, 0.6);
    }

    .flomay-chat-button .bot-avatar {
        width: auto;
        height: auto;
        background: none;
        box-shadow: none;
        margin: 0;
        border-radius: 0;
        z-index: 2;
        position: relative;
    }

    .flomay-chat-button .bot-avatar i {
        font-size: 2.2rem;
        color: var(--primary-blue);
        filter: drop-shadow(0 2px 4px rgba(59, 130, 246, 0.3));
    }

    .flomay-chat-button span {
        font-size: 0.75rem;
        font-weight: 400;
        color: white; /* Cambiado a blanco para mejor contraste */
        text-align: center;
        line-height: 1.2;
        padding: 0 0.3rem;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); /* Sombra negra para texto blanco */
        z-index: 2;
        position: relative;
    }

    .pulse-animation {
        display: none;
    }

    /* Ajustar posición de los primeros dos botones más abajo */
    .circles-container .circle:nth-child(1),
    .circles-container .circle:nth-child(2) {
        margin-top: 20px;
    }

    /* Chat window en móvil que cubra toda la pantalla */
    .flomay-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        transform: none !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: none !important;
        max-height: none !important;
        border-radius: 0 !important;
        animation: slideInFromBottom 0.4s ease-out;
        z-index: 99999 !important; /* Z-index muy alto para estar por encima de todo */
        margin: 0 !important;
        padding: 0 !important;
    }

    @keyframes slideInFromBottom {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* Header del chat ajustado para pantalla completa */
    .flomay-chat-header {
        padding: 20px 25px;
        padding-top: max(20px, env(safe-area-inset-top));
        height: auto;
        min-height: calc(70px + env(safe-area-inset-top));
        position: relative;
        z-index: 1;
    }

    /* Mensajes del chat con padding para safe areas */
    .flomay-chat-messages {
        padding: 20px;
        flex: 1;
        overflow-y: auto;
    }

    /* Input del chat con padding para safe areas */
    .flomay-chat-input {
        padding: 20px;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        border-top: 1px solid rgba(59, 130, 246, 0.1);
    }

    /* Botón de cerrar más visible y accesible */
    .close-btn {
        background: rgba(255, 255, 255, 0.2) !important;
        border: none !important;
        color: white !important;
        cursor: pointer;
        padding: 12px !important;
        border-radius: 50% !important;
        transition: all 0.3s ease;
        z-index: 10 !important;
        font-size: 24px !important;
        width: 48px !important;
        height: 48px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: relative !important;
    }

    .close-btn:hover,
    .close-btn:active {
        background-color: rgba(255, 255, 255, 0.3) !important;
        transform: scale(1.1) !important;
    }

    .close-btn i {
        font-size: 18px !important;
        color: white !important;
    }

    /* Animaciones tipo iOS */
    .circle,
    .feature-card {
        -webkit-tap-highlight-color: transparent;
        user-select: none;
        -webkit-user-select: none;
    }

    .circle:active,
    .feature-card:active {
        transition: transform 0.1s;
    }

    /* Ocultar elementos innecesarios */
    body::before {
        display: none;
    }
}

/* Para pantallas muy pequeñas (menos de 360px) */
@media screen and (max-width: 360px) {
    .circles-container {
        gap: 1rem;
        padding: 1.5rem 1rem 1rem;
    }

    .circle {
        width: 100px;
        height: 100px;
    }

    .circle i {
        font-size: 1.8rem;
    }

    .circle span {
        font-size: 0.7rem;
    }

    .feature-icon {
        width: 45px;
        height: 45px;
    }

    .feature-icon i {
        font-size: 1rem;
    }

    .feature-title {
        font-size: 0.6rem;
    }
}

/* Orientación landscape en móviles */
@media screen and (max-height: 500px) and (orientation: landscape) and (max-width: 768px) {
    .circles-container {
        grid-template-columns: repeat(4, 1fr);
        gap: 1rem;
        padding: 1rem;
    }

    .circle {
        width: 80px;
        height: 80px;
    }

    .circle i {
        font-size: 1.5rem;
        margin-bottom: 0.3rem;
    }

    .circle span {
        font-size: 0.65rem;
    }

    .bottom-section {
        padding: 0.8rem 0.5rem;
    }

    .feature-icon {
        width: 40px;
        height: 40px;
    }

    .feature-icon i {
        font-size: 0.9rem;
    }

    .feature-title {
        font-size: 0.6rem;
    }
}

/* Soporte para notch en iOS */
@supports (padding: max(0px)) {
    @media screen and (max-width: 768px) {
        header {
            padding-top: max(0.75rem, env(safe-area-inset-top));
            height: calc(65px + env(safe-area-inset-top));
        }

        .main-app-container {
            padding-top: calc(65px + env(safe-area-inset-top));
        }

        .bottom-section {
            padding-bottom: max(1rem, env(safe-area-inset-bottom));
        }
    }
}

/* Mejora el tap en dispositivos táctiles */
@media (hover: none) and (pointer: coarse) {
    .circle:hover {
        transform: none;
        background: rgba(59, 130, 246, 0.1);
        border-color: var(--accent-dark);
        box-shadow: 0 5px 15px rgba(37, 99, 235, 0.2);
    }
    
    .feature-icon:hover {
        transform: none;
        border-color: var(--accent-dark);
        box-shadow: 0 0 30px rgba(59, 130, 246, 0.3);
    }
}