/*
 * Resilience Academy - KoboToolbox Custom Theme
 * ==============================================
 * Brand color: #54a8dc
 *
 * UPDATE-PROOF: This file is mounted via Docker volume and injected
 * by nginx sub_filter. Core KoboToolbox updates will not affect it.
 */

/* ==========================================================================
   COLOR VARIABLES
   ========================================================================== */

:root {
  --ra-primary: #54a8dc;
  --ra-primary-dark: #3d8abf;
  --ra-primary-light: #7dc0e8;
  --ra-secondary: #2c3e50;
  --ra-header-bg: #1a2a3a;
  --ra-sidebar-bg: #f7f9fb;
  --ra-accent: #e67e22;
  --ra-text-dark: #2c3e50;
}

/* ==========================================================================
   HEADER / TOP BAR
   ========================================================================== */

.main-header {
  background-color: var(--ra-header-bg) !important;
}

/* Replace the KoboToolbox logo with RA logo in the header */
.main-header .header__logo {
  background-image: url('/custom-static/images/ra-logo.png') !important;
  background-size: contain !important;
  background-repeat: no-repeat !important;
  background-position: left center !important;
}

/* Hide the default SVG logo text if visible */
.main-header .header__logo svg {
  opacity: 0 !important;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

/* Primary action buttons (NEW, Deploy, Save, etc.) */
.kobo-button--blue {
  background-color: var(--ra-primary) !important;
  border-color: var(--ra-primary) !important;
}

.kobo-button--blue:hover {
  background-color: var(--ra-primary-dark) !important;
  border-color: var(--ra-primary-dark) !important;
}

/* Form builder "Add question" and other action buttons */
.form-builder-header__button--save,
.form-builder-header__button--deploy {
  background-color: var(--ra-primary) !important;
}

/* ==========================================================================
   LOGIN PAGE
   ========================================================================== */

/* Login background image */
/* Hide language selector on login/signup pages */
.language-switcher {
  display: none !important;
}

.registration__bg {
  background-image: url('/custom-static/images/login-bg.jpg') !important;
  background-size: cover !important;
  background-position: center !important;
}

/* Semi-transparent overlay */
.registration__bg::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(26, 42, 58, 0.85) 0%,
    rgba(84, 168, 220, 0.7) 100%
  ) !important;
  z-index: 0;
}

/* Login form card */
.registration {
  background-color: rgba(255, 255, 255, 0.95) !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3) !important;
}

/* Login button */
.registration .kobo-button--blue {
  background-color: var(--ra-primary) !important;
  border-radius: 4px !important;
}

.registration .kobo-button--blue:hover {
  background-color: var(--ra-primary-dark) !important;
}

/* Replace login page logo with RA dark logo (visible on white card) */
.registration--logo {
  padding: 20px 0 10px !important;
  text-align: center !important;
}

.registration--logo a {
  display: block !important;
  width: 260px !important;
  height: 80px !important;
  margin: 0 auto !important;
  background: url('/custom-static/images/ra-logo-dark.png') no-repeat center / contain !important;
}

/* Hide the original img, replaced by background on parent link */
.registration--logo img {
  display: none !important;
}

/* Welcome text below the logo */
.registration--logo::after {
  content: 'Welcome to the Resilience Academy Data Collection Platform';
  display: block;
  margin-top: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ra-secondary);
  text-align: center;
  line-height: 1.4;
}

/* Hide the default photo credit (optional) */
.registration__credit {
  display: none !important;
}

/* Login form input fields - ensure visibility */
.registration input[type="text"],
.registration input[type="password"],
.registration input[type="email"] {
  color: #2c3e50 !important;
  background-color: #ffffff !important;
  border: 1px solid #ccc !important;
  border-radius: 4px !important;
  padding: 10px 12px !important;
  font-size: 14px !important;
}

.registration input[type="text"]::placeholder,
.registration input[type="password"]::placeholder,
.registration input[type="email"]::placeholder {
  color: #999 !important;
}

.registration input[type="text"]:focus,
.registration input[type="password"]:focus,
.registration input[type="email"]:focus {
  border-color: var(--ra-primary) !important;
  outline: none !important;
  box-shadow: 0 0 0 2px rgba(84, 168, 220, 0.2) !important;
}

