:root {
  --bg:        #F3F4EE;
  --panel:     #FFFFFF;
  --ink:       #1F2A24;
  --ink-soft:  #5B655E;
  --line:      #DDE1D8;
  --accent:    #2F5D50;   /* vert botanique profond */
  --accent-2:  #C98A4B;   /* ambre / cuivre */
  --accent-2-soft: #F3E3D2;
  --ok:        #2F7A4F;
  --ko:        #B24A3A;
  --radius:    10px;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

h1, h2 { font-family: "Iowan Old Style", "Georgia", serif; font-weight: 600; }

/* --- Topbar --- */
/* --- Barre de progression globale (visible pendant tout chargement) --- */
#progress-bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--accent-2); z-index: 999; opacity: 0;
}
#progress-bar.active {
  opacity: 1;
  animation: progress-sweep 1.1s ease-in-out infinite;
}
@keyframes progress-sweep {
  0%   { width: 0%;  left: 0%; }
  50%  { width: 55%; left: 20%; }
  100% { width: 0%;  left: 100%; }
}

/* --- État "en cours de calcul" dans un tableau ou une grille --- */
.loading-row td {
  text-align: center; padding: 28px 12px !important; color: var(--ink-soft);
  font-size: .88rem;
}
.spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 8px;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; vertical-align: middle;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
button.apply:disabled, button.export:disabled {
  opacity: .55; cursor: not-allowed;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--accent);
  color: #fff;
}
.brand { font-family: "Iowan Old Style", Georgia, serif; font-size: 1.3rem; letter-spacing: .02em; }
.brand span { font-family: inherit; font-size: .85rem; opacity: .75; font-weight: 400; }
.topbar-right { display: flex; align-items: center; gap: 16px; font-size: .82rem; }
.import-badge { padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.15); }
.import-badge.ko { background: var(--ko); }
.role-badge { padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.15); font-weight: 600; }
.role-badge.role-utilisateur { background: rgba(255,255,255,.28); }

/* Ceinture-et-bretelles : le bouton export est déjà omis côté serveur (PHP)
   pour un compte 'utilisateur', mais on le masque aussi ici si jamais du
   contenu HTML mis en cache ne l'a pas retiré. */
body[data-role="utilisateur"] .export { display: none !important; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .68rem; font-weight: 700; letter-spacing: .02em; margin-right: 4px; white-space: nowrap; }
.badge-vip { background: #2F5D50; color: #fff; }
.badge-fidele { background: var(--accent-2-soft); color: #8a5a20; }
.badge-reactiver { background: #F5DEDA; color: #8a2f20; }
.logout { color: #fff; text-decoration: none; opacity: .85; border-bottom: 1px solid rgba(255,255,255,.4); }
.logout:hover { opacity: 1; }

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 18px 28px 0;
}
.tab-btn {
  border: none;
  background: transparent;
  padding: 10px 18px;
  font-size: .95rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: var(--radius) var(--radius) 0 0;
}
.tab-btn.active {
  background: var(--panel);
  color: var(--accent);
  box-shadow: 0 -1px 0 var(--line) inset;
}

main { padding: 0 28px 40px; }

.tab-panel { display: none; background: var(--panel); border-radius: 0 var(--radius) var(--radius) var(--radius); padding: 20px 24px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.tab-panel.active { display: block; }

/* --- Filters --- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.filters input[type=text], .filters input[type=date], .filters select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: .88rem;
  background: #fff;
  color: var(--ink);
}
.filters label { font-size: .8rem; color: var(--ink-soft); display: flex; gap: 6px; align-items: center; }
.filters input[type=text] { min-width: 240px; flex: 1 1 240px; }
.filters .date-row { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
button.apply {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: .88rem;
}
button.apply:hover { background: #24493f; }
button.export {
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: .88rem;
}
button.export:hover { background: var(--accent-2-soft); }

/* --- KPIs --- */
.kpis { display: flex; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.kpi {
  background: var(--accent-2-soft);
  border-radius: var(--radius);
  padding: 12px 18px;
  min-width: 150px;
}
.kpi .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.kpi .kpi-period { text-transform: none; letter-spacing: 0; font-weight: 400; }
.kpi .value { font-size: 1.4rem; font-weight: 700; color: var(--accent); }

/* --- Table --- */
.table-wrap { overflow-x: auto; max-height: 62vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .87rem; }
thead th {
  position: sticky; top: 0;
  background: var(--accent);
  color: #fff;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
thead th.num { text-align: right; }
thead th:hover { background: #24493f; }
tbody td { padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #F7F6F1; cursor: pointer; }
tbody tr:nth-child(even) { background: #FBFBF8; }

/* --- Overlay détail client --- */
.overlay { position: fixed; inset: 0; background: rgba(20,25,20,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.overlay.hidden { display: none; }
.overlay-card { background: #fff; border-radius: var(--radius); padding: 24px; width: min(900px, 92vw); max-height: 82vh; overflow: auto; position: relative; }
.overlay-close { position: absolute; top: 14px; right: 18px; border: none; background: none; font-size: 1.4rem; cursor: pointer; color: var(--ink-soft); }

/* --- Login --- */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { background: var(--panel); padding: 36px 40px; border-radius: var(--radius); box-shadow: 0 4px 24px rgba(0,0,0,.08); text-align: center; width: 320px; }
.login-card h1 { margin: 0 0 4px; color: var(--accent); }
.login-card .subtitle { color: var(--ink-soft); font-size: .85rem; margin-bottom: 20px; }
.login-card input { width: 100%; padding: 10px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 6px; }
.login-card button { width: 100%; padding: 10px; background: var(--accent); color: #fff; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; }
.login-card .error { color: var(--ko); font-size: .85rem; }

@media (max-width: 720px) {
  main, .topbar, .tabs { padding-left: 14px; padding-right: 14px; }
  .filters input[type=text] { min-width: 100%; }
}

.analyses-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.analyses-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; overflow: hidden; }
.analyses-card h3 { margin: 0 0 4px; font-size: .95rem; color: var(--accent); }
.analyses-card .sub { font-size: .74rem; color: var(--ink-soft); margin-bottom: 8px; }
.analyses-card table { width: 100%; font-size: .78rem; border-collapse: collapse; table-layout: fixed; }
.analyses-card td, .analyses-card th {
  padding: 4px 6px; border-bottom: 1px solid var(--line);
  white-space: normal; word-break: break-word; overflow-wrap: break-word;
}
.analyses-card th {
  text-align: left; color: var(--ink-soft); font-weight: 600;
  background: transparent; position: static; cursor: default;
  border-bottom: 2px solid var(--line);
}
.analyses-card th:hover { background: transparent; }
.analyses-card td.num, .analyses-card th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.analyses-card td:first-child, .analyses-card th:first-child { width: 40%; }
