:root {
  color-scheme: dark light;
  --bg: #0b1626;
  --bg-card: #15233a;
  --bg-card-soft: #1c2e4a;
  --fg: #e7eef8;
  --fg-muted: #8aa0bd;
  --accent: #ff8a3d;
  --accent-soft: rgba(255, 138, 61, 0.15);
  --danger: #ff5260;
  --ok: #3ad29f;
  --radius: 12px;
  --maxw: 720px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: env(safe-area-inset-top);
}

/* Brand header — single-view app, no primary nav. */
.brand {
  display: block;
  text-align: center;
  padding: 0.8rem 0.75rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand__plus { color: var(--accent); }

/* Notification bell — hidden until push.js confirms support + server keys. */
.push-toggle {
  position: absolute;
  top: 50%;
  right: 0.75rem;
  transform: translateY(-50%);
  margin-top: calc(env(safe-area-inset-top) / 2);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
}
.push-toggle--on { color: var(--accent); background: var(--accent-soft); }
.push-toggle:disabled { opacity: 0.5; }
/* display:flex above would defeat the UA rule for [hidden] — restate it. */
.push-toggle[hidden] { display: none; }

/* Sub-tabs inside a page — secondary navigation (ex: En cours / Clôturées). */
.subtabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: -1rem -1rem 0;          /* span the app-main horizontal padding */
  background: var(--bg-card);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  gap: 1px;                        /* hairline separator between the two */
  background-color: rgba(255, 255, 255, 0.06); /* shows through as the separator line */
}
.subtab {
  text-align: center;
  padding: 0.7rem 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fg-muted);
  background: var(--bg-card);
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.subtab:hover { color: var(--fg); }
.subtab:active { background: var(--bg-card-soft); }
.subtab--active {
  color: var(--accent);
  background: var(--accent-soft);
  border-bottom-color: var(--accent);
}
.subtab__count {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 0.45em;
  margin-left: 0.4em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg-muted);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
.subtab--active .subtab__count {
  background: rgba(255, 138, 61, 0.2);   /* accent-soft, more saturated */
  color: var(--accent);
}

/* --- Detail-page tabs (3 sections of one intervention) ----------------
   CSS-only: 3 radios live as siblings of the 3 panels; the active panel
   is revealed via `input:checked ~ .detail-panel--X`. .app-main is a
   flex column with gap, so we apply the gap inside each visible panel
   instead of relying on its own gap (hidden panels would otherwise leave
   a phantom gap above them). */
.detail-tabs__radio {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0; height: 0;
}
.detail-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0 -1rem;
  gap: 1px;
  background-color: rgba(255, 255, 255, 0.06);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.detail-tab {
  text-align: center;
  padding: 0.7rem 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fg-muted);
  background: var(--bg-card);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.detail-tab:hover { color: var(--fg); }
