/* Reset + base element styles + shared primitives (buttons, fields, cards). */

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-sans);
    font-size: var(--fs-300);
    line-height: 1.55;
    color: var(--color-text);
    background: var(--color-bg);
}

h1, h2, h3, h4 {
    margin: 0 0 var(--sp-4);
    line-height: 1.2;
    color: var(--color-primary);
    font-weight: 600;
}

p {
    margin: 0 0 var(--sp-4);
}

a {
    color: var(--c-blue-dark);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    display: block;
}

.muted {
    color: var(--color-text-muted);
}

.container {
    width: 100%;
    max-width: var(--container);
    margin-inline: auto;
    padding-inline: var(--sp-5);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 0.7rem 1.4rem;
    border: 2px solid transparent;
    border-radius: var(--radius);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
    text-decoration: none;
    transform: translateY(-1px);
}

.btn:focus-visible {
    outline: 3px solid var(--c-blue);
    outline-offset: 2px;
}

/* Primary and accent buttons share the brand-green look (client decision): green fill,
 * navy text (white on #AFCA0B fails WCAG contrast), darker green on hover. */
.btn--primary,
.btn--accent {
    background: var(--c-green);
    color: var(--c-navy);
}

.btn--primary:hover,
.btn--accent:hover {
    background: var(--c-green-hover);
}

.btn--ghost {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-primary);
}

/* Muted secondary action (e.g. the wizard "Back" buttons): brand-gray fill, navy ink
 * (white on #9D9D9C fails WCAG contrast). */
.btn--muted {
    background: var(--c-gray);
    color: var(--c-navy);
}

.btn--muted:hover {
    background: #8d8d8c; /* derived darker shade of --c-gray */
}

/* Restrained destructive action (e.g. "Remove this building"): outlined muted red
 * (same red as .form__error) that only fills lightly on hover. */
.btn--danger-ghost {
    background: transparent;
    border-color: #b3261e;
    color: #b3261e;
}

.btn--danger-ghost:hover {
    background: rgba(179, 38, 30, 0.08);
}

.btn--sm {
    padding: 0.4rem 0.9rem;
    font-size: var(--fs-200);
}

/* --- Form fields --- */
.field {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.field__label {
    font-weight: 600;
    font-size: var(--fs-200);
}

.select,
.input {
    width: 100%;
    padding: 0.65rem 0.8rem;
    font: inherit;
    color: var(--color-text);
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.select:focus,
.input:focus {
    outline: 2px solid var(--c-blue);
    outline-offset: 1px;
    border-color: var(--c-blue);
}

/* --- Searchable country combobox (countrySelect.js) ---
   Fronts a hidden native <select>: the toggle mimics .select, the panel holds a search box and
   the filtered list. The native select still submits the value. */
.country-combo {
    position: relative;
}

.country-combo__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    width: 100%;
    padding: 0.65rem 0.8rem;
    font: inherit;
    text-align: left;
    color: var(--color-text);
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* Caret, drawn so the toggle needs no extra markup. */
.country-combo__toggle::after {
    content: "";
    flex: 0 0 auto;
    width: 0.5rem;
    height: 0.5rem;
    margin-left: auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
}

.country-combo__toggle.is-placeholder {
    color: var(--c-gray, #9d9d9c);
}

.country-combo__toggle:focus-visible {
    outline: 2px solid var(--c-blue);
    outline-offset: 1px;
    border-color: var(--c-blue);
}

/* The real <select>, kept for form submission. Hidden with opacity (not display:none) so a
   `required` select stays focusable and native validation can still point at it. */
.country-combo__native {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

/* Mirror the invalid state onto the visible toggle (JS flags the hidden select). */
.country-combo:has(.country-combo__native.is-invalid) .country-combo__toggle {
    border-color: #b3261e;
    box-shadow: 0 0 0 2px rgba(179, 38, 30, 0.15);
}

.country-combo__panel {
    position: absolute;
    z-index: 30;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-2);
}

.country-combo__search {
    width: 100%;
    padding: 0.5rem 0.6rem;
    font: inherit;
    color: var(--color-text);
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.country-combo__search:focus {
    outline: 2px solid var(--c-blue);
    outline-offset: 1px;
    border-color: var(--c-blue);
}

.country-combo__list {
    list-style: none;
    margin: var(--sp-2) 0 0;
    padding: 0;
    max-height: 15rem;
    overflow-y: auto;
    text-align: left;
}

.country-combo__option {
    padding: 0.45rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* Hover and keyboard highlight share one look so the two navigation modes agree. */
.country-combo__option:hover,
.country-combo__option.is-active {
    background: var(--c-blue);
    color: #fff;
}

.country-combo__option[aria-selected="true"] {
    font-weight: 600;
}

.country-combo__empty {
    padding: 0.45rem 0.6rem;
    color: var(--c-gray, #9d9d9c);
}

/* --- Card --- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-6);
}

.section-title {
    text-align: center;
    margin-bottom: var(--sp-6);
}

/* --- Legal / prose pages (privacy policy, cookies) --- */
.legal-page {
    max-width: 760px;
    padding-block: var(--sp-5);
}

.legal-page h2 {
    margin-top: var(--sp-6);
    font-size: var(--fs-400);
}

.legal-page ul {
    margin: 0 0 var(--sp-4);
    padding-left: 1.25rem;
}

.legal-page li {
    margin-bottom: var(--sp-2);
}

/* --- Print ---------------------------------------------------------------
 * Every colour on the result page is a background (bar segments, treemap tiles, card tints,
 * legend dots) and browsers drop backgrounds when printing, so the client's Ctrl-P came out
 * colourless. print-color-adjust: exact keeps them. Interactive chrome is dropped from the
 * printout — it is not actionable on paper. */
@media print {
    *,
    *::before,
    *::after {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body {
        background: #fff;
    }

    .page-header__nav-wrapper,
    .tabbar,
    .result__actions,
    .fp-unit-toggle,
    .fp-hint,
    .fp-edit-cta,
    .result__cta,
    .home-more {
        display: none !important;
    }

    .card,
    .total-card {
        break-inside: avoid;
    }
}
