/**
 * Switch - Toggle switch styles
 * @countermeasure/web-components/primitives/switch
 */

/* ============================================================================
   BASE SWITCH
   ============================================================================ */
.cmm-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

/* Visually hidden checkbox input */
.cmm-switch__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Track (pill shape) */
.cmm-switch__track {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  border-radius: 9999px;
  background-color: hsl(var(--muted));
  transition: background-color var(--transition-fast) ease-in-out;
}

/* Thumb (circle) */
.cmm-switch__thumb {
  position: absolute;
  left: 2px;
  border-radius: 50%;
  background-color: white;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast) ease-in-out;
}

/* ============================================================================
   CHECKED STATE
   ============================================================================ */
.cmm-switch__input:checked + .cmm-switch__track {
  background-color: hsl(var(--primary));
}

/* ============================================================================
   SIZE VARIANTS
   ============================================================================ */

/* Small */
.cmm-switch--sm .cmm-switch__track {
  width: 28px;
  height: 16px;
}

.cmm-switch--sm .cmm-switch__thumb {
  width: 12px;
  height: 12px;
}

.cmm-switch--sm .cmm-switch__input:checked + .cmm-switch__track > .cmm-switch__thumb {
  transform: translateX(12px);
}

/* Medium (default) */
.cmm-switch--md .cmm-switch__track {
  width: 36px;
  height: 20px;
}

.cmm-switch--md .cmm-switch__thumb {
  width: 16px;
  height: 16px;
}

.cmm-switch--md .cmm-switch__input:checked + .cmm-switch__track > .cmm-switch__thumb {
  transform: translateX(16px);
}

/* Large */
.cmm-switch--lg .cmm-switch__track {
  width: 44px;
  height: 24px;
}

.cmm-switch--lg .cmm-switch__thumb {
  width: 20px;
  height: 20px;
}

.cmm-switch--lg .cmm-switch__input:checked + .cmm-switch__track > .cmm-switch__thumb {
  transform: translateX(20px);
}

/* ============================================================================
   FOCUS STATE
   ============================================================================ */
.cmm-switch__input:focus-visible + .cmm-switch__track {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
}

/* ============================================================================
   DISABLED STATE
   ============================================================================ */
.cmm-switch--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================================================================
   LABEL TEXT
   ============================================================================ */
.cmm-switch__label {
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: hsl(var(--foreground));
}
