/* ===== 沃土 样式 v2 — Chat-First ===== */
:root {
    --bg: #1a1b26;
    --bg-secondary: #24283b;
    --bg-tertiary: #1f2335;
    --text: #c0caf5;
    --text-muted: #565f89;
    --accent: #7aa2f7;
    --accent-hover: #89b4fa;
    --green: #9ece6a;
    --red: #f7768e;
    --yellow: #e0af68;
    --border: #3b4261;
    --radius: 8px;
    --top-bar-height: 48px;
    --sidebar-width: 260px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: var(--app-height, 100dvh);
    overflow: hidden;
}

/* ===== 认证页面 ===== */
#auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--app-height, 100dvh);
}
.auth-card {
    background: var(--bg-secondary);
    padding: 48px 40px;
    border-radius: 16px;
    width: 380px;
    max-width: 92%;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.auth-card h1 { font-size: 28px; margin-bottom: 8px; }
.auth-subtitle { color: var(--text-muted); margin-bottom: 32px; font-size: 14px; }
#login-form input {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 15px;
}
#login-form input:focus { outline: none; border-color: var(--accent); }
.auth-actions { display: flex; gap: 12px; margin-top: 8px; }
.auth-actions button { flex: 1; }

/* ===== 主布局：顶栏 + 全屏对话 ===== */
#app {
    display: flex;
    flex-direction: column;
    height: var(--app-height, 100dvh);
}

/* ===== 顶栏 ===== */
#top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    height: var(--top-bar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--top-bar-height) + env(safe-area-inset-top, 0px));
}
.top-bar-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--radius);
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.top-bar-btn:active { color: var(--accent); background: var(--bg-tertiary); }
.top-bar-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
}

/* ===== 左侧抽屉 ===== */
#drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}
#drawer-overlay.active { display: block; }

#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    max-width: 85vw;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top, 0px);
}
#sidebar.active { transform: translateX(0); }

#branch-tree {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* 枝条节点 */
.branch-node {
    padding: 10px 12px;
    margin: 2px 0;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}
.branch-node:hover { background: var(--bg-tertiary); }
.branch-node.active { background: var(--accent); color: var(--bg); }
.branch-icon { font-size: 16px; }
.branch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== 对话区 ===== */
#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}
.welcome-msg {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    line-height: 1.8;
}

/* 消息气泡 */
.message {
    margin-bottom: 16px;
    max-width: 85%;
    animation: fadeIn 0.3s;
}
.message.user { margin-left: auto; }
.message.assistant { margin-right: auto; }
.message .role { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.message .content {
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
    font-size: 15px;
    word-break: break-word;
}
.message.user .content { background: var(--accent); color: var(--bg); }
.message.assistant .content { background: var(--bg-secondary); color: var(--text); }
.message .content p { margin-bottom: 8px; }
.message .content p:last-child { margin-bottom: 0; }
.message .content code {
    background: rgba(0,0,0,0.2);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 13px;
}
.message .content pre {
    background: var(--bg);
    padding: 12px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 8px 0;
}
.message .content pre code { background: none; padding: 0; }
/* Markdown 渲染样式 */
.message.assistant .content { line-height: 1.7; }
.message .content > *:first-child { margin-top: 0; }
.message .content > *:last-child { margin-bottom: 0; }
.message .content ul, .message .content ol { margin: 8px 0; padding-left: 20px; }
.message .content li { margin-bottom: 4px; }
.message .content h1, .message .content h2, .message .content h3, .message .content h4 {
    margin: 12px 0 6px; font-weight: 600;
}
.message .content h1 { font-size: 1.3em; }
.message .content h2 { font-size: 1.2em; }
.message .content h3 { font-size: 1.1em; }
.message .content blockquote {
    margin: 8px 0; padding: 8px 12px;
    border-left: 3px solid var(--accent);
    background: rgba(0,0,0,0.03); border-radius: 0 6px 6px 0;
}
.message .content strong { font-weight: 600; }
.message .content a { color: var(--accent); text-decoration: none; }
.message .content table { border-collapse: collapse; margin: 8px 0; }
.message .content th, .message .content td { border: 1px solid #ddd; padding: 6px 10px; }
.message .content hr { border: none; border-top: 1px solid #ddd; margin: 12px 0; }


/* ===== 待发送图片预览 ===== */
#pending-images {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    overflow-x: auto;
    background: var(--bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
#pending-images::-webkit-scrollbar { height: 4px; }
.pending-img {
    position: relative;
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
}
.pending-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.pending-file-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}
.pending-img-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}
.pending-img-remove:active { background: var(--red); }

/* ===== 输入区 ===== */
#input-area {
    display: flex;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    gap: 8px;
    align-items: flex-end;
    background: var(--bg);
    flex-shrink: 0;
}
#msg-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 16px;
    resize: none;
    font-family: inherit;
    max-height: 120px;
}
#msg-input:focus { outline: none; border-color: var(--accent); }
#send-btn {
    width: 40px; height: 40px;
    border: none;
    background: var(--accent);
    color: var(--bg);
    border-radius: var(--radius);
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
#send-btn:active { background: var(--accent-hover); }
#attach-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    flex-shrink: 0;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}
#attach-btn:active { color: var(--accent); }

