/* ==========================================================================
   controls.css - Airline Inbox design system v2 ("Calm ledger")
   Buttons, icon and link buttons, fields and every form control, checkboxes,
   radios, switches, fieldsets, form grids/sections/folds/actions, toolbars and
   filters, search input, kbd, dropzone, field checks (.chk*), busy spinner,
   compact fields, read-only values, inline table cell input, touch and phone
   sizes, and the disabled states.
   Tokens come from tokens.css (loaded first). No raw hex here.
   Text-control selector TX (used inside :where() so it adds no specificity):
   every input except checkbox, radio, file, submit, button, reset, hidden,
   range and colour; plus select and textarea.
   ========================================================================== */


/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: var(--weight-medium) var(--text-base)/1 var(--font-sans);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background-color var(--dur-1) ease, border-color var(--dur-1) ease,
    color var(--dur-1) ease, box-shadow var(--dur-1) ease, transform var(--dur-2) var(--ease-out);
}
.btn, .btn:hover { text-decoration: none; }
.btn .i { width: 16px; height: 16px; flex: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--ink-2);
}
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-danger);
}
.btn-warning {
  background: var(--warning-soft);
  border-color: var(--warning-line);
  color: var(--warning-ink);
}

.btn-small {
  height: var(--control-h-sm);
  padding: 0 10px;
  font-size: var(--text-sm);
  gap: 5px;
}
.btn-small .i { width: 14px; height: 14px; }
.btn-lg {
  height: var(--control-h-lg);
  padding: 0 16px;
  font-size: var(--text-md);
}
.btn-block { width: 100%; }

/* Hover colours only where a pointer can hover, and never on a disabled button. */
@media (hover: hover) and (pointer: fine) {
  .btn:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--surface-2);
    border-color: var(--field-line-hover);
  }
  .btn-primary:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--on-accent);
  }
  .btn-ghost:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--surface-3);
    border-color: transparent;
    color: var(--ink);
  }
  .btn-danger:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
    color: var(--on-danger);
  }
  .btn-warning:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--warning-soft);
    border-color: var(--warning);
    color: var(--warning-ink);
  }
}

/* Press: scale 0.97 on pointer and touch presses only. Keyboard presses (:focus-visible) get no scale.
   Written after the hover rules so it wins while both apply. */
.btn:not(:disabled):not([aria-disabled="true"]):active:not(:focus-visible) {
  transform: scale(0.97);
}
.btn-primary:not(:disabled):not([aria-disabled="true"]):active {
  background: var(--accent-active);
  border-color: var(--accent-active);
}
.btn-danger:not(:disabled):not([aria-disabled="true"]):active {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

/* Confirm micro-feedback (approve/save): the label fades out and the check fades in, same size, no layout shift.
   gap: inherit gives .btn-label the gap of its button (6px, or 5px in .btn-small), so the spacing is unchanged. */
.btn:has(> .btn-confirm) {
  position: relative;
}
.btn-label {
  display: inline-flex;
  align-items: center;
  gap: inherit;
  transition: opacity var(--dur-1) var(--ease-out);
}
.btn-confirm {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(0.95);
  pointer-events: none;
  transition: opacity var(--dur-3) var(--ease-out), transform var(--dur-3) var(--ease-out);
}
.btn.is-confirmed .btn-label {
  opacity: 0;
}
.btn.is-confirmed .btn-confirm {
  opacity: 1;
  transform: none;
}


/* --------------------------------------------------------------------------
   Icon buttons
   -------------------------------------------------------------------------- */

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color var(--dur-1) ease, color var(--dur-1) ease, transform var(--dur-2) var(--ease-out);
}
.icon-btn .i { width: 16px; height: 16px; }
.icon-btn:not(:disabled):not([aria-disabled="true"]):active:not(:focus-visible) {
  transform: scale(0.97);
}
.icon-btn.small { width: 28px; height: 28px; }
@media (hover: hover) and (pointer: fine) {
  .icon-btn:not(:disabled):hover {
    background: var(--surface-3);
    color: var(--ink);
  }
}


/* --------------------------------------------------------------------------
   Link buttons
   -------------------------------------------------------------------------- */

