.igdm-tool-wrapper { --p-bg: #ffffff; --p-border: #e2e8f0; --p-primary: #0095F6; --p-text: #0f172a; width: 100%; max-width: 1300px; margin: 0 auto; background: var(--p-bg); border-radius: 20px; padding: 24px; border: 1px solid var(--p-border); box-shadow: 0 10px 25px -5px rgba(0,0,0,0.05); box-sizing: border-box; }
.igdm-header-main { font-size: 1.6rem; font-weight: 800; color: var(--p-text); margin-bottom: 8px; text-align: center; }
.igdm-subtitle { color: #64748b; font-size: 0.95rem; padding-bottom: 20px; border-bottom: 1px solid var(--p-border); margin-bottom: 24px; text-align: center; max-width: 800px; margin-left: auto; margin-right: auto; line-height: 1.6; }

/* 布局 */
.igdm-layout { display: flex; flex-direction: column; gap: 24px; }
.igdm-panel { display: flex; flex-direction: column; background: #f8fafc; border: 1px solid var(--p-border); border-radius: 16px; overflow: hidden; padding: 0; box-sizing: border-box; }
.igdm-preview-panel { background: #e0f2fe; padding: 24px; display: flex; align-items: center; justify-content: flex-start; flex-direction: column; box-sizing: border-box; }
.igdm-panel-title { font-size: 1.05rem; font-weight: 700; color: #334155; padding: 20px; border-bottom: 1px solid var(--p-border); background: #ffffff; margin: 0; }
.igdm-preview-panel .igdm-panel-title { background: #bae6fd; color: #0369a1; border-bottom: none; }

/* 配置区网格布局 */
.igdm-config-grid { display: grid; grid-template-columns: 300px 1fr; gap: 24px; padding: 24px; box-sizing: border-box; }
.igdm-config-section { display: flex; flex-direction: column; }
.igdm-section-title { font-size: 0.95rem; font-weight: 700; color: #475569; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; border-bottom: 1px dashed #cbd5e1; padding-bottom: 10px; }

.igdm-form-group { display: flex; flex-direction: column; margin-bottom: 12px; }
.igdm-label { font-size: 0.85rem; font-weight: 600; color: #64748b; margin-bottom: 6px; }
.igdm-input, .igdm-select, .igdm-textarea { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid #cbd5e1; background: #ffffff; color: var(--p-text); font-size: 0.95rem; outline: none; transition: 0.2s; box-sizing: border-box; }
.igdm-input:focus, .igdm-select:focus, .igdm-textarea:focus { border-color: var(--p-primary); box-shadow: 0 0 0 3px rgba(0, 149, 246, 0.15); }

.igdm-file-upload { display: block; width: 100%; border: 1px dashed #94a3b8; background: #ffffff; border-radius: 8px; padding: 10px; text-align: center; cursor: pointer; transition: 0.2s; box-sizing: border-box; }
.igdm-file-upload:hover { border-color: var(--p-primary); background: #f0f9ff; color: var(--p-primary); }
.igdm-file-upload input[type="file"] { display: none; }
.igdm-file-upload span { font-size: 0.85rem; font-weight: 600; color: #475569; }

/* 悬浮控制栏 */
.igdm-theme-picker-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 16px; margin-top: 24px; padding: 12px 24px; background: #ffffff; border: 1px solid var(--p-border); border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); box-sizing: border-box; width: 100%; max-width: 450px; }
.igdm-theme-label { font-weight: 700; color: #475569; font-size: 0.95rem; white-space: nowrap; }
.igdm-theme-picker { display: flex; flex-wrap: wrap; gap: 12px; flex: 1; }
.igdm-select-sm { flex: 1; min-width: 130px; padding: 8px; border-radius: 6px; border: 1px solid #cbd5e1; background: #f8fafc; color: #0f172a; font-size: 0.85rem; outline: none; font-weight: 600;}
.igdm-select-sm:focus { border-color: var(--p-primary); }

/* 按钮 */
.igdm-btn-primary { background: var(--p-primary); color: white; border: none; padding: 10px 20px; border-radius: 20px; font-weight: 700; font-size: 0.95rem; cursor: pointer; transition: 0.2s; display: flex; align-items: center; gap: 6px; box-shadow: 0 4px 12px rgba(0, 149, 246, 0.3); }
.igdm-btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* ================= 黑夜模式适配 ================= */
[data-theme="dark"] .igdm-tool-wrapper { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .igdm-header-main { color: #f8fafc; }
[data-theme="dark"] .igdm-panel { background: #0f172a; border-color: #475569; }
[data-theme="dark"] .igdm-panel-title { background: #1e293b; border-bottom-color: #475569; color: #f8fafc; }
[data-theme="dark"] .igdm-preview-panel { background: #020617; }
[data-theme="dark"] .igdm-section-title { border-bottom-color: #334155; }
[data-theme="dark"] .igdm-label { color: #cbd5e1; }
[data-theme="dark"] .igdm-input, [data-theme="dark"] .igdm-select, [data-theme="dark"] .igdm-textarea { background: #020617; border-color: #475569; color: #f8fafc; }
[data-theme="dark"] .igdm-file-upload { background: #1e293b; border-color: #475569; }
[data-theme="dark"] .igdm-theme-picker-bar { background: #0f172a; border-color: #475569; }
[data-theme="dark"] .igdm-theme-label { color: #cbd5e1; }
[data-theme="dark"] .igdm-select-sm { background: #1e293b; border-color: #475569; color: #f8fafc; }


/* =======================================================
   独立封装的 Instagram DM 渲染引擎 (防污染)
   ======================================================= */
.igdm-preview-container { width: 100%; display: flex; justify-content: center; margin-top: 20px; overflow: hidden; box-sizing: border-box; }

.igdm-mockup-wrapper {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    width: 100%;
    max-width: 400px;
    background-color: var(--igdm-bg);
    border: 1px solid var(--igdm-border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    transition: background-color 0.3s;
    /* 默认浅色 */
    --igdm-bg: #ffffff;
    --igdm-text: #262626;
    --igdm-text-dim: #8e8e8e;
    --igdm-border: #dbdbdb;
    --igdm-bubble-them: #efefef;
    --igdm-bubble-them-text: #262626;
    
    /* 默认气泡 (蓝色) */
    --igdm-bubble-me: #3797f0;
    --igdm-bubble-me-text: #ffffff;
}

/* 暗黑模式 */
.igdm-mockup-wrapper[data-igdm-theme="dark"] {
    --igdm-bg: #000000;
    --igdm-text: #fafafa;
    --igdm-text-dim: #a8a8a8;
    --igdm-border: #262626;
    --igdm-bubble-them: #262626;
    --igdm-bubble-them-text: #fafafa;
}

/* 自定义气泡颜色变体 */
.igdm-mockup-wrapper[data-igdm-bubble="purple"] { --igdm-bubble-me: linear-gradient(45deg, #A41FD5, #E1306C); }
.igdm-mockup-wrapper[data-igdm-bubble="gray"] { --igdm-bubble-me: #262626; }
.igdm-mockup-wrapper[data-igdm-theme="dark"][data-igdm-bubble="gray"] { --igdm-bubble-me: #363636; }

/* 头部 */
.igdm-mockup-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--igdm-border); }
.igdm-header-left { display: flex; align-items: center; }
.igdm-icon-back { width: 24px; height: 24px; color: var(--igdm-text); margin-right: 16px; }
.igdm-mockup-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; margin-right: 12px; }
.igdm-user-info { display: flex; flex-direction: column; }
.igdm-name { font-weight: 700; font-size: 16px; color: var(--igdm-text); }
.igdm-status { font-size: 12px; color: var(--igdm-text-dim); margin-top: 2px; }
.igdm-header-right { display: flex; align-items: center; gap: 16px; }
.igdm-icon-action { width: 26px; height: 26px; color: var(--igdm-text); }

/* 聊天主体 */
.igdm-mockup-body { flex: 1; min-height: 400px; padding: 16px; display: flex; flex-direction: column; gap: 4px; background: var(--igdm-bg); }

/* 时间线 */
.igdm-time-row { text-align: center; width: 100%; margin: 16px 0; }
.igdm-time-text { font-size: 12px; color: var(--igdm-text-dim); font-weight: 500; }

/* 聊天气泡行 */
.igdm-row { display: flex; width: 100%; align-items: flex-end; margin-bottom: 8px; }
.igdm-row.them { justify-content: flex-start; }
.igdm-row.me { justify-content: flex-end; }

/* 对方头像 */
.igdm-row-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; margin-right: 8px; visibility: hidden; /* 默认隐藏，由JS决定最后一条显示 */ flex-shrink: 0; }
.igdm-row.show-avatar .igdm-row-avatar { visibility: visible; }

/* 气泡本体 */
.igdm-bubble { max-width: 70%; padding: 12px 16px; font-size: 15px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.igdm-row.them .igdm-bubble { background: var(--igdm-bubble-them); color: var(--igdm-bubble-them-text); border-radius: 22px 22px 22px 4px; }
.igdm-row.me .igdm-bubble { background: var(--igdm-bubble-me); color: var(--igdm-bubble-me-text); border-radius: 22px 22px 4px 22px; }

/* 连续消息圆角合并逻辑 */
.igdm-row.them.consecutive .igdm-bubble { border-radius: 22px 22px 22px 22px; }
.igdm-row.me.consecutive .igdm-bubble { border-radius: 22px 22px 22px 22px; }

/* 底部输入区 */
.igdm-mockup-footer { padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.igdm-camera-btn { width: 36px; height: 36px; border-radius: 50%; background: #0095F6; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.igdm-input-pill { flex: 1; background: var(--igdm-border); border-radius: 22px; padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; }
.igdm-input-placeholder { color: var(--igdm-text-dim); font-size: 15px; }
.igdm-input-icons { display: flex; gap: 12px; }
.igdm-input-icons svg { width: 20px; height: 20px; color: var(--igdm-text-dim); }

/* ================= 移动端强力自适应适配 ================= */
@media (max-width: 650px) {
    .igdm-tool-wrapper { padding: 16px; }
    .igdm-preview-panel { padding: 16px 12px; }
    
    /* 配置区变为单列 */
    .igdm-config-grid { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
    .igdm-config-section[style] { grid-column: span 1 !important; }
}