/* ==========================================================================
   短剧标题工作台 · 统一样式
   零构建、无外部依赖，字体全部使用系统字体栈（Windows 上优先雅黑）
   ========================================================================== */

:root {
  --brand: #6366f1;
  --brand-2: #8b5cf6;
  --brand-soft: #eef0ff;
  --bg: #f5f6fa;
  --card: #ffffff;
  --line: #e6e8f0;
  --text: #1f2430;
  --text-2: #5b6273;
  --text-3: #939aab;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(24, 30, 55, .05);
  --shadow: 0 4px 16px rgba(24, 30, 55, .07);
  --shadow-lg: 0 16px 48px rgba(24, 30, 55, .16);
  --font: "Microsoft YaHei UI", "Microsoft YaHei", -apple-system,
          "Segoe UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

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

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 60px;
  background: linear-gradient(100deg, #5b5ff0 0%, #8b5cf6 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(80, 70, 200, .25);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .3px;
}

.brand .logo { font-size: 21px; }

.badge {
  padding: 1px 7px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .22);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
}

.topbar .spacer { flex: 1; }

.topbar a, .topbar button.link {
  color: rgba(255, 255, 255, .92);
  text-decoration: none;
  font-size: 13.5px;
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background .15s;
}

.topbar a:hover, .topbar button.link:hover { background: rgba(255, 255, 255, .16); }

.workbench {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  flex: 1;
  align-items: start;
  max-width: 1680px;
  width: 100%;
  margin: 0 auto;
}

.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ---------------------------------------------------------------- 卡片 */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  font-size: 14px;
}

.card-head .icon { font-size: 15px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; overflow-x: auto; }

/* 列多的表（模型管理 7 列）：给足最小宽度保证可读，容器窄时横向滚动 */
.wide-table { min-width: 1000px; }
.wide-table td, .wide-table th { padding-left: 7px; padding-right: 7px; }
.wide-table input, .wide-table select { padding: 5px 7px; }
.wide-table .row-actions { gap: 5px; flex-wrap: nowrap; }
.wide-table .btn.sm { padding: 3px 7px; }

/* ---------------------------------------------------------------- 表单 */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 7px;
}

.label .req { color: var(--danger); }
.label .hint { font-weight: 400; color: var(--text-3); font-size: 12px; }
.label .spacer { flex: 1; }

.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 10px;
  font-weight: 700;
  cursor: help;
  position: relative;
}

.tip:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: 130%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 240px;
  padding: 7px 10px;
  background: #2b3040;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  border-radius: 7px;
  z-index: 40;
  white-space: normal;
  box-shadow: var(--shadow);
}

select, input[type="text"], input[type="password"], input[type="number"], textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .12);
}

textarea { resize: vertical; min-height: 120px; line-height: 1.65; }

select { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23939aab' d='M6 8.5L1.5 4h9z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}

/* 没有可用的提示词文件时下拉置灰：要一眼看出「这里缺配置」，不能看着像能用 */
select:disabled {
  background-color: #f4f4f7;
  color: var(--text-3);
  border-color: var(--line);
  cursor: not-allowed;
}

.counter { text-align: right; font-size: 11.5px; color: var(--text-3); margin-top: 4px; }

/* ------------------------------------------------------------ 剧情截图 */
.img-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
/* 上面给了 display:flex，会盖掉 [hidden] 自带的效果，必须显式补一条 */
.img-strip[hidden] { display: none; }

.thumb {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 8px;
  overflow: hidden;
  border: 1.5px solid var(--line);
  background: #f5f5f8;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.thumb-x {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 19px;
  height: 19px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-x:hover { background: rgba(0, 0, 0, .78); }

textarea.dragging {
  border-color: var(--brand);
  background: #f8f8ff;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .12);
}

#plotImageHint { color: var(--text-3); }

/* ---------------------------------------------------------------- 标签选择 */
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  padding: 4px 11px;
  border-radius: 20px;
  border: 1.5px solid var(--line);
  background: #fbfbfd;
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  transition: all .12s;
  white-space: nowrap;
}

