/**
 * EME Generic Forms - Frontend Styles
 * Version: 2.2.0 (Fully Externalized Design Tokens)
 *
 * Table of Contents:
 * 0. Design Tokens (Variables)
 * 1. Base Styles & Layout
 * 2. Bootstrap Grid System
 * 3. Form Fields & Inputs
 * 4. Field Types
 * 5. Labels & Typography
 * 6. Buttons
 * 7. Messages & Notifications
 * 8. Special Sections (GDPR, reCAPTCHA)
 * 9. Validation States
 * 10. Themes
 * 11. Responsive Design
 * 12. Accessibility & Media Queries
 */

/* ============================================
   0. DESIGN TOKENS (VARIABLES)
   ============================================ */
:root {
  /* Fonts & Typography — match live site: Open Sans 14px, navy brand */
  --eme-font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --eme-font-size-base: 14px;
  --eme-font-size-sm: 13px;
  --eme-font-size-xs: 12px;
  --eme-font-weight-normal: 400;
  --eme-font-weight-medium: 500;
  --eme-font-weight-bold: 700;

  /* Text Colors — live site body #191919, label #595959 */
  --eme-color-text-main: #191919;
  --eme-color-text-muted: #595959;
  --eme-color-text-light: #6a6a6a;
  --eme-color-placeholder: #7c7c7c;
  --eme-color-text-disabled: #626262;

  --eme-tick-color: #002a5c;

  /* Input Field Colors & Borders — live site: white bg, #e1e1e1 border, 0 radius */
  --eme-input-bg: #ffffff;
  --eme-input-bg-focus: #ffffff;
  --eme-input-border: #e1e1e1;
  --eme-input-border-width: 1px;
  --eme-input-border-focus: #002a5c;
  --eme-file-border-style: solid;
  --eme-file-border-width: 1px;

  /* Primary Submit Button — live site: navy bg, white text, square corners */
  --eme-btn-primary-bg: #002a5c;
  --eme-btn-primary-bg-hover: #001f44;
  --eme-btn-primary-color: #fff;

  /* Secondary/Reset Button */
  --eme-btn-secondary-bg: #f0f0f0;
  --eme-btn-secondary-bg-hover: #e0e0e0;
  --eme-btn-secondary-border: #ddd;
  --eme-btn-secondary-color: #333;

  /* Validation & Status Colors */
  --eme-color-danger: #df3131;
  --eme-color-success: #4caf50;
  --eme-color-success-bg: #d5f5d9;
  --eme-color-success-text: #2f6e35;
  --eme-color-error-bg: #f8d7da;
  --eme-color-error-text: #842029;
  --eme-color-warning-bg: #fff3cd;
  --eme-color-warning-border: #ffc107;
  --eme-color-warning-text: #856404;

  /* Layout, Spacing, & Radii — live site: 0 radius, 10px 15px padding, 40px height */
  --eme-border-radius: 0px;
  --eme-border-radius-round: 25px; /* Used for rounded themes */
  --eme-input-padding: 10px 15px;
  --eme-input-height: 40px;
  --eme-btn-padding: 0 15px;
  --eme-btn-padding-sm: 0 15px;
  --eme-transition-speed: 0.3s;

  /* SVG Icons (Hex colors must be URL encoded, e.g., #3c3c3c becomes %233c3c3c) */
  --eme-icon-select-dropdown: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"><path fill="%233c3c3c" d="M6 9L1 4h10z"/></svg>');
}

/* ============================================
   1. BASE STYLES & LAYOUT
   ============================================ */

.eme-form-wrapper {
  max-width: 100%;
  margin: 20px 0;
  padding: 0;
  color: var(--eme-color-text-main);
  font-family: var(--eme-font-family);
}

.eme-form {
  background: transparent;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  color: var(--eme-color-text-main);
}

.eme-form-fields {
  margin-bottom: 20px;
}

.eme-form-row {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -10px;
}

.eme-field-wrapper,
.dfb-form-group {
  padding: 0 10px;
  margin-bottom: 25px;
}

/* ============================================
   2. BOOTSTRAP GRID SYSTEM
   ============================================ */

.eme-form-wrapper.row, .eme-form-wrapper .row  {
  display: flex;
  flex-wrap: wrap;
  margin-right: -10px;
  margin-left: -10px;
}

.eme-form-wrapper .col-12 {
  flex: 0 0 100%;
  max-width: 100%;
  padding-right: 10px;
  padding-left: 10px;
}

