:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #3d3a34;
  --muted: #7a756c;
  --line: #ddd6c8;
  --accent: #6b8f71;
  --accent-dark: #4f6f55;
  --danger: #b4543c;
  --shadow: 0 8px 24px rgba(60, 50, 30, 0.08);
  --radius: 12px;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.topbar .spacer { flex: 1; }
.topbar .muted { color: var(--muted); font-size: 13px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #f7f3eb; border-color: #cfc6b5; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: #e0b8ad; }
.btn.danger:hover { background: #fff1ed; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { display: block; text-align: center; margin: 8px 0 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 300px;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel h2, .panel h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.panel h2 {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--line);
}
.panel h3 { margin: 10px 0 6px; color: var(--ink); }
.panel h3.sub { padding: 12px 0 4px; border-top: 1px solid var(--line); margin-top: 12px; }

.left-panel { padding: 0; }

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tab.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-pane {
  display: none;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}
.tab-pane.active { display: flex; }

.pad { padding: 10px 12px 4px; flex-shrink: 0; }

.search {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
}
.search:focus { outline: 2px solid rgba(107, 143, 113, 0.35); border-color: var(--accent); }

.nav-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  margin: 8px 0;
}
.hint.tight { margin: 6px 0 4px; }

.quote-list {
  list-style: none;
  margin: 0;
  padding: 0 0 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.quote-list li {
  padding: 8px 12px;
  border-bottom: 1px solid #efe9dc;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.35;
}
.quote-list li:hover { background: #f7f3eb; }
.quote-list li.active {
  background: #e8f0e9;
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}
.quote-list .qid {
  font-variant-numeric: tabular-nums;
  color: var(--accent-dark);
  font-weight: 600;
  margin-right: 6px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}
.gallery.bases { grid-template-columns: 1fr; }
.thumb {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}
.thumb:hover, .thumb.active { border-color: var(--accent); background: #f3f8f3; }
.thumb img {
  max-width: 100%;
  max-height: 72px;
  object-fit: contain;
}
.gallery.bases .thumb img { max-height: 120px; }

#tab-mats {
  overflow-y: auto;
}

.canvas-wrap {
  align-items: center;
  justify-content: center;
  background: #ebe4d6;
  padding: 12px;
}

.canvas-stage {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#mainCanvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 100px);
  width: auto;
  height: auto;
  box-shadow: 0 12px 40px rgba(40, 30, 10, 0.18);
  background: #ddd;
  cursor: default;
  touch-action: none;
}

.side .body {
  padding: 10px 14px 16px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.side .body.scroll { overflow-y: auto; }

.ctrl-block { margin-bottom: 8px; }

.field {
  margin-bottom: 10px;
}
.field label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.field .val { color: var(--ink); font-variant-numeric: tabular-nums; }
.field input[type="range"] { width: 100%; }
.field input.text,
.field input[type="date"],
.field input[type="text"],
.field select,
.field textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
.field textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.45;
}
.field input[type="color"] {
  width: 100%;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.layer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
}
.layer-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 6px;
  cursor: pointer;
}
.layer-list li:hover { background: #f7f3eb; }
.layer-list li.active { background: #e8f0e9; }
.layer-list img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 240px minmax(0, 1fr) 260px;
  }
}

#tab-tpl {
  overflow-y: auto;
}

.tpl-opts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 6px 0 8px;
}

.tpl-opts .check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink);
}

.tpl-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
}

.tpl-list li {
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fff;
  font-size: 13px;
}

.tpl-list li.active {
  border-color: var(--accent);
  background: #f3f8f3;
}

.tpl-list .tpl-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.tpl-list .tpl-name {
  font-weight: 600;
  color: var(--ink);
}

.tpl-list .tpl-date {
  font-size: 11px;
  color: var(--muted);
}

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

#tab-batch {
  overflow-y: auto;
}

.quote-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.quote-list li .qcheck {
  margin-top: 2px;
  flex-shrink: 0;
}

.quote-list li .qbody {
  flex: 1;
  min-width: 0;
}

.tabs .tab {
  font-size: 11px;
  padding: 10px 2px;
}

.frame-list { list-style:none; margin:0 0 8px; padding:0; }
.frame-list li {
  display:flex; align-items:center; gap:6px; flex-wrap:wrap;
  padding:8px; border:1px solid var(--line); border-radius:8px;
  margin-bottom:6px; font-size:12px; background:#fff; cursor:pointer;
}
.frame-list li.active { border-color: var(--accent); background:#f3f8f3; }
.frame-list li.current { box-shadow: inset 3px 0 0 var(--accent); }
.batch-deco-pool {
  display:grid; grid-template-columns:1fr 1fr; gap:4px;
  max-height:160px; overflow-y:auto; margin-bottom:8px;
  font-size:12px;
}
.batch-deco-pool label {
  display:flex; align-items:center; gap:6px;
  padding:4px 6px; border:1px solid var(--line); border-radius:6px; background:#fff;
}

/* text box inspector */
#textBoxControls h3 { color: var(--ink); }
