:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --border: #e3e8e6;
  --text: #1f2a28;
  --muted: #6b7c78;
  --accent: #0e7c66;
  --accent-soft: #e7f4f0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 36, .06), 0 8px 24px rgba(16, 40, 36, .05);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 顶栏 ---------- */
.topbar {
  flex: none;
  padding: 18px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .2px;
}

.topbar .sub {
  margin: 5px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 布局 ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  padding: 16px;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  padding: 8px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.group + .group {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  word-break: break-word;
}

.group-head .count {
  flex: none;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 999px;
}

.file {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background .15s;
}

.file:hover { background: #f1f5f4; }

.file.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.file .ico {
  flex: none;
  margin-top: 1px;
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
  color: var(--muted);
  background: #eef1f0;
  border-radius: 4px;
}

.file.is-active .ico {
  color: #fff;
  background: var(--accent);
}

.file .label {
  flex: 1;
  word-break: break-word;
}

/* ---------- 预览区 ---------- */
.viewer {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.viewer-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.viewer-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  word-break: break-word;
}

.viewer-meta {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.zoom {
  flex: none;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.zoom button {
  padding: 5px 10px;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}

.zoom button:hover {
  background: #f1f5f4;
  color: var(--text);
}

.viewer-body {
  position: relative;
  flex: 1;
  min-height: 0;
}

/* PDF.js 画布阅读器 */
.viewer-body.is-pdf {
  overflow: hidden;
}

.pdf-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 12px;
  background: #e9eceb;
  -webkit-overflow-scrolling: touch;
}

.pdf-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.pdf-page {
  max-width: 100%;
  overflow: hidden;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(16, 40, 36, .14);
  transition: height .15s;
}

.pdf-page canvas {
  display: block;
  opacity: 0;
  transition: opacity .2s;
}

.pdf-page canvas.is-ready {
  opacity: 1;
}

.pdf-page.is-failed {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  font-size: 13px;
  color: var(--muted);
}

.viewer-body.is-image {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow: auto;
  background: #f0f2f1;
}

.viewer-body.is-image img {
  max-width: 100%;
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

/* ---------- 窄屏 ---------- */
@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    gap: 12px;
    padding: 12px;
  }

  .sidebar { max-height: 42vh; }
  .viewer { min-height: 60vh; }
  .viewer-meta { display: none; }
  .viewer-bar { gap: 8px; padding: 10px 12px; }
  .zoom button { padding: 5px 8px; }
}