/**
 * Custom Styles
 * 
 * @package Lightway
 * @since 1.0.0
 * @updated 2025-12-19 - Timeline styling enhancement
 */

/* 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 - Timeline Style */
.post-meta-timeline {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1.25rem 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    position: relative;
    overflow: hidden;
}

.post-meta-timeline::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #2563eb 0%, #3b82f6 50%, #60a5fa 100%);
}

.timeline-header {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.timeline-title {
    flex-shrink: 0;
}

.timeline-category {
    font-size: 0.8125rem;
    font-weight: 500;
    color: #64748b;
    text-align: right;
}

.timeline-category a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.timeline-category a:hover {
    color: #1d4ed8;
}

.timeline-header::before {
    display: none;
}

.timeline-item {
    position: relative;
    padding-left: 2rem;
    padding-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    transition: transform 0.2s ease;
}

.timeline-item:hover {
    transform: translateX(2px);
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 1.5rem;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, 
        #3b82f6 0%, 
        #60a5fa 50%, 
        #93c5fd 100%
    );
    border-radius: 2px;
}

.timeline-dot {
    position: absolute;
    left: 0;
    top: 0.25rem;
    width: 1.25rem;
    height: 1.25rem;
    background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 
        0 0 0 2px rgba(37, 99, 235, 0.1),
        0 2px 6px rgba(37, 99, 235, 0.3);
    z-index: 1;
    transition: all 0.3s ease;
}

.timeline-item:hover .timeline-dot {
    transform: scale(1.1);
    box-shadow: 
        0 0 0 3px rgba(37, 99, 235, 0.15),
        0 4px 10px rgba(37, 99, 235, 0.4);
}

.timeline-content {
    flex: 1;
    background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid #e2e8f0;
    transition: all 0.3s ease;
}

.timeline-item:hover .timeline-content {
    background: #ffffff;
    border-color: #cbd5e1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.timeline-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.timeline-label::before {
    content: '';
    width: 3px;
    height: 3px;
    background: #94a3b8;
    border-radius: 50%;
}

.timeline-value {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 0.25rem;
    line-height: 1.4;
}

.timeline-meta {
    font-size: 0.8125rem;
    color: #475569;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.timeline-meta::before {
    content: '👤';
    font-size: 0.75rem;
    opacity: 0.6;
}

.timeline-meta strong {
    color: #2563eb;
    font-weight: 600;
    transition: color 0.2s ease;
}

.timeline-item:hover .timeline-meta strong {
    color: #1d4ed8;
}

.timeline-meta a,
.timeline-value a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
    display: inline-block;
}

.timeline-meta a:hover,
.timeline-value a:hover {
    color: #1e40af;
    background: #dbeafe;
    transform: translateY(-1px);
}

.timeline-value a {
    margin-right: 0.375rem;
    margin-bottom: 0.25rem;
}

/* Responsive timeline */
@media (max-width: 768px) {
    .post-meta-timeline {
        padding: 1rem;
    }
    
    .timeline-header {
        font-size: 0.9375rem;
        margin-bottom: 0.875rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding-bottom: 0.625rem;
    }
    
    .timeline-category {
        font-size: 0.75rem;
        text-align: left;
    }
    
    .timeline-item {
        padding-left: 1.75rem;
        padding-bottom: 0.875rem;
    }
    
    .timeline-item:not(:last-child)::before {
        left: 0.4375rem;
    }
    
    .timeline-dot {
        width: 1.125rem;
        height: 1.125rem;
        left: -0.0625rem;
    }
    
    .timeline-content {
        padding: 0.625rem 0.875rem;
    }
    
    .timeline-value {
        font-size: 0.875rem;
    }
    
    .timeline-meta {
        font-size: 0.75rem;
    }
}

/* Animation on page load */
@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.post-meta-timeline {
    animation: slideInFromLeft 0.6s ease-out;
}

.timeline-item {
    animation: slideInFromLeft 0.6s ease-out;
    animation-fill-mode: both;
}

.timeline-item:nth-child(2) {
    animation-delay: 0.1s;
}

.timeline-item:nth-child(3) {
    animation-delay: 0.2s;
}

.timeline-item:nth-child(4) {
    animation-delay: 0.3s;
}

.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;
    }
}
