:root {
  --bg: #f4f5f7; --surface: #ffffff; --ink: #1b1f24; --muted: #5b646e; --line: #dde1e6; --soft: #f0f2f5;
  --accent: #0b57d0; --top: #14171a; --top-ink: #e9ecef; --warn-bg: #fff4d6; --warn-line: #e0bd4f;
  --ok-bg: #e7f5ec; --ok-line: #8fd0a7; --err-bg: #fdecec; --err-line: #ef9a9a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215; --surface: #171b20; --ink: #e5e8eb; --muted: #9aa3ad; --line: #2b3139; --soft: #1e232a;
    --accent: #7aaeff; --top: #0a0c0e; --warn-bg: #3a2f10; --warn-line: #8a6d1d; --ok-bg: #12301f;
    --ok-line: #2f7a4d; --err-bg: #3a1717; --err-line: #8a3434; color-scheme: dark;
  }
  .state-ok { color: #3fb950 !important; } .state-ko, .lv-confirmed { color: #ff7b72 !important; }
  .state-wait, .statusbar .warn, .b-unk { color: #d29922 !important; } .lv-potential { color: #b39dfa !important; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1 { font-size: 20px; margin: 0 0 2px; }
h2 { font-size: 15px; margin: 0 0 8px; }
h3 { font-size: 12px; margin: 12px 0 4px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); }
p { margin: 4px 0 8px; }
ul { margin: 4px 0; padding-left: 18px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 4px; background: var(--surface); padding: 6px 10px; z-index: 10; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* en-tête */
.top { display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 48px; background: var(--top); color: var(--top-ink); }
.brand { color: #fff; font-weight: 800; letter-spacing: 2px; font-size: 15px; }
.brand:hover { text-decoration: none; }
.top nav { display: flex; gap: 2px; height: 100%; overflow-x: auto; }
.top nav a { display: flex; align-items: center; padding: 0 12px; color: #c3c9cf; border-bottom: 3px solid transparent; white-space: nowrap; }
.top nav a:hover { color: #fff; text-decoration: none; background: #1f2429; }
.top nav a[aria-current="page"] { color: #fff; border-bottom-color: #7aaeff; font-weight: 600; }
.top .search { margin-left: auto; }
.top .search input { width: 240px; height: 30px; border-radius: 4px; border: 1px solid #343a40; background: #1f2429; color: #fff; padding: 0 8px; }
.top .who { display: flex; gap: 10px; align-items: center; font-size: 12.5px; white-space: nowrap; }
.top .who a { color: #c3c9cf; }
.top .who form { margin: 0; }
.statusbar { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 5px 16px; background: var(--surface); border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.statusbar .warn { color: #9a6700; font-weight: 600; }
.statusbar a { color: inherit; text-decoration: underline; }

main { max-width: 1480px; margin: 0 auto; padding: 14px 16px 40px; }
.head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin-bottom: 8px; }
.head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* badges : la couleur vient de /colors.css, le texte et le symbole portent toujours le sens */
.b { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11.5px; font-weight: 600; line-height: 1.5; white-space: nowrap; vertical-align: 1px; }
.b-line { background: transparent; color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
.b-kev { background: #b3261e; color: #fff; }
.b-cert { background: #1d3a8a; color: #fff; }
.b-unk { background: transparent; color: #9a6700; border: 1px dashed #c99a2e; }
.score { font-variant-numeric: tabular-nums; font-weight: 600; }
.lv-confirmed { color: #c4162a; font-weight: 600; }
.lv-potential { color: #7c5ce0; font-weight: 600; }
.lv-none { color: var(--muted); }

/* puces de synthèse */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 12.5px; }
.chip strong { font-variant-numeric: tabular-nums; }
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* filtres et formulaires */
.filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 10px; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=date], input[type=number], input[type=url], select, textarea {
  height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); }
textarea { height: auto; padding: 6px 8px; width: 100%; }
.filters input[type=search] { width: 220px; }
label.check { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; font-weight: 400; }
.btn, button.btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 4px; border: 1px solid var(--top); background: var(--top); color: #fff; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(1.3); }
.btn-s, button.btn-s { background: var(--surface); color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn-danger, button.btn-danger { background: #b3261e; border-color: #b3261e; color: #fff; }
.btn-sm { height: 24px; padding: 0 8px; font-size: 12px; }
button.link { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-decoration: underline; font-size: inherit; }
.form { display: grid; grid-template-columns: 230px minmax(0, 540px); gap: 10px 14px; align-items: start; }
.form > label { padding-top: 5px; font-weight: 600; }
.form .help { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; font-weight: 400; }
.form input[type=text], .form input[type=email], .form input[type=password], .form input[type=url], .form select, .form textarea { width: 100%; }
.radios { display: grid; gap: 4px; padding-top: 4px; }
.inline-form { display: inline; margin: 0; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* tableaux */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th { position: sticky; top: 0; background: var(--soft); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover { background: var(--soft); }
table.grid .t { font-weight: 600; }
table.grid .sub { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }
tr.r4 td:first-child { box-shadow: inset 4px 0 #c4162a; }
tr.r3 td:first-child { box-shadow: inset 4px 0 #c2410c; }
tr.r2 td:first-child { box-shadow: inset 4px 0 #1f5fbf; }
tr.r1 td:first-child { box-shadow: inset 4px 0 #6741d9; }
.empty { padding: 18px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 10px; align-items: center; margin-top: 8px; font-size: 13px; }

/* cartes et fiche */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; margin-bottom: 12px; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: 12px; align-items: start; }
.cols3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; align-items: start; }
dl.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 4px 10px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 4px; }
.note { background: var(--soft); border-left: 3px solid var(--line); padding: 6px 10px; font-size: 12.5px; color: var(--muted); margin: 6px 0; }
.ai-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; margin-left: 6px; font-weight: 500; text-transform: none; letter-spacing: 0; }
.fixitem { border: 1px solid var(--line); border-radius: 5px; padding: 8px 10px; margin: 6px 0; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 3px 0; border-bottom: 1px dashed var(--line); overflow-wrap: anywhere; }
.list-plain li:last-child { border-bottom: 0; }
details summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }
.code { font: 600 22px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 2px; padding: 6px 12px; border: 1px dashed var(--accent); border-radius: 4px; display: inline-block; }
.desc { overflow-wrap: anywhere; }

/* messages */
.flash { padding: 8px 12px; border-radius: 5px; margin-bottom: 10px; border: 1px solid var(--line); }
.flash.ok { background: var(--ok-bg); border-color: var(--ok-line); }
.flash.error { background: var(--err-bg); border-color: var(--err-line); }
.banner { padding: 8px 12px; border-radius: 5px; margin-bottom: 10px; background: var(--warn-bg); border: 1px solid var(--warn-line); font-size: 13px; }
.state-ok { color: #1a7f37; font-weight: 600; }
.state-ko { color: #c4162a; font-weight: 600; }
.state-wait { color: #9a6700; font-weight: 600; }

/* connexion */
.login { max-width: 360px; margin: 10vh auto; padding: 0 12px; }
.login .card { padding: 20px; }
.login label { display: block; font-weight: 600; margin: 10px 0 4px; }
.login input { width: 100%; }

@media (max-width: 1100px) { .cols { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .top { flex-wrap: wrap; height: auto; padding: 6px 10px; gap: 6px 10px; }
  .top nav { order: 3; width: 100%; height: 36px; }
  .top .search { margin-left: 0; order: 2; flex: 1; }
  .top .search input { width: 100%; }
  main { padding: 10px 8px 30px; }
  .hide-s { display: none; }
  .form { grid-template-columns: 1fr; }
  .form > label { padding-top: 0; }
  .filters input[type=search] { width: 100%; }
  dl.kv { grid-template-columns: 110px minmax(0, 1fr); }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; }
  table.stack tr { padding: 6px 4px 6px 8px; border-bottom: 1px solid var(--line); }
  table.stack td { border: 0; padding: 2px 4px; }
  table.stack tr td:first-child { box-shadow: none; }
  table.stack tr.r4 { box-shadow: inset 4px 0 #c4162a; } table.stack tr.r3 { box-shadow: inset 4px 0 #c2410c; }
  table.stack tr.r2 { box-shadow: inset 4px 0 #1f5fbf; } table.stack tr.r1 { box-shadow: inset 4px 0 #6741d9; }
  table.stack td.hide-s { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  table.grid tbody tr, .chip, .btn { transition: background-color 80ms, border-color 80ms; }
}
