/* css/immersive_layout.css */

:root {
  --immersive-separator-color: var(--color-slate-200);
  --immersive-handle-width: 1px;
  --immersive-handle-color: transparent;
  --immersive-handle-hover-color: var(--color-primary-100);
  --immersive-panel-min-width: 200px; /* 增加最小宽度，避免布局崩坏 */
  --dock-height-in-immersive: 45px;
  --immersive-transition-duration: 0.2s;
  --immersive-surface-bg: var(--color-slate-50);
  --immersive-panel-bg: #ffffff;
}

/* 确保沉浸式布局容器在需要时可以显示为 flex */
#immersive-layout-container {
  /* display: flex; */ /* JS会控制这个 */
  background: var(--immersive-surface-bg);
  font-family: var(--font-sans);
}

#immersive-content-area {
  display: flex;
  flex: 1;
  overflow: hidden;
  /* height: calc(100vh - var(--dock-height-in-immersive)); */ /* REMOVED: 为Dock预留空间, 现在dock在TOC内部 */
}

.immersive-panel {
  overflow: hidden;
  padding: 0;
  box-sizing: border-box;
  position: relative;
  min-width: var(--immersive-panel-min-width);
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--immersive-panel-bg);
  transition: all var(--immersive-transition-duration) ease;
  margin: 0;
  border-right: 1px solid var(--immersive-separator-color);
}

/* 主内容区域在沉浸模式下可能需要特殊处理其内部的 .container 样式 */
#immersive-main-content-area .container {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 8px 16px !important;
  box-shadow: none;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #ffffff;
  border-radius: 0;
  border: none;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

/* 将标题和 meta 信息合并到一行 */
#immersive-main-content-area .container > h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
  padding: 0;
  gap: 12px;
}

#immersive-main-content-area .container > .meta {
  position: absolute;
  top: 8px;
  right: 16px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* tabs 和 fileName/meta 在同一行区域 */
#immersive-main-content-area .container > .tabs-container {
  order: 0;
  margin-top: 0;
}

#immersive-main-content-area .container .tabs-container {
  flex-shrink: 0;
}

#immersive-main-content-area .container .tab-content {
  flex-grow: 1;
  overflow-y: auto !important; /* 确保tab-content是滚动容器 */
  height: 0; /* flex-grow 生效的关键 */
  margin-bottom: 0; /* 移除可能的外边距 */
  margin-top: 0 !important; /* 覆盖原始的 margin-top: -2px */
  padding: 0 !important; /* 覆盖原始的 padding: 24px */
  min-height: 0 !important; /* 覆盖原始的 min-height: 300px */
  background: transparent !important; /* 移除背景色，避免视觉干扰 */
  border-radius: 0 !important; /* 移除圆角 */
  display: flex !important;
  flex-direction: column !important;
}

/* 强制修复：确保所有内容容器都正确填充 */
#immersive-main-content-area .tab-content .content-wrapper {
  flex: 1 !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  margin: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  padding: 20px !important; /* 给内容适当的呼吸空间 */
}

#immersive-main-content-area .tab-content .chunk-compare-container {
  /* 让 tab-content 成为唯一滚动容器，避免内部再滚动 */
  flex: none !important;
  min-height: auto !important;
  overflow: visible !important;
  margin: 0 !important;
  display: block !important;
}

/* chunk-compare-container保持原有的间距设计 */
#immersive-main-content-area .tab-content .chunk-compare-container {
  padding: 0 !important; /* chunk-compare有自己的内部间距 */
}

/* 确保h3标题不影响flex计算 */
#immersive-main-content-area .tab-content > h3 {
  flex: none !important;
  margin-bottom: 16px !important;
  margin-top: 0 !important;
}

#immersive-main-content-area .container .tab-content:last-child {
  margin-bottom: 0 !important;
}


/* TOC - 极简美观 */
#immersive-toc-area #toc-popup {
  position: static;
  display: flex !important;
  flex-direction: column;
  width: 100% !important;
  flex-grow: 1;
  border: none !important;
  box-shadow: none !important;
  transform: none !important;
  visibility: visible !important;
  opacity: 1 !important;
  padding: 0;
  margin: 0;
  background: transparent;
  overflow: hidden;
}

