/*
  Identité visuelle : poste de contrôle / instrumentation, pas un SaaS générique.
  Fond graphite chaud (pas noir-bleu), accent unique teal-signal réservé au marquage
  d'état actif/interactif -- jamais utilisé pour les couleurs sémantiques (ok/warn/bad),
  qui restent un système à part. Typographie Plex Mono pour tout ce qui est chiffre,
  identifiant ou libellé de section (lecture "télémétrie"), Plex Sans pour le texte
  courant. Un seul monde visuel assumé (voir DECISIONS.md) : pas de thème clair.
*/

:root {
  --bg: #0c0a09;
  --surface: #151210;
  --surface-2: #1c1712;
  --surface-3: #241d17;
  --border: #2a2219;
  --border-strong: #3c3125;
  --text: #f3f0ea;
  --text-dim: #9c9082;
  --text-faint: #635a4c;

  --accent: #2bbfae;
  --accent-strong: #55d9c9;
  --accent-soft: rgba(43, 191, 174, 0.13);
  --accent-line: rgba(43, 191, 174, 0.35);

  --ok: #4fc97a;
  --ok-soft: rgba(79, 201, 122, 0.13);
  --warn: #e0a83f;
  --warn-soft: rgba(224, 168, 63, 0.13);
  --bad: #ef5f59;
  --bad-soft: rgba(239, 95, 89, 0.14);

  --font-body: 'Plex Sans', -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --radius: 7px;
  --radius-sm: 4px;
}

* { box-sizing: border-box; }
::selection { background: var(--accent-soft); color: var(--accent-strong); }

html { background: var(--bg); }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, .mono { font-family: var(--font-mono); }
.tabular { font-variant-numeric: tabular-nums; }

/* faible texture de fond -- grille d'instrumentation à peine perceptible */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 64px 64px;
  opacity: 0.055;
}

.layout { position: relative; z-index: 1; display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.4rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0.5rem 1.5rem;
  font-family: var(--font-mono);
}
.brand-mark {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 10px 1px var(--accent-line);
  flex-shrink: 0;
  animation: pulse-dot 2.6s ease-in-out infinite;
}
.brand-text { font-weight: 600; font-size: 0.88rem; letter-spacing: 0.02em; color: var(--text); }
.brand-sub { display: block; font-size: 0.66rem; color: var(--text-faint); letter-spacing: 0.06em; margin-top: 1px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.86rem;
  font-weight: 500;
  position: relative;
  border-left: 2px solid transparent;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}
.nav-item.active svg { opacity: 1; }

.sidebar .spacer { flex: 1; }
.sidebar form { padding: 0 0.1rem; }
.btn-ghost {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
}
.btn-ghost:hover { border-color: var(--text-faint); color: var(--text); }

/* ---------- Main ---------- */
.main { flex: 1; padding: 1.9rem 2.4rem 3.5rem; max-width: 1180px; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.6rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.page-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0 0 0.35rem;
}
.page-header h1 {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.live-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 6px 1px rgba(79, 201, 122, 0.55);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.8); }
}
@media (prefers-reduced-motion: reduce) {
  .brand-mark, .live-dot { animation: none; }
}

