:root {
  --bg: #f6f7f9;
  --card: #fff;
  --text: #1c2024;
  --muted: #6b7280;
  --line: #e4e7eb;
  --blue: #2563eb;
  --green: #15803d;
  --green-bg: #dcfce7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --gray-bg: #eceef1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1560px; margin: 0 auto; padding: 0 20px; }
.wrap.narrow { max-width: 420px; }

.topbar { background: #fff; border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.logo { font-weight: 600; color: var(--text); }
.topbar nav { display: flex; gap: 16px; align-items: center; font-size: 14px; }

h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 32px 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.break { word-break: break-all; }

.head-row {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 8px;
}
.head-row h1 { margin-bottom: 4px; }
.stats { display: flex; gap: 8px; align-items: center; }

/* --- Cartes & formulaires --- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px; margin-bottom: 20px;
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.card.stat { display: flex; flex-direction: column; gap: 4px; }
.card.stat strong { font-size: 20px; }

label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
input, select {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 6px; font-size: 15px;
  background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }

.add-form .row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.add-form .row label { margin-bottom: 0; }
.add-form .grow { flex: 1 1 240px; }

.btn {
  display: inline-block; padding: 9px 16px; border: 1px solid var(--blue);
  background: var(--blue); color: #fff; border-radius: 6px; cursor: pointer;
  font-size: 14px; font-family: inherit;
}
.btn:hover { opacity: .9; text-decoration: none; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: #fff; color: var(--text); border-color: var(--line); }
.btn.danger { background: #fff; color: var(--red); border-color: #f3c6c6; }

/* --- Pastilles de statut --- */
.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill.up { background: var(--green-bg); color: var(--green); }
.pill.down { background: var(--red-bg); color: var(--red); }
.pill.warn { background: var(--amber-bg); color: var(--amber); }
.pill.unknown { background: var(--gray-bg); color: var(--muted); }

/* --- Tableaux --- */
table.sites {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
table.sites th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600;
}
table.sites td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.sites tr:last-child td { border-bottom: 0; }
table.sites tr.paused { opacity: .55; }
.site-name { font-weight: 600; color: var(--text); }
.actions form { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- Messages --- */
.alert { padding: 10px 14px; border-radius: 6px; margin: 0 0 18px; font-size: 14px; }
.alert.ok { background: var(--green-bg); color: var(--green); }
.alert.err { background: var(--red-bg); color: var(--red); }
.empty { color: var(--muted); padding: 32px; text-align: center; background: #fff;
         border: 1px dashed var(--line); border-radius: 8px; }
.log { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px 16px 16px 34px; }

.foot { padding: 32px 20px; font-size: 13px; }

@media (max-width: 720px) {
  table.sites, table.sites thead, table.sites tbody, table.sites tr, table.sites td { display: block; }
  table.sites thead { display: none; }
  table.sites tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.sites td { border: 0; padding: 4px 12px; }
}

/* --- Onglets d'ajout --- */
.hidden { display: none !important; }

.tabs { display: flex; gap: 4px; margin-bottom: -1px; }
.tab-btn {
  padding: 8px 16px; font: inherit; font-size: 14px; cursor: pointer;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 8px 8px 0 0;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  background: var(--card); color: var(--text); font-weight: 600;
  border-color: var(--line); border-bottom-color: var(--card);
}
.tabs + .card { border-top-left-radius: 0; }

textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
  color: var(--text); font: 14px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }

/* --- Rapport d'import --- */
.report {
  border: 1px solid var(--line); border-radius: 6px; padding: 10px 14px;
  margin: 0 0 12px; font-size: 14px; background: #fff;
}
.report summary { cursor: pointer; font-weight: 600; }
.report.warn { background: var(--amber-bg); color: var(--amber); border-color: #f2dda3; }
.report.err  { background: var(--red-bg); color: var(--red); border-color: #f3c6c6; }
.report ul { margin: 8px 0 0; padding-left: 20px; font-family: ui-monospace, Consolas, monospace;
             font-size: 13px; max-height: 220px; overflow: auto; }

/* --- Sélection multiple --- */
td.tiny, th.tiny { width: 28px; padding-right: 0; }
td.tiny input, th.tiny input { width: 16px; height: 16px; margin: 2px 0 0; cursor: pointer; }

.bulk-bar {
  display: flex; align-items: center; gap: 12px; margin-top: 12px;
  padding: 10px 14px; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px;
}

/* --- Cases à cocher en ligne dans les formulaires --- */
label.check {
  display: flex; align-items: center; gap: 6px; margin-bottom: 0;
  font-size: 13px; color: var(--text); white-space: nowrap; padding-bottom: 9px;
}
label.check input { width: 16px; height: 16px; margin: 0; }

/* --- Bouton discret façon lien (bascule des alertes) --- */
.linkish {
  padding: 0; border: 0; background: none; font: inherit; font-size: 13px;
  color: var(--blue); cursor: pointer; text-decoration: underline;
}
.linkish:hover { opacity: .75; }

/* --- Barre de filtres --- */
.filters {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 20px 0 12px;
}
.filters input[type="search"] {
  width: auto; flex: 1 1 260px; margin-top: 0; padding: 7px 10px; font-size: 14px;
}
.filters select { width: auto; margin-top: 0; padding: 7px 10px; font-size: 14px; }

/* Pastilles cliquables du bandeau de statistiques */
a.pill { text-decoration: none; }
a.pill:hover { text-decoration: none; filter: brightness(.95); }
a.pill.on { outline: 2px solid currentColor; outline-offset: 1px; }

/* --- Barre d'actions groupées --- */
.bulk-bar { flex-wrap: wrap; }
.bulk-bar select { width: auto; margin-top: 0; padding: 5px 8px; font-size: 13px; }

/* --- Icône « ouvrir le site dans un nouvel onglet » --- */
.ext-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; margin-left: 4px; vertical-align: middle;
  border-radius: 4px; color: var(--muted); flex: none;
}
.ext-link svg { fill: none; stroke: currentColor; stroke-width: 2;
                stroke-linecap: round; stroke-linejoin: round; }
.ext-link:hover { color: var(--blue); background: var(--gray-bg); text-decoration: none; }
.ext-link:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

/* --- Jauge de disponibilité --- */
.gauge {
  height: 5px; background: var(--gray-bg); border-radius: 3px;
  overflow: hidden; margin: 5px 0;
}
.gauge span { display: block; height: 100%; border-radius: 3px; }
.gauge.mini { height: 4px; width: 60px; margin: 3px 0 0; }
.gauge span.up      { background: var(--green); }
.gauge span.warn    { background: var(--amber); }
.gauge span.down    { background: var(--red); }
.gauge span.unknown { background: var(--muted); }

.up-text      { color: var(--green); }
.warn-text    { color: var(--amber); }
.down-text    { color: var(--red); }
.unknown-text { color: var(--muted); }

.cards.summary { margin-bottom: 22px; }
.card.stat.big strong { font-size: 30px; line-height: 1.1; }

/* --- Barres des 7 derniers jours --- */
.week {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 16px; margin-bottom: 10px;
}
.week .day { text-align: center; }
.week .bar {
  height: 90px; background: var(--gray-bg); border-radius: 4px;
  display: flex; align-items: flex-end; overflow: hidden; margin-bottom: 6px;
}
.week .bar span { display: block; width: 100%; border-radius: 4px 4px 0 0; }
.week .bar.up span      { background: var(--green); }
.week .bar.warn span    { background: var(--amber); }
.week .bar.down span    { background: var(--red); }
.week .bar.unknown span { background: var(--muted); }
.week .day-pct { font-weight: 600; font-size: 13px; }
.week .day-label { display: block; }
.week .day-count::before { content: "· "; }

@media (max-width: 560px) {
  .week { gap: 4px; padding: 12px 8px; }
  .week .bar { height: 64px; }
  .week .day-label, .week .day-count { font-size: 11px; }
}

/* --- Le tableau défile dans son cadre, jamais la page entière --- */
.table-wrap { overflow-x: auto; }
.table-wrap table.sites { min-width: 900px; }
td.actions { white-space: nowrap; }
td.actions .btn { margin-right: 4px; }

@media (max-width: 720px) {
  .table-wrap table.sites { min-width: 0; }
}

/* --- Avertissement (tache planifiee, doublons d'import) --- */
.alert.warn-box { background: var(--amber-bg); color: var(--amber); }

/* --- Menu de groupe dans une carte --- */
.card.stat form { display: flex; gap: 6px; align-items: center; margin: 2px 0 4px; }
.card.stat form select { width: auto; margin-top: 0; padding: 5px 8px; font-size: 13px; flex: 1 1 auto; }

/* --- Lignes compactes : plus de sites visibles sans defiler --- */
table.sites td { padding: 7px 10px; vertical-align: middle; }
table.sites th { padding: 7px 10px; }
table.sites td .muted.small { line-height: 1.3; }
.site-name { display: inline-block; }

/* Les boutons d'action tiennent sur une seule ligne */
td.actions .btn.small { padding: 3px 8px; font-size: 12px; }
.linkish { font-size: 12px; }
.pill { padding: 2px 8px; }

/* La largeur minimale du tableau suit la page elargie */
.table-wrap table.sites { min-width: 1100px; }
@media (max-width: 900px) { .table-wrap table.sites { min-width: 0; } }
