/* Swappable-parts picker (#642) — the template selector, evolved.
   One entry control (the template button) → a sectioned Body/Head/Hat card
   browse. Mock-driven demo, flag-gated. Editor idiom: #4caf50 accent, 6px radii. */

/* ——— Browse modal (appended to body; .main-container clips fixed children) ——— */
.parts-browse-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 1100;
  align-items: center;
  justify-content: center;
}

.parts-browse-modal.open {
  display: flex;
}

.parts-browse-dialog {
  background: var(--surface);
  border-radius: 10px;
  width: min(900px, 94vw);
  /* Fixed height so the dialog doesn't jump as tabs vary in option count. */
  height: min(560px, 86vh);
  display: flex;
  flex-direction: column;
  padding: 18px;
  box-shadow: 0 10px 40px var(--shadow-strong);
}

.parts-browse-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

/* ——— Split layout: preview | browse ——— */
.parts-browse-body {
  display: flex;
  gap: 18px;
  min-height: 0;
  flex: 1 1 auto;
}

.parts-browse-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0; /* let the grid scroll within, not overflow the dialog */
}

/* ——— Preview pane — a maker's cutting mat (deliberately NOT the paint canvas).
       Sage ground + fine grid + 45° bias lines read as the work surface the
       audience already knows; the pieces sit "laid out on the mat". Same in both
       themes (a mat is a mat), and it stays in the warm palette. ——— */
.parts-preview {
  flex: 0 0 40%;
  position: relative;
  border-radius: 8px;
  background-color: #5c6a51;
  background-image:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.09) 0 1px, transparent 1px 46px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.09) 0 1px, transparent 1px 46px),
    linear-gradient(rgba(255, 255, 255, 0.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.14) 1px, transparent 1px);
  background-size: auto, auto, 22px 22px, 22px 22px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Lens toggle (Look | Pieces) — drives what the hero shows. */
.parts-preview-views {
  display: flex;
  gap: 2px;
  margin: 10px 10px 0;
  padding: 2px;
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
}

.parts-preview-view {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.74em;
  padding: 3px 12px;
  border-radius: 4px;
  cursor: pointer;
}

.parts-preview-view.active {
  background: var(--surface);
  color: #3f4a37;
  font-weight: 600;
}

/* The hero area — assembled look OR the workbench of pieces. */
.parts-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 14px;
  overflow-y: auto;
}

.parts-assembly {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.parts-preview-body {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Preview line-art. Fill/stroke are set per-element in applyPreviewLineArt()
   (faint fills + white outlines) so features stay visible — a blanket filter
   would flatten everything to opaque white and hide the eyes/teeth. */
.parts-preview-svg {
  max-width: 100%;
  max-height: 260px;
}

.parts-preview-ghost {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 9px;
  border: 1.5px dashed rgba(255, 255, 255, 0.85);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--surface);
  font-size: 0.74em;
  white-space: nowrap;
  pointer-events: none;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Stacked at the neck: hat sits above the head. */
.parts-ghost-head { top: 9%; }
.parts-ghost-hat { top: 1%; }

/* Look switcher — flip which assembled look is shown. */
.parts-look-switcher {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding-top: 8px;
}

.parts-switch-chip {
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
  color: var(--surface);
  font-size: 0.72em;
  padding: 3px 10px;
  border-radius: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.parts-switch-chip.active {
  background: var(--surface);
  color: #3f4a37;
  font-weight: 600;
  border-color: var(--surface);
}

.parts-stage-hint {
  flex: 0 0 auto;
  margin: 8px 2px 0;
  font-size: 0.7em;
  font-style: italic;
  color: rgba(255, 255, 255, 0.55);
  text-align: center;
}

.parts-preview-tag {
  position: absolute;
  bottom: 8px;
  right: 10px;
  font-size: 0.66em;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
  pointer-events: none;
}

/* ——— Pieces lens = the workbench (all parts laid out as tiles) ——— */
.parts-workbench {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
  align-content: start;
}

.parts-table-tile {
  position: relative;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.parts-table-tile.focused {
  border-color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.18);
}

.parts-table-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  padding: 8px 6px;
  background: transparent;
  border: none;
  color: var(--surface);
  cursor: pointer;
}

.parts-table-main:disabled {
  cursor: default;
}

.parts-table-thumb {
  width: 56px;
  height: 56px;
  border-radius: 5px;
  object-fit: cover;
}

.parts-table-name {
  font-size: 0.66em;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.parts-table-slot {
  font-size: 0.56em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.55);
}

.parts-table-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: var(--surface);
  font-size: 0.85em;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
}

.parts-table-tile:hover .parts-table-remove,
.parts-table-remove:focus {
  opacity: 1;
}

@media (max-width: 720px) {
  .parts-browse-dialog { width: 96vw; height: 90vh; padding: 14px; }
  .parts-browse-body { flex-direction: column; min-height: 0; overflow: hidden; }
  /* Preview is secondary on a phone — bound it so the cards get the room. */
  .parts-preview { flex: 0 0 auto; max-height: 34vh; }
  .parts-stage { min-height: 120px; }
  .parts-preview-svg { max-height: 22vh; }
  .parts-browse-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}

.parts-browse-header h3 {
  margin: 0;
  font-size: 1.15em;
}

/* ——— Footer: the primary confirm/continue CTA (always present, since the
       picker stays open on select). Front door shows "Start painting"; a reopen
       shows "Done". ——— */
.parts-front-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line-1);
}

