/* ==========================================================================
   WebStats — feuille de style
   Palette data-viz validée (CVD + contraste) en mode clair et sombre.
   ========================================================================== */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;

  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 12px rgba(11, 11, 11, 0.04);

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;

    --good-text: #0ca30c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.2);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;

  --good-text: #0ca30c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--plane);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --------------------------------------------------------------------------
   Mise en page
   -------------------------------------------------------------------------- */

.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  font-weight: 650;
  font-size: 16px;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand:hover { text-decoration: none; }

.brand-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--series-1);
}

.topnav { display: flex; gap: 4px; margin-left: 8px; }

.topnav a {
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
}
.topnav a:hover { background: var(--plane); text-decoration: none; color: var(--text-primary); }
.topnav a.active { background: var(--plane); color: var(--text-primary); font-weight: 600; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 14px; letter-spacing: -0.01em; }

.subtitle { color: var(--text-secondary); font-size: 13px; margin-top: 3px; }

/* --------------------------------------------------------------------------
   Cartes
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

/* align-items: start évite que les cartes d'une même rangée s'étirent à la
   hauteur de la plus haute, ce qui laissait du vide sous les tableaux courts. */
.grid { display: grid; gap: 16px; align-items: start; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* --------------------------------------------------------------------------
   Tuiles d'indicateurs
   -------------------------------------------------------------------------- */

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.025em;
  margin-top: 6px;
  line-height: 1.1;
}

.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  margin-top: 8px;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--plane);
}
.trend.up { color: var(--good-text); }
.trend.down { color: var(--critical); }
.trend.flat { color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Sélecteur de période
   -------------------------------------------------------------------------- */

.periods {
  display: inline-flex;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
  flex-wrap: wrap;
}

.periods a {
  padding: 5px 11px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}
.periods a:hover { background: var(--plane); text-decoration: none; }
.periods a.active { background: var(--series-1); color: #fff; font-weight: 600; }

/* --------------------------------------------------------------------------
   Tableaux
   -------------------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--border);
}

td { padding: 9px 10px; border-bottom: 1px solid var(--gridline); }
tr:last-child td { border-bottom: none; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.path-cell {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12.5px;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Barre de proportion en fond de ligne : donne l'échelle sans second graphique.
   La couleur est posée en rgba littéral plutôt qu'en color-mix sur une
   variable, qui ne s'évalue pas de façon fiable dans tous les navigateurs. */
/* La barre est peinte en dégradé sur le fond de la cellule elle-même : dans un
   <td>, un enfant en position absolue ne peut pas être étiré à la hauteur de
   la ligne (ni `top`/`bottom`, ni une hauteur en pourcentage ne s'y résolvent).
   La largeur est portée par --bar, posée en style inline. */
.bar-cell {
  position: relative;
  background-image: linear-gradient(
    to right,
    rgba(42, 120, 214, 0.13) 0 var(--bar, 0%),
    transparent var(--bar, 0%) 100%
  );
  background-repeat: no-repeat;
  background-size: 100% calc(100% - 6px);
  background-position: 0 center;
}
.bar-cell > * { position: relative; z-index: 1; }

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .bar-fill { background: rgba(57, 135, 229, 0.22); }
}
:root[data-theme="dark"] .bar-fill { background: rgba(57, 135, 229, 0.22); }

/* --------------------------------------------------------------------------
   Pastilles et étiquettes
   -------------------------------------------------------------------------- */

.dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: -1px;
  flex-shrink: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 20px;
  background: var(--plane);
  color: var(--text-secondary);
  font-weight: 500;
  border: 1px solid var(--border);
}

.badge.live { color: var(--good-text); border-color: color-mix(in srgb, var(--good) 35%, transparent); }

.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--good);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
}

/* --------------------------------------------------------------------------
   Formulaires
   -------------------------------------------------------------------------- */

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text-primary);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="url"], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface-1);
  color: var(--text-primary);
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--series-1);
  outline-offset: -1px;
  border-color: var(--series-1);
}

.field { margin-bottom: 16px; }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; font-weight: 400; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--series-1);
  color: #fff;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }

.btn-secondary {
  background: var(--surface-1);
  color: var(--text-primary);
  border-color: var(--baseline);
}
.btn-secondary:hover { background: var(--plane); filter: none; }

.btn-danger { background: var(--critical); }
.btn-sm { padding: 6px 11px; font-size: 13px; }

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 16px;
  border: 1px solid;
}
.alert-error {
  background: color-mix(in srgb, var(--critical) 8%, var(--surface-1));
  border-color: color-mix(in srgb, var(--critical) 30%, transparent);
  color: var(--critical);
}
.alert-success {
  background: color-mix(in srgb, var(--good) 8%, var(--surface-1));
  border-color: color-mix(in srgb, var(--good) 30%, transparent);
  color: var(--good-text);
}

/* --------------------------------------------------------------------------
   Bloc de code (extrait d'intégration)
   -------------------------------------------------------------------------- */

.code {
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12.5px;
  overflow-x: auto;
  white-space: pre;
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   Graphiques
   -------------------------------------------------------------------------- */

.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 200px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--text-secondary);
}
.legend-item { display: flex; align-items: center; }

/* Carte de chaleur horaire */
.heatmap { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; }
.heat-cell {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--gridline);
  position: relative;
}
.heat-labels {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
  margin-top: 5px;
  font-size: 9.5px;
  color: var(--text-muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.empty {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* --------------------------------------------------------------------------
   Connexion
   -------------------------------------------------------------------------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 380px; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 980px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 680px) {
  .wrap { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; gap: 12px; }
  .topnav { display: none; }
  .stat-value { font-size: 25px; }
  .chart-box { height: 220px; }
}
