/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;600;700&display=swap');

/* Global Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --bg-black: #000000;
    --bg-dark: #121212;
    --bg-card: #181818;
    --bg-hover: #282828;
    --text-primary: #FFFFFF;
    --text-secondary: #B3B3B3;
    --spotify-green: #1DB954;
    --gradient-1: linear-gradient(135deg, #4b1085, #1d2570);
    --gradient-2: linear-gradient(135deg, #1e3c72, #2a5298);
    --border-radius: 8px;
}

body {
    background-color: var(--bg-black);
    color: var(--text-primary);
    font-family: 'Montserrat', sans-serif;
    margin: 0;
    padding: 0;
    /* Standard scroll behavior, not app-fixed */
    min-height: 100vh;
    overflow-x: hidden;
    /* Prevent horizontal scroll from gallery */
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-black);
}

::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* Utilities */
.hidden {
    display: none !important;
}

.d-none {
    display: none !important;
}

.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

/* App Container */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Header */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-primary);
}

.logo-area i {
    color: var(--spotify-green);
}

.logo-area h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.pill-btn-action {
    background-color: var(--spotify-green);
    color: #000;
    border: none;
    padding: 8px 24px;
    border-radius: 500px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s;
}

.pill-btn-action.sec {
    background-color: transparent;
    border: 1px solid #777;
    color: #fff;
}

.pill-btn-action:hover {
    transform: scale(1.05);
}

/* Upload Hero */
.upload-hero {
    background: var(--gradient-1);
    border-radius: var(--border-radius);
    padding: 60px 20px;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.hero-title {
    font-size: 2.5rem;
    margin: 0 0 10px 0;
    font-weight: 800;
}

.hero-sub {
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 30px;
}

.upload-zone {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 60px;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.2s;
}

.upload-zone:hover,
.upload-zone.highlight {
    background: rgba(255, 255, 255, 0.1);
    border-color: #fff;
}

.upload-zone i {
    font-size: 2rem;
}

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: center;
    background: var(--bg-card);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 12px;
    border-radius: 4px;
}

.filter-group input {
    background: transparent;
    border: none;
    color: #fff;
    font-family: inherit;
}

.filter-group input:focus {
    outline: none;
}

.filter-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Dashboard Grid Structure */
.dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 30px;
    width: 100%;
}

@media (max-width: 900px) {
    /* No change needed as it's already flex-col */
}

/* KPIs */
.kpi-row {
    grid-column: 1 / -1;
    display: grid;
    /* Keep KPIs in row as they are small Stats Cards, unless user insists on stacking these too.
     Usually "Columns" refers to layout blocks. */
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 0;
}

@media (max-width: 600px) {
    .kpi-row {
        grid-template-columns: 1fr;
    }
}

.kpi-card {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px;
    border-radius: var(--border-radius);
    color: #fff;
    transition: transform 0.2s;
}

.kpi-card:hover {
    transform: translateY(-5px);
}

