/* Global CSS Variables & Design System */
:root {
  --bg-dark: #0a0c10;
  --bg-card: rgba(22, 27, 34, 0.75);
  --bg-sidebar: rgba(15, 18, 25, 0.85);
  --bg-hud: rgba(15, 20, 28, 0.85);
  
  --border-color: rgba(255, 255, 255, 0.1);
  --border-active: rgba(99, 102, 241, 0.5);
  
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-secondary: #06b6d4;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #06b6d4 100%);
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  /* Status & Severity Colors */
  --color-critical: #ef4444;
  --bg-critical-subtle: rgba(239, 68, 68, 0.15);
  --color-warning: #f59e0b;
  --bg-warning-subtle: rgba(245, 158, 11, 0.15);
  --color-info: #3b82f6;
  --bg-info-subtle: rgba(59, 130, 246, 0.15);
  --color-success: #10b981;
  --bg-success-subtle: rgba(16, 185, 129, 0.15);
  
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Header Navbar */
.app-header {
  height: 64px;
  background: var(--bg-sidebar);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

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

.logo-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.brand-text h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.brand-text h1 span {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.sample-models {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.sample-models .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
}

/* Workspace Layout */
.workspace {
  display: flex;
  flex: 1;
  height: calc(100vh - 64px);
  overflow: hidden;
  position: relative;
}

/* Sidebar Styling */
.sidebar {
  width: 330px;
  background: var(--bg-sidebar);
  backdrop-filter: blur(12px);
  border-color: var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  overflow-y: auto;
  z-index: 10;
}

.sidebar-left {
  border-right: 1px solid var(--border-color);
}

.sidebar-right {
  width: 380px;
  border-left: 1px solid var(--border-color);
}

.panel-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title i {
  color: var(--accent-secondary);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Bounding Box Specs */
.bb-specs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

.bb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
}

.bb-row span {
  color: var(--text-muted);
}

.bb-row strong {
  font-family: var(--font-mono);
  color: var(--accent-secondary);
}

/* Render Modes */
.render-modes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  transition: all 0.2s ease;
  text-align: left;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.mode-btn.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: #fff;
  font-weight: 500;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.control-group {
  margin-bottom: 12px;
}

.control-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.control-group input {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #fff;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.control-group input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

/* Center Viewport */
.viewport-container {
  flex: 1;
  position: relative;
  background: radial-gradient(circle at center, #1a202c 0%, #0a0c10 100%);
  overflow: hidden;
}

#canvas3d {
  width: 100%;
  height: 100%;
}

.viewport-hud {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 10px;
  pointer-events: none;
}

.hud-chip {
  background: var(--bg-hud);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-chip span {
  color: #fff;
  font-weight: 600;
}

.viewport-toolbar {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-hud);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  padding: 6px;
  border-radius: 30px;
  display: flex;
  gap: 6px;
  box-shadow: var(--shadow-card);
}

.tool-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.2s ease;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

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

/* Drag Drop Overlay */
.drag-drop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 12, 16, 0.85);
  backdrop-filter: blur(10px);
  border: 3px dashed var(--accent-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 50;
}

.drag-drop-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.drop-message {
  text-align: center;
}

.drop-message i {
  font-size: 64px;
  color: var(--accent-secondary);
  margin-bottom: 16px;
  animation: bounce 1.5s infinite;
}

.drop-message h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.drop-message p {
  color: var(--text-muted);
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 12, 16, 0.8);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 40;
}

.loading-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-secondary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.progress-bar-container {
  width: 280px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent-gradient);
  transition: width 0.2s ease;
}

/* Right Sidebar Error Reports */
.panel-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.severity-summary {
  display: flex;
  gap: 8px;
}

.sev-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 12px;
}

.sev-critical {
  background: var(--bg-critical-subtle);
  color: var(--color-critical);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.sev-warning {
  background: var(--bg-warning-subtle);
  color: var(--color-warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.sev-info {
  background: var(--bg-info-subtle);
  color: var(--color-info);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.error-list-container {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 4px;
}

/* Error Card Item */
.error-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--text-muted);
  border-radius: var(--radius-md);
  padding: 14px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.error-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.2);
}

.error-card.critical {
  border-left-color: var(--color-critical);
}

.error-card.warning {
  border-left-color: var(--color-warning);
}

.error-card.info {
  border-left-color: var(--color-info);
}

.error-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.error-title {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.error-count {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
}

.error-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 10px;
}

.error-fix-tip {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: #d1d5db;
  border-left: 2px solid var(--accent-secondary);
}

.error-fix-tip strong {
  color: var(--accent-secondary);
}

.action-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
}

/* Button UI Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
}

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

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.btn-success {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
}

.badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success {
  background: var(--bg-success-subtle);
  color: var(--color-success);
}

.badge-warning {
  background: var(--bg-warning-subtle);
  color: var(--color-warning);
}

/* Modal Popup */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #121620;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 650px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent-secondary);
}

.close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  background: rgba(0, 0, 0, 0.2);
}

.fix-step-item {
  margin-bottom: 14px;
  background: rgba(255, 255, 255, 0.03);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.fix-step-item h4 {
  font-size: 14px;
  color: var(--text-main);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Keyframe Animations */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* Sidebar Navigation Tabs */
.sidebar-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  gap: 4px;
  margin-bottom: 4px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  color: #fff;
  background: var(--accent-gradient);
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

.tab-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.tab-content.active {
  display: flex;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: 0.25s;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: #fff;
  transition: 0.25s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background: var(--accent-gradient);
  border-color: var(--accent-primary);
}

input:checked + .toggle-slider:before {
  transform: translateX(18px);
}

/* Axis Selector Buttons */
.axis-selector {
  display: flex;
  gap: 4px;
}

.axis-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.axis-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.axis-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

/* Tool Buttons Active State */
.tool-btn.active {
  background: var(--accent-primary) !important;
  color: #fff !important;
  border-color: var(--accent-secondary) !important;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.5);
}

/* Part Selector Bar */
.part-selector-bar .btn.active {
  background: var(--accent-primary);
  color: #fff;
}

/* Multi-Part & AI Auto-Assembly Styles */
.part-item-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 11px;
  transition: all 0.2s ease;
}

.part-item-pill:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(168, 85, 247, 0.4);
}

.part-item-left {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.part-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

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

.part-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 3px;
  transition: color 0.15s ease;
}

.part-action-btn:hover {
  color: #fff;
}

/* AI Step Cards */
.ai-step-card {
  background: var(--bg-card);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 8px;
  position: relative;
  overflow: hidden;
}

.ai-step-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, #a855f7, #6366f1);
}

.ai-step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.ai-step-title {
  font-size: 12px;
  font-weight: 600;
  color: #c084fc;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-step-confidence {
  font-size: 11px;
  font-family: var(--font-mono);
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}

.ai-step-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Assembly Matrix Table */
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-top: 8px;
}

.matrix-table th {
  text-align: left;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
}

.matrix-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

.matrix-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 600;
}

.matrix-badge.success {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.matrix-badge.danger {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.matrix-badge.info {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}
