/* ============================================================
   KCM 控制台统一滑动开关（kcm-switch）
   用法：
   <label class="kcm-switch">
     <input type="checkbox" ...>
     <span class="ks-track" aria-hidden="true"></span>
     <span class="ks-text">文案（可选）</span>
   </label>
   说明：input 保留原生 checkbox 语义与 change 事件，仅做视觉替换；
   禁用态由 input:disabled 自动呈现，无需额外改 JS。
   ============================================================ */

.kcm-switch {
  --ks-w: 42px;
  --ks-h: 24px;
  --ks-pad: 3px;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0;
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink-2, #475467);
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.kcm-switch > input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.kcm-switch .ks-track {
  position: relative;
  flex: 0 0 auto;
  width: var(--ks-w);
  height: var(--ks-h);
  border-radius: 999px;
  background: var(--line-strong, #cbd5e1);
  box-shadow: inset 0 0 0 1px rgba(17,36,39, 0.08);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.kcm-switch .ks-track::after {
  content: "";
  position: absolute;
  top: var(--ks-pad);
  left: var(--ks-pad);
  width: calc(var(--ks-h) - var(--ks-pad) * 2);
  height: calc(var(--ks-h) - var(--ks-pad) * 2);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(17,36,39, 0.28), 0 0 0 0.5px rgba(17,36,39, 0.06);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.kcm-switch:hover > input:not(:disabled) + .ks-track {
  background: #bcc4d2;
}

.kcm-switch > input:checked + .ks-track {
  background: var(--brand, #0e7c86);
  box-shadow: inset 0 0 0 1px rgba(14,124,134, 0.16);
}

.kcm-switch:hover > input:checked:not(:disabled) + .ks-track {
  background: var(--brand-hover, #0a6670);
}

.kcm-switch > input:checked + .ks-track::after {
  transform: translateX(calc(var(--ks-w) - var(--ks-h)));
}

.kcm-switch > input:focus-visible + .ks-track {
  outline: 2px solid var(--focus, #084e56);
  outline-offset: 2px;
}

.kcm-switch > input:disabled + .ks-track {
  opacity: 0.45;
}

.kcm-switch > input:disabled ~ .ks-text {
  color: var(--ink-3, #667085);
}

.kcm-switch:has(> input:disabled) {
  cursor: not-allowed;
}

.kcm-switch .ks-text {
  white-space: nowrap;
}

.kcm-switch > input:checked ~ .ks-text {
  color: var(--ink, #112427);
}

/* 表格内的开关不加额外外边距，保持单元格紧凑 */
.instance-table .kcm-switch {
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  .kcm-switch .ks-track,
  .kcm-switch .ks-track::after {
    transition: none;
  }
}