/**
 * MS Dynamics 365 Form - Custom CSS for CSG/Forte Design System
 * 
 * APPROACH: Simplified CSS using cascading, CSS variables, and scoping.
 * 
 * KEY PRINCIPLES:
 * 1. Single font-family at top level (no repetition)
 * 2. Color cascading from root (white text by default)
 * 3. CSS variables for repeated values (fallbacks for MS Dynamics editor)
 * 4. .marketingForm scoping to prevent global CSS leakage
 * 
 * CSS VARIABLES (with fallbacks):
 * - --form-bg: Form background color
 * - --form-text: Form text color
 * - --field-bg: Input field background
 * - --field-border: Input field border color
 * - --field-radius: Input field border radius
 * - --field-padding: Input field padding
 * - --field-height: Input field height
 * - --field-gap: Gap between form fields
 * - --button-bg: Submit button background
 * - --button-text: Submit button text color
 */

/* CSS Variables - Scoped to form container so they evaluate in current theme context */
.marketingForm {
  --form-bg: var(--ds-background-primary, #ffffff);
  --form-text: var(--ds-foreground-primary, #000000);
  /* TODO: set these vars in the DS (inputs design tokens) */
  --field-bg: #ffffff;
  --field-text: #000000;
  --field-padding: var(--spacing-3, 0.75rem);
  --field-height: 2.5rem;

  --field-border: var(--ds-border-tertiary, #d0d2d5);
  --field-radius: var(--radius, 0.5rem);
  --field-gap: var(--spacing-5, 1.25rem);
  --button-bg: var(--ds-cta-secondary-fg-default, #003d87);
  --button-text: var(--ds-cta-primary-fg-default, #ffffff);
  --button-radius: var(--radius, 0.5rem);
}

/* Global font family - cascade to form and descendants only */
.marketingForm {
  font-family: var(
    --font-body,
    'Noto Sans',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Arial,
    sans-serif
  );
  color: var(--form-text) !important;
  text-align: left;
  background: var(--form-bg);
  padding: 0;
  font-size: 0.875rem;
}

/* Utility classes */
.marketingForm .hide-on-desktop-class {
  display: none !important;
}

/* Editor control layout */
.marketingForm .editor-control-layout html {
  box-sizing: border-box;
  background-color: transparent;
}

.marketingForm .editor-control-layout *,
.marketingForm .editor-control-layout ::before,
.marketingForm .editor-control-layout ::after {
  box-sizing: inherit;
}

.marketingForm input,
.marketingForm select,
.marketingForm textarea {
  box-sizing: border-box !important;
}

/* Typography - let white cascade */
.marketingForm h1 {
  margin: 0;
  padding: 0;
  width: 100%;
  line-height: 1.25;
  font-size: 1.75rem;
}

.marketingForm h2 {
  margin: 0;
  padding: 0;
  width: 100%;
  line-height: 1.25;
  font-size: 1.375rem;
}

.marketingForm h3 {
  margin: 0;
  padding: 0;
  width: 100%;
  line-height: 1.25;
  font-size: 1.125rem;
}

.marketingForm p {
  margin: 0;
  padding: 0;
  line-height: 1.25;
  font-size: 0.875rem;
  color: inherit !important;
}

.marketingForm a {
  text-decoration: underline !important;
  text-decoration-color: inherit !important;
  font-size: 0.875rem;
  color: inherit !important;
  -webkit-text-fill-color: inherit !important;
}

/* Buttons */
.marketingForm .submitButtonWrapper {
  text-align: left;
  margin: 0;
  margin-top: 1rem;
}

.marketingForm .submitButton {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.375rem;
  background: var(--button-bg) !important;
  color: var(--button-text) !important;
  border: none !important;
  border-radius: var(--button-radius);
  padding: 0.875rem 1.75rem;
  cursor: pointer;
  width: auto;
  min-width: 10rem;
  height: 3rem;
  transition: opacity 0.2s ease;
}

.marketingForm .submitButton:hover {
  opacity: 0.9;
}

.marketingForm .error {
  font-weight: bold;
  font-size: 0.5rem;
  margin: 0;
  padding: 0;
  color: #ff0000;
}

/* FIXED: Remove max-width so form respects grid layout */
.marketingForm [data-layout='true'] {
  margin: 0 auto;
  background-color: transparent;
  width: 100%;
}

/* Override MS Dynamics table-based layout */
.marketingForm table {
  width: 100% !important;
  table-layout: fixed !important;
}

.marketingForm th,
.marketingForm td {
  width: auto !important;
  max-width: 100% !important;
}

/* Override inline width on table header cells */
.marketingForm th[style*='width'],
.marketingForm th.columnContainer {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
}

/* Force inner container to respect parent width and remove excessive padding */
.marketingForm .inner.ui-sortable {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  padding: 0 !important;
}

/* Remove padding from table cells - ancestor padding removed, controlled at component level */
.marketingForm th {
  padding: 0 !important;
}

/* FIXED: Adjust padding and change from row to column layout - ONLY for visible fields
 * Right padding added for side-by-side field spacing
 */
.marketingForm .textFormFieldBlock:not([style*='display: none']):not([style*='display:none']),
.marketingForm .dateTimeFormFieldBlock:not([style*='display: none']):not([style*='display:none']),
.marketingForm .twoOptionFormFieldBlock:not([style*='display: none']):not([style*='display:none']),
.marketingForm .optionSetFormFieldBlock:not([style*='display: none']):not([style*='display:none']),
.marketingForm .lookupFormFieldBlock:not([style*='display: none']):not([style*='display:none']),
.marketingForm .phoneFormFieldBlock:not([style*='display: none']):not([style*='display:none']) {
  padding: 0.5rem 0.75rem 0.5rem 0 !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 0.5rem !important;
}

.marketingForm .consentBlock {
  padding: 0.5rem 0.75rem 0.5rem 0 !important;
}

/* Labels - white color inherited, proper sizing */
.marketingForm .textFormFieldBlock label,
.marketingForm .dateTimeFormFieldBlock label,
.marketingForm .lookupFormFieldBlock label,
.marketingForm .phoneFormFieldBlock label,
.marketingForm .twoOptionFormFieldBlock label.block-label,
.marketingForm .optionSetFormFieldBlock label.block-label {
  font-size: 1rem;
  font-weight: 600;
  display: block;
  margin: 0;
  padding: 0;
  width: 100%;
  text-align: left;
  color: inherit !important;
}

/* Required field indicator */
.marketingForm .textFormFieldBlock label::after,
.marketingForm .dateTimeFormFieldBlock label::after,
.marketingForm .lookupFormFieldBlock label::after,
.marketingForm .phoneFormFieldBlock label::after,
.marketingForm .twoOptionFormFieldBlock label.block-label::after,
.marketingForm .optionSetFormFieldBlock label.block-label::after {
  width: 1.375rem;
  display: inline-block;
  line-height: 1.375rem;
  text-align: center;
  color: var(--form-text) !important;
  content: '*';
  visibility: hidden;
}

.marketingForm div[data-required].textFormFieldBlock label::after,
.marketingForm div[data-required].dateTimeFormFieldBlock label::after,
.marketingForm div[data-required].lookupFormFieldBlock label::after,
.marketingForm div[data-required].phoneFormFieldBlock label::after,
.marketingForm div[data-required] label.block-label::after {
  visibility: visible;
}

/* Input fields - use CSS variables */
.marketingForm .optionSetFormFieldBlock select,
.marketingForm .textFormFieldBlock input,
.marketingForm .dateTimeFormFieldBlock input,
.marketingForm .lookupFormFieldBlock input,
.marketingForm .phoneFormFieldBlock input,
.marketingForm textarea {
  padding: var(--field-padding);
  background-color: var(--field-bg) !important;
  border: 1px solid var(--field-border);
  border-radius: var(--field-radius);
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  height: var(--field-height);
  box-sizing: border-box !important;
  font-size: 1rem;
  text-align: left;
  color: var(--field-text) !important;
  flex: none !important;
  margin: 0 !important;
}

/* Additional specificity for text inputs */
.marketingForm input[type='text'],
.marketingForm input[type='email'],
.marketingForm input[type='tel'] {
  background-color: var(--field-bg) !important;
  color: var(--field-text) !important;
}

/* Phone field — hide country code prefix, let tel input fill full width */
.marketingForm .phoneCountryCode {
  display: flex;
  align-items: center;
  width: 100%;
  border: none !important;
  outline: none !important;
  background: transparent !important;
  padding: 0 !important;
}

.marketingForm .phoneCountryCode .phoneCountryCodeLabel {
  display: none;
}

.marketingForm .phoneCountryCode input[type='tel'] {
  flex: 1;
}

.marketingForm .textFormFieldBlock textarea {
  resize: vertical;
  height: auto;
  min-height: 5rem;
  padding: 0.5rem var(--field-padding);
}

.marketingForm .optionSetFormFieldBlock select {
  background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iNyIgdmlld0JveD0iMCAwIDEyIDciIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik02IDYuNzA4OThMMC4xNDY0ODQgMC44NTU0NjlMMC44NTU0NjkgMC4xNDY0ODRMNiA1LjI5MTAyTDExLjE0NDUgMC4xNDY0ODRMMTEuODUzNSAwLjg1NTQ2OUw2IDYuNzA4OThaIiBmaWxsPSIjNjA1RTVDIi8+Cjwvc3ZnPgo=');
  background-repeat: no-repeat;
  background-position: 98% 50%;
  appearance: none;
}

/* Placeholder text */
.marketingForm input::placeholder,
.marketingForm textarea::placeholder {
  color: #999999;
}

/* Radio buttons and checkboxes */
.marketingForm .twoOptionFormFieldBlock div.radiobuttons,
.marketingForm .optionSetFormFieldBlock div.radiobuttons {
  font-size: 0.875rem;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0;
  gap: 0.5rem;
  flex: 2.8 1 0%;
  margin-top: 1rem;
}

.marketingForm .twoOptionFormFieldBlock div.radiobuttons > div,
.marketingForm .optionSetFormFieldBlock div.radiobuttons > div {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 0;
  gap: 0.5rem;
  width: 100%;
}

.marketingForm .twoOptionFormFieldBlock div.radiobuttons div label,
.marketingForm .optionSetFormFieldBlock div.radiobuttons div label {
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.25rem;
}

.marketingForm .twoOptionFormFieldBlock div.radiobuttons div input,
.marketingForm .optionSetFormFieldBlock div.radiobuttons div input {
  margin: 0;
  box-sizing: border-box;
  width: 1.5rem;
  height: 1.5rem;
  border: 1px solid #ffffff;
  border-radius: 0.125rem;
  accent-color: var(--button-bg);
  flex-shrink: 0;
}

/* Checkbox styles */
.marketingForm .twoOptionFormFieldBlock div.twooption_checkbox,
.marketingForm .consentBlock {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.marketingForm .twoOptionFormFieldBlock div.twooption_checkbox > div,
.marketingForm .consentBlock > div {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  padding: 0;
  gap: 0.5rem;
}

.marketingForm .twoOptionFormFieldBlock div.twooption_checkbox div label,
.marketingForm .consentBlock div label {
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25rem;
}

.marketingForm .twoOptionFormFieldBlock div.twooption_checkbox div input,
.marketingForm .consentBlock div input {
  margin: 0;
  box-sizing: border-box;
  width: 1.5rem;
  height: 1.5rem;
  border: 1px solid #ffffff;
  border-radius: 0.125rem;
  accent-color: var(--button-bg);
  flex-shrink: 0;
}

/* Override inline styles on consent/checkbox label spans */
.marketingForm .twoOptionFormFieldBlock div.twooption_checkbox div label span,
.marketingForm .consentBlock div label span,
.marketingForm div[data-editorblocktype='Text'] span {
  color: var(--form-text) !important;
  font-family: inherit !important;
  font-size: 0.875rem !important;
  font-weight: 500 !important;
  line-height: 1.25rem !important;
  background-color: transparent !important;
}

/* Notifications */
.marketingForm .notification-container {
  margin: 0.625rem;
}

.marketingForm .notification-message {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 2.5rem;
  border: 1px solid var(--field-border);
  border-radius: 0.625rem;
  margin-bottom: 0.625rem;
  margin-top: 0.625rem;
}

.marketingForm .notification-message-hide {
  display: none;
}

/* Form submission confirmation */
.marketingForm .onFormSubmittedFeedback,
div[data-cached-form-url] .onFormSubmittedFeedback {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 2rem !important;
  width: 100% !important;
  height: auto !important;
  min-height: 12.5rem !important;
  background: transparent !important;
  font-family: var(
    --font-body,
    'Noto Sans',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Arial,
    sans-serif
  ) !important;
}

.marketingForm .onFormSubmittedFeedbackInternalContainer,
div[data-cached-form-url] .onFormSubmittedFeedbackInternalContainer {
  text-align: center !important;
  position: static !important;
  top: auto !important;
  padding: 1rem !important;
}

/* Hide the icon */
.marketingForm .onFormSubmittedFeedbackIcon,
div[data-cached-form-url] .onFormSubmittedFeedbackIcon {
  display: none !important;
}

.marketingForm .onFormSubmittedFeedbackMessage,
div[data-cached-form-url] .onFormSubmittedFeedbackMessage {
  font-size: 1.125rem !important;
  line-height: 1.5 !important;
  color: var(--form-text) !important;
  margin: 0 !important;
  padding: 1rem !important;
  font-family: inherit !important;
}

/* Responsive */
@media only screen and (max-width: 48rem) {
  .marketingForm {
    padding: 3rem 1rem;
  }
}
