* {
  box-sizing: border-box;
}

body, h1, h2, h3, h4, p {
  margin: 0;
  padding: 0;
}

/* 数学公式 (MathML / MathJax) 样式保护与基线对齐 */
.docx-wrapper math,
.docx-wrapper mjx-container {
  font-family: "Cambria Math", "Latin Modern Math", "STIX Two Math", "Apple Symbols", serif !important;
  font-size: 1.05em;
  vertical-align: middle;
}

.docx-wrapper .docx-math-block {
  display: block;
  text-align: center;
  margin: 0.45em 0;
}

.docx-wrapper mfrac {
  padding: 0 2px;
}

.docx-vml-picture {
  display: inline;
}

.docx-vml-img {
  vertical-align: middle;
  display: inline-block;
  margin: 2pt 1pt;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: #f1f5f9;
  color: #0f172a;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ========================
   顶部工具栏
   ======================== */
.toolbar {
  height: 54px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 30;
  flex-shrink: 0;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar-center {
  display: flex;
  align-items: center;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s;
}

.brand:hover {
  background: #f1f5f9;
}

.brand-logo {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(37, 99, 235, 0.28);
}

.brand-text {
  font-weight: 700;
  font-size: 15px;
  color: #0f172a;
  letter-spacing: -0.01em;
}

.brand-text span {
  font-weight: 500;
  color: #64748b;
}

.divider-v {
  width: 1px;
  height: 20px;
  background: #e2e8f0;
  margin: 0 2px;
}

.doc-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.file-name {
  font-size: 13.5px;
  font-weight: 500;
  color: #334155;
  max-width: 340px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-badge {
  font-size: 11px;
  font-weight: 500;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

/* 按钮组件 */
.btn {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  user-select: none;
  line-height: 1.2;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(29, 78, 216, 0.25);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #1d4ed8, #1e40af);
}

.btn-secondary {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #334155;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.btn-secondary:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-icon-subtle {
  background: transparent;
  color: #475569;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
}

.btn-icon-subtle:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.btn-zoom {
  background: transparent;
  color: #334155;
  width: 28px;
  height: 26px;
  padding: 0;
  font-size: 15px;
  border-radius: 6px;
}

.btn-zoom:hover {
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.btn-zoom-text {
  background: transparent;
  color: #475569;
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-zoom-text:hover {
  background: #ffffff;
  color: #0f172a;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.zoom-label {
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: center;
  color: #1e293b;
}

/* ========================
   主体布局与左侧边栏
   ======================== */
.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.sidebar {
  width: 280px;
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 20;
}

.sidebar.collapsed {
  margin-left: -280px;
}

.sidebar-search {
  padding: 12px 12px 8px;
  position: relative;
}

.sidebar-search .search-icon {
  position: absolute;
  left: 22px;
  top: 21px;
  color: #94a3b8;
  pointer-events: none;
}

.sidebar-search input {
  width: 100%;
  height: 32px;
  padding: 0 10px 0 30px;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  background: #f8fafc;
  font-size: 12.5px;
  color: #0f172a;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.sidebar-search input:focus {
  background: #ffffff;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 16px;
}

.sidebar-section {
  margin-top: 10px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 6px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.count-pill {
  background: #f1f5f9;
  color: #475569;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
}

.btn-clear {
  background: transparent;
  border: none;
  font-size: 11.5px;
  color: #64748b;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-clear:hover {
  color: #dc2626;
  background: #fef2f2;
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.list-empty {
  font-size: 12.5px;
  color: #94a3b8;
  text-align: center;
  padding: 20px 8px;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.14s ease;
  border: 1px solid transparent;
}

.doc-item:hover {
  background: #f8fafc;
}

.doc-item.active {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.doc-item-main {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  min-width: 0;
  flex: 1;
}

.doc-item-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #eff6ff;
  color: #2563eb;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.doc-item.active .doc-item-icon {
  background: #2563eb;
  color: #ffffff;
}

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

.doc-item-title {
  font-size: 13px;
  font-weight: 500;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}

.doc-item.active .doc-item-title {
  color: #1d4ed8;
  font-weight: 600;
}

.doc-item-sub {
  font-size: 11px;
  color: #64748b;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-item-remove {
  opacity: 0;
  background: transparent;
  border: none;
  color: #94a3b8;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 14px;
  transition: all 0.12s;
}

.doc-item:hover .doc-item-remove {
  opacity: 1;
}

.doc-item-remove:hover {
  background: #fee2e2;
  color: #dc2626;
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid #f1f5f9;
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
  background: #fcfcfd;
}

/* ========================
   主工作区与欢迎页
   ======================== */
.workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #e2e8f0;
}

.empty-state {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}

.welcome-container {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.drop-card {
  background: #ffffff;
  border: 1.5px dashed #cbd5e1;
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: 0 10px 30px -10px rgba(15, 23, 42, 0.07);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.drop-card:hover {
  border-color: #3b82f6;
  box-shadow: 0 14px 36px -10px rgba(37, 99, 235, 0.12);
}

.drop-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: #eff6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.drop-card h2 {
  font-size: 20px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 8px;
}

.drop-card p {
  font-size: 13.5px;
  color: #64748b;
  line-height: 1.5;
}

.btn-lg {
  padding: 10px 24px;
  font-size: 14px;
  border-radius: 9px;
  margin-top: 20px;
}

.feature-tags {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  font-size: 12px;
  color: #64748b;
}

/* 欢迎页最近阅读网格 */
.welcome-recent {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  padding: 18px 20px;
}

.welcome-recent-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.welcome-recent-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
}

.welcome-recent-header span {
  font-size: 11.5px;
  color: #64748b;
}

.welcome-recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.recent-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s ease;
}

.recent-card:hover {
  border-color: #93c5fd;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
  transform: translateY(-1px);
}

/* 加载状态与错误提示 */
.loading-state {
  position: absolute;
  inset: 0;
  background: rgba(241, 245, 249, 0.78);
  backdrop-filter: blur(4px);
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-card {
  background: #ffffff;
  padding: 24px 36px;
  border-radius: 14px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-size: 13.5px;
  color: #334155;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e2e8f0;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.error-banner {
  background: #fef2f2;
  color: #991b1b;
  border-bottom: 1px solid #fecaca;
  padding: 10px 20px;
  font-size: 13px;
  text-align: center;
  z-index: 10;
}

/* 文档滚动预览区 */
.doc-scroll-container {
  flex: 1;
  overflow: auto;
  padding: 28px 20px 56px;
}

.docx-container {
  transform-origin: top center;
  transition: transform 0.12s ease-out;
}

.docx-wrapper {
  background: transparent !important;
  padding: 0 !important;
}

.docx-wrapper > section.docx {
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.12), 0 1px 3px rgba(15, 23, 42, 0.06) !important;
  margin-bottom: 28px !important;
  border-radius: 2px;
}

/* 全屏拖拽遮罩 */
.drag-overlay {
  position: fixed;
  inset: 0;
  background: rgba(37, 99, 235, 0.14);
  backdrop-filter: blur(3px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drag-overlay.active {
  display: flex;
}

.drag-box {
  background: #1d4ed8;
  color: #ffffff;
  padding: 24px 42px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 16px 36px rgba(29, 78, 216, 0.35);
}

.drag-box-icon {
  font-size: 32px;
}

/* ========================
   原生级打印样式 (@media print)
   ======================== */
@media print {
  @page {
    size: auto;
    margin: 14mm 0;
  }

  html, body {
    background: #ffffff !important;
    height: auto !important;
    overflow: visible !important;
  }

  .no-print {
    display: none !important;
  }

  .app-body,
  .workspace,
  .doc-scroll-container {
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    height: auto !important;
    display: block !important;
    background: #ffffff !important;
  }

  .docx-container {
    transform: none !important;
  }

  .docx-wrapper {
    padding: 0 !important;
    background: #ffffff !important;
    display: block !important;
  }

  .docx-wrapper > section.docx {
    box-shadow: none !important;
    margin: 0 auto !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    min-height: auto !important;
    overflow: visible !important;
    page-break-after: always;
    break-after: page;
  }

  .docx-wrapper > section.docx:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .docx tr,
  .docx-vml-img,
  .docx math,
  .docx mjx-container,
  .docx img {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
