/* =========================================================
   部落格視覺化 HTML 編輯器 - 樣式設定
   ========================================================= */

:root {
  --studio-bg: #eef1f5;
  --studio-surface: #ffffff;
  --studio-surface-muted: #f8fafc;
  --studio-border: #dbe2ea;
  --studio-ink: #1e293b;
  --studio-ink-muted: #64748b;
  --studio-teal: #0f766e;
  --studio-teal-hover: #0d625b;
  --studio-teal-soft: #e6f4f1;
  --studio-danger: #c2410c;
  --studio-shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --studio-shadow-md: 0 10px 28px rgba(15, 23, 42, 0.1);
}

/* 編輯器整體外框：固定 100dvh 工作台版面 */
.studio-body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--studio-bg);
  color: var(--studio-ink);
  font-family: "Noto Sans TC", system-ui, -apple-system, sans-serif;
}

/* =========================================================
   頂部主控工作列
   ========================================================= */
.studio-header {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
  padding: 0.625rem 1rem;
  background-color: var(--studio-surface);
  border-bottom: 1px solid var(--studio-border);
  box-shadow: var(--studio-shadow-sm);
  z-index: 30;
}

.studio-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background-color: var(--studio-teal);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
}

.studio-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--studio-ink);
}

.studio-subtitle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--studio-ink-muted);
}

.save-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background-color: var(--studio-teal-soft);
  color: var(--studio-teal);
  font-weight: 500;
  font-size: 0.7rem;
}

/* 頂部右側動作區 */
.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.action-divider {
  width: 1px;
  height: 22px;
  background-color: var(--studio-border);
}

.mode-switcher .mode-btn {
  border-color: var(--studio-border);
  color: var(--studio-ink-muted);
  background-color: var(--studio-surface);
  font-weight: 500;
}

.mode-switcher .mode-btn.active {
  background-color: var(--studio-teal);
  border-color: var(--studio-teal);
  color: #ffffff;
}

/* 自訂主題色按鈕 */
.btn-teal {
  background-color: var(--studio-teal);
  border-color: var(--studio-teal);
  color: #ffffff;
  font-weight: 600;
}

.btn-teal:hover,
.btn-teal:focus-visible {
  background-color: var(--studio-teal-hover);
  border-color: var(--studio-teal-hover);
  color: #ffffff;
}

.btn-outline-teal {
  border-color: var(--studio-teal);
  color: var(--studio-teal);
  background-color: transparent;
  font-weight: 500;
}

.btn-outline-teal:hover,
.btn-outline-teal:focus-visible {
  background-color: var(--studio-teal);
  border-color: var(--studio-teal);
  color: #ffffff;
}

.btn-xs {
  padding: 0.18rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 5px;
}

/* =========================================================
   三欄式工作區主體
   ========================================================= */
.studio-workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr) 310px;
}

/* HTML 同步預覽與真實預覽模式：將左右工具列抽屜收起隱藏 */
.studio-workspace.drawers-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.studio-workspace.drawers-collapsed .studio-sidebar-left,
.studio-workspace.drawers-collapsed .studio-sidebar-right {
  display: none;
}

.studio-sidebar-left,
.studio-sidebar-right {
  background-color: var(--studio-surface);
  overflow-y: auto;
  padding: 0.9rem;
}

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

.studio-sidebar-right {
  border-left: 1px solid var(--studio-border);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

/* 左側欄手風琴積木分類 */
.sidebar-top-hint {
  margin: 0 0 0.65rem;
  font-size: 0.74rem;
  color: var(--studio-ink-muted);
  line-height: 1.45;
}

.sidebar-accordion {
  border: 1px solid var(--studio-border);
  border-radius: 9px;
  background-color: var(--studio-surface-muted);
  margin-bottom: 0.55rem;
  overflow: hidden;
}

.accordion-trigger {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.58rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--studio-ink);
  background-color: var(--studio-surface);
  cursor: pointer;
  user-select: none;
}

.accordion-trigger::-webkit-details-marker {
  display: none;
}

