/* Custom Styling & Enhancements for Age Calculator */

/* Google Fonts loaded via parallel <link> in HTML head for Core Web Vitals optimization */

:root {
    --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
    --accent-glow: rgba(99, 102, 241, 0.25);

    /* Brand Primary & Accents */
    --color-primary: #6366f1;
    --color-primary-hover: #4f46e5;
    --color-primary-dark: #4338ca;
    --color-secondary: #a855f7;
    --color-accent: #ec4899;
    --color-primary-rgb: 99, 102, 241;

    /* Base & Surface Design Tokens (Light) */
    --color-bg: #f8fafc;
    --color-surface: rgba(255, 255, 255, 0.85);
    --color-surface-solid: #ffffff;
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-border: rgba(226, 232, 240, 0.8);

    /* Semantic Feedback Tokens */
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #f43f5e;
    --color-info: #3b82f6;

    /* Dimensions & Touch Controls */
    --min-touch-target: 44px;
    --input-min-height: 46px;
    --button-min-height: 44px;
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
}

.dark {
    --color-bg: #020617;
    --color-surface: rgba(15, 23, 42, 0.78);
    --color-surface-solid: #0f172a;
    --color-text: #f8fafc;
    --color-text-muted: #94a3b8;
    --color-border: rgba(255, 255, 255, 0.08);
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    font-size: 16px;
}

* {
    font-family: var(--font-main);
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

.font-mono {
    font-family: var(--font-mono);
    font-feature-settings: "tnum" 1, "zero" 1;
    font-variant-numeric: tabular-nums;
}

/* Typography Foundation & Spatial Rhythm */
body {
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    width: 100%;
    font-size: 1rem;
    line-height: 1.6;
    letter-spacing: -0.011em;
    text-rendering: optimizeLegibility;
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
}

p {
    line-height: 1.65;
}

h1, h2, h3, h4, h5, h6 {
    text-wrap: balance;
    letter-spacing: -0.02em;
}

h1 {
    letter-spacing: -0.025em;
    line-height: 1.22;
}

h2 {
    letter-spacing: -0.02em;
    line-height: 1.3;
}

h3 {
    letter-spacing: -0.015em;
    line-height: 1.35;
}

/* Accessibility Screen Reader Only & Skip Link Utilities */
.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;
}

.focus\:not-sr-only:focus,
.focus\:not-sr-only:focus-visible {
    position: fixed !important;
    width: auto !important;
    height: auto !important;
    padding: 0.75rem 1.25rem !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
    z-index: 9999 !important;
}

/* Accessibility Focus & Touch States */
button, 
input, 
select, 
a {
    touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 3px solid #6366f1 !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.25) !important;
}

/* Respect Reduced Motion Preferences */
@media (prefers-reduced-motion: reduce) {
    *, ::before, ::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Mobile Scrollbar Utility */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}
.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

/* Glassmorphism Cards */
.glass-card {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.05);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.dark .glass-card {
    background: rgba(15, 23, 42, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 24px -2px rgba(0, 0, 0, 0.35);
}

.glass-card-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px -4px rgba(99, 102, 241, 0.15);
}

.dark .glass-card-hover:hover {
    box-shadow: 0 12px 28px -4px rgba(99, 102, 241, 0.22);
}

/* Gradient Text */
.gradient-text {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Dynamic Gradient Accent Backgrounds */
.gradient-bg {
    background: var(--primary-gradient);
}

.gradient-border {
    position: relative;
    border-radius: 1.25rem;
}
.gradient-border::before {
    content: '';
    position: absolute;
    inset: -2px;
    background: var(--primary-gradient);
    border-radius: calc(1.25rem + 2px);
    z-index: -1;
    opacity: 0.7;
    transition: opacity 0.3s ease;
}
.gradient-border:hover::before {
    opacity: 1;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.4);
    border-radius: 9999px;
}

.dark ::-webkit-scrollbar-thumb {
    background: rgba(75, 85, 99, 0.5);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(107, 114, 128, 0.8);
}

/* Subtle Floating Animations */
@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-6px);
    }
}

.animate-float {
    animation: float 4s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% {
        box-shadow: 0 0 15px rgba(99, 102, 241, 0.2);
    }
    50% {
        box-shadow: 0 0 30px rgba(168, 85, 247, 0.4);
    }
}

.glow-effect {
    animation: pulseGlow 3s infinite ease-in-out;
}

/* Custom Date Picker Styling */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    filter: invert(0.4);
    transition: filter 0.2s ease;
}

.dark input[type="date"]::-webkit-calendar-picker-indicator,
.dark input[type="time"]::-webkit-calendar-picker-indicator {
    filter: invert(0.85);
}

