/**
 * WealthFromAI CLS Prevention
 * Cumulative Layout Shift prevention for Core Web Vitals
 * Aspect ratio containers, reserved heights, skeleton loading
 *
 * @package WealthFromAI
 * @version 1.0.0
 */

/* ===========================
   BASE IMAGE RULES
   =========================== */

/* Prevent layout shift from images */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Images with explicit dimensions */
img[width][height] {
    height: auto;
}

/* ===========================
   ASPECT RATIO CONTAINERS
   =========================== */

/* Standard aspect ratios */
.aspect-square { aspect-ratio: 1 / 1; }
.aspect-video { aspect-ratio: 16 / 9; }
.aspect-wide { aspect-ratio: 21 / 9; }
.aspect-featured { aspect-ratio: 1200 / 630; }
.aspect-card { aspect-ratio: 16 / 10; }
.aspect-thumbnail { aspect-ratio: 4 / 3; }
.aspect-portrait { aspect-ratio: 3 / 4; }
.aspect-hero { aspect-ratio: 16 / 7; }

/* Featured image container */
.post-thumbnail,
.featured-image-container {
    aspect-ratio: 1200 / 630;
    background: var(--wfai-surface);
    overflow: hidden;
}

.post-thumbnail img,
.featured-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Card image container */
.card-image,
.post-card-image {
    aspect-ratio: 16 / 9;
    background: var(--wfai-surface);
    overflow: hidden;
}

.card-image img,
.post-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--wfai-duration-normal) var(--wfai-ease-out);
}

/* Square image container */
.image-square {
    aspect-ratio: 1 / 1;
    background: var(--wfai-surface);
    overflow: hidden;
}

.image-square img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ===========================
   HEADER SPACE RESERVATION
   =========================== */

/* Fixed header height */
:root {
    --header-height: 80px;
}

/* Reserve space for fixed header */
.site-header {
    height: var(--header-height);
}

/* Body padding for fixed header */
body {
    padding-top: var(--header-height);
}

/* Admin bar adjustment */
.admin-bar {
    padding-top: calc(var(--header-height) + 32px);
}

@media (max-width: 782px) {
    .admin-bar {
        padding-top: calc(var(--header-height) + 46px);
    }
}

/* ===========================
   AD SPACE RESERVATION
   =========================== */

/* Ad container placeholders - prevents CLS from ads loading */
.ad-container {
    min-height: 90px;
    background: var(--wfai-surface);
}

.ad-container-leaderboard {
    min-height: 90px;
    max-width: 728px;
    margin: 0 auto;
}

.ad-container-sidebar {
    min-height: 250px;
    background: var(--wfai-surface);
}

.ad-container-rectangle {
    min-height: 250px;
    max-width: 300px;
}

.ad-container-skyscraper {
    min-height: 600px;
    max-width: 160px;
}

/* ===========================
   SKELETON LOADING STATES
   =========================== */

/* Base skeleton */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--wfai-surface) 25%,
        rgba(255, 255, 255, 0.05) 50%,
        var(--wfai-surface) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--wfai-radius-md);
}

@keyframes skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Skeleton text line */
.skeleton-text {
    height: 1em;
    margin-bottom: var(--wfai-space-2);
    border-radius: var(--wfai-radius-sm);
}

.skeleton-text-sm {
    height: 0.875em;
    width: 80%;
}

.skeleton-text-lg {
    height: 1.5em;
}

/* Skeleton heading */
.skeleton-heading {
    height: 2em;
    width: 70%;
    margin-bottom: var(--wfai-space-4);
    border-radius: var(--wfai-radius-sm);
}

.skeleton-heading-lg {
    height: 2.5em;
    width: 60%;
}

/* Skeleton paragraph */
.skeleton-paragraph {
    display: flex;
    flex-direction: column;
    gap: var(--wfai-space-2);
}

.skeleton-paragraph .skeleton-text:last-child {
    width: 65%;
}

/* Skeleton image */
.skeleton-image {
    aspect-ratio: 16 / 9;
    border-radius: var(--wfai-radius-lg);
}

.skeleton-image-square {
    aspect-ratio: 1 / 1;
}

.skeleton-image-featured {
    aspect-ratio: 1200 / 630;
}

/* Skeleton avatar */
.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--wfai-radius-full);
}

.skeleton-avatar-sm {
    width: 32px;
    height: 32px;
}

.skeleton-avatar-lg {
    width: 80px;
    height: 80px;
}

/* Skeleton button */
.skeleton-button {
    height: 44px;
    width: 120px;
    border-radius: var(--wfai-radius-md);
}

/* Skeleton badge */
.skeleton-badge {
    height: 24px;
    width: 80px;
    border-radius: var(--wfai-radius-full);
}

