/* Mortgage Calculator NZ - Responsive Styles */
/* Mobile-first breakpoint system for NZ devices */

/* ===== BREAKPOINT SYSTEM ===== */
/*
   Mobile: 0-639px (default - mobile first)
   Tablet: 640px-767px
   Desktop Small: 768px-1023px
   Desktop Large: 1024px+
*/

/* ===== MOBILE STYLES (Default - 0-639px) ===== */
/* These are already handled in the main styles.css */

/* ===== TABLET STYLES (640px and up) ===== */
@media (min-width: 640px) {
    /* Typography adjustments */
    html {
        font-size: 16px;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.75rem;
    }

    /* Header */
    .header-content {
        gap: var(--spacing-xl);
    }

    header h1 {
        font-size: 1.8rem;
    }

    nav ul {
        gap: 12px;
    }

    nav a {
        font-size: var(--font-size-base);
        padding: 6px 12px;
    }

    /* Hero Section */
    .hero {
        padding: var(--spacing-3xl) var(--spacing-lg);
    }

    .hero h2 {
        font-size: 2rem;
    }

    /* Calculator Card */
    .calculator-card {
        padding: var(--spacing-xl);
    }

    /* Forms - Two column layout for related fields */
    .form-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--spacing-lg);
    }

    .form-row .form-group {
        margin-bottom: 0;
    }

    /* Results Grid */
    .results-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-md);
    }

    /* Stats Grid */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Calculator Navigation */
    .calculator-nav {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Footer */
    .footer-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===== DESKTOP (1024px and up) ===== */
/* NOTE: Hamburger menu shows on all screens below 1024px (mobile + tablets + large phones) */
@media (min-width: 1024px) {
    /* Hide close button on desktop */
    .close-menu {
        display: none !important;
    }

    /* Typography */
    h1 {
        font-size: 2.5rem;
    }

    h2 {
        font-size: 2rem;
    }

    /* Container padding */
    .container {
        padding: 0 20px;
    }

    /* Header */
    header {
        padding: 15px 0;
    }

    header h1 {
        font-size: 2rem;
    }

    nav ul {
        flex-wrap: nowrap;
        gap: 15px;
    }

    /* Hero */
    .hero h2 {
        font-size: 2.5rem;
    }

    /* Calculator Card */
    .calculator-card {
        max-width: 800px;
        padding: var(--spacing-2xl);
    }

    /* Results - Three column layout */
    .results-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .comparison-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Refinance Comparison */
    .refinance-comparison {
        grid-template-columns: 1fr 1fr;
    }

    /* Stats Grid */
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Calculator Navigation */
    .calculator-nav {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Footer */
    .footer-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Tables - Better spacing */
    th, td {
        padding: var(--spacing-lg);
    }

    /* Action Buttons - Horizontal layout */
    .action-buttons {
        flex-direction: row;
        justify-content: flex-start;
    }

    .action-btn {
        width: auto;
    }

    /* Table Filters */
    .table-filters {
        flex-direction: row;
    }

    .filter-btn {
        width: auto;
    }
}

/* ===== DESKTOP LARGE (1024px and up) ===== */
@media (min-width: 1024px) {
    /* Typography */
    h1 {
        font-size: 3rem;
    }

    h2 {
        font-size: 2.25rem;
    }

    /* Header */
    header {
        padding: 15px 0;
    }

    header h1 {
        font-size: 2.25rem;
    }

    nav ul {
        gap: 18px;
    }

    /* Hero */
    .hero {
        padding: var(--spacing-3xl) var(--spacing-2xl);
    }

    .hero h2 {
        font-size: 3rem;
    }

    /* Calculator Card - Side-by-side layout option */
    .calculator-layout-horizontal {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--spacing-2xl);
        max-width: 1200px;
    }

    .calculator-layout-horizontal .calculator-inputs {
        padding-right: var(--spacing-lg);
        border-right: 2px solid var(--gray-200);
    }

    /* Results - Four column layout for comparison pages */
    .results-grid.four-col {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Stats Grid */
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Footer */
    .footer-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Bank Comparison Table - More columns visible */
    .bank-comparison-table table {
        min-width: auto;
    }

    /* Advanced Calculator Features */
    .advanced-options {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-lg);
    }
}

/* ===== EXTRA LARGE SCREENS (1280px and up) ===== */
@media (min-width: 1280px) {
    .container {
        max-width: 1280px;
    }

    .calculator-card {
        max-width: 900px;
    }

    /* Multi-column form layouts */
    .form-row-3 {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: var(--spacing-lg);
    }
}

/* ===== LANDSCAPE MOBILE (Height-based) ===== */
@media (max-height: 500px) and (orientation: landscape) {
    /* Reduce vertical spacing on landscape mobile */
    header {
        padding: 10px 0;
    }

    body {
        padding-top: 60px;
    }

    .hero {
        padding: var(--spacing-lg);
    }

    .calculator-card {
        padding: var(--spacing-lg);
    }

    .section {
        padding: var(--spacing-lg) 0;
    }

    footer {
        padding: var(--spacing-lg) 0;
    }

    /* Hide hero image on landscape mobile to save space */
    .hero img {
        max-height: 150px;
        object-fit: cover;
    }
}

/* ===== HAMBURGER MENU STYLES ===== */
/* Hamburger menu button - hidden by default on desktop, shown on mobile */
.hamburger-menu {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 8px;
    line-height: 1;
    transition: opacity 0.3s ease;
    z-index: 1001;
    -webkit-tap-highlight-color: transparent;
    min-width: 46px;
    min-height: 46px;
}

/* CRITICAL: Hide hamburger when menu is open */
body.menu-open .hamburger-menu {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Close button - hidden by default, only visible on mobile when menu is open */
.close-menu {
    display: none;
}

.hamburger-menu:hover {
    opacity: 0.8;
}

.hamburger-menu:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.hamburger-menu[aria-label]::before {
    content: attr(aria-label);
    position: absolute;
    left: -9999px;
}

/* Mobile navigation styles - shows on all devices below 1024px */
/* This includes large phones like Samsung S25 Plus, tablets, and smaller devices */
@media (max-width: 1023px) {
    .hamburger-menu {
        display: block !important;
        font-size: 2rem !important;
        min-width: 46px !important;
        min-height: 46px !important;
    }

    /* Hide hamburger when menu is open */
    body.menu-open .hamburger-menu {
        display: none !important;
    }

    nav {
        position: fixed;
        top: 0;
        right: -100%;
        width: 85vw; /* Wider menu for mobile */
        max-width: 400px;
        height: 100vh;
        background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
        transition: right 0.3s ease-in-out;
        z-index: 99999 !important; /* ABOVE overlay - highest priority */
        overflow-y: auto;
        padding-top: 80px;
    }

    nav.active {
        right: 0;
    }

    nav ul {
        flex-direction: column;
        gap: 0;
        width: 100%;
        padding: 0;
    }

    nav li {
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    nav a {
        display: block;
        padding: 24px 28px;
        text-align: left;
        font-size: 1.5rem !important; /* Much larger nav links */
        transition: background 0.2s ease;
        min-height: 70px;
    }

    nav a:hover,
    nav a:focus {
        background: rgba(255, 255, 255, 0.1);
    }

    /* Mobile overlay - BEHIND nav menu, ABOVE page content */
    .nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        z-index: 0 !important; 
    }

    .nav-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Close button inside menu - only visible when menu is active */
    .close-menu {
        display: none;
        position: absolute;
        top: 15px;
        right: 20px;
        background: none;
        border: none;
        color: white;
        font-size: 3rem; /* Much larger close button */
        cursor: pointer;
        padding: 12px;
        line-height: 1;
        z-index: 100000 !important; /* Above nav */
        transition: opacity 0.3s ease;
        min-width: 60px;
        min-height: 60px;
    }

    /* Show close button only when nav is active */
    nav.active .close-menu {
        display: block !important;
    }

    .close-menu:hover {
        opacity: 0.8;
    }

    .close-menu:focus {
        outline: 2px solid rgba(255, 255, 255, 0.5);
        outline-offset: 2px;
    }

    /* ===== MOBILE PADDING OPTIMIZATION ===== */
    /* Balance between screen usage and readability */

    /* Container elements - optimal mobile padding */
    .container {
        padding: 0 16px !important;
    }

    /* Calculator cards - comfortable padding */
    .calculator-card {
        padding: 24px 18px !important;
        margin: 20px auto !important;
        max-width: 100% !important;
    }

    /* Hero section - balanced padding */
    .hero {
        padding: 32px 18px !important;
        margin-top: 30px !important;
    }

    /* Navigation header container */
    header .container {
        padding: 0 12px !important;
        position: relative !important;
    }

    /* Center header items on mobile */
    .header-content {
        justify-content: center !important;
        text-align: center !important;
        gap: 15px !important;
    }

    .header-content h1 {
        text-align: left !important;
        margin: 0 !important;
    }

    /* Position hamburger menu to the right of h1 */
    .hamburger-menu {
        flex-shrink: 0 !important;
    }

    /* ===== CONTENT SECTIONS - READABLE PADDING ===== */

    /* Results section - blue gradient background */
    .results {
        padding: 24px 18px !important;
    }

    .result-item {
        padding: 18px !important;
    }

    /* Disclaimer boxes - yellow background */
    .disclaimer {
        padding: 18px 16px !important;
    }

    /* FAQ sections - larger touch targets */
    .faq-question {
        padding: 18px 16px !important;
    }

    .faq-answer p {
        padding: 20px 16px !important;
    }

    /* Related calculator cards */
    .related-calc-card {
        padding: 24px 18px !important;
    }

    /* All section containers with backgrounds */
    section.container {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* Any sections with inline styled backgrounds */
    section[style*="background"] {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* Form groups - adequate spacing */
    .form-group {
        margin-bottom: 24px !important;
    }

    /* Info boxes and alert boxes */
    .info-box,
    .warning-box,
    .success-box,
    .error-box {
        padding: 18px 16px !important;
    }

    /* Comparison grid items */
    .comparison-item {
        padding: 18px 16px !important;
    }

    /* Stats cards/boxes */
    .stat-card,
    .feature-box {
        padding: 24px 18px !important;
    }

    /* Footer - comfortable padding */
    footer {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    .footer-grid {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Bank comparison table container */
    .table-container {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* Guide content sections */
    .guide-content,
    .guide-section {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* Location page containers */
    .location-header,
    .location-content {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* Testimonial boxes */
    .testimonial,
    .review-card {
        padding: 18px 16px !important;
    }

    /* CTA sections */
    .cta-section,
    .cta-box {
        padding: 24px 18px !important;
    }

    /* News/blog card elements */
    .news-card,
    .blog-card,
    .article-card {
        padding: 24px 18px !important;
    }

    /* Breadcrumb containers */
    .breadcrumb {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
}

/* Prevent body scroll when menu is open */
body.menu-open {
    overflow: hidden;
}

/* ===== MOBILE CHART OPTIMIZATIONS ===== */
@media (max-width: 1023px) {
    /* Make charts wider and shorter on mobile for better visibility */
    #rateComparisonChart {
        height: 300px !important;
        max-height: 300px !important;
    }

    /* Reduce chart container padding to maximize width on mobile */
    #rateComparisonChartContainer > div {
        padding: 15px 10px !important;
    }

    /* Custom legend table mobile optimizations */
    #customLegendTable {
        font-size: 0.85rem;
    }

    #customLegendTable .bank-header {
        padding: 10px 8px !important;
    }

    #customLegendTable table {
        font-size: 0.8rem;
    }

    #customLegendTable table td {
        padding: 6px 8px !important;
    }

    /* Smart recommendation mobile padding */
    #smartRecommendation > div {
        padding: 15px 10px !important;
    }

    /* Tutorial tooltip - smaller on mobile */
    #legendTutorial {
        padding: 10px 12px !important;
        font-size: 0.85rem;
    }

    #legendTutorial button {
        padding: 5px 10px !important;
        font-size: 0.85rem;
    }

    /* ===== ADDITIONAL MOBILE OPTIMIZATIONS (640-767px) ===== */
    /* These apply to larger mobile devices and small tablets in portrait */

    /* Ensure buttons meet touch targets across all mobile sizes */
    button,
    .btn,
    .cta-button {
        min-height: 44px !important;
        min-width: 44px !important;
    }

    /* Optimize footer for all mobile devices */
    footer {
        padding: 35px 15px 20px !important;
    }

    .footer-column a {
        min-height: 44px;
        display: inline-block;
        line-height: 44px;
    }

    /* Ensure images are responsive across all mobile */
    img {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Tables scroll on all mobile devices */
    .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Add padding to tables so last column isn't cut off when scrolling */
    .table-container table {
        padding-right: 20px;
    }

    /* Also add padding to bank rates list tables */
    .bank-rates-list table {
        padding-right: 15px;
    }
}

/* ===== MOBILE/TABLET ENHANCEMENTS (below 1024px) ===== */
/* Applies to all phones and tablets - Samsung S25 Plus, iPad, etc. */
@media (max-width: 1023px) {
    /* CRITICAL: Prevent page from expanding beyond screen width */
    html {
        font-size: clamp(14px, 3.2vw, 32px) !important; /* Scales with viewport width - 15% smaller */
        -webkit-text-size-adjust: 100% !important;
        text-size-adjust: 100% !important;
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }

    /* REM-BASED typography */
    h1 { font-size: 1.6rem !important; margin-bottom: 1rem !important; }
    h2 { font-size: 1.4rem !important; margin-bottom: 0.875rem !important; }
    h3 { font-size: 1.2rem !important; margin-bottom: 0.75rem !important; }
    body, p, li, span, div { font-size: 1rem !important; line-height: 1.7 !important; }

    /* INCREASED SPACING between elements */
    p { margin-bottom: 1.25rem !important; }
    section { margin-bottom: 2rem !important; }

    /* Form elements */
    input[type="number"],
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    select,
    textarea {
        font-size: 1.1rem !important;
        padding: 14px 12px !important;
        min-height: 52px !important;
        border-radius: 8px !important;
        margin-bottom: 1rem !important;
    }
    label { font-size: 1rem !important; margin-bottom: 0.5rem !important; display: block !important; }
    button, .cta-button { font-size: 1.05rem !important; min-height: 50px !important; padding: 12px 20px !important; }

    /* Form group spacing */
    .form-group { margin-bottom: 1.5rem !important; }

    body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }

    /* Prevent ANY element from causing horizontal scroll */
    *, *::before, *::after {
        max-width: 100vw;
    }

    /* Main container must not exceed viewport */
    .container,
    main,
    section,
    article,
    header,
    footer {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* TYPOGRAPHY - Scaled down with better spacing */
    h1 {
        font-size: 1.6rem !important;
        line-height: 1.3;
        margin-bottom: 1rem !important;
    }

    h2 {
        font-size: 1.4rem !important;
        line-height: 1.35;
        margin-bottom: 0.875rem !important;
    }

    h3 {
        font-size: 1.2rem !important;
        line-height: 1.4;
        margin-bottom: 0.75rem !important;
    }

    h4 {
        font-size: 1.1rem !important;
        margin-bottom: 0.625rem !important;
    }

    body,
    p,
    li,
    span,
    div {
        font-size: 1rem !important;
        line-height: 1.7;
    }

    p {
        margin-bottom: 1.25rem !important;
    }

    /* Ensure all text elements are large enough */
    * {
        -webkit-text-size-adjust: 100%;
        -moz-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    /* BUTTONS - Scaled down touch targets */
    button,
    .btn,
    .cta-button,
    input[type="submit"],
    input[type="button"],
    a.button,
    .nav-link,
    .action-btn,
    .filter-btn {
        min-height: 48px !important;
        min-width: 48px !important;
        padding: 12px 20px !important;
        font-size: 1rem !important;
    }

    /* CTA buttons - primary actions */
    .cta-button {
        padding: 14px 24px !important;
        font-size: 1.05rem !important;
        min-height: 52px !important;
    }

    /* FORM INPUTS - Larger and easy to tap - REM VALUES */
    input[type="number"],
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    select {
        padding: 16px 14px !important;
        font-size: 1.2rem !important; /* 22px */
        min-height: 60px !important;
        border-radius: 8px;
    }

    .form-group {
        margin-bottom: 24px !important;
    }

    label {
        font-size: 1.1rem !important; /* 20px */
        margin-bottom: 10px !important;
        display: block;
        font-weight: 600;
    }

    .input-help {
        font-size: 1rem !important; /* 18px */
        line-height: 1.5;
        margin-top: 8px;
    }

    /* CALCULATOR CARDS - More padding for readability */
    .calculator-card {
        padding: 28px 20px !important;
        margin: 24px auto !important;
        border-radius: 14px;
    }

    .calculator-card h3 {
        font-size: 1.4rem !important; /* 25px */
        margin-bottom: 20px;
    }

    /* RESULTS SECTION - REM VALUES */
    .results {
        padding: 24px 18px !important;
    }

    .result-item {
        padding: 16px !important;
        margin-bottom: 12px;
    }

    .result-label {
        font-size: 1rem !important; /* 18px */
        margin-bottom: 6px;
    }

    .result-value {
        font-size: 2rem !important; /* 36px */
        font-weight: 700;
    }

    /* IMAGES - Fully responsive */
    img {
        max-width: 100% !important;
        height: auto !important;
        display: block;
    }

    /* HERO SECTION - REM VALUES */
    .hero {
        padding: 32px 18px !important;
    }

    .hero h2 {
        font-size: 1.5rem !important; /* 27px */
        margin-bottom: 14px;
    }

    .hero p {
        font-size: 1.1rem !important; /* 20px */
        line-height: 1.6;
    }

    /* ===== MOBILE CARD-BASED TABLE LAYOUT ===== */
    /* Transform tables into stacked cards on mobile for better readability */

    .table-container,
    .comparison-card,
    div:has(> table) {
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: visible !important;
    }

    /* Hide table header on mobile - data shown in cards */
    table.mobile-cards thead {
        display: none !important;
    }

    /* Transform table into card layout */
    table.mobile-cards {
        display: block !important;
        width: 100% !important;
        min-width: unset !important;
        overflow-x: visible !important;
    }

    table.mobile-cards tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    table.mobile-cards tr {
        display: block !important;
        background: white !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 12px !important;
        padding: 1rem !important;
        margin-bottom: 0.5rem !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important;
    }

    table.mobile-cards td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0.625rem 0 !important;
        border-bottom: 1px solid #f1f5f9 !important;
        white-space: normal !important;
        font-size: 0.95rem !important;
    }

    table.mobile-cards td:last-child {
        border-bottom: none !important;
    }

    /* Show data labels from data-label attribute */
    table.mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600 !important;
        color: #475569 !important;
        font-size: 0.85rem !important;
        text-transform: uppercase !important;
        letter-spacing: 0.3px !important;
        flex-shrink: 0 !important;
        margin-right: 1rem !important;
    }

    /* Rate cells - highlight the value */
    table.mobile-cards td.rate-cell {
        font-weight: 700 !important;
        color: #1e3a8a !important;
        font-size: 1.1rem !important;
    }

    /* Bank name as card header */
    table.mobile-cards td:first-child {
        font-size: 1.1rem !important;
        font-weight: 700 !important;
        color: #1e3a8a !important;
        padding-bottom: 0.75rem !important;
        margin-bottom: 0.5rem !important;
        border-bottom: 2px solid #e2e8f0 !important;
    }

    table.mobile-cards td:first-child::before {
        display: none !important;
    }

    /* Fallback for tables without mobile-cards class - horizontal scroll */
    table:not(.mobile-cards) {
        font-size: 0.9rem !important;
        min-width: 500px;
        width: max-content;
        display: block;
        overflow-x: auto;
    }

    table:not(.mobile-cards) th,
    table:not(.mobile-cards) td {
        padding: 10px 8px !important;
        font-size: 0.9rem !important;
        white-space: nowrap;
    }

    /* DISCLAIMER BOXES - REM VALUES */
    .disclaimer {
        padding: 16px 14px !important;
        font-size: 1rem !important; /* 18px */
        line-height: 1.6;
    }

    /* FAQ SECTIONS - REM VALUES */
    .faq-question {
        padding: 16px 14px !important;
        font-size: 1.1rem !important; /* 20px */
        min-height: 56px;
    }

    .faq-answer p {
        padding: 18px 14px !important;
        font-size: 1.05rem !important; /* 19px */
        line-height: 1.6;
    }

    .faq-icon {
        font-size: 1.5rem !important; /* 27px */
    }

    /* RELATED CALCULATORS / CARDS - REM VALUES */
    .related-calc-card,
    .guide-card {
        padding: 22px 16px !important;
    }

    .related-calc-card h3,
    .guide-card h2 {
        font-size: 1.25rem !important; /* 22px */
    }

    .related-calc-card p,
    .guide-card p {
        font-size: 1.05rem !important; /* 19px */
        line-height: 1.6;
    }

    .related-calc-link,
    .guide-link {
        font-size: 1.1rem !important; /* 20px */
        padding: 10px 0;
        min-height: 48px;
        display: inline-flex;
        align-items: center;
    }

    /* FOOTER - REM VALUES */
    footer {
        padding: 36px 18px 24px !important;
    }

    .footer-grid {
        grid-template-columns: 1fr;
        gap: 28px;
    }

    footer h4 {
        font-size: 1.2rem !important; /* 22px */
        margin-bottom: 14px;
    }

    footer ul li {
        margin-bottom: 10px;
    }

    footer a {
        display: inline-block;
        min-height: 48px;
        line-height: 48px;
        font-size: 1.05rem !important; /* 19px */
        padding: 0 4px;
    }

    .footer-bottom {
        padding: 20px 0 0;
        font-size: 1rem !important; /* 18px */
    }

    /* NAV LINKS in slide-out menu - REM VALUES */
    nav a {
        min-height: 56px !important;
        display: flex !important;
        align-items: center !important;
        padding: 16px 24px !important;
        font-size: 1.15rem !important; /* 21px */
    }

    /* AFFILIATE CTA BUTTONS - REM VALUES */
    .affiliate-button,
    .affiliate-cta-inline a {
        min-height: 56px !important;
        padding: 14px 24px !important;
        font-size: 1.1rem !important; /* 20px */
    }

    /* CONTAINER PADDING */
    .container {
        padding: 0 16px !important;
    }
}

/* ===== SMALL PHONES (below 640px) ===== */
@media (max-width: 639px) {
    /* Slightly reduce padding on very small screens */
    .container {
        padding: 0 12px !important;
    }

    .calculator-card {
        padding: 18px 12px !important;
    }

    .hero {
        padding: 26px 12px !important;
    }

    h1 {
        font-size: 1.6rem !important; /* 29px */
    }

    h2 {
        font-size: 1.35rem !important; /* 24px */
    }

    /* Ensure grids stack on small phones */
    .related-calculators-grid,
    .guides-grid {
        grid-template-columns: 1fr !important;
    }

    /* Footer stacks completely */
    .footer-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ===== VERY SMALL PHONES (below 375px) - REM VALUES ===== */
@media (max-width: 374px) {
    html {
        font-size: 16px !important; /* Smaller base for tiny screens */
    }

    h1 {
        font-size: 1.5rem !important; /* 24px */
    }

    h2 {
        font-size: 1.3rem !important; /* 21px */
    }

    h3 {
        font-size: 1.15rem !important; /* 18px */
    }

    body, p, li, span, div {
        font-size: 1rem !important; /* 16px */
    }

    .calculator-card {
        padding: 14px 10px !important;
    }

    .result-value {
        font-size: 1.8rem !important; /* 29px */
    }

    .cta-button {
        padding: 14px 20px !important;
        font-size: 1rem !important; /* 16px */
    }

    input[type="number"],
    input[type="text"],
    select {
        font-size: 1.1rem !important; /* 18px */
        min-height: 54px !important;
    }
}

/* ===== TABLET SPECIFIC (640px - 1023px) ===== */
@media (min-width: 640px) and (max-width: 1023px) {
    /* Tablet-specific optimizations */
    .calculator-card {
        max-width: 700px;
    }

    /* Two-column layouts work well on tablets */
    .tablet-two-col {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--spacing-lg);
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    /* Hide non-essential elements */
    header,
    footer,
    nav,
    .cta-button,
    .action-buttons,
    .calculator-nav,
    .hide-print {
        display: none !important;
    }

    /* Reset backgrounds and colors for print */
    body {
        background: white;
        color: black;
        font-size: 12pt;
    }

    /* Make sure content fits on page */
    .container {
        max-width: 100%;
        padding: 0;
    }

    .calculator-card,
    .results {
        box-shadow: none;
        border: 1px solid #000;
        page-break-inside: avoid;
    }

    /* Print-friendly tables */
    table {
        page-break-inside: avoid;
        border: 1px solid #000;
    }

    th {
        background: #f0f0f0 !important;
        color: #000 !important;
    }

    /* Show URLs in print */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        font-style: italic;
    }

    /* Page breaks */
    h2, h3 {
        page-break-after: avoid;
    }

    /* Print page margins */
    @page {
        margin: 2cm;
    }
}

/* ===== HIGH DPI DISPLAYS (Retina) ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Ensure images are crisp on retina displays */
    img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* ===== REDUCED MOTION ===== */
@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;
    }
}

