/* =====================================================================
   Mes Comptes — feuille de style
   ===================================================================== */

/* ---------- Thème ---------- */
:root {
  --bg:        #f4f6fb;
  --bg-soft:   #eaeefa;
  --surface:   #ffffff;
  --surface-2: #f8f9fd;
  --border:    #e2e6f0;
  --text:      #171a26;
  --text-soft: #6a7189;
  --text-dim:  #9aa1b5;

  --accent:      #4f6bff;
  --accent-soft: #eaeeff;
  --accent-text: #ffffff;

  --green:  #12a05a;
  --green-soft: #e4f7ed;
  --red:    #e0344a;
  --red-soft: #fdeaec;
  --amber:  #d98216;
  --violet: #7c5cf0;

  --radius:    14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow:    0 1px 2px rgba(16,20,40,.05), 0 8px 24px -12px rgba(16,20,40,.18);
  --shadow-lg: 0 20px 60px -20px rgba(16,20,40,.35);
  --sidebar-w: 264px;   /* « Opérations régulières » tient sur une ligne */
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg:        #0d1019;
  --bg-soft:   #12161f;
  --surface:   #161b26;
  --surface-2: #1b2130;
  --border:    #262d3d;
  --text:      #e9ecf5;
  --text-soft: #9aa3ba;
  --text-dim:  #6b748c;

  --accent:      #6b83ff;
  --accent-soft: #1e2542;
  --accent-text: #ffffff;

  --green: #35c47e;  --green-soft: #14301f;
  --red:   #ff5f72;  --red-soft:   #331519;
  --amber: #f0a83c;
  --violet:#9b83ff;

  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  --shadow-lg: 0 20px 60px -20px rgba(0,0,0,.8);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg:        #0d1019;
    --bg-soft:   #12161f;
    --surface:   #161b26;
    --surface-2: #1b2130;
    --border:    #262d3d;
    --text:      #e9ecf5;
    --text-soft: #9aa3ba;
    --text-dim:  #6b748c;
    --accent:      #6b83ff;
    --accent-soft: #1e2542;
    --green: #35c47e;  --green-soft: #14301f;
    --red:   #ff5f72;  --red-soft:   #331519;
    --amber: #f0a83c;
    --violet:#9b83ff;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
    --shadow-lg: 0 20px 60px -20px rgba(0,0,0,.8);
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -.012em; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--text-soft); }
.dim   { color: var(--text-dim); }
.num   { font-variant-numeric: tabular-nums; }

/* =====================================================================
   Écrans de connexion / installation
   ===================================================================== */
.auth-body {
  display: grid; place-items: center; min-height: 100dvh; padding: 24px;
  background:
    radial-gradient(900px 500px at 15% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
    radial-gradient(700px 500px at 100% 100%, color-mix(in srgb, var(--violet) 18%, transparent), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 32px 28px; box-shadow: var(--shadow-lg);
}
.auth-card.wide { max-width: 520px; }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-card > .muted { margin-top: 0; margin-bottom: 20px; font-size: 14px; }
.auth-logo {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); font-size: 22px; font-weight: 700;
  margin-bottom: 16px;
}
.sep { border: 0; border-top: 1px solid var(--border); margin: 22px 0 18px; }

/* =====================================================================
   Formulaires
   ===================================================================== */
label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: var(--text-soft); }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=search], select, textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px; font-weight: 400; color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
  background: var(--surface);
}
textarea { min-height: 72px; resize: vertical; }
input[type=color] {
  width: 46px; height: 38px; padding: 2px; margin-top: 6px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
/* Trois champs de front : si un intitulé passe à la ligne, les saisies restent
   quand même alignées entre elles. */
.field-row.three { grid-template-columns: 1fr 1fr 1fr; align-items: end; }
.field-row.three > label { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; margin: 0; }

/* =====================================================================
   Boutons
   ===================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover  { background: var(--surface-2); border-color: var(--text-dim); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn.danger  { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.btn.ghost   { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; filter: none; transform: none; }
.btn:disabled:hover { background: var(--surface); border-color: var(--border); }
.btn.primary:disabled:hover { background: var(--accent); border-color: var(--accent); }
.btn.small   { padding: 6px 11px; font-size: 13px; }
.btn.block   { width: 100%; margin-top: 6px; padding: 11px; white-space: normal; }
.icon-btn {
  border: 0; background: transparent; color: var(--text-soft); cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; font-size: 15px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* =====================================================================
   Alertes / listes de contrôle
   ===================================================================== */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 16px; border: 1px solid transparent; }
