/* m3-switch.css — Material Design 3 Switch（参考 easemize / 21st） */

.m3-switch {
  --m3-switch-ease: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --m3-switch-track-w: 52px;
  --m3-switch-track-h: 32px;
  --m3-switch-translate: 20px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 48px;
  cursor: pointer;
  user-select: none;
}

.m3-switch__input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.m3-switch__input:focus-visible + .m3-switch__track {
  outline: 2px solid color-mix(in srgb, var(--primary) 50%, transparent);
  outline-offset: 2px;
}

.m3-switch__input:disabled + .m3-switch__track {
  opacity: 0.5;
  cursor: not-allowed;
}

.m3-switch__track {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: var(--m3-switch-track-w);
  height: var(--m3-switch-track-h);
  border: 2px solid var(--hairline);
  border-radius: var(--rounded-full);
  background: var(--surface-soft);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.m3-switch__input:checked + .m3-switch__track {
  background: var(--primary);
  border-color: var(--primary);
}

.m3-switch--destructive .m3-switch__input:checked + .m3-switch__track {
  background: var(--error);
  border-color: var(--error);
}

/* 带图标时，解开/锁定使用相同尺寸的滑块（与 M3 Icon Mode 一致） */
.m3-switch--icons .m3-switch__handle {
  width: 24px;
  height: 24px;
}

.m3-switch--icons.is-pressed .m3-switch__handle {
  width: 28px;
  height: 28px;
}

.m3-switch__handle-wrap {
  position: absolute;
  inset: 0;
  transition: transform 0.3s var(--m3-switch-ease);
  transform: translateX(0);
}

.m3-switch__input:checked + .m3-switch__track .m3-switch__handle-wrap {
  transform: translateX(var(--m3-switch-translate));
}

.m3-switch__handle {
  position: absolute;
  top: 50%;
  left: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: var(--rounded-full);
  background: var(--foreground);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  transform: translateY(-50%);
  transition: width 0.3s var(--m3-switch-ease), height 0.3s var(--m3-switch-ease), margin 0.3s var(--m3-switch-ease), background 0.3s ease, color 0.3s ease;
}

.m3-switch--destructive .m3-switch__input:not(:checked) + .m3-switch__track .m3-switch__handle {
  background: var(--success);
  color: #fff;
}

.m3-switch--destructive .m3-switch__input:not(:checked) + .m3-switch__track .m3-switch__icon--off {
  color: #fff;
}

.m3-switch--destructive .m3-switch__input:not(:checked) + .m3-switch__track .m3-switch__halo {
  background: var(--success);
}

.m3-switch__input:checked + .m3-switch__track .m3-switch__handle {
  width: 24px;
  height: 24px;
  background: #fff;
  color: var(--primary);
}

.m3-switch--destructive .m3-switch__input:checked + .m3-switch__track .m3-switch__handle {
  color: var(--error);
}

.m3-switch.is-pressed .m3-switch__handle {
  width: 28px;
  height: 28px;
  margin-left: -2px;
}

.m3-switch__icons {
  position: relative;
  width: 100%;
  height: 100%;
}

.m3-switch__icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s var(--m3-switch-ease), transform 0.3s var(--m3-switch-ease);
}

.m3-switch__icon svg {
  width: 14px;
  height: 14px;
}

.m3-switch__icon--off {
  opacity: 1;
  transform: scale(1) rotate(0deg);
  color: var(--muted);
}

.m3-switch__icon--on {
  opacity: 0;
  transform: scale(0.5) rotate(-45deg);
}

.m3-switch__input:checked + .m3-switch__track .m3-switch__icon--off {
  opacity: 0;
  transform: scale(0.5) rotate(45deg);
}

.m3-switch__input:checked + .m3-switch__track .m3-switch__icon--on {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.m3-switch__halo {
  position: absolute;
  top: 50%;
  left: 10px;
  width: 40px;
  height: 40px;
  border-radius: var(--rounded-full);
  background: var(--foreground);
  transform: translate(-50%, -50%) scale(0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, left 0.3s var(--m3-switch-ease);
}

.m3-switch.is-hovered .m3-switch__halo {
  opacity: 0.05;
  transform: translate(-50%, -50%) scale(1);
}

.m3-switch.is-pressed .m3-switch__halo {
  opacity: 0.1;
  transform: translate(-50%, -50%) scale(1);
}

.m3-switch__input:checked + .m3-switch__track .m3-switch__halo {
  left: 14px;
  background: var(--primary);
}

.m3-switch--destructive .m3-switch__input:checked + .m3-switch__track .m3-switch__halo {
  background: var(--error);
}

.m3-switch--sm {
  --m3-switch-track-w: 40px;
  --m3-switch-track-h: 24px;
  --m3-switch-translate: 16px;
}

.m3-switch--sm .m3-switch__handle {
  width: 12px;
  height: 12px;
}

.m3-switch--sm .m3-switch__input:checked + .m3-switch__track .m3-switch__handle {
  width: 16px;
  height: 16px;
}

.m3-switch--sm .m3-switch__icon svg {
  width: 10px;
  height: 10px;
}
