/* ============================================================
   auth-common.css
   Shared styles for all authentication pages:
   login, register, reset-password, welcome.
   Single source of truth for the auth design language.
   ============================================================ */

/* --- 1. CSS Custom Properties (light theme only) --- */
:root {
    color-scheme: light;

    /* Brand palette */
    --auth-primary: #ce21b1;
    --auth-primary-hover: #a020a0;
    --auth-primary-dark: #b91ca0;
    --auth-secondary: #7c3aed;

    /* Text */
    --auth-text: #0f172a;
    --auth-text-muted: #78716c;
    --auth-text-label: #44403c;

    /* Surfaces */
    --auth-bg: #ffffff;
    --auth-card-bg: rgba(255, 255, 255, 0.95);
    --auth-card-border: rgba(206, 33, 177, 0.08);
    --auth-card-shadow:
        0 24px 60px -20px rgba(206, 33, 177, 0.1),
        0 8px 20px -8px rgba(0, 0, 0, 0.04);

    /* Inputs */
    --auth-input-bg: #ffffff;
    --auth-input-border: rgba(206, 33, 177, 0.12);
    --auth-input-border-hover: rgba(206, 33, 177, 0.2);
    --auth-input-focus-shadow: 0 0 0 4px rgba(206, 33, 177, 0.1);
    --auth-placeholder: #78716c;

    /* Radii */
    --auth-radius-card: 28px;
    --auth-radius-input: 14px;

    /* Button */
    --auth-btn-gradient: linear-gradient(135deg, #ce21b1 0%, #a020a0 100%);
    --auth-btn-gradient-hover: linear-gradient(135deg, #b91ca0 0%, #8b1888 100%);
    --auth-btn-shadow: 0 12px 28px -10px rgba(206, 33, 177, 0.35);
    --auth-btn-shadow-hover: 0 16px 36px -12px rgba(206, 33, 177, 0.45);

    /* Error / Success */
    --auth-error-bg: rgba(239, 68, 68, 0.06);
    --auth-error-border: rgba(239, 68, 68, 0.15);
    --auth-error-text: #b91c1c;
    --auth-success-bg: rgba(16, 185, 129, 0.1);
    --auth-success-border: rgba(16, 185, 129, 0.18);
    --auth-success-text: #047857;
}

:root[data-theme="light"] {
    color-scheme: light;
}


/* --- 2. Base Reset --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--auth-text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px 16px;
    position: relative;
    overflow-x: hidden;
    background:
        radial-gradient(ellipse 900px 500px at 20% -10%, rgba(206, 33, 177, 0.1), transparent 70%),
        radial-gradient(ellipse 700px 400px at 80% 110%, rgba(124, 58, 237, 0.08), transparent 65%),
        linear-gradient(180deg, #fdf8fc 0%, #f5f0f8 50%, #f0eaf5 100%);
}


/* --- 3. Auth Container (centering wrapper) --- */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
}


/* --- 4. Auth Card (glass card) --- */
.auth-card,
.login-card,
.register-card,
.reset-card {
    width: 100%;
    max-width: 480px;
    background: var(--auth-card-bg);
    border: 1px solid var(--auth-card-border);
    border-radius: var(--auth-radius-card);
    padding: 44px 38px 36px;
    box-shadow: var(--auth-card-shadow);
    position: relative;
    overflow: hidden;
    animation: slideUp 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

/* Top highlight line on card */
.auth-card::before,
.login-card::before,
.register-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(206, 33, 177, 0.15), transparent);
}


/* --- 5. Brand Wordmark --- */
.logo-container {
    text-align: center;
    margin-bottom: 32px;
}

.logo-container h1 {
    background: none;
    -webkit-background-clip: unset;
    -webkit-text-fill-color: unset;
}

.matrixe-wordmark,
.logo-container .matrixe-wordmark {
    font-family: "Ubuntu Mono", monospace;
    font-weight: 700;
    font-size: 36px;
    letter-spacing: 0.03em;
    text-transform: lowercase;
    color: #1a1a2e;
    background: none;
    -webkit-background-clip: unset;
    -webkit-text-fill-color: #1a1a2e;
    display: inline-block;
    transform: none;
    text-shadow: none;
    margin-bottom: 10px;
    line-height: 1;
}

