/*
 * RootReal Switch (InputSwitch) styles — Material UI Switch parity.
 *
 * Drives the `rr-switch` markup emitted by `toggle/input_switch.rs`. Geometry is
 * parametrised through CSS custom properties so the Small/Medium/Large size
 * modifiers and the iOS / Android 12 / Ant / MUI day-night presets all share one
 * base. The on-state colour is themeable via `--rr-switch-accent`, which the
 * dev-config sidebar sets from `aesthetics.accent_hue` / the `color` knob so the
 * Rust runtime tracks the React MUI runtime 1:1.
 */

.rr-switch {
  /* Themeable accent (overridable inline via --rr-switch-accent). */
  --rr-switch-accent: #1976d2;
  --rr-switch-track-off: rgba(0, 0, 0, 0.38);
  --rr-switch-thumb-bg: #ffffff;
  --rr-switch-thumb-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);

  /* Medium geometry (default). */
  --rr-sw-w: 58px;
  --rr-sw-h: 38px;
  --rr-sw-track-w: 34px;
  --rr-sw-track-h: 14px;
  --rr-sw-thumb: 20px;
  --rr-sw-thumb-rest: 9px;
  --rr-sw-travel: 20px;
  --rr-sw-track-opacity-off: 1;
  --rr-sw-track-opacity-on: 0.5;
  --rr-sw-thumb-radius: 50%;

  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-family: Inter, system-ui, sans-serif;
  color: #0f172a;
  user-select: none;
  vertical-align: middle;
}

/* ── Size variants ─────────────────────────────────────────────────────── */
.rr-switch--small {
  --rr-sw-w: 46px;
  --rr-sw-h: 30px;
  --rr-sw-track-w: 26px;
  --rr-sw-track-h: 11px;
  --rr-sw-thumb: 16px;
  --rr-sw-thumb-rest: 7px;
  --rr-sw-travel: 15px;
}

.rr-switch--large {
  --rr-sw-w: 74px;
  --rr-sw-h: 46px;
  --rr-sw-track-w: 44px;
  --rr-sw-track-h: 18px;
  --rr-sw-thumb: 26px;
  --rr-sw-thumb-rest: 10px;
  --rr-sw-travel: 26px;
}

/* ── Color variants (on-state accent) ──────────────────────────────────── */
.rr-switch--color-primary {
  --rr-switch-accent: #1976d2;
}
.rr-switch--color-secondary {
  --rr-switch-accent: #9c27b0;
}
.rr-switch--color-success {
  --rr-switch-accent: #2e7d32;
}
.rr-switch--color-warning {
  --rr-switch-accent: #ed6c02;
}
.rr-switch--color-error {
  --rr-switch-accent: #d32f2f;
}
.rr-switch--color-info {
  --rr-switch-accent: #0288d1;
}
.rr-switch--color-default {
  --rr-switch-accent: #6b7280;
}

/* ── Control geometry ──────────────────────────────────────────────────── */
.rr-switch__control {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  width: var(--rr-sw-w);
  height: var(--rr-sw-h);
}

.rr-switch__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: inherit;
  z-index: 1;
}

.rr-switch__track {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: var(--rr-sw-track-w);
  height: var(--rr-sw-track-h);
  border-radius: 999px;
  background: var(--rr-switch-track-off);
  opacity: var(--rr-sw-track-opacity-off);
  transition: background-color 0.2s ease, opacity 0.2s ease;
}

