/*
 * Capa de "app" de EbeneCenter: transiciones entre pantallas, barra de carga, hojas inferiores, bienvenida,
 * campana y avisos. Se carga en todas las pantallas, después de los estilos comunes.
 */

/* ---------- Transiciones entre pantallas (View Transitions entre documentos) ---------- */
/* En móvil el navegador puede cambiar el área visible durante el salto de página. */
@media (min-width: 992px) {
    @view-transition {
        navigation: auto;
    }

    .ec-sidebar { view-transition-name: app-sidebar; }
}

::view-transition-old(root) {
    animation: 140ms ease-in both app-fade-out;
}

::view-transition-new(root) {
    animation: 260ms cubic-bezier(0.23, 1, 0.32, 1) both app-rise-in;
}

::view-transition-group(app-sidebar) {
    animation: none;
}

@keyframes app-fade-out {
    to { opacity: 0; }
}

@keyframes app-rise-in {
    from { opacity: 0; transform: translateY(10px); }
}

/* ---------- Barra de carga ---------- */
.app-progress {
    position: fixed;
    z-index: 2000;
    top: env(safe-area-inset-top, 0px);
    left: 0;
    width: 100%;
    height: 3px;
    pointer-events: none;
    opacity: 0;
    transform: scaleX(0);
    transform-origin: left;
    background: linear-gradient(90deg, var(--ec-accent), #54b9d7);
    transition: opacity 200ms ease;
}

.app-progress.is-loading {
    opacity: 1;
    animation: app-progress 2.4s cubic-bezier(0.1, 0.7, 0.2, 1) forwards;
}

@keyframes app-progress {
    0% { transform: scaleX(0); }
    40% { transform: scaleX(0.6); }
    100% { transform: scaleX(0.92); }
}

/* ---------- Botones que trabajan y respuesta táctil ---------- */
.ec-button,
.app-button,
.dashboard-secondary-action,
.dashboard-primary-action,
.ec-bottom-nav__item,
.tp-person-row,
.ec-directory-item {
    -webkit-tap-highlight-color: transparent;
    transition-property: transform, background-color, color, border-color, box-shadow, opacity;
    transition-duration: 140ms;
}

.ec-button:active:not(:disabled),
.app-button:active:not(:disabled),
.dashboard-secondary-action:active,
.dashboard-primary-action:active,
.tp-person-row:active,
.ec-directory-item:active {
    transform: scale(0.975);
}

button[aria-busy="true"],
.ec-button[aria-busy="true"],
.app-button[aria-busy="true"] {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

button[aria-busy="true"]::after,
.ec-button[aria-busy="true"]::after,
.app-button[aria-busy="true"]::after {
    position: absolute;
    inset: 0;
    width: 18px;
    height: 18px;
    margin: auto;
    border: 2px solid currentColor;
    border-color: color-mix(in srgb, var(--ec-text-primary) 35%, transparent);
    border-top-color: var(--ec-text-primary);
    border-radius: 50%;
    content: "";
    animation: app-spin 700ms linear infinite;
}

.ec-button--primary[aria-busy="true"]::after,
.app-button[aria-busy="true"]:not(.app-button--ghost)::after {
    border-color: rgb(255 255 255 / 0.35);
    border-top-color: #fff;
}

@keyframes app-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Avisos de la pantalla (flashes) ---------- */
.ec-alert {
    animation: app-drop-in 320ms cubic-bezier(0.23, 1, 0.32, 1) both;
}

.ec-alert.is-leaving {
    animation: app-fold-out 260ms ease-in forwards;
}

@keyframes app-drop-in {
    from { opacity: 0; transform: translateY(-8px) scale(0.98); }
}

@keyframes app-fold-out {
    to { opacity: 0; transform: translateY(-6px); margin-bottom: -60px; }
}

/* ---------- Botones de las capas de la app ---------- */
.app-button {
    display: inline-flex;
    width: 100%;
    min-height: 52px;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 22px;
    border: 0;
    border-radius: 14px;
    background: #003d50;
    color: #fff;
    font: inherit;
    font-size: 1rem;
    font-weight: var(--font-weight-bold);
    text-decoration: none;
    cursor: pointer;
}

:root[data-theme="dark"] .app-button {
    background: #1c7895;
}

.app-button--ghost,
:root[data-theme="dark"] .app-button--ghost {
    background: transparent;
    color: var(--ec-text-secondary);
    font-weight: var(--font-weight-medium);
}

/* ---------- Bienvenida del primer acceso ---------- */
html.has-overlay,
html.has-overlay body {
    overflow: hidden;
}

.app-onboarding {
    position: fixed;
    z-index: 3000;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding: calc(24px + env(safe-area-inset-top, 0px)) 24px calc(24px + env(safe-area-inset-bottom, 0px));
    background:
        radial-gradient(90% 60% at 100% 0%, rgb(84 185 215 / 0.28), transparent 70%),
        radial-gradient(70% 50% at 0% 100%, rgb(11 111 141 / 0.45), transparent 70%),
        linear-gradient(165deg, #003d50, #00202b);
    color: #fff;
    animation: app-fade-in 300ms ease both;
}

.app-onboarding.is-leaving {
    animation: app-fade-out 320ms ease forwards;
}

@keyframes app-fade-in {
    from { opacity: 0; }
}

.app-onboarding__steps {
    position: relative;
    display: grid;
    flex: 1;
    width: 100%;
    max-width: 440px;
    margin: 0 auto;
}

.app-onboarding__step {
    display: flex;
    grid-area: 1 / 1;
    flex-direction: column;
    justify-content: flex-end;
    gap: 14px;
    padding-bottom: 12px;
    visibility: hidden;
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 320ms ease, transform 420ms cubic-bezier(0.23, 1, 0.32, 1), visibility 0s linear 420ms;
}

.app-onboarding__step.is-current {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition-delay: 0s;
}

.app-onboarding__step.is-past {
    transform: translateX(-40px);
}

.app-onboarding__art {
    display: grid;
    width: 96px;
    height: 96px;
    margin-bottom: 18px;
    place-items: center;
    border-radius: 28px;
    box-shadow: 0 24px 50px -18px rgb(0 0 0 / 0.6);
}

.app-onboarding__art img {
    width: 96px;
    height: 96px;
    border-radius: 28px;
}

.app-onboarding__art--icon {
    background: rgb(255 255 255 / 0.12);
    color: #9fd8e8;
    font-size: 2.4rem;
    backdrop-filter: blur(10px);
}

.app-onboarding h2 {
    margin: 0;
    color: #fff;
    font-size: clamp(2rem, 8vw, 2.5rem);
    font-weight: var(--font-weight-bold);
    letter-spacing: -0.035em;
    line-height: 1.05;
}

.app-onboarding p,
.app-onboarding li {
    margin: 0;
    color: rgb(255 255 255 / 0.82);
    font-size: 1rem;
    line-height: 1.55;
}

.app-onboarding__hint:empty {
    display: none;
}

.app-onboarding__hint {
    padding: 12px 14px;
    border-radius: 12px;
    background: rgb(255 255 255 / 0.1);
}

.app-install-guide { display: grid; gap: 12px; }
.app-install-guide__label { font-size: .875rem; font-weight: var(--font-weight-bold); }
.app-install-guide__select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 8px 10px;
    border: 1px solid #9fd8e8;
    border-radius: 10px;
    background: #003d50;
    color: #fff;
    font: inherit;
    font-size: 1rem;
    color-scheme: dark;
}
.app-install-guide__select:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.app-install-guide__steps { display: grid; gap: 16px; margin: 4px 0; padding: 0; list-style: none; counter-reset: install; }
.app-install-guide__steps li { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 12px; counter-increment: install; }
.app-install-guide__icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: rgb(255 255 255 / .12); color: #9fd8e8; font-size: 1.4rem; }
.app-install-guide__steps strong { display: block; color: #fff; font-size: .9375rem; }
.app-install-guide__steps strong::before { content: counter(install) ". "; }
.app-install-guide__steps span[data-install-description] { display: block; margin-top: 3px; font-size: .875rem; line-height: 1.45; }
.app-onboarding .app-install-guide__help { font-size: .8125rem; line-height: 1.45; }
/* La guía sigue accesible en pantallas bajas, con zoom o texto ampliado. */
.app-onboarding:has(.app-install-guide) { overflow-y: auto; overflow-x: clip; }
.app-onboarding__step[data-step="install"] { justify-content: center; }
.app-onboarding__step[data-step="install"]:not(.is-current) { display: none; }
.app-onboarding__step[data-step="install"] .app-onboarding__art { display: none; }
.app-onboarding__step[data-step="install"] h2 { font-size: clamp(1.65rem, 6vw, 2.1rem); }

/* :root para ganar a la variante oscura de .app-button: la bienvenida es siempre oscura. */
:root .app-onboarding .app-button {
    background: #fff;
    color: #003d50;
}

:root .app-onboarding .app-button--ghost {
    background: transparent;
    color: rgb(255 255 255 / 0.75);
}

/* La acción favorable destaca; posponer sigue siendo legible y conserva un área táctil amplia. */
.app-onboarding .app-button--ghost,
.app-sheet .app-button--ghost {
    width: auto;
    min-height: 44px;
    align-self: center;
    padding-inline: 18px;
    font-size: .875rem;
    font-weight: var(--font-weight-medium);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Sin botón de instalar, "Continuar" es la única acción del paso y se ve como principal. */
:root .app-onboarding [data-install-prompt][hidden] + .app-button--ghost {
    background: #fff;
    color: #003d50;
    width: 100%;
    font-size: 1rem;
    font-weight: var(--font-weight-bold);
    text-decoration: none;
}

.app-onboarding .app-button[aria-busy="true"]::after {
    border-color: rgb(0 61 80 / 0.25);
    border-top-color: #003d50;
}

.app-onboarding__dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding-top: 10px;
}

.app-onboarding__dots span {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: rgb(255 255 255 / 0.3);
    transition: width 300ms ease, background-color 300ms ease;
}

.app-onboarding__dots span.is-current {
    width: 22px;
    background: #fff;
}

/* ---------- Hoja inferior ---------- */
.app-sheet {
    position: fixed;
    z-index: 2500;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.app-sheet__backdrop {
    position: absolute;
    inset: 0;
    background: var(--ec-overlay);
    animation: app-fade-in 240ms ease both;
}

.app-sheet__panel {
    position: relative;
    display: grid;
    width: min(100%, 480px);
    gap: 12px;
    padding: 12px 22px calc(22px + env(safe-area-inset-bottom, 0px));
    border-radius: 26px 26px 0 0;
    background: var(--ec-surface);
    box-shadow: 0 -20px 50px -20px rgb(0 0 0 / 0.4);
    color: var(--ec-text-primary);
    text-align: center;
    animation: app-sheet-up 380ms cubic-bezier(0.32, 0.72, 0, 1) both;
}

.app-sheet.is-leaving .app-sheet__panel {
    animation: app-sheet-down 260ms ease-in forwards;
}

.app-sheet.is-leaving .app-sheet__backdrop {
    animation: app-fade-out 260ms ease forwards;
}

@keyframes app-sheet-up {
    from { transform: translateY(100%); }
}

@keyframes app-sheet-down {
    to { transform: translateY(100%); }
}

.app-sheet__handle {
    width: 40px;
    height: 5px;
    margin: 0 auto 6px;
    border-radius: 999px;
    background: var(--ec-line);
}

.app-sheet__icon {
    display: grid;
    width: 60px;
    height: 60px;
    margin: 4px auto;
    place-items: center;
    border-radius: 20px;
    background: color-mix(in srgb, var(--ec-accent) 14%, transparent);
    color: var(--ec-accent);
    font-size: 1.5rem;
}

.app-sheet h2 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: var(--font-weight-bold);
    letter-spacing: -0.02em;
}

.app-sheet p {
    margin: 0 0 6px;
    color: var(--ec-text-secondary);
    font-size: 0.92rem;
    line-height: 1.55;
}

@media (min-width: 600px) {
    .app-sheet {
        align-items: center;
    }

    .app-sheet__panel {
        border-radius: 24px;
    }

    .app-sheet__handle {
        display: none;
    }
}

/* ---------- Mensaje flotante breve ---------- */
.app-toast {
    position: fixed;
    z-index: 2600;
    left: 50%;
    bottom: calc(var(--ec-bottom-nav-height, 66px) + 16px + env(safe-area-inset-bottom, 0px));
    width: max-content;
    max-width: calc(100% - 32px);
    padding: 13px 18px;
    border-radius: 14px;
    background: #102a33;
    box-shadow: 0 16px 40px -16px rgb(0 0 0 / 0.5);
    color: #fff;
    font-size: 0.9rem;
    line-height: 1.45;
    transform: translateX(-50%);
    animation: app-toast-in 320ms cubic-bezier(0.23, 1, 0.32, 1) both;
}

.app-toast.is-leaving {
    animation: app-fade-out 240ms ease forwards;
}

@keyframes app-toast-in {
    from { opacity: 0; transform: translate(-50%, 12px); }
}

@media (min-width: 992px) {
    .app-toast {
        bottom: 28px;
    }
}

/* ---------- Campana y contadores ---------- */
.ec-mobile-header {
    grid-template-columns: 44px 1fr auto;
}

.ec-mobile-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.app-bell {
    position: relative;
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border-radius: 12px;
    color: var(--primary);
    font-size: 1.1rem;
    text-decoration: none;
}

.app-bell:hover,
.app-bell.is-active {
    background: var(--surface-soft);
    color: var(--primary);
}

.app-bell__badge,
.ec-nav-badge {
    display: inline-grid;
    min-width: 19px;
    height: 19px;
    place-items: center;
    padding: 0 5px;
    border-radius: 999px;
    background: #d6453d;
    color: #fff;
    font-size: 0.66rem;
    font-weight: var(--font-weight-bold);
    line-height: 1;
    animation: app-pop 360ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.app-bell__badge {
    position: absolute;
    top: 5px;
    right: 3px;
    box-shadow: 0 0 0 2px var(--surface);
}

.ec-nav-badge {
    margin-left: auto;
}

.app-bell__badge[hidden],
.ec-nav-badge[hidden] {
    display: none;
}

@keyframes app-pop {
    from { transform: scale(0.4); opacity: 0; }
}

/* ---------- Tirar para recargar ---------- */
.app-pull {
    position: fixed;
    z-index: 1100;
    top: calc(var(--ec-mobile-header-height, 72px) + env(safe-area-inset-top, 0px));
    left: 50%;
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 50%;
    background: var(--ec-surface);
    box-shadow: 0 8px 20px -8px rgb(0 0 0 / 0.35);
    color: var(--ec-accent);
    pointer-events: none;
    opacity: calc(var(--pull, 0) / 80);
    transform: translate(-50%, calc(var(--pull, 0) * 0.5px - 30px)) rotate(calc(var(--pull, 0) * 3deg));
}

.app-pull.is-refreshing :is(.fas) {
    animation: app-spin 700ms linear infinite;
}

/* ---------- App instalada: sin selección accidental de textos de navegación ---------- */
html.is-standalone .ec-bottom-nav,
html.is-standalone .ec-mobile-header,
html.is-standalone .tp-nav {
    -webkit-user-select: none;
    user-select: none;
}

@media (prefers-reduced-motion: reduce) {
    @view-transition {
        navigation: none;
    }

    .app-progress.is-loading,
    .ec-alert,
    .app-onboarding,
    .app-onboarding__step,
    .app-sheet__panel,
    .app-sheet__backdrop,
    .app-toast,
    .app-bell__badge,
    .ec-nav-badge {
        animation: none;
        transition: none;
    }
}

/* El aviso de novedades mantiene las dos acciones visibles incluso en pantallas bajas. */
[data-feature-announcement] .app-sheet__panel { max-height: 100dvh; overflow-y: auto; }
[data-feature-status]:empty { display: none; }
