/* Inputs, radio cards, checkboxes, code boxes and the card-style dropdown (never a native select). */

.field > * + * {
    margin-top: var(--space-2);
}

.field-label {
    display: block;
    font-size: var(--text-md);
    font-weight: var(--weight-bold);
}

.field-hint {
    font-size: var(--text-sm);
    color: var(--ink-soft);
}

.field-error {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--danger);
}

.input,
.textarea {
    display: block;
    width: 100%;
    min-height: var(--field-h);
    padding: 8px var(--space-3);
    border: var(--border-thin) solid var(--line-strong);
    border-radius: var(--radius-button);
    background: var(--paper);
    font-size: var(--field-font);
}

.input:hover,
.textarea:hover {
    border-color: var(--ink-muted);
}

.input:focus,
.textarea:focus {
    border-color: var(--accent);
    outline: 1px solid var(--accent);
    outline-offset: 0;
}

.input::placeholder,
.textarea::placeholder {
    color: var(--ink-muted);
}

.input[aria-invalid='true'],
.textarea[aria-invalid='true'] {
    border-color: var(--danger);
}

.textarea {
    min-height: 120px;
    resize: vertical;
}

.input-with-icon {
    position: relative;
}

.input-with-icon svg {
    position: absolute;
    left: var(--space-4);
    top: 50%;
    width: 18px;
    height: 18px;
    color: var(--accent);
    transform: translateY(-50%);
    pointer-events: none;
}

/* A search field: the icon sits inside it, on the left. */
.input-with-icon .input {
    padding-left: 42px;
}

.input-with-icon svg {
    left: 14px;
    color: var(--ink-soft);
}

/* ---------------------------------------------------------------- radio cards */

.choice-list > * + * {
    margin-top: var(--space-3);
}

.choice {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border: var(--border-thin) solid var(--line);
    border-radius: var(--radius-card);
    background: var(--paper);
    box-shadow: var(--shadow-card);
    cursor: pointer;
}

.choice:hover {
    border-color: var(--accent);
}

.choice:has(input:checked) {
    border: var(--border-thick) solid var(--accent);
    background: var(--accent-tint);
    padding: calc(var(--space-2) - 1px) calc(var(--space-3) - 1px);
}

.choice:has(input:checked) .choice-title {
    font-weight: var(--weight-bold);
}

.choice input[type='radio'] {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin: 2px 0 0;
    accent-color: var(--accent);
}

.choice-hint {
    display: block;
    font-size: var(--text-sm);
    color: var(--ink-soft);
}

/* ---------------------------------------------------------------- checkbox */

.check {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--field-h);
    font-weight: var(--weight-semibold);
    cursor: pointer;
}

.check input[type='checkbox'] {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--accent);
}

/* ---------------------------------------------------------------- code boxes */

.code-boxes {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: var(--space-2);
    max-width: 420px;
}

.code-box {
    width: 100%;
    min-height: 64px;
    padding: 0;
    border: var(--border-thin) solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--paper);
    font-family: var(--font-mono);
    font-size: var(--text-2xl);
    text-align: center;
}

/* ---------------------------------------------------------------- card-style dropdown */

.dropdown {
    position: relative;
}

.dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    width: 100%;
    min-height: var(--field-h);
    padding: 8px var(--space-3);
    border: var(--border-thin) solid var(--line-strong);
    border-radius: var(--radius-button);
    background: var(--paper);
    font-size: var(--field-font);
    text-align: left;
    cursor: pointer;
}

.dropdown-trigger svg {
    width: 18px;
    height: 18px;
}

.dropdown-menu {
    position: absolute;
    right: 0;
    z-index: 25;
    min-width: 100%;
    max-height: 280px;
    margin-top: var(--space-1);
    overflow-y: auto;
    border: var(--border-thin) solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper);
    box-shadow: var(--shadow-raised);
}

.dropdown-option {
    min-height: var(--control-h);
    display: block;
    width: 100%;
    padding: var(--control-pad-y) var(--control-pad-x);
    border: 0;
    background: none;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.dropdown-option:hover,
.dropdown-option[aria-selected='true'] {
    background: var(--accent);
    color: var(--paper);
}

.dropdown-option[aria-disabled='true'] {
    color: var(--ink-muted);
    cursor: default;
}

/* ---------------------------------------------------------------- form layout */

.form-actions > * + * {
    margin-top: var(--space-3);
}

.button-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.file-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

/* htmx: show while a request is in flight. */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline;
}