/* Animated Number Ticker Transition */
.number-tick {
    display: inline-block;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Custom Tab Styling - Responsive Wrapping Mobile Layout */
.secondary-tab-nav {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: stretch !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow: visible !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
    gap: 0.375rem !important;
    padding: 0.375rem !important;
}

.tab-btn {
    flex: 1 1 calc(50% - 0.375rem) !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    padding: 0.45rem 0.5rem !important;
    font-size: 0.75rem !important;
    line-height: 1.25 !important;
    gap: 0.375rem !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.tab-btn span {
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
    text-overflow: clip !important;
    overflow: visible !important;
    text-align: center !important;
    display: inline-block !important;
}

.tab-btn i,
.tab-btn svg {
    flex-shrink: 0 !important;
    width: 1rem !important;
    height: 1rem !important;
}

.tab-btn.active {
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

/* 414px - 767px: Wraps naturally into approximately 2 rows (3 tabs per row) */
@media (min-width: 414px) and (max-width: 767px) {
    .secondary-tab-nav {
        gap: 0.5rem !important;
        padding: 0.5rem !important;
    }
    .secondary-tab-nav .tab-btn {
        flex: 1 1 calc(33.333% - 0.5rem) !important;
        padding: 0.5rem 0.5rem !important;
        font-size: 0.75rem !important;
    }
}

/* 768px and up: Tablet and Desktop single-row SaaS navigation */
@media (min-width: 768px) {
    .secondary-tab-nav {
        flex-wrap: nowrap !important;
        align-items: center !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        gap: 0.5rem !important;
        padding: 0.375rem 0.5rem !important;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .secondary-tab-nav::-webkit-scrollbar {
        display: none;
    }
    .secondary-tab-nav .tab-btn {
        flex: 0 0 auto !important;
        white-space: nowrap !important;
        padding: 0.5rem 0.875rem !important;
        font-size: 0.8125rem !important;
    }
    .secondary-tab-nav .tab-btn span {
        white-space: nowrap !important;
    }
}

/* Top Navigation & Dropdown Styling */
.top-nav-item {
    position: relative;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.top-nav-item.active {
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    color: #ffffff !important;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.25);
}

.top-nav-item.active i {
    color: #ffffff !important;
}

.dropdown-menu {
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    transform-origin: top;
}

/* Dropdown Keyboard, Touch & Hover Support */
.group:hover .dropdown-menu,
.group.is-open .dropdown-menu,
.group:focus-within .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.mobile-nav-link {
    min-height: 46px;
    font-size: 0.9375rem;
}

.mobile-nav-link.active {
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.mobile-nav-link.active i {
    color: #ffffff !important;
}

.mobile-tab-link {
    min-height: 40px;
}

.mobile-tab-link.active {
    background: rgba(99, 102, 241, 0.15);
    color: #6366f1 !important;
    font-weight: 700;
}

.dark .mobile-tab-link.active {
    background: rgba(99, 102, 241, 0.25);
    color: #a5b4fc !important;
}

@keyframes fadeInMenu {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fadeIn {
    animation: fadeInMenu 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Form Controls & Universal iOS Auto-Zoom Prevention */
label {
    letter-spacing: 0.025em;
}

input[type="date"],
input[type="time"],
input[type="number"],
input[type="text"],
input[type="email"],
select,
textarea {
    font-size: 16px !important; /* Prevents auto-zoom on iOS Safari across all viewport sizes and orientations */
    min-height: var(--input-min-height, 46px);
    line-height: 1.5;
}

/* Mobile Touch Target & iOS Form Optimizations */
@media (max-width: 640px) {
    html {
        font-size: 15.5px;
    }
    body {
        line-height: 1.62;
    }
    h1 {
        font-size: 1.65rem !important;
        line-height: 1.25 !important;
    }
    h2 {
        font-size: 1.35rem !important;
        line-height: 1.3 !important;
    }
    input[type="date"],
    input[type="time"],
    input[type="number"],
    input[type="text"],
    input[type="email"],
    select {
        font-size: 16px !important; /* Prevents auto-zoom on iOS Safari */
        min-height: 46px;
    }
    
    .glass-card {
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }
}

/* Touch Targets & Minimum Hit Box */
#themeToggle,
#mobileMenuToggle,
.modal-close-btn {
    min-width: var(--min-touch-target, 44px);
    min-height: var(--min-touch-target, 44px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.preset-btn,
#faqExpandAllBtn {
    min-height: 38px;
}

footer button[onclick*="openLegalModal"] {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}

/* Ensure no text selection interference on tap buttons */
.preset-btn,
.tab-btn,
.bmi-gender-btn {
    user-select: none;
    -webkit-user-select: none;
}

/* Print Styling for Export Card */
@media print {
    body {
        background: #ffffff !important;
        color: #000000 !important;
    }
    .no-print {
        display: none !important;
    }
    .glass-card {
        box-shadow: none !important;
        border: 1px solid #e5e7eb !important;
    }
}

/* FAQ Accordion Component Styling */
.faq-accordion-panel {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.faq-accordion-panel.open {
    grid-template-rows: 1fr;
}

.faq-chevron {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.faq-accordion-btn[aria-expanded="true"] .faq-chevron {
    transform: rotate(180deg);
}

.faq-accordion-item {
    transition: border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
}

.faq-accordion-item.is-open {
    border-color: rgba(139, 92, 246, 0.5) !important;
    background: rgba(139, 92, 246, 0.04) !important;
    box-shadow: 0 4px 20px -2px rgba(139, 92, 246, 0.12);
}

.dark .faq-accordion-item.is-open {
    border-color: rgba(168, 85, 247, 0.45) !important;
    background: rgba(139, 92, 246, 0.08) !important;
    box-shadow: 0 4px 24px -2px rgba(139, 92, 246, 0.2);
}



/* Core Web Vitals: Off-screen Content Visibility & GPU Layer Promotion */
#faqSection,
footer,
#relatedCalcsSection,
.related-calculators-section {
    content-visibility: auto;
    contain-intrinsic-size: 1px 500px;
}

.bg-blur-sphere {
    transform: translate3d(0, 0, 0);
    will-change: transform;
    contain: strict;
    clip-path: inset(0);
    overflow: hidden;
    max-width: 100vw;
}