/* ═══════════════════════════════════════════════
   SCROBBLE MANAGER — Dark Music Dashboard Theme
   ═══════════════════════════════════════════════ */

:root {
    --fm-red: #d51007;
    --fm-red-soft: #e8342b;
    --fm-red-glow: rgba(213, 16, 7, 0.3);
    --fm-dark: #0d0d0d;
    --fm-surface: #161616;
    --fm-surface-raised: #1e1e1e;
    --fm-surface-hover: #252525;
    --fm-border: #2a2a2a;
    --fm-text: #e8e6e3;
    --fm-text-muted: #8a8a8a;
    --fm-success: #2ecc71;
    --fm-warning: #f39c12;
    --fm-danger: #e74c3c;

    --font-display: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

/* Pico overrides */
[data-theme="dark"] {
    --pico-background-color: var(--fm-dark);
    --pico-card-background-color: var(--fm-surface);
    --pico-card-border-color: var(--fm-border);
    --pico-primary: var(--fm-red);
    --pico-primary-hover: var(--fm-red-soft);
    --pico-color: var(--fm-text);
    --pico-muted-color: var(--fm-text-muted);
    --pico-border-color: var(--fm-border);
    --pico-form-element-background-color: var(--fm-surface);
    --pico-form-element-border-color: var(--fm-border);
    --pico-form-element-focus-color: var(--fm-red);
}

/* ── Film grain overlay ── */
.grain-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-size: 128px;
}

/* ── Typography ── */
body {
    font-family: var(--font-display);
    font-weight: 400;
    letter-spacing: -0.01em;
    background: var(--fm-dark);
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.03em;
}

code, pre, .mono {
    font-family: var(--font-mono);
}

/* ── Navigation ── */
.topnav {
    border-bottom: 1px solid var(--fm-border);
    padding: 0.8rem 2rem;
    backdrop-filter: blur(12px);
    background: rgba(13, 13, 13, 0.85);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topnav ul {
    margin: 0;
    align-items: center;
}

.topnav a {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--fm-text-muted);
    text-decoration: none;
    transition: color 0.2s;
    border-bottom: 2px solid transparent;
    padding-bottom: 0.3rem;
}

.topnav a:hover,
.topnav a.active {
    color: var(--fm-text);
}

.topnav a.active {
    border-bottom-color: var(--fm-red);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--fm-text) !important;
    font-size: 1rem !important;
}

.brand-icon {
    color: var(--fm-red);
    font-size: 1.3rem;
}

/* ── Nav dropdowns ── */
.nav-dropdown {
    position: relative;
}

.nav-dropdown > a small {
    font-size: 0.7em;
    margin-left: 0.15rem;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    background: var(--fm-card);
    border: 1px solid var(--fm-border);
    border-radius: 8px;
    padding: 0.4rem 0;
    min-width: 160px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 200;
}

.dropdown-menu a {
    display: block;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    color: var(--fm-text-muted) !important;
    border-bottom: none !important;
    white-space: nowrap;
}

.dropdown-menu a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--fm-text) !important;
}

[x-cloak] { display: none !important; }

/* ── Fetch progress ── */
.fetch-progress {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--fm-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}

.fetch-progress.done {
    border-color: #4caf50;
    background: rgba(76, 175, 80, 0.1);
}

.fetch-progress.error {
    border-color: var(--fm-red);
    background: rgba(186, 24, 27, 0.1);
}

.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--fm-text-muted);
    border-top-color: var(--fm-red);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Main container ── */
main.container {
    padding-top: 2rem;
    padding-bottom: 4rem;
    max-width: 960px;
}

/* ── Page headers ── */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.page-header p {
    color: var(--fm-text-muted);
    margin-bottom: 0;
}

/* ── Cards ── */
article, .card {
    background: var(--fm-surface);
    border: 1px solid var(--fm-border);
    border-radius: 8px;
    padding: 1.5rem;
}

/* ── Date range form ── */
.date-range-form {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 1rem;
    align-items: end;
}

.date-range-form label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--fm-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.3rem;
}

.date-range-form input[type="date"] {
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

/* ── Buttons ── */
button, [type="submit"], .btn {
    font-family: var(--font-display);
    font-weight: 500;
    letter-spacing: 0.02em;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-red {
    background: var(--fm-red);
    border-color: var(--fm-red);
    color: white;
}

.btn-red:hover {
    background: var(--fm-red-soft);
    border-color: var(--fm-red-soft);
    box-shadow: 0 0 20px var(--fm-red-glow);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--fm-border);
    color: var(--fm-text);
}

.btn-outline:hover {
    background: var(--fm-surface-hover);
    border-color: var(--fm-text-muted);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.btn-danger {
    background: var(--fm-danger);
    border-color: var(--fm-danger);
    color: white;
}

.btn-danger:hover {
    opacity: 0.9;
}

/* ── Scrobble table ── */
.scrobble-table {
    width: 100%;
    border-collapse: collapse;
}

.scrobble-table th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--fm-text-muted);
    border-bottom: 1px solid var(--fm-border);
    padding: 0.6rem 0.8rem;
    text-align: left;
}

