/* Import des unités produits · Batidal — même charte que la Caisse Batidal (docs/DESIGN_BATIDAL.md du projet caisse) :
   rouge BigMat + bleu nuit sur blanc, orange en accent, Inter, pas d'ombres, bordures --line, chiffres tabulaires. */
:root {
  /* Marque (tokens caisse : --bm-*) */
  --brand: #d60812;
  --brand-dark: #b00610;
  --navy: #002154;
  --navy-dark: #001635;
  --accent: #f18e2f;
  /* Neutres */
  --ink: #0b1220;
  --muted: #5b6b84;
  --line: #dde3ec;
  --surface: #f4f6fa;
  --surface-2: #e8edf5;
  /* États */
  --ok: #127a4b;
  --ok-soft: #e6f4ec;
  --warn: #b45309;
  --warn-soft: #fff4e5;
  --bad: #b00020;
  --bad-soft: #fdeaee;
  --brand-soft: #fdeaee;
  --navy-soft: #e8edf5;
  /* Rayons */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --radius: var(--r-md);
  /* Hauteur des contrôles : échelle PC (souris) par défaut, tactile plus bas */
  --touch: 36px;
  --touch-lg: 44px;
  /* Typo : échelle PC 13 / 14 / 15 / 18 / 22 / 28 (tactile : 14 / 16 / 18 / 22 / 28 / 40) */
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --t-sm: 13px; --t-ui: 14px; --t-lg: 15px; --t-xl: 18px; --t-2xl: 22px; --t-3xl: 28px;
}
/* Tablette / écran tactile : cibles ≥ 48 px et texte plus grand, comme la caisse */
@media (pointer: coarse) {
  :root {
    --touch: 48px; --touch-lg: 64px;
    --t-sm: 14px; --t-ui: 16px; --t-lg: 18px; --t-xl: 22px; --t-2xl: 28px; --t-3xl: 40px;
  }
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html { color-scheme: light; }
body {
  margin: 0; font-family: var(--font); font-size: var(--t-ui); color: var(--ink); background: #fff;
  line-height: 1.45; -webkit-font-smoothing: antialiased;
}
a { color: var(--navy); font-weight: 600; }
code { font-size: .92em; background: var(--surface); padding: 0 .3em; border-radius: var(--r-sm); }
.num, td, th { font-variant-numeric: tabular-nums; }
.wrap { max-width: 1440px; margin: 0 auto; padding: 0 20px; }
.main { padding: 20px 20px 40px; min-height: calc(100vh - 120px); }
.small { font-size: var(--t-sm); }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.num { text-align: right; }
.txt-bad { color: var(--bad); font-weight: 700; }
.txt-warn { color: var(--warn); font-weight: 700; }
.txt-ok { color: var(--ok); font-weight: 700; }
.inline { display: inline; margin-left: 8px; }

/* ---- barre bleu nuit (comme la caisse) */
.topbar { background: var(--navy); color: #fff; }
.topbar__inner { display: flex; align-items: center; gap: 12px; min-height: calc(var(--touch) + 16px); }
.brand { display: inline-flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; }
.brand__mark { display: inline-block; width: 16px; height: 16px; border-radius: var(--r-sm); background: var(--brand); }
.brand__logo { height: 32px; width: auto; display: none; }
.brand--logo .brand__logo { display: block; } .brand--logo .brand__mark { display: none; }
.brand__name { font-weight: 700; font-size: var(--t-xl); letter-spacing: .5px; }
.brand__app { font-weight: 600; font-size: var(--t-ui); color: rgba(255,255,255,.8); border-left: 1px solid rgba(255,255,255,.35); padding-left: 12px; margin-left: 4px; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a {
  display: inline-flex; align-items: center; min-height: var(--touch); padding: 0 12px; border-radius: var(--r-md);
  color: rgba(255,255,255,.8); text-decoration: none; font-weight: 600; font-size: var(--t-lg);
}
.nav a:hover, .nav a:active { background: rgba(255,255,255,.1); }
.nav a.is-active { background: rgba(255,255,255,.15); color: #fff; }
.logout { display: flex; align-items: center; gap: 12px; margin: 0 0 0 auto; }
.logout__user { font-weight: 600; font-size: var(--t-ui); }
.footer { padding: 12px 16px; color: var(--muted); font-size: var(--t-sm); border-top: 1px solid var(--line); }

/* ---- typo */
.h1 { font-size: var(--t-2xl); font-weight: 700; margin: 0 0 4px; color: var(--navy); letter-spacing: -.2px; }
.h2 { font-size: var(--t-xl); font-weight: 700; margin: 0 0 6px; color: var(--navy); }
.h3 { font-size: var(--t-ui); font-weight: 700; margin: 0 0 6px; color: var(--navy); }
.page-head { margin-bottom: 20px; }
.page-head p { margin: 0; }
.page-head--row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* ---- cartes : bordure --line, pas d'ombre */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px; margin-bottom: 16px; }
.card--flat { background: var(--surface); }
.card--narrow { max-width: 560px; margin: 40px auto; }
.card--success { border-color: var(--ok); }
.card--table { padding: 0; overflow: hidden; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid-3 { grid-template-columns: 1fr; } }

/* ---- boutons : cibles ≥ 48 px, bordure 2 px, variantes caisse */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600;
  min-height: var(--touch); padding: 0 14px; border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer;
  text-decoration: none; line-height: 1.2; font-size: var(--t-ui); white-space: nowrap; background: #fff; color: var(--navy);
  transition: background-color .1s; user-select: none;
}
.btn:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.btn--primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn--primary:hover, .btn--primary:active { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn--navy { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn--navy:hover, .btn--navy:active { background: var(--navy-dark); }
.btn--secondary { background: #fff; color: var(--navy); border-color: var(--line); }
.btn--secondary:hover, .btn--secondary:active { background: var(--surface); }
.btn--ghost { background: transparent; color: var(--navy); border-color: transparent; }
.btn--ghost:hover, .btn--ghost:active { background: var(--surface); }
.topbar .btn--ghost { color: #fff; border-color: rgba(255,255,255,.4); }
.topbar .btn--ghost:hover { background: rgba(255,255,255,.1); }
.btn--danger { background: #fff; color: var(--bad); border-color: var(--bad); }
.btn--danger:hover, .btn--danger:active { background: var(--bad); color: #fff; }
.btn--warn { color: var(--warn); border-color: var(--warn); }
.btn--sm { min-height: calc(var(--touch) - 6px); padding: 0 10px; font-size: var(--t-sm); }
.btn--lg { min-height: var(--touch-lg); padding: 0 20px; font-size: var(--t-lg); }
.btn--block { width: 100%; }

/* ---- formulaires */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 4px; font-weight: 600; font-size: var(--t-sm); }
.field--inline { grid-template-columns: auto auto; align-items: center; gap: 10px; }
.field input, .input, input[type=search] {
  font: inherit; min-height: var(--touch); padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: #fff; min-width: 0; color: var(--ink);
}
.field input:focus, .input:focus { outline: none; border-color: var(--navy); }
.input--sm { width: 170px; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 16px; }

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--r-md); background: var(--surface); padding: 32px 20px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-drag { border-color: var(--navy); background: var(--navy-soft); }
.dropzone.is-filled { border-style: solid; border-color: var(--ok); background: var(--ok-soft); }
.dropzone__input { display: none; }
.dropzone__icon { font-size: var(--t-3xl); color: var(--brand); font-weight: 700; line-height: 1; margin-bottom: 8px; }
.dropzone__title { font-weight: 700; font-size: var(--t-xl); color: var(--navy); }

/* ---- alertes, badges, pastilles */
.alert { padding: 10px 14px; border: 1px solid; border-radius: var(--r-sm); margin: 0 0 16px; font-weight: 600; }
.alert--error { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.alert--warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.alert--ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.alert p { margin: 6px 0 0; font-weight: 400; color: var(--ink); }
.badge { display: inline-block; padding: 4px 10px; font-size: var(--t-sm); font-weight: 700; text-transform: uppercase; letter-spacing: .3px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--navy); white-space: nowrap; }
.badge--simule { background: var(--navy); color: #fff; }
.badge--simulation, .badge--application { background: var(--accent); color: var(--ink); }
.badge--applique { background: var(--ok); color: #fff; }
.badge--erreur_simulation, .badge--erreur_application { background: var(--bad); color: #fff; }
.pill { display: inline-block; padding: 2px 10px; border-radius: var(--r-sm); font-size: var(--t-sm); font-weight: 700; }
.pill--erreur, .pill--statut-attention { background: var(--warn-soft); color: var(--warn); }
.pill--doublon { background: var(--accent); color: var(--ink); }
.pill--statut-ok { background: var(--ok-soft); color: var(--ok); }
.pill--statut-inconnu { background: var(--surface-2); color: var(--muted); }
.pill--incomplet { background: var(--bad-soft); color: var(--bad); }

/* ---- compteurs */
.kpis { display: flex; gap: 12px; flex-wrap: wrap; margin: 0 0 20px; }
.kpi { flex: 1 1 140px; background: var(--surface); border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--r-sm); padding: 8px 12px; }
.kpi__n { font-size: var(--t-2xl); font-weight: 700; line-height: 1.1; color: var(--navy); }
.kpi__l { font-size: var(--t-sm); color: var(--muted); font-weight: 600; }
.kpi--ok { border-color: var(--ok); } .kpi--ok .kpi__n { color: var(--ok); }
.kpi--bad { border-color: var(--bad); } .kpi--bad .kpi__n { color: var(--bad); }
.kpi--warn { border-color: var(--warn); } .kpi--warn .kpi__n { color: var(--warn); }

/* ---- barre d'actions */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.toolbar__files { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar__apply { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-left: auto; }

/* ---- onglets et tableaux */
.tabs { display: flex; gap: 4px; padding: 6px 6px 0; background: var(--surface); border-bottom: 1px solid var(--line); }
.tab { font: inherit; font-weight: 600; font-size: var(--t-ui); min-height: var(--touch); padding: 0 14px; background: transparent; border: 1px solid transparent; border-bottom: 0; border-radius: var(--r-md) var(--r-md) 0 0; cursor: pointer; color: var(--muted); }
.tab.is-active { color: var(--navy); background: #fff; border-color: var(--line); margin-bottom: -1px; }
.tab__n { background: var(--surface-2); border-radius: var(--r-sm); padding: 1px 8px; margin-left: 6px; font-size: var(--t-sm); }
.table-tools { display: flex; align-items: center; gap: 12px; padding: 10px 12px; }
.table-tools .input { flex: 1; max-width: 460px; }
.table-count { margin: 0; padding: 0 12px 8px; font-size: var(--t-sm); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--t-ui); }
.table th, .table td { padding: 5px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { background: var(--surface); font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; position: sticky; top: 0; }
.table tbody tr:nth-child(even) { background: var(--surface); }
.table--dense td { padding: 4px 8px; }
.table tbody tr.row--dup, .table tbody tr.row--attention { background: var(--warn-soft); }
.pager { display: flex; justify-content: center; align-items: center; gap: 16px; padding: 12px; font-weight: 600; }
.empty { padding: 24px; text-align: center; }

/* ---- progression */
.steps { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0 0 18px; flex-wrap: wrap; }
.steps li { flex: 1 1 160px; display: flex; align-items: center; gap: 10px; min-height: var(--touch); padding: 6px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); font-weight: 600; color: var(--muted); }
.steps__n { display: inline-flex; width: 24px; height: 24px; align-items: center; justify-content: center; border-radius: 50%; background: var(--surface-2); font-size: var(--t-sm); font-weight: 700; }
.steps li.is-current { color: var(--ink); border-color: var(--accent); background: var(--warn-soft); }
.steps li.is-current .steps__n { background: var(--accent); color: var(--ink); }
.steps li.is-done { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.steps li.is-done .steps__n { background: var(--ok); color: #fff; }
.progress { height: 14px; background: var(--surface-2); border-radius: var(--r-sm); overflow: hidden; }
.progress__bar { height: 100%; background: var(--brand); transition: width .3s; }
.progress__bar.is-indeterminate { width: 30% !important; animation: slide 1.2s infinite linear; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(350%); } }
.progress__meta { display: flex; justify-content: space-between; margin-top: 8px; font-weight: 600; font-size: var(--t-ui); }

/* ---- fenêtre de confirmation */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0,33,84,.6); }
.modal__box { position: relative; background: #fff; width: min(540px, 92vw); padding: 20px; border: 1px solid var(--bad); border-top-width: 4px; border-radius: var(--r-md); }
.modal__warn { background: var(--bad-soft); border: 1px solid var(--bad); border-radius: var(--r-sm); padding: 10px 14px; font-size: var(--t-ui); }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* ---- connexion */
.login { display: flex; justify-content: center; padding-top: 6vh; }
.login__card { width: min(420px, 100%); }

/* ---- référentiel des unités */
.unit-add__row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.unit-add__row .field { flex: 0 1 auto; }
.unit-add__row .field:nth-child(2) { flex: 1 1 260px; }
.unit-edit { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.unit-edit .input { flex: 1 1 220px; }
.unit-edit .input--sm { flex: 0 0 200px; }
.unit-actions { text-align: right; }
.row--saved td { animation: flash 1.5s ease-out; }
@keyframes flash { from { background: var(--ok-soft); } to { background: transparent; } }

/* ---- tablette (1280×800 paysage et moins) */
@media (max-width: 800px) {
  .topbar__inner { flex-wrap: wrap; padding: 8px 0; gap: 8px; }
  .brand__app { display: none; }
  .nav { margin-left: 0; width: 100%; order: 3; }
  .kpi { flex-basis: 45%; }
}

/* ---- page Aide (guide utilisateur rendu depuis Markdown) */
.prose { max-width: 960px; margin: 0 auto; padding: 24px 32px; line-height: 1.55; }
.prose h1 { font-size: var(--t-2xl); color: var(--navy); margin: 0 0 12px; }
.prose h2 { font-size: var(--t-xl); color: var(--navy); margin: 32px 0 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.prose h3 { font-size: var(--t-lg); color: var(--navy); margin: 20px 0 8px; }
.prose img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: var(--r-sm); margin: 12px 0 20px; }
.prose table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: var(--t-sm); }
.prose th, .prose td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface); }
.prose blockquote { margin: 12px 0; padding: 8px 14px; border-left: 4px solid var(--accent); background: var(--warn-soft); color: var(--ink); }
.prose blockquote p { margin: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.prose li { margin: 3px 0; }
.prose code { font-size: .9em; }
