/**
 * Visual Enhancements
 * Refined animations, glassmorphism effects, and micro-interactions
 * Integrates with existing Megistone design system
 */

/* ==================== CSS Custom Properties - Enhancements ==================== */
:root {
    /* Glassmorphism tokens */
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.18);
    --glass-blur: 12px;

    /* Enhancement colors derived from brand */
    --glow-primary: rgba(2, 102, 127, 0.4);
    --glow-secondary: rgba(82, 151, 32, 0.35);

    /* Animation tokens */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-spring: cubic-bezier(0.5, 1.8, 0.5, 0.8);
}

/* ==================== Hero Section Enhancements ==================== */

/* Animated grid overlay for hero */
.hero__background::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(82, 151, 32, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(82, 151, 32, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    animation: gridPulse 8s ease-in-out infinite;
    pointer-events: none;
}

@keyframes gridPulse {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.02); }
}

/* Floating orbs decoration */
.hero::before {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, var(--glow-secondary) 0%, transparent 70%);
    top: 10%;
    right: -100px;
    border-radius: 50%;
    filter: blur(60px);
    animation: floatOrb1 15s ease-in-out infinite;
    pointer-events: none;
    z-index: 1;
}

.hero::after {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--glow-primary) 0%, transparent 70%);
    bottom: 20%;
    left: -50px;
    border-radius: 50%;
    filter: blur(50px);
    animation: floatOrb2 12s ease-in-out infinite;
    pointer-events: none;
    z-index: 1;
}

@keyframes floatOrb1 {
    0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.6; }
    33% { transform: translate(-30px, 40px) scale(1.1); opacity: 0.8; }
    66% { transform: translate(20px, -20px) scale(0.95); opacity: 0.5; }
}

@keyframes floatOrb2 {
    0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.5; }
    50% { transform: translate(40px, -30px) scale(1.15); opacity: 0.7; }
}


/* Hero CTA button enhancement */
.hero .btn--primary {
    position: relative;
    overflow: hidden;
    transition: all 0.4s var(--ease-out-expo);
}

.hero .btn--primary::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(45deg, transparent, rgba(255,255,255,0.2), transparent);
    transform: translateX(-100%);
    transition: transform 0.6s var(--ease-out-expo);
}

.hero .btn--primary:hover::before {
    transform: translateX(100%);
}

.hero .btn--primary:hover {
    transform: translateY(-3px);
    box-shadow:
        0 10px 30px -10px rgba(2, 102, 127, 0.5),
        0 0 20px rgba(82, 151, 32, 0.3);
}

/* ==================== Unified Typography System ==================== */
/*
 * Sistema tipografico elegante e coerente per Megistone
 * Ispirato alla tipografia editoriale: leggibilità, ritmo, respiro
 */

:root {
    /* Paragraph Typography Tokens */
    --prose-size: 1rem;
    --prose-size-lg: 1.0625rem;
    --prose-line-height: 1.75;
    --prose-letter-spacing: 0.005em;
    --prose-color: #4a5568;
    --prose-color-light: rgba(255, 255, 255, 0.9);
    /* Unified text container width - optimal reading length */
    --prose-max-width: 800px;
}

/* ============================================
   PROSE MIXIN - Stile base per tutti i testi
   ============================================ */

/* Paragrafi su sfondo CHIARO */
p[class*="__text"],
p[class*="__description"],
p[class*="__intro"],
p[class*="__items"],
.industry-card p,
.tech-category p {
    font-size: var(--prose-size);
    line-height: var(--prose-line-height);
    letter-spacing: var(--prose-letter-spacing);
    color: var(--prose-color);
    text-align: justify !important;
    text-justify: inter-word;
    -webkit-hyphens: auto;
    hyphens: auto;
    font-weight: 400;
}

/* Paragrafi su sfondo SCURO (hero, cta, page-hero) */
.hero p,
.cta p,
.page-hero p,
.section--primary p {
    color: var(--prose-color-light);
}