#immersive-toc-area #toc-popup #toc-popup-header {
  display: none;
}

#immersive-toc-area #toc-popup #toc-list {
  overflow-y: auto;
  flex-grow: 1;
  padding: 8px 0;
  background: transparent;
  max-height: none !important;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.06) transparent;
}

#immersive-toc-area #toc-popup #toc-list::-webkit-scrollbar {
  width: 2px;
}

#immersive-toc-area #toc-popup #toc-list::-webkit-scrollbar-track {
  background: transparent;
}

#immersive-toc-area #toc-popup #toc-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 1px;
}

#immersive-toc-area #toc-list li {
  margin: 0 !important;
}

#immersive-toc-area #toc-list li a {
  padding: 6px 12px !important;
  font-size: 0.8rem !important;
  font-weight: 500 !important;
  color: var(--color-slate-500) !important;
  border: none !important;
  border-left: 3px solid transparent !important;
  background: transparent !important;
  transition: all 0.15s ease !important;
  line-height: 1.5 !important;
}

#immersive-toc-area #toc-list li a:hover {
  color: var(--color-slate-900) !important;
  background: var(--color-slate-100) !important;
  border-left-color: var(--color-slate-300) !important;
}

#immersive-toc-area #toc-list li a.active {
  color: var(--color-primary-700) !important;
  background: var(--color-primary-50) !important;
  border-left-color: var(--color-primary-500) !important;
}

#immersive-toc-area #toc-list li.toc-h1 a {
  font-weight: 600 !important;
  color: var(--color-slate-700) !important;
  margin-top: 8px !important;
}

#immersive-toc-area #toc-list li.toc-h2 a {
  padding-left: 18px !important;
  font-size: 0.7em !important;
}

#immersive-toc-area #toc-list li.toc-h3 a {
  padding-left: 26px !important;
  font-size: 0.68em !important;
  color: #b5bac1 !important;
}

#immersive-toc-area #toc-list .toc-toggle {
  display: none !important;
}

#immersive-toc-area #toc-popup #toc-popup-close-btn {
  display: none;
}

#immersive-toc-area #toc-popup .toc-controls {
  display: none;
}

/* 移除 TOC 中的文件名图标，保持极简 */
#immersive-toc-area #toc-list li a[href^="#placeholder-"] {
  font-weight: 500 !important;
  color: #6b7280 !important;
  background: transparent !important;
  border: none !important;
  border-left: 2px solid transparent !important;
  padding-left: 10px !important;
}

#immersive-toc-area #toc-list li a[href^="#placeholder-"]::before {
  display: none !important;
}

#immersive-toc-area #toc-list li a[href^="#placeholder-"]:hover {
  color: #374151 !important;
  background: rgba(0, 0, 0, 0.02) !important;
  border-left-color: #9ca3af !important;
}

/* Chatbot特定样式调整 */
#immersive-chatbot-area #chatbot-modal {
  position: static !important;
  display: flex !important;
  width: 100% !important;
  height: 100% !important;
  pointer-events: auto !important;
  background-color: transparent !important;
  padding: 0 !important;
  margin: 0 !important;
}

#immersive-chatbot-area .chatbot-window {
  position: static !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  max-height: none !important;
  min-height: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  resize: none !important;
  overflow: hidden !important;
  display: flex;
  flex-direction: column;
  background: var(--immersive-surface-bg) !important;
  border: none !important;
  transition: all var(--immersive-transition-duration) ease !important;
}

#immersive-chatbot-area #chatbot-fab {
  display: none !important; /* 沉浸模式下隐藏FAB */
}

/* 隐藏chatbot自己的全屏和位置切换按钮，因为布局由外部控制 */
#immersive-chatbot-area #chatbot-fullscreen-toggle-btn,
#immersive-chatbot-area #chatbot-position-toggle-btn,
#immersive-chatbot-area #chatbot-close-btn {
  display: none !important;
}


