/* ========================================
   Custom Cup Prints — Product Customizer
   ======================================== */

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

:root {
  --blue: #00B6F1;
  --blue-hover: #00a3d9;
  --navy: #003459;
  --header-bg: #EAF0F6;
  --page-bg: #FCFBF5;
  --green: #46523E;
  --green-hover: #3a4533;
  --gold: #DFD493;
  --gray-100: #f7f7f5;
  --gray-200: #ececea;
  --gray-300: #ddddd9;
  --gray-400: #b0b0aa;
  --gray-500: #888883;
  --danger: #d9534f;
  --font-heading: 'Ovo', serif;
  --font-body: 'Instrument Sans', sans-serif;
  --sidebar-w: 280px;
  --viewpanel-w: 120px;
  --toolbar-h: 52px;
  --bottombar-h: 60px;
  --radius: 4px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--navy);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
}

/* ========== TOP TOOLBAR ========== */
.top-toolbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: var(--viewpanel-w);
  height: var(--toolbar-h);
  background: var(--header-bg);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  z-index: 100;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.top-toolbar.hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

.toolbar-inner {
  width: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.toolbar-label {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  white-space: nowrap;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  color: var(--navy);
  transition: background 0.15s;
}

.toolbar-btn:hover {
  background: rgba(0, 52, 89, 0.08);
}

.toolbar-btn--danger {
  color: var(--danger);
}

.toolbar-btn--danger:hover {
  background: rgba(217, 83, 79, 0.1);
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--gray-300);
  margin: 0 6px;
}

/* ========== MAIN LAYOUT ========== */
.app-layout {
  display: flex;
  height: calc(100vh - var(--bottombar-h));
}

/* ========== SIDEBAR ========== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
}

.brand-logo {
  font-family: var(--font-heading);
  font-size: 20px;
  color: var(--navy);
  font-weight: 400;
}

/* Tab Navigation */
.tab-nav {
  display: flex;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-100);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  color: var(--gray-500);
  transition: color 0.15s, background 0.15s;
  border-bottom: 2px solid transparent;
}

.tab-btn:hover {
  color: var(--navy);
  background: rgba(0, 182, 241, 0.04);
}

.tab-btn.active {
  color: var(--blue);
  background: #fff;
  border-bottom-color: var(--blue);
}

.tab-btn svg {
  opacity: 0.6;
}

.tab-btn.active svg {
  opacity: 1;
}

/* Tab Panels */
.tab-panels {
  flex: 1;
  overflow-y: auto;
}

.tab-panel {
  display: none;
  padding: 16px 20px;
}

.tab-panel.active {
  display: block;
}

/* Drop Zone */
.drop-zone {
  border: 2px dashed var(--gray-300);
  border-radius: 8px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--blue);
  background: rgba(0, 182, 241, 0.04);
}

.drop-zone-text {
  font-size: 13px;
  color: var(--navy);
  margin-top: 10px;
  font-weight: 500;
}

.drop-zone-sub {
  font-size: 12px;
  color: var(--gray-400);
  margin: 6px 0 10px;
}

/* Upload Options */
.upload-options {
  margin-top: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--gray-200);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.toggle-label {
  font-weight: 600;
  font-size: 13px;
}

.toggle-switch {
  display: inline-block;
}

.toggle-track {
  width: 40px;
  height: 22px;
  background: var(--gray-300);
  border-radius: 11px;
  position: relative;
  transition: background 0.2s;
}

.toggle-track .toggle-thumb {
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle-switch.active .toggle-track {
  background: var(--blue);
}

.toggle-switch.active .toggle-thumb {
  transform: translateX(18px);
}

.help-text {
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 6px;
  line-height: 1.4;
}

/* Uploaded Images */
.uploaded-images {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--gray-200);
}

.section-label {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin-bottom: 10px;
}

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

.thumb-item {
  aspect-ratio: 1;
  border: 2px solid var(--gray-200);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
  position: relative;
}

.thumb-item:hover {
  border-color: var(--blue);
}

.thumb-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
}

.thumb-item:hover .thumb-delete {
  opacity: 1;
}

/* Always show on touch devices */
@media (hover: none) {
  .thumb-delete {
    opacity: 1;
  }
}

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

/* Format Buttons */
.format-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.format-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  background: #fff;
  color: var(--navy);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 14px;
  transition: all 0.15s;
}

