/* ============================================================
   ECOHUB — botón flotante global (.ecofab), cortina de salida
   (.ecofab-burst) y llegada a /ecohab (.eco-llegada).
   El botón se pinta en todas las páginas públicas desde
   layouts/footer.php (excepto dentro del propio módulo /ecohab).
   Colores del logo oficial "Bolivia EcoHub" (perfil CMYK → sRGB):
   azul #005A85 y verde #72C594, con el oro CAINCO como acento.
   Motivo: el brote de la "H" del logo, que se dibuja solo
   (layouts/eco-brote.php).
   ============================================================ */

:root {
    --eco-cauce:    #005A85;   /* azul de la marca */
    --eco-brote:    #72C594;   /* verde del brote */
    --eco-hondo:    #00344E;   /* azul profundo: sombras y degradés */
    --cainco-noche: #000020;
    --cainco-oro:   #eba436;
}

/* Iris de la llegada: se anima el radio del hueco */
@property --eco-iris {
    syntax: '<length>';
    inherits: false;
    initial-value: 0px;
}

/* ── BROTE (trazo) ───────────────────────────────────── */
.eco-brote { display: block; overflow: visible; }
.eco-brote path {
    fill: none;
    stroke: var(--eco-brote);
    stroke-width: 4.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 1;          /* sin dibujar: se anima a 0 */
    stroke-opacity: 0;             /* oculta el punto del extremo redondo hasta que arranca el trazo */
}
.eco-brote .eco-brote__brillo { stroke-width: 2.8; }
.eco-brote__planta {
    transform-box: fill-box;
    transform-origin: 50% 100%;    /* se mece desde la base del tallo */
}

/* ============================================================
   BOTÓN FLOTANTE
   ============================================================ */
.ecofab {
    --fab-size: 64px;

    position: fixed;
    right: max(24px, env(safe-area-inset-right));
    bottom: max(24px, env(safe-area-inset-bottom));
    z-index: 9000;                 /* debajo del navbar/menú móvil (9998+) y de los modales (9999) */
    width: var(--fab-size);
    height: var(--fab-size);
    display: block;
    text-decoration: none;
    font-family: 'Montserrat', system-ui, -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
    animation: ecofabPop .75s cubic-bezier(.34, 1.56, .64, 1) .45s both;
}
.ecofab *,
.ecofab *::before,
.ecofab *::after { box-sizing: border-box; }

.ecofab:focus { outline: none; }
.ecofab:focus-visible .ecofab__orb {
    outline: 3px solid var(--cainco-oro);
    outline-offset: 9px;
}

/* Orbe: esfera azul de la marca */
.ecofab__orb {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 50% 78%, rgba(114, 197, 148, .28) 0%, rgba(114, 197, 148, 0) 55%),
        radial-gradient(circle at 32% 24%, #0d7fb5 0%, var(--eco-cauce) 46%, var(--eco-hondo) 100%);
    box-shadow:
        0 14px 32px rgba(0, 52, 78, .45),
        0 3px 8px rgba(0, 0, 32, .25),
        inset 0 2px 3px rgba(255, 255, 255, .28),
        inset 0 -9px 18px rgba(0, 0, 32, .28);
    transition: transform .45s cubic-bezier(.34, 1.56, .64, 1), box-shadow .45s ease;
}
.ecofab__orb .eco-brote {
    width: 78%;
    height: 78%;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 32, .35));
}

/* El brote crece al aparecer el botón: tallo → hojita → hoja → brillo */
.ecofab__orb .eco-brote__tallo  { animation: ecoDraw .5s cubic-bezier(.4, 0, .2, 1) .8s forwards; }
.ecofab__orb .eco-brote__hojita { animation: ecoDraw .35s cubic-bezier(.4, 0, .2, 1) 1.15s forwards; }
.ecofab__orb .eco-brote__hoja   { animation: ecoDraw .55s cubic-bezier(.4, 0, .2, 1) 1.2s forwards; }
.ecofab__orb .eco-brote__brillo { animation: ecoDraw .25s ease-out 1.65s forwards; }
.ecofab__orb .eco-brote__planta { animation: ecoSway 5.5s ease-in-out 2.4s infinite; }

