/* =============================================================================
   Register V2 — Base Layout
   ============================================================================= */

.regv2 {
    position: relative;
    isolation: isolate;
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--space-3) var(--space-4) var(--space-6);
    background:
        radial-gradient(circle at 20% 15%, var(--emerald-alpha-8), transparent 42%),
        radial-gradient(circle at 82% 0%, var(--emerald-alpha-5), transparent 32%),
        var(--color-bg-primary);
    color: var(--color-text-primary);
    overflow-x: hidden;
    overflow-y: visible;
}


.regv2::before,
.regv2::after {
    content: "";
    position: absolute;
    pointer-events: none;
    border-radius: var(--radius-full);
}

.regv2::before {
    width: 32rem;
    height: 32rem;
    top: -14rem;
    right: -10rem;
    background: radial-gradient(circle, var(--emerald-alpha-12), transparent 70%);
    filter: blur(var(--glass-blur));
}

.regv2::after {
    width: 26rem;
    height: 26rem;
    bottom: -12rem;
    left: -10rem;
    background: radial-gradient(circle, var(--emerald-alpha-10), transparent 72%);
    filter: blur(var(--glass-blur));
}

/* -----------------------------------------------------------------------------
   Header
   ----------------------------------------------------------------------------- */

.regv2-topbar {
    position: relative;
    z-index: 60;
    max-width: 680px;
    margin: 0 auto var(--space-4);
    padding: var(--space-2) var(--space-3) var(--space-3);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    background: linear-gradient(180deg, var(--glass-bg-card), var(--overlay-white-4));
    backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow-sm), var(--shadow-md), var(--glow-accent-subtle);
}

.regv2-topbar--compact {
    padding-bottom: var(--space-1);
}

.regv2-topbar--compact .regv2-header {
    margin-bottom: 0;
    border-bottom: none;
}

.regv2-header {
    position: relative;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
    margin: 0 0 var(--space-3);
    padding: var(--space-1) 0;
    border-bottom: 1px solid var(--glass-border);
}

.regv2-header__logo {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

/* Logo — dark/light variants */
.regv2-header__logo-img {
    height: 30px;
    width: auto;
}

.regv2-header__logo-img--light { display: none; }
.regv2-header__logo-img--dark { display: block; }

:root[data-theme="light"] .regv2-header__logo-img--light { display: block; }
:root[data-theme="light"] .regv2-header__logo-img--dark { display: none; }

.regv2-header__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 3px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
    background: var(--glass-bg-card);
}

/* Theme switch — CSS grid + calculated thumb alignment ----------------------
   Outer: 74 × 40px, border 1px → inner: 72 × 38px
   Grid: 1fr 1fr → each cell 36px wide
   Cell centers: 18px and 54px from inner left
   Thumb: 32px circle → left: 2px (dark) / 38px (light)
   --------------------------------------------------------------------------- */
.regv2-theme-switch {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 74px;
    height: 40px;
    border-radius: var(--radius-full);
    border: 1px solid var(--glass-border);
    background: transparent;
    cursor: pointer;
    padding: 0;
    overflow: hidden;
    transition: background 0.2s var(--ease-smooth), border-color 0.2s var(--ease-smooth);
}

.regv2-theme-switch:hover {
    background: var(--overlay-white-8);
    border-color: var(--glass-border-strong);
}

.regv2-theme-switch:focus-visible {
    outline: 2px solid var(--emerald-400);
    outline-offset: 2px;
}

/* Each icon sits in its own grid cell, perfectly centered */
.regv2-theme-switch__icon {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    line-height: 1;
    color: var(--color-text-muted);
    transition: color 0.2s var(--ease-smooth);
}

/* Thumb: 32 × 32 circle, centered over cell center (18px or 54px) */
.regv2-theme-switch__thumb {
    position: absolute;
    top: 3px;
    left: 2px;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--emerald-500);
    box-shadow: var(--shadow-sm);
    transition: left 0.25s var(--ease-smooth);
    pointer-events: none;
}

/* Dark mode: thumb at left (sun highlighted) */
:root:not([data-theme="light"]) .regv2-theme-switch__icon:nth-of-type(1) {
    color: var(--brand-blue-700);
}

/* Light mode: thumb slides to right cell */
:root[data-theme="light"] .regv2-theme-switch__thumb {
    left: 38px;
}

:root[data-theme="light"] .regv2-theme-switch__icon:nth-of-type(2) {
    color: var(--brand-blue-700);
}

.regv2-lang {
    position: relative;
}

