/* SoundCloud Tree View Styles */

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f5f5f5;
    color: #333;
    height: 100vh;
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 120px; /* Space for preview pane */
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.header-section {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

h1 {
    margin: 0;
    color: #ff6600;
}

.user-auth {
    display: flex;
    align-items: center;
    gap: 10px;
}

.auth-status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 20px;
    border: 1px solid #dee2e6;
}

.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    font-weight: 500;
    color: #333;
}

.auth-button {
    padding: 8px 16px;
    background-color: #ff6600;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
    text-decoration: none;
    display: inline-block;
}

.auth-button:hover {
    background-color: #e55500;
}

.auth-button.logout {
    background-color: #6c757d;
}

.auth-button.logout:hover {
    background-color: #5a6268;
}

.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

input[type="text"] {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px;
}

button {
    padding: 10px 20px;
    background-color: #ff6600;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

button svg {
    width: 16px;
    height: 16px;
}

button:hover {
    background-color: #e55500;
}

button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.tree-container {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.background-mode-toggle {
    padding: 8px 0;
    margin-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.background-mode-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    transition: color 0.2s;
}

.background-mode-label:hover {
    color: #333;
}

.background-mode-label input[type="checkbox"] {
    cursor: pointer;
}

.tree-node {
    margin: 2px 0;
}

.tree-node-content {
    display: flex;
    align-items: center;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.tree-node-content[onclick] {
    cursor: pointer;
}

.tree-node-content:hover {
    background-color: #f0f0f0;
}

.tree-node-expand {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 4px;
    font-size: 16px;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    user-select: none;
}

.tree-node-expand.expanded::before {
    content: '−';
}

.tree-node-expand.collapsed::before {
    content: '+';
}

.tree-node-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    font-size: 16px;
    transition: transform 0.2s;
}

.icon-track::before {
    content: '';
}

.icon-user::before {
    content: '';
}

.icon-list::before {
    content: '';
}

.icon-load-more::before {
    content: '';
}

/* Lucide icon styling */
.tree-node-icon svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

.node-link {
    align-items: center;
    text-decoration: none;
    color: inherit;
}

.node-link:hover .tree-node-icon {
    transform: scale(1.05);
}

.node-link:hover .tree-node-label {
    text-decoration: underline;
}

.tree-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    font-size: 14px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s, transform 0.2s;
}

.tree-icon:hover {
    opacity: 1;
    transform: scale(1.05);
}

.tree-icon::before {
    content: '';
}

.tree-icon svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
}

.purchase-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    font-size: 14px;
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s, transform 0.2s;
}

.purchase-icon:hover {
    opacity: 1;
    transform: scale(1.05);
}

.play-button {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    cursor: pointer;
    color: #ff6600;
    font-size: 14px;
    transition: transform 0.2s;
}

.play-button:hover {
    transform: scale(1.05);
}

.play-button::before {
    content: '';
}

.play-button svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: currentColor;
}

.tree-node-label {
    flex: 1;
    font-size: 14px;
    cursor: default;
}

.tree-node-children {
    margin-left: 28px;
}

