/* Forms - the inputs, the stacked .form layout, fields that slide open,
   checkboxes and file inputs. Loaded on every page (base.html), right
   after base.css: the login and create-account pages have forms too. */

.input {
    padding: var(--vpad) 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--gray-0);
    color: var(--text);
    font: inherit;
    /* After `font` - the shorthand resets line-height to `normal`, which
       inputs and selects each resolve to a different height. */
    line-height: 1.25;
}

.input:focus {
    outline: 1px solid var(--red-pastel);
}

/* A multi-line text box (a support ticket's message and comments): it can
   be dragged taller, never wider - wider would push it out of its card. */
textarea.input {
    resize: vertical;
}

/* Shown but not editable (e.g. the email that comes with an invitation, the
   calibrate page's boxes until a machine is chosen) - grayed out: a lighter
   background than a usable box's black, muted text, and no text cursor
   suggesting you can type in it. */
.input:disabled {
    background: var(--gray-2);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* The browser's own dropdown arrow is pinned to the right edge and ignores
   padding, so it's switched off and redrawn as a background image, which
   can be positioned. The SVG can't read CSS variables - its stroke is
   --text-muted (#909090) written out, URL-encoded as %23909090. The site's
   own dropdown's button (below) has the same arrow. */
:is(select.input, .dropdown__button) {
    appearance: none;
    padding-right: 2.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23909090' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2 5l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    cursor: pointer;
}

/* Shared layout for a stacked form - label above each field, even gaps,
   buttons bottom-right (in an .actions row). Page-specific extras (e.g. the profile
   image controls) stay in that page's own CSS. */
.form {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
    max-width: var(--width-form);
}

.form label {
    font-size: var(--font-sm);
    color: var(--text-muted);
}

/* Room above a label (or a group of fields) that follows a field (+: the
   element right before it; :is(): any of these) - a text box or dropdown,
   a file input, a field that slides open, a checkbox row, a group, a row
   of buttons in the middle of the form (a machine's Restore factory
   tolerances), a phone number's row - so between one field and the next,
   but never above the form's first label or below its last field. */
.form :is(.input, .dropdown, .date-field, input[type="file"], .reveal, .checkbox-field, fieldset, .button-row, .phone-field, .form-note) + :is(label, fieldset) {
    margin-top: 0.5rem;
}

/* A group of fields under one caption - a <fieldset> and its <legend>: a
   supporter's departments, Book service's day. The browser draws a border,
   padding and a margin round a fieldset; here the fields inside are what's
   seen, so none of them. min-width: 0 - a fieldset is otherwise never
   narrower than its content, so a calendar couldn't scroll sideways inside
   one on a phone. */
.form fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

/* The group's caption reads like the form's labels. */
.form legend {
    padding: 0;
    font-size: var(--font-sm);
    color: var(--text-muted);
}

/* A line between parts of a form (a device's What customers see - what
   and from when), the same room above and below it. An <hr> rather than a
   fieldset's own top border, which the browser draws through its legend.
   No auto margins at its sides (the browser's own), so it spans the form. */
.form hr {
    margin: 0.5rem 0;
    border: 0;
    border-top: 1px solid var(--border);
}

/* A field that slides open (.reveal, below): its label (or a group's
   fieldset) is the first thing inside the part that slides, so the room
   above it goes there too - as padding, inside, so it slides shut with the
   field instead of leaving a gap behind. */
.form .reveal__inner > :is(label, fieldset):first-child {
    padding-top: 0.5rem;
}

/* A note in a form (e.g. what saving a change does) - quiet, like the
   labels: background information, not something to fill in. */
.form-note {
    font-size: var(--font-sm);
    color: var(--text-muted);
    padding-top: 0.25rem;
}

/* The form's own gap is tight (it keeps each label close to its field),
   so the buttons need extra room to read as separate from the last field. */
.form .actions {
    margin-top: 1rem;
}

/* === Dropdowns === */

/* The site's own dropdown (js/dropdown.js): a button showing the chosen
   option, its list opening under it. The <select> it stands for stays, only
   invisible (opacity - not visibility or display: none, which would stop the
   browser focusing it to say a required one is empty) and unclickable, in
   the same grid cell as the button: the cell is as wide as the <select>
   would be - its longest option - so the button takes the room the <select>
   took, wherever it is. minmax(0, ...) - where the room is narrower (a
   filter's column), the button is, its text cut off with "...". A date
   field (js/date_picker.js, below) is built the same way round its date
   input. */
:is(.dropdown, .date-field) {
    display: inline-grid;
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
}

/* Hidden with its <select> (or date input) - the scripts copy its hidden
   onto the wrapper, and display here would otherwise beat it. */
:is(.dropdown, .date-field)[hidden] {
    display: none;
}

.dropdown > select,
.date-field > input,
:is(.dropdown__button, .date-field__button) {
    grid-area: 1 / 1;
}

:is(.dropdown > select, .date-field > input) {
    opacity: 0;
    pointer-events: none;
}

:is(.dropdown__button, .date-field__button) {
    width: 100%;
    text-align: left;
}

/* The <select> (or date input) focused by the browser, to say a required
   one is empty - the button under its message looks focused. */
:is(.dropdown:has(> select:focus), .date-field:has(> input:focus)) > button {
    outline: 1px solid var(--red-pastel);
}

:is(.dropdown__value, .date-field__value) {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Open: the arrow points up, and the outline of a focused field stays. */
.dropdown__button[aria-expanded="true"] {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23909090' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2 11l6-6 6 6'/%3E%3C/svg%3E");
}

/* The list - like Book service's list of technicians: a raised panel of
   the cards' lighter gray; a date field's calendar too. A popover, so the
   browser's own popover look (centred in the window, its own border and
   colours) is undone; the script places it (top, left, its width and
   height). */
:is(.dropdown__list, .date-picker) {
    position: fixed;
    inset: auto;
    margin: 0;
    padding: 0.25rem;
    max-width: calc(100vw - 1rem);
    overflow-y: auto;
    color: var(--text);
    background-color: var(--gray-2);
    border: 1px solid var(--border-lighter);
    border-radius: var(--radius);
    box-shadow: var(--shadow-raised);
    opacity: 1;
    transition: opacity var(--trans) ease;
}

/* Fading in as it opens (@starting-style - where it starts from). */
@starting-style {
    :is(.dropdown__list, .date-picker):popover-open {
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    :is(.dropdown__list, .date-picker) {
        transition: none;
    }
}

/* An option: its text, and a tick at its right end when it's the chosen
   one. The one under the mouse or the keyboard (--active) lighter; the
   chosen one tinted red, more so when it's also the active one. */
.dropdown__option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0.5rem;
    font-size: var(--font-sm);
    border-radius: var(--radius);
    cursor: pointer;
}

/* An option's text on one line, so the list is as wide as its widest
   option (or its button - dropdown.js); one wider than the window is cut
   off with "..." (the list's max-width). min-width: 0 - a flex item is
   otherwise never narrower than its text. */
.dropdown__text {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.dropdown__option--active {
    background-color: var(--gray-3);
}

.dropdown__option[aria-selected="true"] {
    color: var(--red-pastel);
    background-color: color-mix(in srgb, var(--red-pastel) 12%, transparent);
}

.dropdown__option[aria-selected="true"].dropdown__option--active {
    background-color: color-mix(in srgb, var(--red-pastel) 20%, transparent);
}

/* One that can't be chosen (another company's, for one) - there, faded. */
.dropdown__option[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.45;
}

/* The tick: a box's right and bottom edges, turned 45 degrees. Only the
   chosen option's is seen - the others keep its room, so the texts line
   up. */
.dropdown__check {
    flex-shrink: 0;
    width: 0.35rem;
    height: 0.65rem;
    margin: 0 0.2rem -0.1rem auto;
    border: solid currentColor;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) translateY(-0.15rem);
    visibility: hidden;
}

.dropdown__option[aria-selected="true"] .dropdown__check {
    visibility: visible;
}

/* A group's name (<optgroup> - "Scanners") over its options, small and
   quiet; a line above every group but the first. */
.dropdown__group {
    padding: 0.5rem 0.5rem 0.25rem;
    font-size: var(--font-xs);
    text-transform: uppercase;
    color: var(--text-muted);
}

.dropdown__list > [role="group"] + [role="group"] {
    margin-top: 0.25rem;
    border-top: 1px solid var(--border);
}

/* === Date fields === */

/* A date field's button (js/date_picker.js) - the date in the page's
   language, a calendar drawn at its right end like a dropdown's arrow (the
   same --text-muted, written out); "Choose a date" quieter while there's
   none. */
.date-field__button {
    padding-right: 2.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 16 16'%3E%3Cg fill='none' stroke='%23909090' stroke-width='1.5' stroke-linecap='round'%3E%3Crect x='1.75' y='3' width='12.5' height='11.25' rx='1.5'/%3E%3Cpath d='M1.75 6.5h12.5M5 1.5v3M11 1.5v3'/%3E%3C/g%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    cursor: pointer;
}

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

/* The calendar: the month and its arrows, the days, then Clear and Today.
   Never scrolled - always shown whole (placePopover(..., whole), which
   gives it no max-height): overflow visible, so not even a scrollbar for
   a rounding pixel. */
.date-picker {
    padding: 0.5rem;
    overflow: visible;
}

/* Its gray buttons (the arrows, Clear, Today) a shade lighter than the
   panel they're on, which is the gray they'd otherwise be - the next gray
   inside a block of one (base.css's grays). Two classes, like .btn.btn--gray. */
.date-picker .btn--gray {
    background: var(--gray-3);
}

.date-picker .btn--gray:hover {
    background: var(--gray-4);
}

.date-picker__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

/* The arrows - small square gray buttons, like the site's calendars'. */
.date-picker__arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
}

.date-picker__title {
    font-weight: bold;
    font-size: var(--font-sm);
}

/* Each week (and the weekdays' names) a row of seven equal columns
   across the whole calendar, which is as wide as its field when that's
   wider than a week of days - the days spread out to fill it, each a round
   button in the middle of its cell. A grid, not the table's own layout: a
   table at width: 100% in a calendar only as wide as its content stretches
   it across the window (Chrome). The rows keep role="row" (the script), so
   it's still read as a table of days. */
.date-picker__grid,
.date-picker__grid :is(thead, tbody) {
    display: block;
}

.date-picker__grid tr {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

.date-picker__grid th {
    padding: 0.25rem 0;
    font-size: var(--font-xs);
    font-weight: normal;
    color: var(--text-muted);
    text-align: center;
}

.date-picker__grid td {
    padding: 1px;
    text-align: center;
}

/* A day: its number in a circle, the digits all one width so 11 isn't
   narrower than 18 - like the site's calendars' days. */
.date-picker__day {
    width: 2rem;
    height: 2rem;
    padding: 0;
    font: inherit;
    font-size: var(--font-sm);
    font-variant-numeric: tabular-nums;
    color: var(--text-darker);
    background: none;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.date-picker__day:hover:not(:disabled) {
    color: var(--text);
    background-color: var(--gray-3);
}

.date-picker__day:focus-visible {
    outline: 1px solid var(--red-pastel);
}

/* Today in a filled circle of the site's red, like every calendar's. */
.date-picker__day[aria-current="date"] {
    color: var(--text);
    font-weight: bold;
    background-color: var(--red);
}

/* The chosen day tinted red, like a dropdown's chosen option - with a ring
   when it's today too, its fill being red already. */
[aria-selected="true"] > .date-picker__day {
    color: var(--red-pastel);
    background-color: color-mix(in srgb, var(--red-pastel) 20%, transparent);
}

[aria-selected="true"] > .date-picker__day[aria-current="date"] {
    color: var(--text);
    background-color: var(--red);
    box-shadow: 0 0 0 2px var(--red-pastel);
}

/* Outside the field's min / max - there, faded, not clickable. */
.date-picker__day:disabled {
    cursor: not-allowed;
    opacity: 0.35;
}

.date-picker__foot {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

/* === Phone numbers === */

/* A phone number's country code and the number on one row
   (authentication/phone_field.html), 2 parts to 3 of the row (fr - a share
   of the room) - not the dropdown's own width, which for "Bosnia and
   Herzegovina +387" would leave the number no room on a phone; a long name
   is cut off in the closed dropdown instead. minmax(0, ...) - a grid
   column is otherwise never narrower than its content. */
.phone-field {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    gap: 0.5rem;
}

/* === Fields that slide open === */

/* A form field that slides open/closed - the profile's current password,
   a supporter's departments, a license's number and expiration date (their page's script toggles
   .reveal--open). Same trick as the sidebar's .nav-sub: height can't be
   animated to/from `auto`, but a one-row grid can go from 0fr to 1fr. */
.reveal {
    display: grid;
    grid-template-rows: 0fr;
    /* Closed, it's still an item in the form's flex column, so the form's
       0.25rem gap would leave an empty sliver - pulled back up while closed. */
    margin-top: -0.25rem;
    /* Keeps the closed input out of the Tab order; transitioning it delays
       the switch to hidden until the row has finished closing. */
    visibility: hidden;
}

.reveal--open {
    grid-template-rows: 1fr;
    margin-top: 0;
    visibility: visible;
}

/* Only added by the script after the page's starting state is set - so the
   field doesn't visibly slide shut on every page load. */
.reveal--animated {
    transition: grid-template-rows var(--trans) ease, margin-top var(--trans) ease, visibility var(--trans);
}

/* Laid out like the rest of the form (label above input, same gap).
   overflow: hidden clips it while the row is shorter than its content;
   the 1px padding/negative margin pair leaves room for the input's focus
   outline, which would otherwise be clipped too. */
.reveal__inner {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-height: 0;
    overflow: hidden;
    padding: 1px;
    margin: -1px;
}

/* === Checkboxes === */

/* A checkbox (or a radio button) next to its label, on one line (profile's
   SMS notifications, a license's Subscription, a ticket's remote session) -
   .form stacks everything else label-over-field.
   The room a label gets above it when it follows a field goes on the whole
   row instead (padding-top): on the label it would push the label below the
   middle of its checkbox. */
.checkbox-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.5rem;
}

.checkbox-field input:is([type="checkbox"], [type="radio"]) {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--red);
    cursor: pointer;
}

.checkbox-field label {
    cursor: pointer;
}

/* === File inputs === */

input[type="file"]::file-selector-button {
    padding: var(--vpad) var(--hpad);
    margin-right: 0.75rem;
    background: var(--gray-2);
    color: var(--text);
    border: 0;
    border-radius: var(--radius);
    font: inherit;
    cursor: pointer;
    transition: background-color var(--trans) ease;
}

input[type="file"]::file-selector-button:hover {
    background: var(--gray-3);
}

/* The saved image on an edit page (profile, milling machine model), shown
   above the file input that replaces it, with a way to remove it. */
.current-image {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.current-image__preview {
    width: 3rem;
    height: 3rem;
    object-fit: contain;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* The "Remove image" button (image_remove.js) - a button, since it does
   something, but looking like a small red link. */
.remove-label {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    font-size: var(--font-sm);
    color: var(--red);
    text-decoration: underline;
    cursor: pointer;
}

/* === The per-axis fields === */

/* A milling machine model's per-axis fields and a milling machine's own
   tolerances, as a small table: a row per axis (X, Y, Z), a column per
   value (a model's drive, warning, alarm). Every child of .axis-grid is one
   cell, filled in left to right, a new row every 4 cells. */
.axis-grid {
    display: grid;
    /* The axis letter only as wide as it needs to be, the fields sharing
       the rest equally. */
    grid-template-columns: auto 1fr 1fr 1fr;
    gap: 0.5rem;
    align-items: center;
    /* The same space above as a .form label has, so it doesn't sit tighter
       under the field before it than the other fields do. */
    padding-top: 0.5rem;
}

/* A machine's tolerances - no drive, so a new row every 3 cells. Its
   Restore factory tolerances button (a .button-row) right under it. */
.axis-grid--limits {
    grid-template-columns: auto 1fr 1fr;
}

/* A field's natural width is wider than a third of the form - without
   min-width: 0 a grid column never shrinks below its contents, and the
   fields would stick out of the card. */
.axis-grid .input {
    min-width: 0;
}

/* Column headings, styled like the form's labels. */
.axis-grid__head {
    font-size: var(--font-sm);
    color: var(--text-muted);
}

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

/* The row of buttons right under the grid (a machine's Restore factory
   tolerances) - the grid's own gap between its rows, not the form's tighter
   one, so it doesn't read as the grid's last row. */
.form .axis-grid + .button-row {
    margin-top: 0.25rem;
}
