/* ===========================================
   MFA KENYA CMS - WAGTAIL ADMIN THEME

   Best Practices Applied:
   - Use Wagtail's CSS variables for theming
   - Don't override internal class layouts
   - Let Wagtail handle its own CSS
   - Only customize colors through variables

   Sources:
   - https://docs.wagtail.org/en/stable/advanced_topics/customization/admin_templates.html
   - https://learnwagtail.com/docs/best-practices/customizing-the-wagtail-admin/
   =========================================== */

/* ===========================================
   WAGTAIL CSS VARIABLES - BRAND COLORS
   This is the official way to theme Wagtail
   =========================================== */

:root {
    /* Primary color - Teal accent (using HSL for all shades) */
    --w-color-primary: #0d9488;
    --w-color-primary-200: #14b8a6;
    --w-color-primary-hue: 175;
    --w-color-primary-saturation: 84%;
    --w-color-primary-lightness: 29%;

    /* Secondary color - Slate neutrals */
    --w-color-secondary: #64748b;
    --w-color-secondary-hue: 215;
    --w-color-secondary-saturation: 16%;
    --w-color-secondary-lightness: 47%;
    --w-color-secondary-50: #f8fafc;
    --w-color-secondary-75: #f1f5f9;
    --w-color-secondary-100: #e2e8f0;
    --w-color-secondary-400: #94a3b8;
    --w-color-secondary-600: #475569;

    /* Text colors */
    --w-color-text-context: #0f172a;
    --w-color-text-label: #1e293b;
    --w-color-text-meta: #64748b;

    /* Surface colors */
    --w-color-surface-page: #ffffff;
    --w-color-surface-field: #ffffff;
    --w-color-surface-menus: #1e293b;
    --w-color-surface-header: #1e293b;
    --w-color-surface-tooltip: #1e293b;
    --w-color-surface-button-default: #1e293b;

    /* Border colors */
    --w-color-border-furniture: #e2e8f0;
    --w-color-border-field-default: #cbd5e1;
    --w-color-border-field-hover: #94a3b8;
    --w-color-border-field-inactive: #e2e8f0;

    /* Status colors */
    --w-color-positive: #16a34a;
    --w-color-positive-100: #dcfce7;
    --w-color-warning: #d97706;
    --w-color-warning-100: #fef3c7;
    --w-color-critical: #dc2626;
    --w-color-critical-100: #fee2e2;
    --w-color-info: #0284c7;
    --w-color-info-100: #e0f2fe;

    /* Focus color - matches primary */
    --w-color-focus: #0d9488;

    /* Icon colors */
    --w-color-icon-primary: #ffffff;
    --w-color-icon-secondary: #64748b;
    --w-color-icon-secondary-hover: #0d9488;

    /* UI Density - slightly tighter than default */
    --w-density-factor: 0.9;

    /* Custom MFA Kenya colors (for login page) */
    --mfa-kenya-black: #0f0f0f;
    --mfa-kenya-red: #bb0000;
    --mfa-kenya-green: #006600;
}

/* ===========================================
   DARK THEME SUPPORT
   =========================================== */

.w-theme-dark {
    --w-color-surface-page: #0f172a;
    --w-color-surface-field: #1e293b;
    --w-color-text-context: #f1f5f9;
    --w-color-text-label: #e2e8f0;
    --w-color-border-furniture: #334155;
    --w-color-border-field-default: #475569;
}

@media (prefers-color-scheme: dark) {
    .w-theme-system {
        --w-color-surface-page: #0f172a;
        --w-color-surface-field: #1e293b;
        --w-color-text-context: #f1f5f9;
        --w-color-text-label: #e2e8f0;
        --w-color-border-furniture: #334155;
        --w-color-border-field-default: #475569;
    }
}

/* ===========================================
   KENYA FLAG STRIPE - BRANDING
   =========================================== */

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg,
        #1e293b 0%, #1e293b 25%,
        #dc2626 25%, #dc2626 50%,
        #16a34a 50%, #16a34a 75%,
        #1e293b 75%, #1e293b 100%);
    z-index: 9999;
    pointer-events: none;
}

/* Upgrade-banner CSS removed — handled by WAGTAIL_ENABLE_UPDATE_CHECK=False
   in settings/base.py (no JS fetch, no banner DOM rendered). */

/* ===========================================
   SIDEBAR POPUP/FLYOUT MENUS
   Fix visibility and contrast issues
   =========================================== */

/* Sidebar submenu dropdowns */
.sidebar-sub-menu-panel,
.w-sidebar__menu-item--open .sidebar-sub-menu-panel,
[data-controller="w-dropdown"] .w-dropdown__content,
.tippy-box,
.tippy-content {
    background-color: #ffffff !important;
    color: #1e293b !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
    border-radius: 8px !important;
}