.linklike {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.linklike.small { font-size: var(--text-sm); }
@media (hover: hover) and (pointer: fine) {
  .linklike:hover { text-decoration: underline; text-underline-offset: 2px; }
}


/* --------------------------------------------------------------------------
   Busy state and spinner
   -------------------------------------------------------------------------- */

.btn.is-busy,
.btn[aria-busy="true"] {
  cursor: progress;
}
.btn.is-busy::before,
.btn[aria-busy="true"]::before {
  content: "";
  width: 14px;
  height: 14px;
  flex: none;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
/* A busy button was just disabled by app.js; keep it readable while it works. */
.btn.is-busy:disabled,
.btn[aria-busy="true"]:disabled {
  opacity: 1;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* --------------------------------------------------------------------------
   Fields: label, hint, error, required marker
   -------------------------------------------------------------------------- */

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}
/* stacked fields (login, signup, plain forms): 16px between consecutive fields, 20px above a submit row.
   Grids, toolbars and other containers that already use a gap keep their own spacing (reset below). */
.field + .field { margin-top: var(--space-4); }
:is(.form-grid, .form-grid-3, .toolbar, .toolbar-row, .stack, .stack-sm, .stack-lg, .grid, .grid-2, .grid-3,
    .grid-main, .compact-fields, .split, .split-wide, .cluster, .actions, .toolbar-actions, .form-actions,
    .settings-section, .layout-form, [class*="grid"], [class*="stack"]) > .field + .field { margin-top: 0; }
form > .field + :is(button, .btn) { margin-top: var(--space-5); }
.field > label,
.field > .label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 18px;
  color: var(--ink);
}
.req {
  color: var(--critical-ink);
  font-weight: var(--weight-semibold);
  margin-left: 2px;
}
.hint {
  font-size: var(--text-xs);
  line-height: 16px;
  color: var(--muted);
}
.field-error {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  font-size: var(--text-xs);
  line-height: 16px;
  color: var(--critical-ink);
}
.field-error .i {
  width: 14px;
  height: 14px;
  flex: none;
  margin-top: 1px;
}


/* --------------------------------------------------------------------------
   Text controls (inputs except checkbox, radio, file, buttons, hidden, range, colour; select; textarea)
   -------------------------------------------------------------------------- */

:where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="hidden"]):not([type="range"]):not([type="color"]), select, textarea) {
  width: 100%;
  min-height: var(--control-h);
  padding: 0 10px;
  font: var(--weight-regular) var(--text-base)/20px var(--font-sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--field-line);
  border-bottom-color: var(--field-line-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--dur-1) ease, box-shadow var(--dur-1) ease;
}
input::placeholder,
textarea::placeholder {
  color: var(--placeholder);
  opacity: 1;
}
@media (hover: hover) and (pointer: fine) {
  :where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="hidden"]):not([type="range"]):not([type="color"]), select, textarea):hover {
    border-color: var(--field-line-hover);
    border-bottom-color: var(--field-line-strong);
  }
}
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="hidden"]):not([type="range"]):not([type="color"]), select, textarea):focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="hidden"]):not([type="range"]):not([type="color"]), select, textarea)[aria-invalid="true"] {
  border-color: var(--critical);
}
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="hidden"]):not([type="range"]):not([type="color"]), select, textarea)[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--critical) 25%, transparent);
}
input[readonly],
textarea[readonly] {
  background: var(--surface-2);
}
input[type="search"]::-webkit-search-cancel-button {
  cursor: pointer;
}


/* --------------------------------------------------------------------------
   Select
   -------------------------------------------------------------------------- */

/* native pickers (date calendar icon, select popups, number spinners) follow the theme: each text control
   states the scheme that tokens.css set on the page, so a dark page never gets a light-scheme indicator */
:root :where(input, select, textarea) { color-scheme: light; }
:root[data-theme="dark"] :where(input, select, textarea) { color-scheme: dark; }

select {
  padding-right: 32px;
  background: var(--surface) var(--chevron) no-repeat right 10px center / 16px 16px;
  cursor: pointer;
}
select:disabled {
  background: var(--surface-3) var(--chevron) no-repeat right 10px center / 16px 16px;
}


/* --------------------------------------------------------------------------
   Textarea
   -------------------------------------------------------------------------- */

textarea {
  min-height: 88px;
  padding: 8px 10px;
  line-height: 1.5;
  resize: vertical;
}


/* --------------------------------------------------------------------------
   Date and time
   -------------------------------------------------------------------------- */

