:root {
  --bg: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-hover: #e8e8e8;
  --text: #1a1a1a;
  --text-secondary: #666;
  --text-muted: #999;
  --border: #e0e0e0;
  --accent: #0366d6;
  --accent-hover: #0256b9;
  --error: #d73a49;
  --success: #28a745;
  --shadow: rgba(0,0,0,0.08);
  --oversized: #ccc;
  --code-bg: #f6f8fa;
  --control-bg: #ffffff;
  --table-row-index: #f8f9fb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --bg-secondary: #252525;
    --bg-hover: #333;
    --text: #e0e0e0;
    --text-secondary: #999;
    --text-muted: #666;
    --border: #333;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --error: #f85149;
    --success: #3fb950;
    --shadow: rgba(0,0,0,0.3);
    --oversized: #555;
    --code-bg: #2d2d2d;
    --control-bg: #202020;
    --table-row-index: #222;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sidebar-header h1 { font-size: 16px; font-weight: 600; }

.shares-section {
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

.shares-section h2 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.share-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.share-link:hover { text-decoration: underline; }
.share-link .badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-hover);
  color: var(--text-muted);
}

.share-link.oversized {
  color: var(--oversized);
  cursor: not-allowed;
  text-decoration: none;
}

.file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  user-select: none;
}

.tree-item:hover { background: var(--bg-hover); }
.tree-item.active { background: var(--bg-hover); color: var(--accent); font-weight: 500; }
.tree-item.oversized { color: var(--oversized); cursor: not-allowed; }
.tree-item .icon { font-size: 12px; width: 16px; text-align: center; flex-shrink: 0; }
.tree-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-children { padding-left: 20px; }

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.toolbar .search-input {
  flex: 1;
  max-width: 300px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.toolbar .search-input:focus { border-color: var(--accent); }

.toolbar button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.toolbar button:hover { background: var(--bg-hover); }

.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
  display: flex;
  gap: 24px;
}

.content { flex: 1; max-width: 95%; min-width: 0; }

.content h1, .content h2, .content h3, .content h4 {
  margin: 24px 0 12px;
  font-weight: 600;
  line-height: 1.3;
}

.content h1 { font-size: 28px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.content h2 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.content h3 { font-size: 18px; }
.content p { margin: 8px 0; }
.content ul, .content ol { margin: 8px 0; padding-left: 24px; }
.content li { margin: 4px 0; }
.content a { color: var(--accent); text-decoration: none; }
.content a:hover { text-decoration: underline; }
.content code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.content pre {
  background: var(--code-bg);
  border-radius: 6px;
  padding: 16px;
  overflow-x: auto;
  margin: 16px 0;
}

.content pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.45;
}

.content blockquote {
  margin: 16px 0;
  padding: 0 16px;
  color: var(--text-secondary);
  border-left: 4px solid var(--border);
}

.content img { max-width: 100%; border-radius: 4px; }
.content hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.content table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: max-content; margin: 16px 0; }
.content th, .content td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.content th { background: var(--bg-secondary); font-weight: 600; }

.md-table-shell {
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: visible;
  background: var(--bg);
}

.md-table-toolbar {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 8px 6px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.md-table-count {
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

.md-table-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.md-table-column-picker {
  position: relative;
  flex-shrink: 0;
}

.md-table-search,
.md-table-filter-row input {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--control-bg);
  color: var(--text);
  outline: none;
}

.md-table-search {
  width: min(240px, 42vw);
  padding: 5px 8px;
  font-size: 12px;
}

.md-table-search:focus,
.md-table-filter-row input:focus {
  border-color: var(--accent);
}

.md-table-action {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--control-bg);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
}

.md-table-action:hover,
.md-table-action.active {
  border-color: var(--accent);
  color: var(--accent);
}

.md-table-column-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 20;
  min-width: 160px;
  max-width: min(280px, 70vw);
  max-height: 280px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--control-bg);
  box-shadow: 0 8px 24px var(--shadow);
}

.md-table-column-menu[hidden] { display: none; }