/* Dropdown menu items */
.sidebar-sub-menu-panel a,
.sidebar-sub-menu-panel button,
.w-dropdown__content a,
.w-dropdown__content button,
.tippy-content a,
.tippy-content button {
    color: #1e293b !important;
    background: transparent !important;
    padding: 10px 16px !important;
    display: block !important;
    transition: background-color 0.15s ease !important;
}

/* Hover states for dropdown items */
.sidebar-sub-menu-panel a:hover,
.sidebar-sub-menu-panel button:hover,
.w-dropdown__content a:hover,
.w-dropdown__content button:hover,
.tippy-content a:hover,
.tippy-content button:hover {
    background-color: #f1f5f9 !important;
    color: #0d9488 !important;
}

/* Active/selected dropdown item */
.sidebar-sub-menu-panel a.is-active,
.sidebar-sub-menu-panel a[aria-current="page"],
.w-dropdown__content a.is-active {
    background-color: #f0fdfa !important;
    color: #0d9488 !important;
    font-weight: 600 !important;
}

/* Dropdown icons */
.sidebar-sub-menu-panel .icon,
.w-dropdown__content .icon,
.tippy-content .icon {
    color: #64748b !important;
}

.sidebar-sub-menu-panel a:hover .icon,
.w-dropdown__content a:hover .icon {
    color: #0d9488 !important;
}

/* Dropdown headers/labels */
.sidebar-sub-menu-panel h2,
.sidebar-sub-menu-panel .sidebar-sub-menu-panel__title,
.w-dropdown__content h2,
.w-dropdown__content h3 {
    color: #64748b !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    padding: 12px 16px 8px !important;
    margin: 0 !important;
    border-bottom: 1px solid #e2e8f0 !important;
}

/* Dropdown dividers */
.sidebar-sub-menu-panel hr,
.w-dropdown__content hr {
    border: none !important;
    border-top: 1px solid #e2e8f0 !important;
    margin: 8px 0 !important;
}

/* Action menus (more button dropdowns) */
.w-action-menu,
.c-dropdown__menu {
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
    border-radius: 8px !important;
    overflow: hidden !important;
}

.w-action-menu a,
.w-action-menu button,
.c-dropdown__menu a,
.c-dropdown__menu button {
    color: #1e293b !important;
    padding: 10px 16px !important;
}

.w-action-menu a:hover,
.w-action-menu button:hover,
.c-dropdown__menu a:hover,
.c-dropdown__menu button:hover {
    background-color: #f1f5f9 !important;
    color: #0d9488 !important;
}

/* ===========================================
   MINIMAL FORM ENHANCEMENTS
   Using CSS variables, not layout overrides
   =========================================== */

/* Focus states - use primary color */
input:focus,
textarea:focus,
select:focus,
.w-field__input input:focus,
.w-field__input textarea:focus,
.w-field__input select:focus {
    border-color: var(--w-color-focus);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
    outline: none;
}

/* Error states */
.w-field--error input,
.w-field--error textarea,
.w-field--error select {
    border-color: var(--w-color-critical);
}

/* Hide empty error/help containers */
.w-field__errors:not(:has(*)),
.w-field__help:not(:has(*)) {
    display: none;
}

/* ===========================================
   ACCESSIBILITY - REDUCED MOTION
   =========================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===========================================
   LOGIN PAGE STYLES
   Isolated to body.login - doesn't affect admin
   =========================================== */

