:root {
  --color-route-red:    #e74c3c;
  --color-route-blue:   #2980b9;
  --color-route-purple: #8e44ad;
  --color-route-orange: #f39c12;
  --color-route-green:  #27ae60;
  --color-route-gray:   #7f8c8d;

  --color-primary: #e74c3c;
  --color-primary-hover: #c0392b;
  --color-text: #2c3e50;
  --color-text-secondary: #555;
  --color-text-muted: #888;
  --color-bg: #f5f5f5;
  --color-card: #fff;
  --color-border: #ddd;
  --color-border-light: #eee;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --shadow-card: 0 2px 10px rgba(0, 0, 0, .08);
  --shadow-card-hover: 0 4px 16px rgba(0, 0, 0, .12);

  /* 仅 CSS 字体调用（不嵌入任何字体文件，技术上不构成分发，无侵权风险）
     fallback 链：用户本机有 Apple/Microsoft 字体则优先用，否则降级到
     开源可商用 CJK（HarmonyOS Sans / MiSans / Source Han Sans 均 OFL/MIT 许可） */
  --font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "HarmonyOS Sans SC", "MiSans", "Source Han Sans SC", "Noto Sans CJK SC",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Source Code Pro", monospace;

  --header-height: 56px;
  --editor-width: 340px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

.app-header {
  height: var(--header-height);
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: var(--shadow-card);
  position: relative;
  z-index: 10;
}

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

.brand-logo {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: block;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1;
}

.brand-link {
  font-size: 12px;
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 500;
  align-self: baseline;
}

.brand-link:hover {
  color: var(--color-primary);
}

.noscript-fallback {
  max-width: 760px;
  margin: 40px auto;
  padding: 24px 32px;
  font-family: var(--font-family);
  color: var(--color-text);
  line-height: 1.7;
}

.noscript-fallback h1 {
  font-size: 22px;
  margin: 0 0 12px;
}

.noscript-fallback ul {
  padding-left: 20px;
}

.noscript-fallback li {
  margin-bottom: 4px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:not(:disabled):hover {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: #f0f0f0;
  color: var(--color-text);
}

.btn-secondary:not(:disabled):hover {
  background: #e0e0e0;
}

.app-main {
  display: flex;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

.app-editor {
  width: var(--editor-width);
  flex-shrink: 0;
  background: var(--color-card);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 16px;
}

.app-preview {
  flex: 1;
  min-width: 0;
  padding: 16px 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
}

.preview-toolbar {
  width: 100%;
  max-width: 1123px;
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  font-size: 12px;
}

.poi-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-secondary);
  cursor: pointer;
  user-select: none;
  padding: 2px 4px;
}

.poi-toggle input {
  cursor: pointer;
  margin: 0;
}

.a4-container {
  /* 严格 A4 横版（297×210 mm）@ 96 DPI: 1123×794 px, 比例 297/210
     固定尺寸不响应式，确保屏幕显示 = 导出图（所见即所得）
     视口窄时父容器 .app-preview 横向滚动 */
  width: 1123px;
  height: 794px;
  flex-shrink: 0;
  background: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  container-type: inline-size;
  display: flex;
  flex-direction: column;
}

.placeholder {
  color: var(--color-text-muted);
  text-align: center;
  padding: 40px;
  font-size: 13px;
}

/* 内联提示（贴在 field-label 下） */

.field-hint {
  margin: 0 0 6px;
  padding: 5px 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--color-text-muted);
  background: #fff8e1;
  border-left: 2px solid #f39c12;
  border-radius: var(--radius-sm);
}

.tips-kbd {
  display: inline-block;
  font-family: var(--font-mono);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 0 4px;
  font-size: 10px;
  color: var(--color-text);
}

/* ===== 编辑栏卡片 ===== */

