:root {
    --primary-color: #1A73E8;
    --primary-hover: #1557B0;
    --bg-color: #F8F9FA;
    --border-color: #E0E0E5;
    --text-primary: #202124;
    --text-secondary: #5F6368;
    --hover-bg: #F1F3F4;
    --selected-bg: #E8F0FE;
    --white: #FFFFFF;
}

* {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    overflow: hidden;
    color: var(--text-primary);
}

/* Utils */
.text-blue { color: #4285F4 !important; }
.text-green { color: #34A853 !important; }
.text-yellow { color: #FBBC04 !important; }
.text-gray { color: #5F6368 !important; }

/* App Container */
.app-container {
    display: flex;
    height: calc(100vh - 70px); /* 减去导航栏高度 */
    width: 100%;
    background: #fff;
    overflow: hidden; /* 关键：限制整体高度，防止内容撑开 */
}

/* ==========================================================================
   Far Left Sidebar (Icons)
   ========================================================================== */
.nav-strip {
    width: 60px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    background: #fff;
    flex-shrink: 0;
    z-index: 100;
}

.nav-item {
    width: 40px;
    height: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 8px;
    margin-bottom: 8px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.nav-item i {
    font-size: 20px;
    margin-bottom: 2px;
}

.nav-item span {
    font-size: 10px;
    transform: scale(0.9);
}

.nav-item:hover {
    background-color: var(--hover-bg);
}

.nav-item.active {
    background-color: var(--primary-color);
    color: #fff;
}

.nav-item.active span {
    color: #fff;
}

/* 新建会话按钮样式 */
.nav-new-session {
    background: linear-gradient(135deg, #3b82f6, #2563eb) !important;
    color: #fff !important;
    margin-bottom: 12px !important;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.nav-new-session:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.nav-new-session i {
    font-size: 18px;
}

.nav-new-session span {
    color: #fff !important;
}

.spacer {
    flex: 1;
}

/* ==========================================================================
   Left Sidebar (List)
   ========================================================================== */
.left-sidebar {
    width: 280px; /* 固定初始宽度，支持拖拽调整 */
    min-width: 200px;
    max-width: 400px;
    background: #fff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    flex-shrink: 0;
    overflow: hidden; /* 限制高度 */
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* 防止被压缩 */
}

.sidebar-title {
    font-size: 16px;
    font-weight: 500;
    margin: 0;
    color: var(--text-primary);
}

.btn-new-research {
    background-color: var(--primary-color);
    font-size: 12px;
    padding: 0 12px;
    height: 32px;
    line-height: 32px;
}

.list-area {
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* 关键：让 flex 子元素能正确计算高度 */
}

.list-item {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.list-item:hover {
    background-color: var(--hover-bg);
}

.list-item.active {
    background-color: var(--selected-bg);
    border-left: 3px solid var(--primary-color); /* Added active indicator */
}

.item-title {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 12px;
    font-weight: 500;
    line-height: 1.4;
}

.item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.timestamp {
    font-size: 12px;
    color: var(--text-secondary);
}

.status-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.status-badge.done {
    background-color: #E6F4EA;
    color: #1E8E3E;
}

.status-badge.doing {
    background-color: #FEF7E0;
    color: #F9AB00;
}

/* ==========================================================================
   Middle Panel
   ========================================================================== */
.middle-panel {
    flex: 1;
    background: #fff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 300px; /* 降低最小宽度，允许右侧面板有更大的调整空间 */
    overflow: hidden; /* 关键：限制高度，防止内容撑开 */
}

.panel-header {
    padding: 20px 24px 10px; /* Adjusted padding */
    flex-shrink: 0; /* 防止被压缩 */
}

.panel-title {
    font-size: 20px;
    color: var(--text-primary);
    margin: 0;
    font-weight: 500;
}

/* Custom Tabs */
.custom-tab .layui-tab-title {
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    height: 48px;
}

.custom-tab .layui-tab-title li {
    font-size: 14px;
    color: var(--text-secondary);
    min-width: unset;
    padding: 0 16px;
    line-height: 48px;
}

.custom-tab .layui-tab-title .layui-this {
    color: var(--primary-color);
    font-weight: 500;
}

.custom-tab .layui-tab-title .layui-this:after {
    border-bottom: 2px solid var(--primary-color);
    height: 48px;
}

/* 自定义 Tab 容器 - 必须是 flex 容器并限制高度 */
.custom-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 关键：限制高度 */
    min-height: 0; /* 关键：让 flex 子元素能正确计算高度 */
}

.custom-tab .layui-tab-content {
    padding: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 关键：限制高度 */
    min-height: 0; /* 关键：让 flex 子元素能正确计算高度 */
}

/* 覆盖 Layui 默认样式 */
.custom-tab .layui-tab-item {
    height: 100% !important;
    display: none !important;
    overflow: hidden !important;
}

.custom-tab .layui-tab-item.layui-show {
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

/* 确保标签标题栏不被压缩 */
.custom-tab .layui-tab-title {
    flex-shrink: 0;
}

/* Search Section */
.search-section {
    padding: 24px;
    flex-shrink: 0; /* 防止被压缩，确保固定高度 */
}

.search-box-wrapper {
    position: relative;
    margin-bottom: 16px;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: #9AA0A6;
    font-size: 20px;
}

.search-input-large {
    width: 100%;
    height: 48px;
    padding: 10px 16px 10px 48px;
    font-size: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    outline: none;
    transition: all 0.2s;
}

.search-input-large:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px var(--primary-color);
}

.search-options-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.options-left {
    display: flex;
    gap: 12px;
}

.option-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    height: 32px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.option-pill:hover {
    background-color: var(--hover-bg);
}

.option-pill.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.option-pill.active i {
    color: #fff;
}

#btn-start-search {
    padding: 0 24px;
    height: 32px;
    line-height: 32px;
    font-size: 13px;
}

.divider-line {
    height: 1px;
    background-color: var(--border-color);
    margin: 0 24px;
    flex-shrink: 0; /* 防止被压缩 */
}

.add-source-wrapper {
    padding: 12px 24px;
}

.btn-add-source {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px dashed var(--border-color);
    border-radius: 6px;
    background: #fff;
    color: var(--text-secondary);
    width: 100%;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
}

.btn-add-source:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #F8FBFF;
}

/* Search Results */
.search-results-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 24px;
    min-height: 0; /* 关键：让 flex 子元素能够正确计算高度，使 overflow 生效 */
}

.result-card {
    display: flex;
    align-items: center;
    padding: 16px;
    border-radius: 8px;
    transition: background-color 0.2s;
    margin-bottom: 4px;
}

.result-card:hover {
    background-color: var(--hover-bg);
}

.card-icon-wrapper {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-right: 16px;
    flex-shrink: 0;
}

.card-icon-wrapper i {
    font-size: 18px;
}

.card-content {
    flex: 1;
}

.card-title {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 400;
}

.card-check {
    padding-left: 12px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 0;
    color: var(--text-secondary);
}

.empty-icon-bg {
    width: 64px;
    height: 64px;
    background: var(--hover-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.empty-icon-bg i {
    font-size: 32px;
    color: #9AA0A6;
}

.sub-text {
    font-size: 12px;
    color: #9AA0A6;
    margin-top: 4px;
}

/* ==========================================================================
   Right Panel
   ========================================================================== */
.right-panel {
    width: 450px; /* 固定初始宽度，支持拖拽调整 */
    background: #fff;
    display: flex;
    flex-direction: column;
    min-width: 300px;
    /* max-width 由 JavaScript 动态控制，确保中间层不小于最小宽度 */
    flex-shrink: 0; /* 防止被压缩 */
    overflow: hidden; /* 限制高度 */
}

.right-panel .panel-header {
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* 防止被压缩 */
}

.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: #fff;
    min-height: 0; /* 关键：让 flex 子元素能正确计算高度 */
}

.message {
    display: flex;
    gap: 16px;
    margin-bottom: 32px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 500;
}

.avatar.user {
    background: var(--primary-color);
    color: #fff;
}

.avatar.ai {
    background: #fff;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.msg-content {
    flex: 1;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
}

/* Markdown-like styling for AI response */
.msg-content p {
    margin-bottom: 12px;
}

.msg-content h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 16px 0 8px;
}

/* Bottom Input Area */
.bottom-input-container {
    padding: 0 24px 24px;
    border-top: 1px solid var(--border-color);
    background: #fff;
}

.suggestion-chips {
    display: flex;
    gap: 12px;
    padding: 16px 0;
    overflow-x: auto;
}

.chip {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    background: #fff;
    transition: all 0.2s;
}

.chip:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
    border-color: #DADCE0;
}

.input-area-box {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 16px;
    position: relative;
    background: #fff;
    transition: border-color 0.2s;
}

.input-area-box:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px var(--primary-color);
}

.chat-textarea {
    width: 100%;
    border: none;
    resize: none;
    height: 60px; /* Adjust height */
    font-size: 14px;
    outline: none;
    font-family: inherit;
    padding-right: 40px;
    color: var(--text-primary);
}

.send-btn-round {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%; /* Round button */
    background: var(--primary-color);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.send-btn-round:hover {
    background: var(--primary-hover);
}

.selected-tags-inline {
    margin-bottom: 8px;
    padding-bottom: 4px;
    /* border-bottom: 1px solid #f0f0f0; Removed border to make it cleaner */
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tags-header {
    width: 100%;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tags-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}

.selected-tag-chip {
    display: flex;
    align-items: center;
    background: #E8F0FE;
    color: #1A73E8;
    border: 1px solid #D2E3FC;
    border-radius: 16px; /* Pill shape */
    padding: 2px 8px 2px 10px;
    font-size: 12px;
    max-width: 100%;
}

.selected-tag-chip .tag-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

.selected-tag-chip .tag-remove {
    margin-left: 4px;
    cursor: pointer;
    padding: 2px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.selected-tag-chip .tag-remove:hover {
    background-color: rgba(26, 115, 232, 0.1);
}

/* Resizers */
.resizer {
    width: 12px; /* 增加宽度便于拖拽和选中 */
    background: transparent;
    cursor: col-resize;
    position: absolute;
    top: 0;
    bottom: 0;
    right: -6px; /* 居中显示在边框上（宽度的一半） */
    z-index: 100; /* 提高层级确保可点击 */
    transition: background 0.2s;
}

.resizer:hover,
.resizer:active {
    background: var(--primary-color);
}

/* 拖拽时的全局样式 */
body.resizing {
    cursor: col-resize !important;
    user-select: none !important;
}

body.resizing * {
    cursor: col-resize !important;
}

/* Layui Override */
.layui-form-checkbox[lay-skin=primary]:hover i {
    border-color: var(--primary-color);
}
.layui-form-checked[lay-skin=primary] i {
    border-color: var(--primary-color) !important;
    background-color: var(--primary-color) !important;
}

/* AI Action Buttons */
.ai-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    background: none;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.action-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

/* Selected Data Tab Styles */
.selected-layout {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.selected-top {
    flex: 2;
    overflow-y: auto;
    padding: 0;
}

.dataset-card-row {
    padding: 16px 24px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.dataset-card-row:hover {
    background-color: var(--hover-bg);
}

.selected-bottom {
    flex: 1;
    background: #F8F9FA;
    border-top: 1px solid var(--border-color);
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
}

.section-header-small {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 12px;
}
