/* =====================================================================
   Vigie — feuille de style unique de l'interface.

   Organisation :
     1. Variables de thème (sombre par défaut, clair en option)
     2. Base et typographie
     3. Mise en page (barre latérale + contenu)
     4. Composants réutilisables (cartes, boutons, tableaux, badges…)
     5. Écrans spécifiques (connexion, terminal, explorateur, graphiques)
     6. Adaptation mobile

   Aucune dépendance externe : pas de framework CSS, pas de police distante.
   ===================================================================== */

/* ---------------------------------------------------------------------
   1. Thème
   --------------------------------------------------------------------- */
:root {
  --bg: #0e1116;
  --bg-soft: #151a21;
  --bg-card: #171d26;
  --bg-hover: #1e252f;
  --border: #262e3a;
  --border-soft: #1d242e;
  --text: #e6ebf2;
  --text-dim: #9aa7b8;
  --text-faint: #6b7889;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --ok: #35c98a;
  --warn: #f0b429;
  --crit: #f2545b;
  --info: #56b3d9;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius: 10px;
  --radius-sm: 6px;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", "SF Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* Thème clair : activé par l'attribut data-theme sur <html>. */
html[data-theme="light"] {
  --bg: #f4f6fa;
  --bg-soft: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef2f8;
  --border: #dbe2ec;
  --border-soft: #e8edf4;
  --text: #17202c;
  --text-dim: #5b6878;
  --text-faint: #8a97a8;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --shadow: 0 4px 16px rgba(20, 32, 50, 0.1);
}

/* ---------------------------------------------------------------------
   2. Base
   --------------------------------------------------------------------- */
* { box-sizing: border-box; }

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

h1, h2, h3, h4 { margin: 0 0 0.4em; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.8em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 0.86em; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ---------------------------------------------------------------------
   3. Mise en page
   --------------------------------------------------------------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 226px;
  flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}
.brand svg { width: 26px; height: 26px; }
.brand small { display: block; font-weight: 400; font-size: 0.68rem; color: var(--text-faint); }

.nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 500;
  margin-bottom: 2px;
}
.nav a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .nav-badge {
  margin-left: auto;
  background: var(--crit);
  color: #fff;
  border-radius: 10px;
  padding: 0 7px;
  font-size: 0.7rem;
  font-weight: 700;
}
.nav-section {
  padding: 14px 12px 6px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 8px;
}

.content { flex: 1; min-width: 0; padding: 22px 28px 60px; }

.page-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }

/* ---------------------------------------------------------------------
   4. Composants
   --------------------------------------------------------------------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 14px; }
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }

.grid { display: grid; gap: 14px; }
.grid-hosts { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.stat { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 1.6rem; font-weight: 650; line-height: 1.2; margin-top: 2px; }
.stat .sub { font-size: 0.78rem; color: var(--text-faint); }

button, .btn {
  font: inherit;
  font-weight: 550;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s, border-color 0.12s;
}
button:hover, .btn:hover { background: var(--border); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-danger { background: transparent; border-color: var(--crit); color: var(--crit); }
.btn-danger:hover { background: var(--crit); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 4px 9px; font-size: 0.8rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 0.85rem; }
/* Sans hauteur explicite, un sélecteur de couleur s'affiche comme un simple trait. */
input[type="color"] { height: 38px; padding: 3px; cursor: pointer; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); cursor: pointer; }
label { display: block; font-size: 0.8rem; color: var(--text-dim); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.hint { font-size: 0.76rem; color: var(--text-faint); margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.check label { margin: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border-soft); }
th { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); font-weight: 600; }
tbody tr:hover { background: var(--bg-hover); }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.badge-ok { background: rgba(53, 201, 138, 0.14); color: var(--ok); }
.badge-warn { background: rgba(240, 180, 41, 0.14); color: var(--warn); }
.badge-crit { background: rgba(242, 84, 91, 0.14); color: var(--crit); }
.badge-info { background: rgba(86, 179, 217, 0.14); color: var(--info); }
.badge-mute { background: var(--bg-hover); color: var(--text-faint); }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(53, 201, 138, 0.16); }
.dot-warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.16); }
.dot-crit { background: var(--crit); box-shadow: 0 0 0 3px rgba(242, 84, 91, 0.16); }
.dot-mute { background: var(--text-faint); }

.bar { height: 6px; border-radius: 4px; background: var(--bg-hover); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.4s; }
.bar.warn > span { background: var(--warn); }
.bar.crit > span { background: var(--crit); }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 0.8rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }

.empty {
  text-align: center;
  padding: 34px 20px;
  color: var(--text-faint);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-dim);
  padding: 8px 14px;
}
.tabs button:hover { background: var(--bg-hover); color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Fenêtres modales */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 13, 0.66);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  padding: 20px;
}
.modal.wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; flex: 1; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* Notifications éphémères */
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  max-width: 380px;
  animation: slide-in 0.18s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--crit); }