.accordion-trigger span {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.accordion-trigger span i {
  color: var(--studio-teal);
}

.accordion-chevron {
  font-size: 0.78rem;
  color: var(--studio-ink-muted);
  transition: transform 0.18s ease;
}

.sidebar-accordion[open] .accordion-chevron {
  transform: rotate(180deg);
}

.sidebar-accordion[open] .accordion-trigger {
  border-bottom: 1px solid var(--studio-border);
}

.accordion-body {
  padding: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
}

.palette-card {
  border: 1px solid var(--studio-border);
  border-radius: 8px;
  background-color: var(--studio-surface);
  padding: 0.5rem 0.6rem;
}

.palette-card-head {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.81rem;
  font-weight: 600;
  color: var(--studio-ink);
  margin-bottom: 0.42rem;
}

.palette-card-head i {
  color: var(--studio-teal);
  font-size: 0.95rem;
}

.variant-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.variant-chip {
  flex: 1 1 auto;
  padding: 0.24rem 0.48rem;
  border: 1px solid var(--studio-border);
  border-radius: 5px;
  background-color: var(--studio-surface-muted);
  color: var(--studio-ink);
  font-size: 0.74rem;
  font-weight: 500;
  text-align: center;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.variant-chip:hover {
  border-color: var(--studio-teal);
  background-color: var(--studio-teal-soft);
  color: var(--studio-teal);
}

.palette-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--studio-border);
  border-radius: 8px;
  background-color: var(--studio-surface);
  color: var(--studio-ink);
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.12s ease;
}

.palette-btn:hover,
.palette-btn.is-active-preset {
  border-color: var(--studio-teal);
  background-color: var(--studio-teal-soft);
}

.palette-btn:active {
  transform: translateY(1px);
}

.palette-icon {
  flex: 0 0 32px;
  height: 32px;
  border-radius: 6px;
  background-color: var(--studio-surface-muted);
  border: 1px solid var(--studio-border);
  display: grid;
  place-items: center;
  color: var(--studio-teal);
  font-size: 1rem;
}

.palette-btn:hover .palette-icon {
  background-color: #ffffff;
  border-color: rgba(15, 118, 110, 0.35);
}

.palette-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.palette-text strong {
  font-size: 0.82rem;
  font-weight: 600;
}

.palette-text small {
  font-size: 0.71rem;
  color: var(--studio-ink-muted);
  margin-top: 2px;
}

/* =========================================================
   中央畫布與 WYSIWYG 工具列
   ========================================================= */
.studio-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background-color: var(--studio-bg);
}

.preview-container[hidden],
.split-container[hidden],
.canvas-scroll-area[hidden] {
  display: none !important;
}

/* 右側文字設定面板內的格式按鈕列 */
.inspector-tool-row {
  display: flex;
  flex-wrap: wrap;
  width: fit-content;
  max-width: 100%;
  gap: 0.25rem;
  padding: 0.25rem;
  background-color: #ffffff;
  border: 1px solid var(--studio-border);
  border-radius: 6px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-width: 30px;
  height: 30px;
  padding: 0 0.4rem;
  border: 1px solid transparent;
  border-radius: 5px;
  background-color: transparent;
  color: var(--studio-ink);
  font-size: 0.9rem;
}

.tool-btn[hidden] {
  display: none !important;
}

.tool-btn:hover:not(:disabled) {
  background-color: var(--studio-surface-muted);
  border-color: var(--studio-border);
}

.tool-btn.is-active {
  background-color: var(--studio-teal-soft);
  border-color: rgba(15, 118, 110, 0.4);
  color: var(--studio-teal);
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 編輯畫布捲動區 */
.canvas-scroll-area {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.5rem 1.75rem 5rem;
}

.canvas-stage {
  position: relative;
  max-width: 1240px;
  margin: 0 auto;
  background-color: #f7f8fa;
  border: 1px solid var(--studio-border);
  border-radius: 10px;
  box-shadow: var(--studio-shadow-md);
  overflow: visible;
}

/* =========================================================
   部落格文章 CSS 模擬（同步用於畫布與真實預覽 iframe）
   ========================================================= */
.noto-sans-tc {
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

.bg-post {
  background-color: #ffffff;
}

.fs-65 {
  font-size: 1rem;
  line-height: 1.85;
  color: #2b3035;
}

@media (min-width: 1200px) {
  .fs-xl-5 {
    font-size: 1.15rem;
  }
}

/* 品牌圓形 Logo 上緣重疊效果 */
.brand-logo-container {
  margin-top: -54px;
  position: relative;
  z-index: 4;
}

.brand-logo-inner {
  width: 96px;
  height: 96px;
  padding: 6px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.1);
}

.brand-logo {
  width: 100%;
  height: 100%;
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

@media (min-width: 1200px) {
  .brand-logo-container {
    margin-top: -76px;
  }

  .brand-logo-inner {
    width: 132px;
    height: 132px;
    padding: 8px;
  }
}

#articleMount article h1 {
  font-weight: 700;
  line-height: 1.4;
  font-size: clamp(1.5rem, 2.4vw, 2.1rem);
  color: #1e293b;
}

#articleMount article h2 {
  font-weight: 700;
  line-height: 1.45;
  font-size: clamp(1.25rem, 1.8vw, 1.65rem);
  color: #1e293b;
}