.gradient-1 {
    background: linear-gradient(135deg, #1e3c72, #2a5298);
}

.gradient-2 {
    background: linear-gradient(135deg, #8E2DE2, #4A00E0);
}

.gradient-3 {
    background: linear-gradient(135deg, #11998e, #38ef7d);
}

.kpi-icon {
    font-size: 2rem;
    opacity: 0.8;
}

.kpi-data {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1.1;
}

.kpi-label {
    font-size: 0.85rem;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 5px;
}

/* Chart Containers - Dynamic Height */
.chart-box {
    position: relative;
    /* Remove aspect ratio to allow natural height based on content */
    height: 250px;
    /* Fixed reasonable height for square-ish charts */
    width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* On PC, reducing the height to remove 'blank space' */
.chart-box canvas {
    max-height: 100% !important;
    max-width: 100% !important;
}

.chart-box-lg {
    position: relative;
    height: 250px;
    /* Reduced from 300px */
    width: 100%;
}

.chart-card {
    background-color: #181818;
    border-radius: var(--border-radius);
    padding: 15px;
    /* Reduced padding */
    transition: background 0.2s;
}

.chart-card:hover {
    background: var(--bg-hover);
}

.chart-card.wide {
    grid-column: 1 / -1;
}

.chart-card h3 {
    margin: 0 0 15px 0;
    font-size: 1.1rem;
}

.chart-box {
    height: 250px;
    position: relative;
    width: 100%;
}

.chart-box-lg {
    height: 350px;
    position: relative;
    width: 100%;
}

/* Side Ranking */
.side-ranking .chart-card {
    height: 100%;
}

.ranking-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.ranking-list li {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.9rem;
}

.ranking-list li:last-child {
    border-bottom: none;
}

.track-rank {
    width: 25px;
    color: var(--text-secondary);
    font-weight: 600;
    text-align: center;
}

.track-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.track-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

/* --- MEGA STATS EXPANSION --- */

.section-title {
    font-size: 1.5rem;
    margin: 40px 0 20px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
    color: #fff;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* 1. Calendar Heatmap */
.heatmap-container {
    overflow-x: auto;
    padding-bottom: 10px;
}

.calendar-heatmap {
    display: flex;
    gap: 4px;
}

.heatmap-week {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.heatmap-day {
    width: 10px;
    height: 10px;
    background-color: #222;
    border-radius: 2px;
}

.heatmap-day:hover {
    border: 1px solid #fff;
    transform: scale(1.5);
}

/* Colors for Heatmap */
.lvl-0 {
    background-color: #161616;
}

.lvl-1 {
    background-color: #0e4429;
}

.lvl-2 {
    background-color: #006d32;
}

.lvl-3 {
    background-color: #26a641;
}

.lvl-4 {
    background-color: #39d353;
}

/* 2. Stat Card Grid Layouts */
.nerd-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.nerd-card {
    background: #181818;
    padding: 15px;
    border-radius: 6px;
    border: 1px solid #282828;
    position: relative;
    overflow: hidden;
}

.nerd-card:hover {
    border-color: #444;
}

.nerd-label {
    font-size: 0.75rem;
    color: #888;
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 5px;
}

.nerd-value {
    font-size: 1.5rem;
    color: #fff;
    font-weight: 700;
}

.nerd-unit {
    font-size: 0.8rem;
    color: #666;
    margin-left: 4px;
    font-weight: 400;
}

.nerd-sub {
    font-size: 0.7rem;
    color: #555;
    margin-top: 5px;
}

/* Visual Bars in Cards */
.mini-bar-bg {
    height: 4px;
    width: 100%;
    background: #333;
    margin-top: 8px;
    border-radius: 2px;
    position: relative;
}

.mini-bar-fill {
    height: 100%;
    background: var(--spotify-green);
    border-radius: 2px;
}

/* Sparkline Simulator (CSS-only bars) */
.sparkline {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 30px;
    margin-top: 10px;
    opacity: 0.8;
}

.spark-bar {
    flex: 1;
    background: #1DB954;
    border-radius: 1px 1px 0 0;
    min-width: 2px;
}

/* Hour Heatmap Table */
.hour-heatmap-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.7rem;
    color: #555;
    margin-top: 15px;
}

.hour-heatmap-table td {
    width: 15px;
    height: 15px;
    text-align: center;
    border: 1px solid #111;
}

.hour-heatmap-table th {
    text-align: left;
    padding-right: 5px;
    color: #888;
}

/* --- SOCIAL STORY CARDS (9:16) --- */
.social-gallery-container {
    grid-column: 1 / -1;
    overflow-x: auto;
    padding: 20px 0;
    margin-top: 40px;
}

.gallery-scroller {
    display: flex;
    gap: 20px;
    padding-bottom: 10px;
}

.story-card-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.story-card {
    width: 270px;
    height: 480px;
    /* 9:16 Aspect Ratio */
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
}

/* Themes */
.theme-bold {
    background: var(--spotify-green);
    color: #000;
}

.theme-dark {
    background: #121212;
    color: #fff;
    border: 1px solid #333;
}

.theme-dot {
    background-color: #f0f0f0;
    color: #000;
    /* Use SVG Data URI for reliable html2canvas export */
    background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23000000' fill-opacity='1' fill-rule='evenodd'%3E%3Ccircle cx='20' cy='20' r='4'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 40px 40px;
}

.theme-gradient {
    background: linear-gradient(45deg, #4b1085, #1d2570);
    color: #fff;
}

/* Content Layout inside Card */
.story-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: auto;
    /* Push content down */
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
    width: 100%;
    /* Ensure full width */
}

.story-main {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    margin: auto 0;
    z-index: 2;
    /* Above pattern */
}

.story-footer {
    margin-top: auto;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    gap: 5px;
    opacity: 0.7;
    z-index: 2;
}

/* Typography variants */
.story-big-stat {
    font-size: 4rem;
    font-weight: 800;
    line-height: 1;
}

.story-label {
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 10px;
}

.story-sub {
    font-size: 0.9rem;
    margin-top: 10px;
    font-weight: 500;
}

/* Specific Styling for Dot Theme to match screenshot */
.theme-dot .story-main {
    background: #f0f0f0;
    /* Match card background */
    padding: 20px;
    border-radius: 4px;
    /* Slight rounded rect */
    /* No border, no shadow */
    box-shadow: none;
    width: 90%;
}

.export-btn {
    background: #333;
    color: #fff;
    border: none;
    padding: 8px 24px;
    border-radius: 500px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
    transition: background 0.2s;
    margin-top: 5px;
}

.export-btn:hover {
    background: var(--spotify-green);
    color: #000;
}

/* Tooltip for nerd stats */
.nerd-card[title] {
    cursor: help;
}

.track-artist {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Charts Area */
.charts-grid {
    display: grid;
    /* Allow side-by-side for charts to save space (Density), but stack on mobile */
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

/* --- MOBILE RESPONSIVENESS (Phone Optimization) --- */
@media (max-width: 768px) {
    .app-container {
        padding: 10px;
        /* Minimal padding */
    }

    .hero-title {
        font-size: 1.4rem;
        margin-bottom: 5px;
    }

    .section-title {
        font-size: 1rem;
        margin: 20px 0 10px 0;
    }

    /* KPI Row: Dense Grid */
    .kpi-row {
        grid-template-columns: 1fr 1fr;
        /* Force 2 columns */
        gap: 8px;
    }

    /* KPI Card: Compact */
    .kpi-card {
        padding: 10px;
        gap: 5px;
        flex-direction: column;
        text-align: center;
        min-height: 0;
        /* Remove any defaults */
    }

    .kpi-icon {
        display: none;
    }

    /* Hide icon on mobile to save space? Or make small */
    /* Let's keep icon but small */
    /* .kpi-icon { font-size: 1rem; } */

    .kpi-value {
        font-size: 1.1rem;
    }

    .kpi-label {
        font-size: 0.6rem;
        letter-spacing: 0;
    }

    /* Filter Bar */
    .filter-bar {
        flex-direction: column;
        gap: 5px;
    }

    .filter-input,
    .date-input,
    .btn-spotify {
        width: 100%;
        padding: 8px;
        font-size: 0.8rem;
    }

    /* Chart Cards: Super Compact */
    .chart-card {
        padding: 10px;
        /* Reduced internal padding */
    }

    /* Headers */
    .chart-card h3 {
        font-size: 0.9rem;
        margin-bottom: 5px;
    }

    /* Charts Grid: 2 cols for density */
    .charts-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    /* Wide charts */
    .chart-card.wide {
        grid-column: 1 / -1;
    }

    /* Explicit Heights for Chart Canvases on Mobile */
    .chart-box {
        height: 140px;
        /* Very short */
        min-height: 0;
        padding: 0;
    }

    .chart-box-lg {
        height: 180px;
        padding: 0;
    }

    /* History List */
    .history-item {
        padding: 5px;
        font-size: 0.8rem;
    }

    .history-list-header {
        display: none;
    }
}

@media (max-width: 480px) {
    /* On VERY small screens, try to keep 2 cols for charts if possible, otherwise 1 */
    /* But user wants density. 1fr 1fr is risky but requested. */
}

.track-plays {
    margin-left: auto;
    color: var(--spotify-green);
    font-size: 0.85rem;
}

/* History List Panel */
.history-list-header {
    display: grid;
    grid-template-columns: 120px 1fr 1fr;
    padding: 10px;
    border-bottom: 1px solid #333;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-scroll-area {
    max-height: 400px;
    overflow-y: auto;
}

.history-item {
    display: grid;
    grid-template-columns: 120px 1fr 1fr;
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.9rem;
    align-items: center;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Override previous flex structure for specific grid alignment */
.history-time {
    width: auto;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.history-details {
    display: block;
}

/* Reset from flex */
.history-artist {
    color: var(--text-secondary);
}