/* ============================================================================
   Form Styles
   ============================================================================ */

.form,
.form-card {
  padding: 1.5rem;
}

.form-card {
  margin-top: 1rem;
}

.form-section,
.settings-section {
  margin-bottom: 1.75rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--clr-border);
}

/* Last section drops its rule, the action bar draws its own */
.form-section:last-child,
.settings-section:last-child,
.form-section:last-of-type:has(~ .form-actions) {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

/* The "Fields marked * are required" note that opens a form */
.form > .help-text:first-child {
  margin: 0 0 1rem;
}

/* A group of related controls (checkboxes, repeated rows) */
fieldset.form-group {
  border: 0;
  min-width: 0;
}

.form-section h2 {
  margin: 0 0 0.875rem 0;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label,
.form-group legend,
.photo-lightbox-attribute label {
  display: block;
  font-size: var(--text-base);
  font-weight: 600;
  margin-bottom: 0.375rem;
}

/* One look for every text control, :where() lets one class override it */
input:where(
    :not(
      [type="checkbox"],
      [type="radio"],
      [type="file"],
      [type="range"],
      [type="color"],
      [type="submit"],
      [type="reset"],
      [type="button"],
      [type="image"]
    )
  ),
textarea,
select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--clr-border-light);
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-family: inherit;
  color: var(--clr-text);
  background: var(--clr-surface);
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
}

textarea {
  resize: vertical;
}

/* Undo Safari's inset search styling, keep the clear button */
input[type="search"] {
  appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--clr-accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--clr-accent) 10%, transparent);
}

input:disabled,
textarea:disabled,
select:disabled {
  background: var(--clr-bg);
  color: var(--clr-text-muted);
  cursor: not-allowed;
}

.form-group input:not([type="checkbox"], [type="radio"], [type="file"]),
.form-group textarea,
.form-group select {
  width: 100%;
}

/* Notes around a control: help and errors under it, hints above */
.help-text,
.form-hint,
.field-error {
  font-size: var(--text-md);
  line-height: 1.45;
  max-width: 70ch;
}

.help-text {
  color: var(--clr-text-muted);
  margin-top: 0.375rem;
}

/* Help that comes before its control (a picker, a list of rows) */
.help-text-lead {
  margin: 0 0 0.4rem 0;
}

.url-list-add {
  margin-top: 0.375rem;
}

/* Browser defaults vary, the muted token is 7:1 everywhere */
::placeholder {
  color: var(--clr-text-muted);
  opacity: 1;
}

/* Under the submit button */
.form-footer-note {
  margin: 0.75rem 0 0;
  text-align: center;
}

.form-hint {
  color: var(--clr-text-muted);
  margin: -0.125rem 0 0.5rem;
}

.field-error {
  color: var(--clr-error-text);
  margin-top: 0.375rem;
}

input.has-error,
textarea.has-error,
select.has-error {
  border-color: var(--clr-error);
}

/* Password field with a Show / Hide toggle */
.password-field {
  position: relative;
}

.password-field input {
  padding-right: 4rem;
}

/* Fills the input's height, so the whole right end is the target */
.password-toggle {
  position: absolute;
  top: 0.125rem;
  bottom: 0.125rem;
  right: 0.375rem;
  display: inline-flex;
  align-items: center;
  padding: 0 0.375rem;
  font-size: var(--text-sm);
  color: var(--clr-accent);
}

.password-toggle:hover {
  text-decoration: underline;
}

.password-toggle:disabled {
  color: var(--clr-text-muted);
  cursor: not-allowed;
  text-decoration: none;
}

/* Multi-URL input rows (profile-edit attribution/website lists) */
.url-entry {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.4rem;
}

.url-entry .url-label {
  flex: 1;
}
.url-entry .url-url {
  flex: 2;
}

/* Remove-row buttons: website rows, coordinator list */
.remove-url-btn,
.coordinator-remove {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  font-size: var(--text-xl);
  line-height: 1;
  border: 1px solid var(--clr-border-strong);
  border-radius: var(--radius);
  background: var(--clr-surface);
  cursor: pointer;
  color: var(--clr-text-muted);
}

.remove-url-btn:hover,
.coordinator-remove:hover {
  background: var(--clr-error-bg);
  border-color: var(--clr-error);
  color: var(--clr-error);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--clr-border);
  /* Long forms: Save stays in reach while the form is on screen */
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: var(--clr-surface);
}

/* Checkbox / Radio chip groups */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3125rem 0.625rem;
  border: 1px solid var(--clr-border-strong);
  border-radius: var(--radius);
  font-size: var(--text-md);
  font-weight: 400;
  cursor: pointer;
  background: var(--clr-bg);
  color: var(--clr-text);
  transition:
    border-color var(--transition),
    background var(--transition);
  user-select: none;
  line-height: 1.35;
}

