/* ==========================================================================
   CONFIGURATOR.CSS — Product Configurator Layout & Sidebar
   toilet-cubicle.co.uk
   ========================================================================== */

/* =========================================================================
   PAGE WRAPPER
   ========================================================================= */

.configurator-page {
  min-height: calc(100vh - var(--header-height));
  min-height: calc(100dvh - var(--header-height));
  background-color: var(--color-off-white);
  overflow: hidden;
}

@media (min-width: 1024px) {
  .configurator-page {
    height: calc(100vh - var(--header-height));
    height: calc(100dvh - var(--header-height));
    overflow: hidden;
  }
}

/* =========================================================================
   TWO-COLUMN LAYOUT
   Viewport (drawing/SVG) on left, sidebar on right
   ========================================================================= */

.configurator {
  display: grid;
  grid-template-columns: 1fr;
  min-height: calc(100vh - var(--header-height));
  min-height: calc(100dvh - var(--header-height));
}

@media (min-width: 1024px) {
  .configurator {
    grid-template-columns: 1fr var(--sidebar-width);
    height: 100%;
    overflow: hidden;
  }
}

/* =========================================================================
   VIEWPORT — Drawing / SVG area
   ========================================================================= */

.configurator__viewport {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Reserve clear bands around the centred drawing so the floating
     controls (view-toggle top-left, drawing tools top-right, dimensions
     readout bottom) never overlap the SVG. --toolbar-band covers the
     ~44px control row plus its top offset; --readout-band the bottom strip. */
  --toolbar-band: 64px;
  --readout-band: 52px;
  padding:
    calc(var(--sp-4) + var(--toolbar-band))
    var(--sp-4)
    calc(var(--sp-4) + var(--readout-band));
  background-color: var(--color-off-white);
  overflow: hidden;

  /* Subtle architectural grid background */
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.025) 1px, transparent 1px);
  background-size: 40px 40px;
}

@media (min-width: 1024px) {
  .configurator__viewport {
    padding:
      calc(var(--sp-6) + var(--toolbar-band))
      var(--sp-6)
      calc(var(--sp-6) + var(--readout-band));
  }
}

/* SVG drawing scales responsively and stays inside the reserved bands.
   The flex parent's padding already keeps it clear of the toolbars; the
   max dimensions stop a wide plan view from spilling under them. */
.configurator__viewport svg {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.06));
  transition: opacity var(--transition-base);
}

/* Loading state */
.configurator__viewport--loading svg {
  opacity: 0.4;
}

/* -- Dimensions Readout --------------------------------------------------- */

.configurator__dimensions-readout {
  position: absolute;
  bottom: var(--sp-3);
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.375rem 0.75rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-grey-200);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-charcoal);
  white-space: nowrap;
}

.configurator__dimensions-readout span {
  color: var(--color-grey-400);
}

@media (max-width: 480px) {
  .configurator__dimensions-readout {
    font-size: var(--text-2xs);
    padding: 0.25rem 0.5rem;
  }

  .configurator__view-toggle .btn {
    font-size: var(--text-2xs);
    padding: 0.25rem 0.5rem;
  }
}

/* Highlight dimension that just changed */
.configurator__dim-value {
  transition: color var(--transition-fast);
}

.configurator__dim-value--changed {
  color: var(--color-green);
}

/* -- Viewport toolbar (zoom, reset, etc.) --------------------------------- */

.configurator__toolbar {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  /* Sit clearly above the drawing (SVG is a later, non-positioned flex
     child). Solid white so the drawing can never show through it. */
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--color-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-grey-200);
  overflow: hidden;
}

.configurator__toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--color-grey-600);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.configurator__toolbar-btn:hover {
  background-color: var(--color-grey-100);
  color: var(--color-petrol);
}

.configurator__toolbar-btn:focus-visible {
  outline: 2px solid var(--color-petrol);
  outline-offset: -2px;
}

.configurator__toolbar-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.configurator__toolbar-btn:disabled:hover {
  background: transparent;
  color: var(--color-grey-600);
}

.configurator__toolbar-btn[aria-pressed="true"] {
  background-color: var(--color-teal-tint);
  color: var(--color-petrol-dark);
}

.configurator__toolbar-btn + .configurator__toolbar-btn {
  border-top: 1px solid var(--color-grey-200);
}

