:root {
    --primary-blue: #1A56DB;
    --primary-hover: #1e429f;
    --light-blue: #E1EFFE;
    --bg-gray: #EDEEF1;
    --border-color: #E5E7EB;
    --text-main: #111827;
    --text-gray: #4B5563;
    --danger-red: #E02424;
    --success-green: #059669;

    /* 侧边栏 */
    --sidebar-bg: #F0F4FA;
    --sidebar-hover: #E2E8F4;
    --sidebar-active: #1A56DB;
    --sidebar-text: #374151;
    --sidebar-text-muted: #6B7280;
    --sidebar-border: #E2E8F0;

    /* 统一阴影 */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 24px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);

    /* 统一圆角 */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: "Microsoft YaHei", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

body { background-color: var(--bg-gray); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* ======== 统一样式组件 (按钮/表单均衡化) ======== */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 16px; font-size: 13px; font-weight: 500; border-radius: var(--radius-sm); cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s; border: 1px solid transparent; height: 34px; white-space: nowrap; }
.btn-primary { background: var(--primary-blue); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #fff; border-color: var(--border-color); color: var(--text-main); }
.btn-secondary:hover { background: var(--bg-gray); }
.btn-outline { background: transparent; border-color: var(--primary-blue); color: var(--primary-blue); }
.btn-outline:hover { background: var(--light-blue); }
.btn-text { background: none; color: var(--primary-blue); border: none; padding: 0; height: auto; font-size: 12px; }
.btn-text:hover { text-decoration: underline; }
.btn-icon { padding: 4px 8px; font-size: 12px; height: 28px; }

.form-input, .form-select { width: 100%; padding: 8px 12px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); outline: none; font-size: 13px; color: var(--text-main); height: 34px; transition: border-color 0.15s; }
.form-input:focus, .form-select:focus { border-color: var(--primary-blue); }
textarea.form-input { height: 80px; resize: none; padding: 10px 12px; }

