/* Essor — design « grand livre » (éditorial clair).
   Papier froid + encre navy + accent émeraude (revenu) + brique (churn).
   Gros chiffres en serif (figures oldstyle = caractère ledger), données en sans
   à chiffres tabulaires (alignement). Look assumé clair, une seule direction. */

/* Polices auto-hébergées (mêmes que le site perso de MatgordFR → cohérence de marque) */
@font-face { font-family: "Fraunces"; src: url("../fonts/fraunces.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "Space Grotesk"; src: url("../fonts/space-grotesk.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }

:root {
  --paper:      #F1F3F5;   /* fond, froid (pas cream) */
  --surface:    #FFFFFF;
  --surface-2:  #FAFBFC;
  --ink:        #16202E;   /* texte principal */
  --ink-soft:   #47535F;
  --muted:      #5F6B78;
  --hair:       #E4E7EB;   /* filets */
  --hair-2:     #EEF0F3;
  --accent:     #0F7D63;   /* émeraude — revenu / marque */
  --accent-ink: #0A5C49;
  --accent-wash:#E7F2EE;
  --up:         #1C7C53;
  --down:       #B23A32;   /* brique — churn */
  --down-wash:  #F7E9E7;
  --gold:       #B9892B;

  --font-ui: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  --r: 10px;
  --shadow: 0 1px 2px rgba(22,32,46,.04), 0 8px 24px rgba(22,32,46,.05);
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--paper);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.num { font-variant-numeric: lining-nums tabular-nums; }
.eyebrow {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 13px;
  color: var(--accent-ink);
  letter-spacing: .01em;
}
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--hair);
  display: flex; flex-direction: column;
  padding: 22px 16px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: baseline; gap: 8px; padding: 4px 8px 22px; }
.brand-mark {
  font-family: var(--font-display); font-weight: 700; font-size: 22px;
  color: var(--ink); letter-spacing: -.01em;
}
.brand-tag { font-family: var(--font-display); font-style: italic; font-size: 13px; color: var(--accent-ink); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--ink-soft); text-decoration: none;
  font-size: 14.5px; cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
  font-family: var(--font-ui);
}
.nav-item:hover { background: var(--hair-2); color: var(--ink); }
.nav-item.is-active { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.nav-item .ic { width: 8px; height: 8px; border-radius: 2px; background: currentColor; opacity: .55; flex: none; }
.nav-item.is-active .ic { opacity: 1; }

.account {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: 12px 8px 2px; border-top: 1px solid var(--hair);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-ink));
}
.account b { font-size: 14px; }
.account small { display: block; color: var(--muted); font-size: 12px; }

/* ---------- Main / topbar ---------- */
.main { padding: 26px 40px 60px; max-width: 1760px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 26px; }
.topbar h1 { font-family: var(--font-display); font-size: 30px; letter-spacing: -.01em; margin-top: 2px; }
.topbar .sub { color: var(--muted); font-size: 14px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.badge-demo {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600; color: var(--gold);
  border: 1px solid #E6D6A8; background: #FCF7E8; padding: 6px 11px; border-radius: 999px;
}
.badge-demo::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); }

.search { position: relative; }
.search input {
  font-family: var(--font-ui); font-size: 14px; color: var(--ink);
  border: 1px solid var(--hair); background: var(--surface); border-radius: 8px;
  padding: 8px 12px 8px 30px; width: 190px; outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.search::before { content: "⌕"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 15px; }

.segmented { display: inline-flex; border: 1px solid var(--hair); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button {
  font-family: var(--font-ui); font-size: 13px; color: var(--ink-soft);
  border: 0; background: none; padding: 7px 12px; cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--hair); }
.segmented button.is-active { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }

.btn {
  font-family: var(--font-ui); font-size: 13.5px; color: var(--ink);
  border: 1px solid var(--hair); background: var(--surface); border-radius: 8px;
  padding: 7px 13px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }

/* ---------- Views ---------- */
.view { display: none; }
.view.is-active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r); box-shadow: var(--shadow); }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-family: var(--font-display); font-size: 18px; }
.card-head .sub { color: var(--muted); font-size: 13px; }

.grid-kpi { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r); padding: 18px 20px; box-shadow: var(--shadow); }
.kpi .kpi-label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.kpi .kpi-val { font-family: var(--font-display); font-size: 34px; line-height: 1; letter-spacing: -.015em; }
.kpi .kpi-delta { margin-top: 11px; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.delta-up { color: var(--up); }
.delta-down { color: var(--down); }
.delta-up::before { content: "▲"; font-size: 9px; }
.delta-down::before { content: "▼"; font-size: 9px; }
.kpi.accent { position: relative; }
.kpi.accent::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 3px; background: var(--accent); }

