/* ============================================================
   base.css  —  Reset moderno + tipografía base (BEM Layer 0)
   ============================================================ */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    background: var(--c-bg);
    overscroll-behavior-y: none;
}

body {
    font-family: var(--ff-base);
    color: var(--c-text);
    background: var(--c-bg);
    line-height: 1.6;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    overscroll-behavior-y: none;
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
}

a { color: inherit; }

/* El atributo hidden siempre gana, aunque la clase defina display */
[hidden] { display: none !important; }
button,
a,
[role="button"] {
    font: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}
input,
textarea,
[contenteditable="true"] {
    font: inherit;
    user-select: text;
    -webkit-user-select: text;
    -webkit-touch-callout: default;
}
img,
svg {
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
}

.app-safe-bottom {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

/* Accessibility: foco visible por teclado */
:focus-visible {
    outline: 2px solid var(--c-primary);
    outline-offset: 2px;
}

/* Reduce motion si el usuario lo pide */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---------- Skeletons de carga ---------- */
.skeleton {
    display: block;
    background: linear-gradient(90deg, #e9edf3 25%, #f6f8fb 50%, #e9edf3 75%);
    background-size: 200% 100%;
    border-radius: 0.5rem;
    animation: skeletonShimmer 1.2s linear infinite;
}
.skeleton--text { height: 0.9em; }
.skeleton--title { height: 1.5em; width: 62%; }
.skeleton--card {
    min-height: 10rem;
    border-radius: 1rem;
}
@keyframes skeletonShimmer {
    to { background-position: -200% 0; }
}

/* ---------- Badge de notificaciones (estilo Facebook) ---------- */
.nav-perfil-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}
.notif-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    margin-left: 6px;
    padding: 0 5px;
    border-radius: 10px;
    background: #e23744;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 1px 4px rgba(226, 55, 68, 0.45);
    animation: notifBadgePop 0.35s ease-out;
    transition: opacity 0.2s, transform 0.2s;
}
.notif-badge--hidden {
    opacity: 0;
    transform: scale(0.6);
    pointer-events: none;
    animation: none;
    min-width: 0;
    width: 0;
    height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
}
@keyframes notifBadgePop {
    0%   { transform: scale(0.4); opacity: 0; }
    60%  { transform: scale(1.2);  opacity: 1; }
    100% { transform: scale(1);    opacity: 1; }
}
.notif-badge--pop {
    animation: notifBadgePop 0.35s ease-out;
}
@media (prefers-reduced-motion: reduce) {
    .notif-badge,
    .skeleton { animation: none; }
}

/* ---------- Transiciones entre páginas (sensación de app nativa) ----------
   Chrome/Android: fundido suave al navegar entre páginas del mismo origen.
   Navegadores sin soporte lo ignoran sin romper nada. */
@view-transition {
    navigation: auto;
}
@media (prefers-reduced-motion: no-preference) {
    ::view-transition-old(root) {
        animation: vtFadeOut 0.14s ease both;
    }
    ::view-transition-new(root) {
        animation: vtFadeIn 0.18s ease both;
    }
}
@keyframes vtFadeOut {
    to { opacity: 0; }
}
@keyframes vtFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

/* ---------- Barra de navegación inferior (app móvil) ---------- */
.appnav {
    display: none;
}
@media (max-width: 768px) {
    .appnav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: var(--z-header, 50);
        display: flex;
        justify-content: space-around;
        align-items: stretch;
        background: rgba(255, 255, 255, 0.96);
        -webkit-backdrop-filter: blur(12px);
        backdrop-filter: blur(12px);
        border-top: 1px solid var(--c-border);
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -4px 20px rgba(44, 62, 80, 0.08);
    }
    .appnav__item {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 8px 2px 7px;
        min-height: 54px;
        text-decoration: none;
        color: var(--c-text-muted);
        transition: color var(--t-fast);
    }
    .appnav__icon {
        position: relative;
        width: 23px;
        height: 23px;
        display: block;
    }
    .appnav__icon svg {
        width: 100%;
        height: 100%;
        display: block;
    }
    .appnav__label {
        font-size: 10px;
        font-weight: 600;
        line-height: 1;
        letter-spacing: 0.01em;
    }
    .appnav__item--active {
        color: #667eea;
    }
    .appnav__item--active .appnav__label {
        font-weight: 800;
    }
    .appnav__badge {
        position: absolute;
        top: -5px;
        right: -9px;
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        border-radius: 8px;
        background: #e23744;
        color: #fff;
        font-size: 10px;
        font-weight: 700;
        line-height: 16px;
        text-align: center;
    }
    .appnav__badge--hidden {
        display: none;
    }
    /* Deja espacio al final de la página para que la barra no tape contenido */
    html.has-appnav body {
        padding-bottom: calc(66px + env(safe-area-inset-bottom));
    }
    /* Con barra inferior no hace falta el nav superior: un solo nav, como app */
    html.has-appnav .dashboard__navbar,
    html.has-appnav .buy-varas__navbar,
    html.has-appnav .comunidades__navbar,
    html.has-appnav .sorteo-global__navbar,
    html.has-appnav .profile__navbar,
    html.has-appnav .settings__navbar {
        display: none;
    }
}

/* Botón "Cerrar sesión" del Perfil: solo visible en móvil con barra inferior
   (en escritorio ya existe en el nav superior). */
.logout-mobile {
    display: none;
}
@media (max-width: 768px) {
    html.has-appnav .logout-mobile {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        margin-top: var(--sp-5);
        padding: 0.85rem;
        border: 1.5px solid var(--c-error);
        border-radius: var(--r-md);
        background: var(--c-surface);
        color: var(--c-error);
        font-weight: 700;
        font-size: var(--fs-md);
        text-decoration: none;
    }
}