.mobile_w8ben-container {
  display: flex;
  justify-content: center;
}

.mobile_w8ben-form {
  max-width: 100%;
  margin: auto;
  padding: 20px;
  border: 1px solid #ccc;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  background-color: #fff;
  width: 100%;
}

.mobile_w8ben-subtitle {
  text-align: center;
  margin-bottom: 20px;
  font-size: 14px;
}

/* Default styles for header - apply for mobile, overridden for desktop */
.mobile_w8ben-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
  flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

.mobile_w8ben-header-left,
.mobile_w8ben-header-center,
.mobile_w8ben-header-right {
  flex: 1; /* Default flex behavior */
  padding-top: 0;
  text-align: center; /* Default center align for mobile */
}
.mobile_w8ben-header-left {
  order: 1;
}
.mobile_w8ben-header-center {
  order: 2;
}
.mobile_w8ben-header-right {
  order: 3;
}

.mobile_w8ben-header-left .mobile_w8ben-form-label {
  font-size: 12px;
  display: block;
}

.mobile_w8ben-header-left .mobile_w8ben-form-number {
  font-size: 24px;
  font-weight: bold;
  line-height: 1;
  margin-top: 0;
}

.mobile_w8ben-header-left .mobile_w8ben-form-subtitle,
.mobile_w8ben-header-left .mobile_w8ben-form-department {
  font-size: 12px;
  line-height: 1.3;
}

.mobile_w8ben-header-center h3 {
  font-size: 18px;
  text-align: center;
  margin-bottom: 5px;
  line-height: 1.2;
  margin-top: 0;
}

.mobile_w8ben-header-center p {
  font-size: 12px;
  text-align: center;
}

.mobile_w8ben-header-right p {
  font-size: 12px;
  padding-top: 0;
  margin-top: 0;
}

.mobile_w8ben-instructions {
  border: 1px solid #ccc;
  padding: 10px;
  margin-bottom: 20px;
  background-color: #f9f9f9;
}

.mobile_w8ben-instruction-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 5px;
}

.mobile_w8ben-instruction-left {
  flex: 1;
  padding-right: 10px;
}

.mobile_w8ben-instruction-right {
  width: 80px;
  text-align: right;
}

.mobile_w8ben-note {
  margin-bottom: 20px;
  font-size: 12px;
  font-style: italic;
}

.mobile_w8ben-part {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  border-bottom: 2px solid #000;
  padding-bottom: 5px;
}

.mobile_w8ben-part .mobile_w8ben-part-header {
  font-weight: bold;
  font-size: 16px;
  margin-right: 10px;
}

.mobile_w8ben-part .mobile_w8ben-part-title {
  font-size: 16px;
  font-weight: bold;
}

/* Default field row styling - flex for single column or wrapping on smaller screens */
.mobile_w8ben-field-row {
  display: flex;
  align-items: flex-start; /* Align numbers and labels to the top */
  margin-bottom: 15px;
  flex-wrap: wrap; /* Allow wrapping for general case */
  gap: 20px; /* Consistent gap */
}

.mobile_w8ben-field-number {
  width: 20px; /* Fixed width for number */
  font-weight: bold;
  font-size: 14px;
  flex-shrink: 0;
}

.mobile_w8ben-field-content {
  flex: 1; /* Allow content to grow/shrink */
  display: flex;
  flex-direction: column;
  min-width: auto; /* Allow to shrink as needed for small inputs */
}

.mobile_w8ben-field-content.mobile_w8ben-full-width {
  flex-basis: 100%;
  margin-left: 0; /* Handled by flex/gap */
}

.mobile_w8ben-field-label {
  font-size: 12px;
  margin-bottom: 5px;
  display: block;
}

.mobile_w8ben-field-value {
  border: 1px solid #ccc;
  padding: 5px;
  min-height: 20px;
  width: 100%;
  box-sizing: border-box;
  font-size: 14px;
}

input[type="text"].mobile_w8ben-field-value {
  width: 100%;
  padding: 3px;
}

input[type="checkbox"].mobile_w8ben-field-value {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: middle;
  padding: 0;
}

.mobile_w8ben-certification {
  margin-top: 20px;
  font-size: 12px;
}

.mobile_w8ben-certification ul {
  list-style: disc;
  margin-left: 20px;
  margin-bottom: 10px;
}

.mobile_w8ben-certification ul li {
  margin-bottom: 5px;
}

.mobile_w8ben-signature {
  display: flex;
  align-items: center;
  margin-top: 20px;
  border-top: 1px solid #eee;
  padding-top: 10px;
  gap: 20px;
}