.configurator__toolbar-btn svg {
  width: 18px;
  height: 18px;
}

/* -- View Toggle (Plan / Elevation) --------------------------------------- */

.configurator__view-toggle {
  position: absolute;
  top: var(--sp-3);
  left: var(--sp-3);
  display: flex;
  gap: 0;
  /* Solid white + above the drawing, matching the drawing-tools toolbar. */
  background: var(--color-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-grey-200);
  overflow: hidden;
  z-index: 4;
}

.configurator__view-toggle .btn {
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--color-grey-200);
  min-height: 44px;
  text-transform: none;
  letter-spacing: var(--tracking-normal);
  font-weight: var(--weight-medium);
  font-size: var(--text-xs);
  color: var(--color-grey-600);
  background: transparent;
}

.configurator__view-toggle .btn:last-child {
  border-right: none;
}

.configurator__view-toggle .btn.active {
  background-color: var(--color-petrol);
  color: var(--color-white);
  font-weight: var(--weight-semibold);
}

.configurator__view-toggle .btn:hover:not(.active) {
  background-color: var(--color-grey-100);
  color: var(--color-grey-900);
}

/* =========================================================================
   SIDEBAR
   ========================================================================= */

.configurator__sidebar {
  background-color: var(--color-white);
  border-left: 1px solid var(--color-grey-100);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 1024px) {
  .configurator__sidebar {
    position: sticky;
    top: var(--header-height);
    max-height: calc(100vh - var(--header-height));
    max-height: calc(100dvh - var(--header-height));
  }
}

/* -- Sidebar Header ------------------------------------------------------- */

.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3);
  border-bottom: 1px solid var(--color-grey-100);
  flex-shrink: 0;
}

.sidebar__header h1 {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-normal);
  line-height: 1.4;
  margin-bottom: 0;
}

/* Close button — visible only on mobile */
.sidebar__close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--color-grey-600);
  background: var(--color-grey-100);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.sidebar__close:hover {
  background-color: var(--color-grey-200);
  color: var(--color-grey-900);
}

.sidebar__close svg {
  width: 18px;
  height: 18px;
}

/* =========================================================================
   TABS — Within sidebar
   ========================================================================= */

.tabs {
  display: flex;
  border-bottom: 1px solid var(--color-grey-100);
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

[role="tab"] {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.875rem var(--sp-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-grey-600);
  white-space: nowrap;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  cursor: pointer;
  transition:
    color var(--transition-fast),
    border-color var(--transition-fast),
    background-color var(--transition-fast);
}

[role="tab"]:hover {
  color: var(--color-grey-900);
  background-color: var(--color-grey-50);
}

[role="tab"][aria-selected="true"] {
  color: var(--color-green);
  border-bottom-color: var(--color-green);
  font-weight: var(--weight-semibold);
}

[role="tab"]:focus-visible {
  outline: 2px solid var(--color-green);
  outline-offset: -2px;
}

[role="tab"] svg {
  width: 16px;
  height: 16px;
  opacity: 0.7;
}

[role="tab"][aria-selected="true"] svg {
  opacity: 1;
}

/* -- Sidebar scrollable content wrapper ------------------------------------ */

.sidebar__content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* -- Fieldsets & Legends in sidebar ---------------------------------------- */

.configurator__sidebar fieldset {
  border: none;
  margin-bottom: var(--sp-3);
}

.configurator__sidebar fieldset:last-child {
  margin-bottom: 0;
}

/* Section headings follow the shared .kicker recipe (BRAND.md §2):
   mono 500, 11px, uppercase, 0.08em, petrol, 24×2px lime rule */
.configurator__sidebar legend {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--color-petrol);
  margin-bottom: var(--sp-2);
  width: 100%;
}

.configurator__sidebar legend::before {
  content: "";
  flex-shrink: 0;
  width: 24px;
  height: 2px;
  background-color: var(--color-lime);
}

/* -- Tab panels ----------------------------------------------------------- */

[role="tabpanel"] {
  padding: var(--sp-3);
}

[role="tabpanel"][hidden] {
  display: none;
}

/* Section dividers within panels */
.panel-section {
  margin-bottom: var(--sp-4);
}

.panel-section:last-child {
  margin-bottom: 0;
}

