:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e2e6ec;
  --text: #1c2430;
  --text-2: #4f5968;
  --muted: #7d8696;
  --primary: #2a78d6;
  --primary-hover: #1f64b8;
  --primary-soft: #e8f1fc;
  --bar: #2a78d6;
  --bar-hover: #1a56a0;
  --grid: #e9ecf1;
  --sidebar: #1d2735;
  --sidebar-2: #273344;
  --sidebar-text: #c3ccd8;
  --sidebar-active: #ffffff;
  --success: #17804a;
  --success-bg: #e5f5ec;
  --danger: #c93b3b;
  --danger-bg: #fcebeb;
  --warning: #9a6200;
  --warning-bg: #fdf4e0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12161c;
    --surface: #1b2029;
    --surface-2: #212733;
    --border: #2d3441;
    --text: #e8ebf0;
    --text-2: #b4bcc8;
    --muted: #8a93a1;
    --primary: #3987e5;
    --primary-hover: #5a9cec;
    --primary-soft: #1e2d42;
    --bar: #3987e5;
    --bar-hover: #7cb2f2;
    --grid: #2a303b;
    --sidebar: #0e1217;
    --sidebar-2: #1a2029;
    --success: #4cc387;
    --success-bg: #173226;
    --danger: #f07c7c;
    --danger-bg: #3a1d1f;
    --warning: #e8b04a;
    --warning-bg: #3a2e14;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
code, .mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Mise en page */
.layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 18px;
  color: #fff;
  font-weight: 650;
  font-size: 17px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.menu-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
