/* SME Shield — console de la plateforme (même identité visuelle que le capteur).
   Palette « salle de contrôle en plein jour » : brume bleutée, encre marine,
   le flux sortant en bleu profond, l'entrant en bleu clair, la gravité en couleurs signal. */
:root {
  --mist: #EEF2F6;
  --paper: #FFFFFF;
  --ink: #14213D;
  --ink-soft: #4E5D75;
  --rule: #D3DCE7;
  --out: #2F5DA8;
  --in: #8FA9CF;
  --sev-info: #7A8699;
  --sev-low: #2A8C82;
  --sev-medium: #B87A0B;
  --sev-high: #C8432B;
  --sev-critical: #9B1D5A;
  --ok: #2A8C82;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --r-big: 14px;
  --r-small: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--mist);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
code { font-size: .92em; background: #E3EAF2; padding: 1px 5px; border-radius: 4px; word-break: break-all; }
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: .6rem; }
.hint { color: var(--ink-soft); margin: 0 0 1rem; max-width: 70ch; }

:focus-visible { outline: 3px solid var(--out); outline-offset: 2px; border-radius: 4px; }

/* ---------------------------------------------------------------- boutons */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: var(--r-small);
  border: 1px solid var(--ink); background: var(--paper); color: var(--ink); padding: .5rem 1rem;
}
.btn.primary { background: var(--ink); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn.ghost:hover { color: var(--ink); background: #E3EAF2; }
.btn.small { padding: .3rem .7rem; font-size: .88rem; }
.btn.danger { border-color: var(--sev-high); color: var(--sev-high); }
.btn:disabled { opacity: .5; cursor: default; }

/* ------------------------------------------------------------- connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-box { background: var(--paper); border-radius: var(--r-big); padding: 2rem; width: min(440px, 100%);
  border: 1px solid var(--rule); }
.login-box .brand { font-size: 1.6rem; margin-bottom: .75rem; }
.login-box label { display: block; font-weight: 600; margin: 1rem 0 .3rem; }
.login-box input { width: 100%; font: inherit; padding: .6rem .7rem; border: 1px solid var(--rule);
  border-radius: var(--r-small); }
.login-error { color: var(--sev-high); min-height: 1.5em; margin: .5rem 0; }

/* -------------------------------------------------------------- en-tête */
.top {
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  padding: .9rem clamp(1rem, 3vw, 2.5rem); background: var(--paper); border-bottom: 1px solid var(--rule);
}
.ident { display: flex; align-items: baseline; gap: .75rem; margin-right: auto; }
.brand { font-family: var(--display); font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.sensor-name { color: var(--ink-soft); }
.health { display: inline-flex; align-items: center; gap: .5rem; font-weight: 600; padding: .3rem .8rem;
  border-radius: 999px; background: #E3EAF2; }
.health::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; background: var(--sev-info); }
.health.healthy::before { background: var(--ok); }
.health.degraded { background: #F6EBD6; } .health.degraded::before { background: var(--sev-medium); }
.health.offline { background: #F6DEDA; } .health.offline::before { background: var(--sev-high); }
.learning { color: var(--ink-soft); font-size: .9rem; display: flex; align-items: center; gap: .5rem; }
.learning .bar { width: 90px; height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; }
.learning .bar i { display: block; height: 100%; background: var(--out); }

main { padding: 1.5rem clamp(1rem, 3vw, 2.5rem) 4rem; max-width: 1400px; margin: 0 auto; }

/* --------------------------------------------------- la rivière (héros) */
.river { background: var(--paper); border-radius: var(--r-big); padding: 1.25rem 1.25rem .75rem;
  border: 1px solid var(--rule); }
.river-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .75rem; }
.rates { display: flex; gap: 1.5rem; color: var(--ink-soft); }
.rate strong { color: var(--ink); font-size: 1.05rem; margin-left: .35rem; }
.rate .key { display: inline-block; width: .75rem; height: .75rem; border-radius: 2px; margin-right: .4rem;
  vertical-align: -1px; }
.rate.out .key { background: var(--out); }
.rate.in .key { background: var(--in); }
.chart { position: relative; margin-top: .5rem; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .axis-label { fill: var(--ink-soft); font-size: 12px; font-family: var(--font); }
.chart .scale-label { fill: var(--ink-soft); font-size: 11px; font-family: var(--font); }
.chart .marker { cursor: pointer; stroke: var(--paper); stroke-width: 2; }
.chart .marker:focus-visible { outline: none; stroke: var(--ink); stroke-width: 3; }
.chart .cursor { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: .85rem;
  padding: .45rem .65rem; border-radius: var(--r-small); white-space: nowrap; transform: translate(-50%, -110%); }
.chart-empty { color: var(--ink-soft); padding: 3rem 0; text-align: center; }

/* -------------------------------------------------------- chiffres clés */
.figures { display: grid; grid-template-columns: repeat(4, 1fr); margin: 1.5rem 0 1.25rem; }
.fig { padding: .25rem 1.25rem; border-left: 1px solid var(--rule); display: flex; flex-direction: column; }
.fig:first-child { border-left: 0; padding-left: .25rem; }
.fig-v { font-family: var(--display); font-size: 1.9rem; font-weight: 600; letter-spacing: -.02em; }
.fig-l { color: var(--ink-soft); font-size: .9rem; }
.sev-strip { display: flex; gap: .35rem; margin-top: .4rem; flex-wrap: wrap; }
.sev-chip { font-size: .78rem; font-weight: 600; padding: .05rem .45rem; border-radius: 4px; color: #fff; }

/* ---------------------------------------------------------------- onglets */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--rule); margin-bottom: 1.25rem; }
.tabs button { font: inherit; font-weight: 600; color: var(--ink-soft); background: none; border: 0;
  padding: .6rem 1rem; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs button .count { font-weight: 500; color: var(--ink-soft); margin-left: .3rem; }

.filters { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters label { display: flex; flex-direction: column; font-size: .85rem; color: var(--ink-soft); gap: .2rem; }
select, .drawer input, .drawer textarea {
  font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--r-small); padding: .4rem .55rem;
}

/* ------------------------------------------------------- liste d'alertes */
.alert-list { list-style: none; margin: 0; padding: 0; background: var(--paper); border-radius: var(--r-big);
  border: 1px solid var(--rule); overflow: hidden; }
.alert-list li + li { border-top: 1px solid var(--rule); }
.alert-row { display: grid; grid-template-columns: 6px 1fr auto; gap: 1rem; width: 100%; text-align: left;
  background: none; border: 0; font: inherit; color: inherit; padding: .85rem 1.1rem .85rem 0; cursor: pointer; }
.alert-row:hover { background: #F5F8FB; }
.alert-row .sev-bar { border-radius: 0 3px 3px 0; }
.alert-row .what { min-width: 0; }
.alert-row .title { font-weight: 600; }
.alert-row .who { color: var(--ink-soft); font-weight: 500; margin-left: .4rem; }
.alert-row .sum { color: var(--ink-soft); font-size: .92rem; margin-top: .15rem;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.alert-row .when { color: var(--ink-soft); font-size: .85rem; text-align: right; white-space: nowrap; }
.alert-row .when .sev-word { display: block; font-weight: 600; }
.alert-row.handled .title { color: var(--ink-soft); }
.more { text-align: center; margin: 1rem 0 0; }
.empty { padding: 2.5rem 1.5rem; color: var(--ink-soft); text-align: center; }

.sev-info { --sev: var(--sev-info); } .sev-low { --sev: var(--sev-low); } .sev-medium { --sev: var(--sev-medium); }
.sev-high { --sev: var(--sev-high); } .sev-critical { --sev: var(--sev-critical); }
.sev-bar, .sev-chip { background: var(--sev); }
.sev-word { color: var(--sev); }

/* ---------------------------------------------------------------- tables */
.grid { width: 100%; border-collapse: collapse; background: var(--paper); border-radius: var(--r-big);
  overflow: hidden; border: 1px solid var(--rule); }
.grid th { text-align: left; font-size: .85rem; font-weight: 600; color: var(--ink-soft);
  padding: .65rem .9rem; border-bottom: 1px solid var(--rule); }
.grid td { padding: .65rem .9rem; border-top: 1px solid #E8EDF3; vertical-align: top; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: #F5F8FB; }
.grid .num { text-align: right; }
.grid .sub { display: block; color: var(--ink-soft); font-size: .85rem; }
.tag { display: inline-block; font-size: .8rem; font-weight: 600; padding: .05rem .5rem; border-radius: 4px;
  background: #E3EAF2; color: var(--ink-soft); margin: 0 .25rem .2rem 0; }
.tag.warn { background: #F6EBD6; color: #7A5206; }
.tag.crit { background: #F3DCE7; color: var(--sev-critical); }
.tag.high { background: #F6DEDA; color: var(--sev-high); }
.tag.ok { background: #DCEFEC; color: #1E6B63; }

/* ------------------------------------------------------------- capteur */
.sensor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
.stats { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 1rem 0 0; }
.stats dt { color: var(--ink-soft); }
.stats dd { margin: 0; font-weight: 600; }
.reasons { margin: .5rem 0 0; padding-left: 1.1rem; }
.supp-list { list-style: none; padding: 0; margin: 0; }
.supp-list li { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-small);
  padding: .7rem .9rem; margin-bottom: .5rem; display: flex; gap: 1rem; justify-content: space-between; align-items: start; }

/* --------------------------------------------------------------- tiroir */
.scrim { position: fixed; inset: 0; background: rgba(20, 33, 61, .28); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--paper);
  overflow-y: auto; padding: 1.5rem 1.75rem 3rem; border-left: 1px solid var(--rule);
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer .close { position: absolute; top: 1rem; right: 1rem; }
.drawer h2 { font-size: 1.35rem; margin: .4rem 0 .6rem; padding-right: 5rem; }
.drawer .lead { font-size: 1.02rem; margin: 0 0 1.25rem; max-width: 60ch; }
.drawer section { margin-top: 1.4rem; }
.drawer .meta { color: var(--ink-soft); font-size: .9rem; }
.drawer ul.factors { margin: 0; padding-left: 1.1rem; }
.drawer ul.factors li { margin-bottom: .35rem; }
.drawer .kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.drawer .kv dt { color: var(--ink-soft); }
.drawer .kv dd { margin: 0; word-break: break-word; }
.drawer .actions { display: flex; flex-direction: column; gap: .7rem; background: var(--mist);
  border-radius: var(--r-small); padding: 1rem; }
.drawer .actions .row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.drawer textarea { width: 100%; min-height: 3.2rem; resize: vertical; }
.drawer .form-row { display: flex; gap: .8rem; flex-wrap: wrap; align-items: end; }
.drawer .form-row label { display: flex; flex-direction: column; font-size: .85rem; color: var(--ink-soft); gap: .2rem; }
.drawer .linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--out);
  text-decoration: underline; cursor: pointer; }
.drawer .handled-note { background: #DCEFEC; color: #1E6B63; padding: .6rem .8rem; border-radius: var(--r-small); }
.mini { display: block; width: 100%; height: auto; }
.mini .bar { fill: var(--out); }
.mini .ref { stroke: var(--sev-medium); stroke-dasharray: 4 3; stroke-width: 1.5; }
.mini text { fill: var(--ink-soft); font-size: 11px; font-family: var(--font); }

.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); background: var(--ink);
  color: #fff; padding: .6rem 1.1rem; border-radius: var(--r-small); opacity: 0; transition: opacity .2s;
  pointer-events: none; }
.toast.on { opacity: 1; }

/* ---------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .figures { grid-template-columns: 1fr 1fr; row-gap: 1rem; }
  .fig:nth-child(3) { border-left: 0; padding-left: .25rem; }
  .sensor-grid { grid-template-columns: 1fr; }
  .grid thead { display: none; }
  .grid tr { display: block; padding: .5rem 0; border-top: 1px solid #E8EDF3; }
  .grid td { display: block; border: 0; padding: .15rem .9rem; }
  .grid .num { text-align: left; }
}
@media (max-width: 560px) {
  .alert-row { grid-template-columns: 6px 1fr; }
  .alert-row .when { grid-column: 2; text-align: left; }
  .tabs { overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .drawer { animation: none; }
  .toast { transition: none; }
}

/* =====================================================================
   Plateforme multi-clients : console prestataire et client
   ===================================================================== */
.top .org { color: var(--ink-soft); }
.top .who { color: var(--ink-soft); font-size: .9rem; }
.role-tag { font-size: .78rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: #E3EAF2;
  color: var(--ink-soft); }

.page-head { display: flex; justify-content: space-between; align-items: end; gap: 1rem; flex-wrap: wrap;
  margin: .25rem 0 1rem; }
.page-head h2 { font-size: 1.35rem; }
.page-head p { margin: .25rem 0 0; color: var(--ink-soft); }

/* Bandeau de veille : la phrase qui résume l'état du parc */
.watch { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-big);
  padding: 1.25rem 1.4rem; display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: center; }
.watch .verdict { font-family: var(--display); font-size: 1.45rem; font-weight: 600; letter-spacing: -.01em;
  line-height: 1.25; max-width: 48ch; }
.watch .verdict.calm { color: #1E6B63; }
.watch .verdict.alarm { color: var(--sev-high); }
.watch .sub { color: var(--ink-soft); margin-top: .35rem; }

.fig .delta { font-size: .82rem; color: var(--ink-soft); }
.state-dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; margin-right: .4rem;
  vertical-align: 1px; background: var(--sev-info); }
.state-dot.online { background: var(--ok); } .state-dot.degraded { background: var(--sev-medium); }
.state-dot.offline { background: var(--sev-high); } .state-dot.pending { background: #B9C4D3; }
.state-dot.stock { background: transparent; border: 1.5px solid var(--ink-soft); }

.sevs { display: flex; gap: .3rem; flex-wrap: wrap; }
.sevs .none { color: var(--ink-soft); font-size: .9rem; }
.client-name { font-weight: 600; }
.grid td.actions-cell { white-space: nowrap; text-align: right; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.75rem; }
.card { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-big); padding: 1.1rem 1.25rem; }
.card h3 { margin-bottom: .75rem; }
.stack > * + * { margin-top: .9rem; }
.field { display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; color: var(--ink-soft); }
.field input, .field select, .field textarea { font: inherit; color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: var(--r-small); padding: .5rem .6rem; }
.field .help { font-size: .8rem; }
.form-error { color: var(--sev-high); min-height: 1.3em; margin: .25rem 0; }
.secret-box { background: var(--ink); color: #fff; font-size: 1.15rem; letter-spacing: .06em; padding: .8rem 1rem;
  border-radius: var(--r-small); text-align: center; font-weight: 600; user-select: all; }
.notice { background: #F6EBD6; color: #6B4805; border-radius: var(--r-small); padding: .7rem .9rem; }
.notice.ok { background: #DCEFEC; color: #1E6B63; }
pre.conf { background: var(--mist); border-radius: var(--r-small); padding: .7rem .9rem; overflow-x: auto;
  font-size: .82rem; margin: .4rem 0 0; white-space: pre-wrap; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--rule); }
.timeline li { padding: 0 0 .7rem 1rem; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .45rem; width: 10px; height: 10px;
  border-radius: 50%; background: var(--paper); border: 2px solid var(--ink-soft); }
.timeline li.done::before { background: var(--ok); border-color: var(--ok); }
.timeline .t { color: var(--ink-soft); font-size: .85rem; }

/* ============================================================= rapport */
.report-view { position: fixed; inset: 0; background: var(--mist); overflow-y: auto; z-index: 20; }
.report-bar { position: sticky; top: 0; display: flex; gap: .75rem; justify-content: space-between; align-items: center;
  padding: .8rem clamp(1rem, 3vw, 2.5rem); background: var(--paper); border-bottom: 1px solid var(--rule); z-index: 1; }
.report { max-width: 960px; margin: 2rem auto 4rem; background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--r-big); padding: clamp(1.25rem, 4vw, 3rem); }
.report header { border-bottom: 2px solid var(--ink); padding-bottom: 1.1rem; margin-bottom: 1.5rem; }
.report .kicker { color: var(--ink-soft); }
.report h1 { font-family: var(--display); font-size: 2rem; letter-spacing: -.02em; margin: .2rem 0 .4rem; }
.report h2 { font-size: 1.2rem; margin: 2.2rem 0 .8rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.report .lede { font-size: 1.08rem; max-width: 70ch; }
.report .figures { margin: 1.25rem 0 .5rem; }
.finding { border-left: 4px solid var(--sev); padding: .6rem 0 .6rem 1rem; margin: 0 0 1rem; break-inside: avoid; }
.finding h3 { margin: 0 0 .25rem; display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.finding p { margin: 0 0 .4rem; color: var(--ink-soft); max-width: 75ch; }
.finding ul { margin: 0; padding-left: 1.1rem; }
.finding li { margin-bottom: .15rem; }
.report .grid { font-size: .9rem; }
.report .grid tbody tr { cursor: default; }
.report .footnote { color: var(--ink-soft); font-size: .85rem; margin-top: 2rem; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .watch { grid-template-columns: 1fr; }
}
@media print {
  body { background: #fff; }
  #app > :not(.report-view), .report-bar, .toast { display: none !important; }
  .report-view { position: static; overflow: visible; background: #fff; }
  .report { border: 0; margin: 0; padding: 0; max-width: none; }
  .report h2 { break-after: avoid; }
  .grid tr { break-inside: avoid; }
  .sev-chip, .finding, .tag { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.panel .grid + .page-head, .panel .empty + .page-head { margin-top: 2.25rem; }
