/* ============================================================
   H5 动效编辑器 — Design System & Layout
   ============================================================ */

/* --- 1. Design Tokens --- */
:root {
  /* Backgrounds */
  --bg:           #e8eaf2;
  --surface:      #ffffff;
  --surface-2:    #f3f5f9;
  --surface-3:    #ebecf5;

  /* Borders */
  --border:       #dde1ec;
  --border-hi:    #c2c8dc;

  /* Header (dark navy) */
  --hd-bg:        #14172b;
  --hd-text:      #dce2f0;
  --hd-dim:       #7580a0;
  --hd-hover:     rgba(255,255,255,0.06);
  --hd-active:    rgba(255,255,255,0.12);
  --hd-sep:       rgba(255,255,255,0.08);

  /* Brand */
  --primary:      #2563eb;
  --primary-hov:  #1d4ed8;
  --primary-sub:  #eff6ff;
  --primary-txt:  #1e40af;

  /* Status */
  --success:      #16a34a;
  --success-sub:  #f0fdf4;
  --warning:      #d97706;
  --warning-sub:  #fffbeb;
  --danger:       #dc2626;
  --danger-hov:   #b91c1c;
  --danger-sub:   #fef2f2;
  --info-sub:     #eff6ff;

  /* Text */
  --text:         #111827;
  --text-2:       #374151;
  --text-3:       #6b7280;
  --text-4:       #9ca3af;

  /* Radii */
  --r:            6px;
  --r-sm:         4px;
  --r-lg:         10px;
  --r-xl:         14px;

  /* Shadows */
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow:       0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg:    0 10px 30px rgba(0,0,0,0.15), 0 4px 8px rgba(0,0,0,0.08);

  /* Dimensions */
  --hd-h:         48px;
  --sl-w:         232px;
  --sr-w:         286px;
  --tbar-h:       46px;
}

/* --- 2. Reset / Base --- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* --- 3. App Header --- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--hd-h);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--hd-bg);
  border-bottom: 1px solid var(--hd-sep);
  padding: 0 8px;
  overflow: hidden;
}

/* Brand */
.app-header__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  flex-shrink: 0;
  margin-right: 8px;
}

.brand-logo {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--hd-text);
  white-space: nowrap;
}

/* Nav area */
.app-header__nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

.app-header__nav::-webkit-scrollbar { display: none; }

/* Right actions */
.app-header__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 8px;
  flex-shrink: 0;
  border-left: 1px solid var(--hd-sep);
  margin-left: 4px;
}

/* Header buttons */
.hbtn {
  height: 30px;
  padding: 0 10px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--hd-dim);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}

.hbtn:hover {
  background: var(--hd-hover);
  color: var(--hd-text);
}

.hbtn.hbtn--icon {
  width: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hbtn.hbtn--sm {
  font-size: 11px;
  padding: 0 7px;
  color: var(--hd-dim);
}

.hbtn.hbtn--ghost {
  border: 1px solid rgba(255,255,255,0.18);
  color: var(--hd-text);
}
.hbtn.hbtn--ghost:hover { background: var(--hd-hover); }

.hbtn.hbtn--primary {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}
.hbtn.hbtn--primary:hover { background: var(--primary-hov); }

/* Accent button for import operations */
.hbtn.hbtn--accent {
  background: #0f766e;
  color: #fff;
  font-weight: 600;
}
.hbtn.hbtn--accent:hover { background: #0d9488; }

.hbtn-sep {
  width: 1px;
  height: 20px;
  background: var(--hd-sep);
  flex-shrink: 0;
  margin: 0 4px;
}

.hbtn-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* --- 4. App Body Layout --- */
.app-body {
  display: grid;
  grid-template-columns: var(--sl-w) 1fr var(--sr-w);
  height: calc(100vh - var(--hd-h));
  margin-top: var(--hd-h);
  overflow: hidden;
}

/* --- 5. Sidebars --- */
.sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;          /* explicit height so flex children can use flex:1 */
  min-height: 0;
  background: var(--surface);
  overflow: hidden;
}

.sidebar-left {
  border-right: 1px solid var(--border);
}

.sidebar-right {
  border-left: 1px solid var(--border);
}

/* Sidebar Tab Nav */
.sidebar-tabs {
  display: flex;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 5px 6px 0;
  gap: 2px;
  flex-shrink: 0;
}

.stab {
  flex: 1;
  padding: 6px 6px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
}

.stab:hover { color: var(--text-2); }

.stab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--surface);
}

