/* styles.css */

/* Reset & base */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f5f5f5;
  color: #333;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* Page management */
.page { display: none; min-height: 100vh; }
.page.active { display: block; }

/* Product selection */
#productSelection {
  background: linear-gradient(135deg, #fcedfb 0%, #a06ad7 100%);
  color: #fff;
}
#productSelection h1 {
  text-align: center;
  font-size: 3rem;
  margin-bottom: 3rem;
  text-shadow: 0 2px 4px rgba(0,0,0,.3);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 2rem;
  margin-top: 2rem;
}

.product-card {
  background: #fff;
  border-radius: 15px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: transform .3s ease, box-shadow .3s ease;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
  color: #333;
}
.product-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 20px 40px rgba(0,0,0,.3);
}
.product-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 1rem;
}
.product-card h3 {
  font-size: 1.5rem;
  margin-bottom: .5rem;
  color: #2c3e50;
}
.product-card p {
  font-size: 1.2rem;
  color: #3498db;
  font-weight: 700;
}

/* Designer layout */
.designer-container {
  display: grid;
  grid-template-columns: 700px 1fr 250px;
  height: 100vh;
  background: #f8fafc;
}

/* Sidebar */
.sidebar {
  background: #fff;
  border-right: 1px solid #e2e8f0;
  padding: 1rem;
  overflow-y: auto;
}
.sidebar-header { margin-bottom: 2rem; }

.back-btn {
  background: #64748b;
  color: #fff;
  border: none;
  padding: .5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
  transition: background .2s;
}
.back-btn:hover { background: #475569; }

.tool-section h3 {
  margin-bottom: 1rem;
  color: #1e293b;
  font-size: 1.1rem;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  margin-bottom: 2rem;
}

.tool-btn {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem;
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
}
.tool-btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
.tool-btn.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }
.tool-icon { font-size: 1.5rem; }
.tool-btn span { font-size: .8rem; font-weight: 500; }

/* Panels */
.panel {
  display: none;
  margin-top: 1rem;
  padding: 1rem;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}
