/* --- 纳西妲主题变量 --- */
:root {
    --primary-green: #7dc476;
    --dark-green: #4a8f5d;
    --light-green-bg: rgba(125, 196, 118, 0.15);
    --danger-red: #ff5f56;
    
    --user-bubble-bg: #8bc34a;
    --user-text-color: #ffffff;
    --ai-bubble-bg: rgba(255, 255, 255, 0.96);
    --ai-text-color: #333333;

    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: 1px solid rgba(255, 255, 255, 0.6);
    --blur-amt: 15px;
    
    --bg-gradient: linear-gradient(135deg, #fdfbf7 0%, #eaf7e8 100%);
    --avatar-ai: url('https://i0.hdslb.com/bfs/article/1f5053074558229c1d68305c45300f2832863899.jpg'); 
    --avatar-user: url('https://upload-os-bbs.hoyolab.com/upload/2021/05/10/6803247/e1124d5573435133d18c3b4a45a3152d_4408375423871404179.png?x-oss-process=image/resize,s_1000/quality,q_80/auto-orient,0/interlace,1/format,png');
    --bg-image: url('https://images.alphacoders.com/128/1286992.jpg'); 
}

* { box-sizing: border-box; }

body {
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
    margin: 0; padding: 0;
    height: 100dvh; width: 100vw;
    background: #000000; 
    /* background: var(--bg-image) no-repeat center center fixed; background-size: cover; */
    display: flex; justify-content: center; overflow: hidden;
    color: #444;
}

/* --- 主容器 --- */
#app {
    width: 100%; max-width: 950px; height: 100%;
    display: flex; flex-direction: column;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(5px);
    position: relative;
    box-shadow: 0 0 30px rgba(78, 168, 88, 0.2);
}

@media (min-width: 768px) {
    #app { height: 92vh; margin-top: 4vh; border-radius: 20px; border: 1px solid rgba(255,255,255,0.8); }
}

/* --- 头部 Header --- */
header {
    flex-shrink: 0; height: 56px; padding: 0 15px;
    display: flex; align-items: center; justify-content: space-between;
    background: var(--glass-bg); backdrop-filter: blur(var(--blur-amt));
    border-bottom: var(--glass-border); z-index: 100;
    border-radius: 20px 20px 0 0;
}
@media (max-width: 768px) { header { border-radius: 0; } }

.header-left { display: flex; align-items: center; gap: 15px; }
#mobile-menu-trigger {
    font-size: 20px; cursor: pointer; background: none; border: none; padding: 0;
    color: var(--primary-green); transition: transform 0.3s;
}
.header-title { font-size: 16px; font-weight: bold; color: var(--dark-green); }

/* --- 菜单系统 --- */
.desktop-menu { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 0; scrollbar-width: none; }
.desktop-menu::-webkit-scrollbar { display: none; }

.menu-item {
    cursor: pointer; padding: 6px 12px; border-radius: 15px;
    color: #666; font-weight: 500; transition: all 0.2s;
    display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap;
}
.menu-item:hover { background: var(--light-green-bg); color: var(--dark-green); }
.menu-item.active { background: var(--primary-green); color: white; box-shadow: 0 2px 5px rgba(125, 196, 118, 0.4); }

/* 手机主菜单侧边栏 */
.mobile-menu-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.3); z-index: 999;
    opacity: 0; visibility: hidden; transition: all 0.3s;
}
.mobile-menu-sidebar {
    position: absolute; top: 0; left: -260px;
    width: 260px; height: 100%;
    background: rgba(255,255,255,0.98);
    display: flex; flex-direction: column; padding: 20px;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 5px 0 15px rgba(0,0,0,0.1);
}
.mobile-menu-overlay.open { opacity: 1; visibility: visible; }
.mobile-menu-overlay.open .mobile-menu-sidebar { left: 0; }

.mobile-nav-item {
    padding: 12px 15px; margin-bottom: 5px; border-radius: 10px;
    font-size: 15px; color: #555; cursor: pointer; display: flex; align-items: center; gap: 12px;
}
.mobile-nav-item.active { background: var(--primary-green); color: white; }