.scrobble-table td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--fm-border);
    font-size: 0.9rem;
    vertical-align: middle;
}

.scrobble-table tr:last-child td {
    border-bottom: none;
}

.scrobble-table tr:hover {
    background: var(--fm-surface-hover);
}

.scrobble-table .track-name {
    font-weight: 500;
    color: var(--fm-text);
}

.scrobble-table .artist-name {
    color: var(--fm-red-soft);
}

.scrobble-table .album-name {
    color: var(--fm-text-muted);
    font-size: 0.85rem;
}

.scrobble-table .timestamp {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--fm-text-muted);
    white-space: nowrap;
}

.scrobble-img {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--fm-surface-hover);
}

/* ── Duplicate groups ── */
.duplicate-group {
    border: 1px solid var(--fm-border);
    border-radius: 8px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.duplicate-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.2rem;
    background: var(--fm-surface-raised);
    border-bottom: 1px solid var(--fm-border);
}

.duplicate-group-header .track-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.duplicate-group-header .track-info .track {
    font-weight: 600;
    font-size: 1rem;
}

.duplicate-group-header .track-info .artist {
    font-size: 0.85rem;
    color: var(--fm-red-soft);
}

.duplicate-count {
    background: var(--fm-red);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-family: var(--font-mono);
    white-space: nowrap;
}

.group-deselected {
    opacity: 0.4;
    filter: grayscale(0.5);
    transition: opacity 0.2s, filter 0.2s;
}

.duplicate-group:not(.group-deselected) {
    transition: opacity 0.2s, filter 0.2s;
}

.duplicate-instances {
    padding: 0;
}

.duplicate-instance {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1.2rem;
    border-bottom: 1px solid var(--fm-border);
    font-size: 0.85rem;
}

.duplicate-instance:last-child {
    border-bottom: none;
}

.duplicate-instance.keep {
    background: rgba(46, 204, 113, 0.05);
    border-left: 3px solid var(--fm-success);
}

.duplicate-instance.remove {
    background: rgba(231, 76, 60, 0.05);
    border-left: 3px solid var(--fm-danger);
    opacity: 0.7;
}

.instance-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
}

.instance-label.keep {
    color: var(--fm-success);
    background: rgba(46, 204, 113, 0.1);
}

.instance-label.remove {
    color: var(--fm-danger);
    background: rgba(231, 76, 60, 0.1);
}

/* ── Progress bar ── */
.progress-container {
    margin: 1.5rem 0;
}

.progress-bar-wrapper {
    background: var(--fm-surface);
    border: 1px solid var(--fm-border);
    border-radius: 6px;
    height: 28px;
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--fm-red), var(--fm-red-soft));
    border-radius: 6px;
    transition: width 0.3s ease;
    position: relative;
}

.progress-bar-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    animation: shimmer 2s infinite;
}

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

.progress-text {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--fm-text-muted);
    margin-top: 0.5rem;
    text-align: center;
}

/* ── Stats cards ── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--fm-surface);
    border: 1px solid var(--fm-border);
    border-radius: 8px;
    padding: 1rem 1.2rem;
    text-align: center;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--fm-text);
    line-height: 1;
    margin-bottom: 0.3rem;
}

.stat-value.red { color: var(--fm-red); }
.stat-value.green { color: var(--fm-success); }

.stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--fm-text-muted);
}

/* ── Auth page ── */
.auth-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.auth-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.auth-dot.connected {
    background: var(--fm-success);
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.4);
}

.auth-dot.disconnected {
    background: var(--fm-danger);
}

/* ── Setup form ── */
.setup-form {
    max-width: 500px;
}

.setup-form label {
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fm-text-muted);
}

.setup-form input {
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

/* ── Flash messages ── */
.flash-message {
    background: var(--fm-surface-raised);
    border: 1px solid var(--fm-red);
    border-left: 4px solid var(--fm-red);
    border-radius: 6px;
    padding: 0.8rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Empty states ── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--fm-text-muted);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

/* ── Footer ── */
footer {
    border-top: 1px solid var(--fm-border);
    padding: 1.5rem 2rem;
    text-align: center;
}

.footer-text {
    color: var(--fm-text-muted);
    font-size: 0.8rem;
}

/* ── HTMX loading indicator ── */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--fm-border);
    border-top-color: var(--fm-red);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 0.4rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .date-range-form {
        grid-template-columns: 1fr;
    }

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

    .topnav {
        padding: 0.6rem 1rem;
    }
}

/* ── Period picker ── */
.period-picker {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.period-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.period-buttons button {
    margin: 0;
}

/* ── Tab bar ── */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--fm-border);
    margin-bottom: 1rem;
}

.tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--fm-text-muted);
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
    color: var(--fm-text);
}

.tab-btn.active {
    color: var(--fm-text);
    border-bottom-color: var(--fm-red);
}

/* ── Chart containers ── */
.chart-container {
    padding: 1.5rem;
}

