:root {
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: #202b2b;
  background: #f3f6f5;
  font-size: 14px;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
body { min-width: 360px; margin: 0; }
button, input, textarea, select { color: inherit; font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  z-index: 3;
  top: 0;
  display: flex;
  height: 68px;
  align-items: center;
  gap: 42px;
  padding: 0 max(28px, calc((100vw - 1360px) / 2));
  border-bottom: 1px solid #e1e7e5;
  background: rgb(255 255 255 / 96%);
}
.brand { display: flex; align-items: center; gap: 11px; white-space: nowrap; }
.brand strong { font-size: 15px; font-weight: 650; }
.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 7px;
  background: #174d49;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.tabs { display: flex; height: 100%; gap: 26px; }
.nav-tab {
  position: relative;
  border: 0;
  background: transparent;
  color: #727d7b;
  font-size: 13px;
}
.nav-tab::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: transparent;
  content: "";
}
.nav-tab.active { color: #174d49; font-weight: 600; }
.nav-tab.active::after { background: #198377; }
.save-state { margin-left: auto; color: #798481; font-size: 12px; }

main { width: min(1320px, calc(100% - 64px)); margin: 0 auto; padding: 34px 0 64px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
h1, h2, p { margin: 0; }
h1 { font-size: 22px; font-weight: 650; line-height: 1.35; }
h2 { font-size: 17px; font-weight: 650; }
.section-heading p { margin-top: 6px; color: #78827f; font-size: 13px; }
.source-panel { padding: 0 0 25px; border-bottom: 1px solid #dce4e1; }
.source-row { display: grid; grid-template-columns: minmax(0, 1fr) 132px; align-items: center; gap: 12px; }
textarea, input:not([type="color"]), select {
  border: 1px solid #d2dbd8;
  border-radius: 5px;
  outline: 0;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
textarea { width: 100%; padding: 11px 12px; line-height: 1.55; }
textarea:focus, input:focus, select:focus { border-color: #388e83; box-shadow: 0 0 0 3px rgb(56 142 131 / 12%); }
.source-row textarea { min-height: 78px; resize: vertical; }
.button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid #d0d9d6;
  border-radius: 5px;
  background: #fff;
  color: #35413f;
  font-size: 12px;
  font-weight: 550;
  transition: background .15s, border-color .15s, transform .15s;
}
.button:hover { transform: translateY(-1px); border-color: #aabbb6; background: #f8faf9; }
.button.primary { border-color: #176e65; background: #176e65; color: #fff; }
.button.primary:hover { border-color: #125c55; background: #125c55; }
.button:disabled { transform: none; opacity: .42; cursor: default; }
.muted { color: #858f8c; font-size: 12px; }
.param-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.param { display: flex; max-width: 100%; gap: 8px; padding: 6px 9px; border: 1px solid #deebe7; border-radius: 4px; background: #edf5f2; font-size: 11px; }
.param b { color: #176e65; font-weight: 650; }
.param span { overflow-wrap: anywhere; }

.template-section { padding-top: 25px; }
.template-section > .section-heading { margin-bottom: 17px; }
.template-heading-actions { display: flex; align-items: end; gap: 9px; }
.template-picker { display: flex; min-width: 210px; flex-direction: column; gap: 5px; color: #68746f; font-size: 10px; font-weight: 600; }
.template-picker select { width: 100%; height: 36px; padding: 0 30px 0 10px; border-color: #d2dbd8; background: #fff; font-size: 12px; }
.template-list { display: grid; gap: 12px; }
.template-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 252px;
  gap: 27px;
  padding: 20px;
  border: 1px solid #dfe6e3;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 7px rgb(28 55 49 / 3%);
}
.template-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, 1fr); align-content: start; gap: 14px 16px; }
.field-label { display: flex; min-width: 0; flex-direction: column; gap: 7px; color: #66726e; font-size: 11px; font-weight: 600; }
.field-label input:not([type="color"]), .field-label textarea { width: 100%; padding: 9px 10px; color: #283330; font-size: 12px; font-weight: 400; }
.field-label textarea { min-height: 66px; resize: vertical; }
.url-label { grid-column: 1 / -1; grid-row: 2; }
.url-label textarea { min-height: 88px; font-family: ui-monospace, Consolas, monospace; font-size: 11px; line-height: 1.5; }
.color-control { display: flex; height: 36px; align-items: center; gap: 10px; }
.color-control input { width: 36px; height: 32px; padding: 2px; border: 1px solid #d2dbd8; border-radius: 5px; background: #fff; cursor: pointer; }
.color-control code { color: #53605c; font-size: 12px; font-weight: 500; }
.template-actions { display: flex; min-width: 0; flex-direction: column; align-items: center; gap: 10px; }
.qr-preview { display: grid; width: 100%; min-height: 180px; max-height: 250px; overflow: auto; place-items: center; padding: 9px; border: 1px solid #edf0ef; border-radius: 6px; background: #fafcfb; }
.qr-preview canvas { display: block; width: 100%; height: auto; }
.action-stack { display: flex; width: 100%; flex-wrap: wrap; justify-content: center; gap: 6px; }
.action-stack .button { min-height: 31px; padding: 0 9px; font-size: 11px; }
.icon-button { min-height: 31px; padding: 0 9px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: #a44d43; font-size: 11px; }
.icon-button:hover { border-color: #f0ddda; background: #fff8f6; }
.error { padding: 10px; color: #b42318; font-size: 12px; }

.heading-actions { display: flex; gap: 8px; }
.file-button { display: inline-flex; align-items: center; }
.json-input { min-height: 150px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.data-controls { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.data-controls > label { display: flex; flex-direction: column; gap: 5px; color: #707b77; font-size: 11px; }
.data-controls input, .data-controls select { width: auto; min-width: 145px; height: 36px; padding: 6px 9px; font-size: 12px; }
.data-controls label:first-of-type select { min-width: 96px; }
.data-controls label:last-of-type input { min-width: 175px; }
.table-wrap { overflow: auto; border: 1px solid #e0e6e3; border-radius: 7px; background: #fff; }
table { width: 100%; border-collapse: collapse; text-align: left; white-space: nowrap; }
th, td { padding: 11px 13px; border-bottom: 1px solid #edf0ef; font-size: 12px; }
th { background: #f7f9f8; color: #626e6a; font-size: 11px; font-weight: 650; }
tbody tr:hover { background: #f6faf8; }
.empty-row { padding: 38px; color: #89928f; text-align: center; }
.table-footer { display: flex; align-items: center; justify-content: space-between; padding: 13px 1px; }
.pagination { display: flex; align-items: center; gap: 10px; color: #56615d; font-size: 12px; }
.pagination .button { min-height: 31px; padding: 0 10px; }
.pagination select { height: 31px; border: 1px solid #d2dbd8; border-radius: 5px; background: #fff; }
.toast { position: fixed; z-index: 5; bottom: 24px; left: 50%; transform: translate(-50%, 12px); padding: 10px 16px; border-radius: 5px; background: #24312e; color: #fff; opacity: 0; pointer-events: none; transition: opacity .16s, transform .16s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 820px) {
  .topbar { gap: 25px; padding: 0 22px; }
  main { width: calc(100% - 44px); }
  .template-row { grid-template-columns: minmax(0, 1fr) 215px; gap: 18px; padding: 16px; }
  .qr-preview { min-height: 160px; }
}
@media (max-width: 620px) {
  body { min-width: 360px; }
  .topbar { height: auto; min-height: 60px; flex-wrap: wrap; gap: 0 15px; padding: 0 14px; }
  .brand { height: 56px; }
  .brand strong { font-size: 13px; }
  .tabs { order: 3; width: 100%; height: 42px; gap: 15px; }
  .nav-tab { flex: 1; font-size: 12px; }
  .save-state { font-size: 10px; }
  main { width: calc(100% - 28px); padding: 24px 0 44px; }
  .section-heading { align-items: flex-start; gap: 12px; }
  h1 { font-size: 19px; }
  h2 { font-size: 16px; }
  .section-heading p { max-width: 260px; font-size: 12px; }
  .template-section > .section-heading { align-items: flex-end; }
  .template-heading-actions { align-items: flex-end; flex-direction: column; gap: 7px; }
  .template-picker { min-width: 150px; }
  .template-picker select { height: 33px; }
  .source-row { grid-template-columns: 1fr; gap: 9px; }
  .source-row .button { justify-self: end; }
  .template-row { grid-template-columns: 1fr; gap: 14px; padding: 14px; }
  .template-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px 10px; }
  .url-label { grid-column: 1 / -1; grid-row: auto; }
  .url-label textarea { min-height: 86px; }
  .template-actions { display: grid; grid-template-columns: 118px minmax(0, 1fr); align-items: center; gap: 10px; }
  .qr-preview { width: 118px; min-height: 118px; max-height: 150px; padding: 6px; }
  .action-stack { justify-content: flex-start; }
  .action-stack .button, .icon-button { padding: 0 7px; font-size: 10px; }
  .heading-actions { flex-wrap: wrap; justify-content: flex-end; }
  .heading-actions .button { min-height: 32px; padding: 0 9px; font-size: 11px; }
  .data-controls { align-items: stretch; gap: 8px; }
  .data-controls label { min-width: calc(50% - 5px); flex: 1; }
  .data-controls input, .data-controls select, .data-controls label:last-of-type input { width: 100%; min-width: 0; }
  .data-controls > .button { flex: 1; }
  .table-footer { align-items: flex-start; flex-direction: column; gap: 10px; }
  .pagination { width: 100%; justify-content: space-between; gap: 6px; }
  .pagination .button { padding: 0 7px; }
}
