/* ============ CSS Variables ============ */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;
    --bg-hover: #22222f;
    --bg-active: #2a2a3a;
    
    --text-primary: #e8e8ef;
    --text-secondary: #9898a8;
    --text-muted: #5a5a6a;
    
    --accent: #7c5cff;
    --accent-hover: #9478ff;
    --accent-glow: rgba(124, 92, 255, 0.3);
    
    --success: #4ade80;
    --error: #f87171;
    
    --font-display: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --transition: 0.2s ease;
}

/* ============ Reset & Base ============ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-display);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

.screen {
    height: 100vh;
    width: 100vw;
}

.hidden {
    display: none !important;
}

/* ============ Login Screen ============ */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.ambient-bg {
    position: absolute;
    inset: 0;
    background: 
        radial-gradient(ellipse 80% 50% at 20% 40%, rgba(124, 92, 255, 0.15), transparent),
        radial-gradient(ellipse 60% 40% at 80% 60%, rgba(124, 92, 255, 0.1), transparent);
    animation: ambientPulse 8s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes ambientPulse {
    0% { opacity: 0.6; transform: scale(1); }
    100% { opacity: 1; transform: scale(1.05); }
}

.login-container {
    width: 100%;
    max-width: 380px;
    padding: 40px;
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    border: 1px solid var(--bg-tertiary);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
}

.logo-icon {
    font-size: 32px;
    color: var(--accent);
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.logo-text {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.tagline {
    color: var(--text-secondary);
    font-size: 14px;
}

.input-group {
    margin-bottom: 16px;
}

.input-group input {
    width: 100%;
    padding: 14px 18px;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 15px;
    transition: var(--transition);
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.error-msg {
    color: var(--error);
    font-size: 13px;
    text-align: center;
    margin-top: 16px;
    min-height: 20px;
}

/* ============ App Screen ============ */
#app-screen {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: 1fr;
    height: calc(100vh - 90px);
    overflow: hidden;
}

/* ============ Sidebar ============ */
.sidebar {
    grid-row: 1 / 2;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--bg-tertiary);
    height: calc(100vh - 90px);
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--bg-tertiary);
}

.sidebar-header .logo-icon {
    font-size: 24px;
}

.sidebar-header .logo-text {
    font-size: 20px;
    font-weight: 600;
}

.nav-section {
    flex: 1;
    overflow-y: auto;
    padding: 16px 0;
    min-height: 0; /* Enables flex child scrolling */
}

.nav-section h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 0;
    margin-bottom: 0;
}

.library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    margin-bottom: 12px;
}

.sort-controls {
    display: flex;
    gap: 4px;
}

.btn-sort {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-sort:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sort.active {
    background: var(--bg-active);
    color: var(--accent);
}

.playlist-nav {
    list-style: none;
    max-height: calc(100vh - 280px);
    overflow-y: auto;
}

.playlist-nav li {
    padding: 10px 24px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
}

.playlist-nav li:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.playlist-nav li.active {
    background: var(--bg-active);
    color: var(--text-primary);
    border-left: 3px solid var(--accent);
}

.playlist-nav li::before {
    content: "📁";
    font-size: 16px;
}

.playlist-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.playlist-count {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 10px;
    font-family: var(--font-mono);
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--bg-tertiary);
}

.user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#current-user {
    font-size: 14px;
    color: var(--text-secondary);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.btn-icon:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

#logout-btn {
    font-size: 18px;
    padding: 8px 12px;
    color: var(--error);
    background: rgba(248, 113, 113, 0.1);
    border-radius: var(--radius-md);
}

#logout-btn:hover {
    background: rgba(248, 113, 113, 0.2);
    color: #ff6b6b;
}

.admin-panel {
    margin-top: 12px;
}

.btn-small {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-small:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ============ Main Content ============ */
.main-content {
    grid-row: 1 / 2;
    overflow-y: auto;
    padding: 24px 32px;
    padding-bottom: 140px;
    background: linear-gradient(180deg, var(--bg-tertiary) 0%, var(--bg-primary) 300px);
}

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

.content-header h1 {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.track-sort-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-tertiary);
    padding: 4px 8px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    white-space: nowrap;
}

.sort-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-right: 4px;
}

.track-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ============ Search ============ */
.search-container {
    margin-bottom: 20px;
}

#search-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 14px;
    transition: var(--transition);
}

#search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#search-input::placeholder {
    color: var(--text-muted);
}

.search-options {
    margin-top: 8px;
    display: flex;
    gap: 16px;
}

.search-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}

.search-toggle input[type="checkbox"] {
    accent-color: var(--accent);
}

.search-result-header {
    font-size: 12px;
    color: var(--text-muted);
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
}

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 60px 20px;
    font-size: 15px;
}

.track-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.track-item:hover {
    background: var(--bg-hover);
}

.track-item.playing {
    background: var(--bg-active);
}

.track-item.playing .track-number {
    color: var(--accent);
}

