/* Critical CSS - Above the fold styles for instant paint */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { 
    margin: 0; 
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-display: swap;
}

/* Weather widget styles to prevent CLS */
.weather-widget {
    min-height: 120px;
    width: 100%;
    contain: layout style;
    transform: translateZ(0); /* Force GPU layer */
}

/* Trust elements styling */
.trust-elements {
    min-height: 100px;
    contain: layout style;
    margin-bottom: 1rem;
}

.privacy-notice {
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
}

.privacy-link {
    color: #4a5568;
    text-decoration: none;
    font-weight: 500;
}

.privacy-link:hover {
    color: #2d3748;
    text-decoration: underline;
}

/* Breathing controls styling */
.breathing-controls {
    min-height: 80px;
    contain: layout style;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
}

.breathing-btn {
    background: linear-gradient(135deg, #4a5568, #2d3748);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.breathing-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.breath-icon {
    font-size: 18px;
}

/* Loading placeholders to prevent CLS */
.content-placeholder {
    height: var(--expected-height, 200px);
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.1) 25%,
        rgba(255, 255, 255, 0.2) 50%,
        rgba(255, 255, 255, 0.1) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}

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

/* EMERGENCY CLS PREVENTION - CRITICAL FIXES */
.welcome-section,
.main-content,
.weather-section {
    min-height: 400px; /* Reserve space */
    contain: layout style;
    transform: translateZ(0); /* Force layer */
}

.weather-widget,
.analytics-widget,
.recommendation-widget {
    min-height: 120px;
    max-height: 120px;
    contain: layout style paint size;
    will-change: auto; /* Remove after loading */
}

/* Reserve space for hero/banner */
.hero { 
    min-height: 280px; 
}

/* Images with known aspect ratio - responsive-safe */
img[width][height] { 
    height: auto; 
    max-width: 100%;
}

/* Modern aspect ratio for cards */
.card-thumb { 
    aspect-ratio: 16/9; 
    object-fit: cover; 
    display: block;
    width: 100%;
}

/* Widget shells with content visibility */
.widget-shell {
    content-visibility: auto;
    contain-intrinsic-size: 200px;
}

/* Shell reserves space before data arrives */
.widget-shell.weather {
  min-height: 150px;
  contain: layout paint style;
  content-visibility: auto;
  contain-intrinsic-size: 150px;
}

/* Weather card CLS prevention */
.weather-card {
  min-height: 160px;
  contain: layout paint style;
  content-visibility: auto;
  contain-intrinsic-size: 160px;
}

/* Prediction slot CLS prevention */
.prediction-slot {
  min-height: 48px;
  contain: layout paint style;
  content-visibility: auto;
  contain-intrinsic-size: 48px;
}

/* Image CLS prevention */
img {
  width: auto;
  height: auto;
  max-width: 100%;
}

/* Specific image sizing for common elements */
img[src*="sun.svg"], img[src*="weather"], img[src*="icon"], .weather-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

/* Weather widget CLS prevention */
#weather-widget {
    min-height: 160px;
    contain: layout paint style;
    content-visibility: auto;
    contain-intrinsic-size: 160px;
}

/* Weather content CLS prevention */
#weather-temp {
    min-width: 80px;
    text-align: center;
}

#weather-desc {
    min-height: 16px;
    text-align: center;
}

/* Dynamic widget slots - prevent CLS */
.weather-slot {
    min-height: 160px;
    contain: layout paint style;
    content-visibility: auto;
    contain-intrinsic-size: 160px;
}

.header-slot {
    min-height: 64px;
    contain: layout paint style;
    content-visibility: auto;
    contain-intrinsic-size: 64px;
}

.prediction-slot {
    min-height: 48px;
    contain: layout paint style;
    content-visibility: auto;
    contain-intrinsic-size: 48px;
}

/* Z-index layering to prevent overlay collisions */
.weather-card {
    z-index: 10;
    position: relative;
}

