:root {
  --bg: #05060a;
  --text: #e9eef5;
  --muted: #a2b0c2;
  --border: rgba(255,255,255,0.08);
  --blood: #c61a1a;
  --bone: #e7e2da;
  --glow: rgba(198,26,26,0.22);
  --topbar-height: 64px;
  --ok: #3fae5a;
  --warn: #d99a2b;
  --err: #c61a1a;
  /* --err sert aux bordures et aux fonds. Pour du TEXTE sur fond sombre il
     échoue au contraste WCAG AA (3,4:1) : les messages d'erreur du dashboard
     étaient difficiles à lire. --err-text monte à ~6,5:1. Détecté par les
     tests axe sur les vues rendues (apps/admin/test/e2e/a11y.spec.js). */
  --err-text: #ff6b6b;
  --ok-text: #5fd47c;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 800px at 18% 12%, rgba(198,26,26,0.10), transparent 56%),
    radial-gradient(900px 700px at 90% 20%, rgba(231,226,218,0.04), transparent 60%),
    radial-gradient(1400px 900px at 50% 110%, rgba(0,0,0,0.8), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

.hidden { display: none !important; }

a { color: inherit; }

/* ===== LOGIN ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.login-card {
  width: 340px;
  background: rgba(8,10,16,0.92);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: 0 20px 80px rgba(0,0,0,0.5);
  backdrop-filter: blur(12px);
}

.login-card .brand {
  font-family: "UnifrakturCook", serif;
  font-size: 32px;
  text-align: center;
  text-shadow: 0 0 24px var(--glow);
}

.login-sub {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0 20px;
}

.login-card label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 14px;
}

.login-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(4,6,10,0.72);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.login-card input:focus {
  border-color: rgba(198,26,26,0.55);
  box-shadow: 0 0 0 3px rgba(198,26,26,0.10);
}

.login-error {
  color: var(--err-text);
  font-size: 12px;
  margin-top: 12px;
  min-height: 14px;
  text-align: center;
}

/* ===== APP SHELL ===== */
.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

#topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: var(--topbar-height);
  background: linear-gradient(90deg, rgba(6,8,14,0.96), rgba(12,14,22,0.92));
  border-bottom: 1px solid var(--border);
  box-shadow: 0 12px 50px rgba(0,0,0,0.35);
  z-index: 10;
}

#topbar .brand {
  font-family: "UnifrakturCook", serif;
  font-size: 24px;
  text-shadow: 0 0 24px var(--glow);
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}

.nav a {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease;
}

.nav a:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.nav a.active { color: var(--bone); background: rgba(198,26,26,0.16); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.whoami { font-size: 12px; color: var(--muted); }

.content {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ===== COMPONENTS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(4,6,10,0.62);
  color: rgba(231,226,218,0.92);
  padding: 9px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}
.btn:hover { transform: translateY(-1px); border-color: rgba(198,26,26,0.40); background: rgba(198,26,26,0.10); }
.btn-mini { padding: 6px 10px; font-size: 12px; border-radius: 10px; }
.btn-primary { width: 100%; justify-content: center; background: rgba(198,26,26,0.18); border-color: rgba(198,26,26,0.45); }
.btn-primary:hover { background: rgba(198,26,26,0.30); }

.card {
  background: rgba(8,10,16,0.85);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.20);
}

.grid {
  display: grid;
  gap: 16px;
}
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 20px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat-card .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 700; }
.stat-card .value { font-size: 30px; font-weight: 800; margin-top: 6px; color: var(--bone); }
.stat-card .value.ok { color: var(--ok-text); }
.stat-card .value.warn { color: var(--warn); }
.stat-card .value.err { color: var(--err-text); }

h2 { font-size: 16px; margin: 0 0 14px; color: var(--bone); }

