/* ============================================================
   Form.io design compatibility layer (v4.14 runtime)
   --------------------------------------------------------------
   IMPORTANT — Scope policy:
   This file MUST NOT change the appearance of plain Form.io forms
   that did NOT explicitly opt into a custom design.
   Therefore EVERY visual rule here is gated by ONE of these markers
   that are only present when the user/admin enabled them:

     1. .formio-html-wrapper-root             — only on forms that have a
                                                custom HTML wrapper applied.
     2. [data-formio-design="custom"] root    — set by FormioBlazor.applyCustomDesign
                                                when a non-empty custom CSS exists.

   The runtime-helper class .formio-runtime-ready is added to ALL Form.io
   forms (so radios/wizard hooks fire), but pure visual rules below are
   intentionally NOT keyed on that class alone.
   ============================================================ */


/* ============================================================
   1) Wrapper-only neutralization
   When a custom HTML wrapper is around the form container, the container's
   own chrome (white bg, border, min-height) hides the wrapper visuals.
   These rules ONLY take effect when the wrapper exists.
   ============================================================ */
.formio-html-wrapper-root {
  display: block;
  width: 100%;
}
.formio-html-wrapper-slot {
  display: block;
  width: 100%;
}
.formio-html-wrapper-slot > [id^="formio-container-"],
.formio-html-wrapper-slot > #publicRenderer,
.formio-html-wrapper-slot > #renderer,
.formio-html-wrapper-slot > #fullPageRenderer,
.formio-html-wrapper-slot > .formio-container-rtl,
.formio-html-wrapper-slot > .formio-container-ltr {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  min-height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
}
.formio-wrapper .formio-html-wrapper-root .aqt-shell,
.formio-html-wrapper-root .aqt-shell {
  min-height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}
.formio-wrapper .formio-html-wrapper-root .aqt-card,
.formio-html-wrapper-root .aqt-card {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 auto !important;
}


/* ============================================================
   2) Custom-design-only safety net & v4 bridge
   These rules apply ONLY to forms that opted into a custom design
   (either through HtmlWrapper or saved CustomCss).
   The marker [data-formio-design="custom"] is added by formio-blazor.js
   `applyCustomDesign` ONLY when CustomCss is non-empty.
   ============================================================ */

