/* ===========================================
   Theme switch (design §A.8): a System / Light / Dark segmented control.
   Each option keeps .theme-toggle, so the exact .theme-toggle:focus-visible
   ring below stays meaningful (spec/design_system/focus_ring_spec.rb).
   =========================================== */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  padding: 0 var(--spacing-sm);
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.theme-toggle:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.theme-toggle__icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* A single two-icon toggle (the OAuth layout until Slice 8) shows the icon of
   the theme it switches to. */
[data-theme="dark"] .theme-toggle__icon--light,
[data-theme="light"] .theme-toggle__icon--dark {
  display: none;
}

/* Three equal columns, each as wide as the longest label, so no label is
   cut off when the switch sizes to its content. */
.theme-switch {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.theme-switch__option {
  min-width: 0;
  /* 44px below 1024px and on coarse pointers, --control-height above
     (design §A.8); the group grows by its padding and border. */
  min-height: var(--control-height);
  padding: 0 var(--spacing-sm);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
}

.theme-switch__option[aria-pressed="true"] {
  background: var(--color-surface-active);
  color: var(--color-text-emphasis);
  font-weight: var(--font-semibold);
  box-shadow: inset 0 0 0 2px var(--color-text-emphasis);
}

.theme-switch__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (forced-colors: active) {
  .theme-switch__option[aria-pressed="true"] {
    border: 2px solid Highlight;
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle {
    transition: none;
  }
}