/* ============================================
   DIMENSIONI CONTESTUALI
   ============================================ */

/* Card descriptions - leggermente più compatte */
.service-card__description,
.service-block__description,
.solution-card__description,
.expertise-card__description,
.expertise-block__text,
.approach-item__description,
.dc-feature__description,
.dc-future__description,
.value-item__description,
.industry-card__description,
.dc-service-card__description {
    font-size: 0.9375rem;
    line-height: 1.7;
}

/* Testi introduttivi - più grandi e ariosi */
.text-block__text,
.dc-intro__text,
.about-intro__text,
.partner__text,
.values__text,
.experience__description,
.contact-info__intro,
.section__intro,
.section__description {
    font-size: var(--prose-size-lg);
    line-height: 1.8;
    margin-bottom: var(--spacing-lg);
}

/* ============================================
   ALLINEAMENTI SPECIFICI
   ============================================ */

/* Hero - allineato a sinistra, più grande */
.hero__description {
    font-size: 1.125rem;
    text-align: left !important;
    line-height: 1.8;
}

/* CTA - centrato */
.cta__description {
    text-align: center !important;
    max-width: var(--prose-max-width);
    margin-inline: auto;
}

/* Section intro e description - centrato */
.section__intro,
.section__description {
    text-align: center !important;
    max-width: var(--prose-max-width);
    margin-inline: auto;
    margin-bottom: var(--spacing-xl);
}

/* Experience highlight - justify forzato */
.experience-highlight__description {
    text-align: justify;
    font-size: 1.0625rem;
    line-height: 1.8;
    max-width: var(--prose-max-width);
    margin-inline: auto;
}

/* ============================================
   UNIFIED TEXT CONTAINER WIDTHS
   ============================================ */

/* All text-heavy containers use unified width */
.dc-intro__content,
.about-intro__content,
.partner__content,
.values__content,
.approach__content,
.text-block--centered,
.experience-highlight__content {
    max-width: var(--prose-max-width);
    margin-inline: auto;
}

/* ============================================
   SOTTOTITOLI E ITEMS
   ============================================ */

.section__subtitle,
.page-hero__subtitle {
    font-size: 1.125rem;
    line-height: 1.6;
    letter-spacing: 0.01em;
    font-weight: 400;
}

.tech-category__items {
    font-size: 0.9375rem;
    line-height: 1.7;
}

/* ============================================
   ULTIMO ELEMENTO - rimuovi margine
   ============================================ */

p[class*="__text"]:last-child,
p[class*="__description"]:last-child,
p[class*="__intro"]:last-child {
    margin-bottom: 0;
}

/* ==================== Unified Card System ==================== */
/* Stile unico per tutte le card del sito - basato su .service-block */
/* Bordino animato che si estende dagli angoli */

/* Base card styles - applied to ALL card types */
.service-block,
.service-card,
.solution-card,
.expertise-block,
.expertise-card,
.dc-feature,
.dc-future__item,
.dc-service-card,
.industry-card,
.approach-item {
    position: relative;
    padding: var(--spacing-xl);
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border-left: 4px solid var(--color-primary);
    background-image: linear-gradient(to bottom, rgba(82, 151, 32, 0.9), rgba(82, 151, 32, 0.9));
    background-size: 4px 0;
    background-position: left top;
    background-repeat: no-repeat;
    transition:
        transform var(--transition-base),
        box-shadow var(--transition-base),
        background-size 1s var(--ease-out-expo);
}

/* Hover state - green border grows */
.service-block:hover,
.service-card:hover,
.solution-card:hover,
.expertise-block:hover,
.expertise-card:hover,
.dc-feature:hover,
.dc-future__item:hover,
.dc-service-card:hover,
.industry-card:hover,
.approach-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    background-size: 4px 100%;
}

/* Icon hover effect con gradient */
.expertise-block__icon,
.service-card__icon,
.service-block__icon,
.dc-feature__icon {
    transition: all 0.4s var(--ease-out-back);
}

