: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;
}
