/* ========================================
   Worship Practice App - Multitrack Audio Player
   Dark Theme Styles
   ======================================== */

/* CSS Custom Properties */
:root {
    /* Colors */
    --bg-primary: #1a1a1a;
    --bg-secondary: #242424;
    --bg-tertiary: #2d2d2d;
    --bg-hover: #3a3a3a;
    --bg-active: #4a4a4a;
    
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --text-muted: #707070;
    
    --accent-primary: #00d4ff;
    --accent-secondary: #00a8cc;
    --accent-success: #4caf50;
    --accent-warning: #ff9800;
    --accent-danger: #f44336;
    
    --waveform-active: #00d4ff;
    --waveform-inactive: #4a4a4a;
    
    --border-color: #404040;
    --border-light: #505050;
    
    /* Sizing */
    --track-control-width: 200px;
    --track-height: 100px;
    --transport-height: 80px;
    --tab-height: 36px;
    --timeline-header-height: 100px;
    --timeline-height: 50px;
    
    /* Knob */
    --knob-size: 40px;
    --knob-track-color: #404040;
    --knob-fill-color: var(--accent-primary);
    
    /* Transitions */
    --transition-fast: 0.1s ease;
    --transition-normal: 0.2s ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-primary);
    background-color: var(--bg-primary);
}

/* App Container */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
}

/* ========================================
   Tab Bar
   ======================================== */
#tab-bar {
    display: flex;
    align-items: center;
    height: var(--tab-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 8px;
    padding-left: calc(8px + env(safe-area-inset-left));
    padding-right: calc(8px + env(safe-area-inset-right));
    gap: 4px;
    position: relative; /* Required for absolute positioned dropdown */
}

#tabs-container {
    display: flex;
    flex: 1;
    overflow-x: auto;
    gap: 2px;
}

#tabs-container::-webkit-scrollbar {
    height: 4px;
}

#tabs-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.song-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background-color: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: 4px 4px 0 0;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    min-width: 100px;
    max-width: 200px;
    transition: background-color var(--transition-fast);
}

.song-tab:hover {
    background-color: var(--bg-hover);
}

.song-tab.active {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-color);
    border-bottom-color: var(--bg-primary);
}

.song-tab-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}

.song-tab-name:focus {
    outline: none;
    background-color: var(--bg-tertiary);
    padding: 2px 4px;
    margin: -2px -4px;
    border-radius: 2px;
}

.song-tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 2px;
    opacity: 0;
    transition: opacity var(--transition-fast), background-color var(--transition-fast);
}

.song-tab:hover .song-tab-close,
.song-tab.active .song-tab-close {
    opacity: 1;
}

.song-tab-close:hover {
    background-color: var(--accent-danger);
    color: var(--text-primary);
}

#add-song-btn {
    flex-shrink: 0;
    position: relative;
}

/* Arrangement Selector in Tab Bar */
#arrangement-selector {
    flex-shrink: 0;
    margin-left: auto; /* Push to the right */
    padding-right: 8px;
}

#arrangement-selector select {
    padding: 6px 24px 6px 8px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%23b0b0b0' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
}

#arrangement-selector select:hover {
    border-color: var(--accent-primary);
}

#arrangement-selector select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* ========================================
   Circular Add Buttons
   ======================================== */
