/* ============================================================
   RickyFlix — Design System
   Dark theme, cinematic, warm & cozy Netflix-inspired feel.
   ============================================================ */

:root {
    --bg: #09090b;
    --bg-raised: #0f0f13;
    --surface: #16161d;
    --surface-hover: #1e1e28;
    --surface-active: #2a2030;
    --border: #2a2030;
    --border-subtle: #1e1e2e;
    --text: #ececf1;
    --text-secondary: #8e8ea0;
    --text-muted: #4e4e6a;
    --accent: #e50914;
    --accent-hover: #b20710;
    --accent-soft: rgba(229, 9, 20, 0.12);
    --green: #34d399;
    --green-soft: rgba(52, 211, 153, 0.08);
    --amber: #fbbf24;
    --amber-soft: rgba(251, 191, 36, 0.08);
    --red: #f87171;
    --red-soft: rgba(248, 113, 113, 0.08);
    --purple: #a78bfa;
    --purple-soft: rgba(167, 139, 250, 0.08);
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
    --transition: 0.15s ease;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   LAYOUT: Sidebar + Main
   ============================================================ */

.app-layout {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--bg-raised);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.sidebar-logo-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--accent), #b20710);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: white;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 4px 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 450;
    color: var(--text-secondary);
    transition: all var(--transition);
    cursor: pointer;
}

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

.nav-item.active {
    color: var(--text);
    background: var(--accent-soft);
}

.nav-item.active .nav-icon {
    color: var(--accent);
}

.nav-icon {
    width: 18px;
    height: 18px;
    opacity: 0.7;
}

.nav-item.active .nav-icon { opacity: 1; }

.nav-badge {
    margin-left: auto;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid var(--border-subtle);
}

/* Main content */
.main-content {
    flex: 1;
    margin-left: 240px;
    min-height: 100vh;
}

/* ============================================================
   TOP BAR
   ============================================================ */

.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(9, 9, 11, 0.8);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 32px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.top-bar-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 4px;
}

/* Search bar */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0 14px;
    height: 38px;
    width: 320px;
    transition: border-color var(--transition);
}

.search-bar:focus-within {
    border-color: var(--accent);
}

.search-bar input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
}

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

.search-bar svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ============================================================
   PAGE CONTENT
   ============================================================ */

.page-content {
    padding: 28px 32px 48px;
    max-width: 1400px;
}

.page-header {
    margin-bottom: 28px;
}

.page-header h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.page-header .subtitle {
    color: var(--text-secondary);
    font-size: 15px;
}

/* ============================================================
   STATS CARDS (Library overview)
   ============================================================ */

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 18px 20px;
}

.stat-card .label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.stat-card .value.accent { color: var(--accent); }
.stat-card .value.green { color: var(--green); }

/* ============================================================
   MEDIA GRID (Library / Posters)
   ============================================================ */

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

.media-card {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    transition: all 0.2s ease;
    cursor: pointer;
}

.media-card:hover {
    transform: translateY(-4px);
    border-color: var(--border);
    box-shadow: var(--shadow);
}

.media-card-poster {
    aspect-ratio: 2/3;
    background: var(--bg-raised);
    overflow: hidden;
    position: relative;
}

.media-card-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.media-card:hover .media-card-poster img {
    transform: scale(1.05);
}

.media-card-poster .no-poster {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 8px;
}

.media-card-poster .no-poster svg {
    width: 36px;
    height: 36px;
    opacity: 0.4;
}

.media-card-poster .no-poster span {
    font-size: 12px;
    opacity: 0.5;
}

.media-card-info {
    padding: 12px;
}

.media-card-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.media-card-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.media-card-rating {
    display: flex;
    align-items: center;
    gap: 3px;
    color: var(--amber);
    font-size: 11px;
    font-weight: 600;
}

.media-card-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    color: white;
}

/* Overlay on hover */
.media-card-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    align-items: flex-end;
    padding: 16px;
}

.media-card:hover .media-card-overlay {
    opacity: 1;
}

.media-card-overlay .actions {
    display: flex;
    gap: 8px;
    width: 100%;
}

/* ============================================================
   FILE LIST (Browser view)
   ============================================================ */

.file-list {
    list-style: none;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    border: 1px solid transparent;
}

.file-item:hover {
    background: var(--surface);
    border-color: var(--border-subtle);
}

