/* 标书格式统一器 — 工作台 UI + A4 纸张预览 */

:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #5c6570;
  --line: #d8dde3;
  --accent: #1f6feb;
  --accent-hover: #1858c4;
  --ok: #1a7f37;
  --warn: #9a6700;
  --danger: #cf222e;
  --paper-shadow: 0 10px 32px rgba(15, 23, 42, 0.12);
  --radius: 8px;
  --font-ui: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --page-w: 21cm;
  --page-h: 29.7cm;
  --mt: 2.54cm;
  --mb: 2.54cm;
  --ml: 3.17cm;
  --mr: 3.17cm;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
}

button, input, select { font: inherit; }

.app {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  min-height: 0;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: linear-gradient(160deg, #1f6feb, #0b3d91);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
}

.brand-sub {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fafbfc;
  padding: 12px;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 650;
  text-transform: none;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.panel h2 .count {
  margin-left: 6px;
  color: var(--ink);
  font-weight: 600;
}

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1.5px dashed #b6c0cb;
  border-radius: var(--radius);
  background: #fff;
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  position: relative;
  min-height: 88px;
}

.drop-title { color: var(--ink); }
.drop-title strong { color: var(--accent); }
.drop-hint { font-size: 12px; }

/* 视觉隐藏但仍可被 label 触发的 file input */
.drop input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.drop:hover, .drop:focus-within {
  border-color: var(--accent);
  outline: none;
  background: #f3f8ff;
}

.drop.dragover {
  border-color: var(--accent);
  background: #eaf2ff;
  color: var(--ink);
}

.drop strong { color: var(--ink); }

.drop-cta {
  display: inline-block;
  margin-top: 4px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.file-meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

.upload-status {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid #d7e0ea;
  background: #f7fafc;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-status-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.35;
}

.upload-status-detail {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  word-break: break-all;
  white-space: pre-line;
}

.upload-status[data-tone="busy"] {
  border-color: #9ec0ff;
  background: #eef5ff;
}

.upload-status[data-tone="busy"] .upload-status-title {
  color: #1d4ed8;
}

.upload-status[data-tone="busy"] .upload-status-title::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  border: 2px solid #1d4ed8;
  border-top-color: transparent;
  animation: upload-spin 0.7s linear infinite;
  vertical-align: -1px;
}

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

.upload-status[data-tone="ok"] {
  border-color: #86c9a2;
  background: #eefaf3;
}

.upload-status[data-tone="ok"] .upload-status-title {
  color: #0f7a45;
  font-size: 15px;
}

.upload-status[data-tone="error"] {
  border-color: #f0a0a0;
  background: #fff1f1;
}

.upload-status[data-tone="error"] .upload-status-title {
  color: var(--danger);
}

.drop.busy {
  border-color: var(--accent);
  background: #eef5ff;
  pointer-events: none;
  opacity: 0.85;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  min-height: 34px;
}

.btn:hover { background: #f3f4f6; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

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

.btn-quiet {
  background: transparent;
}

.rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.rules-table th,
.rules-table td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.rules-table th { color: var(--muted); font-weight: 600; }

.diag-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.diag-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px;
}

.diag-loc {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  word-break: break-all;
}

.diag-row {
  display: grid;
  grid-template-columns: 64px 1fr 1fr 48px;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.diag-row .to { color: var(--ink); }
.diag-row .st { text-align: right; color: var(--ok); font-weight: 600; }

.diag-item {
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.diag-item:hover {
  border-color: #b6c0cb;
}

.diag-item.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.15);
}

.diag-item.is-reverted {
  opacity: 0.72;
  border-style: dashed;
}

.diag-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.btn-mini {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.btn-warn {
  border-color: #d4a72c;
  color: #7d4e00;
  background: #fff8e6;
}

.btn-warn:hover {
  background: #ffefc2;
}

.reverted-tag {
  font-size: 11px;
  color: var(--warn);
  font-weight: 600;
}

/* 标题导航 + 预览布局 */
.preview-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  align-items: start;
}

.outline-nav {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 100px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 8px;
}

.outline-title {
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 8px;
  padding: 0 4px;
}

.outline-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.outline-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 4px;
}

