:root {
  --orange: #ff6310;
  --orange-dark: #df4f05;
  --dark: #111518;
  --grey: #687279;
  --border: #dfe4e7;
  --input: #f7f8f8;
  --white: #ffffff;
  --bg: #e9ebec;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: Verdana, Arial, sans-serif;
  color: var(--dark);
  background: var(--bg);
  overflow-x: auto; /* scroll rather than break below minimum */
}

/* ── Layout ── */
.configurator {
  display: flex;
  flex-direction: row;
  height: 100vh;        /* exact viewport height — constrains children so controls can scroll */
  min-width: 640px;
}

.viewer-pane {
  flex: 1 1 0%;
  min-width: 260px;
  min-height: 0;        /* allow flex child to shrink freely */
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

#viewer {
  width: 100%;
  height: 100%;         /* fill the pane, no min-height needed */
}

#viewer canvas { display: block; }

.view-reset {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--grey);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 12px;
  cursor: pointer;
  z-index: 2;              /* above the canvas */
  transition: color 0.12s, background 0.12s;
}
.view-reset:hover { color: var(--dark); background: rgba(255, 255, 255, 0.96); }
.view-reset svg { width: 14px; height: 14px; display: block; flex-shrink: 0; }

.viewer-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--grey);
  background: rgba(255,255,255,0.82);
  padding: 4px 12px;
  border-radius: 12px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 1; /* always on top of canvas */
}

/* ---------- Read-only view (?view=readonly) — customer config opened from a quote email ---------- */
/* Keep the full controls panel visible as a read-only spec sheet: every field is disabled (a hard
   lock) but styled to look crisp and filled-in, not the ugly native grey. The action buttons are
   hidden (a live "Request a Quote" makes no sense on an already-submitted quote). */
body.view-readonly .cta-area { display: none; }

/* Part-number header (only in read-only) */
.ro-head {
  margin: -6px 0 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.ro-head__label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--grey);
}
.ro-head__pn {
  display: block;
  font-size: 18px;
  font-weight: 600;
  color: var(--dark);
  margin-top: 3px;
}

/* Read-only: link to the printable internal spec sheet (inserted by JS after the PN header). */
.ro-spec-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: -8px 0 18px;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  color: var(--dark);
  font-family: Verdana, Arial, sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.ro-spec-btn:hover { border-color: var(--orange); background: #fff7f3; }
.ro-spec-btn svg { width: 15px; height: 15px; flex: none; }

/* Read-only: "visualization only" disclaimer at the bottom (CTA area is hidden in readonly). */
.ro-note { font-size: 11px; color: var(--grey); line-height: 1.5; text-align: center; margin: 20px 0 0; }

/* Staff-only "Copy view-only link" button (shown in ?staff= mode; dashed = internal tool). */
.staff-link-btn {
  width: 100%; height: 42px; margin-bottom: 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px dashed var(--grey); border-radius: 8px;
  background: #fafbfc; color: var(--dark);
  font-family: Verdana, Arial, sans-serif; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.staff-link-btn:hover { border-color: var(--orange); background: #fff7f3; }
.staff-link-btn svg { width: 15px; height: 15px; flex: none; }

/* Make disabled fields read as "locked & filled", not "greyed-out / broken". */
body.view-readonly select:disabled,
body.view-readonly input:disabled {
  opacity: 1;
  color: var(--dark);
  -webkit-text-fill-color: var(--dark);   /* Safari keeps disabled text grey without this */
  background-color: var(--white);
  cursor: default;
}
body.view-readonly .check-field input:disabled { cursor: default; }
/* Drop the dropdown arrow — nothing is clickable in read-only, so the caret would mislead. */
body.view-readonly .field select {
  background-image: none;
  padding: 0 12px;
}

.controls-pane {
  flex: 0 0 clamp(300px, 38%, 380px);
  min-height: 0;        /* required for overflow-y to work in a flex child */
  padding: 24px 26px 28px;
  overflow-y: auto;
  background: var(--white);
  border-left: 1px solid var(--border);
}

.controls-pane h1 {
  font-family: 'Oswald', sans-serif;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 20px;
  color: var(--dark);
}

/* ── Groups ── */
.group {
  margin-top: 20px;
}

.group:first-of-type {
  margin-top: 0;
}

.group--material {
  margin-top: 28px;
}

/* ── Fields ── */
.field {
  margin-bottom: 12px;
  min-width: 0;   /* let the 2-col grid tracks shrink below content (no overflow on narrow phones) */
}

.field:last-child { margin-bottom: 0; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 8px;
}

.field-row:last-child { margin-bottom: 0; }

/* No gap between End Pin Type/Pin Ø row and Flip Ends checkbox */
.field-row:has(+ .check-field) { margin-bottom: 0; }

/* Gap between Flip Ends and legs section */
.check-field { margin-bottom: 10px; }

/* Collapse that gap when warning is showing (warning provides own spacing) */
.check-field:has(+ .warning:not(:empty)) { margin-bottom: 0; }

/* Disabled state: not-allowed cursor on whole check-field */
.check-field:has(input:disabled) { cursor: not-allowed; }
.check-field:has(input:disabled) label { cursor: not-allowed; opacity: 0.4; }
.check-field:has(input:disabled) input { cursor: not-allowed; }

.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--grey);
  margin-bottom: 6px;
}

.field select,
.field input[type="number"],
.field input[type="text"] {
  width: 100%;
  height: 44px;
  padding: 0 34px 0 12px;
  font-size: 13px;
  font-family: Verdana, Arial, sans-serif;
  color: var(--dark);
  background-color: var(--input);
  border: 1px solid #cfd6da;
  border-radius: 8px;
  appearance: none;
  background-image:
    linear-gradient(45deg,  transparent 50%, var(--dark) 50%),
    linear-gradient(135deg, var(--dark) 50%, transparent 50%);
  background-position: calc(100% - 16px) 19px, calc(100% - 11px) 19px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color 0.15s, background-color 0.15s;
}

.field input[type="number"],
.field input[type="text"] {
  background-image: none;
  padding: 0 12px;
}

.field select:hover  { border-color: #9fa8ad; background-color: var(--white); }
.field select:focus,
.field input:focus   {
  outline: 3px solid rgba(255, 99, 16, 0.18);
  border-color: var(--orange);
  background-color: var(--white);
}

/* ── Checkbox ── */
.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--orange);
  cursor: pointer;
  flex-shrink: 0;
}