.panel-section__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--color-grey-600);
  margin-bottom: var(--sp-2);
  padding-bottom: var(--sp-1);
  border-bottom: 1px solid var(--color-grey-100);
}

/* =========================================================================
   SPECIFICATION SUMMARY — replaces the old fake step progress
   ========================================================================= */

.config-overview {
  padding: var(--sp-3);
  border-top: 1px solid var(--color-grey-100);
}

.config-overview .kicker {
  margin-bottom: var(--sp-2);
}

.config-overview__list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}

.config-overview__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-2);
}

.config-overview__row dt {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-grey-600);
  flex-shrink: 0;
}

.config-overview__row dd {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-grey-900);
  text-align: right;
  margin: 0;
  overflow-wrap: anywhere;
}

/* =========================================================================
   SIDEBAR ACTIONS — Sticky bottom strip
   ========================================================================= */

.sidebar__actions {
  padding: var(--sp-3);
  border-top: 1px solid var(--color-grey-100);
  background-color: var(--color-white);
  flex-shrink: 0;
}

/* Mono readout strip above the primary action */
.sidebar__readout {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-grey-800);
  background-color: var(--color-grey-50);
  border: 1px solid var(--color-grey-100);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  text-align: center;
  margin-bottom: var(--sp-1);
}

/* Inline error (replaces alert()) */
.sidebar__error {
  margin-top: var(--sp-1);
  font-size: var(--text-xs);
  color: var(--color-error);
  text-align: center;
}

.sidebar__error[hidden] {
  display: none;
}

/* Actions button area stays pinned at bottom via flexbox — no sticky needed */

.sidebar__actions .btn {
  width: 100%;
}

.sidebar__actions .btn + .btn {
  margin-top: var(--sp-1);
}

/* Trade / Pro link */
.sidebar__trade-link {
  display: block;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-grey-600);
  margin-top: var(--sp-2);
}

.sidebar__trade-link a {
  color: var(--color-green);
  font-weight: var(--weight-medium);
}

.sidebar__trade-link a:hover {
  color: var(--color-green-dark);
}

/* =========================================================================
   MOBILE / TABLET — Below 1024px
   Stacked layout: viewport on top, sidebar below, page scrolls
   ========================================================================= */

@media (max-width: 1023px) {
  .configurator-page {
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  .configurator {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  .configurator__viewport {
    min-height: 280px;
    max-height: 50vh;
    /* Tighter reserved bands on the shorter stacked viewport so the
       drawing keeps as much room as possible while still clearing the
       floating controls. */
    --toolbar-band: 52px;
    --readout-band: 40px;
  }

  .configurator__sidebar {
    position: relative;
    transform: none;
    border-left: none;
    border-top: 1px solid var(--color-grey-100);
    max-height: none;
    overflow: visible;
  }

  .sidebar__content {
    overflow: visible;
  }

  /* Hide close button — sidebar is inline, not overlay */
  .sidebar__close {
    display: none;
  }

  /* Backdrop not needed in stacked mode */
  .configurator__sidebar-backdrop {
    display: none !important;
  }
}

/* Desktop — always hide backdrop */
@media (min-width: 1024px) {
  .configurator__sidebar-backdrop {
    display: none !important;
  }
}

/* =========================================================================
   FLOATING "OPEN SIDEBAR" BUTTON — Mobile only
   ========================================================================= */

/* Floating configure button — no longer needed since sidebar is inline on mobile */
.configurator__open-sidebar {
  display: none;
}

/* =========================================================================
   STEPPER — the single numeric input pattern (− / mono value / +)
   44px touch targets, mono value, unit suffix inside the field
   ========================================================================= */

.stepper {
  display: flex;
  align-items: stretch;
}

.stepper__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  color: var(--color-petrol);
  background-color: var(--color-white);
  border: 1px solid var(--color-grey-300);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.stepper__btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.stepper__btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.stepper__btn:hover {
  background-color: var(--color-grey-100);
  color: var(--color-petrol-dark);
}

.stepper__btn:focus-visible {
  outline: 2px solid var(--color-petrol);
  outline-offset: -2px;
  position: relative;
  z-index: 1;
}

.stepper__field {
  position: relative;
  display: flex;
  align-items: stretch;
  flex: 1;
  min-width: 0;
}

.stepper .stepper__input {
  height: 44px;
  min-height: 44px;
  border-radius: 0;
  border-left: none;
  border-right: none;
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: 0 0.25rem;
  min-width: 0;
  -moz-appearance: textfield;
  appearance: textfield;
}

.stepper__input::-webkit-outer-spin-button,
.stepper__input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.stepper__unit {
  display: flex;
  align-items: center;
  padding: 0 0.625rem;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-grey-600);
  background-color: var(--color-grey-50);
  border-top: 1px solid var(--color-grey-300);
  border-bottom: 1px solid var(--color-grey-300);
  user-select: none;
}

/* Compact variant for door rows and the floating toolbar */
.stepper--compact {
  flex: 1 1 150px;
}

.stepper--compact .stepper__unit {
  padding: 0 0.4rem;
}

/* =========================================================================
   SEGMENTED TOGGLE — swing / hinge controls
   ========================================================================= */

.segmented {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--color-grey-300);
  border-radius: var(--radius);
  background-color: var(--color-white);
  overflow: hidden;
}

