:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --ink: #1f1b18;
  --muted: #776e66;
  --line: #e4ded6;
  --accent: #8a3b2c;
  --accent-ink: #ffffff;
  --ok: #2f7d4f;
  --warn: #b7791f;
  --bad: #c0392b;
  --idle: #9a928a;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412; --surface: #221e1b; --ink: #f1ece6; --muted: #a39a91;
    --line: #3a332e; --accent: #d9826d; --accent-ink: #1b1512; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
code { font-size: 12px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); margin: 4px 0 16px; max-width: 760px; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-size: 16px; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 20px; padding: 1px 8px; margin-left: 6px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button { background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; font: inherit; }
nav button.active { background: var(--bg); color: var(--ink); font-weight: 600; }
.publish { margin-left: auto; display: flex; align-items: center; gap: 12px; }

main { padding: 24px; max-width: 1280px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 28px 0 10px; font-size: 15px; }

button, input, select { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
input, select { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 8px; }
input[type=checkbox] { width: 16px; height: 16px; }

.toolbar { display: flex; align-items: center; gap: 16px; margin: 8px 0 12px; flex-wrap: wrap; }
.inline { display: inline-flex; align-items: center; gap: 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; max-width: 900px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.form-grid .full { grid-column: 1 / -1; }

table.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.grid th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; background: var(--bg); }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid td select, table.grid td input:not([type=checkbox]) { padding: 3px 6px; }
.thumb { width: 72px; height: 41px; object-fit: cover; border-radius: 4px; background: var(--bg); display: block; }
.thumb.rot { width: 41px; height: 72px; }
.flag { color: var(--warn); font-size: 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .n { font-size: 28px; font-weight: 600; }
.tile .l { color: var(--muted); font-size: 12px; }

.region { margin-bottom: 20px; }
.region h3 { margin: 0 0 8px; }
.branch-row { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.branch-row .name { width: 180px; font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 20px; padding: 2px 10px 2px 8px; font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); }
.dot.en_ligne { background: var(--ok); }
.dot.hors_ligne { background: var(--bad); }
.dot.jamais_vu { background: var(--warn); }
.dot.erreur_affichage { background: var(--bad); box-shadow: 0 0 0 2px var(--warn); }
.badge { font-size: 11px; border-radius: 20px; padding: 1px 8px; background: var(--bg); color: var(--muted); }
.badge.closed { color: var(--warn); }

.dropzone { display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; text-align: center;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px; background: var(--surface); cursor: pointer; margin-bottom: 12px; }
.dropzone.over { border-color: var(--accent); }
#upload-log div { font-size: 12px; padding: 2px 0; }

.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.preview-card h4 { margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.preview-card .items { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.preview-card figure { margin: 0; width: 110px; }
.preview-card figure img, .preview-card figure video { width: 110px; height: 62px; object-fit: cover; border-radius: 4px; background: var(--bg); }
.preview-card figcaption { font-size: 10.5px; color: var(--muted); word-break: break-all; }
.empty { color: var(--muted); font-style: italic; }
.targets { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.targets label { flex-direction: row; align-items: center; color: var(--ink); font-size: 13px; }

.login { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 85%, transparent); padding: 16px; }
.login form { display: flex; flex-direction: column; gap: 12px; width: min(380px, 100%); }
.login p { margin: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.toast.err { background: var(--bad); color: #fff; }

@media (max-width: 720px) {
  main { padding: 16px; }
  .top { padding: 10px 16px; }
  .branch-row .name { width: auto; }
  table.grid { display: block; overflow-x: auto; }
}

/* Connexion (page Supabase) */
.login input { width: 100%; }
.login h2 { margin: 0; }
section.login[hidden], header[hidden], main[hidden] { display: none; }
.login form[hidden] { display: none; }
