/* ==========================================================================
   Excamar 3D CAD Studio - Professional Fusion 360 Style Parametric CAD
   - Precision Millimeter Units for 3D Printing (STL Output)
   - Viewport 3D with CAD Grid, Axes & Edges
   - Parametric Inspector, Dimension Calipers & Slicer Weight Estimator
   ========================================================================== */

/* Floating Launcher Button */
#excamar-cad-btn {
  position: fixed;
  bottom: 188px;
  right: 20px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.4), 0 2px 6px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
}

#excamar-cad-btn:hover {
  transform: scale(1.1) translateY(-2px);
  box-shadow: 0 8px 24px rgba(2, 132, 199, 0.6), 0 4px 10px rgba(0, 0, 0, 0.25);
  border-color: #38bdf8;
}

#excamar-cad-btn:active {
  transform: scale(0.96) translateY(0);
}

#excamar-cad-btn svg {
  width: 22px;
  height: 22px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

/* CAD Studio Fullscreen Workspace Overlay */
#excamar-cad-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 2000;
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  flex-direction: column;
  color: #f1f5f9;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", Helvetica, Arial, sans-serif;
  user-select: none;
  overflow: hidden;
}

#excamar-cad-overlay.open {
  display: flex;
  opacity: 1;
}

/* Studio Window Container */
#excamar-cad-window {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #0b1120;
  box-sizing: border-box;
}

/* Header Bar */
.cad-header {
  height: 52px;
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

.cad-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cad-logo-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14.5px;
  font-weight: 700;
  color: #38bdf8;
  letter-spacing: -0.2px;
}

.cad-logo-badge svg {
  width: 22px;
  height: 22px;
  color: #38bdf8;
}

.cad-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.25);
  display: flex;
  align-items: center;
  gap: 5px;
}

.cad-header-center {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cad-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #334155;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cad-tool-btn:hover {
  background: #334155;
  color: #f8fafc;
  border-color: #475569;
}

.cad-tool-btn.active {
  background: #0284c7;
  color: #ffffff;
  border-color: #38bdf8;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);
}

.cad-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cad-btn-ai {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
  transition: all 0.2s ease;
}

.cad-btn-ai:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.cad-btn-export {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 8px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
  transition: all 0.2s ease;
}

.cad-btn-export:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.cad-close-btn {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cad-close-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

/* Studio Workspace Body */
.cad-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Left Sidebar - Parametric Feature Tree */
.cad-sidebar-left {
  width: 280px;
  background: #0f172a;
  border-right: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
}

.cad-panel-section {
  padding: 14px;
  border-bottom: 1px solid #1e293b;
}

.cad-panel-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #64748b;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Preset Shape Selector */
.cad-preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.cad-preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #cbd5e1;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cad-preset-btn:hover {
  background: #334155;
  color: #38bdf8;
  border-color: #0284c7;
  transform: translateY(-1px);
}

.cad-preset-btn.active {
  background: rgba(2, 132, 199, 0.15);
  color: #38bdf8;
  border-color: #38bdf8;
}

.cad-preset-btn svg {
  width: 20px;
  height: 20px;
  opacity: 0.85;
}

/* Parametric Inputs */
.cad-params-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  max-height: calc(100vh - 350px);
  padding-right: 4px;
}

.cad-param-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cad-param-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  font-weight: 600;
  color: #94a3b8;
}

.cad-param-val {
  color: #38bdf8;
  font-family: monospace;
}

.cad-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cad-range {
  flex: 1;
  accent-color: #0284c7;
  cursor: pointer;
  height: 4px;
  background: #334155;
  border-radius: 2px;
}

.cad-num-input {
  width: 60px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 4px 6px;
  color: #f8fafc;
  font-size: 11.5px;
  font-weight: 600;
  font-family: monospace;
  text-align: right;
  outline: none;
}

.cad-num-input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px #38bdf8;
}

.cad-unit {
  font-size: 10.5px;
  color: #64748b;
  font-weight: 600;
}

/* Holes & Mounting Sub-panel */
.cad-hole-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #131d33;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #1e293b;
}

