:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #334155;
    --bg-input: #1e293b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --warning: #eab308;
    --danger: #ef4444;
    --border: #475569;
    --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: 220px;
    background: var(--bg-secondary);
    padding: 1rem;
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.sidebar h1 { font-size: 1.5rem; margin-bottom: 2rem; color: var(--accent); }
.sidebar nav a {
    display: block;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: var(--radius);
    color: var(--text-secondary);
    transition: background 0.15s;
}
.sidebar nav a:hover, .sidebar nav a.active {
    background: var(--bg-card);
    color: var(--text-primary);
}
.main-content {
    margin-left: 220px;
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.card h3 { margin-bottom: 0.5rem; }

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.stat-card .value { font-size: 2rem; font-weight: bold; color: var(--accent); }
.stat-card .label { font-size: 0.85rem; color: var(--text-secondary); }

/* Album art */
.album-art {
    width: 48px;
    height: 48px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--bg-card);
    vertical-align: middle;
}
.album-art-lg {
    width: 250px;
    height: 250px;
    border-radius: var(--radius);
    object-fit: cover;
    background: var(--bg-card);
}
.album-art-placeholder {
    display: inline-block;
    width: 48px;
    height: 48px;
    border-radius: 4px;
    background: var(--bg-card);
}
.album-art-placeholder-lg {
    display: block;
    width: 250px;
    height: 250px;
    border-radius: var(--radius);
    background: var(--bg-card);
}
.album-header {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}
.artist-meta {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.25rem;
}
.artist-meta .tag {
    font-size: 0.8rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-secondary);
}
.artist-links {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}
.artist-links a {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.artist-links a:hover { color: var(--accent); }
.artist-banner-wrap {
    background-size: 100% auto;
    background-position: top center;
    background-repeat: no-repeat;
    border-radius: var(--radius);
    margin: -2rem -2rem 1rem -2rem;
    padding: 2rem;
    padding-top: 30%;
    position: relative;
}
.artist-banner-wrap::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(15,23,42,0.4) 0%, rgba(15,23,42,0.85) 60%, rgba(15,23,42,0.95) 100%);
    border-radius: var(--radius);
    pointer-events: none;
}
.artist-banner-wrap > * {
    position: relative;
    z-index: 1;
}
.artist-photo {
    width: 120px;
    height: 120px;
    border-radius: var(--radius);
    object-fit: cover;
    flex-shrink: 0;
}
.artist-bio {
    color: var(--text-secondary);
    line-height: 1.6;
    max-width: 800px;
    margin-top: 0.5rem;
}
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    z-index: 10;
    max-height: 250px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.autocomplete-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.autocomplete-item:hover {
    background: var(--bg-hover);
}
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.5rem;
}
.lyrics {
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
    padding: 1rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    max-height: 400px;
    overflow-y: auto;
    margin: 0;
}

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.75rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-secondary); font-weight: 600; font-size: 0.85rem; text-transform: uppercase; text-align: center; }
tr:hover { background: var(--bg-card); }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
/* Progress bars for library columns */
.progress-bar-wrap {
    position: relative;
    background: var(--bg-card);
    border-radius: 4px;
    height: 1.4rem;
    min-width: 4.5rem;
    overflow: hidden;
}
.progress-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 4px;
    opacity: 0.3;
    transition: width 0.3s ease;
}
.progress-bar-text {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-fixed { min-width: 5.5rem; text-align: center; }
.btn-lib { min-width: 4.5rem; text-align: center; padding-left: 0.25rem; padding-right: 0.25rem; }

/* Forms */
input, select {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.search-bar { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.search-bar input { flex: 1; }
.search-bar select { width: auto; min-width: 120px; }

/* Form groups */
.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.25rem; }
.form-group input[type="number"] { width: 150px; }
.form-group select { width: auto; min-width: 150px; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: auto; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-wanted { background: var(--warning); color: #000; }
.badge-available { background: var(--accent); color: white; }
.badge-downloaded { background: var(--success); color: white; }
.badge-owned { background: #6366f1; color: white; }
.badge-pending { background: var(--text-muted); color: white; }
.badge-failed { background: var(--danger); color: white; }
.badge-completed { background: var(--success); color: white; }
.badge-success { background: var(--success); color: white; }

/* Task table fixed column widths */
table.tasks-table { table-layout: fixed; }
table.tasks-table th:nth-child(1) { width: 100px; }
table.tasks-table th:nth-child(2) { width: 100px; }
table.tasks-table th:nth-child(3) { width: 40%; }
table.tasks-table td { overflow: hidden; text-overflow: ellipsis; }

/* Page header */
.page-header { margin-bottom: 1.5rem; }
.page-header h2 { font-size: 1.5rem; }
.page-header p { color: var(--text-secondary); }

/* Utility */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 0.85rem; }
.loading { color: var(--text-muted); font-style: italic; }
.error { color: var(--danger); }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Auth pages */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}
.auth-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}
.auth-card h1 { font-size: 1.8rem; color: var(--accent); margin-bottom: 0.25rem; }
.auth-card p { margin-bottom: 1.5rem; }

/* Tab bar */
.tab-bar { display: flex; gap: 0; margin-bottom: 1rem; border-bottom: 2px solid var(--border); }
.tab-btn { padding: 0.5rem 1rem; background: none; border: none; color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; font-size: 0.9rem; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover { color: var(--text-primary); }

/* Drag and drop */
.drag-handle { cursor: grab; user-select: none; color: var(--text-muted); padding-right: 0.5rem; font-size: 1.2rem; }
tr.drag-over { background: rgba(59, 130, 246, 0.1); }
tr[draggable="true"] { cursor: grab; }
tr[draggable="true"]:active { cursor: grabbing; }

/* Sidebar user section */
.sidebar-user {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Hamburger menu button — hidden on desktop */
.hamburger {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 101;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1.4rem;
    padding: 0.25rem 0.6rem;
    cursor: pointer;
    line-height: 1;
}

/* Sidebar overlay — hidden on desktop */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .hamburger { display: block; }
    .sidebar-overlay.open { display: block; }
    .sidebar {
        transform: translateX(-100%);
        z-index: 100;
        transition: transform 0.2s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 3.5rem;
    }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    table { display: block; overflow-x: auto; }
    .form-group input[type="text"],
    .form-group input[type="number"],
    .form-group input[type="password"],
    .form-group select {
        width: 100% !important;
        min-width: 0 !important;
    }
    .tab-bar { overflow-x: auto; }
    .album-art-lg { width: 120px; height: 120px; }
    .album-header { flex-direction: column; }
    .artist-photo { width: 80px; height: 80px; }
    .scroll-track { width: 18px; }
    .scroll-track-letter { font-size: 0.7rem; }
    .playlist-controls-row { grid-template-columns: repeat(2, 1fr); }
}

/* Tooltips */
.tooltip-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: bold;
    cursor: help;
    flex-shrink: 0;
}
.tooltip-text {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    width: 240px;
    padding: 0.5rem 0.6rem;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.75rem;
    line-height: 1.4;
    z-index: 50;
    pointer-events: none;
    transition: opacity 0.15s;
}
.tooltip-wrap:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Playlist controls row */
.playlist-controls-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    align-items: end;
}

/* Alphabetical scroll track — fixed to right edge next to browser scrollbar */
.scroll-track {
    position: fixed;
    right: 18px;
    top: 0;
    bottom: 0;
    width: 28px;
    z-index: 100;
    pointer-events: none;
    overflow: hidden;
}
.scroll-track-letter {
    pointer-events: auto;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    user-select: none;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow: hidden;
}
.scroll-track-letter:hover {
    color: var(--accent);
}
