/* -------------------------------------------------------------------------
   Theme switch — the three-way slider shared by the admin panel and the
   HarmonyTech workspace. Self-contained: it carries its own tokens per
   `data-theme`, so it looks the same on both surfaces without depending on
   either stylesheet. js/theme-modes.js keeps `data-active` in sync.
   ------------------------------------------------------------------------- */
.theme-switch {
    --ts-bg: rgba(255, 255, 255, .1);
    --ts-border: rgba(255, 255, 255, .18);
    --ts-fg: rgba(255, 255, 255, .68);
    --ts-fg-active: #ffffff;
    --ts-thumb: rgba(255, 255, 255, .2);
    --ts-thumb-border: rgba(255, 255, 255, .28);
    --ts-focus: rgba(255, 255, 255, .35);
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0;
    padding: 3px;
    border: 1px solid var(--ts-border);
    border-radius: 999px;
    background: var(--ts-bg);
    line-height: 1;
}
.theme-switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    z-index: 0;
    width: calc((100% - 6px) / 3);
    height: calc(100% - 6px);
    border: 1px solid var(--ts-thumb-border);
    border-radius: 999px;
    background: var(--ts-thumb);
    transition: transform .22s cubic-bezier(.4, 0, .2, 1);
}
.theme-switch[data-active="light"] .theme-switch-thumb { transform: translateX(0); }
.theme-switch[data-active="dark"] .theme-switch-thumb { transform: translateX(100%); }
.theme-switch[data-active="developer"] .theme-switch-thumb { transform: translateX(200%); }

/* The public site renders a two-option switch (light/dark); `developer` stays
   a tooling mode with no button of its own. The thumb is sized from the
   rendered option count so the same component serves both widths. A stored
   `developer` still paints dark tokens, so the thumb parks on `dark`. */
.theme-switch[data-theme-count="2"] .theme-switch-thumb { width: calc((100% - 6px) / 2); }
.theme-switch[data-theme-count="2"][data-active="developer"] .theme-switch-thumb { transform: translateX(100%); }
.theme-switch-option {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 1 0 auto;
    min-width: 34px;
    height: 28px;
    padding: 0 10px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--ts-fg);
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .01em;
    cursor: pointer;
    transition: color .18s ease;
}
.theme-switch-option i { font-size: 13px; }
.theme-switch-option:hover { color: var(--ts-fg-hover, var(--ts-fg-active)); }
.theme-switch-option[aria-checked="true"] { color: var(--ts-fg-active); }
.theme-switch-option:focus-visible { outline: 0; box-shadow: 0 0 0 3px var(--ts-focus); }
.theme-switch-text { white-space: nowrap; }

/* No transition before the boot script has settled the initial position. */
.theme-switch:not([data-ready]) .theme-switch-thumb { transition: none; }

/* The public header is a light surface in the light theme, and the base tokens
   above are white at low alpha — they assume the dark admin topbar. Rendered
   unchanged on the site header that meant white on white: a 1:1 contrast
   ratio, an invisible control. Taking the ink from the --site-* tokens fixes
   both themes at once, because those flip with the theme by design.
   Same shape as the workspace block below it. */
.theme-switch-site {
    --ts-bg: var(--site-surface, #f8fafc);
    --ts-border: var(--site-border, #e2e8f0);
    --ts-fg: var(--site-fg-muted, #64748b);
    /* Sits on the raised thumb, which is the canvas — and --site-accent-fg is
       contrast-checked against exactly that. */
    --ts-fg-active: var(--site-accent-fg, #4f46e5);
    /* Hover happens on the track, not the thumb, so it needs its own value. */
    --ts-fg-hover: var(--site-fg, #0f172a);
    --ts-thumb: var(--site-canvas, #ffffff);
    --ts-thumb-border: var(--site-border, #e2e8f0);
    --ts-focus: var(--site-accent-muted, rgba(109, 93, 251, .35));
}

/* The workspace topbar is a light surface, so the switch needs real ink. */
.harmony-workspace .theme-switch,
[data-theme="light"] .harmony-workspace .theme-switch {
    --ts-bg: var(--harmony-surface-soft, #f8f9fc);
    --ts-border: var(--harmony-border, #e4e8f0);
    --ts-fg: var(--harmony-muted, #6b7487);
    --ts-fg-active: var(--harmony-accent, #4f46e5);
    --ts-thumb: var(--harmony-surface, #fff);
    --ts-thumb-border: var(--harmony-border, #e4e8f0);
    --ts-focus: color-mix(in srgb, var(--harmony-accent, #4f46e5) 30%, transparent);
    height: 45px;
    border-radius: 13px;
    padding: 4px;
}
.harmony-workspace .theme-switch-thumb { border-radius: 10px; }
.harmony-workspace .theme-switch-option { height: 100%; border-radius: 10px; font-size: 11px; }

[data-theme="dark"] .harmony-workspace .theme-switch,
[data-theme="developer"] .harmony-workspace .theme-switch {
    --ts-thumb: var(--harmony-surface-soft);
    --ts-fg: var(--harmony-muted);
    --ts-fg-active: #fff;
    --ts-bg: var(--harmony-bg);
}

@media (max-width: 991px) {
    .theme-switch-text { display: none; }
    .theme-switch-option { min-width: 32px; padding: 0 8px; }
}