.segmented__btn {
  flex: 1;
  min-height: 42px; /* +1px border each side = 44px outer target */
  padding: 0 0.75rem;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-grey-600);
  background: transparent;
  border: none;
  border-right: 1px solid var(--color-grey-300);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.segmented__btn:last-child {
  border-right: none;
}

.segmented__btn:hover {
  background-color: var(--color-grey-50);
  color: var(--color-grey-900);
}

.segmented__btn:focus-visible {
  outline: 2px solid var(--color-petrol);
  outline-offset: -2px;
}

/* Selected state — teal-tint bg + petrol (BRAND.md §1) */
.segmented__btn[aria-pressed="true"] {
  background-color: var(--color-teal-tint);
  color: var(--color-petrol-dark);
  font-weight: var(--weight-semibold);
  box-shadow: inset 0 0 0 1px var(--color-petrol);
}

.segmented--compact .segmented__btn {
  padding: 0 0.6rem;
  font-size: var(--text-xs);
}

/* =========================================================================
   PRESET CARDS — quick-start layouts with mini plan glyphs
   ========================================================================= */

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-1);
}

.preset-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: var(--sp-1);
  min-height: 44px;
  background-color: var(--color-white);
  border: 1px solid var(--color-grey-200);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.preset-card:hover {
  border-color: var(--color-petrol);
  box-shadow: var(--shadow-sm);
}

.preset-card:focus-visible {
  outline: 2px solid var(--color-petrol);
  outline-offset: 2px;
}

.preset-card svg {
  width: 64px;
  height: 40px;
  color: var(--color-petrol);
}

.preset-card__label {
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  color: var(--color-grey-800);
  text-align: center;
}

/* =========================================================================
   DOOR ROWS — per-door width / hinge / swing
   ========================================================================= */

.door-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--sp-1) 0;
  border-bottom: 1px dashed var(--color-grey-200);
}

.door-row:last-child {
  border-bottom: none;
}

.door-row__title {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--color-grey-600);
}

.door-row__controls {
  display: flex;
  align-items: stretch;
  gap: var(--sp-1);
  flex-wrap: wrap;
}

.door-rows__reset {
  margin-top: var(--sp-1);
}

/* =========================================================================
   FLOATING CUBICLE TOOLBAR — appears over the canvas for the selected
   cubicle (plain HTML, keyboard-reachable)
   ========================================================================= */

.cubicle-toolbar {
  position: absolute;
  z-index: 5;
  min-width: 300px;
  max-width: calc(100% - 16px);
  padding: var(--sp-1) var(--sp-2) var(--sp-2);
  background-color: var(--color-white);
  border: 1px solid var(--color-grey-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.cubicle-toolbar[hidden] {
  display: none;
}

.cubicle-toolbar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-1);
  margin-bottom: 4px;
}

.cubicle-toolbar__title {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--color-petrol);
}

.cubicle-toolbar__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: -8px -10px -8px 0;
  color: var(--color-grey-600);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.cubicle-toolbar__close:hover {
  background-color: var(--color-grey-100);
  color: var(--color-grey-900);
}

.cubicle-toolbar__close:focus-visible {
  outline: 2px solid var(--color-petrol);
  outline-offset: -2px;
}

.cubicle-toolbar__row {
  display: flex;
  align-items: stretch;
  gap: var(--sp-1);
  flex-wrap: wrap;
}