#articleMount article a {
  color: #0d6efd;
}

#articleMount article img {
  max-width: 100%;
}

/* 若圖片網址無法載入（例如尚未上傳的 07.jpg），於畫布內提供友善佔位邊框 */
#articleMount img[data-img-error="true"] {
  min-height: 160px;
  background: repeating-linear-gradient(-45deg,
      #f1f5f9,
      #f1f5f9 12px,
      #e2e8f0 12px,
      #e2e8f0 24px);
  border: 2px dashed #94a3b8;
  object-fit: contain;
}

/* 編輯模式中避免影片 iframe 攔截點擊，確保可順暢點選整個影片區塊 */
#articleMount iframe {
  pointer-events: none;
}

/* 編輯模式中為空白間距與空白分隔提供可視虛線提示（不影響預覽與輸出 HTML） */
#articleMount .col-xl-12>div[aria-hidden="true"][style*="height"]:not(.my-4),
#articleMount .col-xl-12>div.my-4[aria-hidden="true"]:empty {
  position: relative;
  border: 1px dashed #cbd5e1;
  border-radius: 4px;
  background-color: rgba(241, 245, 249, 0.55);
}

#articleMount .col-xl-12>div[aria-hidden="true"][style*="height"]:not(.my-4)::after {
  content: "空白間距";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  color: #64748b;
  pointer-events: none;
}

#articleMount .col-xl-12>div.my-4[aria-hidden="true"]:empty::after {
  content: "空白分隔";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  color: #64748b;
  pointer-events: none;
}

/* 空白文章狀態於視覺編輯畫布顯示提示 */
#articleMount .col-xl-12:empty {
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #dbe2ea;
  border-radius: 8px;
  margin: 1rem 0;
}

#articleMount .col-xl-12:empty::before {
  content: "目前為空白文章，請點擊左側積木開始編輯內容";
  color: #94a3b8;
  font-size: 0.9rem;
}

/* =========================================================
   畫布互動選取外框與外部浮動區塊操作列
   ========================================================= */
#articleMount .editor-block-hover {
  outline: 1.5px dashed rgba(15, 118, 110, 0.45);
  outline-offset: 4px;
  border-radius: 4px;
}

#articleMount .is-selected-block {
  outline: 2px solid var(--studio-teal) !important;
  outline-offset: 5px;
  border-radius: 4px;
}

/* 區塊內部正在編輯／選取的子元件範圍框（淡淡虛線區隔） */
#articleMount .is-selected-element {
  outline: 1.5px dashed rgba(2, 132, 199, 0.78) !important;
  outline-offset: 2px;
  border-radius: 4px;
  background-color: rgba(224, 242, 254, 0.16);
}

#articleMount .is-dragging-block {
  opacity: 0.45;
}

.block-drop-indicator {
  position: absolute;
  left: 16px;
  right: 16px;
  height: 3px;
  background-color: var(--studio-teal);
  border-radius: 999px;
  z-index: 30;
  pointer-events: none;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.block-drop-indicator[hidden] {
  display: none !important;
}

#articleMount [contenteditable="true"]:focus {
  outline: none;
}

.block-action-toolbar {
  position: absolute;
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.25rem 0.4rem;
  background-color: #0f172a;
  color: #ffffff;
  border-radius: 7px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.22);
  pointer-events: auto;
}

.block-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 26px;
  border-radius: 4px;
  color: #94a3b8;
  cursor: grab;
}

.block-drag-handle:hover {
  background-color: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.block-drag-handle:active {
  cursor: grabbing;
}

.block-drag-handle[hidden] {
  display: none !important;
}

.block-action-toolbar[hidden] {
  display: none !important;
}

.block-type-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0 0.45rem;
  color: #99f6e4;
}

.block-act-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 5px;
  background-color: transparent;
  color: #e2e8f0;
  font-size: 0.85rem;
}

