/* one family of form controls: selects, text, date, number, checkbox, and the way a form lays out.
   components.css holds the base field look, this fills the gaps and keeps every view the same. colours
   all come from the theme variables, so Night, Fog and the Look studio variants follow along. */

/* ---------- fields ---------- */
input, select, textarea { min-height: 44px; text-overflow: ellipsis; }
input:hover:not(:disabled, :focus), select:hover:not(:disabled, :focus), textarea:hover:not(:disabled, :focus) {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--chi) 45%, var(--line-2));
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--chi); outline-offset: 2px;
}
input:disabled, select:disabled, textarea:disabled { opacity: 0.45; cursor: not-allowed; }
input[readonly] { color: var(--ink-2); background: var(--well); }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { box-shadow: inset 0 0 0 1px var(--red, #ff5d6c), inset 0 -2px 0 var(--red, #ff5d6c); }

/* ---------- select: a stepper chevron, same on every drop-down ---------- */
select {
  max-width: 100%;
  padding-right: 40px;
  text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
  cursor: pointer;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='16' viewBox='0 0 12 16'%3E%3Cpath d='M2 6l4-4 4 4M2 10l4 4 4-4' fill='none' stroke='%238f9bab' stroke-width='1.8' stroke-linecap='square'/%3E%3C/svg%3E") calc(100% - 14px) 50% / 12px 16px no-repeat,
    var(--panel-hi);
}
html[data-theme="fog"] select, html[data-theme="petal"] select, html[data-theme="lilac"] select {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='16' viewBox='0 0 12 16'%3E%3Cpath d='M2 6l4-4 4 4M2 10l4 4 4-4' fill='none' stroke='%235b6572' stroke-width='1.8' stroke-linecap='square'/%3E%3C/svg%3E") calc(100% - 14px) 50% / 12px 16px no-repeat,
    var(--panel-hi);
}
select:focus { background-color: var(--panel-hi); }
select optgroup { font: 700 11px var(--font-label); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); background: var(--panel-solid); }
select option { font: 16px var(--font-body); letter-spacing: normal; text-transform: none; }
select[multiple] { padding-right: 14px; background-image: none; }

/* ---------- date, time and number ---------- */
/* :where keeps these at no weight, so a view's own width class (.time-input, a weight box) still wins over the fill */
:where(input[type="date"], input[type="time"], input[type="datetime-local"], input[type="month"], input[type="number"]) {
  font-variant-numeric: tabular-nums; width: 100%;
}
:where(input[type="date"], input[type="time"], input[type="datetime-local"], input[type="month"]) { min-width: 0; padding-right: 10px; }
input[type="date"]::-webkit-calendar-picker-indicator, input[type="time"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator, input[type="month"]::-webkit-calendar-picker-indicator {
  cursor: pointer; opacity: 0.7; padding: 8px; margin: -8px -4px -8px 0;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover, input[type="time"]::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { opacity: 0.5; }

/* ---------- checkbox: a square key with a notch tick ---------- */
input[type="checkbox"]:not(.toggle input) {
  -webkit-appearance: none; appearance: none;
  position: relative; flex: none; width: 24px; height: 24px; min-height: 24px; margin: 0;
  background: var(--well); box-shadow: inset 0 0 0 1px var(--line-2);
  cursor: pointer; vertical-align: middle;
}
input[type="checkbox"]:not(.toggle input):hover { box-shadow: inset 0 0 0 1px var(--chi); }
input[type="checkbox"]:not(.toggle input):checked { background: var(--chi); box-shadow: none; }
input[type="checkbox"]:not(.toggle input):checked::after {
  content: ""; position: absolute; left: 8px; top: 3px; width: 6px; height: 12px;
  border: solid var(--chi-ink); border-width: 0 3px 3px 0; transform: rotate(40deg);
}
input[type="checkbox"]:not(.toggle input):focus-visible { outline: 2px solid var(--chi); outline-offset: 2px; }
input[type="radio"] { width: 22px; height: 22px; min-height: 22px; margin: 0; }
/* every label that wraps a plain checkbox is a 44px target */
label:has(> input[type="checkbox"]:not(.toggle input)), .checkbox-list > label {
  display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer;
}

/* ---------- form layout: same gaps, hint under the field, action last ---------- */
form.stack, form.settings-form, .panel.stack { gap: 12px; }
.field { gap: 6px; min-width: 0; }
.field > .hint, .field + .hint { margin-top: -4px; }
/* labelled fields that sit side by side, wrapping to one column on a narrow phone */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 12px; align-items: end; }
.form-grid > .field > :is(input, select, textarea) { width: 100%; }
/* the primary action closes the form, on the right, and the quiet ones sit beside it */
.form-grid > .field:has(> input[type="datetime-local"]) { grid-column: 1 / -1; }
@media (min-width: 700px) { .form-grid > .field:has(> input[type="datetime-local"]) { grid-column: auto; } }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
.form-actions > .pill:not(.small) { min-width: 120px; }
form .row { flex-wrap: wrap; }
/* a key beside a field keeps its size; the field is what gives way */
.inline-form > :is(.pill, button), .row > .pill.icon-only, .search + .pill.icon-only { flex: none; }
form .row > select { flex: 1 1 140px; }
form .row > input[type="date"], form .row > input[type="datetime-local"] { flex: 1 1 160px; }
fieldset.panel > .hint:last-child, .panel > .hint:last-child { margin-bottom: 0; }