.cad-select {
  width: 100%;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 6px 8px;
  color: #f8fafc;
  font-size: 11.5px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

.cad-select:focus {
  border-color: #38bdf8;
}

/* Center Viewport */
.cad-viewport-container {
  flex: 1;
  position: relative;
  background: radial-gradient(circle at center, #1e293b 0%, #0b1120 100%);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#cad-canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  outline: none;
}

/* Viewport HUD Overlays */
.cad-hud-top-left {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  gap: 6px;
  z-index: 10;
}

.cad-hud-btn {
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(51, 65, 85, 0.6);
  border-radius: 6px;
  padding: 5px 9px;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cad-hud-btn:hover {
  background: rgba(30, 41, 59, 0.9);
  color: #38bdf8;
  border-color: #38bdf8;
}

.cad-hud-btn.active {
  background: #0284c7;
  color: #ffffff;
  border-color: #38bdf8;
}

/* Camera Views Widget */
.cad-hud-views {
  position: absolute;
  top: 14px;
  right: 320px;
  display: flex;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(51, 65, 85, 0.6);
  border-radius: 8px;
  overflow: hidden;
  z-index: 10;
}

.cad-view-btn {
  background: transparent;
  border: none;
  padding: 5px 9px;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border-right: 1px solid rgba(51, 65, 85, 0.4);
}

.cad-view-btn:last-child {
  border-right: none;
}

.cad-view-btn:hover {
  background: #334155;
  color: #f8fafc;
}

/* Viewport Navigation Helper Bar (Bottom Center) */
.cad-nav-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(51, 65, 85, 0.4);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 10.5px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

/* Right Sidebar - Inspector & 3D Print Health */
.cad-sidebar-right {
  width: 300px;
  background: #0f172a;
  border-left: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
  box-sizing: border-box;
}

.cad-stat-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.cad-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.cad-stat-label {
  color: #94a3b8;
  font-weight: 500;
}

.cad-stat-val {
  color: #f8fafc;
  font-weight: 700;
  font-family: monospace;
}

.cad-stat-val.highlight {
  color: #38bdf8;
}

.cad-stat-val.success {
  color: #34d399;
}

/* Slicer Readiness Checklist */
.cad-checklist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #131d33;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #1e293b;
}

.cad-check-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: #cbd5e1;
}

.cad-check-icon {
  color: #10b981;
  font-weight: 700;
}

/* Material & Weight Estimator */
.cad-material-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.cad-weight-badge {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
  font-weight: 700;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
}

/* AI CAD Prompt Drawer */
#cad-ai-drawer {
  position: absolute;
  bottom: 0;
  left: 280px;
  right: 300px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid #334155;
  padding: 14px 20px;
  display: none;
  flex-direction: column;
  gap: 10px;
  z-index: 50;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
}

#cad-ai-drawer.open {
  display: flex;
}

.cad-ai-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cad-ai-title {
  font-size: 13px;
  font-weight: 700;
  color: #a78bfa;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cad-ai-input-row {
  display: flex;
  gap: 10px;
}

.cad-ai-input {
  flex: 1;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 8px;
  padding: 8px 12px;
  color: #f8fafc;
  font-size: 13px;
  outline: none;
}

.cad-ai-input:focus {
  border-color: #8b5cf6;
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.25);
}

.cad-ai-submit {
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cad-ai-submit:hover {
  filter: brightness(1.1);
}

.cad-ai-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.cad-ai-sample-pill {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 2px 10px;
  color: #94a3b8;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cad-ai-sample-pill:hover {
  background: #334155;
  color: #c4b5fd;
  border-color: #8b5cf6;
}

/* CAD Toast Notification */
#cad-toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #0f172a;
  color: #f8fafc;
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid #334155;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 8px;
}

#cad-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

#cad-toast.success {
  border-color: #10b981;
  color: #34d399;
}

#cad-toast.error {
  border-color: #ef4444;
  color: #f87171;
}

/* Home & Login CAD Quick Access Card */
.excamar-cad-home-box {
  margin-top: 24px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(2, 132, 199, 0.08) 0%, rgba(244, 63, 94, 0.08) 100%);
  border: 1.5px solid rgba(2, 132, 199, 0.25);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  transition: all 0.2s ease;
}

.dark .excamar-cad-home-box,
[data-theme="dark"] .excamar-cad-home-box {
  background: linear-gradient(135deg, rgba(2, 132, 199, 0.15) 0%, rgba(244, 63, 94, 0.15) 100%);
  border-color: rgba(56, 189, 248, 0.3);
}

.cad-home-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cad-home-icon {
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.cad-home-info {
  display: flex;
  flex-direction: column;
}

.cad-home-title {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dark .cad-home-title,
[data-theme="dark"] .cad-home-title {
  color: #f8fafc;
}

.cad-home-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e0f2fe;
  color: #0284c7;
}

.dark .cad-home-badge,
[data-theme="dark"] .cad-home-badge {
  background: #0369a1;
  color: #e0f2fe;
}

.cad-home-desc {
  font-size: 12px;
  color: #64748b;
  margin-top: 2px;
}

.dark .cad-home-desc,
[data-theme="dark"] .cad-home-desc {
  color: #94a3b8;
}

.cad-home-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.3);
  transition: all 0.2s ease;
}

.cad-home-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

