:root {
  --bg-header: #f5f5f5;
  --text-header: #222;
  --bg-editor: #ffffff;
  --text-editor: #000000;
  --bg-viewer: #eeeeee;
  --text-viewer: #222;
  --bg-resizer: #ccc;
  --btn-bg: #ddd;
  --scrollbar-bg: #ddd;
  --scrollbar-thumb: #aaa;
  --viewer-bg-color: #eeeeee;
}

body.light {
  --bg-header: #222;
  --text-header: white;
  --bg-editor: #1e1e1e;
  --text-editor: #d4d4d4;
  --bg-viewer: #2c2c2c;
  --text-viewer: white;
  --bg-resizer: #555;
  --btn-bg: #444;
  --scrollbar-bg: #555;
  --scrollbar-thumb: #888;
  --viewer-bg-color: #2c2c2c;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: sans-serif;
  overflow: hidden;
}

header {
  height: 50px;
  background-color: var(--bg-header);
  color: var(--text-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

header .left, header .right {
  display: flex;
  align-items: center;
  gap: 15px;
  justify-content: space-between;
}

header button {
  background: var(--btn-bg);
  color: var(--text-header);
  border: none;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 14px;
}

.separator {
  margin: 0 10px;
  color: #888;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tools-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 50px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  border-radius: 50px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:checked + .slider:before {
  transform: translateX(14px);
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 10px;
}

main {
  display: flex;
  height: calc(100% - 50px);
  width: 100%;
  overflow: auto;
}

.editor {
  width: 30%;
  flex-shrink: 0;
  flex-grow: 0;
  background: var(--bg-editor);
  color: var(--text-editor);
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.monaco-scrollable-element > .scrollbar > .slider {
  border-radius: 4px;
  background: var(--scrollbar-thumb, #888);
  box-shadow: none;
}

.monaco-scrollable-element > .scrollbar > .slider::before {
  display: none;
}

.myLineHighlight {
  background-color: rgba(100, 180, 255, 0.2);
}

/* Styl dla wyłączonych linii - zaciemnienie */
.disabled-line {
  background-color: rgba(128, 128, 128, 0.15) !important;
  opacity: 0.5;
}

.disabled-line .mtk1 {
  color: #666 !important;
}

.resizer {
  width: 8px;
  background: var(--bg-resizer);
  cursor: col-resize;
}

.viewer {
  flex: 1 1 auto;
  min-width: 100px;
  background: var(--bg-viewer);
  color: var(--text-viewer);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  font-size: 1.2rem;
}

.viewer-info {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 8px 12px;
  background-color: rgba(0, 0, 0, 0.75);
  color: var(--text-viewer);
  font-family: monospace;
  font-size: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.viewer-info-toggle {
  width: 20px;
  height: 20px;
  padding: 0;
  color: #b8d8ff;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 20px;
  margin-left: auto;
}

.viewer-info-header {
  align-self: stretch;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 20px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  cursor: grab;
  user-select: none;
  touch-action: none;
  font-size: 0.78rem;
  font-weight: bold;
}

.viewer-info-header span {
  margin-bottom: 0;
}

.viewer-info.is-dragging .viewer-info-header {
  cursor: grabbing;
}

.viewer-info.is-collapsed {
  min-width: 20px;
  min-height: 20px;
  padding: 3px 4px;
}

.viewer-info.is-collapsed .viewer-info-header {
  padding-bottom: 0;
  border-bottom: 0;
}

.viewer-info.is-collapsed .viewer-info-body {
  display: none;
}

.viewer-info.is-hidden,
#virtualPreviewPanel.is-hidden {
  display: none;
}

.viewer-info-body {
  padding-right: 14px;
}

.viewer-info span {
  margin-bottom: 4px;
}

.stock-size-control {
  width: 100%;
  margin-top: 4px;
  padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.stock-size-title {
  display: block;
  font-size: 0.72rem;
  opacity: 0.85;
}

.stock-size-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stock-size-actions {
  display: flex;
  gap: 4px;
}

#estimateStockBtn {
  padding: 2px 5px;
  color: #fff;
  background: rgba(33, 150, 243, 0.45);
  border: 1px solid rgba(144, 202, 249, 0.7);
  border-radius: 3px;
  cursor: pointer;
  font: 0.68rem/1.2 monospace;
}

#estimateStockBtn:hover {
  background: rgba(33, 150, 243, 0.7);
}

#baseSetupBtn {
  padding: 2px 5px;
  color: #fff;
  background: rgba(215, 25, 32, 0.55);
  border: 1px solid rgba(255, 150, 150, 0.7);
  border-radius: 3px;
  cursor: pointer;
  font: 0.68rem/1.2 monospace;
}

#baseSetupBtn:hover {
  background: rgba(215, 25, 32, 0.8);
}

.base-setup-modal {
  position: absolute;
  inset: 0;
  z-index: 40;
  padding: 20px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.base-setup-modal.is-hidden {
  display: none;
}

.base-setup-window {
  position: absolute;
  top: 20px;
  left: 20px;
  width: min(520px, 100%);
  max-height: min(620px, 100%);
  display: flex;
  flex-direction: column;
  color: #fff;
  background: rgba(0, 0, 0, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 7px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  font: 0.78rem/1.25 monospace;
  pointer-events: auto;
}

.base-setup-header,
.base-setup-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.25);
}

.base-setup-header {
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.base-setup-window.is-dragging .base-setup-header {
  cursor: grabbing;
}

.base-setup-close {
  margin-left: auto;
  width: 24px;
  height: 24px;
  padding: 0;
  color: #fff;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 1.2rem;
}

.base-setup-content {
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
}

.base-setup-row {
  margin-bottom: 8px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
}

.base-setup-row.is-active {
  border-color: rgba(255, 90, 90, 0.8);
  background: rgba(215, 25, 32, 0.12);
}

.base-setup-row-heading,
.base-setup-fields {
  display: flex;
  align-items: center;
  gap: 6px;
}

.base-setup-row-heading {
  margin-bottom: 5px;
  font-weight: bold;
}

.base-setup-row-heading select {
  flex: 1 1 auto;
}

.base-pick-button {
  flex: 0 0 auto;
  padding: 3px 6px;
  color: #fff;
  background: rgba(33, 150, 243, 0.45);
  border: 1px solid rgba(120, 200, 255, 0.65);
  border-radius: 3px;
  cursor: crosshair;
  font: inherit;
}

.base-setup-row.is-active .base-pick-button {
  background: rgba(215, 25, 32, 0.62);
  border-color: rgba(255, 130, 130, 0.85);
}

.base-setup-fields label {
  display: flex;
  align-items: center;
  gap: 3px;
}

.base-setup-fields input,
.base-setup-fields select,
.base-setup-row-heading select {
  min-width: 0;
  box-sizing: border-box;
  padding: 3px 4px;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  font: inherit;
}

.base-setup-fields input {
  width: 72px;
}

.base-setup-hint {
  margin-top: 8px;
  color: #ffaaaa;
  font-size: 0.7rem;
}

.base-setup-spacer {
  flex: 1 1 auto;
}

.base-setup-footer button {
  padding: 4px 8px;
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  cursor: pointer;
  font: inherit;
}

.base-setup-footer button:last-child {
  background: rgba(33, 150, 243, 0.65);
}

.stock-shape-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin: 3px 0 6px;
  font: 0.72rem/1 monospace;
}

.stock-shape-label select {
  min-width: 88px;
  padding: 2px 4px;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  font: inherit;
}

.stock-size-fields {
  display: flex;
  gap: 5px;
}

.stock-size-fields label {
  display: flex;
  align-items: center;
  gap: 2px;
  font: 0.72rem/1 monospace;
}

.stock-size-fields input {
  width: 50px;
  box-sizing: border-box;
  padding: 3px 4px;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  font: inherit;
}

.stock-size-fields input:focus {
  outline: 1px solid #2196f3;
  border-color: #2196f3;
}

.stock-size-fields .is-hidden {
  display: none;
}

.model-quality-control {
  display: block;
  margin-top: 8px;
  font: 0.7rem/1.2 monospace;
}

.model-quality-control > span:first-child,
.model-quality-scale {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.model-quality-control output {
  color: #b7dcff;
}

.model-quality-control input {
  display: block;
  width: 100%;
  height: 14px;
  margin: 3px 0 0;
  accent-color: #42a5f5;
  cursor: pointer;
}

.model-quality-scale {
  opacity: 0.72;
  font-size: 0.62rem;
}

.detail-height-estimate {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  color: #ffbf55;
  font: 0.72rem/1.2 monospace;
}

.detail-height-estimate.is-hidden {
  display: none;
}

.base-rotation-controls {
  width: auto;
  min-width: 0;
  max-width: 164px;
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.base-rotation-controls.is-hidden {
  display: none;
}

.base-rotation-title {
  font-size: 0.68rem;
  opacity: 0.85;
}

.base-rotation-row {
  display: grid;
  grid-template-columns: 28px 31px 48px;
  align-items: center;
  gap: 3px;
  margin-top: 3px;
  font: 0.66rem/1 monospace;
}

.base-rotation-row select,
.base-rotation-row input {
  min-width: 0;
  width: 100%;
  height: 20px;
  box-sizing: border-box;
  padding: 1px 2px;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  font: inherit;
}

.base-rotation-row select {
  appearance: auto;
  cursor: pointer;
}

#viewer {
  position: relative;
  width: 100%;
}

#viewerSlider {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 10px;
  background-color: #ddd;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 5px;
  outline: none;
}

#viewerProgressInfo {
  position: absolute;
  z-index: 30;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 40px);
  padding: 5px 10px;
  color: #fff;
  background: rgba(12, 17, 23, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 5px;
  font: 12px/1.2 monospace;
  white-space: nowrap;
  pointer-events: none;
}

