:root {
  --bg0: #07060d;
  --bg1: #0b0717;
  --panel: rgba(16, 14, 26, 0.7);
  --panel2: rgba(16, 14, 26, 0.45);
  --border: rgba(255, 255, 255, 0.08);
  --border2: rgba(255, 255, 255, 0.12);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.6);
  --muted2: rgba(255, 255, 255, 0.42);
  --accent: #3b82f6;
  --accent2: #60a5fa;
  --danger: #ef4444;
  --radius: 18px;
}

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

body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  background: radial-gradient(1200px 700px at 50% -120px, rgba(59, 130, 246, 0.35), transparent 60%),
    radial-gradient(900px 500px at 10% 0%, rgba(96, 165, 250, 0.22), transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app-container {
  display: grid;
  grid-template-columns: 350px 1fr 350px;
  height: 100%;
  width: 100%;
}

/* 左侧预览栏 -> 包含 文件列表 */
.preview-sidebar {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
  border-right: 1px solid var(--border);
  border-radius: var(--radius) 0 0 var(--radius);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 280px;
  backdrop-filter: blur(14px);
}

/* 侧边栏上传区 */
.sidebar-upload-section {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
  align-items: center;
}

.upload-btn-sidebar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 150px;
  padding: 18px 14px;
  background: rgba(0, 0, 0, 0.12);
  border: 2px dashed rgba(255, 255, 255, 0.22);
  border-radius: 14px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.2s;
}

.upload-btn-sidebar i {
  font-size: 40px;
  color: var(--muted);
  transition: color 0.2s;
}

.upload-btn-title {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.upload-btn-subtitle {
  font-size: 12px;
  color: var(--muted2);
}

.upload-btn-sidebar:hover {
  background: rgba(59, 130, 246, 0.06);
  border-color: rgba(59, 130, 246, 0.45);
  color: var(--accent);
}

.upload-btn-sidebar.dragover {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.65);
  color: var(--accent);
}

.upload-btn-sidebar:hover i {
  color: var(--accent);
}

.upload-btn-sidebar.tom-hide-text-icons i,
.upload-btn-sidebar.tom-hide-text-icons span {
  display: none;
}

/* 侧边栏文件列表 */
.sidebar-file-list-container {
  flex: 1;
  /* 占满剩余高度 */
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border-color);
  overflow: hidden;
}

.sidebar-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.18);
}

.file-list-vertical {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 5px;
}

/* 中间区域容器 */
.main-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* PDF Preview Container (Moved to Main Panel) */
.pdf-preview-container {
  flex: 1;
  /* 占 50% 高度 (如果 result-container 也是 flex: 1) */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-bottom: 1px solid var(--border-color);
  min-height: 200px;
}

/* File List Items (Vertical) */
.file-list-item {
  display: flex;
  align-items: center;
  padding: 8px;
  background-color: transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  border: 1px solid transparent;
}

.file-list-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.file-list-item.active {
  background-color: rgba(0, 122, 204, 0.2);
  border-color: var(--accent-color);
}

.file-list-thumb {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  margin-right: 10px;
  background-color: #000;
  flex-shrink: 0;
}

.file-list-info {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.file-list-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.file-list-meta {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.file-list-remove {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  opacity: 0;
  transition: opacity 0.2s;
  cursor: pointer;
}

.file-list-item:hover .file-list-remove {
  opacity: 1;
}

.file-list-remove:hover {
  color: var(--error-color);
  background-color: rgba(255, 255, 255, 0.1);
}

.empty-list-tip {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

/* Remove old header styles */
.panel-header-new,
.upload-section-square-wrapper,
.file-list-horizontal-container {
  display: none;
}


.preview-header {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

#preview-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.preview-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pdf-loading-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  min-width: 56px;
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-primary);
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  border-color: var(--accent-color);
}

.text-button {
  background: none;
  border: none;
  color: var(--accent-color);
  cursor: pointer;
  font-size: 12px;
}

.text-button:hover {
  text-decoration: underline;
}

.pdf-pages-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  align-content: start;
}

.pdf-page-item {
  position: relative;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  background-color: var(--bg-input);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px;
}

.pdf-page-item:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.pdf-page-checkbox {
  position: absolute;
  top: 5px;
  left: 5px;
  z-index: 2;
  cursor: pointer;
}

.pdf-page-item input[type="checkbox"]:checked+.pdf-page-thumbnail {
  opacity: 1;
}

.pdf-page-item.selected,
.pdf-page-item:has(input:checked) {
  border-color: var(--accent-color);
  background-color: rgba(0, 122, 204, 0.1);
}

.pdf-page-thumbnail {
  width: 100%;
  height: 120px;
  object-fit: contain;
  background-color: #fff;
  border-radius: 2px;
}

.img-preview-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.img-preview-image {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 520px;
  display: block;
}

.img-selection-rect {
  position: absolute;
  border: 2px dashed rgba(59, 130, 246, 0.95);
  background: rgba(59, 130, 246, 0.14);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16) inset;
  pointer-events: none;
  border-radius: 2px;
}