.add-btn.circular {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(0, 212, 255, 0.5);
    background-color: rgba(0, 212, 255, 0.3);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.add-btn.circular:hover {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #000;
}

/* ========================================
   Picker Dropdown (for song/track selection)
   ======================================== */
.picker-dropdown {
    position: absolute;
    top: 100%;
    left: 8px;
    margin-top: 4px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    z-index: 100;
    min-width: 220px;
    max-width: 320px;
    max-height: 300px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.picker-dropdown.hidden {
    display: none;
}

.picker-header {
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}

.picker-list {
    overflow-y: auto;
    padding: 4px;
}

.picker-item {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 4px;
    transition: background-color var(--transition-fast);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.picker-item:hover {
    background-color: var(--bg-hover);
}

.picker-item.disabled {
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.5;
}

.picker-item.disabled:hover {
    background-color: transparent;
}

.picker-empty {
    padding: 16px 12px;
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

/* ========================================
   Main Content
   ======================================== */
#main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative; /* Constrains absolute positioned children like empty state */
}

/* ========================================
   Track Controls Panel (Left)
   ======================================== */
#track-controls-panel {
    width: var(--track-control-width);
    min-width: var(--track-control-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#track-controls-header {
    height: var(--timeline-header-height);
    min-height: var(--timeline-header-height);
    padding: 8px 12px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
    letter-spacing: 0.5px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    box-sizing: border-box;
}

#track-header-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

#cache-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 400;
    color: var(--text-tertiary);
    opacity: 0.7;
    text-transform: none;
    letter-spacing: normal;
    cursor: default;
}

#cache-indicator svg {
    opacity: 0.7;
}

#cache-indicator:hover {
    opacity: 1;
}

#help-btn {
    opacity: 0.7;
    width: 24px;
    height: 24px;
}

#help-btn:hover {
    opacity: 1;
    color: var(--accent-primary);
}

#track-controls-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Hide scrollbar for track controls (synced with waveform panel) */
#track-controls-list::-webkit-scrollbar {
    width: 0;
    display: none;
}

#track-controls-list {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Track Header Bottom Row */
#track-header-bottom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

/* Track Control Item */
.track-control {
    height: var(--track-height);
    min-height: var(--track-height);
    max-height: var(--track-height);
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    transition: background-color var(--transition-fast);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.track-control:hover {
    background-color: var(--bg-tertiary);
}

.track-control.selected {
    background-color: var(--bg-tertiary);
    border-left: 3px solid var(--accent-primary);
    padding-left: 9px;
}

.track-control.inactive {
    opacity: 0.5;
}

/* Drag and Drop Reordering */
.track-control[draggable="true"] {
    cursor: grab;
}

.track-control[draggable="true"]:active {
    cursor: grabbing;
}

.track-control.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.track-control.drag-over-top {
    border-top: 2px solid var(--accent-primary);
    margin-top: -1px;
}

.track-control.drag-over-bottom {
    border-bottom: 2px solid var(--accent-primary);
    margin-bottom: -1px;
}

.track-control-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.track-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 8px;
}

.track-delete-btn {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-fast), background-color var(--transition-fast);
}

.track-control:hover .track-delete-btn {
    opacity: 1;
}

.track-delete-btn:hover {
    background-color: var(--accent-danger);
    color: var(--text-primary);
}

/* Volume & Pan Row */
.track-control-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.track-control-row label {
    font-size: 11px;
    color: var(--text-muted);
    width: 28px;
    flex-shrink: 0;
}

/* Volume Slider */
.volume-slider-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
}

.volume-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-active);
    border-radius: 2px;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.volume-value {
    font-size: 11px;
    color: var(--text-muted);
    width: 28px;
    text-align: right;
}

/* Pan Knob Container */
.pan-container {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.pan-value {
    font-size: 10px;
    color: var(--text-muted);
    width: 24px;
    text-align: center;
}

/* Solo/Mute Buttons */
.track-buttons {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.track-btn {
    width: 28px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--border-color);
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 3px;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.track-btn:hover {
    background-color: var(--bg-hover);
}

.track-btn.solo.active {
    background-color: var(--accent-warning);
    border-color: var(--accent-warning);
    color: #000;
}

.track-btn.mute.active {
    background-color: var(--accent-danger);
    border-color: var(--accent-danger);
    color: #fff;
}

/* ========================================
   Waveform Panel (Right)
   ======================================== */
#waveform-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-primary);
}

/* Timeline Header */
#timeline-header {
    height: var(--timeline-header-height);
    min-height: var(--timeline-header-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

#timeline-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    height: 30px;
}

#timeline-mode-toggle {
    display: flex;
    gap: 2px;
}

