/**
 * Moderne CSS-Features
 * Container Queries, CSS Nesting, :has() Selector, moderne Layout-Features
 *
 * @package IT_Expert_Hub
 * @since 1.1.0
 */

/* ===== Container Queries für Responsive Components ===== */

/* Container für Cards Grid definieren */
.cards-container,
.experts-grid,
.companies-grid,
.events-grid {
    container-type: inline-size;
    container-name: cards;
}

/* Responsive basierend auf Container-Größe, nicht Viewport */
@container cards (max-width: 600px) {
    .cards-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .card,
    .expert-card,
    .company-card,
    .event-card {
        padding: 1rem;
    }
    
    .card-title {
        font-size: 1.25rem;
    }
}

@container cards (min-width: 601px) and (max-width: 900px) {
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

@container cards (min-width: 901px) {
    .cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 2rem;
    }
}

/* ===== :has() Selector für kontextbasiertes Styling ===== */

/* Karten mit Bildern anders stylen */
.card:has(img),
.expert-card:has(img) {
    padding-top: 0;
    overflow: hidden;
}

.card:has(img) img,
.expert-card:has(img) img {
    margin: 0;
    border-radius: 8px 8px 0 0;
}

/* Navigation mit aktivem Item hervorheben */
.main-navigation:has(.current-menu-item) {
    border-bottom: 2px solid var(--primary-color);
}

/* Formulare mit Fehlern */
.form-group:has(.error) {
    margin-bottom: 2rem;
}

.form-group:has(.error) label {
    color: var(--error-color, #dc3545);
}

/* Artikel mit Featured Image */
.entry:has(.post-thumbnail) .entry-header {
    margin-top: 0;
}

/* Container mit sticky Sidebar */
.site-content:has(.sidebar-sticky) {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
    align-items: start;
}

/* ===== Moderne Layout-Features ===== */

/* Subgrid für verschachtelte Grids */
@supports (grid-template-rows: subgrid) {
    .cards-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 2rem;
    }
    
    .card {
        display: grid;
        grid-template-rows: subgrid;
        grid-row: span 3;
    }
    
    .card-header,
    .card-body,
    .card-footer {
        grid-row: auto;
    }
}

/* ===== CSS Cascade Layers ===== */

@layer reset, base, components, utilities;

@layer base {
    :root {
        /* Moderne CSS Custom Properties */
        --font-size-fluid-sm: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
        --font-size-fluid-md: clamp(1rem, 0.9rem + 0.5vw, 1.25rem);
        --font-size-fluid-lg: clamp(1.25rem, 1.1rem + 0.75vw, 1.75rem);
        --font-size-fluid-xl: clamp(1.5rem, 1.3rem + 1vw, 2.5rem);
        
        /* Spacing mit Fluid Typography */
        --spacing-xs: clamp(0.5rem, 0.45rem + 0.25vw, 0.75rem);
        --spacing-sm: clamp(1rem, 0.9rem + 0.5vw, 1.5rem);
        --spacing-md: clamp(1.5rem, 1.3rem + 1vw, 2.5rem);
        --spacing-lg: clamp(2rem, 1.7rem + 1.5vw, 3.5rem);
        --spacing-xl: clamp(3rem, 2.5rem + 2.5vw, 5.5rem);
        
        /* Modern Transitions */
        --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
        --transition-base: 300ms cubic-bezier(0.4, 0, 0.2, 1);
        --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);
    }
}

@layer components {
    /* Button Varianten */
    .btn-primary {
        background-color: var(--primary-color);
        color: white;
        padding: 0.75rem 1.5rem;
        border-radius: 0.375rem;
        transition: all var(--transition-base);
    }
    
    .btn-primary:hover {
        background-color: var(--primary-hover);
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
    }
    
    /* Card Component */
    .modern-card {
        background: white;
        border-radius: 0.75rem;
        padding: var(--spacing-md);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        transition: all var(--transition-base);
    }
    
    .modern-card:hover {
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
        transform: translateY(-4px);
    }
}