.format-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.format-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.format-divider {
  width: 1px;
  height: 22px;
  background: var(--gray-300);
  margin: 0 4px;
}

.curve-controls {
  padding: 10px 12px;
  background: var(--gray-100);
  border-radius: 6px;
}

/* Form Controls */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 6px;
}

.form-input,
.form-select {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--navy);
  background: #fff;
  transition: border-color 0.15s;
  outline: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--blue);
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888883' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

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

.form-color {
  width: 36px;
  height: 36px;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
}

.form-color::-webkit-color-swatch-wrapper {
  padding: 0;
}

.form-color::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

.color-hex {
  font-size: 12px;
  font-family: monospace;
  color: var(--gray-500);
}

.form-range {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  background: var(--gray-200);
  border-radius: 2px;
  outline: none;
}

.form-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--blue);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Coming Soon */
.coming-soon {
  text-align: center;
  padding: 40px 10px;
}

.coming-soon h3 {
  font-family: var(--font-heading);
  font-size: 16px;
  margin-top: 12px;
  color: var(--navy);
}

.coming-soon p {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 6px;
  line-height: 1.5;
}

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  width: 100%;
  justify-content: center;
}

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

.btn-upload {
  width: auto;
  padding: 7px 20px;
  font-size: 12px;
}

.btn-outline {
  background: #fff;
  color: var(--navy);
  border-color: var(--gray-300);
}

.btn-outline:hover {
  border-color: var(--navy);
  background: var(--gray-100);
}

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

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

/* ========== EDITOR MAIN ========== */
.editor-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: var(--page-bg);
}

.cup-container {
  position: relative;
  display: inline-block;
}

.cup-image {
  display: block;
  height: calc(100vh - var(--bottombar-h) - 60px);
  max-height: 660px;
  width: auto;
  filter: drop-shadow(0 8px 24px rgba(0, 52, 89, 0.12)) drop-shadow(0 2px 8px rgba(0,0,0,0.06));
  user-select: none;
  -webkit-user-drag: none;
}

.canvas-wrapper {
  position: absolute;
  /* These get set by JS based on cup image dimensions */
  border: 1.5px dashed rgba(0, 182, 241, 0.18);
  border-radius: 3px;
  overflow: hidden;
  transition: border-color 0.25s;
}

.canvas-wrapper:hover {
  border-color: rgba(0, 182, 241, 0.45);
}

.canvas-wrapper canvas {
  display: block;
}

/* ========== VIEW PANEL (RIGHT) ========== */
.view-panel {
  width: var(--viewpanel-w);
  min-width: var(--viewpanel-w);
  background: #fff;
  border-left: 1px solid var(--gray-200);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.view-panel-title {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
}

.view-thumbs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.view-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border: 2px solid var(--gray-200);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s;
}

.view-thumb:hover {
  border-color: var(--blue);
}

.view-thumb.active {
  border-color: var(--blue);
  background: rgba(0, 182, 241, 0.04);
}

.view-thumb img {
  width: 60px;
  height: 75px;
  object-fit: contain;
}

.view-thumb span {
  font-size: 10px;
  font-weight: 600;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.view-thumb-placeholder {
  width: 60px;
  height: 75px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  border-radius: 4px;
  color: var(--gray-400);
}

.undo-redo-controls {
  display: flex;
  gap: 6px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--gray-200);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
  color: var(--navy);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover:not(:disabled) {
  background: var(--gray-100);
  border-color: var(--gray-300);
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ========== BOTTOM BAR ========== */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottombar-h);
  background: #fff;
  border-top: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

.bottom-bar-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.product-name {
  font-family: var(--font-heading);
  font-size: 18px;
  color: var(--navy);
  font-weight: 400;
}

.product-meta {
  font-size: 12px;
  color: var(--gray-500);
}

.bottom-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ========== SCROLLBAR ========== */
.tab-panels::-webkit-scrollbar {
  width: 4px;
}

.tab-panels::-webkit-scrollbar-track {
  background: transparent;
}

.tab-panels::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 2px;
}

/* ========== 3D PREVIEW ========== */
.three-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page-bg);
  z-index: 10;
}

.three-container canvas {
  width: 100% !important;
  height: 100% !important;
  cursor: grab;
}

.three-container canvas:active {
  cursor: grabbing;
}

/* 3D View Thumb Icon */
.view-thumb-icon {
  width: 60px;
  height: 75px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
}

