/* ─── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #f8f8f6;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-muted: #666;
  --color-accent: #2c2c2c;
  --color-border: #e0e0e0;
  --color-hover: #f0f0ee;
  --color-active: #2c2c2c;
  --color-active-text: #ffffff;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ─── Header ──────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 160px 1rem 2rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header__title {
  font-size: 1.2rem;
  font-weight: 600;
  white-space: nowrap;
}

.header__price {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-text);
  margin-left: auto;
  white-space: nowrap;
}

.header__search {
  flex: 1;
  max-width: 400px;
}

.header__search input {
  width: 100%;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.header__search input:focus {
  border-color: var(--color-accent);
}

.header__filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.header__filters select {
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: white;
  cursor: pointer;
}

.header__back {
  background: none;
  border: 1px solid var(--color-border);
  padding: 0.4rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
}

.header__back:hover {
  background: var(--color-hover);
}

/* ─── Color Filter Dropdown ───────────────────────────────────────────── */
.color-dd {
  position: relative;
  width: 100%;
  min-width: 0;
}

.color-dd__trigger {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: white;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font);
  color: var(--color-text);
  width: 100%;
  box-sizing: border-box;
}

.color-dd__trigger:hover {
  border-color: var(--color-accent);
}

.color-dd__arrow {
  font-size: 0.7rem;
  opacity: 0.5;
  margin-left: 0.2rem;
}

.color-dd__menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
}

.color-dd__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: background 0.15s;
}

.color-dd__item:hover {
  background: var(--color-hover);
}

.color-dd__item--active {
  font-weight: 600;
  background: var(--color-hover);
}

.color-dd__dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 0.5px rgba(0,0,0,0.15);
}

/* ─── Product Grid ────────────────────────────────────────────────────── */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.product-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.product-card__image {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: contain;
  background: #f5f5f3;
  padding: 1rem;
}

.product-card__info {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.product-card__name {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.product-card__category {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-transform: capitalize;
  margin-bottom: 0.5rem;
}

.product-card__price {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.4rem;
}

.product-card__swatches {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
  align-content: flex-start;
}

.product-card__swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
}

.product-card__badge {
  display: inline-block;
  background: #1a1a1a;
  color: white;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

/* ─── Configurator ────────────────────────────────────────────────────── */
.configurator {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* Viewer */
.configurator__viewer {
  position: sticky;
  top: 80px;
  align-self: start;
}

.configurator__image-wrap {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.configurator__image-wrap img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  display: block;
  padding: 1rem;
  transition: opacity 0.3s;
}

.configurator__image-wrap img.loading {
  opacity: 0.4;
}

.configurator__spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.6);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.configurator__position-tabs {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.configurator__position-tabs button {
  flex: 1;
  padding: 0.6rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.configurator__position-tabs button.active {
  background: var(--color-active);
  color: var(--color-active-text);
  border-color: var(--color-active);
}

.configurator__position-tabs button:hover:not(.active) {
  background: var(--color-hover);
}

.configurator__360 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 0.75rem;
}

.configurator__360 button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-surface);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.configurator__360 button:hover {
  background: var(--color-hover);
}

#frame-indicator {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* Options Panel */
.configurator__options {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.configurator__name {
  font-size: 1.5rem;
  font-weight: 700;
}

.configurator__category {
  text-transform: capitalize;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.configurator__designer {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-style: italic;
}

.configurator__description {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  line-height: 1.6;
}

.configurator__section {
  border-top: 1px solid var(--color-border);
  padding-top: 1.25rem;
}

.configurator__section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.fabric-name-label {
  font-weight: 400;
  color: var(--color-text-muted);
}

/* Fabric Filter (Family tabs) */
.fabric-filter {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.fabric-filter button {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.fabric-filter button.active {
  background: var(--color-active);
  color: var(--color-active-text);
  border-color: var(--color-active);
}

.fabric-filter button:hover:not(.active) {
  background: var(--color-hover);
}

/* Fabric Grid */
.fabric-grid {
  max-height: 360px;
  overflow-y: auto;
  padding: 4px;
}

.fabric-group {
  margin-bottom: 1rem;
}

.fabric-group__label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--color-border);
}

.fabric-group__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
}

.swatch {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.1s;
  background: #eee;
  position: relative;
}

.swatch:hover {
  transform: scale(1.1);
  z-index: 1;
}

.swatch.active {
  border-color: var(--color-active);
  box-shadow: 0 0 0 2px var(--color-active);
}

.swatch img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.swatch__stock {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid white;
}

.swatch__stock--in-stock { background: #4caf50; }
.swatch__stock--on-order { background: #ff9800; }

/* Fabric Info */
.fabric-info {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--color-bg);
  border-radius: var(--radius);
}

.fabric-info table {
  width: 100%;
  font-size: 0.85rem;
}

.fabric-info td {
  padding: 0.25rem 0;
}

.fabric-info td:first-child {
  color: var(--color-text-muted);
  width: 40%;
}

/* Leg Grid */
.leg-grid {
  display: flex;
  gap: 0.5rem;
}

.leg-option {
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  background: var(--color-surface);
}

.leg-option.active {
  background: var(--color-active);
  color: var(--color-active-text);
  border-color: var(--color-active);
}

.leg-option:hover:not(.active) {
  background: var(--color-hover);
}

/* Dimensions Table */
.dimensions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.dimensions-table th {
  text-align: left;
  padding: 0.5rem 0;
  border-bottom: 2px solid var(--color-border);
  font-weight: 600;
}

.dimensions-table td {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--color-border);
}

.dimensions-table td:first-child {
  color: var(--color-text-muted);
}

.dimensions-table td:last-child {
  text-align: right;
  font-weight: 500;
}

/* Features */
#features-list {
  list-style: none;
  font-size: 0.9rem;
}

#features-list li {
  padding: 0.25rem 0;
  padding-left: 1rem;
  position: relative;
}

#features-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--color-text-muted);
}

/* CTA */
.configurator__cta {
  display: block;
  text-align: center;
  padding: 0.85rem 2rem;
  background: var(--color-accent);
  color: white;
  text-decoration: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  transition: opacity 0.2s;
  margin-top: 1rem;
}

.configurator__cta:hover {
  opacity: 0.85;
}

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .configurator {
    grid-template-columns: 1fr;
  }

  .configurator__viewer {
    position: static;
  }

  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    padding: 1rem;
    gap: 1rem;
  }

  .header {
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
  }

  .header__title {
    flex: 1;
    min-width: 0;
    padding-right: 120px;
  }

  .header__search {
    order: 3;
    max-width: 100%;
    flex-basis: 100%;
  }

  .header__filters {
    order: 4;
    flex-basis: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    overflow: visible;
  }

  .header__filters select {
    width: 100%;
    min-width: 0;
    font-size: 0.82rem;
    padding: 0.45rem 0.6rem;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* ─── Loading State ───────────────────────────────────────────────────── */
.loading-message {
  text-align: center;
  padding: 4rem;
  color: var(--color-text-muted);
  font-size: 1.1rem;
}

/* No Results */
.no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem;
  color: var(--color-text-muted);
}

.product-card__cta {
  display: block;
  margin-top: 12px;
  padding: 9px 16px;
  background: var(--color-accent, #2D8C5A);
  color: #fff;
  border-radius: var(--radius, 6px);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s;
}
.product-card:hover .product-card__cta {
  background: #246f47;
}
