/* Phase 3: Auth modal (registration/login) — reuses site.css variables. */

.auth-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-modal[hidden] {
    display: none;
}

.auth-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
}

.auth-modal-dialog {
    position: relative;
    width: 100%;
    max-width: 440px;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    background: var(--color-bg, #fff);
    border-radius: var(--radius-lg, 12px);
    box-shadow: var(--shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1));
    padding: 2rem;
    text-align: center;
}

.auth-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md, 8px);
    color: var(--color-text-light, #64748b);
    cursor: pointer;
}

.auth-modal-close:hover {
    background: var(--color-bg-gray, #f1f5f9);
    color: var(--color-text, #1e293b);
}

.auth-modal-close:focus-visible,
.auth-btn:focus-visible,
.auth-input:focus-visible,
.auth-code-digit:focus-visible,
.auth-link-btn:focus-visible {
    outline: 3px solid var(--color-primary, #2563eb);
    outline-offset: 2px;
}

/* Panels: only the panel matching the dialog's current view is shown.
   auth.js (Task 04) drives the view by changing data-auth-view. */
.auth-panel {
    display: none;
}

.auth-modal-dialog[data-auth-view="choose"] .auth-panel-choose,
.auth-modal-dialog[data-auth-view="email"] .auth-panel-email,
.auth-modal-dialog[data-auth-view="check-email"] .auth-panel-check-email,
.auth-modal-dialog[data-auth-view="code"] .auth-panel-code,
.auth-modal-dialog[data-auth-view="success"] .auth-panel-success {
    display: block;
}

.auth-modal-title {
    font-size: 1.375rem;
    line-height: 1.35;
    margin: 0.5rem 0 1rem;
    color: var(--color-text, #1e293b);
}

.auth-subtitle {
    font-size: 1.0625rem;
    color: var(--color-text-light, #64748b);
    margin-bottom: 1.5rem;
}

/* Benefits copy */
.auth-benefits {
    text-align: left;
    background: var(--color-bg-alt, #f8fafc);
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: var(--radius-md, 8px);
    padding: 1.25rem 1.25rem 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}

.auth-benefits-heading {
    font-size: 1.0625rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--color-text, #1e293b);
}

.auth-benefits-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.auth-benefits-list li {
    position: relative;
    padding-left: 1.5rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text, #1e293b);
}

.auth-benefits-list li::before {
    content: "\2713";
    position: absolute;
    left: 0;
    top: 0;
    color: var(--color-success, #10b981);
    font-weight: 700;
}

/* Actions / buttons — large tap targets for older users */
.auth-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.auth-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 52px;
    padding: 0.75rem 1.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    border-radius: var(--radius-md, 8px);
    border: 2px solid transparent;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
}

.auth-btn-block {
    width: 100%;
}

.auth-btn-primary {
    background: var(--color-primary, #2563eb);
    color: #fff;
}

.auth-btn-primary:hover {
    background: var(--color-primary-dark, #1d4ed8);
}

.auth-btn-secondary {
    background: #fff;
    color: var(--color-primary, #2563eb);
    border-color: var(--color-primary, #2563eb);
}

.auth-btn-secondary:hover {
    background: var(--color-bg-alt, #f8fafc);
}

.auth-btn:active {
    transform: translateY(1px);
}

.auth-link-btn {
    display: inline-block;
    margin-top: 1rem;
    background: none;
    border: none;
    color: var(--color-primary, #2563eb);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    padding: 0.5rem;
}

.auth-link-btn:hover {
    text-decoration: underline;
}

/* Forms */
.auth-form {
    text-align: left;
}

.auth-field-group {
    margin-bottom: 1rem;
}

/* Name is only collected for sign up; auth.js sets data-auth-mode="login"
   on the dialog when the user chooses to log in instead. */
.auth-modal-dialog[data-auth-mode="login"] .auth-name-field {
    display: none;
}

.auth-label {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-text, #1e293b);
}

.auth-input {
    width: 100%;
    min-height: 52px;
    padding: 0.75rem 1rem;
    font-size: 1.125rem;
    border: 2px solid var(--color-border, #e2e8f0);
    border-radius: var(--radius-md, 8px);
    margin-bottom: 0.5rem;
}

.auth-input:focus {
    border-color: var(--color-primary, #2563eb);
}

.auth-error {
    color: var(--color-error, #ef4444);
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 0.25rem 0 0.75rem;
}

.auth-error[hidden] {
    display: none;
}

/* 4-digit code entry — large, numeric */
.auth-code-inputs {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.auth-code-digit {
    width: 3.25rem;
    height: 3.75rem;
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
    border: 2px solid var(--color-border, #e2e8f0);
    border-radius: var(--radius-md, 8px);
}

.auth-code-digit:focus {
    border-color: var(--color-primary, #2563eb);
}

/* Icons (check-email / success states) */
.auth-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    background: var(--color-bg-alt, #f8fafc);
    color: var(--color-primary, #2563eb);
}

.auth-icon-success {
    color: var(--color-success, #10b981);
}

/* Loading indicator */
.auth-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
    color: var(--color-text-light, #64748b);
    font-size: 0.9375rem;
}

.auth-loading[hidden] {
    display: none;
}

.auth-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border, #e2e8f0);
    border-top-color: var(--color-primary, #2563eb);
    border-radius: 50%;
    animation: auth-spin 0.8s linear infinite;
}

@keyframes auth-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .auth-btn,
    .auth-spinner {
        animation: none;
        transition: none;
    }
}

/* Mobile: full-width dialog, larger tap targets */
@media (max-width: 480px) {
    .auth-modal {
        padding: 0;
        align-items: flex-end;
    }

    .auth-modal-dialog {
        max-width: 100%;
        max-height: 92vh;
        width: 100%;
        border-radius: var(--radius-lg, 12px) var(--radius-lg, 12px) 0 0;
        padding: 1.5rem;
    }

    .auth-modal-title {
        font-size: 1.25rem;
    }

    .auth-code-digit {
        width: 2.75rem;
        height: 3.25rem;
        font-size: 1.5rem;
    }
}

/* Phase 3 Task 05: User nav state (header), sits in .header-actions
   (see base.html). Reuses site.css's colour/reset conventions; buttons
   need an explicit reset since they don't inherit `a` tag styling. */
.user-nav {
    display: flex;
    align-items: center;
}

.user-nav[hidden] {
    display: none;
}

.user-nav-signed-out {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-nav-signed-in {
    position: relative;
    display: flex;
    align-items: center;
}

.user-nav-signed-in[hidden],
.user-nav-signed-out[hidden] {
    display: none;
}

/* Sign in / Register - outlined pill button, per the desktop header design. */
.user-nav-signin-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: 1.5px solid rgba(255, 255, 255, 0.6);
    border-radius: 999px;
    font: inherit;
    font-weight: 600;
    font-size: 0.875rem;
    color: #fff;
    cursor: pointer;
    padding: 0.5rem 1.1rem;
    white-space: nowrap;
}

.user-nav-signin-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.9);
}

/* Avatar + name + chevron trigger for the signed-in dropdown. */
.user-nav-avatar-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: none;
    border: none;
    font: inherit;
    color: #fff;
    cursor: pointer;
    padding: 0.35rem 0.6rem 0.35rem 0.35rem;
    border-radius: 999px;
}

.user-nav-avatar-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.user-nav-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    font-weight: 700;
    font-size: 0.8125rem;
    flex-shrink: 0;
}

.user-nav-name {
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
    font-size: 0.9375rem;
}

.user-nav-chevron {
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.user-nav-avatar-btn[aria-expanded="true"] .user-nav-chevron {
    transform: rotate(180deg);
}

/* Dropdown panel (My Library / Account / Logout). */
.user-nav-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 0.6rem);
    right: 0;
    min-width: 190px;
    background: var(--color-bg);
    color: var(--color-text);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.4rem 0;
    z-index: 200;
}

.user-nav-dropdown.is-open {
    display: block;
}

.user-nav-dropdown-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.65rem 1rem;
    background: none;
    border: none;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
}

.user-nav-dropdown-link:hover {
    background: var(--color-bg-gray);
    color: var(--color-text);
}

.user-nav-dropdown-link svg {
    flex-shrink: 0;
    color: var(--color-text-light);
}

/* The signed-out block doubles as the mobile top-bar action: on desktop it
   shows the "Sign in / Register" pill; on mobile that pill is replaced by
   a plain search icon (mirrored by the .nav-mobile-auth entry inside the
   hamburger dropdown - see site.css). */
.mobile-search-btn {
    display: none;
    align-items: center;
    justify-content: center;
    color: #fff;
}

@media (max-width: 768px) {
    .user-nav-signin-btn {
        display: none;
    }

    .mobile-search-btn {
        display: flex;
    }

    .user-nav-name {
        display: none;
    }

    .user-nav-avatar-btn {
        padding: 0.25rem;
        gap: 0.35rem;
    }

    .user-nav-dropdown {
        min-width: 170px;
    }
}
