/* ============================================================
   AUTH MODAL & NAV WIDGET — TD Portfolio
   Sign-In, Register, User Nav Widget
   ============================================================ */

/* ── Overlay ── */
.auth-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9990;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.auth-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
body.auth-modal-open { overflow: hidden; }

/* ── Modal Card ── */
.auth-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 2.5rem 2rem;
    width: min(440px, 92vw);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.55);
    position: relative;
    animation: authSlideUp 0.3s ease;
    text-align: center;
}
@keyframes authSlideUp {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* ── Close button ── */
.auth-modal-close {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
}
.auth-modal-close:hover { color: var(--text-primary); background: var(--accent-glow); }

/* ── Logo ── */
.auth-logo {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--accent-primary);
    letter-spacing: -0.05em;
    margin-bottom: 1.5rem;
}
.auth-logo span:last-child { color: var(--text-primary); }
.auth-logo-dot {
    display: inline-block;
    width: 6px; height: 6px;
    background: var(--accent-primary);
    border-radius: 50%;
    margin: 0 1px 1px;
    vertical-align: middle;
}

/* ── Steps ── */
.auth-step { display: none; }
.auth-step.active { display: block; animation: authSlideUp 0.25s ease; }

/* ── Titles ── */
.auth-title {
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}
.auth-subtitle {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 1.75rem;
    line-height: 1.6;
}
.auth-subtitle strong { color: var(--text-primary); }

/* ── Step icon ── */
.auth-step-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    display: block;
}

/* ── Terms text ── */
.auth-terms {
    font-size: 0.74rem;
    color: var(--text-secondary);
    line-height: 1.5;
    opacity: 0.85;
    margin-top: 1rem;
}
.auth-terms em { color: var(--accent-primary); font-style: normal; font-weight: 600; }

/* ── Sign-in / Register switch row ── */
.auth-switch-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 0.9rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
}
.auth-text-btn {
    -webkit-appearance: none;
    appearance: none;
    background: none;
    border: none;
    padding: 0;
    color: var(--accent-primary);
    font-size: inherit;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.auth-text-btn:hover { color: var(--accent-comp); }

/* ── Disclosure box ── */
.auth-disclosure-box {
    background: var(--bg-primary);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    text-align: left;
    font-size: 0.87rem;
    color: var(--text-primary);
    line-height: 1.65;
    margin-bottom: 1.5rem;
}
.auth-disclosure-box p + p { margin-top: 0.75rem; }
.auth-disclosure-box strong { color: var(--accent-primary); }
.auth-disclosure-box em { color: var(--accent-comp); font-style: italic; }

/* ── "Understood" timer button ── */
.btn-understood {
    position: relative;
    width: 100%;
    padding: 0.85rem 1.5rem;
    border: 2px solid var(--accent-primary);
    border-radius: 10px;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    overflow: hidden;
    cursor: not-allowed;
    transition: border-color 0.2s, color 0.2s;
    margin-bottom: 0.6rem;
}
.btn-understood.ready { cursor: pointer; }
.btn-understood.ready:hover { border-color: var(--accent-comp); color: var(--accent-comp); }

.understood-btn-text {
    position: relative;
    z-index: 1;
}
.understood-timer-fill {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-comp));
    opacity: 0.3;
    border-radius: 8px;
    pointer-events: none;
}
.btn-understood.ready .understood-timer-fill { opacity: 0.5; }

.auth-timer-hint {
    font-size: 0.76rem;
    color: var(--text-secondary);
    transition: opacity 0.4s ease;
    margin-bottom: 0;
}

/* ── Form inputs ── */
.auth-form-group { margin-bottom: 1rem; text-align: left; }
.auth-form-label {
    display: block;
    font-size: 0.79rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    margin-bottom: 0.4rem;
}
.auth-form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}
.auth-form-input:focus { border-color: var(--accent-primary); }

.auth-form-error {
    font-size: 0.8rem;
    color: #ff5252;
    min-height: 1.1rem;
    margin-bottom: 0.5rem;
    text-align: left;
}

.auth-form-success {
    font-size: 0.8rem;
    color: #22c55e;
    min-height: 1.1rem;
    margin-bottom: 0.5rem;
    text-align: left;
}

/* Email verification step info box */
.auth-verify-info {
    background: var(--bg-primary);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.88rem;
    color: var(--accent-primary);
    word-break: break-all;
    text-align: left;
}
.auth-verify-info i { flex-shrink: 0; font-size: 1rem; }

