/* ==========================================================================
   1. ГЛОБАЛЬНЫЕ СТИЛИ И АНИМИРОВАННЫЙ ФОН
   ========================================================================== */

   body {
    font-family: 'Roboto', sans-serif;
    margin: 0;
    background: linear-gradient(-45deg, #0f0f0f, #1b1432, #0f0f0f, #32142d);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ==========================================================================
   2. ОСНОВНАЯ ФОРМА И КОНТЕЙНЕР
   ========================================================================== */

.auth-page-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    width: 100%; 
    box-sizing: border-box; 
}

.auth-form {
    width: 100%;
    max-width: 380px;
    padding: 28px 30px 40px;
    border-radius: 16px;
    text-align: center;
    background: rgba(28, 28, 28, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    position: relative;
    box-sizing: border-box;
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* ==========================================================================
   3. ПАНЕЛЬ: ТЕМА (одна кнопка) + ЯЗЫК
   ========================================================================== */

.auth-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    width: 100%;
    margin: 0 0 20px;
    flex-shrink: 0;
}

.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-width: 28px;
    height: 26px;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.2);
    color: #e8e8e8;
    font-size: 12px;
    font-weight: 700;
    font-family: inherit;
    line-height: 1;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.theme-toggle-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.theme-toggle-icon {
    font-size: 13px;
    line-height: 1;
    display: block;
}

.auth-toolbar--lang-only {
    justify-content: flex-end;
}

.lang-switcher {
    display: flex;
    gap: 4px;
    align-items: center;
}

.lang-switcher a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    height: 26px;
    min-height: 0;
    line-height: 1;
    color: #a0a0a0;
    text-decoration: none;
    font-size: 12px;
    font-weight: 700;
    padding: 0 8px;
    border-radius: 6px;
    transition: all 0.3s ease;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.lang-switcher a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.lang-switcher a.active {
    color: #fff;
    background: linear-gradient(45deg, #007BFF, #3ea6ff);
    box-shadow: 0 2px 5px rgba(0, 123, 255, 0.3);
    border-color: transparent;
}

/* ==========================================================================
   4. ТИПОГРАФИКА
   ========================================================================== */

.auth-form h2 {
    margin-top: 0;
    margin-bottom: 24px;
    color: #fff;
    font-weight: 500;
    font-size: 24px;
    letter-spacing: 0.5px;
}

.auth-form p {
    margin-top: 25px;
    color: #a0a0a0;
}

.auth-form > h2 + p,
.auth-form .auth-desc {
    margin-top: 0;
    margin-bottom: 14px;
    font-size: 14px;
    line-height: 1.45;
    color: #a0a0a0;
}

.auth-form .auth-muted {
    margin: 0 0 12px;
    font-size: 13px;
    text-align: center;
    color: #888;
}

.auth-form-footer-link {
    margin-top: 16px !important;
    margin-bottom: 0;
    text-align: center;
}

.auth-form a {
    color: #4fa8ff;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

.auth-form a:hover {
    color: #81c3ff;
}

/* ==========================================================================
   5. ЭЛЕМЕНТЫ ФОРМЫ
   ========================================================================== */

.input-wrapper {
    position: relative;
    margin-bottom: 25px;
}

.input-wrapper--code {
    margin-bottom: 16px;
}

.auth-form input {
    width: 100%;
    padding: 12px 50px; 
    border: 1px solid transparent;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 16px;
    box-sizing: border-box;
    transition: all 0.3s ease;
    margin-bottom: 0;
}

.auth-form input::placeholder {
    color: #888;
}

.auth-form input:focus {
    outline: none;
    background-color: rgba(0, 0, 0, 0.4);
    border-color: #4fa8ff;
}

.auth-form button:not(.theme-toggle-btn):not(.captcha-refresh-btn):not(.resend-link-btn) {
    width: 100%;
    padding: 12px;
    margin-top: 5px;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-weight: 500;
    font-size: 16px;
    cursor: pointer;
    background: linear-gradient(45deg, #007BFF, #3ea6ff);
    transition: transform 0.2s ease, box-shadow 0.3s ease;
}

.auth-form button:not(.theme-toggle-btn):not(.captcha-refresh-btn):not(.resend-link-btn):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
}

.auth-form .theme-toggle-btn {
    width: auto;
    max-width: none;
    margin-top: 0;
    transform: none;
    box-shadow: none;
}

.input-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    transition: filter 0.3s ease;
    filter: invert(1) opacity(0.4);
    pointer-events: none;
}

.input-wrapper:focus-within .input-icon {
    filter: invert(1) opacity(1);
}

.input-wrapper.is-autofilled .input-icon {
    filter: invert(0) !important;
}

/* ==========================================================================
   6. ПОЛЗУНОК "ЗАПОМНИТЬ МЕНЯ"
   ========================================================================== */

.remember-me-wrapper {
    display: flex;
    align-items: center;
    margin-bottom: 25px;
}

.toggle-label {
    color: #a0a0a0;
    font-size: 14px;
    margin-left: 12px;
    cursor: pointer;
    user-select: none;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: #3ea6ff;
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

/* ==========================================================================
   7. СООБЩЕНИЯ И ОШИБКИ
   ========================================================================== */

.error-message,
.success-message {
    padding: 12px;
    margin-bottom: 20px;
    border-radius: 6px;
    text-align: center;
    font-size: 14px;
}

.error-message {
    background: rgba(255, 82, 82, 0.1);
    border: 1px solid rgba(255, 82, 82, 0.3);
    color: #ff8a80;
}

.success-message {
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid rgba(76, 175, 80, 0.3);
    color: #81c784;
}

.auth-banner-line {
    margin: 0 0 0.5rem;
}

.auth-banner-line:last-child {
    margin-bottom: 0;
}

.input-error-message {
    position: absolute;
    bottom: -22px;
    left: 5px;
    top: 45px; 
    color: #ff8a80;
    font-size: 13px;
    text-align: left;
    opacity: 0;
    transform: translateY(-5px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.input-error-message.visible {
    opacity: 1;
    transform: translateY(0);
}

.auth-form input.input-error {
    border-color: #ff5252;
}

.input-wrapper:has(input.input-error) .input-icon {
    filter: brightness(0) saturate(100%) invert(49%) sepia(31%) saturate(2206%) hue-rotate(315deg) brightness(102%) contrast(102%);
}

.field-error-icon {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    cursor: help;
}

.field-error-icon img {
    width: 20px;
    height: 20px;
    filter: brightness(0) saturate(100%) invert(49%) sepia(31%) saturate(2206%) hue-rotate(315deg) brightness(102%) contrast(102%);
}

.field-error-icon::after {
   content: attr(data-tooltip);
   position: absolute;
   bottom: 130%;
   right: 50%;
   transform: translateX(50%);
   background-color: #333;
   color: #ff8a80;
   padding: 8px 12px;
   border-radius: 6px;
   font-size: 13px;
   line-height: 1.4;
   width: 260px;
   text-align: left;
   opacity: 0;
   visibility: hidden;
   transition: opacity 0.3s ease, visibility 0.3s ease;
   pointer-events: none;
   z-index: 10;
   border: 1px solid #ff5252;
   box-shadow: 0 0 10px rgba(255, 82, 82, 0.3);
   white-space: pre-line;
}

.field-error-icon:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ==========================================================================
   8. АДАПТАЦИЯ — смартфоны
   ========================================================================== */

@media screen and (max-width: 768px) {
    body:has(.auth-page-container) {
        padding:
            max(12px, env(safe-area-inset-top, 0px))
            max(12px, env(safe-area-inset-right, 0px))
            max(12px, env(safe-area-inset-bottom, 0px))
            max(12px, env(safe-area-inset-left, 0px));
    }

    .auth-page-container {
        padding: 0;
        width: 100%;
        max-width: 400px;
    }

    .auth-form {
        padding: 22px 20px 26px;
    }

    .auth-toolbar {
        margin-bottom: 8px;
        gap: 6px;
        min-height: 0;
    }

    .theme-toggle-btn {
        height: 26px;
        min-width: 28px;
        padding: 0 6px;
    }

    .lang-switcher a {
        height: 26px;
        padding: 0 9px;
        font-size: 12px;
    }

    .auth-form h2 {
        font-size: 22px;
        margin-bottom: 14px;
    }

    .auth-form > h2 + p,
    .auth-form .auth-desc {
        margin-bottom: 12px;
    }

    .input-wrapper {
        margin-bottom: 16px;
    }

    .auth-form input {
        font-size: 16px;
        padding: 12px 44px 12px 44px;
    }

    .auth-form button:not(.theme-toggle-btn):not(.captcha-refresh-btn):not(.resend-link-btn) {
        padding: 12px 14px;
        font-size: 16px;
    }

    .auth-form p {
        margin-top: 18px;
    }

    .auth-bottom-links {
        margin-top: 14px;
        gap: 8px;
    }

    .auth-bottom-links p {
        margin-top: 0;
    }

    .captcha-image-wrap {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        gap: 8px;
        margin: 0 0 10px;
    }

    .captcha-image {
        flex: 1 1 auto;
        width: auto;
        max-width: calc(100% - 104px);
        height: 48px;
        min-height: 0;
        object-fit: contain;
    }

    .captcha-refresh-btn {
        flex: 0 0 auto;
        min-width: 92px !important;
        width: auto !important;
        min-height: 0 !important;
        height: 40px;
        padding: 8px 10px !important;
        font-size: 13px !important;
        align-self: center;
    }

    .code-input-field {
        padding: 14px 0 !important;
        font-size: 22px !important;
        letter-spacing: 10px !important;
    }
}

@media screen and (max-width: 420px) {
    .auth-form {
        padding: 20px 16px 22px;
    }

    .auth-form input {
        padding: 12px 40px 12px 42px;
    }

    .input-icon {
        left: 14px;
    }

    .captcha-image {
        max-width: calc(100% - 96px);
    }

    .captcha-refresh-btn {
        min-width: 84px !important;
        font-size: 12px !important;
    }
}

/* ==========================================================================
   9. CAPTCHA (картинка + кнопка обновления)
   ========================================================================== */

.captcha-image-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: -2px 0 12px;
}

.captcha-image {
    height: 56px;
    width: 230px;
    max-width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: #eef2f7;
    object-fit: cover;
}

.captcha-refresh-btn {
    width: auto !important;
    min-width: 128px;
    margin-top: 0 !important;
    padding: 10px 12px !important;
    border-radius: 8px !important;
    border: 1px solid rgba(79, 168, 255, 0.45) !important;
    background: rgba(79, 168, 255, 0.1) !important;
    color: #d9ebff !important;
    font-size: 14px !important;
    line-height: 1.2;
    box-shadow: none !important;
    transform: none !important;
}

.captcha-refresh-btn:hover {
    background: rgba(79, 168, 255, 0.2) !important;
    box-shadow: 0 0 0 2px rgba(79, 168, 255, 0.16) !important;
    transform: none !important;
}


/* ==========================================================================
   10. КНОПКА-ССЫЛКА (ПОВТОРНАЯ ОТПРАВКА КОДА)
   ========================================================================== */
   .auth-form button.resend-link-btn {
    background: transparent !important;
    border: none !important;
    color: #4fa8ff !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    text-decoration: none !important; /* Убрали подчеркивание везде */
    padding: 0 !important;
    margin: 15px auto 0 !important;
    box-shadow: none !important;
    width: auto !important;
    display: inline-block !important;
}

.auth-form button.resend-link-btn:hover {
    color: #81c3ff !important;
    transform: none !important; 
    box-shadow: none !important;
}

.auth-form button.resend-link-btn:disabled {
    color: #666 !important;
    cursor: not-allowed !important;
}

/* ==========================================================================
   11. ВВОД КОДА (ИДЕАЛЬНАЯ КАРЕТКА И ЦИФРЫ)
   ========================================================================== */
.code-input-field {
    text-align: center !important;
    font-size: 24px !important; /* Оптимальный размер цифр */
    line-height: 1 !important;  /* Жестко фиксируем высоту курсора по размеру шрифта */
    letter-spacing: 12px !important; /* Воздух между цифрами */
    padding: 16px 0 !important; /* Высота поля задается отступами */
    height: auto !important;
    font-weight: bold !important;
    font-family: monospace, monospace !important;
    border-radius: 8px !important;
}

.code-input-field::placeholder {
    letter-spacing: 12px !important;
    font-weight: normal !important;
    color: #555 !important;
}

/* ==========================================================================
   12. ВСПЛЫВАЮЩИЕ УВЕДОМЛЕНИЯ (ТОСТЫ) И НИЖНИЕ ССЫЛКИ
   ========================================================================== */
.auth-bottom-links {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.auth-bottom-links p {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

.auth-form a {
    font-size: 15px; 
}

/* Стили для всплывающих уведомлений (вместо тех, что раздвигали форму) */
.toast-alert {
    position: fixed;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    padding: 14px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    animation: slideDownToast 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards, 
               fadeOutToast 0.4s ease 3.5s forwards; /* Исчезает через 3.5 сек */
    pointer-events: none; /* Чтобы не мешать кликать по сайту */
    white-space: nowrap;
}

.toast-success {
    background: rgba(46, 125, 50, 0.95); /* Темно-зеленый */
    border: 1px solid rgba(76, 175, 80, 0.4);
    color: #fff;
    backdrop-filter: blur(10px);
}

.toast-error {
    background: rgba(198, 40, 40, 0.95); /* Темно-красный */
    border: 1px solid rgba(255, 82, 82, 0.4);
    color: #fff;
    backdrop-filter: blur(10px);
}

@keyframes slideDownToast {
    from { top: -50px; opacity: 0; }
    to { top: 30px; opacity: 1; }
}

@keyframes fadeOutToast {
    from { opacity: 1; }
    to { opacity: 0; visibility: hidden; }
}