/* ═══════════════════════════════════════════
   SPUNTO PENSIONE — CSS LAYOUT
   ═══════════════════════════════════════════ */

/* ══════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════ */
.app-header {
    position: fixed;
    inset: 0 0 auto 0;
    height: var(--header-h);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-placeholder {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: var(--uil-yellow);
    color: var(--uil-blue);
    font-weight: 800;
    font-size: 14px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    letter-spacing: 1px;
}

.header-title {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--uil-text-light);
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 0;
    background: rgba(0, 0, 0, .15);
    color: var(--bianco);
    display: grid;
    place-items: center;
    transition: background .2s;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, .25);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

/* ══════════════════════════════════════════
   FOOTER
   ══════════════════════════════════════════ */
.app-footer {
    position: fixed;
    inset: auto 0 0 0;
    height: var(--footer-h);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    gap: 14px;
    z-index: 100;
}

.footer-left {
    flex: 1;
}

.footer-input {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid rgba(0, 0, 0, .15);
    border-radius: 0;
    background: rgba(255, 255, 255, .35);
    color: var(--antracite);
    font-size: .9rem;
    font-family: inherit;
    outline: none;
}

.footer-input::placeholder {
    color: rgba(0, 0, 0, .4);
}

.footer-btn {
    white-space: nowrap;
    padding: 10px 20px;
    border: none;
    border-radius: 0;
    background: rgba(255, 255, 255, .4);
    color: var(--antracite);
    font-weight: 700;
    font-size: .85rem;
    font-family: inherit;
    transition: background .2s;
}

/* ══════════════════════════════════════════
   MAIN CONTENT & VIEW SYSTEM
   ══════════════════════════════════════════ */
.app-main {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    overflow-y: auto;
    background: var(--uil-grey-bg);
    transition: background-color 0.4s ease;
}

/* Master CSS Theme Modifiers (Radial Mesh Gradients & Accents) */
.app-main.theme-home {
    --current-accent: var(--uil-blue);
    background: radial-gradient(circle at 100% 0%, rgba(0, 61, 153, 0.15) 0%, var(--bg-home) 60%);
}

.app-main.theme-pensioni {
    --current-accent: var(--accent-pensioni);
    background: radial-gradient(circle at 100% 0%, rgba(255, 120, 46, 0.15) 0%, var(--bg-home) 60%);
}

.app-main.theme-salute {
    --current-accent: var(--accent-salute);
    background: radial-gradient(circle at 100% 0%, rgba(255, 64, 129, 0.15) 0%, var(--bg-home) 60%);
}

.app-main.theme-integrazioni {
    --current-accent: var(--accent-integrazioni);
    background: radial-gradient(circle at 100% 0%, rgba(41, 182, 246, 0.15) 0%, var(--bg-home) 60%);
}

.app-main.theme-servizi {
    --current-accent: var(--accent-servizi);
    background: radial-gradient(circle at 100% 0%, rgba(102, 187, 106, 0.15) 0%, var(--bg-home) 60%);
}

.view {
    display: none;
    width: 100%;
    min-height: 100%;
    padding-top: var(--header-h);
    padding-bottom: var(--footer-h);
}

