* {
  box-sizing: border-box;
}

:root {
  --bg: #0b1220;
  --surface: #f3f7fc;
  --surface-muted: #e8f0f9;
  --surface-accent: #dfeafa;
  --border: #c5d3e4;
  --border-strong: #98acc4;
  --text: #152033;
  --text-muted: #607086;
  --primary: #1769e8;
  --primary-hover: #1256c0;
  --primary-soft: #dceaff;
  --secondary: #d7e4f4;
  --secondary-hover: #c5d7ec;
  --danger: #c43d32;
  --danger-hover: #a93128;
  --shadow: 0 16px 38px rgba(4, 13, 29, 0.18);
}

@font-face {
  font-family: "Noto Sans SC";
  src: url("/fonts/NotoSansSC-Regular.otf") format("opentype");
  font-weight: 400;
}

@font-face {
  font-family: "Noto Sans SC";
  src: url("/fonts/NotoSansSC-Bold.otf") format("opentype");
  font-weight: 700;
}

@font-face {
  font-family: "Noto Serif SC";
  src: url("/fonts/NotoSerifSC-Regular.otf") format("opentype");
  font-weight: 400;
}

@font-face {
  font-family: "Noto Serif SC";
  src: url("/fonts/NotoSerifSC-Bold.otf") format("opentype");
  font-weight: 700;
}

@font-face {
  font-family: "ZCOOL XiaoWei";
  src: url("/fonts/ZCOOLXiaoWei-Regular.ttf") format("truetype");
}

@font-face {
  font-family: "ZCOOL QingKe HuangYou";
  src: url("/fonts/ZCOOLQingKeHuangYou-Regular.ttf") format("truetype");
}

@font-face {
  font-family: "ZCOOL KuaiLe";
  src: url("/fonts/ZCOOLKuaiLe-Regular.ttf") format("truetype");
}

@font-face {
  font-family: "Ma Shan Zheng";
  src: url("/fonts/MaShanZheng-Regular.ttf") format("truetype");
}

@font-face {
  font-family: "Long Cang";
  src: url("/fonts/LongCang-Regular.ttf") format("truetype");
}

@font-face {
  font-family: "Liu Jian Mao Cao";
  src: url("/fonts/LiuJianMaoCao-Regular.ttf") format("truetype");
}

