/* ==========================================================================
   工作台版式：页头、卷首、三栏、步骤标签与预览栏。
   组件样式在 app.css；这里只负责版面与响应式。
   ========================================================================== */

/* ------------------------------------------------------------ 顶栏 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 58px;
  padding: 0 3.2%;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 10px; flex: none; color: var(--ink); text-decoration: none; }
.brand-seal { display: block; width: 32px; height: 32px; border-radius: 9px; }
.brand-word { font-family: var(--font-display); font-size: 17px; font-weight: 600; letter-spacing: .05em; line-height: 1.1; }
.brand-word small { display: block; margin-top: 3px; font-family: var(--font-ui); font-size: 7.5px; font-weight: 400; letter-spacing: .24em; color: var(--muted); }

.top-motto { flex: 1; text-align: center; font-size: 10.5px; letter-spacing: .14em; color: var(--muted); }
.top-tools { display: flex; align-items: center; gap: 9px; flex: none; margin-left: auto; }

.icon-toggle {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink-2);
  transition: border-color .16s var(--ease), color .16s var(--ease);
}
.icon-toggle:hover { border-color: var(--line-2); color: var(--accent); }
.icon-toggle svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
[data-theme="light"] .ic-sun { display: none; }
[data-theme="dark"] .ic-moon { display: none; }

.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 10px;
  letter-spacing: .03em;
  color: var(--muted);
}
.local-badge i { width: 5px; height: 5px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 16%, transparent); }

/* ------------------------------------------------------------ 卷首 */

.page { max-width: 1720px; margin: 0 auto; padding: 0 3.2% 40px; }

.masthead {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 26px 2px 20px;
}
.masthead-copy { min-width: 0; }
.eyebrow { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; font-size: 8.5px; font-weight: 500; letter-spacing: .24em; text-transform: uppercase; color: var(--muted); }
.eyebrow-rule { width: 22px; height: 1px; background: var(--accent); }
.masthead h1 { font-family: var(--font-display); font-size: clamp(24px, 2.2vw, 32px); font-weight: 600; line-height: 1.28; letter-spacing: .02em; color: var(--ink); }
.accent-dot { color: var(--accent); }
.lede { max-width: 560px; margin-top: 7px; font-size: 11.5px; line-height: 1.7; color: var(--muted); text-wrap: pretty; }

.masthead-actions { display: flex; align-items: center; gap: 10px; flex: none; padding-bottom: 2px; }
.masthead-buttons { display: flex; align-items: center; gap: 7px; }

.ratio-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.ratio-badge strong { font-family: var(--font-display); font-size: 19px; font-weight: 600; letter-spacing: .06em; line-height: 1; color: var(--ink); }
.ratio-badge span { font-size: 8.5px; line-height: 1.5; letter-spacing: .04em; color: var(--muted); }
.ratio-badge small { font-size: 8.5px; color: var(--ink-2); letter-spacing: .02em; }

.new-chart-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--accent-solid);
  border-radius: 9px;
  background: var(--accent-solid);
  color: var(--on-accent);
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: .02em;
  transition: background .16s var(--ease), border-color .16s var(--ease), transform .1s var(--ease);
}
.new-chart-button:hover { background: color-mix(in srgb, var(--accent-solid) 88%, #000); border-color: color-mix(in srgb, var(--accent-solid) 88%, #000); color: var(--on-accent); }
.new-chart-button:active { transform: translateY(1px); }
.new-chart-button svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; }

/* 历史记录：收纳在卷首，避免和编辑器抢版面 */
.history-drawer { position: relative; z-index: 60; }
.history-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--surface);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  list-style: none;
  transition: border-color .16s var(--ease), color .16s var(--ease);
}
.history-trigger::-webkit-details-marker { display: none; }
.history-trigger:hover, .history-drawer[open] .history-trigger { border-color: var(--accent); color: var(--accent); }
.history-trigger em {
  min-width: 17px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--surface-2);
  font-style: normal;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--muted);
}
.history-trigger svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .18s var(--ease); }
.history-drawer[open] .history-trigger svg { transform: rotate(180deg); }

