/**
 * Bakery Forms — Public form styles (WCAG 2.1 AA).
 */

/* ── Screen reader only utility ── */

.bakery-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Wrapper ── */

.bakery-form-wrapper {
  --bakery-form-font:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    sans-serif;
  --bakery-form-border: #94a3b8;
  --bakery-form-focus: #2563eb;
  --bakery-form-error: #b91c1c;
  --bakery-form-success: #15803d;
  --bakery-form-text: #1e293b;
  --bakery-form-muted: #475569;
  --bakery-form-bg: #fff;
  --bakery-form-radius: 6px;
  font-family: var(--bakery-form-font);
  color: var(--bakery-form-text);
  max-width: 640px;
}

.bakery-form-title {
  margin: 0 0 24px;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--bakery-form-text);
}

/* ── Fields ── */

.bakery-form-field {
  margin-bottom: 20px;
}

.bakery-form-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--bakery-form-text);
}

.bakery-form-field input[type="text"],
.bakery-form-field input[type="email"],
.bakery-form-field input[type="url"],
.bakery-form-field input[type="tel"],
.bakery-form-field input[type="number"],
.bakery-form-field input[type="date"],
.bakery-form-field select,
.bakery-form-field textarea {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--bakery-form-text);
  background: var(--bakery-form-bg);
  border: 1px solid var(--bakery-form-border);
  border-radius: var(--bakery-form-radius);
  box-sizing: border-box;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.bakery-form-field input:focus,
.bakery-form-field select:focus,
.bakery-form-field textarea:focus {
  outline: 2px solid var(--bakery-form-focus);
  outline-offset: 2px;
  border-color: var(--bakery-form-focus);
}

.bakery-form-field textarea {
  resize: vertical;
  min-height: 100px;
}

/* ── Checkboxes and Radios ── */

.bakery-form-field fieldset {
  border: none;
  margin: 0;
  padding: 0;
}

.bakery-form-field legend {
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--bakery-form-text);
}

.bakery-form-radio-option,
.bakery-form-checkbox-option,
.bakery-form-checkbox-single {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.bakery-form-radio-option input,
.bakery-form-checkbox-option input,
.bakery-form-checkbox-single input {
  width: 18px;
  height: 18px;
  margin: 0;
  flex-shrink: 0;
}

.bakery-form-radio-option input:focus,
.bakery-form-checkbox-option input:focus,
.bakery-form-checkbox-single input:focus {
  outline: 2px solid var(--bakery-form-focus);
  outline-offset: 2px;
}

.bakery-form-radio-option label,
.bakery-form-checkbox-option label,
.bakery-form-checkbox-single label {
  display: inline;
  margin-bottom: 0;
  font-weight: 400;
}

/* ── File input (Phase F2) ── */

.bakery-form-field input[type="file"] {
  font-size: 0.875rem;
  padding: 8px 0;
}

.bakery-form-field input[type="file"]:focus {
  outline: 2px solid var(--bakery-form-focus);
  outline-offset: 2px;
}

.bakery-form-field input[type="file"][aria-invalid="true"] {
  outline: 2px solid var(--bakery-form-error);
  outline-offset: 2px;
}

.bakery-file-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bakery-file-list__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  font-size: 0.8125rem;
  color: var(--bakery-form-text);
  max-width: 100%;
}

.bakery-file-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.bakery-file-size {
  color: var(--bakery-form-muted);
  font-variant-numeric: tabular-nums;
}

.bakery-file-progress:not(:empty) {
  display: block;
  margin-top: 6px;
  font-size: 0.8125rem;
  color: var(--bakery-form-muted);
  font-variant-numeric: tabular-nums;
}

.bakery-form-required {
  color: var(--bakery-form-error);
  margin-left: 2px;
}

/* ── Help text ── */

.bakery-form-help {
  margin-top: 4px;
  font-size: 0.8125rem;
  color: var(--bakery-form-muted);
}

/* ── Error messages ── */

.bakery-form-error:not(:empty) {
  margin-top: 4px;
  font-size: 0.8125rem;
  color: var(--bakery-form-error);
  font-weight: 500;
}

/* ── Submit button ── */

.bakery-form-submit {
  margin-top: 24px;
}

.bakery-form-button {
  display: inline-block;
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--bakery-form-focus);
  border: none;
  border-radius: var(--bakery-form-radius);
  cursor: pointer;
  transition: background-color 0.15s;
}

.bakery-form-button:hover {
  background: #1d4ed8;
}