@font-face {
  font-family: "Zhi Mang Xing";
  src: url("/fonts/ZhiMangXing-Regular.ttf") format("truetype");
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(38, 108, 229, 0.28), transparent 30%),
    linear-gradient(135deg, #07111f 0%, #0b1728 46%, #12233a 100%);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid transparent;
  border-radius: 5px;
  background: linear-gradient(180deg, #2477f0, #1760d0);
  color: #fff;
  cursor: pointer;
  padding: 10px 14px;
}

button:hover {
  background: linear-gradient(180deg, #1f69d9, #1256c0);
}

button.secondary {
  background: linear-gradient(180deg, #dbe8f7, #c9d9ed);
  border-color: var(--border-strong);
  color: #173154;
}

button.secondary:hover {
  background: linear-gradient(180deg, #cfdef2, #b9cce6);
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

button.danger:hover {
  background: var(--danger-hover);
}

.hidden {
  display: none !important;
}

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

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

.login-panel {
  display: grid;
  gap: 16px;
  max-width: 380px;
  padding: 28px;
  width: 100%;
}

.admin-view {
  min-height: 100vh;
  padding: 24px 28px 32px;
}

.topbar,
.toolbar,
.panel-title {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.topbar {
  align-items: stretch;
  background: linear-gradient(135deg, rgba(13, 32, 58, 0.96), rgba(19, 52, 91, 0.92));
  border: 1px solid rgba(129, 171, 226, 0.28);
  border-radius: 10px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.2);
  color: #f5f9ff;
  padding: 18px 20px;
}

.dashboard-strip {
  display: grid;
  flex: 1;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  margin-left: auto;
  max-width: 760px;
}

.dashboard-card {
  background: rgba(226, 238, 255, 0.1);
  border: 1px solid rgba(156, 190, 236, 0.28);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  min-height: 58px;
  padding: 9px 12px;
}

.dashboard-card span {
  color: #aebfd6;
  font-size: 12px;
}

.dashboard-card strong {
  color: #ffffff;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

.topbar h1,
.login-panel h1,
.panel h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 24px;
  letter-spacing: 0;
}

.topbar p {
  color: #b7c8df;
  margin: 6px 0 0;
}

.toolbar {
  justify-content: flex-start;
  margin: 22px 0;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.tab {
  background: rgba(216, 229, 246, 0.16);
  border-color: rgba(148, 176, 213, 0.34);
  color: #d7e6f8;
}

.tab.active {
  background: linear-gradient(180deg, #2477f0, #1760d0);
  border-color: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.toolbar input,
.toolbar select {
  max-width: 220px;
}

.content-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
}

.template-hub-grid {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  margin-top: 18px;
}

.template-kind-column {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.template-list-toolbar {
  align-items: center;
  flex-wrap: wrap;
  margin: 0 0 12px;
}

.template-list-toolbar input,
.template-list-toolbar select {
  flex: 1 1 150px;
  max-width: none;
  min-width: 120px;
}

.template-hub-grid .table-wrap {
  max-height: 520px;
}

form.panel {
  display: grid;
  gap: 14px;
  padding: 20px;
}

label {
  color: #2f4058;
  display: grid;
  gap: 6px;
}

input,
select,
textarea {
  background: #fbfdff;
  border: 1px solid var(--border);
  border-radius: 5px;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 84, 214, 0.12);
  outline: none;
}

textarea {
  resize: vertical;
}

.upload-info,
.message {
  color: #506176;
  margin: 0;
}

.message.success {
  background: #ecfdf3;
  border: 1px solid #abefc6;
  border-radius: 6px;
  color: #067647;
  padding: 8px 10px;
}

.message.error {
  background: #fef3f2;
  border: 1px solid #fecdca;
  border-radius: 6px;
  color: #b42318;
  padding: 8px 10px;
}

.inline-save-message {
  display: inline-block;
  margin-left: 8px;
  vertical-align: middle;
}

.error {
  color: #c9372c;
  margin: 0;
}

.table-panel {
  padding: 20px;
}

.panel-actions {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.table-wrap {
  max-height: 620px;
  overflow-x: auto;
  overflow-y: auto;
}

table {
  border-collapse: collapse;
  margin-top: 14px;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 11px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #dce7f4;
  color: #41516a;
  font-size: 13px;
  font-weight: 700;
}

.status {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  padding: 3px 8px;
}

.status-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.status-summary button {
  background: linear-gradient(180deg, #dbe8f7, #c9d9ed);
  border: 1px solid #91a9c5;
  color: #173154;
  min-height: 30px;
  padding: 5px 10px;
}

.status-summary button.active {
  background: linear-gradient(180deg, #2477f0, #1760d0);
  border-color: #1760d0;
  color: #fff;
}

.status.enabled {
  background: #e3fcef;
  color: #216e4e;
}

.status.disabled {
  background: #f1f3f5;
  color: #596773;
}

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

.actions button {
  padding: 7px 10px;
}

#templateCategoryRows .actions {
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.category-template-picker {
  align-items: center;
  display: grid;
  inset: 0;
  padding: 24px;
  position: fixed;
  z-index: 1000;
}

.category-template-picker-backdrop {
  background: rgba(15, 23, 42, 0.38);
  inset: 0;
  position: absolute;
}

.category-template-picker-panel {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, 0.24);
  display: grid;
  gap: 12px;
  margin: auto;
  max-height: min(680px, calc(100vh - 48px));
  overflow: hidden;
  padding: 14px;
  position: relative;
  width: min(680px, 100%);
  z-index: 1;
}

.category-template-picker-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
}

.category-template-picker-item {
  align-items: center;
  background: var(--surface-accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  display: grid;
  gap: 6px;
  grid-template-columns: 52px minmax(0, 1fr);
  justify-items: start;
  padding: 9px 10px;
  text-align: left;
}

.category-template-picker-item:hover {
  background: #dfeafa;
}

.recharge-button-list {
  display: grid;
  gap: 6px;
}

.recharge-button-row {
  align-items: end;
  background: #e9f1fb;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: grid;
  gap: 6px;
  grid-template-columns: auto minmax(76px, 0.8fr) minmax(130px, 1.4fr) 58px 58px auto;
  padding: 8px;
}

.recharge-button-row label {
  margin: 0;
}

.recharge-custom-button-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(160px, 1fr) 70px 70px;
}

.profile-personal-editor {
  align-items: end;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  grid-template-columns: minmax(260px, 1fr) auto;
  padding-top: 10px;
}

.profile-personal-editor .subsection-title,
.profile-personal-editor .recharge-button-list {
  grid-column: 1 / -1;
}

.profile-personal-editor .subsection-title {
  margin: 0;
}

.profile-personal-editor .button-row {
  align-items: end;
  justify-content: flex-start;
}

.profile-personal-editor .check {
  grid-column: 1 / 2;
}

.profile-personal-editor .recharge-custom-button-grid {
  grid-column: 2 / 3;
  min-width: 320px;
}

.profile-recharge-tools {
  align-items: end;
  background: var(--surface-accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  grid-template-columns: minmax(280px, 1fr) auto;
  padding: 8px;
}

.profile-recharge-tools label {
  margin: 0;
}

.profile-recharge-tools .button-row {
  justify-content: flex-start;
  margin: 0;
}

.editor-shell {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  margin-top: 18px;
}

.editor-main {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr);
}

.canvas-panel {
  min-width: 0;
  padding: 14px;
}

.editor-toolbar {
  align-items: stretch;
  background: linear-gradient(135deg, #e5eef9, #dce8f5);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
}

.editor-toolbar-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.editor-toolbar button,
.property-panel button,
.object-sidebar button,
.pdf-editor-main button,
.pdf-property-panel button {
  background: linear-gradient(180deg, #dbe8f7, #c9d9ed);
  border: 1px solid #91a9c5;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  color: #173154;
}

.editor-toolbar button:hover,
.property-panel button:hover,
.object-sidebar button:hover,
.pdf-editor-main button:hover,
.pdf-property-panel button:hover {
  background: linear-gradient(180deg, #cfdef2, #b9cce6);
}

.editor-toolbar button.primary,
.pdf-editor-main button.primary,
.property-panel button.primary,
.pdf-property-panel button.primary {
  background: linear-gradient(180deg, #2477f0, #1760d0);
  border-color: #1760d0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
  color: #fff;
}

.editor-toolbar button.danger,
.property-panel button.danger,
.object-sidebar button.danger,
.pdf-editor-main button.danger,
.pdf-property-panel button.danger {
  background: linear-gradient(180deg, #d04a3f, #b7352c);
  border-color: #b7352c;
  color: #fff;
}

.editor-toolbar select {
  max-width: 260px;
}

.inline-control {
  align-items: center;
  display: flex;
  gap: 8px;
}

.inline-control input {
  width: 140px;
}

.editor-toolbar .inline-control input {
  width: 180px;
}

.editor-toolbar .inline-control input[type="range"] {
  width: 120px;
}

.editor-toolbar .inline-control input[type="color"] {
  height: 28px;
  padding: 0;
  width: 42px;
}

.editor-tool-actions {
  background: rgba(219, 232, 247, 0.62);
  border: 1px solid rgba(145, 169, 197, 0.55);
  border-radius: 6px;
  padding: 8px;
}

.editor-tool-actions .compact-select {
  color: #2f4058;
  font-size: 13px;
}

.editor-tool-actions .compact-select select {
  min-height: 34px;
  width: 132px;
}

.hint {
  color: #64748b;
  font-size: 13px;
}

.muted {
  color: #64748b;
}

.canvas-scroller {
  background: #111827;
  border-radius: 6px;
  height: 96vh;
  max-height: 1100px;
  min-height: 720px;
  overflow: auto;
  padding: 24px;
}

.canvas-stage {
  background: #fff;
  position: relative;
}

#templateImage,
#backgroundTintLayer,
#overlayLayer,
#screenCaptureLayer {
  left: 0;
  position: absolute;
  top: 0;
}

#overlayLayer {
  height: 100%;
  z-index: 2;
  width: 100%;
}

#templateImage {
  z-index: 0;
}

#backgroundTintLayer {
  background-color: transparent;
  mix-blend-mode: normal;
  height: 100%;
  pointer-events: none;
  width: 100%;
  z-index: 1;
}

#screenCaptureLayer {
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.32) 0 1px, rgba(0,0,0,0.18) 2px 3px, transparent 4px 6px),
    repeating-linear-gradient(90deg, rgba(255,0,0,0.12) 0 1px, rgba(0,255,255,0.10) 1px 2px, transparent 2px 4px),
    radial-gradient(ellipse at 32% 24%, rgba(255,255,255,0.22), transparent 42%),
    repeating-radial-gradient(ellipse at 58% 46%, rgba(80,120,255,0.14) 0 1px, transparent 2px 9px);
  background-size: 100% 6px, 4px 100%, 100% 100%, 140px 88px;
  height: 100%;
  mix-blend-mode: overlay;
  opacity: 0;
  pointer-events: none;
  width: 100%;
  z-index: 30;
}

.overlay-box {
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid #1f6feb;
  cursor: move;
  min-height: 18px;
  overflow: visible;
  padding: 0;
  position: absolute;
  transform-origin: center center;
  touch-action: none;
  user-select: none;
}

.inline-value {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: inherit;
  height: 100%;
  line-height: inherit;
  overflow: hidden;
  padding: 4px;
  pointer-events: auto;
  white-space: pre-wrap;
  word-break: break-word;
  width: 100%;
  position: relative;
  z-index: 1;
}

.watermark-value {
  align-items: stretch;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  max-height: 100%;
  max-width: 100%;
  overflow: hidden;
}

.watermark-value > div {
  display: block;
  line-height: 1.2;
  max-width: 100%;
  min-height: 1em;
  overflow: hidden;
  text-overflow: clip;
  white-space: pre;
  width: 100%;
}

.qr-preview {
  align-items: center;
  background: #fff;
  color: #111;
  justify-content: center;
  padding: 4px;
  text-align: center;
}

.qr-preview .qr-pattern {
  aspect-ratio: 1 / 1;
  background:
    conic-gradient(from 90deg, #111 25%, transparent 0 50%, #111 0 75%, transparent 0) 0 0 / 16px 16px,
    linear-gradient(#111 0 0) 8% 8% / 22% 22% no-repeat,
    linear-gradient(#111 0 0) 92% 8% / 22% 22% no-repeat,
    linear-gradient(#111 0 0) 8% 92% / 22% 22% no-repeat;
  border: 6px solid #fff;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18);
  max-height: 100%;
  width: min(100%, 180px);
}

.inline-value::after {
  content: "";
  display: block;
  height: 0;
  overflow: hidden;
}

.overlay-box.dragging .inline-value,
.move-handle,
.resize-handle,
.rotate-handle {
  user-select: none;
}

.inline-value:focus {
  background: rgba(255, 255, 255, 0.22);
  outline: none;
}

.overlay-box.selected {
  border-color: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25);
}

.watermark-box {
  border-color: #8b5cf6;
  background: rgba(139, 92, 246, 0.08);
}

.watermark-box.tiled-clone {
  border-style: dashed;
  overflow: visible;
  pointer-events: none;
}

.watermark-box.tiled-clone .watermark-value {
  overflow: visible;
}

.tile-area-box {
  background: rgba(139, 92, 246, 0.05);
  border: 2px dashed rgba(139, 92, 246, 0.85);
  box-sizing: border-box;
  cursor: move;
  min-height: 18px;
  min-width: 18px;
  overflow: visible;
  position: absolute;
  touch-action: none;
  user-select: none;
  z-index: 12;
}

.tile-area-box.active {
  background: rgba(139, 92, 246, 0.08);
}

.tile-area-label {
  background: rgba(139, 92, 246, 0.92);
  border-radius: 4px;
  color: #fff;
  font-size: 12px;
  left: 4px;
  line-height: 1;
  padding: 3px 5px;
  position: absolute;
  top: 4px;
  white-space: nowrap;
}

.object-label {
  background: rgba(31, 111, 235, 0.92);
  border-radius: 4px;
  color: #fff;
  display: inline-block;
  font-size: 12px;
  line-height: 1;
  margin-bottom: 3px;
  padding: 3px 5px;
}

.resize-handle {
  background: #f59e0b;
  border: 1px solid #fff;
  border-radius: 3px;
  bottom: -6px;
  cursor: nwse-resize;
  height: 14px;
  position: absolute;
  right: -6px;
  touch-action: none;
  width: 14px;
  z-index: 10;
}

.move-handle {
  background: rgba(31, 111, 235, 0.9);
  border-radius: 4px;
  cursor: move;
  height: 20px;
  left: 4px;
  position: absolute;
  top: 4px;
  touch-action: none;
  width: 20px;
  z-index: 3;
}

.rotate-handle {
  background: #22c55e;
  border-radius: 999px;
  cursor: grab;
  height: 14px;
  position: absolute;
  right: 18px;
  top: -8px;
  width: 14px;
  z-index: 3;
}

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

.style-copy-row {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.style-copy-row button {
  font-size: 12px;
  min-height: 28px;
  padding: 5px 8px;
}

.editor-actions,
.pager {
  align-items: center;
  display: flex;
  gap: 10px;
}

.editor-actions button {
  flex: 1;
  font-size: 12px;
  min-height: 28px;
  padding: 5px 8px;
}

.watermark-line-editor {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 10px;
}

.watermark-line-editor h4 {
  color: #2f4058;
  font-size: 14px;
  grid-column: 1 / -1;
  margin: 0;
}

.stamp-row-editor {
  align-items: end;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 8px;
}

.stamp-row-editor .button-row {
  align-self: end;
  gap: 4px;
}

.stamp-row-editor .button-row button {
  min-width: 30px;
  padding: 6px 0;
}

.stamp-preview-svg {
  display: block;
  height: 100%;
  width: 100%;
}

.pager {
  border-top: 1px solid var(--border);
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 12px;
}

.pager span {
  color: var(--text-muted);
  min-width: 180px;
  text-align: center;
}

.button-row button {
  background: linear-gradient(180deg, #dbe8f7, #c9d9ed);
  border: 1px solid #91a9c5;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  color: #173154;
  min-width: 38px;
  padding: 8px;
}

.button-row button:hover {
  background: linear-gradient(180deg, #cfdef2, #b9cce6);
}

.button-row button.active {
  background: linear-gradient(180deg, #2477f0, #1760d0);
  border-color: #1760d0;
  color: #fff;
}

.property-panel {
  align-self: start;
  position: relative;
  padding: 18px;
  position: sticky;
  top: 12px;
}

.property-panel h2 {
  margin-bottom: 12px;
}

.stack {
  display: grid;
  gap: 10px;
}

.property-panel .stack {
  align-items: end;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
}

.property-panel .stack .hint,
.property-panel .stack .editor-actions {
  grid-column: 1 / -1;
}

.property-panel .stack label {
  font-size: 12px;
  gap: 4px;
}

.property-panel .stack input,
.property-panel .stack select,
.property-panel .stack textarea {
  font-size: 12px;
  min-height: 30px;
  padding: 5px 7px;
}

.property-panel .stack textarea {
  min-height: 58px;
}

.property-panel .stack label:has(textarea) {
  grid-column: span 2;
}

.property-panel .stack .watermark-line-editor {
  align-self: stretch;
  grid-column: span 2;
}

.image-watermark-editor {
  align-items: end;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  padding: 8px;
}

.image-watermark-editor .hint {
  grid-column: 1 / -1;
  margin: 0;
}

.image-watermark-editor .check {
  align-self: center;
  min-height: 30px;
}

.image-watermark-editor button {
  min-height: 30px;
  padding: 5px 8px;
}

.check {
  align-items: center;
  display: flex;
  gap: 8px;
}

.check input {
  min-height: auto;
  width: auto;
}

.object-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  max-height: 220px;
  overflow: auto;
}

.list-item {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: #1f2933;
  display: flex;
  justify-content: space-between;
  text-align: left;
}

.list-row {
  align-items: stretch;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.list-row .list-item {
  width: 100%;
}

.list-delete {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.list-item.active {
  border-color: #1f6feb;
}

.object-sidebar {
  align-self: start;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 16px;
}

.object-sidebar details {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}

.object-sidebar summary {
  color: #2f4058;
  cursor: pointer;
  font-weight: 700;
}

.preview-image {
  border: 1px solid var(--border);
  max-width: 100%;
}

.bot-config-panel {
  display: grid;
  gap: 18px;
  margin-top: 18px;
  padding: 20px;
}

.font-panel {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  padding: 20px;
}

.resource-pane:not(.hidden) {
  box-sizing: border-box;
  display: inline-block;
  vertical-align: top;
  width: calc(50% - 8px);
}

.resource-pane:not(.hidden) + .resource-pane:not(.hidden) {
  margin-left: 12px;
}

.resource-pane .table-wrap {
  max-height: none;
  overflow: visible;
}

.resource-pane > .panel {
  box-sizing: border-box;
  display: block;
  height: auto;
  margin-top: 0;
  min-height: 0;
}

.resource-pane .panel-title {
  flex: 0 0 auto;
  min-height: 38px;
}

.resource-pane .font-upload-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.resource-pane .font-upload-form button {
  min-height: 34px;
}

.bot-settings-pane:not(.hidden) {
  display: block;
}

.bot-settings-pane:not(.hidden) + .bot-settings-pane:not(.hidden) {
  margin-top: 16px;
}

.font-upload-form {
  align-items: end;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(180px, 1.2fr) minmax(150px, 1fr) minmax(150px, 1fr) minmax(180px, 1.1fr) minmax(150px, 1fr) auto;
  padding: 10px;
}

.font-upload-form label {
  min-width: 0;
}

.font-upload-form input {
  width: 100%;
}

.font-upload-form button {
  min-height: 38px;
  white-space: nowrap;
}

.font-preview {
  font-size: 22px;
  white-space: nowrap;
}

.usage-tag {
  background: #eef4ff;
  border: 1px solid #c7d7fe;
  border-radius: 999px;
  color: #1d4ed8;
  display: inline-block;
  font-size: 12px;
  margin: 0 4px 4px 0;
  padding: 2px 7px;
}

.font-usage-compact {
  color: #344054;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.dynamic-var-tools {
  align-items: center;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  grid-column: 1 / -1;
  padding: 8px;
}

.dynamic-var-tools span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.dynamic-var-tools button {
  font-size: 12px;
  min-height: 28px;
  padding: 4px 8px;
}

.settings-grid {
  display: grid;
  align-items: start;
  gap: 10px;
  grid-template-columns: 1fr;
}

#systemSettingsForm fieldset {
  align-content: start;
  background: rgba(248, 251, 255, 0.72);
  gap: 8px 12px;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  padding: 10px 12px;
}

#systemSettingsForm legend {
  font-size: 13px;
  padding: 0 4px;
}

#systemSettingsForm label {
  color: #334155;
  font-size: 12px;
  gap: 4px;
  min-width: 0;
}

#systemSettingsForm input,
#systemSettingsForm select {
  font-size: 12px;
  min-height: 30px;
  padding: 5px 8px;
}

#systemSettingsForm input[type="checkbox"] {
  min-height: auto;
  width: auto;
}

#systemSettingsForm label.check {
  align-items: center;
  display: flex;
  gap: 6px;
  min-height: 30px;
}

#systemSettingsForm .hint,
#systemSettingsForm .message,
#systemSettingsForm .button-row,
#systemSettingsForm [data-ai-enhance-advanced] {
  grid-column: 1 / -1;
}

#systemSettingsForm .hint {
  font-size: 12px;
  line-height: 1.45;
}

#systemSettingsForm .message {
  font-size: 12px;
  padding: 6px 8px;
}

#systemSettingsForm > fieldset > button,
#systemSettingsForm .button-row button {
  font-size: 12px;
  min-height: 30px;
  padding: 5px 10px;
}

#systemSettingsForm > fieldset > button {
  justify-self: start;
}

#systemSettingsForm .button-row {
  flex-wrap: wrap;
  gap: 6px;
}

#systemSettingsForm .enhance-advanced-grid {
  gap: 8px 12px;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.monitor-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 16px;
}

.monitor-card {
  background: #0f1b2d;
  border: 1px solid #31537d;
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(3, 10, 24, 0.24);
  display: grid;
  gap: 10px;
  min-height: 96px;
  padding: 16px;
  position: relative;
}

.monitor-card::before {
  background: #64748b;
  border-radius: 999px;
  content: "";
  height: 9px;
  position: absolute;
  right: 14px;
  top: 14px;
  width: 9px;
}

.monitor-card.ok::before {
  background: #22c55e;
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.75);
}

