:root {
    --bg-color: #0b0b0b;
    --text-color: #ffffff;
    --text-muted: #a9a9a9;
    --input-bg: #151515;
    --input-border: #333;
    --input-text: #fff;
    --btn-bg: #ffffff;
    --btn-text: #000000;
    --btn-hover: #e0e0e0;
    --zocial-border: #333;
    --zocial-bg: transparent;
    --zocial-hover: #1a1a1a;
    --zocial-hover: #1a1a1a;
    --zocial-text: #fff;
    --error-color: #ff4444;
    --modal-bg: #2a2a2a;
}

[data-theme="light"] {
    --bg-color: linear-gradient(135deg, #00B87C 0%, #00D68F 100%);
    --text-color: #1c1e21;
    --text-muted: #65676b;
    --input-bg: #ffffff;
    --input-border: #dddfe2;
    --input-text: #1c1e21;
    --btn-bg: #00B87C;
    --btn-text: #ffffff;
    --btn-hover: #009966;
    --zocial-border: #dddfe2;
    --zocial-bg: #ffffff;
    --zocial-hover: #f2f2f2;
    --zocial-text: #1c1e21;
    --error-color: #dc3545;
    --modal-bg: #c8f5e9;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-color) !important;
    background-attachment: fixed !important;
    background-size: cover !important;
    background-repeat: no-repeat !important;
    color: var(--text-color);
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    min-height: 100vh;
    overflow-y: auto;
    transition: background-color 0.3s, color 0.3s;
}

.login-pf-page {
    width: 100%;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 20px;
    box-sizing: border-box;
}

#kc-header {
    display: none;
    /* Hide default Keycloak header */
}

#kc-header-wrapper {
    display: none;
}

.card-pf {
    background: transparent;
    border: none;
    box-shadow: none;
    max-width: 400px;
    width: 100%;
    text-align: center;
    margin: 0 auto;
    position: relative;
}

#kc-content-wrapper {
    width: 100%;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
}

#kc-content {
    width: 100%;
    max-width: 450px;
    margin: 0 auto;
}

/* Logo Area */
.logo-container {
    margin-bottom: 32px;
}

.logo-container img {
    width: 300px;
    height: 300px;
    margin-bottom: 16px;
}

.login-title {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 32px;
}

/* Form Styles */
.form-group {
    margin-bottom: 20px;
    text-align: left;
    position: relative;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-color) !important;
    /* Force consistent color */
}

.form-control {
    width: 100%;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 12px 16px;
    color: var(--input-text);
    font-size: 16px;
    box-sizing: border-box;
    transition: border-color 0.2s, background-color 0.3s, color 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: var(--text-color);
}

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

.error-message {
    color: var(--error-color);
    font-size: 12px;
    margin-top: 4px;
}

.password-toggle {
    position: absolute;
    right: 12px;
    top: 38px;
    /* Adjust based on label height + padding */
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 16px;
}

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

.forgot-password {
    text-align: right;
    margin-top: 8px;
}

.forgot-password a {
    color: var(--text-color);
    font-size: 14px;
    text-decoration: none;
    font-weight: 500;
}

.forgot-password a:hover {
    text-decoration: underline;
}

/* Buttons */
.btn-primary {
    width: 100%;
    background-color: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    border-radius: 24px;
    padding: 10px;
    /* Match Google button padding */
    font-size: 14px;
    /* Match Google button font size */
    font-weight: 500;
    /* Match Google button weight */
    cursor: pointer;
    margin-top: 16px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    /* Ensure consistent height */
    box-sizing: border-box;
}

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

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Error Messages */
.error-message {
    color: var(--error-color);
    font-size: 12px;
    margin-top: 4px;
    display: block;
}

.form-control.error,
.form-control[aria-invalid="true"] {
    border-color: var(--error-color);
}

/* Social Providers */
.separator {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 32px 0;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
}

.separator::before,
.separator::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--input-border);
}

.separator::before {
    margin-right: 10px;
}

.separator::after {
    margin-left: 10px;
}

.social-providers {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cpd-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background-color: #ffffff;
    border: 1px solid #dadce0;
    border-radius: 24px;
    padding: 10px;
    color: #3c4043;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s, border-color 0.2s;
    cursor: pointer;
    box-sizing: border-box;
    font-family: 'Google Sans', Roboto, Arial, sans-serif;
    min-height: 40px;
    /* Ensure consistent height */
}

.cpd-button:hover {
    background-color: #f7f8f8;
    border-color: #d2e3fc;
}

.cpd-button svg {
    margin-right: 12px;
}

