.online-search-page {
    min-height: 100vh;
    background: var(--bg-color);
    color: var(--font-color);
    max-width: none;
    width: 100%;
    padding: 1rem 0;
    /* Ensure proper stacking context */
    position: relative;
    /* Do not raise z-index here; it can overlay the sidebar and block clicks */
    z-index: 0;
}

.section {
    margin-bottom: 1.5rem;
    padding: 0 1.5rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.container {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.section_title {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--font-color);
    margin: 0;
    font-family: var(--inter-font);
}

.section_desc {
    font-size: 0.875rem;
    color: var(--font-color-secondary);
    margin: 0;
    opacity: 0.8;
}

.search-input-container {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 1200px;
    width: 100%;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    padding: 0.875rem 1rem 0.875rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: var(--inter-font);
    transition: all 0.2s ease;
    background-color: var(--input-bg);
    color: var(--font-color);
    box-sizing: border-box;
    height: 48px;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(var(--accent-color-rgb), 0.1);
    background-color: var(--input-bg-focus);
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--font-color-secondary);
    pointer-events: none;
    z-index: 1;
    width: 20px;
    height: 20px;
}

.search-filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}

.filter-chip {
    background: var(--button-bg);
    color: var(--font-color);
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--inter-font);
    font-weight: 500;
}

.filter-chip:hover {
    background: var(--button-bg-hover);
    border-color: var(--accent-color);
}

.filter-chip.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.search-button, .download-button {
    padding: 0.5rem;
    border: none;
    border-radius: 0 0 8px 8px;
    background-color: var(--accent-color);
    color: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.2s ease;
    height: 32px;
    white-space: nowrap;
    margin-top: auto;
    align-self: stretch;
    font-family: var(--inter-font);
}

.search-button:hover, .download-button:hover {
    background-color: var(--brand-color);
}

.search-button:disabled, .download-button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.search-type-select {
    padding: 0.75rem;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background-color: #2a2a2a;
    color: #fff;
    min-width: 120px;
}

.connection-status-banner {
    background-color: #dc3545;
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    text-align: center;
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.2);
}

.search-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
    width: 100%;
    max-width: none;
    position: relative;
    padding-bottom: 1rem;
}

.result-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    position: relative;
}

.result-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--accent-color);
}

.result-item:nth-child(1) { animation-delay: 0.1s; }
.result-item:nth-child(2) { animation-delay: 0.2s; }
.result-item:nth-child(3) { animation-delay: 0.3s; }
.result-item:nth-child(4) { animation-delay: 0.4s; }
.result-item:nth-child(5) { animation-delay: 0.5s; }
.result-item:nth-child(6) { animation-delay: 0.6s; }
.result-item:nth-child(n+7) { animation-delay: 0.7s; }

.result-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--image-placeholder-bg);
    transition: transform 0.3s ease;
}

.result-item:hover .result-image {
    transform: scale(1.05);
}

.result-info {
    padding: 0.75rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    background: var(--card-bg);
}

.result-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--font-color);
    margin: 0;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.result-artist {
    font-size: 0.8rem;
    color: var(--font-color-secondary);
    margin: 0;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.result-duration {
    font-size: 0.8rem;
    color: var(--font-color-tertiary);
    margin: 0;
    font-weight: 500;
}

.download-button {
    margin: 1rem 1.25rem 1.25rem;
    width: calc(100% - 2.5rem);
    padding: 0.75rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px; /* Ensure adequate touch target size */
}

.download-button:hover {
    background: var(--brand-color);
    transform: translateY(-1px);
}

.download-button.downloading {
    background: var(--warning-color);
    cursor: not-allowed;
    min-height: 60px; /* Accommodate progress bar */
    padding: 0.5rem;
}

.download-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
}

