:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e2e6ec;
  --line-strong: #cbd2dc;
  --text: #1f2937;
  --muted: #6b7280;
  --faint: #9ca3af;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --blue-dark: #1d4ed8;
  --green: #059669;
  --green-soft: #d1fae5;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #b45309;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
  --radius: 8px;
  --topbar-h: 56px;
  --sidebar-w: 300px;
  --inspector-w: 320px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 13px;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 900px;
}

/* ---------- top bar ---------- */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(145deg, #3b82f6, #1d4ed8);
  color: #fff;
  font-size: 17px;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.28);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.draft-status {
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.draft-status[data-state="saved"] { color: var(--muted); }
.draft-status[data-state="unsaved"] { color: var(--amber); }
.draft-status[data-state="unavailable"] { color: var(--red); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.divider {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 4px;
}

.btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  padding: 6px 11px;
  border-radius: 6px;
  line-height: 1.3;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--panel-2); border-color: #adb7c5; }
.btn:active { background: #eef1f5; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-accent {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.btn-accent:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-sm { padding: 4px 8px; font-size: 12px; }

.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ---------- page tabs ---------- */
.page-tabs {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  overflow-y: auto;
  scrollbar-width: thin;
  flex: 1 1 auto;
  min-height: 0;
}

.page-tab {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  font-size: 13px;
}
.page-tab:hover { background: #eef1f5; color: var(--text); }
.page-tab.active {
  background: var(--blue-soft);
  border-color: #bfdbfe;
  color: var(--blue-dark);
  font-weight: 600;
}

/* ---------- main layout ---------- */
.main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  z-index: 2;
}

.sidebar-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--line);
}

.sidebar-tab {
  flex: 1;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 9px 6px 8px;
  border-radius: 5px 5px 0 0;
  font-size: 13px;
}
.sidebar-tab:hover { background: var(--panel-2); color: var(--text); }
.sidebar-tab.active {
  color: var(--blue-dark);
  font-weight: 600;
  border-bottom-color: var(--blue);
  background: #f8fbff;
}

.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  background: #fcfdff;
  flex: 0 0 auto;
}
.panel-toolbar .hint {
  margin: 0;
  font-size: 10px;
  line-height: 1.4;
}

.sidebar-panel {
  padding: 10px;
  overflow: auto;
  min-height: 0;
  flex: 1 1 auto;
}

.panel-empty {
  color: var(--faint);
  font-size: 12px;
  text-align: center;
  padding: 26px 10px;
  line-height: 1.7;
}