.editor-card {
  background: var(--color-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 12px;
}

.editor-card.route-card {
  border-left-width: 4px;
  border-left-style: solid;
}

.card-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-body {
  padding-top: 4px;
}

/* ===== 表单 ===== */

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.field-label {
  font-size: 12px;
  color: var(--color-text-secondary);
  font-weight: 600;
}

.field-row {
  display: flex;
  gap: 8px;
}

.field-row .field {
  flex: 1;
  margin-bottom: 10px;
}

.input {
  width: 100%;
  padding: 7px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-family);
  background: #fff;
  color: var(--color-text);
  outline: none;
  transition: border-color .15s;
}

.input:focus {
  border-color: var(--color-primary);
}

.textarea {
  resize: vertical;
  min-height: 50px;
  font-family: var(--font-family);
}

/* ===== 颜色 swatch ===== */

.color-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.color-swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform .1s, border-color .1s;
}

.swatch:hover {
  transform: scale(1.1);
}

.swatch.active {
  border-color: var(--color-text);
  transform: scale(1.15);
}

/* ===== 列表行（waypoint / step） ===== */

.list-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.list-row.no-mb {
  margin-bottom: 0;
}

/* 拖拽 waypoint 行 */
.waypoint-row {
  cursor: grab;
  transition: opacity .15s, background .15s;
}

.waypoint-row.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

.waypoint-row.drag-over {
  background: rgba(231, 76, 60, .08);
  border-top: 2px solid var(--color-primary);
}

.drag-handle {
  font-size: 16px;
  color: var(--color-text-muted);
  line-height: 1;
  padding: 0 2px;
  user-select: none;
  flex-shrink: 0;
}

.waypoint-status {
  font-size: 12px;
  color: var(--color-text-muted);
  padding: 6px 8px;
  background: #f8f8f8;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  text-align: center;
}

.waypoint-status.is-set {
  color: var(--color-text);
  background: #f0f9f0;
  border-style: solid;
  border-color: #27ae60;
  font-weight: 500;
}

.row-index {
  font-size: 12px;
  color: var(--color-text-muted);
  width: 18px;
  flex-shrink: 0;
  text-align: right;
  font-family: var(--font-mono);
}

.flex-1 {
  flex: 1;
  min-width: 0;
}

/* ===== 按钮变体 ===== */

.btn-icon {
  padding: 0;
  width: 28px;
  height: 28px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-compact {
  padding: 4px 10px;
  height: 28px;
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
}

.btn-danger {
  background: #fdecea;
  color: #c0392b;
}

.btn-danger:not(:disabled):hover {
  background: #f5c6cb;
}

.btn-block {
  width: 100%;
  margin-top: 4px;
  font-weight: 500;
  font-size: 12px;
  padding: 6px;
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px dashed var(--color-border);
}

.btn-block:not(:disabled):hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(231, 76, 60, .05);
}

.btn-link {
  background: transparent;
  color: var(--color-text-secondary);
  font-weight: 500;
  padding: 6px 12px;
}

.btn-link:hover {
  color: var(--color-primary);
}

.btn-link.danger {
  color: #c0392b;
}

.btn-link.danger:hover {
  color: #922b21;
}

/* ===== 底部操作区 ===== */

.editor-footer {
  display: flex;
  justify-content: space-between;
  padding: 12px 0 8px;
  border-top: 1px solid var(--color-border-light);
  margin-top: 8px;
}

/* ===== A4 横版预览区 ===== */

.preview-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

.preview-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text);
}

.preview-meta {
  font-size: 12px;
  color: var(--color-text-secondary);
  display: flex;
  gap: 12px;
}

.preview-note {
  color: var(--color-text-muted);
}

.preview-body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.preview-map {
  flex: 0 0 62%;
  height: 100%;
  background: #eef2f5;
}

.preview-steps {
  flex: 0 0 38%;
  padding: 1cqw;
  overflow: hidden;
  background: #fafafa;
  border-left: 1px solid var(--color-border-light);
}

.step-block {
  margin-bottom: 0.7cqw;
  padding: 0.6cqw 0.85cqw;
  background: #fff;
  border-radius: var(--radius-sm);
  border-left: 0.35cqw solid var(--color-border);
}

