/* ================== 1. 核心变量 (Hugging Face 风格) ================== */
:root {
  --bg-body: #f3f4f6;          /* Tailwind gray-100: HF 外围背景色 */
  --bg-card: #ffffff;          /* 纯白卡片 */
  --bg-panel: #f9fafb;         /* Tailwind gray-50: 右侧控制栏底色 */
  --text-primary: #111827;     /* 深灰黑: 主文本 */
  --text-secondary: #4b5563;   /* 中灰: 次要文本 */
  --text-tertiary: #9ca3af;    /* 浅灰: 提示文本 */
  --border-light: #e5e7eb;     /* 浅灰边框 */
  --border-hover: #d1d5db;     /* 悬浮边框 */
  --radius-card: 16px;
  --radius-pill: 999px;
  --theme-hf-yellow: #ffd21e;  /* 🤗 Hugging Face 标志性黄色 */
  --theme-hf-yellow-hover: #fcd34d; 
  --theme-blue: #3b82f6;       /* HF 辅助链接蓝 */
  --theme-green: #10b981;      /* HF 成功绿 */
  --theme-red: #ef4444;
}

* { box-sizing: border-box; margin: 0; padding: 0; outline: none; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
}
a { text-decoration: none; color: inherit; transition: 0.2s; }

/* ================== 2. 顶部统计导航栏 ================== */
.sticky-header-wrapper {
  width: 100%; display: flex; justify-content: center;
  padding: 15px 20px; z-index: 999; flex-shrink: 0;
}
.filter-bar {
  display: flex; gap: 15px; align-items: center; 
  background: #ffffff; padding: 10px 20px;
  border-radius: 12px; border: 1px solid var(--border-light);
  width: 100%; max-width: 1600px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

#stats { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
#stats div {
  font-size: 0.8rem; font-weight: 600; color: var(--text-secondary);
  background: #f3f4f6; padding: 4px 12px; border-radius: 6px;
  border: 1px solid var(--border-light); display: flex; align-items: center; white-space: nowrap;
}
#stats div span { color: var(--text-primary); margin-left: 6px; font-weight: 700; font-family: monospace; font-size: 0.9rem;}

