// Copyright (C) 2023 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

@import "../assets/theme";

.pf-form {
  display: flex;
  flex-direction: column;

  &__button-bar {
    display: flex;
    justify-content: right;
    flex-direction: row-reverse;
    align-items: baseline;
    gap: 4px;
  }

  &__label {
    margin-bottom: 6px;
    font-size: smaller;
    font-weight: 500;
  }

  &__row {
    display: grid;
    gap: 8px 16px;
  }

  &__grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0 8px;
    align-items: baseline;
  }

  &__section {
    border: 1px solid var(--pf-color-border);
    display: flex;
    flex-direction: column;
    border-radius: 4px;
    padding: 8px;
    margin: 0; // Reset default fieldset margin
    margin-bottom: 8px;

    &-label {
      font-weight: 500;
      text-transform: uppercase;
      font-size: 0.7em;
      color: var(--pf-color-text-muted);
      padding: 0 2px;
    }
  }

  // Styles for common input elements
  .pf-checkbox,
  .pf-switch,
  .pf-radio-group {
    margin-bottom: 10px;
  }

  .pf-select,
  .pf-text-input {
    margin-bottom: 8px;
  }

  .pf-select:invalid {
    border-color: var(--pf-color-danger);
    &:active,
    &:focus {
      border-color: var(--pf-color-danger);
    }
  }

  .pf-text-input:has(input:invalid) {
    border-color: var(--pf-color-danger);
    &:has(input:focus) {
      border-color: var(--pf-color-danger);
    }
  }
}

// Add some spacing around forms when placed inside a menu
.pf-menu {
  .pf-form {
    // Compensate for the uneven |4px 0| padding in pf-menu, resulting in an
    // even 4px padding all around the form.
    margin: 0 4px;
  }
}