.immersive-resize-handle {
  width: var(--immersive-handle-width);
  background: var(--immersive-separator-color);
  cursor: col-resize;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  margin: 0;
  border-radius: 0;
}

/* 移除拖动条中间的细线 */
.immersive-resize-handle::before {
  display: none;
}

.immersive-resize-handle:hover {
  background: var(--color-primary-100);
  transition-delay: 0.1s; /* 防止意外划过时的闪烁 */
}

.immersive-resize-handle:hover::before {
  display: none;
}

/* 拖动时的样式 */
.immersive-dragging .immersive-resize-handle {
  background: var(--color-primary-200);
}

.immersive-dragging .immersive-resize-handle::before {
  display: none;
}

/* 当body上应用了 no-scroll 类时（例如沉浸模式下），禁用滚动 */
body.no-scroll {
  overflow: hidden;
}

/* 原本的 .container 和 #toc-float-btn, #toc-popup 在沉浸模式下需要隐藏 */
body.immersive-active > .container,
body.immersive-active > #toc-float-btn,
body.immersive-active > #toc-popup:not(#immersive-toc-area #toc-popup),
body.immersive-active > #chatbot-modal:not(#immersive-chatbot-area #chatbot-modal),
body.immersive-active > #chatbot-fab
/* body.immersive-active > #bottom-left-dock REMOVED - Dock is now moved, not hidden globally */
{
  display: none !important;
}

/* 确保沉浸式布局下的主要内容区域不会被其他元素遮挡，比如聊天机器人的某些内部定位元素 */
#immersive-main-content-area {
    position: relative; /* for z-index context */
    z-index: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* 调整dock设置弹窗、批注弹窗等在沉浸模式下的z-index，确保它们能显示在沉浸式布局之上 */
body.immersive-active .modal-overlay {
    z-index: 20001 !important; /* 高于沉浸式布局的 header */
}

body.immersive-active #custom-context-menu {
    z-index: 20002 !important;
}

/* 确保原始的 toc-popup 在非沉浸模式下能正常显示 */
#toc-popup {
    /* 保留其原始样式 */
}

/* 沉浸模式下，如果 chatbot-window 内部有自己的 resize handle (通常没有，但以防万一) */
#immersive-chatbot-area .chatbot-window::after {
    display: none !important; /* 隐藏可能的伪元素 resize handle */
}

/* Styling for the toggle button when it acts as an exit button */
/* #toggle-immersive-btn.immersive-exit-btn-active {
  position: fixed !important; // Ensure it overrides inline styles if any
  top: auto !important;
  right: 20px !important;
  bottom: 20px !important; // Position relative to viewport bottom, removed dock height adjustment
  left: auto !important;
  width: 40px !important; // Smaller, circular or square button
  height: 40px !important;
  padding: 0 !important;
  border-radius: 50% !important; // Circular
  background-color: #dc3545 !important; // Danger color for exit
  color: white !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px; // Adjust icon size
  box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
  transition: transform 0.2s ease-out;
}

#toggle-immersive-btn.immersive-exit-btn-active:hover {
  transform: scale(1.1);
  background-color: #c82333 !important; // Darker on hover
} */

/* Base style for the immersive toggle button - 使用统一尺寸系统 */
#toggle-immersive-btn {
  position: fixed !important;
  top: 12px !important;
  right: 12px !important;
  z-index: 20000 !important;
  width: 32px !important;
  height: 32px !important;
  border: 1px solid var(--color-slate-200) !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md) !important;
  background: #ffffff !important;
  color: var(--color-slate-600) !important;
  font-size: 14px !important;
  box-shadow: var(--shadow-sm) !important;
  transition: all 0.2s ease !important;
}

#toggle-immersive-btn:hover {
  background: var(--color-slate-50) !important;
  color: var(--color-slate-900) !important;
  border-color: var(--color-slate-300) !important;
  box-shadow: var(--shadow-md) !important;
}

#toggle-immersive-btn:active {
  transform: translateY(0) !important;
  transition: all 0.1s ease !important;
}