.bar-row { display: flex; align-items: center; gap: 10px; font-size: 12px; padding: 5px 0; }
.bar-row .bar-label { width: 110px; flex-shrink: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-track { flex: 1; height: 8px; background: rgba(255,255,255,0.06); border-radius: 6px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; background: linear-gradient(90deg, var(--blood), rgba(198,26,26,0.6)); }
.bar-row .bar-count { width: 50px; text-align: right; color: var(--text); font-weight: 700; }

/* ===== TOOLBAR / FILTERS ===== */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.toolbar input, .toolbar select {
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(4,6,10,0.62);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.toolbar input:focus, .toolbar select:focus { border-color: rgba(198,26,26,0.45); }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  padding: 10px 12px;
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--bone); }
tbody td { padding: 9px 12px; border-top: 1px solid rgba(255,255,255,0.05); white-space: nowrap; }
tbody tr:hover { background: rgba(198,26,26,0.05); }
tbody tr.clickable { cursor: pointer; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.ok { background: rgba(63,174,90,0.15); color: var(--ok-text); }
.badge.warn { background: rgba(217,154,43,0.15); color: var(--warn); }
.badge.err { background: rgba(198,26,26,0.15); color: var(--err-text); }
.badge.muted { background: rgba(162,176,194,0.15); color: var(--muted); }

.pager { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 12px; color: var(--muted); }

/* ===== MODAL ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  width: 560px; max-width: 92vw; max-height: 86vh; overflow-y: auto;
  background: rgba(10,12,18,0.97); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px; box-shadow: 0 20px 80px rgba(0,0,0,0.5);
}
.modal h3 { margin: 0 0 16px; color: var(--bone); }
.modal label { display: block; font-size: 11px; color: var(--muted); font-weight: 700; margin-bottom: 12px; text-transform: uppercase; }
.modal input, .modal textarea {
  display: block; width: 100%; margin-top: 6px; padding: 9px 11px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.10); background: rgba(4,6,10,0.72); color: var(--text);
  font-size: 13px; outline: none; font-family: inherit;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal-error { color: var(--err-text); font-size: 12px; margin-top: 10px; }
.modal-close { float: right; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; }

.log-line { font-family: ui-monospace, Consolas, monospace; font-size: 12px; padding: 4px 0; border-top: 1px solid rgba(255,255,255,0.04); display: flex; gap: 10px; }
.log-line .ts { color: var(--muted); flex-shrink: 0; }
.log-line .lvl { flex-shrink: 0; width: 56px; font-weight: 700; }
.log-line .lvl.info { color: var(--muted); }
.log-line .lvl.warning { color: var(--warn); }
.log-line .lvl.error { color: var(--err-text); }

.empty { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }
.loading { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }

/* ===== MONITOR ===== */
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.mon-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 300ms;
}
.pulse-dot.live { animation: pulse-anim 2s ease-in-out infinite; }

@keyframes pulse-anim {
  0%, 100% { box-shadow: 0 0 0 0 rgba(63,174,90,0.5); }
  50%       { box-shadow: 0 0 0 5px rgba(63,174,90,0); }
}

.log-stream {
  height: 420px;
  overflow-y: auto;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  scroll-behavior: smooth;
}

.log-stream .log-line {
  display: flex;
  gap: 10px;
  padding: 3px 0;
  border-top: 1px solid rgba(255,255,255,0.04);
  word-break: break-all;
  white-space: pre-wrap;
}

@keyframes log-flash {
  from { background: rgba(63,174,90,0.10); }
  to   { background: transparent; }
}
.log-new { animation: log-flash 1.8s ease-out; }

.mon-run-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 8px 0;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.mon-run-row:first-child { border-top: none; padding-top: 0; }

/* ==================================================================
   Refonte : composants du découpage par intention
   ================================================================== */