/* category list */
.category-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 9px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  margin-bottom: 6px;
  user-select: none;
  transition: border-color 0.12s, background 0.12s;
}
.category-row:hover { border-color: #b7c3d4; background: #fbfdff; }
.category-row.placed { border-left: 3px solid var(--green); }
.category-row.unplaced { border-left: 3px solid #cbd5e1; }
.category-row[draggable="true"] { cursor: grab; }
.category-row[draggable="true"]:active { cursor: grabbing; }

.category-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 13px;
}

.category-meta {
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  line-height: 1.5;
  white-space: nowrap;
}
.pill-green { background: var(--green-soft); color: #047857; }
.pill-gray { background: #f1f5f9; color: #64748b; }
.pill-blue { background: var(--blue-soft); color: var(--blue-dark); }

.row-actions {
  display: flex;
  gap: 2px;
}

/* layer list */
.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  margin-bottom: 6px;
  background: #fff;
  cursor: pointer;
  user-select: none;
}
.layer-row:hover { border-color: #b7c3d4; background: #fbfdff; }
.layer-row.selected { border-color: var(--blue); background: #eff6ff; box-shadow: 0 0 0 1px #bfdbfe inset; }
.layer-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  font-size: 12px;
}
.layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.layer-sub { color: var(--faint); font-size: 10px; }
.layer-bg-row { background: #fbfcfd; }
.layer-bg-image-row {
  margin-left: 18px;
  border-left: 2px solid #e2e8f0;
  background: #fff;
}
.layer-bg-image-row.selected { border-left-color: var(--blue); }
.layer-bg-add {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 5px;
  width: 22px;
  height: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.layer-bg-add:hover { border-color: #b7c3d4; color: var(--text); }

/* background library modal */
.bg-library-list { display: flex; flex-direction: column; gap: 8px; }
.bg-library-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}
.bg-library-row .input { flex: 1; min-width: 0; }
.bg-library-meta { color: var(--faint); font-size: 11px; white-space: nowrap; }

/* property inspector */
.inspector {
  width: var(--inspector-w);
  flex: 0 0 var(--inspector-w);
  min-height: 0;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  background: #fcfdff;
  z-index: 2;
}

.property-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  flex: 0 0 auto;
}

.selection-label {
  font-weight: 500;
  color: var(--blue-dark);
  background: var(--blue-soft);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.property-panel {
  padding: 10px 12px 18px;
  overflow: auto;
  min-height: 0;
  flex: 1 1 auto;
}

.prop-group {
  border-bottom: 1px dashed var(--line);
  padding-bottom: 9px;
  margin-bottom: 9px;
}
.prop-group:last-child { border-bottom: none; margin-bottom: 0; }

.prop-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  margin: 2px 0 8px;
  letter-spacing: 0.03em;
}

.field {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
}
.field > label {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}
.field .control { min-width: 0; display: flex; align-items: center; gap: 5px; }
.field .control .unit { color: var(--faint); font-size: 10px; }

.field-compact { grid-template-columns: 58px minmax(0, 1fr); }
.field-compact .check-row { font-size: 11px; line-height: 1.3; }

.input, .select {
  width: 100%;
  min-width: 0;
  height: 27px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  padding: 3px 7px;
  font-size: 12px;
  outline: none;
}
.input:focus, .select:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12); }
.input[type="number"] { font-variant-numeric: tabular-nums; }

.color-input {
  width: 34px;
  height: 27px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}

/* ---------- local font picker ---------- */
.font-list-field { align-items: start; }
.font-list-field > label { padding-top: 7px; }
.font-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
  min-width: 0;
}
.font-list-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.font-list-name {
  flex: 1 1 auto;
  min-width: 0;
  height: 27px;
  padding: 3px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.font-list-name:hover { border-color: var(--blue); }
.font-list-name:focus-visible { outline: 2px solid rgba(37, 99, 235, 0.25); outline-offset: 1px; }
.font-list-delete { flex: 0 0 auto; width: 27px; height: 27px; }
.font-list-input { flex: 1 1 auto; min-width: 0; }
.font-list-add { align-self: flex-start; }
.font-list-manual {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.font-list-manual .input { flex: 1 1 auto; min-width: 0; }
.font-list-hint { margin: 0; }

.font-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 220px;
}
.font-picker-search { height: 30px; }
.font-picker-status {
  min-height: 17px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}
.font-picker-status.is-loading { color: var(--blue-dark); }
.font-picker-status.is-empty { color: var(--amber); }
.font-picker-status.is-error { color: var(--red); }
.font-picker-hint { margin: -2px 0 0; }

.font-picker-list {
  max-height: 56vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  scrollbar-width: thin;
}
.font-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
}
.font-row:last-child { border-bottom: 0; }
.font-row:hover, .font-row:focus-visible { background: #f8fbff; outline: none; }
.font-row:focus-visible { box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.25); }
.font-row.is-active { background: var(--blue-soft); }
.font-row-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}
.font-preview {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #111827;
  font-size: 20px;
  line-height: 1.35;
}

.range-row { display: flex; align-items: center; gap: 7px; width: 100%; }
.range-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--blue); }
.range-value { width: 42px; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.check-row { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.check-row input[type="checkbox"] { accent-color: var(--blue); }
.export-options { flex-wrap: wrap; gap: 4px 16px; }
.export-options .check-row { white-space: nowrap; }
.export-options input[type="radio"] { accent-color: var(--blue); }

.seg {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  overflow: hidden;
  width: 100%;
}
.seg button {
  flex: 1;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  padding: 4px 2px;
  white-space: nowrap;
}
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--blue-soft); color: var(--blue-dark); font-weight: 600; }

.table-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 7px 2px;
  margin-bottom: 7px;
  background: #fff;
}
.table-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}
.table-card-title { font-size: 11px; font-weight: 700; color: var(--muted); }
.table-card .field { grid-template-columns: 58px minmax(0, 1fr); margin-bottom: 6px; }
.table-card .field > label { font-size: 10px; }
.table-margin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.table-margin-item {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  font-size: 10px;
  color: var(--muted);
}
.table-margin-item .input {
  min-width: 0;
  width: 100%;
  padding-left: 5px;
  padding-right: 4px;
}
.table-card .table-margin-grid + .hint { margin-top: 2px; flex: 1 1 100%; }
.table-card .field .control { flex-wrap: wrap; }
.table-card .table-margin-grid { flex: 1 1 100%; }

