/* ===== Design tokens (palette validée — voir skill dataviz) ===== */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.16);

  --series-1: #2a78d6;   /* bleu — métrique principale */
  --series-1-soft: rgba(42, 120, 214, 0.14);
  --series-2: #1baf7a;   /* aqua — métrique secondaire */
  --series-2-soft: rgba(27, 175, 122, 0.14);

  /* Palette catégorielle (8 slots, ordre fixe — voir skill dataviz) */
  --cat-1: #2a78d6;  /* bleu */
  --cat-2: #1baf7a;  /* aqua */
  --cat-3: #eda100;  /* jaune */
  --cat-4: #008300;  /* vert */
  --cat-5: #4a3aa7;  /* violet */
  --cat-6: #e34948;  /* rouge */
  --cat-7: #e87ba4;  /* magenta */
  --cat-8: #eb6834;  /* orange */
  --cat-other: #898781; /* "Autres" — hors palette catégorielle */

  --good: #0ca30c;
  --good-soft: rgba(12, 163, 12, 0.12);
  --warning: #fab219;
  --warning-soft: rgba(250, 178, 25, 0.16);
  --serious: #ec835a;
  --serious-soft: rgba(236, 131, 90, 0.14);
  --critical: #d03b3b;
  --critical-soft: rgba(208, 59, 59, 0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 1px 2px rgba(11, 11, 11, 0.04), 0 1px 12px rgba(11, 11, 11, 0.03);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.16);

  --series-1: #3987e5;
  --series-1-soft: rgba(57, 135, 229, 0.16);
  --series-2: #199e70;
  --series-2-soft: rgba(25, 158, 112, 0.18);

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

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 16px rgba(0, 0, 0, 0.25);
}

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

    --series-1: #3987e5;
    --series-1-soft: rgba(57, 135, 229, 0.16);
    --series-2: #199e70;
    --series-2-soft: rgba(25, 158, 112, 0.18);

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

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 16px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

a { color: inherit; }

/* ===== Layout ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}

.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--series-1);
  flex-shrink: 0;
}

.main-nav {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav-link {
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-secondary);
  border: 1px solid transparent;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  background: var(--series-1-soft);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--series-1);
  color: #fff;
}

.nav-link { position: relative; }

.nav-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--critical);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.global-search {
  position: relative;
}

.global-search input {
  width: 190px;
  padding: 0.42rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 0.82rem;
  transition: width 0.15s ease;
}

.global-search input:focus {
  width: 260px;
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}

.global-search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  z-index: 30;
  display: none;
  padding: 0.4rem;
}

.global-search-results.visible { display: block; }

.global-search-results .group-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 700;
  padding: 0.4rem 0.5rem 0.2rem;
}

.global-search-results a.result-item {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-primary);
  font-size: 0.82rem;
}

.global-search-results a.result-item:hover { background: var(--series-1-soft); }

.global-search-results .result-meta {
  color: var(--text-muted);
  font-size: 0.76rem;
  white-space: nowrap;
}

.global-search-results .empty-hint {
  padding: 0.6rem 0.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.1s ease;
}

.icon-btn:hover { background: var(--series-1-soft); color: var(--text-primary); }
.icon-btn:active { transform: scale(0.94); }

main {
  padding: 1.5rem;
  max-width: 1180px;
  margin: 0 auto 3rem;
}

.page-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.25rem 0 1.25rem;
  flex-wrap: wrap;
}

.page-title h1 {
  font-size: 1.3rem;
  margin: 0;
}

.page-title .subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover { background: var(--series-1-soft); border-color: var(--border-strong); }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
}

.btn-primary:hover { background: var(--series-1); filter: brightness(1.08); }

.btn-good {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
}

.btn-good:hover { background: var(--good); filter: brightness(1.08); }

.btn-danger {
  background: var(--critical);
  border-color: var(--critical);
  color: #fff;
}

.btn-danger:hover { background: var(--critical); filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover { background: var(--series-1-soft); color: var(--text-primary); }

.btn.is-active {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
}

.btn-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ===== Stat tiles ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1rem 1.1rem;
}

.stat-tile .label {
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.stat-tile .value {
  font-size: 1.65rem;
  font-weight: 700;
  margin-top: 0.3rem;
  font-variant-numeric: proportional-nums;
}

.stat-tile .value.accent-good { color: var(--good); }
.stat-tile .value.accent-critical { color: var(--critical); }
.stat-tile .value.accent-warning { color: #a86300; }

/* ===== Cards / panels ===== */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
  font-size: 1rem;
}

