:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #687385;
  --line: #d9e0e8;
  --soft: #edf2f6;
  --primary: #176b5d;
  --primary-strong: #105247;
  --danger: #b83232;
  --focus: #2f80ed;
  --warning: #9a6a00;
  --radius: 8px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

code {
  padding: 2px 6px;
  border-radius: 5px;
  background: #eef3f1;
  color: #0d4d43;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 22px;
  min-height: 64px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.brand {
  font-size: 18px;
  font-weight: 800;
  white-space: nowrap;
}

.nav {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
}

.nav a,
.logout {
  padding: 9px 12px;
  border-radius: 7px;
  color: #4d5a6b;
  font-weight: 650;
  white-space: nowrap;
}

.nav a.active,
.nav a:hover,
.logout:hover {
  background: var(--soft);
  color: var(--text);
}

.page {
  width: min(1280px, calc(100vw - 40px));
  margin: 28px auto 56px;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(900px, 100%);
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 36px;
  align-items: center;
  padding: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(23, 32, 42, 0.08);
}

.login-panel h1,
.page-head h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.15;
}

.login-panel p,
.page-head p,
.muted {
  margin: 0;
  color: var(--muted);
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
}

.template-edit-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.template-edit-meta span:not(:last-child)::after {
  content: "·";
  margin-left: 8px;
  color: #9aa8b6;
}

.panel {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(23, 32, 42, 0.04);
  margin-bottom: 18px;
}

.panel.narrow {
  max-width: 680px;
}

