/* Audio PWA Styles - Dark Theme */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  padding: 20px;
  background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 50%, #16213e 100%);
  min-height: 100vh;
  color: #e2e8f0;
  font-weight: 400;
}

h1 {
  color: #f8fafc;
  text-align: center;
  margin-bottom: 40px;
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #e2e8f0 0%, #94a3b8 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 30px rgba(148, 163, 184, 0.3);
}

h3 {
  margin-bottom: 20px;
  color: #cbd5e1;
  font-size: 1.25rem;
  font-weight: 600;
}

/* ===== BUTTON STYLES ===== */
button {
  padding: 12px 24px;
  margin: 0;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  color: #f1f5f9;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

#startBtn {
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  color: white;
  width: 160px;
  height: 56px;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.3;
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
}

#startBtn:hover:not(:disabled) {
  box-shadow: 0 8px 30px rgba(16, 185, 129, 0.6);
}

#stopBtn {
  background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
  color: white;
  width: 160px;
  height: 56px;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.3;
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
}

#stopBtn:hover:not(:disabled) {
  box-shadow: 0 8px 30px rgba(239, 68, 68, 0.6);
}

.refresh-btn {
  padding: 10px 16px;
  background: linear-gradient(135deg, #0ea5e9 0%, #3b82f6 100%);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.refresh-btn:hover {
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

.metronome-toggle {
  padding: 10px 20px;
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.metronome-toggle:hover {
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}

.export-all-btn {
  background: linear-gradient(135deg, #7c3aed 0%, #8b5cf6 100%);
  color: white;
  font-weight: 600;
  padding: 14px 28px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  font-size: 15px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
}

.export-all-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #6d28d9 0%, #7c3aed 100%);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(139, 92, 246, 0.6);
}

.export-all-btn:disabled {
  background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.delete-btn {
  background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* ===== FORM ELEMENTS ===== */
select, input {
  padding: 12px 16px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.8);
  color: #f1f5f9;
  font-family: inherit;
  font-weight: 400;
  transition: all 0.3s ease;
  backdrop-filter: blur(5px);
}

select:focus, input:focus {
  outline: none;
  border-color: #06b6d4;
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.2);
}

.device-select {
  padding: 12px 16px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.8);
  color: #f1f5f9;
  flex: 1;
  min-width: 0;
  max-width: 100%;
  font-weight: 500;
  backdrop-filter: blur(5px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metronome-input {
  width: 80px;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 8px;
  text-align: center;
  background: rgba(30, 41, 59, 0.8);
  color: #f1f5f9;
  font-weight: 500;
  font-family: 'JetBrains Mono', monospace;
}

.metronome-select {
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 8px;
  background: rgba(30, 41, 59, 0.8);
  color: #f1f5f9;
  font-weight: 500;
}

.beat-input {
  width: 60px;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 8px;
  text-align: center;
  background: rgba(30, 41, 59, 0.8);
  color: #f1f5f9;
  font-weight: 500;
  font-family: 'JetBrains Mono', monospace;
}

#gainSlider {
  width: 300px;
  height: 6px;
  background: linear-gradient(to right, #1e293b 0%, #334155 100%);
  outline: none;
  border-radius: 10px;
  appearance: none;
  cursor: pointer;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

#gainSlider::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, #06b6d4 0%, #0ea5e9 100%);
  border: 2px solid #f1f5f9;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.4);
  transition: all 0.3s ease;
}

#gainSlider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.6);
}

#gainSlider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, #06b6d4 0%, #0ea5e9 100%);
  border: 2px solid #f1f5f9;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.4);
}

/* ===== LAYOUT CONTAINERS ===== */
.top-controls {
  display: flex;
  gap: 30px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.devices-section {
  flex: 1;
  background: rgba(15, 23, 42, 0.6);
  padding: 24px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.1);
  backdrop-filter: blur(10px);
  min-width: 350px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.bpm-section {
  flex: 1;
  background: rgba(15, 23, 42, 0.6);
  padding: 24px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.1);
  backdrop-filter: blur(10px);
  min-width: 350px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.recording-station {
  background: rgba(15, 23, 42, 0.4);
  padding: 24px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.1);
  backdrop-filter: blur(10px);
  margin: 30px 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.recordings-container {
  background: rgba(15, 23, 42, 0.6);
  padding: 24px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.1);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* ===== DEVICE SELECTION ===== */
.device-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
  width: 100%;
  overflow: hidden;
}

.device-label {
  font-weight: 600;
  min-width: 140px;
  flex-shrink: 0;
  text-align: left;
  color: #f1f5f9;
  font-size: 14px;
}

.refresh-button-container {
  display: flex;
  justify-content: flex-start;
  margin: 20px 0 15px 0;
}

#recordingStatus {
  margin-top: 20px;
  font-weight: 600;
  color: #06b6d4;
  padding: 16px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: 12px;
  text-align: center;
  backdrop-filter: blur(5px);
}

/* ===== GAIN CONTROLS ===== */
.gain-section {
  margin-bottom: 24px;
  padding: 20px;
  background: rgba(15, 23, 42, 0.4);
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.gain-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
}

.gain-label {
  font-weight: 600;
  min-width: 120px;
  color: #f1f5f9;
  font-size: 14px;
}

#gainMeter {
  width: 300px;
  height: 24px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(30, 41, 59, 0.8);
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  backdrop-filter: blur(5px);
}