input[type="date"],
input[type="time"] {
  min-width: 0;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  opacity: 0.7;
  cursor: pointer;
}
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
:root[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator {
  opacity: .75;
}
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator:hover,
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator:focus-visible,
:root[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator:hover,
:root[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator:focus-visible {
  opacity: 1;
}


/* --------------------------------------------------------------------------
   File input (the button part is styled like .btn-small)
   -------------------------------------------------------------------------- */

input[type="file"] {
  max-width: 100%;
  font-size: var(--text-sm);
  color: var(--ink-2);
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  display: inline-flex;
  align-items: center;
  height: var(--control-h-sm);
  margin-right: 10px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: var(--weight-medium) var(--text-sm)/1 var(--font-sans);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) {
  input[type="file"]:hover::file-selector-button {
    background: var(--surface-2);
  }
}


/* --------------------------------------------------------------------------
   Number, money and code inputs
   -------------------------------------------------------------------------- */

input.num,
.num input {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
input.mono {
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
@media (min-width: 640px) and (pointer: fine) {
  input.mono { font-size: var(--text-sm); }
}


/* --------------------------------------------------------------------------
   Checkbox and radio
   -------------------------------------------------------------------------- */

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}
input[type="checkbox"]:disabled,
input[type="radio"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}


/* --------------------------------------------------------------------------
   .check: a checkbox or radio with its label text
   -------------------------------------------------------------------------- */

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  font-size: var(--text-base);
  line-height: 20px;
  color: var(--ink);
  cursor: pointer;
}
.check > input[type="checkbox"],
.check > input[type="radio"] {
  margin-top: 2px;
}
.check .hint {
  display: block;
  margin-top: 2px;
}
.check:has(> input:disabled) {
  color: var(--muted);
  cursor: not-allowed;
}


/* --------------------------------------------------------------------------
   .switch: a toggle with its label text (label > input[type=checkbox] + text)
   -------------------------------------------------------------------------- */

.switch {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  font-size: var(--text-base);
  line-height: 20px;
  color: var(--ink);
  cursor: pointer;
}
.switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 32px;
  height: 18px;
  margin: 1px 0 0;
  border-radius: var(--radius-full);
  background: var(--field-line-strong);
  cursor: pointer;
  transition: background-color var(--dur-2) ease;
}
.switch input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--on-accent);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-2) var(--ease-out);
}
.switch input[type="checkbox"]:checked {
  background: var(--accent);
}
.switch input[type="checkbox"]:checked::before {
  transform: translateX(14px);
}
.switch input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.switch-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.switch .hint {
  display: block;
}
.switch:has(> input:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}
/* consecutive switch rows breathe; the hint sits inside .switch-text, so it lines up under the label text */
.switch + .switch { margin-top: var(--space-3); }
:is(.stack, .stack-sm, .stack-lg, .grid, .grid-2, .grid-3, .form-grid, .settings-section) > .switch + .switch { margin-top: 0; }
/* settings wrap each switch in its own .field: consecutive switch fields get the same 12px */
.field + .field:has(> .switch) { margin-top: var(--space-3); }


/* --------------------------------------------------------------------------
   Fieldset and legend
   -------------------------------------------------------------------------- */

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--ink);
}


/* --------------------------------------------------------------------------
   Form grid, sections, folds (disclosures) and actions
   -------------------------------------------------------------------------- */

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
  align-items: start;
}
@media (min-width: 640px) {
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (min-width: 960px) {
  .form-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.form-grid .field.wide,
.form-grid .span-all,
.field.wide {
  grid-column: 1 / -1;
}

/* a field, switch or fieldset that follows a form grid starts 16px below it */
.form-grid + :is(.field, .switch, fieldset) { margin-top: var(--space-4); }

.form-section {
  padding-top: 20px;
  margin-top: 20px;
  border-top: 1px solid var(--hairline);
}
.form-section:first-child {
  padding-top: 0;
  margin-top: 0;
  border-top: 0;
}
.form-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--muted);
}
.form-section-title .i {
  width: 14px;
  height: 14px;
  flex: none;
}
.fold-note {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

/* Disclosures: summary is the clickable title; the chevron turns when open. */
details.form-fold > summary,
details.mailbox-settings > summary,
details.more-filters > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
  cursor: pointer;
}
details.form-fold > summary::-webkit-details-marker,
details.mailbox-settings > summary::-webkit-details-marker,
details.more-filters > summary::-webkit-details-marker {
  display: none;
}
details.form-fold > summary.form-section-title {
  margin-bottom: 0;
}
details.form-fold[open] > summary.form-section-title {
  margin-bottom: 12px;
}
details.form-fold > summary .chev,
details.mailbox-settings > summary .chev {
  width: 16px;
  height: 16px;
  flex: none;
  margin-left: auto;
  transition: transform var(--dur-2) var(--ease-out);
}
details.form-fold[open] > summary .chev,
details.mailbox-settings[open] > summary .chev {
  transform: rotate(180deg);
}
/* A standalone fold (not a form section) gets a box; its body is padded. */
details.form-fold:not(.form-section) {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
details.form-fold:not(.form-section) > summary {
  padding: 10px 12px;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--ink);
}
details.form-fold:not(.form-section)[open] > summary {
  border-bottom: 1px solid var(--hairline);
}
details.form-fold:not(.form-section) > :not(summary) {
  padding: 16px;
}
details.mailbox-settings > summary {
  padding: 10px 12px;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--ink);
}
@media (hover: hover) and (pointer: fine) {
  details.form-fold > summary:hover,
  details.mailbox-settings > summary:hover {
    color: var(--ink);
  }
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
}
.form-actions .muted {
  font-size: var(--text-sm);
}
/* Sticky action bar on long forms (mail detail). Negative margins reach the card edges. */
.form-actions.sticky {
  position: sticky;
  bottom: 0;
  z-index: var(--z-sticky);
  margin: 20px -16px -16px;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

form.inline {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
}


/* --------------------------------------------------------------------------
   Toolbars, filters, search input
   -------------------------------------------------------------------------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 10px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.toolbar .field {
  flex: 1 1 160px;
}
.toolbar .field.grow {
  flex: 2 1 240px;
}
.toolbar .field > label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--muted);
}
.toolbar-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-left: auto;
}

/* filters fold (list pages): on phones the filter panel folds behind "Filters · n" (app.js closes it on load);
   from 640px up the summary is hidden and the panel is always open, as before */
.filters-fold > summary { display: none; }
.filters-fold > summary::-webkit-details-marker { display: none; }

.more-filters {
  flex: 1 1 100%;
  min-width: 0;
}
.more-filters > summary {
  align-self: flex-start;
  height: var(--control-h-sm);
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--ink-2);
}
.more-filters > summary .chev {
  width: 14px;
  height: 14px;
  flex: none;
  transition: transform var(--dur-2) var(--ease-out);
}
.more-filters[open] > summary .chev {
  transform: rotate(180deg);
}
@media (hover: hover) and (pointer: fine) {
  .more-filters > summary:hover {
    background: var(--surface-3);
    color: var(--ink);
  }
}
.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}
.more-filters[open] .toolbar-row {
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}
.toolbar-row .field {
  flex: 1 1 160px;
}