.auth-form-hint {
    font-size: 0.74rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    text-align: left;
}

.auth-label-hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-secondary);
}

/* ── Submit button ── */
.btn-auth-submit {
    width: 100%;
    padding: 0.85rem;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-comp));
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: opacity 0.2s, transform 0.1s;
}
.btn-auth-submit:hover  { opacity: 0.9; }
.btn-auth-submit:active { transform: scale(0.98); }
.btn-auth-submit:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Nav sign-in widget ── */
.auth-nav-wrap {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.btn-nav-signin {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.42rem 0.9rem;
    background: transparent;
    border: 1.5px solid var(--accent-primary);
    border-radius: 8px;
    color: var(--accent-primary);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s;
}
.btn-nav-signin:hover { background: var(--accent-primary); color: var(--bg-primary); }
.btn-nav-signin.auth-nav-loading {
    opacity: 0;
    pointer-events: none;
    cursor: default;
}

.auth-nav-wrap {
    display: flex;
    align-items: center;
}

.auth-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-comp));
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.auth-avatar img { width: 100%; height: 100%; object-fit: cover; }

.auth-username-nav {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.auth-nav-tier-label {
    font-size: 0.74rem;
    font-weight: 500;
    opacity: 0.9;
}

/* ── Fixed stats bar — wraps auth widget + viewer stats on blog page ── */
.fixed-stats-bar {
    position: fixed;
    top: 13px;
    right: 1rem;
    z-index: 1002;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── auth-nav-user is now a button ── */
.auth-nav-user {
    display: none;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 999px;
    transition: background 0.18s;
    color: inherit;
}
.auth-nav-user:hover { background: var(--bg-primary); }
.auth-nav-chevron {
    font-size: 0.58rem;
    color: var(--text-secondary);
    transition: transform 0.22s;
    flex-shrink: 0;
}
.auth-nav-chevron.open { transform: rotate(180deg); }

/* ── User dropdown ── */
.auth-user-dropdown {
    position: fixed;
    z-index: 2000;
    min-width: 270px;
    max-width: min(320px, calc(100vw - 1rem));
    background: var(--bg-secondary);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    padding: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
    transition: opacity 0.22s, transform 0.22s;
    pointer-events: none;
}
.auth-user-dropdown.visible {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}
.auth-dd-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1rem 0.75rem;
}
.auth-dd-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-comp));
    color: #fff;
    font-size: 0.9rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.auth-dd-name { font-size: 0.9rem; font-weight: 700; }
.auth-dd-tier { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-top: 1px; }
.auth-dd-divider { height: 1px; background: var(--card-border); margin: 0.25rem 0; }
.auth-dd-section { padding: 0.6rem 1rem 0.4rem; }
.auth-dd-section-title { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-secondary); margin-bottom: 0.6rem; }
.auth-dd-max-msg { font-size: 0.82rem; font-weight: 600; display: flex; align-items: center; gap: 0.4rem; }
.auth-dd-req { margin-bottom: 0.55rem; }
.auth-dd-req.done .auth-dd-req-label { opacity: 0.75; text-decoration: none; }
.auth-dd-req-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.2rem; }
.auth-dd-req-label { font-size: 0.79rem; color: var(--text-primary); }
.auth-dd-req-status { font-size: 0.72rem; color: var(--text-secondary); white-space: nowrap; margin-left: 0.5rem; }
.auth-dd-req.done .auth-dd-req-status { color: var(--accent-primary); }
.auth-dd-req-status.done-check { color: #22c55e !important; font-size: 0.9rem; }
.auth-dd-bar-wrap { height: 5px; background: var(--bg-primary); border-radius: 99px; overflow: hidden; }
.auth-dd-bar { height: 100%; background: var(--accent-primary); border-radius: 99px; transition: width 0.4s ease; min-width: 0; }
.auth-dd-actions { padding: 0.5rem 0.6rem 0.6rem; display: flex; flex-direction: column; gap: 0.3rem; }
.auth-dd-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 0.84rem;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background 0.15s;
}
.auth-dd-btn:hover { background: var(--bg-primary); }
.auth-dd-btn.danger { color: #ff5252; }
.auth-dd-btn.danger:hover { background: rgba(255,82,82,0.1); }
.auth-dd-email-warn { color: #f59e0b !important; }
.auth-dd-email-warn:hover { background: rgba(245,158,11,0.1) !important; }

/* ── Edit / Delete account overlays ── */
.auth-account-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 3000;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}
.auth-account-overlay.active { opacity: 1; }
.auth-account-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 2rem 1.75rem 1.75rem;
    width: min(420px, 92vw);
    position: relative;
    box-shadow: 0 12px 48px rgba(0,0,0,0.5);
    transform: translateY(24px);
    transition: transform 0.3s;
}
.auth-account-overlay.active .auth-account-modal { transform: translateY(0); }
.auth-account-close {
    position: absolute;
    top: 0.9rem; right: 1rem;
    background: none; border: none;
    font-size: 1.4rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}
