:root {
  --navy: #0f2848;
  --navy-2: #1c3a63;
  --red: #c62828;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e2e7ee;
  --text: #1a2433;
  --muted: #67748a;
  --shadow: 0 1px 3px rgba(15,40,72,.08), 0 4px 16px rgba(15,40,72,.06);
  /* CIVALIM */
  --vert: #2e7d32;
  --jaune: #f9a825;
  --orange: #ef6c00;
  --rouge: #c62828;
  --bleu: #0e89ae;
  --mauve: #b07fc2;
  /* Statuts lots */
  --dispo: #0e89ae;
  --option: #f9a825;
  --reserve: #ef6c00;
  --acte: #2e7d32;
  --desiste: #97a1b2;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(72px + var(--safe-b));
}

/* ---------- Header ---------- */
header.app {
  position: sticky; top: 0; z-index: 50;
  background: var(--navy);
  color: #fff;
  padding: env(safe-area-inset-top,0) 14px 0;
  display: flex; align-items: center; gap: 10px;
  min-height: 56px;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
header.app .title { font-weight: 700; font-size: 17px; flex: 1; display:flex; flex-direction:column; line-height:1.15; padding: 8px 0; min-width:0; }
header.app .title .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.app .title small { font-weight: 400; font-size: 12px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.app button.icon {
  background: rgba(255,255,255,.12); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 10px; font-size: 20px; cursor: pointer;
  display:flex; align-items:center; justify-content:center; flex:none;
}
header.app button.icon:active { background: rgba(255,255,255,.25); }
header.app .hdr-logo { height: 30px; width: auto; flex: none; }

/* ---------- Layout ---------- */
.container { max-width: 1000px; margin: 0 auto; padding: 14px; }
.row { display: flex; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
h2.section { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 8px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.card.clickable { cursor: pointer; transition: transform .08s ease; }
.card.clickable:active { transform: scale(.99); }
.list-item { display: flex; align-items: center; gap: 12px; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .grow .s { font-size: 13px; color: var(--muted); }
.chev { color: var(--muted); font-size: 22px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 11px 15px; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { filter: brightness(.96); }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.red { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 11px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.fab {
  position: fixed; right: 18px; bottom: calc(82px + var(--safe-b)); z-index: 40;
  width: 60px; height: 60px; border-radius: 50%; background: var(--red); color: #fff;
  border: none; font-size: 30px; box-shadow: 0 6px 20px rgba(198,40,40,.45); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=date], input[type=number], input[type=email], input[type=tel], textarea, select {
  width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--text);
}
textarea { min-height: 72px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--navy-2); outline-offset: 0; border-color: var(--navy-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 560px){ .grid3 { grid-template-columns: 1fr 1fr; } }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: #fff; border-radius: 999px;
  padding: 7px 13px; font-size: 14px; font-weight: 600; cursor: pointer; color: var(--text);
  user-select: none;
}
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* statut pills */
.pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; color: #fff; white-space: nowrap; display:inline-block; }
.pill.dispo{background:var(--dispo)} .pill.option{background:var(--option); color:#3a2c00} .pill.reserve{background:var(--reserve)} .pill.acte{background:var(--acte)} .pill.desiste{background:var(--desiste)}
.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; display:inline-block;}
.dot.dispo{background:var(--dispo)} .dot.option{background:var(--option)} .dot.reserve{background:var(--reserve)} .dot.acte{background:var(--acte)} .dot.desiste{background:var(--desiste)}
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: #eef1f6; color: var(--muted); }
.badge.montage{background:#eef1f6;color:var(--muted)} .badge.commercialisation{background:#e0f2f8;color:#0a6b8a} .badge.travaux{background:#fef0e0;color:#a04d00} .badge.livraison{background:#e6f4ea;color:#1f6b2b} .badge.solde{background:#eceaf4;color:#6b4d85}

/* ---------- KPI ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.kpi .n { font-size: 22px; font-weight: 800; line-height:1.1; }
.kpi .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-top:3px; }
.kpi .sub { font-size: 11px; color: var(--muted); margin-top:2px; }

/* progress / repartition bar */
.progress { height: 10px; border-radius: 999px; background: #eef1f6; overflow: hidden; display:flex; }
.progress > span { display:block; height:100%; }
.legend { display:flex; flex-wrap:wrap; gap:10px 16px; margin-top:10px; }
.legend .li { display:flex; align-items:center; gap:6px; font-size:12px; color:var(--muted); }

/* ---------- Table ---------- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border:1px solid var(--line); border-radius: 12px; background:#fff; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th, table.grid td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid th { background: #f7f9fc; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:active { background: #f4f6f9; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tfoot td { font-weight: 700; background:#f7f9fc; }

/* ---------- Tabs (fiche opération) ---------- */
nav.subtabs { display:flex; gap:4px; overflow-x:auto; padding: 8px 0 2px; margin-bottom: 6px; -webkit-overflow-scrolling: touch; }
nav.subtabs button { flex:none; background:#fff; border:1px solid var(--line); color:var(--muted); padding:8px 14px; border-radius:999px; font-size:13.5px; font-weight:600; cursor:pointer; white-space:nowrap; }
nav.subtabs button.active { background: var(--navy); color:#fff; border-color:var(--navy); }

/* ---------- Bottom nav ---------- */
nav.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
  background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: var(--safe-b);
}
nav.tabbar button {
  flex: 1; background: none; border: none; padding: 9px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600;
}
nav.tabbar button .ic { font-size: 21px; }
nav.tabbar button.active { color: var(--navy); }

/* ---------- Modal / sheet ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10,20,35,.45); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 8px 0 calc(20px + var(--safe-b));
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(100%);} to { transform: translateY(0);} }
.sheet .sheet-head { position: sticky; top: 0; background: var(--bg); display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); z-index: 2; }
.sheet .sheet-head .h { font-weight: 700; flex: 1; font-size: 16px; }
.sheet .sheet-body { padding: 14px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .ic { font-size: 44px; opacity: .4; }

hr.sep { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

.toast { position: fixed; bottom: calc(90px + var(--safe-b)); left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 200; font-size: 14px; box-shadow: var(--shadow); }

details.group { background:#fff; border:1px solid var(--line); border-radius:12px; margin-bottom:10px; overflow:hidden;}
details.group > summary { padding:12px 14px; font-weight:700; cursor:pointer; list-style:none; display:flex; align-items:center; gap:10px;}
details.group > summary::-webkit-details-marker{display:none;}
details.group > summary .count{ margin-left:auto; }
details.group .group-body{ padding: 0 12px 12px;}

/* Bilan complet v2 (niveau Salvia) */
table.grid.bilan { font-size:12px; }
table.grid.bilan th, table.grid.bilan td { padding:5px 8px; white-space:nowrap; }
table.grid.bilan thead th { position:sticky; top:0; background:var(--card,#fff); z-index:2; box-shadow:0 1px 0 var(--line); }
table.grid.bilan td:first-child, table.grid.bilan th:first-child { position:sticky; left:0; background:inherit; z-index:1; }
table.grid.bilan tbody tr { background:#fff; }
table.grid.bilan tbody tr.b-grp td:first-child { background:var(--bg2,#f4f6fa); }
table.grid.bilan input, table.grid.bilan select { padding:3px 6px; font-size:12px; }
