/* =========================================================================
   MCSI USA — Closure configurator
   Depends on style.css tokens.
   ========================================================================= */

.cfg-hero {
  background:
    radial-gradient(100% 140% at 88% 0%, rgba(216, 160, 61, .16) 0%, transparent 58%),
    linear-gradient(150deg, var(--ink-900) 0%, var(--ink-800) 100%);
  color: var(--mist-200);
  padding-block: clamp(2.25rem, 4vw, 3.5rem);
}
.cfg-hero h1 { color: #fff; margin-bottom: .4rem; font-size: clamp(1.9rem, 3vw, 2.9rem); }
.cfg-hero .lead { color: rgba(220, 227, 234, .82); max-width: 62ch; }

/* -------------------------------------------------------------- Shell */
.cfg-shell {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: clamp(1.5rem, 3vw, 3rem);
  align-items: start;
  padding-block: clamp(2rem, 4vw, 3.5rem);
}
@media (max-width: 1000px) {
  .cfg-shell { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------ Preview */
.cfg-stage {
  position: sticky;
  top: calc(var(--header-h) + 1rem);
  border: 1px solid var(--mist-200);
  border-radius: var(--r-lg);
  background: #fff;
  box-shadow: var(--sh-sm);
  overflow: hidden;
}
@media (max-width: 1000px) {
  .cfg-stage { position: static; }
}

.cfg-stage__canvas {
  position: relative;
  background:
    radial-gradient(80% 70% at 50% 30%, #FFFFFF 0%, var(--mist-100) 62%, var(--mist-200) 100%);
  padding: 1.25rem;
  display: grid;
  place-items: center;
  min-height: 330px;
}
/* The rendered closure carries a viewBox but no width/height attributes, so it
   has no intrinsic size. #cfg-preview is a shrink-to-fit grid item, which makes
   the sizing circular — host and drawing both collapse to 0x0. Giving the host
   a definite box breaks the cycle; the drawing then scales from its ratio. */
#cfg-preview { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }
.cfg-stage__canvas svg { max-height: 380px; width: auto; max-width: 100%; }
.cfg-stage__canvas.is-swapping svg { opacity: 0; }
.cfg-stage__canvas svg { transition: opacity .18s var(--ease); }

/* ------------------------------------------------------------ 3D stage */
/* Replaces the SVG drawing when WebGL is available. The canvas fills the
   host box that #cfg-preview establishes above. */
.cfg-stage__canvas.is-3d { min-height: 380px; }

canvas.cap-3d {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  /* horizontal drags turn the closure, vertical swipes still scroll the
     page — otherwise the stage would trap scrolling on touch devices */
  touch-action: pan-y;
}
canvas.cap-3d.is-grabbing { cursor: grabbing; }

.cfg-stage__canvas.is-3d #cfg-preview::after {
  content: "Drag to rotate";
  position: absolute;
  left: 50%;
  bottom: .7rem;
  transform: translateX(-50%);
  font-size: var(--fs-xs);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--steel-400);
  background: rgba(255, 255, 255, .82);
  border: 1px solid var(--mist-200);
  border-radius: var(--r-pill);
  padding: .2rem .7rem;
  pointer-events: none;
  transition: opacity .35s var(--ease);
}
#cfg-preview.has-interacted::after { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  canvas.cap-3d { cursor: default; }
}

.cfg-views {
  position: absolute;
  top: .75rem; left: .75rem;
  display: flex;
  gap: .25rem;
  background: rgba(255, 255, 255, .8);
  backdrop-filter: blur(8px);
  padding: .25rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--mist-200);
}
.cfg-views button {
  border: 0;
  background: transparent;
  padding: .38rem .75rem;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--steel-500);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.cfg-views button:hover { color: var(--ink-900); }
.cfg-views button[aria-pressed="true"] { background: var(--ink-900); color: #fff; }

.cfg-stage__code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1.15rem;
  background: var(--ink-900);
  color: var(--mist-200);
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: .02em;
  word-break: break-all;
}
.cfg-stage__code b { color: var(--brass-400); font-weight: 500; }
.cfg-stage__code span:first-child {
  font-family: var(--font-body);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--steel-400);
  flex: none;
}

.cfg-summary { padding: 1.15rem 1.25rem 1.35rem; }
.cfg-summary h2 {
  font-family: var(--font-body);
  font-size: 10.5px;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--steel-400);
  font-weight: 700;
  margin-bottom: .85rem;
}
.cfg-summary dl { margin: 0; display: grid; gap: 0; }
.cfg-summary .row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--mist-100);
  font-size: var(--fs-sm);
  align-items: baseline;
}
.cfg-summary .row:last-child { border-bottom: 0; }
.cfg-summary dt { color: var(--steel-500); }
.cfg-summary dd { margin: 0; text-align: right; color: var(--ink-800); font-weight: 600; }

