:root {
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: #eff4ff;
    --background: #f4f5f7;
    --border: #e3e6ea;
    --danger: #d92d20;
    --danger-hover: #b42318;
    --ink: #101828;
    --muted: #667085;
    --success: #12b76a;
    --surface: #ffffff;
    --radius: 8px;
    --field-width: 260px;
    /* the room one validation message takes: 4px above it and one line of it */
    --message-space: 23px;
}

* {
    box-sizing: border-box;
}

body {
    background: var(--background);
    color: var(--ink);
    font-family:
        "Roboto",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
}

/* ---------------------------------------------------------------- the card */

.form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow:
        0 1px 2px rgba(16, 24, 40, 0.04),
        0 8px 24px rgba(16, 24, 40, 0.05);
    max-width: 560px;
    padding: 24px 28px 26px;
}

.form .re-render {
    align-items: center;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    margin: -4px 0 20px;
    padding-bottom: 16px;
}

.form .re-render::before {
    color: var(--muted);
    content: "Renders of the form";
    font-size: 12px;
    font-weight: 500;
}

.field-row {
    margin-top: 16px;
}

.field-row:first-of-type {
    margin-top: 0;
}

/* --------------------------------------------------------------- the field */

/**
 * The plain elements are styled inside a cascade layer, and everything a
 * component library of its own writes is unlayered - so Material UI, or
 * anything like it, always wins over what follows without a specificity race.
 * Without the layer `input[type="text"]` alone out-specifies every class
 * Material UI puts on the same element, and its fields come out 260px wide
 * inside a full width outline.
 */
@layer demo {
    label {
        color: #344054;
        display: inline-block;
        font-size: 13px;
        font-weight: 600;
        margin: 0 0 4px;
    }

    input:not([type]),
    input[type="color"],
    input[type="date"],
    input[type="datetime"],
    input[type="datetime-local"],
    input[type="email"],
    input[type="month"],
    input[type="number"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="text"],
    input[type="time"],
    input[type="url"],
    input[type="week"],
    select,
    textarea {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        color: var(--ink);
        font-family: inherit;
        font-size: 14px;
        outline: none;
        padding: 9px 12px;
        transition:
            border-color 0.15s ease,
            box-shadow 0.15s ease;
        width: var(--field-width);
    }

    textarea {
        resize: vertical;
        vertical-align: top;
    }

    /**
     * Scoped to the demo's own card rather than to every textarea on the page:
     * a component library measures the height of one row by rendering a hidden
     * textarea, and a minimum height applied to that one is read back as the
     * height of a row.
     */
    .form textarea {
        min-height: 84px;
    }

    input:focus,
    select:focus,
    textarea:focus {
        border-color: var(--accent);
        box-shadow: 0 0 0 3px var(--accent-soft);
    }

    input[type="checkbox"],
    input[type="radio"] {
        accent-color: var(--accent);
        height: 15px;
        margin: 0 2px 0 0;
        vertical-align: -2px;
        width: 15px;
    }

    input[type="checkbox"] + label,
    input[type="radio"] + label {
        font-weight: 400;
        margin: 0;
    }

    input[disabled],
    select[disabled],
    textarea[disabled],
    select option[disabled] {
        background: #f9fafb;
        color: #98a2b3;
        cursor: not-allowed;
    }
} /* @layer demo */

.field-invalid {
    border-color: var(--danger) !important;
}

.field-valid {
    border-color: var(--success) !important;
}

/**
 * A message always sits on its own line under the field, and that line is
 * always there - held open by the rule below while there is nothing to show.
 * A field turning invalid then colours a line which was already reserved
 * instead of pushing the rest of the form down.
 */
.field-message {
    display: block;
    font-size: 12.5px;
    line-height: 19px;
    padding: 4px 0 0;
}

.field-row:has(input, select, textarea):not(:has(.field-message))::after {
    content: "";
    display: block;
    height: var(--message-space);
}

/* one group of radios shows one message, on whichever option comes first */
.field-row:has(input[type="radio"])
    + .field-row:has(input[type="radio"])::after {
    display: none;
}

.field-message-invalid {
    color: var(--danger);
}

.field-message-valid {
    color: var(--success);
}

