:root {
  --bg-deep: #0c0e12;
  --bg-panel: #141820;
  --bg-elevated: #1a2030;
  --border: #2a3348;
  --text: #e8ecf4;
  --text-muted: #8b95a8;
  --accent: #00d4aa;
  --accent-dim: #00a888;
  --danger: #f05252;
  --danger-hover: #ff6b6b;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --font-sans: "Outfit", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-deep);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  color: var(--accent);
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.settings-dialog,
.app-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  max-height: calc(100vh - 2rem);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  color: var(--text);
  padding: 0;
  max-width: 400px;
  width: calc(100% - 2rem);
  box-shadow: var(--shadow);
  overflow: auto;
}

.settings-dialog::backdrop,
.app-dialog::backdrop {
  background: rgba(6, 8, 12, 0.65);
}

.settings-dialog-form,
.app-dialog-form {
  display: flex;
  flex-direction: column;
}

.settings-dialog-head,
.app-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
}

.settings-dialog-head h2,
.app-dialog-head h2 {
  font-size: 1rem;
  font-weight: 600;
}

.settings-dialog-close,
.app-dialog-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.35rem;
}

.settings-dialog-close:hover,
.app-dialog-close:hover {
  color: var(--text);
}

.settings-dialog-body,
.app-dialog-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.settings-dialog-body .module-hint,
.app-dialog-body .module-hint {
  margin-bottom: 0.35rem;
}

.app-dialog-body .field-label {
  margin-top: 0.35rem;
}

.app-dialog-body .save-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.settings-dialog-foot,
.app-dialog-foot {
  padding: 0.75rem 1rem 1rem;
  display: flex;
  justify-content: flex-end;
}

.btn {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: #232b3d;
  border-color: #3d4a66;
}

.btn-secondary {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.btn-secondary:hover {
  background: rgba(0, 212, 170, 0.1);
}

.btn-secondary.is-active,
.btn-secondary[aria-pressed="true"] {
  background: rgba(0, 212, 170, 0.18);
  border-color: var(--accent);
  color: var(--text);
}

#btn-placeholders[aria-pressed="false"] {
  opacity: 0.8;
}

.btn-danger {
  border-color: transparent;
  background: rgba(240, 82, 82, 0.15);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(240, 82, 82, 0.25);
  color: var(--danger-hover);
}

.btn-block {
  width: 100%;
  margin-top: 0.35rem;
}

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

.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
}

.toolbar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.settings-bar {
  width: 250px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  margin: 10px 12px 10px 8px;
  padding: 12px 14px;
  border-radius: var(--radius);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.settings-empty,
.settings-content {
  padding: 10px;
  min-width: 0;
}

.settings-empty-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 0.5rem;
}

.settings-content {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.settings-bar .param-grid,
.settings-bar .dim-grid {
  gap: 0.75rem;
}

.settings-bar .dim-field {
  gap: 1rem 1.25rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.settings-bar .dim-field input,
.settings-bar .pos-grid input,
.settings-bar .input-number {
  width: auto;
  flex: 1 1 64px;
  min-width: 52px;
  max-width: 100%;
  padding: 6px 8px;
}

.settings-bar .dim-field--compact input {
  min-width: 48px;
  max-width: 72px;
}

.settings-bar .dim-field--choice select {
  flex: 1 1 100%;
  min-width: 0;
  padding: 6px 8px;
}

.settings-bar .dim-field input[type="text"] {
  flex: 1 1 100%;
  min-width: 0;
  max-width: 100%;
  font-family: var(--font-ui, inherit);
}

.settings-bar .ebene-row {
  padding: 12px 14px;
  gap: 0.5rem 0.75rem;
}

.settings-bar .derived-info {
  padding: 12px 14px;
}

.settings-bar .field-label {
  margin-top: 0.85rem;
}

.settings-bar .selection-actions {
  margin-top: 1rem;
  padding-top: 12px;
}

.tool-group-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.tool-group-subtitle {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 1rem 0 0.4rem;
}

.bauteile-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 220px;
  overflow-y: auto;
}

.bauteile-list-empty {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0;
}

.bauteil-done-btn {
  display: block;
  width: 100%;
  margin-bottom: 0.4rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 22%, var(--bg-elevated));
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-sans);
}

