:root {
  --blue: #1e4aa0; --blue-dark: #16387b; --orange: #ee6f00; --orange-dark: #c85d00;
  --bg: #f3f5fa; --card: #fff; --text: #1a2238; --muted: #626d86; --line: #dfe4ef;
  --ok: #117a45; --ok-bg: #e4f5ec; --warn: #9a4d00; --warn-bg: #fdf0e1; --danger: #b81f27; --danger-bg: #fbe7e8;
  --radius: 12px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.35rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.02rem; margin: 0 0 10px; }
h2.section { margin: 22px 0 10px; color: var(--muted); text-transform: uppercase; font-size: .78rem; letter-spacing: .06em; }
a { color: var(--blue); }
p { margin: 0 0 10px; }
small { color: var(--muted); font-size: .8rem; }
.muted { color: var(--muted); }
.boot, .empty { color: var(--muted); text-align: center; padding: 18px 8px; }

/* ---------- structure ---------- */
.shell { min-height: 100vh; }
.side { display: none; }
main { padding: 14px 14px calc(92px + env(safe-area-inset-bottom)); max-width: 980px; margin: 0 auto; }
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.top p { margin: 2px 0 0; }
.back { display: inline-block; font-size: .85rem; text-decoration: none; margin-bottom: 4px; }
.bottom { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--card); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
.bottom a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; color: var(--muted); text-decoration: none; font-size: .72rem; border-radius: 10px; }
.bottom a i { font-style: normal; font-size: 1.15rem; line-height: 1.2; height: 1.4rem; }
.bottom a.on { color: var(--blue); font-weight: 700; }
.bottom a.main i { background: var(--orange); color: #fff; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 1.6rem; margin-top: -20px; box-shadow: 0 4px 12px rgba(238, 111, 0, .35); }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); }
  .bottom { display: none; }
  .side { display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; background: var(--blue); color: #fff; padding: 16px 12px; }
  main { width: 100%; padding: 24px 28px 90px; }
  .brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-size: 1.05rem; margin-bottom: 20px; }
  .brand img { width: 40px; height: 40px; background: #fff; border-radius: 10px; padding: 3px; }
  .brand b { color: #ffb066; }
  .side nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
  .side nav a { display: flex; gap: 10px; align-items: center; color: #dbe5fb; text-decoration: none; padding: 9px 10px; border-radius: 10px; }
  .side nav a i { font-style: normal; width: 20px; text-align: center; }
  .side nav a.on { background: rgba(255, 255, 255, .16); color: #fff; font-weight: 700; }
  .side nav a.main { background: var(--orange); color: #fff; font-weight: 700; margin: 4px 0; }
  .who { color: #fff; text-decoration: none; border-top: 1px solid rgba(255,255,255,.2); padding-top: 10px; display: flex; flex-direction: column; }
  .who small { color: #c5d3f3; }
}

/* ---------- blocs ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-head h2 { margin: 0; }
.cols { display: grid; gap: 0 12px; }
@media (min-width: 760px) { .cols { grid-template-columns: 1fr 1fr; align-items: start; } }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 3px; color: inherit; text-decoration: none; min-width: 0; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat b { font-size: 1.12rem; overflow-wrap: anywhere; }
.stat.ok b { color: var(--ok); }
.stat.warn b { color: var(--warn); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.list { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.card .list { border: 0; border-radius: 0; margin: 0 -14px -4px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; text-decoration: none; text-align: left; font: inherit; width: 100%; cursor: pointer; }
div.row { cursor: default; flex-wrap: wrap; }
.row:last-child { border-bottom: 0; }
.row:hover { background: #f8faff; }
.row > div { display: flex; flex-direction: column; min-width: 0; }
.row > div:first-child { flex: 1; }
.row b { overflow-wrap: anywhere; }
.row .right { align-items: flex-end; text-align: right; flex: 0 0 auto; gap: 3px; }
.row.struck b { text-decoration: line-through; color: var(--muted); }
.chev { color: var(--muted); font-size: 1.4rem; }

.badge { display: inline-block; font-size: .74rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; background: #e9eefb; color: var(--blue); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.alert { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; background: #e9eefb; }
.alert.error { background: var(--danger-bg); color: var(--danger); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.warn-text { color: var(--warn); display: block; }
.danger-note { color: var(--danger); font-weight: 700; }

/* ---------- formulaires ---------- */
input, select, textarea { font: inherit; font-size: 16px; color: inherit; background: #fff; border: 1px solid #c9d0e0; border-radius: 9px; padding: 9px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
input:disabled { background: #eef0f6; color: var(--muted); }
input[type="checkbox"] { width: 20px; height: 20px; padding: 0; flex: 0 0 auto; accent-color: var(--blue); }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; min-width: 0; }
.field > span, .label { font-size: .8rem; font-weight: 600; color: var(--muted); display: block; }
.grid { display: grid; gap: 0 12px; }
@media (min-width: 620px) { .grid { grid-template-columns: 1fr 1fr; } .grid .wide { grid-column: 1 / -1; } }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; font-size: .92rem; }
.search { margin-bottom: 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 10px; }
.filters > * { flex: 1 1 180px; margin-bottom: 0; }
.big { font-size: 1.1rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; border: 1px solid var(--blue); background: var(--blue); color: #fff; border-radius: 10px; padding: 10px 14px; cursor: pointer; text-decoration: none; min-height: 42px; }
.btn:hover { background: var(--blue-dark); }
.btn.orange { background: var(--orange); border-color: var(--orange); }
.btn.orange:hover { background: var(--orange-dark); }
.btn.ghost { background: #fff; color: var(--blue); border-color: #c9d0e0; }
.btn.ghost:hover { background: #f0f4fd; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger-text { color: var(--danger); }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: .86rem; }
.btn.block { width: 100%; margin-top: 6px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon { border: 0; background: none; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.danger-zone { margin-top: 18px; text-align: center; }

.segmented { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 12px; scrollbar-width: none; }
.segmented button { flex: 0 0 auto; font: inherit; font-size: .88rem; border: 1px solid #c9d0e0; background: #fff; border-radius: 99px; padding: 7px 14px; cursor: pointer; color: var(--text); }
.segmented button.on { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 700; }

/* ---------- nouveau document ---------- */
.line { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 10px 0; background: #fcfdff; }
.line-head { display: flex; gap: 6px; align-items: center; }
.line-label { font-weight: 600; }
.line-section { margin-top: 6px; font-size: 15px; }
.line-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; margin-top: 8px; }
@media (min-width: 620px) { .line-grid { grid-template-columns: 1.2fr .8fr 1fr 1fr; } }
.line-grid .field { margin-bottom: 4px; }
.line-total { display: flex; flex-direction: column; justify-content: center; align-items: flex-end; }
.line-total span { font-size: .8rem; color: var(--muted); }
.stepper { display: grid; grid-template-columns: 38px 1fr 38px; gap: 4px; }
.stepper button { font-size: 1.2rem; border: 1px solid #c9d0e0; background: #fff; border-radius: 9px; cursor: pointer; }
.stepper input { text-align: center; padding: 9px 4px; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 10px 0 0; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; }
.totals .grand { font-size: 1.15rem; font-weight: 800; color: var(--text); border-top: 1px solid var(--line); padding-top: 6px; }
.savebar { position: fixed; z-index: 15; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom)); display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--card); border-top: 1px solid var(--line); padding: 10px 14px; box-shadow: 0 -4px 14px rgba(20, 30, 60, .08); }
.savebar span { display: block; font-size: .75rem; color: var(--muted); }
.savebar b { font-size: 1.15rem; }
main:has(.savebar) { padding-bottom: 170px; }
@media (min-width: 900px) { .savebar { left: 220px; bottom: 0; padding: 12px 28px; } main:has(.savebar) { padding-bottom: 110px; } }

.picker-head { display: flex; gap: 8px; margin-bottom: 10px; }
.list.scroll { max-height: 62vh; overflow-y: auto; margin-bottom: 0; }

/* ---------- tableaux ---------- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 2px solid var(--line); padding: 6px 4px; }
td { border-bottom: 1px solid var(--line); padding: 7px 4px; vertical-align: top; }
.r { text-align: right; }
td.r { white-space: nowrap; }
td small { display: inline; }
.section-row td { background: #e9eefb; color: var(--blue); font-weight: 700; }
.subtotal-row td { font-weight: 700; }
@media (max-width: 520px) {
  table.lines { font-size: .82rem; }
  table.lines td.r { white-space: normal; }
}

/* ---------- boîtes de dialogue, messages ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(15, 22, 45, .5); display: flex; align-items: flex-end; justify-content: center; }
.dialog { background: var(--card); border-radius: 18px 18px 0 0; padding: 18px; width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto; }
@media (min-width: 640px) { .overlay { align-items: center; padding: 20px; } .dialog { border-radius: 16px; } }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.actions.wrap { flex-wrap: wrap; }
.toasts { position: fixed; z-index: 60; left: 12px; right: 12px; bottom: calc(80px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #14213a; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: 520px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warn); }

.number-row { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.number-row div { display: flex; flex-direction: column; }

/* ---------- connexion ---------- */
.auth { max-width: 400px; margin: 0 auto; padding: 32px 16px; text-align: center; }
.auth img { width: 96px; height: auto; margin-bottom: 8px; }
.auth h1 { margin-bottom: 6px; }
.auth .card { text-align: left; margin-top: 14px; }