@keyframes viewEnter {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.view.active {
    display: flex;
    flex-direction: column;
    animation: viewEnter 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

/* --- APP STARTUP ANIMATIONS --- */
@keyframes titleVortex {
    0% {
        opacity: 0;
        transform: translateX(-10vw) translateY(30vh) scale(1.4);
    }

    15% {
        opacity: 1;
        transform: translateX(-10vw) translateY(30vh) scale(1.4);
    }

    70% {
        opacity: 1;
        transform: translateX(-10vw) translateY(30vh) scale(1.4);
    }

    100% {
        opacity: 1;
        transform: translateX(0) translateY(0) scale(1);
    }
}

@keyframes opacityReveal {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

@keyframes slideUpFade {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUpFadeAndOut {
    0% {
        opacity: 0;
    }

    15% {
        opacity: 1;
    }

    85% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

@keyframes vortexIn {
    0% {
        opacity: 0;
        transform: scale(0.6) translateY(60px);
    }

    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes viewSlideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Overrides for home vs child views */
.view--home.active {
    animation: none;
    /* Let children animate instead */
}

.view.active:not(.view--home) {
    animation: viewSlideInRight 0.35s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

/* Master CSS - TITOLI DI PAGINA / CATEGORIA */
.category-title {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.1;
    transition: color 0.4s ease;
}

/* Colore titolo in base al tema contenitore - Dynamic Accent Glow */
.app-main.theme-home .category-title,
.app-main.theme-pensioni .category-title,
.app-main.theme-salute .category-title,
.app-main.theme-integrazioni .category-title,
.app-main.theme-servizi .category-title {
    color: var(--current-accent);
    text-shadow: 0 0 15px var(--current-accent);
}

/* ══════════════════════════════════════════
   VISTA 1 — HOME (Griglia 2x2)
   ══════════════════════════════════════════ */
.view--home {
    align-items: center;
    justify-content: center;
    padding: calc(var(--header-h) + 10px) 30px calc(var(--footer-h) + 180px);
    overflow-y: auto;
}

.view--category {
    padding: calc(var(--header-h) + 10px) 30px calc(var(--footer-h) + 180px);
    align-items: center;
    justify-content: center;
    overflow-y: auto;
}

.view--category .card-grid {
    max-width: 700px;
}

.page-title {
    font-size: 2.8rem;
    font-weight: 900;
    text-transform: uppercase;
    text-align: left;
    width: 100%;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.05;
    margin-bottom: 110px;
    letter-spacing: -0.5px;
}

/* Colore titolo in base al tema */
.app-main.theme-home .page-title,
.app-main.theme-pensioni .page-title,
.app-main.theme-salute .page-title,
.app-main.theme-integrazioni .page-title,
.app-main.theme-servizi .page-title {
    color: var(--uil-text-dark);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    width: 100%;
    max-width: 1200px;
}

/* Home view startup animations (Solo il titolo gigante) */
body.app-startup {
    overflow: hidden;
}

body.app-startup .app-header {
    opacity: 0;
    animation: opacityReveal 0.6s ease forwards;
    animation-delay: 2.3s;
    /* Navbar appears AFTER title settles */
}

body.app-startup .view--home .page-title {
    opacity: 0;
    animation: titleVortex 2.6s cubic-bezier(0.25, 1, 0.4, 1) forwards;
    transform-origin: center center;
    position: relative;
    z-index: 100;
}

body.app-startup .view--home .subtitle-argomento {
    opacity: 0;
    animation: slideUpFadeAndOut 10s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    animation-delay: 2.3s;
    /* Wait for title to finish */
    pointer-events: none;
    /* Evita collisioni invisibili */
}

body.app-startup .view--home .card-grid {
    opacity: 0;
    animation: slideUpFade 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    animation-delay: 2.3s;
    /* Wait for title to finish */
}

/* Normal transition for Home when navigating back (no spin/stagger) */
body:not(.app-startup) .view--home.active {
    animation: viewEnter 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}


.tile {
    position: relative;
    border-radius: 16px;
    padding: 24px 12px;
    aspect-ratio: 1;
    width: 100%;
    /* Strict sizing to match home grid perfectly */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
    transition: box-shadow 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), border-color 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    overflow: hidden;
}

.tile__title {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.25;
    /* Prevent long text from expanding the square */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 42px rgba(0, 0, 0, 0.5), 0 0 20px var(--hover-accent, var(--current-accent));
    border-color: var(--hover-accent, var(--current-accent));
}

.tile:hover .tile__icon svg {
    stroke: var(--hover-accent, var(--current-accent));
}

/* Specific glows for Home categories */
.tile[data-category="Pensioni"] {
    --hover-accent: var(--accent-pensioni);
}

.tile[data-category="Salute e Invalidità"] {
    --hover-accent: var(--accent-salute);
}

.tile[data-category="Integrazioni e Aiuti"] {
    --hover-accent: var(--accent-integrazioni);
}

.tile[data-category="Altri Servizi"] {
    --hover-accent: var(--accent-servizi);
}

.tile__icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    pointer-events: none;
}

.tile__icon svg {
    width: 38px;
    height: 38px;
}

/* Monochrome icon colors by card type */
.card-light .tile__icon {
    background: rgba(255, 255, 255, .05);
    color: var(--uil-text-dark);
}

.card-light .tile__icon svg {
    stroke: var(--uil-text-dark);
    stroke-width: 1.8;
    fill: none;
}

.card-dark .tile__icon {
    background: rgba(255, 255, 255, .05);
    color: var(--uil-text-dark);
}

.card-dark .tile__icon svg {
    stroke: var(--uil-text-dark);
    stroke-width: 1.8;
    fill: none;
}

.tile__icon svg {
    width: 38px;
    height: 38px;
}

.tile__title {
    font-weight: 800;
    font-size: .85rem;
    line-height: 1.2;
    text-transform: uppercase;
    pointer-events: none;
    letter-spacing: 0.5px;
    margin-top: 15px;
}

/* --- VARIANTE CARD BIANCA (Per la Home) --- */
.card-light {
    background: var(--antracite);
    color: var(--uil-text-dark);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.card-light .icon {
    color: var(--uil-text-dark);
}

/* --- VARIANTE CARD ANTRACITE (Per le Sezioni) --- */
.card-dark {
    background: var(--antracite);
    color: var(--uil-text-dark);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.25);
}

.card-dark .icon {
    color: var(--uil-text-dark);
}

@keyframes wobble {
    0% {
        transform: translateX(0);
    }

    15% {
        transform: translateX(-5px);
    }

    30% {
        transform: translateX(4px);
    }

    45% {
        transform: translateX(-3px);
    }

    60% {
        transform: translateX(2px);
    }

    75% {
        transform: translateX(-1px);
    }

    100% {
        transform: translateX(0);
    }
}

.tile:active,
.tile.wobbling {
    box-shadow: none;
    animation: wobble .4s var(--ease-out);
}

.tile--routable {
    cursor: pointer;
}

.tile:not(.tile--routable) {
    cursor: default;
}

/* ── Responsive Tweaks (Layout-related) ── */
@media (max-width: 700px) {
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .tile {
        padding: 14px 10px;
    }

    .tile__icon {
        width: 40px;
        height: 40px;
    }

    .tile__icon svg {
        width: 20px;
        height: 20px;
    }

    .tile__title {
        font-size: .7rem;
    }

    .page-title {
        font-size: 2rem;
    }

    .footer-btn {
        font-size: .78rem;
        padding: 8px 12px;
    }
}

@media (max-width: 480px) {
    .page-title {
        font-size: 1.6rem;
    }

    .card-grid {
        gap: 10px;
    }
}

/* ══════════════════════════════════════════
   SPOTLIGHT SEARCH (Command Palette)
   ══════════════════════════════════════════ */
.spotlight-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 15vh;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.spotlight-overlay:not(.hidden) {
    opacity: 1;
    visibility: visible;
}
.spotlight-overlay:not(.hidden) .spotlight-container {
    transform: scale(1) translateY(0);
}

.spotlight-container {
    background: var(--antracite);
    width: 90%;
    max-width: 650px;
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
    transform: scale(0.95) translateY(-20px);
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.spotlight-overlay:not(.hidden) .spotlight-container {
    transform: scale(1) translateY(0);
}

.spotlight-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.spotlight-icon {
    width: 24px;
    height: 24px;
    stroke: var(--uil-text-dark);
    opacity: 0.5;
    margin-right: 16px;
}

.spotlight-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--uil-text-dark);
    font-size: 1.25rem;
    font-weight: 500;
    outline: none;
    font-family: 'Inter', sans-serif;
    width: 100%;
}

.spotlight-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.spotlight-close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--uil-text-dark);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.spotlight-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.spotlight-results {
    max-height: 350px;
    overflow-y: auto;
    padding: 8px 0;
}

.spotlight-result-item {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    color: var(--uil-text-dark);
}

.spotlight-result-item:hover,
.spotlight-result-item.selected {
    background: rgba(255, 255, 255, 0.05);
    border-left-color: var(--current-accent, #66bb6a);
}

.spotlight-footer {
    padding: 12px 20px;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* ══════════════════════════════════════════
   SKELETON LOADERS
   ══════════════════════════════════════════ */
@keyframes skeletonPulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.2;
    }

    100% {
        opacity: 1;
    }
}

.skeleton-pulse {
    animation: skeletonPulse 1.2s ease-in-out infinite;
    pointer-events: none;
}

.skeleton-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    margin-bottom: 12px;
}

.skeleton-text {
    width: 70%;
    height: 12px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    margin-top: 15px;
}

.fade-in-fast {
    animation: slideUpFade 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}