.chart-container h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.chart-wrapper {
    position: relative;
    height: 350px;
}

.chart-wrapper-square {
    height: 300px;
    max-width: 300px;
    margin: 0 auto;
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ── Collage grid ── */
.collage-grid {
    display: grid;
    gap: 2px;
    background: var(--fm-dark);
}

.collage-tile {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--fm-surface-raised);
}

.collage-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tile-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(transparent 50%, rgba(0,0,0,0.85));
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.collage-tile:hover .tile-overlay,
.collage-grid.show-labels .tile-overlay,
.mosaic-container.show-labels .tile-overlay {
    opacity: 1;
}

.tile-overlay .tile-album {
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    line-height: 1.2;
}

.tile-overlay .tile-artist {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.7);
}

.tile-overlay .tile-plays {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--fm-red-soft);
}

.tile-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.7rem;
    color: var(--fm-text-muted);
    background: var(--fm-surface-hover);
}

/* ── Mosaic layout ── */
.mosaic-container {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-flow: dense;
    gap: 2px;
    background: var(--fm-dark);
}

.mosaic-tile {
    position: relative;
    overflow: hidden;
    background: var(--fm-surface-raised);
}

.mosaic-tile[data-span="3"] {
    grid-column: span 3;
    grid-row: span 3;
}

.mosaic-tile[data-span="2"] {
    grid-column: span 2;
    grid-row: span 2;
}

.mosaic-tile[data-span="1"] {
    grid-column: span 1;
    grid-row: span 1;
}

.mosaic-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ── Search ── */
.search-bar {
    display: flex;
    gap: 0.75rem;
    align-items: end;
}

.search-bar input[type="search"] {
    flex: 1;
    font-size: 0.95rem;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--fm-surface);
    border: 1px solid var(--fm-border);
    border-radius: 6px;
}

.filter-row label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--fm-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0;
}

.filter-row select {
    font-size: 0.85rem;
    padding: 0.3rem 0.6rem;
    margin: 0;
}

/* ── Timeline ── */
.timeline-section {
    margin-bottom: 2rem;
}

.streak-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.streak-card {
    background: var(--fm-surface);
    border: 1px solid var(--fm-border);
    border-radius: 8px;
    padding: 1rem 1.2rem;
}

.streak-card .streak-value {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--fm-red);
}

.streak-card .streak-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--fm-text-muted);
    margin-top: 0.2rem;
}

.streak-card .streak-dates {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--fm-text-muted);
    margin-top: 0.4rem;
}

.discovery-list {
    list-style: none;
    padding: 0;
}

.discovery-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--fm-border);
}

.discovery-item:last-child {
    border-bottom: none;
}

.discovery-artist {
    font-weight: 500;
}

.discovery-meta {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--fm-text-muted);
    text-align: right;
}

/* ── Utility ── */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.text-muted { color: var(--fm-text-muted); }
.text-red { color: var(--fm-red); }
.text-center { text-align: center; }
.text-mono { font-family: var(--font-mono); }

/* ── Heatmap ── */
.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    justify-content: flex-end;
}

.heatmap-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.heatmap-tooltip {
    position: absolute;
    background: var(--fm-surface-raised);
    border: 1px solid var(--fm-border);
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--fm-text);
    pointer-events: none;
    z-index: 200;
    white-space: nowrap;
}

.heatmap-cell:hover {
    stroke: var(--fm-text);
    stroke-width: 1;
}

/* ── Records grid ── */
.records-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.record-card {
    text-align: center;
    padding: 1.5rem 1rem;
}

.record-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.6;
}

.record-value {
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--fm-red);
    margin-bottom: 0.3rem;
}

.record-title {
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--fm-text-muted);
    margin-bottom: 0.5rem;
}

.record-detail {
    font-size: 0.9rem;
    line-height: 1.4;
}

/* ── Artist links ── */
.artist-name a {
    color: var(--fm-red-soft);
    text-decoration: none;
}

.artist-name a:hover {
    text-decoration: underline;
}

/* ── Dashboard On This Day ── */
details summary {
    cursor: pointer;
    padding: 0.5rem 0;
    color: var(--fm-text);
}

details summary:hover {
    color: var(--fm-red-soft);
}

/* ── Achievements ── */
.achievement-locked {
    opacity: 0.35;
    filter: grayscale(0.7);
}

.achievement-locked:hover {
    opacity: 0.6;
    filter: grayscale(0.3);
    transition: all 0.2s;
}

/* ── Responsive additions ── */
@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }

    .period-buttons {
        gap: 0.3rem;
    }

    .period-buttons button {
        font-size: 0.75rem;
        padding: 0.3rem 0.6rem;
    }

    .tab-btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }

    .mosaic-container {
        grid-template-columns: repeat(3, 1fr);
    }

    .mosaic-tile[data-span="3"] {
        grid-column: span 3;
        grid-row: span 3;
    }

    .mosaic-tile[data-span="2"] {
        grid-column: span 2;
        grid-row: span 2;
    }
}
