:root {
  --bg: #eef1f5;
  --bg-2: #e6eaf0;
  --card: #ffffff;
  --card-border: #e2e6ec;
  --accent: #1f3a5f;
  --accent-2: #2d5388;
  --accent-soft: #eaf0f8;
  --good: #1a7f4b;
  --good-soft: #e6f4ec;
  --bad: #b3261e;
  --bad-soft: #fbeae9;
  --warn: #9a6700;
  --warn-soft: #fdf2d6;
  --text: #1f2933;
  --muted: #6b7682;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: #c2c9d4; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #a9b1bf; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; margin-bottom: 28px;
  background: #fff;
  border-bottom: 1px solid var(--card-border);
  box-shadow: 0 1px 0 rgba(16,24,40,.04);
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 600; font-size: 16px; color: var(--accent); }
.brand .logo {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: var(--accent);
  display: grid; place-items: center; font-size: 16px; color: #fff; font-weight: 700;
}
.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-links a, .nav-links button {
  color: var(--muted); background: transparent; border: 1px solid transparent;
  padding: 8px 14px; border-radius: var(--radius-sm); font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
  transition: background .12s, color .12s;
}
.nav-links a:hover, .nav-links button:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.nav-links a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }
.card-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
h1 { font-size: 24px; font-weight: 600; color: var(--text); }
h2 { font-size: 18px; font-weight: 600; margin-bottom: 14px; }
h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg-2); }
.login-card {
  width: 100%; max-width: 390px; padding: 32px;
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.login-card .logo {
  width: 52px; height: 52px; border-radius: var(--radius-sm); margin: 0 auto 16px;
  background: var(--accent);
  display: grid; place-items: center; font-size: 24px; color: #fff; font-weight: 700;
}
.login-card h1 { text-align: center; font-size: 22px; font-weight: 600; }
.login-card p.sub { text-align: center; color: var(--muted); margin: 6px 0 22px; font-size: 14px; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text); margin-bottom: 6px; font-weight: 500; }
.input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: 14px; color: var(--text);
  background: #fff; border: 1px solid #cdd3dc; border-radius: var(--radius-sm);
  outline: none; transition: border-color .12s, box-shadow .12s; font-family: inherit;
}
.input:hover, select:hover { border-color: #b3bcc9; }
.input:focus, select:focus, textarea:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(45,83,136,.15); }
.input::placeholder { color: #98a1ad; }
select option { background: #fff; color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  transition: background .12s, border-color .12s, color .12s;
  background: var(--accent); color: #fff;
}
.btn:hover { background: var(--accent-2); text-decoration: none; }
.btn:active { background: var(--accent); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #fff; border-color: #cdd3dc; color: var(--text); }
.btn.secondary:hover { background: var(--bg); border-color: #b3bcc9; }
.btn.ghost { background: transparent; border-color: #cdd3dc; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--bg); }
.btn.danger { background: var(--bad); }
.btn.danger:hover { background: #962019; }
.btn.block { width: 100%; }

/* Dropzone */
.dropzone {
  border: 2px dashed #c2c9d4; border-radius: var(--radius); padding: 40px 20px;
  text-align: center; cursor: pointer; transition: border-color .15s, background .15s;
  background: #fafbfc;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent-2); background: var(--accent-soft); }
.dropzone .ico { font-size: 36px; margin-bottom: 8px; }
.dropzone .t { font-weight: 600; color: var(--text); }
.dropzone .s { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* Steps */
.steps { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.step {
  flex: 1; min-width: 150px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: #fff; border: 1px solid var(--card-border); display: flex; align-items: center; gap: 10px;
}
.step .n {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--bg); color: var(--muted);
}
.step.active .n { background: var(--accent); color: #fff; }
.step.active { border-color: var(--accent-2); background: var(--accent-soft); }
.step .label { font-size: 13px; color: var(--muted); }
.step.active .label { color: var(--text); font-weight: 500; }

/* Mapping */
.mapping-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.mapping-grid .full { grid-column: 1 / -1; }
.comp-row {
  display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 10px; align-items: end;
  padding: 12px; border: 1px solid var(--card-border); border-radius: var(--radius-sm); background: #fafbfc;
  margin-bottom: 10px;
}
.comp-row .comp-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.comp-badge { width: 22px; height: 22px; border-radius: 5px; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; background: var(--accent); }

/* Stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.stat {
  padding: 18px; border-radius: var(--radius); background: #fff;
  border: 1px solid var(--card-border); position: relative; overflow: hidden;
}
.stat .name { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.stat .big { font-size: 28px; font-weight: 700; margin-top: 4px; color: var(--text); }
.stat .row-mini { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.stat .row-mini span b { color: var(--text); }
.stat.good .big { color: var(--good); }
.stat.bad .big { color: var(--bad); }
.stat .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); }

/* Table */
.table-wrap { overflow-x: auto; border: 1px solid var(--card-border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; }
thead th {
  text-align: left; padding: 11px 12px; color: var(--muted); font-weight: 600;
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  background: var(--bg); border-bottom: 1px solid var(--card-border); position: sticky; top: 0;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid #eef0f3; vertical-align: top; color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
.price { font-variant-numeric: tabular-nums; font-weight: 600; }
.pct { font-variant-numeric: tabular-nums; font-weight: 700; }
.pct.up { color: var(--good); }
.pct.down { color: var(--bad); }
.pct.flat { color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.mix { background: var(--warn-soft); color: var(--warn); }
.badge.mute { background: var(--bg); color: var(--muted); }

/* Alerts */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; }
.alert.err { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--good-soft); color: var(--good); }
.alert.info { background: var(--accent-soft); color: var(--accent); }

.hidden { display: none !important; }
.spinner {
  width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
.btn.secondary .spinner, .btn.ghost .spinner { border-color: rgba(31,41,51,.3); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

.success-screen { text-align: center; padding: 28px 0; }
.success-screen .check {
  width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 16px;
  background: var(--good); display: grid; place-items: center; font-size: 32px; color: #fff;
}

.tag { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--accent-soft); color: var(--accent); border: 1px solid #d6e2f0; }

.chart-card { position: relative; height: 380px; }

/* Legend graphique historique */
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  background: #fff; border: 1px solid var(--card-border);
  font-size: 12.5px; font-weight: 600; color: var(--text);
  transition: background .12s, border-color .12s, opacity .12s;
  font-family: inherit;
}
.legend-item:hover { border-color: var(--c); }
.legend-item .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, #fff); }
.legend-item.off { opacity: .4; }
.legend-item.off .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pill-toggle { display: inline-flex; background: var(--bg); border: 1px solid var(--card-border); border-radius: 999px; padding: 3px; gap: 2px; }
.pill-toggle button { border: none; background: transparent; color: var(--muted); padding: 6px 13px; border-radius: 999px; cursor: pointer; font-size: 13px; }
.pill-toggle button.active { background: var(--accent); color: #fff; }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty .ico { font-size: 40px; margin-bottom: 10px; opacity: .5; }

@media (max-width: 720px) {
  .mapping-grid { grid-template-columns: 1fr; }
  .comp-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 22px; }
}
