/* Deck Material Calculator: inputs beside a sticky result column, then the shopping list and cut plan.
   Colours come from the shared tokens, so the panel follows the light and dark themes. */
.dmc {
  display: grid;
  gap: 1.25rem;
  padding: clamp(14px, 2.4vw, 32px);
  text-align: left;
  color: var(--ink);
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  box-shadow: 4px 4px 0 var(--shade);
}
.dmc *, .dmc *::before, .dmc *::after { box-sizing: border-box; }
.dmc [hidden] { display: none !important; }
.dmc h2 { margin: 0 0 .35rem; font-size: 1.45rem; letter-spacing: -.02em; }
.dmc h3 { margin: 0 0 .6rem; font-size: 1.1rem; }
.dmc h4 { margin: 1rem 0 .4rem; font-size: 1rem; }
.dmc p { margin: 0; color: var(--ink-soft); }
.dmc-head p { max-width: 80ch; }
.dmc-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.dmc label { display: grid; gap: .3rem; min-width: 0; font-size: .85rem; font-weight: 650; }
.dmc-sub { display: block; font-size: .78rem; font-weight: 450; color: var(--ink-soft); }
.dmc input[type="text"], .dmc select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: .5rem .6rem;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--field);
  border: 1.5px solid var(--border-soft);
  border-radius: 6px;
}
.dmc input[aria-invalid="true"], .dmc [data-dmc="lengths"][aria-invalid="true"] { border-color: var(--error); box-shadow: 0 0 0 2px var(--error-soft); }
.dmc :is(input, select, button, summary, a, svg, [tabindex]):focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.dmc button {
  min-height: 42px;
  padding: .5rem .95rem;
  font: inherit;
  font-weight: 650;
  color: var(--ink);
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.dmc button:disabled { opacity: .5; cursor: default; }
.dmc .dmc-primary { color: var(--on-action); background: var(--action); box-shadow: 3px 3px 0 var(--shade); }
.dmc .dmc-primary:hover:not(:disabled) { background: var(--primary-dark); }
.dmc .dmc-check { display: flex; align-items: center; gap: .55rem; min-height: 42px; font-size: .95rem; font-weight: 500; }
.dmc .dmc-check input { flex: none; width: 1.2rem; height: 1.2rem; margin: 0; accent-color: var(--action); }

.dmc-bar { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: .75rem 1rem; }
.dmc-skip { align-self: center; font-weight: 650; color: var(--action-text); }
.dmc-pills { display: flex; flex-wrap: wrap; gap: .5rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.dmc-pills legend { width: 100%; margin-bottom: .45rem; padding: 0; font-weight: 700; }
.dmc-pills .dmc-sub-legend { font-size: .85rem; font-weight: 650; }
.dmc-pills label { position: relative; display: inline-flex; align-items: center; min-height: 42px; padding: .45rem .9rem; font-size: .92rem; background: var(--bg-2); border: 2px solid var(--line); border-radius: 999px; cursor: pointer; }
.dmc-pills input { position: absolute; opacity: 0; pointer-events: none; }
.dmc-pills label:has(input:checked) { color: var(--on-action); background: var(--action); box-shadow: 2px 2px 0 var(--shade); }
.dmc-pills label:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }

.dmc-layout { display: grid; gap: 1.25rem; align-items: start; }
@media (min-width: 1040px) {
  /* Inputs on the left; the summary, plan and code checks beside them, so the framing inputs sit next to their checks. */
  .dmc-layout { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
  .dmc-skip { display: none; }
  /* Reserve the first section, summary cards and drawing while the saved deck is restored. */
  [inert] .dmc-sections:empty { min-height: 4.3rem; }
  [inert] .dmc-result { min-height: clamp(25rem, 68rem - 45vw, 39rem); }
  [inert] .dmc-plan-box:empty { aspect-ratio: 5 / 4; max-height: 520px; }
}
.dmc-inputs { display: grid; gap: 1rem; min-width: 0; }
.dmc-group { display: grid; gap: .8rem; min-width: 0; margin: 0; padding: 1rem; background: var(--blue-tint); border: 2px solid var(--line); border-radius: 10px; }
.dmc-group:nth-child(even) { background: var(--paper-3); }
.dmc-group > legend { padding: 0 .4rem; font-weight: 750; }
.dmc-sub-legend { padding: 0; font-weight: 650; font-size: .85rem; }
.dmc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: .8rem 1rem; align-items: end; }
.dmc-hint { font-size: .85rem; }
.dmc-sections { display: grid; gap: .6rem; }
.dmc-section { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .6rem 1rem; align-items: end; }
.dmc-section .dmc-remove { justify-self: start; }
.dmc-lengths, .dmc-sides { min-width: 0; margin: 0; padding: 0; border: 0; }
.dmc-lengths legend, .dmc-sides legend { margin-bottom: .2rem; }
.dmc-lengths > div, .dmc-sides { display: flex; flex-wrap: wrap; gap: 0 1.1rem; }
.dmc-lengths > div { padding: .1rem .4rem; border: 1.5px solid transparent; border-radius: 6px; }
.dmc-sides legend { width: 100%; }
.dmc-more { padding: .55rem .8rem; background: var(--bg-2); border: 1.5px solid var(--border-soft); border-radius: 8px; }
.dmc-more summary { font-weight: 650; cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.dmc-more[open] summary { margin-bottom: .6rem; }

.dmc-results { display: grid; gap: 1rem; min-width: 0; }
.dmc-results:focus { outline: none; }
.dmc-result { padding: 1rem 1.1rem 1.1rem; background: var(--pastel-green); border: 2px solid var(--line); border-radius: 10px; }
.dmc-result[data-stale="true"] .dmc-answer, .dmc-result[data-stale="true"] .dmc-stats { opacity: .55; }
.dmc .dmc-answer { font-size: clamp(1.15rem, 3vw, 1.5rem); font-weight: 800; line-height: 1.25; letter-spacing: -.01em; color: var(--ink); overflow-wrap: anywhere; }
.dmc-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 7.4rem), 1fr)); gap: .5rem; margin: .9rem 0 0; }
@media (min-width: 1040px) { .dmc-stats { grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); } }
.dmc-stats div { padding: .5rem .65rem; background: var(--bg-2); border: 1.5px solid var(--border-soft); border-radius: 6px; }
.dmc-stats .dmc-key-stat { border: 2px solid var(--line); }
.dmc-stats dt { font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.dmc-stats dd { margin: .2rem 0 0; font: 600 .95rem var(--font-mono); overflow-wrap: anywhere; }
.dmc .dmc-status { margin-top: .8rem; font-weight: 600; color: var(--ink); }
.dmc .dmc-status:empty { margin-top: 0; }
.dmc-errors { margin: .8rem 0 0; padding: .55rem .8rem .55rem 1.6rem; color: var(--ink); background: var(--error-soft); border-left: 4px solid var(--error); border-radius: 6px; font-weight: 600; }

.dmc-plan { margin: 0; padding: .75rem; background: var(--bg-2); border: 2px solid var(--line); border-radius: 10px; }
.dmc-plan figcaption { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .3rem 1rem; margin-bottom: .5rem; }
.dmc-plan-title { font-weight: 750; }
.dmc-legend { display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin: 0; padding: 0; list-style: none; font-size: .8rem; color: var(--ink-soft); }
.dmc-legend li { display: inline-flex; align-items: center; gap: .35rem; }
.dmc-key { display: inline-block; width: 14px; height: 10px; border-radius: 2px; }
.dmc-key-board { background: var(--border-faint); border: 1px solid var(--border-soft); }
.dmc-key-joint { width: 9px; height: 9px; border-radius: 50%; background: var(--action); }
.dmc-key-joist { height: 0; border-top: 2px solid var(--border-soft); }
.dmc-key-beam { height: 0; border-top: 4px solid var(--ink); }
.dmc-key-rail { height: 0; border-top: 3px dashed var(--primary); }
.dmc-plan-box { overflow: hidden; }
.dmc-svg { display: block; width: 100%; height: auto; max-height: 520px; }
.dmc-house { stroke: var(--ink); stroke-linecap: square; }
.dmc-outline { fill: none; stroke: var(--line); }
.dmc-board { stroke: var(--border-faint); stroke-linecap: butt; }
.dmc-border { stroke: var(--border-soft); opacity: .7; }
.dmc-joist { stroke: var(--border-soft); }
.dmc-frame-joist { stroke-dasharray: 4 3; }
.dmc-beam { stroke: var(--ink); stroke-linecap: butt; }
.dmc-post { fill: var(--ink); }
.dmc-joint { fill: var(--action); }
.dmc-rail { stroke: var(--primary); fill: none; }
.dmc-rail-post { fill: var(--primary); }
.dmc-stair { fill: var(--bg-2); stroke: var(--ink-soft); }
.dmc-tread { stroke: var(--ink-soft); }
.dmc-label { fill: var(--ink); font-family: var(--font-mono); font-weight: 600; }
.dmc .dmc-plan-text { margin-top: .5rem; font-size: .82rem; }

.dmc-checks { padding: 1rem; background: var(--bg-2); border: 2px solid var(--line); border-radius: 10px; }
.dmc-checks ul { display: grid; gap: .5rem; margin: 0 0 .7rem; padding: 0; list-style: none; }
.dmc-checks li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .65rem; align-items: start; padding: .55rem .7rem; border: 1.5px solid var(--border-soft); border-left-width: 5px; border-radius: 6px; }
.dmc-checks li p { margin-top: .15rem; font-size: .88rem; color: var(--ink); }
.dmc-checks .dmc-source { display: block; margin-top: .2rem; font-size: .75rem; color: var(--ink-soft); }
.dmc-badge { display: inline-block; min-width: 3.4rem; padding: .15rem .45rem; font-size: .75rem; font-weight: 750; text-align: center; text-transform: uppercase; letter-spacing: .04em; border-radius: 999px; border: 1.5px solid var(--line); background: var(--bg-2); color: var(--ink); }
.dmc-check-pass { border-left-color: var(--success) !important; }
.dmc-check-pass .dmc-badge { background: var(--success-soft); }
.dmc-check-fail { border-left-color: var(--error) !important; background: var(--error-soft); }
.dmc-check-fail .dmc-badge { color: var(--on-action); background: var(--error); border-color: var(--error); }
.dmc-check-outside { border-left-color: var(--warning) !important; background: var(--warning-soft); }
.dmc-check-info { border-left-color: var(--info) !important; }