/* ===== 草稿卡片 ===== */
#draft-cards { padding: 0 16px 12px; }
.draft-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--yellow);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
.draft-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.draft-header h4 { font-size: 16px; color: var(--yellow); }
.draft-timer { font-size: 12px; color: var(--text-muted); }
.draft-content {
    background: var(--bg);
    padding: 12px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    font-size: 14px;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}
.draft-actions { display: flex; gap: 8px; }
.draft-actions button {
    padding: 6px 16px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
}
.confirm-btn { background: var(--green); color: var(--bg); }
.edit-btn { background: var(--yellow); color: var(--bg); }
.reject-btn { background: var(--red); color: var(--bg); }

/* ===== 弹窗 ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.modal-content {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: 12px;
    width: 400px;
    max-width: 92%;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-content-lg {
    width: 500px;
    max-width: 95%;
    max-height: 85vh;
}
.modal-content h3 { margin-bottom: 16px; }
.modal-content input {
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
}
.modal-content input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions button { flex: 1; }
#search-results { margin: 12px 0; max-height: 300px; overflow-y: auto; }

/* ===== 通用组件 ===== */
.primary-btn {
    padding: 10px 20px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
}
.primary-btn:hover { background: var(--accent-hover); }
.secondary-btn {
    padding: 10px 20px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
}
.secondary-btn:hover { border-color: var(--accent); color: var(--accent); }
.error-msg { color: var(--red); font-size: 13px; margin-top: 8px; }
.empty-hint { color: var(--text-muted); text-align: center; padding: 40px 0; font-size: 14px; }

/* 笔记/枝条条目（弹窗内） */
.note-item, .branch-item {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
}
.note-item:hover, .branch-item:hover { background: var(--bg); }
.note-title, .branch-item-name { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.note-preview { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.note-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.tag-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--accent);
    color: var(--bg);
    border-radius: 12px;
    font-size: 11px;
    margin-right: 4px;
    margin-bottom: 4px;
}
.note-detail { padding: 8px 0; }
.note-detail h2 { font-size: 20px; margin-bottom: 12px; }
.note-detail .note-content {
    line-height: 1.8;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.note-detail .note-content p { margin-bottom: 8px; }
.back-btn {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius);
    cursor: pointer;
    margin-bottom: 16px;
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ===== 思考动画 ===== */
.thinking-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
}
.thinking-indicator span {
    width: 6px; height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}
