/* =========================================================
   ATO V3 · 侧栏 / 素材库 / 属性浮窗 / 图层 / 时间轴
   ========================================================= */

/* ---------- 左侧素材库 ---------- */
.assets-panel {
  background: var(--bg-1); border-right: 1px solid var(--border-1);
  display: flex; flex-direction: column; min-height: 0;
  /* 面板高度由父级 grid 行高约束；内部 .asset-list 通过
     flex:1 + overflow-y:auto 实现独立滚动 */
}
/* 素材面板头：标题与分类 Tab 分两行排列（避免单行挤压成乱码） */
.assets-panel .panel-head {
  flex-wrap: wrap; height: auto; padding-bottom: 4px;
  align-content: flex-start;
}
.assets-panel .panel-head > span {
  width: 100%; margin-bottom: 4px;
}
.assets-panel #asset-tabs {
  width: 100%;
  overflow-x: visible; flex-wrap: wrap;
}
.assets-panel #asset-tabs .seg-btn {
  padding: 0 14px; font-size: var(--fs-13);
  white-space: nowrap; flex-shrink: 0; height: 32px;
}
.asset-search { display: flex; align-items: center; gap: 6px; padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border-1); background: var(--bg-2); }
.asset-search .search-ico { color: var(--text-3); font-size: var(--fs-13); }
.asset-search input[type=text] { background: transparent; border-color: transparent; }
.asset-search input[type=text]:focus { background: var(--bg-2); border-color: var(--accent); }
.asset-search input, .pf-body input[type=text], .pf-body input[type=number], .pf-body select,
.tl-field input, .tl-field select {
  width: 100%; height: 28px; padding: 0 var(--s-2);
  background: var(--bg-2); color: var(--text-1);
  border: 1px solid var(--border-2); border-radius: var(--r-2);
  font-size: var(--fs-12); font-family: var(--font-ui);
}
.asset-search input:focus, .pf-body input:focus, .pf-body select:focus,
.tl-field input:focus, .tl-field select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.asset-list {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: var(--s-2);
  display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-3);
  align-content: start; grid-auto-flow: dense;
  /* 关键：auto 行高在 flex+overflow 容器里会被压成 0，
     强制按内容（aspect-ratio 撑出的方块）计算行高，避免折叠重叠 */
  grid-auto-rows: max-content;
}

/* 二级分类标签条（平铺换行，高度上限防窄屏挤占素材网格） */
.asset-cat-bar {
  display: flex; flex-wrap: wrap; gap: 5px;
  padding: 5px var(--s-3); border-bottom: 1px solid var(--border-1);
  background: var(--bg-1);
  max-height: 120px;
  overflow-y: auto;
}
.cat-chip {
  flex: none; height: 26px; padding: 0 10px;
  border: 1px solid var(--border-2); border-radius: 999px;
  background: var(--bg-2); color: var(--text-2);
  font-size: 11px; white-space: nowrap; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  display: inline-flex; align-items: center; justify-content: center;
}
.cat-chip:hover { background: var(--bg-hover); color: var(--text-1); }
.cat-chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-color: transparent; color: var(--text-on-accent); font-weight: 600;
}
.asset-cat-title {
  grid-column: 1 / -1; font-size: var(--fs-11); color: var(--text-3);
  padding: var(--s-2) 2px var(--s-1); font-weight: 600;
}
.asset-item {
  position: relative; aspect-ratio: 1; border-radius: var(--r-2);
  background: var(--bg-2); border: 1px solid var(--border-1);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; transition: border-color .15s, transform .05s;
}
.asset-item:hover { border-color: var(--accent); background: var(--bg-3); transform: scale(1.04); box-shadow: var(--sh-1); }
.asset-item:active { transform: scale(.96); }
.asset-item img { width: 80%; height: 80%; object-fit: contain; pointer-events: none; }
.asset-item .ai-label {
  display: none;
}
.asset-item.shape-item { font-size: 26px; color: var(--text-1); }

