/* === BUILDER LAYOUT === */
.builder-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 41px); /* below nav */
  overflow: hidden;
}

/* === TOOLBAR === */
.builder-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.toolbar-label {
  font-size: 0.75rem;
  color: #7d8590;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 0.25rem;
}

.palette-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.35rem 0.6rem;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #e6edf3;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

.palette-btn:hover {
  background: #30363d;
}

.palette-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.freeride-swatch {
  background: repeating-linear-gradient(
    45deg,
    #484f58,
    #484f58 2px,
    #30363d 2px,
    #30363d 4px
  );
}

.toolbar-field {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-field label {
  font-size: 0.7rem;
  color: #7d8590;
  text-transform: uppercase;
}

.toolbar-field input {
  width: 65px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 4px;
  padding: 0.3rem 0.4rem;
  color: #e6edf3;
  font-size: 0.85rem;
  text-align: center;
}

.toolbar-field input:focus {
  outline: none;
  border-color: #f97316;
}

.toolbar-unit {
  font-size: 0.8rem;
  color: #7d8590;
}

.toolbar-btn {
  padding: 0.35rem 0.65rem;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #e6edf3;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

.toolbar-btn:hover {
  background: #30363d;
}

.toolbar-btn.accent {
  background: #f97316;
  border-color: #f97316;
  color: #fff;
}

.toolbar-btn.accent:hover {
  background: #ea580c;
}

.toolbar-btn.danger {
  color: #f85149;
  border-color: #f8514933;
}

.toolbar-btn.danger:hover {
  background: #3d1117;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: #30363d;
}

/* === SUMMARY BAR === */
.builder-summary {
  padding: 0.4rem 1rem;
  background: #0d1117;
  border-bottom: 1px solid #21262d;
  font-size: 0.8rem;
  color: #7d8590;
}

.builder-summary span:not(.summary-sep) {
  color: #e6edf3;
  font-weight: 600;
}

.summary-sep {
  margin: 0 0.5rem;
  color: #30363d !important;
  font-weight: 400 !important;
}

/* === CHART AREA === */
.chart-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  background: #0d1117;
}

/* Y-axis */
.y-axis {
  width: 50px;
  flex-shrink: 0;
  position: relative;
  border-right: 1px solid #21262d;
  background: #0d1117;
}

.y-label {
  position: absolute;
  right: 6px;
  font-size: 0.65rem;
  color: #484f58;
  transform: translateY(-50%);
  white-space: nowrap;
}

/* Scrollable chart - hidden scrollbar, pan to scroll */
.chart-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.chart-scroll::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.chart-scroll.panning {
  cursor: grabbing;
}

.chart-scroll.panning * {
  pointer-events: none;
}

.chart-canvas {
  position: relative;
  height: 100%;
  min-width: 100%;
}

/* Zone grid lines */
.zone-grid {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 28px; /* room for time axis */
  pointer-events: none;
  z-index: 1;
}

.zone-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed #21262d;
  z-index: 1;
}

.zone-line.ftp-line {
  border-top: 1px solid #f9731644;
}

.zone-band-label {
  position: absolute;
  right: 8px;
  font-size: 0.6rem;
  color: #30363d;
  transform: translateY(-50%);
  pointer-events: none;
}

/* Blocks row */
.blocks-row {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 28px;
  display: flex;
  align-items: flex-end;
  z-index: 2;
}

/* Individual block */
.b-block {
  position: relative;
  height: 100%;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  cursor: pointer;
  border-right: 1px solid #0d1117;
  user-select: none;
  transition: opacity 0.1s;
}

.b-block:hover {
  opacity: 0.9;
}

.b-block.selected {
  outline: 2px solid #f97316;
  outline-offset: -2px;
  z-index: 5;
}

/* Block bar (filled portion) */
.b-bar {
  width: 100%;
  position: relative;
  border-radius: 2px 2px 0 0;
  transition: none;
}

.b-bar.freeride-bar {
  background: repeating-linear-gradient(
    45deg,
    #484f58,
    #484f58 3px,
    #30363d 3px,
    #30363d 6px
  ) !important;
}

/* Labels on blocks */
.b-label-duration {
  position: absolute;
  bottom: 4px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.65rem;
  color: #ffffffbb;
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
  overflow: hidden;
}

.b-label-power {
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #ffffffdd;
  pointer-events: none;
  text-shadow: 0 1px 3px #000;
  white-space: nowrap;
  overflow: hidden;
}