/* ------------------------------------------------------------ Stepper */
.stepper {
  display: flex;
  gap: .35rem;
  list-style: none;
  margin: 0 0 1.75rem;
  padding: 0 0 .5rem;
  overflow-x: auto;
  scrollbar-width: thin;
}
.stepper li { flex: 1 1 0; min-width: 128px; }
.stepper button {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-top: 3px solid var(--mist-200);
  padding: .7rem .2rem 0;
  cursor: pointer;
  transition: border-color .2s var(--ease);
}
.stepper button:hover { border-top-color: var(--steel-300); }
.stepper .num {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  color: var(--steel-400);
  margin-bottom: .15rem;
}
.stepper .name {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--steel-500);
  line-height: 1.25;
}
.stepper li.is-done button { border-top-color: var(--brass-400); }
.stepper li.is-done .name { color: var(--ink-700); }
.stepper li.is-active button { border-top-color: var(--brass-500); }
.stepper li.is-active .num { color: var(--brass-600); }
.stepper li.is-active .name { color: var(--ink-900); }

/* ------------------------------------------------------------- Panels */
.cfg-panel { display: none; }
.cfg-panel.is-active { display: block; animation: cfgIn .3s var(--ease); }
@keyframes cfgIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.cfg-panel__head { margin-bottom: 1.5rem; }
.cfg-panel__head h2 { font-size: var(--fs-h3); margin-bottom: .35rem; }
.cfg-panel__head p { color: var(--steel-500); margin: 0; max-width: 68ch; }

.cfg-group { margin-bottom: 2rem; }
.cfg-group > h3 {
  font-family: var(--font-body);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--steel-400);
  font-weight: 700;
  margin-bottom: .85rem;
  display: flex;
  align-items: center;
  gap: .6rem;
}
.cfg-group > h3::after { content: ""; flex: 1; height: 1px; background: var(--mist-200); }

/* ------------------------------------------------------- Option cards */
.opt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: .75rem;
}
.opt-grid--wide { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.opt { position: relative; display: block; cursor: pointer; height: 100%; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt__box {
  height: 100%;
  border: 1.5px solid var(--mist-200);
  border-radius: var(--r-md);
  padding: .95rem 1.05rem;
  background: #fff;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background .18s var(--ease);
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.opt:hover .opt__box { border-color: var(--steel-300); }
.opt input:focus-visible + .opt__box { outline: 3px solid var(--brass-500); outline-offset: 2px; }
.opt input:checked + .opt__box {
  border-color: var(--ink-800);
  box-shadow: 0 0 0 3px rgba(29, 58, 86, .1);
  background: #fff;
}
.opt__title {
  font-weight: 600;
  color: var(--ink-900);
  font-size: var(--fs-base);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .6rem;
  line-height: 1.3;
}
.opt__note { font-size: var(--fs-sm); color: var(--steel-500); line-height: 1.45; }
.opt__check {
  flex: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--mist-200);
  display: grid;
  place-items: center;
  margin-top: 1px;
  transition: background .18s var(--ease), border-color .18s var(--ease);
}
.opt__check::after {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: transparent;
  transition: background .18s var(--ease);
}
.opt input:checked + .opt__box .opt__check { border-color: var(--brass-500); background: var(--brass-500); }
.opt input:checked + .opt__box .opt__check::after { background: var(--ink-900); }
.opt input[type="checkbox"]:checked + .opt__box .opt__check { border-radius: 6px; }
.opt input[type="checkbox"] + .opt__box .opt__check { border-radius: 6px; }

.opt__badge {
  display: inline-block;
  align-self: flex-start;
  margin-top: .5rem;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ok-500);
  background: rgba(46, 139, 107, .1);
  padding: .2rem .5rem;
  border-radius: var(--r-pill);
}

/* Option card with a rendered closure thumbnail */
.opt--visual .opt__box { padding: 0; overflow: hidden; }
.opt--visual .opt__thumb {
  background: radial-gradient(70% 70% at 50% 35%, #fff 0%, var(--mist-100) 75%);
  border-bottom: 1px solid var(--mist-200);
  display: grid;
  place-items: center;
  padding: .75rem;
  height: 148px;
}
.opt--visual .opt__thumb svg { max-height: 130px; width: auto; }
.opt--visual .opt__text { padding: .85rem 1rem 1rem; display: flex; flex-direction: column; gap: .2rem; }

/* ------------------------------------------------------------ Swatches */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: .7rem;
}
.swatch { position: relative; cursor: pointer; text-align: center; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch__chip {
  display: block;
  aspect-ratio: 1;
  border-radius: var(--r-md);
  border: 1.5px solid var(--mist-200);
  box-shadow: inset 0 -12px 22px rgba(0, 0, 0, .12), inset 0 10px 18px rgba(255, 255, 255, .35);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.swatch:hover .swatch__chip { transform: translateY(-2px); }
.swatch input:checked + .swatch__chip {
  border-color: var(--ink-900);
  box-shadow: 0 0 0 3px rgba(29, 58, 86, .14), inset 0 -12px 22px rgba(0, 0, 0, .12);
}
.swatch input:focus-visible + .swatch__chip { outline: 3px solid var(--brass-500); outline-offset: 2px; }
.swatch__name {
  display: block;
  font-size: 11px;
  color: var(--steel-500);
  margin-top: .4rem;
  line-height: 1.25;
}
.swatch input:checked ~ .swatch__name { color: var(--ink-900); font-weight: 600; }

.custom-colour {
  display: flex;
  align-items: flex-end;
  gap: .85rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: 1rem;
  border: 1px dashed var(--mist-200);
  border-radius: var(--r-md);
  background: var(--paper-soft);
}
.custom-colour input[type="color"] {
  width: 56px; height: 44px;
  padding: 0;
  border: 1.5px solid var(--mist-200);
  border-radius: var(--r-sm);
  background: none;
  cursor: pointer;
}
.custom-colour .field { margin-bottom: 0; flex: 1 1 180px; }

/* --------------------------------------------------------------- Range */
.range-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
}
.range-row output {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  background: var(--ink-900);
  color: #fff;
  padding: .3rem .65rem;
  border-radius: var(--r-sm);
  min-width: 76px;
  text-align: center;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--mist-200);
  border-radius: 4px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--ink-900);
  border: 3px solid #fff;
  box-shadow: var(--sh-md);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--ink-900);
  border: 3px solid #fff;
  box-shadow: var(--sh-md);
  cursor: pointer;
}

