/* ============================================================
   Ventrys — Registre des métiers
   Neutres chauds (parchemin) + accent bronze.
   Palette de graphiques : palette catégorielle validée (8 slots).
   ============================================================ */

:root {
  /* Plans & encre */
  --page:            #f6f4ef;
  --surface:         #fcfcfb;
  --ink:             #0b0b0b;
  --ink-2:           #52514e;
  --muted:           #898781;
  --grid-line:       #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --hover-wash:      rgba(11, 11, 11, 0.04);
  --chip-bg:         #f1efe8;

  /* Accent bronze (UI uniquement, jamais dans les graphiques) */
  --accent:          #a14e22;
  --accent-strong:   #8a421c;
  --on-accent:       #ffffff;

  /* Palette catégorielle — mode clair (validée) */
  --cat1: #2a78d6;  /* bleu    — Forgeron    */
  --cat2: #1baf7a;  /* aqua    — Artisan     */
  --cat3: #eda100;  /* jaune   — Apothicaire */
  --cat4: #008300;  /* vert    — Cuisinier   */
  --cat5: #4a3aa7;  /* violet  — Ouvrier     */
  --cat6: #e34948;  /* rouge   — Couturier   */
  --cat7: #e87ba4;  /* magenta — Bâtisseur   */
  --cat8: #eb6834;  /* orange  — Paysan      */

  --seq:  var(--cat1);   /* teinte séquentielle par défaut */
  --seq2: var(--cat2);   /* second contexte séquentiel     */
}

:root[data-theme="dark"] {
  --page:            #0d0d0d;
  --surface:         #1a1a19;
  --ink:             #ffffff;
  --ink-2:           #c3c2b7;
  --muted:           #898781;
  --grid-line:       #2c2c2a;
  --baseline:        #383835;
  --border:          rgba(255, 255, 255, 0.10);
  --hover-wash:      rgba(255, 255, 255, 0.05);
  --chip-bg:         #242422;

  --accent:          #c96a35;
  --accent-strong:   #b35a28;
  --on-accent:       #ffffff;

  /* Palette catégorielle — mode sombre (validée) */
  --cat1: #3987e5;
  --cat2: #199e70;
  --cat3: #c98500;
  --cat4: #008300;
  --cat5: #9085e9;
  --cat6: #e66767;
  --cat7: #d55181;
  --cat8: #d95926;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button { font: inherit; color: inherit; }

/* ------------------------------ Barre haute ------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  min-height: 56px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}

.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.brand-sub  { color: var(--ink-2); font-size: 13px; }

.tabs { display: flex; gap: 4px; flex: 1; }

.tab {
  border: none;
  background: none;
  padding: 16px 14px 14px;
  cursor: pointer;
  color: var(--ink-2);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 150ms ease-out;
}

.tab:hover { color: var(--ink); }

.tab.is-active {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.theme-toggle {
  border: 1px solid var(--border);
  background: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  transition: background 150ms ease-out;
}

.theme-toggle:hover { background: var(--hover-wash); }

/* -------------------------------- Page ---------------------------------- */

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

/* ------------------------------ Toolbar ---------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.search {
  flex: 0 1 300px;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.search:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.search::placeholder { color: var(--muted); }

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-2);
  transition: background 150ms ease-out, color 150ms ease-out;
}

.chip:hover { background: var(--hover-wash); color: var(--ink); }

.chip.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
  font-weight: 600;
}

.chip.is-empty { opacity: 0.45; }

.chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.chip .n { font-variant-numeric: tabular-nums; opacity: 0.75; }

.toolbar-end {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.row-count { color: var(--muted); font-size: 13px; white-space: nowrap; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13.5px;
  transition: background 150ms ease-out;
}

.btn:hover { background: var(--hover-wash); }

/* ------------------------------- Tableau --------------------------------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
  max-height: calc(100vh - 190px);
}

.grid {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

.grid thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  box-shadow: inset 0 -1px 0 var(--baseline);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  padding: 10px 12px;
  white-space: nowrap;
  user-select: none;
}

.grid thead th.sortable { cursor: pointer; }
.grid thead th.sortable:hover { color: var(--ink); }

.grid thead th .arrow { color: var(--accent); font-size: 10px; margin-left: 4px; }

.grid thead th.num, .grid td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.grid tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--grid-line);
  vertical-align: top;
}

.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr:hover td { background: var(--hover-wash); }

.cell-job {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-size: 13.5px;
  color: var(--ink-2);
}

.cell-job .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.craft-name { font-weight: 600; }

.craft-desc {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 1px;
  max-width: 260px;
}

.ing-list { display: flex; flex-wrap: wrap; gap: 5px; max-width: 420px; }

.ing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--chip-bg);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12.5px;
  color: var(--ink-2);
  white-space: nowrap;
}

.ing b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.out-name {
  font-size: 13.5px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

/* Icônes d'items (pixel-art 16×16 ; object-fit coupe les bandes d'animation) */
.icon {
  width: 20px;
  height: 20px;
  flex: none;
  image-rendering: pixelated;
  object-fit: cover;
  object-position: top;
}

.icon.sm { width: 16px; height: 16px; }

.out-missing { color: var(--muted); font-style: italic; font-size: 12.5px; }

.warn-chip {
  display: inline-block;
  font-size: 11px;
  font-style: normal;
  color: var(--ink-2);
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}

.empty-state {
  padding: 48px;
  text-align: center;
  color: var(--muted);
}

/* --------------------------------- KPIs ---------------------------------- */

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

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

.kpi .label { font-size: 12.5px; color: var(--ink-2); }

.kpi .value {
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 2px;
}

.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ------------------------------ Graphiques ------------------------------- */

.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px 18px;
  min-width: 0;
}