#gainBar {
  height: 100%;
  background: linear-gradient(to right, #10b981, #f59e0b, #ef4444);
  width: 0%;
  transition: width 0.1s ease;
  border-radius: 12px;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.gain-value {
  font-weight: 600;
  color: #94a3b8;
  min-width: 60px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
}

/* ===== METRONOME CONTROLS ===== */
.metronome-controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.bpm-row, .time-signature-row, .beats-row {
  display: flex;
  align-items: center;
  gap: 15px;
}

.number-input-group {
  display: flex;
  align-items: center;
  background: rgba(51, 65, 85, 0.8);
  border-radius: 12px;
  border: 1px solid rgba(71, 85, 105, 0.6);
  overflow: hidden;
  min-width: 140px;
  width: 140px;
}

.number-btn {
  background: rgba(71, 85, 105, 0.8);
  border: none;
  color: #f1f5f9;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  user-select: none;
}

.number-btn:hover {
  background: rgba(100, 116, 139, 0.8);
}

.number-btn:active {
  background: rgba(148, 163, 184, 0.8);
  transform: scale(0.95);
}

.number-input-group input {
  border: none;
  background: transparent;
  text-align: center;
  flex: 1;
  width: 68px;
  font-weight: 600;
  color: #f1f5f9;
  font-family: 'JetBrains Mono', monospace;
}

/* Hide native number input spinners */
.number-input-group input::-webkit-outer-spin-button,
.number-input-group input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.number-input-group input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.metronome-status {
  display: flex;
  align-items: center;
  gap: 20px;
}

#metronomeIndicator {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(71, 85, 105, 0.8);
  transition: all 0.1s ease;
  border: 2px solid rgba(148, 163, 184, 0.3);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#metronomeIndicator.active {
  background: linear-gradient(135deg, #10b981 0%, #34d399 100%);
  border-color: #10b981;
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.6);
}

.beat-counter {
  font-weight: 600;
  color: #94a3b8;
  min-width: 50px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
}

/* ===== RECORDING CONTROLS ===== */
.recording-controls {
  display: flex;
  gap: 30px;
  align-items: flex-start;
  background: rgba(15, 23, 42, 0.4);
  padding: 24px;
  border-radius: 16px;
  margin: 30px 0;
  border: 1px solid rgba(148, 163, 184, 0.1);
  backdrop-filter: blur(10px);
}

.button-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.waveform-display {
  flex: 1;
}

.audio-track-row {
  display: flex;
  align-items: center;
  gap: 15px;
  width: 100%;
  overflow: hidden;
}

.time-display {
  font-size: 12px;
  color: #94a3b8;
  min-width: 50px;
  flex-shrink: 0;
  font-weight: 500;
  font-family: 'JetBrains Mono', monospace;
}

#audioTrackCanvas {
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  max-width: 100%;
  width: 100%;
  flex: 1;
  min-width: 300px;
  border-radius: 12px;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.4);
}

/* ===== RECORDINGS LIST ===== */
.recordings-layout {
  display: flex;
  gap: 30px;
  align-items: flex-start;
}

.recordings-list {
  flex: 2;
}

.recordings-footer {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
}

#audioPlayback {
  width: 100%;
  max-width: 300px;
  border-radius: 12px;
  outline: none;
}

#recordingsList {
  list-style: none;
  padding: 0;
  width: 100%;
  overflow: hidden;
}

#recordingsList li {
  background: rgba(30, 41, 59, 0.8);
  margin: 16px 0;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  backdrop-filter: blur(5px);
  transition: all 0.3s ease;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

