:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #1c2230;
  --muted: #697184;
  --border: #e1e4ea;
  --accent: #1d4ed8;
  --accent-soft: #e6edff;
  --accent-text: #ffffff;
  --hl: #fff4c2;
  --danger: #b42318;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --diagram-bg: #ffffff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141a;
    --surface: #1a1e26;
    --surface-2: #20252f;
    --text: #e7eaf0;
    --muted: #9aa3b5;
    --border: #2d3340;
    --accent: #6d95ff;
    --accent-soft: #23304f;
    --accent-text: #0b1020;
    --hl: #4a3f12;
    --danger: #ff7b6e;
    --shadow: none;
    --diagram-bg: #f4f5f7;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
main { flex: 1; width: 100%; max-width: 1600px; margin: 0 auto; padding: 16px; }

/* ---------- En-tête ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); white-space: nowrap; }
.logo:hover { text-decoration: none; }
.logo-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); box-shadow: inset 0 0 0 5px var(--surface); outline: 2px solid var(--accent); }
.search { flex: 1; display: flex; gap: 8px; align-items: center; max-width: 760px; }
.search input[type=search] {
  flex: 1; min-width: 0;
  padding: 9px 12px; font: inherit;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
}
.search input[type=search]:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.search .scope { font-size: .85rem; color: var(--muted); white-space: nowrap; display: flex; gap: 4px; align-items: center; }
button, .btn {
  font: inherit; cursor: pointer;
  padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
.search button[type=submit] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.listlink { white-space: nowrap; font-weight: 600; }
.badge {
  display: inline-block; min-width: 22px; padding: 1px 7px; margin-left: 4px;
  border-radius: 999px; background: var(--accent); color: var(--accent-text);
  font-size: .8rem; text-align: center;
}
.badge.bump { animation: bump .35s ease; }
@keyframes bump { 50% { transform: scale(1.35); } }

.crumbs {
  max-width: 1600px; width: 100%; margin: 0 auto; padding: 10px 16px 0;
  font-size: .9rem; color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.crumbs .sep { opacity: .6; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px; }

/* ---------- Accueil ---------- */
.hero { padding: 20px 0 8px; }
.hero h1 { font-size: 1.9rem; }
.hero p { color: var(--muted); margin: 0; max-width: 60ch; }
.brand { margin-top: 24px; }
.model-name { color: var(--muted); font-weight: 600; margin: 12px 0 8px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.card-title { font-weight: 650; font-size: 1.05rem; }
.card-meta { color: var(--muted); font-size: .9rem; }
.card-foot { margin-top: 8px; color: var(--accent); font-size: .9rem; }
.ill-card img { width: 100%; aspect-ratio: 10/7; object-fit: contain; background: var(--diagram-bg); border-radius: 6px; margin-bottom: 6px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel.empty { text-align: center; color: var(--muted); }
pre.err { text-align: left; white-space: pre-wrap; color: var(--danger); font-size: .85rem; }

/* ---------- Catalogue ---------- */
.catalog { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.sidebar {
  position: sticky; top: 72px;
  max-height: calc(100vh - 88px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.sidebar-head { padding: 12px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sidebar-head input {
  padding: 7px 10px; font: inherit; font-size: .9rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text);
}
.group summary {
  cursor: pointer; padding: 9px 12px; list-style: none;
  display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .92rem;
}
.group summary::-webkit-details-marker { display: none; }
.group summary::after { content: "›"; margin-left: auto; transition: transform .15s; color: var(--muted); }
.group[open] summary::after { transform: rotate(90deg); }
.group summary:hover { background: var(--surface-2); }
.group .count { color: var(--muted); font-weight: 400; font-size: .8rem; }
.gnum {
  display: inline-grid; place-items: center; width: 24px; height: 24px; flex: none;
  border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .85rem;
}
.group ul { list-style: none; margin: 0; padding: 0 0 6px; }
.group li a { display: block; padding: 5px 12px 5px 44px; color: var(--text); font-size: .9rem; }
.group li a:hover { background: var(--surface-2); text-decoration: none; }
.group li a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.code { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; margin-right: 4px; }
a.active .code { color: inherit; }

.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.group-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.group-tile h2 { display: flex; gap: 8px; align-items: center; font-size: 1rem; }
.group-tile ul { list-style: none; margin: 0; padding: 0; }
.group-tile li a { display: block; padding: 4px 0; }
.group-tile.disabled { opacity: .55; }

.ill-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.ill-head h1 { margin: 0; }
.eyebrow { margin: 0; color: var(--muted); font-size: .85rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.pager { display: flex; gap: 8px; }

.ill-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 1280px) {
  .ill-layout { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; }
  .viewer { position: sticky; top: 72px; }
}

.viewer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.viewer-tools { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--border); }
.viewer-tools .btn { padding: 4px 10px; min-width: 36px; justify-content: center; }
.viewer-scroll { overflow: auto; max-height: 72vh; background: var(--diagram-bg); touch-action: pan-x pan-y; }
.viewer.zoomed .viewer-scroll { cursor: grab; }
.viewer-scroll.dragging { cursor: grabbing; user-select: none; }
.viewer-stage { position: relative; width: 100%; }
.viewer-stage img { display: block; width: 100%; height: auto; user-select: none; }
.noimg { padding: 80px 20px; text-align: center; color: #8a919c; }
.hotspot {
  position: absolute; transform: translate(-50%, -50%);
  min-width: 28px; height: 28px; padding: 0 6px; justify-content: center;
  border-radius: 999px; border: 2px solid #1d4ed8; background: #fff; color: #1d4ed8;
  font-weight: 700; font-size: .8rem; box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
  transition: transform .12s, background .12s;
}
.hotspot:hover, .hotspot.hover { background: #1d4ed8; color: #fff; transform: translate(-50%, -50%) scale(1.15); }
.hotspot.selected { background: #f59e0b; border-color: #b45309; color: #fff; transform: translate(-50%, -50%) scale(1.2); }

.parts { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.parts-tools { display: flex; gap: 10px; align-items: center; padding: 8px; border-bottom: 1px solid var(--border); }
.parts-tools input {
  flex: 1; min-width: 0; padding: 7px 10px; font: inherit; font-size: .9rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text);
}
.parts-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.parts-table th {
  text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.parts-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.parts-table tbody tr { transition: background .1s; }
.parts-table tbody tr:hover, .parts-table tbody tr.hover { background: var(--surface-2); }
.parts-table tbody tr.selected { background: var(--hl); }
.parts-table td.pos { font-weight: 700; color: var(--accent); width: 48px; cursor: pointer; }
.parts-table td.qty { width: 56px; text-align: center; }
.parts-table td.act { width: 1%; text-align: right; }
.results td { vertical-align: middle; }
.remark { color: var(--muted); font-size: .85rem; }
.tag { display: inline-block; margin-top: 2px; padding: 0 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-size: .78rem; }
.ref {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88rem; font-weight: 600;
  padding: 2px 6px; border: 1px dashed transparent; background: none; border-radius: 6px;
}
.ref:hover { border-color: var(--border); background: var(--surface-2); }
.ref:hover::after, .ref[aria-expanded="true"]::after { content: "▾"; margin-left: 4px; color: var(--muted); font-weight: 400; }
.ref[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Filtre moteur ---------- */
.engine-form { display: grid; gap: 4px; }
.engine-form label { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.engine-form select {
  width: 100%; padding: 7px 8px; font: inherit; font-size: .9rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text);
}
.engine-form select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.notice {
  margin: 0 0 12px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--text); font-size: .92rem;
}
.na { opacity: .45; }
.group li a.na, .group-tile li a.na { text-decoration: line-through; text-decoration-color: var(--border); }
.card.na:hover { opacity: .8; }
.parts-table tbody tr.na { opacity: .5; }
.parts-table tbody tr.na td:first-child { box-shadow: inset 3px 0 0 var(--border); }
.hotspot.na { opacity: .35; }
.btn-na { padding: 4px 10px; font-size: .85rem; color: var(--muted); }
.btn-na[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* ---------- Menu des références ---------- */
.ref-menu {
  position: absolute; z-index: 40; min-width: 220px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .18);
  display: grid;
}
.ref-menu[hidden] { display: none; }
.ref-menu-head {
  padding: 6px 10px 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .82rem; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.ref-menu [role=menuitem] {
  display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; border-radius: 6px;
  background: none; color: var(--text); font-size: .9rem; font-weight: 400;
}
.ref-menu [role=menuitem]:hover, .ref-menu [role=menuitem]:focus { background: var(--accent-soft); color: var(--accent); text-decoration: none; outline: none; }
.btn-add { padding: 4px 10px; font-size: .85rem; color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }
.btn-add:hover { background: var(--accent); color: var(--accent-text); }
.btn-x { padding: 4px 8px; border: 0; background: none; color: var(--muted); }
.btn-x:hover { color: var(--danger); }
form.inline, .add-form { display: inline; margin: 0; }
.qty-form input { width: 64px; padding: 4px 6px; font: inherit; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); color: var(--text); }

.list-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.list-head h1 { margin: 0; }
.list-actions { display: flex; gap: 8px; flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #1c2230; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .search .scope { display: none; }
  .listlink { margin-left: auto; }
  .catalog { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; max-height: 45vh; }
  .ill-layout .parts-table th:nth-child(4), .ill-layout .parts-table td.qty { display: none; }
  .results th:nth-child(3), .results td:nth-child(3) { display: none; }
}

@media print {
  .topbar, .crumbs, .sidebar, .viewer-tools, .parts-tools, .list-actions, .act, .footer, #toast, .ref-menu, .notice { display: none !important; }
  body { background: #fff; color: #000; }
  .panel, .parts, .viewer { border: 0; box-shadow: none; }
  .catalog { display: block; }
  .ill-layout { display: block; }
  .viewer-scroll { max-height: none; overflow: visible; }
}

/* ---------- Comptes ---------- */
.acctlink { white-space: nowrap; }
.auth { max-width: 440px; margin: 32px auto; }
.auth h1 { margin-bottom: 1rem; }
.auth-form { display: grid; gap: 14px; margin: 0 0 8px; max-width: 440px; }
.auth-form label { display: grid; gap: 4px; font-weight: 600; font-size: .92rem; }
.auth-form label .muted { font-weight: 400; }
.auth-form input[type=email], .auth-form input[type=password] {
  padding: 9px 12px; font: inherit; font-weight: 400;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text);
}
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.auth-form .muted { margin: 0; font-size: .85rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); justify-content: center; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.auth-form .btn.primary { justify-self: start; padding: 9px 18px; }
.auth-links { margin: 16px 0 0; font-size: .92rem; }
.notice.error { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); }
.account { max-width: 900px; margin: 0 auto; }
.account h2 { margin-top: 28px; }
.account .devices { margin-bottom: 12px; }
.account-actions { margin: 0 0 8px; }
.tag { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; font-size: .75rem; background: var(--accent-soft); color: var(--accent); }
@media (max-width: 860px) {
  .devices th:nth-child(2), .devices td:nth-child(2), .devices th:nth-child(4), .devices td:nth-child(4) { display: none; }
}