/* --------------------------------------------------------------- Chips */
.chip-grid { display: flex; flex-wrap: wrap; gap: .55rem; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip__box {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .55rem 1rem;
  border: 1.5px solid var(--mist-200);
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--steel-600);
  background: #fff;
  transition: all .18s var(--ease);
}
.chip:hover .chip__box { border-color: var(--steel-300); }
.chip input:focus-visible + .chip__box { outline: 3px solid var(--brass-500); outline-offset: 2px; }
.chip input:checked + .chip__box {
  background: var(--ink-900);
  border-color: var(--ink-900);
  color: #fff;
}
.chip__box::before {
  content: "";
  width: 14px; height: 14px;
  border-radius: 4px;
  border: 1.5px solid var(--steel-300);
  flex: none;
  transition: all .18s var(--ease);
}
.chip input:checked + .chip__box::before {
  background: var(--brass-500) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230B1622' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center / 10px no-repeat;
  border-color: var(--brass-500);
}

/* ------------------------------------------------------------- Actions */
.cfg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
  justify-content: space-between;
  margin-top: 2.25rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--mist-200);
}
.cfg-actions__right { display: flex; gap: .75rem; flex-wrap: wrap; }

.cfg-note {
  display: flex;
  gap: .75rem;
  align-items: flex-start;
  padding: .95rem 1.15rem;
  border-radius: var(--r-md);
  background: var(--brass-100);
  border: 1px solid var(--brass-400);
  color: var(--brass-700);
  font-size: var(--fs-sm);
  margin-bottom: 1.5rem;
}
.cfg-note svg { flex: none; width: 18px; height: 18px; margin-top: 2px; }

/* -------------------------------------------------------- Review table */
.review-table {
  border: 1px solid var(--mist-200);
  border-radius: var(--r-md);
  overflow: hidden;
}
.review-table__group {
  padding: .5rem 1.1rem;
  background: var(--paper-soft);
  border-bottom: 1px solid var(--mist-200);
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--steel-500);
}
.review-table__row {
  display: grid;
  grid-template-columns: minmax(140px, 240px) 1fr;
  gap: 1rem;
  padding: .7rem 1.1rem;
  border-bottom: 1px solid var(--mist-100);
  font-size: var(--fs-sm);
}
.review-table__row:last-child { border-bottom: 0; }
.review-table__row dt { color: var(--steel-500); margin: 0; }
.review-table__row dd { margin: 0; color: var(--ink-800); font-weight: 600; }
@media (max-width: 560px) {
  .review-table__row { grid-template-columns: 1fr; gap: .1rem; }
}