.search-input {
  position: relative;
}
.search-input > .i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}
.search-input input {
  padding-left: 34px;
}


/* --------------------------------------------------------------------------
   kbd
   -------------------------------------------------------------------------- */

kbd {
  font: var(--weight-medium) var(--text-2xs)/1 var(--font-mono);
  padding: 3px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  color: var(--muted);
}


/* --------------------------------------------------------------------------
   Dropzone (a label around a file input; the input is visually hidden but focusable)
   -------------------------------------------------------------------------- */

.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 32px 24px;
  text-align: center;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-xl);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color var(--dur-1) ease, background-color var(--dur-1) ease,
    box-shadow var(--dur-1) ease;
}
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
@media (hover: hover) and (pointer: fine) {
  .dropzone:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
  }
}
.dropzone:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.dropzone > input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}
.dropzone-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent-icon);
  box-shadow: var(--shadow-xs);
}
.dropzone-icon .i {
  width: 20px;
  height: 20px;
}
.dropzone-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--ink);
}
.dropzone-cta {
  color: var(--link);
  font-weight: var(--weight-medium);
}
.dropzone-hint {
  font-size: var(--text-xs);
  color: var(--muted);
}
.dropzone-files {
  max-width: 100%;
  font-size: var(--text-sm);
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.dropzone-files:empty {
  display: none;
}
.upload-force {
  margin-bottom: 16px;
}
.upload-force .hint {
  display: block;
  margin-top: 3px;
}


/* --------------------------------------------------------------------------
   Field checks (.chk). Markup is fixed by tests: <div class="chk chk-warn">
   -------------------------------------------------------------------------- */

.chk {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 2px;
  font-size: var(--text-xs);
  line-height: 16px;
  color: var(--muted);
}
.chk .i {
  width: 14px;
  height: 14px;
  flex: none;
  margin-top: 1px;
}
.chk-ok .i {
  color: var(--good-ink);
}
.chk-warn {
  color: var(--warning-ink);
}
.chk-warn .i {
  color: var(--warning-ink);
}
.chk-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
/* A field whose check warns gets a warning edge (progressive: fine if :has is unsupported). */
.field:has(.chk-warn) :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]):not(:focus) {
  border-color: var(--warning-line);
  border-bottom-color: var(--warning);
}


/* --------------------------------------------------------------------------
   Compact fields (mail page: empty fields hidden until asked for)
   -------------------------------------------------------------------------- */

.compact-fields .field-empty {
  display: none;
}
.compact-toggle {
  margin: 8px 0 0;
}


/* --------------------------------------------------------------------------
   Read-only values and the inline table cell input
   -------------------------------------------------------------------------- */

