/* DiveOS form substrate — utility classes the ejected shared/fields/*
   partials (T6) and DiveosFormBuilder (T5) apply so 75+ forms inherit
   consistent styling without per-call class lists.
   Per docs/archive/UI-MIGRATION-PLAN.md PR1 task T4 + design-review D2 (error state)
   + D9 (focus rings + touch targets). */

/* Vertical rhythm between stacked fields — without this they collapse to
   margin:0 and read as a cramped wall (legacy-redesign QA finding). The
   label→input gap stays tight (6px); the field→field gap breathes (22px). */
.form-section__body > * + * { margin-top: 22px; }
.diveos-field + .diveos-field { margin-top: 22px; }

.diveos-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.diveos-label--required::after {
  content: " *";
  color: var(--error);
}

/* v4 input model per the repo spec: gray-50 bg, gray-300 border with a
   gray-400 hover step, accent-derived focus border + 10% focus ring. */
.diveos-input,
.diveos-select,
.diveos-textarea {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  transition: border-color 100ms ease, box-shadow 100ms ease;
}
.diveos-input:hover,
.diveos-select:hover,
.diveos-textarea:hover {
  border-color: var(--input-border-hover);
}
.diveos-input:focus,
.diveos-select:focus,
.diveos-textarea:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.diveos-input:disabled,
.diveos-select:disabled,
.diveos-textarea:disabled {
  background: var(--surface-alt);
  color: var(--text-muted);
  cursor: not-allowed;
}
.diveos-input::placeholder,
.diveos-textarea::placeholder {
  color: var(--input-placeholder);
}
.diveos-textarea {
  min-height: 96px;
  resize: vertical;
}

/* Error state — applied by ejected field partials (T6) when the field
   has validation errors. Design-review D2: red border + inline message
   below. The message itself uses .diveos-error. */
.diveos-input.is-invalid,
.diveos-select.is-invalid,
.diveos-textarea.is-invalid {
  border-color: var(--error);
}
.diveos-input.is-invalid:focus,
.diveos-select.is-invalid:focus,
.diveos-textarea.is-invalid:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--error) 10%, transparent);
}

.diveos-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 6px;
}
.diveos-error {
  font-size: var(--text-xs);
  color: var(--error);
  margin-top: 6px;
}

/* Checkbox / radio sized for comfortable click + WCAG AA touch on
   mobile. Native input + spacing — no custom-painted control. */
.diveos-checkbox,
.diveos-radio {
  width: 18px;
  height: 18px;
  margin-top: 3px; /* optical alignment to label cap-height when parent is flex-start */
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.diveos-checkbox-label,
.diveos-radio-label {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
  min-height: 44px;
}

/* ══════════════════════════════════════════════════════════════
   CANONICAL CHECKBOX COMPONENT  (.diveos-check)
   Painted square box + Lucide check icon. Native input visually
   hidden but fully accessible (focus, keyboard, screen readers).
   Aligns the box to the label's first line.
   ══════════════════════════════════════════════════════════════ */
.diveos-check {
  display: inline-flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-primary);
  line-height: 1.45;
}
.diveos-check__input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}
.diveos-check__box {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.diveos-check__box svg {
  width: 12px;
  height: 12px;
  opacity: 0;
  transform: scale(.6);
  transition: opacity 120ms ease, transform 120ms ease;
}
.diveos-check__input:checked + .diveos-check__box {
  background: var(--accent);
  border-color: var(--accent);
}
.diveos-check__input:checked + .diveos-check__box svg {
  opacity: 1;
  transform: scale(1);
}
.diveos-check__input:indeterminate + .diveos-check__box {
  background: var(--accent);
  border-color: var(--accent);
}
.diveos-check__input:indeterminate + .diveos-check__box::after {
  content: "";
  width: 9px;
  height: 1.5px;
  background: #fff;
  border-radius: 1px;
}
.diveos-check__input:focus-visible + .diveos-check__box {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}
.diveos-check:hover .diveos-check__input:not(:checked) + .diveos-check__box {
  border-color: var(--accent);
}
.diveos-check__input:disabled + .diveos-check__box {
  background: var(--surface-alt);
  border-color: var(--border);
}
.diveos-check__input:disabled ~ .diveos-check__text {
  color: var(--text-muted);
}
.diveos-check:has(.diveos-check__input:disabled) {
  cursor: not-allowed;
}
.diveos-check__text {
  display: block;
}
.diveos-check__text .t {
  font-weight: 500;
  color: var(--text-primary);
}
.diveos-check__text .d {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 400;
}

/* Buttons — primary/secondary/ghost/destructive. Used by the FormBuilder
   submit helper + everywhere a form needs an action.
   Matches the inline patterns the conforming surfaces ship today. */
.diveos-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 100ms ease, border-color 100ms ease, color 100ms ease;
}
.diveos-button:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}
.diveos-button:disabled,
.diveos-button[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}
.diveos-button--primary {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}
.diveos-button--primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}
.diveos-button--secondary {
  color: var(--text-primary);
  background: var(--surface);
  border-color: var(--border);
}
.diveos-button--secondary:hover {
  background: var(--surface-alt);
}
.diveos-button--ghost {
  color: var(--text-muted);
  background: transparent;
}
.diveos-button--ghost:hover {
  color: var(--text-primary);
}
/* Destructive — used for "Remove diver" etc. NOT for plain Cancel
   (Cancel uses ghost). Red text on neutral background; full-red bg
   reserved for confirmation modals. */
