/*
 * Resilience Academy - Enketo Form Branding
 * ==========================================
 * Injected via nginx sub_filter. Provides:
 *   - Banner with dark overlay and white title
 *   - RA-colored buttons
 *   - Thank you overlay after submission
 *   - Form styling overrides
 *
 * UPDATE-PROOF: Loaded via nginx sub_filter injection.
 */

:root {
  --ra-primary: #54a8dc;
  --ra-primary-dark: #3d8abf;
  --ra-secondary: #2c3e50;
  --ra-header-bg: #1a2a3a;
}

/* ==========================================================================
   BANNER
   ========================================================================== */

.ra-form-banner {
  position: relative;
  width: 100%;
  min-height: 200px;
  background-image: url('/custom-static/images/default-banner.jpg');
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  display: flex;
  align-items: flex-end;
  margin-bottom: 0;
  box-sizing: border-box;
  border-radius: 0;
  overflow: hidden;
}

.ra-form-banner::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    to bottom,
    rgba(26, 42, 58, 0.3) 0%,
    rgba(26, 42, 58, 0.8) 100%
  );
  z-index: 1;
}

.ra-form-banner__title {
  position: relative;
  z-index: 2;
  color: #ffffff;
  font-size: 24px;
  font-weight: 700;
  padding: 20px 30px;
  margin: 0;
  width: 100%;
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* Fix multilingual labels — hide non-active language spans at ANY depth */
.or .question-label span[lang]:not(.active),
.or .or-hint span[lang]:not(.active),
.or-group > h4 span[lang]:not(.active),
.or-group-data > h4 span[lang]:not(.active),
.or .option-label span[lang]:not(.active),
.or .or-form-short span[lang]:not(.active),
.or .or-form-long span[lang]:not(.active),
.or .or-repeat-info span[lang]:not(.active),
.or .or-constraint-msg span[lang]:not(.active),
.or .or-required-msg span[lang]:not(.active) {
  display: none !important;
}

/* Ensure validation messages themselves are visible */
.or .or-required-msg.active,
.or .or-constraint-msg.active,
.or .or-relevant-msg.active,
.or .invalid-value-msg.active,
.or .custom-error-msg.active {
  display: block !important;
}

/* Override "none selected" placeholder to "Select..." */
.or .btn-group .selected[data-i18n="selectpicker.noneselected"] {
  font-size: 0 !important;
}
.or .btn-group .selected[data-i18n="selectpicker.noneselected"]::after {
  content: "Select..." !important;
  font-size: 15px !important;
  color: #999 !important;
}

/* Question containers must never be hidden by lang rules */
.or .question[lang] {
  display: block !important;
}

/* No gap between header and banner */

/* Hide original form title when banner is present */
.ra-has-banner #form-title {
  display: none !important;
}

/* ==========================================================================
   BUTTONS (RA Colors)
   ========================================================================== */

.btn-primary,
.enketo-plugin .btn-primary,
.form-footer .btn-primary {
  background-color: var(--ra-primary) !important;
  border-color: var(--ra-primary) !important;
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  background-color: var(--ra-primary-dark) !important;
  border-color: var(--ra-primary-dark) !important;
}

.form-footer .next-page,
.form-footer .last-page {
  background-color: var(--ra-primary) !important;
  border-color: var(--ra-primary) !important;
  color: #fff !important;
}

.form-footer .next-page:hover,
.form-footer .last-page:hover {
  background-color: var(--ra-primary-dark) !important;
  border-color: var(--ra-primary-dark) !important;
}

.form-footer .previous-page,
.form-footer .first-page {
  border-color: var(--ra-primary) !important;
  color: var(--ra-primary) !important;
}

.form-footer .previous-page:hover,
.form-footer .first-page:hover {
  background-color: rgba(84, 168, 220, 0.1) !important;
}

/* Repeat group add button */
.or-repeat-info .btn,
.btn-default.add-repeat-btn {
  border-color: var(--ra-primary) !important;
  color: var(--ra-primary) !important;
}

.or-repeat-info .btn:hover,
.btn-default.add-repeat-btn:hover {
  background-color: rgba(84, 168, 220, 0.1) !important;
}

/* Progress bar */
.progress-bar {
  background-color: var(--ra-primary) !important;
}

/* ==========================================================================
   FORM FIELDS — clear visual definition
   ========================================================================== */