/* Tab Panel Content */
.stab-panel {
  display: none;
  flex-direction: column;
  flex: 1 1 0;      /* flex-basis 0 is key for scrolling inside flex parent */
  min-height: 0;    /* critical: allows overflow-y to work inside flex column */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  gap: 8px;
}

.stab-panel.active { display: flex; }

/*
 * KEY FIX: All direct children of .stab-panel must NOT shrink.
 * Without flex-shrink:0, flex children compress to fit the container
 * instead of overflowing → no scroll ever fires.
 */
.stab-panel > * {
  flex-shrink: 0;
}

/* --- 6. Center Editor --- */
.editor-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ---- 6a. Editor Toolbar ---- */
.editor-toolbar {
  height: var(--tbar-h);
  display: flex;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 6px;
  overflow-x: auto;
  flex-shrink: 0;
  gap: 0;
  scrollbar-width: none;
}

.editor-toolbar::-webkit-scrollbar { display: none; }

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 5px;
  flex-shrink: 0;
}

.toolbar-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  padding-right: 2px;
}

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

.tb-btn-tool {
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.1s;
  flex-shrink: 0;
}

.tb-btn-tool:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-sub);
}

.tb-btn-tool.active {
  background: var(--primary-sub);
  border-color: var(--primary);
  color: var(--primary);
}

.tb-input-sm {
  height: 28px;
  width: 64px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0 6px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
}

.tb-select-sm {
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0 6px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
}

