/* Auth modal, topbar account control, and account page. Loaded after style.css. */

/* Marketing pages load this without tokens.css/style.css; bridge what the modal needs. */
body:has(.nav-account) {
    --bg-hover: color-mix(in srgb, var(--foreground) 6%, transparent);
    --dur-in: .22s;
    --ease-ui: cubic-bezier(.4, 0, .2, 1);
    --error: #f2857f;
    --icon-sm: 16px;
    --input: #1d1d1e;
    --input-height: 40px;
    --inverse-foreground: #1f1f1f;
    --popover: #18191a;
    --radius: 10px;
    --radius-full: 999px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow-modal: 0 24px 64px rgba(0, 0, 0, .6);
    --shadow-overlay: 0 12px 40px rgba(0, 0, 0, .45);
    --font-ui: var(--font-sans);
    --secondary: #2a2b2c;
    --space-12: 48px;
    --text-sm: 14px;
    --text-xs: 12px;
    --accent-strong: #1e40af;
}

/* The marketing spacing and motion scales differ; the account control and modal keep the UI scale. */
body:has(.nav-account) :is(.nav-account, .modal-overlay) {
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --dur: .15s;
}

body:has(.nav-account) .modal-overlay {
    color-scheme: dark;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050;
}

body:has(.nav-account) .modal-overlay.hidden { display: none; }

body:has(.nav-account) .modal {
    background: var(--popover);
    border: 0.5px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-modal);
    padding: var(--space-6);
}

body:has(.nav-account) .modal-auth {
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.5;
}

body:has(.nav-account) .modal-auth .btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-ui);
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--dur) var(--ease-ui), border-color var(--dur) var(--ease-ui), opacity var(--dur) var(--ease-ui);
}

body:has(.nav-account) .modal-auth .btn-secondary {
    background: transparent;
    border: 0.5px solid var(--border-strong);
    color: var(--foreground);
}

body:has(.nav-account) .modal-auth .btn-secondary:hover { background: var(--bg-hover); }

body:has(.nav-account) .modal-auth .btn-primary {
    border: none;
    background: var(--accent-hover);
    color: var(--primary-foreground);
}

body:has(.nav-account) .modal-auth .btn-primary:hover { background: var(--accent-strong); }

body:has(.nav-account) .modal-auth .btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* Zero specificity: clears browser defaults without beating any real rule. */
:where(body:has(.nav-account) .modal-auth) :where(h2, p, button, input) { margin: 0; padding: 0; }

body:has(.nav-account) .modal-auth .modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--space-5);
}

body:has(.nav-account) .modal-auth .modal-header h2 {
    font-size: 17px;
    font-weight: 600;
}

body:has(.nav-account) .modal-auth .modal-subtitle {
    margin-top: var(--space-1);
    font-size: 12.5px;
    color: var(--muted-foreground);
}

body:has(.nav-account) .modal-auth .modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--space-8);
    height: var(--space-8);
    background: transparent;
    border: none;
    color: var(--muted-foreground);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: background var(--dur) var(--ease-ui), color var(--dur) var(--ease-ui);
}

body:has(.nav-account) .modal-auth .modal-close:hover {
    background: var(--bg-hover);
    color: var(--foreground);
}

body:has(.nav-account) .modal-auth .label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

body:has(.nav-account) .modal-auth .auth-field-row .label { margin-bottom: 0; }

body:has(.nav-account) .modal-auth .input {
    display: flex;
    align-items: center;
    height: var(--input-height);
    width: 100%;
    background: var(--input);
    border: 0.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0 var(--space-3);
    color: var(--foreground);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
}

body:has(.nav-account) .modal-auth .input:focus-within {
    border-color: var(--primary);
    outline: none;
}

body:has(.nav-account) .modal-auth .input input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    color: inherit;
    font: inherit;
}

