/* NTP Monitor — feuille de style du dashboard (thème sombre unique).

   Les classes et ids utilisés ici sont aussi manipulés par app.js : les renommer
   casserait l'affichage. app.js lit également les variables --text, --text-2,
   --muted, --grid, --axis et --surface pour dessiner les graphiques.

   Plan : variables · en-tête · cartes · indicateurs (KPI) · cartes serveurs ·
   graphiques et onglets · pays · flux · adaptations écran · ajouts ultérieurs
   (NTS, adresses publiques, transitions, liens NTP Pool), qui complètent ou
   remplacent certaines règles précédentes. */

/* ---------- variables du thème ---------- */
:root {
  color-scheme: dark;
  --page: #0d0d0d;        /* fond de la page */
  --surface: #1a1a19;     /* fond des cartes */
  --surface-2: #222221;   /* fond des éléments dans une carte */
  --border: rgba(255, 255, 255, 0.10);
  --text: #f0efec;
  --text-2: #c3c2b7;      /* texte secondaire */
  --muted: #898781;       /* libellés discrets */
  --grid: #2c2c2a;        /* lignes de grille des graphiques */
  --axis: #383835;        /* axe des graphiques */
  /* couleurs d'état */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --accent: #3987e5;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* l'attribut hidden doit gagner sur display:flex des classes */
html, body { margin: 0; background: var(--page); color: var(--text); }
body { min-height: 100vh; display: flex; flex-direction: column; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num, .kpi-value, .big, dd, td { font-variant-numeric: tabular-nums; }   /* chiffres de même largeur */

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #141413, var(--page));
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 34px; height: 34px; color: var(--accent); }
.brand h1 { font-size: 19px; letter-spacing: .2px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.top-right { display: flex; align-items: center; gap: 18px; }
.clock { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.clock small { font-size: 11px; color: var(--muted); margin-left: 6px; font-weight: 500; }

/* pastille d'état de connexion (#conn) : pill-ok / pill-warn / pill-bad posées par app.js */
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); font-size: 13px; color: var(--text-2); background: var(--surface); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill-ok .dot { background: var(--good); box-shadow: 0 0 0 0 rgba(12,163,12,.6); animation: pulse 2s infinite; }
.pill-warn .dot { background: var(--warning); }
.pill-bad .dot { background: var(--critical); }
/* halo vert qui s'élargit puis disparaît autour du point « tout va bien » */
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(12,163,12,.55); }
  70% { box-shadow: 0 0 0 8px rgba(12,163,12,0); }
  100% { box-shadow: 0 0 0 0 rgba(12,163,12,0); }
}

main {
  flex: 1; padding: 22px 28px 10px; display: flex; flex-direction: column; gap: 18px;
  max-width: 1680px; width: 100%; margin: 0 auto;
}

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; min-width: 0;
}
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-h h2 { font-size: 15px; }

