#xuxiesd_pro {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    max-width: 800px;
    background: white;
    padding: 0;
    /* 改为0，因为拖动句柄会添加padding */
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 1050;
    transition: transform 0.2s ease;
    /* 确保窗口高度自适应内容 */
    min-height: auto;
    height: auto;
    max-height: 90vh;
    overflow: visible;
}
  
#xuxiesd_pro .popup-content {
    padding: 10px;
}
  
/* 桌面端可拖动样式 */
@media (min-width: 769px) {

    #xuxiesd_pro.draggable {
        user-select: none;
    }

    #xuxiesd_pro.dragging {
        transition: none;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    }

    /* 确保拖动时窗口高度自适应 */
    #xuxiesd_pro.dragging {
        height: auto;
        min-height: auto;
    }
}

#xuxiesd_pro .button-group {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 15px;
}





/* ========== 仅移动端：内容区固定高度+内部滚动 ========== */
@media (max-width: 768px) {
    /* 内容区容器：固定高度，内部滚动 */
    #xuxiesdpro {
        max-height: 50vh;      /* 固定最大高度，按需调整 */
        overflow-y: auto;       /* 垂直滚动 */
        overflow-x: hidden;     /* 水平方向隐藏 */
        padding-right: 5px;     /* 给滚动条留空间 */
        
        /* 自定义滚动条 */
        scrollbar-width: thin;
        scrollbar-color: #ccc #f1f1f1;
    }

    /* Webkit滚动条样式 */
    #xuxiesdpro::-webkit-scrollbar {
        width: 6px;
    }

    #xuxiesdpro::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 3px;
    }

    #xuxiesdpro::-webkit-scrollbar-thumb {
        background: #ccc;
        border-radius: 3px;
    }

    #xuxiesdpro::-webkit-scrollbar-thumb:hover {
        background: #999;
    }

    /* 调整多选容器高度，避免占用太多空间 */
    #xuxiesdpro .multi-select-container {
        height: 100px;
    }

    /* 调整行间距 */
    #xuxiesdpro > div {
        margin-bottom: 12px;
    }
}





#xuxiesd_pro-controls {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 15px;
}
  

#xuxiesd_pro textarea {
    width: 100%;
    min-height: 100px;
    margin-bottom: 15px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
    font-family: inherit;
    /* 确保文本区可以调整高度 */
    overflow: auto;
}


  
  /* 为弹窗内部直接子 div 添加垂直间距 */
  #xuxiesdpro > div {
    margin-bottom: 20px;
  }
  #xuxiesdpro > div:last-child {
    margin-bottom: 0;
  }

  /* 每一行使用弹性布局，垂直居中，允许换行 */
  #xuxiesdpro > div {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px; /* 换行后的间距 */
  }

  /* 文字标签右侧留空 */
  #xuxiesdpro span {
    margin-right: 12px;
    white-space: nowrap; /* 防止文字换行 */
  }

  /* 下拉框之间添加右间距 */
  #xuxiesdpro select {
    margin-right: 12px;
  }
  #xuxiesdpro select:last-child {
    margin-right: 0;
  }

  /* 按钮行特殊处理：靠右对齐 */
  #xuxiesdpro > div:last-child {
    justify-content: flex-end;
  }



.multi-select-row {
    margin: 12px 0;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.multi-select-row > span {
    min-width: 50px;
    padding-top: 5px;
    font-weight: bold;
}

/* 关键修改：固定高度，内部布局改为纵向 */
.multi-select-container {
    flex: 1;
    height: 140px;              /* 固定高度，按需调整 */
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 8px;
    display: flex;
    flex-direction: column;     /* 纵向排列：标签区在上，下拉框在下 */
    gap: 4px;
    background: #fff;
    overflow: hidden;           /* 防止整体溢出 */
}

/* 关键修改：标签区域可滚动 */
.selected-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;                    /* 占据剩余空间 */
    align-content: flex-start;  /* 标签从顶部开始排列 */
    overflow-y: auto;           /* 超出时滚动 */
    overflow-x: hidden;
    min-height: 0;              /* 关键：允许flex子项收缩 */
}

/* 自定义滚动条（可选） */
.selected-tags::-webkit-scrollbar {
    width: 10px;
}
.selected-tags::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}
.selected-tags::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}
.selected-tags::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.tag {
    display: inline-flex;
    align-items: center;
    background: #e8f4f8;
    border: 1px solid #b8d4e3;
    border-radius: 3px;
    padding: 4px 10px;
    font-size: 13px;
    color: #2c5aa0;
    white-space: nowrap;
    flex-shrink: 0;
}