.track-number {
    width: 24px;
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.track-item:hover .track-number,
.track-item.playing .track-number {
    display: none;
}

.track-play-icon {
    display: none;
    width: 24px;
    text-align: center;
    color: var(--accent);
}

.track-item:hover .track-play-icon,
.track-item.playing .track-play-icon {
    display: block;
}

.track-name {
    flex: 1;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.track-item.playing .track-name {
    color: var(--accent);
}

/* ============ Player Bar ============ */
.player-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: 260px 1fr 200px;
    align-items: center;
    padding: 0 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--bg-tertiary);
    height: 90px;
    min-height: 90px;
    z-index: 100;
}

.now-playing {
    display: flex;
    align-items: center;
    gap: 14px;
}

.album-art {
    width: 56px;
    height: 56px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--accent);
}

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

.track-title {
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}

.track-artist {
    font-size: 12px;
    color: var(--text-muted);
}

.player-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.control-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-control {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-control:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.btn-control.active {
    color: var(--accent);
}

.btn-play {
    background: var(--text-primary);
    color: var(--bg-primary) !important;
    width: 42px;
    height: 42px;
}

.btn-play:hover {
    background: white;
    transform: scale(1.05);
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 600px;
}

.time {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    min-width: 40px;
}

.time:last-child {
    text-align: right;
}

.progress-bar,
.volume-bar {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-tertiary);
    cursor: pointer;
    flex: 1;
}

.progress-bar::-webkit-slider-thumb,
.volume-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    opacity: 0;
    transition: var(--transition);
}

.progress-bar:hover::-webkit-slider-thumb,
.volume-bar:hover::-webkit-slider-thumb {
    opacity: 1;
}

.progress-bar::-moz-range-thumb,
.volume-bar::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
}

.player-extras {
    display: flex;
    justify-content: flex-end;
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.volume-bar {
    width: 100px;
}

/* ============ Modal ============ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-secondary);
    padding: 32px;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 380px;
    border: 1px solid var(--bg-tertiary);
}

.modal-content h2 {
    margin-bottom: 24px;
    font-size: 20px;
}

.modal-wide {
    max-width: 600px;
}

.logs-filter {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.btn-filter {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-filter:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-filter.active {
    background: var(--accent);
    color: white;
}

.logs-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.log-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    background: var(--bg-tertiary);
}

.log-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.log-content {
    flex: 1;
    min-width: 0;
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.log-user {
    font-weight: 500;
    font-size: 13px;
}

.log-time {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.log-details {
    font-size: 12px;
    color: var(--text-secondary);
    word-break: break-all;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.btn-secondary {
    flex: 1;
    padding: 12px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-actions .btn-primary {
    flex: 1;
}

.hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.6;
}

.hint code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
}

textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    resize: vertical;
    min-height: 120px;
}

textarea:focus {
    outline: none;
    border-color: var(--accent);
}

textarea::placeholder {
    color: var(--text-muted);
}

.cookies-status {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 13px;
}

.cookies-status.has-cookies {
    border-left: 3px solid var(--success);
}

.cookies-status.no-cookies {
    border-left: 3px solid var(--text-muted);
}

.input-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

select:focus {
    outline: none;
    border-color: var(--accent);
}

select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ============ Toast ============ */
.toast {
    position: fixed;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: var(--radius-md);
    padding: 12px 20px;
    z-index: 200;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.toast-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: var(--text-primary);
    font-size: 14px;
    min-width: 250px;
}

.toast-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast-progress {
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.toast-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.toast-stats {
    font-size: 12px;
    color: var(--text-muted);
}

.toast-spinner {
    animation: spin 1s linear infinite;
}

.toast.success {
    border-color: var(--success);
}

.toast.success .toast-spinner {
    animation: none;
}

.toast.error {
    border-color: var(--error);
}

.toast.error .toast-spinner {
    animation: none;
}

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

/* ============ Admin & Download Buttons ============ */
.admin-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.download-section {
    margin-top: 8px;
}

.download-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.download-section .btn-small {
    width: 100%;
}

.btn-accent {
    background: var(--accent) !important;
    color: white !important;
}

.btn-accent:hover {
    background: var(--accent-hover) !important;
}

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

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-active);
}

/* ============ Mobile Menu Button ============ */
.btn-menu {
    display: none;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.btn-menu:hover {
    background: var(--bg-hover);
}

/* ============ Responsive ============ */
@media (max-width: 900px) {
    #app-screen {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 40;
    }
    
    .sidebar-overlay.open {
        display: block;
    }
    
    .btn-menu {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .content-header {
        gap: 12px;
    }
    
    .content-header h1 {
        font-size: 20px;
        flex: 1;
    }
    
    .track-sort-controls .sort-label {
        display: none;
    }
    
    .header-actions {
        gap: 8px;
    }
    
    .main-content {
        padding: 16px;
        padding-bottom: 180px;
        overflow-y: auto;
    }
    
    .player-bar {
        grid-template-columns: 1fr;
        display: flex;
        flex-direction: column;
        gap: 8px;
        padding: 12px;
        height: auto;
    }
    
    .now-playing {
        order: -1;
    }
    
    .player-controls {
        width: 100%;
    }
    
    .progress-container {
        max-width: 100%;
    }
    
    .control-buttons {
        justify-content: center;
    }
    
    .player-extras {
        display: none;
    }
    
    .search-container {
        margin-bottom: 16px;
    }
    
    #search-input {
        padding: 10px 14px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

