:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-soft: #f8f7f3;
  --ink: #101917;
  --muted: #61716b;
  --green-950: #0f3f31;
  --green-900: #155640;
  --green-800: #1f6f52;
  --green-700: #2b8562;
  --green-100: #e4f0eb;
  --line: #e1ded6;
  --danger: #a94b32;
  --shadow: 0 18px 50px rgba(26, 38, 33, 0.1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 80% 0%, rgba(255, 255, 255, 0.96), transparent 34rem), linear-gradient(135deg, #f8f7f3 0%, var(--bg) 48%, #ece8df 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, select, input { font: inherit; }
button, select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: white;
}
button { cursor: pointer; font-weight: 800; }
a { color: inherit; text-decoration: none; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  width: 250px;
  padding: 24px 14px;
  color: white;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(21, 86, 64, 0.96), rgba(11, 57, 43, 0.98)), radial-gradient(circle at 70% 100%, rgba(142, 180, 151, 0.42), transparent 18rem);
  box-shadow: 20px 0 60px rgba(7, 42, 32, 0.25);
}
.brand { display: grid; justify-items: center; gap: 8px; padding: 0 12px 28px; text-align: center; }
.brand-mark {
  display: grid; place-items: center; width: 46px; height: 46px; border: 1px solid rgba(255, 255, 255, 0.38); border-radius: 50%;
  font-family: Georgia, serif; font-size: 1.05rem;
}
.brand strong { font-family: Georgia, "Times New Roman", serif; font-size: 1.55rem; font-weight: 400; letter-spacing: 0.04em; text-transform: uppercase; }
.brand span { color: rgba(255, 255, 255, 0.82); font-size: 0.86rem; }
.side-nav { display: grid; flex: 1 1 auto; gap: 8px; min-height: 0; }
.side-nav a { display: flex; align-items: center; min-height: 50px; border-radius: 8px; padding: 0 18px; color: rgba(255, 255, 255, 0.88); }
.side-nav a.active, .side-nav a:hover { background: rgba(255, 255, 255, 0.12); color: white; }
.side-note {
  flex: 0 0 auto;
  margin: 18px 4px 0;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
  padding: 18px 16px;
  font-family: Georgia, serif;
  font-size: 1rem;
  line-height: 1.4;
  background: rgba(255, 255, 255, 0.08);
}
.page { width: calc(100% - 250px); margin-left: 250px; padding: 28px 30px 36px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 4vw, 2.8rem); line-height: 1; }
.topbar p { margin-bottom: 0; color: #263b34; font-family: Georgia, serif; font-style: italic; font-size: 1.12rem; }
.top-actions { display: flex; align-items: center; gap: 12px; color: #263b34; font-size: 0.92rem; }
.top-actions button, .primary-button { border: 0; color: white; background: var(--green-800); }
.primary-button,
#saveSettingsButton {
  position: relative;
  z-index: 2;
  pointer-events: auto;
}
.avatar { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; color: white; background: linear-gradient(135deg, var(--green-700), var(--green-950)); box-shadow: var(--shadow); font-family: Georgia, serif; font-size: 1.45rem; }
.dashboard { display: grid; gap: 18px; }
.card, .status-card { border: 1px solid rgba(225, 222, 214, 0.82); border-radius: 8px; background: rgba(255, 255, 255, 0.86); box-shadow: var(--shadow); }
.status-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; }
.status-card span, .card span, dt, .muted { color: var(--muted); }
.status-card strong { display: block; margin-top: 2px; font-size: 0.96rem; }
.status-card em { border-radius: 999px; padding: 7px 11px; color: #5a4b23; background: #efe6cb; font-size: 0.82rem; font-style: normal; font-weight: 800; white-space: nowrap; }
.status-card em.ok { color: var(--green-800); background: var(--green-100); }
.status-card em.error { color: var(--danger); background: #f6dfd9; }
.hero-grid { display: grid; grid-template-columns: 1.12fr 0.94fr 1.35fr 1.28fr; gap: 18px; }
.card { padding: 20px; }
.total-card {
  position: relative; overflow: hidden; min-height: 158px; color: white;
  background: radial-gradient(circle at 82% 18%, rgba(228, 240, 235, 0.3), transparent 10rem), linear-gradient(135deg, var(--green-900), #09271f);
}
.total-card::after { content: ""; position: absolute; inset: auto -34px -48px auto; width: 180px; height: 180px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, 0.23), transparent 70%); }
.total-card span, .total-card small { color: rgba(255, 255, 255, 0.82); }
.total-card strong { display: block; margin: 12px 0; font-family: Georgia, serif; font-size: clamp(2.4rem, 4.5vw, 3.6rem); font-weight: 400; line-height: 1; }
.metric-card { min-height: 158px; }
.metric-card > strong, .metric-row strong { display: block; margin: 12px 0 8px; font-family: Georgia, serif; font-size: clamp(1.8rem, 3vw, 2.3rem); line-height: 1; }
.metric-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
mark { display: inline-flex; margin-top: 10px; border-radius: 8px; padding: 6px 10px; color: #1a4b3b; background: var(--green-100); font-weight: 800; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; }
.main-stack { display: grid; gap: 18px; min-width: 0; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.lower-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.donut-card { grid-column: 1 / -1; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2, .rail-title h2 { margin: 0; font-family: Georgia, serif; font-size: 1.25rem; }
.card-head button { min-height: 32px; padding: 0 10px; font-size: 0.82rem; }
.card-head button,
.top-actions button,
.top-actions select {
  white-space: nowrap;
}
.line-chart { min-height: 230px; }
.line-chart svg { width: 100%; height: 230px; display: block; }
.chart-grid text { fill: #31443e; font-size: 12px; }
.donut-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 22px; align-items: center; }
.donut { display: grid; place-items: center; width: 190px; height: 190px; border-radius: 50%; background: radial-gradient(circle, white 0 45%, transparent 46%), conic-gradient(var(--green-800) 0 22%, #6d977e 22% 60%, #a9aa7e 60% 72%, #d5ceb4 72% 100%); }
.donut strong { align-self: end; font-family: Georgia, serif; font-size: 1.45rem; }
.donut span { align-self: start; font-size: 0.85rem; }
.legend { display: grid; gap: 10px; }
.legend-row, .transaction-row, .recommendation { display: grid; gap: 8px; border-radius: 8px; padding: 11px 12px; background: var(--surface-soft); }
.legend-row { grid-template-columns: 10px minmax(150px, 1fr) max-content 46px; align-items: center; column-gap: 10px; }
.legend-row strong,
.legend-row span,
.legend-row small {
  white-space: nowrap;
}
.legend-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green-800); }
.ring { display: grid; place-items: center; width: 92px; height: 92px; border-radius: 50%; background: radial-gradient(circle, white 0 55%, transparent 56%), conic-gradient(var(--green-800) calc(var(--value) * 1%), #e3e8e5 0); }
.ring.large { width: 150px; height: 150px; margin: 4px auto 18px; }
.ring.pale { background: radial-gradient(circle, white 0 55%, transparent 56%), conic-gradient(#0e7a5d calc(var(--value) * 1%), #e3e8e5 0); }
.ring b { font-family: Georgia, serif; font-size: 1.15rem; }
.ring.large b { font-size: 2rem; }
dl { display: grid; gap: 8px; margin: 0; }
dl div { display: flex; justify-content: space-between; gap: 12px; }
dd { margin: 0; font-weight: 900; }
.indicators { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.indicators article { min-width: 0; border-right: 1px solid var(--line); padding-right: 12px; }
.indicators article:last-child { border-right: 0; }
.indicators strong { display: block; margin-top: 8px; color: var(--green-800); font-family: Georgia, serif; font-size: 1.6rem; }
.right-rail { min-width: 0; }
.recommendations { position: sticky; top: 24px; }
.rail-title { display: grid; grid-template-columns: 34px 1fr; gap: 10px; margin-bottom: 18px; }
.rail-title > span { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #7f651e; background: #f4e9c9; font-weight: 900; }
.rail-title p { margin: 8px 0 0; color: var(--muted); font-size: 0.9rem; line-height: 1.35; }
#recommendationsList { display: grid; gap: 12px; }
.recommendation { background: white; border: 1px solid var(--line); }
.recommendation.priority { background: var(--green-100); }
.recommendation strong { color: var(--ink); }
.recommendation p { margin: 0; color: #40524c; font-size: 0.92rem; line-height: 1.35; }
.transaction-row { grid-template-columns: 1fr auto; align-items: center; border: 1px solid var(--line); }
.transaction-row strong { overflow-wrap: anywhere; }
.transaction-row small, .legend-row small, .indicators small { color: var(--muted); }
.positive { color: var(--green-800); }
.negative { color: var(--danger); }
.settings-panel { scroll-margin-top: 18px; }
summary { cursor: pointer; color: var(--green-800); font-weight: 900; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; margin-top: 14px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 0.92rem; font-weight: 800; }
input { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; color: var(--ink); background: white; }
.mobile-nav { display: none; }

@media (max-width: 1180px) {
  .content-grid { grid-template-columns: 1fr; }
  .recommendations { position: static; }
  #recommendationsList { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .sidebar { display: none; }
  .page { width: 100%; margin-left: 0; padding: 22px 18px 96px; }
  .hero-grid, .chart-grid, .lower-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .donut-card { grid-column: 1 / -1; }
  .mobile-nav {
    position: fixed; right: 10px; bottom: 10px; left: 10px; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
    border: 1px solid rgba(255, 255, 255, 0.45); border-radius: 8px; padding: 6px; background: rgba(8, 45, 35, 0.94); box-shadow: 0 10px 32px rgba(0, 0, 0, 0.28); backdrop-filter: blur(14px);
  }
  .mobile-nav a { border-radius: 8px; padding: 9px 4px; color: rgba(255, 255, 255, 0.78); text-align: center; font-size: 0.76rem; font-weight: 800; }
  .mobile-nav a.active { color: white; background: rgba(255, 255, 255, 0.14); }
}
@media (max-width: 720px) {
  body { background: #f4f3ef; }
  .page { padding: 18px 12px 94px; }
  .topbar, .top-actions { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .top-actions span, .avatar { display: none; }
  .top-actions select, .top-actions button { width: 100%; }
  .hero-grid, .chart-grid, .lower-grid, .indicators, #recommendationsList, .settings-grid { grid-template-columns: 1fr; }
  .card, .status-card { padding: 16px; }
  .total-card, .metric-card { min-height: 132px; }
  .donut-layout { grid-template-columns: 1fr; justify-items: center; }
  .legend { width: 100%; }
  .line-chart, .line-chart svg { min-height: 210px; height: 210px; }
  .indicators article { border-right: 0; border-bottom: 1px solid var(--line); padding: 0 0 12px; }
  .indicators article:last-child { border-bottom: 0; padding-bottom: 0; }
}


/* Navigation conditionnelle v5.8 */
.view-heading {
  display: none;
  margin: 0 0 18px;
  padding: 18px 20px;
  border: 1px solid rgba(10, 59, 45, .12);
  border-radius: 16px;
  background: #fff;
}
.view-heading.visible { display: block; }
.view-heading span {
  display: block;
  margin-bottom: 4px;
  color: #6a746f;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.view-heading h2 {
  margin: 0 0 4px;
  color: #143f33;
  font-size: 1.45rem;
}
.view-heading p {
  margin: 0;
  color: #6a746f;
}

.view-item.view-hidden {
  display: none !important;
}

.view-container.view-empty {
  display: none !important;
}

/* Quand une rubrique précise est ouverte, les cartes visibles utilisent la largeur disponible. */
body[data-current-view]:not([data-current-view="synthese"]) .hero-grid,
body[data-current-view]:not([data-current-view="synthese"]) .chart-grid,
body[data-current-view]:not([data-current-view="synthese"]) .lower-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
body[data-current-view]:not([data-current-view="synthese"]) .content-grid {
  grid-template-columns: minmax(0, 1fr);
}
body[data-current-view]:not([data-current-view="synthese"]) .right-rail:not(.view-hidden) {
  width: 100%;
}
.side-nav a,
.mobile-nav a {
  cursor: pointer;
}
.side-nav a:focus-visible,
.mobile-nav a:focus-visible {
  outline: 3px solid rgba(255,255,255,.65);
  outline-offset: 2px;
}


/* Animation douce sur les graphiques */
@keyframes chartFlashGlow {
  0%, 100% {
    filter: drop-shadow(0 0 0 rgba(20, 95, 71, 0));
    transform: translateZ(0) scale(1);
  }
  50% {
    filter: drop-shadow(0 0 10px rgba(20, 95, 71, 0.28));
    transform: translateZ(0) scale(1.006);
  }
}

.chart-card canvas,
.chart-card svg,
[id*="chart"] canvas,
[id*="chart"] svg,
[class*="chart"] canvas,
[class*="chart"] svg {
  animation: chartFlashGlow 2.8s ease-in-out infinite;
  transform-origin: center;
  will-change: filter, transform;
}

/* Petit halo sur la carte du graphique au survol */
.chart-card {
  transition: box-shadow .25s ease, transform .25s ease;
}

.chart-card:hover {
  box-shadow: 0 10px 30px rgba(20, 95, 71, .14);
  transform: translateY(-2px);
}

/* Accessibilité : aucune animation si l'utilisateur préfère réduire les mouvements */
@media (prefers-reduced-motion: reduce) {
  .chart-card canvas,
  .chart-card svg,
  [id*="chart"] canvas,
  [id*="chart"] svg,
  [class*="chart"] canvas,
  [class*="chart"] svg {
    animation: none !important;
  }

  .chart-card {
    transition: none !important;
  }

  .chart-card:hover {
    transform: none !important;
  }
}


/* =========================================================
   Animation graphique visible — v5.8
   Active uniquement dans Prévisions et Analyse.
   ========================================================= */

@keyframes chartCardPulseVisible {
  0%, 100% {
    box-shadow:
      0 8px 22px rgba(10, 59, 45, .08),
      0 0 0 0 rgba(22, 112, 82, 0);
  }
  50% {
    box-shadow:
      0 14px 34px rgba(10, 59, 45, .18),
      0 0 0 5px rgba(22, 112, 82, .10),
      0 0 28px rgba(22, 112, 82, .20);
  }
}

@keyframes chartSweep {
  0%   { transform: translateX(-145%) skewX(-18deg); opacity: 0; }
  15%  { opacity: .08; }
  45%  { opacity: .24; }
  70%  { opacity: .08; }
  100% { transform: translateX(245%) skewX(-18deg); opacity: 0; }
}

@keyframes chartLineGlow {
  0%, 100% {
    filter: drop-shadow(0 0 1px rgba(13,77,59,.15));
    stroke-width: 4;
  }
  50% {
    filter:
      drop-shadow(0 0 4px rgba(13,77,59,.55))
      drop-shadow(0 0 9px rgba(27,125,91,.35));
    stroke-width: 5;
  }
}

@keyframes chartAreaBreath {
  0%, 100% { opacity: .70; }
  50% { opacity: 1; }
}

@keyframes chartPointPulse {
  0%, 100% {
    r: 6px;
    filter: drop-shadow(0 0 1px rgba(13,77,59,.2));
  }
  50% {
    r: 8px;
    filter: drop-shadow(0 0 7px rgba(13,77,59,.55));
  }
}

.chart-card {
  position: relative;
  overflow: hidden;
}

/* Le balayage lumineux est volontairement doux et lent. */
body[data-current-view="previsions"] .chart-card:not(.view-hidden),
body[data-current-view="analyse"] .chart-card:not(.view-hidden) {
  animation: chartCardPulseVisible 3.2s ease-in-out infinite;
}

body[data-current-view="previsions"] .chart-card:not(.view-hidden)::after,
body[data-current-view="analyse"] .chart-card:not(.view-hidden)::after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: -20% auto -20% -35%;
  width: 26%;
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0),
    rgba(172,229,207,.48),
    rgba(255,255,255,.72),
    rgba(172,229,207,.32),
    rgba(255,255,255,0)
  );
  filter: blur(4px);
  animation: chartSweep 3.6s ease-in-out infinite;
  z-index: 4;
}

body[data-current-view="previsions"] .chart-line-animated,
body[data-current-view="analyse"] .chart-line-animated {
  animation: chartLineGlow 2.2s ease-in-out infinite;
}

body[data-current-view="previsions"] .chart-area-animated,
body[data-current-view="analyse"] .chart-area-animated {
  animation: chartAreaBreath 2.6s ease-in-out infinite;
}

body[data-current-view="previsions"] .chart-point-animated,
body[data-current-view="analyse"] .chart-point-animated {
  animation: chartPointPulse 1.8s ease-in-out infinite;
}

/* Si l'ancienne animation générique est présente, on la neutralise pour
   éviter que deux animations se superposent. */
.chart-card svg,
[id*="chart"] svg,
[class*="chart"] svg {
  animation: none;
}

/* Accessibilité */
@media (prefers-reduced-motion: reduce) {
  body[data-current-view="previsions"] .chart-card:not(.view-hidden),
  body[data-current-view="analyse"] .chart-card:not(.view-hidden),
  body[data-current-view="previsions"] .chart-card:not(.view-hidden)::after,
  body[data-current-view="analyse"] .chart-card:not(.view-hidden)::after,
  body[data-current-view="previsions"] .chart-line-animated,
  body[data-current-view="analyse"] .chart-line-animated,
  body[data-current-view="previsions"] .chart-area-animated,
  body[data-current-view="analyse"] .chart-area-animated,
  body[data-current-view="previsions"] .chart-point-animated,
  body[data-current-view="analyse"] .chart-point-animated {
    animation: none !important;
  }
}


.chart-period-select {
  appearance: none;
  border: 1px solid rgba(13, 77, 59, .16);
  background:
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(247,245,239,.96));
  color: #123f32;
  border-radius: 10px;
  padding: 8px 34px 8px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-width: 110px;
  background-image:
    linear-gradient(45deg, transparent 50%, #315e50 50%),
    linear-gradient(135deg, #315e50 50%, transparent 50%),
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(247,245,239,.96));
  background-position:
    calc(100% - 16px) 50%,
    calc(100% - 11px) 50%,
    0 0;
  background-size: 5px 5px, 5px 5px, 100% 100%;
  background-repeat: no-repeat;
}

.chart-period-select:hover,
.chart-period-select:focus {
  border-color: rgba(13, 77, 59, .38);
  outline: none;
  box-shadow: 0 0 0 3px rgba(13, 77, 59, .08);
}


.chart-period-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 8px 0 14px;
}

.chart-period-stats span {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid rgba(13, 77, 59, .10);
  border-radius: 10px;
  background: rgba(255,255,255,.58);
}

.chart-period-stats small {
  color: #6a776f;
  font-size: .76rem;
}

.chart-period-stats strong {
  color: #123f32;
  font-size: .94rem;
}

.chart-period-stats strong.negative { color: #a64040; }
.chart-period-stats strong.positive { color: #246b50; }

@media (max-width: 720px) {
  .chart-period-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}


.week-select {
  min-width: 190px;
}

.week-select[hidden] {
  display: none !important;
}

@media (max-width: 720px) {
  .week-select {
    min-width: 0;
    max-width: 100%;
  }
}


/* Lisibilité des valeurs dans les cartouches des graphiques */
.chart-value-label,
.chart-end-label,
.chart-tooltip-value {
  fill: #ffffff !important;
  color: #ffffff !important;
  font-weight: 700 !important;
}

svg .value-label,
svg .end-label {
  fill: #ffffff !important;
  font-weight: 700 !important;
}


/* Sélecteurs de période avancés */
.month-select[hidden], .year-select[hidden], .week-select[hidden] { display: none !important; }
.month-select, .year-select, .week-select { min-width: 132px; }
.secondary-button { white-space: nowrap; }

/* Analyse enrichie */
.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 16px 0;
}
.compact-insight { min-height: 150px; }
.compact-insight > strong { display: block; font-size: 1.35rem; margin-top: 14px; }
.period-summary { font-size: 1.02rem; line-height: 1.5; margin: 12px 0 8px; }
.period-badge {
  display: inline-flex;
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef3ef;
  color: #0a3b2d;
  font-weight: 700;
}
.mini-list { display: grid; gap: 8px; margin-top: 10px; }
.mini-list > div, .category-budget-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #ece8df;
}
.category-budget-row {
  width: 100%;
  text-align: left;
  background: transparent;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  cursor: pointer;
}
.category-budget-row small { grid-column: 1 / -1; }
.split-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.split-stats span {
  padding: 12px;
  border-radius: 12px;
  background: #f7f5ef;
}
.split-stats small, .split-stats strong { display: block; }
.category-row-button {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.category-row-button:hover { background: rgba(10,59,45,.04); }
.category-detail-card { margin: 16px 0; }

@media (max-width: 980px) {
  .insight-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .insight-grid { grid-template-columns: 1fr; }
  .month-select, .year-select, .week-select { max-width: 100%; min-width: 0; }
}


/* Graphiques financiers : lisibilité et responsive */
.chart-axis-label {
  fill: #5f6b66;
  font-size: 12px;
  font-weight: 600;
}
.balance-chart svg,
.projection-chart svg,
#balanceChart svg,
#projectionChart svg {
  width: 100%;
  height: auto;
  overflow: visible;
}
@media (max-width: 720px) {
  .chart-axis-label { font-size: 11px; }
}


/* Audit pass 2 : robustesse de mise en page */
.card h2,
.card-head h2 {
  overflow-wrap: anywhere;
}
#balanceChart,
#projectionChart {
  min-width: 0;
  overflow: hidden;
}
#balanceChart svg,
#projectionChart svg {
  display: block;
  max-width: 100%;
}
.top-actions {
  flex-wrap: wrap;
}
@media (max-width: 760px) {
  .top-actions select,
  .top-actions button {
    max-width: 100%;
  }
}


/* Budget par catégorie / remboursement du découvert */
.category-cap-card { margin: 16px 0; }
.debt-plan,
.category-cap-footer {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 12px;
  margin: 14px 0;
}
.debt-plan span,
.category-cap-footer span {
  padding: 12px;
  border-radius: 14px;
  background: #f7f5ef;
}
.debt-plan small,
.debt-plan strong,
.category-cap-footer small,
.category-cap-footer strong {
  display: block;
}
.category-caps-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}
.category-cap-row {
  border: 1px solid #e4e0d7;
  border-radius: 14px;
  padding: 12px;
}
.category-cap-title,
.category-cap-values {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.category-cap-title small {
  font-weight: 700;
  color: #66736d;
}
.category-cap-values {
  margin: 10px 0;
  flex-wrap: wrap;
}
.category-cap-values label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.category-cap-input {
  width: 92px;
  padding: 7px 9px;
  border: 1px solid #cfd6d1;
  border-radius: 9px;
  font: inherit;
  text-align: right;
}
.cap-progress {
  height: 8px;
  border-radius: 999px;
  background: #ece9e1;
  overflow: hidden;
}
.cap-progress i {
  display: block;
  height: 100%;
  background: #0a3b2d;
  border-radius: inherit;
}
@media (max-width: 720px) {
  .debt-plan,
  .category-cap-footer {
    grid-template-columns: 1fr;
  }
  .category-cap-values {
    align-items: flex-start;
    flex-direction: column;
  }
}


/* Projection budget */
.budget-projection-card { margin: 16px 0; }
.projection-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.projection-metrics span {
  padding: 14px;
  border-radius: 14px;
  background: #f7f5ef;
}
.projection-metrics small,
.projection-metrics strong {
  display: block;
}
.projection-metrics strong {
  margin-top: 5px;
  font-size: 1.25rem;
}
.budget-projection-message {
  margin: 14px 0 0;
  line-height: 1.5;
}
@media (max-width: 720px) {
  .projection-metrics { grid-template-columns: 1fr; }
}


/* Prévisions mensuelles par catégorie */
.future-category-forecast { margin: 16px 0; }
.forecast-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 12px;
  margin: 14px 0;
}
.forecast-summary span {
  padding: 12px;
  background: #f7f5ef;
  border-radius: 14px;
}
.forecast-summary small,
.forecast-summary strong { display: block; }
.forecast-table-wrap {
  overflow-x: auto;
  border: 1px solid #e4e0d7;
  border-radius: 14px;
}
.forecast-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}
.forecast-table th,
.forecast-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #ece8df;
  text-align: right;
  white-space: nowrap;
}
.forecast-table th:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 2;
}
.forecast-table thead th {
  background: #f7f5ef;
  font-weight: 800;
}
.forecast-month-alert {
  background: #fff0ee !important;
}
.forecast-category-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.forecast-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.forecast-dot.essential { background: #0a3b2d; }
.forecast-dot.adjustable { background: #a8a47b; }
.forecast-dot.alert { background: #b64236; }
.forecast-total-row th,
.forecast-total-row td {
  font-weight: 800;
  border-top: 2px solid #cfc9bb;
}
.forecast-balance-row th,
.forecast-balance-row td {
  font-weight: 800;
}
.forecast-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
  font-size: .9rem;
}
.forecast-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
@media (max-width: 720px) {
  .forecast-summary { grid-template-columns: 1fr; }
}


/* Dépenses fixes mensuelles */
.recurring-fixed-card { margin: 16px 0; }
.recurring-fixed-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}
.recurring-fixed-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #ece8df;
}
.recurring-fixed-row span strong,
.recurring-fixed-row span small {
  display: block;
}
.recurring-fixed-row span small {
  color: #6c7671;
  margin-top: 2px;
}
.recurring-fixed-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}
.recurring-fixed-row input {
  width: 104px;
  padding: 8px 10px;
  border: 1px solid #cfd6d1;
  border-radius: 9px;
  text-align: right;
  font: inherit;
}
.recurring-fixed-total {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-top: 14px;
  padding: 14px;
  border-radius: 14px;
  background: #f7f5ef;
}
.recurring-fixed-total strong {
  font-size: 1.2rem;
}
@media (max-width: 620px) {
  .recurring-fixed-row {
    align-items: flex-start;
    flex-direction: column;
  }
}


/* Charges logement fixes : non modifiables */
.recurring-fixed-row input:disabled {
  background: #f1efe9;
  color: #4f5a55;
  cursor: not-allowed;
  opacity: 1;
  font-weight: 700;
}


.annual-expense-card { margin: 16px 0; }
.annual-expense-row {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 14px;
  border-radius: 14px;
  background: #f7f5ef;
}
.annual-expense-row > span:last-child { text-align: right; }
.annual-expense-row strong,
.annual-expense-row small { display: block; }
@media (max-width: 620px) {
  .annual-expense-row { flex-direction: column; }
  .annual-expense-row > span:last-child { text-align: left; }
}


/* Correctif superposition contenu principal / colonne recommandations */
.content-grid {
  align-items: start;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
}
.content-grid > .main-stack,
.content-grid > .right-rail {
  min-width: 0;
  max-width: 100%;
}
.main-stack {
  min-width: 0;
  overflow: hidden;
}
.right-rail {
  min-width: 0;
  width: 100%;
  align-self: start;
  position: relative;
  z-index: 1;
}
.recommendations {
  width: 100%;
  max-width: 100%;
  position: sticky;
  top: 24px;
}
.recurring-fixed-card,
.future-category-forecast,
.category-cap-card,
.budget-projection-card,
.chart-card,
.compact-insight {
  width: 100%;
  max-width: 100%;
}
.recurring-fixed-row {
  grid-template-columns: 1fr auto;
}
.recurring-fixed-row label {
  justify-self: end;
  white-space: nowrap;
}
@media (max-width: 1400px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
  .recommendations {
    position: static;
  }
  #recommendationsList {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 720px) {
  #recommendationsList {
    grid-template-columns: 1fr;
  }
}


/* Historique mensuel du total des comptes */
.monthly-total-history {
  margin: 0;
}
.monthly-total-history .line-chart {
  min-height: 280px;
}
.monthly-total-history svg {
  width: 100%;
  height: 280px;
  display: block;
  overflow: visible;
}
.monthly-history-path {
  fill: none;
  stroke: var(--green-800);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.monthly-zero-line {
  stroke: #b9c0bc;
  stroke-width: 1.5;
  stroke-dasharray: 6 5;
}
.monthly-history-points circle {
  fill: var(--green-800);
  stroke: white;
  stroke-width: 2;
}
.monthly-history-labels text,
.monthly-value-label {
  fill: #31443e;
  font-size: 12px;
  font-weight: 700;
}
.monthly-value-label.negative-label {
  fill: var(--danger);
}
.monthly-history-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.monthly-history-stats span {
  padding: 12px;
  border-radius: 12px;
  background: #f7f5ef;
}
.monthly-history-stats small,
.monthly-history-stats strong {
  display: block;
}
.monthly-history-stats strong {
  margin-top: 4px;
}
@media (max-width: 720px) {
  .monthly-history-stats {
    grid-template-columns: 1fr;
  }
}


/* Lisibilité renforcée des dépenses fixes mensuelles */
.recurring-fixed-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  align-items: center;
  gap: 18px;
}
.recurring-fixed-row label {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-weight: 800;
}
.recurring-fixed-row input {
  width: 118px;
  min-width: 118px;
  background: #ffffff;
  color: #101917;
  border-color: #c9cfc9;
  font-weight: 800;
  opacity: 1;
}
.recurring-fixed-row input:disabled {
  background: #f4f1e9;
  color: #263b34;
  border-color: #d7d2c7;
}
.recurring-fixed-total {
  font-size: 1rem;
}
.recurring-fixed-total strong {
  color: var(--green-900);
  font-size: 1.3rem;
}
@media (max-width: 620px) {
  .recurring-fixed-row {
    grid-template-columns: 1fr;
  }
  .recurring-fixed-row label {
    justify-content: flex-start;
  }
}


/* Mise en page desktop plus large */
@media (min-width: 1401px) {
  .page {
    width: calc(100% - 250px);
    max-width: none;
    margin-left: 250px;
    padding-right: 34px;
  }
  .dashboard {
    width: 100%;
  }
  .content-grid {
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
  }
}


.forecast-balance-row th,
.forecast-balance-row td {
  background: #f7f5ef;
  font-weight: 900;
}
.forecast-variation-row th,
.forecast-variation-row td {
  font-weight: 800;
}


/* v5.9 - montants fixes explicitement visibles */
.recurring-fixed-visible-amount {
  display: inline-block;
  min-width: 92px;
  text-align: right;
  color: #0f3f31 !important;
  font-weight: 900;
  font-size: 1rem;
}
.recurring-fixed-row label {
  display: grid !important;
  grid-template-columns: 92px 118px !important;
  align-items: center !important;
  justify-content: end !important;
  gap: 10px !important;
}
#liveBuildBadge {
  box-shadow: 0 6px 18px rgba(15,63,49,.18);
}