/* Dark mode overrides for Google button if needed, 
   but usually Google button stays light or has specific dark guidelines. 
   For now keeping it light as per snippet, but maybe adjust border/text for dark theme context?
   Actually, standard Google button is usually white/light. 
   Let's keep it as is for now. */

.cpd-button,
.zocial {
    /* Force exact same dimensions as all other buttons */
    min-height: 48px !important;
    height: 48px !important;
    padding: 0 16px !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    font-family: inherit !important;
    line-height: 1 !important;

    /* Layout */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;

    /* Styling */
    width: 100%;
    background-color: var(--zocial-bg);
    border: 1px solid var(--zocial-border);
    border-radius: 24px;
    color: var(--zocial-text);
    text-decoration: none;
    transition: background-color 0.2s, color 0.3s, border-color 0.3s;
    cursor: pointer;
    margin-bottom: 12px;
}

.cpd-button:hover,
.zocial:hover {
    background-color: var(--zocial-hover);
}

/* Google Sans font for social buttons */
.cpd-button svg {
    margin-left: 10px;
}

.zocial span {
    margin-left: 10px;
}

.zocial-icon {
    width: 20px;
    height: 20px;
}

/* Footer */
.footer {
    margin-top: 40px;
    font-size: 14px;
    color: var(--text-muted);
}

.footer a {
    color: var(--text-color);
    text-decoration: underline;
}

.bottom-links {
    margin-top: 60px;
    display: flex;
    justify-content: center;
    gap: 20px;
    font-size: 12px;
    color: var(--text-muted);
}

.bottom-links a {
    color: var(--text-color);
    text-decoration: none;
    cursor: pointer;
    pointer-events: auto;
}

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

/* Header Controls (Lang + Theme) */
/* We use absolute positioning on children to be robust against HTML caching */
.header-controls {
    /* If this element exists, let it be transparent and non-interfering */
    position: static;
    width: 100%;
    height: 0;
    padding: 0;
    margin: 0;
    border: none;
}

/* Language Picker */
.language-picker {
    position: absolute;
    /* Force absolute positioning */
    top: 20px;
    left: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 0;
    z-index: 20;
    /* Ensure on top */
}

.language-picker a {
    display: flex;
    align-items: center;
    margin: 0;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    opacity: 0.4;
    text-decoration: none;
}

.language-picker a:hover,
.language-picker a.active {
    opacity: 1;
    transform: scale(1.1);
}

.language-picker img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: block;
}

/* Hide Privacy Policy link */
.bottom-links a[href*="privacy"] {
    display: none !important;
}

/* Theme Toggle */
.theme-toggle {
    position: absolute;
    /* Force absolute positioning */
    top: 20px;
    right: 20px;
    transform: none;
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    font-size: 24px;
    padding: 0;
    border-radius: 50%;
    transition: background-color 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: 0;
    z-index: 20;
    /* Ensure on top */
}

.theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

/* Alerts */
.alert {
    padding: 15px;
    margin-bottom: 20px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
}

.alert-success {
    color: #0f5132;
    background-color: #d1e7dd;
    border-color: #badbcc;
}

.alert-warning {
    color: #664d03;
    background-color: #fff3cd;
    border-color: #ffecb5;
}

.alert-error,
.alert-danger {
    color: #842029;
    background-color: #f8d7da;
    border-color: #f5c2c7;
}

.alert-info {
    color: #055160;
    background-color: #cff4fc;
    border-color: #b6effb;
}

/* Icon Mappings */
.pficon {
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-style: normal;
    font-variant: normal;
    text-rendering: auto;
    line-height: 1;
}

.pficon-ok:before {
    content: "\f00c";
}

.pficon-warning-triangle-o:before {
    content: "\f071";
}

.pficon-error-circle-o:before {
    content: "\f06a";
}

.pficon-info:before {
    content: "\f05a";
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .logo-container img {
        width: 280px;
        /* Increased size, but safe for overlap */
        height: auto;
        /* Fix square aspect ratio issue */
        margin-bottom: 16px;
    }

    .logo-container {
        margin-bottom: 16px;
        position: relative;
    }

    .language-picker {
        top: 85px;
        /* Center of ~160px height logo + padding */
        left: 0;
        /* Stick to edge */
        flex-direction: column;
        gap: 15px;
        transform: translateY(-50%);
        padding-left: 5px;
        /* Minimal padding */
    }

    .theme-toggle {
        top: 85px;
        /* Center of ~160px height logo + padding */
        right: 0;
        /* Stick to edge */
        transform: translateY(-50%);
        padding-right: 5px;
        /* Minimal padding */
    }

    .login-pf-page {
        padding: 5px 16px;
        /* Minimal padding */
        justify-content: flex-start !important;
        /* Move content to top */
        padding-top: 5px;
    }

    body {
        align-items: flex-start !important;
        /* Align body content to top */
    }
}

