/* Orbit design system: .ds-* components. docs/design-system.md explains every value.
   The --ds-* tokens these rules use live in design-tokens.css, generated from design/tokens.json by
   `pnpm run tokens` (docs/design-system/tokens.md). Do not define tokens here; edit design/tokens.json.
   Load design-tokens.css, then this file, then style.css; style.css maps its older custom properties
   (--text, --muted, --border, --purple) onto these tokens. */

/* Utilities */

/* Keep an empty status mounted so assistive technology can observe subsequent text changes. */
.ds-visually-hidden,
.ds-state-status:empty {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.ds-state-status:empty { padding: 0; }

/* Glass: a solid surface everywhere, translucent only when the platform can blur behind it and the
   person has not asked for reduced transparency or more contrast. */

.ds-glass {
  background: var(--ds-surface-overlay);
  border: 1px solid var(--ds-hairline);
  box-shadow: var(--ds-lip), var(--ds-shadow-pop);
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) and (background: color-mix(in srgb, red 50%, transparent)) {
  @media (prefers-reduced-transparency: no-preference) and (prefers-contrast: no-preference) {
    .ds-glass {
      background: color-mix(in srgb, var(--ds-surface-overlay) var(--ds-glass-opacity), transparent);
      -webkit-backdrop-filter: blur(var(--ds-glass-blur)) saturate(var(--ds-glass-saturate));
      backdrop-filter: blur(var(--ds-glass-blur)) saturate(var(--ds-glass-saturate));
    }
  }
}

/* Button */

.ds-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-2);
  min-height: var(--ds-target);
  padding: 0 var(--ds-space-4);
  border: 1px solid var(--ds-border-strong);
  border-radius: var(--ds-radius-md);
  color: var(--ds-ink);
  background: var(--ds-fill);
  box-shadow: var(--ds-lip);
  font: 600 var(--ds-text-lg)/1.2 var(--ds-font-sans);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--ds-duration-fast) var(--ds-ease-standard),
    border-color var(--ds-duration-fast) var(--ds-ease-standard),
    transform var(--ds-duration-instant) var(--ds-ease-standard);
}
.ds-button:hover:enabled { background: var(--ds-fill-hover); }
.ds-button:active:enabled { transform: scale(.97); }
.ds-button:disabled { color: var(--ds-ink-disabled); cursor: not-allowed; opacity: .6; }
.ds-button--primary { border-color: transparent; color: var(--ds-accent-ink); background: var(--ds-accent); }
.ds-button--primary:hover:enabled { background: var(--ds-accent-hover); }
.ds-button--quiet { border-color: transparent; background: transparent; box-shadow: none; }
.ds-button--quiet:hover:enabled { background: var(--ds-hairline); }
.ds-button--danger { border-color: var(--ds-danger-edge); color: var(--ds-danger-ink); background: var(--ds-danger); }
.ds-button--danger:hover:enabled { background: var(--ds-danger-hover); }
.ds-button--compact { min-height: var(--ds-target-compact); padding: 0 var(--ds-space-2); border-radius: var(--ds-radius-sm); font-size: var(--ds-text-md); }
.ds-button--icon { min-width: var(--ds-target); padding: 0; }

/* Field: label above control, optional hint below. */

.ds-field { display: grid; gap: var(--ds-space-1); min-width: 0; }
.ds-label { color: var(--ds-ink-muted); font: 600 var(--ds-text-sm)/1.3 var(--ds-font-sans); }
.ds-hint { margin: 0; color: var(--ds-ink-muted); font-size: var(--ds-text-sm); line-height: 1.4; }

.ds-input,
.ds-select {
  width: 100%;
  min-width: 0;
  min-height: var(--ds-target);
  padding: 0 var(--ds-space-3);
  border: 1px solid var(--ds-border-strong);
  border-radius: var(--ds-radius-md);
  color: var(--ds-ink);
  background: var(--ds-fill-sunken);
  font: var(--ds-text-lg)/1.2 var(--ds-font-sans);
  transition: border-color var(--ds-duration-fast) var(--ds-ease-standard);
}
.ds-input:disabled, .ds-select:disabled { color: var(--ds-ink-disabled); cursor: not-allowed; opacity: .6; }
.ds-input:hover:enabled,
.ds-select:hover:enabled { border-color: var(--ds-accent-edge); }
.ds-input:user-invalid { border-color: var(--ds-danger-ink); }
.ds-input[type=number] { font-variant-numeric: tabular-nums; }