.file-item a.file-link {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.file-icon-box {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-icon-box.folder { background: var(--accent-soft); color: var(--accent); }
.file-icon-box.video { background: var(--green-soft); color: var(--green); }
.file-icon-box.audio { background: var(--purple-soft); color: var(--purple); }
.file-icon-box.book { background: var(--amber-soft); color: var(--amber); }
.file-icon-box.other { background: var(--surface); color: var(--text-muted); }

.file-icon-box svg {
    width: 20px;
    height: 20px;
}

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

.file-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
    margin-top: 2px;
}

.file-actions {
    flex-shrink: 0;
    display: flex;
    gap: 6px;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-xs);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn svg { width: 15px; height: 15px; }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--surface); }

.btn-download { background: var(--green-soft); color: var(--green); }
.btn-download:hover { background: rgba(52, 211, 153, 0.16); }

.btn-stream { background: var(--purple-soft); color: var(--purple); }
.btn-stream:hover { background: rgba(167, 139, 250, 0.16); }

.btn-sub { background: var(--amber-soft); color: var(--amber); }
.btn-sub:hover { background: rgba(251, 191, 36, 0.16); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-xs);
}

/* ============================================================
   BREADCRUMBS
   ============================================================ */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    font-size: 13px;
    margin-bottom: 20px;
}

.breadcrumb a {
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: var(--radius-xs);
    transition: all var(--transition);
}

.breadcrumb a:hover {
    color: var(--text);
    background: var(--surface);
}

.breadcrumb .sep { color: var(--text-muted); font-size: 11px; }
.breadcrumb .current { color: var(--text); font-weight: 500; padding: 4px 8px; }

/* ============================================================
   DOWNLOAD PROGRESS ITEMS
   ============================================================ */

.download-item {
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.download-poster {
    width: 48px;
    height: 72px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg);
}

.download-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.download-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
}

.download-status {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
}

.progress-bar {
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
}

.progress-fill.downloading { background: var(--accent); }
.progress-fill.completed { background: var(--green); }
.progress-fill.failed { background: var(--red); }

/* Status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 10px;
}

.status-badge.queued { background: var(--surface); color: var(--text-muted); }
.status-badge.downloading { background: var(--accent-soft); color: var(--accent); }
.status-badge.completed { background: var(--green-soft); color: var(--green); }
.status-badge.failed { background: var(--red-soft); color: var(--red); }

/* ============================================================
   FORMS / SETTINGS
   ============================================================ */

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

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

.form-group .hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font-mono);
    transition: border-color var(--transition);
}

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

.form-card {
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.form-card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.form-card-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */

.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(ellipse at top, #13132a 0%, var(--bg) 60%);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 6px;
}

.login-card .subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 32px;
    line-height: 1.6;
}

/* ============================================================
   ALERTS & TOASTS
   ============================================================ */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-xs);
    font-size: 13px;
    margin-bottom: 16px;
}

.alert-error {
    background: var(--red-soft);
    border: 1px solid rgba(248, 113, 113, 0.15);
    color: var(--red);
}

.alert-success {
    background: var(--green-soft);
    border: 1px solid rgba(52, 211, 153, 0.15);
    color: var(--green);
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
    text-align: center;
    padding: 80px 24px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 56px;
    height: 56px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state .title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.empty-state .desc {
    font-size: 14px;
    max-width: 400px;
    margin: 0 auto;
}

/* ============================================================
   MODAL (for subtitle search, TMDB picker)
   ============================================================ */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 500;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.active {
    display: flex;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    width: 90%;
    max-width: 560px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 28px;
    box-shadow: 0 8px 48px rgba(0,0,0,0.5);
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.modal-close:hover {
    color: var(--text);
    background: var(--surface-hover);
}

/* Subtitle search results */
.sub-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    cursor: pointer;
}

.sub-result:hover {
    background: var(--surface-hover);
}

.sub-result-info {
    flex: 1;
}

.sub-result-name {
    font-size: 13px;
    font-weight: 500;
}

.sub-result-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 10px;
    margin-top: 2px;
}

/* Section dividers */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .mobile-menu-btn {
        display: block;
    }
    .page-content {
        padding: 20px 16px 40px;
    }
    .top-bar {
        padding: 0 16px;
    }
    .search-bar {
        width: 100%;
        max-width: 200px;
    }
    .media-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }
    .file-actions .btn span.btn-text { display: none; }
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .stats-row {
        grid-template-columns: 1fr;
    }
    .media-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}

/* ============================================================
   LOADING / SPINNER
   ============================================================ */

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.skeleton {
    background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Utility: hidden text for btn on mobile */
@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
}
