:root {
    --primary-color: #0056b3;
    --primary-hover-color: #004085;
    --secondary-color: #6c757d;
    --danger-color: #dc3545;
    --excellent-color: #28a745;
    --good-color: #858e00;
    --bad-color: #dc3545;
    --background-color: #f8f9fa;
    --card-background-color: #ffffff;
    --text-color: #333;
    --border-color: #dee2e6;
    --shadow: 0 4px 8px rgba(0,0,0,0.1);
    --border-radius: 8px;
}

html {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Roboto', sans-serif;
    margin: 0;
    background-color: var(--background-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    color: var(--text-color);
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 100vh;
    box-sizing: border-box;
    overflow-x: hidden;
}

main {
    width: 100%;
    max-width: 700px;
    min-width: 0;
    background: var(--card-background-color);
    padding: 2.5rem;
    box-sizing: border-box;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    flex: 1;
}

.page-header {
    text-align: center;
}

.eyebrow {
    margin: 0 0 0.5rem;
    color: var(--secondary-color);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

h1 {
    text-align: center;
    color: var(--primary-color);
    margin: 0;
    font-weight: 700;
}

.intro {
    max-width: 58ch;
    margin: 1rem auto 2rem;
    line-height: 1.6;
}

h2 {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 2rem;
    font-weight: 700;
}

.calculator-section h2 {
    margin: 0 0 0.5rem;
}

.section-intro {
    max-width: 62ch;
    margin: 0 auto 1.5rem;
    color: var(--secondary-color);
    line-height: 1.6;
    text-align: center;
}

h4 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    color: var(--secondary-color);
    text-align: center;
}

form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

fieldset {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    transition: all 0.3s ease;
}

legend {
    font-weight: 500;
    color: var(--primary-color);
    padding: 0 0.5rem;
    font-size: 1.1rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.2rem;
}

label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    display: block;
}

input[type="text"],
input[type="number"] {
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

button[type="submit"] {
    padding: 1rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 500;
    transition: background-color 0.3s ease, transform 0.2s ease;
    align-self: center;
    margin-top: 1rem;
}

button[type="submit"]:hover {
    background-color: var(--primary-hover-color);
    transform: translateY(-2px);
}

#spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#result-container {
    margin-top: 2rem;
    padding: 0;
    background-color: #fdfdff;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    position: relative;
    container-type: inline-size;
    container-name: result;
}

.result-wrapper {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.cost-table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
}

#result-container h2 {
    color: var(--primary-color);
    text-align: center;
    margin: 1.5rem 0;
}

.total-cost {
    background-color: var(--danger-color);
    color: white;
    padding: 1.5rem;
    text-align: center;
}

.result-wrapper .total-cost.excellent { background-color: var(--excellent-color); }
.result-wrapper .total-cost.good { background-color: var(--good-color); }
.result-wrapper .total-cost.bad { background-color: var(--bad-color); }

.total-cost + .total-cost {
    background-color: var(--primary-color);
}


.total-cost span {
    font-size: 1.2rem;
    font-weight: 500;
    opacity: 0.9;
}

.total-cost h3 {
    margin: 0.5rem 0 0;
    font-size: clamp(1.75rem, 7vw, 2.5rem);
    font-weight: 700;
    overflow-wrap: anywhere;
    line-height: 1.2;
}

#result-container table {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    table-layout: fixed;
    border-collapse: collapse;
}

#result-container th,
#result-container td {
    padding: 0.75rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    overflow-wrap: anywhere;
    word-break: break-word;
    vertical-align: top;
    box-sizing: border-box;
}

#result-container th:first-child,
#result-container td:first-child {
    width: 40%;
}

#result-container td:last-child,
#result-container th:last-child {
    text-align: right;
}

#result-container th {
    background-color: #f2f2f2;
    font-weight: 500;
}

#result-container tr:nth-child(even) {
    background-color: #f9f9f9;
}

#result-container tr:hover {
    background-color: #f1f1f1;
}

.total-leasing-cost {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    font-weight: 500;
    font-size: 1.1rem;
    padding: 1.25rem;
    background-color: #f2f2f2;
    border-top: 2px solid var(--border-color);
}

.total-leasing-cost span:last-child {
    font-weight: 700;
    color: var(--primary-color);
}

.error-message {
    background-color: #f8d7da;
    color: #721c24;
    padding: 1rem;
    border-radius: var(--border-radius);
    text-align: center;
    margin: 1.5rem;
}

.result-section {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.result-section h4 {
    margin-top: 0;
    margin-bottom: 1rem;
    color: var(--secondary-color);
    text-align: left;
}

.car-details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
    gap: 0.75rem;
    font-size: 0.95rem;
}

.car-details-grid span {
    background-color: #f9f9f9;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.additional-calculations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
    gap: 0.75rem;
    font-size: 0.95rem;
}

.seo-content,
.faq-section {
    margin-top: 3rem;
    line-height: 1.6;
}

.seo-content h2,
.faq-section h2 {
    margin: 0 0 1rem;
    font-size: 1.5rem;
}

.seo-content h2:not(:first-child) {
    margin-top: 2rem;
}

.seo-content ul {
    margin: 0;
    padding-left: 1.5rem;
}

.seo-content li + li {
    margin-top: 0.5rem;
}

.faq-section details {
    border-top: 1px solid var(--border-color);
    padding: 1rem 0;
}

.faq-section details:last-child {
    border-bottom: 1px solid var(--border-color);
}

.faq-section summary {
    color: var(--primary-color);
    cursor: pointer;
    font-weight: 700;
}

.faq-section details p {
    margin: 0.75rem 0 0;
}

.noscript-message {
    margin-top: 2rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: #fff8e1;
}

footer {
    text-align: center;
    margin-top: 2rem;
    padding: 1rem;
    color: var(--secondary-color);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

@media (max-width: 700px) {
    body {
        padding: 1rem;
    }

    main {
        padding: 1.25rem;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

@container result (max-width: 640px) {
    #result-container table,
    #result-container tbody {
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    #result-container thead {
        display: none;
    }

    #result-container tr {
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        padding: 0.75rem 1rem;
    }

    #result-container th,
    #result-container td,
    #result-container td:last-child {
        display: grid;
        grid-template-columns: minmax(0, 1fr) max-content;
        width: auto;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        align-items: baseline;
        justify-content: stretch;
        column-gap: 0.75rem;
        padding: 0.35rem 0;
        text-align: right;
        border-bottom: 0;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    #result-container td:first-child {
        display: block;
        width: auto;
        padding-top: 0;
        padding-bottom: 0.5rem;
        text-align: left;
        font-weight: 500;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    #result-container td:not(:first-child)::before {
        content: attr(data-label);
        color: var(--secondary-color);
        font-size: 0.875rem;
        text-align: left;
        overflow-wrap: anywhere;
    }
}
