/* Shared form layout and controls (module forms, auth, e-way bill, connectors) */

/* ─── Grid & field shell ─────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 18px 20px;
  align-items: start;
}
.fld {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.fld.wide { grid-column: 1 / -1; }
.fld > label:not(.check-row):not(.ewb2-chk) {
  font: 500 12px var(--font-ui);
  color: var(--ink);
  letter-spacing: .01em;
}
.fld label .req { color: var(--crit-text); margin-left: 2px; font-weight: 600; }
.fld .help {
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}
.fld .help.auto { font-style: italic; color: var(--ink-2); }
.fld .err {
  font-size: 11px;
  line-height: 1.35;
  color: var(--crit-text);
  min-height: 0;
}
.fld .err:empty { display: none; }

/* ─── Text inputs, selects, textareas ────────────────────── */
.fld input:not([type=checkbox]):not([type=file]):not([type=radio]),
.fld select,
.fld textarea,
.auth-form .fld input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  min-height: 40px;
  line-height: 1.35;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, .04);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.fld textarea {
  padding: 10px 12px;
  min-height: 96px;
  resize: vertical;
}
.fld select {
  appearance: none;
  padding-right: 36px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%238a929e' stroke-width='1.6' stroke-linecap='round' d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.fld input:not([type=checkbox]):not([type=file]):focus,
.fld select:focus,
.fld textarea:focus,
.auth-form .fld input:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft), inset 0 1px 2px rgba(16, 24, 40, .04);
}
.fld input:disabled,
.fld select:disabled,
.fld textarea:disabled {
  background: var(--surface-2);
  color: var(--ink-2);
  cursor: not-allowed;
  box-shadow: none;
}
.fld.invalid input:not([type=checkbox]):not([type=file]),
.fld.invalid select,
.fld.invalid textarea {
  border-color: var(--crit);
  box-shadow: 0 0 0 3px var(--crit-soft);
}

/* ─── Toggle checkboxes ──────────────────────────────────── */
.fld-check .check-row,
.fld > label.ewb2-chk {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.fld-check .check-row:hover,
.fld > label.ewb2-chk:hover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.fld-check .check-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}
.fld-check .check-title {
  font: 500 13px var(--font-ui);
  color: var(--ink);
}
.fld-check .check-meta {
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
}
.fld-check .check-meta:empty { display: none; }
.fld-check input[type=checkbox],
.fld > label.ewb2-chk input[type=checkbox] {
  flex-shrink: 0;
  width: 44px;
  height: 26px;
  min-height: 0;
  margin: 1px 0 0;
  appearance: none;
  border: none;
  border-radius: 999px;
  background: var(--surface-3);
  cursor: pointer;
  position: relative;
  transition: background .2s ease;
}
.fld-check input[type=checkbox]::before,
.fld > label.ewb2-chk input[type=checkbox]::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .18);
  transition: transform .2s ease;
}
.fld-check input[type=checkbox]:checked,
.fld > label.ewb2-chk input[type=checkbox]:checked {
  background: var(--accent);
}
.fld-check input[type=checkbox]:checked::before,
.fld > label.ewb2-chk input[type=checkbox]:checked::before {
  transform: translateX(18px);
}
.fld-check input[type=checkbox]:focus-visible,
.fld > label.ewb2-chk input[type=checkbox]:focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: 2px;
}
.fld > label.ewb2-chk {
  align-items: center;
  font: 500 13px var(--font-ui);
  color: var(--ink);
}

/* ─── Sticky actions bar ─────────────────────────────────── */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin: 20px -11px -10px;
  padding: 14px 11px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  bottom: 0;
  z-index: 2;
}
.form-actions .btn.primary {
  min-height: 38px;
  padding: 0 18px;
  font-weight: 600;
}

/* ─── Line-item tables ───────────────────────────────────── */
.lines {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
  background: var(--surface-2);
}
.lines table { width: 100%; border-collapse: collapse; }
.lines thead th {
  padding: 8px 10px;
  text-align: left;
  font: 600 10px var(--font-head);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 70%, var(--surface-2));
  border-bottom: 1px solid var(--line);
}
.lines tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 12px;
  vertical-align: top;
  background: var(--surface);
}
.lines tbody tr:last-child td { border-bottom: none; }
.lines td input:not([type=checkbox]):not([type=file]),
.lines td select {
  width: 100%;
  min-width: 90px;
  min-height: 36px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 0 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, .04);
}
.lines td input:focus,
.lines td select:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.lines [data-add-row] { margin: 10px; }

/* ─── Ref lookup ─────────────────────────────────────────── */
.ref-pick { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ref-pick .ref-q {
  min-height: 36px;
  border-radius: 10px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  background: var(--surface);
}

/* ─── File uploads ───────────────────────────────────────── */
.file-pick { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.file-cur {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 24px;
  font-size: 12px;
  min-width: 0;
}
.fld input[type=file],
.lines td input[type=file] {
  padding: 8px 10px;
  min-height: 0;
  font-size: 12px;
  max-width: 100%;
  border: 1px dashed var(--line-2);
  border-radius: 10px;
  background: var(--surface-2);
}
.lines td .file-pick { min-width: 150px; }
.file-link {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  text-align: left;
  cursor: pointer;
  word-break: break-all;
}
.file-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ─── Auth (sign-in / sign-up) ───────────────────────────── */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-form h2 {
  font: 600 18px var(--font-head);
  margin: 0 0 4px;
  letter-spacing: -.01em;
}
.auth-form .fld { gap: 6px; }
.auth-form .btn.primary {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
  font-weight: 600;
}
.auth-err {
  color: var(--crit-text);
  min-height: 1.2em;
  margin: 0;
  font-size: 12px;
}

#rec-form .form-grid {
  padding: 2px 0 4px;
}

@media (max-width: 720px) {
  .form-grid { gap: 16px; }
  .form-actions {
    margin-left: -11px;
    margin-right: -11px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
}

/* a save a guardrail blocked (core/modules.js guardBox) */
.guard-box { border: 1px solid var(--crit); background: var(--crit-soft); color: var(--crit-text); border-radius: 6px; padding: 8px 10px; margin: 0 0 10px; display: grid; gap: 6px; font-size: 12.5px; }
.guard-box label { display: grid; gap: 2px; color: var(--ink); }
.guard-box input { width: 100%; }
.guard-box .btn { justify-self: start; }

/* ─── Form sections (registry `sections`; core/modules.js) ─── */
.form-sec { border-top: 1px solid var(--line); padding: 4px 0 14px; }
.form-sec:first-of-type { border-top: 0; }
.form-sec > summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 0;
  font: 600 13px var(--font-ui);
  color: var(--ink);
}
.form-sec > summary::-webkit-details-marker { display: none; }
.form-sec > summary::before { content: "▸"; display: inline-block; width: 16px; color: var(--muted); transition: transform .15s; }
.form-sec[open] > summary::before { transform: rotate(90deg); }
.form-sec > summary:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; border-radius: 4px; }
/* a folded section on the detail screen sits between the cards */
.form-sec > .card { margin-top: 6px; }