.dmc-list { display: grid; gap: .7rem; min-width: 0; }
.dmc-list-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: .5rem 1rem; }
.dmc-list-head h3 { margin: 0; }
.dmc .dmc-currency { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.dmc .dmc-currency select { width: auto; min-width: 9rem; }
.dmc-table-wrap { max-width: 100%; overflow: auto; background: var(--bg-2); border: 1.5px solid var(--border-soft); border-radius: 6px; }
.dmc table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.dmc th, .dmc td { padding: .45rem .65rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border-faint); }
.dmc thead th { position: sticky; top: 0; z-index: 1; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); background: var(--paper-3); }
.dmc tbody th { font-weight: 600; }
.dmc .dmc-num { text-align: right; white-space: nowrap; font-family: var(--font-mono); }
.dmc thead .dmc-num { font-family: inherit; }
.dmc .dmc-group-row th { padding-top: .7rem; font-size: .8rem; font-weight: 750; text-transform: uppercase; letter-spacing: .04em; color: var(--ink); background: var(--blue-tint); }
.dmc tfoot th, .dmc tfoot td { font-weight: 750; border-top: 2px solid var(--line); border-bottom: 0; }
.dmc [data-dmc="items"] tbody th { min-width: 11rem; }
/* The item names stay in view while a narrow screen scrolls the table sideways. */
.dmc [data-dmc="items"] tbody tr[data-key] th, .dmc [data-dmc="items"] thead th:first-child { position: sticky; left: 0; z-index: 1; background: var(--bg-2); box-shadow: 1px 0 0 var(--border-faint); }
.dmc [data-dmc="items"] thead th:first-child { z-index: 2; background: var(--paper-3); }
.dmc .dmc-group-row th span { position: sticky; left: .65rem; }
.dmc [data-dmc="items"] tbody th .dmc-sub { margin-top: .15rem; }
.dmc .dmc-price { width: 7.5rem !important; min-height: 36px !important; padding: .3rem .45rem !important; text-align: right; font-family: var(--font-mono) !important; }
.dmc .dmc-cost { font-weight: 650; color: var(--ink); }
.dmc .dmc-cost:empty { display: none; }
.dmc-actions { display: flex; flex-wrap: wrap; gap: .6rem; }