.outline-link {
  appearance: none;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outline-link:hover {
  background: #f3f4f6;
}

.outline-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.outline-link.is-active {
  background: #eaf2ff;
  color: var(--accent);
  font-weight: 600;
}

.outline-link.lvl-1 { font-weight: 650; padding-left: 8px; }
.outline-link.lvl-2 { padding-left: 16px; }
.outline-link.lvl-3 { padding-left: 24px; color: #3d4650; }
.outline-link.lvl-4,
.outline-link.lvl-5,
.outline-link.lvl-6,
.outline-link.lvl-7 { padding-left: 32px; color: var(--muted); font-size: 11px; }

/* 预览内诊断高亮 */
.paper .diag-active {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  background: rgba(31, 111, 235, 0.06);
  border-radius: 2px;
}

.paper .diag-flash {
  animation: diagFlash 1.2s ease;
}

@keyframes diagFlash {
  0% { background: rgba(255, 214, 102, 0.45); }
  100% { background: rgba(31, 111, 235, 0.06); }
}

.paper .diag-block {
  margin: 0;
}

.paper .reverted {
  opacity: 0.95;
}

@media (max-width: 1100px) {
  .preview-layout {
    grid-template-columns: 1fr;
  }
  .outline-nav {
    position: static;
    max-height: 160px;
  }
}

.empty-hint {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 12px;
}

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}

.stat b { display: block; font-size: 16px; font-weight: 650; }

.workspace {
  overflow: auto;
  padding: 24px 16px 48px;
  min-height: 0;
}

.workspace-empty {
  height: 100%;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 8px;
  text-align: center;
  padding: 24px;
}

.workspace-empty h1 {
  margin: 0;
  font-size: 18px;
  color: var(--ink);
  font-weight: 650;
}

.workspace-empty p {
  margin: 0;
  max-width: 420px;
}

/* A4 纸张 */
.paper-wrap {
  display: flex;
  justify-content: center;
}

.paper {
  width: var(--page-w);
  min-height: var(--page-h);
  padding: var(--mt) var(--mr) var(--mb) var(--ml);
  background: #fff;
  box-shadow: var(--paper-shadow);
  color: #000;
  font-family: "宋体", "Times New Roman", "SimSun", serif;
  font-size: 12pt;
  line-height: 1.5;
}

.paper .cover {
  min-height: calc(var(--page-h) - var(--mt) - var(--mb));
  display: flex;
  flex-direction: column;
}

.paper .cover-line {
  font-size: 12pt;
  line-height: 1.5;
}

.paper .cover-marker {
  text-align: right;
  font-weight: 700;
}

.paper .cover-title {
  text-align: center;
  text-indent: 0;
  font-weight: 400;
}

.paper .cover-field {
  text-indent: 1.88cm;
}

.paper .cover-date {
  text-align: center;
  text-indent: 0;
  margin-top: auto;
}

.paper .blank {
  margin: 0;
  min-height: 1.5em;
}

.paper .content {
  /* 正文与封面同页连续；封面过长时自然下推 */
}

.paper .bid-body {
  margin: 0 0 0.2em 0;
  text-align: justify;
  text-indent: 2em;
  line-height: 1.5;
}

.paper .bh {
  margin: 0;
  font-weight: 700;
  line-height: 2;
  text-indent: 0;
  font-family: "宋体", "Calibri", serif;
}

.paper .bh1 { font-size: 22pt; margin-bottom: 6pt; }
.paper .bh1-break {
  page-break-before: always;
  break-before: page;
}
.paper .page-break-mark {
  display: block;
  margin: 1.2em 0 0.8em;
  border-top: 1px dashed #8a949e;
  text-align: center;
  line-height: 0;
  font-size: 0;
  page-break-before: always;
  break-before: page;
}
.paper .page-break-mark span {
  display: inline-block;
  margin-top: -0.75em;
  padding: 0 0.6em;
  background: #fff;
  color: #8a949e;
  font-size: 9pt;
  line-height: 1.4;
  letter-spacing: 0.08em;
}
.paper .bh2 { font-size: 18pt; }
.paper .bh3 { font-size: 16pt; margin-bottom: 6pt; }
.paper .bh4 { font-size: 15pt; }
.paper .bh5 { font-size: 14pt; }
.paper .bh6, .paper .h7 { font-size: 12pt; font-weight: 700; line-height: 2; }

.paper .num {
  font-family: "宋体", serif;
  margin-right: 0.5em;
}

.paper .bid-table {
  border-collapse: collapse;
  margin: 0.5em auto;
  font-size: 10.5pt;
  width: 100%;
  table-layout: fixed;
  text-align: center;
}

.paper .bid-table-original .tc-p {
  font-family: inherit;
}

.paper .bid-table td {
  border: 0.5pt solid #000;
  padding: 2pt 4pt;
  vertical-align: middle;
  text-align: center;
  word-break: break-word;
  font-family: "宋体", "Times New Roman", serif;
  line-height: 1.35;
  text-indent: 0;
  overflow: visible;
  position: relative;
}

.paper .bid-shape-float {
  position: absolute;
  z-index: 1;
  pointer-events: none;
}

.paper .bid-table .tc-p {
  margin: 0;
  line-height: 1.35;
  text-indent: 0;
  text-align: center;
}

.paper .bid-table .tc-p-original {
  line-height: 1.4;
}

.paper .bid-shape {
  display: inline-block;
  vertical-align: middle;
  line-height: 0;
  font-size: 0;
  margin: 0 1pt;
}

.paper .diagram-note {
  display: block;
  margin: 0.5em 0;
  padding: 0.6em 0.8em;
  border: 1px dashed #b6c0cb;
  color: #5c6570;
  font-size: 10.5pt;
  line-height: 1.5;
  text-indent: 0;
  background: #fafbfc;
}

.paper .bid-list {
  margin: 0.15em 0 0.15em 1em;
  padding-left: 1.6em;
  text-indent: -1.2em;
  line-height: 1.5;
}
.paper .list-bullet {
  display: inline-block;
  width: 1.2em;
  margin-right: 0.15em;
  color: #000;
}
.paper .list-num {
  display: inline-block;
  min-width: 1.6em;
  margin-right: 0.25em;
  color: #000;
}

.paper .run-bold { font-weight: 700; }
.paper .run-italic { font-style: italic; }
.paper .run-underline { text-decoration: underline; }
.paper .run-strike { text-decoration: line-through; }
.paper .run-underline.run-strike { text-decoration: underline line-through; }

.paper .bid-img {
  display: inline-block;
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  margin: 0.35em 0;
  page-break-inside: avoid;
}

.paper .img-missing {
  display: inline-block;
  padding: 0.4em 0.6em;
  border: 1px dashed #999;
  color: #666;
  font-size: 10pt;
  margin: 0.35em 0;
}

.status-bar {
  position: sticky;
  bottom: 0;
  margin: 0 auto;
  max-width: var(--page-w);
  padding: 8px 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.status-bar[data-tone="error"] { color: var(--danger); }
.status-bar[data-tone="ok"] { color: var(--ok); }

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 52px auto 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }
  .paper {
    width: min(21cm, 100%);
    padding: 1.5cm;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
