:root {
  --ink: #11141b;
  --ink-2: #4a4f5c;
  --muted: #7b7f8a;
  --bg: #fbf7f1;
  --card: #ffffff;
  --line: #ebe4d8;
  --fauve: #e39a3b;
  --fauve-dark: #b8741d;
  --fauve-soft: #fbecd6;
  --red: #d23b2a;
  --red-soft: #fbe3df;
  --amber: #f2a922;
  --amber-soft: #fdf1d6;
  --green: #2f8a57;
  --green-soft: #e1f2e7;
  --blue: #2f6db3;
  --blue-soft: #e3edf9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 20, 27, .06), 0 4px 16px rgba(17, 20, 27, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--fauve-dark); }
h1, h2 { font-weight: 800; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; margin: .2em 0 .5em; }
h2 { font-size: 1.15rem; margin: 1.2em 0 .6em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.hidden { display: none !important; }

/* En-tête */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--ink); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 900; font-size: 1.25rem; }
.brand .logo { width: 36px; height: 36px; border-radius: 10px; background: #fff; object-fit: cover; }
.top nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; }
.top nav a { color: #d8dae0; text-decoration: none; padding: 6px 10px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.top nav a.on { background: var(--fauve); color: var(--ink); }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
main.narrow { max-width: 440px; padding-top: 40px; }
.foot { text-align: center; padding: 24px; font-size: .85rem; }
.foot a { color: var(--muted); }

.login-logo { display: block; width: 100%; max-width: 320px; margin: 0 auto 8px; }

/* Cartes et formulaires */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card > h2:first-child { margin-top: 0; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .85rem; color: var(--ink-2); margin-bottom: 10px; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--ink);
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--fauve); outline-offset: -1px; border-color: transparent; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #262b36; }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; padding: 0; color: var(--fauve-dark); font: inherit; cursor: pointer; text-decoration: underline; }
.link.danger { color: var(--red); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.actions.sticky {
  position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%);
  padding: 16px 0 12px; margin-top: 8px;
}