.tb-label-inline {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---- 6b. Canvas Area ---- */
.canvas-area {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 32px 24px 48px; /* extra bottom so zoomed canvas isn't cut off */
  /* checkered pattern background */
  background-color: #dde0ea;
  background-image:
    linear-gradient(45deg, #cdd0de 25%, transparent 25%),
    linear-gradient(-45deg, #cdd0de 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #cdd0de 75%),
    linear-gradient(-45deg, transparent 75%, #cdd0de 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.canvas {
  position: relative;
  background: #ffffff;
  border-radius: 3px;
  overflow: hidden; /* 与运行时 scene 一致：边界内裁切 */
  box-shadow:
    0 0 0 1px rgba(37,99,235,0.15),
    0 4px 12px rgba(0,0,0,0.18),
    0 16px 40px rgba(0,0,0,0.12);
  transform-origin: top center;
  flex-shrink: 0;
  transition: transform 0.12s ease;
}

/* Canvas focus ring */
.canvas::after {
  content: '';
  position: absolute;
  inset: -2px;
  border: 1.5px dashed rgba(37,99,235,0.3);
  pointer-events: none;
  border-radius: 4px;
}

/* Canvas size label */
.canvas::before {
  content: attr(data-size);
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
  pointer-events: none;
  letter-spacing: 0.03em;
}

.canvas-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---- 6c. Timeline / Collapsible Sections ---- */
.timeline-section {
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  cursor: pointer;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  user-select: none;
  transition: background 0.1s;
}

.section-header:hover { background: var(--surface-3); }

.section-header-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-body {
  overflow: hidden;
  transition: max-height 0.2s ease;
  max-height: 300px;
  padding: 8px;
}

.section-body.collapsed {
  max-height: 0;
  padding: 0;
}

/* Timeline internals */
.timeline-tracks {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  max-height: 200px;
  overflow: auto;
  position: relative;
}

.timeline-ruler,
.timeline-row {
  display: grid;
  grid-template-columns: 140px 1fr;
}

.timeline-ruler {
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface-2);
  z-index: 5;
}

.timeline-ruler .label {
  padding: 5px 8px;
  font-size: 11px;
  color: var(--text-3);
  font-weight: 600;
}

.timeline-ruler .axis {
  position: relative;
  min-height: 26px;
  cursor: pointer; /* clickable to seek */
}
.timeline-ruler .axis:hover {
  background: rgba(37,99,235,0.06);
}

.tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.tick span {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 10px;
  color: var(--text-4);
}

.timeline-row {
  border-bottom: 1px solid var(--surface-2);
  transition: background 0.1s;
}

.timeline-row:hover { background: var(--surface-2); }

.timeline-row .label {
  padding: 6px 8px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-3);
}

.timeline-row.active .label {
  color: var(--primary);
  font-weight: 600;
}

.timeline-track {
  position: relative;
  min-height: 30px;
}

.timeline-seg {
  position: absolute;
  top: 7px;
  height: 16px;
  border-radius: 3px;
}

.timeline-seg.entry  { background: #93c5fd; }
.timeline-seg.hold   { background: #3b82f6; }
.timeline-seg.exit   { background: #fca5a5; }

.timeline-handle {
  position: absolute;
  top: 5px;
  width: 5px;
  height: 20px;
  background: #1e3a8a;
  border-radius: 3px;
  cursor: ew-resize;
  opacity: 0.7;
}

.timeline-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #ef4444;
  pointer-events: none;
  z-index: 10;
}

/* Health Report */
.health-report {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
}

.health-item {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 6px 10px;
  background: var(--surface);
  font-size: 12px;
  line-height: 1.5;
}

.health-item.error  { border-color: var(--danger);  background: var(--danger-sub); }
.health-item.warn   { border-color: var(--warning); background: var(--warning-sub); }
.health-item.info   { border-color: #93c5fd;        background: var(--info-sub); }

.health-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  border-radius: 10px;
  padding: 1px 7px;
  line-height: 18px;
  min-width: 0;
  transition: background 0.2s;
}
.health-badge:empty { display: none; }

/* --- 7. Sidebar Panel Components --- */

/* Section title */
.section-card {
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 0;
}

.section-card__head {
  padding: 7px 10px;
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}

.section-card__body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Prevent any flex children inside section-card__body from shrinking */
.section-card__body > * {
  flex-shrink: 0;
}

/* Asset grid */
.asset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.asset-empty {
  grid-column: 1 / -1;
  padding: 24px 8px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.5;
}

.asset-item {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  cursor: grab;
  transition: border-color 0.12s, box-shadow 0.12s;
  overflow: hidden;
}
.asset-item:active { cursor: grabbing; }

.asset-item:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-sub), var(--shadow-sm);
}

.asset-item img {
  width: 100%;
  height: 60px;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.asset-info {
  padding: 5px 5px 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.asset-name {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-3);
  font-weight: 500;
}

.asset-size-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  font-size: 9px;
  font-weight: 600;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 3px;
  padding: 1px 4px;
  line-height: 1.4;
  pointer-events: none;
}

.asset-actions {
  display: flex;
  gap: 3px;
}
.asset-add-btn, .asset-preview-btn, .asset-del-btn {
  flex: 1;
  border: none;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.4;
  padding: 3px 4px;
  cursor: pointer;
  transition: background 0.12s;
}
.asset-add-btn {
  background: var(--primary);
  color: #fff;
}
.asset-add-btn:hover { background: var(--primary-hov); }
.asset-preview-btn {
  background: #eef2ff;
  color: #3730a3;
}
.asset-preview-btn:hover { background: #e0e7ff; }
.asset-del-btn {
  background: #fee2e2;
  color: #dc2626;
}
.asset-del-btn:hover { background: #fecaca; }

/* Upload button */
.upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1.5px dashed var(--border-hi);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.upload-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-sub);
}

/* Scene list */
.scene-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 6px;
}

.scene-item {
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 6px;
  font-size: 11px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text-2);
  transition: all 0.12s;
  overflow: hidden;
  user-select: none;
}

.scene-item:hover { border-color: var(--border-hi); background: var(--surface-2); box-shadow: var(--shadow-sm); }

.scene-item.active {
  border-color: var(--primary);
  background: var(--primary-sub);
  color: var(--primary-txt);
  font-weight: 500;
}

.scene-item.dragging { opacity: 0.4; }
.scene-item.drag-over { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-sub); }

/* Layer list */
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.layer-item {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 5px 8px;
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 4px;
  align-items: center;
  font-size: 11px;
  background: var(--surface);
  cursor: pointer;
  transition: all 0.1s;
}

.layer-item:hover { border-color: var(--border-hi); }

.layer-item.active {
  border-color: var(--primary);
  background: var(--primary-sub);
}

.layer-item.dragging { opacity: 0.35; }
.layer-item.drag-over { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-sub); }

.layer-item .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-2);
  font-size: 12px;
}

/* Preset list (templates, components, groups) */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* app.js generates elements with class "template-preset-item" — keep both */
.preset-item,
.template-preset-item {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 7px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  background: var(--surface);
  transition: border-color 0.1s, background 0.1s;
}

.preset-item:hover,
.template-preset-item:hover { border-color: var(--border-hi); background: var(--surface-2); }

