/* Floating Label Inputs for Contact Form 7 */
.floating-group {
  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --input-text: #111827;
  --input-text-secondary: #4b5563;
  --input-focus: #3b82f6;
  --input-focus-ring: rgba(59, 130, 246, 0.15);
  --input-radius: 8px;
  --input-min-height: 3.5rem;

  position: relative;
  container-type: inline-size;

  /* CF7 wrapper span - don't let it affect layout */
  & .wpcf7-form-control-wrap {
    display: block;
    position: relative;
  }

  /* Target inputs inside CF7 wrapper spans */
  & .wpcf7-form-control-wrap input,
  & .wpcf7-form-control-wrap textarea,
  & .wpcf7-form-control-wrap select,
  & .wpcf7-form-control-wrap .select_container select {
    width: 100%;
    padding: 1.5rem 1rem 0.5rem;
    background: var(--input-bg) !important;
    border: 1px solid var(--input-border);
    border-radius: var(--input-radius);
    font-size: 0.95rem;
    color: var(--input-text);
    font-family: inherit;
    min-height: var(--input-min-height);
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
    margin: 0 !important;

    &:focus {
      outline: none;
      border-color: var(--input-focus);
      box-shadow: 0 0 0 3px var(--input-focus-ring);
    }
  }

  & .wpcf7-form-control-wrap textarea {
    min-height: 8rem;
    resize: vertical;
  }

  & .wpcf7-form-control-wrap .select_container {
    all: unset;
    display: block;

    & select {
      cursor: pointer;
      appearance: none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 1rem center;
      padding-right: 2.5rem;
    }
  }

  /* Label base positioning for inputs - vertically centered */
  & > label {
    position: absolute;
    top: calc(var(--input-min-height) / 2);
    left: 1rem;
    color: var(--input-text-secondary);
    pointer-events: none;
    transform: translateY(-50%);
    transition: all 0.2s ease-out;
    font-size: 1rem;
    line-height: 1;
    z-index: 1;
  }

  /* Label positioning for textarea - near the top instead of centered */
  &:has(textarea) > label {
    top: 1.25rem;
    transform: translateY(-50%);
  }

  /* Floated label state for inputs */
  &:has(input:focus) > label,
  &:has(input:not(:placeholder-shown)) > label,
  &:has(select:focus) > label,
  &:has(select) > label {
    top: 0.5rem;
    transform: translateY(0);
    font-size: 0.75rem;
    color: var(--input-focus);
    font-weight: 600;
  }

  /* Floated label state for textarea */
  &:has(textarea:focus) > label,
  &:has(textarea:not(:placeholder-shown)) > label {
    top: 0.5rem;
    transform: translateY(0);
    font-size: 0.75rem;
    color: var(--input-focus);
    font-weight: 600;
  }

  /* Error message - position absolutely below the input */
  & .wpcf7-not-valid-tip {
    position: absolute;
    left: 0;
    color: #ef4444;
    font-size: 0.75rem;
    line-height: 1;
    white-space: nowrap;
    margin-bottom: 0 !important;
  }

  /* Error state styling */
  &:has(.wpcf7-not-valid) {
    & input,
    & textarea,
    & select {
      border-color: #ef4444;
    }

    & > label {
      color: #ef4444;
    }
  }
}

/* Form grid layout */
.cf7-form-container {
  container-type: inline-size;

  .cf7-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    container-type: inline-size;

    @container (width <= 600px) {
      gap: 1rem;
    }

    @container (width <= 480px) {
      grid-template-columns: 1fr;
    }

    & .full-width {
      grid-column: 1 / -1;
    }
  }
}

/* CF7 validation error styling */
.wpcf7-not-valid-tip {
  color: #ef4444;
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.floating-group:has(.wpcf7-not-valid) {
  & input,
  & textarea,
  & select {
    border-color: #ef4444;
  }

  & > label {
    color: #ef4444;
  }
}

/* Reset CF7 theme wrapper styles */
.floating-group .select_container {
  all: unset;
  display: block;
}

.floating-group .wpcf7-form-control-wrap {
  display: block;
}

/* Add class to not show wrapper elements for hidden sections */
.hide-for-conditional:not(:has(.wpcf7cs-section[data-open])):not(:has(.wpcf7cs-section[data-animating])) {
    display: none;
}
