:root {
  --bg: #f4f5f7; --card: #fff; --txt: #1f2328; --mute: #6b7280; --line: #e3e5e8;
  --accent: #e8730c; --accent-d: #c25e06; --ok: #16803c; --warn: #b45309; --err: #c62828;
  --blue: #2457a6; --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--txt); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.3rem; margin: 0 0 .6rem; }
h2 { font-size: 1.05rem; margin: 1.2rem 0 .5rem; }
.mute { color: var(--mute); }
.small { font-size: .85em; }
.err { color: var(--err); }
.warn { color: var(--warn); }
.ok { color: var(--ok); }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.right { margin-left: auto; }

/* En-tête */
header { position: sticky; top: 0; z-index: 10; background: #1f2937; color: #fff; display: flex; align-items: center; gap: .3rem; padding: .4rem .6rem; }
header .logo { font-weight: 700; margin-right: .6rem; color: #fff; }
header nav { display: flex; gap: .2rem; flex: 1; overflow-x: auto; }
header nav a { color: #d1d5db; padding: .35rem .6rem; border-radius: 6px; white-space: nowrap; }
header nav a.on, header nav a:hover { background: #374151; color: #fff; text-decoration: none; }
main { max-width: 1200px; margin: 0 auto; padding: .8rem; }

/* Contrôles */
input, select, textarea { font: inherit; padding: .4rem .5rem; border: 1px solid #cdd1d6; border-radius: 6px; background: #fff; min-width: 0; }
textarea { width: 100%; min-height: 4em; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f6b77d; border-color: var(--accent); }
button, .btn { font: inherit; padding: .4rem .75rem; border-radius: 6px; border: 1px solid #cdd1d6; background: #fff; cursor: pointer; color: var(--txt); display: inline-flex; align-items: center; gap: .3rem; }
button:hover, .btn:hover { background: #f0f1f3; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover, .btn.primary:hover { background: var(--accent-d); }
button.danger { color: var(--err); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: #eceef1; }
button:disabled { opacity: .5; cursor: default; }
button.mini { padding: .15rem .45rem; font-size: .85em; }
header button.primary { padding: .35rem .7rem; }
label.chk { display: inline-flex; gap: .3rem; align-items: center; cursor: pointer; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; margin-bottom: .8rem; }
.badge { display: inline-block; font-size: .78em; padding: .05rem .45rem; border-radius: 99px; background: #eef0f3; color: #374151; }
.badge.bas { background: #fde8d4; color: var(--warn); font-weight: 600; }
.badge.mcp { background: #e5edff; color: var(--blue); }
.tag { display: inline-block; font-size: .78em; padding: 0 .4rem; border-radius: 4px; background: #f1f5f9; color: #475569; margin-right: .2rem; }

/* Recherche */
.search { display: flex; gap: .4rem; margin-bottom: .5rem; }
.search input[type=search] { flex: 1; font-size: 1.05rem; padding: .55rem .7rem; }
.filtres { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .6rem; }
.filtres select { max-width: 15rem; }
.pfiltre { display: inline-flex; align-items: center; gap: .25rem; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: .15rem .35rem; }
.pfiltre input { width: 5.5rem; padding: .25rem .35rem; }

table.liste { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.liste th { text-align: left; font-weight: 600; font-size: .85em; color: var(--mute); background: #fafbfc; padding: .45rem .5rem; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; }
table.liste td { padding: .4rem .5rem; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
table.liste tr.clic { cursor: pointer; }
table.liste tr.clic:hover td { background: #fff7ef; }
table.liste tr.archive td { opacity: .55; }
.thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: #eef0f3; display: block; }
.thumb.vide { display: flex; align-items: center; justify-content: center; color: #b5bac1; font-size: 1.2rem; }
.qte { font-weight: 600; white-space: nowrap; }

/* Fiche article */
.fiche-head { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.fiche-head .photo { width: 120px; height: 120px; border-radius: 8px; object-fit: cover; }
.params { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .9rem; }
.params .k { color: var(--mute); }
.params .principal { font-weight: 600; }
.stocks .ligne { display: flex; align-items: center; gap: .4rem; padding: .45rem 0; border-bottom: 1px solid #f0f1f3; flex-wrap: wrap; }
.stocks .ligne:last-child { border-bottom: 0; }
.stocks .q { font-size: 1.15rem; font-weight: 700; min-width: 4.5rem; text-align: center; }
.gal { display: flex; flex-wrap: wrap; gap: .5rem; }
.gal .doc { width: 130px; font-size: .8em; position: relative; }
.gal .doc img { width: 130px; height: 100px; object-fit: cover; border-radius: 6px; display: block; background: #eef0f3; }
.gal .doc .pdf { width: 130px; height: 100px; border-radius: 6px; background: #fdecec; color: var(--err); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.3rem; }
.gal .doc .x { position: absolute; top: 2px; right: 2px; }
.drop { border: 2px dashed #cdd1d6; border-radius: var(--radius); padding: 1rem; text-align: center; color: var(--mute); cursor: pointer; }
.drop.on { border-color: var(--accent); background: #fff7ef; color: var(--accent-d); }
table.hist { width: 100%; border-collapse: collapse; font-size: .88em; }
table.hist td { padding: .25rem .4rem; border-bottom: 1px solid #f0f1f3; }

/* Formulaire */
.form { display: grid; grid-template-columns: 11rem 1fr; gap: .5rem .8rem; align-items: center; }
.form > label { color: var(--mute); text-align: right; }
.form input, .form select { width: 100%; }
.form .row { flex-wrap: nowrap; }
.form .row > select, .form .row > input { width: auto; }
.form .aide { grid-column: 2; font-size: .82em; margin-top: -.3rem; }
.pval { display: flex; gap: .5rem; align-items: center; }
.pval input, .pval select { flex: 1; }
.pval .norm { font-size: .85em; color: var(--ok); white-space: nowrap; min-width: 5rem; }
.alerte { border-left: 4px solid var(--accent); background: #fff7ef; padding: .6rem .8rem; border-radius: 6px; margin: .6rem 0; }
.alerte.err { border-color: var(--err); background: #fdecec; color: var(--txt); }

/* Arbres */
.arbre ul { list-style: none; margin: 0; padding-left: 1.1rem; }
.arbre > ul { padding-left: 0; }
.arbre .noeud { display: flex; align-items: center; gap: .35rem; padding: .25rem .3rem; border-radius: 6px; }
.arbre .noeud:hover { background: #f3f4f6; }
.arbre .noeud.sel { background: #fff1e3; }
.arbre .noeud.cible { outline: 2px dashed var(--accent); }
.arbre .tog { width: 1.2rem; text-align: center; color: var(--mute); cursor: pointer; }
.arbre .nom { cursor: pointer; }
.arbre .code { font-family: ui-monospace, monospace; font-size: .8em; background: #eef0f3; padding: 0 .3rem; border-radius: 4px; }
.arbre .act { margin-left: auto; display: none; gap: .15rem; }
.arbre .noeud:hover .act, .arbre .noeud.sel .act { display: flex; }
.deux { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: .8rem; align-items: start; }

/* Choix d'article */
.picker { position: relative; }
.picker .res { position: absolute; z-index: 5; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.08); max-height: 240px; overflow: auto; }
.picker .res div { padding: .35rem .5rem; cursor: pointer; }
.picker .res div:hover { background: #fff7ef; }

/* Modale */
.voile { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modale { background: #fff; border-radius: 10px; padding: 1rem; width: 100%; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modale h3 { margin: 0 0 .7rem; font-size: 1.05rem; }
.modale .champ { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .6rem; }
.modale .champ input, .modale .champ select { width: 100%; }
.modale .boutons { display: flex; justify-content: flex-end; gap: .4rem; margin-top: .8rem; }

/* Notifications */
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: .4rem; align-items: center; }
.toast { background: #1f2937; color: #fff; padding: .5rem .9rem; border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 90vw; }
.toast.err { background: var(--err); }

/* Mobile */
.cartes { display: none; }
@media (max-width: 720px) {
  main { padding: .5rem; }
  table.liste.desktop { display: none; }
  .cartes { display: block; }
  .carte { display: flex; gap: .6rem; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem; margin-bottom: .4rem; cursor: pointer; }
  .carte .infos { flex: 1; min-width: 0; }
  .carte .nom { font-weight: 600; }
  .carte .qte { font-size: 1.1rem; }
  .form { grid-template-columns: 1fr; gap: .2rem; }
  .form > label { text-align: left; margin-top: .4rem; }
  .form .aide { grid-column: 1; }
  .deux { grid-template-columns: 1fr; }
  .arbre .act { display: flex; }
  header .logo { display: none; }
  .stocks .ligne button { padding: .45rem .7rem; }
}
@media (max-width: 720px) {
  header nav { justify-content: space-around; }
  header nav a { font-size: 1.3rem; padding: .25rem .8rem; }
  header nav .lib { display: none; }
}