/* 2.a Inputs/components must fill their column when a custom design is active. */
[data-formio-design="custom"] .formio-form,
[data-formio-design="custom"] .formio-form .formio-component,
[data-formio-design="custom"] .formio-form .formio-component-form,
[data-formio-design="custom"] .formio-form .formio-wizard,
[data-formio-design="custom"] .formio-form .formio-wizard-page,
[data-formio-design="custom"] .formio-form .wizard-page,
.formio-html-wrapper-root .formio-form,
.formio-html-wrapper-root .formio-form .formio-component,
.formio-html-wrapper-root .formio-form .formio-component-form,
.formio-html-wrapper-root .formio-form .formio-wizard,
.formio-html-wrapper-root .formio-form .formio-wizard-page,
.formio-html-wrapper-root .formio-form .wizard-page {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

[data-formio-design="custom"] .formio-form .formio-wizard-nav-container,
[data-formio-design="custom"] .formio-form .formio-wizard > .pagination,
[data-formio-design="custom"] .formio-form .formio-wizard > nav,
[data-formio-design="custom"] .formio-form .wizard-nav-container,
[data-formio-design="custom"] .formio-form .pagination.wizard-pages,
.formio-html-wrapper-root .formio-form .formio-wizard-nav-container,
.formio-html-wrapper-root .formio-form .formio-wizard > .pagination,
.formio-html-wrapper-root .formio-form .formio-wizard > nav {
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 0 0 12px;
  padding: 8px 12px;
}

[data-formio-design="custom"] .formio-form .formio-wizard-page,
[data-formio-design="custom"] .formio-form .wizard-page,
.formio-html-wrapper-root .formio-form .formio-wizard-page,
.formio-html-wrapper-root .formio-form .wizard-page {
  width: 100%;
  flex: 1 1 100%;
  padding: 16px;
  box-sizing: border-box;
}

[data-formio-design="custom"] .formio-form .form-control,
[data-formio-design="custom"] .formio-form .choices,
[data-formio-design="custom"] .formio-form .choices__inner,
.formio-html-wrapper-root .formio-form .form-control,
.formio-html-wrapper-root .formio-form .choices,
.formio-html-wrapper-root .formio-form .choices__inner {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* 2.b Hide built-in submission banner only inside a custom-design form. */
[data-formio-design="custom"] .formio-form .alert-success.formio-success-message,
.formio-html-wrapper-root .formio-form .alert-success.formio-success-message {
  display: none !important;
}


/* ============================================================
   3) Runtime helper classes injected by JS
   These don't have any visual rules of their own — they only become
   visible because the user CustomCss targets them, OR because a wrapper
   selector is present. Safe for all forms.
   ============================================================ */
.formio-form.formio-runtime-ready .formio-component {
  position: relative;
}

/* Rating "check mark" decoration only appears when the user CSS uses
   .design-radio-component[data-design-profile="..."] selectors
   (which only match after user opted into the design). */
[data-formio-design="custom"] .formio-form .design-radio-component[data-design-profile="rating-faces"] .rating-check-mark,
.formio-html-wrapper-root .formio-form .design-radio-component[data-design-profile="rating-faces"] .rating-check-mark {
  display: none;
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  border-radius: 999px;
  background: #2563eb;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  position: absolute;
  top: 10px;
  inset-inline-start: 10px;
}

[data-formio-design="custom"] .formio-form .design-radio-component[data-design-profile="rating-faces"] .radio-selected .rating-check-mark,
.formio-html-wrapper-root .formio-form .design-radio-component[data-design-profile="rating-faces"] .radio-selected .rating-check-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   4) Module record editor runtime fixes
   Loaded after all Form.io styles so these rules win in the
   dynamic module editor (/m/{key}/new and /m/{key}/{id}/edit).
   ============================================================ */

.module-editor-container .formio-runtime-container,
.module-editor-container .formio-runtime-container .formio-form,
.module-editor-container .formio-runtime-container .formio-form .formio-component {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* Form.io columns can preserve very narrow Bootstrap columns. In the editor,
   make them wrap before labels are squeezed into one or two characters. */
.module-editor-container .formio-runtime-container .formio-form .formio-component-columns .row {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: flex-start !important;
  width: 100% !important;
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.module-editor-container .formio-runtime-container .formio-form .formio-component-columns .row > [class*="col-"],
.module-editor-container .formio-runtime-container .formio-form .formio-component-columns .row > .col {
  flex: 1 1 240px !important;
  width: auto !important;
  min-width: min(240px, 100%) !important;
  max-width: 100% !important;
  float: none !important;
  padding-left: 6px !important;
  padding-right: 6px !important;
  box-sizing: border-box !important;
}

/* Some saved schemas contain Bootstrap rows/columns outside the standard
   Form.io columns component. Keep those responsive in the editor as well. */
.module-editor-container .formio-runtime-container .formio-form .row > [class*="col-"] > .formio-component,
.module-editor-container .formio-runtime-container .formio-form .row > .col > .formio-component {
  min-width: 0 !important;
}

.module-editor-container .formio-runtime-container .formio-form .row:has(> [class*="col-"] > .formio-component),
.module-editor-container .formio-runtime-container .formio-form .row:has(> .col > .formio-component) {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: flex-start !important;
  width: 100% !important;
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.module-editor-container .formio-runtime-container .formio-form .row:has(> [class*="col-"] > .formio-component) > [class*="col-"],
.module-editor-container .formio-runtime-container .formio-form .row:has(> .col > .formio-component) > .col {
  flex: 1 1 240px !important;
  width: auto !important;
  min-width: min(240px, 100%) !important;
  max-width: 100% !important;
  float: none !important;
  padding-left: 6px !important;
  padding-right: 6px !important;
  box-sizing: border-box !important;
}

.module-editor-container .formio-runtime-container .formio-form label,
.module-editor-container .formio-runtime-container .formio-form .control-label,
.module-editor-container .formio-runtime-container .formio-form .col-form-label,
.module-editor-container .formio-runtime-container .formio-form .form-check-label {
  white-space: normal !important;
  word-break: keep-all !important;
  overflow-wrap: normal !important;
  line-height: 1.55 !important;
}

.module-editor-container .formio-runtime-container .formio-form .form-control,
.module-editor-container .formio-runtime-container .formio-form input,
.module-editor-container .formio-runtime-container .formio-form select,
.module-editor-container .formio-runtime-container .formio-form textarea {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* ============================================================
   5) Selectboxes / Radio / Checkbox group — final layout
   The default Form.io v4 markup squeezes each option when the
   container narrows. Force a clean two-line layout per option
   (checkbox + label on the same line) and let multiple options
   wrap into a flexible grid that fits the available width.
   ============================================================ */

.module-editor-container .formio-runtime-container .formio-form .formio-component-selectboxes,
.module-editor-container .formio-runtime-container .formio-form .formio-component-radio,
.module-editor-container .formio-runtime-container .formio-form .formio-component-checkbox {
  width: 100% !important;
  max-width: 100% !important;
  display: block !important;
  box-sizing: border-box !important;
}

.module-editor-container .formio-runtime-container .formio-form .formio-component-selectboxes > .form-radio,
.module-editor-container .formio-runtime-container .formio-form .formio-component-radio   > .form-radio,
.module-editor-container .formio-runtime-container .formio-form .formio-component-checkbox > .form-radio,
.module-editor-container .formio-runtime-container .formio-form .formio-component-selectboxes > .input-group,
.module-editor-container .formio-runtime-container .formio-form .formio-component-radio   > .input-group,
.module-editor-container .formio-runtime-container .formio-form .formio-component-checkbox > .input-group {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center !important;
  gap: 6px 14px !important;
  width: 100% !important;
  max-width: 100% !important;
  padding: 6px 4px !important;
  margin: 0 !important;
  border: 0 !important;
  background: transparent !important;
  box-sizing: border-box !important;
}

.module-editor-container .formio-runtime-container .formio-form .formio-component-selectboxes .form-check,
.module-editor-container .formio-runtime-container .formio-form .formio-component-radio   .form-check,
.module-editor-container .formio-runtime-container .formio-form .formio-component-checkbox .form-check,
.module-editor-container .formio-runtime-container .formio-form .formio-component-selectboxes .checkbox,
.module-editor-container .formio-runtime-container .formio-form .formio-component-radio   .radio,
.module-editor-container .formio-runtime-container .formio-form .formio-component-checkbox .checkbox {
  display: inline-flex !important;
  flex: 0 1 auto !important;
  align-items: center !important;
  gap: 6px !important;
  padding: 6px 8px !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 6px !important;
  background: transparent !important;
  flex-wrap: nowrap !important;
  white-space: nowrap !important;
  width: auto !important;
  max-width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
  line-height: 1.4 !important;
}

.module-editor-container .formio-runtime-container .formio-form .formio-component-selectboxes .form-check-input,
.module-editor-container .formio-runtime-container .formio-form .formio-component-radio   .form-check-input,
.module-editor-container .formio-runtime-container .formio-form .formio-component-checkbox .form-check-input {
  position: static !important;
  width: 18px !important;
  height: 18px !important;
  margin: 0 !important;
  flex: 0 0 18px !important;
  vertical-align: middle !important;
}

.module-editor-container .formio-runtime-container .formio-form .formio-component-selectboxes .form-check-label,
.module-editor-container .formio-runtime-container .formio-form .formio-component-radio   .form-check-label,
.module-editor-container .formio-runtime-container .formio-form .formio-component-checkbox .form-check-label,
.module-editor-container .formio-runtime-container .formio-form .formio-component-selectboxes label.form-check-label,
.module-editor-container .formio-runtime-container .formio-form .formio-component-radio   label.form-check-label,
.module-editor-container .formio-runtime-container .formio-form .formio-component-checkbox label.form-check-label {
  margin: 0 !important;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  white-space: nowrap !important;
  word-break: keep-all !important;
  overflow-wrap: normal !important;
  font-weight: 500 !important;
  cursor: pointer !important;
  line-height: 1.4 !important;
  flex: 0 1 auto !important;
  max-width: none !important;
}

/* When the container is genuinely narrow (e.g. mobile sidebar/preview),
   let each option take a full row so labels stay readable. */
@media (max-width: 480px) {
  .module-editor-container .formio-runtime-container .formio-form .formio-component-selectboxes .form-check,
  .module-editor-container .formio-runtime-container .formio-form .formio-component-radio   .form-check,
  .module-editor-container .formio-runtime-container .formio-form .formio-component-checkbox .form-check {
    flex: 1 1 100% !important;
  }
}