#viewerProgressInfo.is-hidden {
  display: none;
}

#viewerSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background-color: #007bff;
  border-radius: 50%;
  cursor: pointer;
}

#viewerSlider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background-color: #007bff;
  border-radius: 50%;
  cursor: pointer;
}

.tools-panel {
  position: absolute;
  bottom: 60px;
  left: 10px;
  z-index: 1;
  background-color: rgba(0, 0, 0, 0.75);
  color: white;
  padding: 10px 15px;
  border-radius: 6px;
  font-size: 0.9rem;
  max-height: 250px;
  overflow-y: auto;
  min-width: 160px;
  width: min(420px, calc(100vw - 20px));
  max-width: calc(100vw - 20px);
  box-sizing: border-box;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.tools-panel.is-hidden {
  display: none;
}

.tools-panel .tool-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.2);
  position: sticky;
  top: -10px;
  z-index: 3;
  padding-top: 10px;
  background-color: rgba(0, 0, 0, 0.92);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.tools-panel.is-dragging .tool-header {
  cursor: grabbing;
}

.tools-panel .tool-header span {
  font-weight: bold;
  font-size: 0.9rem;
}

.tools-panel .sort-buttons {
  display: flex;
  gap: 4px;
}

.tools-panel .panel-toggle {
  color: #b8d8ff;
  background: transparent;
  border: 0;
  padding: 2px 5px;
  cursor: pointer;
  font-size: 0.8rem;
}

