:root {
  --bg-page: #ffffff;
  --bg-sidebar: #f8fafc;
  --bg-hover: #eef2f7;
  --bg-active: #eff6ff;
  --bg-card: #ffffff;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --mark-bg: #fef08a;
  --sidebar-width: 296px;
  --toolbar-height: 58px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
a {
  font-family: inherit;
}

[hidden] {
  display: none !important;
}

.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  transition: margin-left 0.2s ease, transform 0.22s ease;
  z-index: 30;
}

.app-shell.sidebar-collapsed .sidebar {
  margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
  height: var(--toolbar-height);
  padding: 0 12px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.brand-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: inherit;
  text-align: left;
  flex: 1;
  min-width: 0;
  transition: background-color 0.15s ease;
}

.brand-btn:hover {
  background: var(--bg-hover);
}

.brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-icon svg {
  width: 17px;
  height: 17px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.25;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.25;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.mobile-only {
  display: none;
}

/* Search */
.search-section {
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  display: inline-flex;
  pointer-events: none;
}

.search-icon svg {
  width: 15px;
  height: 15px;
}

.search-input {
  width: 100%;
  height: 36px;
  padding: 0 30px 0 32px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

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

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-clear-btn {
  position: absolute;
  right: 6px;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.search-clear-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.search-clear-btn svg {
  width: 14px;
  height: 14px;
}

.search-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  padding-left: 2px;
}

/* Directory Tree */
.tree-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.tree-loading,
.tree-empty {
  padding: 24px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.tree-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-folder-btn,
.tree-file-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  color: var(--text-primary);
  padding: 6px 8px 6px calc(8px + var(--depth, 0) * 14px);
  font-size: 13px;
  line-height: 1.35;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.tree-folder-btn:hover,
.tree-file-btn:hover {
  background: var(--bg-hover);
}

.tree-folder-btn {
  font-weight: 500;
  color: var(--text-primary);
}

.tree-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.tree-folder.is-open > .tree-folder-btn .tree-chevron {
  transform: rotate(90deg);
}

.tree-folder-icon,
.tree-file-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tree-folder-icon {
  color: #eab308;
}

.tree-file-icon {
  color: #ef4444;
  margin-left: 14px;
}

.tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-label mark {
  background: var(--mark-bg);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}

.tree-count {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(148, 163, 184, 0.18);
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

.tree-file-btn.is-active {
  background: var(--bg-active);
  color: var(--accent);
  font-weight: 500;
}

.tree-file-btn.is-active .tree-file-icon {
  color: var(--accent);
}

.tree-folder-empty {
  padding: 4px 8px 4px calc(30px + var(--depth, 0) * 14px);
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Area */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-page);
}

.toolbar {
  height: var(--toolbar-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-page);
  flex-shrink: 0;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.doc-header-info {
  min-width: 0;
  flex: 1;
}

.toolbar-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.toolbar-subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.action-btn:hover {
  background: var(--bg-sidebar);
  border-color: #94a3b8;
}

.action-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.action-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.action-btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Content Area */
.content-area {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.overview-view {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px 48px;
  background: #f8fafc;
}

.overview-inner {
  max-width: 880px;
  margin: 0 auto;
}

.overview-hero {
  margin-bottom: 24px;
}

.overview-hero h2 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

.overview-hero p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-value-sm {
  font-size: 20px;
  padding-top: 4px;
  padding-bottom: 4px;
}

.stat-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.overview-section {
  margin-bottom: 26px;
}

.section-title {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.category-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.category-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.category-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
  transform: translateY(-1px);
}

.category-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-card-count {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.recent-list {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.recent-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  border-bottom: 1px solid var(--border-color);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.12s ease;
}

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

.recent-item:hover {
  background: var(--bg-sidebar);
}

.recent-item-main {
  min-width: 0;
  flex: 1;
}

.recent-item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-item-cat {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.recent-item-meta {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.empty-guide {
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  color: var(--text-secondary);
}

.empty-guide-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-guide p {
  margin: 0;
  font-size: 13px;
}

.empty-guide code,
.error-card code {
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  font-family: Consolas, "Courier New", monospace;
}

/* PDF Viewer */
.viewer-view {
  flex: 1;
  min-height: 0;
  display: flex;
  background: #525659;
}

.pdf-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Error View */
.error-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-sidebar);
}

.error-card {
  max-width: 460px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.error-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.error-card p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.sidebar-backdrop {
  display: none;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .mobile-only {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(84vw, 310px);
    margin-left: 0 !important;
    transform: translateX(-100%);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 20;
  }

  .app-shell.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .toolbar {
    padding: 0 10px;
    gap: 8px;
  }

  .action-btn {
    padding: 0 9px;
    height: 32px;
    font-size: 12px;
  }

  .overview-view {
    padding: 20px 14px 36px;
  }

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

  .recent-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
}
