/* ─── Beat Mapper v1.0.0 — StemLabPro ─── */
/* Depends on stemlab-core.css for design tokens */

/* ═══════════════════════════════════════
   PAGE BACKGROUND
   ═══════════════════════════════════════ */
body:has(#beat-mapper-app),
html body:has(#beat-mapper-app) {
  background: var(--color-bg-base) !important;
  background-color: var(--color-bg-base) !important;
}

body:has(#beat-mapper-app) .elementor-element.e-con.e-parent,
body:has(#beat-mapper-app) .elementor-element.e-con {
  background-color: transparent !important;
  background-image: none !important;
}

/* ═══════════════════════════════════════
   APP WRAPPER
   ═══════════════════════════════════════ */
#beat-mapper-app {
  position: relative;
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: 'Satoshi', sans-serif;
  color: var(--color-text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════
   HEADER BAR
   ═══════════════════════════════════════ */
.bm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 20px;
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 100;
  flex-shrink: 0;
}

.bm-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.bm-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.bm-header-center {
  display: flex;
  align-items: center;
  gap: 20px;
}

.bm-transport {
  display: flex;
  align-items: center;
  gap: 4px;
}

.bm-transport-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.bm-transport-btn:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
}

.bm-play-btn {
  width: 36px;
  height: 36px;
  background: var(--color-accent);
  color: #fff;
  border-radius: 50%;
}

.bm-play-btn:hover {
  background: var(--color-accent-hover);
}

.bm-play-btn.playing {
  background: var(--color-accent-active);
}

.bm-time-display {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bm-time-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.bm-time-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
  font-weight: 500;
  color: var(--color-text-primary);
  letter-spacing: 0.02em;
}

.bm-header-right {
  display: flex;
  align-items: center;
}

.bm-export-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: transparent;
  color: var(--color-text-secondary);
  font-family: 'Satoshi', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.bm-export-btn:hover {
  border-color: var(--color-text-muted);
  color: var(--color-text-primary);
}

/* ═══════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════ */
.bm-main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ═══════════════════════════════════════
   INPUT PANEL (LEFT SIDEBAR)
   ═══════════════════════════════════════ */
.bm-input-panel {
  width: 260px;
  min-width: 260px;
  background: var(--color-bg-surface);
  border-right: 1px solid var(--color-border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  flex-shrink: 0;
}

.bm-panel-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bm-section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin: 0;
  padding: 0;
}

/* ═══════════════════════════════════════
   DROP ZONES
   ═══════════════════════════════════════ */
.bm-drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: transparent;
}

.bm-drop-zone:hover,
.bm-drop-zone.drag-over {
  border-color: var(--color-accent);
  background: rgba(240, 23, 111, 0.04);
}

.bm-drop-zone.has-file {
  border-color: var(--color-accent);
  border-style: solid;
}

.bm-drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.bm-drop-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.bm-drop-hint {
  font-size: 11px;
  color: var(--color-text-muted);
}

/* Stem info bar */
.bm-stem-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--color-bg-elevated);
  border-radius: 8px;
  font-size: 12px;
}

.bm-stem-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent);
  flex-shrink: 0;
}

.bm-stem-name {
  flex: 1;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bm-stem-dur {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--color-text-muted);
}

.bm-stem-remove {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}

.bm-stem-remove:hover {
  color: var(--color-accent);
}

/* Sample list */
.bm-sample-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bm-sample-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--color-bg-elevated);
  border-radius: 6px;
  font-size: 12px;
}

.bm-sample-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bm-sample-name {
  flex: 1;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bm-sample-preview,
.bm-sample-remove {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 2px;
  transition: color 0.15s;
}

.bm-sample-preview:hover {
  color: var(--color-accent);
}

.bm-sample-remove:hover {
  color: #EF4444;
}

/* ═══════════════════════════════════════
   DETECTION SETTINGS
   ═══════════════════════════════════════ */
.bm-setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--color-text-secondary);
}

.bm-setting-row label {
  width: 68px;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.bm-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--color-bg-elevated);
  outline: none;
}

.bm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: 2px solid var(--color-bg-surface);
}

.bm-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: 2px solid var(--color-bg-surface);
}

.bm-slider-val {
  width: 36px;
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--color-text-muted);
}

/* ═══════════════════════════════════════
   ANALYZE BUTTON
   ═══════════════════════════════════════ */
.bm-analyze-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover));
  color: #fff;
  font-family: 'Satoshi', sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
}

.bm-analyze-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(240, 23, 111, 0.35);
}

.bm-analyze-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ═══════════════════════════════════════
   PROGRESS
   ═══════════════════════════════════════ */
.bm-progress-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bm-progress-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--color-bg-elevated);
  overflow: hidden;
}

.bm-progress-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--color-accent);
  width: 0%;
  transition: width 0.3s;
}

.bm-progress-text {
  font-size: 11px;
  color: var(--color-text-muted);
  text-align: center;
}

/* ═══════════════════════════════════════
   RESULTS SUMMARY
   ═══════════════════════════════════════ */
.bm-results-summary {
  display: flex;
  justify-content: space-around;
  padding: 14px;
  background: var(--color-bg-elevated);
  border-radius: 10px;
}

.bm-result-stat {
  text-align: center;
}

.bm-stat-num {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--color-accent);
  font-family: 'JetBrains Mono', monospace;
}

.bm-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  font-weight: 600;
}

/* ═══════════════════════════════════════
   ARRANGEMENT PANEL (RIGHT)
   ═══════════════════════════════════════ */
.bm-arrangement-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--color-bg-base);
  min-width: 0;
  overflow: hidden;
}

.bm-arrangement-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--color-text-muted);
}

.bm-arrangement-empty h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin: 0;
}