/* Messages */
.flash { display: block; padding: 10px 14px; border-radius: 12px; margin-bottom: 12px; text-decoration: none; color: var(--ink); }
.flash-ok { background: var(--green-soft); }
.flash-err { background: var(--red-soft); }
.flash-warn { background: var(--amber-soft); }
.flash-info { background: var(--blue-soft); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: #eee; color: var(--ink-2); white-space: nowrap; vertical-align: middle; }
.b-ok { background: var(--green-soft); color: var(--green); }
.b-bad { background: var(--red-soft); color: var(--red); }
.b-warn { background: var(--amber-soft); color: #8a5b00; }
.b-todo { background: var(--blue-soft); color: var(--blue); }
.b-wait { background: #eee; color: var(--ink-2); }

/* Accueil */
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.big-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 120px; border-radius: var(--radius); text-decoration: none; font-weight: 800; font-size: 1.05rem;
  box-shadow: var(--shadow); text-align: center; padding: 12px;
}
.big-btn span { font-size: 2rem; }
.big-btn.bl { background: var(--fauve); color: var(--ink); }
.big-btn.fact { background: var(--ink); color: #fff; }
.todo .flash { font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; gap: 2px; border-top: 4px solid var(--line); }
.tile.bad { border-top-color: var(--red); }
.tile.ok { border-top-color: var(--green); }
.tile.warn { border-top-color: var(--amber); }
.t-val { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.t-lab { color: var(--muted); font-size: .85rem; }

/* Listes */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.row:last-child { border-bottom: 0; }
.card .row:hover, .list .row:hover { background: var(--fauve-soft); }
.list:not(.card .list) { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 12px; }
.r-type { flex: none; width: 44px; text-align: center; font-size: .7rem; font-weight: 900; padding: 4px 0; border-radius: 8px; }
.r-type.bl { background: var(--fauve-soft); color: var(--fauve-dark); }
.r-type.facture { background: #e8e9ec; color: var(--ink); }
.r-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.r-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-end { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filters input[type=search] { flex: 1; min-width: 160px; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs a { padding: 8px 14px; border-radius: 999px; background: #fff; text-decoration: none; color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }
.tabs a.on { background: var(--ink); color: #fff; }

/* Ajout */
.drop { position: relative; display: block !important; border: 2px dashed var(--fauve); border-radius: var(--radius); background: var(--fauve-soft); padding: 28px 16px; text-align: center; cursor: pointer; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop span { font-size: 1.1rem; font-weight: 800; color: var(--ink); }
.file-list { padding-left: 18px; color: var(--ink-2); }

.queue { list-style: none; padding: 0; margin: 0 0 16px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.queue li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.queue li:last-child { border-bottom: 0; }
.q-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.q-state { flex: none; font-weight: 700; }
.q-run .q-state { color: var(--fauve-dark); }
.q-ok .q-state { color: var(--green); }
.q-err .q-state { color: var(--red); }

/* Page document */
.doc-grid { display: grid; grid-template-columns: minmax(280px, 40%) 1fr; gap: 16px; align-items: start; }
.preview { position: sticky; top: 70px; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 90px); overflow: auto; }
.preview img { width: 100%; border-radius: 10px; box-shadow: var(--shadow); background: #fff; }
.preview iframe { width: 100%; height: 75vh; border: 0; border-radius: 10px; background: #fff; box-shadow: var(--shadow); }
.details { min-width: 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 12px; }
.lines-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.lines { border-collapse: collapse; width: 100%; font-size: .88rem; }
.lines th { text-align: left; font-size: .75rem; color: var(--muted); font-weight: 700; padding: 8px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.lines td { padding: 3px 2px; border-bottom: 1px solid var(--line); }
.lines input, .lines select { padding: 6px 6px; border-radius: 8px; width: 100%; font-size: .88rem; }
.lines select { min-width: 96px; }
.w-ref { min-width: 80px; }
.w-des { min-width: 200px; }
.w-num { min-width: 70px; text-align: right; font-variant-numeric: tabular-nums; }
.w-u { min-width: 50px; }
.del { cursor: pointer; color: var(--muted); padding: 4px 8px; display: inline-block; }
.del input { display: none; }
tr.removed td { opacity: .35; text-decoration: line-through; }
tr.removed .del { color: var(--red); opacity: 1; }
body.is-bl .f-fact { display: none; }
#add-line { margin-top: 8px; }
.chip { display: inline-block; padding: 4px 10px; background: var(--fauve-soft); border-radius: 999px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: .85rem; margin: 2px; }
.danger-zone { margin: 20px 0; font-size: .85rem; color: var(--muted); }
.rappro { margin-top: 16px; }

/* Écarts */
.ecarts { display: flex; flex-direction: column; gap: 8px; }
.ecart { display: flex; gap: 12px; justify-content: space-between; padding: 10px 12px; border-radius: 10px; border-left: 4px solid; background: #fafafa; }
.ecart.e-bad { border-color: var(--red); background: #fff7f5; }
.ecart.e-warn { border-color: var(--amber); background: #fffaf0; }
.ecart.e-info { border-color: #b9bdc6; }
.ecart.clos { opacity: .55; }
.e-main { min-width: 0; flex: 1; }
.e-type { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
.e-fact { display: block; font-size: .8rem; }
.e-det, .e-note { font-size: .8rem; color: var(--ink-2); margin-top: 2px; }
.e-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }
.e-montant { font-weight: 800; font-variant-numeric: tabular-nums; }
.e-bad .e-montant { color: var(--red); }
.e-form { display: flex; gap: 8px; align-items: center; }
.e-form select { padding: 4px 6px; font-size: .82rem; }
.split { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.amount.bad { color: var(--red); }

@media (max-width: 900px) {
  .doc-grid { grid-template-columns: 1fr; }
  .preview { position: static; max-height: none; flex-direction: row; overflow-x: auto; }
  .preview img { width: auto; max-height: 260px; }
  .preview iframe { height: 60vh; min-width: 100%; }
  .tiles { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  main { padding: 12px; }
  .top { padding: 8px 12px; }
  .top nav { margin-left: 0; width: 100%; }
  .ecart { flex-direction: column; }
  .e-side { align-items: flex-start; flex-direction: row; justify-content: space-between; }
  .hero .big-btn { min-height: 100px; font-size: .95rem; }
}
