/* ── Unidy Frontend — panel + SDK component styling ──────────────────────── *
 *                                                                            *
 * SDK components are styled via two mechanisms:                              *
 *   1. class-name prop  → SDK applies the class to its internal element     *
 *      → we target it with regular CSS (e.g. .u-input, .u-btn-primary)      *
 *   2. ::part() selectors → target exported Shadow DOM parts                *
 *      (u-submit-button::part(button), u-field::part(input_field), etc.)    *
 * ─────────────────────────────────────────────────────────────────────────── */

/* ── Design tokens ────────────────────────────────────────────────────────── */
:root {
    --u-primary:       #0a0a14;
    --u-primary-hover: #1e1e32;
    --u-border:        #d1d5db;
    --u-border-focus:  #0a0a14;
    --u-bg:            #ffffff;
    --u-bg-muted:      #f9fafb;
    --u-text:          #111111;
    --u-text-muted:    #6b7280;
    --u-danger:        #dc2626;
    --u-radius:        8px;
    --u-input-h:       48px;
    --u-provider-h:    46px;
}

/* ── Page scroll lock ─────────────────────────────────────────────────────── */
body.unidy-open {
    overflow: hidden !important;
}

/* ── Backdrop ─────────────────────────────────────────────────────────────── */
#unidy-backdrop {
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    z-index: 99998;
    background: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 250ms ease;
}
#unidy-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}

/* ── Panel shell ──────────────────────────────────────────────────────────── */
#unidy-panel {
    position: fixed !important;
    top: 0 !important; right: 0 !important; bottom: 0 !important;
    z-index: 99999 !important;
    width: 100% !important;
    max-width: 420px !important;
    height: 100vh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    box-sizing: border-box !important;
    background: #fff !important;
    box-shadow: -8px 0 48px rgba(0,0,0,.16) !important;
    margin: 0 !important; padding: 0 !important;
    border: none !important; border-radius: 0 !important;
    transform: translateX(100%) !important;
    transition: transform 300ms cubic-bezier(.4,0,.2,1) !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    font-size: 15px !important;
    color: var(--u-text) !important;
    line-height: 1.5 !important;
}
#unidy-panel.is-open {
    transform: translateX(0) !important;
}

/* ── Panel header ─────────────────────────────────────────────────────────── */
#unidy-panel .unidy-panel__header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 18px 24px !important;
    border-bottom: 1px solid #f0f0f0 !important;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
}
#unidy-panel .unidy-panel__logo { display: flex !important; align-items: center !important; }
#unidy-panel .unidy-panel__logo a { display: block !important; line-height: 0 !important; }
#unidy-panel .unidy-panel__logo img {
    display: block !important; height: 36px !important; width: auto !important;
    max-width: 140px !important; object-fit: contain !important;
}
#unidy-panel .unidy-panel__logo span {
    font-size: 16px !important; font-weight: 700 !important; color: var(--u-primary) !important;
}
#unidy-panel .unidy-panel__close {
    display: flex !important; align-items: center !important; justify-content: center !important;
    width: 36px !important; height: 36px !important; min-width: 36px !important;
    border: none !important; background: #f5f5f5 !important; border-radius: 50% !important;
    cursor: pointer !important; color: #555 !important;
    padding: 0 !important; margin: 0 !important; box-shadow: none !important; outline: none !important;
    flex-shrink: 0 !important; transition: background 140ms, color 140ms;
}
#unidy-panel .unidy-panel__close:hover { background: #e5e5e5 !important; color: #111 !important; }
#unidy-panel .unidy-panel__close svg { display: block !important; pointer-events: none !important; }

/* ── Panel body ───────────────────────────────────────────────────────────── */
#unidy-panel .unidy-panel__body {
    flex: 1 !important;
    padding: 28px 24px 36px !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    min-height: 0 !important;
}

/* ── SDK wrap ─────────────────────────────────────────────────────────────── */
#unidy-panel .unidy-sdk-wrap { flex: 1 !important; min-height: 0 !important; }

/* ── Status message ───────────────────────────────────────────────────────── */
#unidy-panel .unidy-panel__status {
    margin-top: 16px !important; padding: 12px 16px !important;
    border-radius: var(--u-radius) !important; font-size: 13px !important; text-align: center !important;
}
#unidy-panel .unidy-panel__status--loading { background: #f5f5f5 !important; color: #444 !important; }
#unidy-panel .unidy-panel__status--error   { background: #fef2f2 !important; color: var(--u-danger) !important; }