.grid-2 { display: grid; grid-template-columns: 1.7fr 1fr; gap: 16px; }
.grid-2.rev { grid-template-columns: 1fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Charts ---------- */
.chart-wrap { height: 210px; position: relative; }
.chart { width: 100%; height: 100%; display: block; }
.chart-grid { stroke: var(--hair-2); stroke-width: 1; }
.chart-area-fill { fill: var(--accent-wash); animation: fadeIn .7s ease both; }
.chart-area-line { fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1500; stroke-dashoffset: 1500; animation: draw 1.2s cubic-bezier(.4,0,.2,1) forwards; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.bar-new { fill: var(--accent); }
.bar-churn { fill: var(--down); opacity: .85; }
.axis { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 11.5px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.dot.acc { background: var(--accent); } .dot.dn { background: var(--down); }

.spark { width: 150px; height: 38px; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 600; stroke-dashoffset: 600; animation: draw 1s ease .1s forwards; }

/* ---------- Lists / bars ---------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--hair-2);
  cursor: pointer;
}
.list .row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); }
.chip { width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; }
.row .who { flex: 1; min-width: 0; }
.row .who b { font-size: 14px; }
.row .who small { display: block; color: var(--muted); font-size: 12px; }
.row .amt { font-family: var(--font-display); font-size: 16px; }

.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-line { display: grid; grid-template-columns: 70px 1fr auto; align-items: center; gap: 12px; }
.bar-track { height: 10px; background: var(--hair-2); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; min-width: 6px; width: 0; background: linear-gradient(90deg, var(--accent-ink), var(--accent)); border-radius: 999px; transition: width .9s cubic-bezier(.22,1,.36,1); }
.bar-line .val { font-family: var(--font-display); font-size: 15px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--hair-2); white-space: nowrap; }
table.data th {
  color: var(--muted); font-weight: 600; font-size: 12.5px; cursor: pointer; user-select: none;
  position: sticky; top: 0; background: var(--surface);
}
table.data th.sortable:hover { color: var(--ink); }
table.data th .arrow { opacity: .4; font-size: 10px; }
table.data th.sorted .arrow { opacity: 1; color: var(--accent-ink); }
table.data td.right, table.data th.right { text-align: right; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-2); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
.status.actif { color: var(--up); } .status.résilié { color: var(--muted); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tag-offer { font-size: 12px; color: var(--ink-soft); border: 1px solid var(--hair); border-radius: 6px; padding: 2px 8px; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.col { background: var(--surface-2); border: 1px solid var(--hair); border-radius: var(--r); padding: 12px; }
.col-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; padding: 2px 4px; }
.col-head b { font-size: 13px; }
.col-head .count { font-size: 12px; color: var(--muted); background: var(--hair-2); border-radius: 999px; padding: 1px 8px; }
.deal { background: var(--surface); border: 1px solid var(--hair); border-radius: 8px; padding: 11px; margin-bottom: 10px; }
.deal:last-child { margin-bottom: 0; }
.deal .dh { display: flex; align-items: center; gap: 9px; margin-bottom: 7px; }
.deal .dh b { font-size: 13.5px; }
.deal .dv { font-family: var(--font-display); font-size: 17px; }
.deal small { color: var(--muted); font-size: 12px; }

/* ---------- Feed ---------- */
.feed { display: flex; flex-direction: column; }
.feed .ev { display: flex; gap: 11px; padding: 11px 0; border-top: 1px solid var(--hair-2); }
.feed .ev:first-child { border-top: 0; }
.feed .kind { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex: none; }
.kind.won, .kind.new, .kind.upsell { background: var(--accent); }
.kind.churn { background: var(--down); }
.feed .ev b { font-size: 13.5px; } .feed .ev small { display: block; color: var(--muted); font-size: 12px; }

/* ---------- Slide-over : fiche client ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(22,32,46,.32); opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s; z-index: 40; }
.backdrop.open { opacity: 1; visibility: visible; }
.panel {
  position: fixed; top: 0; right: 0; height: 100vh; width: 380px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--hair); box-shadow: -12px 0 40px rgba(22,32,46,.12);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.4,0,.2,1); z-index: 41;
  display: flex; flex-direction: column; padding: 24px 24px 28px; overflow-y: auto;
}
.panel.open { transform: none; }
.panel .px-close { position: absolute; top: 16px; right: 16px; border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; }
.panel .px-close:hover { color: var(--ink); }
.panel .px-head { display: flex; align-items: center; gap: 13px; margin-bottom: 18px; }
.panel .px-head .chip { width: 44px; height: 44px; border-radius: 11px; font-size: 16px; }
.panel .px-head h3 { font-family: var(--font-display); font-size: 20px; }
.panel .px-mrr { font-family: var(--font-display); font-size: 40px; line-height: 1; margin: 6px 0 2px; }
.px-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0; }
.px-cell { border: 1px solid var(--hair); border-radius: 8px; padding: 11px 13px; }
.px-cell small { color: var(--muted); font-size: 12px; display: block; margin-bottom: 3px; }
.px-cell b { font-size: 15px; }
.px-note { background: var(--surface-2); border: 1px solid var(--hair-2); border-radius: 8px; padding: 12px 14px; font-size: 13.5px; color: var(--ink-soft); }
.px-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin: 16px 0 8px; }

/* ---------- Divers ---------- */
.footer { margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--hair); color: var(--muted); font-size: 13px; }
.footer b { color: var(--ink-soft); }
.hint { color: var(--muted); font-size: 12.5px; }

.menu-btn { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .grid-kpi { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2.rev { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 45; width: 240px; height: 100vh;
    transform: translateX(-100%); transition: transform .26s ease;
  }
  .sidebar.open { transform: none; }
  .main { padding: 18px 18px 50px; }
  .menu-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--hair); background: var(--surface); border-radius: 9px; cursor: pointer; }
  .topbar { flex-direction: column; }
  .topbar-right { justify-content: flex-start; }
  .search input { width: 100%; }
}
@media (max-width: 520px) {
  .grid-kpi { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: 1fr; }
}

/* ===================== Animations ===================== */
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes grow { from { transform: scaleY(0); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.bar-new, .bar-churn, .wf-up, .wf-down, .wf-total { transform-box: fill-box; transform-origin: bottom; animation: grow .7s cubic-bezier(.22,1,.36,1) both; }
.kpi, .metric { animation: rise .5s ease both; }
.grid-kpi > :nth-child(2), .metrics > :nth-child(2) { animation-delay: .05s; }
.grid-kpi > :nth-child(3), .metrics > :nth-child(3) { animation-delay: .10s; }
.grid-kpi > :nth-child(4), .metrics > :nth-child(4) { animation-delay: .15s; }

/* Transitions de thème */
body, .sidebar, .card, .kpi, .metric, .col, .deal, .panel, table.data th, .search input,
.segmented, .segmented button, .btn, .nav-item, .theme-btn, .bar-track {
  transition: background-color .3s ease, color .3s ease, border-color .3s ease;
}

/* ===================== Waterfall MRR ===================== */
.wf-total { fill: var(--ink-soft); }
.wf-up { fill: var(--accent); }
.wf-down { fill: var(--down); }
.wf-conn { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; opacity: .55; }
.wf-cap { fill: var(--muted); font-size: 11px; font-family: var(--font-ui); }
.wf-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-soft); margin-top: 10px; }

/* ===================== Métriques SaaS ===================== */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.metric { border: 1px solid var(--hair); border-radius: 10px; padding: 14px 16px; background: var(--surface-2); }
.metric .m-label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 7px; }
.metric .m-val { font-family: var(--font-display); font-size: 26px; margin-top: 6px; letter-spacing: -.01em; }
.metric .m-hint { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.badge-good { font-size: 10.5px; font-weight: 700; color: var(--up); background: var(--accent-wash); border-radius: 999px; padding: 1px 7px; }

/* ===================== Tooltip graphe ===================== */
.tip { position: absolute; top: 2px; transform: translateX(-50%); pointer-events: none; opacity: 0; transition: opacity .12s; z-index: 3;
  background: var(--ink); color: var(--surface); font-size: 12px; padding: 6px 9px; border-radius: 7px; white-space: nowrap; box-shadow: var(--shadow); }
.tip b { font-family: var(--font-display); }
.tip.show { opacity: 1; }
.guide { position: absolute; top: 6px; bottom: 24px; width: 1px; background: var(--accent); opacity: 0; pointer-events: none; z-index: 2; }
.guide.show { opacity: .45; }

/* ===================== Bouton thème ===================== */
.theme-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border: 1px solid var(--hair); background: var(--surface); border-radius: 9px; cursor: pointer; font-size: 16px; color: var(--ink-soft); }
.theme-btn:hover { border-color: var(--muted); color: var(--ink); }

/* ===================== THÈME SOMBRE ===================== */
:root[data-theme="dark"] {
  --paper: #0E141C; --surface: #161D28; --surface-2: #121A24; --ink: #E8ECF1; --ink-soft: #AEB8C4;
  --muted: #808C9A; --hair: #26313F; --hair-2: #1E2732;
  --accent: #2FA37F; --accent-ink: #46BE97; --accent-wash: #16271F;
  --up: #46BE97; --down: #E0705F; --down-wash: #2A1A18; --gold: #D8B25A;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.4);
}
:root[data-theme="dark"] .badge-demo { background: #241E10; border-color: #48401F; }
:root[data-theme="dark"] .avatar { color: #08120D; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
