/* Layout : barre latérale fixe + colonne de travail ; une bande d'état en haut rappelle le mode. */
:root {
  --bg: #f2f4f6;
  --surface: #ffffff;
  --fg: #16202a;
  --muted: #5a6774;
  --line: #d9e0e7;
  --accent: #1d5a8c;
  --accent-soft: #e3edf6;
  --ok: #2b7a4b;
  --ok-soft: #e2f2e8;
  --warn: #9a6205;
  --warn-soft: #fbefd9;
  --crit: #b0271f;
  --crit-soft: #fae3e1;
  --sim: #3d6b74;
  --sim-soft: #e1eef0;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11171d; --surface: #182129; --fg: #e5ebf0; --muted: #94a3b1; --line: #2a3742;
    --accent: #7db3e0; --accent-soft: #1d3346;
    --ok: #6fcf97; --ok-soft: #173326; --warn: #e9b45a; --warn-soft: #3a2c12;
    --crit: #f08a82; --crit-soft: #3d1b19; --sim: #8cc4cc; --sim-soft: #1b3236;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11171d; --surface: #182129; --fg: #e5ebf0; --muted: #94a3b1; --line: #2a3742;
  --accent: #7db3e0; --accent-soft: #1d3346;
  --ok: #6fcf97; --ok-soft: #173326; --warn: #e9b45a; --warn-soft: #3a2c12;
  --crit: #f08a82; --crit-soft: #3d1b19; --sim: #8cc4cc; --sim-soft: #1b3236;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.5 var(--font-body); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; text-wrap: balance; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }
code, .mono { font-family: var(--font-mono); font-size: .86em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Bande d'état */
.modebar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding-block: 6px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  font-size: .82rem; background: var(--sim-soft); color: var(--sim); border-bottom: 1px solid var(--line); }
.modebar.live { background: var(--warn-soft); color: var(--warn); }
.modebar.halted { background: var(--crit); color: #fff; }
.modebar strong { letter-spacing: .04em; text-transform: uppercase; font-size: .75rem; }

/* Structure */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 34px); }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 12px; display: flex;
  flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 1.05rem; padding: 0 10px 14px; letter-spacing: -.01em; }
.brand span { color: var(--accent); }
.side a { display: block; padding: 7px 10px; border-radius: var(--radius); color: var(--fg); text-decoration: none; }
.side a:hover { background: var(--bg); }
.side a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side form { margin-top: auto; padding: 0 10px; }
main { min-width: 0; padding-block: 24px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.page { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; justify-content: space-between; }

/* Blocs */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.kpis { display: grid; gap: 1px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.kpi { background: var(--surface); padding: 12px 14px; }
.kpi b { display: block; font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi.crit b { color: var(--crit); }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.clip { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Pastilles d'état */
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  white-space: nowrap; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.pill.published, .pill.active { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.scheduled, .pill.queued, .pill.publishing { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.failed, .pill.suspended, .pill.token_expired { background: var(--crit-soft); color: var(--crit); border-color: transparent; }
.pill.paused { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.simulation { background: var(--sim-soft); color: var(--sim); border-color: transparent; }
.pill.live { background: var(--warn); color: var(--surface); border-color: transparent; }

/* Formulaires */
form.stack { display: flex; flex-direction: column; gap: 10px; }
form.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row > label { flex: 1 1 160px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input, select, textarea { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 7px 9px; min-width: 0; }
textarea { min-height: 140px; resize: vertical; }
button, .btn { font: inherit; font-size: .88rem; font-weight: 600; border-radius: var(--radius); padding: 7px 14px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--surface); cursor: pointer;
  text-decoration: none; display: inline-block; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); }
button.danger { background: var(--crit); border-color: var(--crit); }
button.quiet { background: transparent; border-color: var(--line); color: var(--fg); font-weight: 500; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Messages */
.flash { padding: 10px 14px; border-radius: var(--radius); background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--crit-soft); color: var(--crit); }
.note { padding: 10px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); font-size: .88rem; }

/* Aperçu Facebook */
.fb-card { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); max-width: 500px; overflow: hidden; }
.fb-card .fb-head { display: flex; gap: 10px; align-items: center; padding: 12px; }
.fb-card .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; }
.fb-card .fb-text { padding: 0 12px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.fb-card .fb-img { aspect-ratio: 1.91 / 1; background: var(--bg); display: grid; place-items: center; max-width: 100%; }
.fb-card .fb-img img { width: 100%; height: 100%; object-fit: cover; }
.fb-card .fb-link { padding: 10px 12px; background: var(--bg); border-top: 1px solid var(--line); }
.fb-card .fb-link small { text-transform: uppercase; color: var(--muted); font-size: .72rem; }
.fb-card .fb-link b { display: block; }

/* Calendrier */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
  min-height: 160px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.day.today { border-color: var(--accent); }
.day h3 { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.slot { font-size: .8rem; padding: 6px; border-radius: 4px; background: var(--bg); border-left: 3px solid var(--accent);
  text-decoration: none; color: var(--fg); overflow-wrap: anywhere; }
.slot.published { border-left-color: var(--ok); }
.slot.failed { border-left-color: var(--crit); }
.slot time { font-family: var(--font-mono); font-size: .75rem; color: var(--muted); display: block; }

.inherit { color: inherit; }
.brand-title span { color: var(--accent); }
.chart { width: 100%; height: 130px; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar.zero { fill: var(--line); }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 10px; font-family: var(--font-mono); }
.chart .val { fill: var(--fg); }
.thumb { width: 64px; height: 40px; object-fit: cover; border-radius: 3px; background: var(--bg); display: block; }
.login { max-width: 380px; margin: 10vh auto; }
dl.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 0; font-size: .9rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { flex-direction: row; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side .brand { padding: 7px 10px; }
  .side a { white-space: nowrap; }
  .side form { margin: 0; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .week { grid-template-columns: minmax(0, 1fr); }
  .day { min-height: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
