/* ============================================================
   Telegram Web — точная копия страницы авторизации web.telegram.org
   Все классы и ID сохранены. Только визуальные стили.
   ============================================================ */

/* ── Иконочный шрифт ── */
@font-face {
    font-family: "icons";
    font-weight: normal;
    font-style: normal;
    font-display: block;
    src: url("../assets/fonts/icons.woff2") format("woff2");
}

/* ── CSS переменные (точная палитра Telegram) ── */
:root {
    --color-primary:               #3390ec;
    --color-primary-shade:         #2b7de9;
    --color-primary-shade-darker:  #2574e0;
    --color-white:                 #ffffff;
    --color-black:                 #000000;
    --color-text:                  #000000;
    --color-text-secondary:        #707579;
    --color-placeholders:          #a2acb4;
    --color-borders:               #dadce0;
    --color-borders-input:         #dadce0;
    --color-background:            #ffffff;
    --color-background-secondary:  #f4f4f5;
    --color-error:                 #e53935;
    --border-radius-default:       0.75rem;
    --font-weight-normal:          400;
    --font-weight-medium:          500;
}

/* ── Сброс ── */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI",
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    background-color: var(--color-background);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* ── Контейнеры форм ── */
#auth-phone-number-form,
#code-form,
#password-form {
    overflow-y: auto;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Обёртка формы авторизации ── */
.auth-form {
    width: 100%;
    max-width: 25.5rem;
    margin: 0 auto;
    padding: 2rem 1rem 1rem;
    text-align: center;
}

@media (min-width: 600px) and (min-height: 450px) {
    .auth-form {
        padding: 6.8125rem 1.5rem 1.5rem;
    }
}

/* ── Логотип ── */
#logo {
    display: block;
    width: 7.5rem;
    height: 7.5rem;
    margin: 0 auto 1.75rem;
    background: url("../assets/img/logo.jpg") center / cover no-repeat;
    border-radius: 50%;
    overflow: hidden;
}

@media (min-width: 600px) and (min-height: 450px) {
    #logo {
        width: 10rem;
        height: 10rem;
        margin-bottom: 2.5rem;
    }
}

/* ── Заголовок ── */
h1 {
    font-size: 1.25rem;
    line-height: 1.2;
    font-weight: var(--font-weight-normal);
    color: var(--color-text);
    margin: 0 0 1rem;
}

@media (min-width: 600px) {
    h1 {
        font-size: 2rem;
        line-height: 1.5;
    }
}

/* ── Описание ── */
.note {
    margin: 0 0 2.5rem;
    font-size: 0.875rem;
    line-height: 1.35;
    color: var(--color-text-secondary);
}

@media (min-width: 600px) {
    .note {
        margin-bottom: 3rem;
        font-size: 1rem;
    }
}

/* ── Форма ── */
.form {
    min-height: 26.25rem;
}

/* ── Группа поля ввода ── */
.input-group {
    position: relative;
    margin-bottom: 1.125rem;
}

/* Плавающий label */
.input-group label {
    pointer-events: none;
    cursor: text;
    position: absolute;
    top: 0.6875rem;
    left: 1rem;
    transform-origin: left center;
    display: block;
    padding: 0 0.3125rem;
    font-size: 1rem;
    font-weight: var(--font-weight-normal);
    color: var(--color-placeholders);
    white-space: nowrap;
    background-color: var(--color-background);
    transition: transform 0.15s ease-out, color 0.15s ease-out;
}

/* Label вверх — когда заполнено */
.input-group.touched label {
    transform: scale(0.75) translate(0, -2rem);
    color: var(--color-text-secondary);
}

/* Label вверх — при фокусе */
.input-group .form-control:focus + label {
    transform: scale(0.75) translate(0, -2rem);
    color: var(--color-primary);
}

.input-group:focus-within label {
    color: var(--color-primary);
}

.input-group.touched:focus-within label {
    transform: scale(0.75) translate(0, -2rem);
    color: var(--color-primary);
}