.ds-select {
  appearance: none;
  padding-inline-end: calc(var(--ds-space-3) * 2 + 10px);
  /* A background image cannot inherit currentColor, so the chevron is drawn in --ds-ink-muted's value. */
  background: var(--ds-fill-sunken) no-repeat right var(--ds-space-3) center / 14px 14px
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 6 8 10.5 12.5 6' fill='none' stroke='%23aaa5b9' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  cursor: pointer;
}
@media (forced-colors: active) { .ds-select { appearance: auto; background-image: none; } }
.ds-select:dir(rtl) { background-position: left var(--ds-space-3) center; }

/* Stepper: a number input between two pointer shortcuts. Arrow keys already step the input, so the
   buttons stay out of the tab order but keep their names for touch screen readers. */

.ds-stepper {
  display: grid;
  grid-template-columns: var(--ds-target) minmax(0, 1fr) var(--ds-target);
  min-height: var(--ds-target);
  border: 1px solid var(--ds-border-strong);
  border-radius: var(--ds-radius-md);
  background: var(--ds-fill-sunken);
}
.ds-stepper:focus-within { border-color: var(--ds-accent-edge); }
/* The ring belongs to the whole control, not the input squeezed between its buttons. */
.ds-stepper:has(> input:focus-visible) { outline: var(--ds-focus-width) solid var(--ds-focus-color); outline-offset: 1px; }
/* [type] outranks style.css's global ring, whose :is() list includes [tabindex]. */
.ds-stepper > input[type]:focus-visible { outline: none; }
.ds-stepper > input {
  width: 100%;
  min-width: 0;
  border: 0;
  color: var(--ds-ink);
  background: transparent;
  font: 600 var(--ds-text-lg)/1 var(--ds-font-sans);
  font-variant-numeric: tabular-nums;
  text-align: center;
  appearance: textfield;
}
.ds-stepper > input::-webkit-inner-spin-button,
.ds-stepper > input::-webkit-outer-spin-button { margin: 0; appearance: none; }
.ds-stepper > button {
  border: 0;
  border-radius: calc(var(--ds-radius-md) - 1px);
  color: var(--ds-ink-muted);
  background: transparent;
  font: 500 18px/1 var(--ds-font-sans);
  cursor: pointer;
  transition: background-color var(--ds-duration-fast) var(--ds-ease-standard), color var(--ds-duration-fast) var(--ds-ease-standard);
}
.ds-stepper > button:hover:enabled { color: var(--ds-ink); background: var(--ds-hairline); }
.ds-stepper > button:active:enabled { background: var(--ds-fill-pressed); }
.ds-stepper > button:disabled { color: var(--ds-ink-disabled); opacity: .45; cursor: not-allowed; }

/* Segmented control: a radio group drawn as a native-style track with a raised thumb. Put the radios
   inside a fieldset whose legend names the group. */

.ds-segmented {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: var(--ds-space-0);
  padding: var(--ds-space-0);
  border-radius: var(--ds-radius-md);
  background: var(--ds-fill-sunken);
  box-shadow: inset 0 0 0 1px var(--ds-hairline);
}
.ds-segmented > label {
  display: grid;
  place-items: center;
  min-height: calc(var(--ds-target-compact) + 4px);
  padding: var(--ds-space-1) var(--ds-space-2);
  border-radius: calc(var(--ds-radius-md) - var(--ds-space-0));
  color: var(--ds-ink-muted);
  font: 600 var(--ds-text-md)/1.2 var(--ds-font-sans);
  text-align: center;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: background-color var(--ds-duration-fast) var(--ds-ease-standard), color var(--ds-duration-fast) var(--ds-ease-standard),
    box-shadow var(--ds-duration-fast) var(--ds-ease-standard);
}
.ds-segmented > label:hover { color: var(--ds-ink); }
.ds-segmented > label:has(:checked) { color: var(--ds-ink); background: var(--ds-fill-raised); box-shadow: var(--ds-shadow-raise); }
.ds-segmented > label:has(:focus-visible) { outline: var(--ds-focus-width) solid var(--ds-focus-color); outline-offset: 1px; }
.ds-segmented input { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); }
:disabled > .ds-segmented > label,
.ds-segmented > label:has(:disabled) { color: var(--ds-ink-disabled); opacity: .55; cursor: not-allowed; }