.alert.err  { background: var(--red-soft);   color: var(--red);   border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.alert.ok   { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 30%, transparent); }
.alert.warn { background: color-mix(in srgb, var(--amber) 14%, transparent); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.alert p { margin: 6px 0 0; }
.alert code { font-family: var(--mono); font-size: 13px; }
.checklist { list-style: none; padding: 0; margin: 0 0 8px; font-size: 14px; }
.checklist li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.checklist li:last-child { border-bottom: 0; }
.checklist li span { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.checklist li.ok  span { background: var(--green-soft); color: var(--green); }
.checklist li.ko  span { background: var(--red-soft);   color: var(--red); }
.checklist li.ko  { color: var(--red); }

/* =====================================================================
   Structure de l'application
   ===================================================================== */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column;
  padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.brand-name { font-weight: 700; letter-spacing: -.02em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 550; font-size: 14.5px; transition: .13s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .ico { font-size: 15px; width: 18px; text-align: center; flex: 0 0 auto; }
.nav a span:not(.ico), .nav a { white-space: nowrap; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.user-chip {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px;
  background: var(--surface-2); border-radius: var(--radius-sm); font-size: 13px;
}
.user-chip > span { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.user-chip .badge { font-weight: 700; font-size: 10px; }
.link { color: var(--accent); font-size: 12.5px; }
.link:hover { text-decoration: underline; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; }
.view { padding: 24px 28px 60px; }
.loading { padding: 60px 0; text-align: center; color: var(--text-dim); }

.tabbar { display: none; }

/* =====================================================================
   Cartes & grilles
   ===================================================================== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 15px; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row   { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer{ flex: 1; }

/* Tuiles de statistiques */
.stat { padding: 16px 18px; }
.stat .label { font-size: 12.5px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .sub   { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* Cartes de compte */
.acc-card { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden; }
.acc-card::before { content:''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--c, var(--accent)); }
.acc-card .acc-name { font-weight: 650; }
.acc-card .acc-bank { font-size: 12.5px; color: var(--text-dim); }
.acc-card .acc-bal  { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.acc-card.archived { opacity: .55; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 650;
  background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border);
}
.badge.dot::before { content:'●'; margin-right: 5px; color: var(--c, var(--accent)); }

/* =====================================================================
   Tableaux / listes
   ===================================================================== */
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-dim); font-weight: 650; padding: 10px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl .right { text-align: right; }
table.tbl .amount { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.tbl-wrap { overflow-x: auto; }
.actions { display: flex; gap: 4px; justify-content: flex-end; }

.empty { padding: 46px 20px; text-align: center; color: var(--text-dim); }
.empty .big { font-size: 34px; display: block; margin-bottom: 10px; opacity: .5; }

/* Barre de répartition par catégorie */
.catrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 9px 0; }
.catrow .n { font-size: 14px; font-weight: 550; }
.catrow .v { font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }
.catrow .bar { grid-column: 1 / -1; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.catrow .bar i { display: block; height: 100%; border-radius: 99px; background: var(--c, var(--accent)); }

/* Mini graphique en barres */
.chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bars { display: flex; align-items: flex-end; gap: 3px; width: 100%; height: 100%; justify-content: center; }
.chart .bars i { width: 42%; max-width: 22px; border-radius: 4px 4px 0 0; display: block; min-height: 2px; }
.chart .bars .r { background: var(--green); }
.chart .bars .d { background: var(--red); }
.chart .lbl { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-soft); }
.legend b { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }

/* Filtres */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; align-items: end; }
.filters label { margin-bottom: 12px; }

/* =====================================================================
   Modale
   ===================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(8,10,20,.55);
  backdrop-filter: blur(3px); display: grid; place-items: center; padding: 18px;
  animation: fade .16s ease;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%; max-width: 480px; max-height: 88dvh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: pop .18s ease;
}
/* Secousse lorsqu'un clic à côté est ignoré parce qu'une saisie est en cours */
@keyframes modal-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
.modal.shake { animation: modal-shake .32s ease; }
@media (prefers-reduced-motion: reduce) { .modal.shake { animation: none; } }

.modal > header {
  position: sticky; top: 0; background: var(--surface); display: flex; align-items: center;
  justify-content: space-between; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); z-index: 1;
}
.modal > header h2 { font-size: 16px; }
.modal > div { padding: 18px 20px 20px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.modal-foot .spacer { flex: 1; }
@keyframes fade { from { opacity: 0 } }
@keyframes pop  { from { opacity: 0; transform: translateY(10px) scale(.98) } }

/* Sélecteur de type d'opération */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 16px; }
.segmented button {
  padding: 8px; border: 0; background: transparent; border-radius: 7px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--text-soft); transition: .13s;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented button.on[data-k="depense"] { color: var(--red); }
.segmented button.on[data-k="revenu"]  { color: var(--green); }

/* =====================================================================
   Notifications
   ===================================================================== */
.toasts { position: fixed; z-index: 200; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 11px 16px; border-radius: var(--radius-sm); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 550;
  animation: pop .18s ease; max-width: 340px;
}
.toast.ok   { border-left: 3px solid var(--green); }
.toast.err  { border-left: 3px solid var(--red); }
.toast.warn { border-left: 3px solid var(--amber); }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 14px 16px; }
  .topbar h1 { font-size: 17px; }
  .view { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .field-row, .field-row.three { grid-template-columns: 1fr; }
  .toasts { left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }

  .tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    display: grid; grid-template-columns: repeat(7, 1fr); align-items: center;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 5px 0; color: var(--text-dim); font-size: 10.5px;
  }
  .tabbar a .ico { font-size: 16px; }
  .tabbar a em { font-style: normal; font-weight: 600; }
  .tabbar a.active { color: var(--accent); }
  .tab-fab {
    justify-self: center; width: 46px; height: 46px; border-radius: 50%; border: 0;
    background: var(--accent); color: var(--accent-text); font-size: 24px; font-weight: 400;
    line-height: 1; cursor: pointer; box-shadow: 0 6px 18px -6px var(--accent);
  }
  .topbar-actions { display: none; }
  .modal { max-width: none; align-self: end; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92dvh; }
  .modal-backdrop { padding: 0; align-items: end; }
}

@media (max-width: 480px) {
  .grid.cols-3 { grid-template-columns: 1fr; }
  .stat { padding: 13px 14px; }
  .stat .label { font-size: 11px; }
  .stat .value { font-size: 19px; }
  .stat .sub { font-size: 11.5px; }
}

/* =====================================================================
   Patrimoine
   ===================================================================== */
.asset { overflow: hidden; }
.asset-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--c, var(--violet)) 9%, transparent), transparent);
}
.asset-head h3 { font-size: 16px; }
.asset-head .sub { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; }

