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

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #14141f;
    --bg-tertiary: #1a1a2e;
    --bg-card: #1f1f35;
    --bg-hover: #2a2a45;
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #ffffff;
    --text-secondary: #a0a0b8;
    --text-muted: #6b6b82;
    --accent: #ff6b35;
    --accent-hover: #ff8c5a;
    --accent-glow: rgba(255, 107, 53, 0.3);
    --wan2gp-color: #38bdf8;
    --wan2gp-glow: rgba(56, 189, 248, 0.3);
    --success: #4ade80;
    --warning: #fbbf24;
    --danger: #f87171;
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.5;
}

.app { display: flex; flex-direction: column; height: 100vh; }

/* ─── Top Bar ─────────────────────────────── */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
    flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.logo {
    font-size: 18px; font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #ffa500);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.badge {
    padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.badge.online { background: rgba(74,222,128,0.15); color: var(--success); }
.badge.offline { background: rgba(248,113,113,0.15); color: var(--danger); }
.badge.wan2gp-on { background: rgba(56,189,248,0.15); color: var(--wan2gp-color); }
.badge.wan2gp-off { background: rgba(248,113,113,0.15); color: var(--danger); }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-field { display: flex; flex-direction: column; gap: 2px; }
.topbar-field label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.topbar-input {
    padding: 6px 10px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-size: 12px; outline: none;
}
.topbar-input:focus { border-color: var(--accent); }
.topbar-btn {
    padding: 6px 16px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm);
    font-size: 12px; font-weight: 700; cursor: pointer; transition: opacity 0.2s; margin-top: 14px;
}
.topbar-btn:hover { opacity: 0.85; }
.mode-toggle { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.mode-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }

/* ─── Language Selector ─────────────────── */
.lang-select {
    padding: 4px 8px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-size: 11px;
    font-weight: 600; outline: none; cursor: pointer; line-height: 1.4;
}
.lang-select:focus { border-color: var(--accent); }
.lang-select option { background: var(--bg-card); color: var(--text-primary); }

/* ─── Main Layout ─────────────────────────── */
.main { display: flex; flex: 1; overflow: hidden; }
.sidebar {
    width: 320px; background: var(--bg-secondary); border-right: 1px solid var(--border);
    padding: 16px; overflow-y: auto; flex-shrink: 0; display: flex; flex-direction: column; gap: 16px;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.panel { background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.panel-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); margin-bottom: 12px; }

.input-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.input-group:last-child { margin-bottom: 0; }
.input-group label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.input-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.input-row:last-child { margin-bottom: 0; }
.input-num {
    width: 100%; padding: 8px 10px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; outline: none;
}
.input-num:focus { border-color: var(--accent); }
.select-full {
    width: 100%; padding: 8px 10px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; outline: none; cursor: pointer;
}
.select-full:focus { border-color: var(--accent); }
.select-full option { background: var(--bg-card); color: var(--text-primary); }
.prompt-input {
    width: 100%; min-height: 80px; padding: 10px 12px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; font-family: inherit; resize: vertical; outline: none;
}
.prompt-input:focus { border-color: var(--accent); }
.prompt-input.prompt-small { min-height: 50px; font-size: 12px; }

.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    padding: 6px 12px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px;
    color: var(--text-secondary); font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.chip:hover { border-color: var(--border-hover); color: var(--text-primary); }
.chip.active { background: var(--accent); border-color: var(--accent); color: white; }

.generate-btn {
    width: 100%; padding: 14px 20px;
    background: linear-gradient(135deg, var(--accent), #ff8c00); border: none; border-radius: var(--radius);
    color: white; font-size: 15px; font-weight: 700; cursor: pointer; transition: all 0.3s;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    box-shadow: 0 4px 20px var(--accent-glow); flex-shrink: 0;
}
.generate-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 28px var(--accent-glow); }
.generate-btn:active { transform: translateY(0); }
.generate-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.generate-btn.wan2gp-btn {
    background: linear-gradient(135deg, var(--wan2gp-color), #818cf8);
    box-shadow: 0 4px 20px var(--wan2gp-glow);
}
.generate-btn.wan2gp-btn:hover { box-shadow: 0 6px 28px var(--wan2gp-glow); }
.btn-icon { font-size: 18px; }

.model-info { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); line-height: 1.6; }
.model-info .size { color: var(--text-secondary); font-weight: 600; }
.model-info .tag { display: inline-block; padding: 2px 6px; background: rgba(255,107,53,0.15); color: var(--accent); border-radius: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; margin-right: 4px; }

/* Upload */
.upload-area {
    border: 2px dashed var(--border); border-radius: var(--radius-sm); padding: 24px; text-align: center; cursor: pointer; color: var(--text-muted); font-size: 13px; transition: all 0.2s;
}
.upload-area:hover { border-color: var(--wan2gp-color); color: var(--wan2gp-color); }
.upload-area.dragover { border-color: var(--wan2gp-color); background: rgba(56,189,248,0.05); }
.upload-preview { max-width: 100%; max-height: 150px; border-radius: var(--radius-sm); margin-top: 8px; object-fit: contain; }