.tag-remove {
    margin-left: 8px;
    cursor: pointer;
    color: #999;
    font-size: 16px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.tag-remove:hover {
    background: #ff6b6b;
    color: white;
}

.guanxi-tag {
    background: #fff3e0 !important;
    border-color: #ffcc80 !important;
    color: #e65100 !important;
}

/* 关键修改：下拉框固定在底部，高度自适应 */
.multi-select-dropdown {
    border: none;
    background: transparent;
    height: 30px;               /* 固定高度，不要100px */
    min-width: 80px;
    cursor: pointer;
    color: #666;
    flex-shrink: 0;             /* 防止被压缩 */
    align-self: flex-start;     /* 左对齐 */
}

.btn-primary {
    background: #4a90e2;
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.btn-primary:hover {
    background: #357abd;
}



/* ========== 仅作用于 #xuxiesd_pro 弹窗，不影响其他元素 ========== */
#xuxiesd_pro {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    background: transparent;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
}

/* 弹窗内容容器 - 移动端限制最大高度，保证可滚动 */
#xuxiesd_pro .popup-content {
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 25px 45px -12px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.03);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* 左右双栏布局 */
#xuxiesd_pro .dual-panel {
    display: grid;
    grid-template-columns: 1fr 1.1fr;
    gap: 20px;
    padding: 24px 28px 20px 28px;
    background: #fefefe;
    border-bottom: 1px solid #eef2f6;
    align-items: stretch;
}

/* 左侧操作面板 */
#xuxiesd_pro .left-options {
    background: #fafcff;
    border-radius: 20px;
    padding: 4px 6px 12px 6px;
    overflow-y: auto;
    max-height: 70vh;
    scrollbar-width: thin;
}

/* 右侧提示词面板 - 使用 flex 列布局，实现比例高度 */
#xuxiesd_pro .right-prompts {
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #ffffff;
    border-radius: 24px;
    padding: 8px 12px 16px 12px;
    border: 1px solid #edf2f7;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.02);
    height: 100%;           /* 填充父容器高度 */
    min-height: 0;          /* 允许收缩 */
}

/* 每个卡片容器 - 使用 flex 列，让 textarea 自动填充剩余空间 */
#xuxiesd_pro .prompt-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #ffffff;
    border-radius: 20px;
    padding: 6px 4px;
}

/* 故事核心想法卡片：占 70% 高度 */
#xuxiesd_pro .prompt-card:first-child {
    flex: 7;
}

/* 故事结尾卡片：占 30% 高度 */
#xuxiesd_pro .prompt-card:last-child {
    flex: 3;
}

/* 标题区域 - 固定高度，不参与伸缩 */
#xuxiesd_pro .prompt-label {
    flex-shrink: 0;
    font-weight: 700;
    font-size: 0.9rem;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
    border-left: 4px solid #3b82f6;
    padding-left: 12px;
    margin-bottom: 8px;
}

#xuxiesd_pro .prompt-label small {
    font-weight: normal;
    color: #5b6e8c;
    font-size: 0.7rem;
}

/* 文本域统一样式：填充剩余空间，支持滚动 */
#xuxiesd_pro textarea#aikuais,
#xuxiesd_pro textarea#AI_kuaigao {
    flex: 1;
    display: block !important;
    width: 100%;
    padding: 14px 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    border-radius: 20px;
    border: 1px solid #e2edf2;
    background: #fefefe;
    font-family: inherit;
    transition: 0.2s;
    resize: vertical;
    overflow-y: auto;
    min-height: 0;          /* 重要：允许收缩 */
}

/* 可选保留最小高度，防止极端过小 */
#xuxiesd_pro textarea#aikuais {
    min-height: 100px;
}

#xuxiesd_pro textarea#AI_kuaigao {
    min-height: 60px;
}

#xuxiesd_pro textarea#aikuais:focus,
#xuxiesd_pro textarea#AI_kuaigao:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
    outline: none;
    background: #ffffff;
}

/* 卡片开关组（背景/目标/剧情/场景/背景卡） */
#xuxiesd_pro .cards-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    background: #f8fafd;
    padding: 12px 14px;
    border-radius: 24px;
    margin-bottom: 22px;
}

#xuxiesd_pro .cards-group .card-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: white;
    padding: 4px 12px 4px 10px;
    border-radius: 40px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 1px rgba(0,0,0,0.02);
}

