/* Track Analytics Page Styles */

/* Make the analytics page use full browser width */
.container {
    max-width: 100%;
    width: 100%;
    padding-top: 10px;
}

.track-header {
    display: flex;
    /* Align buttons with the top of the track title */
    align-items: flex-start;
    gap: 20px;
    /* Reduce the gap between the header divider line and the next section */
    margin-bottom: 15px;
    /* Reduce vertical padding further to bring the header closer to the top */
    padding: 5px 0;
    border-bottom: 2px solid #eee;
}

.back-button {
    background: #667eea;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
}

.back-button:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
}

.track-info {
    flex: 1;
}

.track-info h1 {
    font-size: 2rem;
    font-weight: 700;
    color: #333;
    /* Tighten spacing between track name and the artist line */
    margin: 0 0 2px 0;
}

.track-info p {
    font-size: 1.1rem;
    color: #666;
    margin: 0;
}

.track-meta-header {
    font-size: 0.9rem;
    color: #555;
    margin-top: 4px;
}

.track-meta-header a {
    color: #667eea;
    text-decoration: none;
}

.track-meta-header a:hover {
    text-decoration: underline;
}

.track-button {
    background: white;
    color: #667eea;
    border: 1px solid #667eea;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.track-button:hover {
    background: #eef0ff;
}

.track-button.tracked {
    background: #ffc107;
    border-color: #ffc107;
    color: #000;
}

.track-button.tracked:hover {
    background: #ffb300;
    border-color: #ffb300;
}

.view-playlists-button {
    background: white;
    color: #667eea;
    border: 1px solid #667eea;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.view-playlists-button:hover {
    background: #eef0ff;
}

.download-button {
    background: white;
    color: #667eea;
    border: 1px solid #667eea;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.download-button:hover {
    background: #eef0ff;
}