.matrixe-brand-dot,
.logo-container .matrixe-wordmark .matrixe-brand-dot {
    color: #ce21b1;
    -webkit-text-fill-color: #ce21b1;
    font-family: inherit;
    font-weight: inherit;
    font-size: inherit;
    text-shadow: 0 0 14px rgba(206, 33, 177, 0.35);
    transform: none;
    display: inline;
    margin: 0;
    min-width: 0;
    line-height: inherit;
    vertical-align: baseline;
}

.logo-container p {
    font-size: 15px;
    font-weight: 500;
    color: var(--auth-text-muted);
}


/* --- 6. Auth Title / Subtitle --- */
.auth-title {
    font-size: 26px;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.03em;
    color: var(--auth-text);
    margin-bottom: 8px;
}

.auth-subtitle {
    color: var(--auth-text-muted);
    font-size: 14px;
    line-height: 1.65;
    margin-bottom: 20px;
}


/* --- 7. Form Group / Label / Input --- */
.form-group {
    margin-bottom: 18px;
}

label {
    display: block;
    color: var(--auth-text-label);
    font-size: 12px;
    margin-bottom: 7px;
    margin-left: 4px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

input {
    width: 100%;
    padding: 15px 18px;
    background: var(--auth-input-bg);
    border: 1px solid var(--auth-input-border);
    border-radius: var(--auth-radius-input);
    color: var(--auth-text);
    font-size: 16px;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:hover {
    border-color: var(--auth-input-border-hover);
    background: var(--auth-input-bg);
}

input:focus {
    outline: none;
    transform: none;
    border-color: var(--auth-primary);
    background: var(--auth-input-bg);
    box-shadow: var(--auth-input-focus-shadow);
}

input::placeholder {
    color: var(--auth-placeholder);
}


/* --- 8. Primary Button --- */
.btn-primary,
.btn-login,
.btn-register {
    width: 100%;
    padding: 15px 16px;
    background: var(--auth-btn-gradient);
    color: white;
    border: none;
    border-radius: var(--auth-radius-input);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
    box-shadow: var(--auth-btn-shadow);
    margin-top: 12px;
}

.btn-primary::before,
.btn-login::before,
.btn-register::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.15), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.btn-primary:hover,
.btn-login:hover,
.btn-register:hover {
    transform: translateY(-2px);
    box-shadow: var(--auth-btn-shadow-hover);
    background: var(--auth-btn-gradient-hover);
}

.btn-primary:hover::before,
.btn-login:hover::before,
.btn-register:hover::before {
    opacity: 1;
}

.btn-primary:active,
.btn-login:active,
.btn-register:active {
    transform: translateY(0);
}

.btn-primary:disabled,
.btn-login:disabled,
.btn-register:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Focus-visible for keyboard navigation */
.btn-primary:focus-visible,
.btn-login:focus-visible,
.btn-register:focus-visible {
    outline: 2px solid var(--auth-primary);
    outline-offset: 2px;
}


/* --- 9. Error / Success Messages --- */
.error-message,
.auth-error {
    background: var(--auth-error-bg);
    border: 1px solid var(--auth-error-border);
    color: var(--auth-error-text);
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
    display: none;
    align-items: center;
    gap: 10px;
    animation: shake 0.4s cubic-bezier(.36, .07, .19, .97) both;
}

.error-message.show,
.auth-error.show {
    display: flex;
}

.success-message {
    background: var(--auth-success-bg);
    border: 1px solid var(--auth-success-border);
    color: var(--auth-success-text);
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
    display: none;
    align-items: center;
    gap: 10px;
    animation: fadeIn 0.4s ease-out;
}

.success-message.show {
    display: flex;
}

/* Status message variant (used in reset-password) */
.status-message {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;
}

.status-message.show {
    display: flex;
}

.status-message.error {
    background: var(--auth-error-bg);
    border: 1px solid var(--auth-error-border);
    color: var(--auth-error-text);
}

.status-message.success {
    background: var(--auth-success-bg);
    border: 1px solid var(--auth-success-border);
    color: var(--auth-success-text);
}


/* --- 10. Loader Spinner --- */
.loader {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}


/* --- 11. Auth Footer (links) --- */
.footer,
.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--auth-text-muted);
}