.thinking-indicator span:nth-child(2) { animation-delay: 0.2s; }
.thinking-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* ===== 动画 ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}
.draft-card.confirmed { border-color: var(--green); opacity: 0.5; }
.draft-card.rejected { border-color: var(--red); opacity: 0.5; }

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== 笔记搜索浮层（可移除）===== */
#note-search-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 88vh;
    background: var(--bg-secondary);
    z-index: 1500;
    border-bottom: 2px solid var(--accent);
    border-radius: 0 0 16px 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: noteSearchSlideDown 0.25s ease;
}
@keyframes noteSearchSlideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}
#note-search-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    flex-shrink: 0;
}
#note-search-header h3 { font-size: 16px; color: var(--text); }
#note-search-input-area {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    flex-shrink: 0;
}
#note-search-input-area input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 15px;
}
#note-search-input-area input:focus { outline: none; border-color: var(--accent); }
#note-search-results {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
    -webkit-overflow-scrolling: touch;
}
.note-search-result {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s;
}
.note-search-result:active { background: var(--bg); }
.nsr-title { font-size: 14px; font-weight: 500; color: var(--yellow); margin-bottom: 4px; }
.nsr-preview { font-size: 12px; color: var(--text-muted); line-height: 1.5; max-height: 60px; overflow: hidden; }
.nsr-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.nsr-tags { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.nsr-tag { font-size: 10px; padding: 1px 6px; border-radius: 3px; background: rgba(187,154,247,0.15); color: var(--purple); }
.nsd-tag-row { margin-top: 12px; }
.nsd-tag-label { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.nsd-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.nsd-content-body { font-size: 14px; color: var(--text); line-height: 1.6; white-space: pre-wrap; word-break: break-all; max-height: 400px; overflow-y: auto; background: var(--bg); padding: 12px; border-radius: 8px; margin-top: 6px; }
#note-search-detail {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
}
/* ===== 笔记搜索浮层 END ===== */
.nsr-cond { font-size: 12px; color: var(--accent); margin-bottom: 8px; padding: 4px 8px; background: var(--bg); border-radius: 4px; }
/* 笔记详情编辑区 */
.nsd-btn { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; font-size: 13px; }
.nsd-btn-edit { background: #7aa2f7; color: #1a1b26; }
.nsd-btn-save { flex: 1; background: #9ece6a; color: #1a1b26; }
.nsd-btn-cancel { flex: 1; background: #565f89; color: #c0caf5; }
.nsd-textarea { width: 100%; min-height: 150px; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-secondary); color: var(--text); font-size: 14px; resize: vertical; box-sizing: border-box; }
.nsd-input { width: 100%; padding: 8px; margin-top: 4px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-secondary); color: var(--text); font-size: 14px; box-sizing: border-box; }
/* 侧边栏搜索按钮统一样式 */
.sidebar-search-btn { width:100%; padding:10px 12px; background:transparent; border:none; color:#c0caf5; font-size:14px; text-align:left; cursor:pointer; border-bottom:1px solid #3b4261; -webkit-tap-highlight-color:transparent; }
.sidebar-search-btn:active { background:var(--bg-secondary); }

/* ===== 枝条搜索浮层（与笔记搜索浮层同结构）===== */
#branch-search-panel { position:fixed; top:0; left:0; right:0; bottom:0; background:var(--bg); z-index:1500; display:flex; flex-direction:column; animation:noteSearchSlideDown 0.25s ease; }
#branch-search-header { display:flex; align-items:center; justify-content:space-between; padding:12px 16px; background:var(--bg-secondary); border-bottom:1px solid var(--border); }
#branch-search-header h3 { margin:0; font-size:16px; color:var(--accent); }
#branch-search-input-area { display:flex; gap:8px; padding:10px 16px; background:var(--bg-secondary); border-bottom:1px solid var(--border); }
#branch-search-input-area input { flex:1; padding:8px 12px; border-radius:8px; border:1px solid var(--border); background:var(--bg-tertiary); color:var(--text); font-size:14px; }
#branch-search-input-area input:focus { outline:none; border-color:var(--accent); }
#branch-search-results { flex:1; overflow-y:auto; padding:12px 16px; -webkit-overflow-scrolling:touch; }
#branch-search-detail { flex:1; overflow-y:auto; padding:12px 16px; -webkit-overflow-scrolling:touch; }
/* 草稿卡片标签 */
.draft-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.draft-tag-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    background: rgba(122,162,247,0.15);
    color: var(--accent);
    border: 1px solid rgba(122,162,247,0.3);
}
.draft-tag-edit { margin: 6px 0; }
.draft-tag-input {
    width: 100%;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--text-muted);
    background: var(--bg-tertiary);
    color: var(--text);
    font-size: 13px;
    box-sizing: border-box;
}
#note-context-banner {
    padding: 6px 12px;
    background: rgba(122, 162, 247, 0.15);
    border-top: 1px solid rgba(122, 162, 247, 0.3);
    font-size: 13px;
    color: #7aa2f7;
    display: flex;
    align-items: center;
}