.eme-form-wrapper .col-sm-6 {
  flex: 0 0 100%;
  max-width: 100%;
}

/* Bootstrap Grid Breakpoints */
@media (min-width: 576px) {
  .eme-form-wrapper .col-sm-3 {
    flex: 0 0 25%;
    max-width: 25%;
  }

  .eme-form-wrapper .col-sm-4 {
    flex: 0 0 33.333333%;
    max-width: 33.333333%;
  }

  .eme-form-wrapper .col-sm-6 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  .eme-form-wrapper .col-sm-8 {
    flex: 0 0 66.666667%;
    max-width: 66.666667%;
  }

  .eme-form-wrapper .col-sm-9 {
    flex: 0 0 75%;
    max-width: 75%;
  }
}

/* Width Utility Classes */
.eme-width-25 {
  width: 25%;
}
.eme-width-33 {
  width: 33.333%;
}
.eme-width-50 {
  width: 50%;
}
.eme-width-66 {
  width: 66.666%;
}
.eme-width-75 {
  width: 75%;
}
.eme-width-100 {
  width: 100%;
}

/* ============================================
   3. FORM FIELDS & INPUTS
   ============================================ */

.eme-input,
.eme-textarea,
.eme-select {
  width: 100%;
  padding: var(--eme-input-padding);
  border: var(--eme-input-border-width) solid var(--eme-input-border);
  border-radius: var(--eme-border-radius);
  font-size: var(--eme-font-size-base);
  font-family: var(--eme-font-family);
  background-color: var(--eme-input-bg);
  color: var(--eme-color-text-main);
  font-weight: var(--eme-font-weight-normal);
  line-height: 1.4;
  height: var(--eme-input-height);
  box-sizing: border-box;
  transition:
    border-color var(--eme-transition-speed) ease,
    box-shadow var(--eme-transition-speed) ease;
}

.eme-input:focus,
.eme-textarea:focus,
.eme-select:focus {
  outline: none;
  border-color: var(--eme-input-border-focus);
  box-shadow: none;
  background-color: var(--eme-input-bg-focus);
}

.eme-textarea {
  resize: vertical;
  min-height: 120px;
  height: auto;
}

/* Placeholder Styling */
.eme-input::placeholder,
.eme-textarea::placeholder {
  color: var(--eme-color-placeholder);
  opacity: 1;
}

/* ============================================
   4. FIELD TYPES
   ============================================ */

/* Select Dropdown */
.eme-select {
  appearance: none;
  background-image: var(--eme-icon-select-dropdown);
  background-repeat: no-repeat;
  background-position: right 15px center;
  background-size: 12px;
  padding-right: 40px;
  cursor: pointer;
}

.eme-field-date {
  cursor: pointer;
}

/* Date Picker */
.eme-input[type="date"] {
  background-repeat: no-repeat;
  background-position: right 15px center;
  background-size: 16px;
  padding-right: 15px;
}

/* Date Range Fields */
.eme-daterange-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.eme-daterange-wrapper .eme-input[type="date"] {
  background-position: right 12px center;
  padding-right: 40px;
}

.eme-daterange-field {
  display: flex;
  flex-direction: column;
}

.eme-daterange-label {
  font-size: var(--eme-font-size-sm);
  font-weight: var(--eme-font-weight-medium);
  margin-bottom: 5px;
  color: var(--eme-color-text-muted);
}

/* Checkbox and Radio Buttons */
.eme-checkbox-label,
.eme-radio-label {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  cursor: pointer;
}

.eme-checkbox,
.eme-radio {
  margin-right: 8px;
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* File Upload */
.eme-file {
  width: 100%;
  padding: 0;
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: border-color var(--eme-transition-speed) ease;
  background: transparent;
  height: var(--eme-input-height);
  line-height: var(--eme-input-height);
  display: inline-flex;
  align-items: center;
  font-family: var(--eme-font-family);
  font-size: var(--eme-font-size-base);
  color: var(--eme-color-text-main);
}

/* Native file upload button — needs both pseudo-elements for cross-browser */
.eme-file::-webkit-file-upload-button,
.eme-file::file-selector-button {
  background: #000;
  color: #fff;
  border: none;
  border-radius: 0;
  width: 150px;
  height: var(--eme-input-height);
  font-family: var(--eme-font-family);
  font-size: var(--eme-font-size-base);
  font-weight: var(--eme-font-weight-bold);
  cursor: pointer;
  margin-right: 15px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0;
}

.eme-file::-webkit-file-upload-button:hover,
.eme-file::file-selector-button:hover {
  background: #1a1a1a;
}

/* ============================================
   5. LABELS & TYPOGRAPHY
   ============================================ */

.eme-field-wrapper label,
.dfb-form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: var(--eme-font-weight-bold);
  color: var(--eme-color-text-muted);
  font-size: var(--eme-font-size-base);
  line-height: 1.5;
  font-family: var(--eme-font-family);
}

