/**
 * Custom Styles
 * 
 * @package Lightway
 * @since 1.0.0
 */

/* Critical CSS - Above the fold */
/* Inline critical path CSS for faster FCP */

/* Reset and Base */
* {
    box-sizing: border-box;
}

/* Prevent layout shift with font loading */
body {
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-display: swap; /* Prevent invisible text during webfont load */
}

/* Prevent CLS with image aspect ratios */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Ensure images have dimensions to prevent CLS */
.wp-block-post-featured-image img,
.post-thumbnail img {
    aspect-ratio: attr(width) / attr(height);
}

/* GPU acceleration for animations (better FID/INP) */
.toc-toggle,
.category-card,
.post-card,
.wp-block-group.has-border-color {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Table of Contents - Collapsible */
.table-of-contents {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 0.5rem;
    padding: 0;
    margin: 2rem 0;
    overflow: hidden;
    contain: layout; /* CSS containment for better performance */
}

.toc-toggle {
    width: 100%;
    background: #2563eb;
    color: white;
    border: none;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.2s ease;
    touch-action: manipulation; /* Better touch performance */
}

.toc-toggle:hover {
    background: #1d4ed8;
}

.toc-toggle:focus {
    outline: 2px solid #60a5fa;
    outline-offset: -2px;
}

.toc-toggle-icon {
    display: inline-block;
    transition: transform 0.3s ease;
    font-size: 0.875rem;
}

.toc-toggle.collapsed .toc-toggle-icon {
    transform: rotate(-90deg);
}

.toc-content {
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding: 1.5rem;
    contain: layout style; /* CSS containment */
}

.toc-toggle[aria-expanded="false"] + .toc-content {
    padding: 0 1.5rem;
}

.table-of-contents ul,
.table-of-contents ol {
    margin: 0;
    padding-left: 1.5rem;
    list-style-position: outside;
}

.table-of-contents li {
    margin: 0.5rem 0;
    line-height: 1.6;
}

.table-of-contents a {
    color: #1f2937;
    text-decoration: none;
    transition: color 0.2s ease;
}

.table-of-contents a:hover {
    color: #2563eb;
    text-decoration: underline;
}

body {
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Reserve space for lazy loaded images to prevent CLS */
img[loading="lazy"] {
    min-height: 200px; /* Adjust based on your content */
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Featured Image Styling */
.wp-block-post-featured-image {
    margin-bottom: 1.5rem;
}

.wp-block-post-featured-image img {
    border-radius: 0.5rem;
    width: 100%;
    height: auto;
}

/* Post Thumbnail */
.post-thumbnail {
    margin-bottom: 1.5rem;
}

.post-thumbnail img {
    border-radius: 0.5rem;
    width: 100%;
    height: auto;
}

/* Post Title */
.wp-block-post-title a,
.entry-title a {
    text-decoration: none;
    color: inherit;
}

.wp-block-post-title a:hover,
.entry-title a:hover {
    color: var(--wp--preset--color--primary);
}

/* Post Meta */
.entry-meta {
    font-size: 0.875rem;
    color: var(--wp--preset--color--secondary);
    margin-bottom: 1rem;
}

/* Post Content */
.entry-content,
.wp-block-post-content {
    line-height: 1.8;
}

.entry-content > *:first-child,
.wp-block-post-content > *:first-child {
    margin-top: 0;
}

/* Comments */
.wp-block-comments {
    margin-top: 3rem;
}

.wp-block-comment-template li {
    list-style: none;
}

/* Navigation */
.wp-block-navigation a {
    text-decoration: none;
}

/* Pagination */
.wp-block-query-pagination {
    margin-top: 2rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.wp-block-query-pagination a {
    padding: 0.5rem 1rem;
    background: var(--wp--preset--color--background);
    border: 1px solid var(--wp--preset--color--primary);
    border-radius: 0.375rem;
    text-decoration: none;
}

.wp-block-query-pagination a:hover {
    background: var(--wp--preset--color--primary);
    color: var(--wp--preset--color--background);
}

/* Search Form */
.wp-block-search {
    margin-bottom: 2rem;
}

.wp-block-search__input {
    padding: 0.75rem;
    border: 1px solid var(--wp--preset--color--secondary);
    border-radius: 0.375rem;
}

.wp-block-search__button {
    padding: 0.75rem 1.5rem;
    background: var(--wp--preset--color--primary);
    color: var(--wp--preset--color--background);
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
}

.wp-block-search__button:hover {
    background: var(--wp--preset--color--accent);
}

/* Responsive Tables */
.responsive_tables {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1.5rem;
}

.responsive_tables table {
    min-width: 100%;
    border-collapse: collapse;
}

/* Responsive */
@media (max-width: 768px) {
    .wp-block-group {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .wp-block-post-featured-image img {
        border-radius: 0.25rem;
    }
    
    .responsive_tables {
        margin-left: -1rem;
        margin-right: -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* Performance Optimization - Reduce layout shifts */
.wp-block-image img {
    height: auto;
}

/* Content visibility for off-screen content (better INP) */
.wp-block-query-pagination,
.wp-block-comments {
    content-visibility: auto;
    contain-intrinsic-size: auto 500px;
}

/* Lazy Loading Support */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Front Page - Post Cards */
.post-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    contain: layout style paint; /* CSS containment */
}

.post-card:hover {
    transform: translateY(-4px);
}

.post-card .wp-block-post-featured-image {
    overflow: hidden;
    margin-bottom: 0;
    contain: layout; /* CSS containment */
}

.post-card .wp-block-post-featured-image img {
    transition: transform 0.3s ease;
}

.post-card:hover .wp-block-post-featured-image img {
    transform: scale(1.05);
}

/* Custom Category Grid (No Hierarchy) */
.lightway-category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
    contain: layout; /* CSS containment for better performance */
}

.lightway-category-grid .category-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: #ffffff;
    border: 2px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 2rem 1.5rem;
    text-decoration: none;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    min-height: 180px;
    contain: layout style paint; /* CSS containment */
    touch-action: manipulation; /* Better touch performance */
}

.lightway-category-grid .category-card:hover {
    border-color: var(--wp--preset--color--primary);
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.15);
    transform: translateY(-4px);
}

.lightway-category-grid .category-icon {
    font-size: 3.5rem;
    line-height: 1;
    margin-bottom: 1rem;
    display: block;
}

.lightway-category-grid .category-name {
    color: var(--wp--preset--color--foreground);
    font-weight: 600;
    font-size: 1.125rem;
    margin: 0 0 0.5rem 0;
    line-height: 1.3;
}

.lightway-category-grid .category-card:hover .category-name {
    color: var(--wp--preset--color--primary);
}

.lightway-category-grid .category-count {
    color: var(--wp--preset--color--secondary);
    font-size: 0.875rem;
    display: block;
    margin-top: auto;
}

/* Responsive for category grid */
@media (max-width: 768px) {
    .lightway-category-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 1rem;
    }
    
    .lightway-category-grid .category-card {
        padding: 1.5rem 1rem;
        min-height: 160px;
    }
    
    .lightway-category-grid .category-icon {
        font-size: 2.5rem;
    }
    
    .lightway-category-grid .category-name {
        font-size: 1rem;
    }
}

/* Categories Grid - Legacy WordPress block support */
.lightway-category-cards ul,
.is-style-category-grid ul {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    list-style: none;
    padding: 0;
    margin: 0;
}

.lightway-category-cards li,
.is-style-category-grid li {
    background: #ffffff;
    border: 2px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 1.5rem;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.lightway-category-cards li:hover,
.is-style-category-grid li:hover {
    border-color: var(--wp--preset--color--primary);
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.15);
    transform: translateY(-4px);
}

/* Hide child categories in block */
.lightway-category-cards .children,
.is-style-category-grid .children {
    display: none;
}

/* Category specific icons based on slug/name */
.lightway-category-cards li::before,
.is-style-category-grid li::before {
    content: '📋';
    font-size: 2.5rem;
    display: block;
    margin-bottom: 0.5rem;
}

/* artikler parent category */
.lightway-category-cards li.cat-item-artikler::before,
.is-style-category-grid li.cat-item-artikler::before {
    content: '📰';
}

/* Have category */
.lightway-category-cards li[class*="have"]::before,
.is-style-category-grid li[class*="have"]::before {
    content: '🌿';
}

/* Huset/Indendørs category */
.lightway-category-cards li[class*="huset"]::before,
.lightway-category-cards li[class*="indendors"]::before,
.is-style-category-grid li[class*="huset"]::before,
.is-style-category-grid li[class*="indendors"]::before {
    content: '🏠';
}

/* Generelt category */
.lightway-category-cards li[class*="generelt"]::before,
.is-style-category-grid li[class*="generelt"]::before {
    content: '📌';
}

/* Bolig category */
.lightway-category-cards li[class*="bolig"]::before,
.is-style-category-grid li[class*="bolig"]::before {
    content: '🏡';
}

/* Featured category */
.lightway-category-cards li[class*="featured"]::before,
.is-style-category-grid li[class*="featured"]::before {
    content: '⭐';
}

/* Gør det selv/DIY category */
.lightway-category-cards li[class*="gor"]::before,
.lightway-category-cards li[class*="selv"]::before,
.is-style-category-grid li[class*="gor"]::before,
.is-style-category-grid li[class*="selv"]::before {
    content: '🔨';
}

/* Haveliv category */
.lightway-category-cards li[class*="haveliv"]::before,
.is-style-category-grid li[class*="haveliv"]::before {
    content: '🌻';
}

.lightway-category-cards a,
.is-style-category-grid a {
    text-decoration: none;
    color: var(--wp--preset--color--foreground);
    font-weight: 600;
    font-size: 1.125rem;
    display: block;
}

.lightway-category-cards a:hover,
.is-style-category-grid a:hover {
    color: var(--wp--preset--color--primary);
}

.lightway-category-cards .cat-item,
.is-style-category-grid .cat-item {
    margin-bottom: 0;
}

/* Hero Section Enhancements */
.wp-block-cover h1 {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.wp-block-cover p {
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

/* Category Feature Cards */
.wp-block-group.has-border-color {
    transition: all 0.3s ease;
}

.wp-block-group.has-border-color:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    transform: translateY(-4px);
    border-color: var(--wp--preset--color--primary) !important;
}

/* Responsive Grid for Posts */
@media (max-width: 1024px) {
    .wp-block-post-template.is-flex-container.is-flex-container.is-flex-container {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 768px) {
    .wp-block-post-template.is-flex-container.is-flex-container.is-flex-container {
        grid-template-columns: 1fr !important;
    }
    
    .is-style-category-grid ul {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    
    .wp-block-cover h1 {
        font-size: 2rem !important;
    }
}

/* Post Meta - Last Updated */
.post-meta-updated {
    background: #f3f4f6;
    border-left: 4px solid var(--wp--preset--color--primary);
    padding: 0.75rem 1rem;
    margin-bottom: 2rem;
    font-size: 0.875rem;
    color: var(--wp--preset--color--secondary);
    border-radius: 0.25rem;
}

.post-meta-updated strong {
    color: var(--wp--preset--color--foreground);
}

/* Print Styles */
@media print {
    .wp-block-navigation,
    .wp-block-query-pagination,
    .wp-block-comments {
        display: none;
    }
}
