:root {
  --bg: #15110e;
  --panel: #1d1814;
  --card: #251e19;
  --card-2: #2d241e;
  --line: #3a2f27;
  --line-2: #4a3c32;
  --text: #f2eae3;
  --muted: #b5a598;
  --faint: #7f7064;
  --accent: #eaa24c;
  --accent-2: #f6c27f;
  --accent-ink: #20150c;
  --cocoa: #6b3a24;
  --ok: #5cc27a;
  --warn: #e9b44c;
  --err: #ec6a5e;
  --info: #6fa8ff;
  --r: 12px;
  --r-sm: 8px;
  --h: 44px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
button, select, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

/* ------------------------------------------------------------- barre du haut */
.topbar { position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: rgba(29, 24, 20, .92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; text-decoration: none; color: var(--text); }
.brand svg { width: 28px; height: 28px; flex: none; }
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; }
.tabs { display: none; gap: 4px; margin-left: 18px; }
.tabs a { padding: 8px 14px; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; }
.tabs a.on { background: var(--card-2); color: var(--text); }
.spacer { flex: 1; }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--card-2);
  display: grid; place-items: center; font-weight: 700; cursor: pointer; color: var(--accent-2); }
.menu { position: absolute; right: 12px; top: 58px; min-width: 240px; background: var(--card); border: 1px solid var(--line-2);
  border-radius: var(--r); box-shadow: 0 18px 40px rgba(0,0,0,.45); padding: 6px; z-index: 50; }
.menu .who { padding: 10px 12px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .who b { display: block; }
.menu button, .menu a { display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px 12px; border: 0; background: none;
  text-align: left; border-radius: var(--r-sm); cursor: pointer; text-decoration: none; color: var(--text); }
.menu button:hover, .menu a:hover { background: var(--card-2); }

.banner { margin: 12px 16px 12px; padding: 10px 14px; border-radius: var(--r-sm); background: #3a2a12; border: 1px solid #6d4b16; color: #ffd9a0; font-size: 14px; }
.banner button { margin-left: 6px; }

/* ------------------------------------------------------------- navigation mobile */
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: rgba(29, 24, 20, .96); backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--faint); text-decoration: none; font-size: 11.5px; font-weight: 600; }
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a.on { color: var(--accent); }
main { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px); }

/* ------------------------------------------------------------- boutons et champs */
.btn { min-height: var(--h); padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--card-2); border: 1px solid var(--line-2); border-radius: var(--r-sm); cursor: pointer; font-weight: 600;
  white-space: nowrap; transition: background .12s, border-color .12s, transform .06s; text-decoration: none; color: var(--text); }
