/* 现代精致设计系统 - 参考 PaperMe 风格 */
:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --pdf-color: #ef4444;
  --pdf-hover: #dc2626;
  --svg-color: #8b5cf6;
  --svg-hover: #7c3aed;
  --png-color: #10b981;
  --png-hover: #059669;
  --print-color: #4b5563;
  --print-hover: #374151;

  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --border-light: #e2e8f0;
  --border-focus: #3b82f6;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-card: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.08);
  --shadow-paper: 0 12px 28px -6px rgba(0, 0, 0, 0.18), 0 8px 12px -4px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 顶部导航条 */
.navbar {
  height: 60px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
  z-index: 20;
}

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

.brand-icon {
  width: 38px;
  height: 38px;
  color: #3b82f6;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-title span {
  font-size: 0.85rem;
  font-weight: 600;
  color: #3b82f6;
  background: #eff6ff;
  padding: 2px 6px;
  border-radius: 4px;
}

.brand-desc {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/* 顶部操作按钮 */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.action-btn svg {
  width: 16px;
  height: 16px;
}

.action-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.15);
}

.action-btn:active {
  transform: translateY(0);
}

.btn-pdf {
  background: var(--pdf-color);
}
.btn-pdf:hover {
  background: var(--pdf-hover);
}

.btn-svg {
  background: var(--svg-color);
}
.btn-svg:hover {
  background: var(--svg-hover);
}

.btn-png {
  background: var(--png-color);
}
.btn-png:hover {
  background: var(--png-hover);
}

.btn-print {
  background: #f1f5f9;
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}
.btn-print:hover {
  background: #e2e8f0;
}

/* 工作区容器 */
.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* 左侧控制面板 */
.control-panel {
  width: 420px;
  min-width: 360px;
  background: #ffffff;
  border-right: 1px solid var(--border-light);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 10;
}

/* 卡片分区 */
.card-section {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
}

.section-header .icon {
  font-size: 1.1rem;
}

.section-header h3 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* 预设模板网格 */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.preset-card {
  padding: 10px;
  border: 1px solid var(--border-light);
  background: #f8fafc;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}

.preset-card:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.preset-card.active {
  background: #eff6ff;
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.preset-card .card-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.preset-card.active .card-name {
  color: var(--primary);
}

.preset-card .card-sub {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  line-height: 1.2;
}

/* 表单字段与网格 */
.field-grid {
  display: grid;
  gap: 12px;
}

.grid-2 {
  grid-template-columns: 1fr 1fr;
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

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

.field-item label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.label-with-val {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.label-with-val span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

input[type="number"],
select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  font-size: 0.85rem;
  background-color: #ffffff;
  color: var(--text-primary);
  transition: all 0.15s ease;
}

input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

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

.helper-text {
  font-size: 0.72rem;
  color: var(--text-tertiary);
}

.cell-size-banner {
  background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cell-size-banner .size-title {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.cell-size-banner .size-val {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1d4ed8;
  font-variant-numeric: tabular-nums;
}

.highlight-checkbox {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 6px;
  padding: 8px 10px;
}

.highlight-checkbox label strong {
  color: #1d4ed8;
}

.slot-config-box {
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px;
}

/* 复选框组件 */
.checkbox-box label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.checkbox-box input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}

/* 颜色选择组件 */
.color-picker-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.native-color-picker {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
}

.preset-colors {
  display: flex;
  gap: 8px;
  align-items: center;
}

.color-pill {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #cbd5e1;
  transition: transform 0.15s, box-shadow 0.15s;
}

.color-pill:hover {
  transform: scale(1.15);
}

.color-pill.active {
  box-shadow: 0 0 0 2px var(--primary);
  transform: scale(1.1);
}

/* 纸张背景底色拾色板 */
.bg-palette {
  display: flex;
  gap: 8px;
}

.bg-swatch {
  flex: 1;
  height: 30px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, box-shadow 0.15s;
}

.bg-swatch:hover {
  transform: translateY(-2px);
}

.bg-swatch.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}

/* 导入导出配置按钮 */
.io-btn-row {
  display: flex;
  gap: 10px;
}

.sub-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: #f8fafc;
  border: 1px solid var(--border-light);
  cursor: pointer;
  transition: all 0.15s ease;
}

.sub-btn svg {
  width: 14px;
  height: 14px;
}

.sub-btn:hover {
  background: #e2e8f0;
  color: var(--text-primary);
}

.panel-bottom-space {
  height: 30px;
}

/* 右侧预览区 */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #cbd5e1;
  overflow: hidden;
  position: relative;
}

.preview-bar {
  height: 48px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 5;
}

.spec-tags {
  display: flex;
  gap: 8px;
}

.tag {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 3px 8px;
  background: #f1f5f9;
  color: var(--text-secondary);
  border-radius: 4px;
  border: 1px solid var(--border-light);
}

.tag-highlight {
  background: #eff6ff;
  color: var(--primary);
  border-color: #bfdbfe;
  font-weight: 600;
}

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

.tool-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-light);
  background: #ffffff;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.tool-btn.fit-btn {
  width: auto;
  padding: 0 8px;
  font-size: 0.75rem;
}

.tool-btn:hover {
  background: #f8fafc;
  color: var(--text-primary);
}

.zoom-text {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: center;
  color: var(--text-secondary);
}

