:root {
  --blue: #145064; --dark: #0d3545; --orange: #F0A000; --grey: #646464;
  --bg: #f2f5f6; --card: #ffffff; --line: #dfe5e8; --text: #1d2a30; --muted: #6b7a80;
  --ok: #1f8a4c; --ok-bg: #e6f4ec; --err: #c0392b; --err-bg: #fbeaea; --warn: #9a6400; --warn-bg: #fff4dc;
  --r: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--blue); }
h1 { font-size: 1.45rem; margin: .2rem 0 1rem; color: var(--dark); }
h2 { font-size: 1.02rem; margin: 1.4rem 0 .6rem; color: var(--dark); }
.card > h2:first-child, section > h2:first-child { margin-top: 0; }
h3 { font-size: .95rem; margin: 1.2rem 0 .5rem; color: var(--dark); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-line; }
.empty { padding: 1rem; text-align: center; }
.pad { padding: .6rem .8rem; }
[hidden] { display: none !important; }

/* Mise en page */
.wrap { max-width: 860px; margin: 0 auto; padding: 16px 16px 110px; }
body.center-page .wrap { padding-bottom: 32px; }
.wrap.wide { max-width: 1240px; }
.card { background: var(--card); border-radius: var(--r); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(13,53,69,.06); border: 1px solid #e8edef; }
.narrow { max-width: 440px; margin: 6vh auto; }
.center-page main.card.narrow { margin: 5vh auto; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.head-row h1 { margin-bottom: .6rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.grid2, .grid3 { display: grid; gap: 0 12px; grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1.3fr 1fr 1fr; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } .grid3 { grid-template-columns: 1fr 1fr; } .grid3 label:first-child { grid-column: 1 / -1; } }

/* Barre du haut */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px; padding-top: env(safe-area-inset-top);
  background: var(--dark); color: #fff; border-bottom: 3px solid var(--orange); }
.topbar .brand { color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .5px; white-space: nowrap; }
.topbar .brand span { color: #fff; }
.topbar .back { color: #fff; text-decoration: none; font-size: 2rem; line-height: 1; margin-right: -4px; padding: 0 6px 4px 0; }
.topnav { display: none; margin-left: 18px; gap: 4px; flex: 1; }
.topnav a { color: #cfe0e6; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-size: .95rem; }
.topnav a.on, .topnav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.topbar .me { margin-left: auto; width: 34px; height: 34px; border-radius: 50%; background: var(--orange); color: var(--dark); font-weight: 700;
  display: flex; align-items: center; justify-content: center; text-decoration: none; }

/* Barre d'onglets mobile */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 2px 8px; font-size: .72rem; color: var(--muted); text-decoration: none; }
.tabbar a i { font-style: normal; font-size: 1.25rem; line-height: 1.2; }
.tabbar a.on { color: var(--blue); font-weight: 600; }
.tabbar a.new i { background: var(--orange); color: #fff; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; }
@media (min-width: 900px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  .wrap { padding-bottom: 40px; }
  .sticky-actions { position: static !important; box-shadow: none !important; background: none !important; padding: 0 !important; }
}

/* Formulaires */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--grey); margin-bottom: 12px; }
label small { display: block; font-weight: 400; margin-top: 4px; }
input, select, textarea { display: block; width: 100%; margin-top: 5px; padding: 11px 12px; font: inherit; font-size: 16px; color: var(--text);
  border: 1px solid #cfd8dc; border-radius: 10px; background: #fff; -webkit-appearance: none; appearance: none; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--grey) 50%), linear-gradient(135deg, var(--grey) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input[type=checkbox], input[type=radio] { display: inline-block; width: auto; margin: 0 8px 0 0; -webkit-appearance: auto; appearance: auto; transform: scale(1.25); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(20,80,100,.15); }
textarea { resize: vertical; }
label.check { display: flex; align-items: center; font-weight: 500; color: var(--text); font-size: .95rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px 2px; margin: 0 0 16px; }
legend { font-weight: 700; color: var(--dark); padding: 0 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px; border: 1px solid #cfd8dc; background: #fff;
  color: var(--dark); font: inherit; font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--dark); }
.btn.danger { color: var(--err); border-color: #e9b8b2; }
.btn.small { padding: 7px 12px; font-size: .88rem; }
.btn.block { display: flex; width: 100%; }
.btn.big { padding: 15px; font-size: 1.08rem; margin-bottom: 14px; }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--blue); font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; padding: 0 0 0 10px; text-decoration: underline; }
.file-btn { cursor: pointer; margin: 0; }

.seg { display: flex; background: #e9eff1; border-radius: 10px; padding: 4px; margin-bottom: 14px; }
.seg label { flex: 1; margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 10px; border-radius: 8px; color: var(--grey); font-size: 1rem; cursor: pointer; }
.seg input:checked + span { background: #fff; color: var(--dark); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-size: .95rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.err { background: var(--err-bg); color: var(--err); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

/* Listes */
.list { background: #fff; border-radius: var(--r); border: 1px solid #e8edef; overflow: hidden; margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid #edf1f2; color: var(--text); text-decoration: none; }
.row:last-child { border-bottom: 0; }
.row:hover { background: #f8fafb; }
.row.off { opacity: .55; }
.row-main { flex: 1; min-width: 0; }
.row-sub { font-size: .88rem; overflow: hidden; text-overflow: ellipsis; }
.row-side { text-align: right; }
.search input { margin: 0 0 12px; padding-left: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 8px; }
.stats div { background: #fff; border-radius: var(--r); padding: 12px; border: 1px solid #e8edef; }
.stats b { display: block; font-size: 1.5rem; color: var(--dark); }
.stats span { font-size: .8rem; color: var(--muted); }
.stats .warn b { color: var(--warn); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0 0 10px; }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; }
.note { background: var(--warn-bg); padding: 10px 12px; border-radius: 8px; font-size: .92rem; }

.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); padding: 8px; border-bottom: 2px solid var(--line); }
.tbl td { padding: 9px 8px; border-bottom: 1px solid #edf1f2; vertical-align: top; }
.tbl .r { text-align: right; }
.tbl.small { font-size: .8rem; }
.tbl.office td { white-space: nowrap; }
.tbl.office td:nth-child(4), .tbl.office td:nth-child(6) { white-space: normal; min-width: 140px; }

.filters { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: flex-end; }
.filters label { flex: 1 1 140px; }
.filters .grow { flex: 2 1 220px; }
.filter-btns { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

/* Formulaire BL */
.client-pill { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #ecf2f4; border-radius: 10px; padding: 12px; }
.results { margin: 6px 0 10px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.results:empty { display: none; }
.result { display: block; width: 100%; text-align: left; padding: 11px 12px; background: #fff; border: 0; border-bottom: 1px solid #edf1f2; font: inherit; cursor: pointer; }
.result:last-child { border-bottom: 0; }
.result span { display: block; font-size: .85rem; }
.result:hover { background: #f5f8f9; }
#client_search { margin: 0 0 8px; }
.subform { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.lines .line { display: grid; grid-template-columns: 90px 1fr 62px 36px; gap: 6px; margin-bottom: 8px; }
.lines input { margin: 0; padding: 10px 8px; }
.l-qty { text-align: center; }
.l-del { border: 0; background: #f1f4f5; border-radius: 8px; font-size: 1.3rem; color: var(--grey); cursor: pointer; }
@media (max-width: 420px) { .lines .line { grid-template-columns: 1fr 58px 36px; } .lines .l-ref { grid-column: 1 / -1; } }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 10px; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; background: #eee; }
.ph { position: relative; }
.ph button { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 1.1rem; cursor: pointer; }
.sig-label { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; font-weight: 600; color: var(--grey); margin: 4px 0 6px; }
canvas.sigpad { display: block; width: 100%; height: 190px; border: 2px dashed #b9c6cb; border-radius: 10px; background: #fff; touch-action: none; margin-bottom: 14px; cursor: crosshair; }
canvas.sigpad.signed { border-style: solid; border-color: var(--blue); }
.sticky-actions { position: sticky; bottom: calc(58px + env(safe-area-inset-bottom)); padding: 10px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.sticky-actions .btn { margin: 0; box-shadow: 0 4px 14px rgba(13,53,69,.25); }
.sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sigs figure { margin: 0; }
.sigs img, .sigs figure > div { width: 100%; height: 110px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.sigs figcaption { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { margin: 0; flex: 1; }

/* Connexion */
.login { padding: 28px 22px; }
.logo-big { text-align: center; margin-bottom: 22px; }
.logo-big span { display: inline-block; font-size: 1.9rem; font-weight: 800; letter-spacing: 1px; color: var(--dark); border-bottom: 4px solid var(--orange); padding-bottom: 2px; }
.logo-big small { display: block; color: var(--muted); margin-top: 8px; }
.logo-prev { max-width: 240px; max-height: 80px; display: block; margin-bottom: 8px; }
.qr-prev { width: 110px; display: block; margin-bottom: 6px; }
code { font-size: .85em; }

/* v1.1 : BL en attente, suppression, catalogue de pièces */
:root { --info: #145064; --info-bg: #e3eef2; }
.badge.info { background: var(--info-bg); color: var(--info); }
.alert.info { background: var(--info-bg); color: var(--info); }
a.block-link { display: block; text-decoration: none; }
.nbadge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px;
  background: var(--orange); color: var(--dark); font-size: .72rem; font-weight: 800; font-style: normal; line-height: 1; vertical-align: 2px; }
.tabbar a i { position: relative; }
.tabbar a i .nbadge { position: absolute; top: -4px; right: -14px; margin: 0; }
form.inline { display: inline; margin: 0; }
.row-btns { display: flex; gap: 6px; justify-content: flex-end; }
.actions form.inline .btn { height: 100%; }
.note { margin-bottom: 14px; }
.lines .part-results { grid-column: 1 / -1; margin: 0 0 4px; max-height: 280px; overflow-y: auto; box-shadow: 0 4px 14px rgba(13,53,69,.12); }
.lines .part-results .result { padding: 9px 12px; }