#xuxiesd_pro .cards-group .card-item span {
    font-size: 0.85rem;
    font-weight: 500;
    color: #334155;
}

#xuxiesd_pro .cards-group select {
    border: none;
    background: transparent;
    font-size: 0.8rem;
    font-weight: 500;
    color: #0f172a;
    outline: none;
    cursor: pointer;
    padding: 4px 0;
    width: auto;
    height: 28px;
}

/* 多选行（人物/关系） */
#xuxiesd_pro .multi-select-row {
    display: flex;
    align-items: flex-start;
    margin-bottom: 18px;
    gap: 12px;
    flex-wrap: wrap;
}

#xuxiesd_pro .multi-select-row > span:first-child {
    font-weight: 600;
    min-width: 48px;
    padding-top: 6px;
    color: #1e2a3e;
}

#xuxiesd_pro .multi-select-container {
    flex: 1;
    background: #ffffff;
    border: 1px solid #e2edf2;
    border-radius: 18px;
    padding: 8px 12px;
}

#xuxiesd_pro .selected-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    min-height: 32px;
}

#xuxiesd_pro .selected-tags span.tag {
    background: #eef2ff;
    color: #1f3a8a;
    padding: 4px 10px;
    border-radius: 32px;
    font-size: 0.75rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#xuxiesd_pro .selected-tags span.tag button {
    background: none;
    border: none;
    cursor: pointer;
    font-weight: bold;
    color: #5b6e8c;
    font-size: 12px;
    padding: 0 4px;
}

#xuxiesd_pro .multi-select-dropdown {
    width: 100%;
    padding: 6px 8px;
    border-radius: 28px;
    border: 1px solid #cbd5e1;
    background: white;
    font-size: 0.8rem;
    cursor: pointer;
}

/* 情绪四象限 */
#xuxiesd_pro .emotion-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px 16px;
    background: #f9fbfe;
    padding: 14px 12px;
    border-radius: 28px;
    margin: 12px 0 8px 0;
}

#xuxiesd_pro .emotion-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: white;
    padding: 6px 12px;
    border-radius: 48px;
    border: 1px solid #e4e9f0;
}

#xuxiesd_pro .emotion-item span {
    font-weight: 600;
    font-size: 0.85rem;
    color: #2c3e50;
    min-width: 32px;
}

#xuxiesd_pro .emotion-item select {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.8rem;
    padding: 6px 0;
    color: #1e293b;
    font-weight: 500;
    cursor: pointer;
    outline: none;
}

/* 底部按钮栏 */
#xuxiesd_pro .action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 28px 22px 28px;
    background: #ffffff;
    border-top: 1px solid #edf2f7;
    flex-wrap: wrap;
    gap: 12px;
}

#xuxiesd_pro .btn-bai {
    background: #f1f5f9;
    border: none;
    padding: 8px 20px;
    border-radius: 40px;
    font-weight: 500;
    font-size: 0.85rem;
    color: #1e293b;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 1px rgba(0,0,0,0.02);
    border: 1px solid #e0e7ef;
}

#xuxiesd_pro .btn-bai:hover {
    background: #e6edf4;
    transform: translateY(-1px);
    border-color: #cbd9e6;
}

/* 滚动条美化（仅左侧面板） */
#xuxiesd_pro .left-options::-webkit-scrollbar {
    width: 5px;
}
#xuxiesd_pro .left-options::-webkit-scrollbar-track {
    background: #eef2f8;
    border-radius: 10px;
}
#xuxiesd_pro .left-options::-webkit-scrollbar-thumb {
    background: #b9cadb;
    border-radius: 10px;
}

