:root {
  --bg: #eaf0f6;
  --panel: #ffffff;
  --line: #d4e0ed;
  --text: #10253b;
  --muted: #4e6378;
  --primary: #2563eb;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 0% 0%, #f8fbff 0, #eaf0f6 45%),
    linear-gradient(135deg, #ecf3fa, #eaf0f6);
}

.app-shell {
  display: grid;
  grid-template-columns: clamp(300px, 22vw, 380px) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── 侧边栏 ── */
.sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #fdfefe, #f8fbff 45%, #f4f8fd);
  padding: 16px 14px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.sidebar h1 { margin: 0; font-size: 20px; line-height: 1.2; }
.subtitle { margin: 2px 0 0; color: #4f6379; font-size: 11px; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.brand-logo {
  font-size: 28px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(37,99,235,0.3));
}

.side-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.side-tab-btn {
  border: 1px solid #c6d8eb;
  background: linear-gradient(180deg, #f7fbff, #eef5ff);
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  color: #1b3f63;
  font-size: 11px;
  display: grid;
  justify-items: center;
  gap: 4px;
  transition: 0.15s ease;
}

.tab-icon {
  width: 22px; height: 22px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: #1f4e83;
  background: #dbeafe;
  border: 1px solid #bfdbfe;
}

.side-tab-btn.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(37,99,235,0.3);
}

.side-tab-btn.active .tab-icon {
  background: rgba(255,255,255,0.22);
  border-color: rgba(255,255,255,0.4);
  color: #fff;
}

.side-pane { display: none; overflow: auto; min-height: 0; padding-right: 2px; }
.side-pane.active { display: block; }

/* ── 面板 ── */
.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  padding: 10px;
  margin-bottom: 10px;
  box-shadow: 0 4px 10px rgba(148,163,184,0.08);
}

.is-hidden { display: none !important; }
.panel h2 { margin: 0 0 8px; font-size: 15px; }
.hint { margin: 0 0 6px; color: var(--muted); font-size: 12px; }

label {
  display: block;
  margin: 6px 0 3px;
  font-size: 12px;
  color: var(--muted);
}

input, select, textarea, button { font-family: inherit; }

input, select, textarea {
  width: 100%;
  border: 1px solid #c8d7e6;
  border-radius: 8px;
  padding: 8px 9px;
  background: #fbfdff;
}

input[type="range"] {
  padding: 4px 0;
  height: auto;
  background: transparent;
  border: none;
  cursor: pointer;
}