/* 同行双数值字段的紧凑排布 */
.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 7px;
}
.field-row .field {
  grid-template-columns: auto minmax(0, 1fr);
  gap: 5px;
  margin-bottom: 0;
}
.field-row .field > label { white-space: nowrap; }

/* 阴影/轮廓分组：开关 + 参数行，关闭时参数禁用 */
.so-group { margin-bottom: 7px; }
.so-group .check-row { margin-bottom: 6px; }
.so-sep {
  border-top: 1px solid var(--line-strong);
  margin: 10px 0 8px;
}
.so-group .input:disabled,
.so-group .color-input:disabled { opacity: 0.45; }

.hint {
  color: var(--faint);
  font-size: 10px;
  line-height: 1.6;
  margin: 4px 0 2px;
}
.hint.warn { color: var(--amber); }

.inline-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.badge-warn {
  display: inline-block;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 9px;
  line-height: 15px;
}

/* ---------- canvas ---------- */
.canvas-pane {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: #e9edf2;
  background-image: radial-gradient(#cfd6e0 0.7px, transparent 0.7px);
  background-size: 16px 16px;
}

.canvas-toolbar {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  width: 56px;
  max-height: calc(100% - 24px);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.canvas-toolbar-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  min-height: 0;
}

.canvas-toolbar-pages { flex: 1 1 auto; min-height: 0; }
.canvas-toolbar .icon-btn { width: 32px; height: 32px; }

.canvas-zoom { flex: 0 0 auto; }
.zoom-input {
  width: 44px;
  height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  padding: 3px 4px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
}
.zoom-input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12); }

.toolbar-divider {
  width: 100%;
  height: 1px;
  background: var(--line);
  margin: 2px 0;
}

.canvas-tip {
  position: fixed;
  z-index: 50;
  max-width: 240px;
  padding: 4px 8px;
  background: rgba(17, 24, 39, 0.95);
  color: #fff;
  font-size: 12px;
  line-height: 1.4;
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
  transform: translateY(-50%);
  opacity: 0;
  transition: opacity 0.12s ease-out;
}
.canvas-tip.show { opacity: 1; }

.canvas-scroll {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.canvas-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.canvas-scroll::-webkit-scrollbar-track { background: transparent; }
.canvas-scroll::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}
.canvas-scroll::-webkit-scrollbar-thumb:hover { background: #adb7c5; background-clip: content-box; }
.canvas-scroll::-webkit-scrollbar-corner { background: transparent; }

.canvas-stage {
  position: relative;
  width: 100%;
  height: 100%;
}

.leafer-view {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
}

.overlay {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  touch-action: none;
  outline: none;
}

.empty-hint {
  position: absolute;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  z-index: 2;
  text-align: center;
  color: #7b8798;
  font-size: 13px;
  line-height: 1.9;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.7);
  border: 1px dashed #c3ccd8;
  border-radius: 12px;
  padding: 22px 30px;
  backdrop-filter: blur(2px);
}
.empty-icon {
  font-size: 34px;
  color: #94a3b8;
  line-height: 1;
  margin-bottom: 8px;
}

#inline-text-editor {
  position: absolute;
  z-index: 8;
  margin: 0;
  padding: 0;
  border: 1px dashed var(--blue);
  outline: none;
  resize: none;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.88);
  color: #111827;
  box-shadow: 0 2px 12px rgba(37, 99, 235, 0.18);
  border-radius: 2px;
}

/* ---------- modal ---------- */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.38);
  padding: 24px;
}

