/* ==========================================================================
   CSS SYSTEM: MONOSTYLE. Virtual Fitting Room (Minimalist B&W)
   ========================================================================== */

/* Variables and Reset */
:root {
  --font-main: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  
  /* Color Palette (Clean Minimalist Black & White) */
  --bg-primary: #ffffff;
  --bg-secondary: #fafafa;
  --bg-tertiary: #f2f2f2;
  --border-light: #e5e5e5;
  --border-dark: #000000;
  
  --text-main: #000000;
  --text-muted: #767676;
  --text-light: #aeaeae;
  
  --danger: #d93838;
  --danger-light: #fdf2f2;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  overflow: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--text-light);
  border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-main);
}

/* Main Layout Structure */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* SIDEBAR: Left Panel */
.sidebar {
  width: 360px;
  border-right: 1px solid var(--border-light);
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  z-index: 10;
}

.sidebar-brand {
  padding: 30px 24px 20px 24px;
}

.brand-logo-img {
  max-width: 140px;
  height: auto;
  display: block;
  margin-bottom: 8px;
}

.sidebar-brand h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-main);
  text-transform: uppercase;
}

.sidebar-brand p {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Google Sheets Configuration */
.sheets-config {
  padding: 0 24px 20px 24px;
  border-bottom: 1px solid var(--border-light);
}

.config-toggle-btn {
  background: none;
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 8px 12px;
  font-size: 12px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.config-toggle-btn:hover {
  border-color: var(--border-dark);
}

.config-toggle-btn i {
  width: 14px;
  height: 14px;
}

.config-content {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
}

.config-help {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 10px;
}

.input-group {
  display: flex;
  gap: 8px;
}

.input-group input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  font-size: 11px;
  outline: none;
}

.input-group input:focus {
  border-color: var(--border-dark);
}

.sheets-status-msg {
  font-size: 11px;
  margin-top: 8px;
  font-weight: 500;
}

.sheets-status-msg.success {
  color: #2e7d32;
}

.sheets-status-msg.error {
  color: var(--danger);
}

/* Categories Navigation */
.categories {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border-light);
}

.category-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-right: 1px solid var(--border-light);
  padding: 12px 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.category-btn:nth-child(3n) {
  border-right: none;
}

.category-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-secondary);
}

.category-btn.active {
  color: var(--text-main);
  border-bottom-color: var(--border-dark);
  background-color: var(--bg-primary);
}

/* Product List Container */
.product-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  position: relative;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

/* Product Card */
.product-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  padding: 10px;
  display: flex;
  flex-direction: column;
  position: relative;
  cursor: grab;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  user-select: none;
}

.product-card:hover {
  border-color: var(--border-dark);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.product-card:active {
  cursor: grabbing;
}

.product-card-img-box {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg-secondary);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  margin-bottom: 10px;
}

.product-card-img-box img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  pointer-events: none;
  transition: transform 0.3s ease;
}

.product-card:hover .product-card-img-box img {
  transform: scale(1.05);
}

.product-card-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.product-card-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

.product-card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.btn-card-link {
  font-size: 10px;
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-card-link:hover {
  color: var(--text-main);
  text-decoration: underline;
}

.btn-card-link i {
  width: 12px;
  height: 12px;
}

.btn-card-add {
  background: var(--border-dark);
  color: var(--bg-primary);
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.btn-card-add:hover {
  transform: scale(1.1);
}

.btn-card-add i {
  width: 12px;
  height: 12px;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-light);
  background: var(--bg-secondary);
}

.info-text {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.4;
  display: block;
}

/* Loading Spinner */
.loading-spinner {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 5;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-light);
  border-top-color: var(--border-dark);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* CANVAS SECTION: Right Panel */
.canvas-section {
  flex: 1;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.canvas-container {
  width: 100%;
  height: 100%;
  max-width: 580px;
  max-height: 760px;
  aspect-ratio: 3/4;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

/* Canvas Placeholder */
.canvas-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  max-width: 80%;
  z-index: 5;
}

.user-big-icon {
  width: 48px;
  height: 48px;
  color: var(--text-light);
  margin-bottom: 20px;
}

.canvas-placeholder h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
}

.canvas-placeholder p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 24px;
}