/* Styles when immersive mode is active (mostly for icon change via JS, positioning is the same) */
#toggle-immersive-btn.immersive-exit-btn-active {
  /* The base style #toggle-immersive-btn already covers position, size, and default BG. */
  /* This class is now mainly a flag for JS to change the icon and title. */
  /* If a different background for "exit" state is desired (but not red as per user): */
  /* background-color: var(--secondary-accent-color, #5bc0de) !important; */
}

/* #toggle-immersive-btn.immersive-exit-btn-active:hover { */
  /* If hover for exit needs to be different */
  /* background-color: var(--secondary-accent-color-dark, #31b0d5) !important; */
/* } */


/* TOC 底部 dock - 极简设计 */
#immersive-toc-area #toc-dock-placeholder {
  flex-shrink: 0;
  border-top: 1px solid var(--color-slate-200);
  background: var(--color-slate-50);
  padding: 12px;
}

#immersive-toc-area #toc-dock-placeholder #bottom-left-dock {
  position: static !important;
  width: 100% !important;
  height: auto !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  gap: 4px !important;
  font-size: 0.7em !important;
}

/* 隐藏详细统计信息 */
#immersive-toc-area #bottom-left-dock.dock-collapsed #dock-info-stack,
#immersive-toc-area #bottom-left-dock #dock-info-stack {
  display: none !important;
}

/* 始终显示进度 */
#immersive-toc-area #bottom-left-dock.dock-collapsed #dock-collapsed-progress-display,
#immersive-toc-area #bottom-left-dock #dock-collapsed-progress-display {
  display: block !important;
  color: #6b7280 !important;
  font-weight: 400 !important;
  margin: 0 !important;
}

/* 按钮行 */
#immersive-toc-area #bottom-left-dock #settings-link,
#immersive-toc-area #bottom-left-dock #dock-toggle-btn,
#immersive-toc-area #bottom-left-dock.dock-collapsed #settings-link,
#immersive-toc-area #bottom-left-dock.dock-collapsed #dock-toggle-btn {
  display: inline-block !important;
  color: #9ca3af !important;
  font-size: 1em !important;
  padding: 2px 4px !important;
  margin: 0 2px !important;
}

#immersive-toc-area #bottom-left-dock #settings-link:hover,
#immersive-toc-area #bottom-left-dock #dock-toggle-btn:hover {
  color: #6b7280 !important;
}

/* Removed old #immersive-dock-placeholder styles */

/* Horizontal Resize Handle for TOC vs Dock adjustment */
#toc-vs-dock-resize-handle {
  height: 1px;
  background: var(--immersive-separator-color);
  cursor: ns-resize;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  border-radius: 0;
  transition: background 0.2s ease;
}

#toc-vs-dock-resize-handle::before {
  display: none;
}

#toc-vs-dock-resize-handle:hover {
  background: var(--immersive-handle-hover-color);
  transform: none;
}

#toc-vs-dock-resize-handle:hover::before {
  display: none;
}

/* Optional: Style when dragging */
body.toc-dock-resizing #toc-vs-dock-resize-handle {
  background: rgba(59, 130, 246, 0.2);
}

body.toc-dock-resizing #toc-vs-dock-resize-handle::before {
  display: none;
}

/* 优化的拖拽状态 */
.immersive-dragging .immersive-resize-handle {
  background: rgba(59, 130, 246, 0.2);
}

.immersive-dragging .immersive-resize-handle::before {
  display: none;
}

.immersive-dragging #toc-vs-dock-resize-handle {
  background: rgba(59, 130, 246, 0.2);
}

.immersive-dragging #toc-vs-dock-resize-handle::before {
  display: none;
}

/* Ensure other panels like TOC and Chatbot still use the default .immersive-panel padding or have their own */
#immersive-toc-area.immersive-panel {
    padding: 4px 6px 0 6px !important;
    border-right: 1px solid var(--immersive-separator-color);
}

#immersive-chatbot-area.immersive-panel {
    padding: 4px 6px 0 6px !important;
    border-right: none;
}

#immersive-main-content-area.immersive-panel {
    border-right: 1px solid var(--immersive-separator-color);
}