.diveos-button--destructive {
  color: #991B1B;
  background: var(--surface);
  border-color: var(--border);
}
.diveos-button--destructive:hover {
  background: #FEF2F2;
  border-color: #FECACA;
}

.diveos-button--sm { height: 32px; padding: 0 12px; font-size: var(--text-sm); }
.diveos-button--lg { height: 44px; padding: 0 20px; font-size: var(--text-sm); }

/* Action bar that sits below the last form-section. Right-aligned by
   default — primary button trails so the eye lands there last. Stacks
   full-width on narrow screens so taps stay reachable. */
.diveos-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}
.diveos-form-actions__leading {
  margin-right: auto;
}
@media (max-width: 640px) {
  .diveos-form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .diveos-form-actions .diveos-button { width: 100%; }
  .diveos-form-actions__leading { margin-right: 0; }
}

/* Touch targets on mobile per DESIGN.md a11y section. Bump small
   buttons + inputs to 44px so they hit the WCAG AAA threshold without
   requiring callers to remember per-screen overrides. */
@media (max-width: 640px) {
  .diveos-button { min-height: 44px; height: auto; padding: 11px 18px; }
  .diveos-input,
  .diveos-select,
  .diveos-textarea {
    min-height: 44px;
    padding: 12px 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .diveos-input,
  .diveos-select,
  .diveos-textarea,
  .diveos-button {
    transition: none;
  }
}

/* Phase 8 PR5 T7 — fitting-room size pill picker. Sits above each
   slot dropdown in the fitting drawer. Tapping a pill calls the
   fitting-size-filter Stimulus controller to filter the dropdown to
   items in that size. --active styles the currently selected pill. */
.fitting-size-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  min-height: 28px;
  padding: 2px 10px;
  font: 500 12px/1 var(--font-sans, system-ui);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 100ms ease, color 100ms ease, border-color 100ms ease;
}
.fitting-size-pill:hover {
  background: var(--canvas);
}
.fitting-size-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.fitting-size-pill--active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Tablet hit-target compliance: bump pill height to 36px on small
   viewports so the fitting room is usable on a 10" tablet without
   stylus-precision taps. */
@media (max-width: 640px) {
  .fitting-size-pill { min-height: 36px; padding: 4px 14px; font-size: var(--text-sm); }
}

