/* ========================================
   LAYOUT REORGANIZATION STYLES
   Wide two-column layout - everything visible at once
   ======================================== */

/* WIDE TWO-COLUMN LAYOUT */
.dashboard main {
  display: grid !important;
  grid-template-columns: 280px 1fr !important;
  max-width: 100% !important;
  width: 100% !important;
  height: calc(100vh - 80px) !important;
  padding: 16px !important;
  gap: 20px !important;
  overflow: hidden !important;
}

/* ====== LEFT SIDEBAR: BASIC CONTROLS (COMPACT VERTICAL) ====== */
.dash-column.dash-column-left {
  width: 280px !important;
  max-width: 280px !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 12px !important;
  order: 1 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding-right: 8px !important;
}

/* Compact styling for left column cards */
.dash-column-left .dash-card {
  margin: 0 !important;
  padding: 12px !important;
  background: rgba(0, 0, 0, 0.4) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.dash-column-left .card-label {
  font-size: 10px !important;
  margin-bottom: 8px !important;
}

/* ====== RIGHT AREA: MAIN CONTENT (WIDE) ====== */
.dash-column.dash-column-right {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 20px !important;
  order: 2 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding-right: 8px !important;
}

/* Ensure the card container doesn't constrain width */
.dash-column-right .card-user-presets {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
}

/* Hide the old full piano roll */
.piano-roll-container {
  display: none !important;
}

.piano-roll-full-width {
  display: none !important;
}

/* ====== SIMPLE CHORD PIANO WITH CONNECTING LINES ====== */
.chord-visualizer {
  width: 100% !important;
  padding: 20px !important;
  background: transparent !important;
  border-radius: 0 !important;
  border: none !important;
  margin-top: 16px !important;
  position: relative !important;
  min-height: 120px !important;
}

#simplePianoCanvas {
  width: 100% !important;
  height: 120px !important;
  display: block !important;
  background: #000000 !important;
  border: 1px solid #2a2a2a !important;
  border-radius: 6px !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6) !important;
  cursor: pointer !important;
}

/* ====== VOICE CARDS SECTION (HORIZONTAL ROW - FULL WIDTH) ====== */
.voice-cards-section {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
}

