/**
 * CAD Mode Styles - Apple Design System
 * Follows CoandaView's existing glassmorphic design patterns
 */

/* Mode Toggle */
.mode-toggle-container {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 20px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.2s ease;
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 500;
}

.mode-toggle .toggle-label {
  color: rgba(255, 255, 255, 0.5);
  transition: color 0.3s ease;
  user-select: none;
  cursor: pointer;
}

.mode-toggle .toggle-label.active {
  color: rgba(255, 255, 255, 0.95);
}

/* Mode-specific visibility */
body.cad-mode .view-mode-only {
  display: none !important;
}

body.view-mode .cad-mode-only {
  display: none !important;
}

/* CAD Sidebar - Reuses existing sidebar styles */
.cad-sidebar {
  /* Inherits from .sidebar-left */
}

/* CAD Tool Grid */
.cad-tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.cad-tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cad-tool-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
  color: rgba(255, 255, 255, 0.95);
}

.cad-tool-btn.active {
  background: rgba(191, 90, 242, 0.2);
  border-color: rgba(191, 90, 242, 0.5);
  color: var(--apple-purple);
}

/* CAD Operation Buttons (Extrude, Revolve, etc.) */
.btn-cad-operation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.btn-cad-operation:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-cad-operation:active {
  transform: translateY(0);
}

.btn-cad-operation svg {
  flex-shrink: 0;
}

.btn-cad-operation span {
  flex: 1;
  text-align: left;
}

/* Small operation buttons (for compact grids) */
.btn-cad-operation-sm {
  padding: 6px 10px;
  font-size: 11px;
  gap: 6px;
}

/* Feature Tree */
.cad-feature-item {
  margin-bottom: 4px;
  border-radius: 8px;
  overflow: hidden;
}

.feature-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.feature-header:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}

.cad-feature-item.active .feature-header {
  background: rgba(191, 90, 242, 0.12);
  border-color: rgba(191, 90, 242, 0.4);
}

.feature-icon {
  flex-shrink: 0;
  color: rgba(255, 255, 255, 0.7);
}

.feature-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
}

.feature-visibility {
  flex-shrink: 0;
  background: transparent;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.6);
  transition: color 0.15s ease;
}

.feature-visibility:hover {
  color: rgba(255, 255, 255, 0.95);
}

/* ===== Gear Designer Modal ===== */

.cad-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.cad-modal.active {
  opacity: 1;
}

.cad-modal-content {
  background: rgba(20, 20, 25, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.cad-modal.active .cad-modal-content {
  transform: scale(1);
}

.cad-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.cad-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.95);
}

.cad-modal-close {
  background: transparent;
  border: none;
  font-size: 28px;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.cad-modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.95);
}

.cad-modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.cad-modal-footer {
  display: flex;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  justify-content: flex-end;
}

/* Gear Parameters Form */

.gear-params-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gear-param-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gear-param-field label {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 6px;
}

.param-info {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  cursor: help;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  transition: all 0.2s ease;
}

.param-info:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
}

.gear-param-input {
  width: 100%;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.95);
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  transition: all 0.2s ease;
}

.gear-param-input:focus {
  outline: none;
  border-color: rgba(191, 90, 242, 0.6);
  background: rgba(0, 0, 0, 0.4);
}

.gear-param-input:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

/* Gear Info Box */

.gear-info-box {
  margin-top: 20px;
  padding: 14px 16px;
  background: rgba(191, 90, 242, 0.08);
  border: 1px solid rgba(191, 90, 242, 0.2);
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.7);
}

/* Modal Buttons */

