/* =========================================
   Dark Mode Toggle — Standalone Styles
   Only the variables + toggle switch needed
   outside WordPress (e.g. Next.js embed).
   ========================================= */

/* Variables used by the toggle */
:root {
    --mz-dm-card: #1f2937;
    --mz-dm-border: #374151;

    /* Track + knob */
    --mz-dm-track-bg: #e4e7ec;
    --mz-dm-track-border: #d3d7de;
    --mz-dm-knob-bg: #ffffff;
    --mz-dm-track-bg-dark: #374151;
    --mz-dm-track-border-dark: #4b5563;
    --mz-dm-knob-bg-dark: #111827;

    /* Icons. The "active" tones sit on the knob, the "idle" tones on the track.
       Both pairs clear 3:1 against their own backdrop (WCAG AA, non-text). */
    --mz-dm-sun-color: #f59e0b;      /* legacy name, kept: used elsewhere in the DM sheet */
    --mz-dm-sun-active: #d97706;     /* on the white knob */
    --mz-dm-sun-idle: #9ca3af;       /* on the dark track */
    --mz-dm-moon-active: #fbbf24;    /* on the dark knob */
    --mz-dm-moon-idle: #6b7280;      /* on the light track */

    /* Motion — 08-motion-principles.md scale */
    --mz-dm-duration: 200ms;
    --mz-dm-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* =========================================
   Toggle Switch — Fixed Position

   Geometry is intentionally physical (left / translateX), not logical:
   a switch is not text, and WordPress (RTL) and the Next.js embed must render
   the sun/moon on the same side. Sun left, moon right, in both directions.

   High specificity + !important required to defeat Elementor / theme global
   <button> styles that otherwise paint the toggle in the site accent color.
   ========================================= */
html body button.mz-dark-toggle,
html body button.mz-dark-toggle:hover,
html body button.mz-dark-toggle:focus,
html body button.mz-dark-toggle:active {
    position: fixed !important;
    top: 120px !important;
    left: 20px !important;
    width: 68px !important;
    height: 36px !important;
    padding: 0 !important;
    margin: 0 !important;
    background: var(--mz-dm-track-bg) !important;
    background-color: var(--mz-dm-track-bg) !important;
    background-image: none !important;
    border: 1px solid var(--mz-dm-track-border) !important;
    border-radius: 999px !important;
    display: block !important;
    cursor: pointer !important;
    z-index: 999999 !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15) !important;
    transition: background-color var(--mz-dm-duration) var(--mz-dm-ease),
                border-color var(--mz-dm-duration) var(--mz-dm-ease),
                box-shadow var(--mz-dm-duration) var(--mz-dm-ease) !important;
    color: var(--mz-dm-card) !important;
    text-decoration: none !important;
    outline: none !important;
    -webkit-tap-highlight-color: transparent !important;
}

/* Expand the hit area to 44px tall without growing the visible track. */
html body button.mz-dark-toggle::before {
    content: "" !important;
    position: absolute !important;
    inset: -5px 0 !important;
    border-radius: inherit !important;
}

html[data-theme="dark"] body button.mz-dark-toggle,
html[data-theme="dark"] body button.mz-dark-toggle:hover,
html[data-theme="dark"] body button.mz-dark-toggle:focus,
html[data-theme="dark"] body button.mz-dark-toggle:active {
    background: var(--mz-dm-track-bg-dark) !important;
    background-color: var(--mz-dm-track-bg-dark) !important;
    background-image: none !important;
    border-color: var(--mz-dm-track-border-dark) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5) !important;
}

/* =========================================
   Knob — slides between the two icons
   ========================================= */
.mz-dark-toggle .mz-toggle-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--mz-dm-knob-bg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transform: translateX(0);
    transition: transform var(--mz-dm-duration) var(--mz-dm-ease),
                background-color var(--mz-dm-duration) var(--mz-dm-ease);
    z-index: 1;
}

html[data-theme="dark"] .mz-dark-toggle .mz-toggle-knob {
    background: var(--mz-dm-knob-bg-dark);
    transform: translateX(32px);
}

/* =========================================
   Icons — both always visible.
   The one under the knob is the active mode.
   ========================================= */
.mz-dark-toggle .mz-icon-sun,
.mz-dark-toggle .mz-icon-moon {
    position: absolute;
    top: 50%;
    width: 20px;
    height: 20px;
    margin-top: -10px;
    z-index: 2;
    transition: color var(--mz-dm-duration) var(--mz-dm-ease);
}

.mz-dark-toggle .mz-icon-sun {
    left: 7px;
}