/* ---------- 模版卡片（跨整行展示：竖版预览 + 名称信息） ---------- */
.tpl-item {
  grid-column: 1 / -1;
  display: flex; gap: 10px; align-items: center;
  padding: 10px;
  border: 1px solid var(--border-1); border-radius: var(--r-2);
  background: var(--bg-2); cursor: pointer;
  transition: border-color .15s, transform .05s;
}
.tpl-item:hover { border-color: var(--accent); background: var(--bg-3); transform: scale(1.02); box-shadow: var(--sh-1); }
.tpl-item:active { transform: scale(.98); }
.tpl-item canvas {
  flex: none; display: block;
  border-radius: 6px; border: 1px solid var(--border-1);
  background: #101522;
}
.tpl-info { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.tpl-name { font-size: var(--fs-13); font-weight: 700; color: var(--text-1); }
.tpl-meta { font-size: var(--fs-11); color: var(--text-3); }
.asset-hint {
  padding: var(--s-2) var(--s-3); font-size: var(--fs-11);
  color: var(--text-2); background: var(--bg-3); border-top: 1px solid var(--border-1);
}

/* ---------- 右侧统一面板（图层 + 属性） ---------- */
#right-panel {
  background: var(--bg-1); border-left: 1px solid var(--border-1);
  display: flex; flex-direction: column; min-height: 0;
  /* 同左面板：滚动容器，窄屏下内容回流/滚动，不撑破布局 */
  overflow: hidden;
}
.rp-head { gap: var(--s-2); }
.layer-ops { display: flex; gap: 4px; }
.rp-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.rp-pane.hidden { display: none; }
.layer-list { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s-1); }
.layer-row {
  display: flex; align-items: center; gap: var(--s-2);
  height: 36px; padding: 0 var(--s-2); margin-bottom: 2px;
  border-radius: var(--r-2); cursor: grab; color: var(--text-2);
  border: 1px solid transparent; border-left: 3px solid transparent;
}
.layer-row:hover { background: var(--bg-2); }
.layer-row.selected { background: var(--accent-soft); border-color: var(--accent); color: var(--text-1); }
.layer-row .lr-thumb { width: 28px; height: 28px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; background: rgba(0,0,0,.25); border-radius: 4px; overflow: hidden; }
.layer-row .lr-thumb canvas { display: block; width: 100%; height: 100%; }
.layer-row .lr-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-12); }
.layer-row .lr-btn {
  width: 20px; height: 20px; border: none; background: transparent;
  color: var(--text-3); cursor: pointer; border-radius: var(--r-1); font-size: 12px;
}
.layer-row .lr-btn:hover { background: var(--bg-hover); color: var(--text-1); }
.layer-row .lr-btn.lr-del:hover { background: var(--danger-soft); color: var(--danger); }
.layer-row.hidden-el .lr-name { color: var(--text-3); text-decoration: line-through; }

/* 图层类型色条（按元素类型着色左侧竖条） */
.layer-row[data-type="text"]      { border-left-color: var(--type-text); }
.layer-row[data-type="image"]     { border-left-color: var(--type-image); }
.layer-row[data-type="frame"]     { border-left-color: var(--type-frame); }
.layer-row[data-type="rect"],
.layer-row[data-type="ellipse"],
.layer-row[data-type="line"]      { border-left-color: var(--type-shape); }
.layer-row[data-type="background"] { border-left-color: var(--type-bg); }
.layer-row.selected { border-left-color: var(--accent); }

/* 图层拖拽排序 */
.layer-row.dragging-row { opacity: 0.4; cursor: grabbing; }
.drop-indicator {
  height: 2px; margin: 2px 0; border-radius: 1px;
  background: var(--accent); box-shadow: 0 0 6px var(--accent);
}

/* ---------- 属性面板（停靠于右侧统一面板内） ---------- */
.pf-body { flex: 1; min-height: 0; padding: var(--s-3); overflow-y: auto; }

