/**
 * Responsive Styles - Mobile-first responsive design
 */

/* Tablet and below (max-width: 992px) */
@media (max-width: 992px) {
    :root {
        --sidebar-width: 80px;
    }

    .sidebar-logo span,
    .nav-link span,
    .sidebar-section h3 {
        display: none;
    }

    .nav-link {
        justify-content: center;
        padding: 16px;
    }

    .sidebar-playlists {
        display: none;
    }

    .section-title {
        font-size: 20px;
    }

    .song-grid,
    .artist-grid,
    .album-grid,
    .playlists-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 16px;
    }

    .artist-name,
    .album-title,
    .playlist-title {
        font-size: 36px;
    }

    .song-table-header,
    .song-row {
        grid-template-columns: 40px 1fr 80px 40px;
    }

    .song-row-album {
        display: none;
    }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
    :root {
        --player-height: 66px;
        --header-height: 56px;
    }

    #app {
        grid-template-columns: 1fr;
    }

    /* Sidebar - Hidden by default, slides in */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: var(--player-height);
        width: 280px;
        z-index: 100;
        transition: left 0.3s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        left: 0;
    }

    /* Sidebar header with close button */
    .sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 12px 0;
    }

    .sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        color: var(--text-secondary);
        transition: var(--transition);
    }

    .sidebar-close:hover {
        color: var(--text-primary);
    }

    .sidebar-close svg {
        width: 24px;
        height: 24px;
        fill: currentColor;
    }

    .sidebar-logo span,
    .nav-link span,
    .sidebar-section h3 {
        display: block;
    }

    .nav-link {
        justify-content: flex-start;
        padding: 12px;
    }

    .sidebar-playlists {
        display: flex;
    }

    /* Menu toggle visible */
    .menu-toggle {
        display: flex;
    }

    /* Header */
    .header {
        padding: 12px 16px;
    }

    .header-nav {
        display: none;
    }

    /* Main content - increased bottom padding for player + bottom nav */
    .main-content {
        padding: 0 16px 180px;
    }

    /* Show bottom navigation on mobile */
    .bottom-nav {
        display: block;
    }

    /* Spotify-style horizontal scroll for all grids on mobile */
    .song-grid,
    .artist-grid,
    .album-grid,
    .playlists-grid {
        display: flex;
        gap: 12px;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 8px;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .song-grid::-webkit-scrollbar,
    .artist-grid::-webkit-scrollbar,
    .album-grid::-webkit-scrollbar,
    .playlists-grid::-webkit-scrollbar {
        display: none;
    }

    .song-card,
    .album-card,
    .playlist-card {
        flex-shrink: 0;
        width: 140px;
        padding: 12px;
        scroll-snap-align: start;
    }

    .artist-card {
        flex-shrink: 0;
        width: 120px;
        padding: 12px;
        scroll-snap-align: start;
    }

    .artist-card-image {
        width: 96px;
        height: 96px;
    }

    .song-card-image {
        margin-bottom: 12px;
    }

    .song-card-title,
    .album-card-title {
        font-size: 14px;
    }

    /* Page headers */
    .artist-header,
    .album-header,
    .playlist-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 24px 0;
        min-height: auto;
    }

    .artist-header {
        margin: -16px -16px 0;
        padding: 80px 16px 24px;
    }

    .artist-image,
    .album-cover,
    .playlist-cover {
        width: 180px;
        height: 180px;
    }

    .artist-name,
    .album-title,
    .playlist-title {
        font-size: 28px;
    }

    .artist-info,
    .album-info,
    .playlist-info {
        align-items: center;
    }

    .album-meta,
    .playlist-meta {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Actions */
    .artist-actions,
    .album-actions,
    .playlist-actions {
        justify-content: center;
        padding: 16px 0;
    }

    /* Song table */
    .song-table-header {
        display: none;
    }

    .song-row {
        grid-template-columns: 1fr 40px;
        padding: 8px;
    }

    .song-row-index,
    .song-row-duration {
        display: none;
    }

    .song-row-main {
        grid-column: 1;
    }

    .song-row-actions {
        grid-column: 2;
        opacity: 1;
    }

    /* Search */
    .search-input-container {
        max-width: 100%;
    }

    .genre-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .genre-card {
        font-size: 16px;
    }

    /* Top result */
    .top-result-card {
        max-width: 100%;
    }

    .top-result-card h3 {
        font-size: 24px;
    }

    /* Library */
    .library-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    /* Player bar - Spotify Now Playing mini-bar */
    .player-bar {
        position: fixed;
        bottom: 56px;
        left: 0;
        right: 0;
        grid-template-columns: 1fr auto auto;
        gap: 12px;
        padding: 8px 12px;
        background: linear-gradient(90deg, #1a4a4a 0%, #2d5a5a 30%, #1a3a3a 100%);
        border-radius: 8px;
        margin: 0 8px 8px;
        width: auto;
        z-index: 99;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    }

    .player-song {
        display: flex;
        align-items: center;
        gap: 10px;
        min-width: 0;
        overflow: hidden;
    }

    .player-song img {
        width: 40px;
        height: 40px;
        border-radius: 4px;
        flex-shrink: 0;
    }

    .player-song-info {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }

    .player-song-info .song-title {
        font-size: 13px;
        font-weight: 600;
        color: var(--text-primary);
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block;
    }

    .player-song-info .song-artist {
        font-size: 11px;
        color: var(--text-secondary);
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block;
    }

    /* Hide extras on mobile to declutter */
    .player-extras {
        display: none;
    }

    /* Hide prev/next, show only play */
    .player-controls {
        order: 2;
        position: static;
        background: transparent;
        padding: 0;
        display: flex;
        flex-direction: row;
        align-items: center;
    }

    .control-buttons {
        gap: 0;
    }

    /* Hide prev/next on mobile, show only play */
    #prev-btn,
    #next-btn {
        display: none;
    }

    .progress-container {
        display: none;
    }

    .player-volume {
        display: none;
    }

    /* Like button in mini player */
    .like-btn {
        min-width: 40px;
        min-height: 40px;
        margin-left: auto;
        color: var(--text-secondary);
    }

    .like-btn.active {
        color: var(--primary);
    }

    /* Play button - Spotify style (white circle) */
    .player-bar .play-btn {
        width: 32px;
        height: 32px;
        background: var(--text-primary);
        border-radius: 50%;
        margin-left: 8px;
    }

    .player-bar .play-btn svg {
        width: 16px;
        height: 16px;
        fill: var(--bg-primary);
    }

    /* Modals */
    .modal {
        margin: 16px;
        max-height: calc(100vh - 32px);
    }

    /* Notification */
    .notification {
        bottom: calc(var(--player-height) + 16px);
        left: 16px;
        right: 16px;
        transform: translateY(20px);
        text-align: center;
    }

    .notification.show {
        transform: translateY(0);
    }
}