/* Login form labels */
.registration label {
  color: #2c3e50 !important;
  font-weight: 500 !important;
}

/* ══════════════════════════════════════════════════════════
   SIGNUP FORM — matches login form design exactly
   ══════════════════════════════════════════════════════════ */

/* ══════════════════════════════════════════════════════════
   SIGNUP FORM — single column, centered, matches login
   ══════════════════════════════════════════════════════════ */

/* Force single column, centered card */
.registration--register {
  display: block !important;
  max-width: 460px !important;
  margin: 0 auto !important;
  text-align: center !important;
}

/* Center the logo and welcome text on signup form — match login exactly */
form.registration--register .registration--logo,
.registration--register .registration--logo {
  text-align: center !important;
  padding: 20px 0 10px !important;
  float: none !important;
  width: 100% !important;
  display: block !important;
}

form.registration--register .registration--logo a,
.registration--register .registration--logo a {
  display: block !important;
  width: 260px !important;
  height: 80px !important;
  margin: 0 auto !important;
  float: none !important;
  background: url('/custom-static/images/ra-logo-dark.png') no-repeat center / contain !important;
}

form.registration--register .registration--logo img,
.registration--register .registration--logo img {
  display: none !important;
}

form.registration--register .registration--logo::after,
.registration--register .registration--logo::after {
  content: 'Welcome to the Resilience Academy Data Collection Platform' !important;
  display: block !important;
  margin-top: 10px !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  color: var(--ra-secondary) !important;
  text-align: center !important;
  line-height: 1.4 !important;
  float: none !important;
  clear: both !important;
}

/* First half takes full width, clear all floats */
.registration--register .registration__first-half,
form.registration--register .registration__first-half {
  width: 100% !important;
  max-width: 100% !important;
  float: none !important;
  flex: none !important;
  padding: 0 20px !important;
  box-sizing: border-box !important;
  text-align: left !important;
  clear: both !important;
}

/* Password field wrappers — force full width */
form.registration--register .field.password1,
form.registration--register .field.password2 {
  width: 100% !important;
  max-width: 100% !important;
}

/* Hide second half and extra fields */
.registration--register .registration__second-half { display: none !important; }
.registration--register .field.country { display: none !important; }
.registration--register .field.sector { display: none !important; }
.registration--register .field.organization_type { display: none !important; }
.registration--register .field.organization_website { display: none !important; }
.registration--register .field.newsletter_subscription { display: none !important; }
.registration--register select[name="language"] { display: none !important; }

/* Hide the h1 — logo::after text replaces it */
.registration--register .registration__first-half h1 {
  display: none !important;
}

/* Compact field spacing */
.registration--register .field {
  margin-bottom: 10px !important;
}

/* Labels — match login exactly */
.registration--register .field label {
  display: block !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  color: #2c3e50 !important;
  margin-bottom: 4px !important;
}

/* Hide asterisks */
.registration--register .field .required {
  display: none !important;
}

/* ALL input fields — identical width and style, very specific selectors */
.registration--register input[type="text"],
.registration--register input[type="email"],
.registration--register input[type="password"],
.registration--register .field input,
form.registration--register input[type="text"],
form.registration--register input[type="email"],
form.registration--register input[type="password"],
form.registration--register .field input,
form.registration--register .field.password1 input,
form.registration--register .field.password2 input,
.registration--register #id_password1,
.registration--register #id_password2 {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 100% !important;
  padding: 10px 12px !important;
  font-size: 14px !important;
  border: 1px solid #ccc !important;
  border-radius: 4px !important;
  background: #fff !important;
  color: #2c3e50 !important;
  box-sizing: border-box !important;
  display: block !important;
}

.registration--register .field input:focus {
  border-color: var(--ra-primary) !important;
  outline: none !important;
  box-shadow: 0 0 0 2px rgba(84, 168, 220, 0.2) !important;
}

/* Create Account button — matches LOGIN button exactly */
.registration--register .kobo-button--blue {
  background-color: #54a8dc !important;
  border-radius: 4px !important;
  font-size: 14px !important;
  padding: 11px !important;
  margin-top: 6px !important;
  letter-spacing: 0.5px !important;
}

.registration--register .kobo-button--blue:hover {
  background-color: #3d8abf !important;
}