.view-thumb.active .view-thumb-icon {
  background: rgba(0, 182, 241, 0.1);
  color: var(--blue);
}

/* ========== FABRIC.JS OVERRIDES ========== */
.canvas-container {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
}

/* ========== 3D PAUSE BUTTON ========== */
.three-pause-btn {
  position: absolute;
  bottom: 16px;
  left: 16px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--gray-300);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  color: var(--navy);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  z-index: 10;
}

.three-pause-btn:hover {
  background: #fff;
  border-color: var(--blue);
  color: var(--blue);
}

/* ========== 3D ZOOM CONTROLS ========== */
.three-zoom-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}

.three-ctrl-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--gray-300);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  color: var(--navy);
  cursor: pointer;
  font-size: 20px;
  font-weight: 600;
  font-family: var(--font-body);
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}

.three-ctrl-btn:hover {
  background: #fff;
  border-color: var(--blue);
  color: var(--blue);
}

.three-ctrl-btn:active {
  transform: scale(0.93);
}

/* ========== MOBILE VIEW TOGGLE (hidden on desktop) ========== */
.mobile-view-toggle {
  display: none;
  width: 100%;
  background: #fff;
  border-top: 1px solid var(--gray-200);
  border-bottom: 1px solid var(--gray-200);
  padding: 6px 12px;
  gap: 8px;
}

.mobile-view-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  transition: all 0.15s;
}

.mobile-view-btn.active {
  background: rgba(0, 182, 241, 0.06);
  border-color: var(--blue);
  color: var(--blue);
}

/* ========== RESPONSIVE — MOBILE ========== */
@media (max-width: 768px) {
  /* Stack layout vertically */
  .app-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - var(--bottombar-h));
  }

  /* Hide the right view panel — we'll use inline toggle */
  .view-panel {
    display: none;
  }

  /* Sidebar becomes bottom panel */
  .sidebar {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-top: 1px solid var(--gray-200);
    order: 3;
    max-height: 40vh;
    overflow-y: auto;
  }

  .tab-panels {
    max-height: calc(40vh - 50px);
    overflow-y: auto;
  }

  .sidebar-header {
    display: none; /* Hide brand logo in sidebar on mobile */
  }

  /* Editor area takes full width */
  .editor-main {
    width: 100%;
    min-height: 350px;
    max-height: 50vh;
    order: 1;
  }

  /* Nudge the cup container right to visually center it */
  .cup-container {
    margin-left: 28px;
  }

  /* Cup image sizing for mobile */
  .cup-image {
    height: auto;
    max-height: 45vh;
    width: auto;
    max-width: 90%;
  }

  /* Three.js container */
  .three-container {
    min-height: 350px;
    max-height: 50vh;
  }

  /* Add mobile view toggle bar between cup and tools */
  .mobile-view-toggle {
    display: flex;
    order: 2;
  }

  /* Bottom bar adjustments */
  .bottom-bar {
    padding: 0 12px;
  }

  .product-name {
    font-size: 14px;
  }

  .product-meta {
    display: none;
  }

  .btn {
    padding: 7px 12px;
    font-size: 12px;
  }

  /* Canvas wrapper needs to scale with the cup */
  /* The JS already handles this via getCanvasDimensions() */

  /* Tab buttons smaller */
  .tab-btn {
    padding: 8px 4px 6px;
    font-size: 10px;
  }

  /* Drop zone compact */
  .drop-zone {
    padding: 16px 12px;
  }

  /* Form controls compact */
  .form-group {
    margin-bottom: 10px;
  }

  /* Scrollbar for sidebar */
  html, body {
    overflow: auto;
  }

  /* Top toolbar: full width, positioned above the cup */
  .top-toolbar {
    left: 0;
    right: 0;
    height: auto;
    min-height: var(--toolbar-h);
    flex-wrap: wrap;
    padding: 6px 12px;
  }

  .toolbar-inner {
    flex-wrap: wrap;
    gap: 8px;
    padding: 0;
  }

  .toolbar-label {
    width: 100%;
    margin-bottom: 2px;
  }

  .toolbar-actions {
    flex-wrap: wrap;
    gap: 2px;
  }

  .toolbar-btn {
    padding: 8px 10px;
    font-size: 11px;
  }

  .toolbar-divider {
    display: none;
  }
}