.eme-required,
.text-danger {
  color: var(--eme-color-danger);
  font-weight: var(--eme-font-weight-normal);
  margin-left: 2px;
}

/* Required Fields Notice */
.eme-required-notice,
.is_required {
  color: var(--eme-color-text-light);
  font-size: var(--eme-font-size-sm);
  margin: 15px 0 20px;
  font-style: italic;
}

.is_required .text-danger {
  margin-right: 3px;
  margin-left: 0;
}

/* ============================================
   6. BUTTONS
   ============================================ */

/* Submit Button Wrapper */
.eme-form-submit-wrapper,
.fb-submit-row {
  text-align: left;
  margin-top: 30px;
}

/* Primary Submit Button */
.eme-form-submit,
.submit-btn,
.orange-bg-btn,
.btn.btn-primary {
  padding: var(--eme-btn-padding);
  background: var(--eme-btn-primary-bg);
  color: var(--eme-btn-primary-color);
  border: 1px solid var(--eme-btn-primary-bg);
  border-radius: var(--eme-border-radius);
  font-size: var(--eme-font-size-base);
  font-weight: var(--eme-font-weight-bold);
  font-family: var(--eme-font-family);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition:
    background var(--eme-transition-speed) ease;
  display: inline-block;
  line-height: var(--eme-input-height);
  height: var(--eme-input-height);
  min-width: 160px;
}

.eme-form-submit:hover,
.submit-btn:hover,
.orange-bg-btn:hover,
.btn.btn-primary:hover {
  background: var(--eme-btn-primary-bg-hover);
  border-color: var(--eme-btn-primary-bg-hover);
}

.eme-form-submit:active,
.submit-btn:active,
.orange-bg-btn:active,
.btn.btn-primary:active {
  background: var(--eme-btn-primary-bg-hover);
}

.eme-form-submit:disabled,
.submit-btn:disabled,
.orange-bg-btn:disabled,
.btn.btn-primary:disabled {
  background: #ccc;
  border-color: #ccc;
  cursor: not-allowed;
}

/* Reset Button */
.reset-btn,
.btn.btn-default {
  padding: var(--eme-btn-padding);
  background: var(--eme-btn-secondary-bg);
  color: var(--eme-btn-secondary-color);
  border: 1px solid var(--eme-btn-secondary-border);
  border-radius: var(--eme-border-radius);
  font-size: var(--eme-font-size-base);
  font-weight: var(--eme-font-weight-bold);
  font-family: var(--eme-font-family);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition:
    background var(--eme-transition-speed) ease,
    transform 0.1s ease;
  display: inline-block;
  line-height: 1.4;
  margin-left: 10px;
}

.reset-btn:hover,
.btn.btn-default:hover {
  background: var(--eme-btn-secondary-bg-hover);
  transform: translateY(-1px);
}

.reset-btn:active,
.btn.btn-default:active {
  transform: translateY(0);
}

/* Button Size Modifier */
.btn-sm {
  padding: var(--eme-btn-padding-sm);
  font-size: 14px;
}

/* Loading Indicator */
.eme-form-loading {
  display: none;
  margin-left: 10px;
  color: var(--eme-color-text-muted);
  font-size: 14px;
}

.eme-form-loading.active {
  display: inline-block;
}

.eme-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: eme-spin 0.6s linear infinite;
}

@keyframes eme-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   7. MESSAGES & NOTIFICATIONS
   ============================================ */

.eme-form-message,
.msg-status-row .alert {
  padding: 15px 20px;
  margin: 20px 0;
  border-radius: var(--eme-border-radius);
  font-size: var(--eme-font-size-base);
}

.eme-message-success,
.eme-form-acknowledgment.eme-message-success {
  background: var(--eme-color-success-bg);
  color: var(--eme-color-success-text);
  border-left: 4px solid var(--eme-color-success);
}

