/* 批量链式生图（/batch-chain.html）专属样式。
   独立成文件，公共 styles.css 一个字不改，为的是：
   1. 完全不影响旧的批量队列页面和其他任何页面；
   2. 这个新页面要单独上下线时，不需要动任何公共文件。
   说明：下面出现的 .batch-queue-panel 只是复用 styles.css 里的公共布局类，并非与旧页面耦合。 */

.batch-queue-panel.chain-panel {
  grid-template-rows: auto auto 1fr auto;
}

.chain-prompt-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.6;
}

.chain-volume-hint {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(103, 232, 249, .26);
  border-radius: 8px;
  background: rgba(103, 232, 249, .07);
  color: #d3ecf5;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.6;
}

/* ---------- 工具栏 ---------- */

.chain-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 0 2px;
}

.chain-toolbar-hint {
  flex: 1 1 220px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
}

.chain-toolbar button {
  height: 34px;
  min-width: 92px;
  padding: 0 12px;
  font-size: 13px;
}

.chain-toolbar-spacer {
  flex: 1 1 auto;
}

.chain-toolbar-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.chain-toolbar-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--cyan);
  cursor: pointer;
}

/* 有勾选时这个按钮要跳出来，所以给它一点强调色。 */
.chain-regen-button:not(:disabled) {
  border-color: rgba(103, 232, 249, .45);
  background: rgba(103, 232, 249, .12);
  color: var(--cyan);
}

/* ---------- 文件夹分组（一级折叠） ---------- */

.chain-group {
  border: 1px solid rgba(170, 197, 218, .16);
  border-radius: 8px;
  background: rgba(8, 15, 27, .58);
  overflow: hidden;
}

.chain-group.running {
  border-color: rgba(103, 232, 249, .46);
  background: rgba(103, 232, 249, .08);
}

.chain-group.done {
  border-color: rgba(52, 211, 153, .38);
}

.chain-group.failed {
  border-color: rgba(251, 113, 133, .38);
}

.chain-group-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
  color: #e4f5fb;
  font-size: 13px;
  font-weight: 600;
}

.chain-group-head::-webkit-details-marker {
  display: none;
}

.chain-group-head::before {
  content: "▸";
  flex: 0 0 auto;
  color: var(--cyan);
  font-size: 12px;
  transition: transform .15s ease;
}

.chain-group[open] > .chain-group-head::before {
  transform: rotate(90deg);
}

.chain-group-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chain-group-meta {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.chain-group-state {
  flex: 0 0 auto;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 600;
}

.chain-group-body {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

/* ---------- 组内各区域（二级折叠） ---------- */

.chain-sub {
  border: 1px solid rgba(170, 197, 218, .14);
  border-radius: 8px;
  background: rgba(8, 15, 27, .5);
}

.chain-sub > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  list-style: none;
  color: #cfe2eb;
  font-size: 12px;
  font-weight: 600;
}

.chain-sub > summary::-webkit-details-marker {
  display: none;
}

.chain-sub > summary::before {
  content: "▸";
  flex: 0 0 auto;
  color: var(--green);
  font-size: 11px;
  transition: transform .15s ease;
}

.chain-sub[open] > summary::before {
  transform: rotate(90deg);
}

.chain-sub > summary em {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-style: normal;
  font-weight: 500;
}

/* 折叠块正文统一缩进。
   注意必须是 ~ 而不是 + ：一个折叠块里可能有多个子块（图片网格 + 按钮行），
   + 只给紧跟在 summary 后的第一个元素加边距，第二个就会贴着盒子底边、看起来被压线。 */
.chain-sub > summary ~ * {
  margin: 0 10px 10px;
}

.chain-sub > summary ~ * + * {
  margin-top: 10px;
}

.chain-prompt-editor {
  display: grid;
  gap: 10px;
}

.chain-prompt-field {
  display: grid;
  gap: 6px;
}

.chain-prompt-field > span {
  color: #d4e5ed;
  font-size: 12px;
  font-weight: 600;
}

.chain-prompt-field textarea {
  min-height: 110px;
  font-size: 13px;
  line-height: 1.6;
}

/* ---------- 图片网格与生成槽位 ---------- */

.chain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
}

.chain-source-grid {
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
}

.chain-source-item {
  position: relative; /* 勾选框要绝对定位到右上角 */
  margin: 0;
  display: grid;
  gap: 4px;
  cursor: pointer;
}

.chain-source-pick {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: rgba(8, 16, 29, .8);
  opacity: .35;
  transition: opacity .15s ease;
}

.chain-source-item:hover .chain-source-pick,
.chain-source-item.picked .chain-source-pick {
  opacity: 1;
}

