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

@layer base {
  * {
    font-display: swap;
  }

  :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%;

    /* Obesity Severity Colors */
    --bmi-obese-class-1: 38 92% 50%;
    --bmi-obese-class-2: 25 95% 53%;
    --bmi-obese-class-3: 0 84% 60%;

    /* 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%;

    /* Calculator Integration Tokens */
    --gradient-start: 208 52% 21%;
    /* #1a3a52 equivalent */
    --gradient-end: 205 46% 33%;
    /* #2d5a7b equivalent */
    --calculator-box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
    --calculator-spacing: 1.5rem;

    /* 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;

    /* Page Gradient Tokens */
    --page-grad-top: 210 60% 20%;
    --page-grad-bottom: 214 30% 45%;

    /* Global Hero & Card Styling Tokens */
    --hero-gradient-start: #0B1120;
    --hero-gradient-end: #1A2744;
    --background-base: #F8F9FB;
    --card-bg: rgba(255, 255, 255, 0.92);
    --card-border: rgba(255, 255, 255, 0.6);
    --card-shadow: 0 2px 20px rgba(11, 17, 32, 0.06);

    /* ── Premium Platform Tokens ── */
    --trust-bg: 217 50% 97%;
    --trust-border: 217 70% 88%;
    --trust-text: 217 70% 35%;

    --hero-bg-from: #09111F;
    --hero-bg-to: #0D1B3E;

    --result-card-border: rgba(6, 182, 212, 0.22);
    --result-card-shadow: 0 8px 40px rgba(6, 182, 212, 0.10);

    --transition-smooth: 0.28s cubic-bezier(0.4, 0, 0.2, 1);

    --signal-badge-bg: rgba(6, 182, 212, 0.08);
    --signal-badge-border: rgba(6, 182, 212, 0.22);
  }

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

    /* Obesity Severity Colors */
    --bmi-obese-class-1: 38 92% 50%;
    --bmi-obese-class-2: 25 95% 53%;
    --bmi-obese-class-3: 0 84% 60%;

    --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%;

    /* Calculator Integration Tokens */
    --gradient-start: 222 47% 4%;
    --gradient-end: 222 47% 11%;
    --calculator-box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);

    /* Page Gradient Tokens */
    --page-grad-top: 215 40% 15%;
    --page-grad-bottom: 215 25% 30%;

    /* ── Dark Mode Premium Platform Tokens ── */
    --trust-bg: 217 40% 12%;
    --trust-border: 217 50% 22%;
    --trust-text: 217 70% 65%;
    --signal-badge-bg: rgba(6, 182, 212, 0.12);
    --signal-badge-border: rgba(6, 182, 212, 0.25);
  }

  * {
    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;
  }
}

@media (min-width: 768px) {
  :root {
    --calculator-spacing: 2.5rem;
  }
}

@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);
  }

  /* Universal Reusable Gradient Background Utility */
  .page-hero-gradient {
    background: linear-gradient(180deg, #06152D 0%, hsl(var(--background)) 100%);
    @apply text-white;
  }

  /* Solid Page Background Utility */
  .solid-page-background {
    background-color: #4A5F7F;
    @apply text-white;
  }

  .dark .solid-page-background {
    background-color: #334155;
    @apply text-white;
  }

  /* Gradient Page Background Utility */
  .gradient-page-background {
    background: linear-gradient(180deg, hsl(var(--page-grad-top)) 0%, hsl(var(--page-grad-bottom)) 100%);
    @apply text-white;
  }

  .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 {

  /* Calculator Page Layout System */
  .calculator-page-container {
    @apply w-full min-h-screen bg-background flex flex-col;
  }

  .calculator-page-gradient {
    background: linear-gradient(180deg, hsl(var(--gradient-start)) 0%, hsl(var(--gradient-end)) 100%);
    @apply relative w-full pt-24 pb-32 md:pt-32 md:pb-40 overflow-hidden;
  }

  .calculator-page-header {
    @apply max-w-3xl mx-auto flex flex-col items-center text-center gap-4 relative z-10 px-4 sm:px-6 lg:px-8 text-white;
  }

  .calculator-box-wrapper {
    @apply max-w-4xl mx-auto w-full bg-card rounded-3xl border border-border relative z-20 -mt-20 md:-mt-32 mb-12 flex flex-col;
    box-shadow: var(--calculator-box-shadow);
    padding: var(--calculator-spacing);
  }

  /* Global Hero & Card Styling Utilities */
  .hero-gradient {
    background: linear-gradient(135deg, var(--hero-gradient-start) 0%, var(--hero-gradient-end) 100%) !important;
  }

  .gradient-bg {
    background: linear-gradient(135deg, rgba(11, 17, 32, 0.08) 0%, rgba(26, 39, 68, 0.08) 100%), var(--background-base) !important;
  }

  .card-styled {
    background: var(--card-bg) !important;
    border: 1px solid var(--card-border) !important;
    box-shadow: var(--card-shadow) !important;
  }

  /* Share Button */
  .share-btn {
    @apply flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold rounded-lg border border-border bg-background hover:bg-muted transition-colors cursor-pointer;
  }

  /* Secondary Outline Button */
  .btn-outline-secondary {
    @apply inline-flex items-center gap-2 px-5 py-2.5 rounded-lg border-2 border-primary text-primary bg-transparent font-semibold text-sm hover:bg-primary hover:text-primary-foreground transition-colors duration-200;
  }

  /* 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;
  }

  /* Highlighted callout box inside legal/disclaimer pages */
  .disclaimer-highlight {
    @apply bg-amber-50 dark:bg-amber-900/20 border-l-4 border-amber-500 rounded-r-xl p-6 my-8;
  }

  /* 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;
  }

  /* BMI Badges */
  .bmi-underweight {
    @apply bg-blue-100 text-blue-800 border-blue-200 dark:bg-blue-900/30 dark:text-blue-300 dark:border-blue-800;
  }

  .bmi-normal {
    @apply bg-green-100 text-green-800 border-green-200 dark:bg-green-900/30 dark:text-green-300 dark:border-green-800;
  }

  .bmi-overweight {
    @apply bg-amber-100 text-amber-800 border-amber-200 dark:bg-amber-900/30 dark:text-amber-300 dark:border-amber-800;
  }

  .bmi-obese {
    @apply bg-red-100 text-red-800 border-red-200 dark:bg-red-900/30 dark:text-red-300 dark:border-red-800;
  }

  /* Obesity Severity Classes */
  .bmi-obese-class-1 {
    @apply bg-[hsl(var(--bmi-obese-class-1)_/_0.15)] text-[hsl(var(--bmi-obese-class-1))] border-[hsl(var(--bmi-obese-class-1)_/_0.3)];
  }

  .bmi-obese-class-2 {
    @apply bg-[hsl(var(--bmi-obese-class-2)_/_0.15)] text-[hsl(var(--bmi-obese-class-2))] border-[hsl(var(--bmi-obese-class-2)_/_0.3)];
  }

  .bmi-obese-class-3 {
    @apply bg-[hsl(var(--bmi-obese-class-3)_/_0.15)] text-[hsl(var(--bmi-obese-class-3))] border-[hsl(var(--bmi-obese-class-3)_/_0.3)];
  }
}

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

/* ── Premium Platform Utilities ── */
.scroll-mt-results {
  scroll-margin-top: 80px;
}

.trust-bar-scroll {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.trust-bar-scroll::-webkit-scrollbar {
  display: none;
}

@keyframes resultReveal {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-reveal {
  animation: resultReveal 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}