.panel.active { display: block; }
.panel h4 { margin-bottom: 1rem; color: #1e293b; }

/* Upload panel */
.upload-area {
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  background: #fff;
}
.upload-label { cursor: pointer; display: block; }
.upload-icon { font-size: 2rem; margin-bottom: .5rem; }
.upload-btn {
  background: #3b82f6;
  color: #fff;
  border: none;
  padding: .5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  margin-top: 1rem;
}

/* Text panel basics */
.text-controls {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin: 1rem 0;
}
.text-controls label { font-size: .9rem; font-weight: 500; color: #374151; }
.text-controls input {
  padding: .5rem;
  border: 1px solid #d1d5db;
  border-radius: 4px;
}
#textInput {
  width: 100%;
  padding: .5rem;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  margin-bottom: 1rem;
}
.add-btn {
  background: #d97ed2;
  color: #fff;
  border: none;
  padding: .5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
}

/* Color panel (default) */
.color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: .3rem;
  max-height: 425px;
  overflow-y: auto;
}
.color-option {
  width: 35px;
  height: 35px;
  border-radius: 8px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform .2s, border-color .2s, box-shadow .2s;
  background-size: cover;
  background-position: center;
  position: relative;
}
.color-option:hover { border-color: #3b82f6; transform: scale(1.1); }
.color-option.selected { border-color: #1e40af; box-shadow: 0 0 0 2px #93c5fd; }


/* Design area (center card) */
.design-area {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fcedfb 0%, #be7eff 100%);
  padding: 2rem;
}
.product-preview {
  background: #fff;
  border-radius: 15px;
  padding: 2rem;
  box-shadow: 0 10px 25px rgba(0,0,0,.1);
}

/* Shirt canvas */
.tshirt-container { position: relative; width: 600px; height: 700px; }
.tshirt-canvas {
  position: relative;
  width: 100%;
  height: 100%;
  background: transparent;
  border-radius: 20px;
  overflow: hidden;
  contain: layout paint size;          /* perf */
}

/* Shirt layers */
.tshirt-color-layer {
  position: absolute; inset: 0;
  border-radius: 20px;
  z-index: 0;
}
.tshirt-view-image {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  pointer-events: none;
  z-index: 1;
  opacity: .8;
}

/* Right panel */
.right-panel {
  background: #fff;
  border-left: 1px solid #e2e8f0;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

/* View tabs (stacked list with thumbnails) */
.view-tabs {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-bottom: 2rem;
}
.view-tab {
  display: flex;
  align-items: center;
  gap: 2.5rem;
  padding: 30px .75rem;
  width: 100%;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  cursor: pointer;
  border-radius: 6px;
  transition: background .2s, color .2s, border-color .2s, box-shadow .2s;
  font-size: .85rem;
  text-align: left;
}
.view-tab.active {
  background: #3b82f6;
  color: #fff;
  border-color: #3b82f6;
  border-width: 2px;
  box-shadow: 0 0 0 2px rgba(236,72,153,.2);
}
.view-tab .view-thumb {
  width: 55px; height: 55px;
  object-fit: contain;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 2px;
}

.product-info { margin-bottom: 2rem; }
.product-info h3 { font-size: 1.2rem; margin-bottom: .5rem; color: #1e293b; }
.product-info p { color: #64748b; margin-bottom: .3rem; }

.action-buttons {
  display: flex; flex-direction: column; gap: 1rem; margin-top: auto;
}
.save-btn,
.price-btn {
  color: #fff; border: none; padding: .75rem; border-radius: 8px; cursor: pointer; font-weight: 600; transition: background .2s;
}
.save-btn { background: #c963c4; }
.save-btn:hover { background: #d97706; }
.price-btn { background: #3b82f6; }
.price-btn:hover { background: #2563eb; }

/* Draggables */
.draggable {
  position: absolute;
  cursor: grab;
  user-select: none;
  border: 2px dashed transparent;
  padding: 4px;
  z-index: 10;

  /* perf */
  will-change: transform;
  backface-visibility: hidden;
  -webkit-user-select: none;
  -moz-user-select: none;
  transform: translate3d(0,0,0);
}
.draggable:hover { border-color: #3b82f6; cursor: grab; }
.draggable:active { cursor: grabbing !important; }
.draggable.selected { border-color: #ef4444; }
.draggable img {
  max-width: 100px; max-height: 100px; pointer-events: none;
  -webkit-user-drag: none; -webkit-user-select: none; -moz-user-select: none; user-select: none;
}
.draggable.text-element { font-weight: 700; border-radius: 4px; }
.draggable,
.draggable:hover,
.draggable.selected { box-shadow: none; transition: border-color .1s ease; }

/* Brand badge in the mockup canvas */
.tshirt-brand-logo {
  position: absolute;
  top: 10px; right: 10px;
  width: clamp(36px, 7vw, 72px);
  height: auto;
  z-index: 50;
  pointer-events: none;
  opacity: .95;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.25));
}
@media (max-width: 480px) {
  .tshirt-brand-logo { width: clamp(28px, 10vw, 48px); top: 8px; right: 8px; }
}

/* Pretty Color Panel (sheet-style overrides when used inside #colorsPanel) */
#colorsPanel {
  --swatch: 28px;
  --swatch-radius: 6px;
  --ring: 2px;
  --ring-color: #1118271a;
  --selected-ring: #0ea5e9;
  --check-bg: #111827;
  --check-color: #fff;
}
#colorsPanel .panel-title {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  font-weight: 600; color: #374151;
  background: linear-gradient(180deg, #f9fafb, #f3f4f6);
  border: 1px solid #e5e7eb; border-radius: 8px;
  padding: .5rem .75rem; margin-bottom: .75rem;
}
#colorsPanel .panel-title small { font-weight: 500; color: #6b7280; }
#colorsPanel .colors-label { font-weight: 600; color: #374151; margin-bottom: .4rem; }
#colorsPanel .color-grid {
  display: grid;
  grid-template-columns: repeat(16, var(--swatch));
  gap: .4rem; justify-content: start;
}
#colorsPanel .color-option {
  width: var(--swatch); height: var(--swatch);
  border-radius: var(--swatch-radius);
  background-size: cover; background-position: center;
  position: relative; border: 0; cursor: pointer; outline: none;
  transition: transform .08s ease, box-shadow .12s ease;
}
#colorsPanel .color-option:hover,
#colorsPanel .color-option:focus-visible {
  box-shadow: 0 0 0 var(--ring) var(--ring-color), inset 0 0 0 1px #d1d5db;
  transform: translateY(-1px);
}
#colorsPanel .color-option.selected {
  box-shadow: 0 0 0 2px #38bdf8, inset 0 0 0 2px var(--selected-ring);
}
#colorsPanel .color-option.selected::after {
  content: '✓';
  position: absolute; right: -3px; bottom: -3px;
  width: 16px; height: 16px; border-radius: 6px;
  background: var(--check-bg); color: var(--check-color);
  font-size: 11px; line-height: 16px; text-align: center;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
@media (max-width: 480px) {
  #colorsPanel { --swatch: 24px; }
  #colorsPanel .color-grid { grid-template-columns: repeat(12, var(--swatch)); gap: .35rem; }
}
@media (max-width: 360px) {
  #colorsPanel { --swatch: 22px; }
  #colorsPanel .color-grid { grid-template-columns: repeat(10, var(--swatch)); gap: .3rem; }
}

/* Visible customization boundary (also used by drag math) */
.customization-boundary {
  border: 2px dashed #3b82f6;
  background-color: rgba(59,130,246,.05);
  pointer-events: none;
  z-index: 5;
  border-radius: 8px;
}

/* Misc */
.curve-control { display: none; }

/* Responsive */
@media (max-width: 1200px) {
  .designer-container { grid-template-columns: 250px 1fr 200px; }
}

@media (max-width: 768px) {
  .designer-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    height: auto;
  }
  .sidebar, .right-panel { order: 2; }
  .design-area { order: 1; min-height: 60vh; }

  .product-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
  }
  .product-card { padding: 1.5rem; }
  #productSelection h1 { font-size: 2rem; }
}

/* Text-element polish */
.draggable.text-element {
  transition: none !important;
  will-change: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Mobile: evenly spaced product colors */
@media (max-width: 768px) {
  /* Flexible tracks that auto-fill the row */
  #colorsPanel .color-grid,
  .color-grid {
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    gap: 8px;
    justify-items: stretch;
  }

  /* Swatches stretch to the track width but stay square */
  #colorsPanel .color-option,
  .color-grid .color-option {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
  }
}

@media (max-width: 480px) {
  #colorsPanel .color-grid,
  .color-grid {
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
    gap: 6px;
  }
}

/* ===== Upload panel (polished) ===== */

.upload-area {
  --up-accent: #D97ED2;          /* brand pink */
  --up-accent-2: #3b82f6;        /* brand blue */
  --up-border: #e5e7eb;
  --up-muted: #6b7280;
  --up-bg: #ffffff;

  position: relative;
  padding: 1.25rem;
  border: 1px solid var(--up-border);
  border-radius: 12px;
  background:
    radial-gradient(1200px 1200px at 100% -20%, rgba(217,126,210,.06), transparent 40%),
    linear-gradient(180deg,#fff,#fbfbff);
  box-shadow: 0 8px 28px rgba(2,6,23,.06);
}

/* The dashed drop zone */
.upload-label {
  display: grid;
  place-items: center;
  gap: .5rem;
  min-height: 160px;
  border-radius: 12px;
  border: 2px dashed rgba(59,130,246,.45);
  background: repeating-linear-gradient(
      45deg,
      rgba(59,130,246,.04) 0 10px,
      rgba(217,126,210,.04) 10px 20px
  );
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease, transform .1s ease;
  text-align: center;
  padding: 1rem;
}

.upload-area.is-dragover .upload-label,
.upload-label:hover {
  border-color: var(--up-accent);
  background-color: rgba(217,126,210,.06);
  transform: translateY(-1px);
}

/* Icon bubble */
.upload-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--up-accent), var(--up-accent-2));
  color: #fff;
  font-size: 1.25rem;
  box-shadow: 0 6px 16px rgba(217,126,210,.35);
}

/* Title + hint */
.upload-title {
  font-weight: 700;
  color: #111827;
  font-size: 1rem;
}
.upload-hint {
  color: var(--up-muted);
  font-size: .85rem;
}

/* Buttons row */
.upload-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: .25rem;
}