.chain-source-pick input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--cyan);
  cursor: pointer;
}

.chain-source-item.picked img {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

/* 这两个按钮在折叠块内部：展开才看得到，收起自动隐藏。 */
.chain-source-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.chain-source-actions button {
  flex: 0 1 auto;
  min-width: 108px;
  height: 34px;
  padding: 0 14px;
  font-size: 13px;
}

.chain-source-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  border: 1px solid rgba(170, 197, 218, .18);
  border-radius: 8px;
  background: #08101d;
}

.chain-source-item figcaption {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chain-media {
  display: grid;
  gap: 10px;
}

.chain-media-row {
  display: grid;
  gap: 6px;
}

/* 成对排列：每对是一个小盒子，里面左边第一张图、右边第二张图，一眼看出对应关系。 */
.chain-pairs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chain-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(103, 232, 249, .18);
  border-radius: 10px;
  background: rgba(103, 232, 249, .04);
}

.chain-pair .chain-slot {
  width: 60px;
}

.chain-media-name {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chain-slot {
  position: relative; /* 勾选框要绝对定位到右上角 */
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  margin: 0;
  padding: 4px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(170, 197, 218, .18);
  border-radius: 8px;
  background: #08101d;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  cursor: pointer;
}

/* 勾选框：平时半透明，鼠标移到图上才完全显现，避免干扰看图。 */
.chain-slot-pick {
  position: absolute;
  top: 2px;
  right: 2px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: rgba(8, 16, 29, .8);
  opacity: .35;
  transition: opacity .15s ease;
}

.chain-slot:hover .chain-slot-pick,
.chain-slot.picked .chain-slot-pick {
  opacity: 1;
}

.chain-slot-pick input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--cyan);
  cursor: pointer;
}

/* 被勾选的槽位加一圈描边，方便一眼看出选了哪些。 */
.chain-slot.picked {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

.chain-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 4px;
}

.chain-slot.running {
  border-color: rgba(103, 232, 249, .5);
  background: rgba(103, 232, 249, .1);
  color: var(--cyan);
}

.chain-slot.done {
  padding: 0;
  border-color: rgba(52, 211, 153, .42);
}

.chain-slot.failed {
  border-color: rgba(251, 113, 133, .45);
  background: rgba(60, 11, 24, .38);
  color: var(--danger);
}

.chain-slot.skipped {
  opacity: .5;
}

.chain-empty {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

@media (max-width: 760px) {
  .chain-group-head {
    flex-wrap: wrap;
  }

  .chain-group-name {
    flex: 1 1 100%;
  }
}

/* ---------- 运行日志 ---------- */

/* 失败原因要能直接被看到，不用去猜、也不用悬停在图上找提示。 */
.chain-log {
  border: 1px solid rgba(170, 197, 218, .16);
  border-radius: 8px;
  background: rgba(8, 15, 27, .5);
  max-height: 280px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  overflow: hidden;
}

.chain-log > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  list-style: none;
  color: #cfe2eb;
  font-size: 12px;
  font-weight: 600;
}

.chain-log > summary::-webkit-details-marker {
  display: none;
}

.chain-log > summary::before {
  content: "▸";
  flex: 0 0 auto;
  color: #a78bfa;
  font-size: 11px;
  transition: transform .15s ease;
}

.chain-log[open] > summary::before {
  transform: rotate(90deg);
}

.chain-log > summary em {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-style: normal;
  font-weight: 500;
}

.chain-log-actions {
  display: flex;
  gap: 8px;
  padding: 0 10px 8px;
}

.chain-log-actions button {
  height: 30px;
  min-width: 88px;
  padding: 0 10px;
  font-size: 12px;
}

.chain-log-list {
  overflow: auto;
  padding: 0 10px 10px;
  display: grid;
  gap: 4px;
  align-content: start;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
  line-height: 1.5;
}

.chain-log-entry {
  margin: 0;
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.chain-log-time {
  flex: 0 0 auto;
  color: var(--muted);
}

.chain-log-level {
  flex: 0 0 auto;
  font-weight: 600;
}

.chain-log-text {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #cfe2eb;
}

.chain-log-count {
  flex: 0 0 auto;
  color: var(--muted);
}

.chain-log-entry.error .chain-log-level {
  color: var(--danger);
}

.chain-log-entry.error .chain-log-text {
  color: #ffd7de;
}

.chain-log-entry.warn .chain-log-level {
  color: #fbbf24;
}

.chain-log-entry.info .chain-log-level {
  color: var(--cyan);
}

.chain-log-empty {
  margin: 0;
  color: var(--muted);
}