/* In front-door mode the casual × is downplayed — the CTA is the way forward. */
.parts-browse-modal.front-door .parts-browse-close {
  opacity: 0.5;
}

.parts-front-hint {
  font-size: 0.82em;
  color: var(--ink-4);
}

.parts-start-btn {
  flex: 0 0 auto;
  padding: 9px 20px;
  border: none;
  border-radius: 6px;
  background: var(--brand);
  color: var(--surface);
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
}

.parts-start-btn:hover {
  background: var(--brand-strong);
}

.parts-start-btn i {
  margin-left: 6px;
}

@media (max-width: 720px) {
  .parts-front-foot { flex-direction: column; align-items: stretch; gap: 8px; }
  .parts-front-hint { text-align: center; }
}

.parts-browse-close {
  border: none;
  background: transparent;
  font-size: 1.6em;
  line-height: 1;
  color: var(--ink-3);
  cursor: pointer;
}

.parts-browse-close:hover {
  color: var(--ink);
}

/* ——— Section tabs (Body / Head / Hat) ——— */
.parts-browse-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line-2);
}

.parts-tab {
  position: relative;
  padding: 8px 14px;
  border: none;
  background: transparent;
  font-size: 0.95em;
  color: var(--ink-5);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.parts-tab:hover {
  color: var(--ink);
}

.parts-tab.active {
  color: var(--brand-dark);
  font-weight: 600;
  border-bottom-color: var(--brand);
}

/* Count badge on a tab: a plain dot at 1, a number when >1. */
.parts-tab-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 14px;
  height: 14px;
  margin-left: 6px;
  padding: 0 3px;
  border-radius: 7px;
  background: var(--brand);
  color: var(--surface);
  font-size: 0.6em;
  line-height: 1;
  vertical-align: middle;
}

.parts-tab-dot:empty {
  min-width: 6px;
  width: 6px;
  height: 6px;
  padding: 0;
}

/* Add-to-kit affordance on additive (head/hat) cards. */
.parts-card-action {
  margin-top: 4px;
  font-size: 0.72em;
  font-weight: 600;
  color: var(--brand-dark);
}

.parts-browse-search {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  margin-bottom: 14px;
  border: 1px solid var(--line-4);
  border-radius: 6px;
  font-size: 0.95em;
}

.parts-browse-search:focus {
  outline: none;
  border-color: var(--brand);
}

.parts-browse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  overflow-y: auto;
  padding: 2px;
  flex: 1 1 auto;
  min-height: 0;
  align-content: start;
}

.parts-browse-empty {
  color: var(--ink-3);
  text-align: center;
  padding: 24px 0;
}

.parts-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  border: 2px solid var(--line-2);
  border-radius: 8px;
  background: var(--surface-1);
  cursor: pointer;
  text-align: center;
}

.parts-card:hover {
  border-color: var(--brand);
  background: var(--brand-wash);
}

.parts-card.selected {
  border-color: var(--brand);
  background: var(--brand-tint);
  box-shadow: 0 0 0 1px var(--brand) inset;
}

.parts-card-thumb {
  width: 84px;
  height: 84px;
  border-radius: 6px;
  object-fit: cover;
}

/* Template SVGs are tall line-art — show the whole figure on a light tile. */
.parts-card-thumb-svg {
  object-fit: contain;
  background: var(--surface);
  padding: 4px;
  box-sizing: border-box;
}

/* Template mode hides the Look/Pieces lens toggle entirely. */
.parts-preview-views.hidden {
  display: none;
}

/* Welcome subtitle — only in the front door. */
.parts-welcome-sub {
  display: none;
  margin: -2px 0 12px;
  font-size: 0.88em;
  color: var(--ink-5);
}

.parts-browse-modal.front-door .parts-welcome-sub {
  display: block;
}

.parts-card-name {
  font-size: 0.85em;
  font-weight: 600;
  color: var(--ink);
}

.parts-card-partner {
  font-size: 0.72em;
  color: var(--premium);
}

.parts-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75em;
}

.parts-card-finish {
  color: var(--ink-4);
  text-transform: capitalize;
}

.parts-card-price {
  color: var(--brand-dark);
  font-weight: 700;
}