.regv2-lang__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 68px;
    gap: var(--space-1);
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    background: transparent;
    color: var(--color-text-primary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    letter-spacing: 0.06em;
    padding: 0 var(--space-2);
    transition: border-color 0.15s var(--ease-smooth), background 0.15s var(--ease-smooth);
}

.regv2-lang__trigger:hover {
    border-color: var(--glass-border);
    background: var(--overlay-white-8);
}

.regv2-lang__trigger:focus-visible {
    outline: 2px solid var(--emerald-400);
    outline-offset: 2px;
}

.regv2-lang__code {
    line-height: 1;
}

.regv2-lang__chevron {
    font-size: 10px;
    color: var(--color-text-muted);
}

.regv2-lang__menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(280px, calc(100vw - 24px));
    max-height: 340px;
    overflow-y: auto;
    padding: var(--space-1);
    border: 1px solid var(--glass-border-strong);
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--color-bg-secondary) 90%, transparent);
    backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow-card);
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity 0.16s var(--ease-smooth), transform 0.16s var(--ease-smooth);
    z-index: 2000;
}

.regv2-lang.is-open .regv2-lang__menu {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.regv2-lang__option {
    width: 100%;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--space-2);
    font-size: var(--font-size-sm);
    text-align: left;
}

.regv2-lang__option:hover {
    background: var(--overlay-white-8);
    color: var(--color-text-primary);
}

.regv2-lang__option:focus-visible {
    outline: 2px solid var(--emerald-400);
    outline-offset: 1px;
}

.regv2-lang__option.is-active {
    border-color: var(--emerald-alpha-30);
    background: var(--emerald-alpha-12);
    color: var(--color-text-primary);
}

.regv2-lang__option-code {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    letter-spacing: 0.05em;
}

/* -----------------------------------------------------------------------------
   Progress indicator — minimal bar + label
   ----------------------------------------------------------------------------- */

.regv2-progress {
    position: relative;
    z-index: 2;
    margin: 0;
    padding: 0;
}


.regv2-progress__info {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.regv2-progress__label {
    min-width: 0;
    flex: 1;
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-normal);
    overflow-wrap: anywhere;
    letter-spacing: 0.01em;
}

.regv2-progress__counter {
    flex-shrink: 0;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
    padding: 0 var(--space-2);
    min-height: 24px;
    border-radius: var(--radius-full);
    border: 1px solid var(--glass-border);
    background: var(--overlay-white-4);
    display: inline-flex;
    align-items: center;
}

.regv2-progress__track {
    height: 3px;
    border-radius: 2px;
    background: var(--overlay-white-8);
    overflow: hidden;
}

.regv2-progress__fill {
    height: 100%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--emerald-500), var(--emerald-400));
    transition: width 0.5s var(--ease-smooth);
    width: 0%;
}

.regv2-progress__meta {
    margin: var(--space-2) 0 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    letter-spacing: 0.02em;
    opacity: 0.72;
}

/* -----------------------------------------------------------------------------
   Content & Steps
   ----------------------------------------------------------------------------- */

.regv2-content {
    position: relative;
    z-index: 2;
    max-width: 680px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
}

.regv2-step {
    width: 100%;
    max-width: 680px;
    display: none;
    animation: regv2FadeIn 0.3s var(--ease-out-expo);
}

.regv2-step--active {
    display: block;
}

/* -----------------------------------------------------------------------------
   Card
   ----------------------------------------------------------------------------- */

.regv2-card {
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-2xl);
    background: var(--glass-bg-card);
    backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow-card), var(--shadow-md), var(--glow-accent-subtle);
    padding: var(--space-8);
    text-align: left;
}

.regv2-card__icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-icon-emerald-border);
    background: var(--glass-icon-emerald);
    color: var(--emerald-500);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xl);
    margin-bottom: var(--space-5);
    box-shadow: var(--shadow-inner-soft);
}

.regv2-card__icon i {
    color: inherit;
}

.regv2-card__icon--indigo {
    color: var(--indigo-500);
    border-color: var(--glass-icon-indigo-border);
    background: var(--glass-icon-indigo);
}

.regv2-card__icon--emerald {
    color: var(--emerald-500);
    border-color: var(--glass-icon-emerald-border);
    background: var(--glass-icon-emerald);
}

.regv2-card__icon--purple {
    color: var(--purple-500);
    border-color: var(--glass-icon-purple-border);
    background: var(--glass-icon-purple);
}

.regv2-card__icon--cyan {
    color: var(--cyan-500);
    border-color: var(--glass-icon-cyan-border);
    background: var(--glass-icon-cyan);
}