/* "or login" link — styled to match login page */
.registration--register .registration__orlogin {
  text-align: center !important;
  margin-top: 10px !important;
  font-size: 13px !important;
  color: #64748b !important;
}

/* Hide the duplicate LOG IN button added by ra-welcome.js auth footer */
.registration--register ~ .ra-auth-footer .ra-auth-btn,
.registration--register + .ra-auth-footer .ra-auth-btn,
.registration--register .ra-auth-btn {
  display: none !important;
}

.registration--register .registration__orlogin a {
  color: #54a8dc !important;
  font-weight: 500 !important;
  text-decoration: none !important;
}

.registration--register .registration__orlogin a:hover {
  text-decoration: underline !important;
}

/* Hide password help text / strength meter */
.registration--register #registration-password-app {
  display: none !important;
}

.registration--register .field .helptext {
  font-size: 11px !important;
  color: #94a3b8 !important;
  margin-top: 2px !important;
}

/* ── Mobile login form — reduce height so login button is visible above keyboard ── */
@media (max-width: 600px) {
  .registration {
    max-width: 92% !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
  }
  .registration--logo {
    padding: 6px 0 2px !important;
  }
  .registration--logo a {
    height: 45px !important;
  }
  .registration--logo::after {
    font-size: 11px;
    margin-top: 2px;
    line-height: 1.2;
  }
  .registration input[type="text"],
  .registration input[type="password"],
  .registration input[type="email"] {
    padding: 7px 10px !important;
    margin-bottom: 4px !important;
    font-size: 16px !important;
  }
  .registration select {
    font-size: 16px !important;
  }
  .registration label {
    margin-bottom: 1px !important;
  }
  .registration .kobo-button--blue {
    padding: 9px !important;
    margin-top: 4px !important;
  }
  .registration .ra-remember-me {
    margin: 4px 0 0 !important;
  }
  .ra-auth-footer {
    margin-top: 8px !important;
    padding-top: 8px !important;
  }
}

/* Auth footer navigation buttons — matches .kobo-button.kobo-button--blue.kobo-button--fullwidth */
.ra-auth-footer a.ra-auth-btn {
  display: block;
  width: 100%;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  text-decoration: none;
  text-align: center;
  border-radius: 6px;
  border: none;
  color: #fff !important;
  background-color: var(--ra-primary) !important;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.25);
  min-height: 40px;
  line-height: 40px;
  padding: 0 16px;
  margin-bottom: 8px;
  transition: background-color 0.2s, box-shadow 0.2s;
}

.ra-auth-footer a.ra-auth-btn:hover {
  background-color: var(--ra-primary-dark) !important;
  box-shadow: 0 3px 8px 0 rgba(0, 0, 0, 0.3);
}

.ra-auth-footer a.ra-auth-btn:active {
  background-color: #2e78a8 !important;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
}

/* Login page links - Create account, Forgot password */
.registration a {
  color: var(--ra-primary-dark) !important;
}

.registration a:hover {
  color: var(--ra-primary) !important;
}

/* Force white text on auth footer buttons (override .registration a color) */
.registration .ra-auth-footer a.ra-auth-btn,
.registration .ra-auth-footer a.ra-auth-btn:hover,
.registration .ra-auth-footer a.ra-auth-btn:active {
  color: #fff !important;
}

/* All text inside the login form card */
.registration p,
.registration span,
.registration div {
  color: #2c3e50 !important;
}


/* ==========================================================================
   SIDEBAR / NAVIGATION
   ========================================================================== */

.form-sidebar {
  background-color: var(--ra-sidebar-bg) !important;
}

/* Active sidebar item */
.form-sidebar__item--active,
.form-sidebar__item:hover {
  border-left-color: var(--ra-primary) !important;
}

/* Left nav icons active state */
.k-header-icons__icon--active {
  border-bottom-color: var(--ra-primary) !important;
}

/* ==========================================================================
   LINKS & ACCENTS
   ========================================================================== */

/* Project name links */
.asset-row__cell--name a {
  color: var(--ra-primary-dark) !important;
}

.asset-row__cell--name a:hover {
  color: var(--ra-primary) !important;
}

/* Status badges */
.badge--deployed {
  background-color: var(--ra-primary) !important;
}

/* ==========================================================================
   PAGE TITLE
   ========================================================================== */