/* ── Поле ввода ── */
.form-control {
    --border-width: 1px;
    display: block;
    width: 100%;
    height: 3rem;
    padding: calc(0.75rem - var(--border-width))
             calc(1.1875rem - var(--border-width))
             0.6875rem;
    border: var(--border-width) solid var(--color-borders-input);
    border-radius: var(--border-radius-default);
    font-size: 1rem;
    line-height: 1.25rem;
    font-family: inherit;
    color: var(--color-text);
    background-color: var(--color-background);
    outline: none;
    -webkit-appearance: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control::placeholder {
    color: var(--color-placeholders);
    opacity: 0.5;
}

.form-control:not(:focus):not(.phone-input-field)::placeholder {
    opacity: 0;
}

.form-control:focus:not(.phone-input-field)::placeholder {
    opacity: 0.5;
}

.form-control:hover {
    border-color: var(--color-primary);
}

.form-control:hover + label,
.form-control:hover ~ label {
    color: var(--color-primary);
}

.form-control:focus {
    border-color: var(--color-primary);
    box-shadow: inset 0 0 0 1px var(--color-primary);
    caret-color: var(--color-primary);
}

.form-control:focus + label,
.form-control:focus ~ label {
    color: var(--color-primary);
}

/* Dropdown open */
.input-group.dropdown-open .form-control {
    border-color: var(--color-primary);
    box-shadow: inset 0 0 0 1px var(--color-primary);
}

.input-group.dropdown-open label {
    transform: scale(0.75) translate(0, -2rem);
    color: var(--color-primary);
}

/* ── Ошибки ── */
.input-group.error .form-control,
.code-input-group.error .form-control,
.password-input-group.error .form-control {
    --border-width: 2px;
    border-color: var(--color-error);
    box-shadow: none;
}

.input-group.error .form-control:focus,
.code-input-group.error .form-control:focus,
.password-input-group.error .form-control:focus {
    border-color: var(--color-error);
    box-shadow: none;
}

.input-group.error label,
.code-input-group.error label,
.password-input-group.error label {
    color: var(--color-error) !important;
    transform: scale(0.75) translate(0, -2rem);
}

.input-group.error.with-label label,
.code-input-group.error.with-label label,
.password-input-group.error.with-label label {
    transform: scale(0.75) translate(0, -2rem);
}

/* ── Выбор страны ── */
.CountryCodeInput {
    position: relative;
}

.CountryCodeInput .input-group {
    cursor: pointer;
    z-index: 10;
}

.CountryCodeInput .css-icon-down {
    position: absolute;
    top: 50%;
    right: 1.3125rem;
    width: 0;
    height: 0;
    border: solid var(--color-text-secondary);
    border-radius: 1px;
    border-width: 0 2px 2px 0;
    display: inline-block;
    padding: 5px;
    margin-top: -9px;
    transform: rotate(45deg);
    pointer-events: none;
}

.CountryCodeInput.ready .css-icon-down {
    transition: margin-top 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.CountryCodeInput .css-icon-down.open {
    margin-top: -4px;
    transform: rotate(225deg);
    border-color: var(--color-primary);
}

.CountryCodeInput .input-group.dropdown-open label {
    color: var(--color-primary) !important;
}

/* ── Выпадающий список стран ── */
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    display: none;
    max-height: 23.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    margin-top: 0.25rem;
    background: var(--color-background);
    border: 1px solid var(--color-borders);
    border-radius: var(--border-radius-default);
    box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.12);
    transform-origin: top center;
    transform: scaleY(0.96) translateY(-4px);
    opacity: 0;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.dropdown-menu::-webkit-scrollbar { display: none; }
.dropdown-menu { -ms-overflow-style: none; scrollbar-width: none; }

.dropdown-menu.show {
    display: block;
    transform: scaleY(1) translateY(0);
    opacity: 1;
}

.MenuItem {
    display: flex;
    align-items: center;
}

.MenuItem button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9375rem;
    color: var(--color-text);
    transition: background-color 0.1s ease;
}

.MenuItem button:hover,
.MenuItem button:focus {
    background-color: var(--color-background-secondary);
    outline: none;
}

.country-flag {
    flex-shrink: 0;
    margin-right: 0.875rem;
    width: 1.75rem;
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.country-flag img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.country-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 0.75rem;
    text-align: left;
}

