:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #1a2332;
  --muted: #5a6a7a;
  --line: #d5dee8;
  --primary: #0f4c81;
  --primary-hover: #0c3d68;
  --accent: #c45c26;
  --accent-hover: #a34a1c;
  --ok: #1b7a4a;
  --warn: #9a6b00;
  --err: #b42318;
  --shadow: 0 8px 24px rgba(15, 76, 129, 0.08);
  --radius: 14px;
  --font: "Noto Sans TC", "PingFang HK", "Microsoft JhengHei", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #dceaf8 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #f8e9dc 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.header h1 {
  margin: 0 0 4px;
  font-size: 1.55rem;
  letter-spacing: 0.02em;
  color: var(--primary);
}
.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.header-badge {
  flex-shrink: 0;
  background: #eef4fa;
  color: var(--primary);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.steps {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 0;
  margin: 0 0 14px;
}
.step {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
}
.step .n {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
}

.status {
  background: #eef6ff;
  border: 1px solid #c9ddf3;
  color: #204868;
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.92rem;
}
.status.is-ok { background: #eefaf3; border-color: #b7e4c7; color: #1b5c38; }
.status.is-err { background: #fff1f0; border-color: #f0c2be; color: #8a2218; }
.status.is-busy { background: #fff8e8; border-color: #f0d9a0; color: #7a5a00; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.upload-zone {
  border: 2px dashed #9bb6d0;
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbff, #f3f7fb);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.upload-zone:hover,
.upload-zone:focus,
.upload-zone.dragover {
  border-color: var(--primary);
  background: #eef5fc;
  outline: none;
}
.upload-illus { font-size: 2rem; margin-bottom: 6px; }
.muted { color: var(--muted); font-size: 0.88rem; }

.toolbar-global {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}
.chk {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}
.chk input[type="range"] { width: 140px; }
.chk-block { flex-direction: row; flex-wrap: wrap; }
.chk-label { min-width: 9.5em; color: var(--ink); font-weight: 600; font-size: 0.86rem; }
.hint { flex-basis: 100%; margin: 0 0 4px; font-size: 0.82rem; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover:not(:disabled) { background: #f3f7fb; border-color: #b7c8da; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}
.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}
.btn-sm { padding: 6px 10px; font-size: 0.82rem; }
.file-btn { display: inline-block; margin-top: 6px; }

.file-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.card-title {
  font-weight: 700;
  font-size: 0.95rem;
  word-break: break-all;
}
.card-meta {
  color: var(--muted);
  font-size: 0.82rem;
}
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-busy { background: #fff3cd; color: #7a5a00; }
.badge-ok { background: #d8f3e3; color: #1b5c38; }
.badge-err { background: #fde2e0; color: #8a2218; }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 14px 0;
}
.tab {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px 8px 0 0;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--muted);
  cursor: pointer;
}
.tab.active {
  background: #fff;
  border-color: var(--line);
  border-bottom-color: #fff;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: -1px;
}

.preview-wrap {
  border-top: 1px solid var(--line);
  padding: 14px;
  min-height: 220px;
  background: #fafbfc;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-wrap img,
.preview-wrap svg,
.preview-wrap object {
  max-width: 100%;
  max-height: 420px;
  height: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.preview-empty {
  color: var(--muted);
  font-size: 0.9rem;
}
.side-by-side {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}
.side-by-side .pane {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
}
.side-by-side .pane h4 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}
.side-by-side img,
.side-by-side .svg-host {
  max-height: 280px;
  width: 100%;
  object-fit: contain;
}
.side-by-side .svg-host {
  overflow: auto;
  max-height: 280px;
}
.side-by-side .svg-host svg {
  max-width: 100%;
  height: auto;
  border: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #c9ddf3;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footer {
  margin-top: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}
.footer code {
  background: #eef2f6;
  padding: 1px 6px;
  border-radius: 4px;
}

@media (max-width: 860px) {
  .steps { grid-template-columns: 1fr 1fr; }
  .side-by-side { grid-template-columns: 1fr; }
  .header { flex-direction: column; }
}


/* geo4 editable labels */
.label-panel {
  border-top: 1px solid var(--line);
  padding: 12px 14px 14px;
  background: #fff;
}
.label-panel h3 {
  margin: 0 0 8px;
  font-size: 0.92rem;
  color: var(--primary);
}
.label-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.label-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.label-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}
.label-row input[type="text"] {
  flex: 1;
  min-width: 80px;
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.label-row input[type="number"] {
  width: 64px;
  font: inherit;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.label-row.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(15, 76, 129, 0.15);
}

.preview-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}
.preview-stage img.stage-img {
  display: block;
  max-width: 100%;
  max-height: 420px;
  width: auto;
  height: auto;
  border: none;
  border-radius: 0;
}
.label-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.label-chip {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: grab;
  user-select: none;
  font-style: italic;
  font-family: "Times New Roman", "Noto Serif TC", Georgia, serif;
  font-weight: 700;
  color: #111;
  text-shadow:
    -1px -1px 0 #fff,
     1px -1px 0 #fff,
    -1px  1px 0 #fff,
     1px  1px 0 #fff,
     0 0 3px #fff;
  padding: 2px 4px;
  border-radius: 4px;
  white-space: nowrap;
  line-height: 1.1;
  z-index: 2;
}
.label-chip:active { cursor: grabbing; }
.label-chip.is-active {
  outline: 2px solid var(--primary);
  background: rgba(15, 76, 129, 0.08);
}
.label-chip[contenteditable="true"] {
  cursor: text;
  min-width: 0.8em;
  outline: 2px dashed var(--accent);
  background: rgba(255, 255, 255, 0.85);
}

.preview-wrap.with-labels {
  flex-direction: column;
  align-items: stretch;
}

.label-box {
  position: absolute;
  border: 1.5px dashed rgba(15, 76, 129, 0.65);
  background: rgba(15, 76, 129, 0.06);
  pointer-events: none;
  box-sizing: border-box;
  border-radius: 2px;
  z-index: 1;
}
.label-box.is-active {
  border-color: var(--accent);
  background: rgba(196, 92, 38, 0.1);
}
