:root {
  --bg: #f4f6f8;
  --surface: #fff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --green-zone: #22c55e;
  --red-zone: #ef4444;
  --radius: 8px;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand-title {
  display: block;
  font-size: 18px;
  font-weight: 700;
}

.brand-sub {
  font-size: 13px;
  color: var(--muted);
}

.mode-tabs {
  display: flex;
  gap: 8px;
  background: var(--bg);
  padding: 4px;
  border-radius: 999px;
}

.mode-tab {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.mode-tab.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.panel-subtabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin: -4px 0 20px;
}

.panel-subtab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.panel-subtab:hover {
  color: var(--text);
}

.panel-subtab.active {
  color: var(--primary);
  font-weight: 600;
  border-bottom-color: var(--primary);
}

.panel-title-spaced {
  margin-top: 28px;
}

.layout {
  width: 100%;
  min-width: 1120px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 380px minmax(680px, 1fr);
  gap: 20px;
  align-items: start;
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.panel-left {
  width: 380px;
  min-width: 380px;
  overflow-x: hidden;
}

.panel-right {
  min-width: 0;
}

.panel-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
}

.sub-title {
  margin: 16px 0 8px;
  font-size: 14px;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.template-card {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: #fafafa;
}

.template-card:hover {
  border-color: var(--primary);
}

.template-card.selected {
  border-color: var(--primary);
  background: #ecfdf5;
}

.template-card-id {
  font-size: 11px;
  color: var(--muted);
}

.template-card-name {
  font-size: 13px;
  font-weight: 600;
  margin-top: 4px;
}

.field-form,
.admin-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.field span {
  color: var(--muted);
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.text-style-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: -6px;
  color: var(--muted);
  font-size: 12px;
}

.text-style-row input[type="color"] {
  width: 42px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.upload-item {
  margin-bottom: 12px;
}

.upload-item label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.upload-default-note {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.material-picker {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.material-card {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
}

.material-card img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.material-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

.material-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.material-empty {
  padding: 10px 12px;
  color: var(--muted);
  background: #fafafa;
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.migration-box {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
}

.migration-import {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.migration-import input {
  display: none;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

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

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

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  margin-right: 8px;
  margin-top: 8px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 0;
}

.hint-inline {
  margin: -8px 0 16px;
}

.category-manager {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
}

.category-add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.category-add-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
}

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.category-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.preview-meta {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
}

.preview-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

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

.tool-btn-wide {
  width: auto;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
}

.zoom-value {
  width: 52px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.canvas-wrap {
  background: #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  width: 100%;
  height: calc(100vh - 190px);
  min-height: 560px;
  overflow: auto;
  overscroll-behavior: contain;
}

.canvas-stage {
  position: relative;
  flex: 0 0 auto;
  transform-origin: top left;
}

.zone-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  pointer-events: none;
}

.zone-overlay.active {
  display: block;
  pointer-events: auto;
}

.zone-box {
  position: absolute;
  min-width: 32px;
  min-height: 32px;
  border: 2px solid var(--green-zone);
  background: rgba(34, 197, 94, 0.12);
  cursor: move;
  user-select: none;
}

.zone-box::before {
  content: attr(data-label);
  position: absolute;
  left: 0;
  top: -26px;
  max-width: 180px;
  padding: 3px 8px;
  overflow: hidden;
  border-radius: 6px 6px 0 0;
  background: var(--green-zone);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zone-box.image-zone {
  border-color: #0ea5e9;
  background: rgba(14, 165, 233, 0.12);
}

.zone-box.image-zone::before {
  background: #0ea5e9;
}

.zone-resize {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--green-zone);
  cursor: nwse-resize;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
}

.image-zone .zone-resize {
  background: #0ea5e9;
}

#canvas {
  display: block;
  position: relative;
  z-index: 1;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  flex: 0 0 auto;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.18);
  background: #fff;
}

.legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}

.legend-item {
  position: relative;
  padding-left: 16px;
}

.legend-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-locked::before {
  background: var(--red-zone);
}

.legend-editable::before {
  background: var(--green-zone);
}

.zone-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}

.zone-row {
  display: grid;
  grid-template-columns: minmax(90px, 0.8fr) minmax(130px, 1.2fr) minmax(96px, 1fr);
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
  font-size: 12px;
}

.zone-row input,
.zone-row select {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}

.zone-row input[type="color"] {
  width: 34px;
  height: 30px;
  padding: 2px;
}

.zone-drag-note {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.zone-file-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.zone-remove {
  justify-self: end;
  width: 30px;
  border: none;
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 6px;
  cursor: pointer;
  height: 30px;
}

.zone-file-label input {
  display: none;
}

.zone-file-status {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.form-status {
  min-height: 20px;
  margin-top: 2px;
  font-size: 12px;
}

.form-status.is-info {
  color: var(--muted);
}

.form-status.is-success {
  color: var(--primary);
  font-weight: 600;
}

.form-status.is-error {
  color: #b91c1c;
  font-weight: 600;
}

@media (max-width: 720px) {
  .layout {
    min-width: 0;
    grid-template-columns: 1fr;
  }

  .panel-left {
    width: auto;
    min-width: 0;
  }

  .canvas-wrap {
    height: 620px;
    min-height: 420px;
  }

  .preview-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .preview-meta {
    margin-left: 0;
  }
}

@media (max-width: 520px) {
  .topbar-inner,
  .layout {
    padding-left: 12px;
    padding-right: 12px;
  }

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

  .actions {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }
}

.zone-row-header {
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.saved-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.saved-list li,
.maker-zone-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.saved-template-item {
  gap: 10px;
}

.saved-empty {
  color: var(--muted);
}

.saved-template-info {
  min-width: 0;
}

.saved-template-info strong {
  display: block;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-template-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.saved-template-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.saved-list .btn-link,
.maker-zone-list button {
  border: none;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

.saved-list .btn-link.danger,
.maker-zone-list button {
  color: #b91c1c;
}

.maker-zone-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.maker-zone-meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.canvas-wrap.maker-active {
  cursor: crosshair;
}

.canvas-wrap.maker-active #canvas {
  cursor: crosshair;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.btn-link {
  border: none;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(244, 246, 248, 0.94);
}

.login-card {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.login-card p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.login-card .btn {
  width: 100%;
  margin-top: 6px;
}

.app-locked {
  filter: blur(1px);
  pointer-events: none;
  user-select: none;
}
