:root{
  --bg:#0b0f17;
  --panel:#111827;
  --panel2:#0f172a;
  --text:#e5e7eb;
  --muted:#94a3b8;
  --border:#1f2937;
  --accent:#60a5fa;
  --accent2:#34d399;
  --danger:#ef4444;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial;
  background:var(--bg);
  color:var(--text);
}
.topbar{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;
  padding:12px 16px;
  border-bottom:1px solid var(--border);
  background:linear-gradient(180deg, rgba(17,24,39,1), rgba(15,23,42,1));
  position:sticky;
  top:0;
  z-index:5;
}
.topbar__title{font-weight:700}
.topbar__controls{display:flex; gap:10px; align-items:center}
.input{
  width:min(520px, 70vw);
  padding:10px 12px;
  border-radius:10px;
  border:1px solid var(--border);
  background:rgba(255,255,255,0.03);
  color:var(--text);
  outline:none;
}
.input:focus{border-color: rgba(96,165,250,0.75)}
.button{
  padding:10px 12px;
  border-radius:10px;
  border:1px solid var(--border);
  background:rgba(255,255,255,0.04);
  color:var(--text);
  cursor:pointer;
}
.button:hover{border-color: rgba(96,165,250,0.6)}
.button:disabled{opacity:0.5; cursor:not-allowed}

/* Loading spinner on generate button */
.button.isLoading{position:relative; padding-right:38px}
.button.isLoading::after{
  content:'';
  position:absolute;
  right:12px;
  top:50%;
  width:14px;
  height:14px;
  margin-top:-7px;
  border-radius:999px;
  border:2px solid rgba(255,255,255,0.45);
  border-top-color: transparent;
  animation: spin 0.85s linear infinite;
}
@keyframes spin{to{transform:rotate(360deg)}}
.button--sm{padding:8px 10px; border-radius:10px; font-size:13px}
.button--primary{
  border-color: rgba(96,165,250,0.75);
  background: rgba(96,165,250,0.18);
}
.button--primary:hover{border-color: rgba(96,165,250,0.95)}

.layout{
  display:grid;
  grid-template-columns: 1fr 420px;
  gap:12px;
  padding:12px;
}
.layout--single{grid-template-columns: 1fr}
@media (max-width: 980px){
  .layout{grid-template-columns:1fr}
  .detail{position:relative; min-height: 30vh;}
}
.panel{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:14px;
  overflow:hidden;
}
.panel__header{
  display:flex;
  justify-content:space-between;
  align-items:baseline;
  gap:12px;
  padding:12px 14px;
  border-bottom:1px solid var(--border);
}
.panel__title{font-weight:700}
.panel__actions{display:flex; align-items:center; gap:10px}
.muted{color:var(--muted); font-size: 13px}

.grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap:10px;
  padding:12px;
}
.card{
  text-align:left;
  display:flex;
  flex-direction:column;
  gap:10px;
  padding:10px;
  border-radius:14px;
  border:1px solid var(--border);
  background:rgba(255,255,255,0.02);
  cursor:pointer;
}
.card:hover{border-color: rgba(96,165,250,0.6)}
.card__imgWrap{
  height:160px;
  border-radius:12px;
  overflow:hidden;
  background:rgba(255,255,255,0.03);
  border:1px solid rgba(255,255,255,0.04);
  display:flex;
  align-items:center;
  justify-content:center;
}
.card__img{width:100%; height:100%; object-fit:cover; display:block}
.card__body{display:flex; flex-direction:column; gap:4px}
.card__sku{font-size:12px; color: var(--muted)}
.card__name{font-weight:650}

.detail{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:14px;
  overflow:hidden;
  min-height: calc(100vh - 72px);
}
.detail__empty{padding:16px}
.detail__content{padding:14px; display:flex; flex-direction:column; gap:14px}
.hidden{display:none !important}
.detail__top{display:flex; justify-content:space-between; align-items:center; gap:12px}
.detail__hero{display:flex; gap:16px; align-items:flex-start}
.detail__image{
  width: clamp(200px, 28vw, 340px);
  height: clamp(200px, 28vw, 340px);
  border-radius:18px;
  border:1px solid var(--border);
  background:rgba(255,255,255,0.03);
  object-fit:contain;
  padding: 6px;
}
.detail__meta{display:flex; flex-direction:column; gap:6px; min-width:0}
.detail__name{font-size:16px; font-weight:750}
.detail__sku{color:var(--muted); font-size:13px}
.detail__link{color: var(--accent); font-size:13px; text-decoration:none}
.detail__link:hover{text-decoration:underline}
.detail__section{border-top:1px solid var(--border); padding-top:14px}
.detail__sectionTitle{font-weight:700; margin-bottom:10px}

.options{display:flex; flex-direction:column; gap:14px}
.optionGroup{padding:10px; border:1px solid var(--border); border-radius:14px; background:rgba(255,255,255,0.015)}
.optionGroup__head{display:flex; justify-content:space-between; align-items:baseline; gap:10px; margin-bottom:10px}
.optionGroup__title{font-weight:700}
.optionGroup__required{color: var(--danger); font-size:12px}
.optionValues{
  display:flex;
  flex-wrap:wrap;
  gap:12px;
}

/* Large, image-only tiles for option values */
.valueBtn{
  width: 170px;
  height: 170px;
  padding: 0;
  border-radius: 16px;
  border:1px solid var(--border);
  background:rgba(255,255,255,0.02);
  color:var(--text);
  cursor:pointer;
  display:flex;
  align-items:stretch;
  justify-content:stretch;
  overflow:hidden;
  position: relative;
  transition: opacity 140ms ease, filter 140ms ease, border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}
@media (max-width: 520px){
  .valueBtn{width: 46vw; height: 46vw;}
}

.valueBtn:hover{border-color: rgba(96,165,250,0.75)}
.valueBtn:focus-visible{outline:3px solid rgba(96,165,250,0.95); outline-offset:2px;}

/* When a value is selected in a group, dim the unselected tiles a bit for clarity */
.optionValues.hasSelection .valueBtn:not(.isSelected){
  opacity: 0.58;
  filter: saturate(0.86) contrast(0.92);
}
.optionValues.hasSelection .valueBtn:not(.isSelected):hover{
  opacity: 0.82;
  filter: none;
}

/* High-contrast selected state (works even for low-contrast underframe/pump images) */
.valueBtn.isSelected{
  border-color: rgba(255,255,255,0.92);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.92), 0 0 0 6px rgba(52,211,153,0.70);
  transform: translateY(-1px);
}
.valueBtn.isSelected::after{
  content:'✓';
  position:absolute;
  top:10px;
  right:10px;
  width:30px;
  height:30px;
  border-radius:999px;
  background: rgba(15,23,42,0.92);
  border:2px solid rgba(255,255,255,0.92);
  color: rgba(255,255,255,0.98);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:18px;
  font-weight:900;
  line-height:1;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
}

.valueBtn__swatch{
  width:100%;
  height:100%;
  object-fit:cover;
  display:block;
  border:0;
  border-radius:0;
  background:rgba(255,255,255,0.04);
}

.valueBtn__swatch.isPlaceholder{
  opacity: 0.22;
  filter: grayscale(1);
}

.card__img.isPlaceholder{
  opacity: 0.22;
  filter: grayscale(1);
}

.generateWrap{display:flex; align-items:center; gap:12px}

.pre{
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  margin: 0;
  color: #cbd5e1;
  overflow:auto;
  max-height: 240px;
}
