:root {
  --bg: #121214;
  --panel: #1a1a1e;
  --panel-2: #222227;
  --line: #2f2f36;
  --text: #e8e6e1;
  --muted: #9a98a0;
  --accent: #f0a63a;
  --ok: #5fc38a;
  --warn: #f0b23a;
  --bad: #ef6b5b;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 ui-sans-serif, -apple-system, "Segoe UI", system-ui, sans-serif;
}
#app { display: grid; grid-template-columns: 360px 1fr; height: 100%; }

#panel {
  background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 0 16px 24px;
}
#panel header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 0 12px; position: sticky; top: 0; background: var(--panel); z-index: 2;
}
h1 { margin: 0; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 600; line-height: 1.3; }
h1 span { color: var(--accent); font-size: 20px; letter-spacing: .04em; }
h2 { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }

details { border-top: 1px solid var(--line); padding: 10px 0; }
summary { cursor: pointer; font-weight: 600; padding: 4px 0 10px; list-style: none; display: flex; justify-content: space-between; }
summary::after { content: "▾"; color: var(--muted); }
details:not([open]) summary::after { content: "▸"; }
details:not([open]) summary { padding-bottom: 4px; }
summary::-webkit-details-marker { display: none; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
input[type=number], select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 7px 8px; font: inherit; width: 100%; min-width: 0;
}
input[type=color] { width: 100%; height: 34px; padding: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.inline { display: flex; gap: 6px; }
.info { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }

button {
  background: var(--accent); color: #1a1205; border: 0; border-radius: 6px;
  padding: 8px 12px; font: inherit; font-weight: 600; cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.ghost:hover { border-color: var(--muted); }
button.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btnrow { display: flex; gap: 8px; align-items: end; }
.btnrow button { flex: 1; }
.hidden { display: none; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 11px; }
.selname { color: var(--accent); }

#right { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#diagBar { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px 10px; flex: none; }
#diagBar header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
#diagBar h2 { margin: 0; }
#diagSummary { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex: 1; }
#diagSummary b { font-weight: 600; }
#diagSummary .ok { color: var(--ok); } #diagSummary .warn { color: var(--warn); } #diagSummary .bad { color: var(--bad); }
#diagToggle { padding: 4px 10px; font-size: 12px; font-weight: 500; }
#diagBar.collapsed #diag { display: none; }
#diagBar.collapsed header { margin-bottom: 0; }
/* les cartes passent à la ligne ; au-delà de ~2 rangées, le bandeau défile verticalement (molette) */
#diag {
  list-style: none; margin: 0; padding: 0 2px 2px 0; display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  max-height: min(200px, 26vh); overflow-y: auto; overscroll-behavior: contain;
}
#diag li {
  background: var(--panel-2); border-radius: 8px; padding: 8px 10px 8px 12px;
  border-left: 3px solid var(--muted); display: grid; align-content: start; gap: 2px; min-width: 0;
}
#diag li.ok { border-color: var(--ok); }
#diag li.warn { border-color: var(--warn); }
#diag li.bad { border-color: var(--bad); }
#diag .t { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
#diag .v { font-weight: 600; }
#diag .h { font-size: 12px; color: var(--muted); }
#diag li.bad .h { color: var(--bad); }
#diag li.warn .h { color: var(--warn); }

#stage { position: relative; min-width: 0; min-height: 0; flex: 1; }

canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#toolbar {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3;
  display: flex; justify-content: space-between; gap: 8px; pointer-events: none; flex-wrap: wrap;
}
#toolbar > * { pointer-events: auto; }
.seg { display: flex; background: rgba(26,26,30,.85); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; backdrop-filter: blur(6px); }
.seg button { background: transparent; color: var(--text); border-radius: 0; font-weight: 500; }
.seg button.on { background: var(--accent); color: #1a1205; font-weight: 600; }
.toggle { background: rgba(26,26,30,.85); color: var(--text); border: 1px solid var(--line); font-weight: 500; backdrop-filter: blur(6px); }
.toggle.on { background: var(--accent); color: #1a1205; }
#label {
  position: absolute; z-index: 2; pointer-events: none; transform: translate(-50%, -50%);
  background: rgba(18,18,20,.8); color: var(--accent); border: 1px solid var(--accent);
  border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
#loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }

@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100%; }
  #right { order: -1; }
  #stage { height: 55vh; flex: none; }
  #diag { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  #panel { border-right: 0; border-top: 1px solid var(--line); }
  .seg button { padding: 6px 8px; font-size: 12px; }
}

.seg button:disabled { opacity: .35; cursor: default; }
.seg button:disabled:hover { filter: none; }
#toolbar { align-items: flex-start; }
#history { margin-left: auto; margin-right: 8px; }

