:root {
    --primary-color: #0056b3;
    --secondary-color: #007bff;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --light-bg: #f8f9fa;
    --dark-bg: #343a40;
    --border-color: #dee2e6;
    --text-color: #333;
    --text-muted: #6c757d;
    --white: #ffffff;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --primary-color: #4dabf7;
    --secondary-color: #339af0;
    --light-bg: #2c2c2c;
    --dark-bg: #1a1a1a;
    --border-color: #495057;
    --text-color: #f8f9fa;
    --text-muted: #adb5bd;
    --white: #2c2c2c;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--light-bg);
    color: var(--text-color);
    line-height: 1.6;
    transition: all 0.3s ease;
}

header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--white);
    padding: 2em 0;
    position: relative;
    box-shadow: var(--shadow);
    text-align: center;
}

header h1 {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 3.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.1;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 20px;
}

.theme-toggle {
    position: absolute;
    top: 1em;
    right: 2em;
}

#theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: var(--white);
    padding: 0.5em;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2em;
    transition: all 0.3s ease;
}

#theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

main {
    padding: 20px;
    max-width: 1200px;
    margin: 20px auto;
    display: flex;
    flex-direction: column;
    gap: 45px;
}

section {
    padding: 35px;
    border: 1px solid var(--border-color);
    border-radius: 15px;
    background-color: var(--white);
    transition: all 0.3s ease;
    position: relative;
    width: 100%;
}

#mortgage-calculator {
    box-shadow: 0 4px 20px rgba(0, 86, 179, 0.12);
}

#wage-calculator {
    box-shadow: 0 4px 20px rgba(40, 167, 69, 0.12);
}

#affordability-calculator {
    box-shadow: 0 4px 20px rgba(255, 193, 7, 0.12);
}

#stamp-duty-calculator {
    box-shadow: 0 4px 20px rgba(220, 53, 69, 0.12);
}

section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 15px 15px 0 0;
}

section:hover {
    transform: translateY(-3px);
}

#mortgage-calculator:hover {
    box-shadow: 0 8px 30px rgba(0, 86, 179, 0.18);
}

#wage-calculator:hover {
    box-shadow: 0 8px 30px rgba(40, 167, 69, 0.18);
}

#affordability-calculator:hover {
    box-shadow: 0 8px 30px rgba(255, 193, 7, 0.18);
}

#stamp-duty-calculator:hover {
    box-shadow: 0 8px 30px rgba(220, 53, 69, 0.18);
}

h2 {
    color: var(--primary-color);
    margin-top: 0;
    margin-bottom: 25px;
    font-weight: 600;
    font-size: 1.4em;
    text-align: center;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--light-bg);
}

.input-group {
    margin-bottom: 20px;
    position: relative;
}

label {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.95em;
}

.tooltip {
    margin-left: 8px;
    cursor: help;
    position: relative;
    font-size: 1.1em;
}

.tooltip:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #2c3e50;
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8em;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .tooltip:hover::after {
    background: #34495e;
    color: #ecf0f1;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

input[type="number"],
input[type="text"],
select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 1em;
    background-color: var(--white);
    color: var(--text-color);
    transition: all 0.3s ease;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 86, 179, 0.1);
}

input:invalid {
    border-color: var(--danger-color);
}

input[readonly] {
    background-color: var(--light-bg);
    cursor: not-allowed;
}

.error-message {
    color: var(--danger-color);
    font-size: 0.85em;
    margin-top: 5px;
    display: none;
    font-weight: 500;
}

.button-group {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
}

button {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.calculate-btn {
    background: linear-gradient(135deg, var(--success-color), #20c997);
    color: var(--white);
    flex: 1;
    min-width: 140px;
}

.calculate-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}

.calculate-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.reset-btn {
    background-color: var(--text-muted);
    color: var(--white);
}

.reset-btn:hover {
    background-color: #5a6268;
    transform: translateY(-2px);
}

.loading-spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.results-section {
    margin-top: 20px;
    padding: 20px;
    border: 2px solid var(--success-color);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(40, 167, 69, 0.05), rgba(32, 201, 151, 0.05));
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.results-header h3 {
    margin: 0 0 20px 0;
    color: var(--success-color);
    font-size: 1.3em;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background-color: var(--white);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    transition: all 0.3s ease;
}

.result-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.result-item.highlight {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--white);
    font-weight: 600;
    font-size: 1.1em;
}

