/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg-deep: #080e1c;
  --bg-primary: #0c1529;
  --bg-secondary: #101b36;
  --bg-card: #152044;
  --bg-hover: #1a2a52;
  --border: #1e3260;
  --border-light: #233b6e;
  --text-primary: #e0e6f2;
  --text-secondary: #8899bb;
  --text-muted: #5a6d8a;
  --accent: #2b8cf0;
  --accent-hover: #3d9df5;
  --accent-glow: rgba(43,140,240,0.25);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --header-h: 56px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  display: flex; flex-direction: column;
}

/* ===== Header ===== */
.header {
  height: var(--header-h);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; flex-shrink: 0; z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 24px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text-primary); }
.logo img { height: 32px; width: auto; border-radius: 4px; }
.nav-links { display: flex; gap: 4px; }
.nav-link {
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: 14px;
  color: var(--text-secondary); cursor: pointer; transition: all 0.2s; text-decoration: none;
}
.nav-link:hover { color: var(--text-primary); background: var(--bg-hover); }
.nav-link.active { color: var(--accent); background: rgba(43,140,240,0.1); font-weight: 600; }

.header-right { display: flex; align-items: center; gap: 14px; }
.search-box {
  display: flex; align-items: center; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 14px; gap: 8px; transition: all 0.2s;
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.search-box input {
  background: transparent; border: none; outline: none; color: var(--text-primary);
  font-size: 13px; width: 160px;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-icon { color: var(--text-muted); font-size: 14px; }

.icon-btn {
  width: 34px; height: 34px; border-radius: var(--radius-sm); border: none;
  background: transparent; color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 16px; transition: all 0.2s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn.has-dot { position: relative; }
.icon-btn.has-dot::after {
  content: ''; position: absolute; top: 6px; right: 6px; width: 7px; height: 7px;
  background: var(--danger); border-radius: 50%; border: 1.5px solid var(--bg-primary);
}
.user-badge { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); }
.user-badge:hover { background: var(--bg-hover); }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #2b8cf0, #1a5faa); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: #fff; }
.user-name { font-size: 13px; color: var(--text-secondary); }

/* ===== Main Layout ===== */
.main { flex: 1; display: flex; overflow: hidden; }

/* ===== Left Sidebar ===== */
.sidebar-left {
  width: 260px; background: var(--bg-primary); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--border);
}
.sidebar-header h3 { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.sidebar-header .settings-icon { color: var(--text-muted); cursor: pointer; font-size: 14px; transition: color 0.2s; }
.sidebar-header .settings-icon:hover { color: var(--text-primary); }

.template-list { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.template-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; cursor: pointer; transition: all 0.25s; display: flex; align-items: center; gap: 12px;
}
.template-card:hover { border-color: var(--accent); background: var(--bg-hover); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,0,0,0.25); }
.template-card.active { border-color: var(--accent); background: rgba(43,140,240,0.08); box-shadow: 0 0 0 3px var(--accent-glow); }
.template-thumb {
  width: 48px; height: 48px; border-radius: var(--radius-sm); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.template-thumb.hat { background: linear-gradient(135deg, #1e3a5f, #2a5298); }
.template-thumb.bag { background: linear-gradient(135deg, #1e4a3a, #2a7858); }
.template-thumb.pouch { background: linear-gradient(135deg, #3a2a1e, #6b4c2a); }
.template-info { overflow: hidden; }
.template-info .name { font-size: 14px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.template-info .meta { font-size: 11px; color: var(--text-muted); }
.template-info .date { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.view-more {
  margin: 8px 12px 16px; padding: 10px; text-align: center; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px dashed var(--border);
  color: var(--text-secondary); font-size: 13px; cursor: pointer; transition: all 0.2s;
}
.view-more:hover { border-color: var(--accent); color: var(--accent); background: var(--bg-hover); }

/* ===== Center Canvas ===== */
.canvas-area {
  flex: 1; position: relative; background: #0a101f;
  background-image:
    linear-gradient(rgba(30,50,96,0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30,50,96,0.12) 1px, transparent 1px);
  background-size: 32px 32px;
}
#three-canvas { width: 100%; height: 100%; display: block; }

/* Canvas photo overlay */
.canvas-photo-overlay {
  display: none; position: absolute; inset: 0; z-index: 15;
  background: rgba(8,14,28,0.92); backdrop-filter: blur(4px);
  align-items: center; justify-content: center; flex-direction: column; gap: 16px;
}
.canvas-photo-overlay.show { display: flex; }
.canvas-photo-overlay img {
  max-width: 85%; max-height: 70%; border-radius: var(--radius); border: 2px solid var(--border-light);
  box-shadow: 0 8px 40px rgba(0,0,0,0.5); object-fit: contain;
}
.canvas-photo-overlay .photo-label {
  font-size: 13px; color: var(--text-secondary);
}
.canvas-photo-overlay .photo-close {
  position: absolute; top: 16px; right: 16px;
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
  background: rgba(12,21,41,0.9); color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 16px; transition: all 0.2s;
}
.canvas-photo-overlay .photo-close:hover { background: var(--bg-hover); color: var(--danger); border-color: var(--danger); }

.canvas-toolbar {
  position: absolute; top: 16px; left: 16px; display: flex; flex-direction: column; gap: 6px;
  z-index: 10;
}
.canvas-tool {
  width: 38px; height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: rgba(12,21,41,0.85); backdrop-filter: blur(8px);
  color: var(--text-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: all 0.2s;
}
.canvas-tool:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-light); }
.canvas-tool.liked { color: var(--danger); border-color: var(--danger); }
.canvas-tool.starred { color: var(--warning); border-color: var(--warning); }

.canvas-hint {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  padding: 8px 18px; border-radius: 20px; background: rgba(12,21,41,0.8); backdrop-filter: blur(8px);
  border: 1px solid var(--border); font-size: 12px; color: var(--text-muted);
  pointer-events: none; z-index: 10;
}

/* ===== Right Panel ===== */
.panel-right {
  width: 340px; background: var(--bg-primary); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; flex-shrink: 0;
}
.panel-tabs {
  display: flex; border-bottom: 1px solid var(--border);
}
.panel-tab {
  flex: 1; padding: 13px 0; text-align: center; font-size: 14px; color: var(--text-secondary);
  cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s;
}
.panel-tab:hover { color: var(--text-primary); }
.panel-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.panel-content { padding: 18px; display: flex; flex-direction: column; gap: 16px; }

.prompt-area { position: relative; }
.prompt-area textarea {
  width: 100%; height: 120px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; color: var(--text-primary); font-size: 13px;
  resize: none; outline: none; font-family: inherit; line-height: 1.6; transition: border-color 0.2s;
}
.prompt-area textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.prompt-area textarea::placeholder { color: var(--text-muted); }
.prompt-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 4px 0; font-size: 12px; color: var(--text-muted);
}
.prompt-footer span.char-count { font-size: 11px; }
.prompt-footer .aux-btns { display: flex; gap: 12px; }
.aux-btn { color: var(--accent); cursor: pointer; font-size: 12px; transition: all 0.2s; background: none; border: none; }
.aux-btn:hover { color: var(--accent-hover); text-decoration: underline; }

/* Tag chips */
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip {
  padding: 7px 14px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; font-size: 12px; color: var(--text-secondary); cursor: pointer;
  transition: all 0.2s; user-select: none;
}
.tag-chip:hover { border-color: var(--accent); color: var(--accent); }
.tag-chip.active { background: rgba(43,140,240,0.15); border-color: var(--accent); color: var(--accent); }

/* Expanded config */
.tag-config {
  margin-top: 10px; padding: 14px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); display: none;
}
.tag-config.show { display: block; animation: fadeIn 0.25s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.color-palette { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; transition: all 0.2s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: #fff; box-shadow: 0 0 8px rgba(255,255,255,0.4); }

.material-options { display: flex; flex-wrap: wrap; gap: 6px; }
.mat-option {
  padding: 5px 12px; border-radius: 14px; font-size: 11px; background: var(--bg-hover);
  border: 1px solid var(--border); color: var(--text-secondary); cursor: pointer; transition: all 0.2s;
}
.mat-option:hover { border-color: var(--accent); color: var(--accent); }
.mat-option.selected { background: rgba(43,140,240,0.15); border-color: var(--accent); color: var(--accent); }

/* Dropdown */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.form-select {
  width: 100%; padding: 10px 14px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; outline: none;
  cursor: pointer; transition: border-color 0.2s;
}
.form-select:focus { border-color: var(--accent); }

/* Generate button */
.btn-generate {
  width: 100%; padding: 14px; background: linear-gradient(135deg, #2b8cf0, #1a6fd4);
  border: none; border-radius: var(--radius); color: #fff; font-size: 16px; font-weight: 700;
  cursor: pointer; transition: all 0.25s; letter-spacing: 1px;
  box-shadow: 0 4px 20px rgba(43,140,240,0.3);
}
.btn-generate:hover { transform: translateY(-1px); box-shadow: 0 6px 28px rgba(43,140,240,0.45); }
.btn-generate:active { transform: translateY(0); }
.btn-generate:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* Export */
.export-row { display: flex; gap: 10px; align-items: center; }
.export-row .form-select { flex: 1; }
.btn-download {
  padding: 10px 20px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.btn-download:hover { background: var(--bg-hover); border-color: var(--accent); color: var(--accent); }

/* Camera */
.camera-section { display: flex; gap: 10px; }
.btn-camera {
  flex: 1; padding: 10px; background: var(--bg-card); border: 1px dashed var(--border);
  border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 13px;
  cursor: pointer; transition: all 0.2s; text-align: center;
}
.btn-camera:hover { border-color: var(--accent); color: var(--accent); background: var(--bg-hover); }
.camera-preview {
  display: none; width: 100%; border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--border);
}
.camera-preview.show { display: block; }
.camera-preview video { width: 100%; display: block; border-radius: var(--radius-sm); }
.camera-preview .cam-actions { display: flex; gap: 8px; padding: 8px 0 0; }
.camera-preview .cam-actions button {
  flex: 1; padding: 7px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-primary); cursor: pointer; font-size: 12px; transition: all 0.2s;
}
.camera-preview .cam-actions button:hover { border-color: var(--accent); }

.captured-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.captured-images img { width: 60px; height: 60px; border-radius: var(--radius-sm); object-fit: cover; border: 1px solid var(--border); }

/* ===== Progress Overlay ===== */
.progress-overlay {
  display: none; position: absolute; inset: 0; z-index: 50;
  background: rgba(8,14,28,0.88); backdrop-filter: blur(6px);
  flex-direction: column; align-items: center; justify-content: center; gap: 20px;
}
.progress-overlay.show { display: flex; }
.progress-ring { width: 100px; height: 100px; position: relative; }
.progress-ring svg { transform: rotate(-90deg); }
.progress-ring .bg-circle { fill: none; stroke: var(--border); stroke-width: 6; }
.progress-ring .fg-circle {
  fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round;
  stroke-dasharray: 251; stroke-dashoffset: 251; transition: stroke-dashoffset 0.4s;
}
.progress-percent {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: var(--accent);
}
.progress-status { font-size: 14px; color: var(--text-secondary); text-align: center; }
.progress-status .step { margin: 4px 0; }
.progress-status .step.done { color: var(--success); }
.progress-status .step.active { color: var(--accent); font-weight: 600; }
.progress-status .step.pending { color: var(--text-muted); }

/* ===== Footer ===== */
.footer {
  height: 36px; background: var(--bg-primary); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; gap: 12px;
  font-size: 11px; color: var(--text-muted); flex-shrink: 0;
}
.footer a { color: var(--text-muted); text-decoration: none; transition: color 0.2s; }
.footer a:hover { color: var(--accent); }
.footer img { height: 14px; vertical-align: middle; }

/* ===== Mobile Toggle ===== */
.mobile-menu-btn { display: none; background: none; border: none; color: var(--text-secondary); font-size: 20px; cursor: pointer; }
.mobile-panel-toggle { display: none; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .sidebar-left { width: 220px; }
  .panel-right { width: 300px; }
}

@media (max-width: 768px) {
  .header { padding: 0 12px; }
  .nav-links { display: none; }
  .search-box { display: none; }
  .user-name { display: none; }
  .mobile-menu-btn { display: block; }

  /* Left sidebar: hidden by default on mobile */
  .sidebar-left {
    display: none; position: absolute; top: var(--header-h); left: 0; bottom: 36px;
    width: 260px; z-index: 90; box-shadow: var(--shadow);
  }
  .sidebar-left.mobile-show { display: flex; }

  /* Right panel: visible by default as mobile bottom panel, positioned absolute */
  .panel-right {
    display: flex; position: absolute; top: auto; right: 0; bottom: 36px; left: 0;
    width: 100%; height: auto; max-height: 55vh; z-index: 90;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
    border-left: none; border-top: 1px solid var(--border); border-radius: 16px 16px 0 0;
  }
  .panel-right.mobile-collapsed { display: none; }

  /* Hide desktop-only elements on mobile */
  .panel-tabs { display: none; }
  .tag-row { display: none; }
  .tag-config { display: none !important; }
  .form-group { display: none; }
  .export-row { display: none; }
  .captured-images { display: none; }
  .panel-content > div[style] { display: none; }

  /* Make prompt smaller on mobile */
  .prompt-area textarea { height: 80px; }

  /* Mobile panel toggle buttons */
  .mobile-panel-toggle {
    display: flex; position: absolute; bottom: 16px; z-index: 20; gap: 8px;
  }
  .mobile-panel-toggle.right { right: 16px; }
  .mobile-panel-toggle.left { left: 16px; }
  .mobile-panel-toggle button {
    padding: 8px 16px; border-radius: 20px; border: 1px solid var(--border);
    background: rgba(12,21,41,0.9); backdrop-filter: blur(8px);
    color: var(--accent); font-size: 13px; cursor: pointer;
  }

  /* Hide canvas hint on mobile */
  .canvas-hint { display: none; }
}

@media (max-width: 480px) {
  .sidebar-left.mobile-show { width: 100%; }
  .panel-right { max-height: 50vh; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* Desktop-only class: hidden on mobile */
@media (max-width: 768px) {
  .desktop-only { display: none !important; }
}
@media (min-width: 769px) {
  .mobile-only { display: none !important; }
}
