/**
 * AI 工作台 /ai — 独立样式，前缀 aiw-，与全站共用 CSS 变量
 */

/* —— 顶栏 TAB（宽度与全站内容区一致）—— */
.aiw-strip {
  width: 100%;
  background: var(--vs-color-bg-body);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.aiw-strip__frame {
  max-width: var(--vs-container-max-width, 1200px);
  margin: 0 auto;
  padding: 0;
  box-sizing: border-box;
}

.aiw-strip__tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--vs-color-border);
  border-radius: 6px;
  background: var(--vs-color-bg-body);
  overflow: hidden;
}

.aiw-tab {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 10px 8px;
  border: none;
  border-right: 1px solid var(--vs-color-border);
  border-radius: 0;
  background: var(--vs-color-bg-body);
  color: var(--vs-color-text-primary);
  font: inherit;
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.aiw-tab:last-child {
  border-right: none;
}

.aiw-tab:hover {
  background: var(--vs-color-bg-lighter);
  color: var(--vs-video-color-primary);
}

.aiw-tab.is-active {
  background: transparent;
  color: var(--vs-video-color-primary);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(255, 204, 204, 0.28);
  border: 2px solid var(--vs-video-color-primary);
  margin: -1px;
  position: relative;
  z-index: 1;
}

.aiw-tab__sub {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.5);
}

.aiw-tab.is-active .aiw-tab__sub {
  color: rgba(255, 255, 255, 0.55);
}

/* —— 主内容 —— */
.aiw {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 12px 32px;
  box-sizing: border-box;
}

@media (min-width: 900px) {
  .aiw {
    max-width: 840px;
    padding: 20px 16px 40px;
  }
}

.aiw-notice {
  margin: 0 0 20px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
  color: rgba(255, 200, 120, 0.95);
  background: rgba(255, 180, 80, 0.08);
  border: 1px solid rgba(255, 200, 120, 0.22);
  border-radius: 8px;
}

.aiw-panel[hidden] {
  display: none !important;
}

/* 上传区两列布局：左输入框、右要求说明 */
.aiw-upload-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 12px;
}

.aiw-upload-col {
  flex: 0 0 220px;
  max-width: 220px;
}

.aiw-upload-rule {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 5px 0;
  font-size: 13px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.62);
}

.aiw-upload-rule__title {
  margin: 0 0 5px;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.84);
}

.aiw-upload-rule__list {
  margin: 0;
  padding: 0 0 0 16px;
}

.aiw-upload-rule__list li {
  margin: 0;
  padding: 0;
  line-height: 1.3;
}

.aiw-upload-rule__list li + li {
  margin-top: 2px;
}

/* 正方形上传区：预览 object-fit: contain 完整显示不拉伸 */
.aiw-slot {
  margin: 0;
  width: 100%;
}

/*
 * 正方形区域：不用 aspect-ratio 做主方案。
 * 部分安卓 WebView 对 aspect-ratio 支持有 bug，且会与 min-height:0 叠加导致高度塌陷（只剩虚线框）。
 * padding-bottom: 100% 相对宽度计算高度，兼容面更好。
 */
.aiw-slot__frame {
  position: relative;
  display: block;
  width: 100%;
  height: 0;
  padding-bottom: 100%;
  border: 2px dashed var(--vs-color-border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
  cursor: pointer;
  overflow: hidden;
  box-sizing: border-box;
}

.aiw-slot__frame:focus-within {
  border-color: var(--vs-video-color-primary);
  outline: none;
}

.aiw-slot__placeholder {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  box-sizing: border-box;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  color: #10f0bf;
  text-shadow: 0 0 12px rgba(16, 240, 191, 0.35);
  pointer-events: none;
  z-index: 0;
}

.aiw-slot.has-file .aiw-slot__placeholder {
  display: none;
}

.aiw-slot .aiw-file {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.aiw-slot__img {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: none;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1;
}

.aiw-slot.has-file .aiw-slot__img {
  display: block;
}

@media (max-width: 768px) {
  .aiw-upload-row {
    display: block;
  }

  .aiw-upload-col {
    max-width: none;
    width: 100%;
  }

  .aiw-upload-rule {
    margin-top: 2px;
    padding: 2px 0;
  }
}

.aiw-field {
  display: block;
  margin: 14px 0 6px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.85);
}

/* —— 模板网格：PC / 移动列宽 —— */
.aiw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
}