.nav { display: flex; flex-direction: column; padding: 12px 10px; gap: 2px; flex: 1; }
.nav a, .nav-logout {
  display: block;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 14.5px;
  border: 0;
  background: none;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.nav a:hover, .nav-logout:hover { background: var(--sidebar-2); color: #fff; }
.nav a.active { background: var(--primary); color: var(--sidebar-active); font-weight: 600; }
.nav-logout { margin-top: auto; color: #9aa5b5; }
.sidebar-footer { padding: 14px 20px 18px; font-size: 13px; border-top: 1px solid rgba(255, 255, 255, .07); }
.pill { display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.ok { background: #35c77a; box-shadow: 0 0 0 3px rgba(53, 199, 122, .18); }
.dot.ko { background: #ef5b5b; box-shadow: 0 0 0 3px rgba(239, 91, 91, .18); }

.main { padding: 28px 32px 48px; max-width: 1240px; width: 100%; outline: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 650; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }

/* ---------- Cartes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { font-size: 16px; font-weight: 620; }
.card-body { padding: 18px 20px; }
.card-body > p:first-child { margin-top: 0; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: 2fr 1fr; }
.grid-halves { grid-template-columns: 1fr 1fr; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat-label { color: var(--text-2); font-size: 13.5px; }
.stat-value { font-size: 28px; font-weight: 650; margin-top: 4px; letter-spacing: -.01em; }
.stat-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- Bandeaux */
.banner { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-radius: var(--radius); margin-bottom: 20px; border: 1px solid transparent; }
.banner.ok { background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.banner.ko { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.banner.warn { background: var(--warning-bg); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.banner.info { background: var(--primary-soft); color: var(--text); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.banner strong { font-weight: 650; }
.banner .banner-icon { font-size: 18px; line-height: 1; flex: none; }

/* ---------- Tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-2); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { white-space: nowrap; }
td .sub { display: block; color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.empty { padding: 36px 20px; text-align: center; color: var(--text-2); }
.empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* ---------- Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.off { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.ko { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.badge.warn { background: var(--warning-bg); color: var(--warning); }

/* ---------- Boutons & formulaires */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px; font-weight: 550;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); background: var(--danger); }
.btn-ghost-danger { color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
label .opt { font-weight: 400; color: var(--muted); }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 14.5px;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav a:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 1px; border-color: var(--primary);
}
.help { color: var(--muted); font-size: 13px; margin: 5px 0 0; }
.form-error { color: var(--danger); font-size: 14px; margin: 10px 0 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
.radio { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; margin: 8px 0; cursor: pointer; }
.radio input { margin-top: 4px; }
.radio strong { display: block; }
.radio .muted { display: block; font-size: 13.5px; }
.radio:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline input[type="text"] { flex: 1; min-width: 200px; }

/* ---------- Copie */
.copy-box { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 8px 8px 12px; margin: 6px 0; }
.copy-box code { flex: 1; overflow-wrap: anywhere; font-size: 13.5px; }
.secret { font-size: 15px !important; font-weight: 600; letter-spacing: .01em; }
pre.code { background: #10151c; color: #dfe6ee; border-radius: 8px; padding: 14px 16px; overflow-x: auto; font-size: 13px; line-height: 1.55; margin: 8px 0 0; }

/* ---------- Graphique */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 240px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--bar); }
.chart .bar.hover { fill: var(--bar-hover); }
.chart .hit { fill: transparent; cursor: default; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--surface);
  padding: 7px 10px; border-radius: 7px; font-size: 13px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}
.tooltip strong { display: block; font-weight: 650; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--text-2); padding: 5px 11px; font: inherit; font-size: 13px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ---------- Liste d'informations */
.kv { margin: 0; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.kv div:last-child { border-bottom: 0; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }

/* ---------- Modèles à installer */
.catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.model-card { border: 1px solid var(--border); border-radius: 9px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.model-card h3 { font-size: 15px; font-family: var(--mono); font-weight: 600; }
.model-card p { margin: 0; color: var(--text-2); font-size: 13.5px; flex: 1; }
.model-card .meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.progress { height: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin: 10px 0 6px; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .3s; }

/* ---------- Test (chat) */
.chat { display: flex; flex-direction: column; height: min(66vh, 640px); }
.chat-log { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; background: var(--surface-2); }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .meta { display: block; font-size: 12px; color: var(--muted); margin-top: 6px; white-space: normal; }
.msg details { margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.msg details pre { white-space: pre-wrap; font-family: inherit; margin: 6px 0 0; }
.chat-form { display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--border); align-items: flex-end; }
.chat-form textarea { min-height: 46px; max-height: 180px; }
.typing { color: var(--muted); font-style: italic; }
.chat-options { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.chat-options > div { min-width: 180px; }
.chat-options label { margin-top: 0; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; padding: 9px 0; cursor: pointer; }

/* ---------- Guide */
.steps { counter-reset: step; }
.step { display: grid; grid-template-columns: 34px 1fr; gap: 14px; padding: 18px 0; border-bottom: 1px solid var(--border); }
.step:last-child { border-bottom: 0; }
.step::before { counter-increment: step; content: counter(step); display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.step h3 { font-size: 15.5px; margin-bottom: 4px; }
.step p { margin: 4px 0; color: var(--text-2); }
.step ol, .step ul { margin: 6px 0; padding-left: 20px; color: var(--text-2); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-top: 10px; }
.tabs button { border: 0; background: none; padding: 8px 12px; font: inherit; font-size: 14px; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- Fenêtres (modales) */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 28, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 520px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); max-height: calc(100vh - 32px); overflow-y: auto; }
.modal-head { padding: 18px 22px 0; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 8px 22px 22px; }
.modal-body > p { color: var(--text-2); }

/* ---------- Notifications */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--surface); padding: 11px 16px; border-radius: 8px; box-shadow: 0 6px 18px rgba(0, 0, 0, .2); font-size: 14px; max-width: 360px; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; }
.brand-login { color: var(--text); padding: 0 0 18px; border: 0; }
.login-card h1 { font-size: 20px; }
.login-card p { margin: 6px 0 4px; }
.login-card .btn { margin-top: 18px; padding: 10px; }

.skeleton { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- Mobile */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-halves { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar { position: sticky; height: auto; z-index: 20; }
  .brand { padding: 12px 16px; }
  .menu-toggle { display: block; }
  .nav { display: none; padding: 6px 8px 10px; }
  .sidebar.open .nav { display: flex; }
  .sidebar-footer { display: none; }
  .main { padding: 20px 16px 40px; }
  .page-head h1 { font-size: 21px; }
  .stat-value { font-size: 23px; }
  .msg { max-width: 92%; }
  th, td { padding: 9px 10px; }
}
