/* ===========================
   CSS变量（亮色/暗色）
   =========================== */
:root {
    --bg: #fde4ec;
    --card: #ffffff;
    --card2: #fff8fb;
    --border: #f0d0de;
    --text: #444;
    --text-light: #888;
    --text-muted: #bbb;
    --primary: #d81b60;
    --primary-mid: #f48fb1;
    --primary-light: #fce4ec;
    --primary-dark: #c2185b;
    --user-bubble: #f8bbd0;
    --ai-bubble: #f3f3f3;
    --ai-bubble-text: #333;
    --shadow: rgba(216,27,96,0.12);
    --input-bg: #fff8fb;
    --tip-bg: #fff3f7;
    --stat-bg: #fff0f5;
    --separator: #f0c0d0;
    --search-bg: #fff8fb;
    --window-header-bg: #fce4ec;
    --btn-secondary: #eee;
    --btn-secondary-text: #555;
}

body.dark {
    --bg: #1a1a2e;
    --card: #16213e;
    --card2: #1a2040;
    --border: #2a3060;
    --text: #e0e0e0;
    --text-light: #aaa;
    --text-muted: #666;
    --primary: #f06292;
    --primary-mid: #e91e8c;
    --primary-light: #2d1a26;
    --primary-dark: #f48fb1;
    --user-bubble: #4a1a30;
    --ai-bubble: #1e2a3a;
    --ai-bubble-text: #ddd;
    --shadow: rgba(0,0,0,0.3);
    --input-bg: #1e2340;
    --tip-bg: #1e1a2e;
    --stat-bg: #1e1a2e;
    --separator: #2a2040;
    --search-bg: #1e2340;
    --window-header-bg: #2d1a26;
    --btn-secondary: #2a3060;
    --btn-secondary-text: #ccc;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    padding: 12px;
    padding-bottom: 40px;
    transition: background 0.3s, color 0.3s;
    -webkit-text-size-adjust: 100%;
}

/* ===========================
   顶部栏
   =========================== */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 1100px;
    margin: 0 auto 16px;
    position: relative;
}
.top-bar h1 {
    font-size: clamp(1.1em, 4vw, 1.5em);
    color: var(--primary);
    text-align: center;
}
.icon-btn {
    position: absolute;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border) !important;
    color: var(--text);
    font-size: 18px;
    padding: 6px 10px !important;
    border-radius: 10px;
    cursor: pointer;
    line-height: 1;
}
.icon-btn:hover { background: var(--primary-light) !important; }

/* ===========================
   卡片
   =========================== */
.section {
    max-width: 1100px;
    margin: 12px auto;
    padding: 16px;
    background: var(--card);
    border-radius: 16px;
    box-shadow: 0 4px 16px var(--shadow);
}
h2 {
    font-size: 0.95em;
    color: var(--primary);
    margin-bottom: 12px;
}

/* ===========================
   设置行 / 表单元素
   =========================== */
.setting-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
label { font-size: 14px; color: var(--text-light); white-space: nowrap; }

input[type="text"], input[type="number"], select {
    font-size: 14px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
    border-color: var(--primary-mid);
}
input[type="text"] { min-width: 100px; }
select { max-width: 280px; }

/* 文件输入隐藏，用label代替 */
input[type="file"] { display: none; }
.file-label {
    display: inline-block;
    padding: 8px 14px;
    background: var(--primary-mid);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    transition: background 0.2s;
}
.file-label:hover { background: var(--primary-dark); }
.file-hint { font-size: 12px; color: var(--text-muted); flex: 1; min-width: 80px; }

button {
    font-size: 14px;
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    background: var(--primary-mid);
    color: white;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}
button:hover { background: var(--primary-dark); }
button:active { opacity: 0.8; }

.secondary-btn {
    background: var(--btn-secondary);
    color: var(--btn-secondary-text);
}
.secondary-btn:hover { background: var(--border); color: var(--text); }