.spinner-small {
    width: 12px;
    height: 12px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.download-complete {
    color: var(--success-color);
    font-size: 0.8rem;
    font-weight: 500;
}

.download-failed {
    color: var(--error-color);
    font-size: 0.8rem;
    font-weight: 500;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.download-button:disabled {
    background: var(--button-disabled-bg);
    color: var(--button-disabled-color);
    cursor: not-allowed;
    transform: none;
}

.connection-banner {
    background: linear-gradient(135deg, #dc3545, #c82333);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    margin: 1.5rem 0;
    text-align: center;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.2);
    border: 1px solid rgba(220, 53, 69, 0.3);
}

.no-results {
    text-align: center;
    color: var(--font-color-secondary);
    font-size: 0.875rem;
    padding: 2rem 1rem;
    grid-column: 1 / -1;
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px dashed var(--border-color);
}

.loading-overlay {
    position: relative;
    background-color: rgba(var(--bg-color-rgb, 255, 255, 255), 0.8);
    backdrop-filter: blur(1px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    border-radius: 8px;
    margin: 1rem 0;
    min-height: 150px;
    border: 1px dashed var(--border-color);
}

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeInUp {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Progress Bar Styles */
.download-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background-color: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
    /* Add subtle glow effect */
    box-shadow: 0 0 2px rgba(0, 164, 220, 0.3);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), var(--brand-color));
    border-radius: 3px;
    transition: width 0.3s ease;
    /* Add subtle animation for active downloading */
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 0.8; }
    50% { opacity: 1; }
    100% { opacity: 0.8; }
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.download-progress span {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--font-color-secondary);
    min-width: 35px;
    text-align: right;
}

/* Clickable Cover Styles */
.result-image.clickable {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.result-image.clickable:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--bg-color);
    border-radius: 12px;
    max-width: 480px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color-secondary);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--font-color);
    flex: 1;
    padding-right: 16px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--font-color-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.modal-close:hover {
    background-color: var(--bg-color-secondary);
    color: var(--font-color);
}

.modal-body {
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
}

.modal-image {
    flex-shrink: 0;
}