.image-viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.86);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.image-viewer-dialog {
  position: relative;
  width: min(92vw, 1280px);
  height: min(90vh, 820px);
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.image-viewer-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
}

.image-viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.75);
  color: rgba(255, 255, 255, 0.92);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-viewer-nav.prev {
  left: 16px;
}

.image-viewer-nav.next {
  right: 16px;
}

.image-viewer-nav:hover,
.image-viewer-close:hover {
  border-color: rgba(59, 130, 246, 0.86);
  color: #ffffff;
}

.image-viewer-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.42);
  background: rgba(15, 23, 42, 0.72);
  color: rgba(255, 255, 255, 0.86);
  cursor: pointer;
}

.image-viewer-caption {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 12px;
  text-align: center;
  font-size: 13px;
  color: rgba(248, 250, 252, 0.92);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.pdf-page-number {
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Action Bar */
.action-bar {
  padding: 10px 15px;
  display: flex;
  align-items: center;
  gap: 15px;
  background-color: var(--bg-main);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.primary-button {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.5), rgba(37, 99, 235, 0.45));
  border: 1px solid rgba(59, 130, 246, 0.55);
  color: rgba(255, 255, 255, 0.92);
  padding: 8px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 900;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.primary-button:hover:not(:disabled) {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.6), rgba(37, 99, 235, 0.55));
}

.primary-button.danger-button {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.5), rgba(220, 38, 38, 0.5));
  border-color: rgba(239, 68, 68, 0.6);
}

.primary-button.danger-button:hover:not(:disabled) {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.6), rgba(220, 38, 38, 0.6));
}

.primary-button:disabled {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.6;
}

.status-indicator {
  font-size: 13px;
  color: var(--text-secondary);
}

.extract-progress {
  height: 3px;
  width: 100%;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  flex-shrink: 0;
}

.extract-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.9), rgba(34, 197, 94, 0.9));
  transition: width 0.18s linear;
}

/* Result Container */
.result-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 15px;
  overflow: hidden;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.result-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 13px;
}

.result-metrics {
  font-size: 12px;
  color: var(--text-secondary);
}

.result-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.result-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  transition: color 0.2s;
  padding: 4px;
}

.result-actions button:hover {
  color: var(--text-primary);
}

.result-container[data-view="structured"] #output-text {
  display: none;
}

.result-container[data-view="text"] .output-structured {
  display: none;
}

.output-structured {
  flex: 1;
  width: 100%;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 12px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  overflow-y: auto;
}

.output-structured.empty {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-break {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: rgba(0, 0, 0, 0.2);
}

.page-break:last-child {
  margin-bottom: 0;
}

.page-break-title {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.page-lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.line-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.line-item:hover {
  border-color: rgba(255, 255, 255, 0.18);
}

.line-label {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  align-self: start;
  white-space: nowrap;
}

.line-text {
  word-break: break-word;
}

.line-title {
  background: rgba(255, 193, 7, 0.12);
  border-color: rgba(255, 193, 7, 0.4);
}

.line-title .line-label {
  background: rgba(255, 193, 7, 0.25);
  color: #ffcc4d;
}

.line-paragraph {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.25);
}

.line-paragraph .line-label {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

.line-list {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.3);
}

.line-list .line-label {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.line-note {
  background: rgba(236, 72, 153, 0.08);
  border-color: rgba(236, 72, 153, 0.25);
}

.line-note .line-label {
  background: rgba(236, 72, 153, 0.2);
  color: #f472b6;
}

.line-code {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.3);
}

.line-code .line-label {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
}

.line-unknown {
  background: rgba(148, 163, 184, 0.1);
  border-color: rgba(148, 163, 184, 0.3);
}

.line-unknown .line-label {
  background: rgba(148, 163, 184, 0.2);
  color: #cbd5f5;
}

#output-text {
  flex: 1;
  width: 100%;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 15px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  outline: none;
}