/* Small mobile (max-width: 480px) */
@media (max-width: 480px) {

    .song-grid,
    .artist-grid,
    .album-grid,
    .playlists-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .song-card,
    .album-card,
    .playlist-card {
        padding: 10px;
    }

    .play-overlay {
        width: 40px;
        height: 40px;
    }

    .play-overlay svg {
        width: 20px;
        height: 20px;
    }

    .artist-image,
    .album-cover,
    .playlist-cover {
        width: 150px;
        height: 150px;
    }

    .artist-name,
    .album-title,
    .playlist-title {
        font-size: 24px;
    }

    .btn-play-large {
        width: 48px;
        height: 48px;
    }

    .btn-play-large svg {
        width: 24px;
        height: 24px;
    }

    /* Extra small mobile player adjustments */
    .player-bar {
        padding: 6px 8px;
    }

    .player-song img {
        width: 42px;
        height: 42px;
    }

    .player-song-info .song-title {
        font-size: 13px;
    }

    .player-song-info .song-artist {
        font-size: 11px;
    }

    .control-buttons {
        gap: 4px;
    }

    .control-buttons .control-btn {
        min-width: 40px;
        min-height: 40px;
    }

    .player-bar .play-btn {
        width: 40px;
        height: 40px;
    }

    .like-btn {
        min-width: 40px;
        min-height: 40px;
        margin-left: 2px;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {

    .artist-header,
    .album-header,
    .playlist-header {
        flex-direction: row;
        min-height: auto;
        padding: 16px 0;
    }

    .artist-image,
    .album-cover,
    .playlist-cover {
        width: 120px;
        height: 120px;
    }

    .artist-info,
    .album-info,
    .playlist-info {
        align-items: flex-start;
        text-align: left;
    }
}

/* Support for devices with notch */
@supports (padding: env(safe-area-inset-bottom)) {
    .player-bar {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .sidebar {
        padding-left: max(12px, env(safe-area-inset-left));
    }
}

/* Print styles */
@media print {

    .sidebar,
    .player-bar,
    .header,
    .play-overlay,
    .btn-icon,
    .btn-primary,
    .control-btn {
        display: none !important;
    }

    #app {
        display: block;
    }

    .main-content {
        padding: 0;
    }

    body {
        background: white;
        color: black;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --bg-primary: #000000;
        --bg-secondary: #111111;
        --bg-elevated: #222222;
        --text-primary: #FFFFFF;
        --text-secondary: #CCCCCC;
        --border: #666666;
    }

    .song-card,
    .album-card,
    .artist-card,
    .playlist-card {
        border: 1px solid var(--border);
    }
}

/* Fullscreen Player Responsive Adjustments */
@media (max-width: 480px),
(max-height: 750px) {
    .fullscreen-player-content {
        padding: 16px;
        /* Flexbox sandwich */
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        /* Distribute space */
        height: 100%;
        max-height: 100vh;
        overflow: hidden;
        /* Prevent scrolling within the player container */
    }

    /* 1. Header (Fixed top) */
    .fullscreen-header {
        margin-bottom: 0;
        /* Let flex gap/justify handle spacing */
        flex-shrink: 0;
        min-height: 48px;
    }

    /* 2. Artwork (Flexible middle) */
    .fullscreen-artwork {
        flex: 1;
        /* Take all available space */
        min-height: 0;
        /* CRITICAL: Allow shrinking below content size */
        margin: 16px 0;
        display: flex;
        align-items: center;
        justify-content: center;
        perspective: 1000px;
    }

    .fullscreen-artwork img {
        width: auto;
        height: auto;
        max-width: 100%;
        max-height: 100%;
        /* Fit within the flex container */
        object-fit: contain;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }

    /* 3. Info & Controls (Fixed bottom) */
    /* Wrapper to group bottom elements if needed, or target them individually */

    .fullscreen-info {
        margin-bottom: 12px;
        flex-shrink: 0;
    }

    .fullscreen-song-title {
        font-size: 20px;
        margin-bottom: 4px;
        line-height: 1.2;
    }

    .fullscreen-song-artist {
        font-size: 14px;
    }

    .fullscreen-progress-container {
        margin-bottom: 12px;
        flex-shrink: 0;
    }

    .fullscreen-controls {
        gap: 16px;
        margin-bottom: 16px;
        flex-shrink: 0;
    }

    /* Play button adjustments */
    .btn-play-xl {
        width: 56px;
        height: 56px;
    }

    .btn-play-xl svg {
        width: 28px;
        height: 28px;
    }

    .fullscreen-extras {
        margin-top: 0;
        /* Remove auto which might fight flex */
        margin-bottom: 0;
        flex-shrink: 0;
        min-height: 32px;
    }
}

/* Landscape mobile / alignment adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .fullscreen-player-content {
        flex-direction: row;
        align-items: center;
        gap: 24px;
    }

    .fullscreen-artwork {
        flex: 0 0 45%;
        /* Fixed width on landscape */
        height: 100%;
        margin: 0;
    }

    /* Right side container for landscape */
    .fullscreen-info,
    .fullscreen-progress-container,
    .fullscreen-controls,
    .fullscreen-extras {
        width: 100%;
        flex: 1;
    }
}