/* ============================================
   全局变量与重置
   ============================================ */
:root {
    --bg-primary: #0a0a14;
    --bg-surface: #141428;
    --bg-elevated: #1c1c3a;
    --bg-hover: #222250;
    --color-primary: #7c5cfc;
    --color-primary-hover: #9b7fff;
    --color-accent: #00d4ff;
    --color-success: #00d68f;
    --color-error: #ff5757;
    --color-warning: #ffb800;
    --text-primary: #e8e8f0;
    --text-secondary: #8888a8;
    --text-tertiary: #5a5a7a;
    --border-color: #2a2a4a;
    --border-hover: #3a3a6a;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-glow: 0 0 20px rgba(124, 92, 252, 0.15);
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   布局
   ============================================ */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-badge {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 20px;
}

.main {
    display: flex;
    flex: 1;
    overflow: hidden;
    gap: 1px;
    background: var(--border-color);
}

/* ============================================
   面板
   ============================================ */
.panel {
    background: var(--bg-primary);
    overflow-y: auto;
}

.input-panel {
    width: 440px;
    flex-shrink: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.output-panel {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 自定义滚动条 */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* ============================================
   区块
   ============================================ */
.section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.section-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.char-count {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 400;
}

.hint {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 400;
}

/* ============================================
   模型选择
   ============================================ */
.model-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.model-card {
    padding: 12px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-surface);
}

.model-card:hover {
    border-color: var(--border-hover);
    background: var(--bg-hover);
}

.model-card.active {
    border-color: var(--color-primary);
    background: rgba(124, 92, 252, 0.08);
    box-shadow: var(--shadow-glow);
}

.model-card-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.model-card-desc {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ============================================
   模式标签
   ============================================ */
.mode-tabs {
    display: flex;
    gap: 6px;
    background: var(--bg-surface);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.mode-tab {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.mode-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.mode-tab.active {
    background: var(--color-primary);
    color: white;
}

.mode-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.15);
}

.mode-tab:not(.active) .mode-icon {
    background: var(--bg-elevated);
}

/* ============================================
   提示词输入
   ============================================ */
.prompt-input {
    width: 100%;
    padding: 12px;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    line-height: 1.6;
    resize: vertical;
    min-height: 100px;
    transition: border-color 0.2s;
}

.prompt-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--shadow-glow);
}

.prompt-input::placeholder {
    color: var(--text-tertiary);
}

/* ============================================
   上传区域
   ============================================ */
.upload-zone {
    border: 1.5px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-surface);
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-zone:hover {
    border-color: var(--color-primary);
    background: var(--bg-hover);
}

.upload-zone.dragover {
    border-color: var(--color-primary);
    background: rgba(124, 92, 252, 0.08);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-tertiary);
}

.upload-placeholder span {
    font-size: 12px;
}

.upload-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}

.preview-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1.5px solid var(--border-color);
}

.preview-item img,
.preview-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-item .remove-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.preview-item .remove-btn:hover {
    background: var(--color-error);
}

.preview-item .role-badge {
    position: absolute;
    bottom: 2px;
    left: 2px;
    font-size: 9px;
    padding: 1px 6px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border-radius: 3px;
    white-space: nowrap;
}

/* ============================================
   高级设置
   ============================================ */
.advanced-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.advanced-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.advanced-toggle .chevron {
    transition: transform 0.2s;
}

.advanced-toggle.expanded .chevron {
    transform: rotate(180deg);
}

.advanced-settings {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-label {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.value-display {
    color: var(--color-primary);
    font-weight: 600;
}

.setting-select,
.setting-input {
    padding: 8px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s;
}

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

.setting-select option {
    background: var(--bg-elevated);
}

.setting-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: var(--bg-elevated);
    border-radius: 2px;
    outline: none;
}

.setting-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--color-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.setting-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.seed-input-group {
    display: flex;
    gap: 6px;
}

.seed-input-group .setting-input {
    flex: 1;
}

.btn-icon {
    padding: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

/* 开关 */
.toggle-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 6px;
    border-top: 1px solid var(--border-color);
}

.toggle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.toggle-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    transition: 0.3s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
    background: white;
}

/* ============================================
   生成按钮
   ============================================ */
.btn-generate {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
    background: linear-gradient(135deg, var(--color-primary), #6845ff);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: auto;
}

.btn-generate:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(124, 92, 252, 0.4);
}

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

.btn-generate.loading {
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

/* ============================================
   输出面板
   ============================================ */
.current-task {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* 空状态 */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-tertiary);
}

.empty-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 8px;
}

.empty-desc {
    font-size: 13px;
    color: var(--text-tertiary);
    text-align: center;
    max-width: 300px;
}

/* 任务进度 */
.task-progress {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.task-progress-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.task-status-indicator {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(124, 92, 252, 0.1);
}

.status-spinner {
    width: 24px;
    height: 24px;
    border: 2.5px solid rgba(124, 92, 252, 0.2);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.task-progress-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.task-status-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.task-model-text {
    font-size: 12px;
    color: var(--text-secondary);
}

.btn-cancel {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel:hover {
    border-color: var(--color-error);
    color: var(--color-error);
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background: var(--bg-elevated);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    border-radius: 3px;
    transition: width 0.5s ease;
}

.task-prompt-preview {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 10px 12px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    line-height: 1.5;
    max-height: 80px;
    overflow-y: auto;
}

/* 视频结果 */
.task-result {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.video-player {
    width: 100%;
    max-height: 500px;
    border-radius: var(--radius-md);
    background: black;
}

.result-actions {
    display: flex;
    gap: 10px;
}

.btn-action {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-action:hover {
    background: var(--bg-hover);
    border-color: var(--color-primary);
}

/* 错误状态 */
.task-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--color-error);
}

.error-title {
    font-size: 16px;
    font-weight: 600;
}

.error-msg {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    max-width: 400px;
    word-break: break-word;
}

.btn-retry {
    margin-top: 8px;
    padding: 8px 20px;
    background: var(--color-primary);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

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

/* ============================================
   历史记录
   ============================================ */
.history-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.history-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.btn-clear-history {
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 12px;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-clear-history:hover {
    color: var(--color-error);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-empty {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 13px;
    padding: 40px 0;
}

.history-item {
    display: flex;
    gap: 12px;
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 4px;
}

.history-item:hover {
    background: var(--bg-hover);
}

.history-thumb {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.history-thumb video,
.history-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-thumb-placeholder {
    color: var(--text-tertiary);
}

.history-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-prompt {
    font-size: 12px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.4;
}

.history-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-tertiary);
}

.history-status {
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
}

.history-status.succeeded {
    background: rgba(0, 214, 143, 0.15);
    color: var(--color-success);
}

.history-status.failed {
    background: rgba(255, 87, 87, 0.15);
    color: var(--color-error);
}

.history-status.queued,
.history-status.running {
    background: rgba(124, 92, 252, 0.15);
    color: var(--color-primary);
}

/* ============================================
   通知
   ============================================ */
.toast-container {
    position: fixed;
    top: 70px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 13px;
    color: white;
    animation: slideIn 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: 360px;
}

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

.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-error); }
.toast.info { background: var(--color-primary); }

/* ============================================
   响应式
   ============================================ */
@media (max-width: 900px) {
    .main {
        flex-direction: column;
    }
    .input-panel {
        width: 100%;
        max-height: 50vh;
    }
    .output-panel {
        flex: 1;
    }
    .model-grid {
        grid-template-columns: 1fr;
    }
}
