:root {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-code: #f6f8fa;
  --bg-hover: #f5f7fa;
  --bg-active: #eef2ff;
  --bg-badge: #f0f1f3;
  --bg-header: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --primary: #4f6ef7;
  --primary-light: #eef2ff;
  --primary-hover: #4361ee;
  --primary-text: #3b55d3;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --score-high: #16a34a;
  --score-mid: #d97706;
  --score-low: #94a3b8;
  --tag-chunk: #4f6ef7;
  --tag-symbol: #a855f7;
  --tag-heading: #0ea5e9;
  --tag-file: #64748b;
  --radius: 8px;
  --radius-sm: 5px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, 'Courier New', monospace;
  --list-width: 400px;
  --header-height: auto;
}

[data-theme="dark"] {
  --bg: #0c0f1a;
  --bg-card: #161b2e;
  --bg-input: #1e2439;
  --bg-code: #1a1f33;
  --bg-hover: #1e2439;
  --bg-active: #1c2a4d;
  --bg-badge: #252b42;
  --bg-header: #131725;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #4a5568;
  --border: #252b42;
  --border-light: #1e2439;
  --primary: #6d8cff;
  --primary-light: #1c2a4d;
  --primary-hover: #8da5ff;
  --primary-text: #8da5ff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 3px rgba(0,0,0,0.25);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.3);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== HEADER ===== */

.app-header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 100;
}

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

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
}

.header-brand h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

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

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.theme-toggle svg { pointer-events: none; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.stats-bar {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-secondary);
}

.stats-bar .stat {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.stat-dot.green { background: var(--success); }
.stat-dot.yellow { background: var(--warning); }
.stat-dot.red { background: var(--danger); }

.search-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.search-input-wrap { flex: 1; }

.search-input {
  width: 100%;
  padding: 9px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,110,247,0.12);
}

.search-btn {
  padding: 8px 18px;
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.search-btn:hover { background: var(--primary-hover); }
.search-btn:active { transform: scale(0.97); }
.search-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.filters-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.filter-input {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  background: var(--bg-input);
  color: var(--text);
  width: 56px;
  outline: none;
  transition: border-color 0.2s;
}
.filter-input:focus { border-color: var(--primary); }

.product-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.product-tag {
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  background: transparent;
  color: var(--text-secondary);
  transition: all 0.15s;
  font-weight: 500;
}
.product-tag:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.product-tag.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ===== MAIN LAYOUT ===== */

.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ===== LEFT: LIST PANEL ===== */

.list-panel {
  width: var(--list-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-card);
  overflow: hidden;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.list-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.list-count {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.list-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.list-body::-webkit-scrollbar { width: 5px; }
.list-body::-webkit-scrollbar-track { background: transparent; }
.list-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.list-body::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Result item in list */
.result-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.12s;
  border-left: 3px solid transparent;
}
.result-item:hover { background: var(--bg-hover); }
.result-item.active {
  background: var(--bg-active);
  border-left-color: var(--primary);
}

.result-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.score-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  flex-shrink: 0;
  line-height: 1.5;
}
.score-badge.high { background: rgba(22,163,74,0.12); color: var(--score-high); }
.score-badge.mid  { background: rgba(217,119,6,0.12); color: var(--score-mid);  }
.score-badge.low  { background: rgba(148,163,184,0.12); color: var(--score-low);  }

.type-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}
.type-badge.chunk   { background: rgba(79,110,247,0.1);  color: var(--tag-chunk); }
.type-badge.symbol  { background: rgba(168,85,247,0.1);  color: var(--tag-symbol); }
.type-badge.heading { background: rgba(14,165,233,0.1);  color: var(--tag-heading); }
.type-badge.file    { background: rgba(100,116,139,0.1); color: var(--tag-file); }

.product-badge {
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-badge);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.result-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.result-item-path {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-item-snippet {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 5px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
}
.result-item-snippet mark {
  background: rgba(250,176,5,0.25);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}

/* ===== RIGHT: DETAIL PANEL ===== */

.detail-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.detail-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

/* Detail header */
.detail-file-header {
  padding: 16px 24px 12px;
  background: var(--bg-card);
  flex-shrink: 0;
}

.detail-file-path {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.detail-file-path .file-icon {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--primary);
}

.detail-file-line {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  margin-left: 28px;
  font-family: var(--font-mono);
}

.detail-badges-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  margin-left: 28px;
  flex-wrap: wrap;
}

/* Detail info section */
.detail-info {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-card);
  flex-shrink: 0;
}

.detail-info-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  align-items: flex-start;
}
.detail-info-row:last-child { margin-bottom: 0; }

.info-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  min-width: 72px;
  flex-shrink: 0;
}

.info-value {
  color: var(--text);
  word-break: break-word;
}