/* All input fields — visible border and background */
.or input[type="text"],
.or input[type="number"],
.or input[type="tel"],
.or input[type="email"],
.or input[type="url"],
.or input[type="date"],
.or input[type="time"],
.or input[type="datetime-local"],
.or textarea,
.or select {
  border: 1px solid #ccc !important;
  border-radius: 4px !important;
  padding: 10px 12px !important;
  background-color: #fafbfc !important;
  font-size: 16px !important;
  color: #333333 !important;
  -webkit-text-fill-color: #333333 !important;
  opacity: 1 !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  height: auto !important;
  min-height: 44px !important;
  line-height: 1.4 !important;
  transition: border-color 0.2s, box-shadow 0.2s !important;
}

/* Focus state — blue highlight */
.or input[type="text"]:focus,
.or input[type="number"]:focus,
.or input[type="tel"]:focus,
.or input[type="email"]:focus,
.or textarea:focus,
.or select:focus {
  border-color: var(--ra-primary) !important;
  box-shadow: 0 0 0 3px rgba(84, 168, 220, 0.2) !important;
  background-color: #ffffff !important;
  outline: none !important;
}

/* Question labels — clear and bold */
.or .question-label {
  font-weight: 600 !important;
  color: #2c3e50 !important;
  margin-bottom: 6px !important;
}

/* Hint text — breathing space (only active language) */
.or .or-hint.active {
  margin-top: 4px !important;
  margin-bottom: 10px !important;
  padding: 4px 0 !important;
  font-size: 13px !important;
  color: #6c757d !important;
  line-height: 1.5 !important;
}

/* Each question block — card-like separation */
.or .question {
  padding: 12px 0 !important;
  margin-bottom: 4px !important;
  border-bottom: 1px solid #f0f0f0 !important;
}

.or .question:last-child {
  border-bottom: none !important;
}

/* Required asterisk — red and visible */
.or .required {
  color: #e74c3c !important;
  font-size: 16px !important;
  margin-left: 3px !important;
}

/* Remove default black left border on all questions */
.or .question {
  border-left: none !important;
}

/* Active question highlight — subtle background only */
.question.focus,
.question:focus-within {
  border-left: none !important;
  background-color: rgba(84, 168, 220, 0.03) !important;
}

/* Dropdown (bootstrap-select) — styled to match */
.or .btn-group .btn-default {
  border: 1px solid #ccc !important;
  border-radius: 4px !important;
  padding: 10px 12px !important;
  background-color: #fafbfc !important;
}

/* File upload — clear boundary */
.or .file-picker .fake-file-input {
  border: 1px dashed #ccc !important;
  border-radius: 4px !important;
  padding: 10px 12px !important;
  background-color: #fafbfc !important;
}

/* Group sections — subtle card effect */
.or .or-group {
  background-color: #ffffff !important;
  border-radius: 6px !important;
  padding: 16px !important;
  margin-bottom: 12px !important;
  border: 1px solid #e8ecf0 !important;
}

/* Mobile/iOS fix — ensure text visible in fields */
@media (max-width: 768px) {
  .or input[type="text"],
  .or input[type="number"],
  .or input[type="tel"],
  .or input[type="email"],
  .or input[type="url"],
  .or input[type="date"],
  .or input[type="time"],
  .or textarea,
  .or select {
    font-size: 16px !important;
    padding: 8px 10px !important;
    height: auto !important;
    min-height: 44px !important;
    line-height: 1.5 !important;
    color: #333333 !important;
    -webkit-text-fill-color: #333333 !important;
    opacity: 1 !important;
    -webkit-appearance: none !important;
    background-color: #ffffff !important;
    box-sizing: border-box !important;
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    clip: auto !important;
    overflow: visible !important;
    text-indent: 0 !important;
  }

  /* Dropdown selected text visible */
  .or .btn-group .btn-default {
    padding: 8px 10px !important;
    height: auto !important;
    min-height: 44px !important;
    line-height: 1.5 !important;
    color: #333333 !important;
    -webkit-text-fill-color: #333333 !important;
  }

  .or .btn-group .btn-default .selected {
    color: #333333 !important;
    -webkit-text-fill-color: #333333 !important;
  }

  /* Disabled fields still visible */
  .or input:disabled,
  .or textarea:disabled,
  .or select:disabled {
    color: #666666 !important;
    -webkit-text-fill-color: #666666 !important;
    opacity: 1 !important;
  }
}