.dmc-cut { padding: .8rem 1rem; border: 1.5px solid var(--border-soft); border-radius: 10px; }
.dmc-cut summary { font-weight: 700; cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.dmc-cut[open] summary { margin-bottom: .6rem; }
.dmc-cut .dmc-table-wrap { max-height: 26rem; }
.dmc-cut td { font-family: var(--font-mono); font-size: .82rem; overflow-wrap: anywhere; }
.dmc .dmc-foot { font-size: .85rem; }

@media (max-width: 560px) {
  .dmc-bar { align-items: stretch; }
  .dmc-bar > button { width: 100%; }
  .dmc .dmc-currency { width: 100%; }
  .dmc .dmc-currency select { flex: 1; }
  .dmc-actions button { flex: 1 1 auto; }
  .dmc-grid { grid-template-columns: minmax(0, 1fr); }
  .dmc-stats dd { font-size: .85rem; }
  .dmc [data-dmc="items"] tbody th { min-width: 8.5rem; }
}

/* Space the page holds for this view until it mounts (see .tool-view-placeholder in _workspace.css).
   Each height is a little under the space the view takes at that width, measured as how far the
   content below moves when the view replaces the placeholder, so nothing below it moves. Re-measure
   after changing the view's layout: node scripts/measure-tool-views.js --apply deck-material-calculator. */
.tool-view-placeholder[data-tool="deck-material-calculator"] { min-height: 5504px; }
@media (max-width: 1032px) { .tool-view-placeholder[data-tool="deck-material-calculator"] { min-height: 7605px; } }
@media (max-width: 928px) { .tool-view-placeholder[data-tool="deck-material-calculator"] { min-height: 7730px; } }
@media (max-width: 632px) { .tool-view-placeholder[data-tool="deck-material-calculator"] { min-height: 9688px; } }
@media (max-width: 480px) { .tool-view-placeholder[data-tool="deck-material-calculator"] { min-height: 12161px; } }