/* ── Mobile: bottom sheet ─────────────────────────────────────────────────── */
@media (max-width: 520px) {
    #unidy-panel {
        top: auto !important; left: 0 !important; right: 0 !important;
        width: 100% !important; max-width: 100% !important;
        height: 92vh !important;
        border-radius: 20px 20px 0 0 !important;
        transform: translateY(100%) !important;
    }
    #unidy-panel.is-open { transform: translateY(0) !important; }
}

/* ════════════════════════════════════════════════════════════════════════════
   LOGGED-IN PROFILE VIEW
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Avatar + name + email header ─────────────────────────────────────────── */
#unidy-panel .unidy-profile-header {
    display: flex !important;
    align-items: center !important;
    gap: 16px !important;
    padding: 0 0 24px !important;
    border-bottom: 1px solid #f0f0f0 !important;
    margin-bottom: 28px !important;
}

#unidy-panel .unidy-avatar {
    flex-shrink: 0 !important;
    width: 52px !important; height: 52px !important;
    border-radius: 50% !important;
    background: var(--u-primary) !important;
    color: #fff !important;
    font-size: 18px !important; font-weight: 700 !important;
    letter-spacing: .03em !important;
    display: flex !important; align-items: center !important; justify-content: center !important;
    user-select: none !important;
}

#unidy-panel .unidy-profile-meta { min-width: 0 !important; }

#unidy-panel .unidy-profile-name {
    font-size: 16px !important; font-weight: 700 !important;
    color: var(--u-text) !important; line-height: 1.3 !important;
    white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important;
}

#unidy-panel .unidy-profile-email {
    font-size: 13px !important; color: var(--u-text-muted) !important;
    margin-top: 3px !important;
    white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important;
}

/* ── Profile form section ─────────────────────────────────────────────────── */
#unidy-panel .unidy-profile-section { margin-bottom: 28px !important; }

#unidy-panel .unidy-section-label {
    font-size: 11px !important; font-weight: 700 !important;
    text-transform: uppercase !important; letter-spacing: .08em !important;
    color: var(--u-text-muted) !important;
    margin: 0 0 14px !important; padding: 0 !important;
}

/* ── u-field (profile) — all ::part() exports ─────────────────────────────── */

u-field {
    display: block !important;
    margin-bottom: 14px !important;
}

u-field::part(field-container) {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 100%;
}

u-field::part(field_label) {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--u-text-muted);
}

u-field::part(field-input-wrapper) {
    display: block;
    width: 100%;
    position: relative;
}

/* Editable input */
u-field::part(input_field),
u-field::part(select_field),
u-field::part(textarea_field) {
    display: block;
    width: 100%;
    height: var(--u-input-h);
    padding: 0 14px;
    border: 1.5px solid var(--u-border);
    border-radius: var(--u-radius);
    background: var(--u-bg);
    font-family: inherit;
    font-size: 15px;
    color: var(--u-text);
    outline: none;
    box-sizing: border-box;
    transition: border-color 160ms, box-shadow 160ms;
}
u-field::part(input_field):focus,
u-field::part(select_field):focus {
    border-color: var(--u-border-focus);
    box-shadow: 0 0 0 3px rgba(10,10,20,.1);
}

/* Read-only state (current value before user clicks to edit) */
u-field::part(input_field--readonly),
u-field::part(select_field--readonly) {
    background: var(--u-bg-muted) !important;
    border-color: transparent !important;
    border-style: solid !important;
    color: var(--u-text) !important;
    cursor: pointer !important;
}
u-field::part(input_field--readonly):hover,
u-field::part(select_field--readonly):hover {
    border-color: var(--u-border) !important;
    background: #f3f4f6 !important;
}

/* Save state indicators */
u-field::part(field-save-indicator) {
    font-size: 12px;
    color: var(--u-text-muted);
}
u-field::part(field-save-indicator--saving) {
    color: var(--u-text-muted);
}
u-field::part(field-save-indicator--saved) {
    color: #16a34a;
}

/* Error message */
u-field::part(field-error-message) {
    font-size: 12px;
    color: var(--u-danger);
    margin-top: 3px;
}

/* Required asterisk */
u-field::part(required-indicator) {
    color: var(--u-danger);
    margin-left: 2px;
}

/* ── Logout button ────────────────────────────────────────────────────────── */
#unidy-panel .unidy-profile-footer {
    margin-top: auto !important;
    padding-top: 24px !important;
}

.u-btn-logout {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    width: 100% !important;
    padding: 12px 16px !important;
    background: transparent !important;
    color: var(--u-danger) !important;
    border: 1.5px solid #fecaca !important;
    border-radius: var(--u-radius) !important;
    font-family: inherit !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    box-sizing: border-box !important;
    transition: background 160ms, border-color 160ms;
    text-align: center !important;
}
.u-btn-logout:hover {
    background: #fef2f2 !important;
    border-color: var(--u-danger) !important;
}