/* Aro giratorio verde → dorado */
.ecofab__ring {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    animation: ecofabFadeIn .6s ease 1s forwards;
}
.ecofab__ring::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(from 0deg,
        var(--cainco-oro) 0deg,
        var(--eco-brote) 100deg,
        rgba(114, 197, 148, 0) 175deg,
        rgba(114, 197, 148, 0) 200deg,
        var(--eco-brote) 285deg,
        var(--cainco-oro) 360deg);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
            mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
    animation: ecofabSpin 3.6s linear infinite;
}

/* Órbita: semilla dorada y una chispa verde que giran alrededor */
.ecofab__orbit {
    position: absolute;
    inset: -14px;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    animation: ecofabFadeIn .6s ease 1.3s forwards, ecofabSpin 8s linear 1.3s infinite reverse;
}
.ecofab__orbit::before,
.ecofab__orbit::after {
    content: '';
    position: absolute;
    left: 50%;
    border-radius: 50%;
}
.ecofab__orbit::before {
    top: 0;
    width: 8px; height: 8px;
    margin-left: -4px;
    background: var(--cainco-oro);
    box-shadow: 0 0 10px 2px rgba(235, 164, 54, .7);
}
.ecofab__orbit::after {
    bottom: 2px;
    width: 5px; height: 5px;
    margin-left: -2.5px;
    background: #b6efcb;
    box-shadow: 0 0 8px 1px rgba(182, 239, 203, .8);
}

/* Ondas que se expanden */
.ecofab__ripple {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--eco-brote);
    opacity: 0;
    pointer-events: none;
    animation: ecofabRipple 3.4s cubic-bezier(.2, .6, .3, 1) 1.8s infinite;
}
.ecofab__ripple--2 { animation-delay: 3.5s; }

/* Insignia "¡Nuevo!" */
.ecofab__tag {
    position: absolute;
    z-index: 4;
    top: -10px;
    right: -15px;
    padding: 3px 8px;
    border-radius: 999px;
    border: 2px solid #fff;
    background: var(--cainco-oro);
    color: var(--cainco-noche);
    font-size: 10px;
    font-weight: 800;
    line-height: 1.15;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(235, 164, 54, .5);
    animation: ecofabTagIn .5s cubic-bezier(.34, 1.56, .64, 1) 1.6s both, ecofabTag 3.4s ease-in-out 3s infinite;
}

/* ── Etiqueta: pastilla blanca con el logo oficial (asoma desde el orbe) ── */
.ecofab__label {
    position: absolute;
    z-index: 1;
    top: 50%;
    right: calc(var(--fab-size) / 2);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 7px;
    height: 62px;
    padding: 0 calc(var(--fab-size) / 2 + 20px) 0 24px;
    border-radius: 999px;          /* la punta derecha queda tapada por el orbe */
    background: #fff;
    box-shadow:
        0 18px 40px rgba(0, 52, 78, .24),
        0 2px 6px rgba(0, 0, 32, .10),
        inset 0 0 0 1px rgba(0, 90, 133, .10);
    white-space: nowrap;
    pointer-events: none;
    overflow: hidden;
    transform: translateY(-50%);
    clip-path: inset(0 0 0 100% round 999px);
    transition: clip-path .7s cubic-bezier(.22, 1, .36, 1);
}
/* Brillo que cruza la pastilla cada vez que se abre */
.ecofab__label::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 30%, rgba(114, 197, 148, .30) 48%, rgba(255, 255, 255, .6) 52%, transparent 70%);
    transform: translateX(-110%);
    pointer-events: none;
}
.ecofab__logo,
.ecofab__caption {
    position: relative;
    display: block;
    opacity: 0;
    transform: translateX(14px);
    transition: opacity .35s ease, transform .55s cubic-bezier(.22, 1, .36, 1);
}
.ecofab__logo {
    width: 156px;
    height: auto;
}
.ecofab__caption {
    color: var(--eco-cauce);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .005em;
    transition-delay: .08s;
}