/* Mobile form width — use 98% on phones */
@media (max-width: 768px) {
  .or.theme-grid,
  form.or {
    width: 98% !important;
    max-width: 98% !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  article.paper {
    padding-left: 4px !important;
    padding-right: 4px !important;
  }

  .or .or-group {
    padding: 10px 8px !important;
  }

  .form-footer .form-footer__content {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
}

/* Radio/checkbox selected */
input[type="radio"]:checked + label::before,
input[type="checkbox"]:checked + label::before {
  border-color: var(--ra-primary) !important;
}

input[type="radio"]:checked + label::after {
  background-color: var(--ra-primary) !important;
}

input[type="checkbox"]:checked + label::after {
  color: var(--ra-primary) !important;
}

/* ==========================================================================
   THANK YOU OVERLAY
   ========================================================================== */

.ra-thankyou-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #ffffff;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  animation: ra-fadeIn 0.5s ease;
}

@keyframes ra-fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.ra-thankyou__content {
  max-width: 500px;
  padding: 40px 30px;
}

.ra-thankyou__logo {
  max-width: 220px;
  height: auto;
  margin-bottom: 30px;
}

.ra-thankyou__partner-logo {
  max-width: 160px;
  height: auto;
  margin: 10px 15px;
}

.ra-thankyou__title {
  font-size: 32px;
  font-weight: 700;
  color: var(--ra-secondary);
  margin: 0 0 15px;
}

.ra-thankyou__message {
  font-size: 16px;
  color: #6c757d;
  margin: 0 0 30px;
  line-height: 1.6;
}

.ra-thankyou__logos {
  margin: 20px 0 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 15px;
}

.ra-thankyou__btn {
  display: inline-block;
  padding: 12px 30px;
  background-color: var(--ra-primary);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  margin: 5px;
  transition: background-color 0.2s;
}

.ra-thankyou__btn:hover {
  background-color: var(--ra-primary-dark);
  color: #ffffff;
  text-decoration: none;
}

.ra-thankyou__btn--secondary {
  background-color: transparent;
  color: var(--ra-primary);
  border: 2px solid var(--ra-primary);
}

.ra-thankyou__btn--secondary:hover {
  background-color: rgba(84, 168, 220, 0.1);
  color: var(--ra-primary);
}

/* ==========================================================================
   FORM HEADER REFINEMENTS
   ========================================================================== */

.form-header {
  background-color: var(--ra-primary) !important;
  border-bottom: 3px solid var(--ra-primary-dark) !important;
  padding: 7px 10px !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}

/* Mobile header — fix overflow caused by negative margins */
@media (max-width: 768px) {
  .form-header {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    padding: 5px 8px !important;
  }

  .form-header .form-language-selector span[data-i18n="form.chooseLanguage"] {
    display: none !important;
  }

  .form-header .form-language-selector {
    flex: 1 1 auto !important;
  }

  .form-header .form-language-selector select {
    width: 100% !important;
    max-width: none !important;
    font-size: 13px !important;
    padding: 4px 6px !important;
  }

  .form-header__branding img,
  .form-header__branding .logo-wrapper img {
    max-width: 90px !important;
    height: auto !important;
  }
}

/* Header text — all white */
.form-header,
.form-header *,
.form-header .form-language-selector,
.form-header .form-language-selector span,
.form-header button,
.form-header a {
  color: #ffffff !important;
}

/* Language dropdown — white border, readable on blue background */
.form-header .form-language-selector select,
.form-header select {
  border: 1px solid #ffffff !important;
  color: #ffffff !important;
  background-color: rgba(255, 255, 255, 0.15) !important;
  border-radius: 4px !important;
  padding: 6px 10px !important;
}

.form-header .form-language-selector select option {
  color: #333 !important;
  background-color: #ffffff !important;
}

/* Print icon white */
.form-header .form-header__button--print {
  color: #ffffff !important;
}

/* ==========================================================================
   GROUP HEADINGS — black text and arrows
   ========================================================================== */

.or-group > h4,
.or-group > h4 span,
.or-group > h4 .question-label {
  color: #000000 !important;
}

/* Group collapse/expand — clear chevron icons */
.or-group > h4 {
  cursor: pointer !important;
  padding-left: 28px !important;
  position: relative !important;
}

.or-group > h4::before {
  content: '\25BC' !important;
  position: absolute !important;
  left: 5px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  font-size: 14px !important;
  color: var(--ra-primary) !important;
  transition: transform 0.2s !important;
  border: none !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
}

.or-group.collapsed > h4::before {
  content: '\25B6' !important;
  color: var(--ra-primary) !important;
}

/* Hide group content when collapsed */
.or-group.collapsed > *:not(h4) {
  display: none !important;
}

.or-group.collapsed {
  padding-bottom: 0 !important;
  min-height: auto !important;
}

/* Modal headers */
.modal-header {
  background-color: var(--ra-primary) !important;
  color: #fff !important;
}

/* Page navigation dots */
.pages .page-toc__item--active {
  background-color: var(--ra-primary) !important;
}

.pages .page-toc__item {
  border-color: var(--ra-primary) !important;
}
