/*
 * Components derived from the DESIGN.md tokens.
 *
 * DESIGN.md is a marketing-site system: it defines no table, form, input or modal. Its own
 * note — "Any screen added to this system needs the same generosity" — licenses the
 * derivations below. Rules carried over unchanged: no shadows anywhere, body line height
 * 1.75, and one deep-green call to action per screen (everything else is outline or text).
 */

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

body {
    margin: 0;
    background: var(--color-surface);
    color: var(--color-on-surface);
    font-family: var(--font-sans);
    font-size: var(--text-body-md);
    line-height: var(--leading-body);

    /* Sticky footer: short pages (a single search result, the 404) would otherwise leave
       the footer floating mid-screen with blank page below it. */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--color-primary); }

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- Chrome ---------- */

.site-header {
    background: var(--color-dark);
    color: var(--color-on-primary);
}

.site-header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-lg);
    min-height: 64px;
}

.site-header__brand {
    color: var(--color-on-primary);
    font-size: var(--text-body-lg);
    letter-spacing: 0.02em;
    text-decoration: none;
}

.site-header__nav a {
    color: var(--color-on-primary);
    padding: var(--space-md);
    text-decoration: none;
}

.site-footer {
    flex-shrink: 0;
    margin-top: var(--space-2xl);
    padding: var(--space-xl) 0;
    background: var(--color-dark);
    color: rgb(255 255 255 / 0.8);
    font-size: var(--text-label-md);
}

main.container {
    /* Takes the leftover height so the footer is pushed to the bottom of the viewport. */
    flex: 1 0 auto;
    padding-top: var(--space-xl);
}

/* ---------- Page head ---------- */

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.headline-lg {
    margin: 0;
    font-size: var(--text-headline-lg);
    font-weight: 500;
    line-height: var(--leading-tight);
}

.page-head__meta {
    margin: var(--space-xs) 0 0;
    color: var(--color-muted);
    font-size: var(--text-label-md);
}

/* ---------- Banners ---------- */

.banner {
    margin: 0 0 var(--space-lg);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--text-body-md);
}

.banner--success {
    background: var(--color-neutral-tint);
    border-left: 3px solid var(--color-primary);
}

.banner--error {
    background: #FCEDEC;
    border-left: 3px solid var(--color-danger);
    color: var(--color-danger);
}

.banner--error:empty { display: none; }

.banner--error ul {
    margin: 0;
    padding-left: var(--space-lg);
}

/* ---------- Filters ---------- */

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-md);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    background: var(--color-neutral-tint);
    border-radius: var(--radius-md);
}

.filters .field { flex: 1 1 200px; margin: 0; }

.filters__actions {
    display: flex;
    gap: var(--space-sm);
}

/* ---------- Fields ---------- */

.field { margin-bottom: var(--space-md); }

.field__label {
    display: block;
    font-size: var(--text-label-md);
    color: var(--color-muted);
}

.field__input {
    width: 100%;
    min-height: 42px;
    padding: var(--space-xs) var(--space-sm);
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-xs);
    color: inherit;
    font-family: inherit;
    font-size: var(--text-body-md);
}

.field__input:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.field__hint {
    display: block;
    color: var(--color-muted);
    font-size: var(--text-label-md);
}

.field__error {
    display: block;
    color: var(--color-danger);
    font-size: var(--text-label-md);
}

.field__error:empty { display: none; }

.field--checkbox {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.field--checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--color-primary);
}

.field--checkbox label { font-size: var(--text-body-md); }

.field--checkbox .field__hint { flex-basis: 100%; }

/* Hidden companion input the checkbox tag helper emits for the unchecked case. */
.field--checkbox input[type="hidden"] { display: none; }

/* ---------- Buttons ---------- */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 45px;
    padding: var(--space-xs) var(--space-lg);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--text-body-md);
    line-height: var(--leading-body);
    text-decoration: none;
    cursor: pointer;
}

/* The single filled action per screen — brand green stays a text and mark color. */
.button--primary {
    background: var(--color-primary-dark);
    color: var(--color-on-primary);
}

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

.button--danger {
    background: transparent;
    border-color: var(--color-danger);
    color: var(--color-danger);
}

/* ---------- Table ---------- */

.table-scroll {
    /* position:relative makes this the containing block for the visually-hidden header
       label, so the clip below catches it; otherwise it escapes and widens the page. */
    position: relative;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-body-md);
}

