:root {
  color-scheme: light;
  --bg: #fafaf7;
  --surface: #ffffff;
  --text: #1d2420;
  --muted: #66706a;
  --border: #dcdfd8;
  --accent: #2f7d4f;
  --grid: rgba(0, 0, 0, 0.08);
  /* six hard-edged bands from healthy (1) to unhealthy (6) */
  --band-1: #2e9e5b;
  --band-2: #8fcf7a;
  --band-3: #f0dc4e;
  --band-4: #f4a14b;
  --band-5: #e8735f;
  --band-6: #d64541;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header, main { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
header {
  padding-top: 8px;
  padding-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.titles { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 12px; }
.lang { display: inline-flex; flex-shrink: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.lang button { display: flex; align-items: center; border: 0; border-radius: 0; background: transparent; padding: 6px 10px; }
.lang button + button { border-left: 1px solid var(--border); }
.lang button svg { display: block; box-shadow: 0 0 0 1px var(--border); opacity: 0.5; transition: opacity 0.15s; }
.lang button:hover svg { opacity: 0.85; }
.lang button[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); }
.lang button[aria-pressed="true"] svg { opacity: 1; box-shadow: 0 0 0 2px var(--accent); }
h1 { margin: 0; font-size: 1.25rem; }
.sub { margin: 0; color: var(--muted); font-size: 0.85rem; }

.controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}
/* top row: the compact axis boxes on the left, the presets and health-label box on the right */
.top-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
fieldset {
  margin: 0;
  padding: 8px 12px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
legend { padding: 0 4px; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.axis { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.categories { flex: 1 1 100%; }

select, button {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}
button { cursor: pointer; }
button:hover, select:hover { border-color: var(--accent); }
.inline { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); font-size: 0.9rem; }

/* Fixed columns (see COLUMNS in app.js): short categories are stacked, the tall ones stand alone on the right. */
/* Columns stretch to the tallest one; space-between pins the first group to the top and the second to the bottom. */
.cat-groups { display: flex; flex-wrap: wrap; gap: 0 10px; align-items: stretch; }
.cat-col { width: 134px; display: flex; flex-direction: column; justify-content: space-between; gap: 6px; }
.cat-group { display: flex; flex-direction: column; gap: 3px; }
.cat-icon { display: flex; justify-content: center; padding: 0 0 2px; color: var(--c); }
.cat-icon svg { width: 34px; height: 34px; fill: currentColor; }
.cat-icon .ln { fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.cat-icon .cut { fill: none; stroke: var(--surface); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.cat-icon .hole { fill: var(--surface); }
.cat-group:has(.cat-btn[aria-pressed="false"]) .cat-icon { color: var(--border); }

/* Every category and subcategory button is exactly one line: fixed height, long names are cut with an ellipsis
   (the full name is in the tooltip). Pressed = filled with the category colour, "mixed" = only some subcategories on. */
button.cat-btn, button.sub-btn {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  width: 100%;
  flex: 0 0 auto; /* never squeezed to a different height inside the scrolling list */
  white-space: nowrap;
  text-align: left;
}
button.cat-btn > :first-child, button.sub-btn > :first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
button.cat-btn {
  height: 26px; padding: 0 7px;
  border: 2px solid var(--c);
  border-radius: 4px;
  background: color-mix(in srgb, var(--c) 20%, var(--surface));
  font-size: 0.85rem; font-weight: 600;
}
button.cat-btn[aria-pressed="mixed"] { border-style: dashed; background: color-mix(in srgb, var(--c) 8%, var(--surface)); }
button.cat-btn[aria-pressed="false"] { border-color: var(--border); background: var(--bg); color: var(--muted); }

.subs { display: flex; flex-direction: column; gap: 2px; }
.subs:empty { display: none; }
button.sub-btn {
  height: 22px; padding: 0 6px;
  border: 1px solid var(--c);
  border-radius: 3px;
  background: color-mix(in srgb, var(--c) 12%, var(--surface));
  font-size: 0.78rem;
}
button.sub-btn[aria-pressed="false"] { border-color: var(--border); background: transparent; color: var(--muted); }
.count { flex-shrink: 0; font-size: 0.72rem; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Left column: the chart with the control boxes directly under it. Right column: the info box, which can grow as tall as it
   likes without moving the controls (the second row takes up any extra height). */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "chart detail" "controls detail";
  gap: 8px 16px;
  padding-bottom: 8px;
}
.stage .chart-wrap { grid-area: chart; }
.stage .below-chart { grid-area: controls; align-self: start; }
.stage .detail { grid-area: detail; align-self: start; }
@media (max-width: 860px) {
  .stage { grid-template-columns: 1fr; grid-template-rows: auto; grid-template-areas: "chart" "controls" "detail"; }
}

.chart-wrap {
  position: relative;
  height: min(70vh, 620px);
  min-height: 360px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); margin: 0; pointer-events: none; }
.empty[hidden] { display: none; }

.detail {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  align-self: start;
}
.detail h2 { margin: 0 0 2px; font-size: 1.15rem; }
.detail .cat { color: var(--muted); font-size: 0.85rem; margin-bottom: 10px; }
.detail h3 { margin: 14px 0 6px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.placeholder { color: var(--muted); margin: 0; }

.nutrients { width: 100%; border-collapse: collapse; }
.nutrients td { padding: 3px 0; border-bottom: 1px solid var(--border); }
.nutrients td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0; list-style: none; }
.tags li { padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); font-size: 0.85rem; }
.tags.allergens li { border-color: #c2602a; color: #c2602a; }
.note { color: var(--muted); font-size: 0.8rem; margin-top: 14px; }

.status { margin: 0 0 4px; color: var(--muted); font-size: 0.8rem; line-height: 1.2; }

.hint { flex-basis: 100%; display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.8rem; }
.hint[hidden] { display: none; }
.hint .bar { width: 54px; height: 8px; border-radius: 2px; background: linear-gradient(90deg, var(--band-1) 0.000% 16.667%, var(--band-2) 16.667% 33.333%, var(--band-3) 33.333% 50.000%, var(--band-4) 50.000% 66.667%, var(--band-5) 66.667% 83.333%, var(--band-6) 83.333% 100.000%); }
.hint .bar.good-high { background: linear-gradient(90deg, var(--band-6) 0.000% 16.667%, var(--band-5) 16.667% 33.333%, var(--band-4) 33.333% 50.000%, var(--band-3) 50.000% 66.667%, var(--band-2) 66.667% 83.333%, var(--band-1) 83.333% 100.000%); }

/* compact axis boxes, stacked */
.axes-col { display: flex; flex-direction: column; justify-content: flex-start; gap: 2px; flex: 0 0 352px; }
.axes-col fieldset { padding: 0 8px 3px; }
.axes-col legend { font-size: 0.68rem; }
.axes-col .axis { gap: 5px 6px; }
.axes-col select { padding: 1px 5px; font-size: 0.82rem; }
.axes-col .hint { flex-basis: 100%; margin-left: 0; }

/* presets and health labels */
.presets-col { flex: 1 1 340px; min-width: 300px; display: flex; flex-direction: column; gap: 4px; }
.presets { min-width: 300px; display: flex; flex-wrap: wrap; gap: 0 14px; align-items: flex-start; padding: 0 8px 5px; }
.presets legend, .cat-presets legend { font-size: 0.68rem; }
.cat-presets { padding: 0 8px 5px; }
.preset-grid { display: flex; flex-direction: column; gap: 2px; flex: 1 1 190px; min-width: 0; }
button.preset-btn {
  height: 21px; padding: 0 7px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-radius: 4px; font-size: 0.78rem;
}
button.preset-btn[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 20%, var(--surface)); font-weight: 600; }
.labels-box { flex: 0 1 190px; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 2px 0 0 12px; border-left: 1px solid var(--border); }
.labels-title { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.labels-checks { display: flex; flex-direction: column; gap: 3px; }
.label-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; font-size: 0.74rem; color: var(--muted); }
.label-legend:empty { display: none; }
.label-legend .chip { display: inline-flex; align-items: center; gap: 4px; }
.label-legend .swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; text-align: center; font-size: 0.68rem; line-height: 14px; font-weight: 700; color: #fff; }
.label-legend .ring { width: 12px; height: 12px; border-radius: 50%; border: 2.5px solid var(--text); display: inline-block; }

/* health labels in the info box */
.health td:first-child { color: var(--muted); }
.health .pill { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 4px; text-align: center; font-weight: 700; color: #fff; }
.health .light { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 6px; vertical-align: -1px; }

/* Data source: a small box in the header, the same height as (and level with) the language flags */
.header-right { display: flex; gap: 14px; align-items: stretch; flex-wrap: wrap; justify-content: flex-end; }
.sources { display: flex; align-items: center; padding: 0 12px; font-size: 0.8rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.source-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
button.seg-btn { display: inline-flex; gap: 5px; align-items: center; border: 0; border-radius: 0; padding: 1px 8px; background: transparent; font-size: 0.75rem; }
button.seg-btn + button.seg-btn { border-left: 1px solid var(--border); }
button.seg-btn[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); font-weight: 600; }
button.seg-btn:disabled { opacity: 0.45; cursor: default; }

/* "Common items" button: a normal subcategory button with a small lightbulb in front */
button.common-btn .label { display: flex; align-items: center; gap: 4px; }
button.common-btn .txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
button.common-btn svg { width: 12px; height: 12px; flex: none; fill: #e0a82e; }

/* Food picture in the info box */
.food-figure { margin: 0 0 12px; }
.food-photo { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); }
.food-figure figcaption { margin-top: 3px; font-size: 0.72rem; color: var(--muted); text-align: right; }
.food-figure a { color: inherit; }

/* the axis, preset and label boxes sit under the chart */
.below-chart { padding-bottom: 8px; }

/* All / None / Choose common items: small buttons next to the "Categories" heading */
.legend-actions { display: inline-flex; gap: 4px; margin-left: 8px; vertical-align: middle; text-transform: none; letter-spacing: 0; }
button.mini-btn { height: 18px; padding: 0 7px; font-size: 0.7rem; line-height: 1; border-radius: 4px; }
