/* ==========================================================================
   Vendwright — tool.css
   Calculator-page styles. Load AFTER style.css:

     <link rel="stylesheet" href="/assets/style.css">
     <link rel="stylesheet" href="/assets/tool.css">

   Contents
   01  Tool page layout (form column + sticky result column)
   02  Input grids & tool sections
   03  Result cards, metrics, breakdowns
   04  Bars, notes, actions
   05  Print
   ========================================================================== */


/* 01  Layout ============================================================== */

.tool { padding-block: clamp(1.75rem, 1.2rem + 2.4vw, 3rem); }

.tool__header {
  max-width: var(--w-prose);
  margin-bottom: var(--s-6);
}

.tool__header > * + * { margin-top: var(--s-3); }

/* Single column on small screens; form + result rail from 62em up. */
.tool-layout {
  display: grid;
  gap: var(--s-6);
  align-items: start;
}

@media (min-width: 62em) {
  .tool-layout {
    grid-template-columns: minmax(0, 1fr) 21rem;
    gap: var(--s-7);
  }

  .tool-layout--wide-rail { grid-template-columns: minmax(0, 1fr) 25rem; }

  /* The results rail follows the reader down the form. */
  .tool-layout__results {
    position: sticky;
    top: calc(var(--header-h) + var(--s-4));
    max-height: calc(100vh - var(--header-h) - var(--s-6));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

.tool-layout__form,
.tool-layout__results { min-width: 0; }

.tool-layout__form > * + * { margin-top: var(--s-6); }
.tool-layout__results > * + * { margin-top: var(--s-4); }

/* On mobile the result summary is more useful pinned to the bottom of the
   viewport than buried under the form. Opt in with .tool-dock. */
@media (max-width: 61.99em) {
  /* The dock covers the bottom ~95px of the viewport. Without this, tabbing
     through the form drops a focused field underneath it — WCAG 2.4.11 Focus
     Not Obscured. Keep it comfortably above the dock's own height. */
  html:has(.tool-dock) { scroll-padding-bottom: 7rem; }

  .tool-dock {
    position: sticky;
    bottom: 0;
    z-index: 20;
    margin-inline: calc(var(--gutter) * -1);
    padding: var(--s-3) var(--gutter);
    background: var(--header-bg);
    backdrop-filter: saturate(160%) blur(10px);
    -webkit-backdrop-filter: saturate(160%) blur(10px);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s-4);
  }

  .tool-dock__label {
    font-size: var(--text-xs);
    font-weight: 650;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
  }

  .tool-dock__value {
    min-width: 0;
    font-size: var(--text-xl);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    overflow-wrap: break-word;
    text-align: right;
  }
}

@media (min-width: 62em) {
  .tool-dock { display: none; }
}


/* 02  Input grids & sections ============================================== */

.tool-section {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: var(--s-5);
}

.tool-section__title {
  font-size: var(--text-base);
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-bottom: var(--s-1);
}

.tool-section__note {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--s-4);
  text-wrap: pretty;
}

.tool-section__title + .input-grid { margin-top: var(--s-4); }

/* Input grid. Columns collapse to 1 below ~30rem of container width, so it
   behaves correctly inside both the wide form column and a narrow rail. */
.input-grid {
  display: grid;
  gap: var(--s-4) var(--s-5);
  grid-template-columns: repeat(auto-fit, minmax(min(13rem, 100%), 1fr));
}

.input-grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr)); }
.input-grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(10.5rem, 100%), 1fr)); }
.input-grid--1 { grid-template-columns: 1fr; }

/* A field that should always take the full row inside an input grid. */
.input-grid .field--full { grid-column: 1 / -1; }

/* .field spacing is handled by the grid here, not the .field + .field rule. */
.input-grid .field + .field { margin-top: 0; }

/* Repeating line-item rows (e.g. one row per ingredient / property). */
.line-items { display: grid; gap: var(--s-3); }

.line-item {
  display: grid;
  gap: var(--s-2) var(--s-3);
  grid-template-columns: minmax(0, 1fr);
  align-items: end;
  padding-bottom: var(--s-3);
  border-bottom: 1px dashed var(--border);
}

.line-item:last-child { border-bottom: 0; padding-bottom: 0; }

@media (min-width: 34em) {
  .line-item { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto; }
}

.line-item__remove {
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  color: var(--text-faint);
  cursor: pointer;
  padding: 0.5rem 0.7rem;
  line-height: 1;
  font-size: var(--text-sm);
}

.line-item__remove:hover { color: var(--bad); border-color: var(--bad); }

/* Ingredient-costing rows carry more cells than the generic .line-item —
   name, pack size, pack unit, pack price, amount used, used unit, cost and
   the remove button. Two columns on narrow screens (a child marked
   .field--full spans the row), eight from 56em up. These rules sit after the
   .line-item block above so they win at every width. */