/* Interactive Workspace */
.fitting-workspace {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #ffffff;
}

#body-bg-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.clothes-overlay {
  position: absolute;
  pointer-events: none; /* Let clicks pass through overlay container */
}

/* Placed Clothing Item on Canvas */
.placed-item {
  position: absolute;
  cursor: move;
  pointer-events: auto; /* Re-enable clicks for items */
  display: flex;
  align-items: center;
  justify-content: center;
  transition: outline 0.1s ease;
}

.placed-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* Dash border for active selected item */
.placed-item.active {
  outline: 1.5px dashed var(--border-dark);
}

/* Canvas Action Buttons */
.canvas-actions {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 10;
}

.btn-canvas-action {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.btn-canvas-action:hover {
  border-color: var(--border-dark);
  transform: translateY(-1px);
}

.btn-canvas-action i {
  width: 14px;
  height: 14px;
}

.btn-black-canvas {
  background: var(--border-dark);
  color: var(--bg-primary);
  border-color: var(--border-dark);
}

.btn-black-canvas:hover {
  background: #222222;
  border-color: #222222;
}



/* Helper Button Classes */
.btn-black {
  background: var(--border-dark);
  color: var(--bg-primary);
  border: 1px solid var(--border-dark);
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-black:hover {
  background: #222222;
  border-color: #222222;
}

.btn-black i {
  width: 14px;
  height: 14px;
}

.btn-small {
  padding: 8px 12px;
  font-size: 11px;
}

.btn-upload {
  padding: 12px 24px;
  font-size: 13px;
}



/* Dash border for active selected item */
.placed-item.active {
  outline: 1.5px dashed var(--border-dark);
}

/* Controls Sidebar Panel (Right Column) */
.controls-sidebar {
  width: 320px;
  border-left: 1px solid var(--border-light);
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  z-index: 10;
}

.control-box-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.control-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 10px;
  color: var(--text-muted);
  height: 100%;
}

.control-empty i {
  width: 32px;
  height: 32px;
  margin-bottom: 16px;
  color: var(--text-light);
}

.control-empty p {
  font-size: 12px;
  line-height: 1.6;
}

.controls-form {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.control-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 16px;
}

.info-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.info-value {
  font-size: 14px;
  font-weight: 700;
}

.controls-footer-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
  border-top: 1px solid var(--border-light);
  padding-top: 24px;
}

.btn-danger-minimal {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-danger-minimal:hover {
  background: var(--danger-light);
}

.btn-danger-minimal i {
  width: 14px;
  height: 14px;
}

/* AI Style Recommendation Panel */
.ai-recommendation-box {
  margin-top: 30px;
  border-top: 1px solid var(--border-light);
  padding-top: 24px;
}

.ai-box-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.ai-box-header h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ai-sparkles-icon {
  width: 16px;
  height: 16px;
  color: var(--text-main);
}

.ai-help-text {
  font-size: 11px;
  color: var(--text-light);
  line-height: 1.5;
  text-align: center;
  padding: 10px 0;
  border: 1px dashed var(--border-light);
  background: var(--bg-secondary);
}

.ai-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 12px;
}

.ai-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.spinner-small {
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border-light);
  border-top-color: var(--border-dark);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.ai-result {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  animation: fade-in 0.2s ease;
}

.ai-advice h4, .ai-items-list h4 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 700;
}

.ai-advice p {
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-main);
}

