:root {
  --bg: #0f1419;
  --card: #1a2332;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --border: #2d3a4f;
  --error: #f87171;
  --success: #34d399;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.page {
  width: 94%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.service-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
  color: var(--muted);
}

.service-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.service-switch-ui {
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: var(--border);
  position: relative;
  transition: background 0.2s;
}

.service-switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.service-switch input:checked + .service-switch-ui {
  background: var(--success);
}

.service-switch input:checked + .service-switch-ui::after {
  transform: translateX(18px);
}

.switch-state {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.switch-state:empty {
  display: none;
}

.switch-state-on {
  color: var(--success);
}

.switch-state-off {
  color: var(--muted);
}

.switch-state-wait {
  color: #fbbf24;
}

.service-switch.is-busy {
  opacity: 0.65;
  pointer-events: none;
}

.notice-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #7dd3fc;
  font-size: 0.9rem;
}

.service-banner {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--error);
  font-size: 0.9rem;
}

.service-banner a {
  color: var(--accent);
}

.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 8px;
  flex-shrink: 0;
}

.btn-link:hover {
  color: var(--text);
}

.layout {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-start;
}

.main-panel {
  flex: 1 1 560px;
  min-width: 0;
}

.history-panel {
  flex: 0 0 320px;
  width: 320px;
  max-width: 100%;
}

@media (max-width: 900px) {
  .page {
    width: 100%;
    padding: 16px 12px 32px;
  }

  .main-panel,
  .history-panel {
    flex: 1 1 100%;
    width: 100%;
  }
}

.panel-title {
  margin: 0 0 8px;
  font-size: 1rem;
}

.history-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  max-height: 70vh;
  overflow-y: auto;
}

.history-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.history-time {
  color: var(--muted);
  font-size: 0.75rem;
}

.history-msg {
  color: var(--muted);
  margin-bottom: 4px;
}

.history-err {
  color: var(--error);
  font-size: 0.8rem;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 3.6em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.badge {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--border);
  white-space: nowrap;
}

.badge.completed {
  background: rgba(52, 211, 153, 0.2);
  color: var(--success);
}

.badge.failed {
  background: rgba(248, 113, 113, 0.15);
  color: var(--error);
}

.badge.processing,
.badge.uploading,
.badge.tts {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: 100%;
  max-width: 440px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card .label {
  margin-bottom: 0;
  font-size: 0.95rem;
}

.login-card input[type="text"],
.login-card input[type="password"] {
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  font-size: 1.1rem;
  line-height: 1.4;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1419;
  color: var(--text);
  box-sizing: border-box;
}

.login-card input[type="password"] {
  letter-spacing: 0.06em;
}

.login-card .btn {
  min-height: 48px;
  font-size: 1.05rem;
  margin-top: 4px;
}

.progress-pct {
  text-align: right;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.header {
  text-align: center;
  margin-bottom: 28px;
}

.header h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  font-weight: 700;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

.field {
  margin-bottom: 20px;
}

.label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
  white-space: normal;
}

.req {
  color: var(--error);
}

.hint {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

input[type="file"],
input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1419;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.4;
}

input[type="number"] {
  min-height: 42px;
}

textarea {
  resize: vertical;
  min-height: 96px;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  flex: 1;
  min-width: 140px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  text-align: center;
  font-size: 0.85rem;
  transition: border-color 0.15s, background 0.15s;
}

.tab input {
  display: none;
}

.tab.active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
}

.preview img {
  max-width: 160px;
  max-height: 160px;
  border-radius: 8px;
  margin-top: 10px;
  object-fit: cover;
  cursor: zoom-in;
}

