:root {
  --bg: #f6f5f1;
  --paper: #fffefa;
  --ink: #292c39;
  --muted: #85858c;
  --line: #e9e7e1;
  --accent: #62664b;
  --accent-hover: #52563d;
  --accent-light: #eff0e7;
  --danger: #b43c32;
  --danger-bg: #fdf1f0;
  --radius: 16px;
  --shadow-sm: 0 2px 8px rgba(41, 44, 57, 0.05);
  --shadow-md: 0 10px 28px rgba(41, 44, 57, 0.09);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  padding: 6px 12px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

button:hover:not(:disabled) {
  border-color: #cfcbb8;
  background: #faf9f4;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fffefa;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

button.ghost:hover:not(:disabled) {
  background: var(--accent-light);
  color: var(--ink);
}

button.danger-text {
  color: var(--danger);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: rgba(255, 254, 250, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  flex-shrink: 0;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

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

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
}

.workspace {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 20px;
  max-width: 1520px;
  margin: 0 auto;
  padding: 18px 24px 28px;
  align-items: start;
}

body.focus-mode .topbar {
  display: none;
}

body.focus-mode .workspace {
  grid-template-columns: 1fr;
  max-width: 100%;
  padding: 12px;
}

body.focus-mode .sidebar {
  display: none;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.sidebar {
  position: sticky;
  top: 74px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 94px);
  overflow: hidden;
}

.tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
}

.tabs {
  display: inline-flex;
  background: var(--bg);
  padding: 3px;
  border-radius: 11px;
  gap: 4px;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
}

.tab-btn.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.save-hint {
  font-size: 12px;
  color: var(--muted);
}

.panel-scroll {
  padding: 16px;
  overflow-y: auto;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hidden {
  display: none !important;
}

.dropzone {
  border: 1.5px dashed #cfcbb8;
  background: #faf9f4;
  border-radius: 14px;
  padding: 16px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.dropzone-title {
  font-weight: 600;
  color: var(--ink);
}

.dropzone-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.doc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.doc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 185px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-chip.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.doc-meta-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  padding: 8px 11px;
  outline: none;
  transition: border-color 0.15s ease;
}

input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

textarea#text {
  min-height: 240px;
  resize: vertical;
  line-height: 1.65;
  font-size: 13.5px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.presets {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.preset {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  min-height: 58px;
  padding: 8px 9px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fffdf8 0%, #f7f3e8 100%);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

.preset::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 9px;
  right: 9px;
  height: 1px;
  background: rgba(206, 94, 94, 0.45);
  box-shadow: 0 7px 0 rgba(206, 94, 94, 0.25);
}

.preset:nth-child(4)::before {
  background: rgba(96, 138, 192, 0.52);
  box-shadow: 0 7px 0 rgba(96, 138, 192, 0.28);
}

.preset:nth-child(6) {
  background: linear-gradient(180deg, #f9f3e3 0%, #f1e8d0 100%);
}

.preset:nth-child(6)::before {
  display: none;
}

.preset[data-preset="print_a4"], .preset[data-preset="meeting_a4"] {
  background: #ffffff;
}

.preset[data-preset="print_a4"]::before, .preset[data-preset="meeting_a4"]::before {
  background: rgba(160, 165, 178, 0.35);
  box-shadow: none;
}

.preset.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(98, 102, 75, 0.22);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field label strong {
  color: var(--ink);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.ink-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 999px;
  border: 2px solid rgba(0, 0, 0, 0.12);
}

.swatch.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="color"]#ink_color {
  width: 34px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  cursor: pointer;
}

.note-box {
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 12px;
}

.seed-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: center;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sidebar-footer .primary {
  flex: 1 1 auto;
  padding: 10px 16px;
  font-size: 14px;
}

.preview-card {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 112px);
}

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.status-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #b8b8bf;
}

.dot.busy {
  background: #d28a1d;
  animation: pulse 1s infinite alternate;
}

.dot.ready {
  background: #4e8c57;
}

.dot.error {
  background: var(--danger);
}

@keyframes pulse {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

.zoom-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.zoom-group button {
  padding: 5px 9px;
  font-size: 12px;
}

.progress-wrap {
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: #faf9f4;
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-track {
  flex: 1 1 auto;
  height: 7px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

.preview-stage {
  flex: 1 1 auto;
  min-height: 540px;
  padding: 20px;
  background: #eceae2;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.empty-state {
  margin: auto;
  max-width: 420px;
  text-align: center;
  padding: 36px 26px;
  background: var(--paper);
  border-radius: var(--radius);
  border: 1px dashed #d3cfc2;
  box-shadow: var(--shadow-sm);
}

.empty-state h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.empty-state p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

#previewImage {
  display: block;
  border-radius: 4px;
  box-shadow: var(--shadow-md);
  background: #fff;
  transform-origin: top center;
  max-width: 100%;
  height: auto;
}

.preview-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.pager-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pager-group select#resultDocument {
  width: auto;
  max-width: 220px;
}

.pager-group input#pageNumber {
  width: 62px;
  text-align: center;
  padding: 5px 6px;
}

.export-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.export-group select#exportFormat {
  width: auto;
}

.error-banner {
  margin: 12px 16px 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #f0c2be;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: #fffefa;
  box-shadow: var(--shadow-md);
  font-size: 13px;
}

dialog#helpDialog {
  max-width: 560px;
  width: calc(100% - 32px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow-md);
  background: var(--paper);
}

dialog#helpDialog::backdrop {
  background: rgba(41, 44, 57, 0.35);
}

.dialog-body {
  padding: 20px 22px;
}

.dialog-body h3 {
  margin: 0 0 12px;
}

.dialog-body ul {
  margin: 0 0 16px;
  padding-left: 18px;
  color: var(--ink);
  line-height: 1.7;
}

@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .preview-card {
    min-height: 600px;
  }
}
