/* =====================================================================
   Form elements — Roach / Mertson Family Tree
   ===================================================================== */

/* ── Input / select / textarea ───────────────────────────────────────── */
.form-group {
    display:       flex;
    flex-direction:column;
    gap:           var(--space-1);
    margin-bottom: var(--space-4);
}
.form-group:last-child { margin-bottom: 0; }

.form-label {
    font-size:   var(--font-size-sm);
    font-weight: 600;
    color:       var(--color-text-secondary);
}
.form-label .required { color: var(--color-danger); margin-left: 2px; }

/* A value shown but not settable (FormModal `static`). Deliberately NOT styled as a box:
   it must read as a fact about the record, not as an input someone could enable. */
.form-static {
    padding:     var(--space-2) 0;
    font-size:   var(--font-size-sm);
    line-height: 1.5;
    color:       var(--color-text);
}

.form-control {
    width:         100%;
    padding:       var(--space-2) var(--space-3);
    border:        1px solid var(--color-border);
    border-radius: var(--radius-md);
    background:    var(--color-bg-surface);
    color:         var(--color-text);
    font-size:     var(--font-size-sm);
    line-height:   1.5;
    transition:    border-color var(--transition-fast),
                   box-shadow var(--transition-fast);
    appearance:    none;
}
.form-control:focus {
    outline:      none;
    border-color: var(--color-primary-light);
    box-shadow:   0 0 0 3px rgba(42,82,120,.15);
}
.form-control::placeholder { color: var(--color-text-muted); }
.form-control:disabled {
    background: var(--color-bg-subtle);
    cursor:     not-allowed;
    opacity:    .75;
}

textarea.form-control  { resize: vertical; min-height: 80px; }
select.form-control    { background-image: var(--select-chevron); background-repeat: no-repeat; background-position: right var(--space-3) center; background-size: 14px; padding-right: var(--space-8); }

/* iOS Safari renders <input type="date"> with a collapsing height + centred value that
   only reflows on focus (fine on desktop). Pin it to the standard field height and
   left-align the native value so it looks the same before and after tapping. */
input[type="date"].form-control,
input[type="datetime-local"].form-control,
input[type="time"].form-control {
    min-height: calc(var(--font-size-sm) * 1.5 + var(--space-2) * 2 + 2px);
    -webkit-appearance: none;
    appearance: none;
}
input[type="date"].form-control::-webkit-date-and-time-value,
input[type="datetime-local"].form-control::-webkit-date-and-time-value,
input[type="time"].form-control::-webkit-date-and-time-value {
    text-align: left;
    margin: 0;
    padding: 0;
}
input[type="date"].form-control::-webkit-datetime-edit {
    line-height: 1.5;
    padding: 0;
}

/* ── Validation states ───────────────────────────────────────────────── */
.form-control.is-invalid { border-color: var(--color-danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(192,24,42,.15); }
.form-error {
    font-size:  var(--font-size-xs);
    color:      var(--color-danger);
    margin-top: var(--space-1);
}

/* ── Inline form row ─────────────────────────────────────────────────── */
.form-row {
    display: grid;
    gap:     var(--space-4);
}
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 640px) {
    .form-row.cols-2,
    .form-row.cols-3 { grid-template-columns: 1fr; }
}

/* ── Checkbox / toggle ───────────────────────────────────────────────── */
.form-check {
    display:     flex;
    align-items: center;
    gap:         var(--space-2);
    cursor:      pointer;
}
.form-check input[type="checkbox"] {
    width:         18px;
    height:        18px;
    accent-color:  var(--color-primary);
    cursor:        pointer;
    flex-shrink:   0;
}
.form-check-label { font-size: var(--font-size-sm); cursor: pointer; }

/* ── Search bar ─────────────────────────────────────────────────────── */
.search-bar {
    position:   relative;
    flex:       1;
    min-width:  0;
}
.search-bar .search-icon {
    position:  absolute;
    left:      var(--space-3);
    top:       50%;
    transform: translateY(-50%);
    color:     var(--color-text-muted);
    pointer-events: none;
    font-size: 15px;
}
.search-bar .form-control { padding-left: 2rem; }

/* ── PIN input ─────────────────────────────────────────────────────── */
.pin-input {
    text-align:    center;
    font-size:     var(--font-size-2xl);
    font-weight:   700;
    letter-spacing:.5em;
    padding:       var(--space-3) var(--space-4);
}

/* ── iOS: stop the page zooming when a field is focused ──────────────────
   Safari/Chrome iOS zoom the whole page whenever you focus an input whose font-size is under
   16px. Our controls are .875rem (14px), so every tap into a field zoomed the form — which then
   reads as "it zooms if I click too long". 16px is the threshold, not a preference. Bigger touch
   targets on a phone are the right call anyway. */
@media (max-width: 820px) {
    .form-control,
    input[type="text"], input[type="number"], input[type="email"], input[type="tel"],
    input[type="url"], input[type="date"], input[type="password"], input[type="search"],
    select, textarea {
        font-size: 16px;
    }
}

/* Money inputs (E4). A `type=number` field spends ~18px of its width on spinner arrows that
   nobody uses for a price, which is why the RFQ unit-cost box could not show $xx.xx — John:
   "cannot even display $xx.xx… should be sized for $x,xxx,xxx.xx". Reclaim that space, right-align
   so decimal points line up down a column, and use tabular figures so the digits don't jitter as
   they are typed. */
.money-input {
    text-align: right;
    font-variant-numeric: tabular-nums;
    /* Measured in real Chrome, not the preview pane (which reports zero geometry): the column was
       130px but the INPUT only got 99px of it once cell padding and borders were taken, and
       1234567.89 still clipped. Floor the input itself so a squeezed table can't shrink it, and
       trim its side padding to buy back room for digits rather than whitespace. */
    min-width: 116px;
    padding-left: var(--space-2);
    padding-right: var(--space-2);
}
.money-input::-webkit-outer-spin-button,
.money-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.money-input[type=number] { -moz-appearance: textfield; appearance: textfield; }
