:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --border: #2a2d3a;
    --text: #e1e4ed;
    --text-muted: #8b8fa3;
    --accent: #e5a00d;
    --accent-hover: #cc8e0b;
    --accent-light: rgba(229, 160, 13, 0.15);
    --plex: #e5a00d;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* --- Navbar --- */
.navbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.8rem 2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-left { display: flex; align-items: center; gap: 1rem; }

.nav-menu { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }

.nav-brand {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--plex);
    text-decoration: none;
    margin-right: 1rem;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.nav-link:hover { color: var(--text); background: var(--border); }
.nav-link.active { color: var(--accent); background: var(--accent-light); }
.nav-user { font-size: 0.9rem; color: var(--text-muted); }
.nav-user-section { display: flex; align-items: center; gap: 0.5rem; margin-left: 0.5rem; }
.nav-icon { height: 24px; width: 24px; border-radius: 4px; margin-right: 0.3rem; vertical-align: middle; }

/* Burger - hidden on desktop */
.burger {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}
.burger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: all 0.2s;
}

.avatar { width: 28px; height: 28px; border-radius: 50%; }
.avatar-small { width: 22px; height: 22px; border-radius: 50%; vertical-align: middle; }

/* --- Container --- */
.container { max-width: 1400px; margin: 0 auto; padding: 2rem; }

/* --- Login --- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 3rem;
    text-align: center;
    max-width: 400px;
    width: 100%;
}

.login-title { font-size: 2.5rem; font-weight: 800; color: var(--plex); margin-bottom: 0.5rem; }
.login-logo { max-width: 280px; width: 100%; margin-bottom: 0.5rem; border-radius: 8px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 2rem; }

.btn-plex {
    background: var(--plex);
    color: #000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.8rem 2rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    width: 100%;
}

.btn-plex:hover { opacity: 0.9; }

/* --- Headers --- */
.page-header { margin-bottom: 2rem; }
.page-header h1 { font-size: 1.8rem; font-weight: 700; margin-bottom: 1rem; }
.count { color: var(--text-muted); font-weight: 400; font-size: 1rem; }

