/* Portails MCP Énergie (/espace et /admin) : mêmes couleurs que le site vitrine,
   clair et sombre. Aucune ressource externe (politique de sécurité : style-src
   'self', img-src 'self', pas de script) : polices du système, icônes en SVG
   dans la page. */
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0b1b2b;
  --text-2: #3c4b5c;
  --muted: #64748b;
  --line: #e3e8ee;
  --line-2: #cfd7e1;
  --accent: #087a54;
  --accent-hover: #06603f;
  --accent-soft: #e3f6ec;
  --accent-text: #ffffff;
  --mark-bg: #0b1b2b;
  --mark-fg: #9df2b1;
  --danger: #c0262d;
  --danger-hover: #9f1d23;
  --danger-soft: #fdecec;
  --ok-bg: #e3f6ec;
  --ok-text: #0b5f3f;
  --err-bg: #fdecec;
  --err-text: #8f1d24;
  --warn-bg: #fff5d9;
  --warn-text: #6b4e00;
  --info-bg: #e7effd;
  --info-text: #1f4b8f;
  /* Barre latérale de /admin : sombre, pour ne pas confondre avec /espace. */
  --admin-side: #0b1b2b;
  --admin-text: #e6edf3;
  --admin-muted: #9fb0c2;
  --admin-hover: rgba(255, 255, 255, 0.08);
  --admin-active: rgba(255, 255, 255, 0.12);
  --admin-chip-bg: #f59e0b;
  --admin-chip-text: #1f1300;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(11, 27, 43, 0.04), 0 6px 24px rgba(11, 27, 43, 0.05);
  --focus: 0 0 0 3px rgba(8, 122, 84, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1118;
    --panel: #111a24;
    --panel-2: #15202c;
    --text: #e6edf3;
    --text-2: #c2ced9;
    --muted: #8b9aab;
    --line: #213041;
    --line-2: #2d3f52;
    --accent: #34d399;
    --accent-hover: #6ee7b7;
    --accent-soft: #0f2e22;
    --accent-text: #052016;
    --mark-bg: #0b1b2b;
    --danger: #f87171;
    --danger-hover: #fca5a5;
    --danger-soft: #3a1a1d;
    --ok-bg: #0f2e22;
    --ok-text: #86efac;
    --err-bg: #3a1a1d;
    --err-text: #fca5a5;
    --warn-bg: #352a10;
    --warn-text: #fcd34d;
    --info-bg: #15263f;
    --info-text: #a9c7f5;
    --admin-side: #05090d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --focus: 0 0 0 3px rgba(52, 211, 153, 0.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
code, pre { font-family: var(--mono); font-size: 0.88em; }
code {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 6px; word-break: break-word;
}
pre {
  background: var(--mark-bg); color: #d7e3ee; border-radius: var(--radius-sm);
  padding: 14px 16px; overflow-x: auto; line-height: 1.6;
}
small { color: var(--muted); }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.skip {
  position: absolute; left: -999px; top: 8px; z-index: 10;
  background: var(--panel); padding: 8px 12px; border-radius: 8px;
}
.skip:focus { left: 8px; }

/* ---------- Mise en page : barre latérale + contenu ---------- */
.app {
  display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh;
  /* Colonne de la barre latérale jusqu'en bas, même sur une page longue. */
  background: linear-gradient(90deg, var(--panel) 0 251px, var(--line) 251px 252px, transparent 252px);
}
.platform-admin .app { background: linear-gradient(90deg, var(--admin-side) 0 252px, transparent 252px); }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 14px 16px; background: var(--panel); border-right: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px; padding: 2px 8px;
  color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -0.01em;
}
.brand:hover { color: var(--text); }
.brand b { color: var(--accent); font-weight: 700; }
.mark { width: 32px; height: 32px; flex: none; border-radius: 9px; }
.org-chip {
  display: flex; flex-direction: column; gap: 1px; margin: 0 4px; padding: 10px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.org-chip small { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.org-chip strong { font-size: 14px; overflow-wrap: anywhere; }
.org-chip.admin { background: var(--admin-chip-bg); border-color: var(--admin-chip-bg); color: var(--admin-chip-text); }
.org-chip.admin small { color: var(--admin-chip-text); opacity: 0.8; }

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); text-decoration: none; font-weight: 500; white-space: nowrap;
}
.side-nav a:hover { background: var(--panel-2); color: var(--text); }
.side-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.side-nav .sep { height: 1px; background: var(--line); margin: 8px 6px; }
.side-nav a.switch { color: var(--muted); }

