/* ══════════════════════════════════════════════════════════
   YouTube Clipper — Dark Mode Design System
   ══════════════════════════════════════════════════════════ */

:root {
    /* Colors */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a2e;
    --bg-card: #16161f;
    --bg-card-hover: #1e1e2d;
    --bg-input: #1a1a28;
    --bg-overlay: rgba(0, 0, 0, 0.6);

    --border: #2a2a3e;
    --border-subtle: #1f1f30;
    --border-focus: #FF2D87;

    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b5;
    --text-muted: #666680;

    --accent: #FF2D87;
    --accent-hover: #FF4D9A;
    --accent-glow: rgba(255, 45, 135, 0.3);
    --accent-subtle: rgba(255, 45, 135, 0.1);

    --success: #4ECDC4;
    --warning: #FFA07A;
    --error: #FF6B6B;
    --info: #45B7D1;

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #FF6B6B, #FF2D87);
    --gradient-card: linear-gradient(145deg, #16161f, #1a1a2e);
    --gradient-glow: radial-gradient(ellipse at 50% 0%, rgba(255, 45, 135, 0.15), transparent 70%);

    /* Typography */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Spacing */
    --sidebar-width: 240px;
    --header-height: 60px;

    /* Transitions */
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

/* ─── Reset ────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

/* ─── App Layout ───────────────────────────────────────── */
#app {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ──────────────────────────────────────────── */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-slow);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.sidebar-toggle {
    display: none;
}

.sidebar-nav {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    transition: all var(--transition);
    position: relative;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-subtle);
    color: var(--accent);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent);
    border-radius: 0 4px 4px 0;
}

.badge {
    margin-left: auto;
    background: var(--accent);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* ─── Main Content ─────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 32px;
    width: 100%;
}

.mobile-header {
    display: none;
}

/* ─── Pages ────────────────────────────────────────────── */
.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Add Video Section ────────────────────────────────── */
.add-video-section {
    position: relative;
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 32px;
    overflow: hidden;
}

.section-glow {
    position: absolute;
    top: -50%;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 200%;
    background: var(--gradient-glow);
    pointer-events: none;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 20px;
    position: relative;
    color: var(--text-primary);
}

.add-video-form {
    position: relative;
}

.input-group {
    display: flex;
    gap: 12px;
}

.input-group input {
    flex: 1;
    padding: 14px 20px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font);
    transition: all var(--transition);
    outline: none;
}

.input-group input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

/* ─── Buttons ──────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 30px var(--accent-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--text-muted);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #ff5555;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.8rem;
}

.btn-icon {
    padding: 8px;
    width: 36px;
    height: 36px;
}

.btn-loader {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ─── Stats Grid ───────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all var(--transition);
}

.stat-card:hover {
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    flex-shrink: 0;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ─── Video Grid ───────────────────────────────────────── */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

.video-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition);
    cursor: pointer;
}

.video-card:hover {
    border-color: var(--border);
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.video-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.video-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-slow);
}

.video-card:hover .video-thumb img {
    transform: scale(1.05);
}

.video-thumb-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7) 0%, transparent 50%);
    display: flex;
    align-items: flex-end;
    padding: 12px;
}

.video-duration {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

.video-info {
    padding: 16px;
}

.video-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.video-status {
    font-size: 0.8rem;
    font-weight: 600;
}

.status-pending {
    color: var(--warning);
}

.status-downloading {
    color: var(--info);
}

.status-downloaded {
    color: var(--success);
}

.status-rendering {
    color: var(--info);
}

.status-done {
    color: var(--success);
}

.status-error {
    color: var(--error);
}

.video-clip-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    opacity: 0.3;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 0.95rem;
}

/* ─── Page Header ──────────────────────────────────────── */
.page-header {
    margin-bottom: 24px;
}

/* ─── Video Detail ─────────────────────────────────────── */
.video-detail-header {
    display: flex;
    gap: 24px;
    margin-bottom: 32px;
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
}

.video-detail-thumb {
    width: 280px;
    aspect-ratio: 16/9;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
}