.inline-btn {
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 6px;
}
.inline-btn.danger { background: #ef9a9a; }
.inline-btn.danger:hover { background: #e53935; }

#nameSaveHint { font-size: 13px; color: var(--primary); }

/* ===========================
   拆分选项
   =========================== */
.split-options-box {
    padding: 12px;
    background: var(--tip-bg);
    border-radius: 10px;
    border: 1px solid var(--border);
    font-size: 14px;
    color: var(--text);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

/* ===========================
   提示框
   =========================== */
.tip-box {
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--tip-bg);
    border-left: 4px solid var(--primary-mid);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-light);
    line-height: 1.6;
}

/* ===========================
   统计卡片
   =========================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
}
.stat-card {
    background: var(--stat-bg);
    border-radius: 12px;
    padding: 12px 8px;
    text-align: center;
    border: 1px solid var(--border);
}
.stat-num {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--primary);
    line-height: 1.2;
}
.stat-label { font-size: 11px; color: var(--text-light); margin-top: 4px; }

/* ===========================
   图表
   =========================== */
canvas {
    width: 100% !important;
    max-height: 260px;
    touch-action: pan-y;
}

/* ===========================
   聊天区头部
   =========================== */
.chat-header-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}

/* ===========================
   聊天显示
   =========================== */
#chatDisplay { display: flex; flex-direction: column; gap: 0; }
.placeholder-text {
    color: var(--text-muted);
    text-align: center;
    padding: 24px;
    font-size: 14px;
}

.window-header {
    background: var(--window-header-bg);
    border-left: 4px solid var(--primary-mid);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: bold;
    color: var(--primary);
    margin: 14px 0 8px;
}
.window-header:first-child { margin-top: 0; }

/* 时间分隔 */
.time-separator {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin: 8px 0 4px;
}
.time-separator::before, .time-separator::after {
    content: "";
    display: inline-block;
    width: 50px;
    height: 1px;
    background: var(--separator);
    vertical-align: middle;
    margin: 0 6px;
}

/* 气泡行 */
.bubble-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    margin: 3px 0;
}
.bubble-row.user { flex-direction: row-reverse; }

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    background: var(--primary-light);
}

.bubble {
    max-width: 75%;
    padding: 9px 13px;
    font-size: 14px;
    line-height: 1.65;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    position: relative;
}
.bubble-row.user .bubble {
    background: var(--user-bubble);
    border-radius: 16px 4px 16px 16px;
    color: var(--text);
}
.bubble-row.assistant .bubble {
    background: var(--ai-bubble);
    border-radius: 4px 16px 16px 16px;
    color: var(--ai-bubble-text);
}

.bubble .meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

/* 画图气泡 */
.dalle-bubble {
    background: linear-gradient(135deg, #fff0f5, #f3e8ff);
    border-radius: 12px;
    padding: 10px 13px;
    font-size: 13px;
    line-height: 1.6;
    border: 1px solid #e0c8f0;
    max-width: 100%;
}
body.dark .dalle-bubble {
    background: linear-gradient(135deg, #2d1a26, #1a1a30);
    border-color: #4a2060;
}
.dalle-label {
    font-size: 11px;
    color: #9c27b0;
    font-weight: bold;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.dalle-prompt {
    color: var(--text);
    font-style: italic;
    font-size: 13px;
    line-height: 1.6;
}

/* 模型标签 */
.model-tag {
    display: inline-block;
    background: #e8f0fe;
    color: #5c6bc0;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 4px;
    white-space: nowrap;
}
body.dark .model-tag { background: #1a2340; color: #90a4ae; }

/* 图片标记 */
.img-tag {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 4px;
}

/* ===========================
   搜索结果
   =========================== */
.search-result-item {
    border-left: 3px solid var(--primary-mid);
    padding: 8px 12px;
    margin: 5px 0;
    background: var(--search-bg);
    border-radius: 0 8px 8px 0;
    font-size: 14px;
    line-height: 1.6;
}
.search-result-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 3px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}
.search-result-role { font-weight: bold; color: var(--primary); }
.search-highlight {
    background: #ffe082;
    border-radius: 3px;
    padding: 0 2px;
    color: #333;
}
body.dark .search-highlight { background: #7c5c00; color: #ffe; }

/* ===========================
   关键词标签
   =========================== */
.kw-tag {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 12px;
    margin: 2px;
    font-size: 13px;
}
.kw-day-row {
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}
.kw-day-label {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 90px;
    flex-shrink: 0;
}

/* ===========================
   手机适配
   =========================== */
@media (max-width: 600px) {
    body { padding: 8px; }
    .section { padding: 12px; border-radius: 12px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-num { font-size: 1.3em; }
    .bubble { max-width: 85%; font-size: 13.5px; }
    canvas { max-height: 180px; }
    .chat-header-row { flex-direction: column; align-items: flex-start; }
    select { max-width: 100%; width: 100%; }
    button { padding: 9px 12px; }
    .top-bar h1 { font-size: 1.1em; }
    .split-options-box { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 400px) {
    .bubble { max-width: 90%; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* safe area for iPhone notch */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    body { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
}