.mode-btn {
    padding: 2px 10px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.mode-btn:first-child {
    border-radius: 3px 0 0 3px;
}

.mode-btn:last-child {
    border-radius: 0 3px 3px 0;
}

.mode-btn:hover {
    background-color: var(--bg-hover);
}

.mode-btn.active {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #000;
}

#zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.zoom-value {
    font-size: 14px;
    color: var(--text-secondary);
    font-family: 'Consolas', 'Monaco', monospace;
    min-width: 40px;
    text-align: right;
}

#zoom-slider {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-active);
    border-radius: 2px;
    cursor: pointer;
}

#zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
}

/* Dual Timeline Display */
#timeline-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.timeline-canvas {
    flex: 1;
    width: 100%;
    display: block;
    min-height: 20px;
}

#timeline-divider {
    height: 1px;
    background-color: var(--border-color);
    flex-shrink: 0;
}

/* Legacy single canvas support */
#timeline-canvas {
    flex: 1;
    width: 100%;
    display: block;
}

/* Waveform Container */
#waveform-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#waveform-scroll-area {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-x: auto;
    overflow-y: auto;
}

#waveform-scroll-area::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#waveform-scroll-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

#waveform-scroll-area::-webkit-scrollbar-corner {
    background: var(--bg-secondary);
}

#waveform-tracks {
    min-width: 100%;
    position: relative;
}

/* Waveform Track */
.waveform-track {
    height: var(--track-height);
    min-height: var(--track-height);
    max-height: var(--track-height);
    border-bottom: 1px solid var(--border-color);
    position: relative;
    background-color: var(--bg-primary);
    box-sizing: border-box;
}

.waveform-track.inactive {
    background-color: var(--bg-secondary);
}

.waveform-canvas {
    position: sticky;
    left: 0;
    height: 100%;
    /* Width set by JS to viewport size - do NOT use 100% as it breaks at high zoom */
    display: block;
}

/* Section Mute Button Container */
.section-mute-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none; /* Allow clicks to pass through to waveform */
    z-index: 5;
}

/* Section Mute Button */
.section-mute-btn {
    position: absolute;
    top: 4px;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 1px solid var(--border-color);
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 9px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 2px;
    pointer-events: auto; /* Re-enable clicks for button */
    opacity: 0;
    transition: opacity var(--transition-fast), background-color var(--transition-fast);
}

/* Show on hover over parent track row */
.waveform-track:hover .section-mute-btn {
    opacity: 0.7;
}

.section-mute-btn:hover {
    opacity: 1 !important;
    background-color: var(--bg-hover);
}

/* Always show when muted (active) */
.section-mute-btn.active {
    opacity: 1;
    background-color: var(--accent-danger);
    border-color: var(--accent-danger);
    color: #fff;
}

.section-mute-btn.active:hover {
    background-color: #d32f2f;
}

/* Playhead */
#playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    pointer-events: none;
    z-index: 10;
    left: 0;
}

#playhead-line {
    width: 1px;
    height: 100%;
    background-color: var(--accent-primary);
    box-shadow: 0 0 4px var(--accent-primary);
}

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

/* ========================================
   Transport Bar
   ======================================== */
#transport-bar {
    height: var(--transport-height);
    min-height: var(--transport-height);
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
}

#transport-controls {
    display: flex;
    align-items: center;
    gap: 24px;
}

/* Playback Controls */
#playback-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.transport-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.transport-btn:hover {
    background-color: var(--bg-hover);
    border-color: var(--accent-primary);
}

.transport-btn.primary {
    width: 48px;
    height: 48px;
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #000;
}

.transport-btn.primary:hover {
    background-color: var(--accent-secondary);
    border-color: var(--accent-secondary);
}

.transport-btn.active {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #000;
}