.detail-tab:active { background: var(--bg-card-soft); }
.detail-tabs__radio:focus-visible + .detail-tabs > .detail-tab,
.detail-tabs__radio:focus-visible ~ .detail-tabs .detail-tab {
  /* keyboard focus ring is on the radio itself — give it a visible cue */
  outline: none;
}
#dtab-info:checked ~ .detail-tabs label[for="dtab-info"],
#dtab-engins:checked ~ .detail-tabs label[for="dtab-engins"],
#dtab-mc:checked ~ .detail-tabs label[for="dtab-mc"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-bottom-color: var(--accent);
}
.detail-tab__count {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg-muted);
  font-size: 0.75rem;
  line-height: 1.4;
  vertical-align: 1px;
}
#dtab-mc:checked ~ .detail-tabs label[for="dtab-mc"] .detail-tab__count {
  background: var(--accent);
  color: var(--bg);
}
.detail-panel { display: none; }
#dtab-info:checked  ~ .detail-panel--info,
#dtab-engins:checked ~ .detail-panel--engins,
#dtab-mc:checked    ~ .detail-panel--mc {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Compact engin row used in the Informations tab. */
.engin-mini-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.engin-mini {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.engin-mini:last-child { border-bottom: none; }
.engin-mini__libelle {
  font-weight: 600;
  font-size: 0.93rem;
}
.engin-mini__centre {
  font-weight: 400;
  color: var(--fg-muted);
  font-size: 0.85rem;
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.app-footer {
  padding: 1rem;
  text-align: center;
  color: var(--fg-muted);
}

/* --- Page heading --- */
.page-head h1 { margin: 0 0 0.2rem; font-size: 1.5rem; }
.page-head__sub { margin: 0; color: var(--fg-muted); font-size: 0.9rem; }
/* --- Interventions list --- */
.loading, .empty, .meta {
  color: var(--fg-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 0.6rem 0;
}
.meta { font-size: 0.78rem; }

.inter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.inter-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.06s ease;
}
.inter-card:active { transform: scale(0.995); }
.inter-card__link {
  display: block;
  padding: 0.85rem 0.9rem;
}
.inter-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.45rem;
}
.inter-card__nature {
  margin: 0 0 0.35rem;
  font-size: 1.0rem;
  font-weight: 600;
  line-height: 1.25;
}
.inter-card__loc {
  margin: 0 0 0.45rem;
  color: var(--fg-muted);
  font-size: 0.88rem;
}
.inter-card__loc strong { color: var(--fg); font-weight: 600; }
.inter-card__loc-detail { color: var(--fg-muted); }
.inter-card__time {
  font-size: 0.85rem;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.inter-card__engins {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.45rem;
}
.inter-card__engins > li {
  background: var(--bg-card-soft);
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-size: 0.78rem;
  display: inline-flex;
  gap: 0.4rem;
  align-items: baseline;
}
.engin__lib { font-weight: 600; }
.engin__centre { color: var(--fg-muted); }

/* --- Status badges --- */
.status {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--bg-card-soft);
  color: var(--fg-muted);
  white-space: nowrap;
}
.status--sm {
  padding: 0.12rem 0.45rem;
  font-size: 0.66rem;
}

/* Intervention-level statuses (calmer palette). */
.status--en_cours { background: var(--accent-soft); color: var(--accent); }
.status--cloturee { background: rgba(58, 210, 159, 0.18); color: var(--ok); }
.status--differee { background: rgba(143, 188, 255, 0.18); color: #8fbcff; }

/* Engin-level statuses — colour matrix specified by the user. */
.status--alert  { background: #8b5cf6; color: #ffffff; }              /* violet */
.status--route  { background: #dc2626; color: #ffffff; }              /* rouge / blanc */
.status--lieux  { background: #dc2626; color: #000000; }              /* rouge / noir */
.status--hop    { background: #1e3a8a; color: #ffffff; }              /* bleu foncé / blanc */
.status--ahop,
.status--arrivhop,
.status--arrh   { background: #1e3a8a; color: #000000; }              /* bleu foncé / noir */
.status--dispr  { background: #7dd3fc; color: #0b1626; }              /* bleu ciel */
.status--dispo  { background: #22c55e; color: #0b1626; }              /* vert vif / texte sombre */
.status--indis  { background: rgba(255, 255, 255, 0.08); color: var(--fg-muted); }

/* --- Detail page --- */
.back-link {
  color: var(--fg-muted);
  font-size: 0.9rem;
  display: inline-block;
  padding: 0.25rem 0;
}
.detail-head {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-bottom: 0.4rem;
}
.detail-head h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.25;
}
.detail-head__id {
  margin: 0;
  color: var(--fg-muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.detail-block {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.detail-block__title {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
  color: var(--accent);
  letter-spacing: 0.03em;
}
.detail-block__sub {
  margin: 0;
  color: var(--fg-muted);
}
.detail-block__text {
  margin: 0;
  font-size: 0.93rem;
  line-height: 1.45;
}
.detail-block__text--muted { color: var(--fg-muted); }

.engagement {
  background: var(--bg-card-soft);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.engagement + .engagement { margin-top: 0.5rem; }
.engagement__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem;
}
.engagement__libelle {
  font-weight: 600;
}
.engagement__centre {
  color: var(--fg-muted);
  font-weight: 400;
  font-size: 0.85rem;
}
.engagement__effectif {
  margin: 0;
  color: var(--fg-muted);
  font-size: 0.82rem;
}
.crew-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.crew-list > li {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.45rem;
  font-size: 0.88rem;
}
.crew__role {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.55rem;
}
.timeline__step {
  background: var(--bg-card);
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  font-size: 0.78rem;
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
}
.timeline__t {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Main courante journal: chronological list of events, most-recent first. */
.historique {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.historique__entry {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  border-left: 3px solid var(--accent-soft);
}
.historique__head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.7rem;
  align-items: baseline;
  font-size: 0.78rem;
  margin-bottom: 0.25rem;
}
.historique__t {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Compteur de republication. Stratus réémet ses lignes d'avancement ; elles
   sont repliées, et ceci dit combien de fois — masquer la répétition sans la
   nier. */
.historique__repeats {
  margin-left: .25rem;
  font-size: .68rem;
  font-weight: 600;
  color: var(--neutral-600, #75798c);
  font-variant-numeric: tabular-nums;
}
.historique__t--unknown { color: var(--fg-muted); }
.historique__centre { color: var(--fg-muted); }
.historique__text {
  margin: 0;
  font-size: 0.88rem;
  white-space: pre-wrap;
  color: var(--fg);
}

/* --- Login (PIN) --- */
.login {
  display: flex;
  justify-content: center;
  padding-top: 12vh;
}
.login-card {
  width: 100%;
  max-width: 22rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.6rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  text-align: center;
}
.login-card__title { margin: 0; font-size: 1.3rem; }
.login-card__sub { margin: 0; color: var(--fg-muted); font-size: 0.9rem; }
.login-card__error {
  margin: 0;
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 600;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.pin-input {
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 1.6rem;
  text-align: center;
  letter-spacing: 0.6rem;
  background: var(--bg-card-soft);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  outline: none;
}
.pin-input:focus { border-color: var(--accent); }
.pin-input--error { border-color: var(--danger); }
.login-submit {
  padding: 0.85rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}
.login-submit:active { filter: brightness(0.92); }
.login-submit:disabled,
.pin-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