.bm-arrangement-empty p {
  font-size: 13px;
  margin: 0;
}

/* ═══════════════════════════════════════
   TIMELINE RULER
   ═══════════════════════════════════════ */
.bm-timeline-ruler {
  height: 28px;
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border);
  overflow: hidden;
  flex-shrink: 0;
}

.bm-timeline-ruler canvas {
  display: block;
}

/* ═══════════════════════════════════════
   PLAYHEAD
   ═══════════════════════════════════════ */
.bm-playhead {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--color-accent);
  z-index: 50;
  pointer-events: none;
}

.bm-playhead::before {
  content: '';
  position: absolute;
  top: 0;
  left: -5px;
  width: 11px;
  height: 8px;
  background: var(--color-accent);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

/* ═══════════════════════════════════════
   TRACKS
   ═══════════════════════════════════════ */
.bm-tracks-container {
  flex: 1;
  overflow: auto;
  position: relative;
}

.bm-tracks-scroll {
  min-height: 100%;
  position: relative;
}

.bm-track-row {
  display: flex;
  height: 56px;
  border-bottom: 1px solid var(--color-border);
}

.bm-track-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--color-bg-surface);
  border-right: 1px solid var(--color-border);
  flex-shrink: 0;
  z-index: 10;
  position: sticky;
  left: 0;
}

.bm-track-color-bar {
  width: 3px;
  height: 32px;
  border-radius: 2px;
  flex-shrink: 0;
}

.bm-track-info {
  flex: 1;
  min-width: 0;
}

.bm-track-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bm-track-meta {
  font-size: 10px;
  color: var(--color-text-muted);
}

.bm-track-controls {
  display: flex;
  gap: 4px;
}

.bm-track-ctrl-btn {
  width: 22px;
  height: 22px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 9px;
  font-weight: 700;
  font-family: 'Satoshi', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.bm-track-ctrl-btn:hover {
  border-color: var(--color-text-muted);
  color: var(--color-text-primary);
}

.bm-track-ctrl-btn.muted {
  background: #EF4444;
  border-color: #EF4444;
  color: #fff;
}

.bm-track-ctrl-btn.soloed {
  background: #F59E0B;
  border-color: #F59E0B;
  color: #000;
}

/* ═══════════════════════════════════════
   CLIPS
   ═══════════════════════════════════════ */
.bm-track-clips {
  flex: 1;
  position: relative;
  min-width: 0;
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent calc(var(--beat-width, 50px) - 1px),
      rgba(255,255,255,0.02) calc(var(--beat-width, 50px) - 1px),
      rgba(255,255,255,0.02) var(--beat-width, 50px)
    );
}

.bm-clip {
  position: absolute;
  top: 4px;
  height: calc(100% - 8px);
  border-radius: 4px;
  overflow: hidden;
  cursor: grab;
  transition: box-shadow 0.15s;
  min-width: 3px;
}

.bm-clip:hover {
  box-shadow: 0 0 0 1px rgba(255,255,255,0.3);
}

.bm-clip.selected {
  box-shadow: 0 0 0 2px var(--color-accent);
}

.bm-clip.dragging {
  opacity: 0.8;
  cursor: grabbing;
  z-index: 20;
}

.bm-clip-inner {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.bm-clip-waveform {
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0.7;
}

.bm-clip-label {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 9px;
  font-weight: 600;
  color: rgba(255,255,255,0.8);
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  pointer-events: none;
}

/* Trim handles */
.bm-trim-handle {
  position: absolute;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 5;
}

.bm-trim-handle-left { left: 0; }
.bm-trim-handle-right { right: 0; }

.bm-trim-handle:hover,
.bm-trim-handle.active {
  background: rgba(255,255,255,0.15);
}

/* ═══════════════════════════════════════
   TOOL SELECTOR
   ═══════════════════════════════════════ */
.bm-tool-selector {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 4px;
  padding: 6px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 60;
}

.bm-tool-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.bm-tool-btn:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
}

.bm-tool-btn.active {
  background: var(--color-accent);
  color: #fff;
}

/* ═══════════════════════════════════════
   CONTEXT MENU
   ═══════════════════════════════════════ */
.bm-context-menu {
  position: fixed;
  padding: 6px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 200;
  min-width: 160px;
}

.bm-ctx-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-secondary);
  font-family: 'Satoshi', sans-serif;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}

.bm-ctx-item:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
}

.bm-ctx-danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #EF4444;
}

/* Split tool cursor */
.bm-arrangement-panel.tool-split .bm-track-clips {
  cursor: crosshair;
}

/* ═══════════════════════════════════════
   MOBILE PANEL BUTTON
   ═══════════════════════════════════════ */
.bm-mobile-panel-btn {
  display: none;
}

/* ═══════════════════════════════════════
   RESPONSIVE — MOBILE
   ═══════════════════════════════════════ */
@media (max-width: 768px) {
  .bm-input-panel {
    position: fixed;
    left: 0;
    top: 52px;
    bottom: 0;
    width: 280px;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .bm-input-panel.open {
    transform: translateX(0);
  }

  .bm-mobile-panel-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px;
    padding: 10px 16px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-bg-surface);
    color: var(--color-text-secondary);
    font-family: 'Satoshi', sans-serif;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
  }

  .bm-track-header {
    width: 80px !important;
    min-width: 80px !important;
    padding: 0 6px;
  }

  .bm-track-name {
    font-size: 10px;
  }

  .bm-track-controls {
    display: none;
  }

  .bm-header {
    padding: 0 12px;
  }

  .bm-export-btn span {
    display: none;
  }
}

@media (max-width: 480px) {
  .bm-track-header {
    width: 60px !important;
    min-width: 60px !important;
  }

  .bm-track-meta {
    display: none;
  }
}