.table th,
.table td {
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

.table thead th {
    background: var(--color-neutral);
    font-weight: 500;
    font-size: var(--text-label-md);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
}

.table tbody tr:nth-child(even) { background: var(--color-neutral-tint); }

.table .is-numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.row-actions {
    display: flex;
    gap: var(--space-md);
}

.status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: transparent;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: var(--text-label-md);
    line-height: 1.2;
    cursor: pointer;
}

.status:hover { background: var(--color-neutral); }

.status:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.status::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: currentColor;
}

.status--active { color: var(--color-primary); }
.status--inactive { color: var(--color-muted); }

/* ---------- Pager ---------- */

/* A footer band on the table, in the same tone as the table header: the grouping is tonal,
   which is how this system separates things (DESIGN.md forbids borders and shadows here). */
.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-lg);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-neutral);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.pager__control {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.pager__control label {
    color: var(--color-muted);
    font-size: var(--text-label-md);
    white-space: nowrap;
}

.pager__control select {
    min-height: 34px;
    padding: 0 var(--space-xs);
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-xs);
    color: inherit;
    font-family: inherit;
    font-size: var(--text-body-md);
}

.pager__control select:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.pager__range {
    color: var(--color-muted);
    font-size: var(--text-label-md);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.pager__arrows {
    display: flex;
    gap: var(--space-xs);
}

.pager__arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    color: var(--color-primary);
    font-size: var(--text-headline-md);
    line-height: 1;
    text-decoration: none;
}

.pager__arrow:hover { background: var(--color-neutral-tint); }

.pager__arrow.is-disabled {
    color: var(--color-muted);
    opacity: 0.4;
}

.pager__go {
    min-height: 34px;
    padding: 0 var(--space-md);
    background: var(--color-primary-dark);
    border: 0;
    border-radius: var(--radius-xs);
    color: var(--color-on-primary);
    font-family: inherit;
    cursor: pointer;
}

/* ---------- SweetAlert2 ---------- */

/* buttonsStyling is off, so these classes carry the whole button look. */
.swal-popup {
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    /* No elevation anywhere in this system; the hairline does the separating. */
    box-shadow: none;
    font-family: var(--font-sans);
    font-size: var(--text-body-md);
    line-height: var(--leading-body);
}

.swal-title {
    font-size: var(--text-headline-md);
    font-weight: 500;
    line-height: var(--leading-tight);
}

.swal-confirm,
.swal-cancel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 45px;
    margin: 0 var(--space-xs);
    padding: var(--space-xs) var(--space-lg);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--text-body-md);
    cursor: pointer;
}

/* Destructive, so red rather than the brand green reserved for ordinary actions. */
.swal-confirm {
    background: var(--color-danger);
    color: var(--color-on-primary);
}

.swal-cancel {
    background: transparent;
    border-color: var(--color-line);
    color: var(--color-on-surface);
}

.swal-toast {
    border: 1px solid var(--color-line);
    border-left: 3px solid var(--color-primary);
    border-radius: var(--radius-md);
    box-shadow: none;
    font-family: var(--font-sans);
}

@media (max-width: 640px) {
    .pager {
        justify-content: space-between;
        gap: var(--space-sm);
    }
}

/* ---------- Modal ---------- */

/* Native <dialog>: the browser handles Escape, focus trapping, and the backdrop. */
.modal {
    width: min(560px, calc(100vw - 2 * var(--space-lg)));
    padding: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    /* No elevation in this system, so a hairline stands in for the usual dialog shadow. */
    box-shadow: none;
    color: var(--color-on-surface);
}

.modal::backdrop { background: rgb(0 0 0 / 0.45); }

.modal__form { padding: var(--space-lg); }

.modal__title {
    margin: 0 0 var(--space-md);
    font-size: var(--text-headline-md);
    font-weight: 500;
    line-height: var(--leading-tight);
}

.modal__body {
    max-height: min(60vh, 520px);
    overflow-y: auto;
}

.modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

/* ---------- Panels ---------- */

.form-panel {
    max-width: 560px;
    padding: var(--space-lg);
    background: var(--color-neutral-tint);
    border-radius: var(--radius-md);
}

.panel--message {
    padding: var(--space-2xl) var(--space-lg);
    background: var(--color-neutral);
    border-radius: var(--radius-md);
    text-align: center;
}

.form-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

.confirm-lead { margin-top: 0; }

.record {
    margin: 0;
    display: grid;
    gap: var(--space-xs);
}

.record > div {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: var(--space-sm);
}

.record dt {
    color: var(--color-muted);
    font-size: var(--text-label-md);
}

.record dd { margin: 0; }

@media (max-width: 640px) {
    .page-head { align-items: flex-start; }
    .filters__actions { width: 100%; }
    .record > div { grid-template-columns: 1fr; }
}