.eme-message-error,
.eme-form-acknowledgment.eme-message-error {
  background: var(--eme-color-error-bg);
  color: var(--eme-color-error-text);
  border-left: 4px solid var(--eme-color-danger);
}

.eme-form-acknowledgment {
  margin-bottom: 20px;
}

.eme-error-message {
  display: block;
  margin-top: 5px;
  color: var(--eme-color-danger);
  font-size: var(--eme-font-size-sm);
}

/* ============================================
   8. SPECIAL SECTIONS (GDPR, reCAPTCHA)
   ============================================ */

/* GDPR Compliance Section */
.eme-field-wrapper.eme-gdpr-section,
.eme-gdpr-compliance {
  margin-top: 30px;
  margin-bottom: 25px;
}

.eme-gdpr-section .eme-field-label,
.eme-gdpr-compliance .eme-field-label {
  font-size: 16px;
  font-weight: var(--eme-font-weight-medium);
  color: var(--eme-color-text-main);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 15px;
  display: block;
}

.eme-gdpr-section .eme-gdpr-content,
.eme-gdpr-compliance .eme-gdpr-content {
  color: var(--eme-color-text-muted);
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 15px;
}

.eme-gdpr-section .eme-gdpr-content p,
.eme-gdpr-compliance .eme-gdpr-content p,
.eme-gdpr-compliance span {
  margin-bottom: 12px;
  color: var(--eme-color-text-disabled);
  font-weight: var(--eme-font-weight-normal);
  font-size: var(--eme-font-size-base);
}

.eme-gdpr-section .eme-checkbox-label,
.eme-gdpr-compliance .eme-checkbox-label {
  font-size: 14px;
  color: var(--eme-color-text-main);
}

/* reCAPTCHA Notice */
.eme-gdpr-section .eme-recaptcha-notice,
.eme-gdpr-compliance .eme-recaptcha-notice,
.recapture,
.eme-recaptcha-notice {
  color: var(--eme-color-text-light);
  font-size: var(--eme-font-size-xs);
  line-height: 1.6;
  margin: 15px 0 10px;
}

.eme-gdpr-section .eme-recaptcha-notice a,
.eme-gdpr-compliance .eme-recaptcha-notice a,
.recapture a,
.eme-recaptcha-notice a {
  color: var(--eme-color-text-muted);
  text-decoration: underline;
}

.eme-gdpr-section .eme-recaptcha-notice a:hover,
.eme-gdpr-compliance .eme-recaptcha-notice a:hover,
.recapture a:hover,
.eme-recaptcha-notice a:hover {
  color: var(--eme-color-text-main);
}

/* reCAPTCHA Field Wrapper */
.eme-field-recaptcha {
  margin-bottom: unset;
}