.est-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1px; background: var(--border); }
.est {
  background: var(--surface); padding: 14px 16px; display: flex; flex-direction: column; gap: 3px;
  cursor: pointer; transition: background .13s; text-align: left; border: 0;
  border-top: 2px solid transparent; font: inherit; color: inherit;
}
.est:hover { background: var(--surface-2); }
.est.on { border-top-color: var(--accent); background: var(--accent-soft); }
.est .k { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); }
.est.on .k { color: var(--accent); }
.est .v { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.est .m { font-size: 11.5px; color: var(--text-dim); line-height: 1.35; }
.est .na { font-size: 15px; font-weight: 600; color: var(--text-dim); }
.est-note { padding: 12px 18px; font-size: 12.5px; color: var(--text-soft); border-top: 1px solid var(--border); }
.asset-foot { display: flex; align-items: center; gap: 10px; padding: 12px 18px;
              border-top: 1px solid var(--border); flex-wrap: wrap; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
        font-size: 11.5px; font-weight: 650; background: var(--surface-2); border: 1px solid var(--border); }
.pill.warn { background: color-mix(in srgb, var(--amber) 15%, transparent); color: var(--amber);
             border-color: color-mix(in srgb, var(--amber) 35%, transparent); }
.pill.ok   { background: var(--green-soft); color: var(--green);
             border-color: color-mix(in srgb, var(--green) 30%, transparent); }

.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 5; left: 0; right: 0; top: 100%; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); max-height: 230px; overflow: auto;
}
.combo-list button {
  display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; background: transparent;
  cursor: pointer; font-size: 14px; border-bottom: 1px solid var(--border);
}
.combo-list button:last-child { border-bottom: 0; }
.combo-list button:hover { background: var(--accent-soft); }
.combo-list .cp { color: var(--text-dim); font-size: 12px; }