/* Estado abierto: lo activa el JS (asomo) o el foco de teclado */
.ecofab.is-open .ecofab__label,
.ecofab:focus-visible .ecofab__label {
    clip-path: inset(0 0 0 0 round 999px);
    pointer-events: auto;
}
.ecofab.is-open .ecofab__label::after,
.ecofab:focus-visible .ecofab__label::after { animation: ecofabShine 1.1s cubic-bezier(.4, 0, .2, 1) .35s; }
.ecofab.is-open .ecofab__logo,
.ecofab.is-open .ecofab__caption,
.ecofab:focus-visible .ecofab__logo,
.ecofab:focus-visible .ecofab__caption {
    opacity: 1;
    transform: none;
}

/* Saltito periódico (lo activa el JS): el orbe rebota y la planta se mece */
.ecofab.is-hop .ecofab__orb { animation: ecofabHop .9s cubic-bezier(.36, .07, .19, .97); }
.ecofab.is-hop .ecofab__orb .eco-brote__planta { animation: ecoFlutter .9s ease-in-out; }

/* Hover solo en dispositivos con puntero real (evita el "doble toque" en iOS) */
@media (hover: hover) {
    .ecofab:hover .ecofab__label {
        clip-path: inset(0 0 0 0 round 999px);
        pointer-events: auto;
    }
    .ecofab:hover .ecofab__label::after { animation: ecofabShine 1.1s cubic-bezier(.4, 0, .2, 1) .25s; }
    .ecofab:hover .ecofab__logo,
    .ecofab:hover .ecofab__caption { opacity: 1; transform: none; }
    .ecofab:hover .ecofab__orb {
        transform: translateY(-3px) scale(1.06);
        box-shadow:
            0 20px 40px rgba(0, 52, 78, .52),
            0 4px 10px rgba(0, 0, 32, .28),
            inset 0 2px 3px rgba(255, 255, 255, .32),
            inset 0 -9px 18px rgba(0, 0, 32, .28);
    }
    .ecofab:hover .ecofab__ring::before { animation-duration: 1.3s; }
    .ecofab:hover .ecofab__orb .eco-brote__planta { animation: ecoFlutter 1s ease-in-out infinite; }
}
.ecofab:active .ecofab__orb { transform: scale(.93); transition-duration: .12s; }

/* ============================================================
   ESCENA DE TRANSICIÓN (la misma en la salida y en la llegada)
   Los tiempos se cuentan desde el clic: en la llegada,
   --eco-t (negativo, lo pone layouts/header.php) hace que la
   escena siga desde donde iba en la página anterior.
   ============================================================ */
.ecofab-burst,
.eco-llegada {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(ellipse 60% 50% at 50% 46%, rgba(114, 197, 148, .32) 0%, rgba(114, 197, 148, 0) 70%),
        radial-gradient(circle at 50% 50%, var(--eco-cauce) 0%, var(--eco-hondo) 58%, var(--cainco-noche) 100%);
}
.eco-escena {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    text-align: center;
}
.eco-escena__brote {
    width: clamp(110px, 20vmin, 168px);
    height: auto;
    aspect-ratio: 1;
    margin-bottom: -.4rem;
    filter: drop-shadow(0 8px 24px rgba(114, 197, 148, .35));
}
.eco-escena__brote path { stroke-width: 3.6; }
.eco-escena__brote .eco-brote__brillo { stroke-width: 2.4; }
.eco-escena__logo {
    display: block;
    width: min(440px, 76vw);
    height: auto;
    clip-path: inset(0 100% 0 0);
    filter: drop-shadow(0 12px 30px rgba(0, 0, 32, .35));
}
.eco-escena__line {
    position: relative;
    width: 132px;
    height: 2px;
    border-radius: 2px;
    background: rgba(255, 255, 255, .16);
    overflow: hidden;
}
.eco-escena__line::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, var(--eco-brote), var(--cainco-oro));
    transform-origin: left center;
    transform: scaleX(0);
}
.eco-escena__msg {
    color: rgba(255, 255, 255, .8);
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: .95rem;
    font-weight: 500;
    letter-spacing: .01em;
    opacity: 0;
    transform: translateY(6px);
}