.upload-btn,
.upload-btn.secondary {
  appearance: none;
  border: 1px solid var(--up-border);
  border-radius: 10px;
  padding: .55rem .9rem;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  background: #fff;
  transition: transform .08s ease, box-shadow .12s ease, border-color .12s ease;
}
.upload-btn {
  color: #fff;
  background: linear-gradient(135deg, var(--up-accent), var(--up-accent-2));
  border-color: transparent;
  box-shadow: 0 6px 16px rgba(59,130,246,.25);
}
.upload-btn.secondary { color: #374151; background: #f9fafb; }
.upload-btn:hover { transform: translateY(-1px); }
.upload-btn:active { transform: translateY(0); }

/* Accepted types “chips” */
.upload-types {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  justify-content: center;
  margin-top: .5rem;
}
.upload-chip {
  padding: .2rem .5rem;
  font-size: .75rem;
  color: #374151;
  border: 1px solid var(--up-border);
  border-radius: 999px;
  background: #fff;
}

/* File list (after selection) */
.file-list {
  margin-top: .85rem;
  display: grid;
  gap: .5rem;
}
.file-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .5rem .65rem;
  border: 1px solid var(--up-border);
  border-radius: 10px;
  background: #fff;
}
.file-thumb {
  width: 40px; height: 40px; border-radius: 8px;
  background-size: cover; background-position: center;
  box-shadow: inset 0 0 0 1px #e5e7eb;
}
.file-name { flex: 1; font-size: .9rem; color: #111827; }
.file-meta { font-size: .8rem; color: var(--up-muted); }
.file-remove {
  border: 0; background: #f3f4f6; color: #6b7280;
  border-radius: 8px; padding: .3rem .5rem; cursor: pointer;
}
.file-remove:hover { background: #e5e7eb; }

/* Progress bar (optional) */
.upload-progress {
  height: 6px; border-radius: 999px; overflow: hidden;
  background: #eef2f7; margin-top: .5rem;
}
.upload-progress > span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--up-accent), var(--up-accent-2));
  transition: width .2s ease;
}