.tag-btn {
  background: #ffffff; border: 1px solid var(--border-light); color: var(--text-primary);
  padding: 6px 16px; border-radius: 8px; font-size: 0.85rem;
  font-weight: 600; cursor: pointer; transition: all 0.2s ease; white-space: nowrap; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
.tag-btn:hover { color: var(--text-primary); background: #f9fafb; border-color: var(--border-hover); box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);}

.global-key-input {
  background: #f9fafb; border: 1px solid var(--border-light); border-radius: 8px;
  color: var(--text-primary); padding: 6px 12px; width: 220px; font-size: 0.85rem; outline: none; transition: 0.3s;
}
.global-key-input:focus { border-color: var(--theme-blue); background: #ffffff; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); }

/* ================== 3. 宽屏工作台布局 ================== */
.workspace {
  width: 100%; max-width: 1600px; flex: 1; margin-bottom: 20px;
  background: var(--bg-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-card); 
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  display: flex; overflow: hidden; animation: fadeUp 0.6s ease backwards;
}

/* 左侧：内容面板 */
.editor-panel {
  flex: 1; padding: 20px; display: flex; flex-direction: column; position: relative;
  background: var(--bg-card);
  overflow: hidden; min-width: 0;
}

/* 右侧：控制面板 */
.control-panel {
  flex: 0 0 360px; padding: 20px; display: flex; flex-direction: column; gap: 15px;
  border-left: 1px solid var(--border-light); background: var(--bg-panel);
  overflow-y: auto; overflow-x: hidden;
}

/* 统一滚动条 (亮色风格) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ================== 4. UI 控件样式 ================== */
.section-title {
  font-size: 0.85rem; font-weight: 700; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center;
}

.glass-card { background: #ffffff; border: 1px solid var(--border-light); border-radius: 12px; padding: 15px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); }

.glass-input {
  width: 100%; background: #f9fafb; border: 1px solid var(--border-light);
  border-radius: 8px; color: var(--text-primary); padding: 10px 12px; font-family: inherit;
  font-size: 0.85rem; transition: all 0.2s; margin-bottom: 10px;
}
.glass-input::placeholder { color: var(--text-tertiary); }
.glass-input:focus { background: #ffffff; border-color: var(--theme-blue); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); }

select.glass-input {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234b5563' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 14px; padding-right: 30px; cursor: pointer;
}
select.glass-input option { background-color: #ffffff; color: var(--text-primary); }
select.glass-input:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="file"].glass-input { padding: 6px 12px; color: var(--text-secondary); cursor: pointer; background: #ffffff;}
input[type="file"]::file-selector-button { background: #f3f4f6; border: 1px solid var(--border-light); padding: 6px 12px; border-radius: 6px; color: var(--text-primary); margin-right: 10px; cursor: pointer; transition: 0.2s;}
input[type="file"]::file-selector-button:hover { background: #e5e7eb; }

.btn-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn {
  padding: 8px 10px; border-radius: 8px; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s; text-align: center; border: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(0); }

/* 原本的毛玻璃按钮变为清爽描边按钮 */
.btn-glass {
  background: #ffffff; border: 1px solid var(--border-light); color: var(--text-primary);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
.btn-glass:hover {
  background: #f9fafb; border-color: var(--border-hover);
  color: var(--text-primary); transform: translateY(-1px); box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

/* 核心行动按钮使用 HF 黄色 */
.bg-blue { background: var(--theme-hf-yellow); color: #000000; box-shadow: 0 1px 2px rgba(0,0,0,0.05); border: 1px solid #fbbf24;}
.bg-blue:hover { background: var(--theme-hf-yellow-hover); transform: translateY(-1px); box-shadow: 0 4px 10px rgba(251, 191, 36, 0.3);}
.bg-blue:disabled { background: #e5e7eb; color: var(--text-tertiary); border-color: var(--border-light); box-shadow: none; cursor: not-allowed; transform: none; }

/* TTS 样式 */
.tts-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 0.8rem; color: var(--text-secondary); }
.tts-row input[type="range"] { width: 60%; accent-color: var(--text-primary); }
.tts-checkbox { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 10px;}
input[type="checkbox"] { accent-color: var(--theme-hf-yellow); width: 14px; height: 14px; cursor: pointer; }

/* 折叠面板 */
.collapsible-header { cursor: pointer; user-select: none; transition: color 0.2s; }
.collapsible-header:hover { color: var(--theme-blue); }
.collapsible-header::after { content: '▼'; font-size: 0.6rem; transition: transform 0.3s; margin-left: 5px;}
.collapsible-header.collapsed::after { transform: rotate(-90deg); }
.collapsible-content { display: block; overflow: hidden; transition: max-height 0.3s ease-out; }
.collapsible-content.collapsed { display: none; }

/* ================== 5. 左侧内容区 & Tab 切换 ================== */
.editor-tabs { display: flex; gap: 8px; margin-bottom: 15px; flex-shrink: 0; overflow-x: auto; padding-bottom: 5px;}
.editor-tabs::-webkit-scrollbar { display: none;}
.editor-tab {
  background: transparent; border: 1px solid transparent;
  color: var(--text-secondary); padding: 8px 16px; border-radius: 8px;
  cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: 0.2s; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
/* 选中 Tab 呈现 HF 黄色标签 */
.editor-tab.active { background: var(--theme-hf-yellow); color: #000000; border-color: #fbbf24; }
.editor-tab:hover:not(.active) { background: #f3f4f6; color: var(--text-primary); border-color: var(--border-light);}

.workspace-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; min-height: 0; background: #ffffff; border: 1px solid var(--border-light); border-radius: 12px; }

/* 视图 1：文本视图 */
.view-header {
  display: flex; justify-content: space-between; align-items: center; gap: 15px;
  padding: 10px 15px; background: #f9fafb; border-bottom: 1px solid var(--border-light);
}
.view-header-title { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; gap: 8px; white-space: nowrap;}
.view-header-controls { display: flex; gap: 10px; align-items: center; flex: 1; justify-content: flex-end;}

#textarea {
  flex: 1; width: 100%; height: 100%; resize: none; background: transparent;
  border: none; padding: 20px; color: var(--text-primary); font-family: monospace;
  font-size: 0.95rem; line-height: 1.6; outline: none;
}

  /* ================== 6. 聊天对话区样式 ================== */
.chat-history {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
  background: #ffffff;
}

.chat-msg {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.6;
  word-break: break-word;
  animation: fadeUp 0.3s ease forwards;
}

/* 用户气泡样式：右对齐 + 主题黄 */
.msg-user {
  align-self: flex-end;
  background: var(--theme-hf-yellow);
  color: #000000;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 5px rgba(255, 210, 30, 0.2);
}

/* AI 气泡样式：左对齐 + 浅灰背景 */
.msg-ai {
  align-self: flex-start;
  background: #f3f4f6;
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-light);
}

/* 底部输入框区域 */
.chat-input-area {
  display: flex;
  gap: 10px;
  padding: 12px 15px;
  background: #f9fafb;
  border-top: 1px solid var(--border-light);
  align-items: flex-end;
}

#chatInput {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
  background: #ffffff;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s;
}

#chatInput:focus {
  border-color: var(--theme-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* 视图 3：图像生成预览 */
.image-gen-container { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; padding: 20px;}
.preview-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-tertiary); gap: 15px; text-align: center;}
.preview-placeholder svg { width: 64px; height: 64px; opacity: 0.5; color: var(--text-tertiary); }
.result-image { max-width: 100%; max-height: calc(100vh - 250px); object-fit: contain; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); border: 1px solid var(--border-light); }

/* 视图 4：媒体解析与抽帧预览 */
.media-image-display { max-width: 100%; max-height: calc(100vh - 350px); object-fit: contain; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); border: 1px solid var(--border-light); flex-shrink: 0;}
.media-time { color: var(--text-secondary); margin-top: 10px; font-size: 0.85rem; flex-shrink: 0;}
#mediaPlayerWrapper video, #mediaPlayerWrapper audio { max-width: 100%; max-height: calc(100vh - 300px); border-radius: 12px; outline: none; border: 1px solid var(--border-light); box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
.media-toolbar { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 8px; margin-top: 5px; max-width: 100%; padding: 8px 4px 12px 4px; flex-shrink: 0; }

/* 视图 5：API 日志 */
.log-entry { margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px dashed var(--border-light); font-family: monospace; font-size: 0.85rem; word-break: break-all; }
.log-time { color: var(--text-tertiary); margin-bottom: 5px; font-size: 0.8rem;}
.log-req { color: var(--theme-blue); margin-bottom: 5px;}
.log-res { color: var(--theme-green); }
.log-err { color: var(--theme-red); }

/* 全局加载动画与报错 */
.loader-spinner { width: 40px; height: 40px; border: 3px solid #f3f4f6; border-top-color: var(--theme-hf-yellow); border-radius: 50%; animation: spin 1s linear infinite; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: none;}
.error-msg { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); background: #fee2e2; border: 1px solid #f87171; color: #b91c1c; padding: 10px 20px; border-radius: 8px; font-weight: 500; font-size: 0.85rem; display: none; z-index: 30; box-shadow: 0 4px 6px rgba(0,0,0,0.1);}

@keyframes spin { 100% { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1024px) {
  .workspace { flex-direction: column-reverse; overflow-y: auto; border-radius: 0; border: none; margin-bottom: 0; box-shadow: none;}
  .control-panel { flex: none; border-left: none; border-top: 1px solid var(--border-light); width: 100%; background: #ffffff;}
  .workspace-view { min-height: 400px; border-radius: 0; border-left: none; border-right: none;}
}