/* ===== 新搜索浮层（与枝条/笔记搜索浮层同结构）===== */
#plan-search-panel, #rawinput-search-panel, #todo-search-panel, #taskcard-search-panel, #schedule-search-panel, #settings-panel {
    position:fixed; top:0; left:0; right:0; bottom:0; background:var(--bg); z-index:1500; display:flex; flex-direction:column; animation:noteSearchSlideDown 0.25s ease;
}
#plan-search-header, #rawinput-search-header, #todo-search-header, #taskcard-search-header, #schedule-search-header, #settings-header {
    display:flex; align-items:center; justify-content:space-between; padding:12px 16px; background:var(--bg-secondary); border-bottom:1px solid var(--border);
}
#plan-search-header h3, #rawinput-search-header h3, #todo-search-header h3, #taskcard-search-header h3, #schedule-search-header h3, #settings-header h3 {
    margin:0; font-size:16px; color:var(--accent);
}
#plan-search-input-area, #rawinput-search-input-area, #todo-search-input-area, #taskcard-search-input-area, #schedule-search-input-area {
    display:flex; gap:8px; padding:10px 16px; background:var(--bg-secondary); border-bottom:1px solid var(--border);
}
#plan-search-input-area input, #rawinput-search-input-area input, #todo-search-input-area input, #taskcard-search-input-area input, #schedule-search-input-area input {
    flex:1; padding:8px 12px; border-radius:8px; border:1px solid var(--border); background:var(--bg-tertiary); color:var(--text); font-size:14px;
}
#plan-search-input-area input:focus, #rawinput-search-input-area input:focus, #todo-search-input-area input:focus, #taskcard-search-input-area input:focus, #schedule-search-input-area input:focus {
    outline:none; border-color:var(--accent);
}
#plan-search-results, #rawinput-search-results, #todo-search-results, #taskcard-search-results, #schedule-search-results, #settings-results {
    flex:1; overflow-y:auto; padding:12px 16px; -webkit-overflow-scrolling:touch;
}
#plan-search-detail {
    flex:1; overflow-y:auto; padding:12px 16px; -webkit-overflow-scrolling:touch;
}
#taskcard-search-detail {
    flex:1; overflow-y:auto; padding:12px 16px; -webkit-overflow-scrolling:touch;
}
/* 新建表单内嵌样式 */
.create-form-area { background: var(--bg-secondary); border-radius: 10px; padding: 16px; margin: 8px 0; }
/* 子任务样式 */
.subtask-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    margin: 4px 0;
    background: rgba(255,255,255,0.03);
    border-radius: 6px;
    font-size: 13px;
}
.subtask-item:hover {
    background: rgba(255,255,255,0.06);
}
.subtask-status {
    font-size: 12px;
    white-space: nowrap;
    color: var(--text-muted);
}
.subtask-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}
.subtask-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    color: #4ade80;
}
.subtask-btn:hover {
    color: #22c55e;
    background: rgba(74,222,128,0.1);
}