.floating-action-button {
    z-index: 40;
}

.audio-control-panel {
    z-index: 30;
}

.error-feedback-button {
    z-index: 20;
}

.install-button {
    z-index: 50;
}

.error-dashboard {
    z-index: 60;
}

/* Ensure weather card doesn't overlap other elements */
.weather-card {
    margin-bottom: 1rem;
    max-width: 300px;
}

/* Avoid viewport toolbar jumps */
:root, .app-root {
  min-height: 100dvh;
}

/* Visually hidden but accessible to screen readers */
.visually-hidden, .sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Header navigation styling */
.site-header nav a { 
  text-decoration: none; 
  color: inherit; 
  padding: 0.5rem 0.75rem; 
}

.site-header nav a:focus-visible { 
  outline: 2px solid currentColor; 
  outline-offset: 2px; 
}

/* Hero images with proper loading attributes */
.hero img {
    width: 100%;
    height: auto;
    object-fit: cover;
    object-position: center;
}

/* Skeleton loaders for dynamic content */
.skeleton-loader {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

/* Skeleton loaders to prevent CLS */
.weather-widget-placeholder,
.analytics-widget-placeholder,
.recommendation-widget-placeholder {
    min-height: 150px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 8px;
    margin: 8px 0;
}

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

/* Font loading optimization - using system fonts for now */
@font-face {
    font-family: 'Inter';
    font-display: swap;
    src: local('Inter'), local('Inter-Regular'), local('system-ui'), local('-apple-system'), local('BlinkMacSystemFont'), local('Segoe UI'), local('Roboto'), local('Helvetica Neue'), local('Arial'), sans-serif;
}

/* Prevent layout shifts from dynamic content */
.dynamic-content {
    min-height: 200px;
    contain: layout style;
}

/* Reserve space for theme transitions */
.theme-transition {
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Emergency loading states */
.loading-content {
    height: var(--content-height, 200px);
    background: linear-gradient(
        90deg, 
        rgba(200,200,200,0.1) 25%, 
        rgba(200,200,200,0.2) 50%, 
        rgba(200,200,200,0.1) 75%
    );
    background-size: 400% 100%;
    animation: emergency-shimmer 1s infinite linear;
    border-radius: 4px;
}

@keyframes emergency-shimmer {
    0% { background-position: -400% 0; }
    100% { background-position: 400% 0; }
}

/* Prevent font loading shifts */
* {
    font-display: swap;
}

/* Critical performance boost */
.heavy-animation {
    animation-duration: 0.1s; /* Reduce all animations */
}

.disable-animations * {
    animation-duration: 0s !important;
    transition-duration: 0s !important;
}

/* Emergency performance mode */
.emergency-mode {
    contain: layout style paint;
}

.emergency-mode * {
    will-change: auto;
    transform: translateZ(0);
}

/* Critical layout classes */
.container { width: 100%; margin-left: auto; margin-right: auto; padding-left: 1rem; padding-right: 1rem; }
.mx-auto { margin-left: auto; margin-right: auto; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.max-w-7xl { max-width: 80rem; }
.min-h-screen { min-height: 100vh; }
.bg-linen-white { background-color: #FDFBF5; }
.text-charcoal { color: #333333; }
.font-inter { font-family: 'Inter', sans-serif; }

/* Critical animations */
.fade-in { animation: fadeIn 0.5s ease-in-out; }
@keyframes fadeIn { 
    from { opacity: 0; transform: translateY(20px); } 
    to { opacity: 1; transform: translateY(0); } 
}

/* Prevent layout shift */
.loading { display: none; }
img { max-width: 100%; height: auto; }

/* Critical button styles */
button { 
    cursor: pointer; 
    border: none; 
    background: none; 
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

/* Critical responsive utilities */
@media (min-width: 640px) {
    .sm\:px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
}
@media (min-width: 1024px) {
    .lg\:px-8 { padding-left: 2rem; padding-right: 2rem; }
}
