:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #dde2ea;
  --primary: #0b5cad;
  --primary-dark: #08467f;
  --sidebar: #0f2a47;
  --sidebar-text: #c9d6e6;
  --danger: #b42318;
  --danger-bg: #fde8e6;
  --warn: #a15c00;
  --warn-bg: #fff2d6;
  --ok: #18794e;
  --ok-bg: #e3f5ec;
  --info-bg: #e7f0fb;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .75rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; margin-top: 1rem; }
.muted { color: var(--muted); }
.small, small { font-size: .85rem; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-warn { color: var(--warn); font-weight: 600; }

/* Structure */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 1rem .75rem;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: var(--sidebar-text); padding: .55rem .75rem; border-radius: 6px; }
.sidebar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; opacity: .6; margin: 1.2rem .75rem .4rem; }
.nav-future { margin-top: auto; display: flex; flex-direction: column; }
.nav-future span { padding: .3rem .75rem; opacity: .45; font-size: .9rem; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 700; margin-bottom: 1.25rem; padding: 0 .5rem; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-weight: 400; font-size: .75rem; opacity: .75; }
.brand-mark {
  display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 .3rem; border-radius: 8px; font-size: .8rem;
  background: var(--primary); color: #fff; font-weight: 800; letter-spacing: .02em;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .75rem 1.5rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 600; font-size: 1.1rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu { display: flex; align-items: center; gap: 1rem; font-size: .9rem; }
.menu-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: 6px; font-size: 1.2rem; padding: .2rem .6rem; cursor: pointer; }
.content { padding: 1.5rem; max-width: 1300px; width: 100%; }

/* Invité (connexion, installation) */
body.guest { display: grid; place-items: center; min-height: 100vh; padding: 1rem; background: var(--sidebar); }
.guest-card { background: var(--surface); width: 100%; max-width: 420px; padding: 2rem; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.brand-center { color: var(--text); justify-content: center; margin-bottom: 1.5rem; }
.guest-card h1 { text-align: center; font-size: 1.3rem; }

/* Composants */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 560px; }
.card.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 1rem; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; color: var(--text); display: flex; flex-direction: column; }
.tile:hover { border-color: var(--primary); text-decoration: none; }
.tile-value { font-size: 1.9rem; font-weight: 700; }
.tile-label { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: .3rem; padding: .5rem .95rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #b8c1cf; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-block { width: 100%; justify-content: center; }
button.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
form.inline { display: inline; }

.badge { display: inline-block; background: var(--info-bg); color: var(--primary-dark); border-radius: 999px; padding: .05rem .55rem; font-size: .78rem; font-weight: 600; }
.pill { display: inline-block; border-radius: 999px; padding: .08rem .6rem; font-size: .8rem; font-weight: 600; background: #eef1f5; color: var(--muted); }
.pill-actif { background: var(--ok-bg); color: var(--ok); }
.pill-maintenance, .pill-conge, .pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-immobilise, .pill-arret, .pill-danger { background: var(--danger-bg); color: var(--danger); }
.pill-planifie, .pill-chargement { background: #e8f0fb; color: #2456a6; }
.pill-en_route, .pill-douane { background: var(--warn-bg); color: var(--warn); }
.pill-livre, .pill-termine { background: var(--ok-bg); color: var(--ok); }
.pill-vendu, .pill-parti, .pill-annule, .pill-archived { background: #eef1f5; color: var(--muted); }

.flash { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid transparent; }
.flash-success { background: var(--ok-bg); color: var(--ok); border-color: #b7e3cc; }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: #f5c2bd; }
.flash-info { background: var(--info-bg); color: var(--primary-dark); border-color: #c4daf3; }

/* Tableaux */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f9fafb; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table-hover tbody tr:hover { background: #f7f9fc; }
.table.compact th, .table.compact td { padding: .4rem .6rem; font-size: .9rem; }
.card .table th { background: none; }
tr.is-archived td { color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.toolbar-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.search { display: flex; gap: .5rem; flex-wrap: wrap; }
.search input[type=search] { min-width: 260px; }
.pagination { display: flex; align-items: center; gap: 1rem; justify-content: center; margin: 1rem 0; }

/* Formulaires */
input, select, textarea {
  font: inherit; color: var(--text); background: #fff; border: 1px solid #c8cfda; border-radius: 6px;
  padding: .5rem .65rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(11,92,173,.25); border-color: var(--primary); }
input.upper { text-transform: uppercase; }
.search input, .search select { width: auto; }
label { display: block; font-weight: 500; font-size: .9rem; }
label > input, label > select, label > textarea { margin-top: .3rem; font-weight: 400; }
label.checkbox { display: flex; align-items: center; gap: .5rem; margin-top: 1.6rem; }
label.checkbox input { width: auto; margin: 0; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
fieldset.card { margin: 0 0 1rem; min-width: 0; }
legend { font-weight: 700; padding: 0 .4rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem 1.1rem; }
.field label + input, .field label + select, .field label + textarea { margin-top: .3rem; }
.field-wide { grid-column: 1 / -1; }
.req { color: var(--danger); }
.help { display: block; color: var(--muted); margin-top: .25rem; }
.error { display: block; color: var(--danger); margin-top: .25rem; font-weight: 500; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }

.checkbox-row { display: flex; flex-wrap: wrap; gap: .25rem 1.5rem; }
.checkbox-row label.checkbox { margin-top: .4rem; }
span.label { display: block; font-weight: 500; font-size: .9rem; }
.center { text-align: center; }
.perm-matrix td:first-child { min-width: 200px; }
.perm-matrix input { width: auto; }
.societe-switch select { width: auto; padding: .35rem .5rem; }
.societe-badge { font-size: .85rem; }
.tile-split { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Préproduction */
.preprod-banner { position: sticky; top: 0; z-index: 30; background: #b45309; color: #fff; text-align: center; font-weight: 700; font-size: .85rem; padding: .35rem 1rem; letter-spacing: .02em; }
body.guest .preprod-banner { position: fixed; left: 0; right: 0; }

/* Fiches */
.details { display: grid; grid-template-columns: minmax(140px, 40%) 1fr; gap: .45rem 1rem; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: .3rem 0; border-bottom: 1px solid var(--border); }
.plain-list li:last-child { border-bottom: 0; }
.history { list-style: none; padding: 0; margin: 0 0 .75rem; font-size: .9rem; }
.history li { padding: .25rem 0; }
.status-list { list-style: none; padding: 0; margin: 0; }
.status-list li { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.status-list li:last-child { border-bottom: 0; }
.checks { list-style: none; padding: 0; }
.checks .ok { color: var(--ok); }
.checks .ko { color: var(--danger); font-weight: 600; }

@media (max-width: 860px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .menu-toggle { display: inline-block; }
  .user-name { display: none; }
  .topbar { flex-wrap: wrap; gap: .5rem; }
  .societe-switch select { max-width: 11rem; }
  .topbar { padding: .6rem 1rem; }
  .content { padding: 1rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .search input[type=search] { min-width: 0; flex: 1; }
  .details { grid-template-columns: 1fr; gap: .1rem; }
  .details dd { margin-bottom: .5rem; }
}
@media print {
  .sidebar, .topbar, .toolbar-actions, .form-actions { display: none; }
  .content { padding: 0; }
}
