/* ---- 10. Forms ------------------------------------------------------------ */

article {
  background: var(--ta-surface);
  border: 1px solid var(--ta-border);
  border-radius: var(--ta-r);
  padding: 1.5rem 1.75rem;
}

article h2,
article h3 {
  margin-top: 0;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ta-text);
}

/* Base controls. `:where()` keeps this at element specificity so the
   type-specific rules below (search icon, select chevron) can override. */
input:where(:not([type="checkbox"]):not([type="radio"]):not([type="file"])),
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--ta-border-strong);
  border-radius: var(--ta-r-sm);
  background: var(--ta-surface);
  color: var(--ta-text);
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input:where(:not([type="checkbox"]):not([type="radio"]):not([type="file"])):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--ta-accent);
  box-shadow: 0 0 0 3px var(--ta-accent-soft);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--ta-accent);
}

/* inline icons drawn as data-URIs — no asset requests */
input[type="search"] {
  appearance: none;
  -webkit-appearance: none;
  padding-left: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2398a0ab' stroke-width='1.5' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='4.5'/%3E%3Cpath d='M10.5 10.5 14 14'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.7rem center;
  background-size: 0.95em;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%238b919a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 0.9em;
}

textarea {
  font-family: var(--ta-mono);
  line-height: 1.5;
  resize: vertical;
}

input[type="file"] {
  color: var(--ta-muted);
  font-size: 0.9rem;
}

input[type="file"]::file-selector-button {
  margin-right: 0.75rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--ta-border-strong);
  border-radius: var(--ta-r-sm);
  background: var(--ta-surface-2);
  color: var(--ta-text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

/* ---- 10a. Data-driven form fields -----------------------------------------
   Each field's control is chosen by its data (see src/components/form.rs):
   long text becomes a textarea, small selects become segmented pills,
   relations become reference pickers, auto timestamps become read-only
   notes. The grid lays short fields side-by-side and spans textareas wide. */

.form-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

/* textarea / JSON editors span the full width */
.field-wide {
  grid-column: 1 / -1;
}

.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ta-text);
}

.field-label .req {
  color: var(--ta-err);
}

.field-hint {
  font-size: 0.78rem;
  color: var(--ta-faint);
  line-height: 1.4;
}

/* email fields get a mail glyph, the same way search gets its magnifier */
input[type="email"] {
  padding-left: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2398a0ab' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='1.5' y='3' width='13' height='10' rx='1.5'/%3E%3Cpath d='M2 4.5 8 9l6-4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.7rem center;
  background-size: 0.95em;
}

/* auto/maintained values are read-only notes, not inputs */
.auto-note {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border: 1px dashed var(--ta-border-strong);
  border-radius: var(--ta-r-sm);
  background: var(--ta-surface-2);
  color: var(--ta-muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.auto-note .auto-badge {
  padding: 0.06rem 0.45rem;
  border-radius: var(--ta-r-sm);
  background: var(--ta-accent-soft);
  color: var(--ta-accent);
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* segmented pill groups: discrete short choices (status, service type, …) */
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.seg-opt {
  position: relative;
  margin: 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ta-muted);
  cursor: pointer;
}

/* the real radio sits invisibly over the pill */
.seg-opt input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.seg-opt span {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--ta-border-strong);
  border-radius: var(--ta-r-sm);
  background: var(--ta-surface);
  color: inherit;
  white-space: nowrap;
  transition: border-color 0.12s ease, background-color 0.12s ease,
    color 0.12s ease;
}

.seg-opt:hover span {
  border-color: var(--ta-accent);
  color: var(--ta-text);
}

.seg-opt input:checked+span {
  border-color: var(--ta-accent);
  background: var(--ta-accent);
  color: #fff;
}

.seg-opt input:focus-visible+span {
  box-shadow: 0 0 0 3px var(--ta-accent-soft);
}

/* relation reference pickers carry a small availability hint */
.relation-meta {
  display: block;
  font-size: 0.78rem;
  color: var(--ta-faint);
}

/* Address lookup fields (`geocode: true`) — search-as-you-type over
   Nominatim + a small Leaflet preview (static/app/address-map-field.js). */
.address-field-control {
  position: relative;
}

input[data-address-input] {
  padding-left: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2398a0ab' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 1.5c-2.6 0-4.5 2-4.5 4.5C3.5 9.5 8 14.5 8 14.5S12.5 9.5 12.5 6c0-2.5-1.9-4.5-4.5-4.5z'/%3E%3Ccircle cx='8' cy='6' r='1.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.7rem center;
  background-size: 0.95em;
}

.address-results {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.3rem);
  left: 0;
  right: 0;
  max-height: 14rem;
  overflow: auto;
  border: 1px solid var(--ta-border-strong);
  border-radius: var(--ta-r-sm);
  background: var(--ta-surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  padding: 0.25rem;
}

.address-result {
  display: block;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 0;
  border-radius: var(--ta-r-sm);
  background: transparent;
  color: var(--ta-text);
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
}

.address-result:hover,
.address-result.active {
  background: var(--ta-surface-2);
}

.address-map {
  margin-top: 0.6rem;
  height: var(--address-map-h, 14rem);
  border-radius: var(--ta-r-sm);
  border: 1px solid var(--ta-border-strong);
  background: var(--ta-surface-2);
  overflow: hidden;
  /* Contain Leaflet's panes (z-index up to 700) so the map never paints
     over the address-results dropdown (z-index 20) or other overlays. */
  isolation: isolate;
}

/* A `map_type: dark` address field keeps the ops-map's night ground behind
   its tiles (the same #0b0f19 the estate map paints while tiles load). */
.address-field[data-map-type="dark"] .address-map {
  background: #0b0f19;
  border-color: rgba(125, 211, 252, 0.18);
}

/* The form's action row is a footer, not a joined control group: separated
   from the fields by a hairline, with the primary action closing on the
   right (the Cancel + Save pair every create/edit form shares). */
.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--ta-border);
}