/* Immersive Mode: Main Content Area Header Styling - REFINED */

/* Grouping fileName and fileMeta - no new div, control via flex item properties if .container is flex column */
#immersive-main-content-area #fileName {
  font-size: 0.75em;
  font-weight: 500;
  color: #6b7280;
  line-height: 1;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  max-width: 180px;
}

#immersive-main-content-area #fileMeta {
  font-size: 0.7em;
  color: #9ca3af;
  line-height: 1;
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#immersive-main-content-area #fileMeta .meta-separator {
  margin: 0 2px;
}

/* 将标题、meta 和 tabs 整合到紧凑的两行顶栏 */
#immersive-main-content-area .container {
  padding: 0 !important;
  gap: 0 !important;
  display: grid !important;
  grid-template-rows: 24px 32px 1fr !important;
  grid-template-columns: 1fr !important;
  flex-direction: unset !important;
}

/* 第一行：h2 和 meta 在同一行 - 极简设计 */
#immersive-main-content-area .container > h2 {
  grid-row: 1;
  grid-column: 1;
  height: 24px;
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0 16px;
  font-size: 0.7em;
  font-weight: 400;
  color: #9ca3af;
  background: transparent;
  border: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 50%;
}

/* meta 与 h2 重叠在同一行 */
#immersive-main-content-area .container > .meta {
  grid-row: 1;
  grid-column: 1;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin: 0;
  padding: 0 16px;
  gap: 12px;
  background: transparent;
  pointer-events: none;
  z-index: 1;
}

#immersive-main-content-area .container > .meta * {
  pointer-events: auto;
}

#immersive-main-content-area .meta-info {
  gap: 8px;
  display: flex;
  align-items: center;
  color: #9ca3af;
  font-size: 0.7em;
}

#immersive-main-content-area .meta-separator {
  color: #d1d5db;
}

#immersive-main-content-area .meta-export-trigger {
  padding: 2px 8px;
  font-size: 0.7em;
  gap: 3px;
  border-radius: 4px;
  height: auto;
  border: none;
  background: transparent;
  color: #9ca3af;
  font-weight: 400;
  transition: all 0.15s ease;
}

#immersive-main-content-area .meta-export-trigger:hover {
  background: #f3f4f6;
  color: #6b7280;
}

#immersive-main-content-area .meta-export-trigger i {
  font-size: 0.85em;
}

/* 第二行：tabs - 更现代简洁的设计 */
#immersive-main-content-area .container > .tabs-container {
  grid-row: 2;
  grid-column: 1;
  padding: 0 16px;
  border: none;
  display: flex;
  gap: 2px;
  margin: 0;
  height: 32px;
  justify-content: flex-start;
  align-items: center;
  background: transparent;
  border-bottom: 1px solid #f0f0f0;
}

#immersive-main-content-area .tabs-container .tab-btn {
  padding: 0 14px;
  font-size: 0.7em;
  font-weight: 500;
  border-radius: 0;
  background-color: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: #9ca3af;
  cursor: pointer;
  transition: all 0.15s ease;
  margin: 0;
  height: 32px;
  line-height: 1;
  display: flex;
  align-items: center;
}

#immersive-main-content-area .tabs-container .tab-btn:hover {
  color: #6b7280;
  border-bottom-color: #e5e7eb;
}

#immersive-main-content-area .tabs-container .tab-btn.active {
  background-color: transparent;
  color: #3b82f6;
  border-bottom-color: #3b82f6;
  font-weight: 600;
}

/* 第三行：tab-content */
#immersive-main-content-area .container > .tab-content {
  grid-row: 3;
  grid-column: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 16px;
  background: #ffffff;
}

/* 沉浸模式下隐藏 PDF 对照按钮 */
body.immersive-active #tab-pdf-compare {
  display: none !important;
}

/* 导出控制面板 */
#immersive-main-content-area .container > .history-export-controls {
  grid-row: 3;
  grid-column: 1;
  z-index: 10;
  pointer-events: none;
}

#immersive-main-content-area .container > .history-export-controls.active {
  pointer-events: auto;
}