.country-code {
    flex-shrink: 0;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    padding-right: 0.25rem;
    opacity: 0.5;
}

/* ── Телефонный ввод ── */
.phone-input-field {
    font-family: inherit;
    letter-spacing: normal;
}

.phone-input-field::placeholder {
    color: #c8cdd0;
    opacity: 1;
}

.phone-input-field:focus::placeholder {
    color: #dde0e2;
}

/* ── Кнопки ── */
.Button {
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 3.5rem;
    padding: 0 0.625rem;
    border: 0;
    border-radius: var(--border-radius-default);
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: var(--font-weight-medium);
    line-height: 1.2;
    color: var(--color-white);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background-color: transparent;
    outline: none;
    transition: background-color 0.15s ease, opacity 0.15s ease;
    margin-top: 2.75rem;
}

.Button + .Button {
    margin-top: 1rem;
}

.Button.size-smaller {
    min-height: 2.75rem;
    padding: 0.3125rem;
}

.Button.color-primary {
    color: var(--color-white);
    background-color: var(--color-primary);
}

.Button.color-primary:hover {
    background-color: var(--color-primary-shade);
}

.Button.color-primary:active {
    background-color: var(--color-primary-shade-darker);
}

.Button.isText {
    background: none;
    color: var(--color-primary);
    padding: 0.5rem 0;
    min-height: auto;
    margin-top: 1rem;
    text-decoration: none;
}

.Button.isText:hover {
    opacity: 0.8;
}

/* Состояние загрузки кнопки */
.Button.loading {
    opacity: 0.75;
    cursor: not-allowed;
    pointer-events: none;
}

.Button.loading::after {
    content: "";
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.125rem;
    height: 1.125rem;
    background: url("../assets/img/loading.svg") center / contain no-repeat;
    filter: brightness(0) invert(1);
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    0%   { transform: translateY(-50%) rotate(0deg); }
    100% { transform: translateY(-50%) rotate(360deg); }
}

/* ── Индикатор загрузки ── */
.loading-indicator {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    margin-top: 0.5rem;
    min-height: 1.25rem;
}

/* ── Сообщение об ошибке ── */
.error-message {
    color: var(--color-error);
    font-size: 0.8125rem;
    margin-top: 0.375rem;
    text-align: center;
    padding: 0.5rem 0.75rem;
    background-color: rgba(229, 57, 53, 0.08);
    border-radius: 0.5rem;
}

.error-text {
    position: absolute;
    bottom: -1.5rem;
    left: 0;
    right: 0;
    color: var(--color-error);
    font-size: 0.8125rem;
    text-align: center;
}

/* ── Анимация обезьянки ── */
.monkey-animation {
    width: 160px;
    height: 160px;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Форма кода ── */
#code-form h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    margin-bottom: 1rem;
}

#code-form h1 #phone-display {
    font-size: 1.75rem;
    font-weight: 600;
}

.auth-number-edit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-secondary);
    opacity: 0.6;
    padding: 0.25rem;
    vertical-align: middle;
    border-radius: 50%;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.auth-number-edit:hover {
    opacity: 1;
    color: var(--color-primary);
}

.code-input-group {
    position: relative;
    margin-bottom: 2rem;
}

.code-input-field {
    text-align: left;
    font-size: 1.125rem;
    letter-spacing: normal;
    font-weight: 400;
    font-family: inherit;
    padding-left: 1rem;
}

/* Скрыть кнопку Next в форме кода */
#code-form .Button {
    display: none;
}

/* ── Форма пароля ── */
.password-input-group {
    position: relative;
    margin-bottom: 1.125rem;
}

