:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --ai-start: #4f46e5;
  --ai-end: #7c3aed;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #ef4444;
  --success: #16a34a;
}

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

body {
  font-family: 'Prompt', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.is-hidden {
  display: none !important;
}

/* Header */
header {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 18px;
}

.brand h1 {
  font-size: 15px;
  font-weight: 700;
}

.brand p {
  font-size: 11px;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 10px;
}

/* Buttons */
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}

.btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-ai {
  width: 100%;
  background: linear-gradient(135deg, var(--ai-start), var(--ai-end));
  color: #fff;
  border: none;
  padding: 10px 14px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.btn-ai:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.btn-ai:disabled {
  opacity: 0.7;
  cursor: wait;
}

.btn-clear {
  border: none;
  background: none;
  color: var(--danger);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
}

.btn-clear:hover {
  text-decoration: underline;
}

.btn-mini-reset {
  border: 1px solid #c7d2fe;
  background: #fff;
  color: #4f46e5;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  cursor: pointer;
}

.btn-mini-reset:hover {
  background: #eef2ff;
}

/* Spinner */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Main Workspace */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* 3D Viewport */
.viewport {
  flex: 1;
  position: relative;
  background: radial-gradient(circle at 50% 42%, #ffffff 0%, #e7edf5 70%, #d8e1ec 100%);
  overflow: hidden;
  user-select: none;
}

#canvas-container {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}

/* Interactive On-Shirt Transform Gizmo */
.decal-gizmo {
  position: absolute;
  top: 0;
  left: 0;
  border: 2px dashed rgba(37, 99, 235, 0.92);
  border-radius: 6px;
  background: rgba(37, 99, 235, 0.05);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.75);
  transform-origin: center center;
  z-index: 4;
  touch-action: none;
  will-change: transform, width, height, left, top;
}

.decal-gizmo.transforming {
  border-style: solid;
  background: rgba(37, 99, 235, 0.1);
}

.gizmo-move-area {
  position: absolute;
  inset: 0;
  cursor: move;
  touch-action: none;
}

.gizmo-handle {
  position: absolute;
  z-index: 2;
  touch-action: none;
  transition: transform 0.12s ease, background 0.12s ease;
}

.gizmo-corner {
  width: 14px;
  height: 14px;
  background: #ffffff;
  border: 2.5px solid var(--primary);
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.25);
}

.gizmo-corner:hover {
  background: var(--primary);
  transform: translate(-50%, -50%) scale(1.2);
}

.gizmo-corner.nw { top: 0; left: 0; transform: translate(-50%, -50%); cursor: nwse-resize; }
.gizmo-corner.ne { top: 0; left: 100%; transform: translate(-50%, -50%); cursor: nesw-resize; }
.gizmo-corner.sw { top: 100%; left: 0; transform: translate(-50%, -50%); cursor: nesw-resize; }
.gizmo-corner.se { top: 100%; left: 100%; transform: translate(-50%, -50%); cursor: nwse-resize; }

.gizmo-rotate-stem {
  position: absolute;
  left: 50%;
  top: -26px;
  width: 2px;
  height: 26px;
  background: var(--primary);
  transform: translateX(-50%);
  pointer-events: none;
}

.gizmo-rotate {
  left: 50%;
  top: -40px;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  background: var(--primary);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: grab;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.38);
}

.gizmo-rotate:hover {
  background: var(--primary-hover);
  transform: translate(-50%, -50%) scale(1.12);
}

.gizmo-rotate:active {
  cursor: grabbing;
}

.gizmo-delete {
  right: -12px;
  top: -12px;
  transform: translate(50%, -50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  background: var(--danger);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.35);
}

.gizmo-delete:hover {
  transform: translate(50%, -50%) scale(1.15);
}

.gizmo-readout {
  position: absolute;
  left: 50%;
  bottom: -32px;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  color: #ffffff;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
}

/* Dropzone Overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(241, 245, 249, 0.82);
  backdrop-filter: blur(4px);
  padding: 20px;
  transition: opacity 0.2s ease;
}

.drop-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.drop-card {
  max-width: 440px;
  width: 100%;
  background: #fff;
  border: 2px dashed #93c5fd;
  border-radius: 18px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
  transition: border-color 0.15s, background 0.15s;
}

.drop-card.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}

.drop-icon {
  font-size: 44px;
  margin-bottom: 10px;
}

.drop-card h2 {
  font-size: 17px;
  margin-bottom: 6px;
}

.drop-card p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 18px;
}

/* Floating Pills */
.pill {
  position: absolute;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  border-radius: 999px;
  font-size: 12px;
  color: #334155;
  z-index: 6;
  padding: 7px 14px;
}

.hint-pill {
  top: 16px;
  left: 16px;
  pointer-events: none;
}

.cam-pill {
  top: 16px;
  right: 16px;
  display: flex;
  gap: 4px;
  padding: 4px;
}

.cam-btn {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: #475569;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.cam-btn:hover {
  background: #f1f5f9;
}

.cam-btn.active {
  background: #0f172a;
  color: #fff;
}

.mode-pill {
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 5px;
  white-space: nowrap;
}