.code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2);
        border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
        word-break: break-all; display: block; }

@media (max-width: 1100px) { .est-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 700px)  { .est-grid { grid-template-columns: 1fr; } }

/* Détail du calcul d'une estimation */
.calc { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.calc td { padding: 7px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.calc td.r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.calc tr.base td { font-weight: 650; background: var(--surface-2); }
.calc tr.total td { font-weight: 750; font-size: 15px; border-bottom: 0; border-top: 2px solid var(--border); }
.calc .pc { font-size: 11.5px; color: var(--text-dim); }
.calc .up { color: var(--money-sav); }
.calc .dn { color: var(--red); }

/* Formulaire de caractéristiques : sections repliables */
.fold { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 10px; }
.fold > summary { padding: 11px 14px; cursor: pointer; font-weight: 650; font-size: 14px; list-style: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: '▸'; display: inline-block; width: 16px; color: var(--text-dim); }
.fold[open] > summary::before { content: '▾'; }
.fold > summary:hover { background: var(--surface-2); }
.fold .fold-body { padding: 4px 14px 6px; border-top: 1px solid var(--border); }
.fold .fold-body label { margin-bottom: 12px; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 14px; }
.chk-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px 14px; margin-bottom: 14px; }
.chk-grid label { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 500; }
.chk-grid input { width: auto; margin: 0; }

@media (max-width: 900px) {
  .tabbar a em { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar a { padding-left: 2px; padding-right: 2px; }
}

/* =====================================================================
   Charges récurrentes · carte à débit différé · confirmations
   ===================================================================== */
.nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--amber); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-grid; place-items: center;
}
.tab-more {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 0;
  border: 0; background: transparent; color: var(--text-dim); font-size: 10.5px; cursor: pointer;
}
.tab-more .ico { font-size: 16px; }
.tab-more em { font-style: normal; font-weight: 600; }

.rec-row { display: grid; grid-template-columns: 1fr auto auto; gap: 2px 14px; padding: 12px 16px;
           border-bottom: 1px solid var(--border); align-items: center; }
.rec-row:last-child { border-bottom: 0; }
.rec-row:hover { background: var(--surface-2); }
.rec-row.off { opacity: .5; }
.rec-main { grid-column: 1; grid-row: 1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rec-main .lbl { font-weight: 600; }
.rec-meta { grid-column: 1; grid-row: 2; font-size: 12.5px; color: var(--text-dim); }
.rec-amt  { grid-column: 2; grid-row: 1 / span 2; text-align: right; font-variant-numeric: tabular-nums; }
.rec-amt .a { font-size: 17px; font-weight: 700; }
.rec-amt .m { font-size: 11.5px; color: var(--text-dim); }
.rec-actions { grid-column: 3; grid-row: 1 / span 2; display: flex; gap: 2px; }

@media (max-width: 640px) {
  .rec-row { grid-template-columns: 1fr auto; }
  .rec-actions { grid-column: 1 / -1; grid-row: 3; justify-content: flex-end; margin-top: 4px; }
}

.card-strip {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px; margin-top: 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); font-size: 13px;
}
.card-strip b { font-variant-numeric: tabular-nums; }