/* ── select2 (super_select) → DiveOS field substrate ──────────────────────
   Bullet Train's theme super_select.css styles select2's chrome with the BT
   palette (base-300 border, primary-500 accent). select2 hides the native
   <select> and renders its OWN box, so .diveos-select on the hidden element
   never shows — the BT-looking box IS this chrome. Restyle it ONCE here to
   match .diveos-input; every super_select field (27 views) inherits. Loaded
   after the theme; !important beats super_select's !important rules. */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
  min-height: 40px !important;
  padding: 0 !important;
  background: var(--input-bg) !important;
  border: 1px solid var(--input-border) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: none !important;
  transition: border-color 100ms ease, box-shadow 100ms ease !important;
}
.select2-container--default .select2-selection--single:hover,
.select2-container--default .select2-selection--multiple:hover {
  border-color: var(--input-border-hover) !important;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
  padding: 0 12px !important;
  line-height: 38px !important;
  color: var(--text-primary) !important;
  font-size: var(--text-sm) !important;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 38px !important;
}
.select2-container--default .select2-selection__placeholder {
  color: var(--input-placeholder) !important;
}
.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple,
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple {
  border-color: var(--input-border-focus) !important;
  box-shadow: 0 0 0 3px var(--focus-ring) !important;
}
.select2-container--default .select2-dropdown {
  background: var(--surface) !important;
  border: 1px solid var(--input-border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
  overflow: hidden !important;
}
.select2-container--default .select2-results__option {
  color: var(--text-primary) !important;
  font-size: var(--text-sm) !important;
  padding: 8px 12px !important;
}
.select2-container--default .select2-results__option--highlighted,
.select2-container--default .select2-results__option--highlighted[aria-selected] {
  background: var(--accent) !important;
  color: #fff !important;
}
.select2-container--default .select2-results__option[aria-selected="true"] {
  background: var(--accent-soft, var(--surface-alt)) !important;
  color: var(--text-primary) !important;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
  border: 1px solid var(--input-border) !important;
  border-radius: var(--radius-sm) !important;
}
.select2-container--default .select2-search--dropdown .select2-search__field:focus {
  border-color: var(--input-border-focus) !important;
  box-shadow: 0 0 0 3px var(--focus-ring) !important;
  outline: none !important;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice {
  background: var(--accent-soft, var(--surface-alt)) !important;
  border: 1px solid var(--hairline) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text-primary) !important;
  margin-top: 7px !important;
}

/* ── Bullet Train .button family → DiveOS buttons ─────────────────────────
   The arena theme's .button / .button-secondary / .button-alternative /
   .button-red classes (BT palette: primary-500, base-300/500) back the file-
   upload buttons (active_storage "Upload New Image"), the buttons-toggle
   field, and any BT-rendered action control. Restyle the family ONCE here so
   every instance matches .diveos-button, no per-view edits. Loaded after the
   theme; ties on specificity, wins on source order. */
.button,
.button-secondary,
.button-alternative {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-sm);
  box-shadow: none;
  transition: background-color 100ms ease, border-color 100ms ease, color 100ms ease;
}
/* primary */
.button {
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
}
.button:hover {
  color: #fff;
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}
/* secondary / alternative (outlined) — the file-upload button look */
.button-secondary,
.button-alternative {
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
}
.button-secondary:hover,
.button-alternative:hover {
  color: var(--text-primary);
  background: var(--surface-alt);
  border-color: var(--border);
}
/* danger */
.button.button-red,
.button-red {
  color: #fff;
  background: var(--red-600);
  border-color: var(--red-600);
}
.button.button-red:hover,
.button-red:hover {
  color: #fff;
  background: var(--red-700);
  border-color: var(--red-700);
}

/* color-swatch buttons (color picker `.button-color`). Neutral DS shell
   matching the .button-alternative look; the swatch fill comes from the
   inline background-color style. Selected state (the BT `ring-2`) reads
   through --accent so the active swatch picks up the DS accent ring. */
.button-color {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: none;
}
.button-color.ring-2,
.button-color:focus-visible {
  --tw-ring-color: var(--accent);
  outline: none;
}

/* ── File-upload widget chrome (file_field + active_storage_image) ─────────
   The ejected upload partials render a progress bar (`bg-primary-500`) and a
   thumbnail/progress panel (`bg-base-100`) straight from the BT palette.
   Retoken both centrally — the partials keep their markup, these win on
   source order. */
.file-field [data-fields--file-field-target="progressBar"] {
  background: var(--accent);
}
.file-field .bg-base-100 {
  background: var(--surface);
}
