:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);

  --series-1: #2a78d6; /* bleu */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* jaune */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* vert */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* rouge */
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}

header.app-header h1 {
  font-size: 18px;
  margin: 0;
}

nav.app-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  margin-left: 20px;
  font-size: 14px;
  padding-bottom: 4px;
}

nav.app-nav a.active {
  color: var(--text-primary);
  border-bottom: 2px solid var(--series-1);
}

main {
  padding: 24px;
  max-width: 1280px;
  margin: 0 auto;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-bottom: 20px;
  padding: 14px 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.field input, .field select {
  font: inherit;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-primary);
}

.field.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

button.primary {
  font: inherit;
  padding: 7px 16px;
  border-radius: 6px;
  border: none;
  background: var(--series-1);
  color: white;
  cursor: pointer;
}

button.primary:hover { opacity: 0.9; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.kpi-tile .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi-tile .value {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
}

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.chart-card h2 {
  font-size: 14px;
  margin: 0 0 12px;
  color: var(--text-secondary);
}

.chart-card canvas { max-height: 280px; }

.state-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 0;
}

.state-msg.error {
  color: var(--series-8);
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--baseline);
  border-top-color: var(--series-1);
  animation: spin 0.7s linear infinite;
  flex: none;
}

.state-msg:not(.loading) .spinner {
  display: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.charts-grid.loading, .kpi-row.loading {
  opacity: 0.5;
  pointer-events: none;
}

#calendar-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.legend-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
}

.legend-row .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.fc-event.esd-internal { opacity: 0.55; }
.fc-event.esd-cancelled { text-decoration: line-through; opacity: 0.4; }
