:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --error-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Header & Navigation */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.navbar {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.nav-links {
    display: flex;
    gap: 1rem;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    transition: background 0.2s;
}

.nav-link:hover {
    background: var(--background);
}

.btn-link {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
}

.auth-status {
    padding: 0.5rem 1rem;
    color: var(--success-color);
    font-size: 0.875rem;
}

/* Flash Messages */
.flash-messages {
    max-width: 1400px;
    margin: 1rem auto;
    padding: 0 2rem;
}

.flash-message {
    padding: 1rem;
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
}

.flash-message.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.flash-message.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

/* Main Content */
main {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 2rem;
}

/* Setup Page */
.setup-container {
    max-width: 900px;
    margin: 0 auto;
    text-align: center;
}

.setup-container h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
}

.upload-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.upload-section {
    background: var(--surface);
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    text-align: left;
}

.upload-section h3 {
    margin-bottom: 0.5rem;
}

.sample-format {
    background: var(--background);
    padding: 1rem;
    border-radius: 0.375rem;
    margin: 1rem 0;
}

.sample-format pre {
    font-size: 0.875rem;
    overflow-x: auto;
}

.upload-section form {
    margin-top: 1rem;
}

.upload-section input[type="file"] {
    display: block;
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 1rem;
    border: 2px dashed var(--border);
    border-radius: 0.375rem;
    cursor: pointer;
}

.upload-section button {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.upload-section button:hover {
    background: #1d4ed8;
}

.status-message {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: 0.375rem;
    display: none;
}

.status-message.success {
    background: #d1fae5;
    color: #065f46;
    display: block;
}

.status-message.error {
    background: #fee2e2;
    color: #991b1b;
    display: block;
}

.import-summary {
    margin-top: 2rem;
    padding: 2rem;
    background: var(--surface);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
}

/* Catalog Page */
.catalog-container {
    width: 100%;
}

.toolbar {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    align-items: center;
}

.search-bar {
    flex: 1;
    min-width: 200px;
}

.search-bar input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 1rem;
}

.filter-tabs {
    display: flex;
    gap: 0.5rem;
}

.tab-btn {
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-secondary {
    padding: 0.5rem 1rem;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-primary {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 0.375rem;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #1d4ed8;
}

/* Progress Bar */
.progress-bar {
    background: var(--surface);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.progress-fill {
    height: 8px;
    background: var(--primary-color);
    border-radius: 4px;
    transition: width 0.3s;
    width: 0%;
}

.progress-text {
    display: block;
    margin-top: 0.5rem;
    text-align: center;
    color: var(--text-secondary);
}

/* Media Grid */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1.5rem;
}

.media-card {
    background: var(--surface);
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.media-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

.media-card img {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    background: var(--background);
}

.media-card .title-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    color: white;
    padding: 1rem 0.5rem 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.media-card .enrichment-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--success-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
}

.media-card .enrichment-badge.pending {
    background: var(--secondary-color);
}

.media-card .enrichment-badge.failed {
    background: var(--error-color);
}

.loading {
    text-align: center;
    padding: 4rem;
    color: var(--text-secondary);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    overflow: auto;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--surface);
    border-radius: 0.5rem;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    padding: 2rem;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: var(--text-primary);
}

.detail-view {
    padding: 1rem;
}

.detail-header {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
}

.detail-header img {
    width: 200px;
    height: auto;
    border-radius: 0.5rem;
    object-fit: cover;
}

.placeholder-cover {
    width: 200px;
    height: 300px;
    background: var(--background);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.detail-info {
    flex: 1;
}

.detail-info h2 {
    margin-bottom: 1rem;
}

.detail-info p {
    margin: 0.5rem 0;
}

.detail-description {
    background: var(--background);
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 2rem;
    line-height: 1.8;
}

.detail-notes h3 {
    margin-bottom: 0.5rem;
}

.detail-notes textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
}

.detail-notes button {
    margin-top: 0.5rem;
    padding: 0.5rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background 0.2s;
}

.detail-notes button:hover {
    background: #1d4ed8;
}

/* Login Page */
.login-container {
    max-width: 400px;
    margin: 4rem auto;
}

.login-box {
    background: var(--surface);
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
}

.login-box h2 {
    margin-bottom: 0.5rem;
}

.login-box p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 1rem;
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.login-box button {
    width: 100%;
}

.login-note {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.welcome-message {
    background: var(--surface);
    padding: 2rem;
    border-radius: 0.5rem;
    text-align: center;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.welcome-message h2 {
    margin-bottom: 0.5rem;
}

.welcome-message a {
    color: var(--primary-color);
    text-decoration: underline;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    margin-top: 4rem;
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
    }

    .toolbar {
        flex-direction: column;
    }

    .media-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 1rem;
    }

    .upload-sections {
        grid-template-columns: 1fr;
    }
}

/* Add/Edit Form Styles */
.toolbar-actions {
    display: flex;
    gap: 10px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.form-actions button {
    padding: 10px 20px;
}

/* Edit button on cards */
.edit-card-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    z-index: 10;
}

.media-card:hover .edit-card-btn {
    opacity: 1;
}

.edit-card-btn:hover {
    background: var(--primary-color);
}

#edit-modal .modal-content {
    max-width: 600px;
}

