/* ============================================================
   Trésorerie — thème clair façon Stripe
   Inter · violet #635BFF · surfaces blanches sur fond #f6f9fc
   ============================================================ */

:root {
  --bg: #f6f9fc;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --surface-3: #eef2f7;
  --line: #e3e8ee;
  --line-2: #e6ebf1;

  --text: #1a1f36;
  --text-2: #3c4257;
  --muted: #697386;
  --faint: #8792a2;

  --primary: #635bff;
  --primary-dark: #4f47e0;
  --primary-soft: #f0effe;
  --blue: #0073e6;
  --green: #0e9f6e;
  --amber: #d98c1f;
  --red: #df1b41;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 0 0 1px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(50, 50, 93, 0.06), 0 1px 1px rgba(0, 0, 0, 0.04);
  --shadow: 0 0 0 1px rgba(0, 0, 0, 0.02), 0 4px 10px -2px rgba(50, 50, 93, 0.10), 0 2px 4px -1px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 7px 14px rgba(50, 50, 93, 0.10), 0 3px 6px rgba(0, 0, 0, 0.07);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px 1fr;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
.num, .hero-amount, .card-value, .ls-val { font-variant-numeric: tabular-nums; }
.hero-amount, .card-value, .ls-val, .num, .delta { white-space: nowrap; }

/* ---------------- Sidebar ---------------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; z-index: 5;
  display: flex; flex-direction: column;
  padding: 22px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; margin-bottom: 28px; padding: 0 8px; }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px;
  color: #fff; background: linear-gradient(135deg, #7a73ff, var(--primary));
  box-shadow: 0 2px 5px rgba(99, 91, 255, 0.35);
}
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -0.01em; color: var(--text); }
.brand-sub { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); margin-top: 1px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  padding: 9px 11px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2);
  font-family: var(--sans); font-size: 14px; font-weight: 550; cursor: pointer;
  transition: background 0.13s, color 0.13s;
}
.nav button .ic { font-size: 14px; width: 16px; text-align: center; color: var(--faint); transition: color 0.13s; }
.nav button:hover { background: var(--surface-2); }
.nav button.active { background: var(--primary-soft); color: var(--primary); }
.nav button.active .ic { color: var(--primary); }

.side-foot { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--line); }
.side-foot-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--faint); }
.side-foot-val { font-size: 12.5px; color: var(--muted); margin: 4px 0 14px; }

/* ---------------- Main ---------------- */
.main { position: relative; padding: 34px 40px 64px; max-width: 1140px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-title { font-weight: 680; font-size: 26px; letter-spacing: -0.02em; margin: 0; color: var(--text); }
.page-sub { color: var(--muted); font-size: 14px; margin-top: 3px; }

.fade-in { animation: fade 0.4s var(--ease) both; }
.stagger > * { animation: fade 0.45s var(--ease) both; }
.stagger > *:nth-child(1) { animation-delay: 0.03s; }
.stagger > *:nth-child(2) { animation-delay: 0.08s; }
.stagger > *:nth-child(3) { animation-delay: 0.13s; }
.stagger > *:nth-child(4) { animation-delay: 0.18s; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- Hero ---------------- */
.hero {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 30px 28px; margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.hero::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, #00d4ff, var(--primary) 45%, #ff80b5);
}
.hero-label { font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.hero-amount {
  font-weight: 700; line-height: 1; letter-spacing: -0.03em;
  font-size: clamp(38px, 5.5vw, 60px); margin: 12px 0 4px; color: var(--text);
}
.hero-amount.neg { color: var(--red); }
.hero-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 13.5px; }
.delta { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.delta.up { color: var(--green); background: #e7f6ef; }
.delta.down { color: var(--red); background: #fdeaee; }
.delta.flat { color: var(--muted); background: var(--surface-3); }
.hero-spark { position: absolute; right: 0; bottom: 0; width: 42%; max-width: 400px; opacity: 0.75; }
.hero-expl { margin-top: 11px; font-size: 13.5px; color: var(--text-2); max-width: 60%; position: relative; z-index: 1; }

/* champ d'explication de variation */
.var-hint { display: none; margin-top: 6px; font-size: 12.5px; color: var(--amber); font-weight: 500; }
.var-hint.show { display: block; }
input.flag { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(217, 140, 31, 0.15); }
#var-delta { font-weight: 500; }
.chart-tip .t-note { margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--line); color: var(--text-2); font-family: var(--sans); max-width: 220px; white-space: normal; font-weight: 500; }

/* ---------------- Cards / grid ---------------- */
.grid-2 { display: grid; grid-template-columns: 1.55fr 1fr; gap: 20px; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 20px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.mint { background: var(--blue); }
.dot.amber { background: var(--amber); }
.dot.blue { background: var(--blue); }
.card-value { font-weight: 680; font-size: 26px; letter-spacing: -0.02em; margin-top: 9px; color: var(--text); }
.card-value.amber { color: var(--amber); }
.card-foot { margin-top: 6px; font-size: 12.5px; color: var(--faint); }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 20px; box-shadow: var(--shadow-sm);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.panel h2 { font-weight: 650; font-size: 15px; margin: 0; color: var(--text); letter-spacing: -0.01em; }

/* ---------------- Chart ---------------- */
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend b { display: inline-flex; align-items: center; gap: 6px; font-weight: 550; }
.legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-path { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw 1s var(--ease) 0.1s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.chart-tip {
  position: absolute; pointer-events: none; transform: translate(-50%, -120%);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; font-size: 12px; white-space: nowrap; opacity: 0; transition: opacity 0.12s;
  box-shadow: var(--shadow-lg); color: var(--text);
}
.chart-tip.show { opacity: 1; }
.chart-tip .t-row { display: flex; gap: 14px; justify-content: space-between; align-items: center; }
.chart-tip .t-row b { font-variant-numeric: tabular-nums; }
.chart-tip .t-date { color: var(--muted); margin-bottom: 5px; font-weight: 600; }

/* ---------------- Donut ---------------- */
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut-legend { display: flex; flex-direction: column; gap: 9px; flex: 1; min-width: 150px; }
.donut-legend .dl { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--text-2); }
.donut-legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.donut-legend .dl .amt { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------- Tables ---------------- */
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; padding: 0 12px 10px; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
tbody td { padding: 11px 12px; border-top: 1px solid var(--line-2); font-size: 14px; color: var(--text-2); }
tbody tr:hover td { background: var(--surface-2); }
.num { text-align: right; }
tr.group td { background: var(--surface-2); font-weight: 600; font-size: 11.5px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
tr.group:hover td { background: var(--surface-2); }
tr.group td .gline { display: inline-flex; align-items: center; gap: 8px; }
tr.total td { border-top: 1.5px solid var(--line); font-weight: 650; color: var(--text); }
tr.grand td { font-size: 15px; font-weight: 680; }
tr.dim td { color: var(--muted); }
.val-pos { color: var(--green); }
.val-neg { color: var(--red); }
.chip { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.chip.live { color: var(--green); background: #e7f6ef; }
.chip.arch { color: var(--muted); background: var(--surface-3); }

/* ---------------- Forms ---------------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12.5px; font-weight: 550; color: var(--text-2); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; font-family: var(--sans); font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.03); transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.18);
}
input.num { text-align: right; font-variant-numeric: tabular-nums; }
.input-money { position: relative; }
.input-money input { padding-right: 40px; }
.input-money .suffix { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); font-size: 12px; font-weight: 600; pointer-events: none; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-2);
  font-family: var(--sans); font-size: 14px; font-weight: 600; cursor: pointer;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04); transition: all 0.15s var(--ease); text-decoration: none;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn-accent {
  background: var(--primary); color: #fff; border-color: transparent;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(99, 91, 255, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.btn-accent:hover { background: var(--primary-dark); color: #fff; box-shadow: 0 2px 5px rgba(99, 91, 255, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15); }
.btn-danger { color: var(--red); border-color: #f5c2cc; background: #fff; }
.btn-danger:hover { background: #fdeaee; color: var(--red); }
.btn-ghost { background: var(--surface); color: var(--text-2); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn-row { display: flex; gap: 12px; margin-top: 18px; }

/* sticky live summary */
.live-bar {
  position: sticky; bottom: 0; margin: 0 -22px -20px; padding: 15px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.9); border-top: 1px solid var(--line);
  backdrop-filter: blur(8px); border-radius: 0 0 var(--radius) var(--radius);
}
.live-stats { display: flex; gap: 26px; flex-wrap: wrap; }
.live-stats .ls-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); font-weight: 600; }
.live-stats .ls-val { font-size: 17px; font-weight: 680; margin-top: 2px; color: var(--text); letter-spacing: -0.01em; }

/* free amount lines */
.extra-row { display: grid; grid-template-columns: 1fr 200px 38px; gap: 11px; margin-bottom: 10px; align-items: center; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--muted); cursor: pointer; font-size: 14px; transition: all 0.15s var(--ease); box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}
.icon-btn:hover { color: var(--red); border-color: #f5c2cc; background: #fdeaee; }
.row-actions { display: inline-flex; gap: 8px; white-space: nowrap; }

/* ---------------- Misc ---------------- */
.empty { text-align: center; color: var(--muted); padding: 56px 20px; }
.empty .em-mark { font-size: 32px; color: var(--faint); display: block; margin-bottom: 12px; }
.skeleton { color: var(--faint); padding: 56px; text-align: center; }

.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translate(-50%, 20px);
  z-index: 100; padding: 12px 20px; border-radius: 8px; font-weight: 600; font-size: 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: all 0.28s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok::before { content: "✓ "; color: var(--green); }
.toast.err { border-color: #f5c2cc; }
.toast.err::before { content: "⚠ "; color: var(--red); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: #cfd7e0; border-radius: 6px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #b7c1cc; }

/* ---------------- Responsive ---------------- */
@media (max-width: 920px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center; gap: 10px;
    padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto;
  }
  .brand { margin: 0 6px 0 0; }
  .brand-sub { display: none; }
  .nav { flex-direction: row; }
  .nav button .ic { display: none; }
  .side-foot { display: none; }
  .main { padding: 22px 18px 50px; }
  .grid-2, .stats, .row-2 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: flex-start; }
}