/* ===== HIGH CONTRAST MODE ===== */
@media (prefers-contrast: high) {
    :root {
        --gray-200: #000;
        --gray-300: #000;
    }

    input,
    select,
    button {
        border-width: 2px;
    }

    .calculator-card {
        border: 2px solid #000;
    }
}

/* ===== DARK MODE (Optional - Future Enhancement) ===== */
@media (prefers-color-scheme: dark) {
    /* Dark mode can be implemented here if needed */
    /* This is left empty for now but can be expanded later */
}

/* ===== SPECIFIC DEVICE OPTIMIZATIONS ===== */

/* iPhone SE and small phones */
@media (max-width: 375px) {
    .calculator-card h3 {
        font-size: var(--font-size-lg);
    }

    .result-value {
        font-size: 1.5rem;
    }
}

/* iPad and tablets in portrait */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    .calculator-card {
        max-width: 600px;
    }
}

/* iPad and tablets in landscape */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .calculator-layout-horizontal {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--spacing-xl);
    }
}

/* ===== CONTAINER QUERIES (Future-proof) ===== */
/* These will activate when browser support improves */
@supports (container-type: inline-size) {
    .calculator-card {
        container-type: inline-size;
    }

    @container (min-width: 600px) {
        .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
        }
    }
}

/* ===== UTILITY CLASSES FOR RESPONSIVE DESIGN ===== */

/* Hide on mobile */
.hide-mobile {
    display: none;
}

@media (min-width: 640px) {
    .hide-mobile {
        display: block;
    }
}

/* Show only on mobile */
.show-mobile {
    display: block;
}

@media (min-width: 640px) {
    .show-mobile {
        display: none;
    }
}

/* Hide on tablet */
@media (min-width: 640px) and (max-width: 1023px) {
    .hide-tablet {
        display: none;
    }
}

/* Hide on desktop */
@media (min-width: 1024px) {
    .hide-desktop {
        display: none;
    }
}

/* Show only on desktop */
.show-desktop {
    display: none;
}

@media (min-width: 1024px) {
    .show-desktop {
        display: block;
    }
}

/* Responsive text alignment */
@media (max-width: 639px) {
    .text-mobile-center {
        text-align: center;
    }
}

/* Responsive spacing */
@media (max-width: 639px) {
    .mobile-spacing-reduced {
        margin-top: var(--spacing-sm) !important;
        margin-bottom: var(--spacing-sm) !important;
    }
}
