/* ============================================
   ForjIA — CAD App Styles
   ============================================ */

/* --- Layout --- */
html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg-gradient);
  min-height: 100vh;
  min-height: calc(var(--vh, 1vh) * 100);
}

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
}

/* --- Header --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}

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

.app-header-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}

.app-header-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.app-header-btn.active {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.15);
}

.header-sep {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.15);
  margin: 0 2px;
  flex-shrink: 0;
}

/* --- Language Switch --- */
.lang-switch {
  display: flex;
  gap: 2px;
  margin-right: 4px;
}

.lang-btn {
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

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

.lang-btn.active {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.5);
}

/* --- Main --- */
.app-main {
  flex: 1;
  overflow: hidden;
  min-height: 0;
  display: flex;
}


/* --- Footer --- */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.72rem;
}

.app-footer a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
}

.app-footer a:hover {
  color: #fff;
}

.footer-sep {
  opacity: 0.4;
}


/* --- Upload Controls --- */
.upload-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.75rem;
}

.upload-file-info #fileName {
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-file-info #fileSize {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.68rem;
}

/* --- Progress Bar --- */
.progress-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary-color);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* --- Element Tree --- */
.element-tree-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.element-tree-header {
  padding: 3px 8px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.75rem;
  font-weight: 600;
}

.element-tree {
  flex: 1;
  overflow-y: auto;
  padding: 0 4px;
}

.tree-node {
  padding: 1px 0;
}

.tree-node-label {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.72rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s;
}

.tree-node-label:hover {
  background: rgba(255, 255, 255, 0.1);
}

.tree-toggle {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  color: rgba(255, 255, 255, 0.5);
  transition: transform 0.15s;
}

.tree-toggle.expanded {
  transform: rotate(90deg);
}

.tree-children {
  padding-left: 16px;
  display: none;
}

.tree-children.expanded {
  display: block;
}

.tree-node-icon {
  width: 14px;
  height: 14px;
  opacity: 0.6;
}

/* --- 3D Viewer --- */
.viewer-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: #1a1a2e;
  border-radius: var(--radius);
  overflow: hidden;
}

.viewer-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Dimensions overlay */
.viewer-dimensions {
  position: absolute;
  bottom: 8px;
  left: 8px;
  display: none;
  gap: 8px;
  padding: 3px 8px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  border-radius: 5px;
  z-index: 5;
}
.viewer-dimensions span {
  font-size: 0.65rem;
  font-family: 'JetBrains Mono', monospace;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.3px;
}

.viewer-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}

