/* Wrench Cove form design system (wc-forms)
   One visual language for every portal control.
   Scoped to body.portal-body so marketing pages stay independent.
   Compatible with English/Spanish: no English-width locks, wrap-friendly labels.
*/

:root {
  --wc-control-h: 44px;
  --wc-control-radius: 12px;
  --wc-control-pad-x: 0.85rem;
  --wc-control-pad-y: 0.65rem;
  --wc-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

[data-fd-theme="dark"] {
  --wc-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23cbd5e1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* ------------------------------------------------------------------ */
/* Shared text / select / textarea surface                             */
/* ------------------------------------------------------------------ */
body.portal-body :is(
  input:not([type]),
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  input[type="number"],
  input[type="date"],
  input[type="datetime-local"],
  input[type="time"],
  input[type="month"],
  input[type="week"],
  textarea,
  select
):not(.wc-unstyled):not([hidden]) {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: var(--wc-control-h);
  box-sizing: border-box;
  margin: 0;
  padding: var(--wc-control-pad-y) var(--wc-control-pad-x);
  border: 1px solid var(--fd-border-strong);
  border-radius: var(--wc-control-radius);
  background-color: var(--fd-surface);
  background-image: none;
  color: var(--fd-ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1.35;
  color-scheme: inherit;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

body.portal-body textarea:not(.wc-unstyled) {
  min-height: 110px;
  resize: vertical;
  padding-top: 0.75rem;
}

body.portal-body select:not(.wc-unstyled):not([hidden]) {
  padding-right: 2.4rem;
  background-image: var(--wc-chevron);
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  background-size: 1rem;
  cursor: pointer;
}

body.portal-body select:not(.wc-unstyled) option,
body.portal-body select:not(.wc-unstyled) optgroup {
  background-color: var(--fd-surface);
  color: var(--fd-ink);
}

body.portal-body :is(
  input:not([type]),
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  input[type="number"],
  input[type="date"],
  input[type="datetime-local"],
  input[type="time"],
  textarea,
  select
):not(.wc-unstyled)::placeholder {
  color: var(--fd-ink-faint);
  opacity: 1;
}

body.portal-body :is(
  input:not([type]),
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  input[type="number"],
  input[type="date"],
  input[type="datetime-local"],
  input[type="time"],
  textarea,
  select
):not(.wc-unstyled):hover:not(:disabled):not([aria-disabled="true"]) {
  border-color: var(--fd-border-strong);
}

body.portal-body :is(
  input:not([type]),
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  input[type="number"],
  input[type="date"],
  input[type="datetime-local"],
  input[type="time"],
  textarea,
  select
):not(.wc-unstyled):focus,
body.portal-body :is(
  input:not([type]),
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  input[type="number"],
  input[type="date"],
  input[type="datetime-local"],
  input[type="time"],
  textarea,
  select
):not(.wc-unstyled):focus-visible {
  outline: 2px solid var(--fd-accent);
  outline-offset: 2px;
  border-color: var(--fd-accent);
  box-shadow: 0 0 0 4px var(--fd-focus-ring);
}

body.portal-body :is(input, textarea, select):not(.wc-unstyled):disabled,
body.portal-body :is(input, textarea, select):not(.wc-unstyled)[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  background-color: var(--fd-surface-2);
}

body.portal-body :is(input, textarea, select).is-error,
body.portal-body :is(input, textarea, select)[aria-invalid="true"] {
  border-color: var(--fd-overdue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--fd-overdue) 18%, transparent);
}

body.portal-body :is(input, textarea, select).is-success {
  border-color: var(--fd-ok);
}

/* Browser autofill should stay on the shop surface, not flash white. */
body.portal-body input:not(.wc-unstyled):-webkit-autofill,
body.portal-body input:not(.wc-unstyled):-webkit-autofill:hover,
body.portal-body input:not(.wc-unstyled):-webkit-autofill:focus {
  -webkit-text-fill-color: var(--fd-ink);
  caret-color: var(--fd-ink);
  box-shadow: 0 0 0 1000px var(--fd-surface) inset;
  transition: background-color 9999s ease-out;
}

/* Keep the list-toolbar search icon gutter. */
body.portal-body .ui-search > input,
body.portal-body .ui-search input[type="search"] {
  padding-left: 2.15rem;
  background-color: var(--fd-surface-2);
}

/* Date / time keep native pickers; only the field chrome is ours. */
body.portal-body :is(input[type="date"], input[type="datetime-local"], input[type="time"], input[type="month"]) {
  min-width: 0;
}

/* Number inputs: no compressed spinner wells on mobile. */
body.portal-body input[type="number"] {
  min-width: 4.5rem;
}

/* ------------------------------------------------------------------ */
/* Field layout                                                        */
/* ------------------------------------------------------------------ */
body.portal-body .ui-field,
body.portal-body .wc-field {
  display: grid;
  gap: 0.35rem;
  margin: 0 0 0.85rem;
  min-width: 0;
}

body.portal-body .ui-field > label,
body.portal-body .wc-field > label,
body.portal-body .ui-field > legend,
body.portal-body .wc-field__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fd-ink-muted);
  line-height: 1.35;
}

body.portal-body .ui-field__hint,
body.portal-body .wc-field__hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--fd-ink-faint);
  line-height: 1.4;
}

