:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #667085;
  --border: #dfe3ea;
  --accent: #1f6feb;
  --ok: #1d953f;
  --offline: #ff2800;
  --alert: #e08a00;
  --warning: #d92d20;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1a2029;
    --text: #e6e9ef;
    --muted: #8b95a5;
    --border: #2a3240;
    --accent: #4c8dff;
    --ok: #3ac26a;
    --alert: #f0a020;
    --warning: #ff6b5e;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.1rem; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; text-decoration: none; color: inherit; }
.brand img { height: 24px; border-radius: 4px; }
.badge { font-size: .72rem; padding: 1px 7px; border-radius: 99px; background: var(--border); color: var(--muted); font-weight: 500; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

.btn {
  padding: 6px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--warning); }
.btn.link { border: 0; background: none; padding: 0; color: inherit; text-align: left; font-weight: 600; }
input[type="text"], input[type="password"], input[type="url"], input[type="search"], select {
  padding: 6px 10px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
}
input:focus-visible, button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.stat .value { font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat.ok .value { color: var(--ok); }
.stat.offline .value { color: var(--offline); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1; min-width: 180px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th[aria-sort="ascending"]::after { content: " ▲"; font-size: .7em; }
th[aria-sort="descending"]::after { content: " ▼"; font-size: .7em; }
tr.device:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
tr.detail td { background: color-mix(in srgb, var(--muted) 7%, transparent); padding: 4px 12px 12px; }
td.num { font-variant-numeric: tabular-nums; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.status { font-weight: 600; }
.status.ok { color: var(--ok); }
.status.offline { color: var(--offline); }
.flag-ALERT { color: var(--alert); }
.flag-WARNING { color: var(--warning); }
.flag-OK { color: var(--ok); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.flag-ALERT { background: var(--alert); }
.dot.flag-WARNING { background: var(--warning); }
.dot.flag-OK { background: var(--ok); }

.payloads { list-style: none; margin: 8px 0 0; padding: 0; }
.payloads li { padding: 3px 0; display: flex; gap: 10px; }
.payloads time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 22px; max-width: 360px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form { display: grid; gap: 12px; }
.error { color: var(--warning); min-height: 1.4em; margin: 0; }

.stat .sub { color: var(--muted); font-size: .78rem; margin-top: 2px; }

/* Graphiques du dashboard */
.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.panel { display: grid; gap: 10px; align-content: start; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel h2 .small { font-weight: 400; margin-left: 6px; }
@media (max-width: 700px) { .panels { grid-template-columns: minmax(0, 1fr); } }

svg.chart { display: block; max-width: 100%; }
svg.spark { width: 100%; height: auto; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--muted); stroke-width: 1; opacity: .5; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .hit { fill: transparent; outline: none; }
.chart .hit:hover, .chart .hit:focus-visible { fill: color-mix(in srgb, var(--muted) 14%, transparent); }
.seg-warning { fill: var(--warning); background: var(--warning); stroke: var(--surface); stroke-width: 1.5; }
.seg-alert { fill: var(--alert); background: var(--alert); stroke: var(--surface); stroke-width: 1.5; }
.seg-other { background: var(--muted); }

.legend, .fresh-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; padding: 0; list-style: none; font-size: .85rem; color: var(--muted); }
.legend span, .fresh-legend li { display: inline-flex; align-items: center; gap: 6px; }
.fresh-legend b { color: var(--text); }
i.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
i.key.seg-warning, i.key.seg-alert, i.key.seg-other { stroke: none; }

.values summary { cursor: pointer; font-size: .85rem; color: var(--muted); }
.values table { margin-top: 6px; font-size: .85rem; }
.values th, .values td { padding: 3px 10px; }

.toplist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.toplist li { display: grid; grid-template-columns: minmax(70px, 38%) 1fr 2.5em; align-items: center; gap: 10px; }
.toplist .btn.link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.toplist .num { text-align: right; font-variant-numeric: tabular-nums; }
.track { display: flex; gap: 2px; height: 10px; }
.track .seg { height: 100%; border-radius: 3px; }

.fresh-bar { display: flex; gap: 2px; height: 22px; }
.fresh { height: 100%; border-radius: 4px; min-width: 3px; }
.fresh.f1, i.key.f1 { background: var(--ok); }
.fresh.f2, i.key.f2 { background: var(--accent); }
.fresh.f3, i.key.f3 { background: var(--alert); }
.fresh.f4, i.key.f4 { background: var(--offline); }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none; min-width: 120px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 10px; font-size: .85rem; box-shadow: 0 4px 14px rgba(0, 0, 0, .15);
}
.tooltip[hidden] { display: none; }
.tip-title { color: var(--muted); font-size: .78rem; margin-bottom: 2px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row b { min-width: 2ch; text-align: right; }
.tip-row span { color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; overflow-x: auto; }
.tab { border: 0; border-bottom: 2px solid transparent; background: none; padding: 8px 14px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab .count { display: inline-block; min-width: 1.6em; padding: 0 6px; border-radius: 99px; background: var(--border); color: var(--text); font-size: .78rem; text-align: center; }
.tab .count:empty { display: none; }
.tab .count.hot { background: var(--offline); color: #fff; }
.since { color: var(--muted); font-size: .85rem; font-weight: 400; margin-left: 6px; }

.more { text-align: center; margin: 10px 0 0; min-height: 1.4em; }

.timeline { margin: 6px 0 2px; }
.timeline .muted { margin-bottom: 2px; }

section.card { margin-bottom: 16px; display: grid; gap: 12px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; }
.grid-form label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.grid-form input[type="url"], .grid-form input[type="password"], .grid-form input[type="text"], .grid-form select { width: 100%; color: var(--text); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.progress { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.progress.indeterminate > div { width: 40%; animation: slide 1.2s infinite ease-in-out; }
@keyframes slide { from { margin-left: -40%; } to { margin-left: 100%; } }
.result { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.result div { background: var(--bg); border-radius: var(--radius); padding: 8px 10px; }
.result b { display: block; font-size: 1.25rem; }
.notice { padding: 10px 12px; border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 10%, transparent); font-size: .9rem; }
.notice.bad { background: color-mix(in srgb, var(--warning) 12%, transparent); }
ol.steps { margin: 0; padding-left: 20px; }
ol.steps li { margin: 2px 0; }