input[type="color"] {
  padding: 2px; height: 36px;
  border-radius: 8px; background: #ffffff; cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: 1px solid #c8d7e6; border-radius: 6px; }

input[type="checkbox"] { width: auto; margin-right: 6px; vertical-align: middle; }

input:disabled, select:disabled, textarea:disabled { opacity: 0.55; cursor: not-allowed; }

textarea { min-height: 116px; resize: vertical; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ── 按钮 ── */
.btn {
  width: 100%;
  border: 1px solid #bfd3ea;
  border-radius: 10px;
  background: #edf4ff;
  color: #15416d;
  padding: 10px;
  cursor: pointer;
  transition: 0.12s;
}

.btn:hover { background: #dbeafe; }

.btn-glyph {
  display: inline-block;
  min-width: 16px;
  margin-right: 6px;
  text-align: center;
  font-weight: 700;
}

.btn.primary {
  border: none;
  background: linear-gradient(120deg, #2563eb, #1d4ed8);
  color: #fff;
  font-weight: 700;
}

.btn.secondary { margin-top: 8px; }

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

/* ── 底部操作区 ── */
.actions {
  position: sticky;
  bottom: 8px;
  background: #fff;
  margin-bottom: 0;
  box-shadow: 0 -8px 12px rgba(255,255,255,0.92);
  z-index: 2;
}

.actions .btn + .btn { margin-top: 0; }

@media (min-width: 1151px) {
  .actions {
    position: fixed;
    right: 20px; bottom: 16px;
    width: clamp(300px, 22vw, 380px);
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(16,37,59,0.16);
    z-index: 20;
  }
}

/* ── 工作区 ── */
.workspace {
  position: relative;
  display: grid;
  grid-template-rows: 1fr;
  min-width: 0; min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,0.95), rgba(234,240,246,0.9)),
    linear-gradient(135deg, #edf3fb, #e7eff8);
}

/* ── 顶栏 ── */
.topbar {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  width: min(900px, calc(100% - 24px));
  padding: 8px 12px;
  border: 1px solid #cad8e8;
  border-radius: 14px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  box-shadow: 0 12px 24px rgba(15,23,42,0.12);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#stats {
  background: #eff6ff;
  color: #1e3a8a;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.pager { display: flex; align-items: center; gap: 4px; }

.pager button, .tab-btn {
  border: 1px solid #c6d8eb;
  background: #f6faff;
  border-radius: 8px;
  padding: 5px 10px;
  cursor: pointer;
  transition: 0.12s;
}

.pager button { min-width: 28px; font-size: 16px; }
.pager button:disabled { opacity: 0.35; cursor: not-allowed; }

#pageInfo { font-size: 13px; font-weight: 600; color: #334155; min-width: 44px; text-align: center; }

/* ── 缩放控制 ── */
.zoom-ctrl { display: flex; align-items: center; gap: 4px; }

.zoom-ctrl button {
  border: 1px solid #c6d8eb;
  background: #f6faff;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  min-width: 28px;
  transition: 0.12s;
}

.zoom-ctrl button:hover { background: #dbeafe; border-color: #93c5fd; }

#zoomLabel {
  font-size: 12px; color: #334155;
  min-width: 38px; text-align: center; font-weight: 600;
}

.view-switch { margin-left: auto; display: flex; gap: 6px; }

.tab-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }

/* ── 标签页 ── */
.tab { display: none; min-height: 0; }
.tab.active { display: block; height: 100%; min-height: 0; }

#sheetTab { padding: 76px 16px 16px; overflow: auto; height: 100%; min-height: 0; }

#sheetViewport {
  min-height: calc(100% - 92px);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* 模板模式下视口垂直居中 */
#sheetViewport.template-mode {
  align-items: center;
}

/* ── 画布 ── */
.sheet {
  border: 1px solid #8ea7c0;
  box-shadow: 0 18px 44px rgba(23,45,76,0.18);
  background: #fff;
  position: relative;
}

.designer-stage {
  position: relative;
  user-select: none;
}

.designer-stage.grid-bg {
  background-image:
    linear-gradient(to right, rgba(148,163,184,0.2) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(148,163,184,0.2) 1px, transparent 1px);
  background-color: #fff;
}

.designer-item {
  position: absolute;
  cursor: move;
  white-space: nowrap;
  padding: 2px 4px;
  border: 1px dashed transparent;
}

.designer-item:hover { border-color: #bfdbfe; background: rgba(219,234,254,0.24); }
.designer-item.selected { border-color: #2563eb; background: rgba(191,219,254,0.38); }
.designer-item.locked { cursor: not-allowed; opacity: 0.78; }

.template-frame {
  position: absolute;
  border: 1px solid rgba(148,163,184,0.5);
  pointer-events: none;
}

/* 模板排版：纸张背景壳（浅灰，让水牌白色区域突出） */
.paper-shell {
  position: relative;
  background: #e8edf3;
  box-shadow: 0 18px 44px rgba(23,45,76,0.18);
  border: 1px solid #8ea7c0;
  flex-shrink: 0;
}

/* 水牌编辑画布：白色 + 阴影，浮在纸张上 */
.designer-stage {
  position: relative;
  user-select: none;
  background: #fff;
  box-shadow: 0 8px 32px rgba(23,45,76,0.18), 0 2px 8px rgba(23,45,76,0.10);
  border-radius: 4px;
}

.designer-stage.grid-bg {
  background-image:
    linear-gradient(to right, rgba(148,163,184,0.18) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(148,163,184,0.18) 1px, transparent 1px);
  background-color: #fff;
}

/* 模板排版：外层居中容器 */
.template-paper-wrapper {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-width: 100%;
  min-height: 100%;
  padding: 20px;
  box-sizing: border-box;
}
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-width: 100%;
  min-height: 100%;
  padding: 20px;
  box-sizing: border-box;
}

/* 添加元素按钮网格 */
.add-el-grid {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.add-el-btn {
  padding: 8px 6px;
  font-size: 12px;
}

.guide-grid { position: absolute; pointer-events: none; opacity: 0.12; }
.guide-grid.guide-v { top: 0; bottom: 0; width: 1px; background: #94a3b8; }
.guide-grid.guide-h { left: 0; right: 0; height: 1px; background: #94a3b8; }

.guide-center { position: absolute; pointer-events: none; opacity: 0.2; }
.guide-center.guide-v { top: 0; bottom: 0; width: 1px; background: #2563eb; }
.guide-center.guide-h { left: 0; right: 0; height: 1px; background: #2563eb; }

.marquee {
  position: absolute;
  border: 1px dashed #1d4ed8;
  background: rgba(59,130,246,0.12);
  pointer-events: none;
}

.resize-handle, .rotate-handle {
  position: absolute;
  width: 8px; height: 8px;
  border: 1px solid #1d4ed8;
  background: #fff;
  border-radius: 2px;
}

.resize-handle.nw { left: -5px; top: -5px; cursor: nwse-resize; }
.resize-handle.n  { left: calc(50% - 4px); top: -6px; cursor: ns-resize; }
.resize-handle.ne { right: -5px; top: -5px; cursor: nesw-resize; }
.resize-handle.e  { right: -6px; top: calc(50% - 4px); cursor: ew-resize; }
.resize-handle.se { right: -5px; bottom: -5px; cursor: nwse-resize; }
.resize-handle.s  { left: calc(50% - 4px); bottom: -6px; cursor: ns-resize; }
.resize-handle.sw { left: -5px; bottom: -5px; cursor: nesw-resize; }
.resize-handle.w  { left: -6px; top: calc(50% - 4px); cursor: ew-resize; }

.rotate-handle {
  width: 10px; height: 10px;
  left: calc(50% - 5px); top: -22px;
  border-radius: 50%;
  background: #2563eb;
  border: 1px solid #0f3ea6;
  cursor: grab;
}

/* ── 图层列表 ── */
.layer-list {
  max-height: 160px;
  overflow: auto;
  border: 1px solid #d8e4f1;
  border-radius: 8px;
  background: #f8fbff;
  padding: 6px;
  margin-bottom: 8px;
}

.layer-row {
  width: 100%;
  text-align: left;
  border: 1px solid #d8e4f1;
  background: #ffffff;
  color: #224061;
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: 0.1s;
}

.layer-row:hover { background: #f0f7ff; }
.layer-row.selected { border-color: #2563eb; background: #eaf2ff; }

.layer-empty {
  text-align: center;
  color: #94a3b8;
  font-size: 12px;
  padding: 12px 0;
}

.shortcut-hint {
  margin-top: 6px;
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
  line-height: 1.6;
}

.shortcut-hint span {
  cursor: help;
  border-bottom: 1px dashed #cbd5e1;
}

/* ── 3D ── */
.sheet-grid { position: absolute; inset: 0; }
.card-box { position: absolute; overflow: hidden; box-shadow: 0 2px 0 rgba(0,0,0,0.06); }

.three-wrap {
  display: grid;
  grid-template-columns: 1fr 300px;
  height: 100%; min-height: 0;
}

#threeContainer {
  min-height: 0; height: 100%;
  background:
    radial-gradient(circle at 22% 24%, rgba(255,255,255,0.96), rgba(208,222,240,0.92)),
    linear-gradient(160deg, #e8eef7 0%, #dbe8f7 100%);
}

.three-side {
  border-left: 1px solid var(--line);
  background: #fff;
  padding: 14px;
  overflow: auto; min-height: 0;
}

.three-side h3 { margin-top: 0; }

.three-side label span {
  float: right;
  font-family: monospace;
  font-size: 11px;
  color: #2563eb;
  background: #eff6ff;
  border-radius: 4px;
  padding: 1px 5px;
}

/* ── 工作流提示 ── */
.workflow-hint {
  font-size: 11px;
  color: #6b8aaa;
  background: #f0f7ff;
  border: 1px solid #dbeafe;
  border-radius: 6px;
  padding: 5px 8px;
  margin-top: 4px;
  line-height: 1.5;
}

/* ── 颜色控件 ── */
.color-field {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.color-field input[type="color"] { width: 36px; flex-shrink: 0; margin: 0; }

.color-hex {
  font-size: 11px;
  color: #4e6378;
  font-family: monospace;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 2px 5px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 3px;
}

.toggle-label input[type="checkbox"] { margin: 0; }

/* ── 配色预设 ── */
.color-presets {
  margin-top: 8px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.presets-label { font-size: 11px; color: #94a3b8; white-space: nowrap; }

.preset-btn {
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid #c6d8eb;
  border-radius: 6px;
  background: #f0f7ff;
  color: #1b3f63;
  cursor: pointer;
  transition: 0.12s;
}

.preset-btn:hover { background: #2563eb; color: #fff; border-color: #2563eb; }

/* ── 字体预览 ── */
.font-preview {
  font-size: 15px;
  padding: 6px 10px;
  background: #f8fbff;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  margin-top: 4px;
  color: #1e3a5f;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── 属性折叠组 ── */
.prop-group {
  border: 1px solid #e2eaf4;
  border-radius: 8px;
  margin-bottom: 6px;
  overflow: hidden;
}

.prop-group summary {
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #1b3f63;
  background: #f0f7ff;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.prop-group summary::-webkit-details-marker { display: none; }

.prop-group summary::after {
  content: "▸";
  margin-left: auto;
  font-size: 10px;
  color: #94a3b8;
  transition: transform 0.15s;
}

.prop-group[open] summary::after { transform: rotate(90deg); }

.prop-group > *:not(summary) {
  padding-left: 8px;
  padding-right: 8px;
}

.style-toggles {
  display: flex;
  gap: 8px;
  padding: 4px 8px;
}

.style-toggles label {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

/* ── 字号滑块+数字输入联动 ── */
.size-slider-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.size-slider-row input[type="range"] {
  flex: 1;
  min-width: 0;
}

.size-num-input {
  width: 52px !important;
  flex-shrink: 0;
  padding: 4px 6px !important;
  text-align: center;
  font-size: 12px;
}

/* ── 数据输入 ── */
.data-input-wrap { position: relative; }

.data-counter {
  position: absolute;
  bottom: 6px; right: 8px;
  font-size: 11px;
  color: #6b8aaa;
  background: rgba(255,255,255,0.85);
  padding: 1px 6px;
  border-radius: 999px;
  pointer-events: none;
}

.data-mode-hint {
  font-size: 11px;
  color: #6b8aaa;
  background: #f8fbff;
  border: 1px dashed #c8d7e6;
  border-radius: 6px;
  padding: 4px 8px;
  margin: 3px 0 4px;
  line-height: 1.5;
}

/* ── 纸张尺寸显示 ── */
.paper-size-display {
  text-align: center;
  font-size: 12px;
  color: #2563eb;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 5px 8px;
  margin-top: 4px;
  font-weight: 600;
}

/* ── 模式引导 ── */
.mode-guide {
  text-align: center;
  padding: 20px 12px;
  color: #475569;
}

.mode-guide-icon { font-size: 36px; margin-bottom: 8px; }

.mode-guide p {
  margin: 4px 0;
  font-size: 13px;
  line-height: 1.5;
}

.mode-guide-sub { font-size: 11px; color: #94a3b8; }

/* ── 打印 ── */
.print-root { display: none; }

/* ── Toast 提示 ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  color: #f8fafc;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  animation: toastIn 0.2s ease, toastOut 0.3s ease 2.2s forwards;
  pointer-events: none;
}

.toast.success { background: #166534; }
.toast.error   { background: #991b1b; }
.toast.warn    { background: #92400e; }

@keyframes toastIn  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ── 弹窗 ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.45);
  z-index: 8888;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
}

.modal-box {
  background: #fff;
  border-radius: 16px;
  padding: 24px 28px;
  min-width: 280px;
  max-width: 360px;
  box-shadow: 0 24px 48px rgba(15,23,42,0.2);
}

.modal-box h3 { margin: 0 0 10px; font-size: 17px; color: #0f172a; }
.modal-box p  { margin: 0 0 16px; font-size: 14px; color: #475569; line-height: 1.6; }

.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { flex: 1; }

/* ── 响应式 ── */
@media (max-width: 1150px) {
  html, body { overflow: auto; }
  .app-shell { grid-template-columns: 1fr; height: auto; min-height: 100vh; overflow: visible; }
  .workspace { overflow: visible; }
  .topbar { position: static; transform: none; width: auto; border-radius: 0; box-shadow: none; border-left: 0; border-right: 0; }
  #sheetTab { padding-top: 16px; }
  .sidebar { overflow: auto; display: block; }
  .side-pane { display: block; overflow: visible; }
  .side-nav { display: none; }
  .three-wrap { grid-template-columns: 1fr; grid-template-rows: 62vh auto; }
}

@media print {
  html, body { width: auto !important; height: auto !important; overflow: visible !important; background: #fff !important; margin: 0 !important; }
  .app-shell { display: none !important; }
  .print-root { display: block !important; position: static !important; width: auto !important; height: auto !important; margin: 0 !important; padding: 0 !important; background: #fff !important; overflow: visible !important; }
  .print-page { page-break-after: always; break-after: page; break-inside: avoid; position: relative; overflow: hidden; margin: 0 !important; padding: 0 !important; }
  .print-page:last-child { page-break-after: auto; break-after: auto; }
}