.tag:hover { border-color: #c7cbf5; color: var(--brand); background: #f7f7ff; }

.tag.on {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, .3);
}

.tags.collapsed .tag:nth-child(n+13) { display: none; }

/* 收起时只露一行（语种用）。行高不写死：JS 把真实标签高度量进 --tag-row，
   这样系统缩放 / 换字号时不会把第二行露出一条边。 */
.tags.collapsed.one-row {
  max-height: var(--tag-row, 31px);
  overflow: hidden;
}

.tags-toggle {
  border: none;
  background: none;
  color: var(--brand);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
}

/* ---------------------------------------------------------------- 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { border-color: #c7cbf5; color: var(--brand); background: #f8f8ff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, .3);
}

.btn.primary:hover:not(:disabled) { filter: brightness(1.06); color: #fff; }

.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); border-color: #f3d4d4; }
.btn.danger:hover:not(:disabled) { background: #fdf4f4; color: var(--danger); border-color: #eab8b8; }

.btn.block { width: 100%; }
.btn.lg { padding: 12px 18px; font-size: 14.5px; border-radius: 10px; }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }

/* ---------------------------------------------------------------- 参考来源切换 */
.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #f1f2f8;
  border-radius: 9px;
  margin-bottom: 12px;
}

.segmented button {
  flex: 1;
  padding: 6px 8px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}