@layer utilities {
    /* Utility Classes */
    .flex-center {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .grid-auto-fit {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
        gap: var(--spacing-md);
    }
}

/* ===== Moderne Viewport Units ===== */

.hero-section {
    min-height: 100dvh; /* Dynamic Viewport Height - berücksichtigt Mobile Browser UI */
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-menu {
    height: 100svh; /* Small Viewport Height - kleinster Viewport */
}

.full-page-section {
    min-height: 100lvh; /* Large Viewport Height - größter Viewport */
}

/* ===== CSS Content Visibility für Performance ===== */

.card,
.expert-card,
.company-card {
    content-visibility: auto;
    contain-intrinsic-size: 0 400px; /* Placeholder für nicht geladene Inhalte */
}

/* ===== Scroll-Snap für bessere UX ===== */

.scrollable-container {
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    overflow-x: auto;
    display: flex;
    gap: 1rem;
}

.scroll-item {
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* ===== Focus-Visible für moderne Browser ===== */

/* Bessere Focus-Styles nur bei Keyboard-Navigation */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 0.25rem;
}

/* Kein Outline bei Maus-Klick */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
    outline: none;
}

/* ===== Logical Properties für bessere Internationalisierung ===== */

.card {
    margin-block: var(--spacing-md);
    margin-inline: auto;
    padding-block: var(--spacing-sm);
    padding-inline: var(--spacing-md);
}

.text-start {
    text-align: start; /* Statt left - funktioniert für RTL */
}

.text-end {
    text-align: end; /* Statt right */
}

/* ===== Aspect Ratio für responsive Medien ===== */

.video-container,
.image-container {
    aspect-ratio: 16 / 9;
    width: 100%;
    overflow: hidden;
}

.square-image {
    aspect-ratio: 1 / 1;
}

.portrait-image {
    aspect-ratio: 3 / 4;
}

/* ===== Color-Mix für dynamische Farben ===== */

@supports (background: color-mix(in srgb, blue, white)) {
    .btn-primary-light {
        background: color-mix(in srgb, var(--primary-color) 20%, white);
    }
    
    .btn-primary-dark {
        background: color-mix(in srgb, var(--primary-color) 80%, black);
    }
    
    .card-hover-bg {
        background: color-mix(in srgb, var(--primary-color) 5%, white);
    }
}

/* ===== Gradient Text ===== */

.gradient-text {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===== Modern Scrollbar Styling ===== */

.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--light-bg);
}

.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: var(--light-bg);
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: var(--primary-hover);
}

/* ===== Backdrop Filter für Glassmorphism ===== */

@supports (backdrop-filter: blur(10px)) {
    .glass-card {
        background: rgba(255, 255, 255, 0.8);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.3);
    }
    
    .glass-header {
        background: rgba(255, 255, 255, 0.9);
        backdrop-filter: blur(20px) saturate(180%);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
    }
}

/* ===== Text Balance für bessere Typografie ===== */

@supports (text-wrap: balance) {
    h1, h2, h3, h4, h5, h6 {
        text-wrap: balance;
    }
}

@supports (text-wrap: pretty) {
    p {
        text-wrap: pretty;
    }
}

/* ===== Header Animation beim Scrollen ===== */

.site-header {
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.site-header.scrolled {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.site-header.header-hidden {
    transform: translateY(-100%);
}

/* ===== Smooth Animations ===== */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.animate-fade-in {
    animation: fadeInUp var(--transition-slow) ease-out;
}

.animate-slide-in {
    animation: slideInRight var(--transition-slow) ease-out;
}

/* Stagger Animation für Listen */
.stagger-animation > * {
    animation: fadeInUp var(--transition-slow) ease-out;
    animation-fill-mode: backwards;
}

.stagger-animation > *:nth-child(1) { animation-delay: 0ms; }
.stagger-animation > *:nth-child(2) { animation-delay: 100ms; }
.stagger-animation > *:nth-child(3) { animation-delay: 200ms; }
.stagger-animation > *:nth-child(4) { animation-delay: 300ms; }
.stagger-animation > *:nth-child(5) { animation-delay: 400ms; }

/* ===== Mobile: Alle Animationen und Effekte deaktivieren ===== */
@media (max-width: 768px) {
    /* Keine Header Animationen */
    .site-header {
        transform: none !important;
        transition: none !important;
    }
    
    .site-header.scrolled {
        transform: none !important;
    }
    
    .site-header.header-hidden {
        transform: none !important;
    }
    
    /* Keine Card Hover Effekte */
    .modern-card:hover,
    .card:hover,
    .expert-card:hover,
    .company-card:hover,
    .event-card:hover {
        transform: none !important;
    }
    
    /* Keine Button Hover Animationen */
    .btn-primary:hover,
    .btn:hover {
        transform: none !important;
    }
    
    /* Alle Animationen deaktivieren */
    .animate-fade-in,
    .animate-slide-in,
    .stagger-animation > * {
        animation: none !important;
    }
    
    /* Hero Section statisch */
    .hero-section,
    .hero-header {
        background-attachment: scroll !important;
        transform: none !important;
    }
    
    /* Reduzierte Transitions */
    * {
        transition-duration: 0.15s !important;
    }
}

/* ===== Reduzierte Bewegungen für Barrierefreiheit ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .site-header,
    .hero-header,
    .card,
    .btn {
        transform: none !important;
    }
}