/* Loop Region Styles */
.loop-region {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(0, 212, 255, 0.12);
    pointer-events: none;
    z-index: 5;
}

.loop-region::before,
.loop-region::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--accent-primary);
}

.loop-region::before {
    left: 0;
}

.loop-region::after {
    right: 0;
}

.loop-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 10px;
    cursor: ew-resize;
    z-index: 10;
}

.loop-handle:hover,
.loop-handle.dragging {
    background: rgba(0, 212, 255, 0.3);
}

.loop-handle-start {
    left: -5px;
}

.loop-handle-end {
    right: -5px;
}

/* Time Display */
#time-display {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.time-separator {
    color: var(--text-muted);
    margin: 0 4px;
}

/* Transport Knob Groups */
.transport-knob-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
}

.transport-knob-group label {
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.knob-container {
    width: var(--knob-size);
    height: var(--knob-size);
}

.knob-value {
    font-size: 15px;
    color: var(--text-secondary);
    font-family: 'Consolas', 'Monaco', monospace;
}

.knob-value.editable {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: background-color var(--transition-fast);
    min-width: 50px;
    text-align: center;
}

.knob-value.editable:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.knob-value-input {
    width: 50px;
    padding: 2px 4px;
    font-size: 15px;
    font-family: 'Consolas', 'Monaco', monospace;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--accent-primary);
    border-radius: 3px;
    color: var(--text-primary);
    text-align: center;
    outline: none;
}

.knob-value-input:focus {
    box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.3);
}

/* Transport Select Groups */
.transport-select-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.transport-select-group label {
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.transport-select-group select {
    padding: 6px 24px 6px 8px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%23b0b0b0' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
}

.transport-select-group select:hover {
    border-color: var(--accent-primary);
}

.transport-select-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Transport Display Groups */
.transport-display-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 7px;
}

.transport-display-group label {
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

/* ========================================
   Empty States
   ======================================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state p {
    margin: 4px 0;
}

.empty-state .hint {
    font-size: 12px;
    color: var(--text-muted);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state.full-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-primary);
    z-index: 10;
}

/* Hide full-screen empty state when content is present */
#no-song-empty-state.hidden {
    display: none;
}

#track-controls-empty,
#waveform-empty {
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none; /* Allow clicks to pass through to buttons behind */
}

#track-controls-panel:has(.track-control) #track-controls-empty,
#waveform-tracks:not(:empty) + #waveform-empty {
    display: none;
}

/* Fix for browsers without :has support */
#track-controls-empty.hidden,
#waveform-empty.hidden {
    display: none;
}

/* ========================================
   Modal
   ======================================== */
#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#modal-overlay.hidden {
    display: none;
}

#modal-dialog {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    min-width: 320px;
    max-width: 520px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#modal-dialog.modal-help {
    width: 90vw;
    max-width: 900px;
    height: 85vh;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

#modal-dialog.modal-arrangement-editor {
    max-width: 650px;
    width: 90vw;
}

#modal-dialog.modal-help #modal-content {
    flex: 1;
    padding: 0;
    overflow: hidden;
    display: flex;
}

.help-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #1a1a2e;
}

#modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

#modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

#modal-content {
    padding: 16px;
    color: var(--text-secondary);
}

#modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background-color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
    color: #000;
}

.btn-primary:hover {
    background-color: var(--accent-secondary);
    border-color: var(--accent-secondary);
}

.btn-secondary {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--bg-hover);
}

.btn-danger {
    background-color: var(--accent-danger);
    border: 1px solid var(--accent-danger);
    color: #fff;
}

.btn-danger:hover {
    background-color: #d32f2f;
}

.icon-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

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

.icon-btn svg,
.add-btn svg {
    pointer-events: none;
}

.zoom-fit-btn {
    width: auto;
    padding: 0 4px;
}

/* ========================================
   Loading Overlay
   ======================================== */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    gap: 16px;
}

#loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#loading-message {
    color: var(--text-primary);
    font-size: 14px;
}



/* ========================================
   Knob Component
   ======================================== */
.knob {
    width: 100%;
    height: 100%;
    position: relative;
    cursor: pointer;
    user-select: none;
}

.knob svg {
    width: 100%;
    height: 100%;
}

.knob-track {
    fill: none;
    stroke: var(--knob-track-color);
    stroke-width: 4;
    stroke-linecap: round;
}

.knob-fill {
    fill: none;
    stroke: var(--knob-fill-color);
    stroke-width: 4;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.05s ease;
}

.knob-center {
    fill: var(--bg-secondary);
}

.knob-indicator {
    fill: var(--accent-primary);
}

/* Small knob for pan */
.knob-small {
    width: 28px;
    height: 28px;
}

.knob-small .knob-track,
.knob-small .knob-fill {
    stroke-width: 3;
}

/* ========================================
   Utilities
   ======================================== */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* Focus styles */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ========================================
   File Selection Modal
   ======================================== */
.file-select-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.file-select-header .file-count {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted);
}

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
}

.file-select-list {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.file-select-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: var(--bg-tertiary);
    border-radius: 4px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.file-select-item:hover {
    background-color: var(--bg-hover);
}

.file-select-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

.file-select-item .file-name {
    flex: 1;
    font-size: 13px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-select-item .file-size {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.file-select-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.file-select-item.disabled:hover {
    background-color: var(--bg-tertiary);
}

.file-select-item.disabled input[type="checkbox"] {
    cursor: not-allowed;
}

/* Selection */
::selection {
    background-color: var(--accent-primary);
    color: #000;
}

/* ========================================
   Arrangement Editor
   ======================================== */
.arrangement-editor {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@media (max-width: 600px) {
    .arrangement-editor-panels {
        flex-direction: column;
    }
    
    .arrangement-panel {
        max-height: 180px;
    }
    
    #modal-dialog.modal-arrangement-editor {
        max-width: 95vw;
        width: 95vw;
    }
}

.arrangement-editor-name {
    display: flex;
    align-items: center;
    gap: 12px;
}

.arrangement-editor-name label {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.arrangement-editor-name input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
}

.arrangement-editor-name input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.arrangement-editor-panels {
    display: flex;
    gap: 16px;
}

.arrangement-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    min-height: 200px;
    max-height: 300px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.panel-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.arrangement-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 4px;
    transition: background-color var(--transition-fast);
}

.arrangement-item:hover {
    background: var(--bg-hover);
}

.item-label {
    font-size: 13px;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-actions {
    display: flex;
    gap: 4px;
    margin-left: 8px;
}

.arrangement-item .btn-icon {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all var(--transition-fast);
}

.arrangement-item .btn-icon:hover:not(:disabled) {
    background: var(--accent-primary);
    color: #000;
}

.arrangement-item .btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.arrangement-item .add-section-btn {
    font-size: 18px;
    font-weight: bold;
}

.arrangement-item .remove-btn {
    font-size: 18px;
}

.draft-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.arrangement-editor-footer {
    display: flex;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

/* ========================================
   Manage Custom Arrangements Dialog
   ======================================== */
.manage-arrangements-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 300px;
}

.manage-arrangement-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    transition: background-color var(--transition-fast);
}

.manage-arrangement-item:hover {
    background: var(--bg-hover);
}

.manage-arrangement-name {
    font-size: 14px;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.manage-arrangement-actions {
    display: flex;
    gap: 4px;
    margin-left: 12px;
}

.manage-arrangement-actions .btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.manage-arrangement-actions .btn-icon:hover {
    background: var(--bg-active);
    color: var(--text-primary);
}

.manage-arrangement-actions .delete-custom-btn:hover {
    background: var(--accent-danger);
    color: #fff;
}

.manage-arrangement-actions .edit-custom-btn:hover {
    background: var(--accent-primary);
    color: #000;
}