.auth-account-close:hover { color: var(--text-primary); }
.auth-account-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0 0 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}
.auth-account-title.danger { color: #ff5252; }
.auth-account-group { margin-bottom: 0.85rem; }
.auth-account-label { display: block; font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-secondary); margin-bottom: 0.3rem; }
.auth-req-mark { color: var(--accent-primary); }
.auth-account-input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--card-border);
    border-radius: 9px;
    padding: 0.6rem 0.8rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}
.auth-account-input:focus { border-color: var(--accent-primary); }
.auth-account-divider-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin: 1rem 0 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.auth-account-divider-label::before,.auth-account-divider-label::after { content:''; flex:1; height:1px; background:var(--card-border); }
.auth-account-divider-label span { opacity: 0.55; font-weight: 400; text-transform: none; letter-spacing: 0; }
.auth-account-error  { color: #ff5252; font-size: 0.82rem; min-height: 1.1em; margin: 0.2rem 0 0.5rem; }
.auth-account-success{ color: var(--accent-primary); font-size: 0.82rem; min-height: 1.1em; margin: 0.2rem 0 0.5rem; }
.auth-account-hint   { font-size: 0.75rem; margin: 0.2rem 0 0; min-height: 1em; color: var(--text-secondary); }
.btn-account-save {
    width: 100%;
    padding: 0.7rem;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-comp));
    color: #fff;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-top: 0.4rem;
}
.btn-account-save:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-account-save:not(:disabled):hover { opacity: 0.88; }

/* Delete modal extras */
.auth-delete-icon-wrap { text-align: center; font-size: 2rem; color: #ff5252; margin-bottom: 0.5rem; }
.auth-delete-warn { font-size: 0.85rem; color: var(--text-secondary); margin: 0 0 1rem; line-height: 1.55; }
.btn-account-delete {
    width: 100%;
    padding: 0.7rem;
    border: none;
    border-radius: 10px;
    background: #3a1a1a;
    color: #ff5252;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: not-allowed;
    opacity: 0.6;
    margin-top: 0.4rem;
    transition: opacity 0.2s, background 0.3s;
}
.btn-account-delete.armed {
    background: linear-gradient(135deg, #ff3333, #c0392b);
    color: #fff;
    cursor: pointer;
    opacity: 1;
}
.btn-account-delete.armed:hover { opacity: 0.88; }
.auth-delete-countdown { font-size: 0.8em; opacity: 0.7; }

@media (max-width: 640px) {
    .fixed-stats-bar { top: 11px; right: calc(38px + 1.5rem + 8px); gap: 5px; }

    /* Hide username text in nav — keep bar compact so it never overflows */
    .auth-username-nav { display: none !important; }

    /* Full-width dropdown on narrow screens — ignore JS right-positioning entirely */
    .auth-user-dropdown {
        left: 8px !important;
        right: 8px !important;
        max-width: none !important;
        width: auto !important;
    }
}

/* ── Tier Congratulations Popup ── */
.tier-congrats-popup {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    background: rgba(0,0,0,0.55);
    opacity: 0;
    transition: opacity 0.35s ease;
    pointer-events: none;
}
.tier-congrats-popup.visible {
    opacity: 1;
    pointer-events: auto;
}
.tier-congrats-inner {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 2.5rem 2rem 2rem;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
    transform: translateY(20px);
    transition: transform 0.35s ease;
}
.tier-congrats-popup.visible .tier-congrats-inner {
    transform: translateY(0);
}
.tier-congrats-close {
    position: absolute;
    top: 0.75rem;
    right: 0.9rem;
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}
.tier-congrats-close:hover { color: var(--text-primary); }
.tier-congrats-badge {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}
.tier-congrats-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0 0 0.9rem;
}
.tier-congrats-msg {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .btn-nav-signin span { display: none; }
    .auth-username-nav  { display: none; }
    .btn-nav-signin { padding: 0.42rem 0.65rem; }
}