/* Salida: un círculo llena la pantalla desde el enlace pulsado */
.ecofab-burst {
    visibility: hidden;
    pointer-events: none;
    clip-path: circle(0 at var(--bx, 92%) var(--by, 92%));
}
.ecofab-burst.is-on {
    visibility: visible;
    pointer-events: auto;
    animation: ecofabBurst .5s cubic-bezier(.7, 0, .3, 1) forwards;
}

/* Línea de tiempo de la escena (salida y llegada comparten tiempos) */
.ecofab-burst.is-on .eco-brote__tallo,
html.eco-llegando .eco-llegada .eco-brote__tallo  { animation: ecoDraw .34s cubic-bezier(.4, 0, .2, 1) calc(var(--eco-t, 0ms) + 120ms) forwards; }
.ecofab-burst.is-on .eco-brote__hojita,
html.eco-llegando .eco-llegada .eco-brote__hojita { animation: ecoDraw .26s cubic-bezier(.4, 0, .2, 1) calc(var(--eco-t, 0ms) + 330ms) forwards; }
.ecofab-burst.is-on .eco-brote__hoja,
html.eco-llegando .eco-llegada .eco-brote__hoja   { animation: ecoDraw .36s cubic-bezier(.4, 0, .2, 1) calc(var(--eco-t, 0ms) + 360ms) forwards; }
.ecofab-burst.is-on .eco-brote__brillo,
html.eco-llegando .eco-llegada .eco-brote__brillo { animation: ecoDraw .18s ease-out calc(var(--eco-t, 0ms) + 640ms) forwards; }
.ecofab-burst.is-on .eco-escena__logo,
html.eco-llegando .eco-llegada .eco-escena__logo  { animation: ecoWipe .45s cubic-bezier(.65, 0, .35, 1) calc(var(--eco-t, 0ms) + 380ms) forwards; }
.ecofab-burst.is-on .eco-escena__line::after,
html.eco-llegando .eco-llegada .eco-escena__line::after { animation: ecoLoad .65s cubic-bezier(.4, 0, .2, 1) calc(var(--eco-t, 0ms) + 200ms) forwards; }
.ecofab-burst.is-on .eco-escena__msg,
html.eco-llegando .eco-llegada .eco-escena__msg   { animation: ecoRise .35s ease calc(var(--eco-t, 0ms) + 480ms) forwards; }

