:root {
  --primary: #1f6f50; --primary-d: #165a40; --primary-l: #e6f2ec;
  --accent: #d9481c; --bg: #f2f4f3; --card: #fff; --text: #16211c; --muted: #61706a;
  --border: #d8dfdb; --bad: #c62828; --bad-l: #fdecea; --warn: #b26a00; --warn-l: #fff4e0;
  --good: #2e7d32; --good-l: #e8f5e9; --risk: #8e24aa; --risk-l: #f6e8fa;
  --radius: 10px; --side: 230px; --top: 56px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
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; }
body.noscroll { overflow: hidden; }
a { color: var(--primary); }
h1, h2 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.1rem; }
h2 small { font-weight: 400; font-size: .85rem; color: var(--muted); }
.inline { display: inline; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pre { white-space: pre-wrap; }
.bad-text { color: var(--bad); }
.nowrap { white-space: nowrap; }
.pad { padding: 10px; }
[hidden] { display: none !important; }

/* ---------- Structure */
.topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--top); background: var(--primary); color: #fff;
  display: flex; align-items: center; gap: 10px; padding: 0 12px; z-index: 30; padding-left: max(12px, env(safe-area-inset-left)); }
.topbar .brand { color: #fff; font-weight: 800; letter-spacing: .5px; text-decoration: none; font-size: 1.1rem; }
.topbar h1 { font-size: 1rem; font-weight: 500; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .95; }
.topbar .icon-btn { color: #fff; font-size: 1.3rem; }
.user-chip { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.2); color: #fff; display: grid; place-items: center; text-decoration: none; font-weight: 700; }
.sidebar { position: fixed; top: var(--top); bottom: 0; left: 0; width: var(--side); background: #fff; border-right: 1px solid var(--border); overflow-y: auto; padding: 8px 0 20px; z-index: 20; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 10px 18px; color: var(--text); text-decoration: none; font-weight: 500; }
.sidebar a span { width: 22px; text-align: center; }
.sidebar a:hover { background: var(--bg); }
.sidebar a.active { background: var(--primary-l); color: var(--primary-d); border-right: 3px solid var(--primary); }
.side-user { padding: 10px 18px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; display: flex; flex-direction: column; }
.side-user small { color: var(--muted); }
.side-bg { display: none; }
main { margin: var(--top) 0 0 var(--side); padding: 18px; max-width: 1200px; }
.menu-btn { display: none; }
.bottombar { display: none; }

@media (max-width: 900px) {
  .menu-btn { display: inline-flex; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; width: 270px; z-index: 40; top: 0; padding-top: 14px; }
  body.side-open .sidebar { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.3); }
  body.side-open .side-bg { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  main { margin-left: 0; padding: 12px 10px calc(78px + env(safe-area-inset-bottom)); }
  .bottombar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--border);
    z-index: 25; padding-bottom: env(safe-area-inset-bottom); }
  .bottombar a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 7px 2px 6px; font-size: .7rem; color: var(--muted); text-decoration: none; gap: 1px; }
  .bottombar a span { font-size: 1.25rem; }
  .bottombar a.active { color: var(--primary); font-weight: 600; }
  .hide-sm { display: none; }
}
@media (min-width: 901px) { .show-sm { display: none; } }
.show-sm { display: block; color: var(--muted); }

