/* forms */
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: var(--fs-13); font-weight: var(--fw-semibold); color: var(--ink-2); }
.field .req { color: var(--bad); margin-left: 3px; font-style: normal; }
.field small { color: var(--muted); font-size: var(--fs-12); line-height: 1.3; }
/* Inline help marker (ui.helpIcon): a plain hairline white « ? » disc at a zone
   title (field label / section legend). Its clarifying note rides the CSS-only
   popover below, shown on hover/focus — it replaces the grey notes that used to sit
   under every field. The disc itself stays inert (no hover state, no shadow); only
   the popover appears. One look site-wide. */
.help-q {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin-left: 5px; flex: none; vertical-align: middle;
  border: 1px solid var(--line); border-radius: 50%; background: var(--white);
  color: var(--muted); font-size: var(--fs-11); font-weight: var(--fw-bold);
  font-style: normal; text-transform: none; letter-spacing: 0; line-height: 1; cursor: help;
}
.help-pop {
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  z-index: 30; width: max-content; max-width: 250px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  box-shadow: var(--shadow-pop); color: var(--ink-2); font-size: var(--fs-12);
  font-weight: var(--fw-normal); font-style: normal; text-transform: none;
  letter-spacing: 0; line-height: 1.4; text-align: left; white-space: normal;
  opacity: 0; visibility: hidden; pointer-events: none;
}
.help-q:hover .help-pop, .help-q:focus .help-pop, .help-q:focus-within .help-pop {
  opacity: 1; visibility: visible;
}
.help-pop a { color: var(--link); pointer-events: auto; }
input, select, textarea {
  font: inherit; padding: 7px 11px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); color: var(--ink); width: 100%;
  /* Checkbox/radio tick adopts the Orchidée brand magenta (never the browser default blue). */
  accent-color: var(--brand);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus-ring); }
/* Shared control height: every single-line input + select sits at --control-h, the
   same box as a button, so dates/selects/text/buttons align on one row (the native
   date input's taller intrinsic box is the reason — box-sizing + a fixed height pins
   it). Wrapped in :where() to carry ZERO specificity, so any compact context
   (.totals-discount, filters…) overrides it with a plain class. Multi-line textarea,
   and checkbox/radio/file inputs (intrinsic sizing) opt out. */
input:where(:not([type=checkbox]):not([type=radio]):not([type=file])), select {
  height: var(--control-h); padding-top: 0; padding-bottom: 0;
}
/* Free-text areas (address, notes, description) read best at a normal text
   measure — cap them so they never stretch edge-to-edge like a full-width band.
   No drag-to-resize handle (resize:none): the box auto-fits its height to its
   content (field-sizing) between a floor and a cap, then scrolls past the cap —
   never a manual corner grabber. */
textarea { max-width: 60ch; min-height: 64px; max-height: 320px; resize: none; overflow-y: auto; field-sizing: content; }
/* Form fields share one layout vocabulary across two contexts. Inline route forms
   keep the FLEX flow here (each field at its declared .field-<size> width, no grow,
   wrapping when cramped, every input bottom-aligned so a 2-line label never pushes its
   input below single-line neighbours). Sectioned entity forms switch the same grid to
   a 12-COLUMN CSS grid (.form-section .form-grid, rule just below) where each size maps
   to a column span. The .field-<size> classes therefore carry BOTH a flex-basis (used
   in flex) and a grid-column span (used in grid); each property is inert in the other
   context, so one vocabulary drives both. */
.form-grid { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: end; }
.form-grid > :where(.field, [data-show-for]) { flex: 0 1 var(--field-md); min-width: 0; grid-column: span 4; }
.field-xs { flex-basis: var(--field-xs); grid-column: span 2; }
.field-sm { flex-basis: var(--field-sm); grid-column: span 3; }
.field-md { flex-basis: var(--field-md); grid-column: span 4; }
.field-lg { flex-basis: var(--field-lg); grid-column: span 6; }
.field-xl { flex-basis: var(--field-xl); grid-column: span 8; }
.field-full, .form-grid > .field:has(textarea), .form-actions { flex-basis: 100%; grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; align-items: center; }
/* Caisse period-closing row (select + native date + button on one line): the shared
   --control-h aligns them automatically; this just gives the closures table below room. */
.close-form { margin-bottom: 18px; }
/* A short inline form (combobox + notes) stays a compact card hugging its reading
   column, not a sparse band across the whole content area. */
.form-narrow { max-width: var(--form-col-narrow); }
/* A field + its submit button on one row, the button to the RIGHT of the field
   (bank queue: combobox/Rapprocher, motif/Ignorer ; supplier-invoice refuse/dispute).
   align-items:end bottom-aligns a labelled field with the button; nowrap + min-width:0
   lets the field shrink to share the row instead of bumping the button onto a new line. */
