/**
 * validators.css
 * Form validation states, radio groups, file uploads, native date inputs
 *
 * Cleaning goals:
 *  - Remove duplicate/conflicting blocks (especially Validation Summary link focus rules).
 *  - Preserve accessibility fixes (wrapping, error states, SR-only helpers, focus handling).
 */
/* Akram 20260114 21:15 */
/* PATCHED: 2026-01-16 - Added missing CSS variable definitions, accessibility improvements */
/* PATCHED: 2026-01-21 - CONFLICT RESOLUTION:
   - Removed duplicate error state rules (.form-control.error, etc.) - now in custom.css with !important
   - Kept date input placeholder hiding rules (hover/focus behavior)
   - All CSS variables properly inherit from WET4/GCWEB --focus-color
*/
/* CLEANED: 2026-01-21 - DATETIMEPICKER CLEANUP:
   - Removed Power Pages datetimepicker bound input hiding (11 lines)
   - Removed Power Pages datetimepicker error states (24 lines)
   - Total: ~35 lines of unused Power Pages code removed
   - Renamed section to "NATIVE DATE INPUT STYLING" for clarity
   - Only native input[type="date"] browser controls are supported
*/
/* PATCHED: 2026-01-16 - Added missing CSS variable definitions, accessibility improvements */
html {
  scroll-behavior: smooth;
}
/* ==================== TOKENS ==================== */
:root{
  /* GCWeb defaults (fallbacks used if your theme variables are missing) */
  --pp-link-default: #295376;
  --pp-link-hover:   #0535d2;
  --pp-focus-ring:   var(--focus-color, #1a5a96); /* GCWeb blue fallback */
  --pp-radio-focus:  var(--focus-color, #1a5a96);

  /* PATCHED: Error state variables (were missing, causing broken error styling) */
  --error-color: #d3080c;           /* WCAG AA compliant red (5.9:1 on white) */
  --error-shadow: 0 0 0 2px rgba(211, 8, 12, 0.25);
  --text-dark: #333333;             /* For legend text */
}

/* ==================== INLINE ERROR MESSAGES ==================== */

/* 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;
  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;
}

/* PATCHED: UniversalAnnounce live region (from validations.js)
   Must be visually hidden but NOT display:none or visibility:hidden
   to ensure screen readers can announce content changes */
#pp-universal-announce {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  /* Ensure it's never visible but always in the accessibility tree */
  opacity: 1 !important;
  pointer-events: none;
}

/* ==================== NATIVE DATE INPUT STYLING ==================== */

/* Keep calendar icon visible */
input[type="date"]::-webkit-calendar-picker-indicator {
  opacity: 1 !important;
  cursor: pointer;
}

/* ==================== FILE UPLOAD CONTROLS ==================== */
/* NOTE: File-upload *layout/reflow* is handled in custom.css.
   This file only keeps semantic visuals (clickable filename, error text, touch targets). */

.file-name--clickable {
  cursor: pointer;
  text-decoration: underline;
  color: #101010;            /* accessibility wants #101010 base colour */
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* 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) ==================== */

/* NOTE: Standard form control error styles (.form-control.error, input.error, etc.) 
   are defined in custom.css with !important flags for better specificity */

/* 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 links (WET/GCWeb exact ring; no box-shadows) */

/* FIX 2026-02-09: Visual styling for validation summary.
   We cannot use .alert .alert-danger on the container because GCWeb's alert
   class triggers implicit aria-live behavior causing NVDA double announcements.
   These styles replicate the exact GCWeb alert-danger appearance WITHOUT the class. */
/* PATCHED 2026-02-10: Icon-on-border effect (GCWeb native pattern) + transparent bg */
#ValidationSummaryEntityFormView {
  scroll-margin-top: 90px;
  border-left: 6px solid var(--error-color, #d3080c);
  padding: 15px 15px 15px 45px;
  margin-bottom: 20px;
  background-color: transparent;
  position: relative;
}

/* Exclamation icon - exact GCWeb .alert-danger ::before pattern.
   White disc sits centered on the red left border at the top. */
#ValidationSummaryEntityFormView::before {
  content: "\e101";
  font-family: 'Glyphicons Halflings';
  font-size: 1.4em;
  color: var(--error-color, #d3080c);
  position: absolute;
  top: 26px !important;
  left: -2px;
  transform: translateX(-50%);
  background: #fff;
  border-radius: 50%;
  padding: 2px;
  line-height: 1;
}

/* FIX 2026-02-09: Consistent validation summary heading size across all forms.
   GCWeb h2 and .alert h2 inherit different base sizes depending on the multi-step
   form context (GI Report renders 26px, SSI Request renders ~32px). This explicit
   rule locks the heading to 26px (the GI/WET4 reference size) on all pages. */
#ValidationSummaryEntityFormView h2#errors-summary,
#ValidationSummaryEntityFormView > h2.validation-header {
  font-size: 24px !important;
}

