@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  :root {
    /* Core UI Colors (HSL format without wrapper) */
    --background: 210 20% 98%;
    --foreground: 222 47% 11%;
    
    --card: 0 0% 100%;
    --card-foreground: 222 47% 11%;
    
    --popover: 0 0% 100%;
    --popover-foreground: 222 47% 11%;
    
    --primary: 221 83% 53%;
    --primary-foreground: 210 40% 98%;
    
    --secondary: 214 32% 91%;
    --secondary-foreground: 222 47% 11%;
    
    --muted: 214 32% 91%;
    --muted-foreground: 215 16% 47%;
    
    --accent: 214 32% 91%;
    --accent-foreground: 222 47% 11%;
    
    --destructive: 0 84% 60%;
    --destructive-foreground: 210 40% 98%;

    --border: 214 32% 91%;
    --input: 214 32% 91%;
    --ring: 221 83% 53%;
    
    --radius: 0.75rem;

    /* Weight Status Colors */
    --status-loss: 142 71% 45%;
    --status-gain: 348 83% 54%;
    --status-flat: 215 16% 47%;
    --status-gold: 43 74% 49%;

    /* Result Card Colors */
    --tdee-bmr: 221 83% 53%;
    --tdee-total: 142 71% 45%;

    /* Enhanced Hero Visibility Tokens */
    --left-pane-bg: 222 47% 4%;
    --left-pane-text: 0 0% 100%;
    --button-prominent: 188 86% 53%;
    
    /* Custom Navy Tokens */
    --navy-bg: 222 47% 11%;
    --navy-text: 0 0% 100%;
    
    /* Text Shadow Variables */
    --text-shadow-base: 0 2px 4px rgba(0,0,0,0.5);
    --text-shadow-strong: 0 4px 12px rgba(0,0,0,0.8), 0 2px 4px rgba(0,0,0,0.6);

    /* Responsive Spacing & Layout Tokens */
    --spacing-xs: 0.5rem;    /* 8px */
    --spacing-sm: 1rem;      /* 16px */
    --spacing-md: 1.5rem;    /* 24px */
    --spacing-lg: 2.5rem;    /* 40px */
    --spacing-xl: 4rem;      /* 64px */
    --spacing-2xl: 6rem;     /* 96px */
    
    --container-width: 80rem; /* 1280px */
    --content-width: 65ch;
  }

  .dark {
    --background: 222 47% 11%;
    --foreground: 210 40% 98%;
    
    --card: 222 47% 11%;
    --card-foreground: 210 40% 98%;
    
    --popover: 222 47% 11%;
    --popover-foreground: 210 40% 98%;
    
    --primary: 217 91% 60%;
    --primary-foreground: 222 47% 11%;
    
    --secondary: 217 32% 17%;
    --secondary-foreground: 210 40% 98%;
    
    --muted: 217 32% 17%;
    --muted-foreground: 215 20% 60%;
    
    --accent: 217 32% 17%;
    --accent-foreground: 210 40% 98%;
    
    --destructive: 0 62% 30%;
    --destructive-foreground: 210 40% 98%;

    --border: 217 32% 17%;
    --input: 217 32% 17%;
    --ring: 217 91% 60%;

    --status-loss: 142 60% 45%;
    --status-gain: 348 70% 54%;
    --status-flat: 215 20% 65%;
    --status-gold: 43 80% 55%;

    --tdee-bmr: 217 91% 60%;
    --tdee-total: 142 71% 50%;

    --left-pane-bg: 222 47% 4%;
    --left-pane-text: 0 0% 100%;
    --button-prominent: 188 86% 53%;
    
    /* Custom Navy Tokens */
    --navy-bg: 222 47% 11%;
    --navy-text: 0 0% 100%;
  }

  * {
    border-color: hsl(var(--border));
  }

  html {
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
  }

  body {
    font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    overflow-x: hidden;
    line-height: 1.625;
  }

  h1, h2, h3, h4, h5, h6 {
    font-family: "Outfit", sans-serif;
    text-wrap: balance;
    letter-spacing: -0.02em;
    font-weight: 700;
  }
}