@media (max-width: 850px) {
    .desktop-menu { display: none; }
    #mobile-menu-trigger { display: block; }
}
@media (min-width: 851px) {
    #mobile-menu-trigger { display: none; }
}

/* --- 通用列表卡片样式 --- */
.view-section { flex: 1; display: none; flex-direction: column; overflow: hidden; position: relative; }
.view-section.active-view { display: flex; }

.list-container {
    flex: 1; overflow-y: auto; padding: 20px;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 15px;
    align-content: start;
}

.common-card {
    background: rgba(255,255,255,0.7); border-radius: 12px; padding: 15px;
    border: 2px solid transparent; transition: all 0.2s; cursor: pointer;
    position: relative; display: flex; flex-direction: column; min-height: 100px;
}
.common-card:hover { transform: translateY(-2px); background: rgba(255,255,255,0.9); }
.common-card.active {
    border-color: var(--primary-green); background: rgba(255,255,255,0.95);
    box-shadow: 0 5px 15px rgba(125, 196, 118, 0.3);
}
.card-tag {
    position: absolute; top: 10px; right: 10px; font-size: 11px;
    background: var(--primary-green); color: white; padding: 2px 6px; border-radius: 4px;
}

/* --- 聊天相关 --- */
#chat-view { position: relative; }

