/**
 * BH Pill Toggle CSS — minimal iOS-style switch, no animation library.
 * Import via: <link rel="stylesheet" href="/components/pill-toggle.css" />
 *
 * Design tokens from styles.css: --accent, --bg-elevated, --surface-2, --text-secondary
 *
 * Structure (produced by createPillToggle()):
 *   <div class="bh-pill-toggle">
 *     <input type="checkbox" class="bh-pill-toggle__input" role="switch" aria-checked="false" />
 *     <div class="bh-pill-toggle__track">
 *       <div class="bh-pill-toggle__thumb"></div>
 *     </div>
 *     <label class="bh-pill-toggle__label">Label text</label>
 *   </div>
 *
 * Usage with label before:
 *   createPillToggle({ labelPosition: 'before', label: 'Dark mode' })
 */

/* ── Wrapper ─────────────────────────────────────────────────────────────── */
.bh-pill-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Hidden native checkbox (used only for a11y) ───────────────────────── */
.bh-pill-toggle__input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ── Track / pill ────────────────────────────────────────────────────────── */
.bh-pill-toggle__track {
  position: relative;
  width: 44px;
  height: 26px;
  background: var(--surface-3, #2b2b28);
  border: 1px solid var(--border-strong, rgba(255, 255, 255, 0.13));
  border-radius: 999px;
  flex-shrink: 0;
  transition: background var(--dur-micro, 110ms) var(--ease, cubic-bezier(0.4, 0, 0.2, 1)),
              border-color var(--dur-micro, 110ms) var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
  display: flex;
  align-items: center;
  padding: 0 2px;
}

/* ── Thumb ───────────────────────────────────────────────────────────────── */
.bh-pill-toggle__thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-tertiary, #78766f);
  flex-shrink: 0;
  transition: transform var(--dur-micro, 110ms) var(--anim-spring, cubic-bezier(0.22, 1, 0.36, 1)),
              background var(--dur-micro, 110ms);
  will-change: transform;
}

/* ── On state ────────────────────────────────────────────────────────────── */
.bh-pill-toggle--on .bh-pill-toggle__track {
  background: var(--accent, #d97757);
  border-color: var(--accent, #d97757);
}

.bh-pill-toggle--on .bh-pill-toggle__thumb {
  transform: translateX(18px);
  background: var(--on-fill, #ffffff);
}

/* ── Hover/focus ─────────────────────────────────────────────────────────── */
.bh-pill-toggle:hover .bh-pill-toggle__track {
  border-color: var(--border-strong, rgba(255, 255, 255, 0.13));
}

.bh-pill-toggle__input:focus-visible + .bh-pill-toggle__track {
  outline: 2px solid var(--accent, #d97757);
  outline-offset: 2px;
}

/* Click target: entire wrapper is clickable */
.bh-pill-toggle:active .bh-pill-toggle__thumb {
  transform: translateX(18px) scale(0.92);
}

.bh-pill-toggle:active:not(.bh-pill-toggle--on) .bh-pill-toggle__thumb {
  transform: translateX(2px) scale(0.92);
}

/* ── Label ──────────────────────────────────────────────────────────────── */
.bh-pill-toggle__label {
  font-size: 13.5px;
  font-family: var(--font-sans, system-ui, sans-serif);
  color: var(--text-primary, #f7f6f2);
  cursor: pointer;
  line-height: 1.3;
}

/* ── Compact variant (smaller) ──────────────────────────────────────────── */
.bh-pill-toggle--sm .bh-pill-toggle__track {
  width: 36px;
  height: 22px;
}

.bh-pill-toggle--sm .bh-pill-toggle__thumb {
  width: 16px;
  height: 16px;
}

.bh-pill-toggle--sm.bh-pill-toggle--on .bh-pill-toggle__thumb {
  transform: translateX(14px);
}

.bh-pill-toggle--sm .bh-pill-toggle__label {
  font-size: 12.5px;
}

/* ── Disabled state ─────────────────────────────────────────────────────── */
.bh-pill-toggle[aria-disabled="true"],
.bh-pill-toggle--disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* ── Respect reduced motion ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .bh-pill-toggle__thumb {
    transition: none;
  }
  .bh-pill-toggle__track {
    transition: none;
  }
  .bh-pill-toggle:active .bh-pill-toggle__thumb {
    transform: translateX(18px);
  }
  .bh-pill-toggle:active:not(.bh-pill-toggle--on) .bh-pill-toggle__thumb {
    transform: translateX(0);
  }
}

/* ── Row layout helper ──────────────────────────────────────────────────── */
/* Use .bh-pill-row in a settings row for pill toggle + value display */
.bh-pill-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap, 44px);
}

.bh-pill-row + .bh-pill-row {
  border-top: 1px solid var(--border-dim, rgba(255, 255, 255, 0.045));
}
