:root {
  --brand: #3b5bdb;
  --brand-dark: #2f4ac0;
  --brand-soft: #eef2ff;
  --star: #f59f00;
  --text: #1c1e21;
  --muted: #65676b;
  --border: #dfe1e6;
  --bg: #f4f5f8;
  --card: #fff;
  --ok: #2b8a3e;
  --ok-soft: #ebfbee;
  --err: #c92a2a;
  --err-soft: #fff5f5;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: .4rem 0 .6rem; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
.card h2 + h2, .card form + h2 { margin-top: 1.4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand); color: #fff;
  padding: .6rem 16px calc(.6rem);
  padding-top: max(.6rem, env(safe-area-inset-top));
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
}
.brand { color: #fff; font-weight: 800; font-size: 1.2rem; text-decoration: none; }
.brand .star { color: var(--star); }
.nav { display: flex; flex-wrap: wrap; gap: .25rem; margin-left: auto; }
.nav a { color: #dfe5ff; text-decoration: none; padding: .35rem .6rem; border-radius: 8px; white-space: nowrap; font-size: .92rem; }
.nav a.on { background: rgba(255,255,255,.18); color: #fff; }
.nav .btn-nav { background: #fff; color: var(--brand); font-weight: 700; }
.nav .btn-nav.on { background: #fff; color: var(--brand); }

.container { width: 100%; max-width: 980px; margin: 0 auto; padding: 16px; flex: 1; }
.footer {
  display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; justify-content: center; align-items: center;
  padding: 1.2rem 16px calc(1.2rem + env(safe-area-inset-bottom)); color: var(--muted); font-size: .85rem;
}
.inline { display: inline; }

/* Cartes et formulaires */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.narrow { max-width: 440px; margin-left: auto; margin-right: auto; }
.center { text-align: center; }
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: .75rem; }
.label { font-weight: 600; font-size: .92rem; margin: .4rem 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem;
  font: inherit; font-size: 16px; /* évite le zoom auto sur iPhone */
  padding: .7rem .75rem; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
textarea { resize: vertical; }
.row { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.row > * { margin-bottom: .75rem; }
.row .grow { flex: 1 1 140px; }
.row .cp { flex: 0 0 110px; }
.field-error { color: var(--err); font-size: .85rem; margin: -.5rem 0 .75rem; font-weight: 600; }

.btn {
  display: inline-block; text-align: center; text-decoration: none; cursor: pointer;
  font: inherit; font-weight: 600; padding: .7rem 1rem; border-radius: 10px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { opacity: .6; }
.btn-block { display: block; width: 100%; margin-bottom: .6rem; }
.btn-lg { padding: 1rem; font-size: 1.1rem; }
.btn-small { padding: .45rem .8rem; font-size: .9rem; }
button.link { background: none; border: 0; padding: .3rem 0; color: var(--brand); font: inherit; cursor: pointer; text-decoration: underline; }
.back { display: inline-block; margin-bottom: .4rem; text-decoration: none; }

.alert { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 14px; }
.alert-success { background: var(--ok-soft); color: var(--ok); border: 1px solid #b2f2bb; }
.alert-error { background: var(--err-soft); color: var(--err); border: 1px solid #ffc9c9; }
.alert-info { background: var(--brand-soft); color: var(--brand-dark); border: 1px solid #c5d0fa; }

/* Formulaire de commande */
.step {
  display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: .85rem; margin-right: .35rem;
}
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: .75rem; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choice { margin: 0; cursor: pointer; position: relative; }
.choice input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.choice span {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 74px; padding: .6rem .3rem; border: 2px solid var(--border); border-radius: 10px; background: #fff;
}
.choice em { font-style: normal; font-weight: 400; font-size: .82rem; color: var(--muted); }
.choice input:checked + span { border-color: var(--brand); background: var(--brand-soft); }
.choice input:focus-visible + span { outline: 2px solid var(--brand); }
.total { border-top: 1px dashed var(--border); padding-top: .6rem; }
.total div { display: flex; justify-content: space-between; align-items: baseline; }
.total strong { font-size: 1.4rem; color: var(--brand); }

.search-status { font-size: .9rem; color: var(--muted); margin: .5rem 0; }
.results { list-style: none; padding: 0; margin: 0 0 .5rem; }
.result {
  width: 100%; text-align: left; font: inherit; cursor: pointer; display: flex; flex-direction: column;
  padding: .7rem .8rem; margin-bottom: .4rem; background: #fff; border: 1px solid var(--border); border-radius: 10px;
}
.result span { color: var(--muted); font-size: .85rem; }
.result:hover, .result:focus { border-color: var(--brand); background: var(--brand-soft); }
.confirmed { display: flex; flex-direction: column; gap: .2rem; padding: .8rem; background: var(--ok-soft); border-radius: 10px; margin-bottom: .5rem; }
.confirmed .ok { color: var(--ok); font-weight: 700; margin: 0; }
.confirmed .link { align-self: flex-start; }

.terms { margin-bottom: .8rem; }
.terms summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.terms-text { white-space: pre-wrap; font-size: .85rem; max-height: 240px; overflow: auto; background: var(--bg); padding: .7rem; border-radius: 8px; margin-top: .5rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 600; }
.check input { width: 1.4rem; height: 1.4rem; margin: 0; flex-shrink: 0; }

.sig-wrap { position: relative; }
#sig {
  display: block; width: 100%; height: 180px; touch-action: none;
  border: 2px dashed #b9c2d6; border-radius: 10px; background: #fff; cursor: crosshair;
}
.sig-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #aab; pointer-events: none; }

/* Listes */
.order-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.order-list li { margin-bottom: .5rem; }
.order-list a {
  display: flex; justify-content: space-between; gap: .8rem; padding: .8rem .9rem;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); color: inherit; text-decoration: none;
}
.order-list a > div:first-child { display: flex; flex-direction: column; min-width: 0; }
.order-list .right { display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; flex-shrink: 0; }
.order-list li.inactive a { opacity: .6; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge.big { font-size: .95rem; padding: .3rem .8rem; }
.s-a_produire { background: #fff4e6; color: #d9480f; }
.s-programmee { background: #e7f5ff; color: #1971c2; }
.s-envoyee { background: #f3f0ff; color: #6741d9; }
.s-livree { background: var(--ok-soft); color: var(--ok); }
.s-annulee { background: #f1f3f5; color: #868e96; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin: 1rem 0; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; display: flex; flex-direction: column; }
.stat-label { font-size: .85rem; color: var(--muted); }
.stat strong { font-size: 1.35rem; color: var(--brand); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem .9rem; margin: 0; }
.kv dt { color: var(--muted); font-size: .9rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: .5rem; }
.chip { white-space: nowrap; padding: .35rem .7rem; border-radius: 999px; background: #fff; border: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: .88rem; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.filters input[type=search] { grid-column: 1 / -1; }
.filters input, .filters select { margin: 0; }
.filters .btn { grid-column: 1 / -1; }

.grid { display: grid; gap: 14px; }
.grid .card { margin: 0; }
.copy { display: flex; gap: .4rem; }
.copy input { margin: 0; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin: .8rem 0; }
.qr { display: block; margin: .6rem auto; image-rendering: pixelated; border-radius: 8px; }
.signature { display: block; max-width: 100%; max-height: 160px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: .8rem; background: #fff; }
.statuses { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.small-choice span { min-height: 48px; font-weight: 600; font-size: .9rem; }
.status-form input[name=note] { margin-bottom: .6rem; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; flex-direction: column; padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.timeline li.err { color: var(--err); }
details form { margin-top: .5rem; }
details summary { cursor: pointer; color: var(--brand); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .5rem .4rem; border-bottom: 1px solid var(--border); text-align: left; }
.num { text-align: right; white-space: nowrap; }
tfoot th { border-top: 2px solid var(--text); border-bottom: 0; }

.amount { font-size: 2.2rem; font-weight: 800; color: var(--brand); margin: .2rem 0 1rem; }
.big-check { font-size: 3rem; color: var(--ok); margin: 0; }
.prose h2 { margin-top: 1.4rem; }
.prose li { margin-bottom: .3rem; }

@media (min-width: 760px) {
  .container { padding: 24px; }
  .grid { grid-template-columns: 1fr 1fr; }
  .filters { grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto; }
  .filters input[type=search], .filters .btn { grid-column: auto; }
  #order-form { max-width: 640px; margin: 0 auto; }
  h1 { font-size: 1.75rem; }
}
