/* Mortgage Calculator NZ - Main Stylesheet */
/* Mobile-first, responsive, accessible design */

/* ===== CSS CUSTOM PROPERTIES (VARIABLES) ===== */
:root {
    /* Colors */
    --primary-blue: #1e3a8a;
    --primary-blue-light: #3b82f6;
    --primary-green: #10b981;
    --primary-green-dark: #059669;
    --accent-orange: #f59e0b;
    --accent-orange-light: #fef3c7;

    /* Neutrals */
    --gray-50: #f8f9fa;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    /* Text */
    --text-primary: #2c3e50;
    --text-secondary: #64748b;
    --text-light: #94a3b8;

    /* Status Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;

    /* Spacing */
    --spacing-xs: 5px;
    --spacing-sm: 10px;
    --spacing-md: 15px;
    --spacing-lg: 20px;
    --spacing-xl: 30px;
    --spacing-2xl: 40px;
    --spacing-3xl: 60px;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.15);
    --shadow-xl: 0 20px 60px rgba(0,0,0,0.2);

    /* Transitions */
    --transition-fast: 150ms ease-in-out;
    --transition-base: 250ms ease-in-out;
    --transition-slow: 350ms ease-in-out;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Helvetica Neue', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;
    --font-size-4xl: 2.25rem;

    /* Line Heights */
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.75;

    /* Container Widths */
    --container-sm: 640px;
    --container-md: 768px;
    --container-lg: 1024px;
    --container-xl: 1200px;
}

/* ===== RESET & BASE STYLES ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Prevent horizontal scroll on mobile */
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    font-family: var(--font-family);
    font-size: 16px;
    line-height: var(--line-height-normal);
    color: var(--text-primary);
    background-color: var(--gray-50);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-top: 80px; /* Space for fixed header */
    /* Prevent horizontal scroll on mobile */
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
}

main {
    flex: 1;
}

/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    line-height: var(--line-height-tight);
    color: var(--primary-blue);
    margin-bottom: var(--spacing-md);
}

h1 {
    font-size: var(--font-size-3xl);
}

h2 {
    font-size: var(--font-size-2xl);
}

h3 {
    font-size: var(--font-size-xl);
}

h4 {
    font-size: var(--font-size-lg);
}

p {
    margin-bottom: var(--spacing-md);
    color: var(--text-light);
}

a {
    color: var(--primary-blue-light);
    text-decoration: none;
    transition: opacity var(--transition-fast);
}

a:hover {
    opacity: 0.8;
}

a:focus-visible {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ===== LAYOUT ===== */
.container {
    max-width: var(--container-xl);
    margin: 0 auto;
    padding: 0 var(--spacing-lg);
    width: 100%;
}

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

/* ===== HEADER ===== */
header {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-blue-light) 100%);
    color: white;
    padding: 15px 0;
    box-shadow: var(--shadow-md);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

header h1 {
    font-size: clamp(1.25rem, 4vw, 1.8rem);
    font-weight: 700;
    margin: 0;
    color: white;
}

header h1 a {
    color: white;
    text-decoration: none;
}

/* Navigation */
nav[aria-label="Main navigation"] ul {
    list-style: none;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
}

nav a {
    color: white;
    text-decoration: none;
    font-weight: 500;
    font-size: var(--font-size-sm);
    transition: opacity var(--transition-base);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    display: inline-block;
    white-space: nowrap;
}

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

nav a.active {
    background: rgba(255, 255, 255, 0.2);
    font-weight: 600;
}

/* ===== HERO SECTION ===== */
.hero {
    text-align: center;
    padding: var(--spacing-2xl) var(--spacing-lg);
    background: white;
    margin-top: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.hero img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow-md);
}

.hero h2 {
    font-size: clamp(1.5rem, 5vw, 2.25rem);
    color: var(--primary-blue);
    margin-bottom: var(--spacing-md);
}

.hero p {
    font-size: var(--font-size-lg);
    color: var(--text-secondary);
    max-width: 700px;
    margin: 0 auto;
}