/* 纸张视口 */
.paper-viewport {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.paper-sheet {
  background: #ffffff;
  box-shadow: var(--shadow-paper);
  transform-origin: center center;
  transition: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

.svg-container {
  display: block;
  line-height: 0;
}

.svg-container svg {
  display: block;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
}

@font-face {
  font-family: PaperGridSans;
  src: url('assets/PaperGridSans.ttf') format('truetype');
  font-display: swap;
}

/* 响应式调整 */
@media (max-width: 1024px) {
  .workspace {
    flex-direction: column;
    overflow-y: auto;
  }
  .control-panel {
    width: 100%;
    min-width: 100%;
    height: auto;
  }
  .preview-panel {
    height: 600px;
  }
}

[hidden] { display: none !important; }
body { height: 100dvh; }
button, input, select, summary { touch-action: manipulation; }
button:disabled, input:disabled { opacity: 0.5; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
[aria-invalid="true"] { border-color: #b91c1c !important; }
.field-full { grid-column: 1 / -1; }
.navbar { flex-shrink: 0; }
.workspace, .preview-panel { min-height: 0; min-width: 0; }
.control-panel { flex-shrink: 0; }
.card-section { flex-shrink: 0; }
.preset-status { margin-left: auto; font-size: 0.7rem; color: var(--text-secondary); }
.more-exports { position: relative; order: 3; }
.more-exports summary { min-height: 36px; list-style: none; white-space: nowrap; }
.more-exports summary::-webkit-details-marker { display: none; }
.export-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: 250px;
  display: grid;
  gap: 12px;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: var(--shadow-paper);
  z-index: 30;
}
.export-menu label { font-size: 0.8rem; }
.export-menu select, #templateName { width: 100%; min-height: 36px; padding: 6px 10px; border: 1px solid var(--border-light); border-radius: 5px; font: inherit; }
.export-menu .action-btn { justify-content: center; }
.preview-bar { height: auto; min-height: 48px; flex-shrink: 0; flex-wrap: wrap; gap: 12px; padding: 12px 20px; }
.spec-tags { flex-wrap: wrap; }
.tag, .page-navigation { font-variant-numeric: tabular-nums; }
.page-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 8px 20px; background: #f8fafc; }
.page-navigation { display: flex; align-items: center; gap: 12px; font-size: 0.8rem; }
.paper-viewport { min-height: 0; display: flex; align-items: flex-start; justify-content: flex-start; padding: 16px; }
.paper-sheet { position: relative; flex: none; margin: auto; display: block; transition: none; }
.svg-container { position: absolute; left: 0; top: 0; transform-origin: top left; }
.print-hint { padding: 8px 16px; text-align: center; font-size: 0.75rem; color: #334155; background: #e2e8f0; }
.app-status { flex-shrink: 0; padding: 7px 20px; font-size: 0.75rem; min-height: 30px; color: #475569; background: #fff; border-top: 1px solid var(--border-light); overflow-wrap: anywhere; }
.status-error { color: #991b1b; background: #fff1f2; }
.validation-message { padding: 12px 20px; font-size: 0.85rem; color: #991b1b; background: #fff1f2; border-bottom: 1px solid #fecdd3; }
.layout-warning { padding: 8px 20px; font-size: 0.8rem; color: #854d0e; background: #fefce8; }
.mobile-view-switch { display: none; }

@media (max-width: 1024px) {
  .navbar { padding: 12px 16px; height: auto; min-height: 60px; gap: 12px; flex-wrap: wrap; }
  .workspace { overflow: hidden; }
  .control-panel { flex: 1; width: 100%; min-width: 0; height: auto; overflow: auto; }
  .preview-panel { flex: 1; height: auto; }
  .mobile-view-switch { display: flex; gap: 4px; padding: 6px 16px; background: #fff; border-bottom: 1px solid var(--border-light); }
  .mobile-view-switch button { flex: 1; min-height: 40px; border: 0; border-radius: 5px; font: inherit; font-size: 0.85rem; background: #f1f5f9; color: #475569; cursor: pointer; }
  .mobile-view-switch button[aria-pressed="true"] { color: #1d4ed8; background: #dbeafe; font-weight: 600; }
  body[data-view="settings"] .preview-panel, body[data-view="preview"] .control-panel { display: none; }
  .tool-btn { min-width: 36px; height: 36px; }
  .color-pill { min-width: 32px; min-height: 32px; }
  .bg-swatch { min-height: 36px; }
}

@media (max-width: 540px) {
  .brand-icon { width: 30px; height: 30px; }
  .brand-title { font-size: 1rem; }
  .brand-desc { display: none; }
  .nav-left, .nav-actions { width: 100%; }
  .nav-actions { gap: 8px; }
  .nav-actions > .action-btn, .more-exports { flex: 1; }
  .action-btn, .more-exports summary { min-height: 40px; justify-content: center; padding: 8px 10px; font-size: 0.8rem; }
  .preview-bar, .page-toolbar { padding: 8px 12px; gap: 6px; }
  .preview-bar { align-items: flex-start; }
  .spec-tags { gap: 4px; }
  .tag { font-size: 0.68rem; padding: 3px 5px; }
  .control-panel { padding: 12px; }
  .app-status, .print-hint { font-size: 0.68rem; padding: 6px 12px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

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