/**
 * validators.css - Optimized Version
 * Form validation states, radio groups, file uploads, date/time pickers
 */

/* ==================== INLINE ERROR MESSAGES ==================== */

/*span.wrapped {
  display: inline-block;
  width: 100%;
  text-wrap: auto;
  text-align: left;
  padding: 5px;
}*/
/* Let the container shrink so children can wrap in Safari (flex/table quirk). */
.table-info,
.table-info > label,
.table-info .field-label,
.form-control-cell,
.form-group {
  min-width: 0;
}

/* Cross-browser Label wrapping for inline error pills */
.label.wrapped,
span.wrapped {
  display: block;              /* occupy the full line under the label */
  max-width: 100%;
  white-space: normal !important;  /* defeat Bootstrap nowrap */

  /* Cross-browser wrapping for long tokens/URLs on Safari/iOS + others */
  overflow-wrap: anywhere;     /* modern */
  word-wrap: break-word;       /* legacy alias */
  word-break: break-word;      /* WebKit/Safari quirk fallback */
  hyphens: auto;

  text-align: left;
  padding: 5px;
}

/* Increase only inline validation error text under field labels */
.form-group label > .label.label-danger.wrapped,
[id$="_label"] > .label.label-danger.wrapped {
  font-size: 14px;          /* tune as needed */
  line-height: 1.35;
  padding: 0.25em 0.5em;
}

/* Optional: slightly larger on very small screens */
@media (max-width: 480px) {
  .form-group label > .label.label-danger.wrapped,
  [id$="_label"] > .label.label-danger.wrapped {
    font-size: 17px;
  }
}