/* 聊天历史侧边栏 */
.history-sidebar {
    position: absolute; top: 0; left: 0; width: 260px; height: 100%;
    background: rgba(255,255,255,0.96); border-right: 1px solid rgba(0,0,0,0.1);
    transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50; display: flex; flex-direction: column;
    backdrop-filter: blur(10px);
}
.history-sidebar.open { transform: translateX(0); box-shadow: 5px 0 15px rgba(0,0,0,0.05); }
.history-header { padding: 15px; border-bottom: 1px solid #eee; display:flex; justify-content:space-between; align-items:center; }
.history-list { flex: 1; overflow-y: auto; padding: 10px; }
.history-item {
    padding: 10px 15px; border-radius: 8px; cursor: pointer; margin-bottom: 5px;
    font-size: 14px; color: #555; display: flex; justify-content: space-between; align-items: center;
}
.history-item:hover { background: #f5f5f5; }
.history-item.active { background: var(--light-green-bg); color: var(--dark-green); font-weight: bold; }
.history-delete { opacity: 0; color: #999; transition: opacity 0.2s; }
.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { color: var(--danger-red); }

/* 聊天气泡区域 */
#chat-container {
    flex: 1; overflow-y: auto; padding: 20px; padding-bottom: 40px;
    display: flex; flex-direction: column; gap: 20px; scroll-behavior: smooth;
}

.message-row { display: flex; gap: 10px; max-width: 100%; animation: fadeIn 0.3s ease-out; }
.message-row.user { flex-direction: row-reverse; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.msg-avatar {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    background-size: cover; border: 2px solid rgba(255,255,255,0.8); background-color: #fff;
    background-position: center;
    /* Fallback text centering */
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: bold; color: #666;
}
/* Remove old variable usage as we set it inline now */
/* .message-row.ai .msg-avatar { background-image: var(--avatar-ai); } */
/* .message-row.user .msg-avatar { background-image: var(--avatar-user); } */

.msg-avatar.text-avatar {
    background-color: #f0f0f0;
    color: var(--primary-green);
    border: 2px solid var(--primary-green);
}
.message-row.user .msg-avatar.text-avatar {
    background-color: #8bc34a;
    color: white;
    border: 2px solid white;
}

.bubble {
    max-width: 85%; padding: 12px 16px; border-radius: 18px; font-size: 15px; line-height: 1.6;
    position: relative; box-shadow: 0 4px 15px rgba(0,0,0,0.05); word-wrap: break-word;
    border: 1px solid rgba(255,255,255,0.5);
    transition: all 0.2s ease;
}
.bubble:hover { box-shadow: 0 6px 20px rgba(0,0,0,0.08); }

.message-row.ai .bubble { 
    background: linear-gradient(145deg, #ffffff, #f0f7f0); 
    color: var(--ai-text-color); 
    border-top-left-radius: 4px; 
}
.message-row.user .bubble { 
    background: linear-gradient(135deg, #8bc34a, #7cb342); 
    color: var(--user-text-color); 
    border-top-right-radius: 4px; 
    box-shadow: 0 4px 15px rgba(139, 195, 74, 0.3);
}
.bubble img { max-width: 100%; border-radius: 8px; margin-top: 8px; display: block; }

/* 输入区 */
#input-area {
    flex-shrink: 0; padding: 10px 15px;
    background: var(--glass-bg); backdrop-filter: blur(var(--blur-amt));
    border-top: var(--glass-border); border-radius: 0 0 20px 20px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
@media (max-width: 768px) { #input-area { border-radius: 0; } }

.input-wrapper {
    display: flex; gap: 10px; align-items: flex-end;
    background: rgba(255,255,255,0.6); padding: 8px 12px; border-radius: 24px;
    border: 1px solid rgba(255,255,255,0.6);
}
textarea { flex: 1; padding: 6px 0; border: none; background: transparent; resize: none; height: 24px; max-height: 80px; font-family: inherit; font-size: 15px; outline: none; }

/* 聊天顶部工具条 */
.header-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
    background: none; border: none; font-size: 18px; color: #555; cursor: pointer;
    width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    transition: background 0.2s, color 0.2s;
}
.icon-btn:hover { background: rgba(0,0,0,0.05); color: var(--primary-green); }

/* --- 底部工具栏 --- */
.toolbar {
    padding: 15px; background: var(--glass-bg); border-top: var(--glass-border);
    display: flex; gap: 10px; justify-content: center;
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
}
.tool-btn {
    background: white; border: 1px solid var(--primary-green); color: var(--primary-green);
    padding: 8px 15px; border-radius: 20px; cursor: pointer; font-size: 14px;
    display: flex; align-items: center; gap: 5px;
}
.tool-btn.primary { background: var(--primary-green); color: white; }
.tool-btn.danger { border-color: var(--danger-red); color: var(--danger-red); }

/* --- 弹窗/设置 --- */
.modal-overlay {
    position: fixed; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.4); z-index: 200;
    display: flex; justify-content: center; align-items: center;
    opacity: 0; visibility: hidden; transition: all 0.2s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal-box {
    background: white; width: 90%; max-width: 500px; padding: 20px;
    border-radius: 15px; display: flex; flex-direction: column; gap: 12px;
    max-height: 80vh; overflow-y: auto;
}
.modal-title { font-weight: bold; font-size: 18px; color: var(--dark-green); }
.modal-input { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 8px; font-family: inherit; }
.modal-textarea { width: 100%; height: 120px; padding: 10px; border: 1px solid #ddd; border-radius: 8px; font-family: inherit; resize: none; }

.range-wrap { display: flex; flex-direction: column; gap: 5px; margin-bottom: 15px; }
.range-header { display: flex; justify-content: space-between; font-size: 14px; font-weight: bold; color: #555; }
input[type=range] { width: 100%; accent-color: var(--primary-green); }

.typing-dot { display: inline-block; width: 5px; height: 5px; background: #999; border-radius: 50%; margin-right: 3px; animation: typing 1.4s infinite ease-in-out both; }
.typing-dot:nth-child(1) { animation-delay: -0.32s; } .typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* --- 消息操作与编辑样式 --- */
.bubble-wrapper {
    max-width: 85%;
    display: flex;
    flex-direction: column;
}
.message-row.user .bubble-wrapper { align-items: flex-end; }
.message-row.ai .bubble-wrapper { align-items: flex-start; }

/* 让 bubble 宽度填满 wrapper */
.bubble { max-width: 100%; }

.msg-actions {
    display: flex; gap: 8px; margin-top: 4px;
    opacity: 1; /* Always visible */
    padding: 0 5px;
}
/* 移动端或悬停时显示 - No longer needed, always visible */
/* .message-row:hover .msg-actions { opacity: 1; } */

.msg-action-btn {
    background: none; border: none; padding: 2px;
    color: #999; cursor: pointer; font-size: 13px;
}
.msg-action-btn:hover { color: var(--primary-green); }

/* --- 消息切换导航 (Swipe Nav) --- */
.swipe-nav {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    margin-top: 5px; user-select: none;
}
.swipe-btn {
    background: none; border: none; color: #999; cursor: pointer;
    font-size: 14px; padding: 2px 8px; transition: color 0.2s;
}
.swipe-btn:hover { color: var(--primary-green); }
.swipe-counter { font-size: 12px; color: #999; }

/* --- Timeline Scrollbar --- */
#chat-timeline {
    position: absolute;
    top: 60px; /* Below top bar */
    bottom: 80px; /* Above input area */
    right: 2px;
    width: 12px;
    display: flex;
    flex-direction: column;
    z-index: 90;
    pointer-events: none; /* Let clicks pass through if empty space */
}
.timeline-node {
    flex: 1; /* Distribute space equally? No, proportional to height? 
                Or just stack them? 
                The user wants "Every message generates a node".
                If there are many messages, flex:1 works to fit them all.
                */
    width: 8px;
    margin: 1px auto;
    border-radius: 4px;
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.2s, background-color 0.2s;
    opacity: 0.6;
}
.timeline-node:hover {
    transform: scaleX(1.5);
    opacity: 1;
}
.timeline-node.user { background-color: #ddd; }
.timeline-node.ai { background-color: var(--primary-green); }
.timeline-node.active { opacity: 1; width: 10px; box-shadow: 0 0 4px rgba(0,0,0,0.2); }

.message-editor {
    width: 100%; min-width: 240px; min-height: 60px;
    padding: 8px; border: 1px solid var(--primary-green);
    border-radius: 8px; outline: none; font-family: inherit;
    background: rgba(255,255,255,0.95); font-size: 14px;
    resize: vertical; color: #333;
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}
.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}
input:checked + .slider {
  background-color: var(--primary-green);
}
input:focus + .slider {
  box-shadow: 0 0 1px var(--primary-green);
}
input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}
.slider.round {
  border-radius: 34px;
}
.slider.round:before {
  border-radius: 50%;
}

/* --- Mobile Chat Optimization --- */
@media (max-width: 768px) {
    #chat-container {
        padding: 10px 5px; /* Reduce horizontal padding significantly */
    }
    .bubble-wrapper {
        max-width: 92%; /* Use more width */
    }
    .message-row {
        gap: 6px;
    }
    .msg-avatar {
        width: 32px; height: 32px;
    }
    /* Ensure user messages don't leave a huge gap on the left */
    .message-row.user {
        padding-left: 0;
    }
    /* Ensure AI messages don't leave a huge gap on the right */
    .message-row.ai {
        padding-right: 0;
    }
    /* Allow AI bubbles (replies) to expand to the right edge */
    .message-row.ai .bubble-wrapper {
        max-width: 100%;
    }
    
    /* Hide AI avatar on mobile to align bubble to left edge */
    .message-row.ai .msg-avatar {
        display: none;
    }
    .message-row.ai {
        padding-left: 0;
    }
    
    /* API Model Group Mobile Visibility */
    .api-model-group-desktop { display: none !important; }
    .api-model-group-mobile { display: block !important; }
}

/* Desktop default */
.api-model-group-desktop { display: flex; gap: 10px; }
.api-model-group-mobile { display: none; }

/* Sidebar Trigger */
.history-trigger {
    position: fixed;
    left: 0;
    top: 80px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.8);
    border-left: none;
    border-radius: 0 12px 12px 0;
    padding: 16px 12px;
    cursor: pointer;
    z-index: 49;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    box-shadow: 4px 0 15px rgba(78, 168, 88, 0.15);
    /* Removed 'all' transition to prevent lag when dragging 'top' */
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s, background 0.3s, box-shadow 0.3s, padding-right 0.3s;
    width: auto;
    touch-action: none;
    user-select: none;
}

.history-trigger:hover {
    background: white;
    box-shadow: 4px 0 20px rgba(78, 168, 88, 0.25);
    padding-right: 16px;
}

.trigger-text {
    font-size: 13px;
    color: var(--dark-green);
    letter-spacing: 1px;
    font-weight: bold;
    white-space: nowrap;
}

.trigger-icon {
    color: var(--primary-green);
    font-size: 14px;
    transition: transform 0.3s;
}

/* When sidebar is open, hide trigger */
.history-trigger.open {
    left: -100px;
    opacity: 0;
    pointer-events: none;
}
