:root {
  --brand: #2b6177;
  --brand-dark: #1e4b5d;
  --brand-light: #e8f2f5;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #15803d;
  --success-bg: #ecfdf5;
  --warning: #b45309;
  --warning-bg: #fffbeb;
  --ink: #1e293b;
  --ink-secondary: #475569;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --surface: #ffffff;
  --canvas: #f1f5f9;
  --sidebar: #f8fafc;
  --soft-blue: #eff6ff;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .07), 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, .08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, .14);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { min-width: 1200px; height: 100%; margin: 0; }
body {
  color: var(--ink);
  background: var(--canvas);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}
[hidden] { display: none !important; }

/* 基礎佈局 */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* 左側主選單 */
.app-sidebar {
  position: relative;
  width: 250px;
  flex: 0 0 250px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-radius: 8px;
  font: 700 20px/1 "Microsoft JhengHei", sans-serif;
  box-shadow: 0 4px 10px rgba(37, 99, 235, .25);
}

.brand strong { display: block; font-size: 17px; color: var(--ink); letter-spacing: .02em; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; }

.sidebar-label {
  margin: 20px 20px 8px;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
}

.app-nav { display: grid; }
.nav-parent, .nav-child { border: 0; background: transparent; text-align: left; text-decoration: none; }
.nav-parent {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-secondary);
}
.nav-icon { color: #64748b; font-size: 20px; }
.nav-chevron { font-size: 13px; color: #94a3b8; }
.nav-child {
  padding: 10px 20px 10px 54px;
  color: var(--ink-secondary);
  font-size: 15px;
  border-left: 3px solid transparent;
  transition: .15s;
}
.nav-child:hover { background: #f1f5f9; color: var(--ink); }
.nav-child.active {
  color: var(--primary);
  background: #eff6ff;
  border-left-color: var(--primary);
  font-weight: 700;
}

.sidebar-note {
  margin: auto 16px 20px;
  padding: 16px;
  color: var(--ink-secondary);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}
.sidebar-note strong { display: block; margin: 6px 0 3px; color: var(--ink); font-size: 15px; }

.demo-chip {
  display: inline-flex;
  padding: 3px 8px;
  color: var(--brand);
  background: var(--brand-light);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
}

/* 主工作區 */
.main-area { display: flex; flex: 1; min-width: 0; flex-direction: column; }

/* 頂部列 */
.topbar {
  display: flex;
  height: 56px;
  flex: 0 0 56px;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-left i { color: #cbd5e1; font-style: normal; margin: 0 2px; }
.topbar-left strong { color: var(--ink); font-size: 15px; }
.hamburger {
  display: grid;
  gap: 3px;
  width: 34px;
  height: 34px;
  place-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}
.hamburger span { width: 16px; height: 2px; background: #64748b; border-radius: 2px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}
.status-badge .badge-dot { width: 8px; height: 8px; border-radius: 50%; }

.status-badge.draft {
  background: var(--warning-bg);
  border: 1px solid #fde68a;
  color: var(--warning);
}
.status-badge.draft .badge-dot { background: #f59e0b; }

.status-badge.safe {
  background: var(--success-bg);
  border: 1px solid #bbf7d0;
  color: var(--success);
}
.status-badge.safe .badge-dot { background: #22c55e; }

.admin-user-pill {
  padding: 4px 10px;
  background: #f1f5f9;
  border-radius: 20px;
  font-size: 13px;
  color: var(--ink-secondary);
}

.workspace-scroll {
  flex: 1;
  overflow: auto;
  padding: 20px 28px 16px;
  display: flex;
  flex-direction: column;
}

/* 頁面標頭區塊 */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  max-width: 1680px;
  margin: 0 auto 14px;
  width: 100%;
}

.page-title-group { display: flex; flex-direction: column; gap: 6px; }
.page-title-row { display: flex; align-items: center; gap: 12px; }
.page-title-row h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -.01em;
}

.page-meta-row {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--ink-secondary);
  font-size: 14px;
}

.page-name-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--ink-secondary);
}
.page-name-control input {
  width: 180px;
  padding: 6px 10px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.meta-tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: #e2e8f0;
  border-radius: 6px;
  font-size: 13px;
  color: #334155;
}
.meta-tag-pill code { font-weight: 700; color: #1e293b; }

.switch-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.switch-chip input { position: absolute; opacity: 0; pointer-events: none; }
.switch-toggle {
  position: relative;
  width: 32px;
  height: 18px;
  background: #cbd5e1;
  border-radius: 18px;
  transition: .15s;
}
.switch-toggle::after {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  content: "";
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: .15s;
}
.switch-chip input:checked + .switch-toggle { background: #2563eb; }
.switch-chip input:checked + .switch-toggle::after { transform: translateX(14px); }

/* 操作按鈕群 */
.page-actions { display: flex; align-items: center; gap: 12px; }
.history-actions, .main-actions { display: flex; align-items: center; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: all .15s ease;
  user-select: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:disabled { cursor: not-allowed; opacity: .45; transform: none; box-shadow: none; }
.btn-icon { font-size: 16px; }

.btn.primary {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(37, 99, 235, .25);
}
.btn.primary:hover { background: var(--primary-hover); }

.btn.secondary {
  color: var(--ink-secondary);
  border-color: var(--line-strong);
  background: #fff;
}
.btn.secondary:hover { background: #f8fafc; color: var(--ink); border-color: #94a3b8; }

.btn.layout {
  color: var(--brand);
  background: var(--brand-light);
  border-color: #bcd7e1;
}
.btn.layout:hover { background: #d7eaf0; border-color: #8fb9c8; }

.btn.danger { color: #dc2626; border-color: #fca5a5; }
.btn.danger:hover { background: #fef2f2; }
.btn.ghost { background: #fff; }

/* 簡易三步驟操作指引列 */
.guide-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  max-width: 1680px;
  width: 100%;
  margin: 0 auto 14px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #f8fafc 0%, #edf4f8 100%);
  border: 1px solid #d4e2ea;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.guide-step {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  color: #fff;
  background: var(--brand);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
}

.step-content { display: flex; flex-direction: column; }
.step-content strong { font-size: 14px; color: var(--ink); }
.step-content span { font-size: 12px; color: var(--muted); }

.guide-arrow {
  color: #94a3b8;
  font-weight: 700;
  font-size: 16px;
  user-select: none;
}

/* 核心編輯工作區 */
.editor-workspace {
  display: grid;
  grid-template-columns: 280px minmax(760px, 1fr);
  grid-template-rows: minmax(0, 1fr);
  width: 100%;
  max-width: 1680px;
  height: calc(100vh - 225px);
  min-height: 560px;
  margin: 0 auto;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}

/* 左側小工具面板 */
.component-panel {
  display: flex;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  flex-direction: column;
  background: #f8fafc;
  border-right: 1px solid var(--line);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid #edf2f7;
}
.panel-heading h2 { margin: 0; font-size: 18px; font-weight: 700; color: var(--ink); }
.panel-sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.count-chip {
  padding: 3px 8px;
  color: #475569;
  background: #e2e8f0;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
}

.component-search { position: relative; display: block; margin: 12px 16px; }
.component-search span {
  position: absolute;
  top: 9px;
  left: 11px;
  color: #94a3b8;
  font-size: 18px;
}
.component-search input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-size: 14px;
}

.component-groups {
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: scroll;
  overscroll-behavior: contain;
  padding: 0 16px 12px;
  scrollbar-gutter: stable;
}
.component-group + .component-group { margin-top: 14px; }
.component-group h3 {
  margin: 0 2px 8px;
  color: #64748b;
  font-size: 13px;
  font-weight: 700;
}

.component-list { display: grid; gap: 8px; }

.component-item {
  display: grid;
  grid-template-columns: 1fr 28px;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: grab;
  text-align: left;
  transition: all .15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.component-item:hover {
  border-color: #93c5fd;
  box-shadow: 0 3px 10px rgba(37, 99, 235, .1);
  transform: translateY(-1px);
}
.component-item:active { cursor: grabbing; }

.component-item strong { display: block; color: var(--ink); font-size: 15px; font-weight: 700; }
.component-item small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

.component-plus {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: #3b82f6;
  background: #eff6ff;
  border-radius: 6px;
  font-size: 18px;
  font-weight: 700;
  transition: .15s;
}
.component-item:hover .component-plus {
  color: #fff;
  background: var(--primary);
}

.drag-tip {
  display: flex;
  gap: 10px;
  margin: 10px 16px 14px;
  padding: 12px;
  color: #334155;
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
}
.drag-tip .tip-icon { font-size: 18px; }
.drag-tip p { margin: 0; }

/* 右側頁面畫布 */
.canvas-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: #f1f5f9;
}

.canvas-toolbar {
  display: flex;
  height: 54px;
  flex: 0 0 54px;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.canvas-toolbar-info { display: flex; align-items: center; gap: 10px; }
.canvas-toolbar-info strong { font-size: 16px; color: var(--ink); }

.block-count-badge {
  padding: 2px 8px;
  background: #e2e8f0;
  border-radius: 10px;
  font-size: 13px;
  color: #475569;
  font-weight: 600;
}

.canvas-toolbar-tip { color: var(--muted); font-size: 13px; }

.status-dot {
  width: 9px;
  height: 9px;
  background: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 0 3px #dcfce7;
}

.canvas-viewport { flex: 1; overflow: auto; padding: 22px; }

.page-canvas {
  position: relative;
  display: grid;
  grid-template-columns: repeat(1086, minmax(0, 1fr));
  grid-auto-flow: row;
  column-gap: 0;
  row-gap: 0;
  max-width: 1120px;
  min-height: 560px;
  align-content: start;
  margin: 0 auto;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.empty-canvas {
  display: grid;
  grid-column: 1 / -1;
  width: 100%;
  min-height: 480px;
  place-items: center;
  color: #64748b;
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  text-align: center;
  font-size: 15px;
  background: #f8fafc;
}
.empty-canvas strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 18px;
}

.drop-indicator {
  position: relative;
  grid-column: 1 / -1;
  width: 100%;
  height: 40px;
  border: 2px dashed #2563eb;
  border-radius: 6px;
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
  pointer-events: none;
}
.drop-indicator::after {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 4px 14px;
  content: attr(data-label);
  color: #1d4ed8;
  background: #fff;
  border: 1px solid #93c5fd;
  border-radius: 14px;
  transform: translate(-50%, -50%);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.drop-indicator.same-row {
  position: absolute;
  z-index: 8;
  grid-column: auto;
  min-width: 0;
  min-height: 35px;
  background: #f0fdf4;
  border-color: #22c55e;
}
.drop-indicator.same-row::after { color: #166534; border-color: #86efac; }
.page-canvas.drag-active { outline: 2px solid #3b82f6; outline-offset: 3px; }

/* 畫布中的內容區塊 */
.canvas-block { 
  position: relative;
  grid-column: span var(--block-width, 1086);
  width: auto;
  min-width: 0;
  height: var(--block-height, 140px);
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: var(--block-bg, #fff);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transition: border .15s, box-shadow .15s, transform .15s;
}
.canvas-block[data-block-type="text"] {
  height: auto;
  min-height: var(--block-height, 70px);
  overflow: visible;
}
.canvas-block[data-row-start="true"] { grid-column: 1 / span var(--block-width, 1086); }
.canvas-block[data-row-start="false"] { margin-left: 0; }
.page-canvas .canvas-block:hover { outline: 1px solid #60a5fa; outline-offset: -1px; }
.page-canvas .canvas-block.selected { outline: 2px solid #2563eb; outline-offset: -2px; }
.canvas-block.dragging { opacity: .45; }

.block-control {
  position: absolute;
  z-index: 4;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.canvas-block:hover .block-control, .canvas-block.selected .block-control { opacity: 1; }

.block-control button {
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  color: #475569;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  box-shadow: var(--shadow-sm);
  transition: .15s;
}
.block-control button:hover { color: var(--primary); border-color: #93c5fd; background: #eff6ff; }
.block-drag { cursor: grab !important; }

.block-body {
  height: 100%;
  min-height: 0;
  padding: calc(var(--block-padding, 24) * 1px);
  color: var(--block-color, #24323d);
  background-color: var(--block-bg, #fff);
  border-radius: inherit;
}

.block-type-chip {
  position: absolute;
  z-index: 3;
  right: 8px;
  bottom: 7px;
  padding: 3px 8px;
  color: #64748b;
  background: rgba(241, 245, 249, .92);
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  transition: opacity .15s;
}
.canvas-block:hover .block-type-chip { opacity: 1; }

.canvas-resize-metrics {
  position: absolute;
  z-index: 7;
  right: 12px;
  bottom: 12px;
  display: none;
  gap: 5px;
  pointer-events: none;
}
.canvas-resize-metrics span {
  padding: 3px 7px;
  color: #1e3a8a;
  background: rgba(255, 255, 255, .95);
  border: 1px solid #93c5fd;
  border-radius: 4px;
  box-shadow: var(--shadow-sm);
  font-size: 12px;
  font-weight: 700;
}

.canvas-resize-handle {
  position: absolute;
  z-index: 6;
  display: none;
  padding: 0;
  background: transparent;
  border: 0;
}
.canvas-block:hover .canvas-resize-handle, .canvas-block.selected .canvas-resize-handle { display: block; }
.canvas-resize-handle.x { top: 40px; right: 0; bottom: 10px; width: 10px; cursor: ew-resize; }
.canvas-resize-handle.y { right: 10px; bottom: 0; left: 0; height: 10px; cursor: ns-resize; }
.canvas-resize-handle.xy { right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize; }
.canvas-resize-handle.x::after, .canvas-resize-handle.y::after, .canvas-resize-handle.xy::after {
  position: absolute;
  content: "";
  background: #2563eb;
  border-radius: 2px;
}
.canvas-resize-handle.x::after { top: 50%; right: 3px; width: 3px; height: 26px; transform: translateY(-50%); }
.canvas-resize-handle.y::after { bottom: 3px; left: 50%; width: 26px; height: 3px; transform: translateX(-50%); }
.canvas-resize-handle.xy::after { right: 3px; bottom: 3px; width: 8px; height: 8px; border-radius: 2px 0 0; }
body.resizing .canvas-block.is-resizing .canvas-resize-metrics { display: flex; }

/* 區塊內容排版樣式 */
.content-hero {
  display: flex;
  height: 100%;
  min-height: inherit;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
  background-image: linear-gradient(135deg, rgba(21, 59, 91, .85), rgba(36, 91, 120, .85)), var(--block-bg-image, none), radial-gradient(circle at 85% 20%, rgba(99, 179, 209, .2), transparent 32%), linear-gradient(135deg, #153b5b, #245b78);
  background-size: cover, cover, auto, auto;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: inherit;
  color: #fff;
}
.content-hero h2 { max-width: 820px; margin: 0 0 12px; font-size: clamp(28px, 3.2vw, 44px); line-height: 1.22; }
.content-hero p { max-width: 720px; margin: 0 0 20px; color: #d8e8ef; font-size: 17px; line-height: 1.6; }
.content-hero a, .content-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 20px;
  color: #fff;
  background: #2563eb;
  border-radius: 6px;
  text-decoration: none;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}

.content-heading { display: flex; height: 100%; min-height: inherit; align-items: center; }
.content-heading h2 { width: 100%; margin: 0; font-size: 32px; line-height: 1.28; }
.content-heading h3 { width: 100%; margin: 0; font-size: 26px; line-height: 1.3; }
.content-heading h4 { width: 100%; margin: 0; font-size: 22px; line-height: 1.35; }

.content-text { height: auto; min-height: 100%; overflow: visible; font-size: 17px; line-height: 1.65; }
.content-text p { margin: 0 0 1em; }
.content-text > :first-child { margin-top: 0; }
.content-text > :last-child { margin-bottom: 0; }

.content-image {
  position: relative;
  display: block;
  height: 100%;
  min-height: inherit;
  margin: 0;
  padding: calc(var(--block-padding, 0) * 1px);
  overflow: hidden;
  background: #f1f5f9;
}
.content-image img { display: block; width: 100%; height: 100%; min-height: 0; object-fit: cover; }
.image-placeholder {
  display: grid;
  height: 100%;
  min-height: 0;
  place-items: center;
  color: #64748b;
  background: linear-gradient(135deg, #f1f5f9 25%, #f8fafc 25%, #f8fafc 50%, #f1f5f9 50%, #f1f5f9 75%, #f8fafc 75%);
  background-size: 24px 24px;
  text-align: center;
  font-size: 15px;
}
.content-image figcaption {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 9px 12px;
  color: #fff;
  background: linear-gradient(transparent, rgba(15, 23, 42, .8));
  font-size: 13px;
}

.content-button-wrap { display: flex; height: 100%; min-height: inherit; align-items: center; }
.content-button.secondary { color: #1e4b5d; background: #e0f2fe; border: 1px solid #bae6fd; }
.content-button.outline { color: #0284c7; background: transparent; border: 1px solid #38bdf8; }

.content-alert {
  height: 100%;
  min-height: inherit;
  padding: 18px 22px;
  color: #1e3a8a;
  background: #eff6ff;
  border: 0;
  border-radius: 0;
  font-size: 16px;
}
.content-alert.warning { color: #854d0e; background: #fefce8; }
.content-alert.success { color: #166534; background: #f0fdf4; }
.content-alert strong { display: block; margin-bottom: 5px; font-size: 17px; }
.content-alert p { margin: 0; font-size: 15px; line-height: 1.55; }

.content-columns { display: grid; height: 100%; min-height: inherit; grid-template-columns: 1fr 1fr; gap: 16px; }
.content-columns > div { padding: 18px; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; }
.content-columns h3 { margin: 0 0 8px; font-size: 19px; }
.content-columns p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.55; }

.content-divider { display: flex; height: 100%; min-height: inherit; align-items: center; }
.content-divider hr { width: 100%; margin: 0; border: 0; border-top: 1px solid var(--line-strong); }
.content-divider hr.dashed { border-top-style: dashed; }
.content-divider hr.bold { border-top-width: 3px; border-top-color: #475569; }

.content-spacer {
  height: 100%;
  min-height: inherit;
  padding: 0;
  background: transparent;
  border: 0;
}

.content-html { height: 100%; min-height: inherit; overflow: auto; font-size: 16px; }
.canvas-block > .block-body, .layout-preview > .block-body { color: var(--block-color, #24323d); background-color: var(--block-bg, #fff); }
.canvas-block > .content-image, .layout-preview > .content-image { background: #fff; }
.canvas-block > .content-spacer, .layout-preview > .content-spacer { background: transparent; }
.canvas-block > .block-body :is(h1, h2, h3, h4, p, li, strong), .layout-preview > .block-body :is(h1, h2, h3, h4, p, li, strong) { color: inherit; }
.align-center { text-align: center; justify-content: center; }
.align-right { text-align: right; justify-content: flex-end; }

.app-footer {
  display: flex;
  max-width: 1680px;
  justify-content: flex-end;
  margin: 12px auto 0;
  color: var(--muted);
  font-size: 13px;
}
.save-status-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #f1f5f9;
  border-radius: 12px;
}

/* 編輯區塊對話框 */
dialog { color: var(--ink); }
.editor-dialog {
  width: min(880px, calc(100vw - 80px));
  max-height: 88vh;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}
.editor-dialog::backdrop, .preview-dialog::backdrop { background: rgba(15, 23, 42, .55); }
.editor-dialog form { display: flex; max-height: 88vh; flex-direction: column; }

.dialog-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.dialog-header h2 { margin: 0; font-size: 21px; font-weight: 700; color: var(--ink); }
.dialog-header p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.icon-close {
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  color: #64748b;
  background: #f1f5f9;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  cursor: pointer;
  font-size: 22px;
}
.icon-close:hover { background: #e2e8f0; color: var(--ink); }

.dialog-tabs { display: flex; gap: 6px; padding: 12px 24px 0; background: #fff; }
.dialog-tabs button {
  padding: 9px 16px;
  color: #64748b;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}
.dialog-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.dialog-body { flex: 1; min-height: 220px; overflow: auto; padding: 22px 24px; }
.dialog-footer {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  padding: 15px 24px;
  background: #fff;
  border-top: 1px solid var(--line);
}

.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: grid; gap: 7px; color: var(--ink-secondary); font-size: 14px; font-weight: 600; }

input, textarea, select {
  width: 100%;
  padding: 9px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-size: 15px;
}
input[readonly] { color: #64748b; background: #f8fafc; }
textarea { min-height: 110px; resize: vertical; }

.color-control {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 88px;
  align-items: center;
  gap: 10px;
}
.color-control input[type="color"] { width: 100%; height: 46px; padding: 4px; cursor: pointer; }
.color-control output {
  display: grid;
  height: 46px;
  place-items: center;
  color: #334155;
  background: #f8fafc;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font: 700 13px/1 Consolas, monospace;
}
.color-field.is-hidden { display: none; }

.form-error {
  padding: 10px 14px;
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 14px;
}

.mini-toolbar { display: flex; gap: 6px; margin-bottom: 8px; }
.mini-toolbar button {
  min-width: 34px;
  padding: 6px 10px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
}
.mini-toolbar button:hover { background: #f8fafc; }
.html-editor { min-height: 220px; font-family: Consolas, monospace; font-size: 14px; }

/* 編輯排版視窗 */
.layout-dialog {
  position: fixed;
  z-index: 50;
  inset: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}
.layout-dialog::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  content: "";
  background: rgba(15, 23, 42, .6);
}

.layout-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
}
.layout-header h2 { margin: 0 0 2px; font-size: 21px; font-weight: 700; color: var(--ink); }
.layout-header p { margin: 0; color: var(--muted); font-size: 14px; }
.layout-header-actions { display: flex; gap: 10px; }

.layout-legend {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 20px;
  padding: 11px 24px;
  color: var(--ink-secondary);
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.layout-legend span { display: flex; align-items: center; gap: 7px; }
.layout-legend strong { margin-left: auto; color: #475569; font-size: 13px; }
.layout-legend i { display: inline-block; width: 16px; height: 10px; border: 2px solid #0284c7; }
.legend-x { border-top: 0 !important; border-bottom: 0 !important; }
.legend-y { border-right: 0 !important; border-left: 0 !important; }
.legend-xy { border-radius: 2px; }

.layout-scroll { flex: 1; overflow: auto; padding: 22px; background: #e2e8f0; }

.layout-canvas {
  position: relative;
  width: 1120px;
  max-width: 100%;
  min-height: 700px;
  margin: 0 auto;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
}

.layout-grid-lines {
  position: absolute;
  inset: 18px;
  pointer-events: none;
  background: repeating-linear-gradient(to right, transparent 0, transparent 99px, #e2e8f0 99px, #e2e8f0 100px);
}

.layout-grid {
  position: relative;
  display: grid;
  z-index: 1;
  grid-template-columns: repeat(1086, minmax(0, 1fr));
  grid-auto-flow: row;
  column-gap: 0;
  row-gap: 0;
  align-content: start;
}

.layout-block {
  position: relative;
  grid-column: span var(--layout-width, 1086);
  width: auto;
  min-width: 0;
  height: calc(var(--layout-height, 160px) + 40px);
  overflow: visible;
  background: #fff;
  border: 1px solid #94a3b8;
  border-radius: 6px;
  box-shadow: 0 3px 10px rgba(0,0,0,.08);
}
.layout-block[data-row-start="true"] { grid-column: 1 / span var(--layout-width, 1086); }
.layout-block[data-row-start="false"] { margin-left: 0; }
.layout-block.dragging { opacity: .4; }

.layout-block-header {
  display: flex;
  height: 40px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: #1e3a8a;
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  border-radius: 5px 5px 0 0;
  cursor: grab;
  user-select: none;
  font-size: 14px;
}
.layout-block-header strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-toggle {
  flex: 0 0 auto;
  padding: 4px 8px;
  color: #1d4ed8;
  background: #fff;
  border: 1px solid #93c5fd;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}
.row-toggle:hover { background: #f0fdf4; border-color: #86efac; color: #15803d; }
.row-toggle.is-first { color: #94a3b8; background: #f1f5f9; border-color: #cbd5e1; cursor: default; }

.layout-metrics { display: flex; gap: 6px; margin-left: auto; }
.layout-metrics span {
  padding: 3px 7px;
  color: #475569;
  background: rgba(255, 255, 255, .9);
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
}

.layout-preview { height: var(--layout-height, 160px); overflow: hidden; pointer-events: none; opacity: 1; }
.layout-block[data-block-type="text"] { height: auto; min-height: calc(var(--layout-height, 70px) + 40px); }
.layout-block[data-block-type="text"] .layout-preview { height: auto; min-height: var(--layout-height, 70px); overflow: visible; }
.layout-preview .block-body { width: 100%; height: 100%; transform: none; }

.resize-handle { position: absolute; z-index: 5; display: block; padding: 0; background: transparent; border: 0; }
.resize-handle.x { top: 38px; right: -7px; bottom: 12px; width: 14px; cursor: ew-resize; }
.resize-handle.y { right: 12px; bottom: -7px; left: 0; height: 14px; cursor: ns-resize; }
.resize-handle.xy { right: -7px; bottom: -7px; width: 18px; height: 18px; cursor: nwse-resize; }
.resize-handle.x::after, .resize-handle.y::after, .resize-handle.xy::after {
  position: absolute;
  content: "";
  background: #2563eb;
  border-radius: 3px;
}
.resize-handle.x::after { top: 45%; right: 5px; width: 3px; height: 26px; transform: translateY(-50%); }
.resize-handle.y::after { bottom: 5px; left: 48%; width: 26px; height: 3px; transform: translateX(-50%); }
.resize-handle.xy::after { right: 4px; bottom: 4px; width: 9px; height: 9px; border-radius: 2px 0 0; }

.layout-empty {
  grid-column: 1 / -1;
  width: 100%;
  padding: 80px;
  color: #64748b;
  border: 2px dashed #cbd5e1;
  border-radius: 6px;
  text-align: center;
  font-size: 16px;
}

.layout-drop-indicator {
  position: relative;
  grid-column: 1 / -1;
  height: 42px;
  border: 2px dashed #2563eb;
  border-radius: 6px;
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
  pointer-events: none;
}
.layout-drop-indicator::after {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 5px 14px;
  content: attr(data-label);
  color: #1d4ed8;
  background: #fff;
  border: 1px solid #93c5fd;
  border-radius: 14px;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.layout-drop-indicator.same-row {
  grid-column: span var(--indicator-width, 300);
  width: auto;
  min-width: 0;
  margin-left: 0;
  background: #f0fdf4;
  border-color: #22c55e;
}
.layout-drop-indicator.same-row::after { color: #166534; border-color: #86efac; }

/* 正式前台的自訂內容區 */
.published-page {
  display: grid;
  grid-template-columns: repeat(1086, minmax(0, 1fr));
  grid-auto-flow: row;
  column-gap: 0;
  row-gap: 0;
  max-width: 1120px;
  min-height: 100%;
  align-content: start;
  margin: 0 auto;
  padding: 18px;
  background: #fff;
  box-shadow: var(--shadow-md);
}
.published-page .canvas-block { pointer-events: none; outline: 0; }
.published-page .block-control, .published-page .block-type-chip { display: none; }

/* Toast 浮動提示訊息 */
.toast {
  position: fixed;
  z-index: 100;
  right: 28px;
  bottom: 26px;
  max-width: 440px;
  padding: 14px 20px;
  color: #fff;
  background: #1e293b;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
}

@media (max-height: 760px) {
  .workspace-scroll { padding-top: 14px; }
  .editor-workspace { min-height: 500px; }
}