.confirm-row {
  display: grid; grid-template-columns: 1fr 150px auto auto; gap: 10px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.confirm-row:last-of-type { border-bottom: 0; }
.confirm-row input { margin-top: 0; }
.confirm-row .lbl { font-weight: 600; font-size: 14px; }
.confirm-row .sub { font-size: 12px; color: var(--text-dim); }

@media (max-width: 700px) {
  .confirm-row { grid-template-columns: 1fr auto; }
  .confirm-row .sub-wrap { grid-column: 1 / -1; }
}

/* Sous-catégories */
.tree { color: var(--text-dim); margin-right: 4px; font-size: 12px; }
tr.catsub td:first-child { padding-left: 26px; }
tr.catparent td:first-child { font-weight: 600; }
.catsubs { padding: 0 0 8px 14px; border-left: 2px solid var(--border); margin: -2px 0 6px 2px; }
.catsubrow { display: flex; justify-content: space-between; gap: 12px;
             font-size: 12.5px; color: var(--text-soft); padding: 3px 0; }

/* Épargne : intérêts */
.card-strip.sav { flex-direction: column; align-items: stretch; gap: 6px; }
.sav-line { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.sav-line b { font-size: 15px; }
.sav-bar { height: 5px; border-radius: 99px; background: var(--border); overflow: hidden; margin: 2px 0; }
.sav-bar i { display: block; height: 100%; border-radius: 99px; background: var(--green); }
.sav-meta { font-size: 11.5px; color: var(--text-dim); }
.card-strip.sav .btn { align-self: flex-start; margin-top: 4px; }
tr.future td { opacity: .6; }

.modal.wide { max-width: 660px; }
/* Un échéancier fait sept colonnes : il lui faut vraiment la place */
.modal.xwide { max-width: 940px; }
/* En-tête figé : sur 240 échéances, on perd sinon le nom des colonnes au premier défilement */
.tbl-wrap thead.sticky th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
.modal .stat { padding: 12px 14px; }
.modal .stat .label { font-size: 11px; }
.modal .stat .value { font-size: 20px; }
.modal .stat .sub { font-size: 11.5px; }
.modal .grid.cols-3 { gap: 10px; }

/* =====================================================================
   Correctif : l'attribut HTML `hidden` doit toujours l'emporter.
   Sans cette règle, tout élément auquel on donne un `display:` explicite
   (pastille, listes, blocs conditionnels) reste visible malgré `hidden`.
   ===================================================================== */
[hidden] { display: none !important; }

/* =====================================================================
   Prévisionnel — courbe de trésorerie
   Palette validée (scripts/validate_palette.js) :
   clair  #4f6bff / #e0344a sur #ffffff — CVD ΔE 27,5 · normale 34,9
   sombre #6b83ff / #e66767 sur #161b26 — CVD ΔE 22,5 · normale 28,2
   ===================================================================== */
:root { --chart-line: #4f6bff; --chart-neg: #e0344a; }
html[data-theme="dark"] { --chart-line: #6b83ff; --chart-neg: #e66767; }
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] { --chart-line: #6b83ff; --chart-neg: #e66767; }
}

.fc-wrap { position: relative; }
.fc-svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.fc-grid   { stroke: var(--border); stroke-width: 1; }
.fc-zero    { stroke: var(--text-dim); stroke-width: 1; stroke-dasharray: 4 4; }
.fc-line    { fill: none; stroke: var(--chart-line); stroke-width: 2;
              stroke-linejoin: round; stroke-linecap: round; }
.fc-area    { fill: var(--chart-line); opacity: .12; }
.fc-areaneg { fill: var(--chart-neg); opacity: .18; }
.fc-lineneg { fill: none; stroke: var(--chart-neg); stroke-width: 2; }
.fc-axis    { fill: var(--text-dim); font-size: 11px; font-family: var(--font); }
.fc-dot     { fill: var(--chart-line); stroke: var(--surface); stroke-width: 2; }
.fc-dot.low { fill: var(--chart-neg); }
.fc-cross   { stroke: var(--text-dim); stroke-width: 1; stroke-dasharray: 3 3; }
.fc-label   { font-size: 11.5px; font-weight: 700; font-family: var(--font); fill: var(--text); }
.fc-label.neg { fill: var(--chart-neg); }

.fc-tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 8px 11px; font-size: 12.5px; transform: translate(-50%, -115%);
}
.fc-tip .d { color: var(--text-dim); font-size: 11.5px; }
.fc-tip .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fc-tip .e { color: var(--text-soft); font-size: 11.5px; margin-top: 3px; }

.fc-legendline { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-soft); }
.fc-legendline i { display: inline-block; width: 14px; height: 3px; border-radius: 2px;
                   margin-right: 6px; vertical-align: middle; }

.ev-row { display: grid; grid-template-columns: 92px 1fr auto; gap: 4px 12px; align-items: center;
          padding: 9px 16px; border-bottom: 1px solid var(--border); }
.ev-row:last-child { border-bottom: 0; }
.ev-row:hover { background: var(--surface-2); }
.ev-date { font-size: 12.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.ev-amt  { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.ev-sep  { padding: 8px 16px; background: var(--surface-2); font-size: 12px; font-weight: 700;
           color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em;
           border-bottom: 1px solid var(--border); }

/* Pastille du menu : affordance de clic (le clic ouvre les échéances à confirmer) */
.nav-badge { cursor: pointer; transition: transform .12s, filter .12s; }
.nav-badge:hover { transform: scale(1.12); filter: brightness(1.08); }
.nav-badge:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* =====================================================================
   Couleur de l'argent
   ---------------------------------------------------------------------
   Les revenus passent du vert au bleu. Rouge/vert est justement la paire
   que les daltoniens (deutéranopie, protanopie) distinguent le plus mal ;
   rouge/bleu est nettement plus sûr.
   Contraste du texte vérifié : 5,48:1 sur fond clair, 6,14:1 sur fond sombre
   (WCAG AA demande 4,5:1). Paire bleu/rouge validée : ΔE daltonisme 26,4.

   Le VERT est réservé à un seul chiffre : ce qu'il vous reste à épargner.
   Ce n'est ni un revenu ni une dépense, mais le résultat des deux — il mérite
   sa propre couleur, et le vert dit « mis de côté » sans qu'on l'explique.
   Contraste vérifié : 5,21:1 sur fond clair (#0b7d45), 7,67:1 sur fond sombre.
   Réserve assumée : quand ce reste devient négatif il passe au rouge, et
   vert/rouge est justement la paire que distinguent le plus mal les daltoniens
   (ΔE 21 en clair, 9 en sombre). La couleur n'est donc jamais seule à porter
   l'information : le signe + ou − est toujours affiché, et le sous-titre dit
   en toutes lettres ce qui se passe.
   ===================================================================== */
:root                    { --money-pos: #3a58f0; --money-sav: #0b7d45; }
html[data-theme="dark"]  { --money-pos: #7d93ff; --money-sav: #35c47e; }
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] { --money-pos: #7d93ff; --money-sav: #35c47e; }
}

.pos                  { color: var(--money-pos); }
.sav                  { color: var(--money-sav); }
.sav-bar i            { background: var(--money-pos); }
.chart .bars .r       { background: var(--chart-line); }
.chart .bars .d       { background: var(--chart-neg); }

/* =====================================================================
   Crédits
   ===================================================================== */
.loan { overflow: hidden; }
.loan-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
             padding: 16px 18px 12px; }
.loan-head h3 { font-size: 16px; }
.loan-head .sub { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; }
.loan-crd { text-align: right; }
.loan-crd .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.loan-crd .l { font-size: 11.5px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }

.loan-bar { height: 8px; margin: 0 18px; border-radius: 99px; background: var(--surface-2);
            overflow: hidden; border: 1px solid var(--border); }
.loan-bar i { display: block; height: 100%; border-radius: 99px;
              background: linear-gradient(90deg, var(--money-pos), var(--chart-line)); }
.loan-bar-lbl { display: flex; justify-content: space-between; padding: 6px 18px 0;
                font-size: 11.5px; color: var(--text-dim); }

.loan-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1px;
             background: var(--border); margin-top: 14px; }
.loan-cell { background: var(--surface); padding: 12px 16px; }
.loan-cell .k { font-size: 11px; font-weight: 700; text-transform: uppercase;
                letter-spacing: .04em; color: var(--text-soft); }
.loan-cell .v { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.loan-cell .m { font-size: 11.5px; color: var(--text-dim); }
.loan-foot { display: flex; align-items: center; gap: 10px; padding: 12px 18px;
             border-top: 1px solid var(--border); flex-wrap: wrap; }
.loan.done { opacity: .6; }

@media (max-width: 760px) { .loan-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } }

/* =====================================================================
   Impôts
   ===================================================================== */
.tax-head { display: flex; align-items: flex-start; justify-content: space-between;
            gap: 12px; padding: 16px 18px 12px; }
.tax-head h3 { font-size: 16px; }
.tax-head .sub { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; }
.tax-total { text-align: right; }
.tax-total .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tax-total .l { font-size: 11.5px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }

.tax-steps { border-top: 1px solid var(--border); }
.tax-step { display: grid; grid-template-columns: 1fr auto; gap: 2px 14px;
            padding: 9px 18px; border-bottom: 1px solid var(--border); align-items: baseline; }
.tax-step:last-child { border-bottom: 0; }
.tax-step .n { font-size: 14px; }
.tax-step .v { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.tax-step .m { grid-column: 1 / -1; font-size: 12px; color: var(--text-dim); }
.tax-step.sum { background: var(--surface-2); font-weight: 700; }
.tax-step.sum .n { font-weight: 700; }
.tax-step.minus .v { color: var(--money-pos); }

.tax-kpi { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1px;
           background: var(--border); border-top: 1px solid var(--border); }
.tax-kpi > div { background: var(--surface); padding: 11px 16px; }
.tax-kpi .k { font-size: 11px; font-weight: 700; text-transform: uppercase;
              letter-spacing: .04em; color: var(--text-soft); }
.tax-kpi .v { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }

.bracket { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 6px 0;
           font-size: 13px; border-bottom: 1px solid var(--border); }
.bracket:last-child { border-bottom: 0; }
.bracket.on { font-weight: 700; }
.bracket .r { font-variant-numeric: tabular-nums; }

@media (max-width: 760px) { .tax-kpi { grid-template-columns: repeat(2, minmax(0,1fr)); } }

/* =====================================================================
   Import de relevés
   ===================================================================== */
.drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 30px 20px;
  text-align: center; background: var(--surface-2); transition: .15s; cursor: pointer;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .big { font-size: 30px; display: block; margin-bottom: 8px; opacity: .6; }
.drop input[type=file] { display: none; }

.imp-row td { vertical-align: middle; }
.imp-row.doublon { opacity: .45; }
.imp-row.rapprochement { background: color-mix(in srgb, var(--amber) 7%, transparent); }
.imp-row input[type=text] { margin-top: 0; padding: 6px 9px; font-size: 13.5px; }
.imp-row select { margin-top: 0; padding: 6px 9px; font-size: 13px; }
/* Le libellé d'origine de la banque : c'est lui qui permet de reconnaître
   l'opération, il doit se lire sans plisser les yeux. */
.imp-raw { font-size: 12.5px; color: var(--text-soft); font-family: var(--mono);
           line-height: 1.4; max-width: 420px;
           display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
           overflow: hidden; }
.imp-raw strong { color: var(--text); font-weight: 600; }

/* Vue regroupée par libellé d'origine */
.grp-row td { vertical-align: middle; }
.grp-n { display: inline-flex; align-items: center; justify-content: center; min-width: 26px;
         height: 22px; padding: 0 7px; border-radius: 999px; background: var(--accent-soft);
         color: var(--accent); font-size: 12px; font-weight: 700; }
.grp-detail { font-size: 12px; color: var(--text-dim); }
.grp-detail td { padding-top: 0; }
.grp-detail table { width: 100%; border-collapse: collapse; }
.grp-detail td.d { padding: 3px 6px; border: 0; }
.seg-view { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm);
            overflow: hidden; }
.seg-view button { border: 0; background: var(--surface); padding: 6px 12px; font-size: 13px;
                   font-weight: 600; color: var(--text-soft); cursor: pointer; }
.seg-view button.on { background: var(--accent); color: var(--accent-text); }

/* Création d'une catégorie sur place, sous le champ qui l'a demandée */
.cat-quick { margin-top: 6px; padding: 10px; border: 1px solid var(--accent);
             border-radius: var(--radius-sm); background: var(--surface-2);
             box-shadow: 0 6px 18px rgba(0,0,0,.10); animation: cqIn .14s ease-out; }
@keyframes cqIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.cat-quick .cq-row { display: flex; gap: 6px; align-items: center; }
.cat-quick input[type=text] { flex: 1; margin: 0; min-width: 0; }
.cat-quick input[type=color] { width: 38px; height: 38px; padding: 2px; margin: 0; flex: none;
                               border: 1px solid var(--border); border-radius: var(--radius-sm);
                               background: var(--surface); cursor: pointer; }
.cat-quick select { margin: 6px 0 0; }
.cat-quick .cq-err { margin-top: 6px; font-size: 12.5px; color: var(--red); }
.cat-quick .cq-foot { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.cat-quick .cq-hint { flex: 1; font-size: 12px; color: var(--text-dim); }
.imp-badge { font-size: 10.5px; padding: 1px 6px; border-radius: 99px; font-weight: 700; }
.imp-badge.dict { background: var(--accent-soft); color: var(--accent); }
.imp-badge.regle { background: var(--green-soft); color: var(--green); }
.imp-badge.nettoyage { background: var(--surface-2); color: var(--text-dim); }

.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 12px; }

/* Import d'un crédit : la liste des contrôles arithmétiques */
.ctrl-list { list-style: none; margin: 0; padding: 0; }
.ctrl-list li { display: flex; gap: 9px; align-items: flex-start; padding: 5px 0; font-size: 13.5px; }
.ctrl-list li .s { font-weight: 700; width: 16px; flex: none; }
.ctrl-list li.ok .s { color: var(--green); }
.ctrl-list li.ko .s { color: var(--red); }
.ctrl-list li.ko { color: var(--red); }

/* Le corps d'une carte de compte est cliquable : il mène à ses opérations */
.acc-open {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 0; margin: 0; cursor: pointer; border-radius: var(--radius-sm);
  transition: background .15s;
}
.acc-open:hover { background: var(--surface-2); }
.acc-open .acc-go { margin-top: 6px; font-size: 12.5px; font-weight: 600; color: var(--accent); opacity: 0; transition: opacity .15s; }
.acc-open:hover .acc-go, .acc-open:focus-visible .acc-go { opacity: 1; }
.acc-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: none) { .acc-open .acc-go { opacity: 1; } }

/* Barre de sélection dans le détail d'un groupe d'import */
.grp-detail tr.d-head td { display: flex; align-items: center; gap: 10px; padding: 4px 6px 8px; }
.grp-detail tr.d-head .spacer { flex: 1; }
.grp-detail tr.d-head .check { white-space: nowrap; }
.grp-detail td.d input[type=checkbox] { width: auto; margin: 0; }