.rr-switch__thumb {
  position: absolute;
  top: 50%;
  left: var(--rr-sw-thumb-rest);
  transform: translateY(-50%);
  width: var(--rr-sw-thumb);
  height: var(--rr-sw-thumb);
  border-radius: var(--rr-sw-thumb-radius);
  background: var(--rr-switch-thumb-bg);
  box-shadow: var(--rr-switch-thumb-shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease;
  z-index: 0;
}

.rr-switch__thumb-icon {
  font-size: calc(var(--rr-sw-thumb) * 0.6);
  line-height: 1;
  color: var(--rr-switch-accent);
  pointer-events: none;
}

/* ── Checked state ─────────────────────────────────────────────────────── */
.rr-switch--checked .rr-switch__track {
  background: var(--rr-switch-accent);
  opacity: var(--rr-sw-track-opacity-on);
}

.rr-switch--checked .rr-switch__thumb {
  transform: translate(var(--rr-sw-travel), -50%);
}

/* ── Focus ring ────────────────────────────────────────────────────────── */
.rr-switch--focused .rr-switch__thumb {
  box-shadow: var(--rr-switch-thumb-shadow), 0 0 0 8px color-mix(in srgb, var(--rr-switch-accent) 16%, transparent);
}

/* ── Disabled / readonly / invalid ─────────────────────────────────────── */
.rr-switch--disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.rr-switch--disabled .rr-switch__control,
.rr-switch--readonly .rr-switch__control {
  cursor: not-allowed;
}
.rr-switch--invalid .rr-switch__track {
  outline: 2px solid #d32f2f;
  outline-offset: 2px;
}

/* ── Label + helper ────────────────────────────────────────────────────── */
.rr-switch__text {
  display: inline-flex;
  flex-direction: column;
  gap: 0.1rem;
}
.rr-switch__label {
  font-size: 0.9rem;
  line-height: 1.3;
}
.rr-switch__asterisk {
  color: #d32f2f;
}
.rr-switch__helper {
  font-size: 0.72rem;
  color: #64748b;
}

/* ── Label placement ───────────────────────────────────────────────────── */
.rr-switch--placement-end {
  flex-direction: row;
}
.rr-switch--placement-start {
  flex-direction: row-reverse;
}
.rr-switch--placement-top {
  flex-direction: column-reverse;
  align-items: center;
}
.rr-switch--placement-bottom {
  flex-direction: column;
  align-items: center;
}

/* ── Edge alignment (MUI `edge`) ───────────────────────────────────────── */
.rr-switch--edge-start .rr-switch__control {
  margin-left: calc(var(--rr-sw-thumb-rest) * -1);
}
.rr-switch--edge-end .rr-switch__control {
  margin-right: calc(var(--rr-sw-thumb-rest) * -1);
}

/* ── RTL ───────────────────────────────────────────────────────────────── */
.rr-switch--rtl {
  direction: rtl;
}
.rr-switch--rtl .rr-switch--checked .rr-switch__thumb,
.rr-switch--rtl.rr-switch--checked .rr-switch__thumb {
  transform: translate(calc(var(--rr-sw-travel) * -1), -50%);
}

/* ───────────────────────────────────────────────────────────────────────
 * Preset: iOS — solid coloured track, larger thumb, no track fade.
 * ─────────────────────────────────────────────────────────────────────── */
.rr-switch--preset-ios {
  --rr-switch-track-off: #e9e9ea;
  --rr-sw-track-w: var(--rr-sw-w);
  --rr-sw-track-h: var(--rr-sw-h);
  --rr-sw-track-opacity-on: 1;
  --rr-sw-thumb-rest: 3px;
  --rr-switch-thumb-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.rr-switch--preset-ios .rr-switch__thumb {
  --rr-sw-thumb: calc(var(--rr-sw-h) - 8px);
}
.rr-switch--preset-ios.rr-switch--small .rr-switch__thumb {
  --rr-sw-thumb: calc(var(--rr-sw-h) - 6px);
}
.rr-switch--preset-ios .rr-switch__thumb {
  background: #ffffff;
}

/* ───────────────────────────────────────────────────────────────────────
 * Preset: Android 12 — small thumb, check/dash glyphs in the track.
 * ─────────────────────────────────────────────────────────────────────── */
.rr-switch--preset-android12 {
  --rr-sw-track-w: var(--rr-sw-w);
  --rr-sw-track-h: calc(var(--rr-sw-h) - 12px);
  --rr-sw-thumb: calc(var(--rr-sw-h) - 24px);
  --rr-sw-thumb-rest: 6px;
  --rr-sw-track-opacity-off: 1;
  --rr-sw-track-opacity-on: 1;
  --rr-switch-track-off: rgba(0, 0, 0, 0.3);
}
.rr-switch--preset-android12 .rr-switch__thumb {
  box-shadow: none;
  background: #ffffff;
}
.rr-switch--preset-android12 .rr-switch__track::before,
.rr-switch--preset-android12 .rr-switch__track::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: calc(var(--rr-sw-track-h) * 0.85);
  line-height: 1;
  color: #ffffff;
}
.rr-switch--preset-android12 .rr-switch__track::before {
  content: "\2713"; /* check */
  left: 18%;
  opacity: 0;
}
.rr-switch--preset-android12 .rr-switch__track::after {
  content: "\2212"; /* dash */
  right: 18%;
  opacity: 1;
}
.rr-switch--preset-android12.rr-switch--checked .rr-switch__track::before {
  opacity: 1;
}
.rr-switch--preset-android12.rr-switch--checked .rr-switch__track::after {
  opacity: 0;
}

/* ───────────────────────────────────────────────────────────────────────
 * Preset: Ant Design — compact, rounded-rectangle thumb, solid track.
 * ─────────────────────────────────────────────────────────────────────── */
.rr-switch--preset-ant {
  --rr-sw-w: 44px;
  --rr-sw-h: 22px;
  --rr-sw-track-w: var(--rr-sw-w);
  --rr-sw-track-h: var(--rr-sw-h);
  --rr-sw-thumb: 18px;
  --rr-sw-thumb-rest: 2px;
  --rr-sw-travel: 22px;
  --rr-sw-track-opacity-on: 1;
  --rr-sw-thumb-radius: 50%;
  --rr-switch-track-off: rgba(0, 0, 0, 0.25);
}
.rr-switch--preset-ant.rr-switch--small {
  --rr-sw-w: 36px;
  --rr-sw-h: 18px;
  --rr-sw-thumb: 14px;
  --rr-sw-travel: 18px;
}
.rr-switch--preset-ant.rr-switch--large {
  --rr-sw-w: 56px;
  --rr-sw-h: 28px;
  --rr-sw-thumb: 24px;
  --rr-sw-travel: 28px;
}
.rr-switch--preset-ant .rr-switch__thumb {
  box-shadow: 0 2px 4px 0 rgba(0, 35, 11, 0.2);
}

/* ───────────────────────────────────────────────────────────────────────
 * Preset: MUI day-night — grey track, dark thumb with sun/moon glyph.
 * ─────────────────────────────────────────────────────────────────────── */
.rr-switch--preset-materialui {
  --rr-sw-w: 62px;
  --rr-sw-h: 34px;
  --rr-sw-track-w: var(--rr-sw-w);
  --rr-sw-track-h: 20px;
  --rr-sw-thumb: 28px;
  --rr-sw-thumb-rest: 3px;
  --rr-sw-travel: 22px;
  --rr-sw-track-opacity-off: 1;
  --rr-sw-track-opacity-on: 1;
  --rr-switch-track-off: #aab4be;
}
.rr-switch--preset-materialui .rr-switch__track {
  background: #aab4be;
}
.rr-switch--preset-materialui.rr-switch--checked .rr-switch__track {
  background: #8796a5;
}
.rr-switch--preset-materialui .rr-switch__thumb {
  background: #001e3c;
  box-shadow: none;
}
.rr-switch--preset-materialui.rr-switch--checked .rr-switch__thumb {
  background: #003892;
}
.rr-switch--preset-materialui .rr-switch__thumb-icon {
  color: #ffffff;
  font-size: calc(var(--rr-sw-thumb) * 0.55);
}
/* Default sun/moon when no custom glyph is configured. */
.rr-switch--preset-materialui .rr-switch__thumb-icon:empty::before {
  content: "\2600"; /* sun */
}
.rr-switch--preset-materialui.rr-switch--checked .rr-switch__thumb-icon:empty::before {
  content: "\263D"; /* first-quarter moon */
}
