@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

:root {
    --bg-dark: #0f111a;
    --bg-panel: rgba(25, 28, 41, 0.6);
    --text-main: #f8f9fa;
    --text-muted: #9ca3af;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --danger: #ef4444;
    --glass-border: rgba(255, 255, 255, 0.08);
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(239, 68, 68, 0.05) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: 'Poppins', sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* Typography */
h1, h2, h3, h4 {
    font-weight: 600;
    margin-top: 0;
}

/* Glassmorphism Utilities */
.glass {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 2rem;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #fff, #a5b4fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.nav-link:hover, .nav-link.active {
    color: var(--text-main);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 999px; /* Pill shape */
    font-weight: 500;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-danger {
    background: var(--danger);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
    background: #f87171;
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

/* Forms */
.form-control {
    width: 100%;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    box-sizing: border-box;
    transition: all 0.3s ease;
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}
.form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

/* ── Stats Bar ─────────────────────────────────────────────────────────── */
.stats-bar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.5rem 1rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    margin-bottom: 0.75rem;
}
.stat-item { display: flex; flex-direction: row; gap: 0.5rem; align-items: baseline; }
.stat-value { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.5px; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-divider { width: 1px; height: 16px; background: var(--glass-border); }

/* ── Upload Panel ─────────────────────────────────────────────────────── */
.upload-panel { overflow: hidden; border-radius: 8px; margin-bottom: 0.75rem; }
.upload-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.5rem 1rem; cursor: pointer; user-select: none;
    transition: background 0.2s; font-size: 0.9rem;
}
.upload-header:hover { background: rgba(255,255,255,0.04); }
.upload-toggle { color: var(--text-muted); font-size: 0.7rem; }
.upload-body { padding: 0 1rem 1rem; }
.upload-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.file-input { color: var(--text-muted); font-size: 0.8rem; font-family: inherit; flex: 1; min-width: 0; }
.folder-select {
    background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border);
    border-radius: 4px; color: var(--text-main); font-family: inherit; padding: 0.3rem 0.5rem;
    cursor: pointer; font-size: 0.8rem;
}
.upload-progress-track {
    height: 4px; background: rgba(255,255,255,0.08);
    border-radius: 2px; margin-top: 0.5rem; overflow: hidden;
}
.upload-progress-fill {
    height: 100%; background: var(--accent);
    border-radius: 2px; transition: width 0.3s ease;
}
.upload-message { margin: 0.5rem 0 0; font-size: 0.8rem; }

.upload-tabs { display: flex; gap: 0.25rem; margin-bottom: 0.75rem; }
.upload-tab {
    background: transparent; border: 1px solid var(--glass-border); border-radius: 4px;
    color: var(--text-muted); font-family: inherit; font-size: 0.8rem;
    padding: 0.3rem 0.7rem; cursor: pointer; transition: background 0.2s, color 0.2s;
}
.upload-tab:hover { background: rgba(255,255,255,0.04); }
.upload-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

input[type="text"].file-input {
    background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border);
    border-radius: 4px; padding: 0.3rem 0.5rem;
}

.upload-progress-indeterminate {
    width: 40% !important;
    animation: upload-indeterminate 1.2s ease-in-out infinite;
}
@keyframes upload-indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
}

/* ── Section labels ───────────────────────────────────────────────────── */
.section-label {
    font-size: 0.65rem; font-weight: 600; letter-spacing: 0.12em;
    color: var(--text-muted); text-transform: uppercase; margin: 1rem 0 0.5rem;
}

/* ── Folder list ──────────────────────────────────────────────────────── */
.folder-list { display: flex; flex-direction: column; gap: 2px; }
.folder-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.4rem 0.75rem; cursor: pointer; border-radius: 6px;
    transition: all 0.2s ease; background: rgba(255,255,255,0.02);
}
.folder-item:hover { background: rgba(255,255,255,0.06); }
.folder-icon { font-size: 1.1rem; }
.folder-info { flex: 1; display: flex; flex-direction: row; align-items: center; gap: 0.5rem; }
.folder-name { font-weight: 600; font-size: 0.9rem; }
.folder-meta { font-size: 0.75rem; color: var(--text-muted); }