.expertise-block:hover .expertise-block__icon,
.service-card:hover .service-card__icon,
.service-block:hover .service-block__icon,
.dc-feature:hover .dc-feature__icon {
    transform: scale(1.08);
    background: linear-gradient(135deg, var(--color-primary), rgba(82, 151, 32, 0.9));
}

/* Top border + right-top (si estende da top-left verso right, poi scende) */
.service-block::before,
.service-card::before,
.solution-card::before,
.expertise-block::before,
.expertise-card::before,
.dc-feature::before,
.dc-future__item::before,
.dc-service-card::before,
.industry-card::before,
.approach-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: calc(50% + 2px);
    border-top: 1px solid var(--color-primary);
    border-right: 1px solid var(--color-primary);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    pointer-events: none;
    clip-path: inset(0 100% 100% 0 round var(--radius-lg));
    transition: clip-path 0.5s var(--ease-out-expo);
}

.service-block:hover::before,
.service-card:hover::before,
.solution-card:hover::before,
.expertise-block:hover::before,
.expertise-card:hover::before,
.dc-feature:hover::before,
.dc-future__item:hover::before,
.dc-service-card:hover::before,
.industry-card:hover::before,
.approach-item:hover::before {
    clip-path: inset(0 0 0 0);
}

/* Bottom border + right-bottom (si estende da bottom-left verso right, poi sale) */
.service-block::after,
.service-card::after,
.solution-card::after,
.expertise-block::after,
.expertise-card::after,
.dc-feature::after,
.dc-future__item::after,
.dc-service-card::after,
.industry-card::after,
.approach-item::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(50% + 2px);
    border-bottom: 1px solid var(--color-primary);
    border-right: 1px solid var(--color-primary);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
    pointer-events: none;
    clip-path: inset(100% 100% 0 0 round var(--radius-lg));
    transition: clip-path 0.5s var(--ease-out-expo);
}

.service-block:hover::after,
.service-card:hover::after,
.solution-card:hover::after,
.expertise-block:hover::after,
.expertise-card:hover::after,
.dc-feature:hover::after,
.dc-future__item:hover::after,
.dc-service-card:hover::after,
.industry-card:hover::after,
.approach-item:hover::after {
    clip-path: inset(0 0 0 0);
}

/* ==================== Stat Counter Enhancements ==================== */

.stat-item {
    position: relative;
    transition: all 0.4s var(--ease-out-expo);
}

.stat-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        180deg,
        transparent 0%,
        rgba(2, 102, 127, 0.03) 100%
    );
    border-radius: var(--radius-lg);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.stat-item:hover::before {
    opacity: 1;
}

.stat-item__number {
    position: relative;
    display: inline-block;
    transition: all 0.4s var(--ease-out-expo);
}

/* Animated underline accent */
.stat-item__number::after {
    content: '' !important;
    position: absolute;
    bottom: -8px;
    left: 50%;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--color-primary), rgba(82, 151, 32, 0.8));
    border-radius: 2px;
    transition: all 0.5s var(--ease-out-expo);
    transform: translateX(-50%);
}

.stat-item.is-counting .stat-item__number::after,
.stat-item:hover .stat-item__number::after {
    width: 60%;
}

/* Number scale animation during count */
.stat-item.is-counting .stat-item__number {
    animation: numberPop 2s var(--ease-out-expo);
}

@keyframes numberPop {
    0% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

.stat-item__label {
    transition: all 0.3s ease;
}

.stat-item:hover .stat-item__label {
    color: var(--color-primary);
}



/* ==================== CTA Section Enhancements ==================== */

.section--primary.cta {
    position: relative;
    overflow: hidden;
}

.section--primary.cta::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(
        circle at 30% 70%,
        rgba(82, 151, 32, 0.15) 0%,
        transparent 50%
    );
    animation: ctaGlow 10s ease-in-out infinite;
}

@keyframes ctaGlow {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(5%, -5%); }
}

.cta .btn--white {
    position: relative;
    overflow: hidden;
    transition: all 0.4s var(--ease-out-expo);
}

