/* HubAdmin — брендинг формы логина Appsmith CE.
   Применяется к /user/login?forceForm=1 (backdoor для суперадмина).
   Все правила — через !important, т.к. styled-components Appsmith генерирует
   классы с высокой специфичностью. */

/* ======================== ШРИФТ INTER ======================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ======================== CSS-ПЕРЕМЕННЫЕ APPSMITH ======================== */
:root,
.appsmith-light-theme,
html,
body {
    --ads-v2-color-bg-brand: #10B981 !important;
    --ads-v2-color-bg-brand-emphasis: #059669 !important;
    --ads-v2-color-bg-brand-emphasis-plus: #047857 !important;
    --ads-v2-color-bg-brand-secondary: #ECFDF5 !important;
    --ads-v2-color-fg-brand: #059669 !important;
    --ads-v2-color-fg-brand-secondary: #10B981 !important;
    --ads-v2-color-border-brand: #10B981 !important;
    --ads-v2-color-outline-brand: #10B981 !important;
    --appsmith-color-black-0: #ffffff !important;
    --appsmith-color-brand: #10B981 !important;
    --appsmith-color-brand-hover: #059669 !important;
}

/* ======================== ФОН СТРАНИЦЫ ЛОГИНА ======================== */
/* Appsmith рендерит форму внутри полноэкранного контейнера. Применяем
   градиент (как в теме Keycloak) только когда мы на auth-роутах —
   определяем по body-классам и наличию #root с формой. */
html,
body.appsmith-light-theme {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    -webkit-font-smoothing: antialiased !important;
    margin: 0 !important;
}

/* Только на странице логина/регистрации — перекрашиваем фон.
   Appsmith оборачивает форму в main[data-testid] или в элемент с ролью "main".
   Проверяем присутствие формы по наличию <form> с action, содержащим "login". */