.form-error {
  margin: 0 0 1rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--ta-err);
  border-radius: var(--ta-r-sm);
  background: rgba(214, 69, 69, 0.08);
  color: var(--ta-err);
  font-size: 0.9rem;
}

.json-input {
  font-family: var(--ta-mono);
}

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

/* API keys page (Settings → API keys): the "Label" field and Generate button
   sit on one line; on phones they stack so the input keeps a tappable width
   (and the article's `width:100%` keeps the row from blowing the pane). */
.api-keys-form {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 2rem;
}

@media (max-width: 640px) {
  .api-keys-form {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .api-keys-form label {
    flex: none;
    min-width: 0;
  }

  .api-keys-form .btn {
    width: 100%;
  }
}

/* ============================================================================
   PARITY B13 — forms, auth, search blocks (old core/app/components/blocks).
   The ports keep the old Tailwind classes verbatim; these tokens and bespoke
   rules supply what the app's token set / the tailwind bundle don't already.
   ========================================================================== */

/* Control-height tokens the old Input/Button/FieldSelect classes reference via
   `h-(--h-control)` — the reference's --h-control is 34px, --h-control-sm 22px. */
:root {
  --h-control: 34px;
  --h-control-sm: 22px;
  /* Old glass aliases the outline button + glass surfaces reference. */
  --glass-fill: var(--ta-glass);
  --glass-fill-strong: var(--ta-glass-strong);
  --glass-fill-solid: var(--ta-glass-solid);
  --glass-rim: var(--ta-glass-rim);
}

/* The old Panel/dropdown compose `.glass-card` (which adds padding + radius in
   vitrine.css) but own their box — zero the shared padding so the header /
   content paddings govern the inside. Element+class beats the late vitrine rule.
   A dropdown nested in a panel is also a nested glass surface, so it drops its
   shadow (the reference's nested-glass rule nulls it). */
.b13-panel.glass-card,
.b13-dropdown.glass-card {
  padding: 0;
}

.b13-panel .b13-dropdown {
  box-shadow: none;
}

/* The reference's control-height utility (`h-(--h-control)`) — the paren form
   can't be generated by the tailwind pipeline, so alias it as a plain class. */
.b13-h-control {
  height: var(--h-control);
}

/* The reference's `bg-(--glass-fill)` outline-button face, same alias. */
.b13-glass-fill {
  background-color: var(--glass-fill);
}

/* A native select standing in for the reference's Radix trigger: the
   "Select…" placeholder reads muted like the reference's data-placeholder
   state (the static render is always the placeholder state). The reference
   trigger is height-driven with 8px inline padding (the sample passes px-2),
   so zero the app's forms.css vertical padding and use 8px here. */
select.b13-select-placeholder {
  color: var(--ta-muted);
  padding: 0 8px;
}

/* The ai-prompt send button — the reference's `bg-primary text-primary-foreground
   size-8` icon face. The app's `button.unstyled` reset beats single utilities,
   so re-apply the face at the same specificity, later in the cascade. */
button.b13-send {
  height: 2rem;
  width: 2rem;
  padding: 0;
  border: 0;
  border-radius: var(--ta-r);
  background-color: var(--ta-accent);
  color: #fff;
  font-size: 1rem;
  line-height: 1.5;
  gap: normal;
}

button.b13-send:disabled {
  opacity: 0.4;
}

/* The app's forms.css adds a leading mail glyph to every email input; the
   reference's email fields are plain (px-3, no icon) — neutralize it on the
   B13 form/auth surfaces. */
.b13-panel input[type="email"],
.b13-dropdown input[type="email"],
#auth-form input[type="email"] {
  padding-left: 12px;
  background-image: none;
}

/* The primary button's lit surface — the reference's `.accent-grad` (app.css),
   remapped to the app's accent token. */
