/* 管理页样式：仿 Shopify 后台（Polaris）的观感，不依赖外部组件库 */
:root {
  --bg: #f1f1f1; --surface: #fff; --surface-2: #f7f7f7; --text: #303030; --muted: #616161; --subtle: #8a8a8a;
  --border: #e3e3e3; --border-strong: #c9c9c9; --primary: #303030; --primary-text: #fff; --accent: #005bd3;
  --danger: #8e1f0b; --danger-bg: #fee9e8; --ok: #0c5132; --ok-bg: #cdfee1; --warn: #5e4200; --warn-bg: #ffef9d;
  --radius: 10px; --shadow: 0 1px 0 rgba(0,0,0,.07), 0 0 0 1px rgba(0,0,0,.06);
  --left-w: 340px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* 按钮 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 30px; padding: 5px 12px; border-radius: 8px;
  border: 0; background: var(--surface); box-shadow: inset 0 -1px 0 #b5b5b5, inset 0 0 0 1px #e3e3e3; cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { background: #fafafa; }
.btn:active { box-shadow: inset 0 1px 1px rgba(0,0,0,.15), inset 0 0 0 1px #d4d4d4; }
.btn:focus-visible, .iconbtn:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn--primary { background: var(--primary); color: var(--primary-text); box-shadow: inset 0 -1px 0 #000, 0 1px 0 rgba(0,0,0,.2); }
.btn--primary:hover { background: #1a1a1a; }
.btn--danger { color: var(--danger); }
.btn--plain { background: none; box-shadow: none; color: var(--accent); padding: 4px 6px; }
.btn--plain:hover { background: rgba(0,0,0,.04); }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 7px; border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.iconbtn:hover { background: rgba(0,0,0,.06); color: var(--text); }
.iconbtn svg, .btn svg { width: 16px; height: 16px; fill: currentColor; }

/* 卡片 / 表格（列表页） */
.page { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.page-head h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 650; }
.card { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.card + .card { margin-top: 16px; }
.card-pad { padding: 16px; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-weight: 550; color: var(--muted); background: var(--surface-2); padding: 8px 16px; border-bottom: 1px solid var(--border); }
table.list td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list td.name a { font-weight: 650; color: var(--text); text-decoration: none; }
table.list td.name a:hover { text-decoration: underline; }
td.actions { text-align: right; white-space: nowrap; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 8px; font-size: 12px; font-weight: 550; background: #e3e3e3; color: #303030; }
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.banner { display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px; background: #eaf4ff; color: #00337c; margin-bottom: 16px; }
.banner--warn { background: var(--warn-bg); color: var(--warn); }
.banner--error { background: var(--danger-bg); color: var(--danger); }

/* 下拉菜单（…） */
.menu-pop { position: absolute; z-index: 30; min-width: 160px; padding: 6px; background: var(--surface); border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.18), 0 0 0 1px rgba(0,0,0,.06); }
.menu-pop button { display: flex; width: 100%; gap: 8px; align-items: center; padding: 7px 10px; border: 0; border-radius: 6px; background: none; text-align: left; cursor: pointer; }
.menu-pop button:hover { background: var(--surface-2); }
.menu-pop button.danger { color: var(--danger); }

/* ---------- 编辑页：上栏 + 左右 ---------- */
.editor { display: grid; grid-template-rows: 52px 1fr; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .title { font-weight: 650; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.dirty-dot { color: var(--warn); font-size: 12px; font-weight: 550; }
.split { display: grid; grid-template-columns: var(--left-w) 6px 1fr; min-height: 0; }
.split.collapsed { grid-template-columns: 0 6px 1fr; }
.left { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); overflow: hidden; }
.resizer { cursor: col-resize; background: transparent; position: relative; }
.resizer:hover, .resizer.drag { background: #d9d9d9; }
.resizer button { position: absolute; top: 50%; left: -6px; width: 18px; height: 34px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer; transform: translateY(-50%); color: var(--muted); }
.right { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.tabs { display: flex; gap: 6px; padding: 10px 10px 0; }
.tab { flex: 1; padding: 7px 8px; border: 0; border-radius: 8px; background: none; cursor: pointer; font-weight: 550; color: var(--muted); }
.tab[aria-selected="true"] { background: #ebebeb; color: var(--text); }
.left-body { flex: 1; overflow: auto; padding: 10px 0 24px; }

/* 菜单树 */
.tree { list-style: none; margin: 0; padding: 0; }
.tree .tree { padding-left: 18px; }
.tree-empty { min-height: 4px; }
.node-row { display: flex; align-items: center; gap: 2px; min-height: 38px; padding: 0 6px 0 4px; border-bottom: 1px solid #f0f0f0; background: var(--surface); }
.node-row:hover { background: #fafafa; }
.node-row.selected { background: #f0f5ff; box-shadow: inset 3px 0 0 var(--accent); }
.node-row.muted .node-title { color: var(--subtle); }
.drag { cursor: grab; color: #b5b5b5; padding: 4px 2px; display: inline-flex; }
.drag svg { width: 14px; height: 14px; fill: currentColor; }
.caret { width: 22px; height: 22px; border: 0; background: none; cursor: pointer; color: var(--muted); border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; }
.caret:hover { background: rgba(0,0,0,.06); }
.caret svg { width: 12px; height: 12px; fill: currentColor; transition: transform .12s; }
.caret[aria-expanded="true"] svg { transform: rotate(90deg); }
.caret-space { width: 22px; flex: none; }
.node-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; padding: 8px 0; }
.node-tag { font-size: 11px; color: var(--subtle); margin-left: 6px; }
.node-actions { display: none; gap: 2px; }
.node-row:hover .node-actions, .node-row:focus-within .node-actions { display: inline-flex; }
.add-row { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 6px; background: #f6f8fb; border-bottom: 1px solid #eef0f3; }
.add-row .or { display: inline-flex; width: 20px; height: 20px; align-items: center; justify-content: center; border-radius: 50%; background: #c9cccf; color: #fff; font-size: 10px; font-weight: 700; }
.add-new { display: flex; justify-content: center; padding: 12px; }
.sortable-ghost > .node-row { background: #e6efff; opacity: .7; }
.sortable-chosen > .node-row { background: #f0f5ff; }

/* 表单 */
.form { padding: 4px 14px 20px; }
.form-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px 10px; border-bottom: 1px solid var(--border); }
.form-head .t { font-weight: 650; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-title { margin: 18px -14px 10px; padding: 8px 14px; background: #f3f5f9; font-weight: 650; }
.field { margin: 12px 0; }
.field > label, .field > .label { display: block; margin-bottom: 4px; font-weight: 500; }
.field .help { margin-top: 4px; color: var(--muted); font-size: 12px; }
.input, select.input, textarea.input { width: 100%; min-height: 32px; padding: 5px 10px; border: 1px solid #8a8a8a; border-radius: 8px; background: #fff; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.input--sm { width: 90px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; margin: 10px 0; cursor: pointer; }
.switch { position: relative; width: 32px; height: 18px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 10px; background: #8a8a8a; transition: background .12s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: #fff; transition: transform .12s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { padding: 7px 4px; border: 0; border-radius: 6px; background: #e6e6e6; cursor: pointer; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--primary); color: #fff; }
.seg button[disabled] { opacity: .45; cursor: default; }
.seg--icons { grid-template-columns: repeat(3, 44px); }
.seg svg { width: 16px; height: 16px; fill: currentColor; vertical-align: middle; }
.color-row { display: flex; gap: 6px; align-items: center; }
.color-row input[type=color] { width: 34px; height: 32px; padding: 2px; border: 1px solid #8a8a8a; border-radius: 8px; background: #fff; cursor: pointer; }
.link-box { display: flex; flex-direction: column; gap: 6px; }
.link-chosen { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.link-chosen span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.img-box { display: flex; flex-direction: column; gap: 8px; }
.img-box img { max-width: 100%; max-height: 160px; object-fit: contain; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }

/* 预览 */
.preview-wrap { flex: 1; min-height: 0; overflow: auto; padding: 16px; background: repeating-linear-gradient(135deg, #f4f4f4 0 6px, #ececec 6px 7px); display: flex; justify-content: center; }
.preview-frame { width: 100%; height: 100%; min-height: 600px; border: 0; background: #fff; box-shadow: var(--shadow); border-radius: 6px; }
.preview-wrap.mobile .preview-frame { width: 390px; flex: none; }
.preview-bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--surface); border-top: 1px solid var(--border); }
.preview-bar .grow { flex: 1; }
.devices { display: inline-flex; gap: 2px; padding: 2px; border-radius: 8px; background: #ebebeb; }
.devices button { width: 34px; height: 28px; border: 0; border-radius: 6px; background: none; cursor: pointer; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.devices button[aria-pressed="true"] { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.devices svg { width: 16px; height: 16px; fill: currentColor; }

/* 弹窗 */
.modal-back { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0,0,0,.45); }
.modal { display: flex; flex-direction: column; width: min(760px, 100%); max-height: calc(100vh - 40px); background: var(--surface); border-radius: 14px; box-shadow: 0 20px 40px rgba(0,0,0,.3); }
.modal--wide { width: min(880px, 100%); }
.modal--narrow { width: min(460px, 100%); }
.modal-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: 14px 14px 0 0; }
.modal-head h2 { flex: 1; margin: 0; font-size: 15px; font-weight: 650; }
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

/* 模板卡片 */
.tpl-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tpl-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.tpl { position: relative; height: 210px; padding: 0; overflow: hidden; border: 2px solid transparent; border-radius: 6px; background: #ececec; cursor: pointer; text-align: left; }
.tpl:hover, .tpl:focus-visible { border-color: var(--accent); outline: none; }
.tpl-thumb { position: absolute; left: 6px; top: 6px; width: 200%; transform: scale(.5); transform-origin: 0 0; pointer-events: none; }
.tpl-thumb .obysm-panel { position: static; visibility: visible; opacity: 1; transform: none; }
.tpl-name { position: absolute; left: 8px; bottom: 8px; padding: 3px 8px; background: #6b6b6b; color: #fff; font-weight: 650; border-radius: 3px; }
.tpl-blank { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 32px; color: #b5b5b5; }

/* 发布前问题列表 */
.issues { margin: 0; padding: 0; list-style: none; }
.issues li { display: flex; gap: 8px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--border); }
.issues li button { margin-left: auto; }
.lvl-error { color: var(--danger); font-weight: 650; }
.lvl-warning { color: var(--warn); font-weight: 650; }

/* 批量添加 */
.multi-rows { display: flex; flex-direction: column; gap: 8px; padding: 12px; background: #e9ecef; border-radius: 10px; }
.multi-row { display: grid; grid-template-columns: 1fr 1fr 28px; gap: 8px; align-items: start; }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; height: 60vh; color: var(--muted); }
