:root {
  color-scheme: light;
  --page: #f4f3ef;
  --surface: #fcfcfb;
  --border: #e3e1da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7d7b75;
  --neutral: #b9b7ae;
  --accent: #2a78d6;
  /* Statuts de rythme : toujours accompagnés d'une icône et d'un libellé */
  --late: #ec835a;
  --ontime: #0ca30c;
  --ahead: #2a78d6;
  --critical: #d03b3b;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #111110;
    --surface: #1a1a19;
    --border: #32322f;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --neutral: #5c5b55;
    --accent: #3987e5;
    --ahead: #3987e5;
  }
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
a {
  color: inherit;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 650;
  text-decoration: none;
}
.account {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-2);
}
.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--text-2);
  text-decoration: underline;
  cursor: pointer;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}
h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 650;
}
.subtitle {
  margin: 0 0 20px;
  color: var(--text-2);
}
.breadcrumb {
  display: inline-block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-2);
}

.button {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--text);
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.panel {
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel p {
  margin: 0 0 16px;
  color: var(--text-2);
}
.error {
  border-color: var(--critical);
}
.error strong {
  display: block;
  margin-bottom: 6px;
}
.error pre {
  margin: 0 0 16px;
  white-space: pre-wrap;
  word-break: break-word;
  font: 13px/1.4 ui-monospace, Menlo, monospace;
  color: var(--text-2);
}
.notice {
  margin-bottom: 16px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--critical);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  color: var(--text-2);
}
.skeleton {
  height: 64px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--border) 25%, var(--surface) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  opacity: 0.6;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* Barre d'outils : recherche, filtres, tri */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.toolbar input[type='search'],
.toolbar select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.toolbar input[type='search'] {
  flex: 1 1 240px;
  max-width: 360px;
}
.toolbar .spacer {
  flex: 1;
}
.toolbar label {
  font-size: 13px;
  color: var(--text-2);
}

/* Page 1 : agences */
.agency-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}
.agency-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.12s, transform 0.12s;
}
.agency-card:hover,
.agency-card:focus-visible {
  border-color: var(--text-2);
  transform: translateY(-1px);
}
.agency-card.idle {
  opacity: 0.62;
}
.agency-logo {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--page);
  border: 1px solid var(--border);
  overflow: hidden;
  font-weight: 650;
  color: var(--text-2);
}
.agency-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}
.agency-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.agency-meta {
  font-size: 13px;
  color: var(--text-2);
}
.agency-count {
  flex: none;
  white-space: nowrap;
  margin-left: auto;
  text-align: right;
  line-height: 1.1;
}
.agency-count b {
  display: block;
  font-size: 20px;
  font-weight: 650;
}
.agency-count span {
  font-size: 11px;
  color: var(--text-3);
}

/* Page 2 : synthèse du rythme */
.summary {
  margin-bottom: 20px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.distribution {
  display: flex;
  gap: 2px;
  height: 10px;
  margin-bottom: 14px;
}
.distribution span {
  min-width: 4px;
  border-radius: 4px;
  background: var(--status, var(--neutral));
}
.status-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.status-filter {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.status-filter[aria-pressed='true'] {
  border-color: var(--text);
  box-shadow: inset 0 0 0 1px var(--text);
}
.status-filter b {
  font-size: 26px;
  font-weight: 650;
  line-height: 1.1;
}
.status-filter small {
  font-size: 12px;
  color: var(--text-3);
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.status i {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--status, var(--neutral));
  color: #fff;
  font-style: normal;
  font-size: 12px;
  line-height: 1;
}
[data-status='en-retard'] {
  --status: var(--late);
}
[data-status='a-l-heure'] {
  --status: var(--ontime);
}
[data-status='en-avance'] {
  --status: var(--ahead);
}
[data-status='indetermine'] {
  --status: var(--neutral);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--text-2);
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend .key-fill {
  width: 22px;
  height: 8px;
  border-radius: 4px;
  background: var(--text-3);
}
.legend .key-now {
  width: 2px;
  height: 16px;
  background: var(--text);
}

/* Liste des campagnes */
.campaigns {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.campaign {
  display: grid;
  grid-template-columns: minmax(220px, 1.25fr) minmax(240px, 1.6fr) 130px 120px;
  align-items: center;
  gap: 20px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--status, var(--neutral));
  border-radius: var(--radius);
}
.campaign-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.campaign-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-2);
}
.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-3);
}

/* La dataviz : barre = part du budget dépensé, trait vertical = part du temps écoulé */
.pace {
  position: relative;
  padding: 6px 0;
}
.pace-track {
  height: 12px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--status, var(--neutral)) 20%, var(--surface));
  overflow: hidden;
}
.pace-fill {
  width: calc(min(var(--spend), 100) * 1%);
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--status, var(--neutral));
}
.pace-now {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--time) * 1%);
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  box-shadow: 0 0 0 2px var(--surface);
  border-radius: 1px;
}
.pace-labels {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.pace-reason {
  font-size: 12px;
  color: var(--text-3);
}
.amounts {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.amounts b {
  display: block;
  font-weight: 600;
}
.amounts span {
  font-size: 12px;
  color: var(--text-2);
}
.verdict {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.verdict .delta {
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.empty {
  padding: 32px;
  text-align: center;
  color: var(--text-2);
}

@media (max-width: 860px) {
  .campaign {
    grid-template-columns: 1fr auto;
    gap: 10px 16px;
  }
  .campaign > .pace-cell {
    grid-column: 1 / -1;
    order: 3;
  }
  .amounts {
    order: 4;
    grid-column: 1 / -1;
    text-align: left;
  }
  .amounts b {
    display: inline;
  }
}