.btn:hover { background: #382d25; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--card-2); }
.btn.danger { color: #ffb1a9; border-color: #6a2d27; background: #2c1714; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

label.field { display: block; margin: 0 0 14px; }
label.field > span, .field-label { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
label.field > span em, .field-label em { font-style: normal; font-weight: 400; color: var(--faint); }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: var(--h); padding: 0 12px; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--r-sm); outline: none; }
textarea { padding: 10px 12px; min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(234, 162, 76, .18); }
.unit { position: relative; }
.unit input { padding-right: 52px; }
.unit b { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-weight: 500; color: var(--faint); font-size: 13px; pointer-events: none; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* boutons à choix (segmentés, puces, cartes) */
.seg { display: flex; padding: 3px; background: var(--bg); border: 1px solid var(--line-2); border-radius: 10px; gap: 3px; }
.seg button { flex: 1; min-height: 38px; border: 0; background: none; border-radius: 7px; cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--muted); padding: 0 6px; }
.seg button.on { background: var(--card-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--bg); cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.chip.on { border-color: var(--accent); color: var(--text); background: rgba(234, 162, 76, .12); }
.chip .sw { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25); }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt { position: relative; text-align: left; padding: 14px; border-radius: var(--r); border: 1px solid var(--line-2); background: var(--bg); cursor: pointer; min-height: 104px; display: flex; flex-direction: column; gap: 6px; }
.opt svg { width: 34px; height: 34px; color: var(--accent-2); }
.opt b { font-size: 14.5px; }
.opt small { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.opt.on { border-color: var(--accent); background: rgba(234, 162, 76, .1); box-shadow: 0 0 0 1px var(--accent) inset; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; cursor: pointer; }
.toggle input { appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--line-2); position: relative; flex: none; cursor: pointer; transition: background .15s; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { left: 21px; }
.toggle span b { display: block; font-weight: 600; }
.toggle span small { color: var(--muted); }

/* ------------------------------------------------------------- mise en page analyse */
.page { max-width: 1320px; margin: 0 auto; padding: 16px; }
.analyse { display: flex; flex-direction: column; gap: 14px; }
.stage { position: relative; z-index: 5; margin: -16px -16px 0; height: 38vh; min-height: 240px; background: radial-gradient(ellipse at 50% 30%, #2a211b, #120e0b 75%); border-bottom: 1px solid var(--line); overflow: hidden; }
.stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.stage .empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--faint); padding: 20px; }
.stage .empty svg { width: 64px; height: 64px; opacity: .6; margin-bottom: 8px; }
.stage .hud { position: absolute; left: 10px; right: 10px; top: 10px; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.stage .hud > * { pointer-events: auto; }
.pill { padding: 5px 10px; border-radius: 999px; background: rgba(21,17,14,.78); border: 1px solid var(--line-2); font-size: 12px; font-weight: 600; color: var(--muted); backdrop-filter: blur(6px); }
.stage .layers { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.stage .layers button { min-height: 32px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line-2); background: rgba(21,17,14,.82); color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.stage .layers button.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.legend { position: absolute; left: 10px; bottom: 10px; padding: 8px 10px; border-radius: var(--r-sm); background: rgba(21,17,14,.82); border: 1px solid var(--line-2); font-size: 11.5px; display: grid; gap: 3px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.stage .full { position: absolute; right: 10px; top: 10px; }

.steps { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.steps::-webkit-scrollbar { display: none; }
.steps button { flex: none; display: flex; align-items: center; gap: 7px; min-height: 36px; padding: 0 12px 0 6px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--faint); font-weight: 600; font-size: 13px; cursor: pointer; }
.steps button i { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-size: 12px; background: var(--card-2); }
.steps button.on { color: var(--text); border-color: var(--accent); }
.steps button.on i { background: var(--accent); color: var(--accent-ink); }
.steps button.done i { background: #2b4a33; color: #b9f0c8; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.panel > h2 { font-size: 18px; margin-bottom: 4px; }
.panel > .lead { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); font-weight: 700; margin: 18px 0 10px; }
.actions { position: sticky; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 6; display: flex; gap: 10px; padding: 12px 0; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.actions .btn { flex: 1; }

/* explorateur de la Visionneuse */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 10px; font-size: 13px; }
.crumbs button { border: 0; background: none; color: var(--accent-2); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-weight: 600; }
.crumbs span { color: var(--faint); }
.list { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; margin: 10px -4px 0; padding: 0 4px; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-height: 54px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--card); cursor: pointer; text-align: left; width: 100%; }
.item:hover { border-color: var(--line-2); }
.item.on { border-color: var(--accent); background: rgba(234,162,76,.08); }
.item .ic { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; background: var(--card-2); color: var(--accent-2); flex: none; }
.item .ic svg { width: 20px; height: 20px; }
.item .tx { flex: 1; min-width: 0; }
.item .tx b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.item .tx small { color: var(--muted); font-size: 12.5px; }
.item .end { color: var(--faint); font-size: 12px; text-align: right; flex: none; }
.note { padding: 12px 14px; border-radius: var(--r-sm); background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: 13.5px; }
.note.err { border-color: #6a2d27; background: #2a1613; color: #ffc2bb; }
.note.ok { border-color: #2c5a3a; background: #14251a; color: #bfeccc; }
.hint { font-size: 12.5px; color: var(--faint); margin-top: 6px; }
.range-meter { position: relative; height: 8px; border-radius: 999px; background: linear-gradient(90deg, #4b6bd8, #3fb3a5 35%, #5cc27a 45%, #5cc27a 55%, #e9b44c 65%, #ec6a5e); margin-top: 10px; }
.range-meter i { position: absolute; top: -5px; width: 4px; height: 18px; border-radius: 2px; background: #fff; box-shadow: 0 0 0 2px var(--bg); transform: translateX(-2px); }

/* ------------------------------------------------------------- résultat */
.result-head { display: flex; gap: 18px; align-items: center; }
.ring { --v: 0; --c: var(--ok); width: 116px; height: 116px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--c) calc(var(--v) * 1%), var(--line) 0); position: relative; }
.ring::before { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--panel); }
.ring b { position: relative; font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.ring b small { font-size: 13px; color: var(--muted); font-weight: 600; }
.verdict { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.verdict.ok { background: #173222; color: #9be3b0; }
.verdict.warn { background: #3a2c10; color: #ffd27c; }
.verdict.err { background: #3a1714; color: #ffaaa1; }
.summary { margin-top: 8px; color: var(--muted); font-size: 13.5px; }
.bars { display: grid; gap: 10px; margin-top: 4px; }
.bar { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 13.5px; }
.bar .track { grid-column: 1 / -1; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar .track i { display: block; height: 100%; border-radius: 999px; }
.issues { display: flex; flex-direction: column; gap: 8px; }
.issue { border: 1px solid var(--line); border-left: 4px solid var(--line-2); border-radius: var(--r-sm); background: var(--card); }
.issue summary { list-style: none; display: flex; gap: 10px; align-items: flex-start; padding: 12px; cursor: pointer; }
.issue summary::-webkit-details-marker { display: none; }
.issue .sev { flex: none; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px; border-radius: 999px; margin-top: 1px; }
.issue .t { flex: 1; }
.issue .t b { display: block; }
.issue .t small { color: var(--faint); font-size: 12px; }
.issue .body { padding: 0 12px 12px; color: var(--muted); font-size: 14px; }
.issue .fix { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--bg); color: var(--text); font-size: 13.5px; }
.issue .fix::before { content: "À faire : "; font-weight: 700; color: var(--accent-2); }
.issue.critique { border-left-color: var(--err); } .issue.critique .sev { background: #3a1714; color: #ffaaa1; }
.issue.attention { border-left-color: var(--warn); } .issue.attention .sev { background: #3a2c10; color: #ffd27c; }
.issue.conseil { border-left-color: var(--info); } .issue.conseil .sev { background: #172640; color: #a9c8ff; }
.positives { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.positives li { display: flex; gap: 8px; font-size: 14px; color: var(--muted); }
.positives li::before { content: "✓"; color: var(--ok); font-weight: 800; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.metric { padding: 10px 12px; border-radius: var(--r-sm); background: var(--card); border: 1px solid var(--line); }
.metric small { display: block; color: var(--faint); font-size: 12px; }
.metric b { font-size: 16px; }
.metric em { font-style: normal; color: var(--muted); font-size: 12px; }
.stack { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--line); margin-top: 6px; }
.stack i { display: block; height: 100%; }
.res-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.res-actions .btn { flex: 1 1 160px; }

/* ------------------------------------------------------------- historique et admin */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1 1 200px; }
.score-chip { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; flex: none; }
.score-chip.ok { background: #173222; color: #9be3b0; }
.score-chip.warn { background: #3a2c10; color: #ffd27c; }
.score-chip.err { background: #3a1714; color: #ffaaa1; }
table.perm { width: 100%; border-collapse: collapse; font-size: 14px; }
table.perm th, table.perm td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.perm th.c, table.perm td.c { text-align: center; width: 80px; }
table.perm td small { display: block; color: var(--faint); font-size: 12px; }
table.perm tr.g td { color: var(--accent-2); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding-top: 18px; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--faint); }
.empty-state svg { width: 56px; height: 56px; opacity: .5; }

/* fenêtres */
.modal-back { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; }
.modal { width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px 18px 0 0; padding: 20px 18px calc(18px + var(--safe-b)); }
.modal h3 { font-size: 18px; margin-bottom: 14px; }
.modal .row { margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 18px); transform: translateX(-50%); z-index: 90; padding: 12px 16px; border-radius: 10px; background: #2f261f; border: 1px solid var(--line-2); box-shadow: 0 10px 30px rgba(0,0,0,.4); font-weight: 600; font-size: 14px; max-width: calc(100% - 32px); }
.toast.err { background: #3a1714; border-color: #6a2d27; }

/* progression du calcul */
.progress { position: fixed; inset: 0; z-index: 70; background: rgba(15,11,9,.82); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 24px; }
.progress .box { width: min(360px, 100%); text-align: center; }
.progress .drop { width: 70px; height: 70px; margin: 0 auto 16px; }
.progress .track { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 12px 0 8px; }
.progress .track i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--cocoa), var(--accent)); transition: width .2s; }
@keyframes drip { 0%, 100% { transform: translateY(0) scaleY(1); } 50% { transform: translateY(4px) scaleY(1.06); } }
.progress .drop path { animation: drip 1.4s ease-in-out infinite; transform-origin: 50% 100%; }

/* ------------------------------------------------------------- connexion */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(ellipse at 20% 0%, #3a2416 0%, transparent 55%), radial-gradient(ellipse at 100% 100%, #2a1a10 0%, transparent 50%), var(--bg); }
.login-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.login-card h1 { display: flex; align-items: center; gap: 12px; font-size: 24px; }
.login-card h1 svg { width: 40px; height: 40px; }
.login-card .subtitle { color: var(--muted); margin: 8px 0 22px; }
.login-card .btn { width: 100%; margin-top: 6px; }
.error-msg { color: #ffaaa1; min-height: 20px; font-size: 14px; margin-bottom: 6px; }
.login-card .hub { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--faint); text-align: center; }

/* ------------------------------------------------------------- grand écran */
@media (min-width: 980px) {
  .tabs { display: flex; }
  .bottomnav { display: none; }
  main { padding-bottom: 24px; }
  .actions { bottom: 0; }
  .toast { bottom: 24px; }
  .analyse { display: grid; grid-template-columns: minmax(0, 1fr) 440px; grid-template-rows: auto 1fr; gap: 16px; align-items: start; }
  .analyse .stage { grid-row: 1 / span 2; position: sticky; top: 72px; margin: 0; height: calc(100vh - 104px); border-radius: var(--r); border: 1px solid var(--line); }
  .analyse .side { min-width: 0; }
  .modal-back { align-items: center; }
  .modal { border-radius: 18px; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 340px) {
  .cards { grid-template-columns: 1fr; }
  .result-head { flex-direction: column; text-align: center; }
}

/* ------------------------------------------------------------- impression */
@media print {
  body { background: #fff; color: #000; }
  .topbar, .bottomnav, .actions, .res-actions, .stage .layers, .banner, .steps, .no-print { display: none !important; }
  .panel, .issue, .metric { background: #fff; border-color: #ccc; color: #000; break-inside: avoid; }
  .issue .body, .muted, .summary, .metric small { color: #333; }
  .stage { position: static; height: 300px; border: 1px solid #ccc; }
  .analyse { display: block; }
  main { padding: 0; }
}