#output-text:focus {
  border-color: rgba(59, 130, 246, 0.55);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.14);
}

/* AI Sidebar */
.ai-sidebar {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
  border-left: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(14px);
}

.ai-header {
  padding: 15px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.18);
}

.ai-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.ai-header h3 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-model-controls {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ai-status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-secondary);
}

.ai-status-indicator.idle {
  background-color: #ff9800;
  box-shadow: 0 0 5px rgba(255, 152, 0, 0.65);
}

.ai-status-indicator.connected {
  background-color: var(--success-color);
  box-shadow: 0 0 5px var(--success-color);
}

.ai-status-indicator.success {
  background-color: var(--success-color);
  box-shadow: 0 0 5px var(--success-color);
}

.ai-status-indicator.error {
  background-color: var(--error-color);
  box-shadow: 0 0 5px var(--error-color);
}

.ai-status-indicator.has-data {
  background-color: #ff9800;
  box-shadow: 0 0 5px rgba(255, 152, 0, 0.65);
}

.ai-status-indicator.offline {
  background-color: #ff9800;
  box-shadow: 0 0 5px rgba(255, 152, 0, 0.65);
}

.ai-status-indicator.loading {
  background-color: #ff9800;
  box-shadow: 0 0 6px rgba(255, 152, 0, 0.85);
  animation: aiIndicatorPulse 1.05s ease-in-out infinite;
}

@keyframes aiIndicatorPulse {
  0% {
    transform: scale(1);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.35);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0.85;
  }
}

.ai-model-selector {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 3px;
  padding: 2px 5px;
  font-size: 12px;
  max-width: 100px;
}

.ai-model-selector option,
.ai-model-selector optgroup {
  background-color: #121527;
  color: #e6ecff;
}

.ai-model-confirm {
  background: none;
  border: none;
  color: var(--success-color);
  cursor: pointer;
}

.model-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.ai-actions-container {
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.ai-result-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 15px;
  border-top: 1px solid var(--border-color);
  overflow: hidden;
}

.ai-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--text-secondary);
  font-size: 13px;
}

.ai-result-actions {
  display: flex;
  gap: 10px;
}

.ai-result-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  transition: color 0.2s;
  padding: 4px;
}

.ai-result-actions button:hover {
  color: var(--text-primary);
}

#ai-result-text {
  flex: 1;
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 15px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  outline: none;
}

#ai-result-text:focus {
  border-color: var(--accent-color);
}

.ai-tip {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.ai-action-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  transition: all 0.2s;
  text-align: left;
}

.ai-action-btn:hover:not(:disabled) {
  background: rgba(59, 130, 246, 0.06);
  border-color: rgba(59, 130, 246, 0.45);
}

.ai-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Chat Container */
.ai-chat-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 15px;
  padding-bottom: 30px;
  /* 底部留白 */
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Custom Scrollbar for Chat */
.ai-chat-container::-webkit-scrollbar {
  width: 6px;
}

.ai-chat-container::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-container::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.ai-chat-container::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.ai-message {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 100%;
  /* 全宽 */
  word-wrap: break-word;
}

.ai-message.system {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  text-align: center;
  font-style: italic;
}

.ai-message.ai {
  background-color: rgba(0, 122, 204, 0.1);
  border-left: 3px solid var(--accent-color);
  color: var(--text-primary);
}

.ai-message.user {
  background-color: rgba(255, 255, 255, 0.1);
  align-self: flex-end;
  /* 如果需要区分用户消息位置 */
}

/* Voice Read Menu */
.voice-read-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.voice-read-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  padding: 5px;
  z-index: 100;
  flex-direction: column;
  gap: 5px;
  min-width: 40px;
}

.voice-read-wrapper:hover .voice-read-menu,
.voice-read-menu:hover {
  display: flex;
}

.voice-menu-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  padding: 5px;
  cursor: pointer;
  border-radius: 3px;
}

.voice-menu-btn:hover {
  background-color: var(--bg-input);
  color: var(--accent-color);
}

.hidden {
  display: none !important;
}