.btn {
  display: inline-block;
  width: 100%;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

.btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.secondary {
  margin-top: 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.status {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.status-title {
  font-weight: 600;
  margin-bottom: 6px;
}

.status-msg {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.progress {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.result {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.result h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: var(--success);
}

video {
  width: 100%;
  border-radius: 10px;
  background: #000;
}

.result-image {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 10px;
  background: #000;
  cursor: zoom-in;
}

.result-image-hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.88);
  cursor: zoom-out;
}

.lightbox.hidden {
  display: none !important;
}

.lightbox-img {
  max-width: 96vw;
  max-height: calc(100vh - 80px);
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.lightbox-hint {
  margin: 12px 0 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.55);
  pointer-events: none;
}

.field.nested {
  margin-top: 8px;
  padding-left: 4px;
  border-left: 2px solid var(--border);
}

.wf-tag {
  font-size: 0.75rem;
  color: var(--accent);
  margin-right: 6px;
}

.error {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.12);
  color: var(--error);
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

.footer {
  text-align: center;
  margin-top: 32px;
  color: var(--muted);
  font-size: 0.8rem;
}

.workflow-tips {
  margin-bottom: 20px;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.08);
}

.workflow-tips.hidden {
  display: none !important;
}

.workflow-tips-title {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.workflow-tips-desc {
  margin: 0 0 10px;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.5;
}

.workflow-tips-list {
  margin: 0;
  padding-left: 1.2em;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.55;
}

.workflow-tips-list li {
  margin-bottom: 4px;
}

.workflow-tips-list li:last-child {
  margin-bottom: 0;
}

.workflow-params {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(59, 130, 246, 0.25);
}

.workflow-params.hidden {
  display: none !important;
}

.workflow-params-hint {
  margin: 0 0 8px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.workflow-params-list {
  margin: 0;
  padding-left: 1.2em;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.55;
}

.workflow-params-list li {
  margin-bottom: 6px;
}

.workflow-params-list li:last-child {
  margin-bottom: 0;
}

.workflow-params-list strong {
  color: var(--accent);
  font-weight: 600;
}

.workflow-params-list .param-options {
  color: var(--muted);
  font-size: 0.8rem;
}

.advanced-controls {
  margin-bottom: 20px;
  padding: 16px 18px;
  border-radius: 12px;
  border: 1px solid rgba(59, 130, 246, 0.35);
  background: linear-gradient(
    165deg,
    rgba(59, 130, 246, 0.08) 0%,
    rgba(15, 20, 25, 0.4) 55%
  );
}

.advanced-controls.hidden {
  display: none !important;
}

.advanced-controls-title {
  margin: 0 0 4px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent);
}

.advanced-controls-hint {
  margin: 0 0 14px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
}

#advancedControlsFields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  align-items: start;
}

.advanced-controls .field {
  margin-bottom: 0;
  min-width: 0;
  padding: 14px 14px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(10, 14, 20, 0.85);
}

.advanced-controls .field .label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.45;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.advanced-controls .field .hint {
  margin-top: 8px;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--muted);
}

.advanced-controls .field select,
.advanced-controls .field input[type="number"],
.advanced-controls .field input[type="text"] {
  width: 100%;
  min-width: 0;
}

.workflow-voice-note {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(139, 156, 179, 0.08);
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--muted);
}

.workflow-voice-note.hidden {
  display: none !important;
}

.speech-voice-hint {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.1);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--muted);
}

@media (max-width: 720px) {
  #advancedControlsFields {
    grid-template-columns: 1fr;
  }
}

.quick-picks {
  margin-bottom: 20px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.06);
}

.quick-picks-title {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 600;
}

.quick-picks-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.quick-pick-btn {
  flex: 1 1 220px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

.quick-pick-btn:hover {
  border-color: var(--accent);
}

.quick-pick-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.quick-pick-label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
}

.quick-pick-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.result-meta {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(15, 20, 25, 0.5);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  line-height: 1.6;
}

.result-meta-k {
  display: inline-block;
  min-width: 6.5em;
  color: var(--muted);
}

.result-meta code {
  font-size: 0.8rem;
  word-break: break-all;
}

.result-meta-actions {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.gpu-status {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.gpu-status-ok {
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.35);
  color: var(--success);
}

.gpu-status-busy {
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: #fbbf24;
}

.gpu-status-error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--error);
}

.textarea-ai-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.ai-brief-wrap {
  width: 100%;
}

.ai-brief-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

.ai-brief-textarea {
  width: 100%;
  min-height: 4.5rem;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.45;
  resize: vertical;
}

.textarea-ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.ai-fill-mode {
  flex: 1 1 140px;
  min-width: 120px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.88rem;
}

.ai-brief-input {
  flex: 1 1 200px;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.btn-ai {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 0.88rem;
}

.btn-ai:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