.inline-form { display: flex; gap: 8px; align-items: end; flex-wrap: nowrap; }
.inline-form > .field { min-width: 0; }
/* One active reconciliation link + its « Dé-rapprocher » red cross (ui.iconBtn) on a row. */
.recon-line { display: flex; align-items: center; gap: 8px; }
@media (max-width: 640px) { .form-grid > :where(.field, [data-show-for]) { flex-basis: 100%; } }

/* Sticky action bar at the foot of an entity form (ui.formActions): ONE convention for the
   article / client / supplier / settings forms — it replaces the old split between header
   actions (article) and a bottom .form-actions (the others). Sticks to the viewport bottom
   so the primary action stays reachable on a long form; a hairline top + page background
   keep content legible scrolling under it. flex-basis 100% lets it span a flex form-grid
   (settings) as well as a block .form-sections stack. */
.form-bar { position: sticky; bottom: 0; z-index: 20; flex-basis: 100%;
  display: flex; gap: 8px; align-items: center; justify-content: flex-end;
  margin-top: 14px; padding: 12px 0; background: var(--bg); border-top: 1px solid var(--line); }
/* Inline save/cancel group for a page header (ui.formActions opts.inline) — same dirty
   wiring as .form-bar, laid out as one flex item among the header .actions. */
.form-actions-h { display: inline-flex; gap: 8px; align-items: center; }

/* Sectioned entity forms (article / client / fournisseur / réglages): the section's
   field grid becomes a shared 12-column grid so fields align between rows and a tuned
   row fills its width — the fix for the ragged right edge and scattered gaps (the
   .field-<size> spans above map each field; on the narrow rail every field stacks). */
.form-section .form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); align-items: end; }
@media (max-width: 640px) { .form-section .form-grid > * { grid-column: 1 / -1; } }

