
  :root{
    --ink:#0E1116;
    --panel:#141920;
    --panel-2:#181F28;
    --ivory:#E9E6DC;
    --muted:#8B92A0;
    --muted-2:#5C6470;
    --hairline:#262D38;
    --gain:#4FAE9E;
    --loss:#BD6A50;
    --focus:#E9E6DC;
  }
  *{box-sizing:border-box; margin:0; padding:0;}
  html,body{height:100%;}
  body{
    background:var(--ink);
    color:var(--ivory);
    font-family:'IBM Plex Sans', sans-serif;
    font-size:14px;
    -webkit-font-smoothing:antialiased;
  }
  a{color:inherit; text-decoration:none;}
  ::selection{background:var(--gain); color:var(--ink);}

  .num{ font-family:'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }

  /* ---------- layout ---------- */
  .app{
    display:flex;
    flex-direction:column;
    height:100vh;
  }

  /* ---------- nav horizontale ---------- */
  .topnav{
    height:56px;
    background:var(--panel);
    border-bottom:1px solid var(--hairline);
    display:flex;
    align-items:center;
    gap:32px;
    padding:0 32px;
  }
  .topnav-brand{ flex:none; display:flex; align-items:center; }
  .brand-logo{ display:block; height:32px; width:auto; }
  .logo-light{ display:none; }
  [data-theme="light"] .logo-dark{ display:none; }
  [data-theme="light"] .logo-light{ display:block; }

  .topnav-menu{
    display:flex;
    align-items:center;
    gap:4px;
    flex:1;
    overflow-x:auto;
  }
  .topnav-item{
    padding:8px 14px;
    font-size:13.5px;
    color:var(--muted);
    border-bottom:2px solid transparent;
    white-space:nowrap;
    transition:color .15s ease, border-color .15s ease;
  }
  .topnav-item:hover{ color:var(--ivory); }
  .topnav-item.active{ color:var(--ivory); border-bottom-color:var(--gain); }

  .topnav-right{ flex:none; display:flex; align-items:center; gap:16px; }
  .user-menu{ display:flex; align-items:center; gap:10px; }
  .user-deconnexion{ font-size:11.5px; color:var(--muted); }
  .user-deconnexion:hover{ color:var(--ivory); }
  .user-avatar{
    width:28px; height:28px; border-radius:2px;
    display:flex; align-items:center; justify-content:center;
    font-family:'IBM Plex Mono', monospace;
    font-size:11px; color:var(--muted);
    flex:none;
    padding:0; cursor:pointer; overflow:hidden;
    background:transparent; border:none; box-shadow:none;
    appearance:none; -webkit-appearance:none;
  }
  .user-avatar-img{ width:100%; height:100%; object-fit:cover; display:block; }
  .user-avatar-grand{ width:64px; height:64px; font-size:20px; }

  /* ---------- modale "Mon compte" ---------- */
  .modale-fond{
    display:none; position:fixed; inset:0; background:rgba(0,0,0,0.55);
    align-items:center; justify-content:center; z-index:1000; padding:24px;
  }
  .modale-fond.ouverte{ display:flex; }
  .modale-boite{
    width:100%; max-width:380px; background:var(--panel);
    border:1px solid var(--hairline); padding:28px;
  }
  .modale-titre{ font-family:'Newsreader', serif; font-size:18px; margin-bottom:20px; }
  .modale-avatar-actuel{ display:flex; justify-content:center; margin-bottom:20px; }
  .modale-aide{ font-size:11px; color:var(--muted-2); margin-top:4px; }
  .modale-actions{ display:flex; gap:12px; margin-top:8px; }

  /* ---------- formulaires & boutons communs (utilisés par la modale + les pages d'admin) ---------- */
  .form-field{ display:flex; flex-direction:column; gap:6px; margin-bottom:16px; }
  .form-field label{ font-size:11px; color:var(--muted-2); }
  .form-field input, .form-field select{
    background:var(--panel-2); border:1px solid var(--hairline); color:var(--ivory);
    padding:8px 10px; font-size:13px; border-radius:2px; font-family:inherit;
  }
  .form-field input:disabled{ color:var(--muted); }
  .btn{
    background:var(--gain); color:var(--ink); border:none; padding:9px 18px;
    font-size:13px; font-weight:500; border-radius:2px; cursor:pointer;
  }
  .btn-ghost{
    background:transparent; color:var(--muted); border:1px solid var(--hairline);
    padding:8px 14px; font-size:13px; border-radius:2px; cursor:pointer;
  }
  .form-error{ color:var(--loss); font-size:12.5px; }

  /* ---------- main ---------- */
  .main{ display:flex; flex-direction:column; min-width:0; flex:1; overflow-y:auto; }

  .topbar{
    height:64px;
    border-bottom:1px solid var(--hairline);
    display:flex;
    align-items:center;
    justify-content:space-between;
    padding:0 32px;
  }
  .topbar-left{ display:flex; align-items:center; gap:18px; }
  .topbar-icon{ height:20px; width:auto; }
  .breadcrumb{ color:var(--muted); font-size:12.5px; }
  .breadcrumb a{ color:var(--muted); }
  .breadcrumb a:hover{ color:var(--ivory); text-decoration:underline; }
  .breadcrumb b{ color:var(--ivory); font-weight:500; }
  .search{
    display:flex; align-items:center; gap:8px;
    color:var(--muted-2);
    border:1px solid var(--hairline);
    border-radius:2px;
    padding:7px 12px;
    font-size:12.5px;
    width:260px;
  }
  .search kbd{
    margin-left:auto;
    font-family:'IBM Plex Mono', monospace;
    font-size:10px;
    color:var(--muted-2);
    border:1px solid var(--hairline);
    padding:1px 5px;
    border-radius:2px;
  }
  .topbar-right{ display:flex; align-items:center; gap:20px; }
  .as-of{ font-size:11.5px; color:var(--muted-2); font-family:'IBM Plex Mono', monospace; }

  .content{ padding:16px 32px 60px; flex:1; min-height:0; }

  .page-head{
    display:flex;
    justify-content:space-between;
    align-items:flex-end;
    margin-bottom:32px;
  }
  .page-title{
    font-family:'Newsreader', serif;
    font-size:30px;
    font-weight:500;
  }
  .page-sub{ color:var(--muted); font-size:13px; margin-top:6px; }
  .period-toggle{
    display:flex; border:1px solid var(--hairline); border-radius:2px; overflow:hidden;
  }
  .period-toggle span{
    padding:7px 14px; font-size:12px; color:var(--muted); cursor:default;
    border-right:1px solid var(--hairline);
  }
  .period-toggle span:last-child{ border-right:none; }
  .period-toggle span.active{ color:var(--ink); background:var(--ivory); }

  /* KPI ledger row */
  .kpi-row{
    display:grid;
    grid-template-columns:repeat(4, 1fr);
    border-top:1px solid var(--hairline);
    border-left:1px solid var(--hairline);
    margin-bottom:40px;
  }
  .kpi{
    padding:20px 24px;
    border-right:1px solid var(--hairline);
    border-bottom:1px solid var(--hairline);
  }
  .kpi-label{ color:var(--muted); font-size:12px; margin-bottom:12px; }
  .kpi-value{ font-size:26px; letter-spacing:-0.3px; }
  .kpi-delta{ font-size:12px; margin-top:8px; }
  .kpi-delta.up{ color:var(--gain); }
  .kpi-delta.down{ color:var(--loss); }

  /* body grid: chart-ish panel + ledger */
  .body-grid{
    display:grid;
    grid-template-columns: 1.4fr 1fr;
    gap:0;
    border-top:1px solid var(--hairline);
    border-left:1px solid var(--hairline);
    margin-bottom:40px;
  }
  .panel{
    border-right:1px solid var(--hairline);
    border-bottom:1px solid var(--hairline);
    padding:24px;
  }
  .panel-head{
    display:flex; justify-content:space-between; align-items:baseline;
    margin-bottom:20px;
  }
  .panel-title{ font-size:14px; font-weight:500; }
  .panel-link{ font-size:12px; color:var(--muted); }

  /* fake area chart via svg */
  .chart-wrap{ position:relative; height:200px; }
  .chart-wrap svg{ width:100%; height:100%; display:block; }
  .chart-axis{
    display:flex; justify-content:space-between;
    margin-top:10px; color:var(--muted-2); font-size:10.5px;
    font-family:'IBM Plex Mono', monospace;
  }

  /* mix list */
  .mix-list{ display:flex; flex-direction:column; gap:16px; }
  .mix-row{ display:flex; align-items:center; gap:12px; }
  .mix-name{ flex:1; font-size:12.5px; color:var(--ivory); }
  .mix-bar-track{ width:120px; height:5px; background:var(--panel-2); border-radius:0; overflow:hidden; }
  .mix-bar-fill{ height:100%; background:var(--gain); }
  .mix-pct{ width:44px; text-align:right; font-size:12px; color:var(--muted); }

  /* transactions ledger table */
  .ledger-panel{
    border-top:1px solid var(--hairline);
    border-left:1px solid var(--hairline);
  }
  table.ledger{ width:100%; border-collapse:collapse; }
  table.ledger thead th{
    text-align:left;
    font-weight:500;
    color:var(--muted-2);
    font-size:11px;
    padding:14px 20px;
    border-bottom:1px solid var(--hairline);
    border-right:1px solid var(--hairline);
  }
  table.ledger thead th:last-child{ border-right:none; text-align:right; }
  table.ledger td{
    padding:14px 20px;
    border-bottom:1px solid var(--hairline);
    border-right:1px solid var(--hairline);
    font-size:13px;
  }
  table.ledger td:last-child{ border-right:none; text-align:right; }
  table.ledger tbody tr:hover{ background:rgba(255,255,255,0.015); }
  .tx-id{ color:var(--muted-2); }
  .tx-status{
    display:inline-block;
    font-size:10.5px;
    padding:2px 7px;
    border:1px solid var(--hairline);
    color:var(--muted);
  }
  .tx-status.settled{ color:var(--gain); border-color:rgba(79,174,158,0.35); }
  .tx-status.pending{ color:#C7A25B; border-color:rgba(199,162,91,0.35); }
  .amt-out{ color:var(--loss); }
  .amt-in{ color:var(--gain); }

  @media (max-width: 980px){
    .topnav{ gap:16px; padding:0 16px; }
    .kpi-row{ grid-template-columns:repeat(2,1fr); }
    .body-grid{ grid-template-columns:1fr; }
  }

/* ---------- opérations journalières ---------- */
.agence-block{ margin-bottom:28px; }
.agence-block + .agence-block{
  border-top:1px solid rgba(140,146,160,0.18);
  padding-top:20px;
}
.agence-head{
  display:flex; align-items:baseline; justify-content:space-between;
  padding:12px 0 10px;
  border-bottom:1px solid var(--hairline);
  margin-bottom:0;
}
.agence-name{ font-size:15px; font-weight:500; }
.agence-ville{ color:var(--muted-2); font-size:12px; margin-left:8px; }
.agence-total{ font-size:13px; color:var(--muted); }

table.marches{ width:100%; border-collapse:collapse; }
table.marches thead th{
  text-align:right;
  font-weight:500;
  color:var(--muted-2);
  font-size:11px;
  padding:10px 20px;
  border-bottom:1px solid var(--hairline);
}
table.marches thead th:first-child{ text-align:left; }
table.marches td{
  padding:11px 20px;
  border-bottom:1px solid var(--hairline);
  font-size:13px;
  text-align:right;
}
table.marches td:first-child{ text-align:left; color:var(--ivory); }
table.marches tbody tr:hover{ background:rgba(255,255,255,0.015); }

.marche-tag{
  display:inline-block;
  font-size:10.5px;
  text-transform:uppercase;
  letter-spacing:0.4px;
  color:#B8BEC9;
  border:1px solid #3A424E;
  padding:1px 7px;
  margin-right:8px;
}
a.marche-tag{ cursor:pointer; }
a.marche-tag:hover{ color:var(--ivory); border-color:var(--ivory); }
:root[data-theme="light"] .marche-tag{ color:#3A3F47; border-color:#C3C7CE; }
:root[data-theme="light"] .marche-tag.total{ color:var(--gain); border-color:var(--gain); }
:root[data-theme="light"] .cumul-panel .marche-tag{ color:var(--gain); border-color:var(--gain); }

.cumul-panel{
  border-top:2px solid var(--ivory);
  margin-top:8px;
}
.cumul-panel table.marches td{ font-weight:500; color:var(--gain); }
.cumul-panel .agence-head{ border-bottom:1px solid var(--hairline); }
.cumul-panel .agence-name{ color:var(--gain); }
.cumul-panel .marche-tag{ color:var(--gain); border-color:var(--gain); }

/* ---------- thème clair ---------- */
:root[data-theme="light"]{
  --ink:#F6F4EF;
  --panel:#FFFFFF;
  --panel-2:#EFEBE3;
  --ivory:#1E2128;
  --muted:#6B7280;
  --muted-2:#9AA0AC;
  --hairline:#DEDACF;
  --gain:#2F8577;
  --loss:#9E4A32;
}
[data-theme="light"] ::selection{ color:#fff; }

/* ---------- sélecteur de thème ---------- */
.theme-toggle{
  display:flex;
  border:1px solid var(--hairline);
  border-radius:2px;
  overflow:hidden;
}
.theme-toggle button{
  background:transparent;
  border:none;
  border-right:1px solid var(--hairline);
  color:var(--muted);
  font-family:inherit;
  font-size:11px;
  padding:6px 10px;
  cursor:pointer;
}
.theme-toggle button:last-child{ border-right:none; }
.theme-toggle button.active{ color:var(--ink); background:var(--gain); }

.ligne-total td{ font-weight:500; color:var(--gain); border-top:1px solid var(--hairline); }
.marche-tag.total{ color:var(--gain); border-color:var(--gain); }

/* ---------- recherche par jour ---------- */
.recherche-jour{ display:flex; gap:10px; align-items:center; }
.recherche-jour input[type="date"]{
  background:var(--panel-2); border:1px solid var(--hairline); color:var(--ivory);
  padding:8px 10px; font-size:13px; border-radius:2px; font-family:inherit;
}
.recherche-jour .btn{
  background:var(--gain); color:var(--ink); border:none; padding:8px 16px;
  font-size:13px; font-weight:500; border-radius:2px; cursor:pointer;
}

/* ---------- accent titres (vert, cohérent avec le reste de l'UI) ---------- */
.page-title,
.panel-title{
  color:var(--gain);
}

/* ---------- opérations journalières : liste défilante + cumul fixe en bas ---------- */
.content-op-jour{
  display:flex;
  flex-direction:column;
  height:100%;
  min-height:0;
  padding-bottom:24px;
}
.content-op-jour .page-head{ flex:none; }
.agences-scroll{
  flex:1;
  overflow-y:auto;
  padding-right:4px;
  margin-right:-4px;
}
.content-op-jour .cumul-panel{
  flex:none;
  background:var(--ink);
  padding-top:14px;
  margin-top:14px;
}

/* ---------- cadre vert des listes (utilisé partout où une liste doit être encadrée) ---------- */
.liste-encadree{
  border:1px solid var(--gain);
  border-radius:2px;
  padding:24px;
}

/* ---------- sélecteur Entité (Agences + Siège) ---------- */
/* passe sur plusieurs lignes si le nombre d'agences le nécessite, Siège toujours en dernier (ordre géré côté PHP) */
.entite-select{
  display:flex;
  flex-wrap:wrap;
  align-items:stretch;
  gap:0;
  border:1px solid var(--hairline);
  border-radius:0;
}
.entite-btn{
  padding:7px 14px;
  font-size:12.5px;
  color:var(--muted);
  border-right:1px solid var(--hairline);
  border-bottom:1px solid var(--hairline);
  transition:color .15s ease, background .15s ease;
}
.entite-btn:last-child{ border-right:none; }
.entite-btn:hover{ color:var(--ivory); background:rgba(255,255,255,0.02); }
.entite-btn.active{
  color:var(--ink);
  background:var(--gain);
}
.entite-btn-siege{ font-weight:500; }

/* ---------- pied de page global ---------- */
.app-footer{
  display:flex;
  flex:none;
  align-items:center;
  justify-content:space-between;
  padding:7px 32px;
  border-top:1px solid var(--hairline);
  font-size:10px;
  color:var(--muted-2);
}
.app-footer a{ color:var(--muted); }
.app-footer a:hover{ color:var(--gain); }