.tools-panel.is-collapsed .tools-panel-body {
  display: none;
}

.tools-panel-body {
  display: block;
}

.tools-panel .sort-buttons button {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.7rem;
  transition: background 0.2s;
}

.tools-panel .sort-buttons button:hover {
  background: rgba(255,255,255,0.3);
}

.tools-panel .sort-buttons button.active {
  background: rgba(33, 150, 243, 0.5);
  border-color: #2196F3;
}

.tools-panel .tool-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 3px 0;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
}

.tools-panel .tool-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.tools-panel .tool-item input[type="checkbox"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.tools-panel .tool-label {
  font-family: monospace;
  font-size: 0.85rem;
  color: #ddd;
}

.tools-panel .tool-description {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: #aeb8c4;
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tools-panel .tool-count {
  font-size: 0.7rem;
  color: #888;
  margin-left: auto;
  flex-shrink: 0;
}

.tools-panel .tool-depth {
  font-family: monospace;
  font-size: 0.72rem;
  color: #b8d8ff;
  white-space: nowrap;
  flex-shrink: 0;
}

.tools-panel .tool-parameters-toggle {
  width: 20px;
  height: 20px;
  padding: 0;
  color: #b8d8ff;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 20px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.tools-panel .tool-parameters-toggle.is-expanded {
  transform: rotate(90deg);
}

.tools-panel .tool-parameters-inline {
  margin: 0 0 6px 28px;
}

.tool-preview-panel {
  position: absolute;
  right: 10px;
  top: 50px;
  z-index: 2;
  width: min(420px, calc(100% - 20px));
  height: min(440px, calc(100% - 70px));
  overflow: hidden;
  background: #171b21;
  color: white;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.tool-preview-panel.is-hidden {
  display: none;
}

.tool-preview-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  height: 56px;
  padding: 0 9px;
  box-sizing: border-box;
  border-bottom: 1px solid rgba(255,255,255,0.16);
  font-size: 0.72rem;
  font-weight: bold;
}

.tool-preview-caption {
  color: #9caabb;
  font-size: 0.65rem;
  font-weight: normal;
  white-space: nowrap;
}

.tool-preview-export {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 4px 8px;
  color: #fff;
  background: rgba(33, 150, 243, 0.5);
  border: 1px solid rgba(144, 202, 249, 0.65);
  border-radius: 4px;
  font: 0.66rem/1.1 monospace;
  cursor: pointer;
}

.tool-preview-export:hover:not(:disabled) {
  background: rgba(33, 150, 243, 0.78);
}

.tool-preview-export:disabled {
  opacity: 0.45;
  cursor: default;
}

.tool-preview-progress {
  position: absolute;
  z-index: 5;
  top: 50%;
  left: 50%;
  width: min(310px, calc(100% - 40px));
  padding: 12px 14px;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  color: #eaf4ff;
  background: rgba(10, 14, 20, 0.92);
  border: 1px solid rgba(144, 202, 249, 0.5);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  text-align: center;
  font: 0.72rem/1.35 sans-serif;
}

.tool-preview-progress.is-hidden {
  display: none;
}

.tool-preview-progress-track {
  height: 8px;
  margin: 9px 0 5px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 5px;
}

.tool-preview-progress-value {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #1976d2, #42a5f5);
  border-radius: inherit;
  transition: width 0.12s linear;
}

.tool-preview-progress.is-error {
  border-color: rgba(239, 83, 80, 0.7);
  color: #ffcdd2;
}

.tool-preview-progress.is-error .tool-preview-progress-value {
  background: #ef5350;
}

#toolPreviewCanvas {
  width: 100%;
  height: calc(100% - 56px);
}

.tools-panel .tool-order {
  font-size: 0.65rem;
  color: #666;
  margin-right: 4px;
  min-width: 24px;
  text-align: right;
}

.tool-parameters-item {
  margin-top: 4px;
  padding: 8px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
}

.tool-parameters-item label {
  display: block;
  color: #aaa;
  font-size: 0.68rem;
  margin-top: 5px;
}

.tool-parameters-item input {
  box-sizing: border-box;
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 3px 5px;
  color: #eee;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 3px;
  font-size: 0.72rem;
}

.tool-parameters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 6px;
}

.tool-parameters-save {
  width: 100%;
  margin-top: 8px;
  padding: 4px 6px;
  color: white;
  background: #1976d2;
  border: 0;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.7rem;
}

.tool-parameters-item.is-saved .tool-parameters-save {
  background: #2e7d32;
}

.tool-parameters-empty {
  color: #888;
  font-size: 0.75rem;
  margin-top: 6px;
}

@media (max-width: 768px) {
  .resizer,
  .viewer {
    display: none;
  }

  .editor {
    width: 100%;
  }
}

/* Select All row */
.tools-panel .select-all-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 8px 4px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tools-panel .select-all-row input[type="checkbox"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: #2196F3;
}

.tools-panel .select-all-row label {
  font-size: 0.75rem;
  color: #aaa;
  cursor: pointer;
  user-select: none;
}

.tools-panel .select-all-row label:hover {
  color: #fff;
}

.machine-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  white-space: nowrap;
}

.machine-control select {
  background: var(--btn-bg);
  color: var(--text-header);
  border: 1px solid var(--bg-resizer);
  border-radius: 3px;
  padding: 4px 6px;
  cursor: pointer;
}

#parserStatus.has-warnings {
  color: #ffb74d;
  cursor: help;
}
