/* --- Base & Color Scheme Variables --- */
:root {
    /* Light Mode (Refined Black & White) */
    --body-bg-color: #f8f9fa;
    --content-bg-color: #ffffff;
    --text-color-primary: #212529;
    --text-color-secondary: #6c757d;
    --border-color-soft: #e9ecef;
    --border-color-medium: #ced4da;
    --shadow-color-soft: rgba(0,0,0,0.05);
    --shadow-color-medium: rgba(0,0,0,0.07);
    --button-bg: #f1f3f5;
    --button-text: var(--text-color-primary);
    --button-hover-bg: #e9ecef;
    --spotify-button-bg: #181818;
    --spotify-button-text: #ffffff;
    --spotify-button-hover-bg: #333333;
    --cover-placeholder-bg: var(--button-bg);
    --cover-placeholder-text-color: var(--text-color-secondary);
    
    --md-input-text-color: var(--text-color-primary);
    --md-input-placeholder-color: var(--text-color-secondary);
    --md-input-underline-color: #bdbdbd; 
    --md-input-underline-focus-color: var(--text-color-primary); 
    --md-input-bg-color: transparent; 

    --transition-speed: 0.2s;
    --transition-ease: ease-out;
    --base-font-size: 15.5px;
    --font-family-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    /* CSS variable for header height, JS will set this */
    --header-height: 60px; /* Default fallback, will be overridden by JS */
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Dark Mode (Refined Black & White) */
        --body-bg-color: #121212; 
        --content-bg-color: #1c1c1c; 
        --text-color-primary: #e8eaed; 
        --text-color-secondary: #9aa0a6; 
        --border-color-soft: #303134; 
        --border-color-medium: #525357;
        --shadow-color-soft: rgba(255,255,255,0.04);
        --shadow-color-medium: rgba(255,255,255,0.06);
        --button-bg: #282a2d;
        --button-text: var(--text-color-primary);
        --button-hover-bg: #3c4043;
        --spotify-button-bg: #e8eaed; 
        --spotify-button-text: #202124;
        --spotify-button-hover-bg: #ffffff;
        --cover-placeholder-bg: #232323;
        --cover-placeholder-text-color: var(--text-color-secondary);

        --md-input-text-color: var(--text-color-primary);
        --md-input-placeholder-color: var(--text-color-secondary);
        --md-input-underline-color: #616161; 
        --md-input-underline-focus-color: var(--text-color-primary); 
        --md-input-bg-color: transparent;
    }
}

/* --- General Body & Typography --- */
body {
    font-family: var(--font-family-sans);
    line-height: 1.65;
    margin: 0;
    padding-top: var(--header-height); /* CRITICAL: Space for fixed header */
    /* No padding-bottom as footer is removed */
    background-color: var(--body-bg-color);
    color: var(--text-color-primary);
    transition: background-color var(--transition-speed) var(--transition-ease), color var(--transition-speed) var(--transition-ease);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: var(--base-font-size);
    box-sizing: border-box; 
}

h1, h2, h3, h4, h5, h6 { margin-top: 0; margin-bottom: 0.7em; font-weight: 600; line-height: 1.3; color: var(--text-color-primary); }
p { margin-top: 0; margin-bottom: 1em; }
a { color: var(--text-color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.emoji-icon { display: inline-block; vertical-align: -0.15em; }

/* --- Fixed Header --- */
.fixed-header-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0; 
    width: 100%; 
    background-color: var(--content-bg-color);
    padding: 12px 25px;
    box-shadow: 0 0 10px var(--shadow-color-medium);
    z-index: 1000;
    text-align: center;
    box-sizing: border-box; 
    transition: background-color var(--transition-speed) var(--transition-ease), border-color var(--transition-speed) var(--transition-ease);
    border-bottom: 1px solid var(--border-color-soft);
}
.fixed-header-container h1 {
    font-size: 1.25em;
    font-weight: 600;
    margin:0; 
}
.fixed-header-container h1 .emoji-icon { 
    font-size: 1em; 
    margin: 0 0.3em;
}


/* --- Main Content Container (inside body with padding-top) --- */
.container {
    max-width: 860px;
    margin: 0 auto; 
    background: var(--content-bg-color);
    padding: 25px 30px; 
    /* No min-height needed here if body handles scroll and has padding */
    box-sizing: border-box;
}


/* --- Playlist Header & Cover Art --- */
#playlist-header { display: flex; align-items: flex-start; margin-bottom: 30px; padding-bottom: 25px; border-bottom: 1px solid var(--border-color-soft); }
.cover-art-container {
    margin-right: 25px;
    border-radius: 8px;
    background-color: var(--cover-placeholder-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid var(--border-color-medium);
}
.cover-art-container.playlist-main-cover { width: 160px; height: 160px; min-width: 160px; }
.cover-art-container img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: inherit; }
.cover-art-container .emoji-placeholder {
    font-size: 4em; 
    color: var(--cover-placeholder-text-color);
    line-height: 1;
    text-align: center;
    user-select: none;
}
.track-item .cover-art-container .emoji-placeholder { font-size: 1.8em; } 


#playlist-info h2#playlist-name { margin-bottom: 10px; font-size: 1.8em; font-weight: 700; }
#playlist-info p { margin-bottom: 10px; font-size: 0.95em; color: var(--text-color-secondary); }
#playlist-info p strong { color: var(--text-color-primary); font-weight: 600; }

/* --- Track List Section & Material Design Search Input (REFINED) --- */
.track-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center; 
    margin-bottom: 25px;
    border-bottom: 1px solid var(--border-color-soft);
    padding-bottom: 18px;
    gap: 20px; 
}
.track-list-header h2 {
    font-size: 1.4em;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    /* flex-grow: 1; /* Removed: Let search box be pushed by space-between */
    /* text-overflow: ellipsis; overflow: hidden; /* Optional */
}