.bakery-form-button:focus-visible {
  outline: 2px solid var(--bakery-form-focus);
  outline-offset: 2px;
}

.bakery-form-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.bakery-form-button[aria-busy="true"] {
  position: relative;
  color: transparent;
}

.bakery-form-button[aria-busy="true"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: bakery-spin 0.6s linear infinite;
}

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

/* ── Multi-step progress ── */

.bakery-form-progress {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  gap: 4px;
  counter-reset: step;
}

.bakery-form-progress__step {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  font-size: 13px;
  color: #94a3b8;
  position: relative;
}

.bakery-form-progress__step::after {
  content: "";
  flex: 1;
  height: 2px;
  background: #e2e8f0;
  margin-left: 6px;
}

.bakery-form-progress__step:last-child::after {
  display: none;
}

.bakery-form-progress__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #e2e8f0;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.bakery-form-progress__step--active {
  color: #1e293b;
}

.bakery-form-progress__step--active .bakery-form-progress__num {
  border-color: #2563eb;
  background: #2563eb;
  color: #fff;
}

.bakery-form-progress__step--completed {
  color: #16a34a;
}

.bakery-form-progress__step--completed .bakery-form-progress__num {
  border-color: #16a34a;
  background: #16a34a;
  color: #fff;
}

.bakery-form-progress__step--completed::after {
  background: #16a34a;
}

.bakery-form-nav {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.bakery-form-nav__back {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.bakery-form-nav__back:hover {
  background: #e2e8f0;
}

/* ── Lookup field (combobox) ── */

.bakery-form-lookup {
  position: relative;
}

.bakery-form-lookup__search {
  width: 100%;
}

.bakery-form-lookup__results {
  display: none;
  position: absolute;
  z-index: 100;
  left: 0;
  right: 0;
  top: 100%;
  margin: 2px 0 0;
  padding: 4px 0;
  list-style: none;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  max-height: 200px;
  overflow-y: auto;
}

.bakery-form-lookup__search[aria-expanded="true"]
  + .bakery-form-lookup__results {
  display: block;
}

.bakery-form-lookup__option {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
}

.bakery-form-lookup__option:hover,
.bakery-form-lookup__option--active {
  background: #eff6ff;
  color: #1e40af;
}

.bakery-form-lookup__option:focus {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
}

@media (prefers-reduced-motion: reduce) {
  .bakery-form-button[aria-busy="true"]::after {
    animation: none;
    border: 2px solid #fff;
    border-top-color: transparent;
  }

  .bakery-form-button[aria-busy="true"] {
    color: #fff;
  }
}

/* ── Status messages ── */

.bakery-form-status:not(:empty) {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--bakery-form-radius);
  font-size: 0.9375rem;
}

.bakery-form-status--success {
  background: #f0fdf4;
  color: var(--bakery-form-success);
  border: 1px solid #86efac;
}

.bakery-form-status--error {
  background: #fef2f2;
  color: var(--bakery-form-error);
  border: 1px solid #fca5a5;
}

/* ── Login required ── */

.bakery-form-login-required {
  padding: 16px;
  background: #f8fafc;
  border: 1px solid var(--bakery-form-border);
  border-radius: var(--bakery-form-radius);
  color: var(--bakery-form-muted);
}

/* ── Responsive ── */

@media (max-width: 480px) {
  .bakery-form-wrapper {
    max-width: 100%;
  }

  .bakery-form-button {
    width: 100%;
    text-align: center;
  }
}

/* ── Repeater fields ── */

.bakery-form-repeater {
  border: 1px solid var(--bakery-border, #e2e8f0);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}

.bakery-form-repeater legend {
  font-weight: 600;
  font-size: 15px;
  padding: 0 4px;
}

.bakery-form-repeater__row {
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 12px 40px 12px 12px;
  margin-bottom: 8px;
  position: relative;
  display: grid;
  gap: 8px;
}

.bakery-form-repeater__row .bakery-form-field {
  margin-bottom: 0;
}

.bakery-form-repeater__remove {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #fff;
  border: 1px solid #dc2626;
  color: #dc2626;
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
  transition:
    background 0.15s,
    color 0.15s;
}

.bakery-form-repeater__remove:hover {
  background: #dc2626;
  color: #fff;
}

.bakery-form-repeater__remove:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.bakery-form-repeater__add {
  margin-top: 8px;
}

.bakery-form-repeater__add:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.bakery-form-repeater__live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
