/* ui/theme @ v1.0 — base stylesheet.
 *
 * Consumes ONLY the custom properties generated from the PHP token set. No
 * literal colour, size or font appears below: change the look by changing a
 * token, never by editing this file.
 *
 * RTL: every directional rule uses CSS *logical* properties
 * (margin-inline-start, padding-block, text-align: start, inset-inline) rather
 * than left/right. Arabic RTL therefore works from the `dir` attribute alone,
 * with no mirrored second stylesheet to keep in sync. Do not introduce
 * margin-left / padding-right / float: right — the test suite fails on them.
 */

/* ---------------------------------------------------------------- reset */

*,
*::before,
*::after {
    box-sizing: border-box;
}

body,
h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd {
    margin: 0;
}

/* ------------------------------------------------------------- document */

html {
    font-size: var(--font-size);
}

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-fg);
    font-family: var(--font-family);
    line-height: var(--font-line-height);
    -webkit-text-size-adjust: 100%;
}

/* Arabic sits better with slightly looser lines than Latin. */
.lang-ar body,
body.lang-ar {
    line-height: calc(var(--font-line-height) + 0.15);
}

/* --------------------------------------------------------------- layout */

.container {
    max-inline-size: var(--layout-max-width);
    margin-inline: auto;
    padding-inline: var(--space-3);
}

.stack > * + * {
    margin-block-start: var(--space-3);
}

.card {
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    box-shadow: var(--shadow-card);
}

/* ----------------------------------------------------------- typography */

h1, h2, h3 {
    font-weight: var(--font-weight-bold);
    line-height: 1.25;
    text-align: start;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }

.muted {
    color: var(--color-muted);
}

a {
    color: var(--color-primary);
}

/* ---------------------------------------------------------------- forms */

label {
    display: block;
    margin-block-end: var(--space-1);
    text-align: start;
}

input,
select,
textarea {
    inline-size: 100%;
    block-size: var(--layout-field-height);
    padding-inline: var(--space-2);
    font-family: inherit;
    font-size: 1rem;
    color: var(--color-fg);
    background: var(--color-bg);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-sm);
    text-align: start;
}

textarea {
    block-size: auto;
    padding-block: var(--space-2);
}

/* v1.10 — A CHECKBOX AND A RADIO ARE NEVER FULL-WIDTH, WHEREVER THEY APPEAR.
   The rule above sizes every control to the field row, which is right for text
   inputs and selects and wrong for a box with a glyph in it. Until now the two
   exceptions were POSITIONAL — `.field--checkbox input` and
   `.radio-group__option input` — so they only worked inside their wrappers, and
   `ui/elements`' `cell: true` mode renders a BARE input with no wrapper (that is
   the whole point of the mode). It matched neither and kept the 100%: the box
   filled the table cell with the glyph floating in the middle.
   Typed rather than positional, so it holds for a control anywhere — and it
   SUBSUMES both former rules, which set exactly these two properties on exactly
   these controls. */
input[type="checkbox"],
input[type="radio"] {
    inline-size: auto;
    block-size: auto;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 1px;
}

/* ------------------------------------------------- form rows (ui/elements) */

.field + .field {
    margin-block-start: var(--space-3);
}

.field__help {
    margin-block-start: var(--space-1);
    font-size: var(--font-size-sm);
    color: var(--color-muted);
    text-align: start;
}

.field__error {
    margin-block-start: var(--space-1);
    font-size: var(--font-size-sm);
    color: var(--color-danger);
    text-align: start;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border-color: var(--color-danger);
}

.field--checkbox label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-block-end: 0;
}


/* v1.6 — the radio GROUP ui/elements v1.3 renders. `border: 0` because the
   <fieldset> is here only for the <legend> a group needs; its default frame
   would draw a box nothing else on a form has. The <legend> is NOT a flex item
   — a fieldset's legend is taken out of that flow by the browser — so it sits
   above the options and the margin below it really does separate them. Shape
   proven live in jimpshini's person form (v6.27) before it was lifted here. */
.field--radio .radio-group {
    border: 0;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

/* Matches the weight a generated <label> gets, so a group heading does not read
   as a different KIND of label than the fields around it. */
.field--radio legend {
    padding: 0;
    margin-block-end: var(--space-1);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-sm);
}

/* The whole option is the label, so the text is part of the hit target rather
   than a word sitting beside a small circle. */
.radio-group__option {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin-block-end: 0;
    cursor: pointer;
}


/* The group carries aria-invalid, not the inputs — so the errored state has to
   be drawn from the group, which the input[aria-invalid] rule above cannot do. */
.radio-group[aria-invalid="true"] legend {
    color: var(--color-danger);
}

.required-mark {
    color: var(--color-danger);
    margin-inline-start: var(--space-1);
}

/* --------------------------------------------------------------- button */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    block-size: var(--layout-field-height);
    padding-inline: var(--space-4);
    font-family: inherit;
    font-size: 1rem;
    font-weight: var(--font-weight-bold);
    color: var(--color-primary-fg);
    background: var(--color-primary);
    border: var(--border-width) solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.button--secondary {
    color: var(--color-fg);
    background: var(--color-surface);
    border-color: var(--color-border);
}

.button--danger {
    color: var(--color-danger-fg);
    background: var(--color-danger);
}

.button[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* -------------------------------------------------------------- messages */

.message {
    padding: var(--space-3);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-sm);
    border-inline-start-width: var(--space-1);
    text-align: start;
}

.message--error {
    border-inline-start-color: var(--color-danger);
    color: var(--color-danger);
}

.message--success {
    border-inline-start-color: var(--color-success);
    color: var(--color-success);
}

/* v1.9 — the third state: not a failure, not good news, but it CHANGES HOW
   THE DATA ABOVE IT SHOULD BE READ (a truncated table, a total that excludes
   something). `error` would train readers to ignore red; `info` lets it be
   skimmed past. */
.message--warning {
    border-inline-start-color: var(--color-warning);
    color: var(--color-warning);
}

/* Screen-reader-only text: still needed even with no inline styles allowed. */
.visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