/* ===== CALCULATOR CARD ===== */
.calculator-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    margin: var(--spacing-xl) auto;
    max-width: 800px;
    box-shadow: var(--shadow-md);
    transition: box-shadow var(--transition-base);
}

.calculator-card:hover {
    box-shadow: var(--shadow-lg);
}

.calculator-card h3 {
    font-size: var(--font-size-2xl);
    color: var(--primary-blue);
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-md);
    border-bottom: 3px solid var(--primary-blue-light);
}

/* ===== FORM ELEMENTS ===== */
.form-group {
    margin-bottom: var(--spacing-xl);
}

label {
    display: block;
    margin-bottom: var(--spacing-sm);
    font-weight: 600;
    color: var(--primary-blue);
    font-size: var(--font-size-base);
}

label .required {
    color: var(--error);
    margin-left: var(--spacing-xs);
}

.tooltip {
    display: inline-block;
    width: 18px;
    height: 18px;
    background: var(--info);
    color: white;
    border-radius: 50%;
    text-align: center;
    font-size: var(--font-size-xs);
    line-height: 18px;
    cursor: help;
    margin-left: var(--spacing-xs);
    position: relative;
}

.tooltip:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-900);
    color: white;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    white-space: nowrap;
    z-index: 10;
    box-shadow: var(--shadow-lg);
}

input[type="number"],
input[type="text"],
input[type="email"],
input[type="tel"],
select {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    color: var(--text-primary);
    transition: all var(--transition-base);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-blue-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input:invalid:not(:placeholder-shown) {
    border-color: var(--error);
}

input:disabled,
select:disabled {
    background: var(--gray-100);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Select dropdown arrow */
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23475569' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

.input-help {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-top: var(--spacing-xs);
    display: block;
}

.error-message {
    color: var(--error);
    font-size: var(--font-size-sm);
    margin-top: var(--spacing-xs);
    display: none;
}

.error-message[role="alert"] {
    display: block;
}

/* Checkbox and Radio Styles */
.checkbox-group,
.radio-group {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

input[type="checkbox"],
input[type="radio"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    margin: 0;
}

/* Range Slider */
input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: var(--radius-sm);
    background: var(--gray-200);
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-blue-light);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-blue-light);
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow-sm);
}

/* ===== RESULTS SECTION ===== */
.results {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-blue-light) 100%);
    color: white;
    padding: var(--spacing-xl);
    border-radius: var(--radius-lg);
    margin-top: var(--spacing-xl);
    display: none;
}

.results.show {
    display: block;
    animation: slideIn 0.3s ease-out;
}

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

.result-item {
    margin: var(--spacing-md) 0;
    padding: var(--spacing-md);
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    transition: background var(--transition-base);
}

.result-item:hover {
    background: rgba(255, 255, 255, 0.15);
}

.result-label {
    font-size: var(--font-size-sm);
    opacity: 0.95;
    margin-bottom: var(--spacing-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.result-value {
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 700;
    margin-top: var(--spacing-xs);
    line-height: 1.2;
}

.result-value.large {
    font-size: clamp(2rem, 6vw, 2.5rem);
}

.result-value.small {
    font-size: var(--font-size-xl);
}

/* Comparison Grid */
.comparison-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-lg);
    margin-top: var(--spacing-lg);
}

.comparison-item {
    background: rgba(255, 255, 255, 0.1);
    padding: var(--spacing-lg);
    border-radius: var(--radius-md);
    text-align: center;
}

.comparison-item h4 {
    color: white;
    font-size: var(--font-size-base);
    margin-bottom: var(--spacing-md);
}

.comparison-item .value {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: white;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-block;
    padding: 12px 24px;
    font-size: var(--font-size-base);
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    font-family: var(--font-family);
    line-height: 1.5;
    user-select: none;
}

.btn:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary,
.cta-button {
    background: var(--primary-green);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover,
.cta-button:hover {
    background: var(--primary-green-dark);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-primary:active,
.cta-button:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary-blue-light);
    color: var(--primary-blue-light);
}

.btn-outline:hover {
    background: var(--primary-blue-light);
    color: white;
}

.btn-block {
    width: 100%;
    display: block;
}

.btn-large {
    padding: 15px 30px;
    font-size: var(--font-size-lg);
}

