:root {
  --ink: #16161d;
  --ink-2: #3a3c48;
  --muted: #646876;
  --line: #e4e4ec;
  --bg: #f4f4f8;
  --card: #ffffff;
  --dark: #111117;
  --magenta: #e4005e;
  --magenta-soft: #fdebf3;
  --teal: #1fb5c3;
  --teal-d: #0d8a96;
  --teal-soft: #e7f7f9;
  --green: #138a5e;
  --green-soft: #e6f5ee;
  --purple: #622181;
  --purple-soft: #f1eaf6;
  --lav: #a08dc3;
  --thermal: #7a7f8e;
  --thermal-soft: #eff0f3;
  --warn: #b45309;
  --warn-soft: #fff4e5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 4px 18px rgba(20, 20, 40, .05);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Outfit', 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font); font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--teal-d); }

/* ---------- Barre supérieure ---------- */
.topbar {
  background: var(--dark); color: #fff; position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; padding: 10px 24px;
}
.topbar .logo { height: 34px; width: auto; display: block; }
.topbar .app-name { font-family: var(--display); font-weight: 500; opacity: .8; font-size: 15px; padding-left: 16px; border-left: 1px solid rgba(255,255,255,.2); }
.topbar .spacer { flex: 1; }
.seg { display: inline-flex; background: rgba(255,255,255,.1); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; color: inherit; padding: 5px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 13px; opacity: .75; }
.seg button[aria-pressed="true"] { background: #fff; color: var(--ink); opacity: 1; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 10px; color: #fff; opacity: .8; text-decoration: none; }
.icon-btn:hover { opacity: 1; background: rgba(255,255,255,.1); }

/* ---------- Navigation entre simulateurs ---------- */
.nav-seg a { color: inherit; text-decoration: none; padding: 5px 14px; border-radius: 999px; font-weight: 600; font-size: 13px; opacity: .75; }
.nav-seg a[aria-current="page"] { background: #fff; color: var(--ink); opacity: 1; }
.nav-seg a:hover { opacity: 1; }

/* ---------- En-tête ---------- */
.hero {
  background: linear-gradient(115deg, var(--dark) 0%, #1c1630 60%, #2a1240 100%);
  color: #fff; padding: 34px 24px 72px;
}
.hero .wrap { max-width: 1320px; margin: 0 auto; }
.hero h1 { font-size: clamp(26px, 3.4vw, 40px); font-weight: 700; line-height: 1.12; max-width: 900px; }
.hero h1 .t { color: var(--teal); }
.hero h1 .m { color: #ff3d8b; }
.hero p { margin: 10px 0 0; opacity: .8; max-width: 720px; }

/* ---------- Mise en page ---------- */
.layout {
  max-width: 1320px; margin: -48px auto 0; padding: 0 24px 48px;
  display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start;
}
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }

/* ---------- Panneau de saisie ---------- */
.inputs { padding: 20px; position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
.inputs h2 { font-size: 18px; margin-bottom: 4px; }
.inputs .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.field { padding: 12px 0; border-top: 1px solid var(--line); }
.field:first-of-type { border-top: 0; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.field label, .field .label { font-weight: 600; font-size: 14px; }
.field .unit { color: var(--muted); font-size: 12px; }
.slide-row { display: grid; grid-template-columns: 1fr 92px; gap: 12px; align-items: center; }
.num-input {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fafafd;
  font-weight: 700; text-align: right; font-size: 16px;
}
.num-input:focus, .text-input:focus { outline: 2px solid var(--teal); outline-offset: 1px; border-color: transparent; }
.text-input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fafafd; }
input[type=range] { width: 100%; accent-color: var(--magenta); height: 28px; }
.seg-light { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg-light button { border: 0; background: none; padding: 7px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg-light button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.reco { margin-top: 8px; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.chip-btn { border: 1px solid var(--teal); color: var(--teal-d); background: var(--teal-soft); border-radius: 999px; padding: 3px 10px; font-weight: 600; font-size: 12px; cursor: pointer; }
.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; font-size: 14px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--magenta); }
.opt-val { margin: 8px 0 0 28px; display: none; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.opt-val.on { display: grid; }
.opt-val .num-input { width: 100px; font-size: 14px; }
.sect { font-size: 15px; margin: 14px 0 0; padding-top: 14px; border-top: 2px solid var(--line); color: var(--ink-2); }
.seg-5 { grid-template-columns: repeat(5, 1fr); }
.seg-5 button { padding: 7px 2px; font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini { display: grid; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.mini .num-input { font-size: 15px; }
select.text-input { padding: 7px 8px; font-weight: 600; }
.co2-note { grid-column: 1 / -1; font-size: 12px; color: var(--green); text-align: center; margin-top: -4px; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 620px; }
.tbl th { text-align: right; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.tbl td { text-align: right; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl td.pos { color: var(--magenta); font-weight: 700; }
.tbl td.neg { color: var(--muted); }
.tbl .ok { color: var(--green); font-weight: 700; }
.tbl .ko { color: #b42318; font-weight: 700; }
.bar-mini { display: inline-block; width: 46px; height: 6px; background: #e8e8ef; border-radius: 3px; vertical-align: middle; margin-right: 6px; overflow: hidden; }
.bar-mini i { display: block; height: 100%; background: var(--teal); }
.inaction { display: flex; flex-wrap: wrap; gap: 10px 24px; align-items: baseline; background: #232634; color: #fff; border-radius: 11px; padding: 12px 16px; }
.inaction b { font-family: var(--display); font-size: 24px; color: #ff6aa6; }
.inaction span { opacity: .85; font-size: 13.5px; }
.alert.bad { background: #fdecec; color: #8a1c13; }
.ref { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; padding: 16px 20px; background: linear-gradient(110deg, #fff 0%, #fdf1f6 100%); }
.ref img { height: 54px; width: auto; }
.ref .q { font-family: var(--display); font-weight: 600; font-size: 17px; }
.ref .nums { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 4px; font-size: 13.5px; color: var(--ink-2); }
.ref .nums b { font-family: var(--display); font-size: 20px; color: var(--magenta); margin-right: 4px; }
.fin3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 620px) { .fin3 { grid-template-columns: 1fr; } .ref { grid-template-columns: 1fr; } }
details.more summary { cursor: pointer; font-weight: 600; font-size: 14px; padding: 12px 0 4px; color: var(--ink-2); border-top: 1px solid var(--line); }

/* ---------- Résultats ---------- */
.results { display: grid; gap: 20px; min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.kpi svg { flex: none; color: var(--ink-2); }
.kpis .kpi > div { min-width: 0; container-type: inline-size; flex: 1; }
.kpi .v { font-family: var(--display); font-size: min(26px, 15cqi); font-weight: 700; color: var(--teal-d); line-height: 1.1; white-space: nowrap; }
.kpi .l { font-size: 13px; color: var(--muted); line-height: 1.3; }

.blocks { display: grid; grid-template-columns: 1.15fr 1fr 1.25fr; gap: 16px; }
.block { overflow: hidden; display: flex; flex-direction: column; }
.block-h { padding: 11px 18px; color: #fff; font-family: var(--display); font-weight: 600; font-size: 17px; }
.block-b { padding: 14px; display: grid; gap: 12px; flex: 1; }
.h-dark { background: #232634; }
.h-mag { background: var(--magenta); }
.h-green { background: var(--green); }
.h-purple { background: var(--purple); }
.h-teal { background: var(--teal-d); }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { border-radius: 11px; padding: 12px 14px; container-type: inline-size; min-width: 0; }
.tile .t { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.tile .big { font-family: var(--display); font-size: clamp(17px, 15cqi, 30px); font-weight: 700; line-height: 1.15; margin: 4px 0; white-space: nowrap; }
.tile .d { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.tile.thermal { background: var(--thermal-soft); }
.tile.elec { background: var(--teal-soft); }
.tile.elec .big { color: var(--teal-d); }
.tile.mag { background: var(--magenta-soft); text-align: center; }
.tile.mag .big { color: var(--magenta); font-size: clamp(26px, 15cqi, 44px); }
.tile.green { background: var(--green-soft); }
.tile.green .big { color: var(--green); }
.tile.purple { background: var(--purple-soft); }
.tile.purple .big { color: var(--purple); }
.pill { display: inline-block; margin-top: 8px; padding: 4px 12px; border-radius: 8px; font-weight: 700; font-family: var(--display); font-size: 22px; }
.pill small { display: block; font: 500 12px var(--font); color: var(--muted); }
.pill.mag { background: #fbd3e4; color: var(--magenta); }
.pill.green { background: #cdebdc; color: var(--green); }
.sub-eco { font-size: 12.5px; color: var(--muted); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.metric-list { display: grid; gap: 0; }
.metric { display: flex; justify-content: space-between; gap: 12px; padding: 8px 2px; border-bottom: 1px dashed var(--line); font-size: 14px; }
.metric:last-child { border-bottom: 0; }
.metric b { font-weight: 700; white-space: nowrap; }
.gauge { height: 10px; background: #fde7d1; border-radius: 999px; overflow: hidden; }
.gauge > span { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--teal-d)); border-radius: 999px; transition: width .25s; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.45; }
.alert.warn { background: var(--warn-soft); color: #7a3e06; }
.alert.ok { background: var(--teal-soft); color: #08525a; }

.indic { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.indic .kpi { flex-direction: column; align-items: flex-start; gap: 2px; }
.indic .v { color: var(--ink); font-size: 22px; }
.indic .v.pos { color: var(--magenta); }

.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card { padding: 16px 18px; }
.chart-card h3 { font-size: 16px; margin-bottom: 8px; }
.chart-card.wide { grid-column: 1 / -1; }
.chart-card.wide .chart { max-height: 300px; }
.keys { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.keys span { display: inline-flex; align-items: center; gap: 7px; }
.keys i { display: inline-block; width: 22px; height: 0; border-top: 3px solid var(--magenta); }
.keys i.inv { border-top: 2px dashed var(--purple); }
.keys i.area { height: 10px; border: 0; background: rgba(228,0,94,.15); }
.chart-card .legend { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #e8e8ef; stroke-width: 1; }
.chart .tick { font: 11px var(--font); fill: #7c8090; }
.chart .val { font: 700 14px var(--display); fill: var(--ink); }
.chart .lbl { font: 600 12.5px var(--font); fill: var(--ink-2); }
.chart .sub { font: 11px var(--font); fill: #7c8090; }
.chart .badge { fill: var(--magenta); }
.chart .badge-t { font: 700 12px var(--font); fill: #fff; }
.chart .invest-line { stroke: var(--purple); stroke-width: 2; stroke-dasharray: 6 5; }
.chart .eco-line { stroke: var(--magenta); stroke-width: 3; }
.chart .gain-area { fill: rgba(228, 0, 94, .1); }
.chart .be-line { stroke: var(--purple); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .be-dot { fill: #fff; stroke: var(--purple); stroke-width: 3; }
.chart .lbl-invest { font: 600 12px var(--font); fill: var(--purple); }
.chart .lbl-eco { font: 600 12px var(--font); fill: var(--magenta); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.btn { border: 0; border-radius: 11px; padding: 12px 20px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.btn.primary { background: var(--magenta); color: #fff; }
.btn.primary:hover { background: #c70052; }
.btn.ghost { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: #c9c9d6; }
.btn.dark { background: var(--ink); color: #fff; }

.hyp { padding: 16px 20px; font-size: 13px; color: var(--ink-2); }
.hyp h3 { font-size: 15px; margin-bottom: 6px; }
.hyp ul { margin: 0; padding-left: 18px; columns: 2; column-gap: 32px; }
.hyp li { margin: 3px 0; break-inside: avoid; }
.disclaimer { font-size: 12px; color: var(--muted); margin-top: 10px; }

.site-foot { max-width: 1320px; margin: 0 auto; padding: 0 24px 30px; color: var(--muted); font-size: 12.5px; display: flex; gap: 16px; flex-wrap: wrap; justify-content: space-between; }

.banner { max-width: 1320px; margin: 12px auto 0; padding: 0 24px; }
.banner .alert { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- Boîte de dialogue ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 10, 20, .55); }
.dlg-b { padding: 22px; display: grid; gap: 14px; }
.dlg-b h2 { font-size: 20px; }
.dlg-b label { font-weight: 600; font-size: 14px; display: grid; gap: 6px; }
.dlg-b .hint { color: var(--muted); font-size: 13px; margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; z-index: 50; font-size: 14px; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#report { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1520px) {
  .blocks { grid-template-columns: 1fr 1fr; }
  .blocks .block:last-child { grid-column: 1 / -1; }
}
@media (max-width: 1180px) {
  .blocks { grid-template-columns: 1fr 1fr; }
  .blocks .block:last-child { grid-column: 1 / -1; }
  .kpis, .indic { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .inputs { position: static; max-height: none; }
  .charts, .row2 { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .topbar .app-name { display: none; }
  .topbar .logo { height: 26px; }
  .topbar .nav-seg a { padding: 5px 10px; font-size: 12px; }
  .hero { padding: 24px 16px 64px; }
  .layout { padding: 0 16px 40px; }
  .blocks { grid-template-columns: 1fr; }
  .kpi { padding: 12px 14px; }
  .kpis .kpi svg { display: none; }
  .hyp ul { columns: 1; }
  .actions .btn { flex: 1; justify-content: center; }
  .banner, .site-foot { padding-left: 16px; padding-right: 16px; }
}
