: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;
  --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: 16px;
  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;}
header.app .title small { font-weight: 400; font-size: 12px; opacity: .75; }
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;
}
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: 820px; 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; }
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(.985); }
.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: 12px 16px; 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: 8px 12px; font-size: 14px; }
.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=email], textarea, select {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; font-family: inherit; background: #fff; color: var(--text);
}
textarea { min-height: 84px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--navy-2); outline-offset: 0; border-color: var(--navy-2); }

/* choice chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: #fff; border-radius: 999px;
  padding: 8px 14px; 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); }
.chip.sev { color: #fff; border: none; opacity: .45; }
.chip.sev.active { opacity: 1; box-shadow: 0 0 0 3px rgba(15,40,72,.18); }
.chip.sev.vert { background: var(--vert); }
.chip.sev.jaune { background: var(--jaune); color:#3a2c00;}
.chip.sev.orange { background: var(--orange); }
.chip.sev.rouge { background: var(--rouge); }

/* severity dot / pill */
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; display:inline-block;}
.dot.vert{background:var(--vert)} .dot.jaune{background:var(--jaune)} .dot.orange{background:var(--orange)} .dot.rouge{background:var(--rouge)}
.pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; color: #fff; white-space: nowrap; }
.pill.vert{background:var(--vert)} .pill.jaune{background:var(--jaune); color:#3a2c00} .pill.orange{background:var(--orange)} .pill.rouge{background:var(--rouge)}
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: #eef1f6; color: var(--muted); }

/* ---------- Photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #ddd; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .del { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 50%; width: 24px; height: 24px; font-size: 14px; cursor: pointer; }
.photo-thumb .cm { position:absolute; left:0; right:0; bottom:0; background: rgba(0,0,0,.55); color:#fff; font-size:10px; padding:2px 4px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.add-photo { aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 10px; display: flex; flex-direction:column; align-items: center; justify-content: center; color: var(--muted); cursor: pointer; font-size: 13px; gap:4px; }
.add-photo span.ic { font-size: 26px; }

/* ---------- Plan annotation ---------- */
.plan-wrap { position: relative; width: 100%; background: #e9edf3; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); touch-action: manipulation; }
.plan-wrap img { width: 100%; display: block; }
.pin {
  position: absolute; transform: translate(-50%, -50%);
  width: 28px; height: 28px; border-radius: 50% 50% 50% 0; transform-origin: center;
  background: var(--red); border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0,0,0,.4);
  color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  rotate: -45deg; cursor: pointer;
}
.pin span { rotate: 45deg; }
.pin.vert{background:var(--vert)} .pin.jaune{background:var(--jaune); color:#3a2c00} .pin.orange{background:var(--orange)} .pin.rouge{background:var(--rouge)}

/* ---------- 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: 820px; 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; }

.kpi-row { display: flex; gap: 8px; }
.kpi { flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.kpi .n { font-size: 24px; font-weight: 800; }
.kpi .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

.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;}