.segmented button.on { background: #fff; color: var(--brand); box-shadow: var(--shadow-sm); }

.pane { display: none; }
.pane.on { display: block; }

.file-drop {
  border: 1.5px dashed var(--line);
  border-radius: 9px;
  padding: 18px;
  text-align: center;
  color: var(--text-3);
  font-size: 12.5px;
  cursor: pointer;
  transition: all .15s;
  background: #fcfcfe;
}

.file-drop:hover { border-color: var(--brand); color: var(--brand); background: #f8f8ff; }
.file-drop.has-file { border-style: solid; border-color: #b9f0c8; background: #f4fdf6; color: var(--ok); }

/* ---------------------------------------------------------------- 结果区 */
.result-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.metrics { display: flex; gap: 14px; color: var(--text-3); font-size: 12.5px; }
.metrics b { color: var(--text); font-weight: 700; }

.result-body {
  padding: 16px;
  min-height: 320px;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 20px;
  color: var(--text-3);
  text-align: center;
}

.empty .big { font-size: 40px; opacity: .55; }

/* 流式原文 */
.stream-status {
  font-size: 12.5px;
  color: var(--brand);
  margin-bottom: 8px;
  min-height: 19px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stream-status:empty { display: none; }

.stream-status .pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: .25; transform: scale(.85); }
  50% { opacity: 1; transform: scale(1); }
}

.stream-view {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  background: #fbfbfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}

.stream-view .caret {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--brand);
  animation: blink 1s steps(2) infinite;
  vertical-align: -2px;
}

@keyframes blink { 50% { opacity: 0; } }

/* 分组标题 */
.group { margin-bottom: 18px; }
.group:last-child { margin-bottom: 0; }

.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.group-name {
  font-weight: 700;
  font-size: 13px;
  color: var(--brand);
  background: var(--brand-soft);
  padding: 3px 10px;
  border-radius: 6px;
}

.group-count { font-size: 11.5px; color: var(--text-3); }

.title-item {
  display: flex;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-bottom: 7px;
  background: #fff;
  transition: all .13s;
  cursor: pointer;
  position: relative;
}

.title-item:hover { border-color: #c7cbf5; background: #fafaff; transform: translateX(2px); }
.title-item.copied { border-color: #b9f0c8; background: #f4fdf6; }

.title-idx {
  flex: 0 0 22px;
  color: var(--text-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding-top: 1px;
}

.title-main { flex: 1; min-width: 0; }

.title-text { font-size: 13.5px; line-height: 1.65; word-break: break-word; }

/* 双语对照：英文标题下面一行中文译文 */
.title-trans {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-3);
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px dashed var(--line);
  word-break: break-word;
}

/* 模型自评 Top 3 */
.top3-box {
  margin-top: 20px;
  padding: 14px 16px 6px;
  border: 1px solid #f0e0b8;
  border-radius: 11px;
  background: #fffdf6;
}

.top3-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 0;
  border-top: 1px dashed #eadfc4;
}

.top3-item:first-of-type { border-top: none; }

.top3-rank {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  color: #a5761a;
  background: #fdf1d6;
  border-radius: 6px;
  padding: 2px 7px;
  font-variant-numeric: tabular-nums;
}

.top3-main { flex: 1; min-width: 0; }

.top3-title { font-size: 13.5px; font-weight: 600; line-height: 1.6; word-break: break-word; }

.top3-reason {
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-2, #5b6070);
}

.top3-item .title-copy { opacity: 0; }
.top3-item:hover .title-copy { opacity: 1; }

.title-copy {
  flex: 0 0 auto;
  opacity: 0;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-3);
  font-size: 13px;
  transition: opacity .13s;
}

.title-item:hover .title-copy { opacity: 1; }
.title-copy:hover { color: var(--brand); }

/* 分析结果折叠 */
.analysis-box { margin-bottom: 16px; }

.analysis-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfbfe;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.analysis-toggle:hover { border-color: #c7cbf5; color: var(--brand); }
.analysis-toggle .arrow { transition: transform .15s; }
.analysis-toggle.open .arrow { transform: rotate(90deg); }

.analysis-content {
  display: none;
  margin-top: 8px;
  padding: 12px;
  background: #fbfbfe;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  max-height: 300px;
  overflow: auto;
  color: var(--text-2);
}

.analysis-content.on { display: block; }

/* ---------------------------------------------------------------- 对话 */
.chat-panel { display: flex; flex-direction: column; }

.chat-log {
  max-height: 340px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { display: flex; gap: 9px; max-width: 92%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  flex: 0 0 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  background: var(--brand-soft);
  color: var(--brand);
}

.msg.user .avatar { background: #e8f5ec; color: var(--ok); }

.bubble {
  padding: 9px 13px;
  border-radius: 11px;
  background: #f6f7fb;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .bubble { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  align-items: flex-end;
}

.chat-input-row textarea { min-height: 42px; max-height: 120px; resize: none; }

/* ---------------------------------------------------------------- 弹窗 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(22, 26, 42, .48);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 24px;
  backdrop-filter: blur(2px);
}

.modal-mask.on { display: flex; }

.modal {
  background: #fff;
  border-radius: 14px;
  width: min(760px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: pop .16s ease-out;
}

@keyframes pop { from { transform: scale(.97); opacity: 0; } }

.modal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.modal-head .spacer { flex: 1; }
.modal-body { padding: 18px; overflow: auto; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
}

.icon-btn {
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--text-3);
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
}

.icon-btn:hover { background: #f2f3f8; color: var(--text); }

pre.code {
  margin: 0;
  padding: 14px;
  background: #fbfbfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 52vh;
  overflow: auto;
  color: var(--text-2);
}

/* ---------------------------------------------------------------- 提示条 */
.toast-wrap {
  position: fixed;
  top: 74px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
}

.toast {
  padding: 10px 16px;
  border-radius: 9px;
  background: #2b3040;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slide .2s ease-out;
  max-width: 360px;
}

.toast.ok { background: #16653a; }
.toast.err { background: #a52222; }
.toast.warn { background: #8a5309; }

@keyframes slide { from { transform: translateX(20px); opacity: 0; } }

/* ---------------------------------------------------------------- 状态点 */
.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  margin-right: 5px;
}

.dot.off { background: var(--warn); }

/* ---------------------------------------------------------------- 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #d6d9e6; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b9bed2; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------- 响应式 */
@media (max-width: 1180px) {
  .workbench { grid-template-columns: 340px minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .workbench { grid-template-columns: 1fr; padding: 12px; }
  .result-body { max-height: none; }
  .topbar { padding: 0 14px; gap: 8px; }
  .brand { font-size: 15px; }
}