.field-required-star,
.required {
    color: var(--danger);
    margin-left: 4px;
    vertical-align: top;
}

/* -------------------------------------------------------------- the button */

@layer demo {
    button,
    input[type="button"],
    input[type="submit"] {
        background: var(--accent);
        border: 1px solid var(--accent);
        border-radius: var(--radius);
        color: #fff;
        cursor: pointer;
        font-family: inherit;
        font-size: 13.5px;
        font-weight: 600;
        padding: 9px 18px;
        transition:
            background 0.15s ease,
            border-color 0.15s ease,
            box-shadow 0.15s ease;
    }

    button:hover,
    input[type="button"]:hover,
    input[type="submit"]:hover {
        background: var(--accent-hover);
        border-color: var(--accent-hover);
    }

    button:focus-visible,
    input[type="button"]:focus-visible,
    input[type="submit"]:focus-visible {
        box-shadow: 0 0 0 3px var(--accent-soft);
    }

    button:disabled,
    input[type="button"]:disabled,
    input[type="submit"]:disabled,
    button:disabled:hover,
    input[type="button"]:disabled:hover,
    input[type="submit"]:disabled:hover {
        background: #eaecf0;
        border-color: #eaecf0;
        color: #98a2b3;
        cursor: not-allowed;
    }
} /* @layer demo */

/* the reset button next to a submit is the quiet one */
.field-row.buttons button + button {
    background: var(--surface);
    border-color: var(--border);
    color: #344054;
    margin-left: 8px;
}

.field-row.buttons button + button:hover {
    background: var(--background);
    border-color: #d0d5dd;
}

.re-render button {
    background: var(--danger);
    border-color: var(--danger);
    font-variant-numeric: tabular-nums;
    padding: 7px 14px;
}

.re-render button:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

.field-row.full-width button,
.full-width {
    width: var(--field-width);
}

/* --------------------------------------------------------------- the notes */

.info {
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 12.5px;
    margin-top: 22px;
    padding-top: 16px;
}

.console-log {
    margin-top: 20px;
}

.console-log h3 {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    margin: 0 0 6px;
    text-transform: uppercase;
}

.console-log pre {
    background: #0b1220;
    border-radius: 10px;
    color: #d7e2f3;
    font-size: 12.5px;
    line-height: 1.55;
    margin: 0;
    min-height: 42px;
    overflow-wrap: anywhere;
    padding: 12px 14px;
    white-space: pre-wrap;
}

/* ---------------------------------- label grid widths, message follows them */

/**
 * The message is a block of its own everywhere, so a label column only has to
 * set its own width and push the message across to line up under the field.
 */
.g-label-80,
.g-label-120,
.g-label-150,
.g-label-180 {
    --label-width: 0;
}

.g-label-80 {
    --label-width: 80px;
}

.g-label-120 {
    --label-width: 120px;
}

.g-label-150 {
    --label-width: 150px;
}

.g-label-180 {
    --label-width: 180px;
}

.g-label-80 label,
.g-label-120 label,
.g-label-150 label,
.g-label-180 label {
    display: inline-block;
    width: var(--label-width);
}

.g-label-80 .field-message,
.g-label-120 .field-message,
.g-label-150 .field-message,
.g-label-180 .field-message {
    margin-left: var(--label-width);
}

/* ------------------------------------------------------------- small screens */

@media (max-width: 600px) {
    :root {
        /* a field takes the width it is given rather than a fixed one */
        --field-width: 100%;
    }

    .form {
        border-radius: 12px;
        padding: 18px 16px 20px;
    }

    /* a label grid does not survive a narrow screen; the label goes above */
    .g-label-80,
    .g-label-120,
    .g-label-150,
    .g-label-180 {
        --label-width: auto;
    }

    .g-label-80 .field-message,
    .g-label-120 .field-message,
    .g-label-150 .field-message,
    .g-label-180 .field-message {
        margin-left: 0;
    }

    .field-row.buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .field-row.buttons button + button {
        margin-left: 0;
    }

    /* a checkbox and its label belong on one line whatever the width */
    input[type="checkbox"],
    input[type="radio"] {
        width: 15px;
    }
}