body:has(.nav-account) .modal-auth .input input:focus,
body:has(.nav-account) .modal-auth .input input:focus-visible {
    outline: none;
}
/* Auth modal — narrow single column, unlike the 3-column Upload modal */
.modal-auth {
    background: var(--popover);
    width: min(400px, calc(100vw - 48px));
    animation: auth-modal-in var(--dur-in) var(--ease-ui);
}

@keyframes auth-modal-in {
    from { opacity: 0; transform: translateY(var(--space-2)); }
    to   { opacity: 1; transform: none; }
}

.modal-auth .modal-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

/* Full-width stacked actions; height meets the 40px mobile tap target on every viewport */
.modal-auth .btn {
    width: 100%;
    height: var(--input-height);
    justify-content: center;
}

.modal-auth .btn svg {
    width: var(--icon-sm);
    height: var(--icon-sm);
    flex-shrink: 0;
}

/* Google button — ivory surface so the four-colour brand mark stays legible */
.btn-google {
    background: var(--foreground);
    color: var(--inverse-foreground);
    border: 0.5px solid color-mix(in srgb, var(--inverse-foreground) 15%, transparent);
}

.btn-google:hover {
    background: color-mix(in srgb, var(--foreground) 92%, var(--inverse-foreground));
}

.btn-google:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* Brand mark keeps its own colours; 18px sits optically level with the 13px label */
.auth-google-mark {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-xs);
    color: var(--muted-foreground);
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 0.5px;
    background: var(--border-strong);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.auth-form fieldset {
    display: contents;
    border: none;
}

/* Label row holds the label and an optional trailing link ("Forgot password?") */
.auth-field-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
}

.auth-field-row .label {
    margin-bottom: 0;
}

.auth-field-hint {
    margin-top: var(--space-1);
    font-size: var(--text-xs);
    color: var(--muted-foreground);
}

.auth-field-error {
    margin-top: var(--space-1);
    font-size: var(--text-xs);
    color: var(--error);
}

.input.is-invalid {
    border-color: var(--error);
}

.input:has(input:disabled) {
    opacity: .5;
}

/* Password reveal — icon-only, sits inside the .input box, pulls into its right padding */
.auth-reveal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--space-8);
    height: var(--space-8);
    margin-right: calc(var(--space-2) * -1);
    background: transparent;
    border: none;
    border-radius: var(--radius-xs);
    color: var(--muted-foreground);
    cursor: pointer;
    flex-shrink: 0;
    transition: color var(--dur) var(--ease-ui), background var(--dur) var(--ease-ui);
}

.auth-reveal:hover {
    color: var(--foreground);
    background: var(--bg-hover);
}

.auth-reveal svg {
    width: var(--icon-sm);
    height: var(--icon-sm);
}

/* Notice — one block for every outcome the form reports (error, info, success) */
.auth-notice {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--input);
    border: 0.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.auth-notice-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--icon-sm);
    height: var(--icon-sm);
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--muted-foreground);
}

.auth-notice-icon svg {
    width: var(--icon-sm);
    height: var(--icon-sm);
}

.auth-notice strong {
    display: block;
    margin-bottom: var(--space-1);
    font-weight: 500;
    color: var(--foreground);
}