.mobile_w8ben-signature-label {
  font-weight: bold;
  margin-right: 10px;
  font-size: 14px;
}

.mobile_w8ben-signature-field,
.mobile_w8ben-signature-date {
  border: 1px solid #ccc;
  padding: 5px;
  min-height: 20px;
  flex: 1;
  font-size: 14px;
}

.mobile_w8ben-signer {
  margin-top: 10px;
}

.mobile_w8ben-signature-name {
  border: 1px solid #ccc;
  padding: 5px;
  min-height: 20px;
  width: 300px;
  font-size: 14px;
}

.mobile_w8ben-signature-title {
  font-size: 12px;
  margin-top: 5px;
}

.mobile_w8ben-signature-instructions {
  display: flex;
  align-items: center;
  margin-top: 30px;
  padding: 10px;
  border-top: 1px solid #eee;
  font-size: 12px;
  color: #555;
}

.mobile_w8ben-signature-icon {
  margin-right: 10px;
}

.mobile_w8ben-signature-icon svg {
  fill: currentColor;
  color: #555;
}

/* Media query for larger screens */
@media (min-width: 769px) {
  .mobile_w8ben-form {
    margin: 20px auto; /* Ensure centering on large screens */
  }

  .mobile_w8ben-header {
    display: grid; /* Use grid for precise header alignment */
    grid-template-columns: 20% 1fr 20%; /* Left, Center (flexible), Right */
    align-items: start; /* Align content to the top of their grid areas */
    gap: 10px; /* Gap between grid columns */
    flex-wrap: nowrap; /* Prevent header from wrapping */
    padding-bottom: 10px; /* Maintain padding */
  }

  .mobile_w8ben-header-left {
    grid-column: 1; /* Place in first column */
    text-align: left;
    flex-basis: auto; /* Reset flex-basis as grid is taking over */
  }

  .mobile_w8ben-header-center {
    grid-column: 2; /* Place in second column */
    text-align: center;
    flex-basis: auto; /* Reset flex-basis */
  }

  .mobile_w8ben-header-right {
    grid-column: 3; /* Place in third column */
    text-align: right;
    flex-basis: auto; /* Reset flex-basis */
  }

  /* Adjust individual element positions within their grid cells */
  .mobile_w8ben-header-left .mobile_w8ben-form-number {
    margin-top: -5px; /* Adjust to pull form number up slightly */
  }
  .mobile_w8ben-header-center h3 {
    margin-top: 5px; /* Adjust to push title down slightly for alignment */
  }
  .mobile_w8ben-header-right p {
    padding-top: 0;
    margin-top: 0;
  }

  /* Field rows: General settings for flex, then specific overrides */
  .mobile_w8ben-field-row {
    display: flex;
    align-items: flex-start; /* Align numbers and labels to the top */
    margin-bottom: 15px;
    flex-wrap: wrap; /* Allow wrapping for general case, overridden by grid */
    gap: 20px; /* Consistent gap */
  }

  .mobile_w8ben-field-number {
    width: 20px; /* Fixed width for number */
    flex-shrink: 0;
    /* margin-right applied specifically below */
  }

  .mobile_w8ben-field-content {
    flex: 1; /* Allow content to grow/shrink */
    display: flex;
    flex-direction: column;
    min-width: auto; /* Allow to shrink as needed for small inputs */
  }

  .mobile_w8ben-field-content.mobile_w8ben-full-width {
    flex-basis: 100%;
    margin-left: 0; /* Handled by flex/gap */
  }

  /* Two-column layout for specific field-rows with numbers (1, 7, 8) */
  .mobile_w8ben-fields .mobile_w8ben-field-row:nth-child(1),
  .mobile_w8ben-fields .mobile_w8ben-field-row:nth-child(7),
  .mobile_w8ben-fields .mobile_w8ben-field-row:nth-child(8) {
    display: grid; /* Override flex for these specific rows */
    grid-template-columns: auto 1fr auto 1fr; /* Number, Field1, Number, Field2 */
    gap: 20px;
    align-items: start; /* Align to top */
  }

  /* Two-column layout for field-rows without numbers (3, 5) */
  .mobile_w8ben-fields .mobile_w8ben-field-row:nth-child(3),
  .mobile_w8ben-fields .mobile_w8ben-field-row:nth-child(5) {
    display: flex; /* Keep as flex */
    flex-direction: row; /* Ensure flex direction */
    align-items: flex-start; /* Align contents to the top */
    justify-content: flex-start; /* Align contents to the left */
    flex-wrap: nowrap; /* Prevent wrapping */
    gap: 20px; /* Gap between city/state/postcode and country */
  }
  /* Adjust the content within these no-number two-column rows */
  .mobile_w8ben-fields
    .mobile_w8ben-field-row:nth-child(3)
    .mobile_w8ben-field-content,
  .mobile_w8ben-fields
    .mobile_w8ben-field-row:nth-child(5)
    .mobile_w8ben-field-content {
    flex: 1 1 calc(50% - 10px); /* Adjust to take half width minus half the gap */
    max-width: calc(50% - 10px);
    min-width: auto; /* Allow shrinking if needed */
  }
  .mobile_w8ben-fields
    .mobile_w8ben-field-row:nth-child(3)
    .mobile_w8ben-field-number,
  .mobile_w8ben-fields
    .mobile_w8ben-field-row:nth-child(5)
    .mobile_w8ben-field-number {
    /* These are empty divs, ensure they don't consume space */
    width: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }

  /* Single-column field-rows with numbers (2, 4, 6, 9, 10) */
  .mobile_w8ben-fields .mobile_w8ben-field-row:nth-child(2),
  .mobile_w8ben-fields .mobile_w8ben-field-row:nth-child(4),
  .mobile_w8ben-fields .mobile_w8ben-field-row:nth-child(6),
  .mobile_w8ben-fields .mobile_w8ben-field-row:nth-child(9),
  .mobile_w8ben-fields .mobile_w8ben-field-row:nth-child(10) {
    display: flex; /* Ensure it's flex */
    flex-direction: row; /* Number and full-width content side-by-side */
    align-items: flex-start; /* Align number and top of content */
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 10px; /* Small gap between number and field content */
  }
  /* Adjust the full-width field content within these rows */
  .mobile_w8ben-fields
    .mobile_w8ben-field-row:nth-child(2)
    .mobile_w8ben-field-content.mobile_w8ben-full-width,
  .mobile_w8ben-fields
    .mobile_w8ben-field-row:nth-child(4)
    .mobile_w8ben-field-content.mobile_w8ben-full-width,
  .mobile_w8ben-fields
    .mobile_w8ben-field-row:nth-child(6)
    .mobile_w8ben-field-content.mobile_w8ben-full-width,
  .mobile_w8ben-fields
    .mobile_w8ben-field-row:nth-child(9)
    .mobile_w8ben-field-content.mobile_w8ben-full-width,
  .mobile_w8ben-fields
    .mobile_w8ben-field-row:nth-child(10)
    .mobile_w8ben-field-content.mobile_w8ben-full-width {
    flex: 1 1 auto; /* Allow to grow and shrink */
    width: auto; /* Let flex handle width */
    margin-left: 0; /* Remove any previous margin */
  }

  /* Ensure all inputs take full width of their content container */
  .mobile_w8ben-field-content input[type="text"] {
    width: 100%;
  }

  /* Signature section, ensure it remains side-by-side */
  .mobile_w8ben-signature {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
  }
  .mobile_w8ben-signature-field,
  .mobile_w8ben-signature-date {
    margin-right: 10px;
    flex: 1;
  }
  .mobile_w8ben-signature-date {
    flex: 0 0 120px;
  }
}

/* Mobile specific adjustments for header, as it's flex by default */
@media (max-width: 768px) {
  .mobile_w8ben-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .mobile_w8ben-field-number {
    display: none;
  }

  .mobile_w8ben-header-left,
  .mobile_w8ben-header-center,
  .mobile_w8ben-header-right {
    width: 100%;
    margin-bottom: 10px;
    text-align: center; /* Ensure center alignment on mobile */
  }

  .mobile_w8ben-header-right {
    margin-left: auto;
    margin-right: auto;
  }

  .mobile_w8ben-field-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .mobile_w8ben-field-number {
    margin-bottom: 5px;
  }

  .mobile_w8ben-field-content.mobile_w8ben-full-width {
    margin-left: 0;
  }

  .mobile_w8ben-field-content {
    width: 100%;
  }

  .mobile_w8ben-signature-field,
  .mobile_w8ben-signature-date {
    width: 100%;
    margin-right: 0;
    margin-bottom: 10px;
  }

  .mobile_w8ben-signature {
    flex-direction: column;
    align-items: flex-start;
  }

  .mobile_w8ben-signature-label {
    margin-bottom: 10px;
  }

  .mobile_w8ben-signature-name {
    width: calc(100% - 12px);
  }
}
