/* styles.css — habillage de l'enrôlement + historique.
   Thème sombre, mobile-first. Rester self-hosted (CSP script/style 'self'). */

:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --card: #121821;
  --card-2: #171f2b;
  --text: #e6edf3;
  --muted: #8b98a5;
  --border: #223040;
  --red: #e5484d;
  --green: #30a46c;
  --amber: #f5a623;
  --blue: #4f9cf9;
}

* { box-sizing: border-box; }

/* L'attribut `hidden` doit toujours cacher : une règle auteur posant un
   `display` (ex. .reenable { display:flex }) écrase sinon le [hidden] de la
   feuille navigateur, rendant l'élément visible malgré le JS. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain; /* calme le rebond natif -> pull-to-refresh custom */
}

.card {
  max-width: 640px;
  margin: 0 auto;
}

h1 {
  font-size: 1.4rem;
  margin: 8px 0 20px;
}

/* --- Enrôlement --- */
button {
  appearance: none;
  border: 0;
  border-radius: 10px;
  background: var(--blue);
  color: #05121f;
  font-weight: 600;
  font-size: 1rem;
  padding: 14px 20px;
  width: 100%;
  cursor: pointer;
}
button:disabled { opacity: .5; }

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  margin-top: 10px;
}
.hint { color: var(--muted); font-size: .8rem; margin-top: 8px; }

#install-help ol { padding-left: 20px; }
#install-help em { color: var(--blue); font-style: normal; font-weight: 600; }
#enable-status { color: var(--muted); font-size: .9rem; }

/* --- Bannière (ré)activation des notifications --- */
.reenable {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px;
  font-size: .9rem; color: var(--muted);
}
.reenable button { width: auto; padding: 8px 14px; font-size: .9rem; }
#reenable-status { color: var(--muted); }

/* --- Pull-to-refresh --- */
.ptr {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 50px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: .85rem;
  opacity: 0; transition: opacity .15s ease;
  z-index: 5; pointer-events: none;
}
.ptr.visible { opacity: 1; }
.ptr.armed { color: var(--blue); font-weight: 600; }

/* --- Filtres --- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 14px; }
.filter-group {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding-right: 10px; border-right: 1px solid var(--border);
}
.filter-group:last-child { border-right: 0; padding-right: 0; }
.chip {
  appearance: none; width: auto;
  border: 1px solid var(--border); background: var(--card);
  color: var(--muted); border-radius: 999px;
  padding: 5px 12px; font-size: .8rem; font-weight: 500;
}
.chip.active { background: var(--blue); color: #05121f; border-color: var(--blue); font-weight: 600; }
.no-match { color: var(--muted); }
.alert-wrap.filtered-out { display: none; }

/* --- Historique --- */
.alerts { list-style: none; margin: 0; padding: 0; }

/* Sections Problèmes / Résolus */
.group { margin-bottom: 20px; }
.group:last-child { margin-bottom: 0; }
.group-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 0 0 8px;
}
.group-head h2 {
  margin: 0;
  font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
}
.group-count {
  display: inline-block; margin-left: 4px;
  background: #1c2836; color: var(--muted);
  border-radius: 999px; padding: 1px 7px;
  font-size: .7rem; letter-spacing: 0;
}
.group-head form { margin: 0; }
.clear-resolved {
  width: auto; padding: 5px 11px;
  font-size: .74rem; font-weight: 600;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
}
.clear-resolved:hover { border-color: var(--red); color: var(--red); }
.badges { display: inline-flex; align-items: center; gap: 6px; }
.src {
  font-size: .68rem; color: var(--muted);
  background: #1c2836; border-radius: 6px; padding: 2px 7px; white-space: nowrap;
}

/* Wrapper de swipe : masque le bouton rouge derrière, le contenu glisse dessus */
.alert-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  margin-bottom: 12px;
}
.alert-wrap.removing {
  transition: opacity .2s ease, transform .2s ease, max-height .25s ease, margin .25s ease;
  opacity: 0;
  transform: translateX(-100%);
  max-height: 0;
  margin-bottom: 0;
}