/* ---------- Composants */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card > h2 { margin-bottom: 10px; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: '▸ '; color: var(--muted); }
details.card[open] > summary::before { content: '▾ '; }
.info-card ol { margin: 10px 0 0; padding-left: 20px; } .info-card li { margin-bottom: 6px; }
.error-card { border-left: 4px solid var(--bad); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.loading.full { min-height: 100vh; display: grid; place-items: center; }
.back { margin: 0 0 10px; } .back a { text-decoration: none; font-weight: 500; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #b7c2bc; background: #fafbfa; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-outline { color: var(--bad); border-color: #e9b4b4; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .88rem; }
.btn.big { min-height: 48px; font-size: 1.02rem; padding: 10px 20px; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 1.1rem; padding: 6px 8px; border-radius: 6px; color: inherit; line-height: 1; }
.link-btn { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 8px; }
.mini { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; margin-left: 4px; cursor: pointer; font-size: .85rem; text-decoration: none; color: var(--text); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .75rem; font-weight: 600; background: #eef1ef; color: #44524b; white-space: nowrap; }
.badge.st-a_faire { background: #e3ecfb; color: #1d4f9c; } .badge.st-en_cours { background: var(--warn-l); color: var(--warn); }
.badge.st-soldee, .badge.st-validee, .badge.good { background: var(--good-l); color: var(--good); }
.badge.st-annulee, .badge.st-refusee { background: #eceff1; color: #607d8b; } .badge.st-en_attente, .badge.warn { background: var(--warn-l); color: var(--warn); }
.badge.bad, .badge.prio-1 { background: var(--bad-l); color: var(--bad); } .badge.prio-2 { background: var(--warn-l); color: var(--warn); }
.badge.risk { background: var(--risk-l); color: var(--risk); } .badge.must-b { background: #fde7e0; color: #b23b12; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* Formulaires */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field label { font-weight: 600; font-size: .88rem; }
.help { font-size: .82rem; color: var(--muted); }
input, select, textarea { font: inherit; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); width: 100%; min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-l); border-color: var(--primary); }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--primary); flex: none; margin: 0; }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.field .check { font-weight: 500; }
.form-error { background: var(--bad-l); color: var(--bad); padding: 10px 12px; border-radius: 8px; margin: 6px 0 10px; font-weight: 500; }
.info-box { background: var(--primary-l); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 10px; }
.actions.left { justify-content: flex-start; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 14px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 320px; } .toolbar .grow { flex: 1; max-width: none; min-width: 200px; }
.toolbar select { width: auto; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; flex-wrap: wrap; }
.seg button, .seg a { border: 0; background: none; padding: 8px 12px; cursor: pointer; font: inherit; color: var(--text); text-decoration: none; }
.seg .on { background: var(--primary); color: #fff; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0 12px; }
.filters-grid .grow2 { grid-column: span 2; }
@media (max-width: 520px) { .filters-grid .grow2 { grid-column: auto; } }
.filters .checks { justify-content: flex-end; gap: 8px; }
.result-head { margin: 4px 2px 8px; color: var(--muted); font-weight: 500; }

/* Sélecteur avec recherche */
.picker { position: relative; }
.picker-in { display: flex; gap: 6px; }
.picker-sel { display: flex; align-items: center; gap: 6px; border: 1px solid var(--primary); background: var(--primary-l); border-radius: 8px; padding: 6px 6px 6px 10px; min-height: 40px; }
.picker-label { flex: 1; font-weight: 500; }
.picker-list { position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 2px); background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.15); max-height: 280px; overflow-y: auto; }
.picker-list button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left; border: 0; border-bottom: 1px solid #eef1ef; background: #fff; padding: 9px 12px; cursor: pointer; font: inherit; }
.picker-list button:hover { background: var(--primary-l); }
.picker-list small { color: var(--muted); }

/* Listes */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 12px; align-items: flex-start; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 12px; color: var(--text); text-decoration: none; position: relative; overflow: hidden; }
a.item:hover { border-color: var(--primary); }
.item.late { border-left: 4px solid var(--bad); }
.item.risk-item { border-left: 4px solid var(--risk); }
.item.inactive, tr.inactive { opacity: .55; }
.nat-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.item.late .nat-bar { display: none; }
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item-main small { color: var(--muted); }
.item-side { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; max-width: 45%; }
.small-desc { font-size: .88rem; color: #3c4a43; margin-top: 4px; max-height: 4.5em; overflow: hidden; }
.list.compact .item { padding: 8px 10px; }
@media (max-width: 600px) { .item { flex-direction: column; } .item-side { max-width: none; justify-content: flex-start; } }

/* Tuiles du tableau de bord */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; text-decoration: none; color: var(--text); display: flex; flex-direction: column; border-top: 4px solid var(--primary); }
.tile b { font-size: 1.9rem; line-height: 1.1; } .tile span { color: var(--muted); font-size: .9rem; }
.tile.warn { border-top-color: #f0a020; } .tile.bad { border-top-color: var(--bad); } .tile.bad b { color: var(--bad); } .tile.good { border-top-color: var(--good); }

/* Tableaux */
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); border-bottom: 2px solid var(--border); padding: 8px 6px; }
.tbl td { border-bottom: 1px solid #eaeeec; padding: 8px 6px; vertical-align: top; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl tr.low td { background: #fff8ec; }
.click-rows tbody tr { cursor: pointer; } .click-rows tbody tr:hover td { background: var(--primary-l); }
.card > .tbl, section > .tbl { display: block; overflow-x: auto; }
@media (min-width: 700px) { .card > .tbl, section > .tbl { display: table; } }

/* Fiche OT */
.ot-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.ot-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.infos { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 16px; margin: 14px 0 0; }
.infos dt { font-size: .78rem; text-transform: uppercase; color: var(--muted); letter-spacing: .3px; }
.infos dd { margin: 2px 0 0; display: flex; flex-direction: column; } .infos dd small { color: var(--muted); }
.desc { background: #f7f9f8; border-radius: 8px; padding: 10px 12px; margin-top: 12px; }
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.ops { display: flex; flex-direction: column; gap: 8px; }
.op { border: 1px solid var(--border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.op.must { border-left: 4px solid var(--accent); }
.op.done { background: #f3faf5; border-color: #c7e3cf; }
.op-check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.op-check input { width: 26px; height: 26px; margin-top: 1px; }
.op-val { display: flex; gap: 8px; align-items: center; padding-left: 36px; flex-wrap: wrap; }
.op-val input { max-width: 180px; } .op-val input.out { border-color: var(--bad); background: var(--bad-l); }
.op-com { margin-left: 36px; width: calc(100% - 36px); font-size: .9rem; min-height: 34px; padding: 6px 9px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.photo { display: flex; flex-direction: column; text-decoration: none; color: var(--muted); font-size: .78rem; }
.photo img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: #e8ece9; }
.notes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.note { background: #f7f9f8; border-radius: 8px; padding: 8px 10px; } .note-head small { color: var(--muted); }
.note-form { display: flex; gap: 8px; align-items: flex-end; } .note-form textarea { flex: 1; }
.close-card { border: 2px solid var(--primary); }
.risk-check { background: var(--risk-l); padding: 10px; border-radius: 8px; color: var(--risk); }
.sig-box { position: relative; border: 2px dashed var(--border); border-radius: 8px; background: #fff; max-width: 520px; }
.sig-box canvas { display: block; width: 100%; height: 170px; touch-action: none; cursor: crosshair; }
.sig-box .btn { position: absolute; right: 6px; top: 6px; }
.sig-view img { display: block; max-width: 320px; border: 1px solid var(--border); border-radius: 8px; margin-top: 4px; }
.journal { margin: 10px 0 0; padding-left: 18px; color: #3c4a43; font-size: .9rem; } .journal li { margin-bottom: 4px; }
.qr-mini { width: 92px; height: 92px; padding: 6px; background: #fff; border: 1px solid var(--border); border-radius: 8px; flex: none; }
.qr-mini svg { width: 100%; height: 100%; display: block; }
.stock-big { font-size: 2rem; font-weight: 700; margin-top: 8px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stock-big small { font-size: 1rem; color: var(--muted); font-weight: 500; } .stock-big.low { color: var(--warn); }

/* Arborescence */
.tree { list-style: none; margin: 0; padding-left: 18px; } #tree-box > .tree { padding-left: 0; }
.tree li { margin: 2px 0; } .tree li.leaf { padding-left: 18px; }
.tree summary { cursor: pointer; padding: 3px 0; }
.tree summary::marker { color: var(--muted); }
.node { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 3px 0; }
.node a { text-decoration: none; color: var(--text); } .node a:hover { color: var(--primary); text-decoration: underline; }
.node.inactive { opacity: .5; }
.node-acts { display: inline-flex; }

/* Fenêtres */
.modal-bg { position: fixed; inset: 0; background: rgba(15,25,20,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 30px 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; border-radius: 12px 12px 0 0; z-index: 2; }
.modal-body { padding: 16px; }
.modal.wide .form { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 14px; }
.modal.wide .form > .actions, .modal.wide .form > .form-error, .modal.wide .form > .info-box, .modal.wide .form > [data-field=notes], .modal.wide .form > [data-field=description] { grid-column: 1 / -1; }
@media (max-width: 600px) { .modal-bg { padding: 0; } .modal { border-radius: 0; min-height: 100%; } .modal-head { border-radius: 0; } }

/* Scanner */
.scanner { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4/3; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 18% 22%; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); }
.manual-code { display: flex; gap: 8px; margin-top: 10px; }

/* Messages */
#toasts { position: fixed; z-index: 200; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 460px); }
.toast { background: #1e2b25; color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-weight: 500; animation: tin .2s; }
.toast.err { background: var(--bad); } .toast.warn { background: #a35f00; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--primary) 0%, #134832 100%); }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; }
.login-logo { font-size: 2rem; font-weight: 800; color: var(--primary); text-align: center; letter-spacing: 1px; }

/* Étiquettes */
.label-pick { max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; display: flex; flex-direction: column; gap: 4px; }
#print-root { position: fixed; inset: 0; background: #888; overflow: auto; z-index: 150; padding: 70px 0 30px; }
body.printing > #app { display: none; }
.print-bar { position: fixed; top: 0; left: 0; right: 0; background: #fff; padding: 10px 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; z-index: 2; box-shadow: var(--shadow); }
.sheet { width: 210mm; height: 297mm; background: #fff; margin: 0 auto 20px; display: grid; align-content: start; overflow: hidden; }
.label { display: flex; align-items: center; gap: 2.5mm; padding: 2mm 2.5mm; overflow: hidden; outline: 1px dashed #ddd; }
.label .lq { height: calc(100% - 1mm); aspect-ratio: 1; max-width: 45%; flex: none; }
.label .lq svg { width: 100%; height: 100%; display: block; }
.label .lt { display: flex; flex-direction: column; min-width: 0; font-size: 8.5pt; line-height: 1.2; overflow: hidden; max-height: 100%; }
.label .lt b { font-size: 10.5pt; word-break: break-all; }
.label .lt span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.label .lt small { color: #555; font-size: 7pt; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.label.small { padding: 1mm 1.5mm; gap: 1.5mm; } .label.small .lt { font-size: 6.5pt; } .label.small .lt b { font-size: 7.5pt; } .label.small .lt small { display: none; }
.label.small .lt span { -webkit-line-clamp: 2; }

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  .no-print, .topbar, .sidebar, .bottombar, #toasts, main, .modal-bg { display: none !important; }
  #print-root { position: static; background: none; padding: 0; overflow: visible; }
  .sheet { margin: 0; page-break-after: always; break-after: page; }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
  .label { outline: none; }
}

/* Import */
.progress { height: 14px; background: #e6ebe8; border-radius: 8px; overflow: hidden; margin-top: 14px; }
.progress > div { height: 100%; background: var(--primary); transition: width .3s; }
.log { background: #1e2b25; color: #d7e7de; padding: 10px 12px; border-radius: 8px; max-height: 260px; overflow: auto; font-size: .85rem; white-space: pre-wrap; }
