/**
 * KAZD AI图片工具箱 前台样式
 * 视觉规范与 zibll-ai-image-generator / zibll-ai-video-generator 完全一致：
 *  - 复用主题 main.css 工具类（but / form-control / muted-box / flex / gap6 / jb-red 等）
 *  - 颜色全部使用主题 CSS 变量（--theme-color / --muted-bg-color 等），不使用硬编码色值
 *  - 仅补充本插件特有的"工具选择网格"样式
 */

/* block 场景无 zib-widget 卡片包裹，需自行提供 padding；
   widget/page/user_center 由 zib-widget 的 padding:15px 提供 */
.zait-toolbox:not(.zib-widget) {
    padding: 15px;
}

/* ========== 工具选择网格 ========== */
.zait-tools-grid {
    display: grid;
    grid-template-columns: repeat(var(--zait-columns, 4), minmax(0, 1fr));
    gap: 10px;
}

/* ========== 工具卡片（封面风格，始终细描边，无悬浮效果） ========== */
.zait-tool-card {
    display: flex;
    flex-direction: column;
    border-radius: var(--main-radius, 8px);
    background-color: var(--main-bg-color, #fff);
    border: 1px solid #e5e7eb;
    text-decoration: none;
    color: var(--key-color, #333);
    cursor: pointer;
    overflow: hidden;
    transition: border-color .2s ease;
}

.zait-tool-card:hover,
.zait-tool-card.zait-active {
    border-color: var(--theme-color, #4A7FFF);
}

/* 封面区域：固定宽高比 */
.zait-tool-cover {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background-color: var(--muted-bg-2-color, #f5f6f8);
}

.zait-tool-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 信息区域 */
.zait-tool-info {
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.zait-tool-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--key-color, #333);
    line-height: 1.4;
    margin-bottom: 3px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.zait-tool-desc {
    font-size: 12px;
    line-height: 1.4;
    color: var(--muted-2-color, #999);
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 17px;
}

.zait-tool-price {
    font-size: 13px;
    font-weight: 600;
    color: var(--theme-color, #2b6cff);
    margin-top: auto;
    line-height: 1.4;
}

.zait-tool-price .badg {
    margin-left: 4px;
    vertical-align: middle;
    font-weight: 400;
    font-size: 11px;
}

/* ========== 工具操作面板 ========== */
/* 面板本身使用 muted-box（无卡片样式，避免嵌套） */
.zait-tool-panel {
    /* 由 muted-box 提供背景与 padding */
}

/* 面板图标尺寸（支持 SVG / 图片 / FA 类名） */
.zait-panel-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    color: var(--theme-color, #2b6cff);
}

/* 面板头部价格 */
.zait-panel-price {
    font-size: 14px;
    font-weight: 600;
}

/* ========== 上传区缩略图 ========== */
/* 上传区本身是 muted-box，缩略图列表用 flex hh gap6 */
.zait-img-preview {
    flex-wrap: wrap !important;
    min-height: 0;
}

.zait-img-thumb {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: var(--mini-radius, 6px);
    overflow: hidden;
    background: var(--main-bg-color, #fff) center/22px no-repeat url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><circle cx='12' cy='12' r='9' stroke='%23theme-color' stroke-width='2' fill='none' stroke-dasharray='40 20' stroke-linecap='round'><animateTransform attributeName='transform' type='rotate' from='0 12 12' to='360 12 12' dur='1s' repeatCount='indefinite'/></circle></svg>");
    transition: transform .2s ease;
    display: inline-block;
}

.zait-img-thumb:hover {
    transform: scale(1.03);
}

.zait-img-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.zait-img-thumb.zait-loading img {
    display: none;
}

.zait-img-thumb .zait-thumb-del {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    line-height: 18px;
    padding: 0;
    text-align: center;
    border-radius: 50%;
    background: rgba(220, 30, 30, .9);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 11px;
}

.zait-img-thumb .zait-thumb-del:hover {
    background: var(--muted-3-color, #c83030);
}

/* ========== 质量按钮（与 zaig/zav 一致：默认 but，激活 jb-blue） ========== */
.zait-quality-btn.is-busy,
.zait-process-btn.is-busy {
    opacity: .7;
    pointer-events: none;
}

/* ========== 进度条（与 zaig/zav 完全一致，使用主题色变量） ========== */
.zait-progress-bar {
    height: 8px;
    padding: 0;
    overflow: hidden;
    border-radius: 999px;
    background: var(--muted-bg-color, rgba(0, 0, 0, .06));
}

.zait-progress-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--theme-color, #2b6cff), var(--focus-color, var(--theme-color, #2b6cff)));
    transition: width .4s ease;
    position: relative;
    overflow: hidden;
}

.zait-progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .35), transparent);
    animation: zait-shine 1.4s ease-in-out infinite;
}

@keyframes zait-shine {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ========== 状态文字（与 zaig/zav 一致） ========== */
.zait-status-text.is-error {
    color: var(--muted-3-color, #ff4d4f);
}
.zait-status-text.is-success {
    color: var(--theme-color, #52c41a);
}
.zait-status-icon + .zait-status-text.is-error,
.zait-result .fa-times-circle {
    color: var(--muted-3-color, #ff4d4f);
}
.zait-result .fa-check-circle {
    color: var(--theme-color, #52c41a);
}

/* ========== 结果图片（与 zaig/zav 一致） ========== */
.zait-result-content img {
    max-width: 100%;
    border-radius: var(--mini-radius, 4px);
}

.zait-result-content .zait-result-item {
    display: block;
    margin-bottom: 6px;
}

.zait-result-content .zait-result-item .zait-result-label {
    font-size: 12px;
    color: var(--muted-2-color, #999);
    margin-bottom: 4px;
    text-align: center;
}

/* 原图/结果对比布局 */
.zait-result-content.has-compare {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    text-align: left;
}

.zait-result-content.has-compare .zait-result-item {
    flex: 1 1 200px;
    min-width: 0;
}

/* ========== 历史记录（与 zaig/zav 一致） ========== */
.zait-history-item {
    transition: transform .2s;
    text-decoration: none;
    color: inherit;
    display: block;
}

.zait-history-item:hover {
    transform: translateY(-2px);
}

.zait-history-item img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
}

/* ========== 封面占位样式 ========== */
.zait-cover-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--muted-bg-2-color, #f0f1f3);
    color: var(--muted-2-color, #bbb);
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .zait-tools-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 8px;
    }

    .zait-tool-info {
        padding: 8px 10px 10px;
    }

    .zait-tool-name {
        font-size: 12px;
    }

    .zait-tool-desc {
        font-size: 10px;
    }

    .zait-tool-price {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .zait-tools-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .zait-upload-box .flex.hh {
        flex-wrap: wrap;
    }

    .zait-upload-box .zait-img-url {
        width: 100%;
        flex: 0 0 100% !important;
        margin-bottom: 6px;
    }

    .zait-result-content.has-compare .zait-result-item {
        flex: 1 1 100%;
    }
}