u-logout-button.u-btn-logout::part(button) {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    color: var(--u-danger);
    border: 1.5px solid #fecaca;
    border-radius: var(--u-radius);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    box-sizing: border-box;
    transition: background 160ms, border-color 160ms;
}
u-logout-button.u-btn-logout::part(button):hover {
    background: #fef2f2;
    border-color: var(--u-danger);
}

/* ════════════════════════════════════════════════════════════════════════════
   SDK COMPONENT STYLES
   Targets: class-name prop values (.u-input, .u-btn-primary, etc.)
            and ::part() pseudo-elements exported by the SDK
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Text inputs (u-email-field, u-password-field, u-raw-field via class-name="u-input") */
.u-input {
    display: block !important;
    width: 100% !important;
    height: var(--u-input-h) !important;
    padding: 0 14px !important;
    border: 1.5px solid var(--u-border) !important;
    border-radius: var(--u-radius) !important;
    background: var(--u-bg) !important;
    font-family: inherit !important;
    font-size: 15px !important;
    color: var(--u-text) !important;
    outline: none !important;
    box-sizing: border-box !important;
    transition: border-color 160ms, box-shadow 160ms;
    margin-bottom: 12px !important;
}
.u-input:focus {
    border-color: var(--u-border-focus) !important;
    box-shadow: 0 0 0 3px rgba(10,10,20,.1) !important;
}
.u-input::placeholder { color: var(--u-text-muted) !important; }

/* Also target the rendered input via ::part() */
u-email-field::part(input_field),
u-password-field::part(input_field),
u-raw-field::part(input_field) {
    display: block;
    width: 100%;
    height: var(--u-input-h);
    padding: 0 14px;
    border: 1.5px solid var(--u-border);
    border-radius: var(--u-radius);
    background: var(--u-bg);
    font-family: inherit;
    font-size: 15px;
    color: var(--u-text);
    outline: none;
    box-sizing: border-box;
    transition: border-color 160ms, box-shadow 160ms;
    margin-bottom: 12px;
}
u-email-field::part(input_field):focus,
u-password-field::part(input_field):focus,
u-raw-field::part(input_field):focus {
    border-color: var(--u-border-focus);
    box-shadow: 0 0 0 3px rgba(10,10,20,.1);
}

/* ── Primary action button (class-name="u-btn-primary") */
.u-btn-primary {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    height: var(--u-input-h) !important;
    padding: 0 20px !important;
    background: var(--u-primary) !important;
    color: #fff !important;
    border: none !important;
    border-radius: var(--u-radius) !important;
    font-family: inherit !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    box-sizing: border-box !important;
    transition: background 160ms;
    margin-top: 4px !important;
    margin-bottom: 0 !important;
    text-decoration: none !important;
}
.u-btn-primary:hover { background: var(--u-primary-hover) !important; }

u-submit-button.u-btn-primary::part(button),
u-skip-button.u-btn-primary::part(button) {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: var(--u-input-h);
    padding: 0 20px;
    background: var(--u-primary) !important;
    color: #fff !important;
    border: none !important;
    border-radius: var(--u-radius);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-sizing: border-box;
    transition: background 160ms;
    margin-top: 4px;
}
u-submit-button.u-btn-primary::part(button):hover,
u-skip-button.u-btn-primary::part(button):hover {
    background: var(--u-primary-hover) !important;
}

/* ── Provider buttons: Google / Passkey (class-name="u-btn-provider") */
.u-btn-provider {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    width: 100% !important;
    height: var(--u-provider-h) !important;
    padding: 0 16px !important;
    background: var(--u-bg) !important;
    color: var(--u-text) !important;
    border: 1.5px solid var(--u-border) !important;
    border-radius: var(--u-radius) !important;
    font-family: inherit !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    box-sizing: border-box !important;
    transition: background 160ms, border-color 160ms;
    margin-top: 8px !important;
    text-align: left !important;
}
.u-btn-provider:hover {
    background: var(--u-bg-muted) !important;
    border-color: #9ca3af !important;
}

u-social-login-button.u-btn-provider::part(button),
u-passkey.u-btn-provider::part(button) {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: var(--u-provider-h);
    padding: 0 16px;
    background: var(--u-bg);
    color: var(--u-text);
    border: 1.5px solid var(--u-border);
    border-radius: var(--u-radius);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    box-sizing: border-box;
    transition: background 160ms;
    text-align: left;
}
u-social-login-button.u-btn-provider::part(button):hover,
u-passkey.u-btn-provider::part(button):hover {
    background: var(--u-bg-muted);
}