.viewer-ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.viewer-ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.viewer-ctrl-btn.active {
  background: rgba(70, 130, 180, 0.5);
  color: #fff;
}
.viewer-ctrl-sep {
  width: 1px;
  height: 18px;
  background: rgba(255,255,255,0.15);
  margin: 0 2px;
}
.viewer-ctrl-section-sep {
  width: 26px;
  border-top: 2px solid rgba(255,255,255,0.2);
  margin: 3px auto;
  position: relative;
}
.viewer-ctrl-section-label {
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.42rem;
  font-family: 'JetBrains Mono', monospace;
  color: rgba(255,255,255,0.25);
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
  line-height: 1;
}
.viewer-ctrl-btn.disabled {
  opacity: 0.2;
  pointer-events: none;
  cursor: default;
}
.viewer-ctrl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.viewer-axis-ref {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 52px;
  height: 52px;
  z-index: 5;
  background: rgba(0,0,0,0.35);
  border-radius: 6px;
  pointer-events: none;
}
/* Legacy — kept for backward compat if canvas gizmo re-enabled */
.viewer-orientation {
  position: absolute;
  bottom: 28px;
  right: 8px;
  width: 48px;
  height: 48px;
  z-index: 5;
  background: rgba(0,0,0,0.35);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.viewer-orientation canvas {
  width: 44px;
  height: 44px;
  display: block;
}
.viewer-ctrl-label {
  font-size: 0.6rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1;
}

/* Drafting mode */
.draft-msg {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.85);
  line-height: 1.4;
}
.draft-building {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.72rem;
  color: rgba(70,200,120,0.9);
}
.spinner-small {
  width: 14px; height: 14px;
  border: 2px solid rgba(70,200,120,0.3);
  border-top-color: rgba(70,200,120,0.9);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.draft-error {
  font-size: 0.72rem;
  color: rgba(255,100,100,0.8);
  margin-top: 4px;
}
.draft-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.draft-accept {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: rgba(60,180,80,0.6);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.draft-accept:hover { background: rgba(60,180,80,0.9); }
.draft-reject {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: rgba(200,60,60,0.4);
  color: rgba(255,255,255,0.8);
  border: none;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.draft-reject:hover { background: rgba(200,60,60,0.7); }
.viewer-ctrl-btn.mode-2d {
  background: rgba(70,130,180,0.5);
  color: #fff;
}

/* Axis legend */
.viewer-axis-legend {
  display: none; /* replaced by static .viewer-axis-ref SVG */
  position: absolute;
  bottom: 8px;
  right: 8px;
  gap: 6px;
  padding: 2px 6px;
  background: rgba(0,0,0,0.5);
  border-radius: 4px;
  z-index: 5;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
}
.axis-x { color: #ff4444; }
.axis-y { color: #44cc44; }
.axis-z { color: #4488ff; }

/* Transform dialog */
.transform-dialog {
  position: absolute;
  bottom: 36px;
  left: 8px;
  width: 180px;
  background: rgba(10,10,30,0.92);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  z-index: 15;
  overflow: hidden;
}
.transform-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: rgba(70,130,180,0.2);
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
}
.transform-dialog-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 2px;
}
.transform-dialog-close:hover { color: #fff; }

/* Copy mode banner */
.copy-mode-banner {
  position: absolute;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: rgba(0, 255, 136, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 255, 136, 0.3);
  border-radius: 6px;
  color: #00ff88;
  font-size: 0.7rem;
  font-weight: 600;
  z-index: 20;
  pointer-events: auto;
  white-space: nowrap;
}
.copy-mode-cancel {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.6rem;
  padding: 1px 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.copy-mode-cancel:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* Undo/Redo dimmed state */
#btnUndo, #btnRedo { transition: opacity 0.15s, background 0.15s, color 0.15s; }

.transform-section {
  padding: 4px 8px;
}
.transform-section-title {
  font-size: 0.62rem;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.transform-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
}
.transform-row label {
  width: 16px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  text-align: center;
  flex-shrink: 0;
}
.transform-row input {
  flex: 1;
  padding: 2px 5px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  color: #fff;
  font-size: 0.72rem;
  font-family: 'JetBrains Mono', monospace;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}
.transform-row input:focus { border-color: rgba(70,130,180,0.5); }

.viewer-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.35);
  font-size: 0.82rem;
  pointer-events: none;
}

/* --- Models Page --- */
.models-page {
  padding: 8px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.models-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.models-search {
  flex: 1;
}

.models-filter {
  width: 120px;
}

.models-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  overflow-y: auto;
  align-content: start;
}

.model-card {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.model-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.model-card-thumb {
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.model-card-thumb svg {
  width: 100%;
  height: 100%;
}

.model-card-body {
  padding: 6px 8px;
}

.model-card-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-color);
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 3px;
}

.model-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: var(--text-light);
  line-height: 1;
}

.format-badge {
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(70, 130, 180, 0.12);
  color: var(--primary-color);
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
}

.model-card-actions {
  display: flex;
  gap: 2px;
  padding: 3px 8px 6px;
}

.model-card-actions button {
  flex: 1;
  padding: 3px 0;
  border: none;
  border-radius: 4px;
  background: rgba(70, 130, 180, 0.08);
  color: var(--primary-color);
  font-size: 0.68rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
  line-height: 1;
}

.model-card-actions button:hover {
  background: rgba(70, 130, 180, 0.18);
}

.model-card-actions button.btn-danger {
  color: #c0392b;
  background: rgba(192, 57, 43, 0.08);
}

.model-card-actions button.btn-danger:hover {
  background: rgba(192, 57, 43, 0.18);
}

.models-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.82rem;
}


/* --- AI Mode Bar --- */
.ai-mode-bar {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 2px;
  flex-shrink: 0;
}
.ai-mode-btn {
  flex: 1;
  padding: 3px 8px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: rgba(255,255,255,0.6);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.ai-mode-btn.active {
  background: rgba(255,255,255,0.2);
  color: #fff;
}
.ai-mode-btn:hover { color: #fff; }

/* --- AI Chat --- */
.ai-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(20,20,40,0.85);
  border-radius: 8px;
  overflow: hidden;
  min-height: 0;
  width: 100%;
  box-sizing: border-box;
  position: relative;
}
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.ai-msg {
  max-width: 92%;
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 0.8rem;
  line-height: 1.35;
  word-wrap: break-word;
}
.ai-msg-system {
  align-self: center;
  background: rgba(70,130,180,0.2);
  color: rgba(255,255,255,0.7);
  font-style: italic;
  font-size: 0.75rem;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-system-clear {
  background: none;
  border: none;
  color: rgba(255,255,255,0.3);
  cursor: pointer;
  padding: 1px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  transition: color 0.12s, background 0.12s;
  flex-shrink: 0;
}
.ai-system-clear:hover {
  color: rgba(255,100,100,0.8);
  background: rgba(255,100,100,0.1);
}
.ai-msg-user {
  align-self: flex-end;
  background: rgba(70,130,180,0.4);
  color: #fff;
}
.ai-msg-ai {
  align-self: flex-start;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
}
.ai-msg-ai pre {
  background: rgba(0,0,0,0.4);
  border-radius: 4px;
  padding: 6px 8px;
  margin: 4px 0;
  overflow-x: auto;
  font-size: 0.72rem;
  line-height: 1.3;
  white-space: pre-wrap;
  font-family: 'JetBrains Mono', monospace;
}
.ai-msg-ai code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
}
.ai-msg-ai .ai-use-script {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 10px;
  background: rgba(70,130,180,0.5);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.ai-msg-ai .ai-use-script:hover { background: rgba(70,130,180,0.8); }
.ai-typing {
  display: inline-block;
  width: 6px; height: 6px;
  background: rgba(255,255,255,0.5);
  border-radius: 50%;
  animation: ai-blink 1s infinite;
  margin-right: 2px;
}
@keyframes ai-blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Chat input */
.ai-chat-input {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 4px 6px;
  background: rgba(0,0,0,0.3);
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.ai-chat-input textarea {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: #fff;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.3;
  min-height: 32px;
  max-height: 120px;
  overflow-y: auto;
  height: 32px;
}
.ai-chat-input textarea::placeholder { color: rgba(255,255,255,0.35); }
.ai-chat-input textarea:focus { border-color: rgba(70,130,180,0.5); }
.ai-send-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(70,130,180,0.6);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.ai-send-btn:hover { background: rgba(70,130,180,0.9); }
.ai-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Floating clear button (top-right of chat and editor) */
.panel-clear-btn {
  position: absolute;
  top: 28px;
  right: 4px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.06);
  border: none;
  border-radius: 4px;
  color: rgba(255,255,255,0.3);
  cursor: pointer;
  z-index: 5;
  padding: 0;
  transition: color 0.12s, background 0.12s;
}
.panel-clear-btn:hover {
  color: rgba(255,100,100,0.8);
  background: rgba(255,100,100,0.1);
}

/* Attach button */
.ai-input-btn {
  width: 32px; height: 32px;
  align-self: flex-end;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.06);
  border: none;
  border-radius: 6px;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.ai-input-btn:hover { background: rgba(70,130,180,0.3); color: #fff; }

/* Textarea wrapper with mic overlay */
.ai-textarea-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
  align-self: flex-end;
}
.ai-textarea-wrap textarea {
  width: 100%;
  padding-right: 28px;
  box-sizing: border-box;
}

/* Mic button */
.ai-mic-btn {
  position: absolute;
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(70,130,180,0.15);
  color: rgba(255,255,255,0.55);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.ai-mic-btn:hover { background: rgba(70,130,180,0.35); color: #fff; }
.ai-mic-btn.recording {
  background: rgba(220,50,50,0.25);
  color: #f66;
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,50,50,0.3); }
  50% { box-shadow: 0 0 0 5px rgba(220,50,50,0); }
}

/* Attachment badge */
.ai-attach-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  margin: 0 6px 2px;
  border-radius: 4px;
  background: rgba(70,130,180,0.15);
  color: rgba(255,255,255,0.8);
  font-size: 0.65rem;
  flex-shrink: 0;
}
.ai-attach-badge svg { flex-shrink: 0; color: rgba(70,130,180,0.8); }
.ai-attach-badge span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}
.ai-attach-badge button {
  border: none;
  background: none;
  color: rgba(255,100,100,0.7);
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0 2px;
}
.ai-attach-badge button:hover { color: #f66; }

/* --- Blocks Panel --- */
.blocks-panel {
  background: rgba(20,20,40,0.7);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}
.blocks-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  cursor: pointer;
  color: rgba(255,255,255,0.8);
  font-size: 0.75rem;
  font-weight: 600;
  transition: background 0.15s;
}
.blocks-header:hover { background: rgba(255,255,255,0.05); }
.blocks-header svg { flex-shrink: 0; }
.blocks-header span { flex: 1; }
.blocks-chevron { transition: transform 0.2s; }
.blocks-panel.open .blocks-chevron { transform: rotate(180deg); }
.blocks-body {
  display: none;
  padding: 4px 6px 6px;
  max-height: 280px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.blocks-panel.open .blocks-body { display: block; }

/* Filters */
.blocks-filters {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.blocks-filter-pill {
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15);
  background: transparent;
  color: rgba(255,255,255,0.6);
  font-size: 0.65rem;
  cursor: pointer;
  transition: all 0.12s;
}
.blocks-filter-pill.active,
.blocks-filter-pill:hover {
  background: rgba(70,130,180,0.3);
  color: #fff;
  border-color: rgba(70,130,180,0.5);
}

/* Block cards grid */
.blocks-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  margin-top: 6px;
}
.block-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1px 3px;
  padding: 3px 6px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  line-height: 1;
  overflow: hidden;
}
.block-card:hover { background: rgba(70,130,180,0.2); }
.block-card.selected { background: rgba(70,130,180,0.3); outline: 1px solid rgba(70,130,180,0.5); }
.block-card-icon {
  width: 20px; height: 20px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.block-card-icon svg { width: 16px; height: 16px; stroke: rgba(255,255,255,0.7); fill: none; stroke-width: 1.5; }
.block-card-name {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
/* Force badge to new line */
.block-card-badge-wrap {
  flex-basis: 100%;
  height: 0;
}
.block-card-badge {
  font-size: 0.5rem;
  padding: 0 4px;
  border-radius: 3px;
  background: rgba(70,130,180,0.25);
  color: rgba(255,255,255,0.55);
  margin-left: 23px;
  line-height: 1.2;
}

/* Params form */
.blocks-params {
  margin-top: 4px;
  padding: 4px 6px;
  background: rgba(0,0,0,0.2);
  border-radius: 5px;
}
.blocks-params-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  margin-bottom: 3px;
}
.blocks-param-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
}
.blocks-param-row label {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.65);
  width: 40%;
  text-align: right;
}
.blocks-param-row input {
  width: 40%;
  padding: 1px 4px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 3px;
  color: #fff;
  font-size: 0.68rem;
  outline: none;
}
.blocks-param-row input:focus { border-color: rgba(70,130,180,0.5); }
.blocks-param-row .param-unit {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.4);
  width: 20%;
}
.blocks-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.blocks-actions button {
  flex: 1;
  padding: 3px 8px;
  border: none;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}