.block-act-btn:hover {
  background-color: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.block-act-btn.block-act-danger:hover {
  background-color: var(--studio-danger);
  color: #ffffff;
}

/* =========================================================
   真實預覽模式與 HTML 雙欄同步預覽模式
   ========================================================= */
.preview-container,
.split-container {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.split-panes {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.split-pane-left {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--studio-border);
}

.split-pane-right {
  min-height: 0;
  overflow: auto;
  padding: 1rem;
  display: flex;
  justify-content: center;
  background-color: #dde3ea;
}

.split-pane-right .preview-iframe {
  min-height: 100%;
}

.split-width-btn.active {
  background-color: var(--studio-teal);
  border-color: var(--studio-teal);
  color: #ffffff;
}

.preview-viewport-bar,
.source-toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background-color: var(--studio-surface);
  border-bottom: 1px solid var(--studio-border);
}

.preview-bar-label,
.source-info {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--studio-ink-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.preview-width-btn.active {
  background-color: var(--studio-teal);
  border-color: var(--studio-teal);
  color: #ffffff;
}

.preview-frame-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 1.25rem;
  display: flex;
  justify-content: center;
  background-color: #dde3ea;
}

.preview-iframe {
  width: 100%;
  height: 100%;
  min-height: 600px;
  border: 1px solid var(--studio-border);
  border-radius: 10px;
  background-color: #ffffff;
  box-shadow: var(--studio-shadow-md);
  transition: width 0.2s ease;
}

.html-source-textarea {
  flex: 1 1 auto;
  width: 100%;
  border: none;
  padding: 1.15rem 1.35rem;
  background-color: #0f172a;
  color: #e2e8f0;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.65;
  resize: none;
  outline: none;
}

/* =========================================================
   右側屬性設定面板
   ========================================================= */
.inspector-card {
  border: 1px solid var(--studio-border);
  border-radius: 9px;
  padding: 0.85rem;
  background-color: var(--studio-surface-muted);
}

.inspector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.inspector-title {
  margin: 0 0 0.55rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--studio-ink);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.inspector-header .inspector-title {
  margin-bottom: 0;
}

.inspector-title i {
  color: var(--studio-teal);
}

.inspector-desc {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--studio-ink-muted);
  margin-bottom: 0.7rem;
}

.quick-tips-box {
  background-color: #ffffff;
  border: 1px solid var(--studio-border);
  border-radius: 7px;
  padding: 0.65rem 0.75rem;
  font-size: 0.75rem;
  color: var(--studio-ink-muted);
}

.tip-title {
  font-weight: 700;
  color: var(--studio-ink);
  margin-bottom: 0.35rem;
}

.quick-tips-box ul {
  margin: 0;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.img-preview-box {
  border: 1px solid var(--studio-border);
  border-radius: 7px;
  background-color: #ffffff;
  padding: 0.35rem;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 92px;
  max-height: 145px;
  overflow: hidden;
}

.img-preview-box img {
  max-width: 100%;
  max-height: 132px;
  object-fit: contain;
  border-radius: 4px;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.swatch-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #cbd5e1;
  cursor: pointer;
}

.swatch-btn:hover {
  transform: scale(1.08);
}

.text-teal {
  color: var(--studio-teal);
}

/* =========================================================
   原生 <dialog> 視窗樣式（遵循 modern-web-guidance）
   ========================================================= */
dialog {
  border: 1px solid var(--studio-border);
  border-radius: 12px;
  padding: 0;
  width: min(480px, calc(100vw - 2rem));
  max-width: 94vw;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
  background-color: var(--studio-surface);
  color: var(--studio-ink);
  margin: auto;
}

dialog.dialog-wide {
  width: min(760px, calc(100vw - 2rem));
}

/* 僅在開啟狀態設定 display，不可無條件設定 display */
dialog[open] {
  display: block;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.studio-dialog-form {
  display: flex;
  flex-direction: column;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--studio-border);
}

.dialog-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.dialog-body {
  padding: 1rem 1.1rem;
  max-height: 70dvh;
  overflow-y: auto;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.1rem;
  background-color: var(--studio-surface-muted);
  border-top: 1px solid var(--studio-border);
}

/* 通知提示 Toast */
.studio-toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  background-color: #0f172a;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
}

/* 焦點與無障礙動態減弱設定 */
:focus-visible {
  outline: 2px solid var(--studio-teal);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}

@media (max-width: 1180px) {
  .studio-workspace {
    grid-template-columns: 240px minmax(0, 1fr) 275px;
  }
}

@media (max-width: 960px) {
  .studio-body {
    height: auto;
    overflow: auto;
  }

  .studio-workspace {
    grid-template-columns: 1fr;
  }

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