.btn-small {
    padding: 8px 16px;
    font-size: var(--font-size-sm);
}

/* CTA Button (specific to calculators) */
.cta-button {
    width: 100%;
    padding: 15px 30px;
    font-size: var(--font-size-lg);
    margin-top: var(--spacing-lg);
}

/* ===== ALERT/INFO BOXES ===== */
.disclaimer,
.info-box,
.warning-box,
.success-box,
.error-box {
    padding: var(--spacing-md);
    margin: var(--spacing-lg) 0;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
}

.disclaimer {
    background: var(--accent-orange-light);
    border-left: 4px solid var(--accent-orange);
    color: #92400e;
}

.info-box {
    background: #eff6ff;
    border-left: 4px solid var(--info);
    color: #1e40af;
}

.warning-box {
    background: #fef3c7;
    border-left: 4px solid var(--warning);
    color: #92400e;
}

.success-box {
    background: #d1fae5;
    border-left: 4px solid var(--success);
    color: #065f46;
}

.error-box {
    background: #fee2e2;
    border-left: 4px solid var(--error);
    color: #991b1b;
}

/* ===== TABLES ===== */
table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--spacing-lg) 0;
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

thead {
    background: var(--primary-blue);
    color: white;
}

th {
    padding: var(--spacing-md);
    text-align: left;
    font-weight: 600;
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

td {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--gray-200);
    color: var(--text-primary);
}

tbody tr:hover {
    background: var(--gray-50);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Sortable table headers */
th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 30px;
}

th.sortable::after {
    content: '⇅';
    position: absolute;
    right: 10px;
    opacity: 0.5;
}

th.sortable.asc::after {
    content: '↑';
    opacity: 1;
}

th.sortable.desc::after {
    content: '↓';
    opacity: 1;
}

/* ===== FOOTER ===== */
footer {
    background: var(--gray-800);
    color: white;
    padding: var(--spacing-3xl) var(--spacing-lg) var(--spacing-xl);
    margin-top: var(--spacing-3xl);
    position: relative;
    overflow: hidden;
}

footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('/images/Footer-background.png');
    background-size: cover;
    background-position: center;
    opacity: 0.05;
    z-index: 0;
}

footer > * {
    position: relative;
    z-index: 1;
}

.footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-xl);
    margin-bottom: var(--spacing-lg);
}

.footer-column h4 {
    color: white;
    margin-bottom: var(--spacing-md);
    font-size: var(--font-size-lg);
}

.footer-column ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.footer-column ul li {
    margin-bottom: var(--spacing-sm);
}

.footer-column a {
    color: var(--gray-300);
    text-decoration: none;
    transition: color var(--transition-fast);
    font-size: var(--font-size-sm);
}

.footer-column a:hover {
    color: white;
}

.footer-bottom {
    border-top: 1px solid var(--gray-600);
    padding-top: var(--spacing-lg);
    text-align: center;
    color: var(--gray-400);
    font-size: var(--font-size-sm);
    margin-top: var(--spacing-xl);
}

/* ===== UTILITY CLASSES ===== */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.mt-1 { margin-top: var(--spacing-sm); }
.mt-2 { margin-top: var(--spacing-md); }
.mt-3 { margin-top: var(--spacing-lg); }
.mt-4 { margin-top: var(--spacing-xl); }

.mb-1 { margin-bottom: var(--spacing-sm); }
.mb-2 { margin-bottom: var(--spacing-md); }
.mb-3 { margin-bottom: var(--spacing-lg); }
.mb-4 { margin-bottom: var(--spacing-xl); }

.p-1 { padding: var(--spacing-sm); }
.p-2 { padding: var(--spacing-md); }
.p-3 { padding: var(--spacing-lg); }
.p-4 { padding: var(--spacing-xl); }

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ===== LOADING STATES ===== */
.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--primary-blue-light);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== ACCESSIBILITY ===== */
*:focus-visible {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

/* Reduced motion for accessibility */
@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;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    header,
    footer,
    nav,
    .cta-button {
        display: none;
    }

    body {
        background: white;
        color: black;
    }

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