/* Small radio chips for a short list of choices inside a row (sectors, roles). */
.choice-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.chip-radio {
    position: relative;
    display: inline-flex;
    cursor: pointer;
}

.chip-radio input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.chip-radio span {
    display: inline-flex;
    align-items: center;
    min-height: var(--control-h);
    padding: var(--control-pad-y) var(--control-pad-x);
    border: var(--border-thin) solid var(--accent-line);
    border-radius: var(--radius-pill);
    background: var(--paper);
    color: var(--accent-ink);
    font-size: var(--text-sm);
    font-weight: var(--weight-bold);
}

.chip-radio input:checked + span {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--paper);
}

.chip-radio input:focus-visible + span {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/*
 * <select class="input"> becomes a card-style dropdown (app.js); the select stays hidden in the
 * form. Without JS it is a plain select styled like an input, with a chevron.
 */
select.input {
    appearance: none;
    padding-right: var(--space-8);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23122' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    background-size: 18px;
}

.select-native {
    display: none;
}

/* Options the same size as the field they fill. */
.dropdown-select .dropdown-option {
    font-size: var(--field-font);
}

.dropdown-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A dropdown in a scrolling table would be cut off by it; while one is open the table stops clipping. */
.table-wrap:has(.dropdown-menu:not([hidden])) {
    overflow: visible;
}

.datefield {
    position: relative;
    display: block;
    min-width: 0;
}

.datefield-native {
    display: none;
}

.datefield-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.datefield-button[data-empty] .datefield-label {
    color: var(--ink-muted);
}

.datefield-button svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--accent);
}

.datecard {
    position: absolute;
    top: calc(100% + var(--space-1));
    left: 0;
    z-index: 40;
    width: min(304px, calc(100vw - 2 * var(--space-4)));
    padding: var(--space-3);
    border: var(--border-thin) solid var(--line);
    border-radius: var(--radius-card);
    background: var(--paper);
    box-shadow: var(--shadow-raised);
}

/* Opened near the right edge of the screen: align to the field's right side instead. */
.datecard.is-right {
    right: 0;
    left: auto;
}

.datecard-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.datecard-title {
    font-weight: var(--weight-bold);
}

.datecard-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--control-h);
    height: var(--control-h);
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--accent);
    cursor: pointer;
}

.datecard-nav:hover {
    background: var(--accent);
    color: var(--paper);
}

.datecard-nav svg {
    width: 18px;
    height: 18px;
}

.datecard-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 2px;
}

.datecard-weekday {
    padding: var(--space-1) 0;
    color: var(--ink-muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    text-align: center;
}

.datecard-day {
    aspect-ratio: 1;
    padding: 0;
    border: var(--border-thin) solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--ink);
    font-size: var(--text-sm);
    cursor: pointer;
}

.datecard-day.is-outside {
    color: var(--ink-muted);
}

.datecard-day.is-today {
    border-color: var(--accent);
    color: var(--accent);
    font-weight: var(--weight-bold);
}

.datecard-day:hover:not(:disabled),
.datecard-day[aria-selected='true'] {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--paper);
}

.datecard-day[aria-selected='true'] {
    font-weight: var(--weight-bold);
}

.datecard-day:disabled {
    color: var(--line-strong);
    text-decoration: line-through;
    cursor: not-allowed;
}

.datecard-day:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 1px;
}

.datecard-foot {
    display: flex;
    justify-content: space-between;
    gap: var(--space-2);
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: var(--border-thin) solid var(--line);
}

/* A required field's label (marked by app.js): a red asterisk after it. Screen readers already
   announce the field as required, so the mark is visual only. */
.field-required::after {
    content: ' *';
    content: ' *' / '';
    color: var(--danger-fill);
    font-weight: var(--weight-bold);
}

/* A date and time card: the calendar with a scrolling column of times beside it. */
.datecard.datecard-wide {
    width: min(400px, calc(100vw - 2 * var(--space-4)));
}

.datecard-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 76px;
    gap: var(--space-3);
}

.datecard-times {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 288px;
    overflow-y: auto;
    padding-left: var(--space-3);
    border-left: var(--border-thin) solid var(--line);
    overscroll-behavior: contain;
}

.datecard-time {
    flex-shrink: 0;
    min-height: 36px;
    padding: 0 var(--space-2);
    border: var(--border-thin) solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--ink);
    font: inherit;
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}

.datecard-time:hover,
.datecard-time[aria-selected='true'] {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--paper);
}

.datecard-time[aria-selected='true'] {
    font-weight: var(--weight-bold);
}

.datecard-time:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: -3px;
}
