/* =========================================
   1. 基础组件 (按钮、调试徽章)
   ========================================= */
.ai-custom-btn { 
    background: linear-gradient(45deg, #ff9a9e, #fad0c4); 
    border: none; color: #fff; padding: 12px 25px; border-radius: 25px; 
    cursor: pointer; margin-top: 15px; width: 100%; font-weight: bold; font-size: 16px; transition: transform 0.2s;
}
.ai-custom-btn:hover { transform: scale(1.02); }

.ai-debug-badge { 
    background:#fff3cd; color:#856404; padding:5px; font-size:12px; border:1px solid #ffeeba; margin-bottom:5px; text-align:center; 
}

/* =========================================
   2. 弹窗 Modal 样式
   ========================================= */
.ai-modal { 
    display:none; position:fixed; z-index:99999; left:0; top:0; width:100%; height:100%; 
    background-color:rgba(0,0,0,0.6); backdrop-filter: blur(5px); 
}
.ai-modal-content { 
    background-color:#fff; margin:0; padding:22px; border-radius:12px; 
    width:min(92vw, 1040px); max-height:calc(100vh - 64px);
    display:flex; align-items:center; gap:24px; overflow: hidden; position: absolute;
    top:50%; left:50%; transform:translate(-50%, -50%);
}

/* 弹窗两栏布局 */
.ai-col { flex:1; min-width:0; display: flex; flex-direction: column; justify-content:center; }
.ai-col h3,
.ai-col h4 { flex:0 0 auto; }

/* 图片预览区 */
.ai-img-wrapper { 
    position: relative; width: 100%; aspect-ratio: 1 / 1; 
    background: #f9f9f9; border-radius: 8px; overflow: hidden; 
    display: flex; align-items: center; justify-content: center; 
}
.ai-preview-img { max-width: 100%; max-height: 100%; object-fit: contain; transition: opacity 0.3s; }

/* =========================================
   3. 表单与交互元素
   ========================================= */
#aiPrompt { 
    width: 100%; padding: 12px; height:100px; border: 1px solid #ddd; 
    border-radius: 8px; font-family: inherit; resize: none; margin-bottom: 5px; 
}
.ai-limit-text { display:block; font-size: 12px; color: #888; margin-bottom: 15px; }

/* 聊天气泡 & 标签 */
.ai-chat-bubble { 
    background: #f0f9eb; border: 1px solid #c2e7b0; color: #3c763d; 
    padding: 12px; border-radius: 8px; margin-bottom: 15px; display: none; 
    font-size: 14px; line-height: 1.5; 
}
.ai-price-tag { display: inline-block; background: #ffeeba; color: #856404; padding: 2px 8px; border-radius: 12px; font-weight: bold; font-size: 12px; margin-top: 5px; border: 1px solid #ffe8a1; }
.ai-price-tag-free { display: inline-block; background: #e2e3e5; color: #383d41; padding: 2px 8px; border-radius: 12px; font-weight: bold; font-size: 12px; margin-top: 5px; border: 1px solid #d6d8db; }

.ai-actions { margin-top: 20px;  padding-top: 10px;
    /* 启用 Flex 布局，控制按钮排列 */
    display: flex;
    gap: 15px; /* 按钮之间的间隙（无论是横排还是竖排） */
    align-items: center;
    flex-wrap: wrap; /* 允许小屏换行 */
}
/* 让按钮在容器内更协调 */
.ai-actions button {
    /* 电脑端：让两个按钮根据内容自动撑开，或者你可以写 flex:1 让它们等宽 */
    flex: 1 1 auto; 
    white-space: nowrap; /* 防止按钮文字换行 */
    min-width: 120px;    /* 防止按钮太窄 */
}
#aiStatusMsg { margin-top: 10px; color: #dc3545; font-weight: bold; font-size: 14px; }
.ai-disclaimer { margin-top: 15px; font-size: 11px; color: #999; line-height: 1.4; padding: 10px; background: #f8f8f8; border-radius: 6px; }

/* Loading 动画 */
.ai-loading-container { display:none; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align:center; z-index: 10; }
.ai-spinner { border: 4px solid #f3f3f3; border-top: 4px solid #ff9a9e; border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 0 auto 15px auto; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.ai-loading-text { background: rgba(255,255,255,0.95); padding: 8px 15px; border-radius: 20px; font-weight: bold; color: #333; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }

.close-ai-modal { position:absolute; right:15px; top:10px; font-size:28px; cursor:pointer; color: #aaa; z-index: 20;}
.close-ai-modal:hover { color: #333; }

#aiLoginGate { text-align: center; padding: 40px 20px; background: #f8f9fa; border-radius: 10px; border: 1px solid #eee; margin-top: 20px; }
#aiLoginGate h3 { margin-top: 0; color: #333; }

/* =========================================
   4. 画廊 Grid 系统 (响应式核心)
   ========================================= */

/* --- 默认：移动端优先 (Mobile First) --- */
.cfd-ai-gallery-grid {
    display: grid;
    /* 150px 足够小，保证大部分手机屏幕能一行放下 2 个 */
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px; /* 间距适中 */
}

/* 卡片容器 (兼容 A 标签) */
.cfd-ai-gallery-item {
    display: block; /* 强制 A 标签表现为块级元素 */
    text-decoration: none !important; /* 去掉下划线 */
    color: inherit; /* 文字颜色继承 */
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    background: #fff;
    position: relative;
}

.cfd-ai-gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}

/* 图片包裹层 (宽高比 1:1) */
.cfd-ai-gallery-img-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1; /* 关键：自动保持正方形 */
    overflow: hidden;
}

.cfd-ai-gallery-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
    display: block; /* 消除图片底部空隙 */
}

/* 悬停放大图片 */
.cfd-ai-gallery-item:hover .cfd-ai-gallery-img-wrap img {
    transform: scale(1.05);
}

/* 遮罩层 */
.cfd-ai-gallery-overlay {
    position: absolute; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.4);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.2s;
    font-weight: bold; font-size: 16px;
    flex-direction: column; gap: 5px;
    text-decoration: none;
}
.cfd-ai-gallery-item:hover .cfd-ai-gallery-overlay { opacity: 1; }

/* 底部文字信息 */
.cfd-ai-gallery-meta {
    padding: 12px;
    font-size: 13px;
    color: #555;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    line-height: 1.4;
    text-align: left;
}

.cfd-ai-user-prompt {
    font-style: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 2.8em; 
}

/* =========================================
   5. 媒体查询 (响应式断点)
   ========================================= */

/* --- 针对 移动端 (小于 768px) 的特殊调整 --- */
@media (max-width: 768px) {
    /* 弹窗在手机上改为单列滚动 */
    .ai-modal-content { flex-direction: column; width: 92%; height: auto; max-height: 86vh; margin: 7vh auto; overflow-y: auto; position: relative; top:auto; left:auto; transform:none; }
    .ai-col { min-width: 0; justify-content: flex-start; }
    .ai-img-wrapper { min-height: 300px; }
}

/* --- 针对 PC端 (大于 768px) 的放大优化 --- */
@media (min-width: 768px) {
    /* 这里的代码只会在电脑上生效 */
    .cfd-ai-gallery-grid {
        /* 将最小卡片宽度强制设为 260px */
        /* 这样在大屏上一行显示 3-4 个大图，而不是 7-8 个小图 */
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 30px; /* PC端间距更大，更透气 */
    }
    
    .cfd-ai-gallery-meta {
        font-size: 14px; /* PC端文字稍大 */
        padding: 15px;
    }
}
