/* =========================================
   1. VARIABLES Y CONFIGURACIÓN GLOBAL
   ========================================= */
:root {
    --verde-oscuro: #1f6a3e;
    --verde: #2d8a4e;
    --verde-medio: #3fae63;
    --verde-claro: #eaf6ee;
    --verde-borde: #cfe9d7;
    --texto: #21301f;
    --texto-suave: #5c6b58;
    --blanco: #ffffff;
    --acento: #f2b705;
    --radius: 14px;
    --sombra: 0 10px 30px rgba(31, 106, 62, 0.08);
    --transicion: all .25s ease;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: 'Poppins', system-ui, sans-serif;
    color: var(--texto);
    background: #f5f9f5;
    overflow-x: hidden;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }

:focus-visible { outline: 3px solid var(--acento); outline-offset: 2px; }

/* =========================================
   2. ANIMACIONES PREMIUM
   ========================================= */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: scale(1); } }

/* Entrada suave con un ligero efecto de zoom */
@keyframes fadeInUp {
    0% { opacity: 0; transform: translateY(40px) scale(0.96); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Flotación más orgánica y natural */
@keyframes float {
    0% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-12px) rotate(3deg); }
    100% { transform: translateY(0px) rotate(0deg); }
}

/* Efecto tipo burbuja de chat de iOS */
@keyframes chatPop {
    0% { opacity: 0; transform: scale(0.8) translateY(20px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* Animación del giro del mapa (de oeste a este) */
@keyframes spinEarth {
    from { background-position: 0 0; }
    to { background-position: -800px 0; }
}

/* =========================================
   3. BOTONES
   ========================================= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 13px 22px; border-radius: 10px; border: none;
    font-weight: 600; font-size: 15px;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.btn:active { transform: scale(0.94); }
.btn-primary { background: var(--verde); color: #fff; box-shadow: 0 6px 16px rgba(45,138,78,.28); }
.btn-primary:hover { background: var(--verde-oscuro); transform: translateY(-3px); box-shadow: 0 10px 25px rgba(45, 138, 78, 0.4); }
.btn-outline { background: #fff; color: var(--texto); border: 1.5px solid #dfe6df; }
.btn-outline:hover { border-color: var(--verde); color: var(--verde); transform: translateY(-3px); }
.btn-block { width: 100%; }
.btn-small { padding: 8px 14px; font-size: 13px; border-radius: 8px; }
.btn-danger { background: #fbeaea; color: #b3392c; }
.btn-danger:hover { background: #f6d3d0; }

/* =========================================
   4. PÁGINA DE INICIO (LANDING PAGE)
   ========================================= */
.landing {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: 40px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 60px 5%;
    min-height: 100vh;
}
.landing-copy h1 { font-size: 54px; margin: 10px 0; color: var(--texto); line-height: 1.1; }
.landing-copy h1 b { color: var(--verde-oscuro); }
.landing-copy .tagline { font-size: 20px; font-weight: 700; color: var(--verde); margin-bottom: 15px; }
.landing-copy .lead { font-size: 16px; color: var(--texto-suave); margin-bottom: 30px; line-height: 1.6; }
.landing-actions { display: flex; gap: 15px; margin-bottom: 25px; }
.landing-note { font-size: 13px; color: var(--texto-suave); }

.features {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-top: 20px;
}
.feature-card {
    background: #fff; padding: 25px 20px; border-radius: var(--radius);
    text-align: center; box-shadow: var(--sombra); border: 1px solid transparent;
    opacity: 0; animation: fadeInUp 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.4s ease;
}
.feature-card:hover { transform: translateY(-10px) scale(1.03); box-shadow: 0 22px 45px rgba(31, 106, 62, 0.15); border-color: var(--verde-medio); }
.feature-card .emoji { font-size: 34px; margin-bottom: 12px; }
.feature-card h4 { margin: 0 0 6px; color: var(--verde-oscuro); font-size: 16px; }
.feature-card p { margin: 0; font-size: 13px; color: var(--texto-suave); }

/* =========================================
   5. EL PLANETA 3D GIRATORIO CORREGIDO
   ========================================= */
.landing-visual { 
    position: relative; animation: popIn .7s ease; display: flex; justify-content: center; align-items: center; 
}
.landing-visual .globe {
    font-size: 0; /* Oculta el emoji de texto */
    width: 380px; height: 380px; border-radius: 50%; margin: 0 auto;
    
    /* Respaldo de color verde por si la imagen falla */
    background-color: var(--verde-medio); 
    /* Imagen del mapa en alta calidad desde un CDN estable */
    background-image: url('https://unpkg.com/three-globe/example/img/earth-blue-marble.jpg'); 
    
    background-size: 800px 100%; background-repeat: repeat-x;
    box-shadow: 
        inset -35px -35px 50px rgba(0, 0, 0, 0.6), 
        inset 15px 15px 30px rgba(255, 255, 255, 0.3), 
        0 25px 45px rgba(45, 138, 78, 0.3); 
    animation: spinEarth 20s linear infinite, float 6s ease-in-out infinite;
}

/* =========================================
   6. MODALES (Login y Registro)
   ========================================= */
.overlay {
    position: fixed; inset: 0; background: rgba(20, 40, 25, .45); display: none;
    align-items: center; justify-content: center; z-index: 50; padding: 20px; animation: fadeIn .2s ease;
}
.overlay.active { display: flex; }
.modal-card {
    background: #fff; border-radius: 20px; width: 100%; max-width: 460px; padding: 34px 36px 40px;
    position: relative; box-shadow: 0 30px 60px rgba(0,0,0,.25); animation: popIn .3s ease;
    max-height: 92vh; overflow-y: auto;
}
.modal-back { display: inline-flex; align-items: center; gap: 6px; color: var(--verde); font-weight: 600; border: none; background: none; font-size: 14px; padding: 0; margin-bottom: 10px; }
.modal-head { text-align: center; margin-bottom: 22px; }
.modal-head .brand-logo { color: var(--verde); margin: 0 auto 8px; }
.modal-head h2 { margin: 6px 0 4px; font-size: 24px; }
.modal-head p { margin: 0; color: var(--texto-suave); font-size: 14px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 6px; }
.input-wrap { position: relative; }
.input-wrap .icon-left { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--verde); }
.input-wrap input { width: 100%; padding: 12px 14px 12px 38px; border: 1.5px solid var(--verde-borde); border-radius: 10px; font-size: 14px; transition: var(--transicion); background: #fbfdfb; }
.input-wrap input:focus { border-color: var(--verde); background: #fff; }
.toggle-pass { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--texto-suave); font-size: 16px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; margin: 14px 0; color: var(--texto-suave); }
.check-row a { color: var(--verde); font-weight: 600; }
.form-link { text-align: right; margin: -6px 0 16px; }
.form-link a { color: var(--verde); font-size: 13.5px; font-weight: 600; }
.switch-form { text-align: center; margin-top: 16px; font-size: 14px; color: var(--texto-suave); }
.switch-form button { background: none; border: none; color: var(--verde); font-weight: 700; }
.alert { padding: 12px 14px; border-radius: 10px; font-size: 13.5px; margin-bottom: 14px; }
.alert-error { background: #fdeceb; color: #a4382b; }
.alert-success { background: #e8f7ec; color: #1f6a3e; }

/* =========================================
   7. ESTRUCTURA DE LA APP (DASHBOARD)
   ========================================= */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 270px; background: linear-gradient(180deg, #1c6b3e 0%, #143f27 100%);
    color: #eafbef; padding: 26px 20px; display: flex; flex-direction: column; position: relative; overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 30px; }
.brand-logo {
    /* Ruta relativa correcta para la web */
    background-image: url('../../uploads/mi-logo.png'); 
    background-size: cover;
    background-position: center;
    background-color: transparent;
    
    /* Tamaños flexibles para que se adapte al inicio y al menú */
    width: 100%;
    min-width: 34px;
    height: 100%;
    min-height: 34px;
    border-radius: 50%; 
    box-shadow: 0 4px 10px rgba(46, 125, 50, 0.3); 
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Ajustes específicos de tamaño según dónde esté el logo */
.landing-logo .brand-logo { width: 54px; height: 54px; }
.modal-head .brand-logo { width: 46px; height: 46px; }
.brand .brand-logo { width: 34px; height: 34px; }
    
.brand:hover .brand-logo { transform: rotate(-15deg) scale(1.1); box-shadow: 0 6px 15px rgba(46, 125, 50, 0.5); }
.brand-title { display: block; font-weight: 700; letter-spacing: .5px; font-size: 17px; }
.brand-sub { display: block; font-size: 11px; color: #bfe8cd; margin-top: 2px; }

.menu-label { font-size: 11px; letter-spacing: 1.5px; color: #a9dcb9; margin: 0 0 12px 6px; }
.menu { display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 10px; font-weight: 500; color: #eafbef; transition: var(--transicion); }
.nav-item .icon { width: 20px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,.08); transform: translateX(3px); }
.nav-item.active { background: #ffffff; color: var(--verde-oscuro); font-weight: 700; box-shadow: 0 8px 18px rgba(0,0,0,.15); }

.sidebar-illustration { flex: 1; }
.btn-salir { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.12); padding: 12px 16px; border-radius: 10px; font-weight: 600; z-index: 2; }
.btn-salir:hover { background: rgba(255,255,255,.22); }

.main { flex: 1; padding: 34px 44px; max-width: 100%; overflow-x: hidden; }
.page-title { font-size: 30px; margin: 0 0 22px; color: var(--verde-oscuro); opacity: 0; animation: fadeInUp 0.5s ease forwards; }

.banner {
    background: linear-gradient(120deg, #1c6b3e, #2d8a4e 60%, #3fae63); color: #fff;
    border-radius: 20px; padding: 40px 44px; display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 28px; box-shadow: var(--sombra); opacity: 0; animation: fadeInUp 0.6s ease forwards;
}
.banner h2 { font-size: 26px; margin: 0 0 10px; }
.banner p { margin: 0; color: #dff3e4; max-width: 420px; }
.banner-emoji { font-size: 90px; display: inline-block; animation: float 4s ease-in-out infinite; filter: drop-shadow(0 10px 10px rgba(0,0,0,0.1)); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.card {
    background: #fff; border-radius: var(--radius); padding: 26px; box-shadow: var(--sombra);
    opacity: 0; animation: fadeInUp 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.4s ease; border: 1px solid transparent;
}
.card h3 { margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
.card p.sub { color: var(--texto-suave); margin: 0 0 18px; font-size: 14px; }
.card:hover { transform: translateY(-5px); box-shadow: 0 22px 45px rgba(31, 106, 62, 0.15); border-color: var(--verde-medio); }

.help-card {
    display: flex; align-items: center; justify-content: space-between; background: #fff; border-radius: var(--radius);
    padding: 22px 28px; margin-top: 22px; box-shadow: var(--sombra); opacity: 0; animation: fadeInUp 0.8s ease forwards;
}

/* =========================================
   8. PÁGINAS ESPECÍFICAS Y COMPONENTES
   ========================================= */
/* ---- Puntos ---- */
.stat-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid #eef3ee; }
.stat-row:last-of-type { border-bottom: none; }
.stat-left { display: flex; align-items: center; gap: 14px; }
.stat-emoji { font-size: 30px; }
.stat-badge { background: var(--verde-claro); color: var(--verde-oscuro); font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 20px; }
.stat-value { font-weight: 700; font-size: 20px; text-align: right; }
.total-box { display: flex; align-items: center; justify-content: space-between; background: var(--verde-claro); border-radius: 12px; padding: 16px 20px; margin-top: 6px; }

.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-radius: 10px; }
.rank-list li.me { background: var(--verde-claro); font-weight: 700; }
.rank-num { width: 22px; font-weight: 700; color: var(--texto-suave); }
.rank-medal { font-size: 18px; }
.rank-name { flex: 1; }
.rank-pts { font-weight: 700; color: var(--verde-oscuro); }

.rewards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 18px; margin-top: 18px; }
.reward-card { 
    background: #fbfdfb; border: 1px solid var(--verde-borde); border-radius: 14px; padding: 16px; text-align: center; 
    opacity: 0; animation: fadeInUp 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.4s ease;
}
.reward-card:nth-child(1) { animation-delay: 0.1s; }
.reward-card:nth-child(2) { animation-delay: 0.2s; }
.reward-card:nth-child(3) { animation-delay: 0.3s; }
.reward-card:hover { transform: translateY(-10px) scale(1.03); box-shadow: 0 22px 45px rgba(31, 106, 62, 0.15); border-color: var(--verde-medio); }
.reward-img { width: 100%; height: 90px; object-fit: contain; margin-bottom: 10px; }
.reward-img.placeholder { display: flex; align-items: center; justify-content: center; font-size: 36px; background: var(--verde-claro); border-radius: 10px; }
.reward-card h4 { margin: 6px 0 2px; font-size: 14px; }
.reward-pts { color: var(--verde); font-weight: 700; font-size: 13px; margin-bottom: 10px; }

/* ---- Perfil ---- */
.profile-grid { display: grid; grid-template-columns: 340px 1fr; gap: 26px; align-items: start; }
.avatar-wrap { width: 160px; height: 160px; border-radius: 50%; overflow: hidden; margin: 0 auto 14px; border: 4px solid var(--verde-claro); background: var(--verde-claro); display: flex; align-items: center; justify-content: center; font-size: 60px; }
.avatar-wrap img { width: 100%; height: 100%; object-fit: cover; }
.upload-label { display: inline-flex; align-items: center; gap: 6px; color: var(--verde); font-weight: 700; cursor: pointer; }
.profile-field { margin-bottom: 20px; }
.profile-field label { display: block; font-size: 13px; color: var(--texto-suave); font-weight: 600; margin-bottom: 6px; }
.profile-field .value-box { display: flex; align-items: center; gap: 10px; border: 1.5px solid var(--verde-borde); border-radius: 10px; padding: 12px 14px; background: #fbfdfb; }
.profile-field input[type="text"], .profile-field input[type="email"] { border: none; background: transparent; font-size: 15px; width: 100%; }

/* ---- Configuración ---- */
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 18px 0; border-bottom: 1px solid #eef3ee; }
.setting-row:last-child { border: none; }
.setting-label { font-weight: 600; }
.setting-desc { font-size: 13px; color: var(--texto-suave); margin-top: 2px; }
.switch { position: relative; width: 54px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-toggle { position: absolute; cursor: pointer; inset: 0; background: #d8e3d9; border-radius: 30px; transition: var(--transicion); }
.slider-toggle::before { content: ''; position: absolute; height: 22px; width: 22px; left: 4px; top: 4px; background: #fff; border-radius: 50%; transition: var(--transicion); }
.switch input:checked + .slider-toggle { background: var(--verde); }
.switch input:checked + .slider-toggle::before { transform: translateX(24px); }
.lang-buttons { display: flex; gap: 8px; }
.lang-btn { padding: 8px 16px; border-radius: 8px; border: 1.5px solid var(--verde-borde); background: #fff; font-weight: 600; }
.lang-btn.active { background: var(--verde); color: #fff; border-color: var(--verde); }

/* ---- Admin Recompensas ---- */
.admin-table { width: 100%; border-collapse: collapse; margin-top: 18px; }
.admin-table th, .admin-table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid #eef3ee; font-size: 14px; }
.admin-table img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; background: var(--verde-claro); }
.admin-actions { display: flex; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---- Chatbot de Ayuda ---- */
.chatbot-container { background: white; border-radius: 16px; border: 1px solid var(--verde-borde); height: 400px; display: flex; flex-direction: column; overflow: hidden; }
.chat-messages { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; background: #f9fbf9; }
.chat-bubble { max-width: 80%; padding: 12px 16px; border-radius: 16px; font-size: 14px; box-shadow: 0 4px 10px rgba(0,0,0,0.04); }
.chat-bot { background: var(--verde-claro); color: var(--verde-oscuro); align-self: flex-start; border-bottom-left-radius: 4px; transform-origin: bottom left; animation: chatPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
.chat-user { background: var(--verde); color: white; align-self: flex-end; border-bottom-right-radius: 4px; transform-origin: bottom right; animation: chatPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
.chat-options { display: flex; flex-wrap: wrap; gap: 8px; padding: 15px; border-top: 1px solid var(--verde-borde); background: white; }
.chat-btn { background: white; border: 1.5px solid var(--verde); color: var(--verde); padding: 8px 14px; border-radius: 20px; cursor: pointer; font-size: 13px; font-weight: 600; transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1); }
.chat-btn:hover { background: var(--verde); color: white; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(45, 138, 78, 0.2); }
.chat-btn:active { transform: scale(0.95); }

/* ---- Extras (Toasts y Voice) ---- */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--verde-oscuro); color: #fff; padding: 14px 18px; border-radius: 10px; box-shadow: var(--sombra); font-size: 14px; animation: popIn .25s ease; }
.toast.error { background: #a4382b; }
#voice-indicator {
    position: fixed; bottom: 20px; left: 20px; z-index: 150; background: var(--verde-oscuro); color: #fff; padding: 10px 16px;
    border-radius: 30px; font-size: 13px; display: none; align-items: center; gap: 8px; box-shadow: var(--sombra); animation: popIn .3s ease;
}
#voice-indicator.show { display: flex; }
#voice-indicator .dot { width: 8px; height: 8px; border-radius: 50%; background: #7ff29a; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* =========================================
   9. RESPONSIVE (Móviles y Tablets)
   ========================================= */
@media (max-width: 980px) {
    .landing { grid-template-columns: 1fr; text-align: center; padding: 40px 6vw; gap: 20px; }
    .landing-copy p.lead { margin-left: auto; margin-right: auto; }
    .landing-actions { justify-content: center; }
    
    /* Ajuste de la Tierra en móviles */
    .landing-visual .globe { width: 280px; height: 280px; background-size: 600px 100%; }
    
    .features { grid-template-columns: repeat(2, 1fr); }
    .app { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 10px; padding: 20px; }
    .sidebar-illustration { display: none; }
    .menu { flex-direction: row; flex-wrap: wrap; width: 100%; }
    .main { padding: 22px; }
    .grid-2, .profile-grid, .form-grid { grid-template-columns: 1fr; }
    .banner { flex-direction: column; text-align: center; gap: 16px; }
    .help-card { flex-direction: column; gap: 15px; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}