/* ==========================================================================
   OpenSCAD Web — Main Stylesheet
   A modern, dark-themed UI for the OpenSCAD web application.
   ========================================================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Colors */
  --bg-primary: #0f0f1a;
  --bg-secondary: #161625;
  --bg-tertiary: #1c1c30;
  --bg-elevated: #22223a;
  --bg-hover: #2a2a45;
  --bg-active: #333355;

  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-muted: #666680;
  --text-accent: #f9a825;

  --border-color: #2a2a40;
  --border-active: #4a4a6a;

  --accent: #f9a825;
  --accent-hover: #ffc107;
  --accent-dim: rgba(249, 168, 37, 0.15);

  --success: #4caf50;
  --error: #f44336;
  --warning: #ff9800;
  --info: #2196f3;

  /* Sizing */
  --toolbar-height: 44px;
  --panel-header-height: 36px;
  --console-height: 180px;
  --resize-handle-size: 5px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;

  /* Effects */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;

  --transition-fast: 120ms ease;
  --transition-normal: 200ms ease;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-height);
  padding: 0 8px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 100;
  gap: 2px;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  color: var(--accent);
}

.logo svg {
  width: 22px;
  height: 22px;
}

.logo-text {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
}

.logo-text small {
  font-weight: 400;
  font-size: 11px;
  color: var(--text-secondary);
  margin-left: 2px;
}

.toolbar-separator {
  width: 1px;
  height: 20px;
  background: var(--border-color);
  margin: 0 4px;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.toolbar-btn i {
  font-size: 16px;
}

.toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.toolbar-btn:active {
  background: var(--bg-active);
}

.toolbar-btn.primary {
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border-color: var(--accent);
}

.toolbar-btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.toolbar-btn.primary:active {
  filter: brightness(0.9);
}

.toolbar-btn.primary.rendering {
  background: var(--bg-hover);
  color: var(--text-secondary);
  border-color: var(--border-color);
  pointer-events: none;
}

.toolbar-btn:disabled,
.toolbar-select:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.toolbar-select {
  padding: 4px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  outline: none;
}

.toolbar-select:focus {
  border-color: var(--accent);
}

/* ---------- Workspace ---------- */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ---------- Panels ---------- */
.panel {
  display: flex;
  flex-direction: column;
  min-width: 100px;
  overflow: hidden;
}

.panel-editor {
  flex: 1;
  min-width: 280px;
  background: var(--bg-primary);
}

.panel-viewer {
  flex: 1;
  min-width: 280px;
  background: var(--bg-secondary);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--panel-header-height);
  padding: 0 8px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.panel-tabs {
  display: flex;
  align-items: center;
  gap: 1px;
}

.panel-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.panel-tab i {
  font-size: 14px;
}

.panel-tab.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.panel-tab:hover:not(.active) {
  color: var(--text-primary);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn i {
  font-size: 14px;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.panel-body {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ---------- Editor ---------- */
#editor-container {
  height: 100%;
}

#editor-container .CodeMirror {
  height: 100%;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg-primary);
}

/* CodeMirror theme overrides for dark mode */
#editor-container .CodeMirror-gutters {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
}

#editor-container .CodeMirror-linenumber {
  color: var(--text-muted);
}

#editor-container .CodeMirror-cursor {
  border-left-color: var(--accent);
}

#editor-container .CodeMirror-selected {
  background: rgba(249, 168, 37, 0.15) !important;
}

#editor-container .CodeMirror-activeline-background {
  background: rgba(255, 255, 255, 0.03);
}

/* ---------- 3D Viewer ---------- */
.viewer-container {
  position: relative;
  background: #1a1a2e;
}

#viewer-canvas {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

.viewer-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.viewer-overlay.hidden {
  display: none;
}

.viewer-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
}

.viewer-message p {
  font-size: 13px;
  line-height: 1.5;
}

.viewer-message kbd {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  background: var(--bg-tertiary);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

.rendering-overlay {
  background: rgba(15, 15, 26, 0.85);
  pointer-events: all;
}

.rendering-overlay p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 16px;
}

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---------- Resize Handle ---------- */
.resize-handle {
  flex-shrink: 0;
  background: var(--border-color);
  transition: background var(--transition-fast);
  z-index: 10;
}

.resize-handle:hover,
.resize-handle.dragging {
  background: var(--accent);
}

.resize-handle.vertical {
  width: var(--resize-handle-size);
  cursor: col-resize;
}

.resize-handle.horizontal {
  height: var(--resize-handle-size);
  cursor: row-resize;
}

/* ---------- Console ---------- */
.console-panel {
  display: flex;
  flex-direction: column;
  height: var(--console-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.console-body {
  overflow: hidden;
}

.console-content {
  height: 100%;
  overflow-y: auto;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.console-content::-webkit-scrollbar {
  width: 8px;
}

.console-content::-webkit-scrollbar-track {
  background: transparent;
}

.console-content::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.console-content::-webkit-scrollbar-thumb:hover {
  background: var(--border-active);
}

.console-line {
  padding: 1px 0;
}

.console-line.info { color: var(--text-secondary); }
.console-line.warn { color: var(--warning); }
.console-line.error { color: var(--error); }
.console-line.success { color: var(--success); }
.console-line.trace { color: var(--info); }

.parameters-content {
  height: 100%;
  overflow-y: auto;
  padding: 12px;
}

.parameters-content.hidden {
  display: none;
}

.placeholder-text {
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
}

.status-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 8px;
}

/* ---------- Modals ---------- */
.modal {
  border: none;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  max-width: 640px;
  width: 90%;
  padding: 0;
  overflow: hidden;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-close {
  color: var(--text-muted);
}

/* ---------- Examples Grid ---------- */
.example-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.example-card {
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  cursor: pointer;
  transition: all var(--transition-normal);
}

.example-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.example-card h3 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--accent);
}

.example-card p {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ---------- Settings ---------- */
.settings-group {
  margin-bottom: 20px;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-group h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 13px;
  cursor: pointer;
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-input {
  padding: 4px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 12px;
  width: 100px;
  outline: none;
}

.setting-input:focus {
  border-color: var(--accent);
}

.setting-input[type="color"] {
  width: 40px;
  height: 28px;
  padding: 2px;
  cursor: pointer;
}

/* ---------- Toast Notifications ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  animation: toast-in 0.3s ease;
  max-width: 400px;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error   { border-left: 3px solid var(--error); }
.toast.toast-warning { border-left: 3px solid var(--warning); }
.toast.toast-info    { border-left: 3px solid var(--info); }

.toast-out {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(20px) scale(0.95); }
}

/* ---------- Customizer parameters ---------- */
.param-group {
  margin-bottom: 16px;
}

.param-group-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.param-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  gap: 12px;
}

.param-label {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 80px;
}

.param-input {
  flex: 1;
  max-width: 180px;
  padding: 4px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
}

.param-input:focus {
  border-color: var(--accent);
}

.param-input[type="range"] {
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border-color);
  border: none;
}

.param-input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.param-input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* ---------- Loading state ---------- */
.app-loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 9999;
  gap: 20px;
}

.app-loading .logo {
  font-size: 24px;
}

.app-loading .spinner {
  width: 32px;
  height: 32px;
}

.app-loading p {
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .btn-label {
    display: none;
  }

  .toolbar-btn {
    padding: 5px 6px;
  }

  .workspace {
    flex-direction: column;
  }

  .resize-handle.vertical {
    width: 100%;
    height: var(--resize-handle-size);
    cursor: row-resize;
  }

  .panel-editor, .panel-viewer {
    min-width: unset;
    min-height: 150px;
  }
}
