/* Layout */
.toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
}

.toggle-input {
}

/* Switch (track + knob) */
.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    cursor: pointer;
}
.slider {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--neutral-control);
    transition: background .2s;
}
.slider::before {
    content: "";
    position: absolute; top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--bg);
    box-shadow: 0 1px 2px rgba(0,0,0,.25);
    transition: transform .2s ease-in-out;
}

/* Checked visuals */
.toggle-input:checked + .switch .slider         { background: var(--accent, #3a7252); }
.toggle-input:checked + .switch .slider::before { transform: translateX(24px); }

/* Keyboard focus ring (proxied to the visible control) */
.toggle-input:focus-visible + .switch .slider {
    outline: 2px solid var(--focus-ring, Highlight);
    outline-offset: 2px;
}

/* Text labels; only show the one matching state */
.state {
    cursor: pointer;
    font-size: var(--font-size-small);
    color: var(--text);
}
.label-checked { display: none; }
.toggle-input:checked ~ .state .label-checked { display: inline; }
.toggle-input:checked ~ .state .label-unchecked { display: none; }

/* -------------------------------------------------------------------------- */

/* Layout for the button-driven toggle */
.btn-toggle-form {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    margin: 0; /* Override default form margins */
}

/* Switch (The Button itself) */
button.btn-toggle-switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
}

.btn-toggle-switch .btn-toggle-slider {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    /* Use a slightly darker neutral for the "off" state so it pops */
    background: var(--neutral-300);
    transition: background .2s;
}

.btn-toggle-switch .btn-toggle-slider::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--bg);
    box-shadow: 0 1px 2px rgba(0,0,0,.25);
    transition: transform .2s ease-in-out;
}

/* Active visuals (Driven by the server rendering the .is-active class) */
button.btn-toggle-switch.is-active .btn-toggle-slider {
    background: var(--accent);
}
button.btn-toggle-switch.is-active .btn-toggle-slider::before {
    transform: translateX(24px);
}

/* Keyboard focus ring */
button.btn-toggle-switch:focus-visible .btn-toggle-slider {
    outline: 2px solid var(--focus-ring, Highlight);
    outline-offset: 2px;
}

/* Text label */
.btn-toggle-label {
    cursor: pointer;
    font-size: var(--font-size-small);
    color: var(--text);
    font-weight: var(--font-weight-bold);
    min-width: 60px; /* Keeps the label from jittering the layout */
}