body.portal-body .wc-field__error {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--fd-overdue);
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

/* Bare <label>Control</label> used on older screens. */
body.portal-body .ui-invite-form > label,
body.portal-body .wc-form > label,
body.portal-body form.ui-invite-form label:not(.ui-check):not(.fo-toggle):not(.ui-contact__toggle):not(.wc-check) {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fd-ink-muted);
}

body.portal-body .ui-invite-form,
body.portal-body .wc-form {
  display: grid;
  gap: 1rem;
  margin: 0 0 1.25rem;
  padding: 1.1rem 1.15rem;
  background: var(--fd-surface);
  border: 1px solid var(--fd-border);
  border-radius: var(--fd-radius);
  box-shadow: var(--fd-shadow);
  min-width: 0;
}

body.portal-body .ui-invite-form .ui-field,
body.portal-body .wc-form .ui-field,
body.portal-body .ui-invite-form .wc-field,
body.portal-body .wc-form .wc-field {
  margin-bottom: 0;
}

body.portal-body .ui-invite-form--embedded,
body.portal-body .wc-form--embedded,
body.portal-body .dispatch-card .ui-invite-form,
body.portal-body .ui-job-card .ui-invite-form {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  margin: 0.75rem 0 0;
}

body.portal-body .wc-form-grid,
body.portal-body .ui-invite-form--grid {
  display: grid;
  gap: 1rem;
  align-items: start;
}

@media (min-width: 720px) {
  body.portal-body .wc-form-grid,
  body.portal-body .ui-invite-form--grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1100px) {
  body.portal-body .wc-form-grid,
  body.portal-body .ui-invite-form--grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

body.portal-body .wc-form-grid .order-form-actions,
body.portal-body .ui-invite-form--grid .order-form-actions,
body.portal-body .wc-form-grid .wc-form__actions,
body.portal-body .wc-field--full,
body.portal-body .ui-field--full {
  grid-column: 1 / -1;
}

body.portal-body .wc-form-row,
body.portal-body .ui-invite-form--row {
  display: grid;
  gap: 0.75rem;
}

@media (min-width: 720px) {
  body.portal-body .wc-form-row,
  body.portal-body .ui-invite-form--row {
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    align-items: end;
  }
}

body.portal-body .wc-toolbar,
body.portal-body form.sites-toolbar,
body.portal-body form.fo-toolbar,
body.portal-body .ui-activity-filters,
body.portal-body .ui-schedule-filters,
body.portal-body .rpt-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}

body.portal-body .wc-toolbar > .ui-field,
body.portal-body .wc-toolbar > .wc-field,
body.portal-body .ui-activity-filters > .ui-field {
  margin: 0;
  flex: 1 1 11rem;
  min-width: min(100%, 11rem);
}

/* Override the leftover tiny schedule select. */
body.portal-body .ui-schedule-filters select {
  min-width: min(100%, 14rem);
  max-width: 100%;
  min-height: var(--wc-control-h);
  padding: var(--wc-control-pad-y) 2.4rem var(--wc-control-pad-y) var(--wc-control-pad-x);
  border-radius: var(--wc-control-radius);
  border: 1px solid var(--fd-border-strong);
  background-color: var(--fd-surface);
  background-image: var(--wc-chevron);
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  background-size: 1rem;
  color: var(--fd-ink);
}

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */
body.portal-body .btn-secondary {
  background: var(--fd-surface-2);
  color: var(--fd-ink) !important;
  border-color: var(--fd-border-strong);
}

body.portal-body .btn-secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--fd-accent-soft) 55%, var(--fd-surface-2));
}

body.portal-body .order-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* ------------------------------------------------------------------ */
/* Checkbox / radio — native control kept, larger target               */
/* ------------------------------------------------------------------ */
body.portal-body input[type="checkbox"]:not(.wc-unstyled),
body.portal-body input[type="radio"]:not(.wc-unstyled) {
  width: 1.2rem;
  height: 1.2rem;
  margin: 0.15rem 0 0;
  flex: 0 0 auto;
  accent-color: var(--fd-accent);
  cursor: pointer;
}

body.portal-body input[type="checkbox"]:focus-visible,
body.portal-body input[type="radio"]:focus-visible {
  outline: 2px solid var(--fd-accent);
  outline-offset: 3px;
}

body.portal-body .ui-check,
body.portal-body .wc-check,
body.portal-body .ui-list-toolbar__check,
body.portal-body .fo-toggle,
body.portal-body .ui-contact__toggle,
body.portal-body .auto-switch {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.45rem 0;
  font-size: 0.92rem;
  color: var(--fd-ink-muted);
  cursor: pointer;
}

body.portal-body .fo-toggle,
body.portal-body .auto-switch {
  align-items: center;
}