/* ---------- Grid / Panels ----------
   Une seule variante de grille (gap réel entre panneaux individuellement bordés),
   jamais le motif "fond du conteneur + gap 1px" : avec des rangées de longueurs
   inégales (ex. 4 panneaux puis 1 seul en dessous), auto-fit ne collapse que les
   colonnes jamais utilisées sur AUCUNE rangée -- une colonne utilisée en rangée 1
   mais vide en rangée 2 reste visible, avec le fond du conteneur qui déborde en
   un bloc plein disgracieux. Constaté à la construction, corrigé en abandonnant
   le motif au profit d'un gap CSS classique (une cellule vide n'affiche alors
   simplement rien). */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.panel {
  background: var(--surface);
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.35rem;
  margin-bottom: 1.2rem;
}
.panel h2, .panel-block h2 {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  margin: 0 0 0.85rem;
  color: var(--text-faint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-unit { font-size: 1rem; color: var(--text-dim); font-weight: 400; margin-left: 0.15rem; }
.stat-sub { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.5rem; font-family: var(--font-mono); }

/* ---------- Badges / pills (état sémantique -- distinct de l'accent) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.22rem 0.65rem; border-radius: 999px;
  font-size: 0.74rem; font-weight: 600; font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th {
  text-align: left; color: var(--text-faint); font-weight: 600;
  padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border);
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em;
  font-family: var(--font-mono);
}
td { padding: 0.65rem 0.7rem; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- Progress bars (bezel plat, pas de glow) ---------- */
.progress { height: 5px; background: var(--surface-3); overflow: hidden; margin-top: 0.6rem; border-radius: 2px; }
.progress > div { height: 100%; background: var(--accent); transition: width 0.4s ease; }
.progress.ok > div { background: var(--ok); }
.progress.warn > div { background: var(--warn); }
.progress.bad > div { background: var(--bad); }

/* ---------- Checklist ---------- */
ul.checklist { list-style: none; padding: 0; margin: 0; }
ul.checklist li {
  padding: 0.62rem 0; border-bottom: 1px solid var(--border);
  display: flex; gap: 0.65rem; align-items: flex-start; font-size: 0.88rem;
}
ul.checklist li:last-child { border-bottom: none; }
.check-icon { flex-shrink: 0; width: 15px; height: 15px; margin-top: 0.15rem; }
.check-icon.done { color: var(--ok); }
.check-icon.partial { color: var(--warn); }
.check-icon.blocked { color: var(--text-faint); }

pre.log {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.9rem; font-size: 0.78rem; font-family: var(--font-mono);
  overflow-x: auto; white-space: pre-wrap; color: var(--text-dim);
}

/* ---------- Markdown (page Décisions) ---------- */
.markdown-body { font-size: 0.9rem; line-height: 1.7; color: var(--text); }
.markdown-body h1 { font-family: var(--font-mono); font-size: 1.15rem; margin: 0 0 1rem; }
.markdown-body h2 {
  font-family: var(--font-mono); font-size: 0.92rem; font-weight: 600; text-transform: none;
  letter-spacing: 0; color: var(--accent-strong); margin: 2rem 0 0.7rem; padding-top: 1.3rem;
  border-top: 1px solid var(--border);
}
.markdown-body h2:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.markdown-body p { margin: 0 0 0.9rem; color: var(--text-dim); }
.markdown-body strong { color: var(--text); }
.markdown-body code {
  background: var(--surface-2); padding: 0.1rem 0.35rem; border-radius: 3px;
  font-size: 0.85em; color: var(--accent-strong);
}
.markdown-body ul { padding-left: 1.3rem; color: var(--text-dim); }
.markdown-body li { margin-bottom: 0.3rem; }
.markdown-body a { color: var(--accent-strong); }

/* ---------- Sparklines ---------- */
.sparkline-wrap { margin-top: 0.7rem; }
canvas.sparkline { width: 100%; height: 44px; display: block; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1rem; position: relative; overflow: hidden; background: var(--bg);
}
.login-wrap::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 48px 48px; opacity: 0.06;
  mask-image: radial-gradient(ellipse 60% 50% at 50% 45%, black 10%, transparent 75%);
}
.login-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2.1rem 2rem; position: relative; z-index: 1;
  animation: rise-in 0.5s cubic-bezier(.16,.9,.35,1) both;
}
@keyframes rise-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .login-card { animation: none; } }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 0.55rem; margin-bottom: 1.7rem; font-family: var(--font-mono); }
.login-brand .brand-mark { width: 8px; height: 8px; }
.login-brand span { font-weight: 600; font-size: 0.92rem; letter-spacing: 0.02em; }
.login-card label { display: block; font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.35rem; }
.login-card input {
  width: 100%; padding: 0.62rem 0.75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text);
  font-size: 0.9rem; margin-bottom: 1rem; font-family: var(--font-body);
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%; padding: 0.68rem; border-radius: var(--radius-sm); border: none;
  background: var(--accent); color: #06211d; font-weight: 600; font-size: 0.88rem;
  cursor: pointer; font-family: var(--font-mono); letter-spacing: 0.03em;
  transition: background 0.15s ease;
}
.login-card button:hover { background: var(--accent-strong); }
.login-error {
  background: var(--bad-soft); color: var(--bad); padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm); font-size: 0.82rem; margin-bottom: 1rem; font-family: var(--font-mono);
}

/* ---------- Chat ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 8.5rem); max-height: 740px; }
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.7rem; padding: 0.4rem 0.2rem; }
.msg { max-width: 78%; padding: 0.65rem 0.9rem; border-radius: var(--radius); font-size: 0.88rem; white-space: pre-wrap; line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent-line); }
.msg.agent { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.msg .meta { font-size: 0.68rem; color: var(--text-faint); margin-top: 0.4rem; font-family: var(--font-mono); }
.msg-html p { margin: 0 0 0.7rem; }
.msg-html p:last-child { margin-bottom: 0; }
.msg-html h1, .msg-html h2, .msg-html h3 { font-family: var(--font-mono); font-size: 0.85rem; color: var(--accent-strong); margin: 0.9rem 0 0.5rem; }
.msg-html h1:first-child, .msg-html h2:first-child, .msg-html h3:first-child { margin-top: 0; }
.msg-html strong { color: var(--accent-strong); }
.msg-html code { background: var(--surface-2); padding: 0.05rem 0.3rem; border-radius: 3px; font-size: 0.85em; }
.msg-html ul { padding-left: 1.1rem; margin: 0 0 0.7rem; }
.msg-html li { margin-bottom: 0.25rem; }
.chat-input { display: flex; gap: 0.6rem; margin-top: 1rem; }
.chat-input textarea {
  flex: 1; resize: none; padding: 0.7rem 0.9rem; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-family: var(--font-body); font-size: 0.88rem;
}
.chat-input textarea:focus { border-color: var(--accent); }
.chat-input button {
  padding: 0 1.4rem; border-radius: var(--radius); border: none;
  background: var(--accent); color: #06211d; font-weight: 600; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.82rem;
}
.chat-input button:hover { background: var(--accent-strong); }
.chat-note { font-size: 0.79rem; color: var(--text-dim); margin: -0.6rem 0 1.1rem; line-height: 1.55; }

@media (max-width: 780px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; overflow-x: auto; padding: 0.65rem; align-items: center; }
  .brand, .sidebar .spacer { display: none; }
  .sidebar form { padding: 0; }
  .nav-item { white-space: nowrap; border-left: none; border-bottom: 2px solid transparent; }
  .nav-item.active { border-left-color: transparent; border-bottom-color: var(--accent); }
  .main { padding: 1.3rem 1.1rem 2.6rem; }
  .chat-wrap { height: calc(100vh - 13rem); }
}