/* Catalogue import wizard (routes/products-import.js). */
/* Upload step: a single drag-and-drop target — no text, no buttons. The whole
   zone is a <label> wrapping a hidden file input (clicking opens the picker); the
   dashed border is the affordance, the inner children are pointer-transparent so
   every drag event targets the zone itself (reliable dragover/leave toggling). */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; min-height: 260px; padding: 40px; text-align: center; cursor: pointer;
  border: 2px dashed var(--line); border-radius: var(--radius-card);
  background: var(--panel); transition: border-color .12s ease, background .12s ease;
}
.dropzone:hover, .dropzone:focus-within, .dropzone.dragover { border-color: var(--brand); background: var(--brand-wash); }
.dropzone > * { pointer-events: none; }
.dropzone .ic { width: 44px; height: 44px; background: var(--brand-grad); }
.dropzone-title { font-size: var(--fs-17); font-weight: var(--fw-semibold); color: var(--ink); }
.dropzone-hint { font-size: var(--fs-13); color: var(--muted); }
.import-resume { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.import-resume p { margin: 0; }
.import-progress-row { display: flex; align-items: center; gap: 10px; margin: 4px 0; }
.import-progress { flex: 1; height: 10px; border: 1px solid var(--line); border-radius: 999px;
  overflow: hidden; appearance: none; -webkit-appearance: none; background: var(--brand-wash); }
.import-progress::-webkit-progress-bar { background: var(--brand-wash); }
.import-progress::-webkit-progress-value { background: var(--brand-grad); border-radius: 999px; }
.import-progress::-moz-progress-bar { background: var(--brand); }
.import-pct { font-variant-numeric: tabular-nums; font-weight: var(--fw-semibold); color: var(--ink-2); min-width: 3.5ch; text-align: right; }
.import-warnings { margin: 8px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.import-warnings li { font-size: var(--fs-13); color: var(--ink-2); }
/* Tighter writing fields in the mapping: shorter selects/combo inputs + slimmer rows.
   No row separator: the per-row <select> already gives the line its own frame, so the
   horizontal rule only adds visual noise here. */
.map-cols select, .map-cols .combo-input { padding: 3px 9px; }
.map-cols td { padding-top: 3px; padding-bottom: 3px; border-bottom: 0; }
/* Import preview: keep each cell on one line (the table-wrap scrolls horizontally),
   rather than wrapping a long value onto two rows. */
.preview-cols th, .preview-cols td { white-space: nowrap; }

/* Catalogue attachments. Detail card (read-only, ui.attachmentView): every photo
   thumbnail + every technical-doc download chip, wrapping side by side. Edit page
   (ui.attachmentFields): a single list of all attachments (image thumbnail + name, or
   doc chip, each + a Delete form), above ONE add form (file picker + optional name +
   button). Photos are same-origin <img> (CSP img-src 'self'). */
.attach-view { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.attach-photo { display: block; line-height: 0; }
.attach-thumb { width: 116px; height: 116px; object-fit: cover; display: block;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--brand-wash); }
.attach-thumb-sm { width: 84px; height: 84px; }
.attach-doc { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  color: var(--link); text-decoration: none; }
.attach-doc:hover { background: var(--brand-wash); }
.attach-size { font-size: var(--fs-13); }

.attach-edit { display: flex; flex-direction: column; gap: 14px; }
.attach-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.attach-item { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
.attach-fname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--fs-13); color: var(--ink-2); }
.attach-del-form { margin: 0 0 0 auto; }
.attach-none { font-size: var(--fs-13); color: var(--muted); }
.attach-upload { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.attach-name { flex: 1 1 180px; width: auto; min-width: 140px; }
/* Styled file picker: the native <input type=file> fills its labelled .btn at
   opacity 0, so the visible affordance is our button (never the OS « Choisir un
   fichier »). The chosen name reflects into .file-name on its own line below. */
.file-pick { position: relative; overflow: hidden; cursor: pointer; }
.file-pick input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 0; }
.file-name { flex-basis: 100%; min-width: 0; font-size: var(--fs-13); color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-name.has-file { color: var(--ink-2); }

/* Project files (ui.projectFiles): an UNCAPPED gallery (N photos + N docs), each removable,
   above a combined upload form. Reuses .attach-view (photo flex-wrap) + .attach-thumb +
   .attach-doc; adds the per-item delete (a small × under a photo / beside a doc chip). */
.pfile { display: flex; flex-direction: column; gap: 14px; }
.pfile-photo { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pfile-docs { display: flex; flex-direction: column; gap: 8px; }
.pfile-doc { display: flex; align-items: center; gap: 8px; }
.pfile-upload { margin-top: 2px; }

/* Project note thread (ui.noteFeed): newest-first list, each note = author + date header
   then the body (whitespace preserved via .comment-ro). Compact, border-separated. */
.note-add { margin-bottom: 12px; }
.note-feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.note { padding: 10px 0; border-top: 1px solid var(--line); }
.note:first-child { border-top: 0; padding-top: 0; }
.note-head { display: flex; align-items: center; gap: 8px; }
.note-date { font-size: var(--fs-13); }
.note-head .link-btn { margin-left: auto; }
.note-body { margin: 4px 0 0; }
.note-empty { font-size: var(--fs-14); }

/* Titled form sections: each is its OWN CARD (border + radius + padding) so a form reads
   as a stack of labelled cards — the « fiche » pattern of the read views — rather than one
   undifferentiated wall. The sectioned entity form (.form-sections) is no longer a card
   itself; it's a transparent stack capped to the reading column (--form-col), left in the
   content area (no band stretched edge-to-edge — the « vide à droite » fix). The <legend>
   is floated so the fieldset draws a COMPLETE border (a legend otherwise notches the top
   border); the field grid clears below it. Sections stack with a margin; side-by-side
   sections (import « Colonnes supplémentaires », .grid-2) drop it. */
.form-sections { max-width: var(--form-col); }
/* Two stacked .form-sections (article edit: the product form then the « Pièces jointes »
   card + foot bar) keep the same 14px rhythm as the inter-section gap. */
.form-sections + .form-sections { margin-top: 14px; }
.form-section { border: 1px solid var(--line); border-radius: var(--radius-card); padding: 14px 18px; margin: 0; min-width: 0; background: var(--panel); }
.form-section + .form-section { margin-top: 14px; }
.grid-2 > .form-section + .form-section { margin-top: 0; }
.form-section > legend { float: left; display: flex; align-items: center; gap: 8px; width: 100%; font-size: var(--fs-15); font-weight: var(--fw-semibold); letter-spacing: -.01em; color: var(--ink); padding: 0; margin-bottom: 12px; }
.form-section > .form-grid, .form-section > .rules-list, .form-section > .perm-grid { clear: both; }

/* Role editor: name field then a checkbox matrix, one fieldset per module. */
.role-form > .field { margin-bottom: 18px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 8px 18px; }
.perm-chk { display: flex; align-items: center; gap: 8px; font-size: var(--fs-14); cursor: pointer; }
.perm-chk input { width: auto; margin: 0; }

/* Validation rules editor: each rule is a row with a toggle, a mode/threshold
   control cluster pinned right, and a help line spanning underneath. */
.rules-list { display: flex; flex-direction: column; gap: 14px; }
.rule-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center;
  padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.rule-row:last-child { border-bottom: 0; padding-bottom: 0; }
.rule-toggle { display: flex; align-items: center; gap: 9px; cursor: pointer; min-width: 0; }
.rule-toggle input { width: auto; margin: 0; flex: 0 0 auto; }
.rule-name { font-size: var(--fs-14); font-weight: var(--fw-semibold); color: var(--ink-2); }
.rule-controls { display: flex; align-items: center; gap: 8px; }
.rule-mode { width: auto; }
.rule-thr { display: inline-flex; align-items: center; gap: 5px; }
.rule-thr input { width: 80px; }
.rule-unit { color: var(--muted); font-size: var(--fs-13); }
.rule-head { display: flex; align-items: center; gap: 2px; min-width: 0; }
.rule-phases { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
@media (max-width: 560px) { .rule-row { grid-template-columns: 1fr; } .rule-controls { justify-content: flex-start; } }

/* full-width field (repeatable refs / prices span the whole section row) */
.field-wide { flex-basis: 100%; grid-column: 1 / -1; }

/* Light inset panel — the quote/order « + Ajouter une ligne » block (.line-add). */
.subblock { background: var(--chip); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 13px; }

/* repeatable rows (additional refs, multiple sale/purchase prices) */
.repeat { display: flex; flex-direction: column; gap: 8px; }
/* Column-header guide row: each cell mirrors the matching input's flex width so the
   label sits above its column. Hidden on the narrow rail where rows wrap and the
   inputs' own placeholders take over. */
.repeat-head { display: flex; gap: 8px; align-items: center; padding: 0 1px; flex-wrap: wrap; }
.repeat-head span { font-size: var(--fs-11); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.repeat-head .rh-text { flex: 0 1 var(--field-md); min-width: 110px; }
.repeat-head .rh-num { flex: 0 1 130px; min-width: 90px; }
.repeat-head .rh-combo { flex: 0 1 var(--field-md); min-width: 160px; }
.repeat-head .rh-narrow { flex: 0 1 84px; min-width: 64px; }
.repeat-head .rh-def { padding-left: 18px; white-space: nowrap; }
.repeat-head .rh-x { flex: 0 0 26px; }
@media (max-width: 820px) { .repeat-head { display: none; } }
/* Conditional column-header guide: show it only when there is ≥ 1 row. An empty block
   (no refs / no supplier / no kit component) hides the « LIBELLÉ / RÉFÉRENCE… » header
   floating over nothing and shows a discreet placeholder instead; adding the first row
   (JS) makes [data-rows] non-empty → header back, placeholder gone, all via CSS. */
.repeat:has([data-rows]:empty) .repeat-head { display: none; }
.repeat-none { display: none; font-size: var(--fs-13); color: var(--muted); padding: 1px 1px 2px; }
.repeat:has([data-rows]:empty) .repeat-none { display: block; }
/* Rows live inside [data-rows]; the gap must be there, not only between .repeat's
   direct children, otherwise stacked rows touch. */
.repeat [data-rows] { display: flex; flex-direction: column; gap: 8px; }
.repeat-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* Each repeatable-row field keeps a fixed width (no flex-grow) so a label/ref never
   stretches edge-to-edge across the full-width section — same discipline as the
   form-grid fields. Shrinks to its min-width when the row wraps on a narrow rail. */
.repeat-row input[type=text] { flex: 0 1 var(--field-md); min-width: 110px; margin: 0; }
.repeat-row input[type=number] { flex: 0 1 130px; min-width: 90px; margin: 0; }
/* A bare <select> in a repeatable row (import-wizard column picker) holds the same fixed
   width; a ≥8-option list is auto-enriched into a .combo (styled above) by app.js. */
.repeat-row select { flex: 0 1 var(--field-md); min-width: 110px; margin: 0; }
.repeat-row .radio-def { display: flex; align-items: center; gap: 5px; font-size: var(--fs-13); color: var(--ink-2); white-space: nowrap; }
.repeat-row .radio-def input { width: auto; margin: 0; }
/* A combobox picker (supplier / kit component) keeps a fixed width too, never a full row. */
.repeat-row .combo { flex: 0 1 var(--field-md); min-width: 160px; width: auto; }
.repeat [data-add-row] { align-self: flex-start; }
/* Supplier-offer row (« Fournisseurs & achat »): packaging / lead-time stay narrow
   so the dense row fits supplier + ref + price + cond. + délai + préféré on a line. */
.offer-row input[name="offer_pack"], .offer-row input[name="offer_lead"] { flex: 0 1 84px; min-width: 64px; }