/* ---------- KPIs ---------- */
/* première case (débit total) un peu plus large que les cinq autres */
.kpis { display: grid; grid-template-columns: 1.3fr repeat(5, 1fr); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi-label { color: var(--text-2); font-size: 13px; }
/* nowrap + overflow : app.js (fit) détecte le débordement et abrège le nombre en K/M/Md */
.kpi-value {
  font-size: 30px; font-weight: 650; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-hero { background: linear-gradient(135deg, #1d2633 0%, var(--surface) 70%); }
.kpi-hero .kpi-value { font-size: 42px; }
.kpi-foot { color: var(--muted); font-size: 12.5px; }

/* ---------- servers ---------- */
/* une carte par serveur (gabarit #tpl-server de index.html), autant de colonnes que la largeur permet */
.servers { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 14px; }
.server { display: flex; flex-direction: column; gap: 14px; transition: opacity .3s; }
.server.offline { opacity: .6; }
.srv-h { display: flex; align-items: center; gap: 10px; }
.swatch { width: 10px; height: 28px; border-radius: 4px; flex: none; }   /* couleur du serveur */
.srv-title { flex: 1; min-width: 0; }
.srv-name { font-size: 15.5px; }
.srv-role { color: var(--muted); font-size: 12.5px; }
.srv-rate { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.big { font-size: 32px; font-weight: 650; }
.unit { color: var(--muted); font-size: 13px; margin-left: 6px; }
.spark { width: 55%; height: 42px; }
/* compteurs jour / mois / année / NTS */
.srv-counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; }
.srv-counts div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.srv-counts dt { color: var(--muted); font-size: 11.5px; }
.srv-counts dd {
  margin: 2px 0 0; font-weight: 600; font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* blocs chrony / GNSS / Système */
.block { border-top: 1px solid var(--border); padding-top: 12px; }
.block h4 {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); margin-bottom: 8px;
}
/* listes libellé / valeur sur deux colonnes */
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; margin: 0; }
.kv div { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; min-width: 0; }
.kv dt { color: var(--text-2); }
.kv dd {
  margin: 0; font-weight: 550; text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* sources chrony : état, nom, NTS, reach, offset (colonnes redéfinies plus bas) */
.sources { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.sources li { display: grid; grid-template-columns: 22px 1fr auto auto; gap: 10px; align-items: center;
  font-size: 12.5px; background: var(--surface-2); padding: 5px 10px; border-radius: 8px; }
.sources .st { font-weight: 700; text-align: center; }
.sources .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sources .rc { color: var(--muted); }
.sources li.sel .st { color: var(--good); }   /* source sélectionnée par chrony (*) */

/* badges d'état (en ligne, fix GNSS, PPS) : good / warn / bad posées par app.js */
.gps-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.good { color: var(--good); border-color: rgba(12,163,12,.35); }
.badge.warn { color: var(--warning); border-color: rgba(250,178,25,.35); }
.badge.bad { color: var(--critical); border-color: rgba(208,59,59,.45); }
/* satellites par constellation */
.constel { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.constel span {
  font-size: 11.5px; padding: 3px 8px; border-radius: 6px;
  background: var(--surface-2); color: var(--text-2);
}
.constel b { color: var(--text); font-weight: 600; }

/* ---------- charts ---------- */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.chart { position: relative; height: 240px; }
.chart canvas { width: 100%; height: 100%; display: block; }
.legend {
  display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px;
  color: var(--text-2); margin-bottom: 6px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 4px; border-radius: 2px; display: inline-block; }
/* infobulle des graphiques, positionnée par app.js (showTip) */
.tip { position: absolute; pointer-events: none; background: #2a2a28; border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; font-size: 12.5px; min-width: 140px; box-shadow: 0 8px 24px rgba(0,0,0,.45); z-index: 2; }
.tip .t { color: var(--muted); margin-bottom: 4px; }
.tip .r { display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.tip .r i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }
.tip .r b { font-variant-numeric: tabular-nums; }

/* onglets (Historique, Pays) : l'onglet actif porte aria-selected="true" */
.tabs { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.tabs button {
  background: none; border: 0; color: var(--text-2); font: inherit; font-size: 12.5px;
  padding: 5px 11px; border-radius: 7px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: #353533; color: var(--text); }
.tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- countries ---------- */
.countries {
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px;
  max-height: 430px; overflow-y: auto;
}
/* colonnes : rang, code, nom, barre, requêtes, pourcentage */
.countries li { display: grid; grid-template-columns: 26px 38px minmax(90px, 170px) 1fr 96px 52px; align-items: center; gap: 10px;
  font-size: 13px; padding: 4px 6px; border-radius: 8px; }
.countries li:hover { background: var(--surface-2); }
.countries .rk { color: var(--muted); text-align: right; }
.countries .cc {
  font-size: 11px; font-weight: 700; letter-spacing: .5px; text-align: center;
  padding: 2px 0; border-radius: 5px; background: #2c2c2a; color: var(--text-2);
}
.countries .nm { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.countries .bar { height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.countries .bar i {
  display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0;
  transition: width .6s ease;
}
.countries .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.countries .pc { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- feed ---------- */
.feed-wrap { max-height: 456px; overflow: hidden; }
.feed { width: 100%; border-collapse: collapse; font-size: 13px; }
.feed th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.feed td { padding: 6px 8px; border-bottom: 1px solid #222221; white-space: nowrap; }
.feed td.ip { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; color: var(--text-2); }
.feed .sv { display: inline-flex; align-items: center; gap: 6px; }
.feed .sv i { width: 8px; height: 8px; border-radius: 2px; }
/* nouvelle ligne : glisse depuis le haut avec un bref surlignage (durée redéfinie plus bas) */
.feed tr.new { animation: flash 1.2s ease-out; }
@keyframes flash {
  0% { background: rgba(57,135,229,.22); opacity: 0; transform: translateY(-6px); }
  25% { opacity: 1; transform: none; }
  100% { background: transparent; }
}

.foot {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  color: var(--muted); font-size: 12px; padding: 14px 28px 20px;
  max-width: 1680px; width: 100%; margin: 0 auto;
}

/* ---------- adaptations à la largeur d'écran ---------- */
/* écran moyen : débit total sur toute la largeur, graphiques l'un sous l'autre */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(5, 1fr); }
  .kpi-hero { grid-column: span 5; }
  .grid2 { grid-template-columns: 1fr; }
}
/* téléphone : KPI sur deux colonnes, colonnes secondaires masquées */
@media (max-width: 640px) {
  .top { padding: 14px 16px; }
  main { padding: 14px 12px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi-hero { grid-column: span 2; }
  .countries li { grid-template-columns: 22px 34px 1fr 70px 44px; }
  .countries .bar { display: none; }
  .feed th:nth-child(5), .feed td:nth-child(5) { display: none; }   /* colonne « NTP » */
}
/* préférence système « réduire les animations » : tout est figé */
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.foot a { color: var(--muted); }

/* ---------- NTS & adresses publiques ---------- */
.pubip { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }
/* user-select: all : un clic sélectionne toute l'adresse, prête à copier */
.pubip span { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; user-select: all; }
.pubip b {
  font-family: system-ui, sans-serif; color: var(--muted); font-weight: 600;
  margin-right: 6px; font-size: 11px;
}
/* étiquette « NTS » (sources chrony et flux) */
.tag-nts { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .4px; padding: 1px 6px; border-radius: 5px;
  color: var(--good); border: 1px solid rgba(12,163,12,.4); background: rgba(12,163,12,.08); margin-left: 6px; vertical-align: 1px; }
/* remplace les colonnes des sources définies plus haut : une colonne de plus pour l'étiquette NTS */
.sources li { grid-template-columns: 22px 1fr auto auto auto; }
/* ip_privacy = hide : la colonne « Client » du flux est masquée */
.feed.no-ip th:nth-child(3), .feed.no-ip td:nth-child(3) { display: none; }
/* entre 1201 et 1400 px, six KPI sur une ligne : chiffres un peu plus petits */
@media (max-width: 1400px) and (min-width: 1201px) { .kpi-value { font-size: 26px; } }

/* ---------- transitions ---------- */
/* classement des pays : nouvelle ligne qui glisse depuis la gauche ; les changements
   de rang sont animés par app.js (technique FLIP, d'où will-change: transform) */
.countries li { will-change: transform; }
.countries li.enter { animation: ccIn .6s ease-out; }
@keyframes ccIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
/* remplacent les durées définies plus haut (barres des pays, lignes du flux) */
.countries .bar i { transition: width .9s cubic-bezier(.2,.8,.2,1); }
.feed tr.new { animation: flash 1.4s ease-out; }

/* ---------- liens NTP Pool ---------- */
/* lien global dans l'en-tête (#pool-link) */
a.pill-link { color: var(--text-2); text-decoration: none; }
a.pill-link:hover, a.pill-link:focus-visible { color: var(--text); border-color: rgba(57,135,229,.6); outline: none; }
/* lien par serveur, à côté des adresses publiques */
.pubip a.pool { font-size: 12px; color: var(--accent); text-decoration: none; padding: 3px 8px; border-radius: 6px;
  border: 1px solid rgba(57,135,229,.35); background: rgba(57,135,229,.08); }
.pubip a.pool:hover, .pubip a.pool:focus-visible { background: rgba(57,135,229,.18); outline: none; }
