:root {
  --bg: #0f1419;
  --panel: #1a2129;
  --border: #2a333d;
  --fg: #e6edf3;
  --muted: #8b98a5;
  --accent: #3b82f6;
  --ok: #22c55e;
  --ko: #ef4444;
  --unknown: #9ca3af;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand { font-size: 1.25rem; font-weight: 700; text-decoration: none; color: var(--fg); display: inline-flex; align-items: center; gap: .5rem; }
.brand .logo { height: 32px; width: auto; }

main { max-width: 960px; margin: 0 auto; padding: 1.5rem; }

a { color: var(--accent); }

h1 { display: flex; align-items: center; gap: .6rem; }

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--fg); }
th.sortable::after { content: "↕"; opacity: .35; margin-left: .35rem; font-size: .85em; }
th.sortable[data-dir="asc"]::after { content: "▲"; opacity: .9; }
th.sortable[data-dir="desc"]::after { content: "▼"; opacity: .9; }
.url { color: var(--muted); font-size: .9rem; word-break: break-all; }
.err { color: var(--ko); font-size: .85rem; }
.meta { color: var(--muted); font-size: .9rem; }
.empty { color: var(--muted); }

.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  color: #0b0e12;
}
.badge.ok { background: var(--ok); }
.badge.ko { background: var(--ko); color: #fff; }
.badge.slow { background: #f59e0b; }
.badge.unknown { background: var(--unknown); }

.btn {
  display: inline-block;
  padding: .5rem .9rem;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border: none;
  font-size: .9rem;
  cursor: pointer;
}
.btn.secondary { background: transparent; border: 1px solid var(--border); color: var(--fg); }

.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.actions form { display: inline; margin: 0; }
.link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: .9rem;
}
.link.danger { color: var(--ko); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.card label { display: flex; flex-direction: column; gap: .35rem; font-size: .9rem; color: var(--muted); }
.card label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--fg); }
.card input[type="text"],
.card input[type="url"],
.card input[type="email"],
.card input[type="number"],
.card input[type="password"],
.card input:not([type]) {
  padding: .55rem .7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: .95rem;
}
.row { display: flex; gap: .75rem; }

/* Formulaire large multi-colonnes (création / édition d'app) */
.form-card { max-width: 820px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.25rem; }
.form-grid > label { display: flex; flex-direction: column; gap: .35rem; margin: 0; }
.form-grid .span-2 { grid-column: 1 / -1; }
.color-field { display: flex; align-items: center; gap: .5rem; }
.color-field input[type="color"] {
  width: 44px;
  height: 38px;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
}
.color-field input:not([type="color"]) { flex: 1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.errors {
  background: rgba(239, 68, 68, .12);
  border: 1px solid var(--ko);
  border-radius: 8px;
  padding: .75rem 1rem;
  color: var(--ko);
  list-style: none;
  margin: 0 0 1rem;
}

/* --- navigation --- */
header nav { display: flex; gap: 1rem; margin-right: auto; margin-left: 1.5rem; }
header nav a { color: var(--muted); text-decoration: none; font-size: .95rem; }
header nav a:hover { color: var(--fg); }

/* --- panneau ressources serveur --- */
.sys-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem 2rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin: 1rem 0 1.5rem;
}
.sys-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: .4rem;
}
.sys-name { font-weight: 600; font-size: .9rem; }
.sys-val { color: var(--muted); font-size: .8rem; }
.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 999px; transition: width .3s; }
.bar-fill.good { background: var(--ok); }
.bar-fill.warn { background: #f59e0b; }
.bar-fill.bad { background: var(--ko); }

/* --- dashboard --- */
/* Mode "wallboard" : pleine largeur pour un affichage permanent en open space,
   un maximum de cartes visibles d'un seul coup d'œil. */
main.board { max-width: none; }

/* En-tête du dashboard : mascotte à gauche, titre + sous-titre + ressources
   (disque / RAM) à droite. Sur le dashboard la mascotte fixe globale est
   masquée (elle vit ici, dans l'en-tête). */
main.board ~ .mascot { display: none; }
.board-header { display: flex; align-items: center; gap: 1.5rem; margin-bottom: 1rem; }
.board-mascot { flex: 0 0 auto; width: 150px; height: auto; }
.board-header-main { flex: 1 1 auto; min-width: 0; }
.board-header-main h1 { margin: 0; }
.board-header-main .meta { margin: .25rem 0 0; }
.board-header-main .sys-panel { margin: .85rem 0 0; }

/* Alerte ressource (disque / RAM > 80%) : bannière bien visible (wallboard). */
.res-alert {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin: 0 0 1rem;
  padding: .85rem 1.15rem;
  border-radius: 10px;
  border: 1px solid var(--ko);
  border-left: 6px solid var(--ko);
  background: rgba(239, 68, 68, .12);
  color: var(--fg);
  font-size: 1.05rem;
  animation: pulse-down 1.8s ease-in-out infinite;
}
.res-alert .ra-icon { font-size: 1.4rem; line-height: 1; }
.res-alert strong { color: var(--ko); }
@media (prefers-reduced-motion: reduce) { .res-alert { animation: none; } }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: .75rem;
  margin-top: 1rem;
}
/* card-wrap, card-link et card remplissent toute la hauteur de la rangée :
   les cartes d'une même rangée ont la même hauteur et le bouton de retest
   (ancré en bas de card-wrap) reste TOUJOURS à l'intérieur de la carte. */