.modal-image img {
    width: 80px;
    height: 80px;
    border-radius: 6px;
    object-fit: cover;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.modal-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.info-label {
    font-weight: 500;
    color: var(--font-color-secondary);
    min-width: 70px;
    font-size: 0.875rem;
}

.info-value {
    color: var(--font-color);
    font-size: 0.875rem;
    flex: 1;
}

.info-link {
    color: var(--accent-color);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.2s ease;
}

.info-link:hover {
    color: var(--brand-color);
    text-decoration: underline;
}

/* Mobile Modal Styles */
@media (max-width: 600px) {
    .modal-content {
        margin: 10px;
        max-height: 90vh;
    }
    
    .modal-body {
        flex-direction: column;
        gap: 16px;
    }
    
    .modal-image {
        align-self: center;
    }
    
    .modal-image img {
        width: 100px;
        height: 100px;
    }
}

/* iPhone/iPad PWA Fixes */
@media (max-width: 800px) and (pointer: coarse) {
    .online-search-page {
        padding: 0;
        margin: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        /* Use safe area insets to avoid notches and home bar */
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
        box-sizing: border-box;
        /* Ensure proper stacking context */
        position: relative;
        z-index: 1;
    }
    
    .section {
        padding: 0 1rem;
        margin-bottom: 1rem;
    }
    
    .search-input-container {
        padding: 0;
        margin: 0;
    }
    
    .search-results {
        padding: 0 0.5rem 1rem 0.5rem;
        margin-top: 1rem;
        /* Ensure grid items fill available space */
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    
    .result-item {
        margin: 0;
    }
    
    /* Enhanced download button for mobile */
    .download-button {
        margin: 0.75rem 1rem 1rem;
        width: calc(100% - 2rem);
        padding: 0.6rem;
        font-size: 0.85rem;
    }
    
    .download-button.downloading {
        min-height: 50px;
    }
    
    /* Make progress bar more visible on mobile */
    .progress-bar-container {
        height: 8px;
        box-shadow: 0 0 4px rgba(0, 164, 220, 0.5);
    }
    
    .download-progress span {
        font-size: 0.8rem;
        font-weight: 600;
        color: var(--font-color);
    }
    
    /* Add subtle background to downloading button for better visibility */
    .download-button.downloading {
        background: linear-gradient(135deg, var(--warning-color), #ff9800);
        box-shadow: 0 2px 8px rgba(255, 152, 0, 0.3);
    }
}
/* Spotify-Style Modal */
.spotify-style-modal {
    max-width: 600px;
    width: 90%;
    background: #1a1a1a;
    color: white;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.spotify-modal-header {
    display: flex;
    gap: 24px;
    padding: 32px;
    background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
}

.large-artwork {
    flex-shrink: 0;
}

.large-artwork img {
    width: 200px;
    height: 200px;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.track-main-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
}

.track-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.1;
    color: white;
}

.track-artist {
    font-size: 1.2rem;
    color: #b3b3b3;
    margin: 0;
    font-weight: 500;
}

.track-album {
    font-size: 1rem;
    color: #b3b3b3;
    margin: 0;
}

.track-stats {
    display: flex;
    gap: 16px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.stat-item {
    font-size: 0.9rem;
    color: #b3b3b3;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.track-badges {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.type-badge {
    background: #1db954;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

.explicit-badge {
    background: #e22134;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

.modal-actions-row {
    display: flex;
    gap: 16px;
    padding: 0 32px 24px;
}

.download-btn {
    flex: 1;
    background: #1db954;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 24px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.2s;
    letter-spacing: 0.5px;
}

.download-btn:hover {
    background: #1ed760;
}

.spotify-btn {
    flex: 1;
    background: transparent;
    color: white;
    border: 2px solid #1db954;
    padding: 12px 24px;
    border-radius: 24px;
    font-weight: 700;
    font-size: 0.9rem;
    text-decoration: none;
    text-align: center;
    transition: all 0.2s;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spotify-btn:hover {
    background: #1db954;
    color: white;
}

.album-tracks-section {
    padding: 0 32px 24px;
    border-top: 1px solid #333;
    margin-top: 8px;
    padding-top: 24px;
}

.album-tracks-section h3 {
    font-size: 1rem;
    font-weight: 700;
    color: #b3b3b3;
    margin-bottom: 16px;
    letter-spacing: 1px;
}

.current-track-highlight {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px;
    background: rgba(29, 185, 84, 0.1);
    border-radius: 8px;
    border-left: 3px solid #1db954;
}

.track-number {
    font-size: 0.9rem;
    color: #1db954;
    font-weight: 700;
    min-width: 40px;
}

.track-info {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.track-name {
    color: white;
    font-weight: 500;
}

.track-duration {
    color: #b3b3b3;
    font-size: 0.9rem;
}

.play-btn {
    background: #1db954;
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

.tracks-note {
    color: #666;
    font-size: 0.8rem;
    margin-top: 16px;
    font-style: italic;
    text-align: center;
}

.preview-section {
    padding: 0 32px 32px;
    border-top: 1px solid #333;
    margin-top: 8px;
    padding-top: 24px;
}

.preview-section h3 {
    font-size: 1rem;
    font-weight: 700;
    color: #b3b3b3;
    margin-bottom: 16px;
    letter-spacing: 1px;
}

.preview-player {
    width: 100%;
    height: 40px;
    border-radius: 8px;
}

/* Responsive design */
@media (max-width: 768px) {
    .spotify-modal-header {
        flex-direction: column;
        text-align: center;
        padding: 24px;
    }
    
    .large-artwork img {
        width: 150px;
        height: 150px;
    }
    
    .track-title {
        font-size: 2rem;
    }
    
    .modal-actions-row {
        flex-direction: column;
        padding: 0 24px 24px;
    }
}