/* Main content */
.main-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: auto;
  /* Main scrollable container */
  position: relative;
}

.main-content-wrapper {
  display: flex;
  flex-direction: column;
  min-width: calc(var(--track-info-panel-width) + var(--max-number-of-bars) * var(--track-grid-bar-width));
  /* info width + grid width */
  min-height: fit-content;
  position: relative;
}

.top-left-spacer {
  position: fixed;
  top: 50px;
  left: 0;
  width: var(--track-info-panel-width);
  height: 40px;
  background-color: #2d2d2d;
  border-bottom: 1px solid #3a3a3a;
  border-right: 1px solid #3a3a3a;
  z-index: 1002;
  /* Higher than other elements to ensure it's always visible */
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

.track-header-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 12px;
  box-sizing: border-box;
}

.track-header-button {
  --toolbar-button-bg: transparent;
  --toolbar-button-fg: #e0e0e0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 3px;
  background-color: var(--toolbar-button-bg);
  color: var(--toolbar-button-fg);
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  justify-content: center;
  cursor: pointer;
  transition:
    background-color 0.18s ease,
    color 0.18s ease,
    transform 0.12s ease,
    box-shadow 0.18s ease;
}

.track-header-button svg {
  font-size: 14px;
}

.track-header-button:hover {
  --toolbar-button-bg: #3a3a3a;
}

.track-header-button.active {
  --toolbar-button-bg: #e0e0e0;
  --toolbar-button-fg: #2d2d2d;
}

.track-header-button.active:hover {
  --toolbar-button-bg: #f0f0f0;
}

.track-header-button:active {
  --toolbar-button-bg: #5a5a5a;
  transform: scale(0.95);
}

.track-header-button.active:active {
  --toolbar-button-bg: #d6d6d6;
}

.track-header-button:focus,
.track-header-button:focus-visible {
  outline: none;
  box-shadow: none;
}

/* Offset spacer when instrument selection panel is visible on the left */
.main-content.has-left-instrument .top-left-spacer {
  left: 300px;
}

.bar-numbers {
  position: sticky;
  top: 0;
  height: 40px;
  display: flex;
  border-bottom: 1px solid #3a3a3a;
  background-color: #2d2d2d;
  z-index: 20;
  margin-left: var(--track-info-panel-width);
  /* Offset for info-container */
  width: calc(var(--max-number-of-bars) * var(--track-grid-bar-width));
  /* Exact width for 32 bars */
  cursor: pointer;
  /* Show pointer cursor on hover to indicate interactivity */
}

.bar-numbers:hover {
  cursor: url("data:image/svg+xml,%3csvg width='16' height='16' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M4 6h8l-4 4-4-4z' fill='%23e0e0e0'/%3e%3c/svg%3e") 8 8, pointer;
}

.bar-number-cell {
  min-width: var(--track-grid-bar-width);
  width: var(--track-grid-bar-width);
  flex-shrink: 0;
  flex-grow: 0;
  height: 40px;
  border-right: 1px solid #3a3a3a;
  color: #999;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  position: relative;
}