/* FIX 2026-02-09: Restore list bullets (stripped when alert class removed) */
#ValidationSummaryEntityFormView > ul,
#ValidationSummaryEntityFormView #errors-summary-section > ul {
  list-style: disc;
  padding-left: 1.25em;
}

#ValidationSummaryEntityFormView ul li a {
  color: var(--pp-link-default) !important;
  text-decoration: underline !important;
  font-size: 16px;
}

#ValidationSummaryEntityFormView ul li a:hover,
#ValidationSummaryEntityFormView ul li a:active {
  color: var(--pp-link-hover, #0535d2) !important;
  text-decoration: underline !important;
  cursor: pointer;
  outline: none;
  box-shadow: none;
}

#ValidationSummaryEntityFormView ul li a:focus,
#ValidationSummaryEntityFormView ul li a:focus-visible {
  color: var(--pp-link-hover);
  outline: 3px solid var(--pp-focus-ring);
  outline-offset: 2px;
  box-shadow: none;              /* remove any global focus shadow */
  border-radius: 4px;
}

@media (forced-colors: active) {
  #ValidationSummaryEntityFormView ul li a:focus,
  #ValidationSummaryEntityFormView ul li a:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
    box-shadow: none;
  }
}

/* 2) Radios: focus only the circle (no group/label rings) */

/* Kill group/label outlines from other styles (patched & legacy groups) */
.wet-patched-radio fieldset.wet-radio-fieldset:focus-within,
.wet-patched-radio label.radio-inline:focus-within,
.boolean-radio:focus-within,
.boolean-radio input[type="radio"]:focus-visible + label,
.form-check-input[type="radio"]:focus-visible + label {
  outline: none !important;
  box-shadow: none !important;
  padding: 0 !important;
}

/* 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;
}

/* Tint only the native radio circle */
.wet-patched-radio input[type="radio"]:focus-visible,
.boolean-radio input[type="radio"]:focus-visible {
  accent-color: var(--pp-radio-focus);
}

@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: defer to OS palette */
@media (forced-colors: active) {
  .wet-patched-radio input[type="radio"],
  .boolean-radio input[type="radio"] {
    accent-color: ButtonText;
  }
}

/* =======================
   Read-only (review) radios: greyed UI + keep tabbable
   ======================= */

body.read-only-summary {
  /* choose accessible greys; keep >=4.5:1 contrast on white */
  --pp-disabled-fg: #6c757d;      /* label text */
  --pp-radio-disabled: #adb5bd;   /* radio circle */
}

body.read-only-summary .boolean-radio.readonly label,
body.read-only-summary .wet-patched-radio label {
  color: var(--pp-disabled-fg);
  cursor: default;
}

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);
  pointer-events: auto; /* keep keyboard focus */
}

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);   /* blue only on focus */
  outline: none !important;
  box-shadow: none !important;
}

/* 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;
}

@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;
  }
}

/* ==================== SELECT/DROPDOWN CHEVRON FIX ==================== */
/* CSS background-image SVG chevron - reliable cross-browser positioning */

.select-icon select,
select.form-select,
select.form-control.form-select,
select.form-control,
select.picklist,
select.lookup {
  /* Ensure consistent height */
  min-height: 38px;
  height: auto;
  padding: 0.375rem 2.25rem 0.375rem 0.75rem;
  
  /* SVG chevron as background-image */
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23333333' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e") !important;
  background-repeat: no-repeat !important;
  background-position: right 0.75rem center !important;
  background-size: 16px 12px !important;
  
  /* Hide native browser chevron */
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

/* Ensure proper vertical alignment of text */
select.form-select option,
select.form-control.form-select option,
select.picklist option {
  padding: 0.375rem 0.75rem;
}

/* High contrast mode support */
@media (forced-colors: active) {
  .select-icon select,
  select.form-select,
  select.form-control.form-select,
  select.form-control,
  select.picklist,
  select.lookup {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='ButtonText' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e") !important;
  }
}