.section { margin-bottom: 2.5rem; }
.section h2 { font-size: 1.1rem; font-weight: 600; color: var(--text-muted); margin-bottom: 1rem; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.section-header h2 { margin-bottom: 0; }

/* --- Filter tabs --- */
.filter-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-tab {
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.filter-tab:hover { color: var(--text); border-color: var(--accent); }
.filter-tab.active { color: #000; font-weight: 600; background: var(--accent); border-color: var(--accent); }

.tab-count {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-left: 0.2rem;
}

/* --- Genre tags --- */
.genre-tags {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.genre-tag {
    padding: 0.3rem 0.7rem;
    border-radius: 14px;
    font-size: 0.8rem;
    text-decoration: none;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    transition: all 0.2s;
    white-space: nowrap;
}

.genre-tag:hover { color: var(--text); border-color: var(--accent); }
.genre-tag.active { color: #000; font-weight: 600; background: var(--accent); border-color: var(--accent); }

/* --- Search --- */
.search-bar { margin-bottom: 1.5rem; }

.search-form { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.search-input {
    flex: 1;
    min-width: 250px;
    padding: 0.6rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.95rem;
}

.search-input:focus { outline: none; border-color: var(--accent); }

.search-wrapper { position: relative; flex: 3; min-width: 300px; }
.search-wrapper .search-input { width: 100%; }

.suggest-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    z-index: 50;
    max-height: 300px;
    overflow-y: auto;
}

.suggest-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
}

.suggest-item:hover { background: var(--accent-light); }
.suggest-item:last-child { border-bottom: none; }
.suggest-title { font-weight: 500; }

.search-select {
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
}

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

.media-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.15s, border-color 0.15s;
}

.media-card:hover { transform: translateY(-2px); border-color: var(--accent); }

img.media-poster {
    width: 100%;
    height: 250px;
    object-fit: cover;
    background-color: var(--border);
    display: block;
}

div.media-poster {
    width: 100%;
    height: 250px;
    background-color: var(--border);
}

.no-poster {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.media-info { padding: 0.8rem; }

.media-title {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.media-meta {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.media-servers {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.media-rating { margin-top: 0.3rem; }
.star { color: var(--border); cursor: pointer; font-size: 1rem; transition: color 0.1s; }
.star:hover, .star.rated { color: var(--plex); }

/* --- Stats grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem;
    text-align: center;
}

.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.error .stat-value { color: var(--error); }
.stat-card.info .stat-value { color: var(--info); }

/* --- Buttons --- */
.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
    text-decoration: none;
}

.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: #000; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ai { background: linear-gradient(135deg, #8b5cf6, #6366f1); color: white; font-weight: 600; white-space: nowrap; }
.btn-ai:hover { opacity: 0.9; }

/* --- AI Response --- */
.ai-response {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(99, 102, 241, 0.1));
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 8px;
    padding: 1rem 1.2rem;
    margin-bottom: 1.5rem;
}
.ai-response-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: #a78bfa;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}
.ai-response p { font-size: 0.95rem; margin-bottom: 0.5rem; }
.ai-criteria { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }

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

.ai-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
.btn-secondary { background: var(--border); color: var(--text); }
.btn-small { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-error { background: var(--error); color: white; }

/* --- Tables --- */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
}

th {
    background: var(--border);
    padding: 0.8rem 1rem;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

tr:last-child td { border-bottom: none; }

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-synced { background: #1e3a5f; color: var(--info); }
.badge-identified { background: #1a3a2a; color: var(--success); }
.badge-moved { background: #1a3a1a; color: var(--success); }
.badge-error { background: #3a1a1a; color: var(--error); }
.badge-pending { background: #3a3a1a; color: var(--warning); }
.badge-approved { background: #1a3a2a; color: var(--success); }
.badge-downloading { background: #1e3a5f; color: var(--info); }
.badge-completed { background: #1a3a1a; color: var(--success); }
.badge-rejected { background: #3a1a1a; color: var(--error); }
.badge-movie { background: #2d1f5e; color: #a78bfa; }
.badge-movie_4k { background: #5e1f4d; color: #f0abfc; }
.badge-series, .badge-show { background: #1f4a5e; color: #67e8f9; }
.badge-res { background: #1a3a2a; color: var(--success); }

/* --- TMDB search results --- */
.tmdb-results { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1rem; }

.tmdb-card {
    display: flex;
    gap: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.8rem;
    align-items: center;
}

.tmdb-poster { width: 50px; height: 75px; border-radius: 4px; object-fit: cover; flex-shrink: 0; }
.tmdb-info { flex: 1; }
.tmdb-info strong { margin-right: 0.5rem; }

/* --- Leaderboard --- */
.stats-leaderboard {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: border-color 0.2s;
}

.leaderboard-row.top-1 { border-color: var(--accent); }
.leaderboard-row.top-2 { border-color: rgba(229, 160, 13, 0.4); }
.leaderboard-row.top-3 { border-color: rgba(229, 160, 13, 0.2); }

.leaderboard-rank {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-muted);
    min-width: 2rem;
    text-align: center;
}

.top-1 .leaderboard-rank { color: var(--accent); font-size: 1.6rem; }
.top-2 .leaderboard-rank { color: #c0c0c0; }
.top-3 .leaderboard-rank { color: #cd7f32; }

.leaderboard-user {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    min-width: 200px;
}

.leaderboard-name { font-weight: 600; font-size: 1rem; }

.avatar-placeholder {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.leaderboard-plays {
    min-width: 100px;
    text-align: right;
    font-size: 0.9rem;
}

.leaderboard-plays strong { font-size: 1.2rem; margin-right: 0.3rem; }

.leaderboard-bar { flex: 1; min-width: 100px; }

@media (max-width: 768px) {
    .leaderboard-row { flex-wrap: wrap; gap: 0.5rem; padding: 0.8rem; }
    .leaderboard-user { min-width: auto; flex: 1; }
    .leaderboard-bar { width: 100%; min-width: auto; }
    .leaderboard-plays { min-width: auto; }
}

/* --- Bar chart --- */
.bar-container {
    width: 100%;
    height: 20px;
    background: var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--plex));
    border-radius: 10px;
    transition: width 0.3s;
}

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 0.8rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    cursor: pointer;
    z-index: 1;
    line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-content {
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem;
}

.modal-poster { flex-shrink: 0; }
.modal-poster img {
    width: 180px;
    border-radius: 8px;
    background: var(--border);
}

.modal-info { flex: 1; min-width: 0; }
.modal-info h2 { font-size: 1.4rem; margin-bottom: 0.5rem; }
.modal-meta { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; font-size: 0.9rem; color: var(--text-muted); }
.modal-summary { color: var(--text-muted); font-size: 0.9rem; line-height: 1.6; margin-bottom: 1.2rem; }

.modal-servers h3, .modal-rating h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 0.5rem; }
.modal-server-item { padding: 0.3rem 0; font-size: 0.9rem; }
.modal-servers { margin-bottom: 1rem; }

.modal-stars { display: flex; gap: 0.3rem; }
.star-lg { font-size: 1.5rem; }

@media (max-width: 768px) {
    .modal-content { flex-direction: column; padding: 1rem; gap: 1rem; }
    .modal-poster { text-align: center; }
    .modal-poster img { width: 140px; }
    .modal-info h2 { font-size: 1.2rem; }
}

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.page-link {
    display: inline-block;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.page-link:hover { color: var(--text); border-color: var(--accent); }
.page-link.active { color: #000; font-weight: 600; background: var(--accent); border-color: var(--accent); }
.page-ellipsis { color: var(--text-muted); padding: 0 0.3rem; }
.page-info { color: var(--text-muted); font-size: 0.85rem; margin-left: 1rem; }

/* --- Task Monitor --- */
.task-monitor { margin-bottom: 0.5rem; }

.task-current {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
}

.task-current.running { border-color: var(--accent); }

.task-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 1.5s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

.task-history { margin-top: 0.5rem; }
.task-history-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

/* --- Dropzone --- */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.dropzone-icon {
    font-size: 2.5rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.dropzone-content p { margin: 0.3rem 0; }
.dropzone-content a { color: var(--accent); text-decoration: underline; }

.upload-results {
    margin-top: 1rem;
    text-align: left;
    font-size: 0.9rem;
}

/* --- Misc --- */
.empty-state { text-align: center; padding: 4rem 2rem; color: var(--text-muted); }
.empty-state h2 { color: var(--text); margin-bottom: 0.5rem; }
.empty-state a { color: var(--accent); text-decoration: underline; }

.filename { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.8rem; color: var(--text-muted); word-break: break-all; }
.truncate { max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }

.select-small {
    padding: 0.2rem 0.4rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.8rem;
}

.config-info {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.config-info code { color: var(--accent); }

/* --- Responsive --- */
@media (max-width: 768px) {
    .container { padding: 1rem; }

    /* Burger visible */
    .burger { display: flex; }

    /* Menu hidden by default, full width dropdown */
    .nav-menu {
        display: none;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 0;
        margin-left: 0;
        padding-top: 0.8rem;
    }
    .nav-menu.open { display: flex; }
    .nav-menu .nav-link {
        padding: 0.7rem 0.6rem;
        border-radius: 0;
        border-top: 1px solid var(--border);
        font-size: 1rem;
    }
    .nav-user-section {
        padding: 0.7rem 0.6rem;
        border-top: 1px solid var(--border);
        margin-left: 0;
        gap: 0.5rem;
    }

    .navbar { padding: 0.6rem 1rem; }

    /* Page header */
    .page-header h1 { font-size: 1.3rem; }

    /* Filter tabs scroll horizontal */
    .filter-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 0.4rem; padding-bottom: 0.3rem; }
    .filter-tab { white-space: nowrap; font-size: 0.8rem; padding: 0.4rem 0.8rem; flex-shrink: 0; }

    /* Search */
    .search-form { flex-direction: column; }
    .search-input { min-width: 0; }

    /* Media grid: 3 columns on mobile */
    .media-grid { grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
    .media-poster { height: 160px; }
    .media-info { padding: 0.5rem; }
    .media-title { font-size: 0.75rem; }
    .media-meta { font-size: 0.65rem; gap: 0.2rem; }
    .media-servers { display: none; }
    .media-rating { font-size: 0.7rem; }
    .star { font-size: 0.8rem; }

    /* Stats grid */
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-value { font-size: 1.5rem; }

    /* Tables: horizontal scroll */
    table { font-size: 0.75rem; display: block; overflow-x: auto; white-space: nowrap; }
    td, th { padding: 0.4rem 0.6rem; }
    .truncate { max-width: 150px; }

    /* Pagination compact */
    .pagination { gap: 0.2rem; }
    .page-link { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
    .page-info { font-size: 0.75rem; margin-left: 0.5rem; }

    /* TMDB search results */
    .tmdb-card { flex-direction: column; align-items: flex-start; }
    .tmdb-poster { width: 40px; height: 60px; }

    /* Login */
    .login-card { padding: 2rem 1.5rem; margin: 1rem; }
    .login-title { font-size: 2rem; }
}

/* Small phones */
@media (max-width: 400px) {
    .media-grid { grid-template-columns: repeat(2, 1fr); }
    .media-poster { height: 180px; }
}