#recordingsList li:hover {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(6, 182, 212, 0.4);
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.recording-item {
  display: flex;
  align-items: center;
  gap: 15px;
  margin: 8px 0;
  color: #f1f5f9;
  width: 100%;
  overflow: hidden;
  justify-content: space-between;
}

.recording-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.recording-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.recording-btn {
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  background: rgba(71, 85, 105, 0.8);
  color: #f1f5f9;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.recording-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.play-btn:hover {
  background: linear-gradient(135deg, #10b981 0%, #34d399 100%);
}

.download-btn:hover {
  background: linear-gradient(135deg, #0ea5e9 0%, #3b82f6 100%);
}

.delete-btn:hover {
  background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
}

.recording-item .filename {
  font-weight: 500;
  color: #f1f5f9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.recording-item .timestamp {
  font-size: 12px;
  color: #94a3b8;
  font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0;
  white-space: nowrap;
}

.recording-controls button {
  padding: 8px 16px;
  margin: 0 4px;
}

/* ===== UTILITY CLASSES ===== */
.input-label {
  font-weight: 600;
  color: #f1f5f9;
  font-size: 14px;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
  .top-controls {
    flex-direction: column;
    gap: 20px;
  }
  
  .devices-section,
  .bpm-section {
    min-width: auto;
    width: 100%;
  }
  
  .recording-controls {
    flex-direction: column;
    gap: 15px;
  }
  
  .button-column {
    align-self: center;
  }
  
  .waveform-display {
    width: 100%;
    overflow: hidden;
  }
  
  #audioTrackCanvas {
    width: 100%;
    max-width: 100%;
    min-width: 280px;
  }
  
  .audio-track-row {
    width: 100%;
  }
  
  .recordings-layout {
    flex-direction: column;
    gap: 15px;
  }
}

/* CRITICAL BREAKPOINT: Prevent width jump during transition */
@media (max-width: 600px) {
  .devices-section,
  .bpm-section {
    min-width: auto !important;
    width: 100% !important;
    box-sizing: border-box;
    flex: none !important;
  }
  
  .top-controls {
    gap: 15px !important;
  }
}

@media (max-width: 480px) {
  body {
    margin: 10px;
  }
  
  .devices-section,
  .bpm-section,
  .recording-station,
  .recordings-container {
    padding: 15px;
  }
  
  /* CRITICAL FIX: Override min-width for responsive behavior */
  .devices-section,
  .bpm-section {
    min-width: auto !important;
    flex: none !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }
  
  .top-controls {
    gap: 10px !important;
  }
  
  #startBtn,
  #stopBtn {
    width: 140px;
    height: 48px;
    font-size: 13px;
    line-height: 1.2;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }
  
  .device-select {
    min-width: 0;
    max-width: 100%;
  }
  
  .gain-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .gain-label {
    min-width: auto;
  }
  
  .device-label {
    min-width: 80px;
    font-size: 12px;
  }
  
  .device-row {
    gap: 10px;
  }
  
  #gainMeter,
  #gainSlider {
    width: 100%;
    max-width: 280px;
  }
  
  .container {
    margin: 10px;
    padding: 16px;
    border-radius: 16px;
  }
  
  .recording-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    overflow: hidden;
  }
  
  .recording-item .timestamp,
  .recording-item .filename {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  #recordingsList li {
    padding: 15px;
    margin: 12px 0;
  }
}

/* Very narrow screens (PWA installations can be narrower than browsers) */
@media (max-width: 400px) {
  .main-container {
    padding: 15px 8px;
  }
  
  .controls {
    gap: 8px;
  }
  
  .recording-buttons {
    gap: 4px;
  }
  
  .recording-btn {
    min-width: 32px;
    height: 32px;
    padding: 6px 8px;
    font-size: 12px;
  }
  
  .recording-item {
    gap: 8px;
  }
  
  .waveform-canvas {
    min-height: 60px;
  }
  
  select {
    font-size: 13px;
    padding: 6px 8px;
  }
  
  .time-display {
    font-size: 14px;
  }
  
  h1 {
    font-size: 20px;
  }
  
  .recording-info {
    font-size: 13px;
  }
  
  .timestamp,
  .filename {
    font-size: 12px;
  }
}

/* ===== ADDITIONAL POLISH ===== */
*::-webkit-scrollbar {
  width: 8px;
}

*::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.8);
  border-radius: 4px;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #475569 0%, #64748b 100%);
  border-radius: 4px;
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #64748b 0%, #94a3b8 100%);
}

/* Smooth transitions for all interactive elements */
* {
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

button, select, input {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