.btn-block-generate {
  background: rgba(70,130,180,0.6);
  color: #fff;
}
.btn-block-generate:hover { background: rgba(70,130,180,0.9); }
.btn-block-add {
  background: rgba(60,160,80,0.5);
  color: #fff;
}
.btn-block-add:hover { background: rgba(60,160,80,0.8); }

/* Scene items */
.scene-items {
  margin-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 3px;
}
.scene-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 4px;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.7);
}
.scene-item-remove {
  background: none;
  border: none;
  color: rgba(255,100,100,0.6);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0 2px;
}
.scene-item-remove:hover { color: #f66; }

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.editor-label {
  flex: 1;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.78rem;
  font-weight: 600;
}

/* --- Code Editor --- */
.code-editor {
  width: 100%;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.85);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.4;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

.code-editor:focus {
  border-color: rgba(255, 255, 255, 0.35);
}

.code-editor-dark {
  background: #0d1117;
  border-color: rgba(255, 255, 255, 0.08);
  color: #c9d1d9;
  flex: 1;
  min-height: 200px;
}

.code-editor::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.code-editor-dark::placeholder {
  color: rgba(201, 209, 217, 0.35);
}

/* --- Output Log --- */
.output-log {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.output-log-header {
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
}

.output-log-content {
  padding: 6px 8px;
  max-height: 150px;
  overflow-y: auto;
  color: rgba(255, 255, 255, 0.7);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.3;
  white-space: pre-wrap;
  word-break: break-all;
}

/* --- Timeout Indicator --- */
.fc-timeout-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.75rem;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}



/* --- Forms --- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.form-group label {
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1;
}

.form-input {
  padding: 3px 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.78rem;
  font-family: var(--font-body);
  line-height: 1;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: rgba(255, 255, 255, 0.35);
}

.form-input option {
  background: #2c5171;
  color: #fff;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 3px 14px;
  border: none;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1;
  white-space: nowrap;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: #3a73a0;
}

.btn-outline {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.8);
}

.btn-outline:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.btn-sm {
  padding: 2px 10px;
  font-size: 0.72rem;
}

/* --- Slide Panels --- */
.slide-panel {
  position: fixed;
  top: 0;
  right: -45%;
  width: 45%;
  max-width: 400px;
  height: 100vh;
  background: rgba(30, 42, 56, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 200;
  transition: right 0.25s ease;
  display: flex;
  flex-direction: column;
}

.slide-panel.open {
  right: 0;
}

.slide-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
}

.slide-panel-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-size: 1.2rem;
  cursor: pointer;
  transition: background 0.12s;
}