#edit-modal-body {
    padding: 20px;
}

#edit-modal-title {
    margin-top: 0;
    margin-bottom: 25px;
    color: var(--text-color);
}

/* Infinite scroll loading indicator */
.loading-more {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 14px;
}

.loading-more::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-left: 10px;
    border: 3px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Mobile Navigation - Hamburger Menu */
.hamburger {
    display: none;
    flex-direction: column;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    z-index: 1001;
}

.hamburger span {
    width: 25px;
    height: 3px;
    background: var(--text-primary);
    margin: 3px 0;
    transition: all 0.3s ease;
    border-radius: 3px;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    /* Show hamburger on mobile */
    .hamburger {
        display: flex;
    }

    /* Hide nav links by default on mobile */
    .nav-links {
        position: fixed;
        top: 60px;
        right: -100%;
        width: 250px;
        height: calc(100vh - 60px);
        background: var(--surface);
        flex-direction: column;
        align-items: flex-start;
        padding: 20px;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
        transition: right 0.3s ease;
        z-index: 1000;
        overflow-y: auto;
    }

    .nav-links.active {
        right: 0;
    }

    .nav-links .nav-link,
    .nav-links .auth-status,
    .nav-links button {
        width: 100%;
        text-align: left;
        padding: 12px 0;
        border-bottom: 1px solid var(--border);
    }

    /* Toolbar adjustments for mobile */
    .toolbar {
        flex-direction: column;
        gap: 15px;
        padding: 15px;
    }

    .toolbar-actions {
        width: 100%;
        flex-direction: column;
    }

    .toolbar-actions button {
        width: 100%;
    }

    .search-bar {
        width: 100%;
    }

    .search-bar input {
        width: 100%;
    }

    .filter-tabs {
        width: 100%;
        justify-content: space-between;
    }

    .tab-btn {
        flex: 1;
        font-size: 13px;
        padding: 8px 6px;
    }

    /* Media grid adjustments for mobile */
    .media-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 15px;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 10px;
        max-height: 90vh;
        overflow-y: auto;
    }

    #edit-modal .modal-content {
        max-width: 95%;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    /* Header adjustments */
    .navbar {
        padding: 0.75rem 1rem;
    }

    .nav-brand h1 {
        font-size: 1.2rem;
    }

    /* Hide edit button on cards in mobile unless actively tapped */
    .edit-card-btn {
        opacity: 1;
        background: rgba(0, 0, 0, 0.6);
    }
}

/* Tablet responsive (768px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .media-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }

    .toolbar {
        padding: 15px 20px;
    }
}

/* Small mobile (max 480px) */
@media (max-width: 480px) {
    .media-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .tab-btn {
        font-size: 11px;
        padding: 8px 4px;
    }

    .nav-brand h1 {
        font-size: 1rem;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions button {
        width: 100%;
    }
}
