/* Orbibat Terrain — outil de terrain, lisible en plein jour */
@font-face {
  font-family: "Instrument Sans";
  src: url("vendor/instrument-sans.woff2") format("woff2-variations");
  font-weight: 400 700;
  font-stretch: 75% 100%;
  font-display: swap;
}

:root {
  --paper: #EEF2F4;
  --surface: #FFFFFF;
  --surface-2: #F6F8F9;
  --ink: #14212E;
  --ink-2: #3D4B59;
  --muted: #5B6B7A;
  --line: #D6DEE4;
  --line-strong: #B9C5CE;
  --accent: #0062B8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3EEF9;
  --ok: #1F7A4D;
  --ok-soft: #E2F2E9;
  --warn: #A65400;
  --warn-soft: #FCEEDC;
  --danger: #B3261E;
  --danger-soft: #FBE6E4;
  /* Code couleur fibre : un repère par technicien */
  --fo-1: #D7262E;
  --fo-2: #1E63C6;
  --fo-3: #2F8F3A;
  --fo-4: #E0A800;
  --fo-5: #7B3FB0;
  --fo-6: #8A8F94;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --shadow: 0 1px 2px rgba(20, 33, 46, .06), 0 4px 14px rgba(20, 33, 46, .06);
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --nav-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: #fff; }
input, textarea, select, button { font: inherit; color: inherit; caret-color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
a { color: var(--accent); text-underline-offset: 3px; }
.num { font-variant-numeric: tabular-nums; }
svg.lucide { width: 20px; height: 20px; stroke-width: 2; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Démarrage ---------- */
.boot { min-height: 100dvh; display: grid; place-content: center; gap: 12px; justify-items: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Connexion ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 380px; }
.wordmark { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.25rem; letter-spacing: -0.01em; }
.wordmark .mark { width: 34px; height: 34px; }
.login h1 { font-size: 1.75rem; line-height: 1.15; letter-spacing: -0.02em; margin: 28px 0 6px; }
.login p.lead { color: var(--muted); margin: 0 0 24px; }

/* ---------- Champs ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: .9375rem; }
.field .hint { color: var(--muted); font-size: .8125rem; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1.5px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); transition: border-color .15s;
}
.textarea { min-height: 84px; resize: vertical; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .textarea::placeholder { color: #6E7C89; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: var(--r-md); margin-bottom: 14px; font-size: .9375rem; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: var(--r-md);
  border: 1.5px solid transparent; font-weight: 600; cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .1s;
  text-decoration: none; white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: #004F95; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ok:hover:not(:disabled) { background: #17603C; }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { border-color: var(--ink-2); background: var(--surface-2); }
.btn-danger-ghost { background: var(--surface); border-color: #E3B4B0; color: var(--danger); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: .9375rem; }
.btn-icon { min-height: 44px; width: 44px; padding: 0; }
.btn .spinner { width: 16px; height: 16px; border-width: 2px; border-color: rgba(255,255,255,.4); border-top-color: #fff; }
.btn-ghost .spinner { border-color: var(--line); border-top-color: var(--accent); }

/* ---------- Coque ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--ink); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.topbar-in { max-width: 980px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.topbar .wordmark { font-size: 1.0625rem; }
.topbar .wordmark .mark { width: 28px; height: 28px; }
.topbar .spacer { flex: 1; }
.who {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px 0 10px;
  border-radius: 999px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18);
  color: #fff; font-weight: 600; cursor: pointer;
}
.who:hover { background: rgba(255,255,255,.16); }
.who svg.lucide { width: 16px; height: 16px; opacity: .8; }
.icon-btn { background: none; border: 0; color: inherit; width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--r-md); cursor: pointer; }
.icon-btn:hover { background: rgba(255,255,255,.12); }

.main { max-width: 980px; margin: 0 auto; padding: 20px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
.main.admin { padding-bottom: 48px; }
.page-title { font-size: 1.5rem; letter-spacing: -0.02em; line-height: 1.2; margin: 4px 0 4px; text-wrap: balance; }
.page-sub { color: var(--muted); margin: 0 0 20px; }
.section-title { font-size: 1.125rem; margin: 32px 0 12px; letter-spacing: -0.01em; display: flex; align-items: baseline; gap: 8px; }
.section-title .count { color: var(--muted); font-weight: 500; font-size: 1rem; }

/* Navigation basse (techniciens) */
.bottomnav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav-in { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); height: var(--nav-h); }
.navbtn {
  background: none; border: 0; cursor: pointer; display: grid; justify-items: center; align-content: center; gap: 3px;
  color: var(--muted); font-size: .8125rem; font-weight: 600; position: relative;
}
.navbtn[aria-current="page"] { color: var(--accent); }
.navbtn[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.navbtn .badge { position: absolute; top: 8px; left: calc(50% + 6px); }

/* Onglets (admin) */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 20px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: 0; cursor: pointer; padding: 12px 12px; min-height: 48px;
  font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.badge.neutral { background: var(--accent); }

/* ---------- Panneaux & listes ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 16px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.item { padding: 14px 16px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.item:first-child { border-top: 0; }
.item-head { display: flex; align-items: flex-start; gap: 12px; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 650; margin: 0; }
.item-meta { color: var(--muted); font-size: .9375rem; margin: 2px 0 0; }
.item-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.item-note { font-size: .9375rem; background: var(--surface-2); border-radius: var(--r-sm); padding: 8px 10px; color: var(--ink-2); }

.status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 650; white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.en_attente { color: var(--warn); background: var(--warn-soft); }
.status.valide, .status.reprise { color: var(--ok); background: var(--ok-soft); }
.status.refuse { color: var(--danger); background: var(--danger-soft); }
.mailflag { font-size: .8125rem; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.mailflag svg.lucide { width: 14px; height: 14px; }
.mailflag.ko { color: var(--danger); }

/* Repère fibre du technicien */
.fo { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 2px rgba(255,255,255,.55); }
.fo.lg { width: 16px; height: 16px; }

.empty { text-align: center; padding: 32px 20px; color: var(--muted); }
.empty svg.lucide { width: 28px; height: 28px; color: var(--line-strong); margin-bottom: 6px; }
.empty p { margin: 4px 0 0; }
.empty strong { color: var(--ink); display: block; }

/* ---------- Choix du technicien ---------- */
.picker { display: grid; gap: 10px; margin-top: 8px; }
.pick {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  min-height: 68px; padding: 12px 16px; background: var(--surface);
  border: 1.5px solid var(--line); border-radius: var(--r-lg); cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.pick:hover { border-color: var(--accent); background: var(--accent-soft); }
.pick .fo { width: 18px; height: 18px; }
.pick-name { font-weight: 650; font-size: 1.0625rem; }
.pick-mail { color: var(--muted); font-size: .875rem; }
.pick svg.lucide { margin-left: auto; color: var(--muted); }

/* ---------- Catalogue de commande ---------- */
.cat-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 200px; }
.search svg.lucide { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
.search .input { padding-left: 38px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: .9375rem; cursor: pointer; user-select: none; min-height: 44px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.cat-group { margin-top: 18px; }
.cat-group h3 { font-size: 1rem; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.cat-group h3 .code-kind { color: var(--muted); font-weight: 500; font-size: .875rem; }
.art { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px 12px 10px 16px; border-top: 1px solid var(--line); }
.art:first-child { border-top: 0; }
.art.has-qty { background: var(--accent-soft); }
.art-name { font-weight: 600; font-size: .9375rem; line-height: 1.3; overflow-wrap: anywhere; }
.art-code { color: var(--muted); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.art-note { color: var(--warn); font-size: .8125rem; font-weight: 600; }
.stepper { display: flex; align-items: center; border: 1.5px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.stepper button { width: 42px; height: 44px; border: 0; background: none; cursor: pointer; display: grid; place-items: center; color: var(--ink-2); }
.stepper button:hover { background: var(--surface-2); color: var(--accent); }
.stepper button:disabled { color: var(--line-strong); cursor: default; background: none; }
.stepper input { width: 52px; height: 44px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; -moz-appearance: textfield; background: transparent; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: none; background: var(--accent-soft); }
.unit { color: var(--muted); font-size: .8125rem; width: 26px; text-align: left; }
.art-qty { display: flex; align-items: center; gap: 6px; }

.cart {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 15;
  padding: 10px 16px; background: rgba(238, 242, 244, .92); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.cart-in { max-width: 980px; margin: 0 auto; display: flex; gap: 12px; align-items: center; }
.cart-sum { flex: 1; font-weight: 600; }
.cart-sum span { color: var(--muted); font-weight: 500; display: block; font-size: .875rem; }

.lines { width: 100%; border-collapse: collapse; font-size: .9375rem; }
.lines td { padding: 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
.lines tr:first-child td { border-top: 0; }
.lines td.q { text-align: right; font-weight: 700; white-space: nowrap; padding-left: 12px; font-variant-numeric: tabular-nums; }
.lines td.c { color: var(--muted); font-size: .8125rem; padding-right: 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .9375rem; min-height: 32px; display: flex; align-items: center; list-style: none; gap: 6px; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary svg.lucide { width: 16px; height: 16px; transition: transform .2s; }
details.more[open] summary svg.lucide { transform: rotate(90deg); }

/* ---------- Malfaçons : le délai est l'information principale ---------- */
.mf { display: grid; grid-template-columns: 84px 1fr; gap: 14px; padding: 16px; border-top: 1px solid var(--line); }
.mf:first-child { border-top: 0; }
.due { align-self: start; min-height: 88px; display: grid; align-content: center; justify-items: center; border-radius: var(--r-md); padding: 10px 4px; text-align: center; line-height: 1; }
.due .d { font-size: 2rem; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; font-stretch: 85%; }
.due .l { font-size: .75rem; font-weight: 650; margin-top: 6px; }
.due.ok { background: var(--ok-soft); color: var(--ok); }
.due.warn { background: var(--warn-soft); color: var(--warn); }
.due.late { background: var(--danger); color: #fff; }
.due.done { background: var(--surface-2); color: var(--muted); }
.due.done .d { font-size: 1.5rem; }
.mf-title { font-weight: 650; margin: 0; overflow-wrap: anywhere; }
.mf-meta { color: var(--muted); font-size: .9375rem; margin: 2px 0 8px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.mf-meta .who-inline { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 600; }
.mf-desc { margin: 0 0 10px; color: var(--ink-2); font-size: .9375rem; }

/* Filtres */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { min-height: 38px; padding: 0 12px; border-radius: 999px; border: 1.5px solid var(--line-strong); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .875rem; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { border-color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Décision admin */
.decide { display: grid; gap: 8px; margin-top: 4px; }
.decide .btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Toasts */
.toasts { position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 12px); z-index: 50; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; max-width: 460px; width: 100%; display: flex; gap: 10px; align-items: flex-start;
  background: var(--ink); color: #fff; padding: 12px 14px; border-radius: var(--r-md);
  box-shadow: 0 8px 24px rgba(20,33,46,.25); font-size: .9375rem;
  animation: toast-in .22s cubic-bezier(.16,1,.3,1);
}
.toast.err { background: var(--danger); }
.toast.ok svg.lucide { color: #8FD9B0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

dialog.sheet { border: 0; padding: 0; border-radius: var(--r-lg); width: min(440px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(20,33,46,.3); }
dialog.sheet::backdrop { background: rgba(20,33,46,.45); }
.sheet-in { padding: 20px 18px; }
.sheet-in h2 { margin: 0 0 6px; font-size: 1.25rem; }

.skeleton { height: 64px; border-radius: var(--r-md); background: linear-gradient(90deg, var(--surface-2), #E8EDF0, var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin-bottom: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.grid-2 { display: grid; gap: 20px; }
@media (min-width: 860px) {
  .grid-2 { grid-template-columns: 360px 1fr; align-items: start; }
  .grid-2 .sticky { position: sticky; top: 84px; }
}
@media (min-width: 720px) {
  .main { padding-top: 28px; }
  .page-title { font-size: 1.75rem; }
}
@media (max-width: 420px) {
  .art { padding-left: 12px; gap: 8px; }
  .art-name { font-size: .875rem; }
  .stepper button { width: 38px; }
  .stepper input { width: 46px; }
  .row-2 { grid-template-columns: 1fr; }
  .topbar .wordmark span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