.btn-primary,
.btn-secondary {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.btn-primary {
  background: linear-gradient(135deg, #BF5AF2, #AF52DE);
  color: white;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #C96EF5, #B85FE0);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(191, 90, 242, 0.3);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

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

/* Toast Notifications */

.cad-toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  padding: 14px 20px;
  background: rgba(20, 20, 25, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 10001;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
}

.cad-toast.active {
  opacity: 1;
  transform: translateY(0);
}

.cad-toast-success {
  border-left: 3px solid #30D158;
}

.cad-toast-error {
  border-left: 3px solid #FF453A;
}

.cad-toast-info {
  border-left: 3px solid #0A84FF;
}

/* Feature Details */

.feature-details {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  margin-top: 4px;
  padding-left: 26px;
}

.cad-feature-item.selected .feature-header {
  background: rgba(191, 90, 242, 0.15);
  border-color: rgba(191, 90, 242, 0.5);
}

.cad-feature-item.selected .feature-name {
  color: rgba(191, 90, 242, 1);
}

/* Undo/Redo Button Styles */
.btn-icon-small:disabled,
.btn-icon-small.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-icon-small:not(:disabled):not(.disabled):hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.btn-icon-small:not(:disabled):not(.disabled):active {
  transform: translateY(0);
}

/* Section Labels */
.section-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  margin-top: 4px;
}

/* CAD Constraint Section */
.cad-constraint-section {
  margin-top: 16px;
}

/* CAD Dimension Section */
.cad-dimension-section {
  margin-top: 16px;
}

/* Small Tool Buttons (for constraints/dimensions) */
.cad-tool-sm {
  padding: 8px 6px;
  font-size: 9px;
  gap: 4px;
}

.cad-tool-sm svg {
  width: 14px;
  height: 14px;
}

.cad-tool-sm span {
  font-size: 9px;
}

/* Feature Actions (Eye, Add, Cut, Remove buttons) */
.feature-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.feature-btn {
  padding: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.6);
  transition: all 0.15s ease;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.feature-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.95);
  transform: scale(1.1);
}

.feature-btn[data-action="edit"] {
  color: rgba(0, 122, 255, 0.8);
}

.feature-btn[data-action="edit"]:hover {
  color: rgba(0, 122, 255, 1);
}

.feature-btn[data-action="add"] {
  color: rgba(0, 255, 0, 0.6);
}

.feature-btn[data-action="add"]:hover {
  color: rgba(0, 255, 0, 1);
}

.feature-btn[data-action="cut"] {
  color: rgba(255, 165, 0, 0.6);
}

.feature-btn[data-action="cut"]:hover {
  color: rgba(255, 165, 0, 1);
}

.feature-btn[data-action="remove"] {
  color: rgba(255, 0, 0, 0.6);
}

.feature-btn[data-action="remove"]:hover {
  color: rgba(255, 0, 0, 1);
}

/* Feature Children (nested entities) */
.feature-children {
  padding-left: 24px;
  margin-top: 4px;
}

.cad-entity-item {
  font-size: 11px;
  opacity: 0.9;
  margin-bottom: 2px;
}

.cad-entity-item .feature-header {
  padding: 4px 6px;
}

/* Expand Icon */
.expand-icon {
  font-size: 10px;
  margin-right: 6px;
  cursor: pointer;
  transition: transform 0.2s ease;
  color: rgba(255, 255, 255, 0.6);
}

.expand-icon:hover {
  color: rgba(255, 255, 255, 0.95);
}

/* Panel Styling Enhancements */
.panel {
  margin-bottom: 12px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  overflow: hidden;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.panel-header {
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.panel-header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.panel-content {
  padding: 16px;
}

/* Status Indicators */
#interactionModeStatus,
#snapModeStatus {
  padding: 6px;
  background: rgba(0, 122, 255, 0.1);
  border-radius: 6px;
  font-size: 10px;
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 8px;
}

#snapModeStatus {
  background: rgba(191, 90, 242, 0.1);
}

/* Ensure consistent spacing */
.cad-sidebar .panel:last-child {
  margin-bottom: 0;
}

/* Smooth scrolling for sidebar */
.cad-sidebar {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(191, 90, 242, 0.3) rgba(0, 0, 0, 0.2);
}

.cad-sidebar::-webkit-scrollbar {
  width: 6px;
}

.cad-sidebar::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.cad-sidebar::-webkit-scrollbar-thumb {
  background: rgba(191, 90, 242, 0.3);
  border-radius: 3px;
}

.cad-sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(191, 90, 242, 0.5);
}

/* Mobile responsiveness for CAD sidebar */
@media (max-width: 768px) {
  .cad-sidebar {
    position: fixed !important;
    top: 54px;
    left: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    z-index: 2000;
    margin-left: 0 !important;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    background: rgba(18, 18, 20, 0.98);
    padding: 12px;
    overflow-y: auto;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  .cad-sidebar.mobile-open {
    transform: translateX(0);
  }
}