.chart.wide { grid-column: 1 / -1; }

.chart-title { font-weight: 600; font-size: 14.5px; }

.chart-sub { font-size: 12.5px; color: var(--muted); margin: 1px 0 14px; }

/* Barres horizontales */

.hbars { display: flex; flex-direction: column; }

.hbar-row {
  display: grid;
  grid-template-columns: minmax(110px, 34%) 1fr 52px;
  align-items: center;
  gap: 10px;
  min-height: 26px;
  border-radius: 6px;
  padding: 0 4px;
}

.hbar-row:hover { background: var(--hover-wash); }

.hbar-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-2);
  min-width: 0;
}

.hbar-label .lbl {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hbar-label .sub2 { color: var(--muted); font-size: 11.5px; }

.hbar-track { position: relative; height: 18px; }

.hbar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 0 4px 4px 0;   /* extrémité de donnée arrondie, base carrée */
  min-width: 2px;
}

.hbar-value {
  font-size: 12.5px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: left;
  white-space: nowrap;
}

/* Histogramme (colonnes) */

.cols {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  height: 210px;
  padding: 0 8px;
  border-bottom: 1px solid var(--baseline);
}

.col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
}

.col-value { font-size: 12px; color: var(--ink-2); margin-bottom: 4px; font-variant-numeric: tabular-nums; }

.col-fill {
  width: 100%;
  max-width: 24px;
  background: var(--seq);
  border-radius: 4px 4px 0 0;   /* sommet arrondi, base carrée */
  min-height: 2px;
}

.col-labels {
  display: flex;
  gap: 18px;
  padding: 6px 8px 0;
}

.col-labels span {
  flex: 1;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

/* Mini-table (intermédiaires) */

.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.mini-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  padding: 4px 10px 6px;
  border-bottom: 1px solid var(--baseline);
}

.mini-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--grid-line);
  color: var(--ink-2);
}

.mini-table tr:last-child td { border-bottom: none; }
.mini-table td:first-child { color: var(--ink); font-weight: 500; }
.mini-table th.num, .mini-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

.mini-table .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.mini-table .icon { vertical-align: -4px; margin-right: 2px; }

/* Matrice d'interdépendance & comparateur */

.matrix-wrap { overflow-x: auto; }

.cell-heat {
  background: color-mix(in srgb, var(--seq) calc(var(--w) * 100%), transparent);
  border-radius: 4px;
}

.cell-empty { color: var(--muted); }

.matrix thead th:first-child { min-width: 190px; }

.dep-row td {
  border-top: 1px solid var(--baseline);
  color: var(--ink-2);
  font-style: italic;
}

/* Guide de récolte */

.harvest {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 18px 24px;
}

.harvest-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 13.5px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--baseline);
  margin-bottom: 6px;
}

.harvest ul { list-style: none; margin: 0; padding: 0; }

.harvest li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  font-size: 13px;
  color: var(--ink-2);
}

.harvest li b { color: var(--ink); font-variant-numeric: tabular-nums; }

.harvest li.more { color: var(--muted); font-size: 12px; }

/* -------------------------------- Divers --------------------------------- */

.footer {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 32px;
  color: var(--muted);
  font-size: 12.5px;
}

.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--ink);
  color: var(--page);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  line-height: 1.45;
  max-width: 320px;
  white-space: pre-line;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

@media (max-width: 900px) {
  .charts { grid-template-columns: 1fr; }
  .topbar-inner { gap: 16px; }
  .brand-sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