@media (min-width: 480px) {
  .aiw-grid {
    grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
    gap: 12px;
  }
}

@media (min-width: 900px) {
  .aiw-grid {
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  }
}

/* —— 模板项：与上传区一致，正方形用 padding 技巧（避免旧 WebView aspect-ratio 问题）—— */
.aiw-tpl {
  position: relative;
  margin: 0;
  border: 2px solid transparent;
  border-radius: 10px;
  box-sizing: border-box;
}

.aiw-tpl.is-selected {
  border-color: #10f0bf;
}

.aiw-tpl__radio {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.aiw-tpl__hit {
  display: block;
  margin: 0;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.25);
}

.aiw-tpl__square {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 100%;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
  box-sizing: border-box;
}

.aiw-tpl__square-inner {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
}

.aiw-tpl__media {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  -o-object-fit: contain;
  object-fit: contain;
  -o-object-position: center;
  object-position: center;
}

.aiw-tpl__media--video {
  background: #000;
  pointer-events: none;
}

.aiw-tpl__missing {
  padding: 8px;
  font-size: 10px;
  line-height: 1.35;
  text-align: center;
  color: rgba(255, 255, 255, 0.45);
}

.aiw-tpl__missing small {
  display: block;
  margin-top: 4px;
  font-size: 9px;
  color: rgba(16, 240, 191, 0.5);
  word-break: break-all;
}

.aiw-tpl__cap {
  display: block;
  padding: 5px 4px 6px;
  font-size: 11px;
  text-align: center;
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.25;
}

/* 放大：在 label 外，避免嵌套 button 与 label 冲突 */
.aiw-tpl__zoom {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 6;
  width: 30px;
  height: 30px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.aiw-tpl__zoom:hover,
.aiw-tpl__zoom:focus {
  background: rgba(16, 240, 191, 0.35);
  outline: none;
}

.aiw-tpl__zoom-ico {
  display: block;
  width: 14px;
  height: 14px;
  margin: 8px auto;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  box-sizing: border-box;
  position: relative;
}

.aiw-tpl__zoom-ico::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 2px;
  background: rgba(255, 255, 255, 0.92);
  right: -4px;
  bottom: -1px;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
  border-radius: 1px;
}

.aiw-tpl--prompt .aiw-tpl__hit {
  padding: 10px 10px 8px;
}

.aiw-tpl__prompt-title {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 6px;
}

.aiw-tpl__prompt-body {
  font-size: 11px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.78);
  max-height: 5.8em;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* —— 全屏灯箱（图片 / 视频 / 提示词）；需高于全站 fixed 顶栏/Tab，建议由 JS 挂到 body —— */