/* Llegada a /ecohab: la escena ya está puesta y se abre como un iris */
.eco-llegada { display: none; }
html.eco-llegando .eco-llegada {
    display: grid;
    -webkit-mask: radial-gradient(circle at 50% 50%, transparent var(--eco-iris), #000 calc(var(--eco-iris) + 1px));
            mask: radial-gradient(circle at 50% 50%, transparent var(--eco-iris), #000 calc(var(--eco-iris) + 1px));
    animation: ecoLlegadaAuto .4s ease 2.6s forwards;   /* respaldo si el JS no corre */
}
.eco-llegada__msg--encuesta { display: none; }
html.eco-llegando--encuesta .eco-llegada__msg--encuesta { display: block; }
html.eco-llegando--encuesta .eco-llegada__msg--hub { display: none; }

html.eco-llegando .eco-llegada.is-out { animation: ecoIris .6s cubic-bezier(.65, 0, .35, 1) forwards; }
html.eco-llegando .eco-llegada.is-out .eco-escena { animation: ecoEscenaOut .3s cubic-bezier(.4, 0, .2, 1) forwards; }

/* El barrido del logo del hero de /ecohab espera al iris y arranca con él */
html.eco-llegando:not(.eco-abriendo) .eco-hero__brand img { animation-play-state: paused; }

/* ── KEYFRAMES ────────────────────────────────────────── */
@keyframes ecoDraw {
    from { stroke-dashoffset: 1; stroke-opacity: 1; }
    to   { stroke-dashoffset: 0; stroke-opacity: 1; }
}
@keyframes ecoSway {
    0%, 100% { transform: rotate(0); }
    50%      { transform: rotate(-3deg); }
}
@keyframes ecoFlutter {
    0%, 100% { transform: rotate(0); }
    25%      { transform: rotate(-9deg); }
    55%      { transform: rotate(6deg); }
    80%      { transform: rotate(-2deg); }
}
@keyframes ecofabPop {
    0%   { opacity: 0; transform: translateY(40px) scale(.35); }
    60%  { opacity: 1; }
    100% { opacity: 1; transform: none; }
}
@keyframes ecofabFadeIn { to { opacity: 1; } }
@keyframes ecofabSpin   { to { transform: rotate(360deg); } }
@keyframes ecofabRipple {
    0%   { transform: scale(1);   opacity: .6; }
    100% { transform: scale(1.9); opacity: 0; }
}
@keyframes ecofabTagIn {
    0%   { opacity: 0; transform: translateY(6px) scale(.4); }
    100% { opacity: 1; transform: none; }
}
@keyframes ecofabTag {
    0%, 70%, 100% { transform: translateY(0) rotate(0); }
    78%           { transform: translateY(-5px) rotate(-6deg); }
    86%           { transform: translateY(0) rotate(4deg); }
    92%           { transform: translateY(-2px) rotate(0); }
}
@keyframes ecofabHop {
    0%, 100% { transform: translateY(0) scale(1); }
    30%      { transform: translateY(-9px) scale(1.06, .96); }
    55%      { transform: translateY(0) scale(.97, 1.03); }
    75%      { transform: translateY(-3px); }
}
@keyframes ecofabShine { from { transform: translateX(-110%); } to { transform: translateX(110%); } }
@keyframes ecofabBurst { to { clip-path: circle(150vmax at var(--bx, 92%) var(--by, 92%)); } }
@keyframes ecoWipe      { to { clip-path: inset(0 -20px 0 0); } }
@keyframes ecoLoad      { to { transform: scaleX(1); } }
@keyframes ecoRise      { to { opacity: 1; transform: none; } }
@keyframes ecoEscenaOut { to { opacity: 0; transform: translateY(-12px) scale(.97); } }
@keyframes ecoIris {
    0%   { --eco-iris: 0px;     opacity: 1; }
    80%  { opacity: 1; }
    100% { --eco-iris: 150vmax; opacity: 0; visibility: hidden; }
}
@keyframes ecoLlegadaAuto { to { opacity: 0; visibility: hidden; } }

/* ── MÓVIL ────────────────────────────────────────────── */
@media (max-width: 640px) {
    .ecofab {
        --fab-size: 58px;
        right: max(16px, env(safe-area-inset-right));
        bottom: max(18px, env(safe-area-inset-bottom));
    }
    .ecofab__label   { height: 56px; gap: 5px; padding: 0 calc(var(--fab-size) / 2 + 16px) 0 18px; }
    .ecofab__logo    { width: 128px; }
    .ecofab__caption { font-size: 10.5px; }
    .ecofab__tag     { font-size: 9px; padding: 2px 7px; right: -12px; }
}
/* Pantallas angostas: la pastilla no entra con el texto completo */
@media (max-width: 420px) {
    .ecofab__extra { display: none; }
}

/* ── ACCESIBILIDAD: sin movimiento si el sistema lo pide ── */
@media (prefers-reduced-motion: reduce) {
    .ecofab,
    .ecofab__ring,
    .ecofab__orbit,
    .ecofab__tag { animation: ecofabFadeIn .3s ease both; }
    .ecofab__ring::before,
    .ecofab__ripple,
    .ecofab__orb .eco-brote__planta,
    .ecofab.is-hop .ecofab__orb { animation: none; }
    .ecofab__orb .eco-brote path { animation: none; stroke-dashoffset: 0; stroke-opacity: 1; }
    .ecofab__label,
    .ecofab__logo,
    .ecofab__caption { transition: none; }
    .ecofab__label::after { display: none; }
    html.eco-llegando .eco-llegada { display: none; }
}

@media print {
    .ecofab,
    .ecofab-burst,
    .eco-llegada { display: none !important; }
}