/* Mobile tweaks */
@media (max-width: 480px) {
  .upload-label { min-height: 140px; padding: .85rem; }
  .upload-actions { gap: .4rem; }
  .upload-btn, .upload-btn.secondary { padding: .5rem .75rem; font-size: .85rem; }
}

/* ===== Image Controls (sheet-style) ===== */
#imageControls{
  --ic-border:#e5e7eb;
  --ic-sep:#eef2f7;
  --ic-bg:#ffffff;
  --ic-chip:#f9fafb;
  --ic-muted:#6b7280;
  --ic-ink:#111827;
  --ic-accent:#3b82f6;
}

/* Header */
#imageControls > h4{
  margin:0 0 .5rem;
  padding:.5rem .75rem;
  text-align:center;
  font-weight:600;
  color:#374151;
  background:linear-gradient(180deg,#fafafa,#f3f4f6);
  border:1px solid var(--ic-border);
  border-radius:8px;
}

/* Card body */
#imageControls .text-controls-grid{
  background:var(--ic-bg);
  border:1px solid var(--ic-border);
  border-radius:10px;
  padding:.25rem;
}

/* Rows */
#imageControls .control-group{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:.75rem;
  padding:.5rem .5rem;
  min-height:44px;
  border-top:1px solid var(--ic-sep);
}
#imageControls .control-group:first-of-type{ border-top:0; }
#imageControls .control-group > label{
  margin:0;
  font-weight:600;
  color:#374151;
}