.check-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--dark);
  cursor: pointer;
}

/* ── Helpers ── */
.custom-input { margin-top: 6px; }
.hidden { display: none !important; }

.note {
  font-size: 11px;
  color: var(--grey);
  margin-top: 5px;
}

.warning {
  font-size: 12px;
  color: #b35900;
  margin-bottom: 12px;
}

/* Clearance above the warning so it never crowds the Flip Ends row (the old
   negative top margin overlapped once the message grew past one line). */
.warning:not(:empty) {
  margin-top: 8px;
}

.warning:empty {
  margin: 0;
}

.warn-line {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 5px;
  line-height: 1.4;
}
.warn-line:first-child { margin-top: 0; }

.warn-icon {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin-top: 1px;
}

.warn-text { flex: 1 1 auto; }

.warn-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

/* Neutral secondary buttons — kept visually quiet and distinct from the amber
   warning text and the orange quote CTA (reserve alert colours for alerts). */
.warn-fix {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 4px;
  border: 1px solid #c2c7cf;
  background: #fff;
  color: #33373d;
  cursor: pointer;
  line-height: 1.3;
}
.warn-fix:hover { background: #f0f1f3; border-color: #9aa0a8; }

/* ── CTA ── */
.cta-area {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.btn {
  width: 100%;
  height: 50px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  font-family: Verdana, Arial, sans-serif;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--orange);
  color: #fff;
  font-weight: 500;
}

.btn-primary:hover { background: #fd7c47; }

/* Impossible config: paddle doesn't fit the leg — quote is blocked. */
.btn-primary:disabled,
.btn-primary.disabled {
  background: #c9ccd1;
  color: #7a7f87;
  cursor: not-allowed;
}
.btn-primary:disabled:hover,
.btn-primary.disabled:hover { background: #c9ccd1; }

.micro-note {
  font-size: 11px;
  color: var(--grey);
  text-align: center;
  line-height: 1.5;
  margin: 10px 0 12px;
}

.btn-reset-link {
  background: none;
  border: none;
  font-family: Verdana, Arial, sans-serif;
  font-size: 12px;
  color: var(--grey);
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.btn-reset-link:hover { color: var(--dark); }

/* ── Short-window compact mode ── */
@media (max-height: 780px) {
  .controls-pane { padding: 18px 26px 20px; }
  .group { margin-top: 14px; }
  .group--material { margin-top: 20px; }
  .cta-area { margin-top: 16px; }
}

@media (max-height: 660px) {
  .controls-pane { padding: 14px 26px 16px; }
  .controls-pane h1 { font-size: 20px; margin-bottom: 14px; }
  .group { margin-top: 10px; }
  .group--material { margin-top: 14px; }
  .field select,
  .field input[type="number"],
  .field input[type="text"] { height: 36px; font-size: 12px; }
  .field label { margin-bottom: 4px; }
  .field-row { gap: 10px; margin-bottom: 6px; }
  .cta-area { margin-top: 12px; }
  .btn { height: 42px; font-size: 14px; }
}

/* ── Responsive ── */
@media (max-width: 700px) {
  .configurator {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    min-width: unset;
  }
  .viewer-pane  {
    flex: 0 0 300px;
    min-width: unset;
    min-height: 300px;
    overflow: visible;
  }
  #viewer { height: 300px; }
  .controls-pane {
    flex: 1 1 auto;
    height: auto;
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* Keep the two-column field layout on phones too — it fits (dropdown values are short).
   Only fall back to a single column on very tiny/legacy screens (≤340px) where two
   columns would get genuinely cramped. */
@media (max-width: 340px) {
  .field-row { grid-template-columns: 1fr; }
}
