/* ======================================================================
   /ai 第三列顶部上传行 + 添加参考图片弹窗
   样式原样取自 pro.css（/pro 批量工作台），保证与 /pro 页面像素一致。
   ====================================================================== */

/* 外层卡片（与 /pro .batch-section 一致） */
.ai-top-upload-section {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

/* 上传区域（弹窗内大按钮用） */
.batch-upload-area {
    border: 2px dashed #ced4da;
    border-radius: 6px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafbfc;
}
.batch-upload-area:hover { border-color: #0d6efd; background: #e7f1ff; }

/* 正方形上传区域（产品图片） */
.batch-upload-square {
    position: relative;
    aspect-ratio: 1;
    border: 2px dashed #ced4da;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafbfc;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.batch-upload-square:hover { border-color: #0d6efd; background: #e7f1ff; }
.batch-upload-placeholder {
    text-align: center;
    padding: 10px;
}
.batch-upload-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

/* 顶部两列布局：产品图片 + 参考图区域（固定高度，不随内容变化） */
.batch-top-row {
    align-items: stretch !important;
    height: 160px;
    flex-shrink: 0;
    overflow: hidden;
}

/* 产品图/参考图左侧竖排名称 */
.batch-img-label {
    writing-mode: vertical-rl;
    text-orientation: upright;
    font-size: 0.55rem;
    font-weight: 600;
    color: #495057;
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 16px;
    padding: 4px 0;
}

/* 左侧：产品图片上传（160x160 正方形） */
.batch-product-col {
    width: 160px;
    min-width: 160px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

/* 左侧上传区域：与整行 160px 严格等高，不再依赖父容器高度与 aspect-ratio */
.batch-product-col .batch-upload-square {
    width: 100%;
    height: 160px;
    flex: 0 0 160px;
    min-height: 0;
    min-width: 0;
    aspect-ratio: auto;
    box-sizing: border-box;
}

/* 右侧：参考图区域（虚线边框，按钮默认居中） */
.batch-ref-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* 与产品图框严格等高，保证两个虚线框高度一致、上下对齐 */
    height: 160px;
    box-sizing: border-box;
    border: 2px dashed #ced4da;
    border-radius: 6px;
    background: #fafbfc;
    overflow: hidden;
}

/* 按钮：默认在框内居中 */
.batch-ref-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* 无参考图时：单个添加按钮（正方形） */
.batch-ref-add-single {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100px;
    height: 100px;
    flex-shrink: 0;
    box-sizing: border-box;
    font-size: 0.7rem;
    padding: 10px;
    border-radius: 8px;
    border: 2px dashed #ced4da;
    background: #fafbfc;
    color: #495057;
    cursor: pointer;
    transition: all 0.2s;
}
.batch-ref-add-single:hover {
    border-color: #0d6efd;
    background: #e7f1ff;
    color: #0d6efd;
}
.batch-ref-add-single i {
    font-size: 1.4rem;
    line-height: 1;
}
.batch-ref-add-single span {
    font-size: 0.6rem;
    line-height: 1.2;
}

/* 有参考图时：隐藏按钮，显示参考图网格 */
.batch-top-row.has-images .batch-ref-actions {
    display: none;
}

.batch-top-row.has-images .batch-ref-col {
    align-items: stretch;
    justify-content: flex-start;
    border: none;
    background: none;
}

.batch-top-row.has-images .batch-ref-grid {
    flex: 1;
    /* 与产品图框严格等高，保证两个虚线框高度一致、上下对齐 */
    height: 160px;
    box-sizing: border-box;
    border: 2px dashed #ced4da;
    border-radius: 6px;
    background: #fafbfc;
}

/* 参考图网格：水平一行，左右滑动（与 /pro 顶行有效样式一致） */
.batch-ref-grid {
    display: none;
    gap: 5px;
    height: 100%;
    min-height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    align-items: center;
    padding: 4px;
}

.batch-top-row.has-images .batch-ref-grid {
    display: flex;
}
.batch-ref-grid .batch-ref-cell {
    width: 120px;
    height: 120px;
    flex-shrink: 0;
    min-height: 0;
    min-width: 0;
}
.batch-ref-grid .batch-ref-cell img {
    width: 100%;
    height: 100%;
    object-fit: contain !important;
    display: block;
}
.batch-ref-cell {
    position: relative;
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid #e9ecef;
    background: #f8f9fa;
}
.batch-ref-cell .ref-delete {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}
.batch-ref-cell:hover .ref-delete { opacity: 1; }
.batch-ref-cell .ref-delete:hover { background: #dc3545; }
.batch-ref-cell .ref-index {
    position: absolute;
    bottom: 2px;
    left: 3px;
    font-size: 0.55rem;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

/* 参考图末尾的+按钮 */
.batch-ref-add-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 100%;
    width: 100px;
    min-width: 100px;
    box-sizing: border-box;
    border: 2px dashed #ced4da;
    border-radius: 6px;
    background: #fafbfc;
    cursor: pointer;
    transition: all 0.2s;
    color: #6c757d;
    flex-shrink: 0;
}
.batch-ref-add-btn:hover {
    border-color: #0d6efd;
    background: #e7f1ff;
    color: #0d6efd;
}
.batch-ref-add-btn i {
    font-size: 1.5rem;
    line-height: 1;
}
.batch-ref-add-btn span {
    font-size: 0.6rem;
    line-height: 1.2;
}

/* 按工具上传配置控制显隐（/ai 特有：count==1 只显示产品图，count<=0 整行隐藏） */
.batch-top-row.no-ref .batch-ref-col { display: none; }
.batch-top-row.no-upload { display: none; }

/* 开始设计按钮：常驻第三列底部（对应 /pro 的"开始批量生成"位置），不随结果滚动 */
.ai-generate-bar {
    margin-top: 8px;
    margin-bottom: 0;
    flex-shrink: 0;
}

/* ==================== 产品图悬停操作条（浮动在图片上层，不改变图片尺寸） ==================== */

.product-hover-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 40px;
    display: flex;
    z-index: 3;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    border-radius: 0 0 4px 4px;
    overflow: hidden;
}

/* 仅已上传（has-image）且悬停时浮现 */
.batch-upload-square.has-image:hover .product-hover-bar {
    opacity: 1;
    visibility: visible;
}

/* 操作条按钮：各约占一半宽度（约 80x40px），点击目标大 */
.product-bar-btn {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border: none;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 0.65rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    transition: background 0.15s;
}
.product-bar-btn + .product-bar-btn {
    border-left: 1px solid rgba(255, 255, 255, 0.25);
}
.product-bar-btn i {
    font-size: 0.85rem;
}
.product-bar-btn:hover {
    background: rgba(13, 110, 253, 0.85);
}
.product-bar-btn.product-bar-btn-danger:hover {
    background: rgba(220, 53, 69, 0.9);
}

/* ==================== 添加参考图片弹窗（与 /pro 一致） ==================== */

/* 添加参考图片弹窗 - 固定大小 */
#addRefModal .modal-dialog {
    width: 720px;
    max-width: 90vw;
    margin: 1.75rem auto;
}
#addRefModal .modal-content {
    width: 720px;
    max-width: 90vw;
    height: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}
#addRefModal .modal-body {
    padding: 0;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
#addRefModal .modal-footer {
    flex-shrink: 0;
}
#addRefModal .nav-tabs {
    border-bottom: 1px solid #e9ecef;
    padding: 8px 12px 0;
}
#addRefModal .nav-link {
    font-size: 0.75rem;
    padding: 6px 12px;
    color: #6c757d;
    border: none;
    border-bottom: 2px solid transparent;
}
#addRefModal .nav-link.active {
    color: #0d6efd;
    border-bottom-color: #0d6efd;
    font-weight: 600;
}
#addRefModal .tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    min-height: 0;
}
#addRefModal .tab-pane {
    min-height: 100%;
}
#modalGalleryCategories .btn {
    font-size: 0.6rem;
    padding: 3px 8px;
}