/* Screen-reader-only helper (if needed) */
.sr-only-validation {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==================== DATE/TIME PICKER ERROR STATES ==================== */

/* Hide bound input (accessibility-friendly method, PP date wrapper) */
.control > input.datetime.form-control {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Paint the visible PP date/time input when invalid */
.form-control-cell .input-group.datetimepicker input.form-control.error,
.form-control-cell .input-group.datetimepicker input.input-text-box.error,
.form-control-cell .input-group.datetimepicker input[aria-invalid="true"] {
  border-color: var(--error-color);
  box-shadow: var(--error-shadow);
}

/* Keep it red while focused */
.form-control-cell .input-group.datetimepicker input.form-control.error:focus,
.form-control-cell .input-group.datetimepicker input.input-text-box.error:focus,
.form-control-cell .input-group.datetimepicker input[aria-invalid="true"]:focus {
  border-color: var(--error-color);
  box-shadow: var(--error-shadow);
  outline: none;
}

/* Wrapper error classes (cell-level) */
.form-control-cell.error .input-group.datetimepicker input.form-control,
.form-control-cell.has-error .input-group.datetimepicker input.form-control,
.form-control-cell.error .input-group.datetimepicker input.input-text-box,
.form-control-cell.has-error .input-group.datetimepicker input.input-text-box {
  border-color: var(--error-color);
  box-shadow: var(--error-shadow);
}

/* ==================== FILE UPLOAD CONTROLS ==================== */

/* File name as clickable link (accessibility wants #101010 base colour) */
.file-name--clickable {
  cursor: pointer;
  text-decoration: underline;
  color: #101010;
}

/* Error text under file controls */
.file-upload-error {
  color: var(--error-color);
  font-weight: bold;
}

/* Touch-friendly file buttons */
@media (pointer: coarse) {
  .file-control-container button,
  .container-file-input button {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ==================== WET-PATCHED RADIO GROUPS ==================== */

/* Fieldset & Legend */
.wet-patched-radio fieldset.wet-radio-fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  text-align: left;              /* defeat any right-align at mobile */
}

.wet-patched-radio fieldset.wet-radio-fieldset > legend {
  font-size: 16px;
  color: var(--text-dark);
  font-weight: 700;
  line-height: 1.4;
  margin: 0 0 0.25rem 0;
  padding: 0;
}

/* Ensure child elements inherit legend styling */
.wet-patched-radio legend .field-label,
.wet-patched-radio legend .field-name {
  font: inherit;
  color: inherit;
  font-weight: inherit;
}

/* Inline layout: "○ No  ○ Yes" (left-aligned, touch-friendly) */
.wet-patched-radio label.radio-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
  margin-right: 1.25rem;         /* gap between “No” and “Yes” */
  padding: 0 !important;         /* cancel Bootstrap/WET left padding */
  width: auto !important;        /* avoid 100% width on small screens */
  float: none !important;        /* defeat any inherited floats */
  max-width: none;
}

.wet-patched-radio label.radio-inline input[type="radio"] {
  position: static;              /* cancel legacy absolute positioning */
  margin: 0 0.45rem 0 0;
  vertical-align: middle;
}

/* Touch-friendly radio padding */
@media (pointer: coarse) {
  .wet-patched-radio label.radio-inline {
    padding: 0.45rem 0.6rem;
  }
}

@media (max-width: 480px) {
  .wet-patched-radio label.radio-inline { white-space: normal; }
}

/* ==================== ERROR STATES (FIELDS & CONTAINERS) ==================== */

/* Standard form control error look */
.form-control.error,
input.error,
select.error,
textarea.error {
  border-color: var(--error-color);
  box-shadow: var(--error-shadow);
  outline: none;
}

/* Container-level error state */
.has-error .form-control,
.has-error .form-control:focus {
  border-color: var(--error-color);
  box-shadow: var(--error-shadow);
}

/* Visible validator text */
.validators span[id^="RequiredFieldValidator"],
.validators span[id^="DateFormatValidator"] {
  color: var(--error-color);
  font-weight: bold;
}

/* Remove default “*” markers coming from CRM form */
.crmEntityFormView .control .validators span[style*="color:Red"],
.crmEntityFormView span[id^="RequiredFieldValidator"],
.crmEntityFormView span[id^="DateFormatValidator"],
.crmEntityFormView abbr[title="(required)"],
.crmEntityFormView .validators span {
  content: none !important;
  display: none !important;
}

/* Compact validators spacing on read-only summary */
body.read-only-summary .crmEntityFormView .table-info .validators {
  margin: 0 !important;
  padding: 0 !important;
}

/* ==================== ACCESSIBLE FOCUS VISUALS ==================== */
/* 1) Validation summary (WET/GCWeb-style links & focus) */

/* Summary container – keep native GCWeb/WET link states and align scroll position */
#ValidationSummaryEntityFormView {
  scroll-margin-top: 90px;
}

/* Match GCWeb/WET link behaviour: hover = colour change only; focus = colour + ring */
#ValidationSummaryEntityFormView ul li a {
  color: var(--bs-link-color, #295376);
  text-decoration: underline;
}

#ValidationSummaryEntityFormView ul li a:hover,
#ValidationSummaryEntityFormView ul li a:active {
  color: var(--bs-link-hover-color, #0535d2);
  outline: none;
  box-shadow: none;
}

#ValidationSummaryEntityFormView ul li a:focus-visible {
  color: var(--bs-link-hover-color, #0535d2);
  outline: 3px solid var(--pp-focus-border);
  outline-offset: 2px;
  box-shadow: none;
}


/* 2) Radio groups: show focus on the option AND around the group */

/* Design tokens for focus rings (built on theme --bs-primary / --focus-color) */
:root{
  /* Fallbacks: GCWeb blue (#1a5a96) if --bs-primary* aren’t defined */
  --pp-focus-border: var(--bs-primary, #1a5a96);
  --pp-focus-ring: rgba(var(--bs-primary-rgb, 26,90,150), .35);
  --pp-focus-radius: .375rem;   /* ~ Bootstrap 5 form-control radius */
  --pp-focus-ring-w: .25rem;    /* ~ 4px ring thickness */
}

/* 2) Radio groups: show focus on the option AND around the group */
.wet-patched-radio fieldset.wet-radio-fieldset:focus-within {
  outline: 3px solid var(--pp-focus-border);
  outline-offset: 4px;
  border-radius: 4px;
  /* small padding so the outline doesn't hug the content */
  padding: .15rem;
}

/* highlight the exact option the keyboard is on */
.wet-patched-radio label.radio-inline:has(input[type="radio"]:focus-visible),
.wet-patched-radio label.radio-inline:focus-within {
  outline: 3px solid var(--pp-focus-border);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ensure the control itself shows a ring in browsers that only outline the input */
.wet-patched-radio input[type="radio"]:focus,
.wet-patched-radio input[type="radio"]:focus-visible {
  outline: 2px solid var(--pp-focus-border);
  outline-offset: 2px;
}

/* === Unified focus style for radios (matches input focus) === */
/* Use the label as the visual target so the ring is large & consistent */

/* Radio directly followed by its label (your markup pattern) */
.boolean-radio input[type="radio"]:focus-visible + label,
.form-check-input[type="radio"]:focus-visible + label {
  outline: 2px solid var(--pp-focus-border);
  outline-offset: 2px;
  border-radius: var(--pp-focus-radius);
  box-shadow: 0 0 0 var(--pp-focus-ring-w) var(--pp-focus-ring);
}

/* Optional: also show a subtle ring on the radio dot itself */
.boolean-radio input[type="radio"]:focus-visible,
.form-check-input[type="radio"]:focus-visible {
  outline: none; /* rely on the label ring */
  box-shadow: 0 0 0 var(--pp-focus-ring-w) var(--pp-focus-ring);
  border-color: var(--pp-focus-border);
}

/* Radio groups: if your group container gets :focus-within, make it match too */
.boolean-radio:focus-within {
  outline: 2px solid var(--pp-focus-border);
  outline-offset: 4px;
  border-radius: var(--pp-focus-radius);
  box-shadow: 0 0 0 var(--pp-focus-ring-w) var(--pp-focus-ring);
}

/* High-contrast user settings: let the OS draw its own indicator */
@media (forced-colors: active) {
  .wet-patched-radio input[type="radio"]:focus,
  .wet-patched-radio input[type="radio"]:focus-visible,
  .boolean-radio input[type="radio"]:focus,
  .boolean-radio input[type="radio"]:focus-visible {
    accent-color: ButtonText;   /* defer to system palette */
  }
}

/* === Radios: focus only the circle (no group or label rings) === */

/* 1) Kill group/label outlines from earlier rules (patched & legacy groups) */
.wet-patched-radio fieldset.wet-radio-fieldset:focus-within,
.wet-patched-radio label.radio-inline:has(input[type="radio"]:focus-visible),
.wet-patched-radio label.radio-inline:focus-within,
.boolean-radio:focus-within {
  outline: none !important;
  box-shadow: none !important;
  /* if you had padding added for outline spacing earlier, reset it */
  padding: 0 !important;
}

/* 2) Remove any outer outline/shadow from the radio control itself */
.wet-patched-radio input[type="radio"]:focus,
.wet-patched-radio input[type="radio"]:focus-visible,
.boolean-radio input[type="radio"]:focus,
.boolean-radio input[type="radio"]:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

/* 3) Show “blue” only on the radio circle */
:root {
  --pp-radio-focus: var(--focus-color, #1a5a96); /* GCWeb blue fallback */
}

/* Use accent-color on focus so only the native dot/border is blue */
.wet-patched-radio input[type="radio"]:focus-visible,
.boolean-radio input[type="radio"]:focus-visible {
  /* Supported in all modern browsers, incl. Safari 15.4+ / iOS 15.4+ */
  accent-color: var(--pp-radio-focus);
}

/* (Optional) For browsers that ignore :focus-visible, also tint on :focus */
@supports selector(:focus-visible) {
  /* nothing extra */
}
@supports not selector(:focus-visible) {
  .wet-patched-radio input[type="radio"]:focus,
  .boolean-radio input[type="radio"]:focus {
    accent-color: var(--pp-radio-focus);
  }
}

/* High-contrast user settings for radios: let the OS draw its own indicator */
@media (forced-colors: active) {
  .wet-patched-radio input[type="radio"],
  .boolean-radio input[type="radio"] {
    accent-color: ButtonText;   /* defer to system palette */
  }
}

/* =======================
   Read-only (review) radios: greyed UI + keep tabbable
   ======================= */

/* Page flag you set from JS on review pages */
body.read-only-summary {
  /* choose accessible greys; keep >=4.5:1 contrast on white */
  --pp-disabled-fg: #6c757d;           /* label text (≈Bootstrap secondary) */
  --pp-radio-disabled: #adb5bd;        /* radio circle (≈Bootstrap gray-500) */
  --pp-radio-focus: #1a5a96;           /* GCWeb blue for focus circle */
}

/* Dim the labels and any inline text */
body.read-only-summary .boolean-radio.readonly label,
body.read-only-summary .wet-patched-radio label {
  color: var(--pp-disabled-fg);
  cursor: default;
}

/* Default circle tint = grey (read-only) */
body.read-only-summary .boolean-radio.readonly input[type="radio"],
body.read-only-summary .wet-patched-radio input[type="radio"] {
  accent-color: var(--pp-radio-disabled);
  /* avoid killing focusability */
  pointer-events: auto;
}

/* Show blue only on the circle when keyboard focus is on the selected radio */
body.read-only-summary .boolean-radio.readonly input[type="radio"]:focus-visible,
body.read-only-summary .wet-patched-radio input[type="radio"]:focus-visible {
  accent-color: var(--pp-radio-focus);
  outline: none !important;
  box-shadow: none !important; /* no big group/label ring */
}

/* Remove any group/label focus frames in read-only mode */
body.read-only-summary .boolean-radio:focus-within,
body.read-only-summary .wet-patched-radio fieldset.wet-radio-fieldset:focus-within,
body.read-only-summary .wet-patched-radio label.radio-inline:focus-within {
  outline: none !important;
  box-shadow: none !important;
  padding: 0 !important;
}

/* High-contrast users: let the OS draw its own indicator */
@media (forced-colors: active) {
  body.read-only-summary .boolean-radio.readonly input[type="radio"],
  body.read-only-summary .wet-patched-radio input[type="radio"] {
    accent-color: ButtonText;
  }
}