.monitor-card.warn::before {
  background: #f59e0b;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.75);
}

.monitor-card.bad::before {
  background: #ef4444;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.75);
}

.monitor-card.idle::before {
  background: #94a3b8;
}

.monitor-card span {
  color: #b8c7dc;
  font-size: 13px;
  font-weight: 600;
}

.monitor-card strong {
  color: #ffffff;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.25;
}

.monitor-failed-list {
  display: grid;
  gap: 10px;
}

.monitor-failed-list h3 {
  color: #f8fafc;
  font-size: 16px;
  margin: 0;
}

.monitor-failed-item {
  align-items: center;
  background: #0f1b2d;
  border: 1px solid #7f1d1d;
  border-radius: 8px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.monitor-failed-item div {
  display: grid;
  gap: 4px;
}

.monitor-failed-item strong {
  color: #ffffff;
}

.monitor-failed-item span {
  color: #fecaca;
  font-size: 13px;
}

.enhance-advanced-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.bot-config-layout {
  align-items: start;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 3fr) minmax(280px, 1fr);
}

.bot-grid-config,
.bot-config-side {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.bot-grid-config > .panel-title,
.bot-menu-preview-wrap h3 {
  min-height: 32px;
}

.bot-config-side {
  align-content: start;
}

.bot-config-side fieldset,
.bot-menu-preview-wrap {
  padding: 12px;
}

.bot-config-side textarea {
  min-height: 72px;
}

.bot-broadcast-compact form {
  display: grid;
  gap: 8px;
}

.bot-broadcast-compact textarea {
  min-height: 108px;
}

.bot-broadcast-compact .compact-toolbar {
  align-items: center;
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr auto auto;
}

.bot-broadcast-compact input[type="file"] {
  min-width: 0;
  width: 100%;
}

.bot-broadcast-compact button {
  width: 100%;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 16px;
}

legend {
  color: #2f4058;
  font-weight: 700;
  padding: 0 6px;
}

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

.custom-button-list,
.bot-menu-list {
  display: grid;
  gap: 10px;
}

.bot-menu-editor {
  align-items: start;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(260px, 320px) minmax(420px, 1fr);
}

.bot-menu-list {
  overflow: visible;
}

.custom-button-row {
  align-items: end;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: 90px 150px minmax(220px, 1fr) 160px minmax(180px, 1fr);
  padding: 12px;
}

.bot-menu-row {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: #1f2933;
  display: grid;
  gap: 4px;
  justify-items: start;
  padding: 10px 12px;
  text-align: left;
}

.bot-menu-row.active {
  border-color: #1f6feb;
  box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.14);
}