/* --- En-tête de vue --- */
.view-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; margin-bottom: 4px; flex-wrap: wrap;
}
.view-head h1 { font-size: 20px; margin: 0 0 8px; color: var(--bone); letter-spacing: .2px; }
.refresh-note { font-size: 11px; color: var(--muted); }
.muted-note { font-size: 12px; color: var(--muted); margin: 0 0 14px; line-height: 1.5; }
.mt { margin-top: 18px; }
.count { font-weight: 400; color: var(--muted); }
.sub { font-size: 11px; color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.err-text { color: var(--err-text); }
.warn-text { color: var(--warn); }
.empty { padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }
.err-box { color: var(--err-text); }
.loading { padding: 18px; color: var(--muted); font-size: 13px; }

/* --- Bandeau de santé --- */
.health-strip {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.health-card {
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 14px;
  border-left: 3px solid var(--muted);
}
.health-card.ok   { border-left-color: var(--ok); }
.health-card.warn { border-left-color: var(--warn); }
.health-card.err  { border-left-color: var(--err); }
.health-card .h-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 700;
}
.health-card .h-value { font-size: 24px; font-weight: 800; color: var(--bone); margin: 4px 0 2px; }
.health-card .h-sub { font-size: 11px; color: var(--muted); }

/* --- Alertes actionnables : le chiffre et son remède côte à côte --- */
.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.alert {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px; border-radius: 12px; font-size: 13px;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
}
.alert-err  { border-left-color: var(--err);  background: rgba(198,26,26,0.07); }
.alert-warn { border-left-color: var(--warn); background: rgba(217,154,43,0.06); }
.alert-ok   { border-left-color: var(--ok);   background: rgba(63,174,90,0.06); }
.alert-actions { display: flex; gap: 8px; flex-shrink: 0; }
.alert-actions .btn { text-decoration: none; }

/* --- Boutons --- */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-col { display: flex; flex-direction: column; gap: 8px; }
.btn-col .btn { justify-content: flex-start; text-align: left; }
.btn .hint { font-weight: 400; font-size: 11px; color: var(--muted); margin-left: 8px; }
.btn-danger { border-color: rgba(198,26,26,0.5); color: #f0b8b8; }
.btn-danger:hover { background: rgba(198,26,26,0.18); }
.btn-primary-sm {
  background: rgba(198,26,26,0.18); border-color: rgba(198,26,26,0.45);
  padding: 8px 14px; font-size: 13px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.link-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--bone); font: inherit; text-align: left; text-decoration: underline;
  text-decoration-color: rgba(255,255,255,0.25);
}
.link-btn:hover { color: #fff; }
.th-sort {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: inherit; font: inherit; font-weight: 700;
}

/* --- Recherche et chips --- */
.search-bar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.search-bar input[type="search"], .search-bar input[type="text"], .search-bar select {
  flex: 1 1 240px; min-width: 140px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  color: var(--text); padding: 9px 12px; border-radius: 10px; font-size: 13px;
}
.search-bar input:focus, .search-bar select:focus {
  outline: none; border-color: rgba(198,26,26,0.45);
}
.inline-check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }
.chip {
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  color: var(--muted); padding: 6px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: rgba(255,255,255,0.2); }
.chip.on {
  background: rgba(198,26,26,0.18); border-color: rgba(198,26,26,0.5); color: var(--bone);
}
.chip-clear { margin-left: auto; }
.chip-sep { width: 1px; height: 20px; background: var(--border); }

/* --- Traitements en cours --- */
.run-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-top: 1px solid rgba(255,255,255,0.05);
}
.run-row:first-of-type { border-top: 0; }
.run-meta { font-size: 11px; color: var(--muted); margin-top: 5px; }
.run-cancel-note { font-size: 11px; color: var(--warn); margin-top: 3px; }

/* --- Zone dangereuse --- */
.danger-zone { border-color: rgba(198,26,26,0.3); margin-top: 20px; }
.danger-zone summary {
  cursor: pointer; font-weight: 700; color: var(--err-text); font-size: 13px;
}
.danger-zone[open] summary { margin-bottom: 10px; }

.feedback { font-size: 12px; margin-top: 10px; color: var(--muted); min-height: 1em; }
.feedback.ok  { color: var(--ok-text); }
.feedback.err { color: var(--err-text); }

/* --- Tables : lignes activables au clavier --- */
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: rgba(255,255,255,0.03); }
tr.clickable:focus-visible { outline: 2px solid var(--blood); outline-offset: -2px; }
.lock { color: var(--blood); }

/* --- Modales --- */
.modal-wide { max-width: 900px; }
.modal-section { margin-bottom: 20px; }
.modal-section > h4 { font-size: 13px; margin: 0 0 10px; color: var(--bone); }
.modal-section > summary { cursor: pointer; font-weight: 700; color: var(--muted); font-size: 13px; }
.modal-section.conflicts {
  border: 1px solid rgba(198,26,26,0.35); border-radius: 12px; padding: 12px;
}
.modal-section.conflicts h4 { color: var(--err-text); }
.field-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.field-grid label { margin-bottom: 0; }
.src-grid { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.src-grid > div { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.src-grid > div > span:first-child { color: var(--muted); }
.modal-close {
  float: right; background: none; border: 0; cursor: pointer;
  color: var(--muted); font-size: 22px; line-height: 1; padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.json, .llm-detail {
  font-size: 11px; white-space: pre-wrap; word-break: break-word;
  background: rgba(255,255,255,0.03); padding: 8px; border-radius: 6px;
  max-height: 300px; overflow: auto; color: var(--muted); margin: 6px 0 0;
}
.llm-item { margin: 4px 0; background: rgba(255,255,255,0.03); border-radius: 6px; padding: 6px 8px; }
.llm-item summary { cursor: pointer; font-size: 12px; }
.detail-row td { padding-top: 0; }
.detail-row summary { cursor: pointer; font-size: 11px; color: var(--muted); }

/* --- Logs --- */
.log-stream { max-height: 400px; overflow-y: auto; }
.log-line .msg { word-break: break-word; }
.lvl-error { color: var(--err-text); }
.lvl-warning { color: var(--warn); }
.lvl-info { color: var(--muted); }

@media (max-width: 720px) {
  .view-head { flex-direction: column; align-items: flex-start; }
  .alert { flex-direction: column; align-items: flex-start; }
  .truncate { max-width: 140px; }
}