/* Switch: a checkbox drawn as a toggle. It stays a native checkbox so forms, labels and tests work. */

.ds-switch {
  position: relative;
  flex: none;
  width: 36px;
  height: 22px;
  margin: 0;
  border-radius: var(--ds-radius-pill);
  background: var(--ds-fill-raised);
  box-shadow: inset 0 0 0 1px var(--ds-hairline);
  appearance: none;
  cursor: pointer;
  transition: background-color var(--ds-duration-base) var(--ds-ease-standard);
}
.ds-switch::before {
  content: '';
  position: absolute;
  inset: 3px auto 3px 3px;
  width: 16px;
  border-radius: 50%;
  background: var(--ds-ink);
  box-shadow: 0 1px 2px rgb(0 0 0 / 40%);
  transition: translate var(--ds-duration-base) var(--ds-ease-spring);
}
.ds-switch:checked { background: var(--ds-accent-edge); }
.ds-switch:checked::before { translate: 14px 0; }
.ds-switch:dir(rtl):checked::before { translate: -14px 0; }
.ds-switch:dir(rtl)::before { inset: 3px 3px 3px auto; }
.ds-switch:disabled { opacity: .45; cursor: not-allowed; }
.ds-toggle-row { display: flex; align-items: center; gap: var(--ds-space-2); min-height: var(--ds-target); color: var(--ds-ink); font-size: var(--ds-text-md); cursor: pointer; }
.ds-toggle-row:has(:disabled) { color: var(--ds-ink-disabled); cursor: not-allowed; }

/* Chip: compact status or result label. */

.ds-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-1);
  min-height: 24px;
  padding: 0 var(--ds-space-2);
  border: 1px solid var(--ds-hairline);
  border-radius: var(--ds-radius-pill);
  color: var(--ds-ink);
  background: var(--ds-fill);
  font: 600 var(--ds-text-sm)/1.2 var(--ds-font-sans);
}

/* Dialog: a modal sheet with a header, a body and a trailing footer. */

.ds-dialog {
  width: min(400px, calc(100vw - var(--ds-space-6)));
  max-height: calc(100dvh - var(--ds-space-6));
  padding: var(--ds-space-5);
  overflow: auto;
  border-radius: var(--ds-radius-xl);
  color: var(--ds-ink);
  font-family: var(--ds-font-sans);
  overscroll-behavior: contain;
}
.ds-dialog::backdrop { background: var(--ds-scrim); }
.ds-dialog-title { margin: 0; font: 700 var(--ds-text-xl)/1.2 var(--ds-font-sans); text-wrap: balance; }
.ds-dialog-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--ds-space-2); }
@media (prefers-reduced-motion: no-preference) {
  .ds-dialog[open] { animation: ds-sheet-in var(--ds-duration-base) var(--ds-ease-sheet); }
  .ds-dialog[open]::backdrop { animation: ds-fade-in var(--ds-duration-base) var(--ds-ease-standard); }
}
@keyframes ds-sheet-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes ds-fade-in { from { opacity: 0; } }

/* Windows high contrast and other forced palettes: let system colors draw every edge. */

@media (forced-colors: active) {
  .ds-glass, .ds-dialog, .ds-stepper, .ds-segmented, .ds-chip { border: 1px solid CanvasText; }
  .ds-button { border: 1px solid ButtonText; }
  .ds-segmented > label:has(:checked):not(:has(:focus-visible)) { outline: 2px solid Highlight; outline-offset: -2px; }
  .ds-segmented > label:has(:checked:focus-visible) { text-decoration: underline; }
  .ds-switch { border: 1px solid ButtonText; appearance: auto; width: auto; height: auto; }
  .ds-switch::before { display: none; }
}