.voice-cards-horizontal {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  justify-content: flex-start !important;
  align-items: stretch !important;
  gap: 16px !important;
  padding: 16px !important;
  background: linear-gradient(135deg, #1a1a2e 0%, #0a0a0a 100%) !important;
  border-radius: 10px !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  overflow-x: visible !important;
  overflow-y: visible !important;
  scroll-snap-type: none !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

/* Force the container to respect flex layout */
.voice-cards-section .voice-cards-horizontal {
  display: flex !important;
  overflow: visible !important;
}

.voice-card {
  flex: 1 1 0 !important;
  min-width: 0 !important;
  max-width: none !important;
  width: auto !important;
  margin: 0 !important;
  flex-shrink: 1 !important;
  flex-grow: 1 !important;
  flex-basis: 0 !important;
  box-sizing: border-box !important;
}

/* Force override the piano-roll-styles.css with higher specificity */
.voice-cards-horizontal .voice-card {
  min-width: 0 !important;
  flex-shrink: 1 !important;
  flex-grow: 1 !important;
  flex-basis: 0 !important;
}

/* Even more specific override - this should definitely win */
.voice-cards-section .voice-cards-horizontal .voice-card {
  min-width: 0 !important;
  flex-shrink: 1 !important;
  flex-grow: 1 !important;
  flex-basis: 0 !important;
  width: auto !important;
  max-width: none !important;
}

/* Nuclear option - using dash-column class for maximum specificity */
.dash-column-right .voice-cards-section .voice-cards-horizontal .voice-card {
  min-width: 0 !important;
  flex-shrink: 1 !important;
  flex-grow: 1 !important;
  flex-basis: 0 !important;
}

/* Ensure stereo-preview grid is equal width */
.stereo-preview {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 8px !important;
}

/* Make stereo layers clickable with hover effect - BIGGER */
.stereo-layer {
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  border-radius: 8px !important;
  padding: 16px !important;
  margin: 8px 0 !important;
  background: rgba(0, 0, 0, 0.3) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}

.stereo-layer:hover {
  background: rgba(0, 217, 255, 0.15) !important;
  transform: translateX(4px) !important;
  border-left: 4px solid #00D9FF !important;
}

.stereo-layer .layer-label {
  font-size: 12px !important;
  font-weight: 700 !important;
  margin-bottom: 8px !important;
}

.stereo-layer .layer-source {
  font-size: 11px !important;
  margin-top: 8px !important;
}

.stereo-layer .mini-waveform {
  margin: 8px 0 !important;
}

/* ABSOLUTE NUCLEAR OVERRIDE - Apply at all breakpoints */
@media (min-width: 1px) {
  .voice-card {
    min-width: 0 !important;
    flex: 1 1 0 !important;
    flex-shrink: 1 !important;
    flex-grow: 1 !important;
    flex-basis: 0 !important;
  }

  .voice-cards-horizontal .voice-card {
    min-width: 0 !important;
    flex: 1 1 0 !important;
  }

  .voice-cards-section .voice-cards-horizontal .voice-card {
    min-width: 0 !important;
    flex: 1 1 0 !important;
  }
}

/* ====== GLOBAL CONTROLS (WIDE HORIZONTAL GRID) ====== */
.global-controls-section {
  width: 100% !important;
  flex-shrink: 0 !important;
  margin: 0 !important;
  padding: 16px !important;
  background: linear-gradient(135deg, #1a1a2e 0%, #0a0a0a 100%) !important;
  border-radius: 10px !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.global-controls-horizontal {
  display: grid !important;
  grid-template-columns: repeat(4, 1fr) !important;
  gap: 16px !important;
  width: 100% !important;
  padding: 0 !important;
  background: transparent !important;
  border-radius: 0 !important;
  margin: 0 !important;
}

.control-group-compact {
  background: rgba(0, 0, 0, 0.5) !important;
  padding: 16px !important;
  border-radius: 8px !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  transition: all 0.2s ease;
  min-width: 0 !important;
}

.control-group-compact:hover {
  background: rgba(0, 0, 0, 0.6) !important;
  border-color: rgba(0, 217, 255, 0.4) !important;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 217, 255, 0.15);
}

.control-group-compact .section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #00D9FF;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(0, 217, 255, 0.2);
}

/* Envelope controls - horizontal */
.envelope-controls-h {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Filter controls */
.filter-controls-h {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Effects grid - compact */
.effects-grid-compact {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.effect-row-compact {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
}

.effect-row-compact .effect-label {
  flex: 0 0 80px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
}

.effect-row-compact .effect-toggle {
  flex: 0 0 60px;
}

.effect-row-compact .param-control-inline {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.effect-row-compact .param-slider-sm {
  flex: 1;
}

/* Performance controls */
.performance-controls-h {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.bass-mode-btn {
  flex: 1;
  padding: 8px;
  font-size: 10px;
}

/* ====== TOP CONTROLS BAR ====== */
.top-controls-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-start;
  padding: 16px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  margin-bottom: 16px;
}

.top-control-group {
  flex: 1;
  min-width: 150px;
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.top-control-group .card-label {
  font-size: 10px;
  margin-bottom: 8px;
}

/* Compact mode selector */
.mode-grid-compact {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.mode-btn-compact {
  padding: 6px 4px;
  font-size: 9px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn-compact:hover {
  background: rgba(0, 217, 255, 0.1);
  border-color: #00D9FF;
}

.mode-btn-compact.active {
  background: #00D9FF;
  color: #000;
  font-weight: 700;
}

/* Compact key selector */
.key-grid-compact {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.key-btn-compact {
  padding: 6px 2px;
  font-size: 9px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
}

.key-btn-compact:hover {
  background: rgba(0, 217, 255, 0.1);
}

.key-btn-compact.active {
  background: #00D9FF;
  color: #000;
  font-weight: 700;
}

/* Preset selector compact */
.preset-section-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preset-selector-btn-compact {
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.preset-selector-btn-compact:hover {
  border-color: #00D9FF;
}

/* ====== RESPONSIVE ADJUSTMENTS ====== */
@media (max-width: 1600px) {
  .global-controls-horizontal {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media (max-width: 1200px) {
  .dashboard main {
    grid-template-columns: 240px 1fr !important;
  }

  .dash-column-left {
    width: 240px !important;
    max-width: 240px !important;
  }

  .voice-cards-horizontal {
    flex-wrap: wrap !important;
  }

  .voice-card {
    flex: 1 1 45% !important;
    min-width: 150px !important;
  }
}

@media (max-width: 900px) {
  .dashboard main {
    grid-template-columns: 1fr !important;
    height: auto !important;
    overflow: visible !important;
    max-height: none !important;
  }

  .dash-column-left {
    width: 100% !important;
    max-width: 100% !important;
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    gap: 12px !important;
    overflow-y: visible !important;
    max-height: none !important;
  }

  .dash-column-right {
    overflow-y: visible !important;
    overflow-x: visible !important;
    max-height: none !important;
  }

  .global-controls-horizontal {
    grid-template-columns: 1fr !important;
  }

  /* Ensure content is visible */
  .card-user-presets {
    overflow: visible !important;
  }

  .preset-sample-row,
  .sample-options-header,
  .sample-options-row {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
}

@media (max-width: 600px) {
  .voice-cards-horizontal {
    flex-direction: column !important;
  }

  .voice-card {
    flex: 1 1 100% !important;
  }
}

/* ====== MOBILE OPTIMIZATIONS (TABLET AND BELOW) ====== */
@media (max-width: 768px) {
  /* Fix layout to allow scrolling */
  .dashboard {
    min-height: 100vh !important;
    height: auto !important;
  }

  .dashboard main {
    height: auto !important;
    overflow: visible !important;
    max-height: none !important;
  }

  .dash-column {
    overflow: visible !important;
    max-height: none !important;
  }

  /* Override inline styles that force nowrap */
  .voice-cards-horizontal {
    flex-wrap: wrap !important;
    gap: 12px !important;
    padding: 12px !important;
  }

  .voice-card {
    flex: 1 1 calc(50% - 6px) !important;
    min-width: 140px !important;
    max-width: none !important;
  }

  /* Allow stereo layers to stack */
  .stereo-preview {
    grid-template-columns: 1fr !important;
  }

  .stereo-layer {
    padding: 12px !important;
  }

  /* Increase font sizes for readability */
  body {
    font-size: 14px !important;
  }

  .card-label {
    font-size: 11px !important;
  }

  .param-label, .effect-label {
    font-size: 12px !important;
  }

  /* Increase touch targets */
  .btn-bpm, .key-btn, .mode-btn, .octave-btn-compact {
    min-height: 44px !important;
    font-size: 12px !important;
  }

  .effect-toggle {
    min-height: 40px !important;
    padding: 8px 14px !important;
  }

  /* Stack sample options vertically */
  .sample-options-row {
    flex-direction: column !important;
    display: flex !important;
  }

  .sample-option-card {
    width: 100% !important;
    display: flex !important;
  }

  /* Make preset/sample row stack */
  .preset-sample-row {
    flex-direction: column !important;
    display: flex !important;
  }

  /* Ensure sample sections are visible */
  .sample-options-header {
    display: block !important;
    visibility: visible !important;
  }

  /* Simplify global controls to 2 columns */
  .global-controls-horizontal {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  /* Header adjustments */
  .dash-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
  }

  .header-controls {
    width: 100% !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .connection-zone {
    width: 100% !important;
    justify-content: space-between !important;
  }

  .preset-controls-header {
    width: 100% !important;
    justify-content: space-between !important;
  }
}

/* ====== MOBILE PHONE SPECIFIC (SMALL SCREENS) ====== */
@media (max-width: 480px) {
  /* Force everything to single column */
  .dashboard {
    padding: 8px !important;
    height: auto !important;
    min-height: 100vh !important;
  }

  .dashboard main {
    height: auto !important;
    overflow: visible !important;
  }

  .dash-grid {
    gap: 8px !important;
  }

  /* Voice cards full width */
  .voice-cards-horizontal {
    flex-direction: column !important;
    padding: 8px !important;
  }

  .voice-card {
    flex: 1 1 100% !important;
    min-width: 100% !important;
    width: 100% !important;
  }

  /* Ensure all sections are visible */
  .sample-options-row,
  .sample-option-card {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
  }

  /* Global controls single column */
  .global-controls-horizontal {
    grid-template-columns: 1fr !important;
  }

  /* Key selector more compact */
  .key-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 4px !important;
  }

  /* Mode selector 2 columns */
  .mode-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* BPM controls stack */
  .bpm-controls {
    flex-direction: column !important;
  }

  .btn-bpm {
    width: 100% !important;
  }

  /* Preset grid fewer columns */
  .preset-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Oscillator modal adjustments */
  .osc-source-selector {
    flex-direction: column !important;
  }

  .osc-source-btn {
    width: 100% !important;
  }

  /* Reduce padding everywhere */
  .dash-card, .control-group-compact, .preset-section {
    padding: 10px !important;
  }

  /* Smaller logo */
  .logo-text {
    font-size: 18px !important;
  }

  /* Connect button full width in mobile */
  .btn-connect {
    width: 100% !important;
    justify-content: center !important;
  }

  /* Preset slot toggle full width */
  .preset-slot-toggle {
    width: 100% !important;
  }

  /* Font size adjustments for very small screens */
  .param-label-sm, .upload-setting-label {
    font-size: 10px !important;
  }

  /* Effect rows stack on tiny screens */
  .effect-row-compact {
    flex-wrap: wrap !important;
  }

  .effect-row-compact .effect-label {
    flex: 1 1 100% !important;
    margin-bottom: 4px !important;
  }

  /* Bass mode buttons wrap */
  .bass-mode-selector, .bass-mode-row {
    flex-wrap: wrap !important;
  }

  /* Chord visualizer smaller */
  #simplePianoCanvas {
    height: 80px !important;
  }

  .chord-visualizer {
    padding: 12px !important;
  }
}

/* ====== LANDSCAPE MOBILE OPTIMIZATIONS ====== */
@media (max-width: 900px) and (orientation: landscape) {
  /* In landscape, use 2 columns for voice cards */
  .voice-cards-horizontal {
    flex-direction: row !important;
    flex-wrap: wrap !important;
  }

  .voice-card {
    flex: 1 1 calc(50% - 8px) !important;
    min-width: 0 !important;
  }

  /* Global controls 2 columns in landscape */
  .global-controls-horizontal {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ====== HIDE/SHOW SECTIONS ====== */
/* Hide the old global parameters section (we have new one at bottom) */
.preset-unified-layout .preset-section.preset-global {
  display: none !important;
}

/* Show the oscillators section (contains piano roll and voice cards) */
.preset-unified-layout {
  display: block !important;
  width: 100% !important;
}

.preset-section.preset-oscillators {
  display: flex !important;
  flex-direction: column !important;
  width: 100% !important;
  gap: 20px !important;
}

/* Hide activity log from left column */
.card-activity {
  display: none !important;
}

/* Show activity log in header instead */
.header-controls {
  flex-wrap: wrap;
  gap: 12px;
}

.card-activity-inline {
  max-width: 300px;
  max-height: 100px;
  overflow-y: auto;
  font-size: 10px;
}

/* ====== CLEAN CONTAINER SPACING ====== */
.card-user-presets {
  padding: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
}