.preset-item.active,
.template-preset-item.active {
  border-color: var(--primary);
  background: var(--primary-sub);
}

.preset-item__name,
.template-preset-item .preset-name,
.template-preset-item > div:first-child {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  color: var(--text-2);
  overflow: hidden;
}

.template-preset-item > div:first-child input.group-name-input {
  width: 100%;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0 6px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
}

.preset-item__meta,
.template-preset-meta {
  color: var(--text-4);
  font-size: 11px;
  width: 100%;
}

/* Slot list */
.slot-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slot-item {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  background: var(--surface);
}

.slot-item .slot-key {
  font-weight: 700;
  color: var(--primary-txt);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Role rule list */
.role-rule-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.role-rule-item {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 6px 8px;
  display: grid;
  grid-template-columns: 1fr 100px 100px auto;
  gap: 5px;
  align-items: center;
  font-size: 11px;
  background: var(--surface);
}

/* --- 8. Property Forms --- */

/* Field label + input */
.field-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field-input {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.field-input[type="number"] { font-variant-numeric: tabular-nums; }

select.field-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}

/* Field grids — all field items must not shrink so their parent can scroll */
.field-grid-1 { display: flex; flex-direction: column; gap: 6px; }
.field-grid-1 > * { flex-shrink: 0; }

.field-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.field-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Checkbox field variant */
.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--primary);
}