.ro-value {
  display: block;
  padding: 6px 0;
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

input.cell-input {
  width: 100%;
  min-height: 28px;
  padding: 0 6px;
  font: inherit;
  text-align: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-xs);
  box-shadow: 0 0 0 3px var(--accent-ring);
  outline: none;
}


/* --------------------------------------------------------------------------
   Touch and phone sizes
   -------------------------------------------------------------------------- */

@media (pointer: coarse) {
  .btn { min-height: 44px; }
  /* layout.css sets `.auth-form .btn-primary { min-height: 40px }`, which beat `.btn` (44px) on the auth pages.
     These selectors are more specific, so every button size stays 44px+ on touch screens. */
  .btn.btn-lg, .auth-form .btn.btn-primary { min-height: 44px; }
  details.form-fold > summary, details.mailbox-settings > summary { min-height: 44px; }
  .colpick-item .check { min-height: 44px; }
  .icon-btn {
    width: 44px;
    height: 44px;
  }
  .more-filters > summary { min-height: 44px; }
  .check > input[type="checkbox"],
  .check > input[type="radio"] {
    width: 20px;
    height: 20px;
  }
}

/* 16px text (no iOS zoom on focus) and 44px tall fields on phones and touch screens. */
@media (max-width: 639.98px), (pointer: coarse) {
  :where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="hidden"]):not([type="range"]):not([type="color"]), select, textarea) {
    min-height: 44px;
    font-size: 16px;
  }
  input.cell-input {
    min-height: 44px;
    font-size: 16px;
  }
}

@media (max-width: 639.98px) {
  .toolbar {
    padding: 10px;
  }
  .toolbar .field,
  .toolbar .field.grow,
  .toolbar-row .field {
    flex: 1 1 100%;
  }
  .toolbar-actions {
    width: 100%;
    margin-left: 0;
  }
  .toolbar-actions .btn {
    flex: 1 1 0;
  }
  .filters-fold > summary {
    display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
    list-style: none; cursor: pointer; color: var(--ink); font-size: var(--text-sm); font-weight: var(--weight-medium);
    border-top: 1px solid var(--hairline);
  }
  .filters-fold > summary .i { color: var(--muted); }
  .filters-fold > summary .chev { margin-left: auto; transition: transform var(--dur-2) var(--ease-out); }
  .filters-fold[open] > summary .chev { transform: rotate(180deg); }
  .filters-count { color: var(--accent-soft-ink); font-weight: var(--weight-semibold); }
  .filters-fold[open] > summary { border-bottom: 1px solid var(--hairline); }
  .filters-fold > .toolbar { margin: 10px 12px 12px; }
  html.js .filters-fold:not([data-ready]) > :not(summary) { display: none; }
  .dropzone {
    padding: 24px 16px;
  }
  .form-actions {
    gap: 10px;
  }
  .form-actions.sticky {
    margin: 20px -16px -16px;
  }
}

/* on wider screens a toolbar select (audit "Show") stops at about 280px instead of filling the card */
@media (min-width: 640px) {
  .toolbar select {
    max-width: 280px;
  }
}


/* --------------------------------------------------------------------------
   Reduced motion: no press scale, no colour/thumb/chevron animation. The spinner still turns, more slowly.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .btn,
  .switch input[type="checkbox"],
  .switch input[type="checkbox"]::before,
  details.form-fold > summary .chev,
  details.mailbox-settings > summary .chev,
  .more-filters > summary .chev,
  .filters-fold > summary .chev {
    transition: none;
  }
  .btn:not(:disabled):not([aria-disabled="true"]):active:not(:focus-visible),
  .icon-btn:not(:disabled):not([aria-disabled="true"]):active:not(:focus-visible) {
    transform: none;
  }
  .btn-confirm {
    transform: none;
  }
  .btn.is-busy::before,
  .btn[aria-busy="true"]::before {
    animation-duration: 1.6s;
  }
}


/* --------------------------------------------------------------------------
   Disabled states (controls, and anything inside a disabled fieldset)
   -------------------------------------------------------------------------- */

.btn:disabled,
.btn[aria-disabled="true"],
fieldset:disabled .btn {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn.is-busy:disabled,
.btn[aria-busy="true"]:disabled {
  cursor: progress;
}

:where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="hidden"]):not([type="range"]):not([type="color"]), select, textarea):disabled {
  background: var(--surface-3);
  color: var(--muted);
  border-color: var(--border);
  box-shadow: none;
  cursor: not-allowed;
}
select:disabled {
  background: var(--surface-3) var(--chevron) no-repeat right 10px center / 16px 16px;
}
