/* Native sun/moon switch (user-provided SVGs), no external theme library. */
.theme-toggle {
  --theme-toggle-track: #d5e6f4;
  --theme-toggle-border: #7994a9;
  --theme-toggle-icon: #203b55;
  --theme-toggle-knob: #ffffff;
  position: relative;
  isolation: isolate;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  width: 78px;
  min-width: 78px;
  height: 42px;
  padding: 0 10px;
  border: 1px solid var(--theme-toggle-border);
  border-radius: 999px;
  background: var(--theme-toggle-track);
  color: var(--theme-toggle-icon);
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.theme-toggle::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: 4px;
  left: 4px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--theme-toggle-knob);
  box-shadow: 0 2px 7px rgb(5 19 37 / 23%);
  transform: translateX(0);
  transition: transform 160ms ease;
}

.theme-toggle .theme-controller {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.theme-toggle svg {
  display: block;
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  pointer-events: none;
  position: relative;
  z-index: 1;
}

.theme-toggle:has(.theme-controller:focus-visible) {
  outline: 3px solid #82baff;
  outline-offset: 3px;
}

html[data-theme="dark"] .theme-toggle {
  --theme-toggle-track: #1b3a65;
  --theme-toggle-border: #80addf;
  --theme-toggle-icon: #e7f2ff;
  --theme-toggle-knob: #0b1e39;
}

html[data-theme="dark"] .theme-toggle::before {
  transform: translateX(34px);
}

/* The Auth dialog is a top-layer element: its own switch must remain visible. */
.auth-dialog .theme-toggle {
  margin-left: auto;
}

@media (max-width: 560px) {
  .workspace-header > .theme-toggle {
    margin-left: auto;
    width: 72px;
    min-width: 72px;
  }

  html[data-theme="dark"] .workspace-header > .theme-toggle::before {
    transform: translateX(28px);
  }

  .auth-dialog .theme-toggle {
    width: 72px;
    min-width: 72px;
  }

  html[data-theme="dark"] .auth-dialog .theme-toggle::before {
    transform: translateX(28px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-toggle::before { transition: none; }
}