.cta .btn--white:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 15px 30px -10px rgba(0, 0, 0, 0.3);
}

/* ==================== Page Hero Floating Particles ==================== */

.page-hero {
    overflow: hidden;
}

/* Decorative floating dots */
.page-hero::before,
.page-hero::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
}

.page-hero::before {
    width: 6px;
    height: 6px;
    background: rgba(82, 151, 32, 0.6);
    top: 30%;
    left: 15%;
    box-shadow:
        40vw 10vh 0 rgba(255, 255, 255, 0.3),
        70vw -5vh 0 rgba(82, 151, 32, 0.4),
        25vw 40vh 0 rgba(255, 255, 255, 0.2),
        80vw 30vh 0 rgba(82, 151, 32, 0.3);
    animation: floatDots 20s linear infinite;
}

@keyframes floatDots {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(180deg); }
}

/* ==================== Scroll Reveal Animations ==================== */

.reveal-on-scroll {
    opacity: 0;
    transform: translateY(30px);
    transition: all 0.8s var(--ease-out-expo);
}

.reveal-on-scroll.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Staggered reveal for grid items */
/* IMPORTANT: Use specific properties, NOT 'all', to preserve card hover animations */
.reveal-stagger > * {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s var(--ease-out-expo), transform 0.6s var(--ease-out-expo);
}

.reveal-stagger.is-visible > *:nth-child(1) { transition-delay: 0ms; }
.reveal-stagger.is-visible > *:nth-child(2) { transition-delay: 80ms; }
.reveal-stagger.is-visible > *:nth-child(3) { transition-delay: 160ms; }
.reveal-stagger.is-visible > *:nth-child(4) { transition-delay: 240ms; }
.reveal-stagger.is-visible > *:nth-child(5) { transition-delay: 320ms; }
.reveal-stagger.is-visible > *:nth-child(6) { transition-delay: 400ms; }
.reveal-stagger.is-visible > *:nth-child(7) { transition-delay: 480ms; }
.reveal-stagger.is-visible > *:nth-child(8) { transition-delay: 560ms; }

.reveal-stagger.is-visible > * {
    opacity: 1;
    transform: translateY(0);
}

/* ==================== Button Micro-interactions ==================== */

.btn {
    position: relative;
    overflow: hidden;
    transition: all 0.4s var(--ease-out-expo);
}

.btn:active {
    transform: scale(0.97);
}

/* Ripple effect on click */
.btn-ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0);
    animation: ripple 0.6s ease-out forwards;
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* ==================== Form Input Enhancements ==================== */

.form-input,
.form-textarea {
    transition: all 0.3s var(--ease-out-expo);
}

.form-input:focus,
.form-textarea:focus {
    transform: translateY(-2px);
    box-shadow:
        0 0 0 3px rgba(2, 102, 127, 0.15),
        0 10px 20px -10px rgba(2, 102, 127, 0.2);
}

/* ==================== Technologies Section Enhancement ==================== */

.tech-category {
    position: relative;
    padding: var(--spacing-xl);
    background: var(--color-white);
    border-radius: var(--radius-lg);
    transition: all 0.4s var(--ease-out-expo);
    box-shadow: var(--shadow-sm);
}

.tech-category::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--color-primary), rgba(82, 151, 32, 0.8));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.5s var(--ease-out-expo);
}

.tech-category:hover::before {
    transform: scaleX(1);
}

.tech-category:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}


/* ==================== Technologies Grid ==================== */

.technologies__grid {
    display: grid;
    gap: var(--spacing-xl);
}

@media (min-width: 640px) {
    .technologies__grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .technologies__grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ==================== Industries Grid ==================== */

.industries__grid {
    display: grid;
    gap: var(--spacing-xl);
}

@media (min-width: 640px) {
    .industries__grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .industries__grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ==================== Reduced Motion Support ==================== */

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

    .hero__title {
        background: none;
        -webkit-text-fill-color: #e6e6e6;
    }
}
