/* CAISSECLAIR – bleu royal, blanc, vert */
:root {
  --blue: #1E3FA8;
  --blue-600: #2348C4;
  --blue-700: #18338A;
  --blue-50: #EEF2FD;
  --blue-100: #DCE4FB;
  --green: #15803D;
  --green-500: #22A04B;
  --green-50: #EAF7EE;
  --orange: #C2410C;
  --orange-50: #FFF1E8;
  --red: #B91C1C;
  --red-50: #FDECEC;
  --amber-50: #FFF8E6;
  --amber: #92600A;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6B7280;
  --line: #E3E7EF;
  --bg: #F4F6FB;
  --card: #FFFFFF;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --chart-rec: #2F55D4;
  --chart-dep: #E8590C;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased;
}
a { color: var(--blue-600); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .98rem; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--blue); font-weight: 800; letter-spacing: .1em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--green); }
.neg { color: var(--orange); }
.hidden { display: none !important; }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Authentification ---------- */
.auth {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr;
}
.auth-hero {
  background: linear-gradient(150deg, var(--blue-700), var(--blue-600) 60%, #2a6be0);
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-hero .brand-big { font-size: 2.4rem; font-weight: 900; letter-spacing: .06em; }
.auth-hero .slogan { font-size: 1.15rem; opacity: .92; max-width: 30ch; margin-top: 10px; }
.auth-hero ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.auth-hero li { display: flex; gap: 10px; align-items: center; opacity: .95; }
.auth-hero li .dot { width: 26px; height: 26px; border-radius: 50%; background: rgba(34, 197, 94, .25); display: grid; place-items: center; }
.auth-panel { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card form { display: grid; gap: 14px; margin-top: 22px; }
.auth-switch { margin-top: 18px; text-align: center; }
.logo-mark { display: inline-flex; align-items: center; gap: 10px; }
.logo-mark img { width: 40px; height: 40px; }

/* ---------- Coquille ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--blue-700); color: #dfe6fb; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sb-brand { padding: 20px 18px 14px; border-bottom: 1px solid rgba(255, 255, 255, .1); }
.sb-brand .name { font-weight: 900; letter-spacing: .08em; color: #fff; font-size: 1.15rem; display: flex; align-items: center; gap: 10px; }
.sb-brand .name img { width: 32px; height: 32px; }
.sb-church { display: flex; gap: 10px; align-items: center; margin-top: 14px; padding: 10px; background: rgba(255, 255, 255, .07); border-radius: 10px; }
.sb-church img { width: 36px; height: 36px; border-radius: 8px; object-fit: contain; background: #fff; }
.sb-church .cn { font-weight: 600; color: #fff; font-size: .9rem; line-height: 1.25; }
.nav { padding: 10px; display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px;
  color: #cdd6f6; text-decoration: none; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav a.active { background: #fff; color: var(--blue); }
.nav .sep { height: 1px; background: rgba(255, 255, 255, .1); margin: 8px 6px; }
.sb-user { margin-top: auto; padding: 14px; border-top: 1px solid rgba(255, 255, 255, .1); font-size: .88rem; }
.sb-user .u { color: #fff; font-weight: 600; }
.sb-user .actions { display: flex; gap: 6px; margin-top: 10px; }
.sb-user button { flex: 1; background: rgba(255, 255, 255, .1); color: #fff; border: 0; border-radius: 8px; padding: 7px; cursor: pointer; font: inherit; font-size: .82rem; }
.sb-user button:hover { background: rgba(255, 255, 255, .18); }
.sb-slogan { padding: 0 16px 16px; font-size: .75rem; font-style: italic; color: #a9b7ea; }

.main { min-width: 0; }
.topbar { display: none; }
.content { padding: 28px 32px 60px; max-width: 1280px; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }
.bottom-nav { display: none; }

/* ---------- Cartes & grilles ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.stack { display: grid; gap: 18px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi .lbl { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; display: flex; align-items: center; gap: 8px; }
.kpi .val { font-size: 1.45rem; font-weight: 800; margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.kpi .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.kpi.hero { background: linear-gradient(135deg, var(--blue), var(--blue-600)); color: #fff; border: 0; }
.kpi.hero .lbl, .kpi.hero .sub { color: #dbe3ff; }
.ic-blue { background: var(--blue-50); color: var(--blue); }
.ic-green { background: var(--green-50); color: var(--green); }
.ic-orange { background: var(--orange-50); color: var(--orange); }
.ic-white { background: rgba(255, 255, 255, .18); color: #fff; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent;
  border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--blue); color: #fff; transition: background .15s, box-shadow .15s; min-height: 42px; white-space: nowrap;
}
.btn:hover { background: var(--blue-700); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .nav a:focus-visible { outline: 3px solid #93AEF5; outline-offset: 1px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.green { background: var(--green); }
.btn.green:hover { background: #116432; }
.btn.wa { background: #1DA851; }
.btn.wa:hover { background: #168a42; }
.btn.ghost { background: #fff; color: var(--ink-2); border-color: var(--line); }
.btn.ghost:hover { background: var(--blue-50); color: var(--blue); }
.btn.danger { background: #fff; color: var(--red); border-color: #F3C4C4; }
.btn.danger:hover { background: var(--red-50); }
.btn.danger.solid { background: var(--red); color: #fff; }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: .86rem; border-radius: 8px; }
.btn.xl { padding: 16px 22px; font-size: 1.05rem; min-height: 56px; width: 100%; letter-spacing: .02em; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--blue-50); color: var(--blue); }

/* ---------- Formulaires ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span, .field > label { font-weight: 600; font-size: .88rem; color: var(--ink-2); }
.field .req { color: var(--red); }
.field .hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid #CDD3DF; border-radius: 10px;
  padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue-600); outline: none; box-shadow: 0 0 0 3px var(--blue-100); }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--blue); }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; font-weight: 500; }
.amount { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.amount-wrap { position: relative; }
.amount-wrap .cur { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .8rem; font-weight: 600; pointer-events: none; }
.amount-wrap input { padding-left: 54px; }

.cat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cat-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #FBFCFE; }
.cat-item label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .9rem; margin-bottom: 8px; }
.cat-item.filled { border-color: #9FD9B3; background: var(--green-50); }

.total-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 18px; padding: 16px 18px; border-radius: 12px; background: var(--blue-50); border: 1px solid var(--blue-100);
}
.total-bar .t { font-size: 1.6rem; font-weight: 900; color: var(--blue); font-variant-numeric: tabular-nums; }

.seg { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; font: inherit; font-weight: 600; font-size: .88rem; color: var(--muted); padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--blue); color: #fff; }
.date-nav { display: inline-flex; align-items: center; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.date-nav .lbl { font-weight: 700; padding: 0 10px; min-width: 150px; text-align: center; font-size: .92rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.filters { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; align-items: end; }
.filters .wide { grid-column: span 2; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 10px; border-bottom: 1px solid #EEF1F6; vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #F8FAFF; }
tr.deleted td { color: var(--muted); text-decoration: line-through; }
tfoot td { font-weight: 800; border-top: 2px solid var(--line); border-bottom: 0; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .76rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.b-rec { background: var(--green-50); color: var(--green); }
.b-dep { background: var(--orange-50); color: var(--orange); }
.b-blue { background: var(--blue-50); color: var(--blue); }
.b-gray { background: #F1F3F7; color: var(--muted); }
.b-red { background: var(--red-50); color: var(--red); }

.list { display: grid; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid #EEF1F6; }
.list-item:last-child { border-bottom: 0; }
.list-item .t { font-weight: 600; }
.progress { height: 8px; border-radius: 99px; background: #E9EDF5; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--green-500); border-radius: 99px; }

/* ---------- Alertes ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; margin-bottom: 10px; font-weight: 500; border: 1px solid; }
.alert.danger { background: var(--red-50); color: var(--red); border-color: #F5C9C9; }
.alert.warning { background: var(--amber-50); color: var(--amber); border-color: #F2DFA9; }
.alert.info { background: var(--blue-50); color: var(--blue-700); border-color: var(--blue-100); }
.alert.success { background: var(--green-50); color: var(--green); border-color: #BDE5CA; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

/* ---------- Graphique ---------- */
.chart-box { position: relative; height: 300px; }
.legend { display: flex; gap: 16px; font-size: .86rem; color: var(--ink-2); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
details.tbl summary { cursor: pointer; color: var(--blue-600); font-weight: 600; font-size: .88rem; margin-top: 10px; }

/* ---------- Rapport ---------- */
.report-result { border: 2px solid #BDE5CA; background: var(--green-50); border-radius: 14px; padding: 18px; margin-top: 18px; }
.report-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.pdf-frame { width: 100%; height: 640px; border: 1px solid var(--line); border-radius: 10px; margin-top: 16px; background: #fff; }
.mini-sum { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.mini-sum div { background: #fff; border-radius: 10px; padding: 10px; border: 1px solid var(--line); }
.mini-sum b { display: block; font-variant-numeric: tabular-nums; }

/* ---------- Fenêtres modales & notifications ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .12s; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 620px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; position: sticky; bottom: 0; background: #fff; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.timeline { display: grid; gap: 10px; }
.timeline .ev { border-left: 3px solid var(--blue-100); padding: 4px 0 4px 12px; font-size: .88rem; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); animation: up .18s; font-weight: 500; }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
.toast.warn { background: #8A5A00; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }
.logo-preview { width: 96px; height: 96px; border: 1px dashed #CDD3DF; border-radius: 12px; display: grid; place-items: center; overflow: hidden; background: #fff; }
.logo-preview img { max-width: 100%; max-height: 100%; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .report-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-hero { padding: 28px 22px; }
  .auth-hero ul { display: none; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: 270px; left: 0; transform: translateX(-100%); transition: transform .2s; }
  .shell.menu-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(15, 23, 42, .45); }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
    background: var(--blue); color: #fff; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  }
  .topbar .t { font-weight: 900; letter-spacing: .08em; flex: 1; }
  .topbar button { background: none; border: 0; color: #fff; padding: 6px; cursor: pointer; }
  .content { padding: 18px 16px 100px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .bottom-nav a { display: grid; justify-items: center; gap: 2px; padding: 8px 2px; font-size: .7rem; color: var(--muted); text-decoration: none; font-weight: 600; }
  .bottom-nav a.active { color: var(--blue); }
  .g2, .g3, .form-grid, .cat-grid { grid-template-columns: 1fr; }
  .mini-sum { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pdf-frame { display: none; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .val { font-size: 1.12rem; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .wide { grid-column: 1 / -1; }
  .report-actions { grid-template-columns: 1fr; }
  h1 { font-size: 1.25rem; }
  .date-nav .lbl { min-width: 0; }
  .hide-sm { display: none; }
}
@media print {
  .sidebar, .topbar, .bottom-nav, .btn, .seg, .date-nav, #toasts { display: none !important; }
  .shell { display: block; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}

/* ---------- Champ mot de passe avec bouton « œil » ---------- */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 48px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 40px; height: 38px;
  border: 0; background: none; border-radius: 8px; color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.pw-toggle:hover { background: var(--blue-50); color: var(--blue); }
.caps-warn { color: var(--amber); font-weight: 600; }
.login-help { margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: var(--blue-50); color: var(--blue-700); font-size: .85rem; }
.pw-pair { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; grid-column: 1 / -1; }
.pw-match { font-size: .86rem; font-weight: 700; }
.pw-match.ok { color: var(--green); }
.pw-match.ko { color: var(--red); }
.sub-banner { margin-bottom: 16px; }
.sub-banner a { color: inherit; font-weight: 700; }