.result-item.highlight .result-label {
    color: rgba(255, 255, 255, 0.9);
}

.result-value {
    font-weight: 700;
    font-size: 1.1em;
    color: var(--text-color);
}

.result-item.highlight .result-value {
    color: var(--white);
}

.amortization-schedule {
    margin-top: 25px;
}

.amortization-schedule h4 {
    color: var(--primary-color);
    margin-bottom: 15px;
}

.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 6px;
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
    margin: 0;
    background-color: var(--white);
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

th {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--white);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85em;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
}

tbody tr:hover {
    background-color: var(--light-bg);
}

.affordability-tips {
    margin-top: 25px;
    padding: 20px;
    background-color: rgba(255, 193, 7, 0.1);
    border-left: 4px solid var(--warning-color);
    border-radius: 6px;
}

.affordability-tips h4 {
    color: var(--warning-color);
    margin-top: 0;
}

.affordability-tips ul {
    margin: 0;
    padding-left: 20px;
}

.affordability-tips li {
    margin-bottom: 8px;
    color: var(--text-color);
}

footer {
    text-align: center;
    padding: 2em 0;
    background: linear-gradient(135deg, var(--dark-bg), #495057);
    color: var(--white);
    margin-top: 40px;
}

[data-theme="dark"] footer {
    color: #f8f9fa;
}

.footer-actions {
    margin-bottom: 30px;
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    width: 100%;
}

.print-btn, .export-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--white);
    padding: 14px 28px;
    border: none;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0, 86, 179, 0.25);
    min-width: 160px;
    justify-content: center;
    text-align: center;
}

.print-btn:hover, .export-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0, 86, 179, 0.35);
    background: linear-gradient(135deg, #004494, var(--primary-color));
}

.print-btn::before {
    content: '🖨️';
    font-size: 1.1em;
}

.export-btn::before {
    content: '📤';
    font-size: 1.1em;
}

.disclaimer {
    font-size: 0.85em;
    color: rgba(255, 255, 255, 0.8);
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.5;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    header {
        padding: 1.5em 0;
    }

    header h1 {
        font-size: 2.5rem;
        font-weight: 800;
        letter-spacing: -0.02em;
        line-height: 1.1;
        text-align: center;
    }

    .theme-toggle {
        top: 0.5em;
        right: 1em;
    }

    main {
        margin: 10px;
        padding: 15px;
    }

    section {
        padding: 20px 15px;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .button-group {
        flex-direction: column;
    }

    .calculate-btn, .reset-btn {
        width: 100%;
    }

    .table-container {
        margin: 0 -15px;
        border-radius: 0;
    }

    table {
        font-size: 0.8em;
        min-width: 500px;
    }

    th, td {
        padding: 8px 6px;
        font-size: 0.85em;
    }

    .footer-actions {
        gap: 15px;
        justify-content: center;
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .print-btn, .export-btn {
        min-width: 140px;
        padding: 12px 20px;
    }
}

@media (max-width: 480px) {
    header {
        padding: 1.2em 0;
    }

    header h1 {
        font-size: 2rem;
        font-weight: 800;
        letter-spacing: -0.02em;
        line-height: 1.1;
        text-align: center;
    }

    main {
        margin: 5px;
        padding: 10px;
    }

    section {
        padding: 15px 10px;
    }

    .table-container {
        margin: 0 -10px;
    }

    table {
        font-size: 0.75em;
        min-width: 450px;
    }

    th, td {
        padding: 6px 4px;
    }

    .print-btn, .export-btn {
        min-width: 110px;
        padding: 10px 14px;
        font-size: 0.85em;
        flex: none;
        white-space: nowrap;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: black;
    }

    header, footer, .theme-toggle, .button-group {
        display: none;
    }

    main {
        box-shadow: none;
        margin: 0;
        padding: 0;
    }

    section {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