.analytics-container {
    background: white;
    border-radius: 12px;
    border: 1px solid #ddd;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Chart Section */
.chart-section {
    padding: 20px;
    border-bottom: 1px solid #ddd;
}

.chart-section.hidden {
    display: none;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.chart-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: #333;
}

.chart-toggles {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.chart-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #555;
    user-select: none;
}

.chart-toggle input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.chart-toggle span {
    font-weight: 500;
}

.chart-scale-toggle {
    margin-left: auto;
    padding-left: 15px;
    border-left: 1px solid #ddd;
}

@media (max-width: 768px) {
    .chart-scale-toggle {
        margin-left: 0;
        padding-left: 0;
        border-left: none;
    }
}

.chart-container {
    position: relative;
    height: 400px;
    width: 100%;
}

@media (max-width: 768px) {
    .chart-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .chart-container {
        height: 300px;
    }
}

.analytics-table {
    overflow-x: auto;
}

.analytics-table.hidden {
    display: none;
}

.analytics-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.analytics-table th {
    background: #f8f9fa;
    color: #333;
    font-weight: 600;
    padding: 12px 10px;
    text-align: left;
    border-bottom: 2px solid #dee2e6;
    position: sticky;
    top: 0;
    z-index: 10;
    white-space: nowrap; /* keep header text on one line */
}

/* Section headers (TikTok and Spotify) */
.analytics-table th.section-header {
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
    padding: 8px 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.analytics-table th.tiktok-section {
    background: #ffe0e0;
    color: #000;
}

.analytics-table th.spotify-section {
    background: #d4f4dd;
    color: #000;
}

/* Apply colors to second row columns */
.analytics-table thead tr:nth-child(2) th:nth-child(1),
.analytics-table thead tr:nth-child(2) th:nth-child(2),
.analytics-table thead tr:nth-child(2) th:nth-child(3) {
    background: #ffe0e0;
}

.analytics-table thead tr:nth-child(2) th:nth-child(n+4) {
    background: #d4f4dd;
}

.analytics-table td {
    padding: 10px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}

.analytics-table tbody tr:hover {
    background: #f8f9fa;
}

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

/* Date column */
.analytics-table td:first-child {
    font-weight: 500;
    color: #333;
    min-width: 120px;
    white-space: nowrap; /* keep date on one line */
}

/* Number columns (totals, counts, saves, skips, listeners, sources) */
.analytics-table td:nth-child(2),  /* Creations */
.analytics-table td:nth-child(3),  /* Views */
.analytics-table td:nth-child(4),  /* TikTok Shares */
.analytics-table td:nth-child(5),  /* Streams */
.analytics-table td:nth-child(6),  /* Sub 30 */
.analytics-table td:nth-child(7),  /* Saves */
.analytics-table td:nth-child(9),  /* Skips */
.analytics-table td:nth-child(11), /* Shares (Spotify) */
.analytics-table td:nth-child(12), /* Listeners */
.analytics-table td:nth-child(13), /* Track Pop */
.analytics-table td:nth-child(14), /* Artist Pop */
.analytics-table td:nth-child(15), /* Algo */
.analytics-table td:nth-child(16), /* Organic */
.analytics-table td:nth-child(17), /* Editorial */
.analytics-table td:nth-child(21), /* First Play */
.analytics-table td:nth-child(22), /* Collection */
.analytics-table td:nth-child(23), /* Search */
.analytics-table td:nth-child(24), /* Playlists */
.analytics-table td:nth-child(25), /* Play Queue */
.analytics-table td:nth-child(26), /* Radio */
.analytics-table td:nth-child(27), /* Album */
.analytics-table td:nth-child(28), /* Other */
.analytics-table td:nth-child(29), /* Artist */
.analytics-table td:nth-child(30)  /* Chart */ {
    text-align: right;
    font-family: 'Courier New', monospace;
    font-weight: 500;
}

/* Percentage columns */
.analytics-table td:nth-child(8),  /* Save % */
.analytics-table td:nth-child(10), /* Skips % */
.analytics-table td:nth-child(18), /* Algo % */
.analytics-table td:nth-child(19), /* Organic % */
.analytics-table td:nth-child(20)  /* Editorial % */ {
    text-align: right;
    font-family: 'Courier New', monospace;
    font-weight: 500;
    color: #666;
}

/* Total rows styling */
.analytics-table tbody tr.total-row {
    background: #f8f9fa;
    font-weight: 600;
    border-top: 2px solid #dee2e6;
}

.analytics-table tbody tr.total-row td {
    border-bottom: 1px solid #dee2e6;
    padding: 10px;
}

.analytics-table tbody tr.total-row td:first-child {
    color: #333;
    font-weight: 700;
}

/* Summary row styling */
.analytics-table tbody tr.summary-row {
    background: #e9ecef;
    font-weight: 700;
    border-top: 2px solid #adb5bd;
}

.analytics-table tbody tr.summary-row td {
    border-bottom: none;
    padding: 12px;
    color: #495057;
}

.analytics-table tbody tr.summary-row td:first-child {
    color: #495057;
}

/* Loading and Error States */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.loading-spinner.hidden {
    display: none;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

.loading-spinner p {
    color: #666;
    font-size: 1.1rem;
    margin: 0;
}

.error-message {
    text-align: center;
    padding: 80px 20px;
    color: #d32f2f;
}

.error-message.hidden {
    display: none;
}

.error-message p {
    font-size: 1.2rem;
    margin-bottom: 10px;
    font-weight: 600;
}

.error-message small {
    font-size: 0.95rem;
    color: #999;
    display: block;
    margin-top: 10px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .track-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .track-info h1 {
        font-size: 1.5rem;
    }

    .track-info p {
        font-size: 1rem;
    }

    .analytics-table {
        font-size: 0.85rem;
    }

    .analytics-table th,
    .analytics-table td {
        padding: 10px 8px;
    }

    .analytics-table th:first-child,
    .analytics-table td:first-child {
        min-width: 80px;
    }
}

@media (max-width: 480px) {
    .track-header {
        padding: 15px 0;
    }

    .track-info h1 {
        font-size: 1.3rem;
    }

    .analytics-table {
        font-size: 0.8rem;
    }

    .analytics-table th,
    .analytics-table td {
        padding: 8px 6px;
    }

    .back-button {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
}

/* ── Note / Mile Marker styles ── */

/* Row with a note — subtle yellow highlight */
.analytics-table tbody tr.has-note {
    background: #fffde7;
}

.analytics-table tbody tr.has-note:hover {
    background: #fff9c4;
}

/* Pencil icon in date cell */
.note-icon {
    font-size: 18px;
    vertical-align: middle;
    cursor: pointer;
    color: #bbb;
    margin-right: 6px;
    transition: color 0.15s;
}

.note-icon:hover {
    color: #667eea;
}

tr.has-note .note-icon {
    color: #f9a825;
}

/* Playlist link in analytics table */
.analytics-table a.playlist-link {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted #aaa;
}

.analytics-table a.playlist-link:hover {
    color: #667eea;
    border-bottom-color: #667eea;
}

/* Note modal overlay */
.note-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.note-modal-overlay.hidden {
    display: none;
}

/* Modal box */
.note-modal {
    background: #fff;
    border-radius: 12px;
    padding: 24px 28px;
    width: 440px;
    max-width: 92vw;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}

.note-modal h3 {
    margin: 0 0 16px;
    font-size: 1.1rem;
    color: #333;
}

.note-modal textarea {
    width: 100%;
    min-height: 90px;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box;
}

.note-modal textarea:focus {
    outline: none;
    border-color: #667eea;
}

/* Options row (global toggle) */
.note-modal-options {
    margin: 14px 0;
    display: flex;
    align-items: center;
}

/* Toggle switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    color: #555;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    width: 38px;
    height: 20px;
    background: #ccc;
    border-radius: 10px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: #667eea;
}

.toggle-switch input:checked + .toggle-slider::after {
    transform: translateX(18px);
}

/* Author info line */
.note-modal-author {
    font-size: 0.8rem;
    color: #999;
    margin-bottom: 10px;
}

/* Action buttons */
.note-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 8px;
}

.note-btn-cancel,
.note-btn-delete,
.note-btn-save {
    border: none;
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.note-btn-cancel {
    background: #eee;
    color: #555;
}
.note-btn-cancel:hover {
    background: #ddd;
}

.note-btn-delete {
    background: #ffebee;
    color: #c62828;
}
.note-btn-delete:hover {
    background: #ffcdd2;
}

.note-btn-save {
    background: #667eea;
    color: #fff;
}
.note-btn-save:hover {
    background: #5a6fd8;
}
