/* ===================== 全局重置 & 变量 ===================== */
:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-bg: #f0f0ff;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --bg: #f8f9fc;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f0f0f0;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===================== 头部 ===================== */
.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, #6366f1 100%);
  color: #fff;
  padding: 16px 24px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 1px;
}

.app-subtitle {
  font-size: 13px;
  opacity: 0.85;
  font-weight: 400;
}

/* ===================== 标签栏 ===================== */
.tab-bar {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  flex-shrink: 0;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  font-family: inherit;
}

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

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ===================== 面板容器 ===================== */
.tab-panel {
  display: none;
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px;
  flex-direction: column;
  overflow: hidden;
}

.tab-panel.active {
  display: flex;
}

/* ===================== 工具栏 ===================== */
.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

/* ===================== 表单元素 ===================== */
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: inline-block;
  margin-bottom: 4px;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.field-inline .field-label {
  margin-bottom: 0;
  white-space: nowrap;
}

.required {
  color: var(--error);
}

.select,
.input,
.textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--card-bg);
  transition: var(--transition);
  outline: none;
}

.select:focus,
.input:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.select {
  cursor: pointer;
  max-width: 360px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group {
  margin-bottom: 14px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

/* 滑块 */
.range {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
}

.range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
}

.range-val {
  color: var(--primary);
  font-weight: 600;
  font-size: 12px;
}

/* 高级设置 */
.advanced-settings {
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--bg);
}

.advanced-settings summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-secondary);
  user-select: none;
}

.advanced-settings[open] summary {
  margin-bottom: 12px;
}

/* ===================== 按钮 ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  white-space: nowrap;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: var(--shadow);
}

.btn-ghost {
  background: none;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 13px;
}

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

/* ===================== 对话区域 ===================== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  scroll-behavior: smooth;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.chat-empty p {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-hint {
  font-size: 13px;
  margin-top: 4px;
}

/* 消息气泡 */
.msg {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-user {
  margin-left: auto;
  align-items: flex-end;
}

.msg-assistant {
  margin-right: auto;
  align-items: flex-start;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-user .msg-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-assistant .msg-bubble {
  background: var(--primary-bg);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg-role {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  padding: 0 4px;
}

/* 流式光标 */
.streaming-cursor::after {
  content: "▋";
  animation: blink 0.8s infinite;
  color: var(--primary);
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* 加载中提示 */
.msg-loading {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
}

.msg-loading .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite ease-in-out;
}

.msg-loading .dot:nth-child(2) { animation-delay: 0.2s; }
.msg-loading .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* 对话输入区 */
.chat-input-area {
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  transition: var(--transition);
}

.chat-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  max-height: 120px;
  padding: 6px 8px;
  background: none;
  color: var(--text);
}

.btn-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-sm);
}

/* ===================== 生成布局 (图片/视频) ===================== */
.generate-layout {
  display: flex;
  gap: 20px;
  flex: 1;
  overflow: hidden;
}

.generate-form {
  width: 380px;
  flex-shrink: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  overflow-y: auto;
}

.generate-output {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.output-area {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.output-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}

/* 图片结果网格 */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  width: 100%;
}

.image-card {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

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

.image-card img {
  width: 100%;
  display: block;
  cursor: pointer;
}

.image-card .image-actions {
  padding: 8px 12px;
  display: flex;
  gap: 8px;
  justify-content: center;
}

.image-card .btn {
  padding: 4px 10px;
  font-size: 12px;
}

/* 视频结果 */
.video-result {
  width: 100%;
  max-width: 720px;
}

.video-result video {
  width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.video-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* 进度状态 */
.progress-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px;
}

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

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

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

.progress-detail {
  font-size: 13px;
  color: var(--text-muted);
}

/* 图片输入标签 */
.image-input-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.img-tab-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
  font-family: inherit;
}

.img-tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.image-preview {
  margin-top: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  max-width: 200px;
}

.image-preview img {
  width: 100%;
  display: block;
}

/* ===================== Toast 提示 ===================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.toast-success {
  background: var(--success);
  color: #fff;
}

.toast-error {
  background: var(--error);
  color: #fff;
}

.toast-warning {
  background: var(--warning);
  color: #fff;
}

/* ===================== 错误提示 ===================== */
.error-box {
  padding: 12px 16px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
}

/* ===================== 响应式 ===================== */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    gap: 4px;
  }

  .tab-bar {
    padding: 0 12px;
    overflow-x: auto;
  }

  .tab-panel {
    padding: 12px;
  }

  .generate-layout {
    flex-direction: column;
  }

  .generate-form {
    width: 100%;
  }

  .select {
    max-width: 100%;
  }

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

  .msg {
    max-width: 95%;
  }
}

/* 滚动条美化 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