.step-block:last-child {
  margin-bottom: 0;
}

.step-title {
  margin: 0 0 0.4cqw;
  font-size: 1.35cqw;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.45cqw;
  flex-wrap: wrap;
  line-height: 1.3;
}

.step-meta {
  font-size: 0.95cqw;
  color: var(--color-text-muted);
  font-weight: 500;
  font-family: var(--font-mono);
  white-space: nowrap;
}

/* ===== 水印（整页斜向重复，防截图复制） ===== */

.watermark {
  position: absolute;
  inset: -30%;
  pointer-events: none;
  user-select: none;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: space-around;
  gap: 8cqw 12cqw;
  transform: rotate(-28deg);
  overflow: hidden;
  font-family: var(--font-family);
  font-size: 1.3cqw;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(44, 62, 80, 0.09);
  white-space: nowrap;
}

/* ===== 地图图例 ===== */

/* 强制隐藏高德 logo + GS 备案号（用我们自己的图例代替） */
.preview-map .amap-logo,
.preview-map .amap-copyright,
#map-container .amap-logo,
#map-container .amap-copyright,
#map-container a[href*="amap.com"] {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
}

.map-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: 10px 16px 12px 14px;
  box-shadow: var(--shadow-card);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  line-height: 1.5;
  backdrop-filter: blur(4px);
  white-space: nowrap;
  max-width: 60%;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  line-height: 1.5;
}

.legend-color {
  width: 20px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-label {
  color: var(--color-text);
  font-weight: 600;
  min-width: 42px;
  flex-shrink: 0;
}

.legend-meta {
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  flex-shrink: 0;
}

.step-list {
  margin: 0;
  padding-left: 1.8cqw;
  font-size: 1.15cqw;
  line-height: 1.4;
  color: var(--color-text-secondary);
}

.step-list li {
  margin-bottom: 0.18cqw;
}

/* ===== 付费弹窗 ===== */

.payment-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.payment-modal-card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
  width: 100%;
  max-width: 420px;
  padding: 24px;
  font-size: 14px;
}

.payment-modal-title {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text);
}

.payment-modal-body {
  color: var(--color-text);
  line-height: 1.6;
  min-height: 80px;
}

.payment-modal-body p {
  margin: 0 0 10px;
}

.payment-modal-body p:last-child {
  margin-bottom: 0;
}

.payment-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 6px;
}

.payment-hint a {
  color: var(--color-primary);
  text-decoration: underline;
}

.payment-error {
  color: #c0392b;
  background: #fdecea;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.payment-success {
  background: #f0f9f0;
  border: 1px solid #27ae60;
  color: var(--color-text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.payment-modal-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ===== 拾取模式 ===== */

[x-cloak] { display: none !important; }

.app-editor.is-picking {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.4);
}

.app-editor.is-readonly {
  opacity: 0.65;
  pointer-events: none;
}

/* ===== 只读模式 banner ===== */

.readonly-banner {
  background: linear-gradient(90deg, #fdecea 0%, #fef3f2 100%);
  border-bottom: 1px solid #f5c6cb;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
  color: var(--color-text);
}

.readonly-banner-text strong {
  color: var(--color-primary);
}

/* ===== 全局 Toast ===== */

.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--color-text);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 80%;
  text-align: center;
}

.toast.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.toast-warn {
  background: #f39c12;
}

.toast.toast-error {
  background: #c0392b;
}

.pick-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 200;
  box-shadow: var(--shadow-card-hover);
  white-space: nowrap;
}

.pick-banner-cancel {
  background: rgba(255, 255, 255, .25);
  color: #fff;
  border: none;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-family);
}

.pick-banner-cancel:hover {
  background: rgba(255, 255, 255, .4);
}

/* field 内 label + 操作按钮并排 */
.field-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

/* app-preview 需要 relative 让 pick-banner absolute 定位有锚 */
.app-preview {
  position: relative;
}