.slide-panel-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

.slide-panel-body {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.78rem;
  line-height: 1.4;
}

.slide-panel-body h3 {
  font-size: 0.88rem;
  margin-bottom: 8px;
  color: #fff;
}

.slide-panel-body h4 {
  font-size: 0.8rem;
  margin-top: 12px;
  margin-bottom: 4px;
  color: rgba(255, 255, 255, 0.9);
}

.slide-panel-body p {
  margin-bottom: 6px;
  color: rgba(255, 255, 255, 0.7);
}
/* Block mini 3D preview in slide panel */
.block-preview-3d {
  position: relative;
  height: 200px;
  background: #f0f2f5;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  overflow: hidden;
}
.block-preview-3d canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  cursor: grab;
}
.block-preview-3d canvas:active { cursor: grabbing; }
.block-preview-refresh {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(70,130,180,0.4);
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  z-index: 5;
  transition: background 0.15s;
}
.block-preview-refresh:hover { background: rgba(70,130,180,0.8); }
.block-preview-axes {
  position: absolute;
  bottom: 4px;
  right: 4px;
  display: flex;
  gap: 4px;
  font-size: 0.6rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
}
.block-preview-dims {
  position: absolute;
  top: 4px;
  left: 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.block-preview-dims span {
  font-size: 0.58rem;
  font-family: 'JetBrains Mono', monospace;
  color: rgba(0,0,0,0.7);
  background: rgba(255,255,255,0.7);
  padding: 0 3px;
  border-radius: 2px;
}

/* Block info card (description + help) */
.block-info-card {
  background: rgba(70,130,180,0.08);
  border: 1px solid rgba(70,130,180,0.15);
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 8px;
}
.block-info-desc {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.7);
  margin-bottom: 4px;
  font-weight: 500;
}
.block-info-help {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.45);
  line-height: 1.35;
}

.slide-panel-footer {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.slide-panel-footer .btn {
  flex: 1;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}
.slide-panel-footer .btn-primary {
  background: rgba(70,130,180,0.7);
  color: #fff;
}
.slide-panel-footer .btn-primary:hover { background: rgba(70,130,180,1); }
.slide-panel-footer .btn-outline {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.8);
  border: 1px solid rgba(255,255,255,0.15);
}
.slide-panel-footer .btn-outline:hover { background: rgba(255,255,255,0.15); }