.form-stack {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

label span {
  color: #3f4b59;
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid #c9d3de;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.color-picker-row {
  display: grid;
  gap: 10px;
}

.color-swatches {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border: 1px solid #b8c4d0;
  border-radius: 7px;
  background: var(--swatch-color);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.color-swatch:hover,
.color-swatch.selected {
  border-color: var(--primary);
  outline: 3px solid rgba(23, 107, 93, 0.18);
}

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

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(47, 128, 237, 0.18);
  border-color: var(--focus);
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid #c8d2dc;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

button:hover,
.button:hover {
  border-color: #9aa8b6;
  background: #f8fafb;
}

button.primary,
.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

button.primary:hover,
.button.primary:hover {
  border-color: var(--primary-strong);
  background: var(--primary-strong);
}

.button.small {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 13px;
}

button.danger,
.button.danger {
  border-color: #efcaca;
  color: var(--danger);
}

button.danger:hover,
.button.danger:hover {
  background: #fff1f1;
}

.button.disabled {
  pointer-events: none;
  opacity: 0.45;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.form-actions.split {
  justify-content: space-between;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.compact {
  gap: 10px;
}

.template-basic-panel {
  padding: 18px;
}

.template-basic-grid {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(220px, 1.1fr) minmax(260px, 1.2fr);
  gap: 14px;
  align-items: end;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: #4f5d6d;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.actions {
  width: 1%;
  white-space: nowrap;
}

.actions,
.actions form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.empty-state {
  display: grid;
  justify-items: start;
  gap: 10px;
  padding: 28px;
  border: 1px dashed #bac6d2;
  border-radius: var(--radius);
  background: #fbfcfd;
}

.empty-state h2,
.result-panel h2,
.editor-panel h2,
.preview-panel h2,
.inspector h2 {
  margin: 0;
  font-size: 20px;
}

.empty-state p,
.result-panel p {
  margin: 0;
  color: var(--muted);
}

.notification-stack {
  position: fixed;
  top: 76px;
  left: 50%;
  z-index: 100;
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(520px, calc(100vw - 32px));
  pointer-events: none;
  transform: translateX(-50%);
}

.notification {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: 100%;
  padding: 11px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 28px rgba(23, 32, 42, 0.16);
  color: var(--text);
  font-weight: 750;
  line-height: 1.45;
  pointer-events: auto;
  backdrop-filter: blur(10px);
  transition: opacity 240ms ease, transform 240ms ease, visibility 240ms ease;
}

.notification-message {
  min-width: 0;
  overflow-wrap: anywhere;
}

.notification-close {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 24px;
  height: 24px;
  margin: -2px -6px -2px 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: currentColor;
  cursor: pointer;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.notification-close:hover {
  background: rgba(23, 32, 42, 0.08);
}

.notification.is-hiding {
  visibility: hidden;
  opacity: 0;
  transform: translateY(-8px);
}

.notification.success {
  border-color: #9dd3bf;
  background: rgba(238, 250, 245, 0.97);
  color: #0d5a42;
}

.notification.error {
  align-items: flex-start;
  border-color: #efb4b4;
  border-radius: 16px;
  background: rgba(255, 243, 243, 0.98);
  color: #9b2525;
}

.editor-layout {
  --template-canvas-height: calc(100vh - 184px);
  --editor-form-width: 400px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr);
  gap: 16px;
  align-items: start;
  padding-right: calc(var(--editor-form-width) + 12px);
}

.editor-main {
  min-width: 0;
}

.editor-panel,
.preview-panel,
.editor-form-panel {
  overflow: hidden;
}

.panel-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-title-row p {
  margin-top: 4px;
}

.sidebar-section {
  display: grid;
  gap: 14px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.sidebar-section:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

.compact-form {
  gap: 12px;
}

.template-settings-form > label {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.template-settings-form > label span {
  line-height: 1.25;
}

.template-settings-form > label input {
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar-note {
  color: var(--muted);
  font-size: 13px;
}

.sidebar-toolbar {
  margin-bottom: 14px;
}

.preview-canvas-shell,
.editor-canvas-shell {
  max-width: 100%;
  height: var(--template-canvas-height);
  min-height: 420px;
  max-height: var(--template-canvas-height);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #dfe5eb;
  padding: 14px;
}

.preview-canvas,
.editor-canvas {
  position: relative;
  display: inline-block;
  max-width: 100%;
  background: #fff;
  box-shadow: 0 8px 24px rgba(23, 32, 42, 0.14);
}

.preview-canvas img,
.editor-canvas img,
.template-image {
  display: block;
  max-width: min(100%, 900px);
  max-height: calc(var(--template-canvas-height) - 30px);
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
}

.preview-layer,
.placeholder-layer {
  position: absolute;
  inset: 0;
}

.preview-layer {
  pointer-events: none;
}

.preview-item {
  position: absolute;
  display: block;
  overflow: hidden;
}

.placeholder-box {
  position: absolute;
  display: block;
  outline: 1px dashed rgba(47, 128, 237, 0.76);
  background: rgba(255, 255, 255, 0.04);
  color: #0a4c9a;
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  cursor: move;
  touch-action: none;
}

.placeholder-box.image {
  outline-color: rgba(224, 122, 39, 0.86);
  background: rgba(224, 122, 39, 0.08);
  color: #9a4a0c;
}

.placeholder-box.selected {
  outline: 3px solid rgba(23, 107, 93, 0.24);
  box-shadow: inset 0 0 0 2px var(--primary);
}

.placeholder-preview-text {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  overflow: hidden;
  white-space: pre;
  font-weight: 400;
  pointer-events: none;
}

.placeholder-preview-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

.placeholder-preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 8px;
  color: #8d4b12;
  text-align: center;
  overflow-wrap: anywhere;
  background: rgba(255, 255, 255, 0.42);
  pointer-events: none;
}

.placeholder-label {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  padding: 3px 5px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.84);
  opacity: 0;
  pointer-events: none;
}

.placeholder-box:hover .placeholder-label,
.placeholder-box.selected .placeholder-label,
.editor-canvas .placeholder-label {
  opacity: 1;
}

.resize-handle {
  position: absolute;
  right: -1px;
  bottom: -1px;
  z-index: 3;
  width: 14px;
  height: 14px;
  border-left: 2px solid currentColor;
  border-top: 2px solid currentColor;
  background: rgba(255, 255, 255, 0.92);
  cursor: nwse-resize;
}

.inspector {
  position: static;
}

.editor-form-panel {
  position: fixed;
  top: 0;
  right: 12px;
  z-index: 30;
  width: var(--editor-form-width);
  height: 100vh;
  margin: 0;
  overflow: auto;
  transform: none;
}

.panel-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 12px;
  cursor: ew-resize;
  touch-action: none;
}

.panel-resize-handle::after {
  content: "";
  position: absolute;
  top: 16px;
  bottom: 16px;
  left: 4px;
  width: 3px;
  border-radius: 999px;
  background: transparent;
}

.editor-form-panel:hover .panel-resize-handle::after,
.editor-form-panel.resizing .panel-resize-handle::after {
  background: rgba(23, 107, 93, 0.24);
}

.hidden {
  display: none !important;
}

.dynamic-fields {
  display: grid;
  gap: 14px;
  padding-top: 8px;
}

.field-row {
  display: grid;
  gap: 9px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.field-row header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #3f4b59;
  font-weight: 800;
}

.field-row small {
  color: var(--muted);
  font-weight: 650;
}

.compact-page-head {
  margin-bottom: 12px;
}

.compact-page-head h1 {
  margin-bottom: 4px;
}

.badge-form-panel {
  padding: 18px 20px;
}

.badge-form {
  gap: 12px;
}

.badge-form .grid.two {
  gap: 12px;
}

.badge-form label {
  gap: 5px;
}

.badge-form input,
.badge-form select,
.badge-form textarea {
  min-height: 36px;
  padding: 7px 10px;
}

.badge-form textarea {
  min-height: 54px;
}

.badge-form .dynamic-fields {
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 10px 12px;
  padding-top: 2px;
}

.badge-form .field-row {
  gap: 7px;
  padding: 10px 12px;
}

.badge-form .field-row header {
  align-items: center;
  font-size: 14px;
}

.badge-form .field-row label span,
.badge-form label span {
  font-size: 12px;
}

.badge-form .field-row small {
  font-size: 12px;
}

.badge-form .template-summary {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
}

.badge-form .empty-placeholder-message {
  grid-column: 1 / -1;
}

.badge-form .template-summary header {
  flex: 1;
}

.badge-form .field-row-image {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.badge-form .field-row-image header {
  grid-column: 1 / -1;
}

.badge-form .form-actions {
  justify-content: flex-end;
}

.result-panel {
  display: grid;
  gap: 12px;
}

.result-image {
  max-width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: #4e5b68;
  font-size: 12px;
  font-weight: 800;
}

.status.success {
  background: #e6f7ef;
  color: #0c5b42;
}

.status.failed {
  background: #fff0f0;
  color: #9d2424;
}

td small {
  display: block;
  max-width: 360px;
  margin-top: 4px;
  color: var(--danger);
  white-space: normal;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 16px;
}

.token-reveal {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid #b8dfcf;
  border-radius: var(--radius);
  background: #effaf5;
}

@media (max-width: 960px) {
  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 14px 18px;
  }

  .nav {
    order: 3;
    width: 100%;
  }

  .page {
    width: min(100% - 24px, 1280px);
  }

  .login-panel,
  .editor-layout,
  .grid.two,
  .template-basic-grid {
    grid-template-columns: 1fr;
  }

  .editor-layout {
    padding-right: 0;
  }

  .editor-form-panel {
    position: static;
    width: 100%;
    height: auto;
    overflow: visible;
    transform: none;
  }

  .template-settings-form > label {
    grid-template-columns: 1fr;
  }

  .panel-resize-handle {
    display: none;
  }

  .badge-form .dynamic-fields,
  .badge-form .field-row-image {
    grid-template-columns: 1fr;
  }

  .login-panel {
    padding: 28px;
  }

  .inspector {
    position: static;
  }

  .data-table {
    display: block;
    overflow-x: auto;
  }
}
