:root {
  --bg: #15171b;
  --bg-2: #1b1e23;
  --panel: #20242a;
  --panel-2: #272c33;
  --line: #333941;
  --line-2: #3f4650;
  --text: #e9e6df;
  --muted: #9aa1aa;
  --dim: #878e97;
  --accent: #f59a23;
  --accent-2: #ffb85c;
  --accent-ink: #1b1d21;
  --ok: #6cc28a;
  --warn: #e8c547;
  --bad: #e5674f;
  --fluid: #5ab0e6;
  --radius: 8px;
  --head: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Barlow', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--body);
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
h2 { font: 600 15px/1.2 var(--head); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.hint { color: var(--dim); font-size: 13px; margin: 0 0 10px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Barre du haut ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 56px; flex: none;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: relative;
}
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 10px, var(--accent-ink) 10px 20px);
  opacity: .9;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 5px; background: var(--accent);
  clip-path: polygon(50% 8%, 94% 88%, 6% 88%);
}
.brand-text { font: 600 20px/1 var(--head); letter-spacing: .03em; text-transform: uppercase; }
.brand-text b { color: var(--accent); font-weight: 700; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs button, .subtabs button {
  background: none; border: 0; cursor: pointer;
  font: 600 15px/1 var(--head); letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 0 14px; border-bottom: 3px solid transparent;
}
.tabs button { height: 100%; }
.tabs button:hover, .subtabs button:hover { color: var(--text); }
.tabs button.active, .subtabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.account { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.account b { color: var(--text); font-weight: 600; }

/* ---------- Boutons / champs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 6px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text);
  font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.ghost:hover { border-color: var(--line-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.icon-btn { background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 15px; padding: 4px 6px; border-radius: 4px; }
.icon-btn:hover { color: var(--bad); background: var(--panel-2); }
input[type=text], input[type=search], input[type=number], input[type=password], input:not([type]), select {
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 6px;
  padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgb(245 154 35 / .15); }
input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
input.invalid { border-color: var(--bad); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--muted); margin: 10px 0; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Layout planificateur ---------- */
.view { flex: 1; min-height: 0; }
.planner { display: grid; grid-template-columns: 380px 1fr; }
.side { overflow-y: auto; border-right: 1px solid var(--line); background: var(--bg-2); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }
.rows { display: flex; flex-direction: column; gap: 8px; }
.row { display: grid; grid-template-columns: 1fr 92px auto; gap: 6px; align-items: center; }
.row .unit { display: none; }
.rows:empty::before { content: 'Aucun'; color: var(--dim); font-size: 13px; }
#targets:empty::before { content: 'Ajoutez un objet à produire.'; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { display: grid; grid-template-columns: 1fr; gap: 6px; }
.seg button {
  text-align: left; padding: 8px 12px; border-radius: 6px; cursor: pointer;
  background: var(--bg); border: 1px solid var(--line-2); color: var(--muted);
}
.seg button.active { border-color: var(--accent); color: var(--text); background: rgb(245 154 35 / .08); }
.seg button.active::before { content: '● '; color: var(--accent); }
details summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
details summary::-webkit-details-marker { display: none; }
details summary::after { content: '▾'; color: var(--dim); }
details[open] summary::after { content: '▴'; }
details summary h2 { margin: 0; }
details[open] summary { margin-bottom: 10px; }
.limits { display: grid; grid-template-columns: 1fr 110px; gap: 6px 8px; align-items: center; margin-bottom: 10px; font-size: 14px; }
.limits input { padding: 5px 8px; }

/* ---------- Résultats ---------- */
.results { overflow-y: auto; padding: 20px 24px 40px; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { font: 600 12px/1 var(--head); letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.stat .value { font: 600 28px/1.1 var(--head); margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 15px; color: var(--muted); margin-left: 3px; }
.stat.accent { border-color: rgb(245 154 35 / .5); }
.stat.accent .value { color: var(--accent); }
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.subtabs button { padding: 10px 14px; margin-bottom: -1px; }

.alert { background: rgb(229 103 79 / .12); border: 1px solid rgb(229 103 79 / .5); color: #f2a395; border-radius: 6px; padding: 10px 12px; margin: 0 0 14px; font-size: 14px; }
.empty { color: var(--dim); text-align: center; padding: 60px 20px; border: 1px dashed var(--line-2); border-radius: var(--radius); }
.empty strong { display: block; font: 600 22px var(--head); color: var(--muted); margin-bottom: 6px; letter-spacing: .03em; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { font: 600 12px/1 var(--head); letter-spacing: .1em; text-transform: uppercase; color: var(--dim); text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: rgb(255 255 255 / .02); }
td.r, th.r { text-align: right; }
.recipe-name { font-weight: 600; }
.alt-tag { display: inline-block; font: 600 11px/1 var(--head); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); border: 1px solid rgb(245 154 35 / .5); border-radius: 3px; padding: 3px 5px 2px; margin-left: 6px; vertical-align: 2px; }
.building { color: var(--muted); font-size: 13px; }
.machines b { font: 600 18px var(--head); }
.machines .exact { color: var(--dim); font-size: 12px; display: block; }
.flows { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; gap: 6px; align-items: baseline; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 2px 7px; font-size: 13px; white-space: nowrap; }
.chip .q { font-variant-numeric: tabular-nums; color: var(--accent-2); font-weight: 600; }
.chip.fluid .q { color: var(--fluid); }
.chip.raw { border-color: var(--line-2); }
.arrow { color: var(--dim); }
.section-title { font: 600 16px var(--head); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 26px 0 10px; }
.bar { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin-top: 5px; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--ok); }
.bar i.warn { background: var(--warn); }
.bar i.bad { background: var(--bad); }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

#graph { height: 640px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- Navigateur ---------- */
.browser { display: flex; flex-direction: column; padding: 20px 24px; gap: 14px; }
.browser-head input { max-width: 520px; font-size: 16px; padding: 10px 14px; }
.browser-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 320px 1fr; gap: 20px; }
.item-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); }
.item-list li { padding: 7px 10px; border-radius: 5px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.item-list li:hover { background: var(--panel-2); }
.item-list li.active { background: rgb(245 154 35 / .12); color: var(--accent-2); }
.item-list li small { color: var(--dim); }
.browse-detail { overflow-y: auto; }
.browse-detail h1 { font: 700 30px var(--head); margin: 0 0 4px; letter-spacing: .02em; }
.browse-detail .meta { color: var(--muted); margin-bottom: 16px; font-size: 14px; }
.rcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.rcard-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.rcard .flows { align-items: center; }
.link { color: var(--accent); cursor: pointer; text-decoration: none; background: none; border: 0; padding: 0; }
.link:hover { text-decoration: underline; }

/* ---------- Mes plans ---------- */
.plans { padding: 24px; overflow-y: auto; }
.plans-wrap { max-width: 900px; margin: 0 auto; }
.plans h1 { font: 700 30px var(--head); margin: 0 0 16px; letter-spacing: .02em; }
.plan-row { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.plan-row .grow { flex: 1; min-width: 0; }
.plan-row .name { font-weight: 600; }
.plan-row .date { color: var(--dim); font-size: 13px; }
.pill { font: 600 11px/1 var(--head); letter-spacing: .08em; text-transform: uppercase; padding: 4px 6px 3px; border-radius: 3px; background: rgb(108 194 138 / .15); color: var(--ok); }

/* ---------- Modales ---------- */
.dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 10px; padding: 18px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgb(0 0 0 / .5); }
.dialog.wide { width: min(980px, calc(100vw - 32px)); height: min(80vh, 900px); display: flex; flex-direction: column; }
.dialog.wide:not([open]) { display: none; }
.dialog::backdrop { background: rgb(0 0 0 / .6); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.dialog-head h2 { margin: 0; color: var(--text); font-size: 18px; }
.dialog label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.dialog-tools { display: grid; grid-template-columns: 1fr 160px auto auto; gap: 8px; margin-bottom: 12px; }
.recipe-list { overflow-y: auto; flex: 1; border-top: 1px solid var(--line); }
.rgroup { padding: 10px 0; border-bottom: 1px solid var(--line); }
.rgroup h3 { font: 600 15px var(--head); letter-spacing: .04em; margin: 0 0 6px; color: var(--accent-2); }
.ritem { display: grid; grid-template-columns: 22px minmax(200px, 300px) 1fr; gap: 8px; align-items: start; padding: 5px 4px; border-radius: 4px; cursor: pointer; }
.ritem:hover { background: var(--panel-2); }
.ritem input { accent-color: var(--accent); width: 16px; height: 16px; margin-top: 2px; }
.ritem .building { display: block; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--accent); padding: 10px 16px; border-radius: 6px; box-shadow: 0 10px 30px rgb(0 0 0 / .4); z-index: 100; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  body { height: auto; min-height: 100%; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px 16px; }
  .tabs { order: 3; width: 100%; height: 38px; overflow-x: auto; }
  .planner { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); padding: 16px; }
  .results { padding: 16px; overflow: visible; }
  .browser { padding: 16px; }
  .browser-body { grid-template-columns: 1fr; }
  .item-list { max-height: 260px; }
  .dialog-tools { grid-template-columns: 1fr 1fr; }
  .ritem { grid-template-columns: 22px 1fr; }
  .ritem .flows { grid-column: 2; }
  .table-wrap { overflow-x: auto; }
  #graph { height: 460px; }
}

/* ---------- Correctifs de spécificité ---------- */
.dialog label.ritem { display: grid; flex-direction: initial; margin: 0; color: var(--text); font-size: 15px; }
.chip.link { background: var(--bg); border: 1px solid var(--line); color: var(--text); padding: 2px 7px; }
.chip.link:hover { border-color: var(--accent); text-decoration: none; }
td .building { display: block; margin-top: 2px; }
.bar { width: 120px; margin-left: auto; }

/* ---------- Collaboration ---------- */
.save-panel .status { margin: 0 0 12px; min-height: 1em; }
.collab { border-top: 1px solid var(--line); margin: 4px 0 14px; padding-top: 12px; }
.collab h3 { font: 600 13px/1 var(--head); letter-spacing: .1em; text-transform: uppercase; color: var(--dim); margin: 0 0 8px; }
.people { list-style: none; margin: 0 0 6px; padding: 0; }
.people li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
.people .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.people .role { font: 600 11px/1 var(--head); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgb(108 194 138 / .18); }
.invite { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin: 8px 0; }
.invite input { padding: 6px 9px; }
.pill.team { background: rgb(245 154 35 / .15); color: var(--accent-2); }
.plans-sub { margin: 28px 0 12px; }
input:disabled { opacity: .6; }

/* ---------- Partage ---------- */
.gallery { padding: 24px; overflow-y: auto; }
.gallery-wrap { max-width: 1280px; margin: 0 auto; }
.gallery h1 { font: 700 30px var(--head); margin: 0 0 4px; letter-spacing: .02em; }
.gallery-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 18px; }
.gallery-head .hint { margin: 0; }
.gallery-tools { display: grid; grid-template-columns: minmax(220px, 340px) 150px; gap: 8px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.gcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.gcard:hover { border-color: var(--line-2); }
.gcard h3 { font: 700 21px/1.15 var(--head); margin: 0; letter-spacing: .02em; overflow-wrap: anywhere; }
.gcard .by { color: var(--muted); font-size: 13px; }
.gcard .by b { color: var(--text); font-weight: 600; }
.gcard .desc { color: var(--muted); font-size: 14px; margin: 0; white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.gcard .gstats { display: flex; gap: 16px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; margin-top: auto; }
.gcard .gstats b { color: var(--text); font: 600 16px var(--head); margin-right: 3px; }
.gcard .gstats .mw b { color: var(--accent); }
.gcard .actions { display: flex; gap: 8px; }
.gcard .actions .btn { flex: 1; }
.gallery-more { display: flex; justify-content: center; margin-top: 18px; }
.publish { border-top: 1px solid var(--line); margin: 4px 0 14px; padding-top: 12px; font-size: 14px; }
.publish .row-actions { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 6px; }
.dialog textarea { background: var(--bg); border: 1px solid var(--line-2); border-radius: 6px; padding: 8px 10px; width: 100%; resize: vertical; font: inherit; color: inherit; }
.dialog textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgb(245 154 35 / .15); }
.hint-inline { color: var(--dim); font-size: 13px; }
.pill.shared { background: rgb(90 176 230 / .15); color: var(--fluid); }
@media (max-width: 900px) {
  .gallery { padding: 16px; }
  .gallery-tools { grid-template-columns: 1fr 130px; width: 100%; }
}

/* ---------- Diagnostic « aucune solution » ---------- */
#result-error strong { display: block; color: #f6b3a6; }
.diag { margin: 8px 0 0; padding-left: 18px; color: var(--text); }
.diag li { margin: 4px 0; }
.diag-hint { color: var(--muted); font-size: 13px; }
.diag-max { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 10px 0 0; color: var(--text); }

.graph-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.graph-bar .hint { margin: 0; }

.update-banner { position: fixed; top: 66px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; align-items: center; gap: 12px; background: var(--panel-2); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 10px 8px 14px; box-shadow: 0 10px 30px rgb(0 0 0 / .45); font-size: 14px; max-width: calc(100vw - 32px); }

/* ---------- SatiLab : outil courant dans la barre ---------- */
.brand-tool { font: 600 15px/1 var(--head); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding-left: 14px; margin-left: -10px; border-left: 1px solid var(--line-2); }
@media (max-width: 900px) { .brand-tool { display: none; } }

/* ---------- Outil Énergie ---------- */
body[data-site="energie"] .only-calcul, body:not([data-site="energie"]) .only-energie { display: none !important; }
.mw-input { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.mw-input input { font: 700 28px/1 var(--head); padding: 8px 12px; text-align: right; }
.mw-input span { font: 700 22px var(--head); color: var(--accent); }
.geo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.geo label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.geo input { padding: 6px 8px; }

.energy-options { margin-bottom: 20px; }
.energy-options:empty { display: none; }
.eo-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 16px; margin-bottom: 8px; }
.eo-head h2 { margin: 0; color: var(--text); font-size: 18px; }
.eo-head .hint { margin: 0; }
.eo-table tbody tr { cursor: pointer; }
.eo-table td { vertical-align: middle; }
.eo-table tr.active td { background: rgb(245 154 35 / .09); }
.eo-table tr.active td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.eo-table .opt-name { font-weight: 600; }
.eo-table .building { display: block; }
.eo-table .big { font: 700 20px var(--head); }
.eo-table tr.ko td { color: var(--dim); }
.eo-table tr.ko .opt-name { font-weight: 500; }
.eo-table .reason { font-size: 13px; }
.best-tag { display: inline-block; font: 600 11px/1 var(--head); letter-spacing: .08em; text-transform: uppercase; color: var(--accent-ink); background: var(--accent); border-radius: 3px; padding: 3px 5px 2px; margin-left: 8px; vertical-align: 2px; }
.alert.warn-note { background: rgb(232 197 71 / .1); border-color: rgb(232 197 71 / .45); color: #eed98a; margin-top: 12px; }
.eo-table tr.ko-toggle { cursor: default; }
.eo-table tr.ko-toggle td { padding: 10px; border-bottom: 0; }

/* Énergie v2 : total en tête */
.eo-hero { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 14px; }
.eo-label { font: 600 15px var(--head); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.eo-total { font: 800 52px/1 var(--head); color: var(--accent); font-variant-numeric: tabular-nums; }
.eo-total small { font-size: 24px; margin-left: 4px; color: var(--accent-2); }
.eo-sub { color: var(--muted); }
.eo-table tr.mix td { background: rgb(245 154 35 / .05); }
.eo-table tr.mix.active td { background: rgb(245 154 35 / .12); }
.eo-table td.r { white-space: nowrap; }
