/* ============================================================
   UI 修复包 021400：
   1) AI 润色按钮重设计（暗色玻璃质感，右对齐）
   2) 生图记录右栏自适应（sticky + 内部滚动）
   3) 图片编辑菜单网格
   4) 反推提示词板块结构重构
   ============================================================ */

/* ---------- 1) AI 润色按钮 ---------- */
.prompt-polish-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin: 2px 0 14px;
}

.polish-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px 8px 13px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.035));
  border: 1px solid var(--border, var(--line, rgba(255, 255, 255, 0.14)));
  border-radius: 12px;
  cursor: pointer;
  transition: 200ms cubic-bezier(0.2, 0.7, 0.3, 1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.polish-btn svg {
  color: #D99A2B;
  flex: none;
}

.polish-btn:hover:not(:disabled) {
  border-color: rgba(217, 154, 43, 0.55);
  background: rgba(217, 154, 43, 0.12);
  transform: translateY(-1px);
}

.polish-btn:active:not(:disabled) { transform: translateY(0); }
.polish-btn:disabled { opacity: 0.55; cursor: progress; transform: none; }
.polish-btn.is-loading svg { animation: polish-spin 900ms linear infinite; }

@keyframes polish-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.polish-hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted, #8A837A);
  text-align: right;
}

@media (max-width: 640px) {
  .prompt-polish-bar { flex-wrap: wrap; }
  .polish-hint { flex-basis: 100%; text-align: left; }
}

/* ---------- 2) 生图记录右栏自适应 ---------- */
@media (min-width: 1101px) {
  /* 左侧大图预览区必须 stretch 占满列高，否则 result-preview 内容（img absolute 脱离流）塌陷到 50px */
  .result-content-layout { align-items: stretch; }
  .recent-records-panel {
    align-self: start;
    position: sticky;
    top: 16px;
    height: auto;
    max-height: calc(100vh - 170px);
  }
  .asset-strip { max-height: calc(100vh - 252px); }
}

/* ---------- 参考图多图预览塌陷修复 ---------- */
.reference-preview:not(.empty) {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 10px;
  padding: 12px 12px 16px;
  min-height: 120px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.reference-preview:not(.empty)::-webkit-scrollbar { height: 6px; }
.reference-preview:not(.empty)::-webkit-scrollbar-track { background: rgba(255,255,255,0.06); border-radius: 999px; }
.reference-preview:not(.empty)::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.22); border-radius: 999px; }
.reference-preview .reference-thumb {
  position: relative;
  width: 88px;
  height: 88px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.2);
  flex: 0 0 auto;
}
.reference-preview .reference-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  padding: 0;
}
.reference-preview .reference-clear-btn {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(127,29,29,0.78);
  color: #fecdd3;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

/* ---------- 3) 图片编辑菜单 ---------- */
.ps-upload-label { cursor: pointer; }

.ps-studio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  min-height: 220px;
  max-height: calc(100vh - 320px);
  overflow-y: auto;
  padding-right: 4px;
}

.ps-studio-grid .empty-state { grid-column: 1 / -1; }
.ps-studio-grid .record-card { height: auto; }
.ps-studio-grid .record-image { height: 150px; }
.ps-studio-grid .record-body p { display: none; }

/* ---------- 4) 反推提示词结构重构 ---------- */
.reverse-layout {
  display: grid;
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}

.reverse-input-panel {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

.reverse-result-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

.reverse-result-content {
  display: grid;
  gap: 14px;
}

.reverse-result-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 15px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  border-radius: 16px;
}

.reverse-result-section:first-child {
  background: linear-gradient(180deg, rgba(217, 154, 43, 0.10), rgba(217, 154, 43, 0.03));
  border-color: rgba(217, 154, 43, 0.38);
}

.reverse-result-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.reverse-result-label > span {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #D99A2B;
}

.reverse-copy-btn {
  padding: 5px 12px !important;
  font-size: 12px !important;
  border-radius: 999px !important;
}

.reverse-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.75;
  resize: vertical;
  font-family: inherit;
}

.reverse-textarea:focus {
  outline: none;
  border-color: rgba(217, 154, 43, 0.55);
  box-shadow: 0 0 0 3px rgba(217, 154, 43, 0.14);
}

#reversePromptResult { min-height: 128px; }
#reverseNegativeResult { min-height: 68px; }

.reverse-tags-list { display: flex; flex-wrap: wrap; gap: 8px; }

.reverse-tags-list > * {
  padding: 5px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
}

.reverse-description {
  color: var(--muted, #8A837A);
  font-size: 13px;
  line-height: 1.7;
}

.reverse-result-meta { color: var(--muted, #8A837A); font-size: 12px; }

.reverse-result-actions { display: flex; }

.reverse-result-actions .primary-btn {
  width: 100%;
  justify-content: center;
  padding: 12px 16px;
  font-size: 14px;
}

.reverse-history-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 150px;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.reverse-history-grid > * { min-height: 120px; }

@media (max-width: 900px) {
  .reverse-layout { grid-template-columns: 1fr; }
  .reverse-input-panel { position: static; }
}