/* ========== 移动端响应式修复：限制总高度，避免右区溢出，保证可滚动 ========== */
@media (max-width: 780px) {
    /* 弹窗整体在手机屏幕上限制最大高度，并允许内部滚动 */
    #xuxiesd_pro {
        max-height: 90vh;
        display: flex;
        flex-direction: column;
    }
    #xuxiesd_pro .popup-content {
        max-height: 90vh;
        overflow-y: auto;
        border-radius: 10px;
    }
    /* 双栏改为上下布局，并去除可能的高度溢出 */
    #xuxiesd_pro .dual-panel {
        grid-template-columns: 1fr;
        gap: 20px;
        padding: 18px 20px;
        overflow-y: visible;
    }
    /* 左侧面板限制最大高度，右侧自动撑开，整体可滚动 */
    #xuxiesd_pro .left-options {
        max-height: 45vh;
        overflow-y: auto;
    }
    /* 右侧面板不再使用百分比高度，由内容撑开，但保留内部比例 */
    #xuxiesd_pro .right-prompts {
        height: auto;
        min-height: 300px;  /* 保证可见度 */
        max-height: 60vh;
        overflow-y: auto;   /* 如果内容过多，右侧自身可滚动，避免整体溢出 */
    }
    /* 情绪网格变为单列 */
    #xuxiesd_pro .emotion-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    /* 底部按钮区域调整内边距，确保可见 */
    #xuxiesd_pro .action-bar {
        padding: 14px 20px;
        flex-direction: column;
        align-items: stretch;
        margin-top: auto;
    }
    #xuxiesd_pro .action-bar > div {
        justify-content: center;
        display: flex;
        gap: 12px;
        flex-wrap: wrap;
    }
    /* 卡片组调整间距 */
    #xuxiesd_pro .cards-group {
        gap: 8px;
    }
    #xuxiesd_pro .cards-group .card-item {
        padding: 2px 10px;
    }
    /* 文本域最小高度调整，避免挤压过甚 */
    #xuxiesd_pro textarea#aikuais {
        min-height: 120px;
    }
    #xuxiesd_pro textarea#AI_kuaigao {
        min-height: 60px;
    }
}

/* 针对极小设备进一步优化 */
@media (max-width: 480px) {
    #xuxiesd_pro .dual-panel {
        padding: 12px 14px;
    }
    #xuxiesd_pro .btn-bai {
        padding: 6px 16px;
        font-size: 0.8rem;
    }
    #xuxiesd_pro .right-prompts {
        min-height: 260px;
        max-height: 55vh;
    }
}

/* 表单元素触摸优化 */
#xuxiesd_pro select,
#xuxiesd_pro button {
    touch-action: manipulation;
}








/* 自定义下拉 - 直接挂在 body 下，使用 fixed 定位 */
.custom-renwu-dropdown-global {
    position: fixed;
    top: 0;
    left: 0;
    min-width: 180px;
    max-height: 250px;
    overflow-y: auto;
    background: white;
    border: 1px solid #ccc;
    border-radius: 12px;
    z-index: 99999;
    display: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.custom-renwu-dropdown-global.show {
    display: block;
}

.custom-renwu-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.1s;
}

.custom-renwu-option:hover {
    background: #f0f2f5;
}

.custom-renwu-option img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    background: #eef2f8;
}

.custom-renwu-option span {
    font-size: 0.85rem;
    color: #1e293b;
}

/* 隐藏原生 select，但保留 */
#renwu_select {
    display: none;
}

.custom-renwu-trigger {
    width: 100%;
    padding: 6px 8px;
    border-radius: 28px;
    border: 1px solid #cbd5e1;
    background: white;
    font-size: 0.8rem;
    cursor: pointer;
    text-align: left;
    color: #666;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.custom-renwu-trigger::after {
    content: "▼";
    font-size: 10px;
    color: #888;
}


/* 关系选择器触发器（与人物选择器共用样式，可复用） */
.custom-guanxi-trigger {
    width: 100%;
    padding: 6px 8px;
    border-radius: 28px;
    border: 1px solid #cbd5e1;
    background: white;
    font-size: 0.8rem;
    cursor: pointer;
    text-align: left;
    color: #666;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.custom-guanxi-trigger::after {
    content: "▼";
    font-size: 10px;
    color: #888;
}

/* 关系选项样式（双头像并排） */
.custom-guanxi-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.1s;
    flex-wrap: wrap;
}

.custom-guanxi-option:hover {
    background: #f0f2f5;
}

.guanxi-avatars {
    display: flex;
    align-items: center;
    gap: 4px;
}

.guanxi-avatars img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    background: #eef2f8;
}

.guanxi-avatars span {
    margin: 0 2px;
    font-size: 12px;
    color: #888;
}

.custom-guanxi-option .guanxi-text {
    font-size: 0.85rem;
    color: #1e293b;
    margin-left: 4px;
}

/* 标签内的头像样式（小尺寸） */
.tag-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 4px;
    vertical-align: middle;
}

.tag-dual-avatars {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-right: 6px;
}

.tag-dual-avatars img {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: cover;
}

/* 隐藏原生关系 select */
#guanxi_select {
    display: none;
}


.tag-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: cover;
    background: #eef2f8;
    vertical-align: middle;
}