.line-item--ingredient { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.line-item--ingredient > .field--full { grid-column: 1 / -1; }

/* Keep the remove button from stretching across a whole column on mobile. */
.line-item--ingredient > .line-item__remove { justify-self: end; }

@media (min-width: 56em) {
  .line-item--ingredient {
    grid-template-columns:
      minmax(0, 1.6fr)   /* ingredient  */
      minmax(0, 0.8fr)   /* pack size   */
      minmax(0, 0.9fr)   /* pack unit   */
      minmax(0, 1fr)     /* pack price  */
      minmax(0, 0.8fr)   /* amount used */
      minmax(0, 0.9fr)   /* used unit   */
      minmax(0, 0.8fr)   /* cost        */
      auto;              /* remove      */
  }

  .line-item--ingredient > .field--full { grid-column: auto; }
}

/* Currency / unit switcher sitting above the form. */
.tool-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--s-3) var(--s-4);
  margin-bottom: var(--s-5);
}

/* 10rem clipped longer option labels ("Pound sterling (GBP)") inside the
   native select, which has no way to scroll or wrap. */
.tool-controls .field { flex: 0 1 14rem; }


/* 03  Results ============================================================= */

.result-card {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: var(--s-5);
}

/* The one number the page exists to produce. */
.result-card--primary {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.result-card--primary .result-headline { color: var(--accent); }

.result-card--ok   { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); background: var(--ok-bg); }
.result-card--warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); background: var(--warn-bg); }
.result-card--bad  { border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); background: var(--bad-bg); }

.result-card__label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.result-card__value {
  display: block;
  margin-top: 0.25rem;
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  /* Large figures wrap rather than run off the side of a narrow screen. */
  overflow-wrap: break-word;
}

.result-card__note {
  display: block;
  margin-top: var(--s-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-wrap: pretty;
}

.result-card + .result-card { margin-top: var(--s-4); }

/* Two or three secondary numbers side by side. */
.metric-grid {
  display: grid;
  gap: var(--s-3);
  grid-template-columns: repeat(auto-fit, minmax(min(8rem, 100%), 1fr));
}

.metric {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  padding: var(--s-3) var(--s-4);
}

.metric__label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-faint);
  letter-spacing: 0.03em;
}

.metric__value {
  display: block;
  margin-top: 0.1rem;
  font-size: var(--text-lg);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.015em;
  overflow-wrap: break-word;
}

.metric--ok   .metric__value { color: var(--ok); }
.metric--warn .metric__value { color: var(--warn); }
.metric--bad  .metric__value { color: var(--bad); }

/* Itemised breakdown. Uses .result-row from style.css for the rows. */
.breakdown { font-variant-numeric: tabular-nums; }

.breakdown__title {
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: var(--s-2);
}

.result-row__value--sub { font-weight: 400; color: var(--text-muted); }
.result-row__value--minus { color: var(--bad); }


/* 04  Bars, notes, actions =============================================== */

/* Proportion bar: set --pct (0–100) inline, e.g. style="--pct: 42". */
.bar {
  height: 0.5rem;
  border-radius: var(--r-full);
  background: var(--bg-sunken);
  overflow: hidden;
}

.bar__fill {
  display: block;
  height: 100%;
  width: calc(var(--pct, 0) * 1%);
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.2s ease;
}

.bar__fill--ok   { background: var(--ok); }
.bar__fill--warn { background: var(--warn); }
.bar__fill--bad  { background: var(--bad); }

.bar-row { display: grid; gap: 0.3rem; }

.bar-row__head {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  font-size: var(--text-sm);
}

.bar-row__label { flex: 1 1 auto; color: var(--text-muted); min-width: 0; }
.bar-row__value {
  flex: 0 0 auto;
  max-width: 100%;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
  text-align: right;
}

.bar-row + .bar-row { margin-top: var(--s-3); }

/* Assumptions / method notes under a calculator. */
.assumptions {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.assumptions dt {
  font-weight: 650;
  color: var(--text);
  margin-top: var(--s-3);
}

.assumptions dt:first-child { margin-top: 0; }

.assumptions dd { margin: 0.15rem 0 0; }

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  align-items: center;
  margin-top: var(--s-4);
}

.tool-actions__note {
  font-size: var(--text-xs);
  color: var(--text-faint);
}

/* Cross-sell block linking the free tool to the paid template. */
.tool-upsell {
  border: 1px solid var(--accent-border);
  border-radius: var(--r-lg);
  background: var(--accent-soft);
  padding: var(--s-5);
}

.tool-upsell__title {
  font-size: var(--text-base);
  font-weight: 650;
  margin-bottom: var(--s-2);
}

.tool-upsell__text {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--s-4);
  text-wrap: pretty;
}

/* Values the script has not written yet render as a neutral dash, not 0. */
[data-empty="true"] { color: var(--text-faint); }


/* 05  Print =============================================================== */

@media print {
  .tool-layout {
    display: block;
  }

  .tool-layout__results {
    position: static;
    max-height: none;
    overflow: visible;
    margin-top: var(--s-5);
  }

  .tool-dock,
  .tool-upsell,
  .line-item__remove,
  .tool-actions { display: none !important; }

  .tool-section,
  .result-card,
  .metric {
    border: 1px solid #ccc;
    background: none;
    break-inside: avoid;
  }

  .bar { border: 1px solid #999; }
  .bar__fill { background: #333; }
}