.modal {
  width: min(560px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: modal-in 0.14s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 14px; font-weight: 700; }
.modal-close {
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 20px;
  line-height: 1;
  padding: 0 2px;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 16px;
  overflow: auto;
  line-height: 1.7;
  font-size: 13px;
}
.modal-body p { margin: 0 0 10px; }
.modal-body p:last-child { margin-bottom: 0; }
.modal-body .error-list {
  margin: 8px 0 0;
  padding: 10px 12px 10px 26px;
  background: #fff7f7;
  border: 1px solid #fecaca;
  border-radius: 6px;
  color: #991b1b;
  font-size: 12px;
  max-height: 260px;
  overflow: auto;
}
.modal-body .summary-box {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 10px 0;
  font-size: 12px;
}
.modal-body .summary-box strong { color: var(--text); }
.modal-body .summary-list { margin: 4px 0 0; padding-left: 18px; color: var(--muted); }
.modal-body .summary-list li { margin: 2px 0; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
}

.modal-form .field { grid-template-columns: 96px minmax(0, 1fr); margin-bottom: 10px; }
.modal-form .field > label { font-size: 12px; }
.modal-form .input, .modal-form .select { height: 30px; }

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.choice-card {
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 7px;
  padding: 12px;
  text-align: left;
  line-height: 1.5;
}
.choice-card:hover { border-color: var(--blue); background: #f8fbff; }
.choice-card strong { display: block; font-size: 13px; margin-bottom: 3px; }
.choice-card span { color: var(--muted); font-size: 11px; }

/* ---------- playlist editor ---------- */
.playlist-editor-modal {
  height: min(720px, 84vh);
  max-height: 86vh;
}
.playlist-editor-modal .modal-body {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  line-height: normal;
}
.playlist-editor {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
}
.playlist-editor-rail {
  flex: 0 0 180px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
}
.playlist-editor-rail-title {
  padding: 10px 12px 8px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.playlist-editor-category-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0 6px 10px;
}
.playlist-editor-rail-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 7px 8px;
  border-radius: 6px;
  text-align: left;
  line-height: 1.4;
}
.playlist-editor-rail-row:hover { background: #eef1f5; }
.playlist-editor-rail-row.active {
  background: var(--blue-soft);
  border-color: #bfdbfe;
  color: var(--blue-dark);
  font-weight: 600;
}
.playlist-editor-rail-row.has-error { color: var(--red); }
.playlist-editor-rail-row.has-error .playlist-editor-rail-count { color: var(--red); }
.playlist-editor-rail-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.playlist-editor-rail-name.is-empty { color: var(--red); font-style: italic; }
.playlist-editor-rail-count { flex: 0 0 auto; font-size: 11px; color: var(--muted); }
.playlist-editor-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}
.playlist-editor-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fcfdff;
}
.playlist-editor-head-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.playlist-editor-name-input { flex: 0 1 260px; height: 30px; }
.playlist-editor-songcount { margin-left: auto; white-space: nowrap; }
.playlist-editor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  align-content: start;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px 14px 18px;
}
.playlist-editor-cell { position: relative; min-width: 0; }
.playlist-editor-cell .playlist-editor-input {
  width: 100%;
  height: 30px;
  padding-right: 22px;
  text-overflow: ellipsis;
}
.playlist-editor-input.is-invalid,
.playlist-editor-name-input.is-invalid {
  border-color: var(--red);
  background: #fff7f7;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.12);
}
.playlist-editor-delete {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--faint);
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
}
.playlist-editor-cell:hover .playlist-editor-delete,
.playlist-editor-cell:focus-within .playlist-editor-delete { opacity: 1; }
.playlist-editor-delete:hover { background: var(--red-soft); color: var(--red); }
.playlist-editor-add-input { border-style: dashed; color: var(--muted); }
.playlist-editor-status { margin-right: auto; font-size: 12px; color: var(--muted); }
.playlist-editor-status.has-errors { color: var(--red); font-weight: 600; }
.playlist-editor-discard {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #fff7f7;
  border-top: 1px solid #fecaca;
  color: #991b1b;
  font-size: 12px;
}
.playlist-editor-discard-text { flex: 1 1 auto; }
.playlist-editor-input:focus-visible,
.playlist-editor-name-input:focus-visible,
.playlist-editor-rail-row:focus-visible,
.playlist-editor-delete:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}
@media (max-width: 1000px) {
  .playlist-editor-rail { flex-basis: 140px; }
  .playlist-editor-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* ---------- toast ---------- */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(17, 24, 39, 0.9);
  color: #fff;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 12px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.25);
  animation: toast-in 0.16s ease-out;
  max-width: 70vw;
}
.toast.error { background: rgba(185, 28, 28, 0.95); }
.toast.success { background: rgba(4, 120, 87, 0.95); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 1180px) {
  :root { --sidebar-w: 280px; --inspector-w: 300px; }
  .topbar-actions { gap: 4px; }
  .btn { padding: 6px 8px; }
  .canvas-toolbar { width: 48px; gap: 4px; padding: 6px 4px; }
  .canvas-toolbar .icon-btn { width: 28px; height: 28px; }
  .page-tab { width: 28px; height: 28px; }
  .zoom-input { width: 38px; }
}