.swipe-delete {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: var(--red);
  color: #fff;
  font-weight: 600;
  font-size: .9rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 30px;
}
/* Repère "relâcher = supprimer" quand le swipe dépasse le seuil de suppression auto */
.alert-wrap.armed .swipe-delete { background: #c5383c; }

.alert {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 12px;
  padding: 12px 14px;
  transition: transform .2s ease;
  will-change: transform;
  touch-action: pan-y; /* le scroll vertical reste natif ; l'horizontal est géré en JS */
}

/* Rouge = problème, Vert = résolu */
.alert.status-problem  { border-left-color: var(--red); }
.alert.status-resolved { border-left-color: var(--green); background: var(--card-2); }

.alert-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.alert-head time { color: var(--muted); font-size: .8rem; white-space: nowrap; }

/* Badge de sévérité (échelle Zabbix 0..5) */
.sev {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 3px 8px;
  border-radius: 999px;
  background: #2a3644;
  color: var(--text);
}
.sev-0 .sev, .sev-1 .sev { background: #2a3644; color: var(--muted); }
.sev-2 .sev { background: rgba(79,156,249,.18); color: var(--blue); }
.sev-3 .sev { background: rgba(245,166,35,.18); color: var(--amber); }
.sev-4 .sev { background: rgba(229,72,77,.18);  color: #ff8a8d; }
.sev-5 .sev { background: var(--red); color: #fff; }

/* Un item résolu : sévérité en vert pour renforcer le signal */
.alert.status-resolved .sev { background: rgba(48,163,108,.18); color: #57d09a; }

/* Bouton × de suppression au clic — pour souris/trackpad (le tactile a le swipe) */
.row-delete { display: none; }
@media (hover: hover) and (pointer: fine) {
  .row-delete {
    position: absolute; top: 8px; right: 8px;
    display: flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; padding: 0;
    border: 0; border-radius: 50%;
    background: rgba(255, 255, 255, .07); color: var(--muted);
    font-size: 1.1rem; line-height: 1; cursor: pointer;
    opacity: 0; transition: opacity .12s ease, background .12s ease, color .12s ease;
  }
  .alert:hover .row-delete { opacity: 1; }
  .row-delete:hover { background: var(--red); color: #fff; }

  /* Au survol le × occupe le coin haut-droit : on décale l'heure vers la
     gauche pour qu'il ne la recouvre pas (transition synchro avec le fondu). */
  .alert-head time { transition: margin-right .12s ease; }
  .alert:hover .alert-head time { margin-right: 30px; }
}

.alert-title { font-weight: 600; }
.alert-body {
  color: var(--muted);
  margin-top: 4px;
  white-space: pre-line;      /* préserve les retours à la ligne du détail Zabbix */
  overflow-wrap: anywhere;    /* évite tout débordement horizontal */
}

.resolved {
  display: inline-block;
  margin-top: 8px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--green);
}

/* --- Desktop (souris / pointeur précis) : alertes plus compactes ----------
   Le mobile-first (iPhone, tactile) reste inchangé ; on ne resserre QUE hors
   tactile, où la taille pensée pour le pouce paraît trop grosse. --- */
@media (hover: hover) and (pointer: fine) {
  h1 { font-size: 1.15rem; }
  .alert { padding: 9px 12px; font-size: .82rem; }
  .alert-head { margin-bottom: 3px; }
  .alert-head time { font-size: .7rem; }
  .alert-title { font-size: .88rem; }
  .alert-body { margin-top: 2px; }
  .alert-wrap { margin-bottom: 9px; }
  .sev { font-size: .66rem; padding: 2px 7px; }
}

/* --- Effacer l'historique --- */
.toolbar { text-align: right; margin: -4px 0 14px; }

.danger-link {
  color: var(--red);
  font-size: .85rem;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.danger-link:hover { border-bottom-color: var(--red); }

.confirm {
  background: var(--card);
  border: 1px solid var(--red);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}
.confirm p { margin-top: 0; }
.confirm form { margin: 0; }

button.danger {
  background: var(--red);
  color: #fff;
}

.cancel {
  display: inline-block;
  margin-top: 10px;
  color: var(--muted);
  text-decoration: none;
}
.cancel:hover { color: var(--text); }