/* 属性表单字段 */
.pf-field { margin-bottom: var(--s-4); }
.pf-field > label { display: block; font-size: var(--fs-11); color: var(--text-3); margin-bottom: 4px; }
.pf-row { display: flex; gap: var(--s-2); }
.pf-row > .pf-field { flex: 1; margin-bottom: 0; }
.pf-body input[type=text], .pf-body input[type=number], .pf-body select, .pf-body textarea {
  width: 100%; height: 30px; padding: 0 var(--s-2);
  background: var(--bg-1); color: var(--text-1);
  border: 1px solid var(--border-2); border-radius: var(--r-2);
  font-size: var(--fs-12); font-family: var(--font-ui);
}
.pf-body textarea { height: auto; min-height: 56px; resize: vertical; padding: var(--s-2); line-height: 1.5; }
.pf-body input:focus, .pf-body select:focus, .pf-body textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft);
}
.pf-color { display: flex; align-items: center; gap: var(--s-2); }
.pf-color input[type=color] {
  width: 32px; height: 30px; padding: 0; border: 1px solid var(--border-2);
  border-radius: var(--r-2); background: var(--bg-1); cursor: pointer;
}
.pf-color input[type=text] { flex: 1; }
.pf-range { display: flex; align-items: center; gap: var(--s-2); }
.pf-range input[type=range] { flex: 1; accent-color: var(--accent); }
.pf-range .rv { width: 42px; text-align: right; color: var(--text-2); font-size: var(--fs-11); font-family: var(--font-mono); }
.pf-section { font-size: var(--fs-11); color: var(--text-2); font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px; margin: var(--s-5) 0 var(--s-2); padding-top: var(--s-3); border-top: 1px solid var(--border-1); }
.pf-empty { color: var(--text-2); font-size: var(--fs-12); padding: var(--s-6) var(--s-3); text-align: center; line-height: 1.6; }
.pf-empty::before { content: "\270E"; display: block; font-size: 26px; color: var(--accent); margin-bottom: var(--s-2); }
.pf-check { display: flex; align-items: center; gap: var(--s-2); color: var(--text-2); font-size: var(--fs-12); }
.pf-check input { accent-color: var(--accent); }

/* ---------- 底部时间轴 ---------- */
#timeline {
  background: var(--bg-1); border-top: 1px solid var(--border-1);
  display: flex; flex-direction: column; padding: var(--s-2) var(--s-4);
  gap: var(--s-2);
}
.tl-head { display: flex; align-items: center; gap: var(--s-4); flex-wrap: wrap; }
.tl-head > span { font-size: var(--fs-12); font-weight: 600; color: var(--text-2); }
.tl-tools { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.tl-field { display: flex; align-items: center; gap: 6px; font-size: var(--fs-11); color: var(--text-2); }
.tl-field input[type=number] { width: 56px; height: 26px; }
.tl-field select { width: auto; height: 26px; }
.tl-track {
  flex: 1; min-height: 0; background: var(--bg-0);
  border: 1px solid var(--border-1); border-radius: var(--r-2);
  padding: var(--s-2); overflow-x: auto;
}
.tl-empty { color: var(--text-2); font-size: var(--fs-12); display: flex; align-items: center; justify-content: center; padding: var(--s-3) 0; text-align: center; }

/* 时间轴折叠态 */
#timeline.tl-collapsed .tl-tools,
#timeline.tl-collapsed .tl-track { display: none; }

/* 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
::-webkit-scrollbar-track { background: transparent; }

/* =========================================================
   新时间轴（真轨道 + 播放头 + 预设面板）
   ========================================================= */
#timeline { padding-bottom: var(--s-3); position: relative; }

/* 顶部高度拖拽条：按住上下拖动调整时间轴高度 */
.tl-resizer {
  position: absolute; top: -3px; left: 0; right: 0; height: 7px;
  cursor: row-resize; z-index: 20;
}
.tl-resizer::before {
  content: ''; position: absolute; left: 50%; top: 2px;
  width: 44px; height: 3px; transform: translateX(-50%);
  border-radius: 2px; background: var(--border-strong);
  transition: background .15s, height .15s;
}
.tl-resizer:hover::before, .tl-resizer.dragging::before { background: var(--accent); height: 4px; }
body.tl-resizing { cursor: row-resize; user-select: none; }
body.tl-resizing * { pointer-events: none; }
body.tl-resizing .tl-resizer { pointer-events: auto; }
.tl-head { row-gap: var(--s-2); }
.tl-controls { display: flex; align-items: center; gap: var(--s-2); }
.tl-play-btn { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent); }
.tl-time { font-family: var(--font-mono); font-size: var(--fs-12); color: var(--text-2); min-width: 84px; }

.tl-body { display: flex; gap: var(--s-3); flex: 1; min-height: 0; margin-top: var(--s-2); }
.tl-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tl-scroll {
  flex: 1; min-height: 0; overflow: auto; position: relative;
  background: var(--bg-0); border: 1px solid var(--border-1); border-radius: var(--r-2);
}
.tl-inner { position: relative; min-width: 100%; }
.tl-ruler { position: sticky; top: 0; height: 22px; background: var(--bg-1); border-bottom: 1px solid var(--border-1); z-index: 3; }
.tl-tick { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border-1); }
.tl-tick.major { background: var(--border-strong); }
.tl-tick span { position: absolute; top: 2px; left: 3px; font-size: 10px; color: var(--text-3); font-family: var(--font-mono); }