/* Scene management */
.ws-scene-actions {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}
.ws-scene-actions .btn { flex: 1; font-size: 0.65rem; padding: 2px 6px; }
.ws-scene-active {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  background: rgba(60,160,80,0.15);
  border: 1px solid rgba(60,160,80,0.3);
  border-radius: 4px;
  margin-bottom: 4px;
}
.ws-scene-active-name {
  font-size: 0.68rem;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  flex: 1;
}
.ws-scene-active-count {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.5);
}
.ws-scenes-list { display: flex; flex-direction: column; gap: 1px; }
.ws-scene-item {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 4px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.1s;
}
.ws-scene-item:hover { background: rgba(255,255,255,0.05); }
.ws-scene-item.active { background: rgba(60,160,80,0.15); }
.ws-scene-name {
  flex: 1;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ws-scene-date {
  font-size: 0.55rem;
  color: rgba(255,255,255,0.35);
  flex-shrink: 0;
}
.ws-scene-new-row {
  display: flex;
  gap: 3px;
  margin-bottom: 4px;
}

/* Scene items tree */
.scene-items-tree {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.scene-tree-title {
  font-size: 0.62rem;
  font-weight: 600;
  color: rgba(60,160,80,0.8);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.scene-tree-item {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 1px 2px;
  border-radius: 3px;
  transition: background 0.1s;
  line-height: 1;
}
.scene-tree-item:hover { background: rgba(255,255,255,0.04); }
.scene-tree-icon { flex-shrink: 0; color: rgba(255,255,255,0.4); display: flex; }
.scene-tree-name {
  flex: 1;
  font-size: 0.62rem;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scene-tree-name:hover { color: #fff; }
.scene-tree-name.scene-tree-group { color: rgba(255,255,255,0.5); font-style: italic; cursor: default; }
.scene-tree-toggle {
  flex-shrink: 0; cursor: pointer; display: flex; align-items: center;
  color: rgba(255,255,255,0.4); transition: transform 0.15s;
  transform: rotate(0deg);
}
.scene-tree-toggle.expanded { transform: rotate(90deg); }
.scene-tree-toggle:hover { color: #fff; }
.scene-tree-children { padding-left: 14px; }
.scene-tree-child { opacity: 0.85; }

/* Component properties panel */
.cp-field { display: flex; flex-direction: column; gap: 1px; margin-bottom: 6px; }
.cp-field label { font-size: 0.55rem; color: rgba(255,255,255,0.45); text-transform: uppercase; letter-spacing: 0.5px; }
.cp-input {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px; padding: 3px 6px; font-size: 0.65rem; color: #fff;
  outline: none; transition: border-color 0.15s;
}
.cp-input:focus { border-color: rgba(70,130,180,0.6); }
.cp-separator { height: 1px; background: rgba(255,255,255,0.08); margin: 8px 0; }
.cp-section-title { font-size: 0.58rem; color: rgba(70,130,180,0.8); font-weight: 600; margin-bottom: 6px; }
/* Origin menu */
.origin-menu {
  position: absolute; top: 36px; right: 0; z-index: 100;
  background: rgba(20,20,40,0.95); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  padding: 3px; min-width: 160px; white-space: nowrap;
}
.origin-menu button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: rgba(255,255,255,0.7);
  font-size: 0.62rem; padding: 4px 8px; border-radius: 3px; cursor: pointer;
}
.origin-menu button:hover { background: rgba(255,255,255,0.08); color: #fff; }

.cp-value {
  font-size: 0.65rem; color: rgba(255,255,255,0.7);
  font-family: 'JetBrains Mono', monospace; letter-spacing: 0.3px;
}
.cp-badge { display: inline-block; font-size: 0.5rem; padding: 0 3px; border-radius: 2px; background: rgba(70,130,180,0.25); color: rgba(255,255,255,0.6); margin-left: 3px; }
.scene-tree-pos {
  font-size: 0.5rem;
  font-family: 'JetBrains Mono', monospace;
  color: rgba(255,255,255,0.35);
  flex-shrink: 0;
}
.block-footer-row { display: flex; gap: 6px; }
.block-footer-row .btn { flex: 1; }
.block-save-row {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.block-save-input {
  flex: 1;
  padding: 4px 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 5px;
  color: #fff;
  font-size: 0.75rem;
  outline: none;
}
.block-save-input:focus { border-color: rgba(70,130,180,0.5); }
.block-save-input::placeholder { color: rgba(255,255,255,0.3); }
.btn-save {
  background: rgba(60,160,80,0.6) !important;
  color: #fff !important;
  white-space: nowrap;
}
.btn-save:hover { background: rgba(60,160,80,0.9) !important; }

/* Block param rows inside panel */
.block-param-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.block-param-row label {
  width: 40%;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.7);
  text-align: right;
}
.block-param-row input {
  flex: 1;
  padding: 4px 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 5px;
  color: #fff;
  font-size: 0.78rem;
  outline: none;
}
.block-param-row input:focus,
.block-param-row select:focus { border-color: rgba(70,130,180,0.5); }
.block-param-select {
  flex: 1;
  padding: 3px 6px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 5px;
  color: #fff;
  font-size: 0.75rem;
  outline: none;
  cursor: pointer;
}
.block-param-select option {
  background: #1a1a2e;
  color: #fff;
}
.block-param-row .param-unit {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.4);
  width: 30px;
  flex-shrink: 0;
}

/* --- Panel Backdrop --- */
.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 190;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.panel-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  bottom: 60px;
  right: 16px;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  z-index: 300;
}

.toast {
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(30, 42, 56, 0.95);
  backdrop-filter: blur(12px);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  animation: toastIn 0.25s ease;
  max-width: 340px;
}

.toast.toast-error {
  background: rgba(180,50,40,0.9);
}

.toast.toast-success {
  background: rgba(30,140,70,0.9);
}

.toast.toast-info {
  background: rgba(50,100,160,0.9);
}

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

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(20px); }
}

/* --- Delete Confirm Row --- */
.confirm-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
}

.confirm-row span {
  flex: 1;
  font-size: 0.72rem;
  color: #c0392b;
  line-height: 1;
}

/* === 3-PANEL WORKSPACE === */
.workspace {
  display: flex;
  flex-direction: row;
  height: 100%;
  overflow: hidden;
}

/* --- Sidebar --- */
.ws-sidebar,
.ws-center {
  width: 380px;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  background: rgba(15,15,35,0.85);
  backdrop-filter: blur(12px);
  border-radius: 12px;
  margin: 4px;
  margin-right: 6px;
  padding: 6px;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}
.ws-sidebar {
  gap: 2px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.ws-sidebar.collapsed {
  display: none;
}
.ws-center.collapsed {
  display: none;
}

/* Sidebar upload zone */
.ws-upload-zone {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px;
  margin: 6px;
  border: 1px dashed rgba(255,255,255,0.15);
  border-radius: 8px;
  cursor: pointer;
  color: rgba(255,255,255,0.5);
  transition: border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.ws-upload-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ws-upload-text span {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.6);
}
.ws-upload-text small {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.3px;
}
.ws-upload-zone:hover, .ws-upload-zone.drag-over {
  border-color: rgba(70,130,180,0.5);
  background: rgba(70,130,180,0.08);
  color: rgba(255,255,255,0.8);
}
.ws-upload-zone svg { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; }

/* Sidebar sections */
.ws-section {
  border-top: 1px solid rgba(255,255,255,0.04);
}
.ws-section-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  font-size: 0.7rem;
  font-weight: 600;
  transition: background 0.12s;
}
.ws-section-header:hover { background: rgba(255,255,255,0.04); }
.ws-section-header svg { width: 14px; height: 14px; flex-shrink: 0; stroke: currentColor; fill: none; }
.ws-section-header > span:not(.ws-section-badge) { flex: 1; }
.ws-section-badge {
  font-size: 0.5rem;
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(180,60,50,0.7);
  color: #fff;
  text-align: center;
  flex: none;
  font-weight: 600;
  line-height: 1.2;
  font-family: 'JetBrains Mono', monospace;
  display: inline-block;
}
.ws-chevron { transition: transform 0.2s; width: 12px; height: 12px; stroke: currentColor; fill: none; }
.ws-section.open .ws-chevron { transform: rotate(180deg); }
.ws-section-body {
  display: none;
  padding: 2px 6px 4px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
  flex: 1;
  min-height: 0;
}
.ws-section.open .ws-section-body { display: block; }
.ws-section.open { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Sidebar search */
.ws-search {
  width: 100%;
  padding: 2px 6px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 4px;
  color: #fff;
  font-size: 0.65rem;
  margin-bottom: 3px;
  outline: none;
  box-sizing: border-box;
}
.ws-search:focus { border-color: rgba(70,130,180,0.4); }
.ws-search::placeholder { color: rgba(255,255,255,0.3); }

/* Model list items */
.ws-models-list { display: flex; flex-direction: column; gap: 1px; }
.ws-model-item {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 4px;
  border-radius: 3px;
  transition: background 0.1s;
  line-height: 1;
}
.ws-model-item:hover { background: rgba(255,255,255,0.05); }
.ws-model-name {
  flex: 1;
  font-size: 0.63rem;
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ws-model-badge {
  font-size: 0.5rem;
  padding: 0 3px;
  border-radius: 3px;
  background: rgba(70,130,180,0.25);
  color: rgba(255,255,255,0.6);
  flex-shrink: 0;
}
.ws-model-action {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  border-radius: 3px;
  transition: color 0.1s, background 0.1s;
}
.ws-model-action:hover { color: rgba(255,255,255,0.9); background: rgba(255,255,255,0.08); }
.ws-model-action.danger:hover { color: #f66; background: rgba(255,80,80,0.1); }
.ws-model-action svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; }

/* --- Center Panel --- */
.ws-center {
  gap: 3px;
}

/* All center children fill width */
.ws-center > * {
  width: 100%;
  box-sizing: border-box;
}

/* Editor in center */
.ws-editor {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-height: 0;
  width: 100%;
  position: relative;
}
.ws-editor .code-editor {
  flex: 1;
  width: 100%;
  box-sizing: border-box;
  min-height: 60px;
  resize: none;
}

/* --- 3D Viewer --- */
.ws-viewer {
  flex: 1;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.ws-viewer .viewer-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.ws-viewer canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

#viewer2d {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  cursor: crosshair;
  background: #1a1a2e;
}
.toolbar-2d {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  gap: 4px;
  padding: 4px 8px;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  z-index: 10;
}
.toolbar-2d button {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(255,255,255,0.08);
  border: none;
  border-radius: 5px;
  color: rgba(255,255,255,0.8);
  font-size: 0.7rem;
  cursor: pointer;
  transition: background 0.12s;
}
.toolbar-2d button:hover { background: rgba(70,130,180,0.4); color: #fff; }
.toolbar-2d button svg { flex-shrink: 0; }

/* Viewer drop overlay */
.viewer-drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(70,130,180,0.15);
  border: 2px dashed rgba(70,130,180,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 10;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
}
.viewer-drop-overlay svg { width: 48px; height: 48px; stroke: rgba(255,255,255,0.6); fill: none; }

/* Conversion bar */
.viewer-convert-bar {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 4px 10px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  z-index: 5;
}
.viewer-convert-bar select {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 0.7rem;
}

/* Element tree overlay */
.viewer-element-tree {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 30vh;
  background: rgba(15,15,35,0.9);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255,255,255,0.1);
  z-index: 5;
  overflow: hidden;
}
.element-tree-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 8px;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  font-size: 0.7rem;
  font-weight: 600;
}
.element-tree-body {
  max-height: 25vh;
  overflow-y: auto;
  padding: 0 6px 4px;
}
.parts-tree-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.1s;
}
.parts-tree-item:hover { background: rgba(255,255,255,0.08); }
.parts-tree-item.selected { background: rgba(70,130,180,0.3); color: #fff; }
.parts-tree-item svg { flex-shrink: 0; color: rgba(255,255,255,0.4); }

/* --- Slide-panel tabs --- */
.sp-tabs {
  display: flex;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding: 0 12px;
  background: rgba(255,255,255,0.03);
  flex-shrink: 0;
}
.sp-tab {
  background: none;
  border: none;
  cursor: pointer;
  padding: 7px 13px;
  font-size: 0.68rem;
  font-weight: 700;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.2px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s;
  text-transform: uppercase;
}
.sp-tab.active { color: #6aafd2; border-bottom-color: #6aafd2; }
.sp-tab:hover:not(.active) { color: rgba(255,255,255,0.7); }
.sp-pane { display: none; }
.sp-pane.active { display: block; }

/* --- Slide-panel form elements --- */
.sp-form-group { margin-bottom: 10px; }
.sp-form-group label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 3px;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.2px;
}
.sp-input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 5px;
  font-size: 0.78rem;
  color: #fff;
  background: rgba(255,255,255,0.06);
  box-sizing: border-box;
}
.sp-input:focus { border-color: #6aafd2; outline: none; background: rgba(255,255,255,0.1); }
.sp-input option, .sp-input optgroup { background: #1e2a38; color: #fff; }
.sp-form-row { display: flex; gap: 6px; }
.sp-form-row .sp-input { flex: 1; }
.sp-separator { border-top: 1px solid rgba(255,255,255,0.08); margin: 12px 0; }
.sp-info { font-size: 0.75rem; color: rgba(255,255,255,0.5); }

/* --- Admin grid (inside panels) --- */
.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.admin-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.05);
  border-radius: 5px;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.8);
}
.admin-stat .status-ok { color: #2ecc71; }
.admin-stat .status-no { color: #e74c3c; }

/* --- Admin models table (inside panel) --- */
.admin-table { width: 100%; font-size: 0.72rem; border-collapse: collapse; }
.admin-table th {
  text-align: left; padding: 3px 4px; font-weight: 600;
  color: rgba(255,255,255,0.5); border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.3px;
}
.admin-table td { padding: 3px 4px; color: rgba(255,255,255,0.8); border-bottom: 1px solid rgba(255,255,255,0.04); }
.admin-table .btn-del {
  font-size: 0.62rem; padding: 1px 5px; background: rgba(231,76,60,0.15);
  color: #e74c3c; border: 1px solid rgba(231,76,60,0.25); border-radius: 4px; cursor: pointer;
}
.admin-table .btn-del:hover { background: rgba(231,76,60,0.3); }
.info-text { font-size: 0.75rem; color: rgba(255,255,255,0.5); }

/* --- Thread detail panel (stacked on admin) --- */
.thread-detail-panel { z-index: 210; }
.thread-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 5px; cursor: pointer;
  font-size: 0.72rem; color: rgba(255,255,255,0.8);
  transition: background 0.1s;
}
.thread-row:hover { background: rgba(255,255,255,0.06); }
.thread-row .thread-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-row .thread-meta { font-size: 0.65rem; color: rgba(255,255,255,0.4); white-space: nowrap; }
.thread-row .thread-mode {
  font-size: 0.6rem; padding: 1px 4px; border-radius: 3px;
  background: rgba(106,175,210,0.15); color: #6aafd2; white-space: nowrap;
}
.thread-row .btn-del { margin-left: 4px; }

/* Thread messages */
.thr-msg { margin-bottom: 10px; }
.thr-msg-role {
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.3px; margin-bottom: 2px;
}
.thr-msg-role.user { color: #6aafd2; }
.thr-msg-role.assistant { color: #2ecc71; }
.thr-msg-content {
  font-size: 0.75rem; color: rgba(255,255,255,0.85);
  line-height: 1.4; white-space: pre-wrap; word-break: break-word;
}
.thr-msg-content pre {
  background: rgba(0,0,0,0.3); padding: 6px 8px; border-radius: 5px;
  overflow-x: auto; font-size: 0.7rem; margin: 4px 0;
}
.thr-msg-content code { font-family: 'JetBrains Mono', monospace; font-size: 0.7rem; }
.thr-msg-time { font-size: 0.6rem; color: rgba(255,255,255,0.3); margin-top: 2px; }

/* (hamburger removed — panel toggles in navbar) */

/* --- Responsive --- */
@media (max-width: 1024px) {
  .slide-panel { width: 55%; right: -55%; max-width: none; }
}

@media (max-width: 768px) {
  .slide-panel { width: 85%; right: -85%; max-width: none; }
}

@media (max-width: 400px) {
  .app-header-title span { display: none; }
  .models-grid { grid-template-columns: 1fr; }
}

/* --- Block Parameter Sketches --- */
.block-sketch {
  text-align: center;
  margin-bottom: 6px;
  padding: 4px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
}
.block-sketch svg {
  max-width: 100%;
  height: auto;
}
.block-sketch text {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  fill: rgba(255,255,255,0.6);
}
.block-sketch .dim-h { stroke: #ff6666; fill: #ff6666; }
.block-sketch .dim-v { stroke: #66cc66; fill: #66cc66; }
.block-sketch .dim-t { stroke: #6699ff; fill: #6699ff; }
.block-sketch .shape { stroke: rgba(255,255,255,0.5); fill: none; stroke-width: 1; }
.block-sketch .dim-line { stroke-width: 0.5; }
.block-sketch .dim-arrow { stroke-width: 0.8; }

/* --- Secondary Viewer (CadQuery/FreeCAD) --- */
.viewer-secondary {
  min-height: 300px;
}

/* ============================================
   Estimation sidebar section
   ============================================ */
.est-actions {
  display: flex; gap: 4px; margin-bottom: 4px;
}
.est-content { font-size: 0.7rem; }
.est-empty { color: rgba(255,255,255,0.4); font-size: 0.65rem; }
.est-category { margin-bottom: 2px; }
.est-category.collapsed .est-cat-lines { display: none; }
.est-cat-header {
  display: flex; align-items: center; gap: 4px; padding: 2px 4px;
  background: rgba(255,255,255,0.04); border-radius: 3px; cursor: pointer;
  font-size: 0.65rem; font-weight: 600; color: rgba(255,255,255,0.85);
}
.est-cat-header:hover { background: rgba(255,255,255,0.08); }
.est-cat-name { flex: 1; }
.est-cat-badge {
  font-size: 0.55rem; background: rgba(44,81,113,0.5); color: rgba(255,255,255,0.7);
  padding: 0 4px; border-radius: 3px;
}
.est-cat-count {
  font-size: 0.55rem; color: rgba(255,255,255,0.4);
}
.est-cat-lines { padding: 1px 0 1px 8px; }
.est-line {
  display: flex; gap: 4px; align-items: baseline; padding: 1px 0;
  font-size: 0.6rem; color: rgba(255,255,255,0.65);
}
.est-line-desc { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.est-line-qty { white-space: nowrap; font-weight: 500; color: rgba(255,255,255,0.8); }
.est-line-wt { white-space: nowrap; font-size: 0.55rem; color: rgba(255,255,255,0.4); }
.est-export-row {
  display: flex; gap: 4px; margin-top: 4px; padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* Estimation factors panel */
.est-factor-row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 4px;
}
.est-factor-row label {
  flex: 1; font-size: 0.65rem; color: rgba(255,255,255,0.7);
}
.est-factor-input-wrap {
  display: flex; align-items: center; gap: 2px;
}
.est-factor-input {
  width: 48px; padding: 2px 4px; text-align: right;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 3px; color: #fff; font-size: 0.65rem;
}
.est-factor-input-wrap span { font-size: 0.6rem; color: rgba(255,255,255,0.4); }

/* ============================================
   Measurement labels & banner
   ============================================ */
.meas-label {
  position: absolute; top: 0; left: 0;
  background: rgba(44,81,113,0.9); color: #fff;
  font-size: 0.65rem; font-weight: 600; padding: 2px 6px;
  border-radius: 3px; white-space: nowrap; pointer-events: auto;
  transform-origin: 0 0; backdrop-filter: blur(4px);
  box-shadow: 0 1px 6px rgba(0,0,0,0.4); cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.meas-label:hover { background: rgba(44,81,113,1); box-shadow: 0 1px 8px rgba(0,0,0,0.6); }
.meas-label-selected {
  background: rgba(255,68,68,0.9); box-shadow: 0 0 8px rgba(255,68,68,0.5);
}
.meas-label-live {
  background: rgba(79,195,247,0.8); font-size: 0.6rem;
  pointer-events: none; cursor: default;
  animation: meas-pulse 0.8s ease-in-out infinite alternate;
}
@keyframes meas-pulse { from { opacity: 0.7; } to { opacity: 1; } }
.meas-status-banner {
  position: fixed; top: 49px; left: 50%; transform: translateX(-50%);
  background: rgba(44,81,113,0.9); color: #fff; padding: 3px 12px;
  border-radius: 0 0 6px 6px; font-size: 0.65rem; z-index: 200;
  display: flex; align-items: center; gap: 8px;
  backdrop-filter: blur(6px); box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
/* Transform dialog: coord mode toggle + apply */
.tf-mode-toggle {
  float: right; display: inline-flex; gap: 1px;
  background: rgba(0,0,0,0.3); border-radius: 3px; overflow: hidden;
}
.tf-mode-btn {
  background: transparent; border: none; color: rgba(255,255,255,0.5);
  font-size: 0.55rem; font-weight: 700; padding: 1px 6px; cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
}
.tf-mode-btn.active { background: rgba(79,195,247,0.4); color: #4FC3F7; }
.tf-mode-btn:hover { color: #fff; }
.tf-apply-row { justify-content: flex-end; margin-top: 2px; }
.tf-apply-btn { font-size: 0.6rem !important; padding: 2px 10px !important; }
.tf-separator { height: 1px; background: rgba(255,255,255,0.08); margin: 4px 0; }

/* Live coordinate badge (bottom-left of viewer) */
.viewer-coord-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 3px 6px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  border-radius: 4px;
  z-index: 5;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.58rem;
  color: rgba(255,255,255,0.5);
}
.coord-row { display: flex; align-items: center; gap: 6px; pointer-events: none; }
.coord-cam-row { pointer-events: auto; }
.coord-icon { font-size: 0.65rem; width: 14px; text-align: center; opacity: 0.5; }
.viewer-coord-badge b {
  color: rgba(255,255,255,0.8);
  font-weight: 600;
  min-width: 36px;
  display: inline-block;
  text-align: right;
}
.coord-edit {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 2px; color: rgba(255,255,255,0.8);
  font-family: 'JetBrains Mono', monospace; font-size: 0.55rem;
  width: 42px; padding: 0 2px; text-align: right;
}
.coord-edit:focus { border-color: rgba(79,195,247,0.5); outline: none; }
.meas-banner-cancel {
  background: rgba(255,255,255,0.15); border: none; color: #fff;
  padding: 1px 8px; border-radius: 3px; cursor: pointer; font-size: 0.6rem;
}
.meas-banner-cancel:hover { background: rgba(255,255,255,0.25); }

/* Active measurement button */
.viewer-ctrl-btn.active {
  background: rgba(44,81,113,0.6);
  box-shadow: 0 0 0 1px rgba(70,130,180,0.5);
}