/* Social Button Image Constraint */
.cpd-button img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    margin-left: 5px;
    /* Reduced to match space character */
}

/* Specific Icon Sizing */
.cpd-button img.social-icon-google {
    width: 20px;
    /* Smaller Google */
    height: 20px;
}

.cpd-button img.social-icon-large {
    width: 32px;
    /* Larger VK/ESIA */
    height: 32px;
}

/* Tooltip Styles */
.tooltip-trigger {
    position: relative;
}

.tooltip-trigger::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    margin-bottom: 8px;
    z-index: 100;
}

.tooltip-trigger:hover::after {
    opacity: 1;
    visibility: visible;
}



/* Form Action Buttons (Register & Restore) */
.form-action-buttons {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    justify-content: space-between;
}

.action-button-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Align first wrapper (Register) to left */
.action-button-wrapper:first-child .action-button-label {
    text-align: left;
}

/* Align last wrapper (Restore) to right */
.action-button-wrapper:last-child .action-button-label {
    text-align: right;
}

.action-button-label {
    font-size: 12px;
    /* Slightly smaller for label */
    color: var(--text-muted);
    font-weight: 400;
    display: flex;
    align-items: center;
    text-align: center;
    white-space: nowrap;
    /* Prevent wrapping if possible */
}

.action-button-label::before,
.action-button-label::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--input-border);
}

.action-button-label::before {
    margin-right: 5px;
}

.action-button-label::after {
    margin-left: 5px;
}

/* Standardize all button heights */
.btn-primary,
.btn-action,
.zocial {
    min-height: 48px !important;
    /* Force fixed height */
    height: 48px !important;
    /* Force fixed height */
    padding: 0 16px !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    font-family: inherit !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 24px !important;
    text-decoration: none !important;
    line-height: 1 !important;
    margin-bottom: 12px;
    /* Consistent margin */
}

.btn-primary {
    width: 100%;
    background-color: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    margin-top: 16px;
    transition: background-color 0.2s;
    cursor: pointer;
}

.btn-action {
    width: 100%;
    background-color: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    transition: background-color 0.2s;
    cursor: pointer;
    margin-bottom: 0;
    /* Reset margin for action buttons inside wrapper */
}

.zocial {
    width: 100%;
    background-color: var(--zocial-bg);
    border: 1px solid var(--zocial-border);
    color: var(--zocial-text);
    transition: background-color 0.2s, color 0.3s, border-color 0.3s;
    cursor: pointer;
}

/* Ensure text inside zocial inherits font */
.zocial span {
    font-family: inherit !important;
    font-size: inherit !important;
    font-weight: inherit !important;
    margin-left: 10px;
}

.btn-action:hover {
    background-color: var(--btn-hover);
    /* Match primary button hover */
    opacity: 1;
    /* Reset opacity change */
}

/* Mobile adjustments for form action buttons */
@media (max-width: 480px) {
    .form-action-buttons {
        flex-direction: row;
        /* Keep side-by-side on mobile */
        gap: 10px;
    }

    .action-button-wrapper {
        flex: 1;
    }

    .btn-action {
        font-size: 14px;
        padding: 10px 16px;
    }

    .action-button-label {
        font-size: 12px;
    }
}

/* Mobile adjustments for form links */
@media (max-width: 480px) {
    .form-links {
        flex-direction: row;
        /* Keep side-by-side layout */
        gap: 10px;
        align-items: baseline;
        /* Align to first line of text */
        justify-content: space-between;
    }

    .register-link {
        display: inline-flex;
        /* Changed to inline-flex */
        flex-direction: column;
        align-items: flex-start;
        /* Align to left */
        gap: 5px;
        text-align: left;
        flex: 1;
        /* Take equal space */
        vertical-align: top;
        /* Align to top */
    }

    .forgot-password {
        display: inline-flex;
        /* Changed to inline-flex */
        flex-direction: column;
        align-items: flex-end;
        /* Align to right */
        gap: 5px;
        text-align: right;
        flex: 1;
        /* Take equal space */
        vertical-align: top;
        /* Align to top */
    }

    .forgot-password-text {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 5px;
        white-space: normal;
        /* Allow text wrapping */
        word-wrap: break-word;
    }
}

/* Desktop Header Controls Positioning */
@media (min-width: 769px) {
    .language-picker {
        position: fixed;
        top: 20px;
        left: 20px;
        flex-direction: row;
        /* Horizontal on desktop */
        gap: 10px;
        transform: none;
        /* Reset transform */
    }

    .theme-toggle {
        position: fixed;
        top: 20px;
        right: 20px;
        transform: none;
        /* Reset transform */
    }
}