.search-input-material-wrapper {
    position: relative; 
    width: auto; 
    max-width: 280px; 
    min-width: 180px; 
    /* margin-left: auto; /* Not needed if justify-content: space-between pushes it */
    /* If the title needs to take more space, this might be needed, or title gets flex-grow:1 */
}

#search-input {
    width: 100%;
    padding: 10px 2px 8px 2px; /* Padding for text, especially bottom for underline */
    font-size: 0.95em;
    font-family: var(--font-family-sans);
    color: var(--md-input-text-color);
    background-color: var(--md-input-bg-color); /* Transparent */
    border: none;
    border-bottom: 1px solid var(--md-input-underline-color); 
    outline: none;
    box-sizing: border-box;
    transition: border-color var(--transition-speed) var(--transition-ease);
}

#search-input::placeholder {
    color: var(--md-input-placeholder-color);
    opacity: 1; 
    transition: color var(--transition-speed) var(--transition-ease);
}

/* Underline active state - more prominent */
.search-input-material-wrapper .search-input-underline {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px; /* Focus underline height */
    background-color: var(--md-input-underline-focus-color);
    transform: scaleX(0); /* Hidden by default */
    transition: transform 0.25s var(--transition-ease); /* Smooth transition */
    pointer-events: none; /* So it doesn't interfere */
}
#search-input:focus + .search-input-underline {
    transform: scaleX(1); /* Show and expand on focus */
}
/* Optional: change placeholder color on focus for Material feel */
#search-input:focus::placeholder {
    color: var(--md-input-underline-focus-color); /* Or a lighter shade */
    opacity: 0.8;
}


#tracks { list-style: none; padding: 0; margin: 0; }
.track-item.hidden { display: none; }

/* --- Individual Track Item (Refined) --- */
.track-item { display: flex; align-items: center; padding: 12px 0px; border-bottom: 1px solid var(--border-color-soft); }
.track-item:last-child { border-bottom: none; }
.track-item:hover { background-color: var(--button-bg); }

.track-item .cover-art-container { width: 45px; height: 45px; min-width: 45px; margin-right: 15px; border-radius: 5px; }

.track-content { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }
.track-details .track-name { font-weight: 500; font-size: 0.95em; margin-bottom: 3px; }
.track-details .track-artist-album { font-size: 0.8em; color: var(--text-color-secondary); margin-bottom: 8px; }
.track-details .track-name, .track-details .track-artist-album { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.track-item .track-duration { font-size: 0.85em; color: var(--text-color-secondary); margin-left: 15px; min-width: 45px; text-align: right; }

/* --- Track Action Buttons --- */
.track-actions { margin-top: auto; padding-top: 4px; display: flex; flex-wrap: wrap; gap: 8px; }
.track-actions .action-button {
    padding: 5px 10px; font-size: 0.7em; text-transform: uppercase; letter-spacing: 0.5px;
    font-weight: 600; border-radius: 14px;
    background-color: var(--button-bg); color: var(--button-text); border: 1px solid var(--border-color-medium);
    transition: background-color var(--transition-speed) var(--transition-ease);
    text-decoration:none; white-space: nowrap;
}
.track-actions .action-button:hover { background-color: var(--button-hover-bg); text-decoration:none; }
.track-actions .action-button.spotify { background-color: var(--spotify-button-bg); color: var(--spotify-button-text); border-color: transparent; }
.track-actions .action-button.spotify:hover { background-color: var(--spotify-button-hover-bg); border-color: transparent; }

/* --- Loading / Error / No Tracks States --- */
.loading-placeholder, .error-message, .no-tracks, .no-results-message {
    text-align: center; padding: 30px 15px; font-style: italic; font-size: 0.9em;
    color: var(--text-color-secondary); display: block; width: 100%;
}
.error-message { color: #c00; font-weight: 500; }
@media (prefers-color-scheme: dark) { .error-message { color: #ff7f7f; } }

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    body { font-size: 15px; }
    .container { padding: 25px 20px; }
    .fixed-header-container h1 { font-size: 1.1em; }
    
    .track-list-header {
        flex-wrap: wrap; 
        justify-content: flex-start;
    }
    .track-list-header h2 {
        width: 100%; 
        margin-bottom: 12px;
        text-align: left;
    }
    .search-input-material-wrapper { 
        width: 100%; 
        max-width: none;
        margin-left: 0;
        flex-basis: auto; 
    }
    .cover-art-container.playlist-main-cover { width: 120px; height: 120px; min-width: 120px; }
    .cover-art-container.playlist-main-cover .emoji-placeholder { font-size: 3.5em; }
    #playlist-info h2#playlist-name { font-size: 1.5em; }
}

@media (max-width: 480px) {
    body { font-size: 14px; }
    .container { padding: 20px 15px; }
    .fixed-header-container { padding: 10px 15px; }
    .fixed-header-container h1 { font-size: 1em; }
    
    .cover-art-container.playlist-main-cover { width: 80px; height: 80px; min-width: 80px; }
    .cover-art-container.playlist-main-cover .emoji-placeholder { font-size: 2.5em; }
    #playlist-info h2#playlist-name { font-size: 1.2em; }

    .track-item { flex-direction: column; align-items: flex-start; padding: 12px 0; }
    .track-item .cover-art-container { margin-bottom: 12px; margin-right: 0; width: 40px; height: 40px; min-width: 40px; }
    .track-item .cover-art-container .emoji-placeholder { font-size: 1.5em; }
    .track-content { width: 100%; }
    .track-item .track-duration { margin-left: 0; margin-top: 8px; text-align: left; }
    .track-actions .action-button { font-size: 0.75em; padding: 5px 10px; }
}