body:has(form[action*="/login"]),
body:has(form[action*="/signup"]),
body:has([data-testid="login-container"]),
body:has([data-testid="t--login-container"]) {
    background: linear-gradient(135deg, #f8fafc 0%, #ecfdf5 50%, #f0fdfa 100%) !important;
    background-color: #f8fafc !important;
    min-height: 100vh !important;
    overflow-x: hidden !important;
}

/* Fallback: класс, который повесит hubadmin-brand.js, если :has() не сработает */
body.hubadmin-auth-page {
    background: linear-gradient(135deg, #f8fafc 0%, #ecfdf5 50%, #f0fdfa 100%) !important;
    background-color: #f8fafc !important;
    min-height: 100vh !important;
    overflow-x: hidden !important;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    color: #111827 !important;
    position: relative !important;
}

/* Декоративные blob'ы (как в Keycloak-теме) */
body.hubadmin-auth-page::before,
body.hubadmin-auth-page::after {
    content: '' !important;
    position: fixed !important;
    border-radius: 50% !important;
    filter: blur(80px) !important;
    pointer-events: none !important;
    z-index: 0 !important;
}
body.hubadmin-auth-page::before {
    top: -120px !important;
    left: -120px !important;
    width: 400px !important;
    height: 400px !important;
    background: rgba(167, 243, 208, 0.5) !important;
}
body.hubadmin-auth-page::after {
    bottom: -120px !important;
    right: -120px !important;
    width: 500px !important;
    height: 500px !important;
    background: rgba(153, 246, 228, 0.4) !important;
}

/* ======================== ЛОГОТИП APPSMITH — подмена ======================== */
/* Скрываем оригинальный img-логотип Appsmith (в header формы логина). */
img[src*="appsmith_logo"],
img[src*="appsmith-logo"],
img[alt="Appsmith logo"],
img[alt="Appsmith Logo"],
img[alt="appsmith_logo"],
a[href="/applications"] img,
.t--appsmith-logo {
    content: url('/hubadmin-logo.svg') !important;
    max-height: 48px !important;
    max-width: 220px !important;
    width: auto !important;
    height: 48px !important;
    object-fit: contain !important;
    object-position: left center !important;
}

/* На случай если Appsmith рендерит логотип через SVG inline (не <img>).
   Перекрываем через селектор svg внутри header-root. */
#header-root svg[data-testid*="logo"],
header svg[class*="logo" i],
header svg[class*="Logo"] {
    display: none !important;
}

/* ======================== КАРТОЧКА ФОРМЫ ======================== */
/* Appsmith оборачивает форму в контейнер — у него нет стабильного id,
   но внутри почти всегда есть <form> + <h1>/<h2> с заголовком. */
form[action*="/login"],
form[action*="/signup"],
form[action*="/forgotPassword"],
form[action*="/resetPassword"] {
    background: #ffffff !important;
    border: 1px solid rgba(229, 231, 235, 0.8) !important;
    border-radius: 20px !important;
    padding: 40px !important;
    max-width: 440px !important;
    width: 100% !important;
    margin: 0 auto !important;
    box-shadow:
        0 20px 60px -10px rgba(16, 185, 129, 0.15),
        0 8px 20px -4px rgba(0, 0, 0, 0.05) !important;
    position: relative !important;
    z-index: 1 !important;
    box-sizing: border-box !important;
}

/* Заголовки формы (Welcome / Sign in to your account / Create your account) */
body.hubadmin-auth-page h1,
body.hubadmin-auth-page h2 {
    font-family: 'Inter', sans-serif !important;
    font-size: 24px !important;
    font-weight: 700 !important;
    color: #111827 !important;
    letter-spacing: -0.3px !important;
    line-height: 1.2 !important;
    margin: 0 0 16px 0 !important;
    text-align: center !important;
}

/* ======================== ИНПУТЫ ======================== */
body.hubadmin-auth-page input[type="text"],
body.hubadmin-auth-page input[type="email"],
body.hubadmin-auth-page input[type="password"],
body.hubadmin-auth-page input:not([type]),
form[action*="/login"] input,
form[action*="/signup"] input,
form[action*="/forgotPassword"] input {
    width: 100% !important;
    padding: 12px 14px !important;
    border: 1.5px solid #e5e7eb !important;
    border-radius: 10px !important;
    font-size: 15px !important;
    font-family: 'Inter', sans-serif !important;
    color: #111827 !important;
    background: #fafbfc !important;
    background-color: #fafbfc !important;
    transition: all 0.2s !important;
    line-height: 1.4 !important;
    box-shadow: none !important;
    outline: none !important;
    box-sizing: border-box !important;
}

body.hubadmin-auth-page input[type="text"]:focus,
body.hubadmin-auth-page input[type="email"]:focus,
body.hubadmin-auth-page input[type="password"]:focus,
body.hubadmin-auth-page input:not([type]):focus,
form[action*="/login"] input:focus,
form[action*="/signup"] input:focus,
form[action*="/forgotPassword"] input:focus {
    border-color: #10b981 !important;
    background: #ffffff !important;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1) !important;
}

/* Метки полей */
body.hubadmin-auth-page label,
form[action*="/login"] label,
form[action*="/signup"] label {
    font-family: 'Inter', sans-serif !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    color: #374151 !important;
}

/* ======================== КНОПКА «SIGN IN» ======================== */
body.hubadmin-auth-page button[type="submit"],
body.hubadmin-auth-page button.t--sign-up,
body.hubadmin-auth-page button.t--login-page-submit-btn,
form[action*="/login"] button[type="submit"],
form[action*="/signup"] button[type="submit"],
form[action*="/forgotPassword"] button[type="submit"],
form[action*="/resetPassword"] button[type="submit"] {
    width: 100% !important;
    padding: 14px 24px !important;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    background-image: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    background-color: #10b981 !important;
    color: #ffffff !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    border: none !important;
    border-radius: 10px !important;
    cursor: pointer !important;
    transition: all 0.2s !important;
    box-shadow: 0 8px 16px -4px rgba(16, 185, 129, 0.4) !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    line-height: 1.4 !important;
    height: auto !important;
    min-height: 48px !important;
    margin-top: 12px !important;
}

body.hubadmin-auth-page button[type="submit"]:hover,
form[action*="/login"] button[type="submit"]:hover,
form[action*="/signup"] button[type="submit"]:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%) !important;
    background-image: linear-gradient(135deg, #059669 0%, #047857 100%) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 12px 24px -6px rgba(16, 185, 129, 0.5) !important;
    color: #ffffff !important;
}

body.hubadmin-auth-page button[type="submit"]:active,
form[action*="/login"] button[type="submit"]:active {
    transform: translateY(0) !important;
    box-shadow: 0 6px 12px -3px rgba(16, 185, 129, 0.4) !important;
}

/* ======================== ССЫЛКИ ======================== */
body.hubadmin-auth-page a,
form[action*="/login"] ~ * a,
form[action*="/signup"] ~ * a,
[class*="signup" i] a,
[class*="login" i] a {
    color: #059669 !important;
    text-decoration: none !important;
    font-weight: 500 !important;
    font-family: 'Inter', sans-serif !important;
}

body.hubadmin-auth-page a:hover {
    color: #047857 !important;
    text-decoration: underline !important;
}

/* ======================== СКРЫТИЕ НЕНУЖНОГО ======================== */
/* Скрываем Appsmith-ссылку на signup (внизу формы):
   «Don't have an account? Sign up» — у нас registrations через Mongo отключены. */
a[href*="/user/signup"],
a[href="/signup"],
a[data-testid*="signup" i] {
    display: none !important;
}

/* Скрываем соц-кнопки Google/GitHub OAuth у формы Appsmith —
   у нас Keycloak SSO отдельно. */
a[href*="/oauth2/authorization/google"],
a[href*="/oauth2/authorization/github"] {
    display: none !important;
}

/* ======================== АДАПТИВНОСТЬ ======================== */
@media (max-width: 480px) {
    form[action*="/login"],
    form[action*="/signup"],
    form[action*="/forgotPassword"] {
        padding: 28px 24px !important;
        border-radius: 16px !important;
    }
    body.hubadmin-auth-page h1,
    body.hubadmin-auth-page h2 {
        font-size: 20px !important;
    }
}
