/* Global Styles & Variables */
:root {
    --primary-color: #007aff;
    --primary-color-dark: #005ecb;
    --bg-color: #f5f5f7;
    --sidebar-bg: #e5e5e7;
    --text-color: #1d1d1f;
    --text-color-light: #86868b;
    --border-color: #d2d2d7;
    --hover-bg: #e8e8ea;
    --modal-bg: rgba(255, 255, 255, 0.98);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Main Layout */
.admin-container {
    display: none; /* Initially hidden */
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem 0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.main-content {
    flex: 1;
    padding: 0 2.5rem;
    display: flex;
    flex-direction: column;
}

/* Sidebar */
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.5rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header i {
    font-size: 1.75rem;
    color: var(--primary-color);
}

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.sidebar-nav {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-color);
    font-weight: 500;
    transition: background-color 0.2s ease;
}

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

.nav-item.active {
    background-color: var(--primary-color);
    color: white;
}

/* Disable nav item when not admin */
.nav-item.disabled {
    pointer-events: none;
    opacity: 0.6;
}

.nav-item i {
    width: 20px;
    text-align: center;
}

/* Main Header */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Header Auth Controls */
.auth-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.auth-status {
    color: var(--text-color-light);
}

.search-container {
    position: relative;
}

.search-container i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-color-light);
}

#searchInput {
    width: 320px;
    padding: 0.6rem 1rem 0.6rem 2.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: #ebebed;
    font-size: 1rem;
}

#searchInput:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: white;
}

.add-music-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.2s ease;
}

.add-music-btn:hover {
    background-color: var(--primary-color-dark);
}

/* Content Sections */
.content-section {
    display: none;
    padding-top: 2rem;
}

.content-section.active {
    display: block;
}

.content-section h2 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
}

/* Music Table */
.music-list-container {
    background-color: white;
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.music-table {
    width: 100%;
    border-collapse: collapse;
}

.music-table th, .music-table td {
    padding: 1rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.music-table th {
    font-weight: 600;
    color: var(--text-color-light);
    font-size: 0.875rem;
    text-transform: uppercase;
}

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

.music-table tbody tr:hover {
    background-color: var(--hover-bg);
}

.cover-col {
    width: 60px;
}

.actions-col {
    width: 100px;
    text-align: right;
}

.table-cover {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    object-fit: cover;
}

.title-cell {
    font-weight: 500;
}

.artist-cell, .genre-cell, .duration-cell {
    color: var(--text-color-light);
}

.actions-cell {
    display: flex;
    gap: 0.5rem;
}

.actions-cell .btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color-light);
    font-size: 1rem;
    padding: 0.5rem;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.actions-cell .btn:hover {
    color: var(--text-color);
    background-color: #dcdce1;
}

/* Upload Section */
.upload-area {
    background-color: white;
    border-radius: 12px;
    padding: 2.5rem;
    box-shadow: var(--shadow);
}

#uploadForm {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2.5rem;
}

.cover-upload-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.cover-uploader {
    width: 280px;
    height: 280px;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.cover-uploader.dragover {
    border-color: var(--primary-color);
}

.cover-uploader i {
    font-size: 3rem;
    color: var(--text-color-light);
    margin-bottom: 1rem;
}

.cover-uploader p {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.cover-uploader span {
    color: var(--text-color-light);
    font-size: 0.875rem;
}

.cover-preview {
    position: relative;
    width: 280px;
    height: 280px;
}

#coverPreviewImg {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

#removeCoverBtn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8rem;
}

.music-details-fields {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.file-input-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.file-label {
    font-weight: 500;
    color: var(--text-color);
}

.file-select-btn {
    background-color: #e5e5e7;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem 1rem;
    cursor: pointer;
}

.file-name {
    color: var(--text-color-light);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.field-group label {
    font-weight: 500;
}

.field-group input, .field-group select, .field-group textarea {
    resize: none;
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background-color: #f5f5f7;
}

.field-group input:focus, .field-group select:focus, .field-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: white;
}

.upload-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.8rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.2s ease;
    margin-top: auto; /* Pushes button to the bottom */
}

.upload-btn:hover {
    background-color: var(--primary-color-dark);
}

.upload-btn .fa-spinner {
    font-size: 1.2rem;
}

/* Modal Styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--modal-bg);
    backdrop-filter: blur(20px);
    margin: auto;
    padding: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    font-size: 1.5rem;
}

.close-btn {
    background: #e5e5e7;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color-light);
}

.modal-body {
    margin-bottom: 2rem;
}

#editForm {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

.btn-secondary {
    background-color: #e5e5e7;
    color: var(--text-color);
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
}

/* Auth Gate */
.auth-gate {
    position: fixed;
    inset: 0;
    display: flex; /* Changed from none */
    align-items: center;
    justify-content: center;
    background: #fff;
    z-index: 2000;
}

.auth-card {
    background: transparent;
    backdrop-filter: none;
    border: none;
    border-radius: 24px;
    padding: 3rem 2.5rem;
    box-shadow: none;
    text-align: center;
    max-width: 480px;
    width: 90%;
    animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.brand-section {
    margin-bottom: 2.5rem;
}

.brand-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}

.brand-icon i {
    font-size: 2.5rem;
    color: white;
}

.brand-title {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0 0 0.5rem 0;
    letter-spacing: -0.02em;
}

.brand-subtitle {
    font-size: 1.1rem;
    color: #6b7280;
    margin: 0;
    font-weight: 500;
}

.login-section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #374151;
    margin: 0 0 0.5rem 0;
}

.login-description {
    color: #6b7280;
    margin: 0 0 2rem 0;
    font-size: 1rem;
    line-height: 1.5;
}

.google-login-btn {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 9999px;
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.google-login-btn:hover {
    background: #f9fafb;
    border-color: #d1d5db;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

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

.google-login-btn i {
    font-size: 1.2rem;
    color: #ea4335;
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: 72px;
    }
    .sidebar-header h1, .nav-item span {
        display: none;
    }
    .sidebar-header {
        justify-content: center;
        padding: 0 0 1.5rem;
    }
    .sidebar-nav {
        padding: 1.5rem 0;
        align-items: center;
    }
    .nav-item {
        justify-content: center;
    }
    .main-content {
        padding: 0 1.5rem;
    }
    #uploadForm {
        grid-template-columns: 1fr;
    }
    .cover-upload-wrapper {
        margin-bottom: 2rem;
    }
}

@media (max-width: 768px) {
    .admin-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 0;
    }
    .sidebar-header {
        display: none;
    }
    .sidebar-nav {
        flex-direction: row;
        padding: 0;
        flex: 1;
        justify-content: space-around;
    }
    .nav-item {
        flex: 1;
        justify-content: center;
        border-radius: 0;
        padding: 1rem 0;
    }
    .nav-item span {
        display: inline;
        font-size: 0.8rem;
    }
    .nav-item i {
        margin-right: 0.5rem;
    }
    .main-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    #searchInput {
        width: 100%;
    }
}