:root {
  --bg: #F5F6F8;
  --panel: #FFFFFF;
  --line: #E8EAEE;
  --line-2: #DFE3E9;
  --text: #1F2329;
  --text-2: #5A616B;
  --text-3: #8A919C;
  --brand: #2563EB;
  --brand-hover: #1D4FD8;
  --brand-weak: #EFF4FF;
  --radius: 10px;
  --paper-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 12px 32px -20px rgba(16, 24, 40, .28);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- topbar ---------- */
.topbar {
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}

.brand-name { font-size: 14px; font-weight: 600; letter-spacing: .2px; }

.title-zone {
  display: flex; align-items: center; gap: 10px;
  min-width: 0; flex: 1 1 auto;
  padding-left: 14px;
  border-left: 1px solid var(--line);
  height: 22px;
}

.doc-title {
  font-size: 13.5px;
  color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 460px;
}

.doc-title.has-doc { color: var(--text); font-weight: 500; }

.page-badge {
  flex: 0 0 auto;
  font-size: 11.5px;
  color: var(--text-3);
  background: #F3F4F7;
  border-radius: 5px;
  padding: 2px 7px;
  font-variant-numeric: tabular-nums;
}

.topbar-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

.search-box {
  display: flex; align-items: center; gap: 6px;
  height: 30px;
  padding: 0 8px;
  background: #F5F6F8;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-3);
  transition: background .15s, border-color .15s;
}

.search-box:focus-within {
  background: #fff;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

.search-box input {
  border: 0; outline: 0; background: transparent;
  font-size: 12.5px; color: var(--text);
  width: 132px;
  font-family: inherit;
}

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

.search-count {
  font-size: 11px; color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.zoom-group {
  display: flex; align-items: center;
  height: 30px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.zoom-btn, .zoom-value, .zoom-fit {
  border: 0; background: transparent; cursor: pointer;
  height: 100%;
  color: var(--text-2);
  font-family: inherit;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}

.zoom-btn { width: 28px; font-size: 15px; line-height: 1; }
.zoom-value { width: 46px; font-size: 11.5px; font-variant-numeric: tabular-nums; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.zoom-fit { width: 42px; font-size: 11.5px; border-left: 1px solid var(--line); }

.zoom-btn:hover, .zoom-value:hover, .zoom-fit:hover { background: var(--brand-weak); color: var(--brand); }
.zoom-fit.on { color: var(--brand); background: var(--brand-weak); }

.icon-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: #fff;
  color: var(--text-2);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}

.icon-btn:hover { background: var(--brand-weak); color: var(--brand); border-color: #C7D8FB; }

.btn-primary {
  height: 30px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, transform .06s;
}

.btn-primary:hover { background: var(--brand-hover); }
.btn-primary:active { transform: translateY(.5px); }
.btn-lg { height: 36px; padding: 0 22px; font-size: 13px; }

/* ---------- body ---------- */
.body { flex: 1 1 auto; display: flex; min-height: 0; }

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 10px 10px 0;
  flex: 0 0 auto;
}

.tab {
  flex: 1;
  height: 30px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-3);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.tab:hover { background: #F5F6F8; color: var(--text-2); }
.tab.active { background: var(--brand-weak); color: var(--brand); font-weight: 500; }

.pane { flex: 1 1 auto; overflow-y: auto; padding: 8px; min-height: 0; }
.pane.hidden { display: none; }

.lib-list { display: flex; flex-direction: column; gap: 2px; }

.lib-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 8px;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: background .12s;
}

.lib-item:hover { background: #F5F6F8; }
.lib-item.active { background: var(--brand-weak); }

.lib-icon {
  flex: 0 0 26px;
  width: 26px; height: 26px;
  border-radius: 6px;
  background: #EEF1F6;
  color: var(--text-3);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: .3px;
  display: flex; align-items: center; justify-content: center;
}

.lib-item.active .lib-icon { background: var(--brand); color: #fff; }

.lib-meta { min-width: 0; flex: 1 1 auto; }

.lib-name {
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.5;
}

.lib-sub { font-size: 10.5px; color: var(--text-3); line-height: 1.4; }

.lib-del {
  flex: 0 0 auto;
  width: 20px; height: 20px;
  border: 0; background: transparent;
  border-radius: 5px;
  color: var(--text-3);
  cursor: pointer;
  font-size: 14px; line-height: 1;
  opacity: 0;
  transition: opacity .12s, background .12s, color .12s;
}

.lib-item:hover .lib-del { opacity: 1; }
.lib-del:hover { background: #FDE8E8; color: #D92D20; }

.lib-empty {
  padding: 26px 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.9;
}

.lib-empty span { font-size: 11px; color: var(--text-3); }

.sidebar-foot {
  flex: 0 0 auto;
  padding: 8px 14px 10px;
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  color: var(--text-3);
  line-height: 1.5;
}

/* outline */
.outline-list { display: flex; flex-direction: column; }

.ol-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text-2);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 2px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
}

.ol-item:hover { background: #F5F6F8; color: var(--text); }
.ol-item.active { color: var(--brand); background: var(--brand-weak); border-left-color: var(--brand); }
.ol-item.lv2 { padding-left: 20px; font-size: 12px; }
.ol-item.lv3 { padding-left: 32px; font-size: 12px; color: var(--text-3); }
.ol-item.lv4 { padding-left: 44px; font-size: 11.5px; color: var(--text-3); }

/* ---------- reader ---------- */
.reader-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

.progress { height: 2px; flex: 0 0 2px; background: transparent; }
.progress-fill { height: 100%; width: 0; background: var(--brand); opacity: .55; transition: width .1s linear; }

.reader {
  flex: 1 1 auto;
  overflow: auto;
  padding: 26px 24px 64px;
  position: relative;
  scroll-behavior: smooth;
}

.reader::-webkit-scrollbar, .pane::-webkit-scrollbar { width: 10px; height: 10px; }
.reader::-webkit-scrollbar-thumb, .pane::-webkit-scrollbar-thumb {
  background: #D5D9E0; border-radius: 6px; border: 3px solid transparent; background-clip: content-box;
}
.reader::-webkit-scrollbar-thumb:hover, .pane::-webkit-scrollbar-thumb:hover { background: #BFC5CF; background-clip: content-box; }
.reader::-webkit-scrollbar-track, .pane::-webkit-scrollbar-track { background: transparent; }

/* empty state */
.empty-state { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 200px); }
.empty-state.hidden { display: none; }

.empty-card {
  text-align: center;
  max-width: 460px;
  padding: 40px 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

.empty-icon {
  width: 60px; height: 60px;
  margin: 0 auto 18px;
  border-radius: 16px;
  background: var(--brand-weak);
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}

.empty-card h2 { font-size: 16px; font-weight: 600; margin: 0 0 8px; letter-spacing: .2px; }
.empty-card p { font-size: 12.5px; color: var(--text-2); margin: 0 0 20px; line-height: 1.8; }
.empty-card .hint { font-size: 11.5px; color: var(--text-3); margin: 20px 0 0; line-height: 1.8; }
.empty-card code {
  background: #F3F4F7; border-radius: 4px; padding: 1px 5px;
  font-family: "SFMono-Regular", Consolas, monospace; font-size: 11.5px; color: var(--text-2);
}

/* document paper */
.doc-container { min-height: 100%; }

.docx-wrapper {
  background: transparent !important;
  padding: 0 !important;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.docx-wrapper > section.docx {
  margin: 0 auto !important;
  background: #fff !important;
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow: var(--paper-shadow);
  overflow: visible !important;
}

.docx-wrapper > section.docx:last-child { margin-bottom: 0 !important; }

/* search highlight */
mark.dr-hit {
  background: #FFE58F;
  color: inherit;
  padding: 0;
  border-radius: 2px;
}
mark.dr-hit.dr-active { background: #FFB020; box-shadow: 0 0 0 1px rgba(255, 176, 32, .6); }

/* loading */
.loading {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(245, 246, 248, .78);
  backdrop-filter: blur(2px);
  z-index: 60;
  font-size: 12.5px;
  color: var(--text-2);
}

.loading.on { display: flex; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid #D8DEE9;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* drop mask */
.drop-mask {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, .06);
  border: 2px dashed var(--brand);
  z-index: 70;
  pointer-events: none;
}

.drop-mask.on { display: flex; }

.drop-inner {
  background: #fff;
  color: var(--brand);
  font-size: 13px;
  font-weight: 500;
  padding: 12px 22px;
  border-radius: 10px;
  box-shadow: 0 8px 30px -12px rgba(37, 99, 235, .5);
}

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 12px);
  background: #1F2329;
  color: #fff;
  font-size: 12.5px;
  padding: 9px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 90;
  max-width: 70vw;
}

.toast.on { opacity: .95; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .search-box input { width: 90px; }
  .doc-title { max-width: 160px; }
}

@media print {
  .topbar, .sidebar, .progress, .empty-state, .loading, .toast, .drop-mask { display: none !important; }
  html, body { overflow: visible; height: auto; background: #fff; }
  .app, .body, .reader-wrap, .reader { display: block; height: auto; overflow: visible; padding: 0; }
  .docx-wrapper { gap: 0 !important; }
  .docx-wrapper > section.docx { box-shadow: none !important; border: 0 !important; margin: 0 !important; }
}