/* Subsection headings within props */
.prop-subtitle {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 0 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

/* Hint text */
.hint-text {
  font-size: 12px;
  color: var(--text-4);
  text-align: center;
  padding: 16px 8px;
  background: var(--surface-2);
  border-radius: var(--r);
  border: 1px dashed var(--border);
}

/* Meta text */
.meta-text {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}

/* --- 9. Buttons --- */

/* Small buttons (in panels) */
.btn-sm {
  height: 27px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.1s;
  flex-shrink: 0;
}

.btn-sm:hover {
  border-color: var(--border-hi);
  background: var(--surface-2);
  color: var(--text);
}

.btn-sm.btn-primary-sm {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-sm.btn-primary-sm:hover { background: var(--primary-hov); border-color: var(--primary-hov); }

.btn-sm.btn-danger-sm {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-sm.btn-danger-sm:hover { background: var(--danger-hov); border-color: var(--danger-hov); }

/* Mini inline button */
.mini-btn {
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-sm);
  font-size: 11px;
  color: var(--text-3);
  cursor: pointer;
  flex-shrink: 0;
}
.mini-btn:hover { border-color: var(--border-hi); color: var(--text); }

/* Button row */
.btn-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

/* Action row (page controls in left sidebar) */
.action-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* --- 10. Spacing utilities --- */
.mt-4  { margin-top: 4px; }
.mt-6  { margin-top: 6px; }
.mt-8  { margin-top: 8px; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.flex-1 { flex: 1; min-width: 0; }
.full-width { width: 100%; }
.hidden { display: none !important; }

/* --- 11. Canvas Layer System (keep for app.js compatibility) --- */

.layer {
  position: absolute;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  border: 0;
  cursor: move;
  border-radius: 1px;
}

.layer.locked { outline: 1px solid rgba(239,68,68,0.45); outline-offset: 0; }
.layer.selected { outline: 1.5px dashed var(--primary); outline-offset: 0; }
.layer.timeline-active { box-shadow: 0 0 0 2px rgba(239,68,68,0.5); }
.layer.hidden-layer { opacity: 0.2 !important; }
.layer.out-of-bounds {
  outline: 1.5px solid rgba(239,68,68,0.9);
  outline-offset: 0;
}
.layer.out-of-bounds::before {
  content: '超界';
  position: absolute;
  top: -18px;
  right: 0;
  font-size: 10px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 3px;
  background: rgba(239,68,68,0.9);
  color: #fff;
  pointer-events: none;
}

.layer img {
  width: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* Resize & Rotate handles */
.layer-resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  z-index: 20;
}

.layer-resize-handle.handle-se {
  right: -6px;
  bottom: -6px;
  cursor: nwse-resize;
}

.layer-resize-handle.handle-e {
  right: -6px;
  top: calc(50% - 6px);
  cursor: ew-resize;
}

.layer-resize-handle.handle-w {
  left: -6px;
  top: calc(50% - 6px);
  cursor: ew-resize;
}

.layer-resize-handle.handle-rotate {
  left: calc(50% - 6px);
  top: -22px;
  cursor: grab;
  border-color: #0f766e;
  background: #f0fdfa;
}

/* Snap guides */
.snap-guide {
  position: absolute;
  background: rgba(14,165,233,0.8);
  pointer-events: none;
  z-index: 999;
}

.safe-area-frame {
  position: absolute;
  left: 5%;
  top: 5%;
  width: 90%;
  height: 90%;
  border: 1px dashed rgba(16,185,129,0.85);
  border-radius: 2px;
  pointer-events: none;
  z-index: 1;
}

.safe-area-label {
  position: absolute;
  left: 6%;
  top: 5%;
  transform: translateY(-110%);
  font-size: 10px;
  color: #065f46;
  background: rgba(167,243,208,0.85);
  border: 1px solid rgba(16,185,129,0.6);
  border-radius: 3px;
  padding: 1px 6px;
  pointer-events: none;
  z-index: 1;
}

.snap-guide.v { top: 0; bottom: 0; width: 1px; }
.snap-guide.h { left: 0; right: 0; height: 1px; }

.snap-gap-line {
  position: absolute;
  height: 1px;
  background: rgba(16,185,129,0.9);
  pointer-events: none;
  z-index: 999;
}

.snap-gap-text {
  position: absolute;
  transform: translate(-50%, -120%);
  background: rgba(15,23,42,0.85);
  color: #fff;
  font-size: 10px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 3px;
  pointer-events: none;
  z-index: 1000;
}

/* Component preview inside canvas */
.component-preview {
  width: 100%;
  min-height: 40px;
  border-radius: var(--r);
  border: 1px solid #93c5fd;
  background: rgba(59,130,246,0.07);
  color: var(--primary-txt);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px;
  font-weight: 500;
}

.component-preview.form    { min-height: 80px; }
.component-preview.video,
.component-preview.carousel { min-height: 70px; }

/* --- 12. Modals --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}

.modal-box {
  width: min(92vw, 920px);
  height: min(90vh, 800px);
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-box.modal-sm {
  width: min(92vw, 520px);
  height: auto;
  max-height: 90vh;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  flex-shrink: 0;
}

.modal-close-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: var(--r);
  color: var(--text-3);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.1s;
}

.modal-close-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#previewFrame {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  margin: 0;
  display: block;
  background: #f0f0f0;
}

/* --- 13. Toast 通知系统 --- */
#toast-container {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  min-width: 220px;
  max-width: 360px;
  padding: 10px 14px 10px 12px;
  border-radius: var(--r-lg);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  pointer-events: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18), 0 2px 6px rgba(0,0,0,0.10);
  opacity: 1;
  transform: translateX(0);
  transition: opacity 0.28s ease, transform 0.28s ease;
  will-change: opacity, transform;
}

.toast.entering {
  opacity: 0;
  transform: translateX(16px);
}

.toast.leaving {
  opacity: 0;
  transform: translateX(16px);
}

.toast--success {
  background: #166534;
  color: #dcfce7;
  border-left: 3px solid #4ade80;
}

.toast--error {
  background: #7f1d1d;
  color: #fee2e2;
  border-left: 3px solid #f87171;
}

.toast--warning {
  background: #78350f;
  color: #fef3c7;
  border-left: 3px solid #fbbf24;
}

.toast--info {
  background: #1e3a5f;
  color: #dbeafe;
  border-left: 3px solid #60a5fa;
}

.toast__icon {
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 1px;
}

.toast__msg {
  flex: 1;
  word-break: break-word;
}

.toast__close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  margin-top: 1px;
}

.toast__close:hover {
  opacity: 1;
}

/* --- 14. 文本图层 --- */
.component-preview.text {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  padding: 6px 8px;
  word-break: break-all;
  text-align: center;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: pre-wrap;
}

/* 自动保存状态指示器 */
.autosave-indicator {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-4);
  background: rgba(255,255,255,0.85);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 50;
  backdrop-filter: blur(4px);
}

.autosave-indicator.visible {
  opacity: 1;
}

/* 快捷键提示 */
.shortcut-hint {
  font-size: 10px;
  color: var(--text-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  font-family: monospace;
  vertical-align: middle;
}

/* 场景列表复制按钮 */
.scene-item-actions {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  gap: 2px;
}

.scene-item:hover .scene-item-actions {
  display: flex;
}

.scene-item {
  position: relative;
}

.scene-dup-btn {
  padding: 2px 5px;
  font-size: 10px;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-2);
  line-height: 1.4;
}