/* Override the browser tab title via CSS (works for login page) */
/* The actual title is set via Django admin - this is a visual-only override */

/* ==========================================================================
   FORM BUILDER
   ========================================================================== */

/* Question type selector active state */
.form-builder__row--selected {
  border-left-color: var(--ra-primary) !important;
}

/* Toggle switches */
.checkbox__input:checked + .checkbox__label::before {
  background-color: var(--ra-primary) !important;
  border-color: var(--ra-primary) !important;
}

/* ==========================================================================
   SCROLLBAR (subtle branding)
   ========================================================================== */

::-webkit-scrollbar-thumb {
  background-color: var(--ra-primary-light) !important;
  border-radius: 4px !important;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--ra-primary) !important;
}

/* ==========================================================================
   Hide service usage / plan errors (not applicable to self-hosted)
   ========================================================================== */
.usage-modal,
[data-tip="Usage"],
.account-settings__usage,
.form-view__cell--service-usage,
.service-usage-banner,
.usage-error,
[class*="service-usage"],
[class*="ServiceUsage"],
.banner--error[data-cy="usage"] {
  display: none !important;
}

/* ==========================================================================
   Hide help/support icon (bottom of page)
   ========================================================================== */
.intercom-lightweight-app,
.intercom-lightweight-app-launcher,
[class*="intercom"],
[class*="help-bubble"],
[class*="support-widget"],
[data-tip="Help"],
.help-bubble,
.kobo-help-icon,
a[href*="support.kobotoolbox.org"],
iframe[title*="Intercom"],
.main-header__help,
[class*="helpBubble"] {
  display: none !important;
}

/* ==========================================================================
   Custom Access Denied / 404 Page
   ========================================================================== */
/*
 * Hide the default KoboToolbox access-denied styling IMMEDIATELY via CSS
 * (CSS loads before JS, so no flash of unstyled content)
 * Our JS then repositions and resyles it with the RA branding
 */

/* Hide default access-denied content until JS resyles it */
.access-denied:not([data-ra-custom]) {
  visibility: hidden !important;
}

/* When access-denied is active, hide ALL UI except the top header bar and the overlay */
body.ra-access-denied-active nav { display: none !important; }
body.ra-access-denied-active .k-drawer { display: none !important; }
body.ra-access-denied-active [class*="drawer"] { display: none !important; }
body.ra-access-denied-active [class*="form-view"] { display: none !important; }
body.ra-access-denied-active [class*="toptabs"] { display: none !important; }
body.ra-access-denied-active [class*="sidebar"] { display: none !important; }
body.ra-access-denied-active [class*="page-title"] { display: none !important; }
body.ra-access-denied-active #ra-welcome-panel { display: none !important; }
body.ra-access-denied-active #ra-leaderboard-page { display: none !important; }
body.ra-access-denied-active #ra-map-page { display: none !important; }
body.ra-access-denied-active #ra-settings-page { display: none !important; }
body.ra-access-denied-active #kpi-app > div > div:not(:first-child) { display: none !important; }

/* Once JS has customized it, make it visible again */
.access-denied[data-ra-custom] {
  visibility: visible !important;
}

.access-denied {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 70vh !important;
  text-align: center !important;
  padding: 40px 20px !important;
  background: #fff !important;
}

.access-denied::before {
  content: '' !important;
  display: block !important;
  width: 160px !important;
  height: 60px !important;
  background: url('/custom-static/images/ra-logo-dark.png') no-repeat center !important;
  background-size: contain !important;
  margin-bottom: 32px !important;
}

.access-denied .access-denied__lock {
  font-size: 48px !important;
  color: #54a8dc !important;
  margin-bottom: 12px !important;
}

.access-denied .access-denied__title {
  font-size: 28px !important;
  font-weight: 700 !important;
  color: #1e293b !important;
  margin: 0 0 16px !important;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
}

.access-denied .access-denied__body {
  font-size: 15px !important;
  color: #64748b !important;
  max-width: 480px !important;
  line-height: 1.6 !important;
  margin: 0 auto 24px !important;
}

.access-denied .access-denied__body a {
  color: #54a8dc !important;
  text-decoration: none !important;
  font-weight: 600 !important;
}

.access-denied .access-denied__body a:hover {
  text-decoration: underline !important;
}

.access-denied .access-denied__details {
  display: none !important;
}
