:root {
  --nuit: #14213d; --nuit-2: #1f3260; --blanc: #fff; --gris: #f1f3f7; --gris-2: #e3e7ee; --texte: #1b2333; --muted: #667085;
  --vert: #2f855a; --vert-clair: #e7f5ee; --orange: #b54708; --orange-clair: #fff4e5; --rouge: #b42318; --rouge-clair: #fdecec;
  --r: 12px; --tap: 52px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--gris); color: var(--texte); font-size: 16px; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; }
a { color: var(--nuit-2); }
h1 { font-size: 1.45rem; margin: .2rem 0 1rem; color: var(--nuit); }
h2 { font-size: 1.15rem; margin: 1.4rem 0 .6rem; color: var(--nuit); }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* Barre supérieure */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--nuit); color: #fff; display: flex; align-items: center; gap: .6rem; padding: .5rem .8rem; min-height: 56px; }
.topbar .brand { font-weight: 800; letter-spacing: .04em; white-space: nowrap; text-decoration: none; color: #fff; }
.topbar .brand small { font-weight: 400; opacity: .7; margin-left: .3rem; }
.topbar .search { flex: 1; max-width: 420px; position: relative; }
.topbar .search input { width: 100%; border: 0; border-radius: 10px; padding: .55rem .8rem; background: var(--nuit-2); color: #fff; }
.topbar .search input::placeholder { color: #b9c2d6; }
.search-results { position: absolute; top: 110%; left: 0; right: 0; background: #fff; color: var(--texte); border-radius: 10px; box-shadow: 0 10px 30px #0003; max-height: 60vh; overflow: auto; }
.search-results a { display: block; padding: .6rem .8rem; text-decoration: none; color: inherit; border-bottom: 1px solid var(--gris-2); }
.sync { font-size: .8rem; padding: .25rem .55rem; border-radius: 99px; background: #ffffff1f; white-space: nowrap; }
.sync.off { background: var(--orange); } .sync.pending { background: #c58a00; }
.topbar .user { font-size: .85rem; opacity: .85; white-space: nowrap; }

/* Navigation */
.layout { display: flex; min-height: calc(100vh - 56px); }
nav.side { width: 220px; flex: none; background: #fff; border-right: 1px solid var(--gris-2); padding: .6rem; position: sticky; top: 56px; height: calc(100vh - 56px); overflow: auto; }
nav.side a { display: flex; align-items: center; gap: .6rem; padding: .75rem .8rem; border-radius: 10px; text-decoration: none; color: var(--texte); font-weight: 500; }
nav.side a.active, nav.side a:hover { background: var(--gris); color: var(--nuit); }
main { flex: 1; min-width: 0; padding: 1rem 1.2rem 6rem; max-width: 1200px; margin: 0 auto; width: 100%; }
.bottomnav { display: none; }
@media (max-width: 860px) {
  nav.side { display: none; }
  .topbar .user, .topbar .brand small { display: none; }
  .topbar { gap: .4rem; padding: .5rem; }
  .topbar .search { min-width: 0; }
  .topbar .brand { font-size: .9rem; }
  main { padding: .8rem .7rem 6.5rem; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: #fff; border-top: 1px solid var(--gris-2); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { flex: 1; text-align: center; padding: .55rem 0; font-size: .72rem; color: var(--muted); text-decoration: none; }
  .bottomnav a .ico { display: block; font-size: 1.3rem; }
  .bottomnav a.active { color: var(--nuit); font-weight: 700; }
}

/* Cartes et grilles */
.card { background: #fff; border-radius: var(--r); padding: 1rem; box-shadow: 0 1px 2px #0000000d; margin-bottom: .9rem; border: 1px solid var(--gris-2); }
.grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.stat { background: #fff; border-radius: var(--r); padding: 1rem; border: 1px solid var(--gris-2); text-decoration: none; color: inherit; display: block; }
.stat .n { font-size: 2rem; font-weight: 800; color: var(--nuit); } .stat .l { color: var(--muted); font-size: .9rem; }
.stat.alert .n { color: var(--orange); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .75rem .2rem; border-bottom: 1px solid var(--gris-2); display: flex; gap: .6rem; align-items: center; justify-content: space-between; }
.list li:last-child { border-bottom: 0; }
.list a.item { text-decoration: none; color: inherit; flex: 1; }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--gris-2); background: #fff; color: var(--nuit); font-weight: 600; cursor: pointer; text-decoration: none; touch-action: manipulation; }
.btn.primary { background: var(--nuit); border-color: var(--nuit); color: #fff; }
.btn.success { background: var(--vert); border-color: var(--vert); color: #fff; }
.btn.danger { background: #fff; border-color: var(--rouge); color: var(--rouge); }
.btn.big { min-height: var(--tap); font-size: 1.05rem; padding: .7rem 1.3rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.round { border-radius: 50%; width: 64px; height: 64px; padding: 0; font-size: 1.6rem; }

/* Badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--gris); color: var(--nuit); white-space: nowrap; }
.badge.ok { background: var(--vert-clair); color: var(--vert); } .badge.warn { background: var(--orange-clair); color: var(--orange); } .badge.err { background: var(--rouge-clair); color: var(--rouge); }
.badge.info { background: #e8eefc; color: var(--nuit-2); }

/* Formulaires */
label.f { display: block; margin-bottom: .7rem; font-weight: 600; font-size: .9rem; }
label.f input, label.f select, label.f textarea, .input { display: block; width: 100%; margin-top: .3rem; padding: .7rem .8rem; border: 1px solid #cfd5df; border-radius: 10px; background: #fff; font-weight: 400; min-height: 46px; }
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 .8rem; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; font-size: .8rem; padding: .5rem; border-bottom: 2px solid var(--gris-2); }
table.t td { padding: .55rem .5rem; border-bottom: 1px solid var(--gris-2); vertical-align: top; }
.table-wrap { overflow-x: auto; }

/* Écran d'inspection */
.statusbar { position: sticky; top: 56px; z-index: 15; background: #fff; border-bottom: 1px solid var(--gris-2); margin: -1rem -1.2rem .8rem; padding: .55rem 1rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; font-size: .85rem; }
@media (max-width: 860px) { .statusbar { margin: -.8rem -.7rem .7rem; } }
.statusbar .piece { font-weight: 800; color: var(--nuit); font-size: 1rem; margin-right: auto; }
.tabs { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .4rem; margin-bottom: .6rem; scrollbar-width: thin; }
.tab { flex: none; padding: .6rem .9rem; border-radius: 99px; border: 1px solid var(--gris-2); background: #fff; font-weight: 600; cursor: pointer; min-height: 44px; white-space: nowrap; }
.tab.active { background: var(--nuit); color: #fff; border-color: var(--nuit); }
.tab.done { border-color: var(--vert); color: var(--vert); } .tab.done.active { background: var(--vert); color: #fff; }
.item { background: #fff; border: 1px solid var(--gris-2); border-radius: var(--r); padding: .8rem; margin-bottom: .6rem; }
.item.done { border-left: 5px solid var(--vert); } .item.todo { border-left: 5px solid #cfd5df; } .item.na { opacity: .75; border-left: 5px solid #98a2b3; }
.item.ecart { border-left: 5px solid var(--orange); background: #fffaf3; }
.item .head { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.item .lib { font-weight: 700; } .item .code { color: var(--muted); font-size: .78rem; }
.notes { display: grid; grid-template-columns: repeat(5, 1fr) repeat(4, auto); gap: .35rem; margin: .6rem 0 .3rem; }
.notes button { min-height: 48px; border-radius: 10px; border: 1px solid #cfd5df; background: #fff; font-weight: 800; font-size: 1.05rem; cursor: pointer; touch-action: manipulation; }
.notes button.sel { background: var(--nuit); color: #fff; border-color: var(--nuit); }
.notes button.n1.sel { background: var(--vert); border-color: var(--vert); }
.notes button.n4.sel, .notes button.n5.sel { background: var(--rouge); border-color: var(--rouge); }
.notes button.flag { padding: 0 .7rem; font-size: .9rem; }
.notes button.flag.sel { background: var(--orange); border-color: var(--orange); }
@media (max-width: 520px) { .notes { grid-template-columns: repeat(5, 1fr); } .notes button.flag { grid-column: span 1; } }
.entree-ref { background: #f6f8fb; border-radius: 8px; padding: .5rem .6rem; font-size: .85rem; margin-top: .4rem; }
.obs { width: 100%; border: 1px solid #cfd5df; border-radius: 10px; padding: .55rem .7rem; min-height: 46px; margin-top: .3rem; }
.thumbs { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.thumbs img, .thumbs .ph { width: 76px; height: 76px; object-fit: cover; border-radius: 8px; border: 1px solid var(--gris-2); cursor: pointer; background: var(--gris); }
.thumbs .pending { outline: 3px dashed #c58a00; }
.fab-bar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 25; background: #fffffff2; backdrop-filter: blur(6px); border-top: 1px solid var(--gris-2); display: flex; gap: .6rem; justify-content: center; align-items: center; padding: .6rem .6rem calc(.6rem + env(safe-area-inset-bottom)); }
@media (min-width: 861px) { .fab-bar { left: 220px; } }
.fab-bar .btn { min-height: 56px; }
.mic.listening { background: var(--rouge); border-color: var(--rouge); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px #b4231833; } }

/* Fenêtres modales */
.modal-bg { position: fixed; inset: 0; background: #0b1324b3; z-index: 50; display: flex; align-items: center; justify-content: center; padding: .6rem; }
.modal { background: #fff; border-radius: 16px; width: min(720px, 100%); max-height: 94vh; overflow: auto; padding: 1rem; }
.modal.full { width: 100%; height: 100%; max-height: none; border-radius: 0; padding: 0; background: #000; display: flex; flex-direction: column; }
.camera video, .camera canvas { width: 100%; flex: 1; object-fit: contain; background: #000; min-height: 0; }
.camera .bar { display: flex; justify-content: space-around; align-items: center; padding: 1rem; background: #000; }
.sigpad { width: 100%; height: 220px; border: 2px dashed #98a2b3; border-radius: 12px; background: #fff; touch-action: none; display: block; }
.viewer { position: relative; overflow: hidden; background: #111; flex: 1; touch-action: none; }
.viewer img, .viewer canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; }

/* Comparaison */
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.compare figure { margin: 0; background: #fff; border-radius: 10px; overflow: hidden; border: 1px solid var(--gris-2); }
.compare img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: var(--gris); }
.compare figcaption { padding: .5rem; font-size: .82rem; }
.slider { position: relative; width: 100%; aspect-ratio: 4/3; overflow: hidden; border-radius: 10px; background: #000; user-select: none; touch-action: none; }
.slider img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.slider .top { clip-path: inset(0 50% 0 0); }
.slider .handle { position: absolute; top: 0; bottom: 0; width: 4px; background: #fff; left: 50%; box-shadow: 0 0 6px #000; }
.slider .lab { position: absolute; top: .5rem; background: #000a; color: #fff; padding: .2rem .5rem; border-radius: 6px; font-size: .78rem; }
@media (max-width: 640px) { .compare { grid-template-columns: 1fr; } }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--nuit), #2b4475); padding: 1rem; }
.login .card { width: min(420px, 100%); padding: 1.6rem; }
.login .logo { font-size: 1.6rem; font-weight: 900; color: var(--nuit); letter-spacing: .05em; }

.toast-wrap { position: fixed; top: 64px; right: 12px; z-index: 60; display: flex; flex-direction: column; gap: .4rem; }
.toast { background: var(--nuit); color: #fff; padding: .7rem 1rem; border-radius: 10px; box-shadow: 0 6px 20px #0003; max-width: 360px; }
.toast.err { background: var(--rouge); } .toast.ok { background: var(--vert); }
.alert { padding: .7rem .9rem; border-radius: 10px; margin: .5rem 0; font-size: .92rem; }
.alert.warn { background: var(--orange-clair); color: #7a3306; } .alert.err { background: var(--rouge-clair); color: #7a1a12; } .alert.info { background: #e8eefc; color: var(--nuit-2); } .alert.ok { background: var(--vert-clair); color: #1f5c3e; }
.tree ul { list-style: none; padding-left: 1.1rem; margin: 0; border-left: 1px dashed #cfd5df; }
.tree > ul { border: 0; padding-left: 0; }
.tree li { padding: .25rem 0; }
.progress { height: 8px; background: var(--gris-2); border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--vert); }