/* ── Divider between submit and social buttons */
.u-divider {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    margin: 16px 0 8px !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    text-transform: uppercase !important;
    letter-spacing: .05em !important;
    color: var(--u-text-muted) !important;
}
.u-divider::before,
.u-divider::after {
    content: '' !important;
    flex: 1 !important;
    height: 1px !important;
    background: #e5e7eb !important;
}

/* ── Secondary / ghost buttons (back, send magic code, resend) */
.u-btn-back {
    display: inline-flex !important;
    align-items: center !important;
    gap: 4px !important;
    background: none !important;
    border: none !important;
    padding: 0 !important;
    margin-bottom: 16px !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    color: var(--u-text-muted) !important;
    cursor: pointer !important;
    text-decoration: none !important;
    transition: color 140ms;
}
.u-btn-back:hover { color: var(--u-primary) !important; }

u-back-button.u-btn-back::part(button) {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    padding: 0;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--u-text-muted);
    cursor: pointer;
    transition: color 140ms;
}
u-back-button.u-btn-back::part(button):hover { color: var(--u-primary); }

.u-btn-secondary {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    padding: 12px 16px !important;
    margin-top: 10px !important;
    background: var(--u-bg) !important;
    color: var(--u-text-muted) !important;
    border: 1.5px solid var(--u-border) !important;
    border-radius: var(--u-radius) !important;
    font-family: inherit !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    box-sizing: border-box !important;
    transition: border-color 160ms, color 160ms;
    text-align: center !important;
}
.u-btn-secondary:hover {
    border-color: var(--u-primary) !important;
    color: var(--u-primary) !important;
}

u-send-magic-code-button.u-btn-secondary::part(button),
u-registration-resend.u-btn-secondary::part(button),
u-registration-resume.u-btn-secondary::part(button) {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px 16px;
    margin-top: 10px;
    background: var(--u-bg);
    color: var(--u-text-muted);
    border: 1.5px solid var(--u-border);
    border-radius: var(--u-radius);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    box-sizing: border-box;
    transition: border-color 160ms, color 160ms;
}
u-send-magic-code-button.u-btn-secondary::part(button):hover,
u-registration-resend.u-btn-secondary::part(button):hover,
u-registration-resume.u-btn-secondary::part(button):hover {
    border-color: var(--u-primary);
    color: var(--u-primary);
}

/* ── Error messages */
.u-error {
    display: block !important;
    font-size: 13px !important;
    color: var(--u-danger) !important;
    margin-top: -8px !important;
    margin-bottom: 10px !important;
}

u-error-message.u-error::part(message) {
    display: block;
    font-size: 13px;
    color: var(--u-danger);
    margin-top: -8px;
    margin-bottom: 10px;
}

/* ── OTP / magic code fields */
.u-otp-wrap {
    display: flex !important;
    justify-content: center !important;
    gap: 8px !important;
    margin-bottom: 16px !important;
}

/* ═════════════════════════════════════════════════════════════════════════════
   LEGACY — OIDC button (wp-login.php) + full-page SDK login
   ══════════════════════════════════════════════════════════════════════════ */
.unidy-sso-wrap { margin-bottom: 1.5em; }
.unidy-sso-btn {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    width: 100%; padding: 12px 20px; background: #0054ff; color: #fff !important;
    border: none; border-radius: 6px; font-size: 15px; font-weight: 600;
    text-decoration: none !important; cursor: pointer; box-sizing: border-box;
    transition: background 150ms;
}
.unidy-sso-btn:hover { background: #0043cc; }
.unidy-sso-divider {
    display: flex; align-items: center; gap: 10px; margin: 18px 0;
    color: #9ca3af; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
}
.unidy-sso-divider::before, .unidy-sso-divider::after { content: ''; flex: 1; height: 1px; background: #e5e7eb; }

.unidy-login-page {
    min-height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background: #f9fafb; padding: 24px 16px; box-sizing: border-box;
}
.unidy-login-card {
    width: 100%; max-width: 400px; background: #fff; border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 24px rgba(0,0,0,.06);
    padding: 40px 36px; box-sizing: border-box;
}
.unidy-login-logo { display: flex; justify-content: center; margin-bottom: 32px; }
.unidy-login-logo img { height: 40px; width: auto; }
.unidy-status { margin-top: 16px; padding: 10px 14px; border-radius: 6px; font-size: 14px; text-align: center; }
.unidy-status--loading { background: #eff6ff; color: #1e40af; }
.unidy-status--error   { background: #fef2f2; color: #991b1b; }
.unidy-login-footer { margin-top: 24px; text-align: center; font-size: 13px; color: #6b7280; }
.unidy-login-footer a { color: #0054ff; text-decoration: none; }
.unidy-login-footer a:hover { text-decoration: underline; }
