:root {
  --bg: #0e1621;
  --surface: #152232;
  --raised: #1c2d42;
  --line: #27405c;
  --text: #e4ecf5;
  --muted: #8ea3bb;
  --blue: #4c8dff;
  --blue-strong: #2f6fe0;
  --amber: #f0b43c;
  --red: #e5534b;
  --green: #3cb37a;
  --plate: #f4f1e6;
  --plate-ink: #13233a;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--blue); }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 600; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- Boutons et champs ---------- */
.btn {
  font: 500 14px/1 var(--font);
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 10px 14px;
  min-height: 40px;
  cursor: pointer;
  transition: background-color .15s, border-color .15s;
}
.btn:hover { background: #24395290; border-color: #36567a; }
.btn.primary { background: var(--blue-strong); border-color: var(--blue-strong); color: #fff; }
.btn.primary:hover { background: var(--blue); }
.btn.danger { color: var(--red); border-color: #6a2d2a; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--raised); }
.btn.small { min-height: 32px; padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: progress; }

label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  font: 15px/1.4 var(--font);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 9px 11px;
  width: 100%;
}
textarea { min-height: 140px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px #4c8dff33; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 400; }
label.check input { width: 18px; height: 18px; }
.form-error { color: var(--red); margin: 0; font-size: 14px; }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  display: grid;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 32px 28px;
}
.login-card p { margin: -8px 0 4px; }
.seal { color: var(--blue); }

/* ---------- Structure ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.rail {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 20px; color: var(--blue); }
.brand span { color: var(--text); font-weight: 600; font-size: 14px; line-height: 1.25; }
#nav { display: grid; gap: 2px; }
#nav a, .rail-foot a {
  color: var(--muted);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: var(--radius-s);
  font-weight: 500;
}
#nav a:hover, .rail-foot a:hover { color: var(--text); background: var(--raised); }
#nav a.active, .rail-foot a.active { color: var(--text); background: var(--raised); box-shadow: inset 3px 0 0 var(--blue); }
.rail-foot { margin-top: auto; display: grid; gap: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.rail-foot a { display: grid; line-height: 1.3; }
.rail-foot a small { color: var(--muted); font-weight: 400; }

.main { min-width: 0; display: flex; flex-direction: column; }
.view { padding: 28px 32px 48px; max-width: 1240px; width: 100%; outline: none; }

/* Bandeau de service : l'élément signature du MDT */
.duty-band {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  transition: background-color .3s;
}
.duty-state { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.duty-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
#duty-timer { color: var(--muted); font-weight: 500; }
#duty-count { margin-left: auto; font-size: 14px; }
.duty-band.on { background: #133227; border-bottom-color: #23604a; }
.duty-band.on .duty-dot { background: var(--green); box-shadow: 0 0 0 4px #3cb37a33; }
.duty-band.on #duty-timer { color: #9fe0bf; }

/* ---------- En-têtes de page ---------- */
.page-head { display: flex; align-items: end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .grow { flex: 1; min-width: 200px; }
.page-head p { margin: 4px 0 0; }
.search { display: flex; gap: 8px; margin-bottom: 16px; max-width: 520px; }
.back { display: inline-block; margin-bottom: 12px; text-decoration: none; color: var(--muted); }
.back:hover { color: var(--text); }

/* ---------- Statistiques ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; margin-bottom: 28px; }
.stat { background: var(--surface); padding: 16px 18px; text-decoration: none; color: inherit; }
a.stat:hover { background: var(--raised); }
.stat b { display: block; font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.alert b { color: var(--amber); }
.stat.danger b { color: var(--red); }
.stat.ok b { color: var(--green); }

/* ---------- Tableaux ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); margin-bottom: 24px; overflow: hidden; }
.panel > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 16px; border-bottom: 1px solid #1f3349; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--raised); }
td.actions { text-align: right; white-space: nowrap; }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; }

/* Plaque d'immatriculation */
.plate {
  display: inline-block;
  font: 600 13px/1 var(--mono);
  letter-spacing: .06em;
  color: var(--plate-ink);
  background: var(--plate);
  border: 2px solid #c9c3ae;
  border-radius: 3px;
  padding: 4px 8px;
}
.badge-id { font-family: var(--mono); font-size: 13px; color: var(--muted); }

/* Étiquettes d'état */
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--raised); color: var(--muted); white-space: nowrap; }
.tag.red { background: #3a1a1c; color: #ff8a83; }
.tag.amber { background: #3a2c12; color: var(--amber); }
.tag.green { background: #123326; color: #74d6a5; }
.tag.blue { background: #16294a; color: #8ab4ff; }

/* ---------- Fiche citoyen ---------- */
.profile { display: grid; grid-template-columns: 300px 1fr; gap: 24px; align-items: start; }
.id-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 20px; }
.id-card.wanted { border-color: var(--red); box-shadow: inset 0 4px 0 var(--red); }
.id-card h2 { font-size: 22px; margin-bottom: 4px; }
.id-card dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 18px 0; font-size: 14px; }
.id-card dt { color: var(--muted); }
.id-card dd { margin: 0; }
.id-card .notes { white-space: pre-wrap; font-size: 14px; border-top: 1px solid var(--line); padding-top: 14px; margin: 0 0 16px; }
.wanted-banner { background: #3a1a1c; color: #ffb3ae; border-radius: var(--radius-s); padding: 8px 12px; font-weight: 600; font-size: 14px; margin-bottom: 14px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Avis de recherche */
.warrant-danger-Faible { box-shadow: inset 3px 0 0 var(--muted); }
.warrant-danger-Modéré { box-shadow: inset 3px 0 0 var(--amber); }
.warrant-danger-Élevé, .warrant-danger-Extrême { box-shadow: inset 3px 0 0 var(--red); }

/* Rapport */
.report-body { white-space: pre-wrap; padding: 20px; line-height: 1.65; max-width: 76ch; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 24px; padding: 16px 20px; border-bottom: 1px solid var(--line); font-size: 14px; }
.meta-grid div span { display: block; color: var(--muted); font-size: 13px; }

/* ---------- Fenêtre modale ---------- */
dialog {
  width: min(560px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 0;
}
dialog::backdrop { background: #050a10b3; }
#modal-form { display: grid; gap: 14px; padding: 24px; }
#modal-form .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
#modal-form footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---------- Notification ---------- */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: var(--radius-s);
  padding: 12px 16px;
  max-width: 360px;
  z-index: 50;
  font-size: 14px;
}
.toast.error { border-left-color: var(--red); }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; padding: 12px 16px; }
  .brand { padding: 0 0 10px; }
  #nav { grid-auto-flow: column; overflow-x: auto; }
  #nav a { white-space: nowrap; }
  .rail-foot { flex-direction: row; display: flex; justify-content: space-between; align-items: center; }
  .view { padding: 20px 16px 40px; }
  .duty-band { padding: 10px 16px; gap: 12px; flex-wrap: wrap; position: static; }
  .profile { grid-template-columns: 1fr; }
  #modal-form .grid-2 { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
