:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --surface-hover: #f7f8fa;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --border-light: #f0f1f3;
    --primary: #4f46e5;
    --primary-light: #eef2ff;
    --primary-hover: #4338ca;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --danger-hover: #b91c1c;
    --success: #059669;
    --success-light: #ecfdf5;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-width: 220px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}

.admin-shell {
    display: flex;
    min-height: 100vh;
}

/* ====== Sidebar ====== */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-light);
}

.brand-icon { font-size: 22px; }
.brand-text { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.nav-icon { flex-shrink: 0; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
}

.logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
    justify-content: center;
}

.logout-btn:hover {
    background: var(--danger-light);
    border-color: var(--danger);
    color: var(--danger);
}

.version-tag {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg);
    padding: 3px 8px;
    border-radius: 4px;
}

/* ====== Main Content ====== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    padding: 24px;
}

.page { display: none; }
.page.active { display: block; }

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

.page-header h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.03em;
}

/* ====== Cards ====== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-light);
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body { padding: 20px; }

/* ====== Badge ====== */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: 11px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
}

/* ====== Buttons ====== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-outline {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
.btn-outline:hover:not(:disabled) { background: var(--surface-hover); border-color: #d1d5db; }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-text {
    background: none;
    color: var(--primary);
    border: none;
    padding: 4px 8px;
    font-size: 13px;
}
.btn-text:hover:not(:disabled) { color: var(--primary-hover); background: var(--primary-light); border-radius: 4px; }

.btn-link {
    background: none;
    color: var(--primary);
    border: none;
    padding: 0;
    font-size: inherit;
    font-weight: 500;
    cursor: pointer;
    text-decoration: underline;
}

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ====== Upload Row ====== */
.upload-row {
    display: flex;
    gap: 20px;
    align-items: stretch;
}

.upload-dropzone {
    flex: 1;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--surface-hover);
}

.upload-dropzone:hover,
.upload-dropzone.dragging {
    border-color: var(--primary);
    background: var(--primary-light);
}

.dropzone-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px 20px;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
}

.dropzone-inner strong {
    color: var(--primary);
    cursor: pointer;
}

.upload-divider {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    font-size: 13px;
}

.upload-divider::before,
.upload-divider::after {
    display: none;
}

.tiktok-download-card {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    background: var(--surface);
}

.tiktok-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

.tiktok-input-row {
    display: flex;
    gap: 8px;
}

.tiktok-input-row input {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease;
}

.tiktok-input-row input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

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

.tiktok-download-card textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    transition: border-color 0.15s ease;
    min-height: 80px;
}

.tiktok-download-card textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.tiktok-download-card textarea::placeholder {
    color: var(--text-muted);
}

.tiktok-batch-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    align-items: center;
}

.tiktok-status {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    font-weight: 500;
    min-height: 18px;
}

.tiktok-status.loading { color: var(--warning); }
.tiktok-status.success { color: var(--success); }
.tiktok-status.error { color: var(--danger); }

/* ====== Data Table ====== */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead {
    border-bottom: 2px solid var(--border);
}

.data-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: var(--surface-hover);
}

.data-table tbody tr.selected {
    background: var(--primary-light);
}

.data-table input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

.material-preview-thumb {
    width: 80px;
    height: 60px;
    border-radius: 4px;
    overflow: hidden;
    background: #000;
    position: relative;
    cursor: pointer;
}

.material-preview-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.source-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.source-tag.upload {
    background: #eef2ff;
    color: #4f46e5;
}

.source-tag.tiktok {
    background: #fdf2f8;
    color: #db2777;
}

.task-status-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.task-pending {
    background: #f3f4f6;
    color: #6b7280;
}

.task-downloading {
    background: var(--warning-light);
    color: var(--warning);
}

.task-downloaded {
    background: var(--success-light);
    color: var(--success);
}

.task-failed {
    background: var(--danger-light);
    color: var(--danger);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-muted);
    gap: 12px;
}

.empty-state p { font-size: 14px; }

.action-btns {
    display: flex;
    gap: 4px;
}

.action-btns .btn {
    padding: 4px 10px;
    font-size: 12px;
}

/* ====== Remix Page ====== */
.remix-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 16px;
    align-items: start;
    margin-bottom: 16px;
}

.remix-materials-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    max-height: 520px;
    overflow-y: auto;
    padding-right: 4px;
}

.remix-materials-grid::-webkit-scrollbar {
    width: 6px;
}

.remix-materials-grid::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.remix-materials-grid::-webkit-scrollbar-track {
    background: transparent;
}

.remix-material-card {
    position: relative;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.15s ease;
}

.remix-material-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.remix-material-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}

.remix-material-card .preview-area {
    width: 100%;
    aspect-ratio: 16/10;
    background: #000;
    position: relative;
}

.remix-material-card .preview-area video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remix-material-card .preview-area .no-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-muted);
    font-size: 12px;
}