/* Sliders + value chip */
#imageControls .size-control,
#imageControls .rotation-control{
  display:flex;
  align-items:center;
  gap:.5rem;
  min-width:55%;
  max-width:70%;
}
#imageControls input[type="range"]{
  flex:1;
  height:6px;
  background:#e5e7eb;
  border-radius:3px;
  outline:none;
  -webkit-appearance:none;
}
#imageControls input[type="range"]::-webkit-slider-thumb{
  appearance:none;width:16px;height:16px;border-radius:50%;
  background:var(--ic-accent);cursor:pointer;
}
#imageControls input[type="range"]::-moz-range-thumb{
  width:16px;height:16px;border:none;border-radius:50%;
  background:var(--ic-accent);cursor:pointer;
}
#imageControls #imageSizeDisplay,
#imageControls #imageRotationDisplay{
  min-width:2.75rem;
  text-align:center;
  padding:.25rem .45rem;
  font-size:.8rem;font-weight:700;color:#374151;
  border:1px solid var(--ic-border);
  border-radius:8px;background:var(--ic-chip);
}

/* Flip buttons → segmented control (no markup change) */
#imageControls .effect-buttons{
  display:inline-flex;
  gap:0;
  border:1px solid var(--ic-border);
  border-radius:10px;
  overflow:hidden;
  background:#f3f4f6;
}
#imageControls .effect-buttons .secondary-btn{
  border:0;background:transparent;color:#374151;
  padding:.45rem .7rem;font-weight:600;font-size:.85rem;cursor:pointer;
}
#imageControls .effect-buttons .secondary-btn:hover{ background:#e5e7eb; }
#imageControls .effect-buttons .secondary-btn:focus-visible{
  outline:2px solid var(--ic-accent);outline-offset:-2px;
}
#imageControls .effect-buttons .secondary-btn.active,
#imageControls .effect-buttons .secondary-btn[aria-pressed="true"]{
  background:#fff;color:var(--ic-ink);
  box-shadow:inset 0 -3px 0 0 var(--ic-accent);
}

/* Footer action */
#imageControls .text-editor-actions{
  display:flex;justify-content:flex-end;
  padding:.5rem .5rem .55rem;
  border-top:1px dashed var(--ic-sep);
  margin:.25rem .25rem 0;
}
#imageControls #duplicateImage.secondary-btn{
  background:#f9fafb;border:1px solid var(--ic-border);
  color:#374151;border-radius:10px;padding:.5rem .75rem;font-weight:600;
}
#imageControls #duplicateImage.secondary-btn:hover{
  background:#eef2f7;
}

/* Mobile tweaks */
@media (max-width:480px){
  #imageControls .control-group{ padding:.45rem .45rem; min-height:40px; }
  #imageControls .size-control, #imageControls .rotation-control{ max-width:68%; }
  #imageControls .effect-buttons .secondary-btn{ padding:.4rem .6rem; font-size:.8rem; }
  #imageControls #duplicateImage.secondary-btn{ font-size:.85rem; padding:.45rem .65rem; }
}

/* Panel close button */
.panel { position: relative; }

.panel .panel-close{
  position: absolute;
  top: .5rem;
  right: .5rem;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  color: #111827;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  transition: background .15s ease, transform .06s ease, box-shadow .15s ease;
}

.panel .panel-close:hover{
  background:#f3f4f6;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}

.panel .panel-close:active{
  transform: translateY(1px);
}

@media (max-width:480px){
  .panel .panel-close{ width:26px; height:26px; font-size:16px; }
}