/* 图库图片已选标识 */
.gallery-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background: #198754;
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    z-index: 2;
}

/* 模板已选标识 */
.template-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background: #198754;
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    z-index: 2;
}

/* 弹窗内图片比例修复 */
/* 图库图片：直接子元素 img，填满卡片 */
#modalGalleryList .batch-picker-card > img {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 !important;
    object-fit: cover !important;
    border-radius: 4px !important;
}

/* 模板缩略图：嵌套在 .d-flex 容器内，固定 28x28 */
#modalSystemTemplateList .batch-picker-card .d-flex img,
#modalUserTemplateList .batch-picker-card .d-flex img {
    width: 28px !important;
    height: 28px !important;
    max-width: 28px !important;
    max-height: 28px !important;
    flex-shrink: 0 !important;
    object-fit: cover !important;
    border-radius: 3px !important;
}

/* 所有弹窗卡片：防止内容溢出 */
#modalGalleryList .batch-picker-card,
#modalSystemTemplateList .batch-picker-card,
#modalUserTemplateList .batch-picker-card {
    overflow: hidden !important;
}

/* 弹窗内模板卡片样式 */
#modalSystemTemplateList .batch-picker-card,
#modalUserTemplateList .batch-picker-card {
    padding: 6px;
    margin-bottom: 6px;
}
#modalSystemTemplateList .batch-picker-card .small,
#modalUserTemplateList .batch-picker-card .small {
    font-size: 0.65rem;
}
#modalSystemTemplateList .batch-picker-card .xs,
#modalUserTemplateList .batch-picker-card .xs {
    font-size: 0.55rem;
}
#modalSystemTemplateList .batch-picker-card .thumb-row,
#modalUserTemplateList .batch-picker-card .thumb-row {
    margin-top: 4px;
}
#modalSystemTemplateList .batch-picker-card .thumb-row img,
#modalUserTemplateList .batch-picker-card .thumb-row img {
    width: 28px !important;
    height: 28px !important;
    object-fit: cover !important;
    border-radius: 3px !important;
}

/* 模板选择弹窗卡片 */
.batch-picker-card {
    border: 2px solid #e9ecef;
    border-radius: 6px;
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: #fff;
    height: 100%;
    overflow: hidden;
}
.batch-picker-card:hover { border-color: #0d6efd; }
.batch-picker-card.selected { border-color: #0d6efd; background: #e7f1ff; }