body.login {
    background: linear-gradient(135deg, #0f0f0f 0%, #0f172a 50%, #006600 100%) !important;
    min-height: 100vh !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif !important;
    padding: 20px !important;
}

/* Kenya flag stripe - thicker on login */
body.login::before {
    height: 4px !important;
    background: linear-gradient(90deg,
        #0f0f0f 0%, #0f0f0f 25%,
        #bb0000 25%, #bb0000 50%,
        #006600 50%, #006600 75%,
        #0f0f0f 75%, #0f0f0f 100%) !important;
}

/* Login card container */
.login .content-wrapper {
    background: #ffffff !important;
    border-radius: 16px !important;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.4) !important;
    max-width: 460px !important;
    width: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Hide default Wagtail h1 */
.login .content-wrapper > h1 {
    display: none !important;
}

/* Branding section - moved to top */
.login-branding {
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%) !important;
    padding: 48px 32px 40px !important;
    text-align: center !important;
    position: relative !important;
    order: -10 !important;
}

/* Subtle pattern overlay */
.login-branding::before {
    content: "";
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;
}

/* Messages container ordering */
.login .content-wrapper > .messages {
    order: -5 !important;
}

/* Form ordering */
.login .content-wrapper > form {
    order: 1 !important;
}

/* Coat of Arms logo */
.login-coa {
    width: 100px;
    height: 100px;
    margin: 0 auto 24px auto;
    display: block;
    position: relative;
}

.login-titles {
    position: relative;
}

.login-gov {
    display: block !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    color: #14b8a6 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.2em !important;
    margin-bottom: 8px !important;
}

.login-ministry {
    font-size: 20px !important;
    font-weight: 700 !important;
    color: #ffffff !important;
    margin: 0 0 12px !important;
    line-height: 1.3 !important;
}

.login-system {
    font-size: 13px !important;
    color: #94a3b8 !important;
    margin: 0 !important;
    font-weight: 500 !important;
}

/* Form section */
.login form {
    padding: 36px 32px 32px;
}

.login .w-field {
    margin-bottom: 20px;
}

/* Form footer */
.login form .form-actions,
.login form footer {
    margin-top: 8px !important;
    border-top: none !important;
    padding: 0 !important;
    background: transparent !important;
}

/* Labels */
.login label {
    font-weight: 600 !important;
    color: #334155 !important;
    font-size: 13px !important;
    margin-bottom: 8px !important;
    display: block !important;
}

/* Inputs */
.login input[type="text"],
.login input[type="password"] {
    width: 100% !important;
    border: 2px solid #e2e8f0 !important;
    border-radius: 8px !important;
    padding: 14px 16px !important;
    font-size: 15px !important;
    background: #f8fafc !important;
    transition: all 0.2s ease !important;
    color: #0f172a !important;
}

.login input[type="text"]:hover,
.login input[type="password"]:hover {
    border-color: #94a3b8 !important;
}

.login input[type="text"]:focus,
.login input[type="password"]:focus {
    border-color: #0d9488 !important;
    box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.1) !important;
    outline: none !important;
    background: #ffffff !important;
}

/* Submit button */
.login-btn {
    width: 100% !important;
    padding: 16px 24px !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    background: linear-gradient(180deg, #006600 0%, #005500 100%) !important;
    border: none !important;
    border-radius: 8px !important;
    color: #ffffff !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important;
    margin-top: 8px !important;
}

.login-btn:hover {
    background: linear-gradient(180deg, #007700 0%, #006600 100%) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(0, 102, 0, 0.3) !important;
}

.login-btn:focus {
    box-shadow: 0 0 0 4px rgba(0, 102, 0, 0.2) !important;
    outline: none !important;
}

.login-btn-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Button text */
.login-btn em,
.login-btn span {
    white-space: nowrap;
}

/* Hide empty elements */
.login .messages:empty,
.login .messages:not(:has(*)),
.login p:empty:not(.login-system),
.login p:not(:has(*)):not(.login-system) {
    display: none !important;
}

/* Error messages */
.login .error-message,
.login .messages .error {
    background: #fef2f2 !important;
    border: 1px solid #fecaca !important;
    border-left: 4px solid #bb0000 !important;
    color: #991b1b !important;
    border-radius: 8px !important;
    padding: 14px 16px !important;
    font-size: 14px !important;
    margin-bottom: 20px !important;
}

/* Forgotten password link */
.login .reset-password {
    display: block !important;
    text-align: right !important;
    font-size: 13px !important;
    margin-bottom: 16px !important;
    color: #64748b !important;
}

.login .reset-password:hover {
    color: #0d9488 !important;
}

/* Remember me checkbox */
.login .remember-me {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    font-size: 14px !important;
    color: #475569 !important;
    margin-bottom: 16px !important;
    cursor: pointer !important;
}

.login .remember-me input[type="checkbox"] {
    width: 16px !important;
    height: 16px !important;
    accent-color: #0d9488 !important;
}

/* Footer help section */
.login .help {
    text-align: center !important;
    padding: 20px 32px 24px !important;
    border-top: 1px solid #f1f5f9 !important;
    background: #f8fafc !important;
}

.login .help a {
    color: #0d9488 !important;
    font-weight: 500 !important;
    text-decoration: none !important;
}

.login .help a:hover {
    text-decoration: underline !important;
}

.login .help::after {
    content: "Republic of Kenya" !important;
    display: block !important;
    margin-top: 16px !important;
    font-size: 11px !important;
    color: #94a3b8 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.15em !important;
    font-weight: 600 !important;
}

/* Links */
.login a {
    color: #0d9488 !important;
    text-decoration: none !important;
}

.login a:hover {
    text-decoration: underline !important;
}

/* Responsive */
@media (max-width: 520px) {
    body.login {
        padding: 12px !important;
    }

    .login-branding {
        padding: 36px 24px 32px !important;
    }

    .login-coa {
        width: 80px;
        height: 80px;
    }

    .login-ministry {
        font-size: 18px !important;
    }

    .login form {
        padding: 28px 24px;
    }

    .login .help {
        padding: 16px 24px 20px !important;
    }
}
