/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #f5f3ef;
  --bg-secondary: #ffffff;
  --bg-tertiary: #eae7e1;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-hover: rgba(59, 130, 246, 0.06);
  --bg-active: rgba(59, 130, 246, 0.12);
  --border: rgba(0, 0, 0, 0.08);
  --border-light: rgba(0, 0, 0, 0.12);
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #2563eb;
  --accent-glow: rgba(37, 99, 235, 0.15);
  --accent-green: #059669;
  --accent-amber: #d97706;
  --accent-red: #dc2626;
  --accent-purple: #7c3aed;
  --sidebar-width: 340px;
  --topbar-height: 56px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 15px;
}

body {
  font-family: 'Inter', 'Noto Sans SC', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow: hidden;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: transform var(--transition), opacity var(--transition);
  z-index: 100;
}

.sidebar.collapsed {
  transform: translateX(-100%);
  opacity: 0;
  position: absolute;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

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

.logo-icon {
  font-size: 1.5rem;
}

.logo-text {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-toggle,
.sidebar-toggle-open {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.sidebar-toggle:hover,
.sidebar-toggle-open:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ===== Search ===== */
.search-box {
  padding: 12px 16px;
  position: relative;
}

.search-box .search-icon {
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  pointer-events: none;
  z-index: 1;
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.87rem;
  outline: none;
  transition: all var(--transition);
  font-family: inherit;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 16px;
  right: 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  max-height: 400px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}

.search-results.hidden {
  display: none;
}

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.search-result-snippet {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.search-result-path {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 3px;
  opacity: 0.7;
}

/* ===== Nav Tabs ===== */
.nav-tabs {
  display: flex;
  padding: 0 16px;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.nav-tab {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  font-family: inherit;
}

.nav-tab:hover {
  color: var(--text-secondary);
}

.nav-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ===== File Tree ===== */
.file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.loading-spinner {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.tree-folder {
  user-select: none;
}

.tree-folder-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition);
}

.tree-folder-header:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tree-folder-header .folder-icon {
  font-size: 0.9rem;
  transition: transform var(--transition);
}

.tree-folder-header.open .folder-icon {
  transform: rotate(90deg);
}

.tree-folder-children {
  display: none;
}

.tree-folder-children.open {
  display: block;
}

.tree-file {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px 6px 32px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.82rem;
  transition: all var(--transition);
  border-left: 2px solid transparent;
}

.tree-file:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tree-file.active {
  background: var(--bg-active);
  color: var(--accent);
  border-left-color: var(--accent);
}

.tree-file .file-icon {
  font-size: 0.85rem;
  flex-shrink: 0;
}

.tree-file .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-file .file-date {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Deeper nesting */
.tree-folder .tree-folder .tree-file {
  padding-left: 48px;
}

.tree-folder .tree-folder .tree-folder .tree-file {
  padding-left: 64px;
}

.tree-folder .tree-folder .tree-folder-header {
  padding-left: 32px;
}

.tree-folder .tree-folder .tree-folder .tree-folder-header {
  padding-left: 48px;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.sidebar-toggle-open {
  display: none;
}

.sidebar.collapsed~.main-content .sidebar-toggle-open {
  display: block;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.breadcrumb-sep {
  opacity: 0.4;
}

.breadcrumb-current {
  color: var(--text-primary);
  font-weight: 500;
}

.topbar-actions {
  margin-left: auto;
}

.file-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ===== Welcome Screen ===== */
.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  overflow-y: auto;
}

.welcome-card {
  text-align: center;
  max-width: 600px;
}

.welcome-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 30px var(--accent-glow));
}

.welcome-card h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-card p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 32px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  /* 移除 mobile 卡顿元凶 backdrop-filter: blur(10px); */
  transition: all var(--transition);
}

.stat-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
  transform: translateY(-2px);
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.quick-link {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.quick-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-hover);
}

/* ===== Article Viewer ===== */
.article-viewer {
  flex: 1;
  overflow-y: auto;
  padding: 32px 48px 60px;
}

.article-viewer.hidden {
  display: none;
}

/* Markdown Styles */
.article-content {
  max-width: 860px;
  margin: 0 auto;
  line-height: 1.8;
}

.article-content h1 {
  font-size: 1.7rem;
  font-weight: 700;
  margin: 28px 0 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
  background: linear-gradient(135deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.article-content h2 {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 28px 0 12px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.article-content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 20px 0 10px;
  color: var(--text-primary);
}

.article-content h4 {
  font-size: 1rem;
  font-weight: 600;
  margin: 16px 0 8px;
  color: var(--text-secondary);
}

.article-content p {
  margin: 10px 0;
  color: var(--text-secondary);
}

.article-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

.article-content em {
  color: var(--accent-amber);
}

.article-content a {
  color: var(--accent);
  text-decoration: none;
}

.article-content a:hover {
  text-decoration: underline;
}

.article-content ul,
.article-content ol {
  padding-left: 24px;
  margin: 8px 0;
}

.article-content li {
  margin: 4px 0;
  color: var(--text-secondary);
}

.article-content li strong {
  color: var(--text-primary);
}

.article-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 10px 16px;
  margin: 12px 0;
  background: rgba(37, 99, 235, 0.04);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.article-content code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  color: var(--accent-green);
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}

.article-content pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  overflow-x: auto;
  margin: 12px 0;
}

.article-content pre code {
  background: none;
  padding: 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.6;
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.87rem;
}

.article-content th {
  background: var(--bg-tertiary);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.article-content td {
  padding: 9px 12px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.article-content tr:hover td {
  background: var(--bg-hover);
}

.article-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.article-content img {
  max-width: 520px;
  width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 12px 0;
  display: block;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

/* Attitude emoji highlights in tables */
.article-content td:has(🟢),
.article-content td:has(🔴),
.article-content td:has(🟡),
.article-content td:has(⚡),
.article-content td:has(⚠️) {
  font-weight: 500;
}

/* ===== Zhihu Article Reader ===== */
.zhihu-article {
  max-width: 860px;
  margin: 0 auto;
}

.zhihu-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.zhihu-type {
  background: var(--accent-glow);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.78rem;
}

.zhihu-link {
  color: var(--accent) !important;
  text-decoration: none;
  margin-left: auto;
}

.zhihu-link:hover {
  text-decoration: underline;
}

.zhihu-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0 0 24px;
  line-height: 1.4;
  background: linear-gradient(135deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.zhihu-content {
  line-height: 1.9;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.zhihu-content p {
  margin: 12px 0;
}

.zhihu-content img {
  max-width: 100%;
  border-radius: var(--radius-md);
  margin: 12px 0;
  display: block;
}

.zhihu-content a {
  color: var(--accent);
}

.zhihu-content b,
.zhihu-content strong {
  color: var(--text-primary);
}

.zhihu-content figure {
  margin: 16px 0;
}

.zhihu-content figcaption {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Comments */
.zhihu-comments {
  margin-top: 40px;
  border-top: 2px solid var(--border);
  padding-top: 24px;
}

.zhihu-comments-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 16px;
}

.zhihu-comment {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: border-color var(--transition);
}

.zhihu-comment:hover {
  border-color: var(--border-light);
}

.zhihu-comment-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.zhihu-comment-author {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.zhihu-comment-author.is-op {
  color: var(--accent);
}

.op-tag {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
  margin-left: 4px;
  vertical-align: middle;
}

.zhihu-comment-votes {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.zhihu-comment-addr {
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.zhihu-comment-body {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.zhihu-comment-body br+br {
  display: none;
}

/* Replies */
.zhihu-replies {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--border-light);
}

.zhihu-reply {
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding: 6px 0;
  line-height: 1.5;
}

.zhihu-reply+.zhihu-reply {
  border-top: 1px solid var(--border);
}

.zhihu-reply-author {
  font-weight: 600;
  color: var(--text-primary);
  margin-right: 4px;
}

.zhihu-reply-author.is-op {
  color: var(--accent);
}

.zhihu-reply-to {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-right: 4px;
}

.zhihu-reply-content {
  color: var(--text-secondary);
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100vh;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
  }

  .sidebar-toggle-open {
    display: block !important;
  }

  .article-viewer {
    padding: 20px 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .zhihu-meta {
    font-size: 0.75rem;
    gap: 8px;
  }

  .zhihu-title {
    font-size: 1.3rem;
  }
}

/* ===== Export Bar ===== */
.export-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-card-solid, #ffffff);
  /* 使用纯色替代模糊，防穿透卡顿 */
  box-shadow: var(--shadow-sm);
}

.export-bar-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.export-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  white-space: nowrap;
}

.export-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.export-btn:active {
  transform: translateY(0);
}

.export-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.export-btn-pdf:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.export-btn-png:hover {
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.export-btn-all:hover {
  border-color: var(--accent-purple);
  color: var(--accent-purple);
}

.export-icon {
  font-size: 0.95rem;
}

.export-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
  transition: color var(--transition);
}

.export-status.exporting {
  color: var(--accent-amber);
}

.export-status.success {
  color: var(--accent-green);
}

.export-status.error {
  color: var(--accent-red);
}

@media (max-width: 768px) {
  .export-bar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
  }

  .export-btn {
    padding: 6px 10px;
    font-size: 0.78rem;
  }
}

/* ===== 圈主评论高亮 ===== */
.zhihu-comment.is-op-comment {
  background: rgba(37, 99, 235, 0.06);
  border-color: var(--accent);
  border-left: 3px solid var(--accent);
}

.zhihu-comment.is-op-comment .zhihu-comment-body {
  color: var(--text-primary);
}

.zhihu-reply.is-op-reply {
  background: rgba(37, 99, 235, 0.08);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  margin: 2px 0;
}

/* ===== 文章工具栏（复制/下载）===== */
.article-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.article-toolbar .export-btn {
  font-size: 0.82rem;
  padding: 6px 14px;
}

.copy-success {
  color: var(--accent-green);
  font-size: 0.82rem;
  align-self: center;
  font-weight: 500;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}