:root {
  --ink: #122033;
  --ink-soft: #506077;
  --line: #d7dee8;
  --paper: #ffffff;
  --canvas: #e9edf2;
  --panel: #f7f9fb;
  --accent: #ef6b3b;
  --accent-dark: #d95425;
  --success: #117866;
  --danger: #b42318;
  --shadow: 0 20px 60px rgba(18, 32, 51, 0.13);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); }
button, input, select { font: inherit; }
button, label, select, input { -webkit-tap-highlight-color: transparent; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 28px;
  color: #fff;
  background: var(--ink);
  border-bottom: 3px solid var(--accent);
}

.product-name { font-size: 16px; color: #fff; font-weight: 750; letter-spacing: .02em; }

.workspace { min-height: calc(100vh - 64px); display: grid; grid-template-columns: minmax(330px, 410px) 1fr; }
.controls { padding: 34px 32px; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.panel-heading h1 { margin: 6px 0 10px; font-family: Georgia, "Songti SC", serif; font-size: clamp(28px, 3vw, 38px); line-height: 1.14; font-weight: 700; letter-spacing: -.02em; }
.eyebrow { margin: 0; color: var(--accent-dark); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
.intro { margin: 0; color: var(--ink-soft); font-size: 15px; line-height: 1.65; }

.drop-zone { margin-top: 24px; min-height: 160px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 22px; text-align: center; border: 1.5px dashed #9aa8ba; background: #fff; cursor: pointer; transition: border-color .2s, background .2s, transform .2s; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--accent); background: #fff8f4; transform: translateY(-1px); }
.drop-zone:focus-within { outline: 3px solid rgba(239,107,59,.25); outline-offset: 2px; }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop-zone strong { font-size: 17px; }
.drop-zone > span:last-child { color: var(--ink-soft); font-size: 13px; }
.drop-icon { width: 38px; height: 38px; display: grid; place-items: center; color: var(--accent-dark); }
.drop-icon svg, .primary-button svg { width: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.file-summary { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 14px; background: #edf7f4; border-left: 3px solid var(--success); }
.file-summary div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.summary-label { color: var(--ink-soft); font-size: 12px; }
.row-count { flex: none; color: var(--success); font-size: 13px; font-weight: 800; }

.settings { min-width: 0; margin: 24px 0 0; padding: 0; display: grid; gap: 18px; border: 0; }
.settings[disabled] { opacity: .48; pointer-events: none; }
.field { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.field label, .field legend, .switch-row label { font-size: 14px; font-weight: 750; }
.field input[type="number"], .field select { width: 100%; height: 42px; padding: 0 12px; color: var(--ink); background: #fff; border: 1px solid #b9c3d0; border-radius: 2px; }
.field input:focus, .field select:focus { outline: 3px solid rgba(239,107,59,.2); border-color: var(--accent); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; background: #e4e9ef; border-radius: 4px; }
.segmented input { position: absolute; opacity: 0; }
.segmented label { padding: 8px 12px; text-align: center; color: var(--ink-soft); cursor: pointer; border-radius: 2px; }
.segmented input:checked + label { color: var(--ink); background: #fff; box-shadow: 0 1px 4px rgba(18,32,51,.13); }
.segmented input:focus-visible + label { outline: 3px solid rgba(239,107,59,.25); }

.column-picker { overflow: hidden; background: #fff; border: 1px solid #b9c3d0; border-radius: 3px; }
.column-picker summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 12px; cursor: pointer; font-size: 14px; font-weight: 750; list-style: none; }
.column-picker summary::-webkit-details-marker { display: none; }
.column-picker summary::before { content: "+"; width: 20px; color: var(--accent-dark); font-size: 20px; font-weight: 500; }
.column-picker[open] summary::before { content: "−"; }
.column-picker summary span { flex: 1; }
.column-picker summary strong { color: var(--accent-dark); font-size: 12px; }
.column-actions { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #f7f9fb; }
.column-actions button { padding: 5px 10px; color: var(--ink); background: #fff; border: 1px solid #b9c3d0; border-radius: 2px; font-size: 12px; cursor: pointer; }
.column-actions button:hover { border-color: var(--accent); }
.column-list { max-height: 220px; overflow-y: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; padding: 6px; }
.column-option { min-width: 0; display: flex; align-items: center; gap: 7px; padding: 7px 6px; font-size: 13px; cursor: pointer; }
.column-option:hover { background: #fff6f1; }
.column-option input { flex: none; width: 16px; height: 16px; accent-color: var(--accent-dark); }
.column-option span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.switch-row > div { display: grid; gap: 3px; }
.switch-row span { color: var(--ink-soft); font-size: 12px; }
.switch { appearance: none; flex: none; width: 46px; height: 25px; padding: 3px; border: 0; border-radius: 999px; background: #aab4c1; cursor: pointer; transition: background .2s; }
.switch::before { content: ""; display: block; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.24); transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(21px); }
.switch:focus-visible { outline: 3px solid rgba(239,107,59,.25); outline-offset: 2px; }

.primary-button { width: 100%; height: 50px; margin-top: 26px; display: flex; align-items: center; justify-content: center; gap: 10px; color: #fff; background: var(--accent); border: 0; border-radius: 3px; font-weight: 800; cursor: pointer; transition: background .2s, transform .2s; }
.primary-button:hover:not(:disabled) { background: var(--accent-dark); transform: translateY(-1px); }
.primary-button:disabled { cursor: not-allowed; background: #aeb7c2; }
.primary-button.busy { cursor: wait; }
.error-message { margin: 12px 0 0; color: var(--danger); font-size: 13px; line-height: 1.5; }

.preview-panel { min-width: 0; display: flex; flex-direction: column; }
.preview-toolbar { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 28px; background: #fff; border-bottom: 1px solid var(--line); }
.preview-toolbar h2 { margin: 4px 0 0; font-size: 20px; }
.pager { display: flex; align-items: center; gap: 12px; color: var(--ink-soft); font-size: 14px; }
.pager button { width: 36px; height: 36px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 50%; font-size: 24px; line-height: 1; cursor: pointer; }
.pager button:disabled { color: #a6afba; cursor: not-allowed; }
.preview-stage { flex: 1; min-height: 500px; display: grid; place-items: center; padding: 36px; overflow: auto; background-image: linear-gradient(rgba(18,32,51,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(18,32,51,.035) 1px, transparent 1px); background-size: 24px 24px; }
.empty-state { max-width: 420px; text-align: center; color: var(--ink-soft); }
.empty-state h3 { margin: 22px 0 7px; color: var(--ink); font-size: 18px; }
.empty-state p { margin: 0; font-size: 14px; }
.paper-stack { position: relative; width: 120px; height: 142px; margin: 0 auto; }
.paper-stack span { position: absolute; inset: 0; background: #fff; border: 1px solid #cfd7e2; box-shadow: 0 8px 22px rgba(18,32,51,.1); }
.paper-stack span:nth-child(1) { transform: translate(-14px, 10px) rotate(-5deg); }
.paper-stack span:nth-child(2) { transform: translate(13px, 7px) rotate(4deg); }
.paper-stack span:nth-child(3) { border-top: 5px solid var(--accent); }
.paper-stack span:nth-child(3)::after { content: ""; position: absolute; left: 18px; right: 18px; top: 32px; height: 45px; background: repeating-linear-gradient(to bottom, #dce2e9 0 2px, transparent 2px 11px); }
.single-preview { display: grid; place-items: center; width: 100%; }

.work-page { --page-width: 148mm; --page-height: 210mm; --fit-scale: 1; width: var(--page-width); height: var(--page-height); overflow: hidden; color: #111827; background: var(--paper); box-shadow: var(--shadow); }
.work-page.landscape { --page-width: 210mm; --page-height: 148mm; }
.page-content { width: calc((100% - 14mm) / var(--fit-scale)); height: calc((100% - 14mm) / var(--fit-scale)); margin: 7mm; transform: scale(var(--fit-scale)); transform-origin: top left; display: flex; flex-direction: column; }
.page-masthead { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; padding-bottom: 3.5mm; border-bottom: 1.2px solid #17263a; }
.page-kicker { margin: 0 0 1.5mm; color: #d95425; font-size: 7.5pt; font-weight: 800; letter-spacing: .12em; }
.page-title { margin: 0; font-family: "Songti SC", Georgia, serif; font-size: 18pt; line-height: 1; }
.page-meta { text-align: right; color: #536174; font-size: 7.5pt; line-height: 1.45; }
.page-grid { flex: 1; min-height: 0; padding-top: 3.5mm; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; gap: 2.2mm 2.8mm; }
.landscape .page-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.8mm 2.8mm; }
.page-grid.dense { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.7mm 2.2mm; }
.landscape .page-grid.dense { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.data-cell { min-width: 0; min-height: 12mm; padding: 2.2mm 2.5mm; background: #f5f7fa; border-left: .9mm solid #d5dce5; break-inside: avoid; }
.dense .data-cell { min-height: 9mm; padding: 1.5mm 2mm; }
.data-label { margin-bottom: 1mm; color: #5f6c7e; font-size: 7.5pt; font-weight: 700; line-height: 1.15; }
.data-value { overflow-wrap: anywhere; white-space: pre-wrap; font-size: 10pt; font-weight: 650; line-height: 1.25; }
.dense .data-value { font-size: 8.5pt; }
.page-grid.no-headers .data-label { display: none; }
.page-grid.no-headers .data-cell { display: flex; align-items: center; min-height: 10mm; }
.signature-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2.3mm 5mm; padding-top: 3.5mm; color: #566375; border-top: 1px solid #d7dde5; font-size: 7.5pt; }
.signature-item { min-width: 0; display: grid; grid-template-columns: auto 1fr; align-items: end; gap: 2mm; }
.signature-item:last-child { grid-column: 1 / -1; }
.signature-line { min-width: 12mm; height: 4mm; border-bottom: .4px solid #7b8695; }

.pdf-pages { position: fixed; left: -20000px; top: 0; width: max-content; background: #fff; }
.pdf-pages .work-page { box-shadow: none; break-after: page; page-break-after: always; }
.pdf-pages .work-page:last-child { break-after: auto; page-break-after: auto; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .controls { border-right: 0; border-bottom: 1px solid var(--line); }
  .preview-stage { min-height: 620px; padding: 20px; }
  .work-page { transform: scale(.68); transform-origin: center; margin: -34mm -24mm; }
  .work-page.landscape { transform: scale(.62); margin: -28mm -40mm; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 18px; }
  .controls { padding: 28px 20px; }
  .preview-toolbar { padding: 16px 20px; }
  .preview-stage { min-height: 480px; }
  .work-page { transform: scale(.48); margin: -55mm -39mm; }
  .work-page.landscape { transform: scale(.4); margin: -44mm -63mm; }
}

@media print {
  body { background: #fff; }
  .topbar, .workspace { display: none !important; }
}
