:root {
  --border: #ccc;
  --accent: #2166ac;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: Arial, "PingFang TC", "Heiti TC", "Microsoft JhengHei", sans-serif;
  font-size: 14px;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

#folderLabel {
  color: #444;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#apiWarning {
  color: #b00020;
  font-weight: bold;
}

.topbar-spacer {
  flex: 1;
}

.icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

#app {
  position: relative;
  display: flex;
  height: calc(100% - 41px);
}

#sidebar {
  width: 280px;
  min-width: 220px;
  border-right: 1px solid var(--border);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  transition: width 0.15s ease, min-width 0.15s ease, padding 0.15s ease, border-width 0.15s ease;
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  border-right-width: 0;
}

.group {
  padding: 0;
}

.group-title {
  font-weight: bold;
  margin-bottom: 6px;
}

#searchInput {
  width: 100%;
  height: 28px;
  padding: 2px 6px;
  margin-bottom: 6px;
}

.filter-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.filter-row #searchInput {
  margin-bottom: 0;
}

.btn-row {
  display: flex;
  gap: 6px;
}

.btn-row button {
  flex: 1;
  height: 30px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

#fileList {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}

#fileList label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#fileList label:hover {
  background: #f2f6fb;
}

#fileList .swatch {
  width: 12px;
  height: 12px;
  flex: none;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

#fileList .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#fileList .file-error-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  color: #999;
  cursor: not-allowed;
  white-space: nowrap;
  overflow: hidden;
}

#fileList .status-icon {
  flex: none;
  color: #b00020;
}

#chartArea {
  position: relative;
  flex: 1;
  display: flex;
  padding: 10px;
  min-width: 0;
}

#chart {
  flex: 1;
  min-width: 0;
}

.chart-tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  max-width: 260px;
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tooltip-swatch {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 2px;
}

.tooltip-x {
  margin-top: 4px;
  color: #666;
  padding-top: 4px;
}

#pipelinePanel {
  width: 300px;
  min-width: 240px;
  border-left: 1px solid var(--border);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  transition: width 0.15s ease, min-width 0.15s ease, padding 0.15s ease, border-width 0.15s ease;
}

#pipelinePanel.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  border-left-width: 0;
}

@media (max-width: 1000px) {
  #sidebar,
  #pipelinePanel {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 6;
    background: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  }

  #sidebar { left: 0; }
  #pipelinePanel { right: 0; }

  #sidebar.collapsed,
  #pipelinePanel.collapsed {
    box-shadow: none;
  }
}

.pipeline-group {
  display: flex;
  flex-direction: column;
  flex: none;
}

.pipeline-list {
  list-style: none;
  margin: 0;
  padding: 4px 4px 28px;
  border-radius: 4px;
  background: #f7f7f7;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 40px;
}

.pipeline-list.drag-over {
  background: #f2f6fb;
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.block-card {
  border-left: 4px solid var(--block-color, var(--border));
  border-radius: 4px;
  background: #fafafa;
  padding: 6px 8px;
  cursor: grab;
  user-select: none;
}

.block-card:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.block-card.dragging {
  opacity: 0.4;
}

.block-card.drag-over {
  box-shadow: 0 0 0 2px var(--accent) inset;
}

.block-card .block-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: bold;
  font-size: 13px;
  margin-bottom: 4px;
}

.block-card .block-order {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--block-color, var(--accent));
  color: #fff;
  font-size: 10px;
  font-weight: normal;
  display: flex;
  align-items: center;
  justify-content: center;
}

.block-card .block-params {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.block-card .param-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
}

.block-card .param-row input,
.block-card .param-row select {
  width: 92px;
  height: 22px;
  font-size: 12px;
}

.grid line {
  stroke: #ccc;
  stroke-opacity: 0.5;
  shape-rendering: crispEdges;
}

.grid path {
  stroke-width: 0;
}

.series-line {
  fill: none;
  stroke-width: 1.4;
}

.peak-point {
  stroke: #fff;
  stroke-width: 0.6;
}

.peak-label {
  font-size: 10px;
  text-anchor: middle;
  pointer-events: none;
}

.axis-label {
  font-size: 13px;
  fill: #222;
}

.chart-title {
  font-size: 15px;
  font-weight: bold;
  fill: #111;
}