.video-detail-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-detail-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.video-detail-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.video-detail-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.video-detail-meta span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.video-detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ─── Clips Section ────────────────────────────────────── */
.clips-section {
    margin-top: 24px;
}

.clips-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.clips-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.clip-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all var(--transition);
}

.clip-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border);
}

.clip-number {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-subtle);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.clip-info {
    flex: 1;
    min-width: 0;
}

.clip-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.clip-time {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.clip-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.clip-status-pending {
    background: rgba(255, 160, 122, 0.15);
    color: var(--warning);
}

.clip-status-rendering {
    background: rgba(69, 183, 209, 0.15);
    color: var(--info);
}

.clip-status-done {
    background: rgba(78, 205, 196, 0.15);
    color: var(--success);
}

.clip-status-error {
    background: rgba(255, 107, 107, 0.15);
    color: var(--error);
}

.clip-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* ─── Jobs List ────────────────────────────────────────── */
.jobs-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.job-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    display: grid;
    grid-template-columns: 100px 1fr 100px 80px 140px;
    align-items: center;
    gap: 16px;
    font-size: 0.85rem;
}

.job-type {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.75rem;
}

.job-type-download {
    color: var(--info);
}

.job-type-find_clips {
    color: var(--accent);
}

.job-type-render {
    color: var(--success);
}

.job-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    text-align: center;
}

.job-status-pending {
    background: rgba(255, 160, 122, 0.15);
    color: var(--warning);
}

.job-status-running {
    background: rgba(69, 183, 209, 0.15);
    color: var(--info);
}

.job-status-done {
    background: rgba(78, 205, 196, 0.15);
    color: var(--success);
}

.job-status-error {
    background: rgba(255, 107, 107, 0.15);
    color: var(--error);
}

.job-time {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: right;
}

/* ─── Toast ────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    min-width: 300px;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
}

.toast-success {
    border-left: 3px solid var(--success);
}

.toast-error {
    border-left: 3px solid var(--error);
}

.toast-info {
    border-left: 3px solid var(--info);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

/* ─── Modal ────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    font-size: 1.5rem;
    width: 36px;
    height: 36px;
}

.modal-body {
    padding: 24px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.9rem;
    transition: all var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* ─── Subtitle Viewer ──────────────────────────────────── */
.subtitle-viewer {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-top: 24px;
    max-height: 400px;
    overflow-y: auto;
}

.subtitle-viewer::-webkit-scrollbar {
    width: 6px;
}

.subtitle-viewer::-webkit-scrollbar-track {
    background: transparent;
}

.subtitle-viewer::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.subtitle-line {
    display: flex;
    gap: 12px;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    transition: background var(--transition);
    cursor: pointer;
}

.subtitle-line:hover {
    background: var(--bg-tertiary);
}

.subtitle-time {
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    min-width: 80px;
    flex-shrink: 0;
    padding-top: 2px;
}

.subtitle-text {
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ─── Progress Bar ─────────────────────────────────────── */
.progress-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 2px;
    transition: width 0.5s ease;
}

/* ─── Pulse animation for active status ────────────────── */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.status-downloading,
.status-rendering {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ─── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: calc(var(--header-height) + 16px);
    }

    .mobile-header {
        display: flex;
        align-items: center;
        gap: 12px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--header-height);
        padding: 0 16px;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-subtle);
        z-index: 90;
    }

    .menu-btn {
        background: none;
        border: none;
        color: var(--text-primary);
        cursor: pointer;
        padding: 4px;
    }

    .mobile-title {
        font-weight: 800;
        background: var(--gradient-primary);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

    .input-group {
        flex-direction: column;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .video-grid {
        grid-template-columns: 1fr;
    }

    .video-detail-header {
        flex-direction: column;
    }

    .video-detail-thumb {
        width: 100%;
    }

    .clip-card {
        flex-wrap: wrap;
    }

    .clip-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .job-card {
        grid-template-columns: 1fr 1fr;
    }

    .add-video-section {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-value {
        font-size: 1.2rem;
    }
}