/* ── Toolbar ──────────────────────────────────────────────────────────── */
.library-toolbar { margin-top: 0.75rem !important; margin-bottom: 0.75rem; }
.search-box { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 0.5rem; font-size: 0.8rem; pointer-events: none; }
.search-input {
    background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border);
    border-radius: 4px; padding: 0.3rem 2rem 0.3rem 1.75rem;
    color: var(--text-main); font-family: inherit; font-size: 0.8rem;
    width: 200px; outline: none; transition: all 0.3s ease;
}
.search-input:focus {
    border-color: var(--accent); background: rgba(99,102,241,0.08);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.15); width: 250px;
}
.search-input::placeholder { color: var(--text-muted); }
.search-clear {
    position: absolute; right: 0.25rem; background: none; border: none;
    color: var(--text-muted); cursor: pointer; font-size: 0.7rem;
    padding: 0.1rem 0.3rem; border-radius: 50%; box-shadow: none;
}
.search-clear:hover { color: var(--text-main); background: rgba(255,255,255,0.1); transform: none; }

/* ── Video List ───────────────────────────────────────────────────────── */
.video-list { display: flex; flex-direction: column; gap: 2px; margin-top: 0.25rem; }

.list-row {
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 0;
    transition: all 0.1s ease;
    padding: 0;
    background: rgba(255,255,255,0.02);
}
.list-row:hover { background: rgba(255,255,255,0.05); }

.list-link {
    display: flex; align-items: center; gap: 0.75rem;
    flex: 1; padding: 0.4rem 0.75rem;
    text-decoration: none; color: inherit;
    min-width: 0;
}

.serial-num {
    font-size: 0.7rem; font-weight: 600; color: var(--text-muted);
    min-width: 20px; text-align: right; flex-shrink: 0;
}

.list-info { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 0.2rem; }
.list-title {
    font-size: 0.9rem; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin: 0; max-width: 100%;
}
.list-meta-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; flex-shrink: 0; row-gap: 0.25rem; }

.meta-pill { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; }
.meta-pill.watched { color: var(--accent); }
.meta-pill.processing { color: #f59e0b; }

/* Progress bar at the bottom of each row */
.row-progress-bar {
    position: absolute;
    bottom: 0; left: 0;
    height: 2px;
    background: linear-gradient(to right, var(--accent), #c084fc);
    border-radius: 0 2px 2px 0;
    transition: width 0.5s ease;
}

/* Row actions */
.row-actions {
    display: flex; align-items: center; gap: 0.25rem;
    padding: 0 0.75rem 0 0; flex-shrink: 0;
}
.move-select {
    background: rgba(255,255,255,0.04); border: 1px solid var(--glass-border);
    border-radius: 4px; color: var(--text-muted); font-size: 0.7rem;
    font-family: inherit; padding: 0.2rem 0.4rem; cursor: pointer; max-width: 100px;
}
.move-select:hover { border-color: var(--accent); color: var(--text-main); }

.delete-btn {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 0.8rem; padding: 0.2rem 0.4rem; border-radius: 4px;
    box-shadow: none; opacity: 0.5; transition: all 0.2s;
}
.delete-btn:hover { opacity: 1; color: var(--danger); background: rgba(239,68,68,0.1); transform: none; }

/* Compact link-style buttons - plain text until hovered, then a subtle border appears */
.link-btn {
    background: none; border: 1px solid transparent; color: var(--text-main);
    cursor: pointer; font-size: 0.75rem; font-family: inherit; font-weight: 500;
    padding: 0.3rem 0.6rem; border-radius: 6px; white-space: nowrap;
    box-shadow: none; transition: border-color 0.15s ease, background 0.15s ease;
    text-decoration: none; display: inline-flex; align-items: center; gap: 0.25rem;
}
.link-btn:hover { border-color: var(--glass-border); background: rgba(255,255,255,0.04); }
.link-btn:disabled { opacity: 0.5; cursor: default; }
.link-btn:disabled:hover { border-color: transparent; background: none; }
.link-btn-accent { color: var(--accent); }
.link-btn-accent:hover { border-color: var(--accent); background: rgba(99,102,241,0.08); }

/* Compact track-selection config bar under a row awaiting Process */
.config-bar {
    width: 100%; margin-top: 0.5rem; padding: 0.5rem 0.75rem;
    display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;
    background: rgba(255,255,255,0.02); border-radius: 8px;
}
.mini-select {
    background: rgba(255,255,255,0.04); border: 1px solid var(--glass-border);
    border-radius: 6px; color: var(--text-muted); font-size: 0.75rem;
    font-family: inherit; padding: 0.3rem 0.5rem; cursor: pointer;
}
.mini-select:hover { border-color: var(--accent); color: var(--text-main); }

/* Popover for picking individual audio/subtitle tracks */
/* .glass uses backdrop-filter, which creates its own stacking context per row - a
   popover's z-index only wins within that context, not against a later sibling row.
   Bumping the whole open row above its siblings fixes that. */
.list-row.popover-active { position: relative; z-index: 50; }

.track-popover-wrap { position: relative; display: inline-block; }
/* Must stay below .list-row.popover-active's z-index (50) - that row (and the popover
   inside it) needs to paint above this overlay, not the other way round. */
.track-popover-overlay { position: fixed; inset: 0; z-index: 40; background: transparent; }
.track-popover {
    position: absolute; top: calc(100% + 4px); left: 0; z-index: 1001;
    min-width: 220px; max-width: 320px;
    background: #1a1d2b; border: 1px solid var(--glass-border); border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.4); padding: 0.5rem;
}
.track-popover label {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.8rem; padding: 0.35rem 0.4rem; border-radius: 6px; cursor: pointer;
}
.track-popover label:hover { background: rgba(255,255,255,0.05); }
.track-popover input[type="checkbox"] { flex-shrink: 0; }

.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
    margin-top: 1.5rem;
}

/* Library Header */
.library-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

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

/* Search */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 1rem;
    font-size: 0.9rem;
    pointer-events: none;
}