.regv2-card__icon--teal {
    color: var(--teal-500);
    border-color: var(--glass-icon-teal-border);
    background: var(--glass-icon-teal);
}

.regv2-card__icon--gold {
    color: var(--gold-500);
    border-color: var(--glass-icon-gold-border);
    background: var(--glass-icon-gold);
}

.regv2-card__icon--rose {
    background: var(--glass-icon-rose);
    border-color: var(--glass-icon-rose-border);
    color: var(--rose-500);
}

.regv2-card__title {
    margin: 0 0 var(--space-3);
    font-size: clamp(var(--font-size-2xl), 3vw, var(--font-size-3xl));
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
    color: var(--color-text-primary);
    text-wrap: balance;
}

.regv2-card__subtitle {
    margin: 0 0 var(--space-8);
    max-width: 60ch;
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    color: var(--color-text-secondary);
    text-wrap: pretty;
}

.regv2-card__footer {
    border-top: 1px solid var(--glass-border);
    padding-top: var(--space-4);
    margin-top: var(--space-4);
}

.regv2-placeholder {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    text-align: center;
    padding: var(--space-6);
}

/* -----------------------------------------------------------------------------
   Animation
   ----------------------------------------------------------------------------- */

@keyframes regv2FadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* -----------------------------------------------------------------------------
   Tablet — 641px to 920px
   Compact stepper (circles only, no labels), 2-col forms
   ----------------------------------------------------------------------------- */

@media (min-width: 641px) and (max-width: 920px) {
    .regv2 {
        padding: var(--space-4) var(--space-3) var(--space-5);
    }

    .regv2-card {
        padding: var(--space-6) var(--space-5);
        border-radius: var(--radius-xl);
    }

    .regv2-card__subtitle {
        font-size: var(--font-size-sm);
    }

    .regv2-topbar {
        padding: var(--space-2);
    }

    .regv2-header__actions {
        gap: var(--space-1);
    }
}

/* -----------------------------------------------------------------------------
   Mobile — <=640px
   Hide full stepper, show mobile counter
   ----------------------------------------------------------------------------- */

@media (max-width: 640px) {
    .regv2 {
        padding: var(--space-3) var(--space-3) var(--space-5);
    }

    .regv2-progress {
        margin-bottom: var(--space-4);
    }

    .regv2-progress__meta {
        display: none;
    }

    .regv2-card {
        padding: var(--space-5) var(--space-4);
        border-radius: var(--radius-xl);
    }

    .regv2-card__title {
        font-size: var(--font-size-xl);
    }

    .regv2-card__subtitle {
        font-size: var(--font-size-sm);
    }

    .regv2-header {
        padding: var(--space-1) 0;
        margin-bottom: 0;
        border-bottom: none;
    }

    .regv2-topbar {
        padding: var(--space-2);
        margin-bottom: var(--space-3);
        border-radius: var(--radius-lg);
    }

    .regv2-header__actions {
        padding: 2px;
    }

    .regv2-progress__label {
        font-size: var(--font-size-sm);
    }

    .regv2-progress__counter {
        min-height: 26px;
    }

}

/* -----------------------------------------------------------------------------
   Reduced Motion
   ----------------------------------------------------------------------------- */

/* --- Toast fallback ------------------------------------------------------- */
.regv2-toast {
    position: fixed;
    top: var(--space-6);
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    z-index: 9999;
    padding: var(--space-3) var(--space-6);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-sm);
    opacity: 0;
    transition: opacity 0.3s var(--ease-smooth), transform 0.3s var(--ease-smooth);
    pointer-events: none;
}
.regv2-toast--visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}
.regv2-toast--error {
    background: var(--red-500);
    color: var(--white);
}

/* --- Light mode color overrides -------------------------------------------- */

:root[data-theme="light"] .regv2-card__icon {
    box-shadow: var(--shadow-inner-soft), var(--shadow-sm);
}

:root[data-theme="light"] .regv2-card {
    border-color: var(--glass-border);
    box-shadow: var(--shadow-sm), var(--shadow-md);
}

/* --- Reduced motion ------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .regv2-step,
    .regv2-phase,
    .regv2-progress__fill,
    .regv2-enrich-mode,
    .regv2-source-card,
    .regv2-sources__input-area,
    .regv2-success__icon,
    #ideaModeFields {
        animation: none !important;
        transition: none !important;
    }

    .regv2-spinner,
    .regv2-btn--loading::after {
        animation-duration: 1.5s !important;
    }
}