.input-group.password-input-group .toggle-password {
    cursor: pointer;
    position: absolute;
    top: 50%;
    right: 0.5rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    font-size: 1.5rem;
    color: var(--color-text-secondary);
    opacity: 0.6;
    outline: none !important;
    border: none;
    background: none;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.input-group.password-input-group .toggle-password:hover {
    opacity: 1;
    color: var(--color-primary);
}

/* Оставляем для обратной совместимости */
.toggle-password {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #8b94a3;
    padding: 0.5rem;
    transition: color 0.2s;
}

.toggle-password:hover {
    color: var(--color-text-secondary);
}

/* ── Иконки ── */
.icon {
    font-family: "icons" !important;
    speak: none;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.icon-edit { font-size: 1.25rem; }
.icon-edit::before    { content: "\f14d"; }
.icon-eye-crossed::before { content: "\f153"; }
.icon-eye::before     { content: "\f155"; }

/* ── Утилиты ── */
.auth-subtitle {
    color: var(--color-text-secondary);
    text-align: center;
    margin: 0 0 2rem;
    font-size: 0.875rem;
    line-height: 1.4;
}

.div-button {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* ── Тонкий скроллбар ── */
.custom-scroll {
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}
.custom-scroll::-webkit-scrollbar { width: 6px; }
.custom-scroll::-webkit-scrollbar-track { background: transparent; }
.custom-scroll::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}


/* ══════════════════════════════════════════════════════════
   ТЁМНАЯ ТЕМА — data-theme="dark"
   ══════════════════════════════════════════════════════════ */

[data-theme="dark"] {
    --color-background:            #212121;
    --color-background-secondary:  #2b2b2b;
    --color-text:                  #ffffff;
    --color-text-secondary:        #aaaaaa;
    --color-placeholders:          #6b7478;
    --color-borders:               #3a3a3a;
    --color-borders-input:         #3a3a3a;
    --color-primary:               #3390ec;
    --color-primary-shade:         #2b7de9;
    --color-primary-shade-darker:  #2574e0;
    --color-error:                 #f44336;
}

[data-theme="dark"] body {
    background-color: var(--color-background);
    color: var(--color-text);
}

[data-theme="dark"] .form-control {
    background-color: var(--color-background);
    color: var(--color-text);
    border-color: var(--color-borders-input);
}

[data-theme="dark"] .input-group label {
    background-color: var(--color-background);
    color: var(--color-placeholders);
}

[data-theme="dark"] .dropdown-menu {
    background: var(--color-background-secondary);
    border-color: var(--color-borders);
    box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .MenuItem button {
    color: var(--color-text);
}

[data-theme="dark"] .MenuItem button:hover {
    background-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .country-code {
    color: var(--color-text-secondary);
}

/* ══════════════════════════════════════════════════════════
   ПАНЕЛЬ УПРАВЛЕНИЯ: ТЕМА + ЯЗЫК
   ══════════════════════════════════════════════════════════ */

.top-controls {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Кнопка темы ── */
.theme-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid var(--color-borders);
    border-radius: 50%;
    background: var(--color-background);
    color: var(--color-text-secondary);
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease,
                box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.theme-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.15);
}

/* Показываем нужную иконку в зависимости от темы */
.theme-icon--moon { display: none; }
.theme-icon--sun  { display: flex; }

[data-theme="dark"] .theme-icon--moon { display: flex; }
[data-theme="dark"] .theme-icon--sun  { display: none; }

/* ── Селектор языка ── */
.lang-select {
    height: 2.25rem;
    padding: 0 0.625rem;
    border: 1px solid var(--color-borders);
    border-radius: 0.625rem;
    background: var(--color-background);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    /* Стрелка вниз через background */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23707579' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    padding-right: 1.75rem;
    min-width: 4.5rem;
}

.lang-select:hover {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.15);
}

.lang-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.15);
}

[data-theme="dark"] .lang-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23aaaaaa' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

[data-theme="dark"] .lang-select option {
    background: var(--color-background-secondary);
    color: var(--color-text);
}

/* ══════════════════════════════════════════════════════════
   ПЛАВНЫЕ ПЕРЕХОДЫ ПРИ СМЕНЕ ТЕМЫ
   ══════════════════════════════════════════════════════════ */

body,
.form-control,
.input-group label,
.dropdown-menu,
.Button,
.theme-btn,
.lang-select,
#logo {
    transition-property: background-color, border-color, color, box-shadow;
    transition-duration: 0.25s;
    transition-timing-function: ease;
}