/* ======== 顶部栏 ======== */
.top-header { background: #fff; min-height: 60px; display: grid; grid-template-columns: minmax(170px, 1fr) minmax(280px, auto) minmax(220px, 1fr); align-items: center; gap: 16px; padding: 0 20px; border-bottom: 1px solid var(--border-color); z-index: 10; box-shadow: var(--shadow-sm); }
.header-left { min-width: 0; }
.header-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-brand img { width: 104px; height: 34px; object-fit: contain; object-position: left center; display: block; flex-shrink: 0; }
.header-center { flex: 1; text-align: center; }
.header-center h1 { color: var(--primary-blue); font-size: 20px; letter-spacing: 1px; white-space: nowrap;}
.date-range { font-size: 12px; color: var(--text-gray); margin-top: 4px; }
.header-right { min-width: 0; display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.header-user { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: #6B7280; }
.logout-btn { font-size: 12px; padding: 4px 10px; height: 28px; }
.header-action { min-width: 92px; }
.version-badge { background: var(--light-blue); color: var(--primary-blue); padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: bold; }
.badge { background: var(--danger-red); color: white; padding: 0 6px; border-radius: 10px; font-size: 11px; margin-left: 4px; line-height: 16px;}

/* ======== 整体布局与侧边栏 ======== */
.app-container { display: flex; flex: 1; overflow: hidden; }

.sidebar { width: 240px; background: var(--sidebar-bg); border-right: 1px solid var(--sidebar-border); display: flex; flex-direction: column; flex-shrink: 0; }

.view-menu { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.view-btn { padding: 10px 12px; border: none; background: transparent; text-align: left; font-size: 13.5px; cursor: pointer; border-radius: var(--radius-sm); color: var(--sidebar-text); font-weight: 500; }
.view-btn:hover { background: var(--sidebar-hover); color: var(--text-main); }
.view-btn.active { background: var(--sidebar-active); color: #fff; border-radius: var(--radius-sm); }

.divider { height: 1px; background: var(--sidebar-border); margin: 6px 12px; }

/* 左侧折叠树 */
.filter-tree { padding: 12px 10px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.tree-header { display: flex; justify-content: space-between; align-items: center; padding: 0 4px; }
.tree-header h3 { font-size: 11px; color: var(--sidebar-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.tree-header .btn-text { color: var(--sidebar-text-muted); font-size: 11px; }
.tree-group { margin-bottom: 4px; }
.tree-l1 { width: 100%; text-align: left; padding: 8px 10px; font-size: 13px; font-weight: 600; background: transparent; border: none; border-radius: var(--radius-sm); cursor: pointer; color: var(--sidebar-text); }
.tree-l1:hover { background: var(--sidebar-hover); }
.tree-l2-list { padding-left: 8px; display: none; flex-direction: column; gap: 2px; margin-top: 2px; }
.tree-l2-list.open { display: flex; }
.tree-l2-item { font-size: 12px; color: var(--sidebar-text-muted); cursor: pointer; padding: 5px 10px; border-radius: var(--radius-sm); }
.tree-l2-item:hover, .tree-l2-item.active { background: var(--sidebar-active); color: #fff; }

/* ======== 主内容区 & 双视窗自适应 ======== */
.main-content { flex: 1; display: flex; overflow: hidden; position: relative; background: var(--bg-gray); }
.view-section { flex: 1; padding: 16px; display: none; overflow: hidden; }
.view-section.active { display: flex; }
.flex-col { flex-direction: column; overflow-y: auto; }

/* ─── 周报面板 拖拽样式 ─── */
.wr-drag-ghost { opacity: 0.4 !important; background: #EFF6FF !important; }
.wr-drag-chosen { box-shadow: var(--shadow-md) !important; }
.wr-items-container { transition: background .1s; }
.wr-items-container.sortable-drag-over { background: #F0F9FF; }

/* 信息流面板 */
.stream-pane { flex: 1; background: #fff; border-radius: var(--radius-md); border: 1px solid var(--border-color); display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-sm); }
/* 草稿面板 */
.draft-pane { width: 0; background: #fff; display: flex; flex-direction: column; overflow: hidden; transition: width 0.3s ease; }
.draft-pane.open { width: clamp(360px, 34vw, 450px); flex-shrink: 0; border-left: 1px solid var(--border-color); box-shadow: var(--shadow-md); }

/* 拖拽分界线 */
.resize-handle { flex-shrink: 0; background: transparent; cursor: col-resize; position: relative; z-index: 5; transition: background 0.15s; }
.resize-handle::after { content: ''; position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%); width: 4px; border-radius: 2px; background: transparent; transition: background 0.15s; }
.resize-handle:hover::after, .resize-handle.dragging::after { background: var(--primary-blue); }
.resize-handle-sidebar { width: 5px; }
.resize-handle-pane { width: 5px; }

.pane-header { padding: 12px 16px; background: #fafbfc; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.pane-header h2 { font-size: 15px; color: var(--text-main); display: flex; align-items: center; gap: 8px; font-weight: 600; }
.stream-header { flex-direction: column; align-items: stretch; gap: 8px; }
.stream-title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-width: 0; }
.stream-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.stream-date-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.small-tool-btn { background:#EFF6FF; border:1px solid #BFDBFE; color:#1A56DB; padding:4px 12px; border-radius:var(--radius-sm); font-size:12px; cursor:pointer; white-space:nowrap; height: 28px; }
.small-tool-btn:hover { background:#DBEAFE; }

/* 高密度卡片 */
.compact-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--bg-gray); }
.compact-card { background: #fff; padding: 12px 15px; border-radius: var(--radius-md); border: 1px solid var(--border-color); display: flex; flex-direction: column; gap: 8px; position: relative; }
.compact-card:hover { border-color: #93C5FD; box-shadow: var(--shadow-sm); }
.card-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.score-badge { font-size: 12px; font-weight: bold; padding: 2px 8px; border-radius: 4px; cursor: help; position: relative; border: 1px solid transparent; }
.score-high { background: #FDF2F2; color: var(--danger-red); border-color: #FBC4C4; }
.score-mid { background: #FEF9C3; color: #854D0E; border-color: #FDE047; }
.score-low { background: #F0FDF4; color: var(--success-green); border-color: #BBF7D0; }
.score-badge .tooltip { display: none; position: absolute; top: 120%; left: 0; background: #fff; border: 1px solid var(--border-color); padding: 12px; width: 260px; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); z-index: 100; font-weight: normal; color: var(--text-main); font-size: 12px; line-height: 1.5; }
.score-badge:hover .tooltip { display: block; }

.card-title { font-size: 14px; font-weight: 600; color: var(--text-main); text-decoration: none; flex: 1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.card-title:hover { color: var(--primary-blue); }
.tag { font-size: 11px; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.tag-l1 { background: var(--text-main); color: #fff; }
.tag-l3 { border: 1px dashed var(--border-color); color: var(--text-gray); }

.card-bottom { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--text-gray); border-top: 1px dashed var(--border-color); padding-top: 8px; }
.card-actions { display: flex; gap: 8px; }
.btn-flywheel { color: var(--success-green); }

/* ── 事件聚类 ── */
.cluster-badge { cursor: pointer; font-size: 12px; color: #2563EB; background: #EFF6FF; border: 1px solid #BFDBFE; border-radius: 4px; padding: 2px 8px; user-select: none; white-space: nowrap; }
.cluster-badge:hover { background: #DBEAFE; }
.cluster-panel { border-top: 1px dashed #BFDBFE; margin-top: 6px; padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.cluster-panel-header { font-size: 11px; color: #6B7280; margin-bottom: 2px; }
.cluster-member { display: flex; align-items: baseline; gap: 8px; font-size: 12px; flex-wrap: nowrap; padding: 3px 4px; border-radius: 4px; }
.cluster-member:hover { background: #EFF6FF; }
.cluster-title { color: #2563EB; text-decoration: none; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cluster-title:hover { text-decoration: underline; }

/* ======== 专属详情视图 ======== */
.detail-content { background: #fff; border-radius: var(--radius-md); border: 1px solid var(--border-color); padding: 30px; margin-top: 15px; display: flex; flex-direction: column; gap: 20px; box-shadow: var(--shadow-sm); }
.detail-title { font-size: 22px; color: var(--text-main); margin-bottom: 10px;}
.detail-meta { display: flex; gap: 15px; color: var(--text-gray); font-size: 13px; border-bottom: 1px solid var(--border-color); padding-bottom: 15px; }
.detail-box { background: #f8fafc; border-radius: var(--radius-md); padding: 20px; border-left: 4px solid var(--primary-blue); }
.detail-box h4 { margin-bottom: 10px; color: var(--primary-hover); }
.detail-box p { font-size: 14px; line-height: 1.6; color: var(--text-main); }
.detail-link { margin-top: 20px; text-align: center; }

/* ======== 飞轮纠偏视图 ======== */
.flywheel-stats { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 14px; margin: 15px 0; }
.stat-card { flex: 1; background: #fff; padding: 20px; border-radius: var(--radius-md); border: 1px solid var(--border-color); text-align: center; }
.stat-card h3 { font-size: 14px; color: var(--text-gray); margin-bottom: 10px; }
.stat-card p { font-size: 24px; font-weight: bold; color: var(--primary-blue); }
.flywheel-logs { background: #fff; border-radius: var(--radius-md); border: 1px solid var(--border-color); padding: 20px; flex: 1; overflow-y: auto; }
.data-table { width: 100%; border-collapse: collapse; margin-top: 15px; font-size: 13px; }
.data-table th, .data-table td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border-color); }
.data-table th { background: #f8fafc; color: var(--text-gray); font-weight: 500; }
.data-table th, .data-table td { vertical-align: middle; }

#review-view .data-table { margin-top: 0; table-layout: fixed; }
#review-view .data-table th,
#review-view .data-table td { white-space: nowrap; }
#review-view .data-table td:first-child { min-width: 190px; }

#dbStatsContainer { background: #fff; }

/* ======== 飞轮弹窗 ======== */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.45); display: flex; justify-content: center; align-items: center; z-index: 1000; }
.modal.hidden { display: none !important; }
.modal-content { background: #fff; padding: 28px; border-radius: var(--radius-lg); width: 500px; display: flex; flex-direction: column; gap: 15px; box-shadow: var(--shadow-lg); }
.modal-header h3 { color: var(--text-main); margin-bottom: 5px; }
.modal-header p { font-size: 12px; color: var(--text-gray); }
.score-adjust-grid { display: grid; grid-template-columns: 1fr; gap: 10px; background: #f8fafc; padding: 15px; border-radius: var(--radius-sm); border: 1px solid var(--border-color); }
.score-adjust-grid label { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.score-adjust-grid input { width: 80px; text-align: center; }
.total-preview { text-align: right; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }

/* 历史库网格 */
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 15px; margin-top: 15px; }
.history-card { background: #fff; padding: 20px; border: 1px solid var(--border-color); border-radius: var(--radius-md); text-align: center; display: flex; flex-direction: column; gap: 10px; }
.history-card h3 { color: var(--text-main); }
.history-card p { font-size: 12px; color: var(--text-gray); }

.ai-preview-box { background: #F8FAFC; border-top: 2px solid var(--primary-blue); padding: 15px; height: 40%; overflow-y: auto; }
.report-content h4 { margin: 10px 0 5px; color: var(--primary-hover); font-size: 14px;}
.report-content p { font-size: 13px; line-height: 1.6; color: var(--text-main); margin-bottom: 8px; }
.empty-state { text-align: center; color: var(--text-gray); padding: 30px 20px; font-size: 13px; }

/* ======== 自定义滚动条 ======== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #C7D2E8; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #93A8CC; }
* { scrollbar-width: thin; scrollbar-color: #C7D2E8 transparent; }

@media (max-width: 1180px) {
    .top-header { grid-template-columns: 140px 1fr auto; }
    .draft-pane.open { width: 380px; }
    .flywheel-stats { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
}

@media (max-width: 920px) {
    body { min-width: 0; }
    .top-header { grid-template-columns: 1fr; height: auto; padding: 10px 14px; gap: 8px; }
    .header-left, .header-center, .header-right { width: 100%; justify-content: center; text-align: center; }
    .header-brand { justify-content: center; }
    .header-center h1 { white-space: normal; font-size: 18px; }
    .app-container { min-width: 0; }
    .sidebar { width: 210px; }
    #stream-view { flex-direction: column !important; }
    .draft-pane.open { width: 100%; max-height: 38vh; border-left: 0; border-top: 1px solid var(--border-color); }
    .stream-title-row { align-items: flex-start; flex-direction: column; }
    .stream-toolbar { justify-content: flex-start; }
}

@media (max-width: 720px) {
    .app-container { flex-direction: column; }
    .sidebar { width: 100%; max-height: 230px; border-right: 0; border-bottom: 1px solid var(--border-color); }
    .view-menu { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .view-btn { text-align: center; }
    .view-btn.active { border-radius: var(--radius-sm); }
    .view-section { padding: 10px; }
    .flywheel-stats { grid-template-columns: 1fr; }
    .modal-content { width: min(500px, calc(100vw - 24px)); }
}