.bot-menu-row small {
  color: #64748b;
}

.bot-button-editor,
.bot-menu-preview-wrap {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.bot-button-editor h3,
.bot-menu-preview-wrap h3 {
  margin: 0;
}

.bot-button-editor-form {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.bot-button-editor-form label:has(textarea),
.bot-button-editor-form .wide,
.bot-button-editor-form label:has(#botButtonLinkUrl),
.bot-button-editor-form .check,
.bot-sub-buttons {
  grid-column: 1 / -1;
}

.bot-main-description textarea,
.bot-sub-modal-form textarea {
  min-height: 220px;
  resize: vertical;
}

.bot-sub-buttons {
  border-top: 1px solid var(--border);
  display: grid;
  gap: 10px;
  padding-top: 10px;
}

.subsection-title {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.bot-sub-button-row {
  align-items: center;
  background: var(--surface-accent);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 12px;
}

.bot-sub-summary {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.bot-sub-summary small {
  color: #64748b;
}

.bot-sub-modal {
  align-items: center;
  display: grid;
  inset: 0;
  padding: 24px;
  position: fixed;
  z-index: 1000;
}

.bot-sub-modal-backdrop {
  background: rgba(15, 23, 42, 0.38);
  inset: 0;
  position: absolute;
}

.bot-sub-modal-panel {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, 0.24);
  display: grid;
  gap: 14px;
  margin: auto;
  max-height: min(860px, calc(100vh - 48px));
  max-width: 920px;
  overflow: auto;
  padding: 18px;
  position: relative;
  width: min(920px, 100%);
}

.bot-sub-modal-form {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.bot-sub-modal-form .check,
.bot-sub-modal-form .wide {
  grid-column: 1 / -1;
}

.bot-menu-preview {
  background: #eef2f7;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 12px;
}

.bot-preview-row {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.bot-preview-row button {
  background: var(--secondary);
  border: 1px solid var(--border-strong);
  color: #173154;
  min-height: 38px;
  padding: 8px;
}

.bot-preview-row button:hover {
  background: var(--secondary-hover);
}

.compact-toolbar {
  margin: 0;
}

.user-actions {
  align-items: center;
  flex-wrap: wrap;
}

.user-actions .balance-delta {
  min-height: 32px;
  width: 100px;
}

.pdf-template-grid {
  align-items: start;
}

.pdf-editor-panel {
  margin-top: 16px;
}

.pdf-preview-frame {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 72vh;
  width: 100%;
}

.pdf-editor-shell {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
}

.pdf-object-lists {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0 0 12px;
  position: relative;
  z-index: 4;
}

.pdf-object-lists details {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.pdf-object-lists summary {
  cursor: pointer;
  font-weight: 700;
}

.pdf-canvas-scroller {
  background: #e5e7eb;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 78vh;
  overflow: auto;
  padding: 24px;
}

.pdf-canvas-stage {
  background: transparent;
  margin: 0 auto;
  position: relative;
}

.pdf-page-canvas,
.pdf-page-overlay {
  left: 0;
  position: absolute;
  top: 0;
}

.pdf-page {
  background: #fff;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  position: absolute;
}

.pdf-page-canvas {
  position: relative;
  z-index: 1;
}

.pdf-page-overlay {
  z-index: 2;
}

.pdf-object {
  border: 1px dashed rgba(37, 99, 235, 0.7);
  box-sizing: border-box;
  cursor: default;
  display: flex;
  flex-direction: column;
  overflow: visible;
  padding: 4px;
  position: absolute;
  transform-origin: center center;
  white-space: pre-wrap;
  word-break: break-word;
}

.pdf-object.selected {
  border: 2px solid #2563eb;
}

.pdf-watermark {
  border-color: rgba(209, 31, 31, 0.7);
}

.pdf-object.tiled-clone {
  border-style: dashed;
  pointer-events: none;
}

.pdf-inline-editor {
  cursor: text;
  flex: 0 0 auto;
  line-height: inherit;
  max-height: 100%;
  min-height: 0;
  outline: none;
  overflow: hidden;
  width: 100%;
}

.pdf-single .pdf-inline-editor {
  white-space: pre;
}

.pdf-stamp-preview {
  align-items: center;
  box-sizing: border-box;
  display: flex;
  height: 100%;
  justify-content: center;
  line-height: 0;
  overflow: hidden;
  pointer-events: none;
  width: 100%;
}

.pdf-stamp {
  padding: 0;
}

.pdf-stamp-preview .stamp-preview-svg {
  display: block;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  width: 100%;
}

.pdf-object-name {
  background: rgba(37, 99, 235, 0.8);
  border-radius: 3px;
  color: #fff;
  font-size: 10px;
  left: 3px;
  line-height: 1;
  padding: 2px 4px;
  pointer-events: none;
  position: absolute;
  top: 3px;
  z-index: 6;
}

.pdf-watermark .pdf-object-name {
  background: rgba(209, 31, 31, 0.8);
}

.pdf-object .move-handle {
  background: rgba(37, 99, 235, 0.9);
  border-radius: 4px;
  cursor: move;
  height: 18px;
  left: 4px;
  position: absolute;
  top: 4px;
  width: 18px;
  z-index: 5;
}

.pdf-object .rotate-handle {
  background: #22c55e;
  border: 1px solid #fff;
  border-radius: 999px;
  cursor: grab;
  height: 14px;
  position: absolute;
  right: 18px;
  top: -8px;
  width: 14px;
  z-index: 5;
}

.pdf-object .resize-handle {
  background: #2563eb;
  border: 1px solid #fff;
  bottom: -5px;
  cursor: nwse-resize;
  height: 10px;
  position: absolute;
  right: -5px;
  width: 10px;
  z-index: 5;
}

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

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

  .topbar {
    flex-wrap: wrap;
  }

  .dashboard-strip {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
    max-width: none;
    order: 3;
    width: 100%;
  }

  .editor-shell,
  .editor-main,
  .pdf-editor-shell,
  .pdf-object-lists,
  .settings-grid,
  .bot-config-layout,
  .resource-pane:not(.hidden),
  .font-upload-form,
  .bot-menu-editor,
  .bot-button-editor-form,
  .bot-sub-button-row,
  .custom-button-row,
  .bot-menu-row {
    grid-template-columns: 1fr;
  }

  .resource-pane:not(.hidden) {
    display: block;
    width: 100%;
  }

  .resource-pane > .panel {
    height: auto;
    min-height: 0;
  }

  #systemSettingsForm fieldset,
  #systemSettingsForm .enhance-advanced-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .resource-pane:not(.hidden) + .resource-pane:not(.hidden) {
    margin-left: 0;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar input,
  .toolbar select {
    max-width: none;
  }

  .property-panel .stack {
    grid-template-columns: 1fr;
  }

  .image-watermark-editor {
    grid-template-columns: 1fr;
  }

  .property-panel .stack label:has(textarea),
  .property-panel .stack .watermark-line-editor,
  .stamp-row-editor {
    grid-column: auto;
  }

  .stamp-row-editor {
    grid-template-columns: 1fr;
  }

  .editor-actions {
    position: static;
    width: auto;
  }
}
