:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --ink: #132033;
  --muted: #667a94;
  --line: #d7e1ef;
  --blue-900: #142f5e;
  --blue-700: #235eba;
  --blue-600: #2f74e7;
  --blue-200: #dbe9ff;
  --danger: #dc3545;
  --warning: #e19410;
  --success: #188457;
  --radius: 12px;
  --shadow: 0 4px 18px rgba(19, 32, 51, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* garantit que l'attribut hidden l'emporte sur tout display */
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
.muted { color: var(--muted); }

.ndf-shell { max-width: 1080px; margin: 0 auto; padding: 22px; }

/* Header */
.ndf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.ndf-header h1 { margin: 0; font-size: 26px; color: var(--blue-900); }
.ndf-header p { margin: 4px 0 0; font-size: 14px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 18px; color: var(--blue-900); }
.card .step { font-size: 13px; font-weight: 700; color: var(--blue-600); text-transform: uppercase; letter-spacing: .04em; }

/* Buttons */
button, .button-like {
  font: inherit;
  border-radius: 8px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  cursor: pointer;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:hover, .button-like:hover { filter: brightness(0.98); }
.btn-primary { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }
.btn-primary:hover { background: var(--blue-700); border-color: var(--blue-700); filter: none; }

/* Capture / source */
.capture-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.capture-head h2 { margin: 0; }
.capture-close {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  width: 34px; height: 34px; border-radius: 8px; font-size: 16px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; padding: 0; flex: 0 0 auto;
}
.capture-close:hover { background: #f2f5fa; color: var(--ink); }
.source-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.source {
  border: 2px dashed #b7cbe6;
  border-radius: var(--radius);
  padding: 26px 16px;
  text-align: center;
  cursor: pointer;
  background: #f7faff;
  color: var(--blue-700);
  font-weight: 600;
  transition: border-color .15s, background .15s;
}
.source:hover { border-color: var(--blue-600); background: #eef5ff; }
.source input { display: none; }
.source .icon { display: block; font-size: 28px; margin-bottom: 6px; }
button.source { width: 100%; font: inherit; }

/* Caméra plein écran */
.camera-modal {
  position: fixed; inset: 0; z-index: 60;
  background: #000; display: flex; flex-direction: column;
}
.camera-modal[hidden] { display: none; }
.camera-modal video { flex: 1; width: 100%; height: 100%; object-fit: contain; background: #000; }
.camera-controls {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 16px calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  background: #0d1420;
}
.camera-controls button { background: #1c2637; color: #fff; border-color: #2c3a52; }
.camera-controls .btn-primary { background: var(--blue-600); border-color: var(--blue-600); font-weight: 700; }

#preview[hidden] { display: none; }
#preview {
  display: block;
  max-width: 100%;
  max-height: 460px;
  margin: 18px auto;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.processing { text-align: center; padding: 22px; color: var(--muted); }
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 3px solid #c8d8ed; border-top-color: var(--blue-600);
  border-radius: 50%; animation: spin 1s linear infinite; margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Review form */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 6px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
input, select {
  width: 100%; font: inherit; color: var(--ink);
  border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px; background: #fff;
}
input:focus, select:focus { outline: none; border-color: var(--blue-600); box-shadow: 0 0 0 3px var(--blue-200); }
.wide { grid-column: 1 / -1; }
.notice {
  background: #fff8e6; border-left: 4px solid var(--warning);
  padding: 10px 12px; border-radius: 6px; color: #7a5600; font-size: 13px; margin: 12px 0 0;
}
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* List head */
.list-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 6px;
}
.list-tools { display: flex; align-items: center; gap: 12px; }
.ndf-summary { font-size: 13px; color: var(--muted); font-weight: 600; }
#filter { padding: 8px 10px; }

.admin-hint {
  font-size: 13px; color: var(--blue-700); background: var(--blue-200);
  border-radius: 8px; padding: 8px 12px; margin: 0 0 14px;
}

/* Expense list */
.ndf-list { display: grid; gap: 12px; }

/* Regroupement par mois (repliable) */
.ndf-month { border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
.ndf-month-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; cursor: pointer; user-select: none; list-style: none; background: #f7faff;
}
.ndf-month-head::-webkit-details-marker { display: none; }
.ndf-month-title { font-weight: 700; color: var(--blue-900); }
.ndf-month-title::before {
  content: '▸'; color: var(--blue-600); margin-right: 8px; display: inline-block; transition: transform .15s;
}
.ndf-month[open] .ndf-month-title::before { transform: rotate(90deg); }
.ndf-month[open] .ndf-month-head { border-bottom: 1px solid var(--line); }
.ndf-month-meta { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.ndf-month-list { display: grid; gap: 12px; padding: 14px 16px; }
.ndf-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.ndf-card:hover { border-color: #c2d3ea; box-shadow: 0 3px 12px rgba(19, 32, 51, .05); }
.ndf-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.ndf-merchant { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ndf-merchant strong { font-size: 16px; }
.ndf-amount-box { display: flex; flex-direction: column; align-items: flex-end; }
.ndf-amount { font-weight: 800; font-size: 18px; color: var(--blue-900); white-space: nowrap; }
.ndf-vat { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; margin-top: 2px; }
.ndf-meta {
  display: flex; gap: 14px; flex-wrap: wrap;
  color: var(--muted); font-size: 13px; margin-top: 8px;
}
.ndf-person { font-weight: 700; color: var(--blue-700); }
.ndf-cat {
  background: #eef2f8; color: #45566e; border-radius: 6px;
  padding: 1px 8px; font-weight: 600;
}
.ndf-desc { margin: 10px 0 0; color: #3d4a5c; font-size: 14px; }
.ndf-card-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-top: 12px;
}
.ndf-receipt { color: var(--blue-600); text-decoration: none; font-weight: 600; font-size: 14px; }
.ndf-receipt:hover { text-decoration: underline; }
.ndf-foot-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ndf-updated { font-size: 12px; }
.ndf-delete {
  background: #fff; color: var(--danger); border: 1px solid #f0c2c7;
  border-radius: 8px; padding: 6px 12px; font-size: 12px; font-weight: 700; letter-spacing: .03em;
}
.ndf-delete:hover { background: var(--danger); border-color: var(--danger); color: #fff; filter: none; }

/* Status badges */
.ndf-badge {
  display: inline-block; border-radius: 999px;
  padding: 3px 11px; font-size: 12px; font-weight: 700; white-space: nowrap;
}
.ndf-badge.pending { color: #8f6100; background: #fff4da; }
.ndf-badge.validated { color: #11613a; background: #dff7ea; }
.ndf-badge.paid { color: #1c56a7; background: #e6f0ff; }
.ndf-badge.editable {
  cursor: pointer; user-select: none;
  border: 1px solid transparent; position: relative;
}
.ndf-badge.editable:hover { filter: brightness(0.96); box-shadow: 0 0 0 2px rgba(47, 116, 231, .18); }
.ndf-badge.editable:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--blue-200); }
.ndf-badge.editable::after { content: " ⇅"; font-size: 10px; opacity: .55; }

.ndf-empty { text-align: center; padding: 30px; color: var(--muted); }

/* Toast */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--blue-900); color: #fff; border-radius: 9px;
  padding: 11px 18px; display: none; z-index: 40; font-size: 14px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(19, 32, 51, .25);
}

@media (max-width: 650px) {
  .ndf-shell { padding: 14px; }
  .ndf-header { flex-direction: column; align-items: stretch; }
  .ndf-header .btn-primary { justify-content: center; }
  .source-grid, .form-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .ndf-card-top { flex-direction: column; }
  .card { padding: 15px; }
}