.history-sheet {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  width: min(370px, calc(100vw - 28px));
  max-height: min(68vh, 520px);
  overflow: auto;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.history-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.history-sheet-head strong { font-family: var(--font-display); font-size: 13px; font-weight: 600; }
.history-sheet .field-hint { margin: 4px 0 9px; }

.history-list { display: flex; flex-direction: column; gap: 5px; }
.history-item { display: flex; align-items: center; gap: 5px; padding: 5px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); transition: border-color .16s var(--ease), background .16s var(--ease); }
.history-item:hover, .history-item:focus-within { border-color: var(--accent-line); background: var(--accent-soft); }
.history-open { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; padding: 2px; border: 0; background: none; text-align: left; }
.history-thumbnail { width: 32px; height: 43px; flex: none; object-fit: contain; border: 1px solid var(--line); border-radius: 3px; background: var(--thumb); }
.history-copy { min-width: 0; flex: 1; }
.history-copy strong { display: block; font-size: 11.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-copy small { display: block; margin-top: 3px; font-size: 9px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-delete { flex: none; padding: 5px 4px; border: 0; border-radius: 4px; background: none; font-size: 9px; color: var(--faint); }
.history-delete:hover { background: var(--danger-soft); color: var(--danger); }

/* ------------------------------------------------------------ 三栏 */

.workspace {
  display: grid;
  grid-template-columns: 214px minmax(0, 1fr) minmax(410px, .88fr);
  gap: 20px;
  align-items: start;
}

.template-panel { align-self: start; }
.editor { min-width: 0; }

@media (min-width: 1101px) and (min-height: 700px) {
  .template-panel { position: sticky; top: 58px; max-height: calc(100vh - 74px); max-height: calc(100dvh - 74px); overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
}

/* 左栏：结构列表 */
.template-panel .panel-head { min-height: 56px; }
.template-panel .panel-title h2 { font-size: 14px; }

/* ------------------------------------------------------------ 步骤标签 */

.step-nav {
  position: sticky;
  top: 58px;
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.step-tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 10px 7px 9px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  text-align: left;
  color: var(--muted);
  transition: background .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease);
}
.step-tab:hover { background: var(--surface-2); color: var(--ink-2); }
.step-tab.is-active { color: var(--ink); border-bottom-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.step-tab-index { flex: none; margin-top: 1px; font-family: var(--font-ui); font-size: 11px; font-weight: 700; letter-spacing: .06em; font-variant-numeric: tabular-nums; color: var(--muted); }
.step-tab.is-active .step-tab-index { color: var(--accent); }
.step-tab-copy { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.step-tab-copy strong { font-family: var(--font-ui); font-size: 16px; font-weight: 700; letter-spacing: .02em; color: var(--ink-2); }
.step-tab.is-active .step-tab-copy strong { color: var(--accent); }
.step-tab-copy small { font-size: 11px; font-weight: 400; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-tab.is-active .step-tab-copy small { color: var(--ink-2); }
.step-dot { flex: none; width: 5px; height: 5px; margin-left: 2px; border-radius: 50%; background: var(--accent); transition: background .16s var(--ease), box-shadow .16s var(--ease); }
.step-tab.is-empty .step-dot { background: transparent; box-shadow: inset 0 0 0 1px var(--line-2); }

/* ------------------------------------------------------------ 步骤内容 */

.step-panel { padding: 18px 16px 22px; }
.step-lead { margin: 0 0 18px; padding-left: 10px; border-left: 2px solid var(--accent-line); font-size: 10.5px; line-height: 1.75; color: var(--muted); }

.group { min-width: 0; }
.group + .group { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.group-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; margin-bottom: 10px; min-height: 17px; }
.group-head h3 { font-family: var(--font-ui); font-size: 12px; font-weight: 600; letter-spacing: .03em; color: var(--ink); }
.group-head p { font-size: 10px; color: var(--muted); line-height: 1.5; }
.group-head .count { margin-left: auto; font-size: 9.5px; font-variant-numeric: tabular-nums; color: var(--faint); }
.group-head .switch-row { margin-left: auto; }

#map-editor:not([hidden]) + #numeric-data { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }

.file-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: var(--surface-2);
}
.file-hint { font-size: 9.5px; line-height: 1.5; color: var(--muted); }

/* ------------------------------------------------------------ 预览栏 */

.preview-column {
  position: sticky;
  top: 58px;
  max-height: calc(100vh - 74px);
  max-height: calc(100dvh - 74px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.preview-column .panel-head { min-height: 56px; }
.preview-column .panel-title h2 { font-size: 14px; }

.preview-tools { display: flex; align-items: center; gap: 7px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.preview-tools .primary-button { width: auto; flex: 1.15; height: 38px; padding: 0 13px; }
.export-actions { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 6px; flex: 1; min-width: 0; }

.preview-main { padding: 10px; }
.preview-column .preview-stage { padding: 8px; }
.paper-mount { max-width: 100%; }

.preview-extras { margin-top: 3px; border-top: 1px solid var(--line); }
.extra { border-bottom: 1px solid var(--line); }
.extra:last-child { border-bottom: 0; }
.extra > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 2px;
  list-style: none;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
}
.extra > summary::-webkit-details-marker { display: none; }
.extra > summary:hover { color: var(--accent); }
.extra > summary small { margin-left: auto; font-size: 9px; font-weight: 400; color: var(--faint); }
.extra > summary svg { width: 11px; height: 11px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; color: var(--faint); transition: transform .18s var(--ease); }
.extra[open] > summary svg { transform: rotate(180deg); }
.extra-body { padding: 0 2px 13px; }
.extra-body > label { margin-top: 9px; }
.extra-body > label:first-child { margin-top: 0; }
.extra-body .field-hint { margin-top: 7px; }
.extra-body .switch-row { padding: 2px 0 6px; }
#watermark-settings, #background-settings { margin-top: 2px; }
#watermark-settings label, #background-settings label { margin-top: 9px; }
#watermark-settings output, #background-settings output { float: right; font-size: 10px; color: var(--accent); font-variant-numeric: tabular-nums; }
#watermark-settings input[type="range"], #background-settings input[type="range"] { width: 100%; margin-top: 2px; }

/* ------------------------------------------------------------ 响应式 */

@media (max-width: 1480px) {
  .workspace { grid-template-columns: 202px minmax(0, 1fr) minmax(380px, .84fr); gap: 16px; }
  .export-actions { grid-template-columns: 1.25fr 1fr 1fr; }
}

@media (max-width: 1260px) {
  .preview-tools { flex-direction: column; align-items: stretch; }
  .preview-tools .primary-button { width: 100%; flex: none; }
  .export-actions { width: 100%; flex: none; }
}

@media (max-width: 1280px) {
  .top-motto { display: none; }
  .workspace { grid-template-columns: 192px minmax(0, 1fr) minmax(360px, .82fr); gap: 14px; }
  .ratio-badge { display: none; }
}

@media (max-width: 1100px) {
  .masthead { padding-top: 20px; padding-bottom: 16px; }
  .lede { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(340px, .8fr); gap: 14px; }
  .template-panel { grid-column: 1 / -1; }
  .template-panel .panel-head { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .template-list { flex-direction: row; overflow-x: auto; padding: 8px; gap: 5px; scrollbar-width: thin; }
  .template-button { flex: 0 0 auto; width: 132px; min-height: 54px; }
  .template-button small { display: none; }
  .aside-note { display: none; }
  .preview-column { top: 58px; }
}

@media (max-width: 900px) {
  .topbar { height: 54px; }
  .local-badge { display: none; }
  .masthead { align-items: flex-start; }
  .masthead-actions { gap: 7px; }
  .workspace { display: flex; flex-direction: column; }
  .template-panel, .editor, .preview-column { width: 100%; }
  .preview-column { position: static; max-height: none; overflow: visible; }
  .step-nav { top: 54px; }
  .preview-stage { padding: 20px; }
  .preview-tools { flex-direction: row; align-items: center; padding: 10px 12px; }
  .preview-tools .primary-button { width: auto; flex: 1.2; }
  .export-actions { width: auto; flex: 1; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .page { padding-left: 14px; padding-right: 14px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .brand-word { font-size: 15px; }
  .brand-word small { display: none; }
  .masthead { flex-direction: column; align-items: stretch; gap: 14px; padding: 18px 0 14px; }
  .masthead h1 { font-size: 24px; }
  .eyebrow { letter-spacing: .18em; }
  .masthead-actions { width: 100%; justify-content: space-between; padding: 0; }
  .new-chart-button { flex: 1; justify-content: center; }
  .history-trigger { flex: none; }
  .history-sheet { position: fixed; top: 62px; left: 14px; right: 14px; width: auto; max-height: 72vh; }
  .step-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; padding: 0 8px; }
  .step-tab { padding: 8px 6px; border-bottom: 1px solid var(--line); }
  .step-tab.is-active { border-bottom-color: var(--accent); }
  .step-panel { padding: 15px 13px 18px; }
  .layout-choices { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .theme-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .header-style-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .preview-tools { flex-direction: column; align-items: stretch; }
  .primary-button { width: 100%; }
  .preview-tools .primary-button { width: 100%; }
  .preview-main { padding: 11px; }
  .preview-stage { padding: 17px; }
  .file-tools { flex-wrap: wrap; }
  .page-footer span:last-child { display: none; }
  .map-provinces { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .top-tools { gap: 6px; }
  .masthead h1 { font-size: 22px; }
  .step-tab-index { display: none; }
  .layout-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .header-style-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-row { grid-template-columns: 1fr; }
  .size-field > span { display: none; }
}
