/* Utilitarian styling — functionality over shine. No external dependencies. */
:root {
  --fg: #1c1c1c; --muted: #6b6b6b; --bg: #f6f6f4; --card: #fff;
  --line: #d9d9d4; --accent: #1f5f4f; --error: #b00020; --ok: #1f7a1f;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--fg); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar { display: flex; align-items: center; justify-content: space-between;
  padding: .6rem 1rem; background: #fff; border-bottom: 1px solid var(--line); }
.topbar .brand { font-weight: 700; color: var(--fg); }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.inline { display: inline; margin: 0; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer;
  font: inherit; padding: 0; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
h1 { font-size: 1.5rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.1rem; margin: 0 0 .3rem; }
.muted { color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem; margin-top: 1rem; }
.card { display: block; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 1rem; color: var(--fg); }
.card:hover { border-color: var(--accent); text-decoration: none; }

table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { border: 1px solid var(--line); padding: .4rem .5rem; text-align: left;
  vertical-align: top; }
th { background: #efefe9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

input, select, textarea { font: inherit; padding: .35rem .45rem; border: 1px solid var(--line);
  border-radius: 4px; background: #fff; }
button { font: inherit; padding: .4rem .8rem; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; border-radius: 4px; cursor: pointer; }
button.secondary { background: #fff; color: var(--accent); }

.messages { list-style: none; margin: .5rem auto; padding: 0 1rem; max-width: 1100px; }
.msg { padding: .5rem .75rem; border-radius: 4px; margin: .25rem 0; border: 1px solid var(--line); }
.msg.error { color: var(--error); border-color: var(--error); background: #fff0f1; }
.msg.success { color: var(--ok); border-color: var(--ok); background: #f0fbf0; }

.login { max-width: 320px; margin: 3rem auto; background: #fff; padding: 1.5rem;
  border: 1px solid var(--line); border-radius: 8px; }
.login label { display: block; font-size: .85rem; color: var(--muted); }
.login input { width: 100%; }
.login button { width: 100%; margin-top: .5rem; }

/* layout helpers */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.small { font-size: .82rem; }
.muted.small, .small.muted { color: var(--muted); }
.card-btn { display: inline-block; background: var(--accent); color: #fff; padding: .45rem .8rem;
  border-radius: 4px; }
.card-btn:hover { text-decoration: none; opacity: .92; }
.filters { display: flex; gap: .5rem; margin: .8rem 0; }
.stacked { display: flex; flex-direction: column; gap: .8rem; max-width: 420px; }
.stacked label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; }

/* status badge */
.badge { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 10px;
  border: 1px solid var(--line); background: #eee; vertical-align: middle; }
.s-brouillon { background: #eee; }
.s-envoyé, .s-envoye { background: #e3eefc; border-color: #9cc0ef; }
.s-accepté, .s-accepte { background: #fdecd2; border-color: #e6b566; }
.s-en-construction { background: #fbf6c9; border-color: #d8c84e; }
.s-livré, .s-livre { background: #ddf3dd; border-color: #7cc47c; }
.s-annulé, .s-annule { background: #fbe0e2; border-color: #d98a90; }

/* builder */
.builder { display: grid; grid-template-columns: 1fr 300px; gap: 1.2rem; align-items: start; }
@media (max-width: 900px) { .builder { grid-template-columns: 1fr; } }
.builder-side { position: sticky; top: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.hdr { border: 1px solid var(--line); border-radius: 6px; padding: .6rem .8rem; display: flex;
  gap: 1.5rem; background: #fff; margin-bottom: 1rem; }
.hdr label { display: flex; flex-direction: column; font-size: .82rem; color: var(--muted); gap: .15rem; }
.qsection { margin-bottom: 1.2rem; }
.qsection-head { display: flex; align-items: baseline; justify-content: space-between; }
.qsection-head h3 { margin: .4rem 0; }
.coeflbl { font-size: .78rem; color: var(--muted); }
.coeflbl input { width: 5.5rem; }
.qsection table { font-size: .86rem; }
.qsection td { padding: .15rem .3rem; }
.qsection input { width: 100%; padding: .2rem .3rem; }
.qsection .i-s { width: 5rem; text-align: right; }
.qsection .i-ref { width: 7rem; }
tr.warn td { background: #fff7ed; }
tr.warn .i-ref { border-color: var(--error); }
.del { color: var(--error); font-weight: bold; }
.hidden-default { position: absolute; left: -9999px; width: 1px; height: 1px; }
.savebar { margin: 1rem 0 2rem; }
button.small { padding: .2rem .6rem; font-size: .82rem; margin-top: .3rem; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: .7rem .8rem; }
.panel h3 { margin: 0 0 .5rem; }
.totals table { font-size: .86rem; }
.totals td { border: 0; padding: .12rem 0; }
.totals tr.grand td { border-top: 1px solid var(--line); font-weight: 700; padding-top: .3rem; }
.catsearch input[type=search] { width: 100%; }
.catsearch select { width: 100%; }
/* keep long result lists scrollable inside the panel */
#search-results { max-height: 45vh; overflow-y: auto; margin-top: .5rem; }
.searchres { font-size: .78rem; margin-top: 0; }
.searchres code { font-size: .78rem; }
.searchres th { position: sticky; top: 0; }

/* lifecycle toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin: .6rem 0 1rem; }
.toolbar form { margin: 0; }
button.danger { background: #fff; color: var(--error); border-color: var(--error); }
button.danger:hover { background: var(--error); color: #fff; }

/* stock hint */
.stockhint { font-size: .72rem; color: var(--muted); }
.stockhint.neg { color: var(--error); }

/* history */
.events { list-style: none; margin: 0; padding: 0; font-size: .82rem; }
.events li { padding: .1rem 0; }

/* customer text */
.ctext { width: 100%; font: 13px/1.5 ui-monospace, Menlo, monospace; padding: .6rem; }

/* data freshness footer + staleness warnings */
.datafoot { margin-top: 2.5rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.stale-flag { color: var(--error); font-weight: 600; }
.stalebar { border: 1px solid var(--error); background: #fff0f1; color: var(--error);
  border-radius: 4px; padding: .5rem .75rem; margin: .6rem 0; font-size: .88rem; }

/* mappings review */
.rowsearch { width: 100%; min-width: 16rem; margin-top: .3rem; }
.rowres { max-height: 240px; overflow-y: auto; }
.rowres .searchres th { position: sticky; top: 0; }