#itemList { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
#itemList li { display: flex; align-items: center; gap: 6px; border-radius: 6px; }
#itemList li.on { background: var(--panel-2); }
#itemList .pick { flex: 1; text-align: left; background: none; color: var(--text); font-weight: 400; padding: 5px 8px; }
#itemList li.on .pick { color: var(--accent); }
#itemList .sub { color: var(--muted); font-size: 12px; margin-left: 4px; }
#itemList .del { background: none; color: var(--muted); padding: 4px 9px; font-size: 15px; line-height: 1; }
#itemList .del:hover { color: var(--bad); }

#reco { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); align-items: start; }
#reco li { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; border-left: 3px solid var(--muted); display: grid; gap: 4px; }
#reco li.ok { border-color: var(--ok); }
#reco li.warn { border-color: var(--warn); }
#reco li.bad { border-color: var(--bad); opacity: .7; }
#reco li.cur { outline: 1px solid var(--accent); }
#reco .rh { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
#reco .price { color: var(--accent); font-weight: 600; white-space: nowrap; }
#reco .specs, #reco .lum { font-size: 12px; color: var(--muted); }
#reco .fit { font-size: 12px; }
#reco li.ok .fit { color: var(--ok); }
#reco li.warn .fit { color: var(--warn); }
#reco li.bad .fit { color: var(--bad); }
#reco .btnrow { margin-top: 4px; }
#reco .btnrow > * { flex: 1; text-align: center; }
a.buy { background: var(--accent); color: #1a1205; border-radius: 6px; padding: 8px 12px; font-weight: 600; text-decoration: none; }
a.buy:hover { filter: brightness(1.08); }
.aff { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

#ctx {
  position: absolute; z-index: 10; min-width: 210px; max-height: 70%; overflow-y: auto;
  background: rgba(26,26,30,.97); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.45); backdrop-filter: blur(8px);
}
#ctx.hidden { display: none; }
#ctx .ctx-title { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 6px 10px 4px; }
#ctx button {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; width: 100%;
  background: none; color: var(--text); font-weight: 400; text-align: left; padding: 7px 10px; border-radius: 5px;
}
#ctx button:hover, #ctx button:focus-visible { background: var(--panel-2); outline: none; filter: none; }
#ctx button.danger { color: var(--bad); border: 0; }
#ctx kbd { color: var(--muted); }
#ctx hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }

.dim-label {
  position: absolute; z-index: 2; pointer-events: none; transform: translate(-50%, -50%);
  background: var(--accent); color: #1a1205; border-radius: 4px; padding: 1px 6px;
  font-size: 11px; font-weight: 700; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
#reco .new { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 4px; background: var(--accent); color: #1a1205; font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; vertical-align: 1px; }

#optimize { padding: 4px 10px; font-size: 12px; }
#optResult {
  position: relative; background: var(--panel-2); border: 1px solid var(--accent); border-radius: 8px;
  padding: 10px 36px 10px 12px; margin-bottom: 8px; font-size: 13px;
}
#optResult.hidden { display: none; }
#optResult ul { margin: 6px 0; padding-left: 18px; }
#optResult p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
#optResult p.left { color: var(--warn); }
#optResult #optClose { position: absolute; top: 6px; right: 6px; padding: 2px 8px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input:disabled { opacity: .55; }
#diag .act { justify-self: start; margin-top: 4px; padding: 3px 10px; font-size: 12px; }
#reco .shops { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; font-size: 12px; }
#reco .shops span { color: var(--muted); margin-right: 2px; }
#reco .shops a { background: var(--accent); color: #1a1205; border-radius: 5px; padding: 4px 8px; font-weight: 600; text-decoration: none; }
#reco .shops a:hover { filter: brightness(1.08); }
#reco .shops sup { font-size: 9px; margin-left: 1px; }
.foot { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.foot a { color: var(--muted); }
.disclaimer { margin: 0 0 8px; font-size: 11px; color: var(--muted); }
.foot p { margin: 0 0 6px; }

/* fenêtre modale des projecteurs recommandés */
#recoModal {
  width: min(1180px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
#recoModal::backdrop { background: rgba(5,5,7,.65); backdrop-filter: blur(2px); }
#recoModal[open] { display: flex; flex-direction: column; }
#recoModal header { position: relative; padding: 18px 56px 12px 20px; border-bottom: 1px solid var(--line); }
#recoModal h2 { font-size: 18px; letter-spacing: 0; text-transform: none; color: var(--text); margin: 0 0 4px; }
#recoModal .hint { margin: 0; }
#recoModal .filters { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
#recoModal .filters label { min-width: 200px; }
#recoClose { position: absolute; top: 12px; right: 12px; font-size: 20px; line-height: 1; padding: 4px 11px; }
#recoModal #reco { overflow-y: auto; padding: 14px 20px; flex: 1; min-height: 0; }
#recoModal #recoNote { padding: 10px 20px 16px; border-top: 1px solid var(--line); }
#openReco { width: 100%; }
@media (max-width: 800px) { #reco { grid-template-columns: 1fr; } #recoModal { max-height: calc(100vh - 16px); } }
