* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  min-height: 100%;
}

/* ── Header ── */
header {
  background: #161b22;
  padding: 18px 32px;
  border-bottom: 1px solid #30363d;
  display: flex;
  align-items: center;
  gap: 12px;
}
header h1 { font-size: 1.4rem; color: #f0f6fc; font-weight: 700; }
.badge { background: #1f6feb; color: #fff; padding: 2px 10px; border-radius: 12px; font-size: .75rem; font-weight: 600; }
.period { margin-left: auto; color: #8b949e; font-size: .85rem; }

/* ── Layout ── */
main { padding: 28px 32px; max-width: 1400px; margin: 0 auto; }

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 22px 24px;
}
.kpi .lbl { font-size: .95rem; color: #f0f6fc; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 2.6rem; font-weight: 800; }
.kpi .sub { font-size: .82rem; color: #484f58; margin-top: 5px; }

.blue   .val { color: #58a6ff; }
.green  .val { color: #3fb950; }
.orange .val { color: #d29922; }
.red    .val { color: #f85149; }
.purple .val { color: #bc8cff; }

/* ── Cards ── */
.row2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
  min-width: 0;
}
.card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 22px;
  overflow: hidden;
  min-width: 0;
}
.card h2 { font-size: 1.05rem; color: #f0f6fc; font-weight: 600; margin-bottom: 18px; display: flex; align-items: center; gap: 8px; }
.chart-wrap { position: relative; height: 240px; width: 100%; overflow: hidden; }
.chart-wrap canvas { max-width: 100%; }

/* ── Table ── */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .85rem; color: #8b949e; font-weight: 600; padding: 10px 12px; border-bottom: 1px solid #21262d; }
td { padding: 11px 12px; font-size: .95rem; border-bottom: 1px solid #1c2128; color: #e6edf3; vertical-align: middle; }
td:first-child { color: #58a6ff; font-family: monospace; font-size: .88rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:hover td { background: #1c2128; }

/* ── Footer ── */
footer { text-align: center; color: #30363d; font-size: .72rem; padding: 24px; }

/* ── Loader ── */
#loader {
  position: fixed; inset: 0; background: #0d1117;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; z-index: 999;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid #30363d; border-top-color: #58a6ff;
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loader p { color: #8b949e; font-size: .9rem; }

/* ── Error ── */
#error {
  display: none; position: fixed; inset: 0; background: #0d1117;
  align-items: center; justify-content: center; flex-direction: column; gap: 12px;
}
#error h2 { color: #f85149; }
#error p  { color: #8b949e; font-size: .85rem; max-width: 400px; text-align: center; }

/* ── Tooltips ── */
.tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 19px; height: 19px; border-radius: 50%;
  background: #21262d; border: 1px solid #30363d;
  color: #8b949e; font-size: 11px; font-weight: 700;
  cursor: help; position: relative; flex-shrink: 0; user-select: none;
}
.tip::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 10px); left: 0;
  background: #1c2128; border: 1px solid #30363d; border-radius: 8px;
  padding: 14px 16px; font-size: .85rem; color: #c9d1d9;
  white-space: pre-wrap; width: 280px; line-height: 1.7;
  pointer-events: none; opacity: 0; transition: opacity .18s; z-index: 200;
  text-transform: none; letter-spacing: 0; font-weight: 400;
  box-shadow: 0 8px 24px rgba(0,0,0,.6);
}
.tip:hover::after { opacity: 1; }

/* ── Responsive ── */

/* Empêcher tout débordement horizontal */
html, body { overflow-x: hidden; max-width: 100%; }

/* Tablette horizontale (≤ 1024px) */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .row2     { grid-template-columns: 1fr 1fr; }
}

/* Tablette verticale (≤ 768px) */
@media (max-width: 768px) {
  header      { padding: 14px 18px; gap: 8px; }
  header h1   { font-size: 1.2rem; }
  .period     { display: none; }

  main        { padding: 14px; }

  .kpi-grid   { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 14px; }
  .kpi        { padding: 16px; }
  .kpi .lbl   { font-size: .82rem; }
  .kpi .val   { font-size: 1.9rem; }

  .row2       { grid-template-columns: 1fr; gap: 12px; margin-bottom: 14px; }
  .card       { padding: 16px; }
  .card h2    { font-size: .9rem; margin-bottom: 12px; }
  .chart-wrap { height: 210px; }

  th          { font-size: .78rem; padding: 8px; }
  td          { font-size: .82rem; padding: 8px; }

  .tip::after { width: 240px; }
}

/* Mobile (≤ 480px) */
@media (max-width: 480px) {
  header    { padding: 12px 14px; }
  header h1 { font-size: 1.05rem; }
  .badge    { font-size: .68rem; }

  main      { padding: 10px; }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 10px;
  }
  .kpi          { padding: 12px 14px; }
  .kpi .lbl     { font-size: .75rem; white-space: normal; line-height: 1.3; }
  .kpi .val     { font-size: 1.6rem; }
  .kpi .sub     { font-size: .7rem; }

  .row2         { gap: 10px; margin-bottom: 10px; }
  .card         { padding: 14px 12px; }
  .card h2      { font-size: .85rem; margin-bottom: 10px; }
  .chart-wrap   { height: 180px; }

  /* Tableau scrollable */
  .table-wrap   { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table         { min-width: 400px; }
  th            { font-size: .72rem; padding: 7px 8px; }
  td            { font-size: .78rem; padding: 7px 8px; }
  td:first-child { max-width: 110px; }

  /* Tooltip réduit et jamais hors écran */
  .tip          { width: 16px; height: 16px; font-size: 10px; }
  .tip::after   { width: min(220px, calc(100vw - 30px)); font-size: .78rem; left: auto; right: 0; }
}