/* ------------------------------------------------------------------ */
/* File inputs — native input kept, chrome restyled                    */
/* ------------------------------------------------------------------ */
body.portal-body input[type="file"]:not(.wc-unstyled) {
  display: block;
  width: 100%;
  min-height: var(--wc-control-h);
  padding: 0.4rem 0.5rem;
  border: 1px dashed var(--fd-border-strong);
  border-radius: var(--wc-control-radius);
  background: var(--fd-surface-2);
  color: var(--fd-ink-muted);
  font: inherit;
  cursor: pointer;
}

body.portal-body input[type="file"]:not(.wc-unstyled)::file-selector-button {
  min-height: 36px;
  margin-right: 0.75rem;
  padding: 0.4rem 0.95rem;
  border: 0;
  border-radius: 10px;
  background: var(--fd-accent);
  color: var(--fd-on-accent, #fff);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

body.portal-body .wc-file {
  position: relative;
  display: grid;
  gap: 0.4rem;
}

body.portal-body .wc-file__ui {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  min-height: 3.25rem;
  padding: 0.55rem 0.75rem;
  border: 1px dashed var(--fd-border-strong);
  border-radius: var(--wc-control-radius);
  background: var(--fd-surface-2);
}

body.portal-body .wc-file__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0.35rem 0.9rem;
  border-radius: 10px;
  background: var(--fd-accent);
  color: var(--fd-on-accent, #fff);
  font-weight: 700;
}

body.portal-body .wc-file__name {
  color: var(--fd-ink-muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

body.portal-body .wc-file.is-enhanced input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* ------------------------------------------------------------------ */
/* Combobox                                                            */
/* ------------------------------------------------------------------ */
body.portal-body .wc-combobox {
  position: relative;
  min-width: 0;
}

body.portal-body .wc-combobox__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.portal-body .wc-combobox__input {
  padding-right: 2.4rem;
  background-image: var(--wc-chevron);
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  background-size: 1rem;
}

body.portal-body .wc-combobox.is-open .wc-combobox__input {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

body.portal-body .wc-combobox__list {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% - 1px);
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  max-height: min(18rem, 60vh);
  overflow: auto;
  background: var(--fd-surface);
  color: var(--fd-ink);
  border: 1px solid var(--fd-border-strong);
  border-top: 0;
  border-radius: 0 0 var(--wc-control-radius) var(--wc-control-radius);
  box-shadow: var(--fd-shadow-lg);
}

body.portal-body .wc-combobox__option {
  display: grid;
  gap: 0.1rem;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
}

body.portal-body .wc-combobox__option[aria-selected="true"],
body.portal-body .wc-combobox__option.is-active {
  background: var(--fd-accent-soft);
  color: var(--fd-ink);
}

body.portal-body .wc-combobox__primary {
  font-weight: 650;
  overflow-wrap: anywhere;
}

body.portal-body .wc-combobox__secondary {
  font-size: 0.8rem;
  color: var(--fd-ink-muted);
  overflow-wrap: anywhere;
}

body.portal-body .wc-combobox__empty {
  padding: 0.7rem;
  color: var(--fd-ink-faint);
  font-size: 0.9rem;
}

/* Job-sheet team picker: native select becomes a full-width control. */
body.portal-body .who-team__picker {
  display: grid;
  gap: 0.5rem;
  align-items: stretch;
}

@media (min-width: 520px) {
  body.portal-body .who-team__picker {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }
}

body.portal-body .who-team__picker select,
body.portal-body .who-team__picker .wc-combobox {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}

body.portal-body .who-assign {
  max-width: none;
}

/* ------------------------------------------------------------------ */
/* Language switcher (present after the multilingual workstream lands) */
/* ------------------------------------------------------------------ */
body.portal-body .lang-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

body.portal-body .lang-switch select {
  width: auto;
  min-width: 8.5rem;
  min-height: 36px;
}

/* ------------------------------------------------------------------ */
/* Empty states used by redesigned admin lists                         */
/* ------------------------------------------------------------------ */
body.portal-body .wc-card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

body.portal-body .wc-card-list > li {
  margin: 0;
  padding: 0.95rem 1.05rem;
  background: var(--fd-surface);
  border: 1px solid var(--fd-border);
  border-radius: var(--fd-radius);
  box-shadow: var(--fd-shadow);
}

body.portal-body .wc-card-list__title {
  margin: 0;
  font-weight: 700;
  color: var(--fd-ink);
}

body.portal-body .wc-card-list__meta {
  margin: 0.3rem 0 0;
  color: var(--fd-ink-muted);
  font-size: 0.9rem;
}

/* ------------------------------------------------------------------ */
/* Mobile                                                              */
/* ------------------------------------------------------------------ */
@media (max-width: 720px) {
  body.portal-body .dispatch-card { display: block; }
  body.portal-body .dispatch-card form { display: grid; gap: 0.4rem; }
}

@media (max-width: 719px) {
  body.portal-body .ui-invite-form,
  body.portal-body .wc-form,
  body.portal-body .wc-toolbar,
  body.portal-body form.sites-toolbar,
  body.portal-body .ui-activity-filters,
  body.portal-body .rpt-filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  body.portal-body .ui-invite-form .btn,
  body.portal-body .wc-form .btn,
  body.portal-body .wc-toolbar .btn {
    width: 100%;
  }
}