.card-wrap { position: relative; display: flex; }
.card-link { display: flex; flex: 1 1 auto; min-width: 0; text-decoration: none; color: inherit; }
.stat-card { padding: .85rem; gap: .55rem; max-width: none; border-left: 3px solid var(--border); flex: 1 1 auto; }

/* Accent de statut sur le bord gauche : couleur lisible de loin, scan rapide. */
.stat-card.status-ok { border-left-color: var(--ok); }
.stat-card.status-slow { border-left-color: #f59e0b; }
.stat-card.status-ko { border-left-color: var(--ko); }
.stat-card.status-unknown { border-left-color: var(--unknown); }

/* Bouton de retest rapide, en surimpression sur la carte */
.card-refresh { position: absolute; bottom: .5rem; right: .5rem; z-index: 2; margin: 0; }
.card-refresh button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15, 20, 25, .55);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: color .2s, border-color .2s, transform .4s;
}
.card-refresh button:hover { color: var(--fg); border-color: var(--accent); }
.card-refresh button:active { transform: rotate(180deg); }

/* Couleur de fond de carte (peinte derrière l'image) */
.stat-card.has-color { background-color: var(--card-color); }

/* Image de fond de carte (assombrie pour garder le texte lisible) */
.stat-card.has-bg {
  background-image:
    linear-gradient(rgba(15, 20, 25, .80), rgba(15, 20, 25, .90)),
    var(--card-bg);
  background-size: cover;
  background-position: center;
}

/* App en erreur : bordure rouge + pulsation stylisée */
.stat-card.is-down {
  border-color: var(--ko);
  animation: pulse-down 1.6s ease-in-out infinite;
}
@keyframes pulse-down {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
  50% { box-shadow: 0 0 0 5px rgba(239, 68, 68, .28); }
}
@media (prefers-reduced-motion: reduce) {
  .stat-card.is-down { animation: none; box-shadow: 0 0 0 2px rgba(239, 68, 68, .3); }
}
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-head .name { font-weight: 600; }