.remix-material-card .check-badge {
    position: absolute;
    top: 8px; right: 8px;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.remix-material-card.selected .check-badge {
    display: flex;
}

.remix-material-card .card-info {
    padding: 8px 10px;
}

.remix-material-card .card-info .name {
    font-size: 12px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.remix-material-card .card-info .meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ====== Preset Radio ====== */
.preset-stack {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.preset-radio {
    display: block;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s ease;
}

.preset-radio:hover {
    border-color: var(--primary);
}

.preset-radio input[type="radio"] {
    display: none;
}

.preset-radio.active {
    border-color: var(--primary);
    background: var(--primary-light);
}

.preset-radio-content strong {
    display: block;
    font-size: 14px;
    margin-bottom: 2px;
}

.preset-radio-content span {
    font-size: 12px;
    color: var(--text-secondary);
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
}

.toggle-row span {
    font-size: 14px;
    font-weight: 500;
}

.toggle-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* ====== Result ====== */
.progress-strip {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.progress-bar {
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    background: var(--border-light);
}

.progress-fill {
    width: 0;
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
}

.stage-text {
    font-size: 12px;
    color: var(--text-muted);
    text-align: right;
}

.status-tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.status-tag.idle { background: #f3f4f6; color: #6b7280; }
.status-tag.loading { background: var(--warning-light); color: var(--warning); }
.status-tag.success { background: var(--success-light); color: var(--success); }
.status-tag.error { background: var(--danger-light); color: var(--danger); }

.result-content {
    min-height: 200px;
}

.result-content .result-player {
    width: 100%;
    max-height: 560px;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    margin-bottom: 12px;
}

.result-content .result-player video {
    width: 100%;
    max-height: 560px;
    display: block;
}

.result-summary {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.result-block {
    padding: 10px 14px;
    background: var(--surface-hover);
    border-radius: var(--radius);
}

.result-block strong {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
    letter-spacing: 0.05em;
}

.result-block div {
    font-size: 13px;
    word-break: break-all;
}

.result-facts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 8px;
}

.fact-card {
    padding: 10px;
    background: var(--primary-light);
    border-radius: var(--radius);
}

.fact-card span {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
}

.fact-card strong {
    display: block;
    font-size: 16px;
    margin-top: 2px;
}

.result-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.result-actions.hidden { display: none; }
.result-actions .hidden { display: none; }

.error-text {
    background: var(--danger-light) !important;
}

.error-detail {
    margin-top: 8px;
}

.error-detail summary {
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--danger);
}

.error-detail pre {
    margin-top: 8px;
    padding: 10px;
    border-radius: var(--radius);
    background: #1e1e1e;
    color: #e5e5e5;
    font-size: 11px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 160px;
    overflow: auto;
}

/* ====== Job List ====== */
.job-list {
    display: grid;
    gap: 8px;
}

.job-list.empty {
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
}

.job-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    background: var(--surface);
    transition: all 0.15s ease;
    text-align: left;
    width: 100%;
    font: inherit;
}

.job-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.job-item.active {
    border-color: var(--primary);
    background: var(--primary-light);
}

.job-item .job-info strong {
    display: block;
    font-size: 14px;
    margin-bottom: 2px;
}

.job-item .job-info span {
    font-size: 12px;
    color: var(--text-muted);
}

.job-item .job-status {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 10px;
}

.job-status.queued { background: #f3f4f6; color: #6b7280; }
.job-status.running { background: var(--warning-light); color: var(--warning); }
.job-status.completed { background: var(--success-light); color: var(--success); }
.job-status.failed { background: var(--danger-light); color: var(--danger); }
.job-status.cancelled { background: #f3f4f6; color: #6b7280; }

/* ====== Media Card (legacy template) ====== */
.media-card { display: none; }

/* ====== Modal ====== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: min(720px, 90vw);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal video {
    width: 100%;
    max-height: 60vh;
    border-radius: var(--radius);
    background: #000;
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    width: 32px; height: 32px;
    border: none;
    background: var(--surface-hover);
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

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

/* ====== BGM Management ====== */
.bgm-upload-row {
    margin-bottom: 16px;
}

.bgm-dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--surface-hover);
}

.bgm-dropzone:hover,
.bgm-dropzone.dragging {
    border-color: var(--primary);
    background: var(--primary-light);
}

.bgm-dropzone-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px 20px;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
}

.bgm-dropzone-inner strong {
    color: var(--primary);
    cursor: pointer;
}

.bgm-upload-status {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    font-weight: 500;
    min-height: 18px;
}

.bgm-upload-status.loading { color: var(--warning); }
.bgm-upload-status.success { color: var(--success); }
.bgm-upload-status.error { color: var(--danger); }

/* ====== Responsive ====== */
@media (max-width: 1024px) {
    .remix-layout {
        grid-template-columns: 1fr;
    }

    .upload-row {
        flex-direction: column;
    }

    .upload-divider {
        flex-direction: row;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }

    .brand-text,
    .nav-item span:not(.nav-icon),
    .version-tag {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 12px;
    }

    .main-content {
        margin-left: 60px;
        padding: 16px;
    }

    :root {
        --sidebar-width: 60px;
    }
}
