:root {
  --bg: #F3F6F8;
  --surface: #FFFFFF;
  --ink: #0F2C3F;
  --ink-2: #4A6273;
  --ink-3: #7F93A1;
  --line: #DCE4EA;
  --line-2: #EBF0F3;
  --accent: #0B7A9C;
  --accent-soft: #E3F1F6;
  --rouge: #D23A2E;
  --rouge-soft: #FBE9E7;
  --vert: #1E8A57;
  --vert-soft: #E5F3EC;
  --noir: #000000;
  --noir-soft: #E6E8EA;
  --inconnu: #B9C6CF;
  --vide: #EEF2F5;
  --nav: #0F2C3F;
  --radius: 10px;
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Structure ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav {
  background: var(--nav);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; text-decoration: none;
  font-weight: 750; font-stretch: 85%; font-size: 20px; letter-spacing: -0.01em;
  padding: 4px 8px 22px;
}
.nav nav { display: flex; flex-direction: column; gap: 2px; }
.nav nav a {
  color: #C9D7E0; text-decoration: none;
  padding: 9px 10px; border-radius: 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.nav nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav nav a[aria-current="page"] { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.badge {
  background: var(--rouge); color: #fff; font-size: 12px; font-weight: 650;
  min-width: 22px; padding: 1px 7px; border-radius: 99px; text-align: center;
}
.badge:empty { display: none; }
.nav-foot { margin-top: auto; }
.role { display: grid; grid-template-columns: 1fr 1fr; background: rgba(255,255,255,.08); border-radius: 8px; padding: 3px; }
.role button { border: 0; background: none; color: #C9D7E0; padding: 6px 4px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.role button[aria-pressed="true"] { background: #fff; color: var(--ink); font-weight: 600; }
.nav-meta { font-size: 12px; color: #8FA6B5; margin: 12px 4px 0; line-height: 1.5; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  display: flex; gap: 16px; align-items: center;
  padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.search { position: relative; flex: 1; max-width: 620px; display: flex; align-items: center; }
.search > svg { position: absolute; left: 12px; color: var(--ink-3); }
.search input {
  width: 100%; padding: 10px 40px 10px 40px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--bg);
}
.search input:focus { background: #fff; border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.search kbd {
  position: absolute; right: 10px; font-family: inherit; font-size: 12px; color: var(--ink-3);
  border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; background: #fff;
}
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  list-style: none; margin: 0; padding: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15,44,63,.14); max-height: 420px; overflow: auto;
}
.search-results li { padding: 8px 10px; border-radius: 7px; cursor: pointer; display: grid; grid-template-columns: 14px 1fr auto; gap: 10px; align-items: center; }
.search-results li[aria-selected="true"], .search-results li:hover { background: var(--accent-soft); }
.search-results .r-lib { font-weight: 550; }
.search-results .r-sub { font-size: 12.5px; color: var(--ink-2); }
.search-results .r-cov { font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.search-results .empty { display: block; color: var(--ink-2); cursor: default; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }

.readonly-banner { background: var(--accent-soft); color: var(--ink); padding: 9px 28px; font-size: 14px; border-bottom: 1px solid var(--line); }

#view { padding: 26px 28px 60px; outline: none; }

/* ---------- Typo & éléments ---------- */
h1 { font-size: 30px; line-height: 1.15; font-weight: 750; font-stretch: 82%; letter-spacing: -0.015em; margin: 0; }
h2 { font-size: 19px; font-weight: 700; font-stretch: 90%; margin: 0 0 4px; }
h3 { font-size: 15px; font-weight: 650; margin: 0; }
.lede { color: var(--ink-2); margin: 6px 0 0; max-width: 75ch; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 550; font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #18405A; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { padding: 16px 20px 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.panel-body { padding: 0 20px 18px; }

/* Puces de statut */
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.s-rouge { background: var(--rouge); }
.s-vert { background: var(--vert); }
.s-noir { background: var(--noir); }
.s-inconnu { background: repeating-linear-gradient(135deg, var(--inconnu) 0 3px, #fff 3px 5px); }
.s-vide { background: var(--vide); }
.s-bientot { background: repeating-linear-gradient(135deg, #D7E3EA 0 3px, #F4F8FA 3px 6px); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 7px; border-radius: 99px; font-size: 13px; font-weight: 600; white-space: nowrap;
}
.chip.rouge { background: var(--rouge-soft); color: #A42B21; }
.chip.vert { background: var(--vert-soft); color: #16683F; }
.chip.noir { background: var(--noir-soft); color: #000; }
.chip.inconnu { background: #EEF2F5; color: var(--ink-2); }
.chip.vide { background: #F4F7F9; color: var(--ink-3); }
.flag { color: var(--rouge); font-weight: 650; font-size: 12.5px; white-space: nowrap; }

/* ---------- Bandeau de synthèse ---------- */
.summary { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 0; margin-bottom: 22px; }
.summary > div { padding: 18px 20px; border-left: 1px solid var(--line); }
.summary > div:first-child { border-left: 0; }
.summary .k { font-size: 13.5px; color: var(--ink-2); }
.summary .v { font-size: 28px; font-weight: 750; font-stretch: 85%; letter-spacing: -0.01em; line-height: 1.2; margin-top: 2px; }
.summary .d { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.split { display: flex; height: 10px; border-radius: 4px; overflow: hidden; margin: 10px 0 8px; gap: 2px; }
.split span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { color: var(--ink); font-weight: 650; }

/* ---------- Mosaïque ---------- */
.dash { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 22px; align-items: start; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px; border-left: 1px solid var(--line); }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
select.input, input.input {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: #fff; font-size: 14px;
}

.mosaic-wrap { overflow-x: auto; padding: 0 20px 18px; }
.mosaic { border-collapse: separate; border-spacing: 3px; font-size: 13px; }
.mosaic th { font-weight: 550; color: var(--ink-2); }
.mosaic thead th {
  height: 118px; vertical-align: bottom; padding: 0 0 6px; width: 21px; min-width: 21px;
}
.mosaic thead th > span {
  display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg);
  white-space: nowrap; font-size: 12.5px; text-align: left;
}
.mosaic thead th.grp > span { color: var(--ink); font-weight: 700; }
.mosaic thead th.dep > span { color: var(--ink-3); }
.mosaic tbody th {
  text-align: left; padding: 0 10px 0 0; white-space: nowrap; max-width: 240px;
  overflow: hidden; text-overflow: ellipsis; font-weight: 450; color: var(--ink);
}
.mosaic tbody th a { color: inherit; text-decoration: none; }
.mosaic tbody th a:hover { color: var(--accent); text-decoration: underline; }
.mosaic td { padding: 0; }
.tile {
  display: block; width: 21px; height: 17px; border-radius: 3px; border: 0; padding: 0; cursor: pointer;
}
.tile:hover { outline: 2px solid var(--ink); outline-offset: 1px; }
.tile.grp { width: 28px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.55); }
.mosaic td.sep { width: 8px; }
.tile.s-bientot { cursor: help; }

.tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--ink); color: #fff; padding: 9px 11px; border-radius: 8px;
  font-size: 13px; line-height: 1.45; max-width: 280px; box-shadow: 0 10px 28px rgba(15,44,63,.3);
}
.tip b { font-weight: 650; }
.tip .tl { color: #A9BFCD; }

/* ---------- Liste d'actions prioritaires ---------- */
.todo { list-style: none; margin: 0; padding: 0; }
.todo li { padding: 12px 20px; border-top: 1px solid var(--line-2); display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.todo .verb { font-size: 12.5px; font-weight: 650; padding: 2px 8px; border-radius: 6px; align-self: start; margin-top: 1px; }
.verb.cmd { background: var(--rouge-soft); color: #A42B21; }
.verb.trf { background: var(--accent-soft); color: #075A73; }
.todo a { color: var(--ink); font-weight: 550; text-decoration: none; }
.todo a:hover { color: var(--accent); }
.todo .sub { grid-column: 2; font-size: 13px; color: var(--ink-2); }
.panel-foot { padding: 12px 20px; border-top: 1px solid var(--line-2); }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
table.data thead th { font-size: 13px; font-weight: 600; color: var(--ink-2); background: #F8FAFB; position: sticky; top: 0; }
table.data thead th[data-sort] { cursor: pointer; user-select: none; }
table.data thead th[data-sort]:hover { color: var(--ink); }
table.data thead th[aria-sort="ascending"]::after { content: " ▲"; font-size: 10px; }
table.data thead th[aria-sort="descending"]::after { content: " ▼"; font-size: 10px; }
table.data td.num, table.data th.num { text-align: right; }
table.data td.lib { white-space: normal; min-width: 220px; }
table.data td.sugg { white-space: normal; min-width: 170px; font-size: 13.5px; }
table.data td.lib a { color: var(--ink); text-decoration: none; font-weight: 550; }
table.data td.lib a:hover { color: var(--accent); }
table.data tbody tr:hover td { background: #FAFCFD; }
table.data tr.hl td { background: var(--accent-soft); }
table.data tr.bientot td { color: var(--ink-3); background: repeating-linear-gradient(135deg, #fff 0 8px, #F6F9FB 8px 16px); }
table.data tfoot td { font-weight: 650; border-top: 2px solid var(--line); border-bottom: 0; }

/* Barre de couverture avec zones */
.covbar { position: relative; width: 110px; height: 12px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.covbar .zone { position: absolute; top: 0; bottom: 0; }
.covbar .fill { position: absolute; left: 0; top: 3px; bottom: 3px; border-radius: 2px; }
.covcell { display: flex; align-items: center; gap: 10px; }
.covcell .n { min-width: 60px; text-align: right; font-weight: 600; }

/* Onglets magasins */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tabs button {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 11px; cursor: pointer;
  display: inline-flex; gap: 7px; align-items: center; font-size: 13.5px;
}
.tabs button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabs button .c { font-weight: 700; font-stretch: 85%; }
.tabs button.soon { border-style: dashed; color: var(--ink-3); cursor: help; }

.mini-stats { display: flex; gap: 28px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.mini-stats div .k { font-size: 13px; color: var(--ink-2); }
.mini-stats div .v { font-size: 21px; font-weight: 700; font-stretch: 88%; }

/* ---------- Fiche article ---------- */
.crumbs { font-size: 13.5px; color: var(--ink-2); margin-bottom: 10px; }
.crumbs a { color: var(--ink-2); }
.art-meta { display: flex; gap: 8px 20px; flex-wrap: wrap; align-items: center; color: var(--ink-2); font-size: 14px; margin-top: 8px; }
.art-meta b { color: var(--ink); font-weight: 600; }
.grid-2 { display: flex; flex-direction: column-reverse; gap: 22px; }
.grid-2 > .stack { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); align-items: start; }
.stack { display: grid; gap: 22px; grid-template-columns: minmax(0, 1fr); }
.reco { padding: 4px 20px 18px; }
.reco .line { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line-2); }
.reco .line:first-child { border-top: 0; }
.reco .big { font-size: 22px; font-weight: 750; font-stretch: 85%; }
.colis-edit { display: inline-flex; gap: 6px; align-items: center; }
.colis-edit input { width: 64px; padding: 2px 8px; }
.colis-edit .btn { padding: 2px 10px; font-size: 13px; }
.note { font-size: 13px; color: var(--ink-2); background: #F8FAFB; border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px; margin: 0; }

/* ---------- Import ---------- */
.steps { display: flex; gap: 0; margin: 0 0 22px; padding: 0; counter-reset: step; flex-wrap: wrap; }
.steps li {
  list-style: none; display: flex; align-items: center; gap: 10px; color: var(--ink-3);
  padding-right: 28px; font-weight: 550;
}
.steps li::before {
  counter-increment: step; content: counter(step);
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--line); font-weight: 700; font-size: 13px; background: #fff;
}
.steps li.on { color: var(--ink); }
.steps li.on::before { border-color: var(--ink); background: var(--ink); color: #fff; }
.steps li.done { color: var(--vert); }
.steps li.done::before { content: "✓"; border-color: var(--vert); background: var(--vert); color: #fff; }

.drop {
  border: 2px dashed #B3C4CF; border-radius: 14px; background: #fff;
  padding: 44px 24px; text-align: center; transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop h2 { font-size: 22px; }
.drop p { color: var(--ink-2); margin: 6px auto 18px; max-width: 52ch; }
.drop .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.files { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 18px; }
.file-card { padding: 16px 18px; }
.file-card .type { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; color: var(--vert); }
.file-card h3 { margin: 6px 0 8px; }
.file-card ul { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 14px; }
.file-card li { margin: 3px 0; }
.period { display: flex; gap: 16px; align-items: end; flex-wrap: wrap; margin-top: 18px; padding: 16px 18px; }
.period label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
.done-box { padding: 28px; text-align: center; }
.done-box .big { font-size: 26px; font-weight: 750; font-stretch: 85%; margin: 8px 0; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0; margin: 18px 0 0; text-align: left; border-top: 1px solid var(--line-2); }
.result-grid div { padding: 14px 16px; border-left: 1px solid var(--line-2); }
.result-grid div:first-child { border-left: 0; }
.result-grid .v { font-size: 22px; font-weight: 700; font-stretch: 88%; }
.result-grid .k { font-size: 13px; color: var(--ink-2); }

/* ---------- Paramètres ---------- */
.params { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0; }
.params label { padding: 16px 20px; border-top: 1px solid var(--line-2); display: grid; gap: 6px; }
.params label .k { font-weight: 600; }
.params label .h { font-size: 13px; color: var(--ink-2); }
.params input { width: 110px; }
.scale { display: flex; height: 26px; border-radius: 6px; overflow: hidden; margin: 6px 20px 18px; font-size: 12.5px; color: #fff; font-weight: 600; }
.scale span { display: flex; align-items: center; justify-content: center; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 14px; z-index: 60;
  box-shadow: 0 10px 28px rgba(15,44,63,.3);
}

.is-lecteur [data-admin] { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .dash { grid-template-columns: minmax(0, 1fr); }
  .summary { grid-template-columns: 1fr 1fr; }
  .summary > div:nth-child(3) { border-left: 0; }
  .summary > div:nth-child(n+3) { border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; gap: 8px; padding: 12px 16px; align-items: center; }
  .brand { padding: 0; font-size: 17px; }
  .nav nav { flex-direction: row; flex-wrap: wrap; order: 3; width: 100%; }
  .nav nav a { padding: 6px 9px; font-size: 14px; }
  .nav-foot { margin: 0 0 0 auto; }
  .nav-meta { display: none; }
  .top { padding: 10px 16px; flex-wrap: wrap; position: static; }
  .search { flex: 1 1 100%; max-width: none; }
  .search-results li { grid-template-columns: 14px 1fr; }
  .search-results .r-cov { display: none; }
  .page-head > div { min-width: 0; }
  .top-actions { margin-left: 0; }
  .search kbd { display: none; }
  #view { padding: 18px 16px 48px; }
  .readonly-banner { padding: 9px 16px; }
  .summary { grid-template-columns: 1fr; }
  .summary > div { border-left: 0; border-top: 1px solid var(--line); }
  .summary > div:first-child { border-top: 0; }
  h1 { font-size: 25px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Impression / PDF ---------- */
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { background: #fff; font-size: 11px; }
  .app { display: block; }
  .nav, .top, .readonly-banner, .toolbar, .btn, .tip, .toast, .no-print { display: none !important; }
  #view { padding: 0; }
  .print-head { display: block !important; }
  .panel { border: 1px solid #ccc; break-inside: avoid-page; }
  .dash, .grid-2 { grid-template-columns: 1fr; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.data thead th { position: static; }
  .mosaic-wrap { overflow: visible; }
}
.print-head { display: none; margin-bottom: 10px; font-size: 12px; color: var(--ink-2); }