/* Skeleton card */
.skeleton-card {
    padding: var(--wfai-space-6);
    background: var(--wfai-card);
    border: 1px solid var(--wfai-border-default);
    border-radius: var(--wfai-radius-xl);
}

.skeleton-card .skeleton-image {
    margin-bottom: var(--wfai-space-4);
}

/* ===========================
   POST CARD SKELETON
   =========================== */

.skeleton-post-card {
    display: flex;
    flex-direction: column;
    background: var(--wfai-card);
    border: 1px solid var(--wfai-border-default);
    border-radius: var(--wfai-radius-xl);
    overflow: hidden;
}

.skeleton-post-card .skeleton-image {
    aspect-ratio: 16 / 9;
    border-radius: 0;
}

.skeleton-post-card-content {
    padding: var(--wfai-space-6);
}

.skeleton-post-card-meta {
    display: flex;
    gap: var(--wfai-space-3);
    margin-bottom: var(--wfai-space-3);
}

.skeleton-post-card-category {
    height: 20px;
    width: 60px;
    border-radius: var(--wfai-radius-sm);
}

.skeleton-post-card-date {
    height: 20px;
    width: 50px;
    border-radius: var(--wfai-radius-sm);
}

.skeleton-post-card-title {
    height: 1.5em;
    width: 90%;
    margin-bottom: var(--wfai-space-2);
    border-radius: var(--wfai-radius-sm);
}

.skeleton-post-card-excerpt {
    height: 1em;
    width: 100%;
    margin-bottom: var(--wfai-space-2);
    border-radius: var(--wfai-radius-sm);
}

.skeleton-post-card-excerpt:last-child {
    width: 70%;
}

/* ===========================
   WIDGET RESERVED HEIGHTS
   =========================== */

/* Sidebar widget minimums */
.widget {
    min-height: 100px;
}

/* Newsletter widget */
.newsletter-widget {
    min-height: 200px;
}

/* Recent posts widget */
.widget_recent_entries {
    min-height: 250px;
}

/* Categories widget */
.widget_categories {
    min-height: 150px;
}

/* ===========================
   FONT LOADING
   =========================== */

/* Prevent FOIT (Flash of Invisible Text) */
.fonts-loading body {
    font-family: system-ui, -apple-system, sans-serif;
}

.fonts-loaded body {
    font-family: var(--wfai-font-body);
}

/* Reserve space for custom fonts */
h1, h2, h3, h4, h5, h6 {
    font-display: swap;
}

/* ===========================
   VIDEO EMBEDS
   =========================== */

/* Responsive video container */
.video-container {
    position: relative;
    aspect-ratio: 16 / 9;
    background: var(--wfai-surface);
    border-radius: var(--wfai-radius-lg);
    overflow: hidden;
}

.video-container iframe,
.video-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* YouTube/Vimeo embed wrapper */
.wp-block-embed__wrapper {
    aspect-ratio: 16 / 9;
    background: var(--wfai-surface);
}

/* ===========================
   FORM ELEMENT HEIGHTS
   =========================== */

/* Input reserved heights */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="tel"],
input[type="number"],
select,
textarea {
    min-height: 44px;
}

/* Button reserved heights */
button,
.wfai-btn,
input[type="submit"],
input[type="button"] {
    min-height: 44px;
}

/* ===========================
   NAVIGATION RESERVED HEIGHTS
   =========================== */

/* Main navigation */
.primary-nav {
    min-height: 48px;
}

/* Mobile navigation */
.mobile-navigation {
    min-height: 100vh;
}

/* Breadcrumbs */
.wfai-breadcrumbs {
    min-height: 48px;
}

/* ===========================
   FOOTER RESERVED HEIGHT
   =========================== */

.site-footer {
    min-height: 300px;
}

/* ===========================
   CONTENT WIDTH CONSTRAINTS
   =========================== */

/* Prevent horizontal overflow */
.single-post-content {
    overflow-x: hidden;
}

.single-post-content img,
.single-post-content iframe,
.single-post-content video,
.single-post-content table {
    max-width: 100%;
}

/* Code blocks horizontal scroll */
.single-post-content pre {
    overflow-x: auto;
    max-width: 100%;
}

/* Tables */
.table-container {
    overflow-x: auto;
    max-width: 100%;
}

/* ===========================
   LAZY LOAD PLACEHOLDERS
   =========================== */

/* Placeholder for lazy loaded images */
img[loading="lazy"] {
    background: var(--wfai-surface);
}

/* Fade in when loaded */
img.lazyloaded {
    animation: fade-in 0.3s ease-out;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ===========================
   PRINT STYLES
   =========================== */

@media print {
    .skeleton,
    .skeleton-card,
    .skeleton-post-card {
        display: none;
    }
}