.scene-dup-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* --- 15. 属性面板优化 --- */

/* 属性区块标题带左边色条 */
.prop-subtitle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  position: relative;
}

.prop-subtitle::before {
  content: '';
  width: 3px;
  height: 12px;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}

/* 数字输入框更紧凑 */
.field-grid-3 .field-input[type="number"],
.field-grid-2 .field-input[type="number"] {
  text-align: right;
  padding-right: 6px;
}

/* 颜色选择器 */
.field-input[type="color"] {
  padding: 2px 4px;
  cursor: pointer;
  height: 30px;
}

/* 图层列表 — 视觉改进 */
.layer-item {
  border-radius: 6px;
}

.layer-item .type-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.layer-item .type-badge.img  { background: #e0f2fe; color: #0369a1; }
.layer-item .type-badge.btn  { background: #dcfce7; color: #166534; }
.layer-item .type-badge.txt  { background: #fef3c7; color: #92400e; }
.layer-item .type-badge.vid  { background: #f3e8ff; color: #7e22ce; }
.layer-item .type-badge.form { background: #fce7f3; color: #9d174d; }
.layer-item .type-badge.csl  { background: #e0e7ff; color: #3730a3; }

/* 场景缩略图 */
.scene-thumb {
  width: 40px;
  height: 24px;
  object-fit: cover;
  border-radius: 3px;
  background: #f0f4ff;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

/* 拖拽提示 */
.drag-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(37,99,235,0.08);
  border: 2px dashed var(--primary);
  border-radius: var(--r);
  font-size: 13px;
  color: var(--primary);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
}

.canvas-area.dragging-over .drag-hint {
  opacity: 1;
}

.audio-preview-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.audio-preview-name {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 画布右下角尺寸/缩放水印 */
.canvas-zoom-label {
  position: fixed;
  bottom: 24px;
  right: 300px;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.65);
  background: rgba(30,40,60,0.55);
  border-radius: 20px;
  padding: 3px 10px;
  pointer-events: none;
  z-index: 20;
  backdrop-filter: blur(4px);
}

/* 组件预览通用 */
.component-preview {
  width: 100%;
  height: 100%;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  pointer-events: none;
  overflow: hidden;
  user-select: none;
}

.component-preview.button {
  font-weight: 600;
  font-size: 14px;
  border-radius: 8px;
}

.component-preview.form {
  font-size: 12px;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
}

.component-preview.video {
  font-size: 22px;
  flex-direction: column;
  gap: 4px;
}

.component-preview.carousel {
  font-size: 12px;
}

/* 层级工具栏 - 对齐/分布高亮 */
.tb-btn-tool.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* 工具栏分组标签 */
.toolbar-group-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  padding: 0 2px;
  flex-shrink: 0;
}

/* 健康检查徽章改进 */
.health-badge.warn { background: #d97706; }
.health-badge.error { background: #dc2626; }
.health-badge.ok { background: #16a34a; }

/* 时间轴轨道高亮 */
.timeline-bar.entry { background: var(--primary); opacity: 0.85; }
.timeline-bar.hold  { background: #0891b2; opacity: 0.75; }
.timeline-bar.exit  { background: #7c3aed; opacity: 0.75; }

/* --- 16. 全局滚动条美化 --- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-hi);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-4); }

/* --- 17. 图层在画布上 selected 状态改进 --- */
.layer.selected::after {
  content: '';
  position: absolute;
  inset: -2px;
  border: 2px solid var(--primary);
  border-radius: 3px;
  pointer-events: none;
  z-index: 100;
}

/* --- 18. 空状态改进 --- */
.no-layer-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  text-align: center;
  gap: 8px;
  color: var(--text-4);
  font-size: 12px;
}

.no-layer-hint__icon {
  font-size: 32px;
  opacity: 0.5;
}

.no-layer-hint__title {
  font-weight: 600;
  color: var(--text-3);
  font-size: 13px;
}

/* --- 19. 响应式改进 --- */
@media (max-width: 1200px) {
  :root {
    --sl-w: 200px;
    --sr-w: 256px;
  }
}

@media (max-width: 900px) {
  :root {
    --sl-w: 0px;
    --sr-w: 0px;
  }
  .sidebar { display: none; }
  .app-header__nav { overflow-x: auto; }
}