/* Detail tabs */
.detail-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
  padding: 0 16px;
}

.detail-tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  user-select: none;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}
.detail-tab:hover { color: var(--text); }
.detail-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.detail-tab-badge {
  font-size: 10px;
  background: var(--bg-badge);
  color: var(--text-muted);
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 5px;
  font-weight: 600;
}

/* Detail content area */
.detail-content-area {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.detail-content-area::-webkit-scrollbar { width: 6px; }
.detail-content-area::-webkit-scrollbar-track { background: transparent; }
.detail-content-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.detail-content-area::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Two-column layout */
.detail-two-col {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  height: 100%;
}

.detail-col-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

.detail-col-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  height: 100%;
}


.detail-fullfile-area {
  flex: 1;
  overflow: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.detail-fullfile-area::-webkit-scrollbar { width: 6px; }
.detail-fullfile-area::-webkit-scrollbar-track { background: transparent; }
.detail-fullfile-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.detail-fullfile-area::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Code display */
.code-container {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.code-container pre {
  margin: 0;
  padding: 16px 20px;
  font-size: 13px;
  line-height: 1.65;
  font-family: var(--font-mono);
  background: var(--bg-code) !important;
  overflow: auto;
  tab-size: 2;
  flex: 1;
  min-height: 0;
}

.code-container pre code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: transparent !important;
  padding: 0 !important;
}

.code-lang-badge {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-badge);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  z-index: 1;
  pointer-events: none;
}

/* Line-numbered code table */
.code-lines-scroll {
  background: var(--bg-code);
}

.code-line-table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  tab-size: 2;
}

.code-line-row.hl {
  background: rgba(79, 110, 247, 0.10);
}
[data-theme="dark"] .code-line-row.hl {
  background: rgba(109, 140, 255, 0.12);
}

.code-line-num {
  width: 1px;
  white-space: nowrap;
  padding: 0 12px 0 16px;
  text-align: right;
  color: var(--text-muted);
  user-select: none;
  vertical-align: top;
  opacity: 0.6;
  font-size: 12px;
}
.code-line-num::before {
  content: attr(data-line);
}
.code-line-row.hl .code-line-num {
  color: var(--primary);
  opacity: 1;
}

.code-line-content {
  padding: 0 16px 0 0;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

/* Markdown rendered view */
.markdown-body {
  padding: 20px 24px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}
.markdown-body h1 { font-size: 1.6em; border-bottom: 1px solid var(--border-light); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.35em; border-bottom: 1px solid var(--border-light); padding-bottom: 0.25em; }
.markdown-body h3 { font-size: 1.15em; }

.markdown-body p { margin-bottom: 0.8em; }

.markdown-body code {
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: var(--font-mono);
}

.markdown-body pre {
  background: var(--bg-code);
  padding: 14px 16px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 0.8em 0;
  border: 1px solid var(--border-light);
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
}

.markdown-body ul, .markdown-body ol {
  padding-left: 1.8em;
  margin-bottom: 0.8em;
}

.markdown-body li { margin-bottom: 0.3em; }

.markdown-body blockquote {
  border-left: 4px solid var(--primary);
  padding: 0.5em 1em;
  margin: 0.8em 0;
  background: var(--primary-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.8em 0;
}

.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.markdown-body th {
  background: var(--bg-hover);
  font-weight: 600;
}

.markdown-body a {
  color: var(--primary);
  text-decoration: none;
}
.markdown-body a:hover { text-decoration: underline; }

.markdown-body img { max-width: 100%; border-radius: var(--radius); }

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}

/* Detail metadata view */
.detail-meta-view {
  padding: 16px 24px;
}

.meta-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.meta-card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.meta-item {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
}
.meta-item:last-child { border-bottom: none; }

.meta-item-label { color: var(--text-secondary); }
.meta-item-value {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: right;
  max-width: 60%;
  word-break: break-all;
}

/* Full file status bar */
.fullfile-status {
  padding: 8px 20px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--primary-light);
  border-bottom: 1px solid var(--border-light);
  font-family: var(--font-mono);
}

/* ===== SHARED ===== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  color: var(--text-muted);
  gap: 10px;
}
.empty-state p { font-size: 13px; }

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px;
  gap: 12px;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin: 12px 16px;
}

/* ===== RESPONSIVE ===== */

@media (max-width: 860px) {
  :root { --list-width: 280px; }
}

@media (max-width: 640px) {
  .main-content { flex-direction: column; }
  .list-panel {
    width: 100%;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .detail-panel { min-height: 50vh; }
  .app-header { padding: 10px 12px; }
  .filters-row { flex-direction: column; gap: 6px; align-items: flex-start; }
  .detail-two-col { flex-direction: column; }
  .detail-col-left {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 50%;
  }
}
