:root {
    --bg: #0f1117;
    --bg-secondary: #171a23;
    --bg-card: #1c202b;
    --bg-hover: #242936;
    --border: #2a3040;
    --text: #e6e9f0;
    --text-muted: #8b93a7;
    --primary: #4f7cff;
    --primary-hover: #3d67e8;
    --success: #34c77b;
    --error: #ff5c5c;
    --warning: #ffb454;
    --info: #48a9ff;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html {
    font-size: 16px;
}

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

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ---------- Header ---------- */
.app-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    gap: 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.05rem;
    white-space: nowrap;
}

.logo svg {
    color: var(--primary);
}

.logo b {
    color: var(--primary);
}

.nav {
    display: flex;
    gap: 4px;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    font-weight: 500;
}

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

.nav-link.active {
    color: var(--primary);
    background: rgba(79, 124, 255, 0.12);
}

.header-stats {
    display: flex;
    gap: 8px;
}

.stat-badge {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ---------- Views ---------- */
.view {
    display: none;
    padding: 32px 0 60px;
}

.view.active {
    display: block;
}

.hero {
    text-align: center;
    margin-bottom: 28px;
}

.hero h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-muted);
    max-width: 640px;
    margin: 0 auto;
}

h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 6px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.input-card {
    margin-bottom: 16px;
}

.url-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 12px 14px;
    font-size: 0.95rem;
    font-family: var(--font);
    resize: vertical;
    transition: border-color 0.15s;
}

.url-input:focus {
    outline: none;
    border-color: var(--primary);
}

.input-actions {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.format-select,
.resolution-select {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.format-select label,
.resolution-select label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
}

.format-select select,
.resolution-select select,
.queue-filters select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    min-width: 160px;
    cursor: pointer;
}

.btn-group {
    display: flex;
    gap: 8px;
    margin-left: auto;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

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

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--bg-hover);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.82rem;
}

.btn-success {
    background: rgba(52, 199, 123, 0.12);
    border: 1px solid rgba(52, 199, 123, 0.3);
    color: var(--success);
}

.btn-success:hover {
    background: rgba(52, 199, 123, 0.2);
}

.btn-danger {
    background: rgba(255, 92, 92, 0.12);
    border: 1px solid rgba(255, 92, 92, 0.3);
    color: var(--error);
}

.btn-danger:hover {
    background: rgba(255, 92, 92, 0.2);
}

.note-stream {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
}

/* ---------- Loading / Error ---------- */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 28px;
    color: var(--text-muted);
}

.hidden {
    display: none !important;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.error-box {
    background: rgba(255, 92, 92, 0.1);
    border: 1px solid rgba(255, 92, 92, 0.3);
    color: var(--error);
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

/* ---------- Meta results (preview cards) ---------- */
.meta-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.video-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.15s;
}

.video-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.vc-thumb {
    position: relative;
    aspect-ratio: 16/9;
    background: var(--bg);
    overflow: hidden;
}

.vc-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.vc-thumb .vc-badges {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    gap: 6px;
}

.badge {
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.badge-audio {
    background: rgba(52, 199, 123, 0.85);
}

.badge-res {
    background: rgba(72, 169, 255, 0.85);
}

.vc-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.vc-body {
    padding: 14px;
}

.vc-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.vc-meta {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-bottom: 10px;
}

.vc-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ---------- Task list (queue) ---------- */
.queue-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.queue-filters {
    display: flex;
    gap: 8px;
    align-items: center;
}

.task-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.empty-note {
    color: var(--text-muted);
    text-align: center;
    padding: 40px 0;
}

.task-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: border-color 0.15s;
}

.task-item:hover {
    border-color: var(--bg-hover);
}

.task-thumb {
    width: 80px;
    height: 45px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    object-fit: cover;
    flex-shrink: 0;
}

.task-thumb-placeholder {
    width: 80px;
    height: 45px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--bg-hover), var(--bg));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.task-main {
    flex: 1;
    min-width: 0;
}

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

.task-sub {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 2px;
}

.task-status {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
    flex-shrink: 0;
}

.status-queued {
    background: rgba(255, 180, 84, 0.12);
    color: var(--warning);
}

.status-downloading {
    background: rgba(72, 169, 255, 0.12);
    color: var(--info);
}

.status-done {
    background: rgba(52, 199, 123, 0.12);
    color: var(--success);
}

.status-error {
    background: rgba(255, 92, 92, 0.12);
    color: var(--error);
}

.task-progress-wrap {
    width: 120px;
    flex-shrink: 0;
}

.progress-bar {
    background: var(--bg);
    border-radius: 20px;
    height: 6px;
    overflow: hidden;
    margin-bottom: 4px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--info));
    border-radius: 20px;
    transition: width 0.3s ease;
}

.progress-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
}

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

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.icon-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.icon-btn.danger:hover {
    color: var(--error);
    border-color: rgba(255, 92, 92, 0.4);
}

/* ---------- Playlist ---------- */
.pl-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 16px 0;
    flex-wrap: wrap;
    gap: 10px;
}

.pl-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
}

.pl-item {
    display: flex;
    gap: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    align-items: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.pl-item:hover {
    border-color: var(--primary);
    background: var(--bg-hover);
}

.pl-item.selected {
    border-color: var(--primary);
    background: rgba(79, 124, 255, 0.08);
}

.pl-item input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.pl-thumb {
    width: 88px;
    height: 50px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg);
}

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

.pl-title {
    font-size: 0.85rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

/* ---------- Toast ---------- */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: 0.88rem;
    min-width: 260px;
    max-width: 360px;
    animation: slideIn 0.25s ease;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideIn {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ---------- Bulk ---------- */
.bulk-panel {
    margin-top: 16px;
}

.bulk-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 10px;
}

.bulk-header h3 {
    font-size: 1rem;
}

/* ---------- SEO content ---------- */
.seo-content {
    margin-top: 48px;
    padding-top: 32px;
    border-top: 1px solid var(--border);
    width: 100%;
}

.seo-content h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 24px 0 10px;
}

.seo-content h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 18px 0 6px;
    color: var(--text);
}

.seo-content p,
.seo-content li {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.65;
    margin-bottom: 8px;
}

.seo-content ul {
    padding-left: 20px;
    margin-bottom: 8px;
}

/* ---------- Footer ---------- */
.app-footer {
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    padding: 20px 0;
    margin-top: 40px;
}

.app-footer p {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .header-inner {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 0;
        gap: 8px;
    }

    .nav {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .btn-group {
        margin-left: 0;
        width: 100%;
    }

    .btn {
        flex: 1;
    }

    .task-item {
        flex-wrap: wrap;
    }

    .task-progress-wrap {
        width: 100%;
        order: 5;
    }
}