/* Resize handles */
.resize-h-duration {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: ew-resize;
  z-index: 10;
}

.resize-h-power {
  position: absolute;
  top: -4px;
  left: 8px;
  right: 8px;
  height: 8px;
  cursor: ns-resize;
  z-index: 10;
}

/* Ramp corner handles */
.resize-h-ramp-start {
  position: absolute;
  left: -2px;
  width: 10px;
  height: 10px;
  cursor: ns-resize;
  z-index: 11;
  background: #f9731688;
  border-radius: 50%;
  border: 1px solid #f97316;
  transform: translate(0, -50%);
}

.resize-h-ramp-end {
  position: absolute;
  right: -2px;
  width: 10px;
  height: 10px;
  cursor: ns-resize;
  z-index: 11;
  background: #f9731688;
  border-radius: 50%;
  border: 1px solid #f97316;
  transform: translate(0, -50%);
}

.b-block:not(.selected) .resize-h-ramp-start,
.b-block:not(.selected) .resize-h-ramp-end {
  display: none;
}

/* Time axis */
.time-axis {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 28px;
  display: flex;
  align-items: center;
  pointer-events: none;
  z-index: 3;
}

.time-tick {
  position: absolute;
  font-size: 0.6rem;
  color: #484f58;
  transform: translateX(-50%);
  white-space: nowrap;
}

/* Drop target highlight */
.chart-scroll.drop-target {
  outline: 2px dashed #f97316;
  outline-offset: -2px;
  background: #f973160a;
}

/* Drag ghost from palette */
.drag-ghost {
  position: fixed;
  transform: translate(-50%, -50%);
  padding: 0.4rem 0.8rem;
  background: #f97316;
  color: #fff;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
  box-shadow: 0 4px 12px #00000066;
}

/* Reorder ghost */
.reorder-ghost {
  position: fixed;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 200;
  opacity: 0.5;
  overflow: hidden;
  border-radius: 4px;
  box-shadow: 0 4px 16px #00000066;
}

/* Insertion indicator line */
.insert-indicator {
  position: absolute;
  top: 0;
  bottom: 28px;
  width: 3px;
  background: #f97316;
  border-radius: 2px;
  z-index: 20;
  pointer-events: none;
  display: none;
  box-shadow: 0 0 8px #f9731688;
}

/* Empty state - centered in the scroll viewport */
.chart-empty-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 0;
  pointer-events: none;
}

.chart-empty {
  text-align: center;
  color: #484f58;
  font-size: 0.95rem;
  pointer-events: none;
  white-space: nowrap;
}

.chart-empty-hint {
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

/* === FOOTER === */
.builder-footer {
  padding: 0.5rem 1rem;
  background: #161b22;
  border-top: 1px solid #30363d;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.builder-footer input {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  color: #e6edf3;
  font-size: 0.85rem;
}

.builder-footer input:focus {
  outline: none;
  border-color: #f97316;
}

/* === EDIT POPUP === */
.edit-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #00000088;
  z-index: 100;
  justify-content: center;
  align-items: center;
}

.edit-overlay.visible {
  display: flex;
}

.edit-popup {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 1.5rem;
  width: 340px;
  max-width: 90vw;
}

.edit-popup h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: #f0f6fc;
}

.edit-field {
  margin-bottom: 0.75rem;
}

.edit-field label {
  display: block;
  font-size: 0.7rem;
  color: #7d8590;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.3rem;
}

.edit-field select,
.edit-field input {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  color: #e6edf3;
  font-size: 0.9rem;
}

.edit-field select {
  width: 100%;
}

.edit-field select:focus,
.edit-field input:focus {
  outline: none;
  border-color: #f97316;
}

.edit-duration-row,
.edit-power-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.edit-duration-row input {
  width: 60px;
  text-align: center;
}

.edit-power-row input {
  width: 70px;
  text-align: center;
}

.edit-power-row span {
  font-size: 0.8rem;
  color: #7d8590;
}

.edit-watts {
  margin-left: auto;
  font-size: 0.8rem;
  color: #7d8590;
}

.edit-zone-indicator {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 1rem;
  text-align: center;
}

.edit-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.edit-actions .btn {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.btn-danger {
  background: #3d1117;
  color: #f85149;
  border: 1px solid #f8514944;
}

.btn-danger:hover {
  background: #5a1a1a;
}

/* === RESPONSIVE === */
@media (max-width: 800px) {
  .builder-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar-right {
    width: 100%;
    justify-content: flex-start;
  }

  .y-axis {
    width: 36px;
  }
}