/* 隐藏 tab-content 内的 h3 标题 */
#immersive-main-content-area .tab-content > h3 {
  display: none;
}

/* 压缩顶部 meta 区域 - 已整合到顶栏中 */
#immersive-main-content-area .meta {
  margin: 0;
  gap: 8px;
  font-size: 0.7em;
  min-height: auto;
  position: absolute;
  top: 0;
  right: 12px;
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0;
  z-index: 3;
  background: transparent;
}

#immersive-main-content-area .meta-info {
  gap: 6px;
  display: flex;
  align-items: center;
  color: #9ca3af;
}

#immersive-main-content-area .meta-info span {
  line-height: 1;
}

#immersive-main-content-area .meta-separator {
  color: #d1d5db;
  margin: 0 2px;
}

#immersive-main-content-area .meta-export-trigger {
  padding: 4px 10px;
  font-size: 0.7em;
  gap: 4px;
  border-radius: 4px;
  height: auto;
  border: 1px solid rgba(59, 130, 246, 0.15);
  background: transparent;
  color: #3b82f6;
  font-weight: 500;
  transition: all 0.15s ease;
}

#immersive-main-content-area .meta-export-trigger:hover {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.25);
}

#immersive-main-content-area .meta-export-trigger i {
  font-size: 0.85em;
}

/* Specific fix for the duplicate padding issue if .container is inside .immersive-panel with padding */
/* This assumes .immersive-main-content-area IS an .immersive-panel */
/* 确保沉浸模式立即生效的样式 - 简化版本 */
body.immersive-active #immersive-main-content-area .container {
  height: 100% !important;
  padding: 20px 24px !important;
  margin-bottom: 0 !important;
  box-sizing: border-box !important;
  display: flex !important;
  flex-direction: column !important;
}

body.immersive-active #immersive-main-content-area.immersive-panel {
  padding: 0 !important;
  height: 100% !important;
}

body.immersive-active .immersive-panel {
  padding-bottom: 0 !important;
  margin-bottom: 0 !important;
}

body.immersive-active #immersive-content-area {
  height: 100vh !important;
  box-sizing: border-box !important;
}

/* 初始化时立即应用的样式 */
body.immersive-entering #immersive-main-content-area .container,
body.immersive-active #immersive-main-content-area .container {
  animation: fixLayoutHeight 0.1s ease-out;
}

@keyframes fixLayoutHeight {
  0% { height: calc(100% - 1px); }
  100% { height: 100%; }
}

/* Reset padding on the general .immersive-panel if we want specific panels to override */
/* This might be too broad, an alternative is to ensure specific panels like #immersive-main-content-area */
/* have their padding managed correctly. For now, let's adjust #immersive-main-content-area.immersive-panel directly. */

/* Additional optimizations for immersive mode UI */

/* 沉浸模式下移除所有虚线，统一使用实线或无边框 */
body.immersive-active .markdown-body img,
body.immersive-active pre,
body.immersive-active .chunk-pair,
body.immersive-active .chunk-divider,
body.immersive-active .chunk-compare-header,
body.immersive-active .chunk-ocr.active,
body.immersive-active .chunk-translation.active {
  border-style: solid !important;
}

body.immersive-active #bottom-left-dock {
  border-style: solid !important;
}

body.immersive-active .toc-info {
  border-left-style: solid !important;
}

/* 改进的动画和过渡效果 */
body.immersive-entering {
  overflow: hidden;
}

body.immersive-exiting {
  overflow: hidden;
}

body.immersive-dragging {
  cursor: col-resize !important;
  user-select: none !important;
}

body.immersive-dragging * {
  cursor: col-resize !important;
  user-select: none !important;
  pointer-events: none;
}

body.immersive-dragging .immersive-resize-handle {
  pointer-events: auto;
}

/* 改进的面板间距 */
#immersive-content-area {
  gap: 0;
  padding: 0;
}

/* 更好的滚动条样式 */
.immersive-panel::-webkit-scrollbar {
  width: 6px;
}

