:root {
  color-scheme: dark;
  --bg: #060a12;
  --surface-1: #0e1726;
  --surface-2: #132033;
  --surface-3: #1a2a42;
  --border: rgba(110, 170, 255, 0.14);
  --border-strong: rgba(110, 170, 255, 0.3);
  --text-primary: #e6eefb;
  --text-secondary: #8fa3c0;
  --text-muted: #5f7290;
  --accent: #22d3ee;
  --accent-2: #338ced;
  --series-1: #338ced;
  --series-2: #e76624;
  --good: #22c55e;
  --warning: #f59e0b;
  --critical: #ef4444;
  --radius: 10px;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, ui-monospace, monospace;
  --sans: "Segoe UI", "Inter", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, rgba(34, 211, 238, 0.07), transparent 60%), var(--bg);
  color: var(--text-primary);
  font: 14px/1.5 var(--sans);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
code { background: var(--surface-3); padding: 1px 6px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; letter-spacing: 0.02em; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.12em; font-weight: 600; }
p { margin: 0 0 8px; }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }

/* ----- Connexion ----- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 360px; text-align: center; }
.login-card canvas { width: 220px; height: 220px; display: block; margin: 0 auto 8px; }
.brand { font-family: var(--mono); letter-spacing: 0.5em; font-size: 22px; font-weight: 600; margin-right: -0.5em; }
.login-card form { margin-top: 24px; display: grid; gap: 12px; }

/* ----- Mise en page ----- */
#app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: rgba(10, 16, 28, 0.85);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 16px; }
.side-brand canvas { width: 40px; height: 40px; }
.side-brand .brand { font-size: 15px; letter-spacing: 0.32em; }
.nav { padding: 6px 10px; display: grid; gap: 2px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-secondary); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text-primary); text-decoration: none; }
.nav a.active { background: linear-gradient(90deg, rgba(34, 211, 238, 0.16), rgba(34, 211, 238, 0.03)); color: var(--text-primary); box-shadow: inset 2px 0 0 var(--accent); }
.nav svg { width: 17px; height: 17px; flex: none; }
.side-foot { padding: 14px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-secondary); display: grid; gap: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); margin-right: 6px; vertical-align: 1px; }
.dot.on { background: var(--good); box-shadow: 0 0 8px var(--good); }
.dot.off { background: var(--critical); }

main { padding: 28px 32px 48px; max-width: 1280px; width: 100%; min-width: 0; }
.inst code { word-break: break-all; }
.inst > div { min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-secondary); }

/* ----- Composants ----- */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card, .chat-wrap > .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar, main { min-width: 0; }
  .sidebar { position: static; height: auto; }
  .nav { grid-auto-flow: column; overflow-x: auto; flex: none; padding-bottom: 10px; }
  .nav a { white-space: nowrap; }
  .side-foot { display: none; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  main { padding: 20px 16px; }
}

