:root {
  --bg: #f4f3f1; --panel: #fff; --ink: #151515; --muted: #6b6b6b; --line: #e4e2de;
  --accent: #151515; --accent-ink: #fff; --ok: #1f7a4d; --warn: #b26b00; --bad: #b3261e; --live: #1f7a4d;
  --radius: 10px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* Trois états de thème : système (media query), choix explicite clair, choix explicite sombre.
   Tous les jetons sont définis dans :root ; les blocs ci-dessous ne font que les redéfinir. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #17181a;
    --panel: #202225;
    --ink: #ececed;
    --muted: #a0a2a6;
    --line: #34363a;
    --accent: #ececed;
    --accent-ink: #17181a;
    --ok: #5fce9b;
    --warn: #e5a04a;
    --bad: #f08a80;
    --live: #5fce9b;
  }
}
:root[data-theme='dark'] {
  --bg: #17181a;
  --panel: #202225;
  --ink: #ececed;
  --muted: #a0a2a6;
  --line: #34363a;
  --accent: #ececed;
  --accent-ink: #17181a;
  --ok: #5fce9b;
  --warn: #e5a04a;
  --bad: #f08a80;
  --live: #5fce9b;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
h1, h2, h3 { margin: 0 0 12px; letter-spacing: -.01em; }
h2 { font-size: 18px; } h3 { font-size: 15px; }
a { color: inherit; }
.loading { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
button { font: inherit; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; }
button:disabled { opacity: .5; cursor: wait; }
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.ghost:hover { border-color: var(--ink); }
button.danger { color: var(--bad); }
button.link { background: none; border: 0; color: inherit; padding: 6px 0; display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; font-weight: 500; flex-wrap: wrap; }
button.icon { padding: 2px 10px; font-size: 18px; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel); width: 100%; min-width: 0; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 38px; }
textarea { resize: vertical; }

.top { display: flex; align-items: center; gap: 20px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { display: flex; gap: 8px; align-items: baseline; }
.brand strong { font-family: 'Arial Black', Arial, sans-serif; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tabs a { text-decoration: none; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tabs a.active { background: var(--bg); color: var(--ink); }
.user { display: flex; gap: 10px; align-items: center; }
.content { padding: 20px; max-width: 1280px; margin: 0 auto; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.split { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; }
.side { position: sticky; top: 76px; }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; flex: 1; }
.toolbar input[type=search] { max-width: 260px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row.between { justify-content: space-between; margin-top: 0; }
.row input { flex: 1; min-width: 180px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-top: 16px; align-items: start; }
.grid2.tight { margin-top: 0; gap: 8px; }
.span2 { grid-column: 1 / -1; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.grid2 .field { margin-bottom: 0; }
.field-label { font-weight: 600; font-size: 13px; }
.field small { color: var(--muted); font-size: 12px; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.checks label { display: flex; gap: 6px; align-items: center; }

.meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { display: inline-block; padding: 3px 9px; border-radius: 999px; background: var(--bg); font-size: 12px; font-weight: 600; }
.chip.small { font-size: 11px; padding: 1px 7px; margin-left: 6px; }
.chip.bad, .chip.error, .chip.too_long { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.chip.live, .chip.pushed { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.chip.upcoming, .chip.would_push { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.chip.demo { background: var(--ink); color: var(--bg); }
.gauge { height: 4px; background: var(--bg); border-radius: 4px; overflow: hidden; margin-bottom: 12px; }
.gauge div { height: 100%; background: var(--ink); }
.warnings { margin: 0 0 12px; padding: 10px 10px 10px 28px; background: color-mix(in srgb, var(--warn) 12%, transparent); border-radius: 8px; color: var(--warn); }
/* Les signatures sont toujours rendues sur fond blanc : c'est le fond d'un client mail. */
.mail { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; margin-bottom: 8px; }
.sigframe { width: 100%; border: 0; min-height: 160px; display: block; }

.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 42vh; overflow-y: auto; }
.import-report { margin-top: 14px; }
.import-report td { font-size: 13px; }
/* Styles de tableaux limités au back-office : ne pas toucher aux <table> des signatures (.sigbox). */
.table-wrap table { width: 100%; border-collapse: collapse; }
.table-wrap th, .table-wrap td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table-wrap th { font-size: 12px; color: var(--muted); font-weight: 600; }
.table-wrap tr.dim td { opacity: .5; }
.table-wrap tr.error td { color: var(--bad); }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { padding: 5px 9px; font-size: 12px; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list small { width: 100%; padding-left: 20px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.cards.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card.live { border-color: var(--live); }
.card.past, .card.off { opacity: .6; }
.card img { width: 100%; aspect-ratio: 4 / 1; object-fit: cover; display: block; background: var(--bg); max-width: 100%; }
.card-body { padding: 12px; display: grid; gap: 4px; }
.thumb { aspect-ratio: 4 / 1; background: var(--bg); border-radius: 8px; display: grid; place-items: center; overflow: hidden; margin-top: 8px; max-width: 600px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.banner-demo { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--panel); border-radius: 12px; width: min(760px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal header, .modal footer { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; }
.modal footer { border-bottom: 0; border-top: 1px solid var(--line); justify-content: flex-end; gap: 8px; }
.modal-body { padding: 0 18px 18px; overflow: auto; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: min(600px, calc(100vw - 32px)); }
.toast.error { background: var(--bad); }

.login { max-width: 420px; margin: 12vh auto; display: grid; gap: 12px; }
.install { max-width: 760px; margin: 0 auto; padding: 32px 16px; display: grid; gap: 16px; }
.sigbox { padding: 16px; border: 1px dashed var(--line); border-radius: 8px; margin: 12px 0; background: #fff; color: #1a1a1a; overflow-x: auto; }
details { border-top: 1px solid var(--line); padding: 10px 0; }
summary { cursor: pointer; font-weight: 600; }

@media (max-width: 860px) {
  .split, .grid2 { grid-template-columns: 1fr; }
  .side { position: static; }
  .content { padding: 12px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; order: 3; flex-basis: 100%; }
  .top { gap: 10px; padding: 10px 12px; }
}