/* Downloads */
.download-list { display: flex; flex-direction: column; gap: 8px; }
.empty-text { text-align: center; color: var(--text-muted); font-size: 12px; padding: 16px 0; }
.download-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.download-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.download-item-name { font-size: 12px; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.download-item-status { font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; flex-shrink: 0; margin-left: 8px; }
.download-item-status.downloading { background: rgba(251,191,36,0.15); color: var(--warning); }
.download-item-status.done { background: rgba(74,222,128,0.15); color: var(--success); }
.download-item-status.error { background: rgba(248,113,113,0.15); color: var(--danger); }
.download-item-bar { height: 4px; background: var(--bg-primary); border-radius: 2px; overflow: hidden; }
.download-item-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #ffa500); border-radius: 2px; transition: width 0.3s; }

/* ─── Content Area ────────────────────────── */
.content { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 20px; }
.result-area {
    flex: 1; display: flex; align-items: center; justify-content: center; background: var(--bg-secondary);
    border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: relative; min-height: 0;
}
.empty-state { text-align: center; color: var(--text-muted); }
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.5; }
.empty-state p { font-size: 16px; margin-bottom: 4px; }
.empty-sub { font-size: 13px !important; color: var(--text-muted); opacity: 0.6; }
.result-image { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-sm); animation: fadeIn 0.5s ease; }
.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }
.progress-area { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); width: 80%; max-width: 500px; background: rgba(20,20,31,0.95); backdrop-filter: blur(10px); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; }
.progress-bar { height: 6px; background: var(--bg-primary); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #ffa500); border-radius: 3px; width: 0%; transition: width 0.2s; }
.progress-fill.wan2gp { background: linear-gradient(90deg, var(--wan2gp-color), #818cf8); }
.progress-text { font-size: 12px; color: var(--text-secondary); text-align: center; }
.progress-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.progress-task-id { font-size: 10px; color: var(--text-muted); font-family: 'SF Mono', Monaco, monospace; white-space: nowrap; }
.result-info { display: flex; gap: 24px; padding: 14px 20px; margin-top: 12px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); }
.info-item { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.info-value { font-size: 13px; color: var(--text-primary); font-family: 'SF Mono', Monaco, monospace; }

/* ─── Download / Action Buttons ────────── */
.result-actions { display: flex; gap: 10px; margin-bottom: 12px; }
.download-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 18px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px;
    font-weight: 600; text-decoration: none; cursor: pointer; transition: all 0.2s;
}
.download-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(255,107,53,0.08); }
.download-btn.open-btn:hover { border-color: var(--wan2gp-color); color: var(--wan2gp-color); background: rgba(56,189,248,0.08); }

/* ─── Connection Toast ──────────────────────────── */
.connection-toast {
    position: fixed; top: 16px; left: 50%; transform: translateX(-50%) translateY(-20px);
    z-index: 9999; padding: 10px 20px; border-radius: 8px;
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; font-weight: 500;
    opacity: 0; transition: all 0.4s ease;
    pointer-events: none; white-space: nowrap;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.connection-toast.show {
    opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto;
}
.connection-toast.reconnecting {
    background: rgba(251, 191, 36, 0.15); border: 1px solid rgba(251, 191, 36, 0.4);
    color: #fbbf24;
}
.connection-toast.recovered {
    background: rgba(74, 222, 128, 0.15); border: 1px solid rgba(74, 222, 128, 0.4);
    color: #4ade80;
}
.connection-toast.disconnected {
    background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.4);
    color: #ef4444;
}
.connection-toast .toast-icon { font-size: 16px; }

/* ─── Responsive ──────────────────────────── */
@media (max-width: 900px) { .sidebar { width: 280px; } }
@media (max-width: 700px) {
    .main { flex-direction: column; }
    .sidebar { width: 100%; height: auto; max-height: 50vh; border-right: none; border-bottom: 1px solid var(--border); }
    .content { padding: 12px; }
}

/* ─── 队列面板 ───────────────────────────────────────────────────────── */
.queue-panel { border-left: 3px solid #6366f1; }
.queue-list { max-height: 240px; overflow-y: auto; }
.queue-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px; border-radius: 6px; margin-bottom: 6px;
    background: rgba(99, 102, 241, 0.08); font-size: 12px;
}
.queue-item.running { background: rgba(16, 185, 129, 0.12); border-left: 2px solid #10b981; }
.queue-item.queued { background: rgba(245, 158, 11, 0.08); border-left: 2px solid #f59e0b; }
.queue-item.yours { background: rgba(99, 102, 241, 0.15); border-left: 2px solid #6366f1; }
.queue-item-header { display: flex; align-items: center; gap: 6px; flex: 1; }
.queue-item-type { font-weight: 600; color: #6366f1; }
.queue-item-status { font-size: 11px; padding: 2px 6px; border-radius: 4px; }
.queue-item-status.running { background: #d1fae5; color: #065f46; }
.queue-item-status.queued { background: #fef3c7; color: #92400e; }
.queue-item-status.cancelled { background: #fee2e2; color: #991b1b; }
.queue-item-cancel {
    background: transparent; border: 1px solid #ef4444; color: #ef4444;
    padding: 2px 8px; border-radius: 4px; font-size: 11px; cursor: pointer;
}
.queue-item-cancel:hover { background: #ef4444; color: #fff; }
.queue-wait-time { color: #6b7280; font-size: 11px; margin-top: 2px; }