.card-header .subtitle {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.two-col {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ===== Toolbar (search + filters) ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.search-input {
  flex: 1;
  min-width: 180px;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 0.88rem;
}

.search-input:focus {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}

.filter-group {
  display: flex;
  gap: 0.3rem;
  background: var(--page-plane);
  padding: 0.2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.filter-group .btn {
  border: none;
  background: transparent;
  padding: 0.4rem 0.7rem;
}

.filter-group .btn.is-active {
  background: var(--series-1);
  color: #fff;
}

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--baseline);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

thead th:hover { color: var(--text-primary); }

thead th .sort-arrow { opacity: 0.4; margin-left: 0.2rem; font-size: 0.7rem; }
thead th.sorted .sort-arrow { opacity: 1; color: var(--series-1); }

tbody tr {
  border-bottom: 1px solid var(--gridline);
  cursor: default;
}

tbody tr.is-clickable { cursor: pointer; }
tbody tr.is-clickable:hover { background: var(--series-1-soft); }

td {
  padding: 0.6rem 0.65rem;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

td.emphasis { font-weight: 700; }
td.muted { color: var(--text-muted); font-variant-numeric: normal; }

.row-detail {
  background: var(--page-plane);
}

.row-detail td {
  padding: 1rem 1.25rem;
}

/* ===== Badges (status — jamais couleur seule, icône + label) ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-good { background: var(--good-soft); color: var(--good); }
.badge-warning { background: var(--warning-soft); color: #8a5a00; }
.badge-critical { background: var(--critical-soft); color: var(--critical); }
.badge-neutral { background: var(--border); color: var(--text-secondary); }

:root[data-theme="dark"] .badge-warning,
@media (prefers-color-scheme: dark) { .badge-warning { color: var(--warning); } }

/* ===== Charts ===== */
.chart-figure { margin: 0; }

.bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 70px;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0;
}

.bar-row .bar-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  position: relative;
  height: 10px;
  background: var(--gridline);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--series-1);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.bar-row .bar-value {
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.line-chart-wrap { position: relative; }

.line-chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--page-plane);
  font-size: 0.75rem;
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-sm);
  transform: translate(-50%, -120%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 5;
}

.line-chart-tooltip.visible { opacity: 1; }

/* ===== Empty / loading state ===== */
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.skeleton {
  background: linear-gradient(90deg, var(--gridline) 25%, var(--border-strong) 37%, var(--gridline) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ===== Detail panel (fiche employé) ===== */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.detail-grid .mini-label {
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-grid .mini-value {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 0.15rem;
}

.warning-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.warning-list li {
  padding: 0.5rem 0.65rem;
  background: var(--warning-soft);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

/* ===== Galerie photos (détail d'un run) ===== */
.photo-groups {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.photo-group h4 {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 700;
}

.photo-thumbs {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.photo-thumbs button.photo-thumb {
  display: block;
  width: 96px;
  height: 96px;
  padding: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  flex: 0 0 auto;
}

.photo-thumbs img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ===== Lightbox (agrandir une image sans changer de page) ===== */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 2.5rem;
  cursor: zoom-out;
}

.lightbox-overlay.visible { display: flex; }

.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 40px rgba(0, 0, 0, 0.5);
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: 1.25rem;
  right: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

.lightbox-close:hover { background: rgba(255, 255, 255, 0.24); }

/* ===== Graphiques circulaires (donut) ===== */
.stat-grid.charts {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.25rem 1.35rem;
}

.chart-card h2 {
  margin: 0 0 0.2rem;
  font-size: 0.95rem;
}

.chart-card .subtitle {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.donut-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.donut-svg {
  width: 150px;
  height: 150px;
  flex-shrink: 0;
}

.donut-arc {
  transition: stroke-width 0.12s ease;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
  min-width: 140px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.legend-item .legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-item .legend-value {
  margin-left: auto;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