.bar-number-label {
  height: 20px;
  text-align: center;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bar-beat-markers {
  position: relative;
  height: 20px;
  border-top: 1px solid #3a3a3a;
  border-bottom: 1px solid #3a3a3a;
  background-color: #1e1e1e;
  box-sizing: border-box;
}

.bar-boundary-marker {
  position: absolute;
  left: -1px;
  bottom: 0;
  width: 1px;
  height: 100%;
  background-color: #3a3a3a;
}

.beat-marker {
  position: absolute;
  bottom: 0;
  width: 1px;
  height: 50%;
  background-color: #3a3a3a;
  transform: translateX(-50%);
}

.bar-number-cell.looped {
  background-color: #e1ae01;
  color: #1e1e1e;
}

.main-content-body {
  display: flex;
  min-height: fit-content;
}

.global-tracks-section {
  display: flex;
  position: relative;
  z-index: 1003;
}

.global-tracks-info-shell,
.global-tracks-grid-shell {
  max-height: calc(var(--global-track-count) * var(--global-track-height));
  opacity: 1;
  transform: translateY(0);
  transition:
    max-height 0.22s ease,
    opacity 0.18s ease,
    transform 0.22s ease;
  will-change: max-height, opacity, transform;
}

.global-tracks-info-shell {
  position: sticky;
  left: 0;
  width: var(--track-info-panel-width);
  z-index: 1003;
  overflow: hidden;
  align-self: flex-start;
}

.global-tracks-grid-shell {
  overflow: hidden;
}

.global-tracks-grid-shell.expanded {
  overflow: visible;
}

.global-tracks-info-shell.collapsed,
.global-tracks-grid-shell.collapsed {
  max-height: 0;
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

.global-tracks-info {
  width: var(--track-info-panel-width);
  background-color: #2d2d2d;
  border-right: 1px solid #3a3a3a;
}

.global-track-info-row {
  height: var(--global-track-height);
  padding: 0 10px 0 12px;
  border-bottom: 1px solid #3a3a3a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  color: #e0e0e0;
  background-color: #4a4a4a;
}

.global-track-name {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.global-track-add-button {
  width: 16px;
  height: 16px;
  border: 1px solid #e0e0e0;
  border-radius: 999px;
  background: transparent;
  color: #e0e0e0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.global-track-add-button svg {
  font-size: 9px;
}

.global-track-add-button:focus,
.global-track-add-button:focus-visible {
  outline: none;
  box-shadow: none;
}

.global-tracks-grid {
  min-width: calc(var(--max-number-of-bars) * var(--track-grid-bar-width));
  background-color: #2d2d2d;
}

.global-track-grid-row {
  height: var(--global-track-height);
  min-width: calc(var(--max-number-of-bars) * var(--track-grid-bar-width));
  box-sizing: border-box;
  border-bottom: 1px solid #3a3a3a;
  background-color: #2d2d2d;
  background-size: var(--track-grid-bar-width) var(--global-track-height);
  background-image: linear-gradient(
    to right,
    transparent calc(var(--track-grid-bar-width) - 1px),
    #3a3a3a calc(var(--track-grid-bar-width) - 1px),
    #3a3a3a var(--track-grid-bar-width)
  );
}

.global-marker-lane {
  position: relative;
  height: var(--global-track-height);
  min-width: calc(var(--max-number-of-bars) * var(--track-grid-bar-width));
  box-sizing: border-box;
  border-bottom: 1px solid #3a3a3a;
  background-color: #2d2d2d;
  background-size: var(--track-grid-bar-width) var(--global-track-height);
  background-image: linear-gradient(
    to right,
    transparent calc(var(--track-grid-bar-width) - 1px),
    #3a3a3a calc(var(--track-grid-bar-width) - 1px),
    #3a3a3a var(--track-grid-bar-width)
  );
}

.global-key-signature-lane.popup-open {
  z-index: 1004;
}

.global-chord-lane.popup-open {
  z-index: 1004;
}

.global-marker-lane.pencil-cursor {
  cursor: crosshair;
}

.global-marker-region {
  position: absolute;
  top: 2px;
  height: calc(var(--global-track-height) - 4px);
  border: 2px solid transparent;
  border-radius: 6px;
  background: #e0e0e0;
  color: #2d2d2d;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  padding: 0 8px;
  overflow: hidden;
  user-select: none;
  cursor: grab;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  transition: box-shadow 0.1s ease, border-color 0.1s ease;
}

.global-marker-region.selected {
  border-color: #ffffff;
  box-shadow: none;
}

.global-marker-region:active {
  cursor: grabbing;
}

.global-key-signature-region {
  background: #d7f0c0;
  color: #24311c;
  overflow: visible;
}

.global-tempo-region {
  background: #dff2ff;
  color: #24314a;
}

.global-chord-region {
  background: #f6dfc8;
  color: #3d2f20;
  overflow: visible;
}

.global-chord-drag-feedback {
  position: fixed;
  z-index: 10020;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 999px;
  color: #1f1f1f;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(8px);
}

.global-chord-drag-feedback-import {
  background: rgba(196, 255, 207, 0.96);
}

.global-chord-drag-feedback-move {
  background: rgba(255, 241, 214, 0.96);
}

.global-chord-drag-feedback-blocked {
  background: rgba(255, 214, 214, 0.97);
}

.global-chord-drag-feedback-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  flex: 0 0 auto;
}

.global-chord-drag-feedback-label {
  white-space: nowrap;
}

.global-key-signature-region .floating-popup {
  min-width: 0;
  width: var(--track-grid-bar-width);
}

.global-key-signature-popup-anchor {
  min-width: 0;
  width: var(--track-grid-bar-width);
  position: absolute;
  left: calc((var(--track-grid-bar-width) - var(--track-grid-bar-width)) / 2);
  top: 50%;
  transform: translateY(-50%);
  z-index: 1008;
}

.global-key-signature-trigger {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.global-key-signature-popup-surface {
  z-index: 1007;
}

.global-key-signature-popup-anchor .floating-popup-surface {
  z-index: 1009;
}

.global-chord-region .floating-popup {
  min-width: 0;
  width: var(--track-grid-bar-width);
}

.global-chord-popup-anchor {
  min-width: 0;
  width: var(--track-grid-bar-width);
  position: absolute;
  left: calc((var(--track-grid-bar-width) - var(--track-grid-bar-width)) / 2);
  top: 50%;
  transform: translateY(-50%);
  z-index: 1008;
}

.global-chord-trigger {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.global-chord-popup-surface {
  --floating-popup-bg: #2d2d2d;
  --floating-popup-border: #555;
  z-index: 10007;
}

.global-chord-popup-anchor .floating-popup-surface {
  z-index: 10009;
}

.global-marker-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.global-marker-input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  font-family: inherit;
  padding: 0;
  outline: none;
}

.info-container {
  position: sticky;
  left: 0;
  width: var(--track-info-panel-width);
  z-index: 1002;
  background-color: #2d2d2d;
  align-self: flex-start;
}

/* Shift the bar numbers and info panel when instrument selection is present */
/* No need to shift bar numbers or info container; they live inside main content.
   Only shift the fixed spacer when the left panel is present. */

.track-top-spacer {
  height: 40px;
  border-bottom: 1px solid #3a3a3a;
  background-color: #2d2d2d;
  position: sticky;
  top: 0;
  z-index: 15;
}

.grid-container {
  margin-left: 0;
  /* No need for margin since we're using flex */
  min-width: calc(var(--max-number-of-bars) * var(--track-grid-bar-width));
  /* Ensure minimum width */
  min-height: fit-content;
  position: relative;
  /* Required for absolute positioned playhead */
}
