:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e4e6eb;
  --line-strong: #cfd3da;
  --text: #1c1f26;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-weak: #eef0ff;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.06);
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
code { background: #eceef2; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 24px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; }
.brand-mark {
  width: 26px; height: 18px; border-radius: 4px; background: var(--accent); position: relative;
}
.brand-mark::after { content: ""; position: absolute; left: 5px; top: 5px; width: 10px; height: 3px; border-radius: 2px; background: #fff; box-shadow: 0 5px 0 0 #c7d2fe; }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: #f0f1f4; color: var(--text); }
.nav a.active { background: var(--accent-weak); color: var(--accent); }

/* ---------------- 按钮 / 输入 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: #f7f8fa; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: #4338ca; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef0f3; color: var(--text); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.icon { width: 26px; height: 26px; padding: 0; font-size: 13px; border-radius: 6px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

input[type="text"], input:not([type]), textarea, select {
  width: 100%; font: inherit; color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 36px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }

/* ---------------- 模板库 ---------------- */
.view { padding: 0 24px 48px; }
.hero { max-width: 1200px; margin: 32px auto 20px; }
.hero h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: .3px; }
.hero p { margin: 0; color: var(--muted); max-width: 760px; }
.hero.small h1 { font-size: 22px; }

.filters { max-width: 1200px; margin: 0 auto 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line-strong); background: #fff; color: var(--muted);
  padding: 4px 12px; border-radius: 999px; cursor: pointer; font: inherit; font-size: 13px;
}
.chip.active { background: var(--text); border-color: var(--text); color: #fff; }

.grid {
  max-width: 1200px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px;
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(16,24,40,.12); }
.card-cover { position: relative; background: #e9ebef; aspect-ratio: 16 / 9; overflow: hidden; cursor: zoom-in; }
.card-cover .pptd-scaled { position: absolute; inset: 0; }
.card-badge {
  position: absolute; right: 10px; top: 10px; background: rgba(17,17,17,.72); color: #fff;
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
}
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-title h3 { margin: 0; font-size: 16px; }
.card-body > p { margin: 0; color: var(--muted); font-size: 13px; flex: 1; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; color: #4b5563; background: #f0f1f4; padding: 1px 8px; border-radius: 6px; }
.card-actions { display: flex; gap: 8px; margin-top: 4px; }
.card-actions .btn { flex: 1; }
.empty { color: var(--muted); padding: 40px; text-align: center; grid-column: 1 / -1; }

/* ---------------- 编辑器 ---------------- */
.view.editor { padding: 0; height: calc(100vh - 56px); display: flex; flex-direction: column; }
.editor-bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.editor-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.title-input { border: 1px solid transparent !important; font-size: 16px !important; font-weight: 600; padding: 3px 8px !important; margin-left: -8px; background: transparent !important; }
.title-input:hover { border-color: var(--line-strong) !important; }
.title-input:focus { border-color: var(--accent) !important; background: #fff !important; }
.editor-actions { display: flex; align-items: center; gap: 8px; }

.editor-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 232px minmax(0, 1fr) 400px; }
.pages-panel, .form-panel { background: #fff; min-height: 0; display: flex; flex-direction: column; }
.pages-panel { border-right: 1px solid var(--line); }
.form-panel { border-left: 1px solid var(--line); }
.panel-head { padding: 12px 16px; font-weight: 600; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }

.page-list { list-style: none; margin: 0; padding: 12px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; counter-reset: pg; }
.page-item { position: relative; display: flex; gap: 6px; align-items: flex-start; }
.page-num { width: 18px; flex: none; text-align: right; font-size: 12px; color: var(--muted); padding-top: 2px; }
.page-thumb {
  position: relative; border-radius: 6px; overflow: hidden; outline: 2px solid transparent; outline-offset: 1px;
  box-shadow: 0 0 0 1px var(--line); cursor: pointer; background: #eee; flex: none;
}
.page-item.active .page-thumb { outline-color: var(--accent); }
.page-tools {
  position: absolute; right: 4px; bottom: 4px; display: none; gap: 2px;
  background: rgba(255,255,255,.95); border-radius: 7px; padding: 2px; box-shadow: 0 1px 6px rgba(0,0,0,.18);
}
.page-item:hover .page-tools, .page-item.active .page-tools { display: flex; }
.page-tools .btn { width: 24px; height: 22px; font-size: 12px; border: none; }
.page-tools .btn.danger:hover { color: var(--danger); }
.page-flag { position: absolute; left: 30px; top: 4px; font-size: 10px; background: var(--accent); color: #fff; padding: 0 5px; border-radius: 4px; }

.stage-panel { min-width: 0; min-height: 0; overflow: auto; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.stage { width: 100%; max-width: 1100px; border-radius: 6px; box-shadow: 0 6px 30px rgba(16,24,40,.16); background: #fff; overflow: hidden; }
.stage-foot { display: flex; align-items: center; gap: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 0; max-width: 760px; text-align: center; }

/* 预览中的可编辑元素 */
.stage .pptd-el.editable { cursor: pointer; }
.stage .pptd-el.editable:hover { outline: 2px dashed rgba(79,70,229,.55); outline-offset: 2px; }
.stage .pptd-el.is-active { outline: 2px solid var(--accent) !important; outline-offset: 2px; }

.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tab { flex: 1; background: none; border: none; font: inherit; font-weight: 600; color: var(--muted); padding: 12px 8px; cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 14px 16px 40px; }

.field-card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.field-card.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.field-card.flash { animation: flash 1s ease; }
@keyframes flash { 0% { background: #eef0ff; } 100% { background: #fff; } }
.field-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 8px; }
.field-label { font-weight: 600; font-size: 13px; }
.field-id { font-size: 11px; color: #9aa0aa; font-family: ui-monospace, Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-para { display: flex; gap: 6px; align-items: flex-start; margin-top: 6px; }
.field-para .inputs { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.field-para .para-tools { display: flex; flex-direction: column; gap: 2px; opacity: .35; }
.field-para:hover .para-tools, .field-para:focus-within .para-tools { opacity: 1; }
.field-modified { font-size: 11px; color: var(--accent); }
.section-title { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .5px; margin: 16px 0 8px; text-transform: uppercase; }
.section-title:first-child { margin-top: 0; }

.img-field { display: flex; gap: 10px; align-items: center; }
.img-field img { width: 96px; height: 54px; object-fit: cover; border-radius: 6px; background: #eee; box-shadow: 0 0 0 1px var(--line); }
.img-field .col { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }

.table-grid { display: grid; gap: 4px; }
.table-grid input { padding: 5px 7px; font-size: 12px; }
.table-actions { display: flex; gap: 6px; margin-top: 8px; }

.color-row { display: grid; grid-template-columns: 1fr 40px 110px; gap: 8px; align-items: center; margin-bottom: 8px; }
.color-row input[type="color"] { width: 40px; height: 32px; padding: 2px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; cursor: pointer; }
.color-row .key { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.setting { margin-bottom: 16px; }
.setting label { display: block; font-weight: 600; margin-bottom: 6px; }

/* ---------------- 弹窗 ---------------- */
.dialog { border: none; border-radius: 16px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.25); max-width: 520px; width: calc(100% - 32px); }
.dialog.wide { max-width: 1240px; max-height: calc(100vh - 48px); }
.dialog::backdrop { background: rgba(15, 18, 25, .55); }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 18px 22px; background: #fff; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0 0 4px; font-size: 18px; }
.dialog-head p { margin: 0; }
.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; padding: 20px 22px 24px; }
.preview-grid figure { margin: 0; }
.preview-grid .pptd-scaled { border-radius: 6px; box-shadow: 0 0 0 1px var(--line), 0 2px 8px rgba(0,0,0,.06); }
.preview-grid figcaption { font-size: 12px; color: var(--muted); margin-top: 6px; }

.result { padding: 26px 26px 22px; text-align: center; }
.result .icon-ok { width: 52px; height: 52px; border-radius: 50%; background: #dcfce7; color: var(--ok); display: grid; place-items: center; font-size: 26px; margin: 0 auto 12px; }
.result .icon-err { background: #fee2e2; color: var(--danger); }
.result h2 { margin: 0 0 6px; font-size: 19px; }
.result .path { text-align: left; background: #f5f6f8; border-radius: 8px; padding: 8px 10px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; margin: 14px 0; }
.result pre { text-align: left; max-height: 220px; overflow: auto; background: #f5f6f8; padding: 10px; border-radius: 8px; font-size: 12px; white-space: pre-wrap; }
.result .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.history { max-width: 1200px; margin: 0 auto; background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.history-row { display: grid; grid-template-columns: 1fr 160px 90px 110px; gap: 12px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.history-row:last-child { border-bottom: none; }
.history-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-row .folder { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.overlay { position: fixed; inset: 0; background: rgba(15,18,25,.45); display: grid; place-items: center; z-index: 100; }
.busy-card { background: #fff; padding: 24px 32px; border-radius: 14px; display: flex; gap: 14px; align-items: center; font-weight: 600; box-shadow: var(--shadow); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #e0e7ff; border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #111827; color: #fff; padding: 9px 16px; border-radius: 10px; z-index: 120; font-size: 13px; box-shadow: var(--shadow); }

/* ---------------- 幻灯片渲染基础样式 ---------------- */
.pptd-page p { margin: 0; }
.pptd-page ul, .pptd-page ol { margin: 0; padding-left: 1.3em; }
.pptd-page li { margin: 0; }
.pptd-page a { color: #2563eb; text-decoration: underline; }
.pptd-page img { user-select: none; }
.pptd-text-inner { width: 100%; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1180px) {
  .editor-body { grid-template-columns: 180px minmax(0, 1fr) 340px; }
}
@media (max-width: 900px) {
  .view.editor { height: auto; }
  .editor-body { grid-template-columns: 1fr; }
  .pages-panel { max-height: 220px; }
  .page-list { flex-direction: row; overflow-x: auto; }
  .editor-bar { flex-wrap: wrap; }
  .history-row { grid-template-columns: 1fr 100px; }
  .history-row .hide-sm { display: none; }
}
.cell-box { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cell-box textarea { padding: 5px 7px; font-size: 12px; min-height: 30px; }