.search-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    padding: 0.65rem 2.5rem 0.65rem 2.5rem;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    width: 260px;
    transition: all 0.3s ease;
    outline: none;
}

.search-input:focus {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.08);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
    width: 320px;
}

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

.search-clear {
    position: absolute;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.2rem 0.4rem;
    border-radius: 50%;
    box-shadow: none;
    transition: color 0.2s;
}

.search-clear:hover {
    color: var(--text-main);
    background: rgba(255,255,255,0.1);
    transform: none;
}

/* View toggle */
.view-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    padding: 4px;
    gap: 4px;
}

.view-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    box-shadow: none;
    transition: all 0.2s ease;
    line-height: 1;
}

.view-btn:hover {
    color: var(--text-main);
    background: rgba(255,255,255,0.08);
    transform: none;
}

.view-btn.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* List view */
.video-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.video-list-item {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 1.5rem;
    text-decoration: none;
    color: inherit;
    transition: all 0.25s ease;
}

.video-list-item:hover {
    transform: translateX(4px);
    border-color: rgba(255,255,255,0.15);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.list-thumb {
    width: 140px;
    min-width: 140px;
    aspect-ratio: 16/9;
    background: linear-gradient(135deg, #2a2d3e, #1a1c29);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.list-play-icon {
    font-size: 1.25rem;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.video-list-item:hover .list-play-icon {
    opacity: 1;
}

.list-info {
    flex: 1;
    min-width: 0;
}

.list-info h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-meta {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.meta-badge {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.list-action {
    color: var(--text-muted);
    font-size: 1.8rem;
    font-weight: 300;
    line-height: 1;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.video-list-item:hover .list-action {
    opacity: 1;
    color: var(--accent);
}

.video-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
}

.video-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    border-color: rgba(255, 255, 255, 0.2);
}

.video-thumbnail {
    aspect-ratio: 16/9;
    background: linear-gradient(135deg, #2a2d3e, #1a1c29);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.play-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.5rem;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.video-card:hover .play-icon {
    opacity: 1;
    transform: scale(1.1);
    background: var(--accent);
}

.video-info {
    padding: 1.5rem;
}

.video-info h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.25rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-info p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Player */
.player-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    animation: fadeIn 0.5s ease-out;
}

video {
    width: 100%;
    border-radius: 16px;
    background: #000;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    aspect-ratio: 16/9;
}

.player-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--glass-border);
}

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