.immersive-panel::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.02);
  border-radius: 3px;
}

.immersive-panel::-webkit-scrollbar-thumb {
  background: rgba(59, 130, 246, 0.2);
  border-radius: 3px;
  transition: background 0.2s ease;
}

.immersive-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(59, 130, 246, 0.4);
}

/* 改进的面板标题样式 */
.immersive-panel-header {
  background: transparent;
  border-bottom: none;
  padding: 8px 12px;
  font-weight: 500;
  font-size: 0.85rem;
  color: #374151;
  border-radius: 0;
}

/* 优化的拖拽状态 */
.immersive-dragging .immersive-resize-handle::before {
  background: #3b82f6 !important;
  width: 3px !important;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.4) !important;
}

.immersive-dragging #toc-vs-dock-resize-handle::before {
  background: #3b82f6 !important;
  height: 3px !important;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.4) !important;
}

/* 响应式优化 */
@media (max-width: 1200px) {
  .immersive-panel {
    padding: 6px 8px 0 8px;
  }

  #immersive-main-content-area .container {
    padding: 12px 16px !important;
  }

  #immersive-toc-area {
    min-width: 200px;
  }

  #immersive-chatbot-area {
    min-width: 250px;
  }
}

/* 移动端禁用沉浸式布局 - 700px以下屏幕 */
@media (max-width: 700px) {
  /* 完全隐藏沉浸式布局切换按钮 */
  #toggle-immersive-btn {
    display: none !important;
  }
  
  /* 强制退出沉浸式模式（如果用户在更大屏幕上进入了沉浸模式后缩小屏幕） */
  body.immersive-active #immersive-layout-container {
    display: none !important;
  }
  
  /* 确保正常布局在移动端可见 */
  body.immersive-active > .container,
  body.immersive-active > #toc-float-btn,
  body.immersive-active > #toc-popup:not(#immersive-toc-area #toc-popup),
  body.immersive-active > #chatbot-modal:not(#immersive-chatbot-area #chatbot-modal),
  body.immersive-active > #chatbot-fab {
    display: block !important;
  }
  
  /* 恢复正常的body滚动 */
  body.immersive-active {
    overflow: auto !important;
  }
}

@media (max-width: 768px) and (min-width: 701px) {
  /* 701px-768px范围内保持沉浸式功能但优化布局 */
  :root {
    --immersive-panel-min-width: 120px;
  }
  
  #immersive-content-area {
    flex-direction: column;
    gap: 2px;
  }
  
  .immersive-resize-handle {
    height: 6px;
    width: 100%;
    cursor: ns-resize;
  }
  
  .immersive-resize-handle::before {
    left: 10%;
    right: 10%;
    top: calc(50% - 1px);
    bottom: auto;
    width: auto;
    height: 2px;
  }
  
  #toggle-immersive-btn {
    top: 10px !important;
    right: 10px !important;
    width: var(--btn-large-mobile, 36px) !important;
    height: var(--btn-large-mobile, 36px) !important;
    font-size: var(--btn-icon-large-mobile, 16px) !important;
  }
}

/* 暗色模式支持 */
@media (prefers-color-scheme: dark) {
  :root {
    --immersive-surface-bg: #1a1d23;
    --immersive-surface-bg-alt: #1a1d23;
    --immersive-separator-color: #374151;
  }

  #immersive-layout-container {
    background: #111827;
  }

  .immersive-panel {
    border-color: #374151;
    color: #e5e7eb;
  }

  #immersive-main-content-area .container {
    background: #1a1d23;
    color: #e5e7eb;
  }

  #toggle-immersive-btn {
    background: #1f2937 !important;
    color: #e5e7eb !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.05) !important;
  }

  #toggle-immersive-btn:hover {
    background: #374151 !important;
  }
}

/* 动态亮度调节 */
body.immersive-active {
  --immersive-bg-brightness: 1;
}

body.immersive-active.reading-focus {
  --immersive-bg-brightness: 0.95;
}

#immersive-layout-container {
  filter: brightness(var(--immersive-bg-brightness, 1));
  transition: filter 0.3s ease;
}