.stat-row { display: flex; gap: 1.5rem; }
.stat { display: flex; flex-direction: column; }
.stat .val { font-size: 1.4rem; font-weight: 700; }
.stat .val.good { color: var(--ok); }
.stat .val.warn { color: #eab308; }
.stat .val.bad { color: var(--ko); }
.stat .lbl { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

.spark { width: 100%; height: 30px; color: var(--accent); display: block; }
.card-url {
  margin: 0;
  color: var(--muted);
  font-size: .8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ip-ok { color: var(--ok); font-weight: 600; }
.ip-warn { color: var(--ko); font-weight: 700; }
.card-ip { margin: 0; color: var(--muted); font-size: .68rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.detail-stats { margin: 1rem 0 0; }

/* en-tête détail : stats à gauche, aperçu à droite */
.detail-top {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin: 1rem 0;
}
.detail-main { flex: 1 1 280px; }
.detail-preview { flex: 0 0 auto; width: 280px; max-width: 100%; margin: 0; }
.detail-preview .preview-img,
.detail-preview .preview-fallback {
  width: 100%;
  height: 158px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  object-fit: cover;
  object-position: top;
  display: block;
}
.detail-preview .preview-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .85rem;
}
.detail-preview figcaption {
  margin-top: .4rem;
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.latency-chart {
  width: 100%;
  height: 120px;
  color: var(--accent);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: .5rem;
}
/* Échelle de temps sous la courbe : repères régulièrement espacés. */
.latency-axis {
  display: flex;
  justify-content: space-between;
  margin-top: .25rem;
  font-size: .72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Bannière "OK/KO depuis X" — grosse, lisible en un coup d'œil. */
.state-banner {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .25rem .9rem;
  margin: .75rem 0 1rem;
  padding: .9rem 1.2rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  border-left: 6px solid var(--unknown);
  background: var(--panel);
}
.state-banner .sb-status { font-size: 2rem; font-weight: 800; letter-spacing: .02em; }
.state-banner .sb-dur { font-size: 1.6rem; font-weight: 700; }
.state-banner .sb-meta { color: var(--muted); font-size: .85rem; margin-left: auto; }
.state-banner.is-ok { border-left-color: var(--ok); }
.state-banner.is-ok .sb-status { color: var(--ok); }
.state-banner.is-ko {
  border-left-color: var(--ko);
  background: rgba(239, 68, 68, .08);
}
.state-banner.is-ko .sb-status { color: var(--ko); }
.state-banner.is-unknown .sb-status { color: var(--unknown); }

/* --- settings / infos --- */
.card h2 { margin: .5rem 0 0; font-size: 1rem; }
.card h2:first-child { margin-top: 0; }
.hint { color: var(--muted); font-size: .8rem; font-weight: 400; }
.warn-note {
  font-size: .85rem;
  color: #f59e0b;
  background: rgba(245, 158, 11, .1);
  border: 1px solid rgba(245, 158, 11, .4);
  border-radius: 8px;
  padding: .5rem .75rem;
  margin: 0;
}
.test-form { margin-top: 1rem; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

/* --- page réglages : sections lisibles + barre d'action collante --- */
.settings-form { display: flex; flex-direction: column; gap: 1rem; }
.settings-section { max-width: none; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.25rem; }
.settings-grid > label { margin: 0; }
.settings-grid .span-2 { grid-column: 1 / -1; }

/* Barre d'actions toujours visible (collée en bas du viewport). */
.settings-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: .9rem 1.1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, .35);
}
.settings-actions .hint { flex: 1 1 220px; }
@media (max-width: 640px) { .settings-grid { grid-template-columns: 1fr; } }

.flash {
  border-radius: 8px;
  padding: .6rem 1rem;
  margin: 0 0 1rem;
  font-size: .9rem;
}
.flash.ok { background: rgba(34, 197, 94, .12); border: 1px solid var(--ok); color: var(--ok); }
.flash.warn { background: rgba(245, 158, 11, .12); border: 1px solid #f59e0b; color: #f59e0b; }
.flash.bad { background: rgba(239, 68, 68, .12); border: 1px solid var(--ko); color: var(--ko); }

/* --- zone utilisateur (header) --- */
.user { color: var(--muted); font-size: .85rem; margin-left: 1rem; }
.user a { color: var(--accent); }

/* --- page de login --- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
.login-logo { width: 72px; height: auto; margin-bottom: .5rem; }
.login-card h1 { justify-content: center; margin: .25rem 0; }
.login-sub { color: var(--muted); margin-top: 0; margin-bottom: 1.5rem; }
.login-note { color: var(--muted); font-size: .8rem; margin-top: 1rem; }
.google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  width: 100%;
  padding: .7rem 1rem;
  border-radius: 10px;
  background: #fff;
  color: #1f2937;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--border);
  transition: filter .15s;
}
.google-btn:hover { filter: brightness(.95); }

/* --- mascotte fixe bas-gauche --- */
/* Placée DERRIÈRE le contenu (z-index négatif) : décor en filigrane qui ne
   masque jamais une carte, quel que soit le nombre de colonnes ou l'écran. */
.mascot {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 220px;
  max-width: 22vw;       /* ne déborde pas sur petits écrans */
  height: auto;
  z-index: -1;
  opacity: .85;
  pointer-events: none;
}

/* --- formulaire : outils source / test --- */
.tools { display: flex; gap: .5rem; flex-wrap: wrap; }
#source-box { display: flex; flex-direction: column; gap: .5rem; }
.source-view {
  width: 100%;
  height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem;
  padding: .6rem .7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
  white-space: pre;
}
.test-result {
  padding: .55rem .8rem;
  border-radius: 8px;
  font-size: .9rem;
  border: 1px solid var(--border);
}
.test-result.ok { background: rgba(34, 197, 94, .12); border-color: var(--ok); color: var(--ok); }
.test-result.bad { background: rgba(239, 68, 68, .12); border-color: var(--ko); color: var(--ko); }

.prose { max-width: 760px; line-height: 1.6; }
.prose h2 { margin-top: 1.25rem; }
.prose ul { padding-left: 1.2rem; }
.prose li { margin: .25rem 0; }
.prose code { background: var(--bg); padding: .1rem .35rem; border-radius: 4px; }

/* --- tableaux scrollables (mobile) --- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* garde des colonnes lisibles : scroll horizontal plutôt que colonnes écrasées */
.table-wrap table { min-width: 600px; }
.table-wrap .url { white-space: nowrap; }

/* --- responsive mobile --- */
@media (max-width: 640px) {
  header {
    flex-wrap: wrap;
    row-gap: .6rem;
    padding: .7rem 1rem;
  }
  .brand { font-size: 1.1rem; }
  .brand .logo { height: 26px; }
  header nav {
    order: 3;
    flex-basis: 100%;
    margin-left: 0;
    gap: .9rem;
    flex-wrap: wrap;
  }
  .user {
    order: 4;
    flex-basis: 100%;
    margin-left: 0;
  }
  header .btn { padding: .45rem .7rem; font-size: .85rem; }

  main { padding: 1rem; }
  h1 { font-size: 1.4rem; }

  /* dashboard : une carte par ligne */
  .cards { grid-template-columns: 1fr; }
  .stat-row { gap: 1.25rem; }

  /* en-tête dashboard compact (mascotte plus petite, reste à gauche) */
  .board-header { gap: .9rem; align-items: flex-start; }
  .board-mascot { width: 80px; }

  /* tableaux : police compacte, scroll horizontal via .table-wrap */
  table { font-size: .85rem; }
  th, td { padding: .5rem .55rem; }
  .actions { gap: .4rem; }

  /* formulaires pleine largeur */
  .card { max-width: none; padding: 1.25rem; }
  .row { flex-wrap: wrap; }

  /* mascotte réduite (et toujours derrière le contenu) pour ne pas manger l'écran */
  .mascot { width: 110px; opacity: .85; }

  /* login */
  .login-card { padding: 1.75rem 1.25rem; }
}