.accent-grad {
  background-color: var(--ta-accent);
  background-image: linear-gradient(180deg,
      color-mix(in oklab, var(--ta-accent) 86%, white) 0%,
      var(--ta-accent) 100%);
  box-shadow:
    inset 0 1px 0 oklch(1 0 0 / 0.25),
    0 4px 12px -2px color-mix(in oklab, var(--ta-accent) 35%, transparent);
}

.accent-grad:hover {
  background-image: linear-gradient(180deg,
      color-mix(in oklab, var(--ta-accent) 74%, white) 0%,
      color-mix(in oklab, var(--ta-accent) 92%, white) 100%);
}

/* The app's `button.unstyled` opt-out (buttons.css) resets colour/padding at
   (0,1,1) — higher than any single utility — so a REAL submit button that
   composes `.unstyled` (to escape the base accent paint) needs the full face
   re-applied at the same specificity, later in the cascade (forms.css loads
   after buttons.css). The reference button has no border and its line-height
   comes from the `text-sm` utility. */
button.accent-grad {
  height: var(--h-control);
  padding: 0 1rem;
  border: 0;
  border-radius: var(--ta-r);
  background-color: var(--ta-accent);
  background-image: linear-gradient(180deg,
      color-mix(in oklab, var(--ta-accent) 86%, white) 0%,
      var(--ta-accent) 100%);
  box-shadow:
    inset 0 1px 0 oklch(1 0 0 / 0.25),
    0 4px 12px -2px color-mix(in oklab, var(--ta-accent) 35%, transparent);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
}

button.accent-grad:hover {
  background-image: linear-gradient(180deg,
      color-mix(in oklab, var(--ta-accent) 74%, white) 0%,
      color-mix(in oklab, var(--ta-accent) 92%, white) 100%);
}

/* The reference's outline Button face (auth address "Find address").
   Same (0,1,1) override as button.accent-grad above. */
button.b13-outline {
  height: var(--h-control);
  padding: 0 1rem;
  border: 1px solid var(--ta-border);
  border-radius: var(--ta-r);
  background-color: var(--glass-fill);
  color: var(--ta-text);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--ta-shadow-xs);
}

button.b13-outline:hover {
  background-color: var(--ta-accent-soft);
  color: var(--ta-accent-hover);
}

/* The reference's checkboxes inherit their label's type (the old preflight
   gave form controls `font: inherit`); the app's base doesn't reset form
   fonts, so unchecked boxes fall to the UA's 13.33px Arial. */
.b13-checkbox {
  font: inherit;
  margin: 0;
}

/* The reference's custom text-scale utilities (old app.css @utility) that the
   tailwind bundle can't generate — used by the form/auth/search blocks. */
.text-label {
  font-size: 0.8125rem;
  line-height: 1.3;
  font-weight: 500;
  letter-spacing: 0;
}

.text-headline {
  font-size: 1.0625rem;
  line-height: 1.35;
  font-weight: 500;
  letter-spacing: -0.014em;
}

.text-mono-label {
  font-family: var(--ta-mono);
  font-size: 11px;
  line-height: 1.4;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ta-muted);
  font-variant-numeric: tabular-nums;
}

/* ---- Slider fields (confidence-style number fields + app settings) ------- */

/* The slider is the field's real input (carries `name`); the readout is a
   typeable display the JS keeps in sync. Row: track flexes, box is fixed. */
.slider-field {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.slider-field input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--ta-accent);
  cursor: pointer;
  height: 1.5rem;
}

/* WebKit/Gecko thumb + track, matching the accent. */
.slider-field input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--ta-border-strong);
}

.slider-field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  margin-top: -5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ta-accent);
  border: 2px solid var(--ta-surface);
  box-shadow: 0 0 0 1px var(--ta-accent);
}

.slider-field input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--ta-border-strong);
}

.slider-field input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ta-accent);
  border: 2px solid var(--ta-surface);
  box-shadow: 0 0 0 1px var(--ta-accent);
}

/* The live numeric readout beside the slider. A `percent` slider wraps it in
   `.slider-readout-wrap` and shows a muted "%" unit inside the box. */
.slider-field .slider-readout-wrap {
  position: relative;
  flex: 0 0 6rem;
  width: 6rem;
}

.slider-field .slider-readout {
  width: 100%;
  padding: 0.4rem 0.55rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* A percent readout makes room for its "%" unit inside the box. */
.slider-field .slider-readout-wrap:has(.slider-unit) .slider-readout {
  padding-right: 1.4rem;
}

.slider-field .slider-unit {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ta-muted);
  font-size: 0.8125rem;
  pointer-events: none;
}

/* ---- Account-level settings card (AppSettings block) ---------------------- */

.app-settings-card {
  max-width: 34rem;
}

.app-settings-card .app-settings-text {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--ta-muted);
}