.ai-items-grid {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.ai-item-mini-card {
  width: 60px;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.ai-item-mini-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

.ai-item-mini-card span {
  font-size: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-align: center;
  margin-top: 4px;
  font-weight: 600;
}

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

/* Utilities */
.hidden {
  display: none !important;
}

/* Close drawer button & Header flex (Default/Desktop) */
.controls-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.btn-close-drawer {
  display: none; /* Hidden on desktop */
  background: none;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 4px;
}

.btn-close-drawer i {
  width: 20px;
  height: 20px;
}

.btn-sparkle-action {
  display: none !important; /* Hidden on desktop, AI box is already visible on the right */
  background: #000000;
  color: #ffffff;
  border-color: #000000;
}

.btn-sparkle-action i {
  color: #ffffff;
  animation: pulse-sparkle 2s infinite;
}

@keyframes pulse-sparkle {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.8; }
  100% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   RESPONSIVE LAYOUT (SMARTPHONES)
   ========================================================================== */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    position: relative;
  }

  /* 1. Brand Logo Header at Top */
  .sidebar-brand {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    padding: 10px 16px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
    box-shadow: var(--shadow-sm);
  }

  .sidebar-brand p {
    display: inline-block;
    margin-top: 0;
    margin-left: 10px;
    font-size: 10px;
  }

  .brand-logo-img {
    max-width: 80px !important;
    margin-bottom: 0 !important;
  }

  /* Hide config button on mobile brand or position it */
  .sheets-config {
    position: fixed;
    top: 60px;
    left: 0;
    width: 100%;
    background: var(--bg-primary);
    z-index: 99;
    border-bottom: 1px solid var(--border-light);
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
  }

  /* 2. Middle Fitting Workspace Canvas */
  .canvas-section {
    order: 1;
    flex: 1;
    padding: 12px;
    margin-top: 60px; /* space for brand logo header */
    margin-bottom: 0px;
    height: calc(100vh - 300px); /* Fill space above bottom catalog */
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  .canvas-container {
    width: 100%;
    height: 100%;
    max-height: 100%;
    aspect-ratio: auto;
  }

  /* Floating action canvas buttons - wrap layout to prevent overflow */
  .canvas-actions {
    bottom: 12px;
    width: 95%;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }

  .btn-canvas-action {
    padding: 8px 12px;
    font-size: 10px;
  }

  .btn-sparkle-action {
    display: flex !important; /* Visible on mobile */
  }

  /* 3. Bottom Wardrobe Catalog */
  .sidebar {
    order: 2;
    width: 100%;
    height: 240px;
    border-right: none;
    border-top: 1px solid var(--border-light);
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    z-index: 90;
  }

  /* Horizontal scrolling for Categories */
  .categories {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    white-space: nowrap;
    width: 100%;
    border-bottom: 1px solid var(--border-light);
    scrollbar-width: none; /* Firefox */
  }
  .categories::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
  }

  .category-btn {
    flex: 1 0 auto;
    padding: 10px 16px;
    border-right: 1px solid var(--border-light);
    border-bottom: none;
    font-size: 11px;
  }

  .category-btn.active {
    border-bottom: 2px solid var(--border-dark);
  }

  /* Horizontal scrolling for Product Catalog List */
  .product-list-container {
    padding: 12px 16px;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    align-items: center;
  }

  .product-grid {
    display: flex;
    flex-direction: row;
    gap: 12px;
    width: max-content;
    height: 100%;
  }

  .product-card {
    width: 120px;
    height: 160px;
    padding: 8px;
    flex-shrink: 0;
  }

  .product-card-img-box {
    margin-bottom: 6px;
    height: 90px;
  }

  .product-card-name {
    font-size: 11px;
  }

  .product-card-actions {
    margin-top: 4px;
  }

  .btn-card-link {
    font-size: 9px;
  }

  .btn-card-add {
    width: 18px;
    height: 18px;
  }

  /* Hide footer on mobile catalog to save space */
  .sidebar-footer {
    display: none;
  }

  /* 4. Controls & AI: Slide-up bottom drawer on mobile */
  .controls-sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 380px;
    border-left: none;
    border-top: 1px solid var(--border-light);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    transition: transform 0.35s cubic-bezier(0.15, 0.85, 0.3, 1);
    transform: translateY(100%); /* hidden off-screen */
  }

  .controls-sidebar.open {
    transform: translateY(0); /* slide up into view */
  }

  /* Handle decoration for the drawer on mobile */
  .controls-sidebar::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    margin: 8px auto 0 auto;
  }

  .controls-sidebar .sidebar-brand {
    position: static;
    height: auto;
    padding: 8px 20px;
    border-bottom: none;
    box-shadow: none;
    display: block;
  }

  .btn-close-drawer {
    display: flex; /* Show on mobile */
  }

  .control-box-content {
    padding: 12px 20px 24px 20px;
    height: calc(100% - 60px);
    overflow-y: auto;
  }

  /* Stack layout in drawer controls */
  .controls-form {
    gap: 16px;
  }

  .control-row {
    margin-bottom: 0;
  }
}