@keyframes slide-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------------
   5. Écrans spécifiques
   --------------------------------------------------------------------- */

/* Connexion et installation */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 15% -10%, rgba(79, 140, 255, 0.16), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card.wide { max-width: 620px; }
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; font-size: 1.3rem; font-weight: 700; }
.auth-logo svg { width: 30px; height: 30px; }
.auth-sub { color: var(--text-dim); margin-bottom: 20px; font-size: 0.9rem; }
.auth-error {
  background: rgba(242, 84, 91, 0.12);
  border: 1px solid rgba(242, 84, 91, 0.35);
  color: var(--crit);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 12px;
  font-size: 0.86rem;
}
.qr-box { background: #fff; padding: 12px; border-radius: var(--radius-sm); width: fit-content; margin: 0 auto 12px; }
.qr-box svg { display: block; width: 200px; height: 200px; }
.secret-key {
  font-family: var(--mono);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
  letter-spacing: 0.1em;
  word-break: break-all;
}
.codes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  font-family: var(--mono);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 12px 0;
}
.steps { display: flex; gap: 6px; margin-bottom: 18px; }
.step { flex: 1; height: 3px; border-radius: 2px; background: var(--border); }
.step.active { background: var(--accent); }

/* Tuile serveur du tableau de bord */
.host-card { cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.host-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.host-card .host-top { display: flex; align-items: center; gap: 9px; margin-bottom: 3px; }
.host-card .host-name { font-weight: 650; font-size: 1rem; }
.host-card .host-addr { font-size: 0.76rem; color: var(--text-faint); font-family: var(--mono); }
.host-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.host-metric .mlabel { font-size: 0.7rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.host-metric .mvalue { font-size: 1.05rem; font-weight: 600; }
.host-foot { display: flex; gap: 12px; margin-top: 12px; font-size: 0.78rem; color: var(--text-dim); flex-wrap: wrap; }

/* Graphiques */
.chart-box { position: relative; height: 190px; }
.chart-box canvas { width: 100%; height: 100%; display: block; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.78rem; color: var(--text-dim); margin-top: 6px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-size: 0.76rem;
  box-shadow: var(--shadow);
  white-space: nowrap;
  z-index: 5;
}

/* Jauges circulaires */
.gauge { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.gauge-value { font-size: 1.25rem; font-weight: 650; line-height: 1.1; }
.gauge-label { font-size: 0.68rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.gauge-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-around; }

/* Listes de barres comparatives */
.bar-list { display: flex; flex-direction: column; gap: 9px; }
.bar-line-head { display: flex; justify-content: space-between; gap: 10px; font-size: 0.8rem; margin-bottom: 3px; }

/* Fiche explicative d'une alerte */
.alert-help { border-left: 3px solid var(--accent); padding-left: 12px; margin: 10px 0; }
.alert-help dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); margin-top: 8px; }
.alert-help dd { margin: 2px 0 0; font-size: 0.88rem; }
.alert-row-detail { background: var(--bg-soft); }
.help-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 0.68rem;
  cursor: help;
  flex-shrink: 0;
}
.help-dot:hover { border-color: var(--accent); color: var(--accent); }

/* Bloc de code copiable (jetons d'API, exemples) */
.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-all;
  position: relative;
}

/* Explorateur de fichiers */
.breadcrumb { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-family: var(--mono); font-size: 0.84rem; }
.breadcrumb button { background: transparent; border: none; padding: 2px 5px; color: var(--accent); }
.breadcrumb span { color: var(--text-faint); }
.file-row td { padding: 6px 10px; }
.file-name { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.file-name:hover { color: var(--accent); }
.file-icon { width: 16px; text-align: center; color: var(--text-faint); }
.editor textarea { min-height: 55vh; font-size: 0.82rem; line-height: 1.45; white-space: pre; overflow-wrap: normal; }
.drop-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 16px; text-align: center; color: var(--text-faint); }
.drop-zone.over { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* Terminal */
.term-wrap { background: #05070a; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; height: 62vh; }
.term-wrap .xterm { height: 100%; }

/* Console de sortie (tâches, logs) */
.console {
  background: #05070a;
  color: #d5dee9;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 55vh;
  overflow-y: auto;
}

/* ---------------------------------------------------------------------
   6. Mobile
   --------------------------------------------------------------------- */
.menu-toggle { display: none; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .brand { padding: 12px 14px; }
  .brand small { display: none; }
  .nav { display: flex; padding: 6px; gap: 4px; }
  .nav a { white-space: nowrap; padding: 8px 10px; }
  .nav-section { display: none; }
  .sidebar-footer { display: none; }
  .content { padding: 16px 14px 50px; }
  .host-metrics { grid-template-columns: repeat(3, 1fr); }
  .codes-grid { grid-template-columns: 1fr; }
}