.md-table-column-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
}

.md-table-column-option:hover { background: var(--bg-hover); }

.md-table-column-option input {
  accent-color: var(--accent);
}

.md-table-scroll {
  max-height: min(72vh, 720px);
  overflow: auto;
}

.content .md-table-scroll table { margin: 0; }
.content .md-data-table {
  width: max-content;
  min-width: 0;
}

.content .md-data-table.md-table-resized {
  table-layout: fixed;
  min-width: 0;
}

.content .md-data-table th,
.content .md-data-table td {
  border-width: 0 1px 1px 0;
  vertical-align: top;
}

.content .md-data-table tr:last-child td { border-bottom-width: 0; }
.content .md-data-table th:last-child,
.content .md-data-table td:last-child { border-right-width: 0; }

.content .md-data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0;
}

.md-table-sort {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  text-align: left;
}

.md-table-sort:hover { background: var(--bg-hover); }
.md-table-row-index-label { cursor: default; }

.md-table-sort-marker {
  color: var(--accent);
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
}

.md-table-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  z-index: 4;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}

.md-table-resizer:hover {
  background: var(--accent);
  opacity: 0.45;
}

.md-table-filter-row { display: none; }
.show-column-filters .md-table-filter-row { display: table-row; }

.content .md-data-table .md-table-filter-row th {
  top: 38px;
  padding: 5px;
}

.md-table-filter-row input {
  width: 100%;
  min-width: 72px;
  padding: 4px 6px;
  font-size: 12px;
}

.content .md-data-table .md-table-row-index {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 1%;
  min-width: 42px;
  padding: 8px;
  background: var(--table-row-index);
  color: var(--text-muted);
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}

.content .md-data-table thead .md-table-row-index {
  z-index: 3;
  padding: 0;
}

.content .md-data-table .md-table-filter-row .md-table-row-index {
  padding: 5px;
}

.content .file-separator {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.content .error-message {
  padding: 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--error);
  border-radius: 8px;
  color: var(--error);
  text-align: center;
}

.toc {
  width: 200px;
  min-width: 200px;
  position: sticky;
  top: 32px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.toc h3 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.toc a {
  display: block;
  padding: 3px 0;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc a:hover { color: var(--accent); }
.toc .toc-h2 { padding-left: 12px; }
.toc .toc-h3 { padding-left: 24px; }
.toc .toc-h4 { padding-left: 36px; }
.toc .toc-h5 { padding-left: 48px; }
.toc .toc-h6 { padding-left: 60px; }

.search-results {
  position: absolute;
  top: 100%;
  left: 16px;
  right: 16px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px var(--shadow);
  z-index: 100;
  display: none;
}

.search-results.show { display: block; }

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

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item .result-name { font-weight: 500; font-size: 14px; }
.search-result-item .result-snippet { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* 暗色模式切换 */
.dark-mode-toggle {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  box-shadow: 0 2px 8px var(--shadow);
}

.dark-mode-toggle:hover { background: var(--bg-hover); }

/* 分享页面样式 */
.share-container {
  margin: 0 auto;
  padding: 32px;
}

.password-form {
  max-width: 400px;
  margin: 80px auto;
  padding: 32px;
  background: var(--bg-secondary);
  border-radius: 12px;
  text-align: center;
}

.password-form h2 { margin-bottom: 16px; }
.password-form input {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  margin-bottom: 12px;
}

.password-form input:focus { border-color: var(--accent); }
.password-form button {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 14px;
  cursor: pointer;
}

.password-form button:hover { background: var(--accent-hover); }
.password-form .error { color: var(--error); font-size: 13px; margin-top: 8px; }

/* 加载状态 */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 64px;
  color: var(--text-muted);
}

@media (max-width: 720px) {
  .content-area,
  .share-container { padding: 16px; }
  .md-table-toolbar { align-items: stretch; flex-direction: column; gap: 4px; }
  .md-table-controls { justify-content: stretch; }
  .md-table-search { flex: 1; width: auto; }
}