.eme-recaptcha-wrapper {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.eme-recaptcha-wrapper.eme-recaptcha-standard {
  align-items: flex-start;
}

.eme-recaptcha-wrapper.eme-recaptcha-invisible {
  align-items: flex-start;
}

/* reCAPTCHA Warning (for admins when keys not configured) */
.eme-recaptcha-warning {
  padding: 15px;
  background-color: var(--eme-color-warning-bg);
  border: 1px solid var(--eme-color-warning-border);
  border-radius: var(--eme-border-radius);
  color: var(--eme-color-warning-text);
}

.eme-recaptcha-warning p {
  margin: 0;
  font-size: 14px;
}

/* reCAPTCHA Error State */
.eme-field-error.eme-field-recaptcha .eme-recaptcha-wrapper {
  border: var(--eme-file-border-width) solid var(--eme-color-danger);
  border-radius: var(--eme-border-radius);
  padding: 10px;
}

.eme-field-error.eme-field-recaptcha .eme-error-message {
  color: var(--eme-color-danger);
  font-size: var(--eme-font-size-sm);
  margin-top: 8px;
  display: block;
}

/* ============================================
   9. VALIDATION STATES
   ============================================ */

/* Error State */
.eme-field-error .eme-input,
.eme-field-error .eme-textarea,
.eme-field-error .eme-select {
  border-color: var(--eme-color-danger);
}

/* ============================================
   10. THEMES
   ============================================ */

.eme-theme-default {
  /* Default theme styles already applied above */
}

/* Minimal Theme */
.eme-theme-minimal .eme-form {
  box-shadow: none;
  border: var(--eme-input-border-width) solid var(--eme-btn-secondary-border);
}

.eme-theme-minimal .eme-form-submit {
  background: #333;
}

.eme-theme-minimal .eme-form-submit:hover {
  background: #000;
}

/* Rounded Theme */
.eme-theme-rounded .eme-input,
.eme-theme-rounded .eme-textarea,
.eme-theme-rounded .eme-select,
.eme-theme-rounded .eme-form-submit {
  border-radius: var(--eme-border-radius-round);
}

/* ============================================
   11. RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 600px) {
  /* Date Range Stacking */
  .eme-daterange-wrapper {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

@media screen and (max-width: 768px) {
  .eme-form {
    padding: 20px 0;
  }

  /* Width Classes Mobile Override */
  .eme-width-25,
  .eme-width-33,
  .eme-width-50,
  .eme-width-66,
  .eme-width-75 {
    width: 100%;
  }

  .eme-form-row {
    margin: 0;
  }

  .eme-field-wrapper {
    padding: 0;
    margin-bottom: 20px;
  }

  .eme-form-submit {
    width: auto;
    padding: var(--eme-btn-padding);
  }
}

/* ============================================
   12. ACCESSIBILITY & MEDIA QUERIES
   ============================================ */

/* High Contrast Mode */
@media (prefers-contrast: high) {
  .eme-input,
  .eme-textarea,
  .eme-select {
    border-width: 2px;
  }

  .eme-form-submit {
    border: 2px solid #fff;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .eme-input,
  .eme-textarea,
  .eme-select {
    background: var(--eme-input-bg);
    border-color: var(--eme-input-border);
    color: var(--eme-color-text-main);
  }

  .eme-field-wrapper label {
    color: var(--eme-color-text-main);
  }
}

/* Print Styles */
@media print {
  .eme-form-submit-wrapper,
  .fb-submit-row {
    display: none;
  }
}

/* Custom Select Arrow */
.eme-field-wrapper select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><path fill='%23000000' d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: calc(100% - 12px) center;
  background-size: 20px;
  padding-right: 20px;
  padding-left: 15px;
  cursor: pointer;
}

.eme-field-wrapper input[type="checkbox"] {
  accent-color: var(--eme-tick-color);
  border-color: var(--eme-tick-color);
}

.eme-field-checkbox {
  margin-bottom: unset;
}

/* Autofill Override */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--eme-input-bg) inset !important;
  -webkit-text-fill-color: var(--eme-color-text-main) !important;
}

/* ============================================
   13. LIVE-SITE PARITY OVERRIDES
   Match the original dynamic-form-builder styling:
   - Two-column grid for short fields
   - Bold uppercase navy section title
   - 30px vertical spacing between field groups
   ============================================ */

/* Section title — match live site's H1 styling inside the form */
.eme-form-wrapper .eme-form-title,
.eme-form-wrapper > h1,
.eme-form-wrapper > h2 {
  color: #002a5c;
  font-family: var(--eme-font-family);
  font-weight: var(--eme-font-weight-bold);
  font-size: 30px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 10px;
  margin: 0 0 30px 0;
  background: transparent;
}

/* Field group spacing — match live site's 30px gap */
.eme-field-wrapper,
.dfb-form-group {
  margin-bottom: 30px;
}

/* Two-column grid alignment (live site uses col-sm-6 col-xs-12) */
.eme-form-row {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -15px;
}

.eme-form-row > .eme-field-wrapper,
.eme-form-row > .dfb-form-group {
  padding: 0 15px;
}

/* Required-field footnote — live site color #002a5C, 11px */
.eme-required-notice,
.is_required {
  color: #002a5c;
  font-size: 11px;
  font-style: normal;
  margin: 0 0 20px 0;
}

.is_required .eme-required,
.is_required .text-danger {
  color: #df3131;
  margin-right: 3px;
  margin-left: 0;
}

/* reCAPTCHA notice — match live site small text */
.recapture,
.eme-recaptcha-notice {
  color: #6a6a6a;
  font-size: 12px;
  line-height: 1.5;
  margin: 0 0 20px 0;
}

.recapture a,
.eme-recaptcha-notice a {
  color: #6a6a6a;
  text-decoration: underline;
}

/* Checkbox / radio accent color (navy) */
.eme-field-wrapper input[type="checkbox"],
.eme-field-wrapper input[type="radio"] {
  accent-color: var(--eme-tick-color);
}