.aiw-lb {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 200000;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

.aiw-lb.is-open {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

.aiw-lb__backdrop {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.88);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.aiw-lb__panel {
  position: relative;
  z-index: 1;
  width: 48%;
  width: 48vw;
  min-width: 220px;
  max-width: 560px;
  max-height: 46vh;
  margin: 0;
  padding: 8px 8px 12px;
  box-sizing: border-box;
  text-align: center;
}

.aiw-lb__close {
  position: absolute;
  top: -4px;
  right: -4px;
  z-index: 2;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.aiw-lb__close:hover,
.aiw-lb__close:focus {
  background: rgba(16, 240, 191, 0.4);
  outline: none;
}

.aiw-lb__stage {
  width: 100%;
  max-width: 520px;
  max-height: 39vh;
  margin: 0 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.aiw-lb__img {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
  max-height: 39vh;
  margin: 0 auto;
  -o-object-fit: contain;
  object-fit: contain;
}

.aiw-lb__video {
  display: block;
  max-width: 100%;
  width: 100%;
  max-height: 39vh;
  height: auto;
  margin: 0 auto;
  background: #000;
}

.aiw-lb__text {
  margin: 0;
  padding: 12px 14px;
  max-height: 35vh;
  overflow: auto;
  font-size: 14px;
  line-height: 1.55;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  font-family: inherit;
}

.aiw-lb__title {
  margin: 10px 0 0;
  padding: 0 8px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.65);
}

body.aiw-lb-open {
  overflow: hidden;
}

/* —— AI 详情页：与制作页同组件，只读无 radio —— */
.aiw-detail-header {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  -webkit-box-align: start;
  -ms-flex-align: start;
  align-items: flex-start;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.aiw-detail-header .vs-user-page-title {
  margin: 0;
  padding: 0;
  -webkit-box-flex: 1;
  -ms-flex: 1 1 200px;
  flex: 1 1 200px;
  min-width: 0;
  text-align: left;
}

.aiw-detail-header .vs-user-btn-link {
  -ms-flex-negative: 0;
  flex-shrink: 0;
}

.aiw-detail-page .aiw-tpl--readonly .aiw-tpl__hit {
  cursor: default;
}

.aiw-detail-page .aiw-tpl--readonly .aiw-tpl__radio {
  display: none;
}

.aiw-detail-user,
.aiw-detail-template-single {
  max-width: 280px;
  margin: 0 auto;
}

@media (min-width: 480px) {
  .aiw-detail-user,
  .aiw-detail-template-single {
    max-width: 320px;
  }
}

/* 结果区：flex 兜底旧浏览器，支持 grid 时用网格 */
.aiw-detail-results {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  margin: -6px;
}

.aiw-detail-result-cell {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-box-flex: 1;
  -ms-flex: 1 1 104px;
  flex: 1 1 104px;
  min-width: 96px;
  max-width: 168px;
  padding: 6px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: stretch;
  -ms-flex-align: stretch;
  align-items: stretch;
}

.aiw-detail-result-cell .vs-user-btn {
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  margin-top: 8px;
}

@supports (display: grid) {
  .aiw-detail-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 12px;
    margin: 0;
  }

  .aiw-detail-result-cell {
    -webkit-box-flex: initial;
    -ms-flex: initial;
    flex: initial;
    min-width: 0;
    max-width: none;
    padding: 0;
  }
}

@media (min-width: 480px) {
  @supports (display: grid) {
    .aiw-detail-results {
      grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
    }
  }
}

@media (min-width: 900px) {
  @supports (display: grid) {
    .aiw-detail-results {
      grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    }
  }
}

.aiw-preview {
  display: none;
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  font-size: 13px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.82);
  white-space: pre-wrap;
}

.aiw-preview.is-visible {
  display: block;
}

.aiw-submit {
  margin-top: 20px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: #10f0bf;
  color: #111;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}

/* 仅「提交中」禁用；未选齐模板/图片时仍可点，提交时再提示 */
.aiw-submit:disabled {
  opacity: 0.5;
  cursor: wait;
}

.aiw-submit:not(.is-ready):not(.is-loading) {
  opacity: 0.92;
}

.aiw-error {
  display: none;
  margin-top: 12px;
  font-size: 14px;
  color: #f88;
}

.aiw-error.is-visible {
  display: block;
}

.aiw-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 24px;
  padding-top: 12px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.55);
}

.aiw-footer__meta strong {
  color: #10f0bf;
  font-weight: 600;
}

.aiw-footer__sep {
  color: rgba(255, 255, 255, 0.22);
  user-select: none;
}

.aiw-footer a {
  color: rgba(255, 255, 255, 0.5);
  text-decoration: none;
}

.aiw-footer a:hover {
  color: var(--vs-video-color-primary, #ffcccc);
}
