/*
 * Copyright (C) 2025 Jema Technology
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

/* Audio Player Styles */
#audio-player {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--background-color);
    z-index: var(--z-modal);
    display: flex;
    color: var(--on-surface);
    font-family: var(--font-family);
}

#audio-player.hidden {
    display: none !important;
}

/* Sidebar (Playlist) */
.audio-sidebar {
    width: 320px;
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.audio-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.audio-header h2 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-medium);
    margin: 0;
}

.audio-back-btn {
    background: none;
    border: none;
    color: var(--on-surface);
    cursor: pointer;
    padding: var(--space-xs);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

.audio-back-btn:hover {
    background-color: var(--surface-variant);
}

.audio-playlist {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

.playlist-item {
    display: flex;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--transition-fast);
    margin-bottom: 2px;
}

.playlist-item:hover {
    background-color: var(--surface-variant);
}

.playlist-item.active {
    background-color: rgba(var(--primary-rgb), 0.15); /* Primary color with opacity */
    color: var(--primary-color);
}

.playlist-item.active .track-number,
.playlist-item.active .track-duration {
    color: var(--primary-color);
}

.track-number {
    width: 24px;
    font-size: var(--font-size-sm);
    color: var(--on-surface-variant);
    margin-right: var(--space-sm);
}

.track-info-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.track-title-list {
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-artist-list {
    font-size: var(--font-size-xs);
    color: var(--on-surface-variant);
}

.track-duration {
    font-size: var(--font-size-xs);
    color: var(--on-surface-variant);
    margin-left: var(--space-sm);
}

/* Main Area */
.audio-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    background: linear-gradient(to bottom, var(--background-color), var(--surface-color));
}

.album-art-container {
    width: 300px;
    height: 300px;
    background-color: var(--surface-variant);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-xl);
    box-shadow: var(--shadow-xl);
}

.album-art-placeholder {
    font-size: 120px;
    color: var(--on-surface-variant);
    opacity: 0.5;
}

.current-track-info {
    text-align: center;
    margin-bottom: var(--space-xl);
    width: 100%;
    max-width: 600px;
}

.current-track-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--space-xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.current-track-artist {
    font-size: var(--font-size-lg);
    color: var(--on-surface-variant);
}

/* Controls */
.player-controls {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.progress-container {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.time-display {
    font-size: var(--font-size-xs);
    color: var(--on-surface);
    width: 45px;
    text-align: center;
}

.progress-bar-wrapper {
    flex: 1;
    height: 20px; /* Hit area */
    display: flex;
    align-items: center;
    cursor: pointer;
    position: relative;
}

.progress-bar-bg {
    width: 100%;
    height: 4px;
    background-color: var(--border-color);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--primary-color);
    width: 0%;
    border-radius: var(--radius-full);
    transition: width 0.1s linear;
}

.progress-bar-wrapper:hover .progress-bar-fill {
    background-color: var(--primary-variant);
}

.audio-controls-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    margin-top: var(--space-md);
}

.center-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-lg);
}

.right-controls {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    justify-self: end;
}

.control-btn {
    background: none;
    border: none;
    color: var(--on-surface);
    cursor: pointer;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    transition: background-color var(--transition-fast);
    pointer-events: auto;
}

.control-btn:hover {
    background-color: var(--surface-variant);
}

.control-btn.active {
    color: var(--primary-color);
}

.control-btn.large {
    width: 64px;
    height: 64px;
    background-color: var(--primary-color);
    color: var(--on-primary);
    box-shadow: var(--shadow-md);
}

.control-btn.large:hover {
    background-color: var(--primary-variant);
    transform: scale(1.05);
}

.control-btn .material-icons {
    font-size: 24px;
}

.control-btn.large .material-icons {
    font-size: 36px;
}

/* Volume Control */
.volume-container {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    justify-self: start;
}

.volume-slider {
    width: 100px;
    height: 4px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: transparent;
    border-radius: var(--radius-full);
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: var(--on-surface-variant);
    border-radius: var(--radius-full);
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    margin-top: -4px;
}

.volume-slider::-moz-range-track {
    width: 100%;
    height: 4px;
    background: var(--on-surface-variant);
    border-radius: var(--radius-full);
    border: none;
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Responsive */
@media (max-width: 768px) {
    #audio-player {
        flex-direction: column;
    }

    .audio-sidebar {
        width: 100%;
        height: 40%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .audio-main {
        height: 60%;
        padding: var(--space-md);
    }

    .album-art-container {
        width: 150px;
        height: 150px;
        margin-bottom: var(--space-md);
    }

    .album-art-placeholder {
        font-size: 64px;
    }

    .current-track-title {
        font-size: var(--font-size-lg);
    }
}

/* Window Controls Overlay Support */
@media (display-mode: window-controls-overlay) {
  .audio-header {
    padding-left: calc(var(--space-md) + env(titlebar-area-x, 0));
    -webkit-app-region: drag;
    app-region: drag;
  }
  
  .audio-header button {
    -webkit-app-region: no-drag;
    app-region: no-drag;
  }

  .audio-main {
    padding-top: calc(var(--space-xl) + env(titlebar-area-height, 0));
    padding-right: calc(var(--space-xl) + (100vw - (env(titlebar-area-x, 0) + env(titlebar-area-width, 100vw))));
    position: relative;
  }

  /* Drag region for main area */
  .audio-main::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: env(titlebar-area-height, 32px);
    -webkit-app-region: drag;
    app-region: drag;
    z-index: 100;
  }
}