.footer a,
.auth-footer a {
    color: var(--auth-primary);
    text-decoration: none;
    font-weight: 700;
    transition: all 0.2s;
    position: relative;
}

.footer a::after,
.auth-footer a::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--auth-primary);
    transition: width 0.3s;
    border-radius: 2px;
}

.footer a:hover::after,
.auth-footer a:hover::after {
    width: 100%;
}

/* Focus-visible for keyboard navigation on links */
.footer a:focus-visible,
.auth-footer a:focus-visible {
    outline: 2px solid var(--auth-primary);
    outline-offset: 2px;
    border-radius: 2px;
}


/* --- 12. Ambient Background / Orbs --- */
.ambient-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.noise-overlay {
    position: absolute;
    inset: 0;
    opacity: 0.07;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    pointer-events: none;
}

.ambient-background .noise-overlay,
.ambient-background .orb {
    opacity: 0.2;
    filter: blur(100px);
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.5;
    animation: floatOrb 25s infinite ease-in-out alternate;
}

.orb-1 {
    width: 700px;
    height: 700px;
    background: radial-gradient(circle, rgba(206, 33, 177, 0.35) 0%, transparent 70%);
    top: -200px;
    left: -200px;
}

.orb-2 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(124, 58, 237, 0.25) 0%, transparent 70%);
    bottom: -200px;
    right: -200px;
    animation-delay: -5s;
}


