/* SweetPal pages (readings.html, food.html). Only what the shared components
   don't cover: the pages reuse .section, .section-head, .form-card, .form,
   .field, .input, .check, .btn, .deflist, .perks, .ruled-cols, .app__notes, the
   explainer's segmented toggle (.explainer__toggle) and the test-types dialog
   (.test-modal, for the delete confirmation) as they are. Colours are the tokens in tokens.css;
   crimson only on each page's main action. */

/* Two columns: the form, and its result. One column below 960px. */
.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  align-items: start;
  gap: var(--space-7) clamp(32px, 5vw, 80px);
}

@media (max-width: 959.98px) {
  .tool-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.tool-panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
}

/* Headings that receive focus after an action (tabindex="-1") */
.tool-panel__head h2:focus,
.food-product__head h2:focus {
  outline: none;
}

.tool-panel__head h2:focus-visible,
.food-product__head h2:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

/* What just happened ("Product saved."): a role="status" line, empty until then */
.tool-status {
  font-weight: 600;
}

/* Saved items: readings, saved products, similar products */
.tool-list {
  border-top: 1px solid var(--line);
}

.tool-list > li {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3) var(--space-5);
  padding-block: var(--space-4);
  border-bottom: 1px solid var(--line);
}

.tool-list__main {
  display: grid;
  gap: 2px;
  flex: 1 1 15rem;
  min-width: 0;
}

.tool-list__title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.tool-list__value {
  font-family: var(--font-display);
  font-size: var(--fs-h4);
  font-variant-numeric: tabular-nums;
}

.tool-list .tool-actions {
  flex: 0 0 auto;
}

/* A status in words, with a shape (icon) in front: never colour alone */
.tool-flag {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--fs-small);
  line-height: 1.5;
}

.tool-flag .icon {
  margin-top: 2px;
  color: var(--blue);
}

.tool-flag--muted {
  color: var(--muted);
}

.tool-flag--alert {
  font-weight: 600;
}

.tool-flag--alert .icon {
  color: var(--navy);
}

/* Options side by side (the reading's unit) */
.choices--inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-5);
}

/* The explainer's segmented toggle, with two options (chart period and unit, similar products) */
.tool-toggle {
  margin-bottom: 0;
}

@media (max-width: 559.98px) {
  .tool-toggle {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.tool-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.tool-section-gap {
  margin-top: var(--space-7);
}

/* Disclosure: "Show the chart data as a table" */
.tool-details > summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--blue);
  font-weight: 600;
  cursor: pointer;
}

.tool-details > summary:hover {
  color: var(--blue-hover);
  text-decoration: underline;
}

.tool-details[open] > summary {
  margin-bottom: var(--space-3);
}

/* Chart (readings.html) ------------------------------------------------------ */
.chart {
  margin: 0;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--white);
}

.chart__plot {
  min-height: 240px;
}

.chart__svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart__band {
  fill: var(--ice);
}

.chart__grid,
.chart__day {
  stroke: var(--line);
  stroke-width: 1;
}

.chart__axis {
  stroke: var(--line-strong);
  stroke-width: 1;
}

.chart__line {
  fill: none;
  stroke: var(--blue);
  stroke-width: 2;
  stroke-linejoin: round;
}

.chart__point {
  fill: var(--white);
  stroke: var(--navy);
  stroke-width: 2;
}

.chart__point--marked {
  fill: var(--navy);
}

.chart__tick {
  fill: var(--muted);
  font-family: var(--font-body);
  font-size: 12px;
}

.chart__mark {
  fill: var(--navy);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  paint-order: stroke;
  stroke: var(--white);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  margin-top: var(--space-3);
  color: var(--muted);
}

.chart__legend li {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.chart__legend svg {
  flex: none;
  width: 18px;
  height: 18px;
}

.chart-stats {
  margin-top: var(--space-5);
}

/* Tables (chart data, nutrition values) ----------------------------------------- */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-small);
}

.data-table caption {
  padding-bottom: var(--space-2);
  color: var(--navy);
  font-weight: 600;
  text-align: left;
}

.data-table th,
.data-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th:first-child,
.data-table td:first-child {
  padding-left: 0;
}

.data-table thead th {
  color: var(--muted);
  font-weight: 600;
}

.data-table tbody th {
  font-weight: 600;
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* "of which sugars", "of which saturates" */
.data-table__sub th {
  padding-left: var(--space-4) !important;
  font-weight: 400;
}

/* Phones: tighter cells, so all three columns fit without scrolling the table */
@media (max-width: 479.98px) {
  .data-table th,
  .data-table td {
    padding: var(--space-2);
  }

  .data-table__sub th {
    padding-left: var(--space-3) !important;
  }
}

/* Food ------------------------------------------------------------------------ */
.food-result {
  display: grid;
  gap: var(--space-6);
}

.food-product__head {
  display: grid;
  gap: var(--space-2);
}

.food-product__head .tool-actions {
  margin-top: var(--space-3);
}

.food-block {
  display: grid;
  gap: var(--space-3);
}

.food-status {
  margin-top: var(--space-4);
}

.level-list {
  border-top: 1px solid var(--line);
}

.level-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding-block: var(--space-3);
  border-bottom: 1px solid var(--line);
}

/* Level in words, with a three-step meter (navy, so it never relies on traffic-light colours) */
.level {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
}

.level__meter {
  display: inline-grid;
  grid-template-columns: repeat(3, 10px);
  gap: 3px;
}

.level__meter span {
  height: 14px;
  border: 1.5px solid var(--navy);
  border-radius: 2px;
}

.level__meter .is-on {
  background: var(--navy);
}

.credit {
  padding: var(--space-5);
  border-radius: var(--radius-md);
  background: var(--ice);
}

.credit p + p {
  margin-top: var(--space-2);
}