.side-foot { display: flex; flex-direction: column; gap: 8px; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; text-transform: uppercase;
}
.who span:last-child { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.who strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { font-size: 12px; }
.logout { margin: 0; }
.logout button { width: 100%; justify-content: center; }

/* Administration plateforme : barre latérale sombre et pastille ambre. */
.platform-admin .side { background: var(--admin-side); border-right-color: var(--admin-side); color: var(--admin-text); }
.platform-admin .brand, .platform-admin .brand:hover { color: #ffffff; }
.platform-admin .brand b { color: var(--mark-fg); }
.platform-admin .side-nav a { color: var(--admin-muted); }
.platform-admin .side-nav a:hover { background: var(--admin-hover); color: #ffffff; }
.platform-admin .side-nav a.active { background: var(--admin-active); color: #ffffff; box-shadow: inset 3px 0 0 var(--admin-chip-bg); }
.platform-admin .side-nav .sep, .platform-admin .side-foot { border-color: rgba(255, 255, 255, 0.1); }
.platform-admin .side-nav .sep { background: rgba(255, 255, 255, 0.1); }
.platform-admin .who small { color: var(--admin-muted); }
.platform-admin .avatar { background: rgba(255, 255, 255, 0.12); color: #ffffff; }
.platform-admin .logout button { background: transparent; color: var(--admin-muted); border-color: rgba(255, 255, 255, 0.16); }
.platform-admin .logout button:hover { color: #ffffff; background: var(--admin-hover); }

.content { min-width: 0; width: 100%; max-width: 1280px; padding: 32px 32px 64px; }

/* ---------- En-tête de page ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin: 0 0 24px; }
.page-head > div:first-child { max-width: 760px; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.back { display: inline-flex; align-items: center; gap: 6px; margin: 0 0 10px; font-size: 14px; text-decoration: none; color: var(--muted); }
.back:hover { color: var(--text); }
.eyebrow { margin: 0 0 4px; font-size: 12px; font-weight: 650; letter-spacing: 0.07em; text-transform: uppercase; color: var(--accent); }
h1 { font-size: 1.75rem; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 8px; }
h2 { font-size: 1.1rem; letter-spacing: -0.01em; margin: 0 0 6px; }
h3 { font-size: 0.95rem; margin: 22px 0 8px; }
.lead { color: var(--text-2); font-size: 1rem; margin: 0; }
.hint { color: var(--muted); font-size: 0.9em; margin: 0 0 12px; }
ul.hint { padding-left: 20px; margin-top: 12px; }
ul.hint li + li { margin-top: 4px; }
.more { font-size: 0.8em; font-weight: 500; margin-left: 8px; color: var(--muted); }
a.more { color: var(--accent); }

/* ---------- Cartes ---------- */
section {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; margin: 0 0 20px;
}
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }
.section-head .hint { margin: 0; }
section > .scroll:first-child, section > .scroll:only-child { margin: -4px -6px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 0 0 20px; }
.cards > section { margin: 0; }
.card-icon {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); margin-bottom: 12px;
}
.card-icon .icon { width: 20px; height: 20px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin: 0 0 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat small { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat strong { display: block; font-size: 1.7rem; letter-spacing: -0.02em; line-height: 1.25; font-variant-numeric: tabular-nums; }

/* Bloc mis en avant : connexion d'une IA. */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #0b1b2b 0%, #0f2f3a 100%); color: #e6edf3; border: 0;
}
.hero h2 { color: #ffffff; font-size: 1.25rem; }
.hero .lead { color: #c2ced9; }
.hero a:not(.button) { color: var(--mark-fg); }
.hero .copy { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.18); color: #ffffff; }
.copy {
  display: inline-block; max-width: 100%; margin: 12px 0 4px; padding: 10px 14px; font-size: 1em;
  border-radius: var(--radius-sm); user-select: all; -webkit-user-select: all; overflow-wrap: anywhere;
}
.steps { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 10px; counter-reset: step; }
.steps + .hint { margin-top: 16px; }
.steps li { position: relative; padding-left: 36px; counter-increment: step; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent);
}
.hero .steps li::before { background: rgba(157, 242, 177, 0.16); color: var(--mark-fg); }

/* ---------- Tableaux ---------- */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650;
  background: var(--panel-2); white-space: nowrap; border-bottom-color: var(--line-2);
}
thead th:first-child { border-top-left-radius: 8px; }
thead th:last-child { border-top-right-radius: 8px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.empty { color: var(--muted); text-align: center; padding: 28px 16px; }
td code { white-space: nowrap; word-break: normal; }
td.desc { min-width: 18em; font-size: 0.92em; color: var(--muted); }
td.nowrap, th.nowrap { white-space: nowrap; }
tr.dim td { color: var(--muted); }
tr.dim td .badge { opacity: 0.85; }
.err-text { color: var(--err-text); font-size: 0.9em; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
h3 + .scroll, h3 + .hint + .scroll { border: 1px solid var(--line); border-radius: var(--radius-sm); }

/* ---------- Formulaires ---------- */
form { margin: 0; }
form.inline { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-top: 14px; }
form.grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px 16px; align-items: end;
}
form.grid .full { grid-column: 1 / -1; }
form.row-action { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 550; color: var(--text-2); }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--panel);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 8px 11px; min-height: 40px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select { padding-right: 28px; }
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input::placeholder { color: var(--muted); opacity: 0.8; }
form.row-action select { min-height: 34px; padding: 4px 26px 4px 8px; font-size: 14px; }

button, .button {
  font: inherit; font-weight: 600; font-size: 14.5px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px;
  color: var(--accent-text); background: var(--accent); border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 8px 16px; transition: background 0.15s, border-color 0.15s;
}
button:hover, .button:hover { background: var(--accent-hover); color: var(--accent-text); }
.button.secondary, button.secondary { background: var(--panel); color: var(--text); border-color: var(--line-2); }
.button.secondary:hover, button.secondary:hover { background: var(--panel-2); border-color: var(--muted); color: var(--text); }
.hero .button.secondary { background: transparent; color: #ffffff; border-color: rgba(255, 255, 255, 0.3); }
.hero .button.secondary:hover { background: rgba(255, 255, 255, 0.08); }
button.small { min-height: 32px; padding: 4px 12px; font-size: 13.5px; }
button.link {
  min-height: 0; background: none; border: 0; color: var(--accent); padding: 2px 0; font-weight: 550;
  text-decoration: underline; text-underline-offset: 2px;
}
button.link:hover { background: none; color: var(--accent-hover); }
button.link.danger { color: var(--danger); }
button.link.danger:hover { color: var(--danger-hover); }
button.danger:not(.link) { background: var(--danger); color: #ffffff; }
button.danger:not(.link):hover { background: var(--danger-hover); }
@media (prefers-color-scheme: dark) { button.danger:not(.link) { color: #1a0b0c; } }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---------- Messages et pastilles ---------- */
.flash {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: var(--radius-sm);
  margin: 0 0 18px; border: 1px solid transparent; font-weight: 500;
}
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.err { background: var(--err-bg); color: var(--err-text); }
.flash.warn { background: var(--warn-bg); color: var(--warn-text); }
.flash.info { background: var(--info-bg); color: var(--info-text); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 650; line-height: 1.6;
  padding: 1px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--info-bg); color: var(--info-text);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.error { background: var(--err-bg); color: var(--err-text); }
.badge.cancelled, .badge.no_data { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.running, .badge.queued, .badge.warn { background: var(--warn-bg); color: var(--warn-text); }

code.secret {
  display: block; padding: 14px 16px; border-radius: var(--radius-sm); word-break: break-all;
  background: var(--warn-bg); color: var(--warn-text); border: 1px dashed currentColor;
  font-size: 1.02em; user-select: all; -webkit-user-select: all;
}
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 0.92em; }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Explications repliables (glossaire, aide). */
details.explain { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-2); margin: 0 0 20px; }
details.explain > summary { padding: 12px 16px; font-weight: 600; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
details.explain > summary::-webkit-details-marker { display: none; }
details.explain > summary::after { content: "+"; margin-left: auto; font-size: 18px; color: var(--muted); }
details.explain[open] > summary::after { content: "–"; }
details.explain > :not(summary) { margin: 0 16px 16px; }
details.explain dl.kv { grid-template-columns: minmax(8em, max-content) 1fr; }

/* Actions secondaires repliables dans un tableau. */
details.inline-more { display: inline-block; margin-right: 10px; }
details.inline-more > summary { cursor: pointer; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; font-size: 0.95em; }
details.inline-more[open] form { margin-top: 8px; }

/* ---------- Pages hors application (message, accueil du domaine) ---------- */
.solo { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.solo-card {
  width: 100%; max-width: 520px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--shadow); padding: 32px;
}
.solo-card .brand { padding: 0; margin: 0 0 24px; }
.solo-card h1 { font-size: 1.5rem; }
.solo-card .form-actions { margin-top: 20px; }
.solo-card .copy { display: block; }
/* Accueil du domaine : logo, nom et connexion seulement, au centre d'une carte étroite. */
.solo-card.solo-min { max-width: 360px; text-align: center; }
.solo-min .brand { justify-content: center; margin-bottom: 8px; }
.solo-min .form-actions .button { width: 100%; justify-content: center; }
.solo-card .form-actions + .hint { margin: 28px 0 0; }
.solo-foot { margin: 20px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- Petits écrans : barre en haut, menu défilant ---------- */
@media (max-width: 900px) {
  .app, .platform-admin .app { display: block; background: none; }
  .side {
    position: static; height: auto; overflow: visible; flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 10px 12px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; font-size: 16px; }
  .mark { width: 28px; height: 28px; }
  .org-chip { margin: 0; padding: 4px 10px; flex-direction: row; align-items: baseline; gap: 6px; }
  .org-chip small { display: none; }
  .side-foot { margin-left: auto; padding: 0; border: 0; flex-direction: row; align-items: center; }
  .who span:last-child, .avatar { display: none; }
  .logout button { min-height: 34px; padding: 4px 10px; }
  .logout .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .side-nav {
    order: 5; flex: 1 1 100%; flex-direction: row; overflow-x: auto; gap: 4px;
    margin: 0 -16px; padding: 2px 16px 0; scrollbar-width: none;
  }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-nav a { padding: 7px 10px; }
  .side-nav .sep { width: 1px; height: auto; margin: 6px 2px; flex: none; }
  .platform-admin .side-nav a.active { box-shadow: inset 0 -2px 0 var(--admin-chip-bg); }
  .content { padding: 20px 16px 48px; }
  h1 { font-size: 1.45rem; }
  section { padding: 16px; border-radius: 12px; }
  section > .scroll:first-child, section > .scroll:only-child { margin: -4px -4px; }
  th, td { padding: 9px 10px; }
  dl.kv, details.explain dl.kv { grid-template-columns: 1fr; gap: 2px; }
  dl.kv dd { margin-bottom: 10px; }
  .solo-card { padding: 24px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.platform-admin .mark { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16); }