.loading {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #ff6600;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

/* Tree node snail loading */
.tree-node-content .snail-loading {
    margin-right: 8px;
}

.snail-loading {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.snail-loading i {
    animation: snail-rock 1.5s ease-in-out infinite;
}

@keyframes snail-rock {
    0%, 100% { 
        transform: rotate(-10deg) scale(1);
        opacity: 0.7;
    }
    25% {
        transform: rotate(8deg) scale(1.1);
        opacity: 0.9;
    }
    50% { 
        transform: rotate(-6deg) scale(1.2);
        opacity: 1;
    }
    75% {
        transform: rotate(4deg) scale(1.1);
        opacity: 0.9;
    }
}

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

.error {
    color: #d32f2f;
    padding: 10px;
    background-color: #ffebee;
    border-radius: 4px;
    margin-bottom: 20px;
}

.info {
    color: #1976d2;
    padding: 10px;
    background-color: #e3f2fd;
    border-radius: 4px;
    margin-bottom: 20px;
    transition: opacity 0.3s ease;
}

/* Glitch-dissolve animation for messages */
@keyframes glitch-dissolve {
    0% {
        opacity: 1;
        transform: translateX(0);
    }
    20% {
        opacity: 0.9;
        transform: translateX(2px);
    }
    40% {
        opacity: 0.7;
        transform: translateX(-1px);
        filter: hue-rotate(90deg);
    }
    60% {
        opacity: 0.5;
        transform: translateX(1px);
        filter: hue-rotate(180deg);
    }
    80% {
        opacity: 0.3;
        transform: translateX(-1px);
        filter: hue-rotate(270deg);
    }
    90% {
        opacity: 0.1;
        transform: translateX(0.5px);
        filter: hue-rotate(360deg);
    }
    100% {
        opacity: 0;
        transform: translateX(0);
        filter: none;
    }
}

.message-dissolving {
    animation: glitch-dissolve 1.5s ease-in-out forwards;
}

.load-more {
    color: #ff6600;
    font-style: italic;
}

.tree-container-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.tree-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.tree-actions {
    display: flex;
    gap: 10px;
}

.delete-tree-btn {
    background-color: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.delete-tree-btn:hover {
    background-color: #c82333;
}

.update-tree-btn {
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.update-tree-btn:hover {
    background-color: #0056b3;
}

.saved-trees {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.saved-trees-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.saved-trees-header h3 {
    margin: 0;
}

.get-download-links-btn {
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.get-download-links-btn:hover {
    background-color: #218838;
}

.get-download-links-btn svg {
    width: 14px;
    height: 14px;
}

.tree-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.tree-item {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.tree-item-content {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.tree-type-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Tree type specific styling */
.tree-type-track {
    border-left: 4px solid #ff6600;
}

.tree-type-track .tree-type-icon {
    color: #ff6600;
}

.tree-type-user {
    border-left: 4px solid #40e0d0;
}

.tree-type-user .tree-type-icon {
    color: #40e0d0;
}

/* Active state overrides */
.tree-item.active.tree-type-track {
    background: #ff6600;
    border-color: #ff6600;
}

.tree-item.active.tree-type-user {
    background: #40e0d0;
    border-color: #40e0d0;
}

.tree-item.active .tree-type-icon {
    color: white;
}

.tree-item:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.tree-item.active {
    background: #ff6600;
    color: white;
    border-color: #ff6600;
}

.tree-item-name {
    flex: 1;
}

.tree-item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tree-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 14px;
    transition: transform 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.tree-action-btn svg {
    width: 14px;
    height: 14px;
}

.tree-item .delete-btn {
    color: #dc3545;
}

.tree-item .copy-link-btn {
    color: #007bff;
}

.tree-item.active .delete-btn,
.tree-item.active .copy-link-btn {
    color: white;
}

.copy-canonical-btn, a.copy-canonical-btn {
    background-color: #17a2b8;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.copy-canonical-btn:hover, a.copy-canonical-btn:hover {
    background-color: #138496;
    color: white;
}

/* Preview pane */
.preview-pane {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    background: #2c2c2c;
    border-top: 2px solid #ff6600;
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 1000;
}

.preview-pane.expanded {
    height: 300px;
}

.preview-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 20px;
}

.preview-info {
    color: white;
}

.preview-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.preview-artist {
    font-size: 14px;
    color: #ccc;
}

.preview-controls {
    display: flex;
    gap: 10px;
}

.preview-toggle {
    position: absolute;
    top: 10px;
    right: 20px;
    background: #ff6600;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

#soundcloudWidget {
    width: 100%;
    height: 166px;
    display: none;
}

.preview-pane.expanded #soundcloudWidget {
    display: block;
    margin-top: 60px;
}

/* Type-specific styling */
.node-type-track .tree-node-label {
    color: #333;
    font-weight: 500;
}

.node-type-user .tree-node-label {
    color: #666;
}

.node-type-user_likes .tree-node-label,
.node-type-user_tracks .tree-node-label {
    color: #888;
    font-style: italic;
}

.node-type-track_likes .tree-node-label {
    color: #888;
    font-style: italic;
}

/* Hide expand arrow for non-expandable nodes */
.tree-node-expand:not(.expanded):not(.collapsed) {
    visibility: hidden;
}

/* Adjust spacing when no play button */
.tree-node:not(.node-type-track) .tree-node-label {
    margin-left: 0;
}

/* Expanded view styling */
.tree-node.expanded-view {
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    margin: 6px 0;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px; /* Ensure minimum height for album art */
    transition: all 0.2s ease;
}

.tree-node.expanded-view:hover {
    background: #f5f5f5;
    border-color: #ccc;
}

.tree-node.expanded-view .tree-node-content {
    flex: 1;
    background: none;
    padding: 0;
    align-items: center;
    min-height: 20px;
}

.album-art-container {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 3px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.album-art {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Compact view (default) remains unchanged */
.tree-node.compact-view {
    /* Existing styles apply */
}

/* Expanded view specific adjustments */
.tree-node.expanded-view .tree-node-icon {
    margin-right: 10px;
}

.tree-node.expanded-view .tree-node-label {
    font-size: 15px;
    line-height: 1.4;
}

/* Make child nodes in expanded view slightly indented */
.tree-node.expanded-view .tree-node-children {
    margin-left: 32px;
}

/* Settings Panel - Fixed position modal */
.settings-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 300px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-in-out;
    z-index: 2000;
}

.settings-modal.open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    visibility: visible;
}

/* Dark backdrop overlay - separate element for better control */
.settings-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out;
}

.settings-backdrop.open {
    opacity: 1;
    visibility: visible;
}

.settings-content {
    background: white;
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
}

.settings-header h3 {
    margin: 0;
    color: #333;
    font-size: 14px;
    font-weight: 600;
}

.settings-close {
    background: none;
    border: none;
    font-size: 16px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.settings-close:hover {
    background-color: #f5f5f5;
    color: #333;
}

.settings-body {
    padding: 12px 16px;
}

.setting-group {
    margin-bottom: 12px;
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    color: #333;
    font-size: 12px;
}

.setting-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
}

/* Custom select dropdown styling */
.custom-select-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

.custom-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 100%;
    padding: 10px 36px 10px 14px;
    border: 2px solid #e1e4e8;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    color: #333;
}

.custom-select:hover {
    border-color: #ff6600;
    box-shadow: 0 2px 4px rgba(255, 102, 0, 0.1);
}

.custom-select:focus {
    outline: none;
    border-color: #ff6600;
    box-shadow: 0 0 0 3px rgba(255, 102, 0, 0.1);
}

.select-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    pointer-events: none;
    color: #666;
    transition: transform 0.2s ease;
}

.custom-select:focus + .select-arrow {
    color: #ff6600;
}

/* Add icons to dropdown options */
.custom-select option {
    padding: 8px;
}

/* Style the dropdown when open (browser-specific) */
.custom-select::-ms-expand {
    display: none;
}

.setting-group input[type="checkbox"] {
    margin-right: 8px;
}

.setting-group label input[type="checkbox"] {
    display: inline;
    margin-bottom: 0;
}

.settings-footer {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding: 10px 16px;
    border-top: 1px solid #eee;
    background: #f8f9fa;
}

.settings-save {
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.settings-save:hover {
    background-color: #218838;
}

.settings-cancel {
    background-color: #6c757d;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.settings-cancel:hover {
    background-color: #5a6268;
}

/* Make user name clickable */
.user-name-container {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: color 0.2s;
}

.user-name {
    font-weight: 500;
    color: #333;
    transition: color 0.2s;
}

.settings-icon {
    width: 14px;
    height: 14px;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
}

.user-name-container:hover .user-name {
    color: #ff6600;
}

.user-name-container:hover .settings-icon {
    opacity: 1;
    transform: scale(1.05);
}

/* Theme toggle switch */
.theme-switch-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.theme-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.theme-switch-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .theme-switch-slider {
    background-color: #ff6600;
}

input:focus + .theme-switch-slider {
    box-shadow: 0 0 1px #ff6600;
}

input:checked + .theme-switch-slider:before {
    transform: translateX(26px);
}

.theme-icon {
    width: 20px;
    height: 20px;
    color: #666;
}

.theme-icon.sun-icon {
    color: #ffb347;
}

.theme-icon.moon-icon {
    color: #9370db;
}

/* Icon Legend */
.icon-legend {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.legend-header:hover {
    color: #ff6600;
}

.legend-header h3 {
    margin: 0;
    font-size: 16px;
}

.legend-toggle {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
}

.legend-toggle.expanded {
    transform: rotate(180deg);
}

.legend-content {
    margin-top: 15px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 14px;
    background: #f8f9fa;
}

.legend-item i {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.purchase-icon-legend {
    font-size: 14px;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.legend-item span {
    color: #666;
}

/* Legend button */
.legend-btn {
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.legend-btn:hover {
    background-color: #218838;
}

/* Fun buttons styling */
.fun-buttons-container {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.fun-button {
    width: 32px;
    height: 32px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0;
    padding: 0;
}

.fun-button i {
    width: 16px;
    height: 16px;
    color: #666;
    transition: color 0.2s ease;
}

.fun-button:hover {
    border-color: #ff6600;
    transform: scale(1.05);
}

.fun-button:hover i {
    color: #ff6600;
}

.fun-button.active {
    background: #ff6600;
    border-color: #ff6600;
}

.fun-button.active i {
    color: white;
}