.stat { padding: 16px 18px; }
.stat .label { color: var(--text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; }
.stat .value { font-family: var(--mono); font-size: 28px; font-weight: 600; margin-top: 6px; letter-spacing: -0.01em; }
.stat .sub { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-3); color: var(--text-primary); border: 1px solid var(--border-strong);
  padding: 7px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: linear-gradient(180deg, #1fb6d4, #1595b3); border-color: transparent; color: #021219; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: #ffb4b4; border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn.ghost:hover { color: var(--text-primary); background: var(--surface-2); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn svg { width: 15px; height: 15px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

input, select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border-strong); color: var(--text-primary);
  border-radius: 8px; padding: 8px 10px; font: inherit;
}
textarea { min-height: 110px; resize: vertical; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
input[type="range"] { padding: 0; accent-color: var(--accent); }
label.field { display: grid; gap: 5px; font-size: 13px; color: var(--text-secondary); }
label.field .help { font-size: 11.5px; color: var(--text-muted); }
.form > .help { font-size: 11.5px; color: var(--text-muted); margin-top: -10px; }
label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form { display: grid; gap: 14px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; border: 1px solid var(--border-strong); color: var(--text-secondary); white-space: nowrap; }
.badge.good { color: #86efac; border-color: rgba(34, 197, 94, 0.4); }
.badge.warn { color: #fcd34d; border-color: rgba(245, 158, 11, 0.4); }
.badge.bad { color: #fca5a5; border-color: rgba(239, 68, 68, 0.4); }
.badge.accent { color: var(--accent); border-color: rgba(34, 211, 238, 0.4); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-secondary); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
td.num, th.num { text-align: right; font-family: var(--mono); }
tr:last-child td { border-bottom: none; }
.list-empty { color: var(--text-muted); padding: 18px 0; text-align: center; }

.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); width: 0; transition: width 0.3s; }

/* ----- Graphique ----- */
.chart { position: relative; }
.chart svg { width: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: rgba(143, 163, 192, 0.12); stroke-width: 1; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px; font-family: var(--mono); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:hover { fill: rgba(143, 163, 192, 0.06); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tooltip {
  position: absolute; pointer-events: none; background: #0a1220; border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; white-space: nowrap; z-index: 5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.tooltip b { font-family: var(--mono); font-weight: 600; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 80px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.bar-row .track { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.bar-row .track div { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-row .v { text-align: right; font-family: var(--mono); color: var(--text-primary); }

/* ----- Chat ----- */
.chat-wrap { display: grid; grid-template-columns: 360px 1fr; gap: 16px; height: calc(100vh - 140px); min-height: 520px; }
.orb-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.orb-panel canvas { width: 100%; aspect-ratio: 1; max-width: 340px; }
.orb-status { font-family: var(--mono); font-size: 12px; letter-spacing: 0.3em; text-transform: uppercase; color: var(--text-secondary); margin-top: 6px; }
.chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: rgba(51, 140, 237, 0.16); border: 1px solid rgba(51, 140, 237, 0.3); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .meta { display: block; margin-top: 6px; font-size: 11px; color: var(--text-muted); font-family: var(--mono); }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: rgba(6, 10, 18, 0.5); }
.composer textarea { min-height: 42px; height: 42px; max-height: 160px; font-family: var(--sans); font-size: 14px; }
.mic.rec { background: rgba(239, 68, 68, 0.2); border-color: var(--critical); color: #fff; }
@media (max-width: 1000px) { .chat-wrap { grid-template-columns: 1fr; height: auto; } .orb-panel canvas { max-width: 240px; } .chat { height: 70vh; } }

/* ----- Intégrations ----- */
.type-card { display: flex; flex-direction: column; gap: 8px; cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.type-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.type-card .ico { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); color: var(--accent); }
.type-card .ico svg { width: 20px; height: 20px; }
.type-card p { color: var(--text-secondary); font-size: 12.5px; margin: 0; }
.inst { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.inst:last-child { border-bottom: none; }
.inst .ico { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); color: var(--accent); flex: none; }
.inst .ico svg { width: 18px; height: 18px; }

/* ----- Rapports (markdown) ----- */
.md h1 { font-size: 18px; margin: 0 0 14px; }
.md h2 { font-size: 14px; margin: 20px 0 8px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; }
.md ul { margin: 0; padding-left: 20px; }
.md li { margin: 3px 0; }
.md table { margin: 6px 0; font-size: 13px; }
.report-list a { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 8px; color: var(--text-primary); }
.report-list a:hover, .report-list a.active { background: var(--surface-2); text-decoration: none; }

/* ----- Rapport des e-mails ----- */
.seg { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; }
.seg button { background: transparent; border: 0; color: var(--text-secondary); padding: 6px 12px; border-radius: 7px; font: inherit; cursor: pointer; }
.seg button:hover:not(:disabled) { color: var(--text-primary); }
.seg button.active { background: var(--surface-3); color: var(--text-primary); box-shadow: inset 0 -2px 0 var(--accent); }
.seg button:disabled { opacity: 0.45; cursor: default; }
.mail-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.mail-item:last-child, .mail-row:last-child { border-bottom: none; }
.mail-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mail-subj { font-weight: 600; margin: 2px 0 4px; overflow-wrap: anywhere; }
.mail-item p { margin: 0 0 4px; }
.reply { margin-top: 10px; background: rgba(51, 140, 237, 0.07); border: 1px solid rgba(51, 140, 237, 0.25); border-radius: 8px; padding: 10px 12px; }
.reply textarea { min-height: 84px; font-family: var(--sans); font-size: 13.5px; }
.mail-row { display: grid; grid-template-columns: minmax(110px, 190px) minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.mail-row b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary-text { font-size: 15px; line-height: 1.65; margin: 4px 0 0; max-width: 80ch; }
.ico-inline { width: 16px; height: 16px; vertical-align: -3px; margin-right: 8px; color: var(--accent); }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▸"; display: inline-block; margin-right: 8px; color: var(--text-secondary); transition: transform 0.15s; }
details.card[open] > summary::before { transform: rotate(90deg); }
@media (max-width: 700px) { .mail-row { grid-template-columns: 1fr; gap: 2px; } }

/* ----- Fichiers & vidéos ----- */
.bad-text { color: #fca5a5; }
.grid + .card { margin-top: 16px; }
.attach-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px 0; border-top: 1px solid var(--border); background: rgba(6, 10, 18, 0.5); }
.attach-bar + .composer { border-top: none; }
.chip { display: flex; align-items: center; gap: 8px; max-width: 320px; padding: 6px 6px 6px 10px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border-strong); }
.chip > svg { width: 18px; height: 18px; flex: none; color: var(--accent); }
.chip.ok { border-color: rgba(34, 197, 94, 0.45); }
.chip.err { border-color: rgba(239, 68, 68, 0.5); }
.chip-text { display: grid; min-width: 0; line-height: 1.3; }
.chip-text b { font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-text small { font-size: 11.5px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .x { background: transparent; border: 0; color: var(--text-muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font: inherit; }
.chip .x:hover { color: var(--text-primary); background: var(--surface-3); }
.card.chat.drop { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.18) inset; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; min-height: 168px; border-style: dashed; border-color: var(--border-strong); cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.over { border-color: var(--accent); background: rgba(34, 211, 238, 0.05); outline: none; }
.dropzone svg.big { width: 30px; height: 30px; color: var(--accent); }
.file-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.file-row:last-child { border-bottom: none; }
.file-row .ico { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); color: var(--accent); }
.file-row .ico svg { width: 18px; height: 18px; }
.file-name { font-weight: 600; overflow-wrap: anywhere; }
.file-sum { color: var(--text-secondary); font-size: 13px; margin-top: 4px; max-width: 90ch; }
.file-actions { justify-content: flex-end; }
.file-preview { display: block; max-width: 100%; max-height: 320px; margin-top: 12px; border-radius: 8px; border: 1px solid var(--border); }
.file-summary { white-space: pre-wrap; line-height: 1.6; }
.file-content { white-space: pre-wrap; word-wrap: break-word; max-height: 340px; overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font: 12.5px/1.55 var(--mono); color: var(--text-secondary); margin: 0; }
.modal-box.wide { width: min(900px, 100%); }
@media (max-width: 700px) { .file-row { grid-template-columns: 34px minmax(0, 1fr); } .file-actions { grid-column: 1 / -1; justify-content: flex-start; } }

/* ----- Modale & toast ----- */
.modal { position: fixed; inset: 0; background: rgba(2, 5, 10, 0.7); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-box { width: min(620px, 100%); max-height: 90vh; overflow-y: auto; background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: 14px; padding: 22px; }
.modal-box .card-head { margin-bottom: 18px; }
.doc { background: rgba(34, 211, 238, 0.06); border: 1px solid rgba(34, 211, 238, 0.2); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; color: var(--text-secondary); }
#toast { position: fixed; bottom: 22px; right: 22px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--surface-2); border: 1px solid var(--border-strong); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 8px; max-width: 380px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); animation: slide 0.2s ease-out; }
.toast.error { border-left-color: var(--critical); }
.toast.success { border-left-color: var(--good); }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } }
.secret-box { font-family: var(--mono); background: var(--bg); border: 1px dashed var(--accent); padding: 12px; border-radius: 8px; word-break: break-all; user-select: all; }

/* ---------- mises à jour */
.nav-count { margin-left: auto; min-width: 18px; padding: 0 6px; border-radius: 99px; background: var(--accent); color: #021219; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.upd-list { margin: 10px 0 4px; padding-left: 18px; display: grid; gap: 4px; }
.upd-list li { line-height: 1.45; }
.upd-log { max-height: 280px; overflow: auto; margin: 10px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--bg, #060a12); border: 1px solid var(--border); font: 12px/1.5 Consolas, monospace; white-space: pre-wrap; }
.upd-check { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
p.help { font-size: 12px; color: var(--text-muted); margin: 6px 0 0; }