.mz-dark-toggle .mz-icon-moon {
    left: 39px;
}

/* Light mode: sun is active (on the knob), moon is idle (on the track) */
.mz-dark-toggle .mz-icon-sun {
    color: var(--mz-dm-sun-active);
}

.mz-dark-toggle .mz-icon-moon {
    color: var(--mz-dm-moon-idle);
}

/* Dark mode: the roles swap */
html[data-theme="dark"] .mz-dark-toggle .mz-icon-sun {
    color: var(--mz-dm-sun-idle);
}

html[data-theme="dark"] .mz-dark-toggle .mz-icon-moon {
    color: var(--mz-dm-moon-active);
}

/* =========================================
   Hover & Press
   ========================================= */
html body button.mz-dark-toggle:hover {
    border-color: var(--mz-dm-sun-active) !important;
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.35) !important;
}

html[data-theme="dark"] body button.mz-dark-toggle:hover {
    border-color: var(--mz-dm-moon-active) !important;
    box-shadow: 0 4px 16px rgba(251, 191, 36, 0.35) !important;
}

html body button.mz-dark-toggle:active .mz-toggle-knob {
    transform: translateX(0) scale(0.92);
    transition-duration: 100ms;
}

html[data-theme="dark"] body button.mz-dark-toggle:active .mz-toggle-knob {
    transform: translateX(32px) scale(0.92);
    transition-duration: 100ms;
}

/* Accessibility — keyboard focus ring */
html body button.mz-dark-toggle:focus-visible {
    outline: 3px solid rgba(51, 100, 173, .45) !important;
    outline-offset: 3px !important;
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    html body button.mz-dark-toggle,
    .mz-dark-toggle .mz-toggle-knob,
    .mz-dark-toggle .mz-icon-sun,
    .mz-dark-toggle .mz-icon-moon {
        transition: none !important;
    }

    html body button.mz-dark-toggle:active .mz-toggle-knob {
        transform: translateX(0) !important;
    }

    html[data-theme="dark"] body button.mz-dark-toggle:active .mz-toggle-knob {
        transform: translateX(32px) !important;
    }
}

/* =========================================
   Mobile — the switch stands up

   Below the phone/tablet boundary the pill rotates to portrait: sun on top,
   moon on the bottom, knob sliding down instead of across. It keeps the toggle
   off the horizontal axis where thumbs and sticky UI compete for room on a
   narrow screen, and it stays clear of content pinned to the side edges.
   ========================================= */
@media (max-width: 767px) {
    html body button.mz-dark-toggle,
    html body button.mz-dark-toggle:hover,
    html body button.mz-dark-toggle:focus,
    html body button.mz-dark-toggle:active {
        width: 36px !important;
        height: 68px !important;
    }

    /* Track is narrower than the 44px minimum, so widen the hit area instead. */
    html body button.mz-dark-toggle::before {
        inset: 0 -5px !important;
    }

    /* Same 7 / 39 offsets as desktop, just on the other axis. */
    .mz-dark-toggle .mz-icon-sun {
        left: 7px;
        top: 7px;
        margin-top: 0;
    }

    .mz-dark-toggle .mz-icon-moon {
        left: 7px;
        top: 39px;
        margin-top: 0;
    }

    .mz-dark-toggle .mz-toggle-knob {
        transform: translateY(0);
    }

    html[data-theme="dark"] .mz-dark-toggle .mz-toggle-knob {
        transform: translateY(32px);
    }

    html body button.mz-dark-toggle:active .mz-toggle-knob {
        transform: translateY(0) scale(0.92);
    }

    html[data-theme="dark"] body button.mz-dark-toggle:active .mz-toggle-knob {
        transform: translateY(32px) scale(0.92);
    }
}

@media (max-width: 767px) and (prefers-reduced-motion: reduce) {
    html body button.mz-dark-toggle:active .mz-toggle-knob {
        transform: translateY(0) !important;
    }

    html[data-theme="dark"] body button.mz-dark-toggle:active .mz-toggle-knob {
        transform: translateY(32px) !important;
    }
}

/* =========================================
   Smooth Transition
   ========================================= */
html {
    transition: background-color 0.3s ease, color 0.3s ease;
}

html.mz-transitioning,
html.mz-transitioning * {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

/* The knob must keep its own timing during a theme switch, otherwise the
   blanket .mz-transitioning rule above suppresses the slide. */
html.mz-transitioning .mz-dark-toggle .mz-toggle-knob {
    transition: transform var(--mz-dm-duration) var(--mz-dm-ease),
                background-color var(--mz-dm-duration) var(--mz-dm-ease) !important;
}