.bauteil-done-btn:hover {
  background: color-mix(in srgb, var(--accent) 35%, var(--bg-elevated));
}

.bauteil-list-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font-sans);
}

.bauteil-list-item:hover {
  border-color: var(--accent);
}

.bauteil-list-item.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--bg-elevated));
  box-shadow: inset 3px 0 0 var(--accent);
}

.bauteil-list-item small {
  display: block;
  color: var(--text-muted);
  font-size: 0.7rem;
  margin-top: 0.15rem;
}

.viewport-wrapper.placing-bauteil {
  cursor: crosshair;
}

.primitive-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.primitive-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font-sans);
  transition: all 0.15s;
  text-align: left;
}

.primitive-btn:hover {
  border-color: var(--accent);
  background: rgba(0, 212, 170, 0.08);
  color: var(--accent);
}

.primitive-btn--compact {
  padding: 0.35rem 0.55rem;
  gap: 0.45rem;
  font-size: 0.72rem;
}

.primitive-btn--compact .primitive-icon {
  font-size: 0.85rem;
  width: 1rem;
}

.primitive-icon {
  font-size: 1.1rem;
  width: 1.5rem;
  text-align: center;
  color: var(--accent);
}

.selection-name {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.field-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0.6rem 0 0.35rem;
}

.module-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
  line-height: 1.4;
}

.param-grid,
.dim-grid {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.derived-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0.5rem 0.6rem;
  background: var(--bg-elevated);
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 0.65rem;
}

.derived-info strong {
  color: var(--accent);
}

.field-group-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0.5rem 0 0.25rem;
}

.segment-export-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.65rem 0 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.segment-export-btn {
  font-size: 0.75rem;
  padding: 0.4rem 0.5rem;
}

.dim-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  gap: 0.5rem;
}

.dim-field--boolean {
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 0.5rem;
}

.dim-field--boolean input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

.dim-field--choice select {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.8rem;
}

.dim-field input,
.pos-grid input,
.input-number {
  width: 64px;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.ebenen-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.ebene-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
}

.ebene-row-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  min-width: 4.5rem;
}

.ebene-row--pick {
  flex-wrap: nowrap;
  gap: 0.5rem;
}

.ebene-row-pick {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 0.25rem 0;
  border: none;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.ebene-row-pick:hover {
  text-decoration: underline;
}

.ebene-row-meta {
  flex: 0 1 auto;
  font-size: 0.68rem;
  color: var(--text-muted, #8a93a3);
  white-space: nowrap;
}

.bauteil-back-btn {
  margin-bottom: 0.35rem;
}

.dim-field--compact {
  font-size: 0.72rem;
  gap: 0.35rem;
}

.dim-field--compact input {
  width: 52px;
}

.ebene-remove {
  padding: 0.15rem 0.45rem;
  min-width: auto;
  line-height: 1.2;
}

.pos-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.pos-grid label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

#color-picker {
  width: 100%;
  height: 36px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
}

.selection-actions {
  margin-top: 0.75rem;
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.mode-btn {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(0, 212, 170, 0.08);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  margin-bottom: 0.5rem;
  user-select: none;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  width: 36px;
  height: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle input:checked + .toggle-track {
  background: rgba(0, 212, 170, 0.2);
  border-color: var(--accent);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: var(--accent);
}

.viewport-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1rem;
  background: var(--bg-deep);
}

.viewport-wrapper {
  flex: 1;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  min-height: 0;
}

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

#viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-top: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-bar .hint {
  margin-left: auto;
  opacity: 0.7;
}

.save-name-input,
.save-select {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
}

.save-name-input:focus,
.save-select:focus {
  outline: none;
  border-color: var(--accent);
}

.save-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.save-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  line-height: 1.35;
  min-height: 1.2em;
}

.auth-status {
  font-size: 0.8rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

@media (max-width: 768px) {
  .workspace {
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
    max-height: 45vh;
  }

  .status-bar .hint {
    display: none;
  }
}
