/* ----------------------------------------------------------------------- */
/* Forms                                                                    */
/* ----------------------------------------------------------------------- */

label, .label {
  display: block;
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: var(--gap-2);
}
label .label-aside,
.label .label-aside {
  font-weight: 400;
  color: var(--ink-muted);
  font-size: 0.82rem;
}
label .req, .label .req { color: var(--err); margin-left: 2px; }

.field { margin-bottom: var(--gap-4); }
.field > .hint,
.field > p.hint {
  margin-top: var(--gap-1);
  font-size: 0.85rem;
  color: var(--ink-muted);
}
.field > .error {
  margin-top: var(--gap-1);
  font-size: 0.85rem;
  color: var(--err);
}

/* JS-applied marker — only set after the user has triggered validation
   (e.g. clicking Next on an empty required field). Using a class instead
   of `:invalid` / `:user-invalid` avoids painting fields red on first
   render before the user has had a chance to fill anything in, and gives
   us consistent cross-browser behavior (Safari only added :user-invalid
   support recently). The matching focus ring keeps the accent halo from
   stomping the red border when the field is focused after the error
   appears. */
.field--invalid > input,
.field--invalid > textarea,
.field--invalid > select {
  border-color: var(--err);
}
.field--invalid > input:focus,
.field--invalid > textarea:focus,
.field--invalid > select:focus {
  border-color: var(--err);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.18);
}

/* ----------------------------------------------------------------------- */
/* Field label row + info tooltip                                           */
/* ----------------------------------------------------------------------- */
/* For fields whose label needs an inline help affordance — use a small
   `?` button next to the label that reveals an explanation tooltip on
   hover/focus. Pattern:
     <div class="field">
       <div class="field__label-row">
         <label>Public host</label>
         <span class="info">
           <button type="button" class="info__btn"
                   aria-describedby="hint-app-host">
             <span aria-hidden="true">?</span>
             <span class="visually-hidden">More info</span>
           </button>
           <span class="info__tip" role="tooltip" id="hint-app-host">…</span>
         </span>
       </div>
       <input … />
     </div>
   ARIA: the button references the tooltip via aria-describedby so
   screen readers announce the explanation when the trigger is focused
   even when the visual tooltip is hidden. CSS handles the visual
   reveal via :hover / :focus-within. */

.field__label-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: var(--gap-2);
}
.field__label-row > label {
  margin-bottom: 0;  /* override .field > label margin-bottom */
}

.info { position: relative; display: inline-flex; }

.info__btn {
  /* :where() so this button-inside-button scenario doesn't clash with
     the global button defaults; the icon is a tiny circular control,
     not a primary action. */
  width: 1.05rem;
  height: 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--ink-faint);
  border-radius: 50%;
  color: var(--ink-muted);
  cursor: help;
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  transition: border-color 0.12s, color 0.12s;
}
.info__btn:hover,
.info__btn:focus-visible {
  background: transparent;
  border-color: var(--ink-soft);
  color: var(--ink);
  transform: none;
}

.info__tip {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  z-index: 20;
  background: var(--ink);
  color: var(--bg);
  padding: var(--gap-2) var(--gap-3);
  border-radius: var(--radius-sm);
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 400;
  line-height: 1.45;
  width: max-content;
  max-width: 22rem;
  white-space: normal;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}
.info__tip code {
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  padding: 0 0.25rem;
  border-radius: 2px;
  font-size: 0.95em;
}

.info:hover .info__tip,
.info:focus-within .info__tip {
  opacity: 1;
  visibility: visible;
}

/* ----------------------------------------------------------------------- */
/* Attachment chips                                                          */
/* ----------------------------------------------------------------------- */
/* Inline-block file affordance — used by /organizations/:id Notes and any
   future "list of downloadable attachments" view. The whole chip is one
   link, so the entire surface is a click target (better Fitts than just
   the filename). Wrap container `.attachment-chips` is a list with bare
   markers; chips wrap to new rows on narrow viewports. */

.attachment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-2);
  padding: 0;
  margin: 0;
  list-style: none;
}

.attachment-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.35rem 0.65rem;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.attachment-chip:hover,
.attachment-chip:focus-visible {
  border-color: var(--rule-strong);
  background: var(--surface);
  color: var(--accent);
}
.attachment-chip__name {
  font-weight: 500;
  word-break: break-word;
}
.attachment-chip__size {
  font-size: 0.78rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="url"], input[type="tel"], input[type="number"], input[type="date"],
input[type="datetime-local"], input[type="time"], input[type="month"],
input[type="week"], input[type="file"],
textarea, select {
  width: 100%;
  font-family: var(--sans);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  line-height: 1.4;
  -webkit-appearance: none;
          appearance: none;
}
/* File input outer padding tuned so the box's overall height matches
   sibling text inputs (~41px) when the button drives the line-box —
   the button is taller than the filename text, so the input's line
   height is button-determined. Symmetric vertical padding around it
   keeps the button visually centered.
   Why not `display: flex; align-items: center` — `::file-selector-
   button` lives in the input's UA shadow DOM, not as a regular flex
   child, and browsers don't honor flex on it consistently. The
   padding-and-line-height approach works everywhere. */
input[type="file"] {
  padding: 0.45rem 0.7rem;
  font-family: var(--sans);
  font-size: 0.9rem;
  cursor: pointer;
}
/* The "Choose file" pseudo-button — browsers ship it tiny and
   inconsistent. Restyle to match our other form chrome (surface-2
   background, rule-strong border, accent on hover). `line-height: 1`
   tightens the button so it doesn't push the input taller than its
   text-input siblings; `vertical-align: middle` belt-and-braces the
   centering against any baseline-alignment quirks vs the
   "(no file chosen)" filename text on the same line. */
input[type="file"]::file-selector-button {
  margin-right: 0.7rem;
  padding: 0.25rem 0.85rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  vertical-align: middle;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
input[type="file"]::file-selector-button:hover {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--accent);
}
textarea {
  resize: vertical;
  min-height: 5rem;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(233, 78, 27, 0.18);
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
input:disabled, textarea:disabled, select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 50%,
    calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 1.75rem;
}

input[type="checkbox"], input[type="radio"] {
  width: auto;
  margin-right: 0.4rem;
  accent-color: var(--accent);
}
.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 400;
  color: var(--ink);
  margin-bottom: 0;
  cursor: pointer;
}

fieldset {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--gap-4) var(--gap-5);
  margin: 0 0 var(--gap-4);
}
fieldset legend {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  padding: 0 var(--gap-2);
}

/* Checkbox / radio groups (vertical list of inline-checks) */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: var(--gap-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  padding: var(--gap-3) var(--gap-4);
}

/* Readonly field (zendesk_user picker on the web) */
.readonly-field {
  display: flex;
  align-items: center;
  gap: var(--gap-3);
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--rule);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-family: var(--sans);
  font-size: 0.92rem;
}
.readonly-field .tiny { margin-left: auto; }

/* Filter chips */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-2);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-pill);
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0;
  font-weight: 500;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chip input { display: none; }
.chip:hover { color: var(--ink); border-color: var(--ink-soft); }
.chip:has(input:checked),
.chip.is-active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
/* Anchor-as-chip: strip the link underline + colour so the chip
   renders identically to a checkbox-as-chip. */
a.chip { text-decoration: none; }
a.chip:hover { text-decoration: none; }
a.chip.is-active:hover { color: var(--bg); border-color: var(--ink); }
.chip.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.chip.is-disabled:hover { color: var(--ink-soft); border-color: var(--rule-strong); }