/* --- 13. Keyframe Animations --- */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(36px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

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

@keyframes floatOrb {
    0% {
        transform: translate(0, 0) scale(1);
    }
    100% {
        transform: translate(30px, 50px) scale(1.1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* --- 14. Mobile Breakpoints --- */

/* Tablet and below: full-screen card */
@media (max-width: 768px) {
    body {
        padding: 0;
        min-height: 100dvh;
        align-items: stretch;
        justify-content: stretch;
        background: var(--auth-bg);
    }

    .ambient-background {
        display: none;
    }

    .auth-card,
    .login-card,
    .register-card,
    .reset-card {
        width: 100%;
        max-width: none;
        min-height: 100dvh;
        margin: 0;
        border-radius: 0;
        border: none;
        box-shadow: none;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--auth-bg);
        padding: calc(32px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .auth-card::before,
    .auth-card::after,
    .login-card::before,
    .login-card::after,
    .register-card::before,
    .register-card::after,
    .reset-card::before,
    .reset-card::after {
        display: none;
    }

    .matrixe-wordmark,
    .logo-container .matrixe-wordmark {
        font-size: 30px;
    }
}

/* Small phone */
@media (max-width: 480px) {
    .auth-card,
    .login-card,
    .register-card,
    .reset-card {
        padding: calc(24px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
    }

    .matrixe-wordmark,
    .logo-container .matrixe-wordmark {
        font-size: 26px;
    }

    .logo-container p {
        font-size: 13px;
    }

    input,
    .btn-primary,
    .btn-login,
    .btn-register {
        min-height: 44px;
    }
}

/* Desktop enhancements */
@media (min-width: 769px) {
    body {
        padding: 44px 24px;
        background:
            radial-gradient(ellipse 1100px 600px at 15% -8%, rgba(206, 33, 177, 0.12), transparent 65%),
            radial-gradient(ellipse 900px 500px at 90% 110%, rgba(124, 58, 237, 0.1), transparent 60%),
            linear-gradient(180deg, #fdf8fc 0%, #f8f0f7 50%, #f3eaf5 100%);
    }

    .auth-card,
    .login-card,
    .register-card,
    .reset-card {
        width: min(100%, 480px);
        max-width: 480px;
        padding: 48px 44px 40px;
        border-radius: var(--auth-radius-card);
        border: 1px solid var(--auth-card-border);
        background: rgba(255, 255, 255, 0.96);
        box-shadow:
            0 32px 72px -24px rgba(206, 33, 177, 0.12),
            0 8px 24px -8px rgba(0, 0, 0, 0.04);
    }

    .auth-card::after,
    .login-card::after {
        content: '';
        position: absolute;
        inset: 10px;
        border-radius: 20px;
        border: 1px solid rgba(206, 33, 177, 0.05);
        pointer-events: none;
    }

    .matrixe-wordmark,
    .logo-container .matrixe-wordmark {
        font-size: 38px;
    }

    input {
        padding: 15px 18px;
        border-radius: var(--auth-radius-input);
    }

    .btn-primary,
    .btn-login,
    .btn-register {
        padding: 16px 18px;
        border-radius: var(--auth-radius-input);
        font-size: 15px;
    }
}


/* --- 15. Accessibility --- */

/* Focus-visible outlines for all interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--auth-primary);
    outline-offset: 2px;
}

/* Override the input outline so it uses box-shadow instead */
input:focus-visible {
    outline: none;
    border-color: var(--auth-primary);
    box-shadow: var(--auth-input-focus-shadow);
}


/* --- Auth Divider --- */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0 14px;
    color: #a8a29e;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(206, 33, 177, 0.1);
}


/* --- Telegram Auth --- */
.telegram-auth-container {
    display: none;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-height: 52px;
    margin-bottom: 4px;
}

.telegram-auth-container.loading::before {
    content: 'Загрузка Telegram...';
    color: var(--auth-text-muted);
    font-size: 13px;
}

.telegram-auth-cta {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    justify-content: center;
    padding: 9px 14px;
    border-radius: var(--auth-radius-input);
    border: 1px solid rgba(206, 33, 177, 0.1);
    background: rgba(206, 33, 177, 0.02);
    color: var(--auth-text-label);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    user-select: none;
    min-height: 46px;
    transition: all 0.2s ease;
}

.telegram-auth-cta:hover {
    border-color: rgba(42, 171, 238, 0.5);
    background: rgba(42, 171, 238, 0.04);
    transform: translateY(-1px);
}

.telegram-auth-cta[aria-busy="true"] {
    opacity: 0.7;
    pointer-events: none;
}

.telegram-auth-cta svg {
    width: 18px;
    height: 18px;
    display: block;
    color: #2AABEE;
    flex: 0 0 18px;
}

@media (min-width: 769px) {
    .telegram-auth-cta {
        min-height: 48px;
        border-radius: var(--auth-radius-input);
    }
}


/* --- Auth Inline Links (e.g., "Forgot password?") --- */
.auth-inline-links {
    display: flex;
    justify-content: flex-end;
    margin: -6px 2px 10px;
}

.auth-inline-links a {
    color: var(--auth-primary-hover);
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
}

.auth-inline-links a:hover {
    text-decoration: underline;
}

.auth-inline-links a:focus-visible {
    outline: 2px solid var(--auth-primary);
    outline-offset: 2px;
    border-radius: 2px;
}


/* ============================================================
   OVERRIDES — beat minimal.css !important rules for auth pages
   ============================================================ */

/* 1. Restore gradient button (minimal.css strips it to transparent) */
html[data-page="login"] .btn-login,
html[data-page="login"] .btn-primary,
html[data-page="register"] .btn-register,
html[data-page="register"] .btn-primary,
html[data-page="reset-password"] .btn-primary {
    background: var(--auth-btn-gradient) !important;
    color: #ffffff !important;
    border: none !important;
    box-shadow: var(--auth-btn-shadow) !important;
    font-weight: 700 !important;
    letter-spacing: 0.01em !important;
}

html[data-page="login"] .btn-login:hover,
html[data-page="login"] .btn-primary:hover,
html[data-page="register"] .btn-register:hover,
html[data-page="register"] .btn-primary:hover,
html[data-page="reset-password"] .btn-primary:hover {
    background: var(--auth-btn-gradient-hover) !important;
    box-shadow: var(--auth-btn-shadow-hover) !important;
    transform: translateY(-2px);
}

html[data-page="login"] .btn-login:active,
html[data-page="register"] .btn-register:active,
html[data-page="reset-password"] .btn-primary:active {
    transform: translateY(0);
}

/* 2. Better card shadow on desktop */
@media (min-width: 769px) {
    .login-card,
    .register-card,
    .reset-card,
    .auth-card {
        box-shadow:
            0 24px 60px -20px rgba(206, 33, 177, 0.12),
            0 8px 20px -8px rgba(0, 0, 0, 0.06) !important;
    }
}

/* 3. Better placeholder contrast (WCAG AA) */
html[data-page] input::placeholder {
    color: #6b7280 !important;
    opacity: 1;
}