.mode-btn {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  padding: 6px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mode-btn:hover {
  background: #f1f5f9;
}

.mode-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Sidebar */
aside {
  width: 420px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title.no-mb {
  margin-bottom: 0;
}

/* AI Refinement Card */
.ai-card {
  background: linear-gradient(180deg, #f5f3ff 0%, #eff6ff 100%);
  border: 1px solid #c7d2fe;
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-title {
  color: #3730a3;
}

.ai-head-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e0e7ff;
  color: #4338ca;
}

.ai-history {
  max-height: 110px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid #e0e7ff;
  border-radius: 10px;
  font-size: 11.5px;
}

.msg-row {
  line-height: 1.4;
  padding: 4px 8px;
  border-radius: 8px;
}

.msg-user {
  background: #eef2ff;
  color: #312e81;
  align-self: flex-end;
  max-width: 92%;
}

.msg-ai {
  background: #ffffff;
  color: #334155;
  border: 1px solid #e2e8f0;
  align-self: flex-start;
  max-width: 94%;
}

.ai-card textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #c7d2fe;
  border-radius: 10px;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
  background: #ffffff;
  color: var(--text);
}

.ai-card textarea:focus {
  outline: none;
  border-color: var(--ai-start);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-btn {
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid #c7d2fe;
  background: #ffffff;
  color: #4338ca;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.chip-btn:hover {
  background: #eef2ff;
  border-color: var(--ai-start);
}

.ai-checkbox {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: #334155;
  cursor: pointer;
}

.ai-checkbox input {
  accent-color: var(--ai-start);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.ai-result {
  background: #ffffff;
  border: 1px solid #ddd6fe;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.55;
  color: #334155;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-result-title {
  font-weight: 700;
  color: #4f46e5;
}

.prod-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.prod-pill {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
}

.prod-lbl {
  font-size: 10px;
  color: var(--muted);
}

.prod-pill strong {
  font-size: 12px;
  color: var(--text);
}

.prod-note {
  font-size: 11.5px;
  color: #047857;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 6px 9px;
  border-radius: 8px;
}

.followup-wrap {
  border-top: 1px dashed #e2e8f0;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.followup-title {
  font-size: 11px;
  font-weight: 600;
  color: #6d28d9;
}

/* Swatches & Fabric */
.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}

.swatch:hover {
  transform: scale(1.08);
}

.swatch.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.22);
}

.fabric-row {
  margin-top: 12px;
}

/* Form Card */
.card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

label.field {
  display: block;
  font-size: 12px;
  color: #475569;
  margin-bottom: 4px;
  font-weight: 500;
}

input[type="text"],
select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}

.color-full {
  width: 100%;
  height: 36px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 2px;
  background: #fff;
  cursor: pointer;
}

.color-compact {
  width: 40px;
  height: 32px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 2px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.slider-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #475569;
  margin-bottom: 2px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Tabs */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 8px;
  gap: 3px;
}

.tabs.tabs-3 {
  grid-template-columns: repeat(3, 1fr);
}

.tabs button {
  border: none;
  background: transparent;
  padding: 6px 4px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  color: #475569;
  white-space: nowrap;
}

.tabs button.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* 30 Lines & Patterns Library */
.pattern-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.cat-btn {
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.cat-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.cat-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.pattern-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  max-height: 225px;
  overflow-y: auto;
  padding: 6px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.pattern-card {
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  padding: 5px 4px 4px;
  background: #f8fafc;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: border-color 0.12s, transform 0.12s, background 0.12s;
}

.pattern-card:hover {
  border-color: #93c5fd;
  transform: translateY(-1px);
}

.pattern-card.active {
  border-color: var(--primary);
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

.pattern-thumb {
  width: 100%;
  height: 42px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  padding: 4px;
  background-color: #e2e8f0;
  background-image:
    linear-gradient(45deg, #cbd5e1 25%, transparent 25%),
    linear-gradient(-45deg, #cbd5e1 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #cbd5e1 75%),
    linear-gradient(-45deg, transparent 75%, #cbd5e1 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}

.pattern-thumb svg {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.pattern-name {
  font-size: 9.5px;
  color: #334155;
  text-align: center;
  line-height: 1.2;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pattern-selected-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: #334155;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 6px 9px;
}

.pattern-tip {
  font-size: 10px;
  color: var(--primary);
  font-weight: 500;
}

.pattern-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
  cursor: pointer;
  transition: transform 0.12s;
}

.mini-swatch:hover {
  transform: scale(1.1);
}

.mini-swatch.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.logo-status {
  font-size: 11px;
  color: var(--muted);
}

.logo-status.ready {
  color: var(--success);
  font-weight: 500;
}

/* Decal List */
.decal-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.decal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.decal-item.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.decal-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(15, 23, 42, 0.25);
  flex-shrink: 0;
}

.zone-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 5px;
  background: #f1f5f9;
  color: #475569;
  flex-shrink: 0;
}

.decal-del {
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-weight: 700;
  padding: 2px 6px;
}

.empty-state {
  font-size: 12px;
  color: #94a3b8;
}

.info-box {
  font-size: 12px;
  color: #1e40af;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 10px 12px;
  border-radius: 10px;
  line-height: 1.5;
}

/* Responsive */
@media (max-width: 900px) {
  body {
    height: auto;
    overflow: auto;
  }

  .workspace {
    flex-direction: column;
  }

  .viewport {
    height: 60vh;
    min-height: 380px;
  }

  .hint-pill {
    display: none;
  }

  aside {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}