@layer utilities {
  .form-label-accessible { color: #4A5568; }
  .body-text-accessible { color: #374151; }

  .text-loss { color: hsl(var(--status-loss)); }
  .bg-loss { background-color: hsl(var(--status-loss)); }
  .border-loss { border-color: hsl(var(--status-loss)); }
  
  .text-gain { color: hsl(var(--status-gain)); }
  .bg-gain { background-color: hsl(var(--status-gain)); }
  .border-gain { border-color: hsl(var(--status-gain)); }
  
  .text-flat { color: hsl(var(--status-flat)); }
  .bg-flat { background-color: hsl(var(--status-flat)); }
  .border-flat { border-color: hsl(var(--status-flat)); }
  
  .text-gold { color: hsl(var(--status-gold)); }
  .bg-gold { background-color: hsl(var(--status-gold)); }
  .border-gold { border-color: hsl(var(--status-gold)); }

  /* Custom Text Shadow Utilities */
  .text-shadow { text-shadow: var(--text-shadow-base); }
  .text-shadow-strong { text-shadow: var(--text-shadow-strong); }

  .skeleton-shimmer {
    @apply bg-muted;
    background-image: linear-gradient(to right, transparent 0%, rgba(0,0,0,0.05) 20%, transparent 40%, transparent 100%);
    background-repeat: no-repeat;
    background-size: 1000px 100%;
    animation: shimmer 2s infinite linear forwards;
  }
  .dark .skeleton-shimmer {
    background-image: linear-gradient(to right, transparent 0%, rgba(255,255,255,0.05) 20%, transparent 40%, transparent 100%);
  }
}

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

@layer components {
  /* Validation Error Styling */
  .input-error {
    @apply border-destructive bg-destructive/10 focus-visible:ring-destructive !important;
  }
  
  .error-text {
    @apply text-sm font-bold text-destructive mt-1.5 block;
  }
  
  .error-container {
    @apply mt-1;
  }

  /* Optimized Layout Containers */
  .responsive-container {
    @apply max-w-[var(--container-width)] mx-auto px-4 sm:px-6 lg:px-8 w-full pb-0;
  }

  .content-section {
    @apply pt-6 pb-2 lg:pt-8 lg:pb-4;
  }

  /* Enhanced Hero Visibility Components - Compact & Balanced */
  .left-pane-container {
    background-color: hsla(var(--left-pane-bg), 0.85);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    @apply rounded-3xl p-6 sm:p-8 border border-white/10 shadow-2xl flex flex-col items-start relative overflow-hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  }

  .left-pane-badge {
    @apply inline-flex items-center gap-2 px-3 py-1.5 rounded-full bg-cyan-500/20 border border-cyan-400/40 text-cyan-100 text-xs font-extrabold tracking-wider uppercase mb-4 shadow-sm backdrop-blur-md;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  }

  .left-pane-title {
    color: hsl(var(--left-pane-text));
    @apply text-3xl md:text-4xl lg:text-5xl font-extrabold leading-tight mb-4 tracking-tight;
    text-shadow: 0 4px 16px rgba(0,0,0,0.7), 0 2px 4px rgba(0,0,0,0.5);
  }

  .left-pane-description {
    @apply text-base md:text-lg text-gray-900 font-semibold leading-relaxed mb-6 max-w-xl bg-white/20 px-5 py-4 rounded-xl backdrop-blur-sm;
  }

  .left-pane-button {
    background-color: hsl(var(--button-prominent));
    @apply inline-flex items-center justify-center px-6 py-3 text-slate-950 font-extrabold rounded-xl hover:-translate-y-1 active:scale-[0.98] transition-all duration-300;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.4);
  }
  
  .left-pane-button:hover {
    box-shadow: 0 12px 30px -8px hsl(var(--button-prominent));
    filter: brightness(1.1);
  }

  /* Data Carryover Indicator */
  .data-carryover-badge {
    @apply inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-muted/60 text-muted-foreground text-xs font-bold border border-border/50 transition-all duration-300;
  }

  /* Email Link Style */
  .email-link {
    color: hsl(var(--primary));
    text-decoration: underline;
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
    @apply transition-all duration-200 cursor-pointer focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-[hsl(var(--ring))] rounded-sm;
  }

  .email-link:hover {
    opacity: 0.75;
    filter: brightness(0.9);
  }

  .email-link:active {
    @apply scale-[0.98];
  }

  /* Educational Components */
  .educational-content-container {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
    overflow: visible !important;
  }

  .math-block {
    @apply font-mono text-sm md:text-base bg-muted/40 p-5 rounded-xl border border-border text-foreground overflow-x-auto my-4;
  }

  .legal-section {
    @apply max-w-[var(--content-width)] mx-auto py-8 md:py-12;
  }

  .legal-section h2 {
    @apply text-2xl md:text-3xl font-bold text-foreground mb-6 mt-12 first:mt-0;
  }

  .legal-section h3 {
    @apply text-xl font-semibold text-foreground mb-4 mt-8;
  }

  .legal-section p {
    @apply text-base body-text-accessible leading-relaxed mb-6;
  }

  .legal-section ul {
    @apply list-disc list-outside ml-6 mb-6 body-text-accessible space-y-2;
  }

  .legal-section li {
    @apply text-base leading-relaxed;
  }

  /* FAQ and Accordion Spacing Optimization */
  .accordion {
    @apply mb-0 pb-0 !important;
  }

  /* Global Accordion Compact Sizing */
  [data-radix-accordion-item],
  .accordion-item {
    min-height: 0 !important;
    @apply mb-0 pb-0 border-b-0;
  }

  [data-radix-accordion-trigger] {
    min-height: 0 !important;
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
  }

  [data-radix-accordion-content] > div {
    padding-bottom: 0.75rem !important;
    padding-top: 0 !important;
  }

  section:has([role="region"]),
  section:has(.accordion) {
    @apply mb-4 md:mb-6 pb-0 !important;
  }

  [role="region"], 
  .accordion-item:last-child {
    @apply mb-0 pb-0 border-b-0;
  }

  [data-state="open"] {
    @apply mb-0 pb-0;
  }

  /* Aggressively reduce excessive bottom spacing on last sections */
  section:last-of-type {
    @apply mb-2 md:mb-4 pb-0 !important;
  }

  /* Tighten spacing before footer */
  main {
    @apply pb-0 mb-0 !important;
  }
  
  /* Target any massive margin-tops on the last elements (like ads or FAQ wrappers) */
  main .mt-16:last-child, 
  main .mt-24:last-child,
  main .lg\:space-y-24 > :last-child,
  main .space-y-16 > :last-child {
    @apply mb-0 pb-0 !important;
  }

  /* Population Caveat Styling */
  .caveat-info-icon {
    @apply body-text-accessible hover:text-amber-600 dark:hover:text-amber-400 transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-full inline-flex items-center justify-center;
  }
  
  .caveat-popover-content {
    @apply w-80 p-4 text-sm leading-relaxed shadow-xl border-amber-200/50 bg-amber-50/95 dark:bg-amber-950/90 dark:border-amber-900/50 backdrop-blur-md z-50;
  }
  
  .caveat-popover-content strong {
    @apply text-amber-900 dark:text-amber-200 font-bold;
  }
  
  .caveat-popover-content p {
    @apply text-amber-800 dark:text-amber-300/90 m-0;
  }
  
  .caveat-badge {
    @apply absolute -top-1 -right-1 flex h-2.5 w-2.5;
  }
  
  .caveat-badge-ping {
    @apply animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75;
  }
  
  .caveat-badge-dot {
    @apply relative inline-flex rounded-full h-2.5 w-2.5 bg-amber-500;
  }
}

@media print {
  header, footer, nav, .ad-placeholder, iframe, .sidebar, 
  .mobile-ad-banner, .whats-next-link, .whats-next-arrow, 
  .next-step-card, button, [role="button"] {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 12pt !important;
    font-family: Arial, Helvetica, sans-serif !important;
  }

  @page {
    margin: 0.75in;
    size: auto;
  }

  .card, .p-6, .p-8, .bg-card, .bg-muted, .border, .rounded-xl, .rounded-2xl {
    page-break-inside: avoid;
    border: 1px solid #ddd !important;
    box-shadow: none !important;
    background: transparent !important;
    color: black !important;
  }

  * {
    color: black !important;
    text-shadow: none !important;
    background-color: transparent !important;
  }

  h1, h2, h3, h4 {
    page-break-after: avoid;
    page-break-inside: avoid;
    color: black !important;
  }
}