.checkbox-label:hover {
  border-color: var(--clr-accent);
  background: var(--clr-accent-bg);
}

.checkbox-label input[type="checkbox"],
.checkbox-label input[type="radio"] {
  width: var(--text-md);
  height: var(--text-md);
  flex-shrink: 0;
  accent-color: var(--clr-accent);
  cursor: pointer;
}

/* Who sees an answer, beside the label on the application form */
.field-privacy {
  display: inline-block;
  margin-left: 0.5rem;
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--clr-text-muted);
  white-space: nowrap;
}

/* A lone checkbox with its label, no chip chrome */
.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: normal;
  cursor: pointer;
}

.checkbox-label:has(input:checked) {
  border-color: var(--clr-accent);
  background: var(--clr-tag-subj);
  color: var(--clr-accent-dark);
  font-weight: 500;
}

/* Avatar Upload */
.avatar-upload {
  display: flex;
  gap: 1.5rem;
  align-items: start;
}

.avatar-preview {
  flex-shrink: 0;
}

.avatar-actions {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.avatar-actions .button {
  width: fit-content;
}

/* Lookup pickers: input + button, then a row per candidate */
.lookup-row {
  display: flex;
  gap: 0.5rem;
}

.lookup-row input {
  flex: 1;
}

.lookup-results {
  margin: 0.25rem 0 0;
  display: flex;
  flex-direction: column;
}

.lookup-result {
  width: 100%;
  text-align: left;
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid var(--clr-border);
  font-size: var(--text-md);
  color: var(--clr-text);
}

.lookup-result:hover {
  background: var(--clr-bg);
  color: var(--clr-accent);
}

/* Equipment pickers: chips above a combobox (public/js/equipment.js) */
.equipment-search-wrap {
  position: relative;
}

.equipment-search {
  width: 100%;
  padding: 0.4rem 0.6rem;
}

/* Chips above the search box, so an empty list adds no gap */
.equipment-selected:not(:empty) {
  margin-bottom: 0.5rem;
}

.equipment-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--clr-accent);
  color: var(--clr-header-text);
  border-radius: var(--radius-pill);
  padding: 0.2rem 0.6rem 0.2rem 0.7rem;
  font-size: var(--text-md);
}

.equipment-pill-remove {
  color: var(--clr-header-text);
  font-size: var(--text-lg);
  line-height: 1;
  opacity: 0.8;
}

.equipment-pill-remove:hover {
  opacity: 1;
}

.equipment-options {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 13.75rem;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow);
}

/* Focus stays in the search box. aria-activedescendant marks the active row */
.equipment-option {
  padding: 0.45rem 0.75rem;
  text-align: left;
  cursor: pointer;
  font-size: var(--text-base);
}

.equipment-option:hover {
  background: var(--clr-bg);
}

/* Keyboard position must stand out more than hover */
.equipment-option.is-active {
  background: var(--clr-bg);
  box-shadow: inset 3px 0 0 var(--clr-accent);
}

/* Free text sits apart from the catalog rows above it */
.equipment-option--add {
  border-top: 1px solid var(--clr-border);
  background: var(--clr-bg);
  font-size: var(--text-sm);
  color: var(--clr-text-muted);
}

.equipment-option--note {
  color: var(--clr-text-muted);
  cursor: default;
}

.equipment-option--note:hover {
  background: none;
}

/* Searchable single-pick selects (public/js/search-select.js) */
.search-select {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-select input {
  width: 100%;
}

.search-select-options {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 13.75rem;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow);
}

.search-select-option {
  padding: 0.45rem 0.75rem;
  text-align: left;
  cursor: pointer;
  font-size: var(--text-base);
}

.search-select-option:hover {
  background: var(--clr-bg);
}

/* Keyboard position must stand out more than hover */
.search-select-option.is-active {
  background: var(--clr-bg);
  box-shadow: inset 3px 0 0 var(--clr-accent);
}

.search-select-option--note {
  color: var(--clr-text-muted);
  cursor: default;
}

.search-select-option--note:hover {
  background: none;
}

/* Mobile */
/* Two fields side by side */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  /* Row's last .form-group drops its margin, so the row carries it */
  margin-bottom: 1rem;
}

@media (max-width: 768px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .form {
    padding: 1rem;
  }

  .form-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
  }

  .avatar-upload {
    flex-direction: column;
    text-align: center;
  }

  .avatar-actions {
    align-items: center;
  }

  /* Phone: label and URL stack, one-field rows keep the button beside */
  .url-entry {
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
  }

  .url-entry .url-label:not(:last-of-type) {
    flex: 1 0 100%;
  }

  .url-entry .url-url {
    flex: 1;
  }
}