.tl-rows { position: relative; }
.tl-row { display: flex; align-items: stretch; height: 34px; border-bottom: 1px solid var(--border-1); }
.tl-row.selected { background: var(--accent-soft); }
.tl-row-label {
  flex: none; width: 110px; padding: 0 var(--s-2);
  display: flex; align-items: center;
  font-size: var(--fs-11); color: var(--text-2);
  border-right: 1px solid var(--border-1); background: var(--bg-1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
  position: sticky; left: 0; z-index: 2;
}
.tl-row-label:hover { color: var(--accent-strong); }
.tl-row-track { position: relative; flex: 1; }

.tl-clip {
  position: absolute; top: 5px; height: 24px;
  border-radius: 6px; cursor: grab;
  display: flex; align-items: center; padding: 0 8px;
  font-size: 10px; color: #fff; font-weight: 600;
  overflow: hidden; white-space: nowrap;
  box-shadow: var(--sh-1); user-select: none;
}
.tl-clip:active { cursor: grabbing; }
.tl-clip.cat-in   { background: #5b8cff; }
.tl-clip.cat-loop { background: #4fc4b0; }
.tl-clip.cat-out  { background: #ff8fb6; }
.tl-h { position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize; background: rgba(255,255,255,.35); border-radius: 6px; opacity: 0; transition: opacity .12s; }
.tl-h.h-l { left: 0; } .tl-h.h-r { right: 0; }
.tl-clip:hover .tl-h { opacity: 1; }

.tl-playhead {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--danger); z-index: 4; pointer-events: none;
}
.tl-playhead::before {
  content: ''; position: absolute; top: 0; left: -5px;
  border: 6px solid transparent; border-top-color: var(--danger);
}

/* 预设面板 */
.tl-presets {
  flex: none; width: 236px; display: flex; flex-direction: column; gap: var(--s-2);
  background: var(--bg-1); border: 1px solid var(--border-1); border-radius: var(--r-2);
  padding: var(--s-2); overflow-y: auto;
}
.tl-pv-wrap { display: flex; justify-content: center; }
.tl-pv-wrap canvas { width: 200px; height: 120px; border-radius: 8px; background: var(--bg-0); border: 1px solid var(--border-1); }
.tl-pv-groups { display: flex; flex-direction: column; gap: var(--s-2); }
.tl-pv-title { display: flex; align-items: center; gap: 6px; font-size: var(--fs-11); font-weight: 700; color: var(--text-2); }
.tl-pv-title i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tl-pv-group { display: flex; flex-wrap: wrap; gap: 4px; }
.tl-pv-chip {
  height: 24px; padding: 0 8px; border-radius: 999px;
  border: 1px solid var(--border-2); background: var(--bg-2);
  color: var(--text-2); font-size: 11px; cursor: pointer;
}
.tl-pv-chip:hover { border-color: var(--accent); color: var(--accent-strong); }
.tl-pv-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* 折叠态 */
#timeline.tl-collapsed .tl-body { display: none; }

/* ---------- 字体按钮网格 ---------- */
.pf-font-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px 0;
}

.pf-font-btn {
  position: relative;
  height: 56px;
  padding: 6px 8px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text-1);
  font-size: 24px;
  line-height: 1.2;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.pf-font-btn:hover {
  border-color: var(--accent);
  background: var(--bg-3);
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
}

.pf-font-btn.active {
  border-color: var(--accent);
  background: var(--bg-3);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

/* 加载动画：边框进度条闭环动效 */
.pf-font-btn.loading {
  pointer-events: none;
  position: relative;
}

/* 使用伪元素创建边框进度条 */
.pf-font-btn.loading::before {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  bottom: -1px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) 50%, transparent 50%, transparent 100%);
  background-size: 200% 100%;
  background-position: 100% 0;
  animation: font-loading-progress 1.5s ease-in-out;
  z-index: 1;
  mask: 
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask: 
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask-composite: exclude;
  -webkit-mask-composite: xor;
  padding: 2px;
}

@keyframes font-loading-progress {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}
