/* Base styles: reset, typography, links, forms, buttons and focus. Reads tokens.css only. */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* a focused element must not end up under the sticky table header */
    scroll-padding-top: var(--space-7);
    -webkit-tap-highlight-color: transparent;
}

/* The hidden attribute must win over any display rule of the stylesheets (e.g. table rows turned into blocks) */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: var(--text-md);
    font-weight: var(--weight-regular);
    line-height: var(--leading);
    text-rendering: optimizeLegibility;
}

::selection {
    background: var(--selection);
    color: var(--ink);
}

/* ---- Typography ---- */
h1,
h2,
h3 {
    margin: 0 0 var(--space-3);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-tight);
    text-wrap: balance;
}

h1 {
    font-size: var(--text-xl);
}

h2 {
    font-size: var(--text-lg);
}

h3 {
    margin-top: var(--space-4);
    font-size: var(--text-md);
}

p {
    margin: 0 0 var(--space-3);
    text-wrap: pretty;
}

strong {
    font-weight: var(--weight-semibold);
}

small {
    font-size: var(--text-xs);
}

/* Machine values (identifiers, secrets, codes, addresses, links) are the only monospace text */
code,
kbd,
samp,
.mono {
    font-family: var(--font-mono);
    font-size: 0.95em;
    font-variant-numeric: tabular-nums;
}

/* Numbers align in columns */
table,
dd,
time,
.num {
    font-variant-numeric: tabular-nums;
}

/* ---- Links ---- */
a {
    color: var(--ink);
    text-decoration: underline;
    text-decoration-color: var(--brass);
    text-decoration-thickness: var(--focus-width);
    text-underline-offset: 0.2em;
}

a:hover {
    text-decoration-thickness: var(--marker);
}

/* ---- Forms ---- */
form {
    margin: 0;
}

label {
    display: block;
    margin-top: var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
}

input,
select,
textarea {
    display: block;
    width: 100%;
    min-height: var(--control-height);
    margin-top: var(--space-1);
    padding: var(--space-2) var(--space-3);
    border: var(--hairline) solid var(--control-border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    transition: border-color var(--duration) var(--easing);
}

input[type="checkbox"],
input[type="radio"] {
    display: inline-block;
    width: auto;
    min-height: 0;
    accent-color: var(--brass);
}

select option {
    background: var(--surface);
    color: var(--ink);
}

input[readonly] {
    background: var(--bg);
}

input[aria-invalid="true"] {
    border-color: var(--error);
}

input:disabled,
select:disabled,
button:disabled {
    cursor: not-allowed;
    opacity: var(--disabled-opacity);
}

/* ---- Buttons: primary (default), secondary, danger and link ---- */
/* The label is centred both ways: an <a> styled as a button would otherwise keep its text at the top of a taller box */
button,
a.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--control-height);
    padding: var(--space-2) var(--space-4);
    border: var(--hairline) solid var(--ink);
    border-radius: var(--radius);
    background: var(--ink);
    color: var(--surface);
    font: inherit;
    font-weight: var(--weight-medium);
    line-height: var(--leading-tight);
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
    transition: background-color var(--duration) var(--easing), border-color var(--duration) var(--easing);
}

button:hover,
a.button:hover {
    border-color: var(--ink-hover);
    background: var(--ink-hover);
}

/* Spacing of the action that closes a form */
form > button,
section > a.button {
    margin-top: var(--space-4);
}

button.secondary,
a.button.secondary {
    border-color: var(--control-border);
    background: var(--surface);
    color: var(--ink);
}

button.secondary:hover,
a.button.secondary:hover {
    background: var(--hover);
}

button.danger,
a.button.danger {
    border-color: var(--error);
    background: var(--error);
    color: var(--on-error);
}

button.danger:hover,
a.button.danger:hover {
    border-color: var(--error);
    background: var(--error);
    filter: brightness(var(--press-dim));
}

/* A button that reads as a link (e.g. "Volver" inside a POST form) */
.link-button {
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--ink);
    font-size: var(--text-sm);
    font-weight: var(--weight-regular);
    text-decoration: underline;
    text-decoration-color: var(--brass);
    text-decoration-thickness: var(--focus-width);
    text-underline-offset: 0.2em;
}

.link-button:hover {
    background: none;
    text-decoration-thickness: var(--marker);
}

/* A request in flight (the JS modules set aria-busy instead of disabled): only the cursor changes */
button[aria-busy="true"] {
    cursor: progress;
}

/* ---- Focus: visible brass ring on everything interactive ---- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

/* Headings that receive programmatic focus (tabindex="-1") do not need a ring */
[tabindex="-1"]:focus-visible {
    outline: none;
}

/* ---- Touch targets ---- */
@media (pointer: coarse) {
    button,
    a.button,
    input:not([type="checkbox"]):not([type="radio"]),
    select {
        min-height: var(--touch-target);
    }

    .link-button {
        min-height: var(--touch-target);
    }

    /* Links that stand alone (table actions, pager, back links, secondary links) get a touch-sized hit area */
    td a,
    .pager a,
    .back-link a,
    p.secondary a,
    .form-grid > a {
        display: inline-flex;
        align-items: center;
        min-height: var(--touch-target);
    }
}

/* ---- Motion ---- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