.auth-notice.is-error { border-color: color-mix(in srgb, var(--error) 45%, transparent); }
.auth-notice.is-error .auth-notice-icon { color: var(--error); }
.auth-notice.is-success { border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.auth-notice.is-success .auth-notice-icon { color: var(--success); }

/* Text-only link buttons (mode switch, "Back to log in") */
.btn-link {
    display: inline;
    padding: 0;
    background: none;
    border: none;
    font: inherit;
    color: var(--foreground);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.btn-link:hover {
    color: var(--primary);
}

/* Mode switch + legal line — padded so the row is a 32px+ tap zone */
.auth-switch,
.auth-legal {
    padding: var(--space-1) 0;
    text-align: center;
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--muted-foreground);
}

.auth-legal a {
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.auth-legal a:hover {
    color: var(--foreground);
}

.spinner {
    width: var(--icon-sm);
    height: var(--icon-sm);
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: var(--radius-full);
    animation: auth-spin .8s linear infinite;
}

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

.account-avatar {
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--space-6);
    height: var(--space-6);
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    background: var(--secondary);
    color: var(--foreground);
    font-size: var(--text-xs);
    font-weight: 500;
    text-transform: uppercase;
}

.account-avatar::before {
    content: attr(data-initial);
}

.account-avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.account-email {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
}

/* Account page */
.account-page {
    overflow-y: auto;
    padding: var(--space-16);
}

.account-content {
    max-width: 1120px;
}

.account-title {
    font-size: var(--text-lg);
    font-weight: 500;
    line-height: 1.3;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.account-subtitle {
    margin-top: var(--space-1);
    font-size: 13px;
    color: var(--muted-foreground);
}

.account-profile {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
        "identity save"
        "first    last"
        "hint     hint"
        "error    error";
    column-gap: var(--space-2);
    margin-top: var(--space-8);
}

.account-identity {
    grid-area: identity;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    margin-bottom: var(--space-8);
}

.account-identity .account-avatar {
    width: var(--space-10);
    height: var(--space-10);
    font-size: var(--text-sm);
}

.account-identity-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.account-identity-name {
    font-size: var(--text-sm);
    font-weight: 500;
    overflow-wrap: anywhere;
}

.account-identity-meta {
    font-size: var(--text-xs);
    color: var(--muted-foreground);
    overflow-wrap: anywhere;
}

.account-save {
    grid-area: save;
    justify-self: end;
    align-self: start;
    margin-top: var(--space-1);
}

.account-field-first { grid-area: first; }
.account-field-last { grid-area: last; }

.account-field .label {
    color: var(--foreground);
}

.account-field-hint,
.account-field-error {
    margin-top: var(--space-3);
    font-size: var(--text-xs);
    color: var(--muted-foreground);
}

.account-field-hint { grid-area: hint; }

.account-field-error {
    grid-area: error;
    margin-top: var(--space-1);
    color: var(--error);
}

.account-rows {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    margin-top: var(--space-8);
}

.account-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    font-size: var(--text-sm);
}

.account-row dt {
    color: var(--muted-foreground);
}

.account-row dd {
    color: var(--foreground);
    text-align: right;
    overflow-wrap: anywhere;
}

.account-section {
    margin-top: var(--space-12);
}

.account-section-title {
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: var(--tracking-eyebrow);
    text-transform: uppercase;
    color: var(--muted-foreground);
}

.account-section .account-rows {
    margin-top: var(--space-5);
}

.account-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--space-12);
}

@media (max-width: 1100px) {
    .account-page { padding: var(--space-10); }
}

@media (max-width: 900px) {
    .account-page { padding: var(--space-8); }
}

@media (max-width: 768px) {
    .account-page { padding: var(--space-6) var(--space-4); }

    .account-profile {
        grid-template-columns: 1fr;
        grid-template-areas: "identity" "first" "last" "hint" "error" "save";
        row-gap: 0;
    }

    .account-identity { margin-bottom: var(--space-6); }
    .account-field-last { margin-top: var(--space-4); }

    .account-save,
    .account-actions .btn {
        justify-self: stretch;
        justify-content: center;
        width: 100%;
        min-height: var(--space-10);
        margin-top: var(--space-5);
        font-size: 13px;
    }

    .account-actions { margin-top: var(--space-10); }
    .account-actions .btn { margin-top: 0; }
    .account-rows { gap: var(--space-4); margin-top: var(--space-6); }
    .account-section { margin-top: var(--space-10); }
}

/* Loading skeleton — pulses opacity only, so it stays under the reduced-motion guard */
.skeleton {
    display: block;
    height: var(--space-3);
    background: var(--secondary);
    border-radius: var(--radius-xs);
    animation: auth-pulse 1.4s var(--ease-ui) infinite;
}

@keyframes auth-pulse {
    50% { opacity: .45; }
}

@media (max-width: 768px) {
    .auth-reveal {
        width: var(--space-10);
        height: var(--space-10);
        min-height: var(--space-10);
    }
}

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