/* Unified editor blocks and preset color palette. */
.format-bar > .color-preset-trigger {
  position: relative;
  display: grid;
  width: 36px;
  height: 32px;
  flex: 0 0 auto;
  cursor: pointer;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
}

.format-bar > .color-preset-trigger:hover,
.format-bar > .color-preset-trigger[aria-expanded="true"] {
  border-color: var(--border);
  background: var(--surface-hover);
  color: var(--text);
}

.color-preset-trigger b { margin-top: -3px; font: 650 13px/1 var(--font-sans); }
.color-preset-trigger > span {
  position: absolute;
  right: 9px;
  bottom: 5px;
  left: 7px;
  height: 3px;
  border-radius: 999px;
  background: var(--selected-color);
  box-shadow: 0 0 0 .5px color-mix(in srgb, var(--text) 18%, transparent);
}
.color-preset-trigger > span.is-transparent {
  background: linear-gradient(135deg, transparent 42%, #d14343 43% 56%, transparent 57%), #fff;
}
.color-preset-trigger > svg {
  position: absolute;
  right: 2px;
  bottom: 3px;
  width: 9px !important;
  height: 9px !important;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.4;
}

.color-preset-popover {
  position: fixed;
  z-index: 1200;
  width: 286px;
  padding: 8px;
  border: 1px solid color-mix(in srgb, var(--border) 90%, transparent);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 18px 46px rgba(31, 35, 41, .14), 0 4px 12px rgba(31, 35, 41, .08);
}

.color-preset-popover[hidden] { display: none; }
.color-preset-popover header {
  display: flex;
  min-height: 38px;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 7px 7px;
  border-bottom: 1px solid var(--border-soft);
}
.color-preset-popover header > div { display: grid; gap: 2px; }
.color-preset-popover header strong { color: var(--text); font-size: 12px; font-weight: 650; }
.color-preset-popover header span { color: var(--text-tertiary); font-size: 9px; }
.color-preset-popover header button {
  display: grid;
  width: 28px;
  height: 28px;
  cursor: pointer;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-tertiary);
}
.color-preset-popover header button:hover { background: var(--surface-hover); color: var(--text); }
.color-preset-popover header svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 1.5; }
.color-preset-section { padding: 9px 4px 3px; }
.color-preset-section > span { display: block; margin: 0 0 7px 3px; color: var(--text-tertiary); font-size: 9px; }
.color-preset-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.color-preset-option {
  position: relative;
  display: grid;
  width: 40px;
  height: 40px;
  cursor: pointer;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
}
.color-preset-option:hover { border-color: var(--border); background: var(--surface-hover); }
.color-preset-option:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 46%, transparent); outline-offset: 1px; }
.color-preset-option i {
  position: relative;
  display: block;
  width: 22px;
  height: 22px;
  border: 1px solid color-mix(in srgb, var(--text) 15%, var(--border));
  border-radius: 50%;
  background: var(--preset-color);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #fff 24%, transparent);
}
.color-preset-option.is-transparent i { background: linear-gradient(135deg, #fff 0 44%, #d14343 45% 54%, #fff 55% 100%); }
.color-preset-option[aria-pressed="true"]::after {
  position: absolute;
  right: 4px;
  bottom: 4px;
  display: grid;
  width: 13px;
  height: 13px;
  place-items: center;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  content: "✓";
  font-size: 8px;
  font-weight: 800;
}
.color-preset-option > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* Shared visual language for all non-code special blocks. */
.special-block:not(.code-block) {
  margin: 10px 0 14px !important;
  border-color: color-mix(in srgb, var(--border) 88%, transparent) !important;
  border-radius: 12px !important;
  background: var(--surface) !important;
  box-shadow: 0 1px 2px rgba(31, 35, 41, .025), 0 8px 24px rgba(31, 35, 41, .035) !important;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.block-row.active > .special-block:not(.code-block),
.special-block:not(.code-block):focus-within {
  border-color: color-mix(in srgb, var(--accent) 32%, var(--border)) !important;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 7%, transparent), 0 10px 28px rgba(31, 35, 41, .055) !important;
}
.special-block:not(.code-block) > .special-head {
  display: flex;
  height: 42px;
  min-height: 42px;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--surface-soft) 72%, var(--surface));
}
.special-title { display: flex; min-width: 0; align-items: center; gap: 8px; }
.special-title > span:last-child { display: grid; min-width: 0; gap: 1px; }
.special-title b { color: var(--text-secondary); font-size: 11px; font-weight: 650; line-height: 1.2; }
.special-title small { color: var(--text-tertiary); font-size: 9px; font-weight: 450; line-height: 1.2; }
.special-icon {
  display: grid;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--border) 86%, transparent);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text-secondary);
}
.special-icon svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.35; }
.pane-label {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 13px;
  color: var(--text-tertiary);
  font: 600 8px/1 var(--font-sans);
  letter-spacing: .08em;
  text-transform: uppercase;
  pointer-events: none;
}

/* Feishu-like quote and a calmer callout. */
#blockEditor > .block-row.type-quote {
  min-height: 44px;
  margin: 8px 0;
  padding: 8px 12px 8px 70px !important;
  border-radius: 0 10px 10px 0;
  background: color-mix(in srgb, var(--surface-soft) 58%, transparent);
}
#blockEditor > .block-row.type-quote::before {
  top: 8px;
  bottom: 8px;
  left: 57px !important;
  width: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text-tertiary) 62%, var(--border));
}
.type-quote .block-content { color: var(--text-secondary); font-size: 14px; line-height: 1.75; }

#blockEditor > .block-row.type-callout {
  min-height: 60px;
  margin: 10px 0;
  padding: 10px 14px 10px 72px !important;
  border: 1px solid color-mix(in srgb, #d7a21d 24%, var(--border));
  border-radius: 12px;
  background: color-mix(in srgb, #fff3bd 34%, var(--surface));
  box-shadow: 0 6px 18px rgba(123, 93, 20, .035);
}
#blockEditor > .block-row.type-callout > .callout-mark {
  top: 14px;
  left: 37px !important;
  width: 30px;
  height: 30px;
  border: 1px solid color-mix(in srgb, #d7a21d 24%, var(--border));
  border-radius: 9px;
  background: color-mix(in srgb, #f5bd23 16%, var(--surface));
  color: #8b6511;
}
.type-callout .block-content { padding-block: 6px; line-height: 1.72; }
[data-theme="dark"] #blockEditor > .block-row.type-callout { background: color-mix(in srgb, #6b5316 16%, var(--surface)); }
[data-theme="dark"] #blockEditor > .block-row.type-callout > .callout-mark { color: #e6bf58; }

/* Table */
.table-block .table-head { flex-wrap: nowrap !important; }
.table-block .table-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.table-block .table-actions button {
  display: inline-flex;
  height: 28px;
  align-items: center;
  gap: 3px;
  padding: 0 7px;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 10px;
}
.table-block .table-actions button svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 1.4; }
.table-block .table-actions button:hover { border-color: var(--border); background: var(--surface); color: var(--text); }
.table-block .table-actions button.table-remove-action:hover { border-color: color-mix(in srgb, var(--danger) 24%, var(--border)); color: var(--danger); }
.table-block .table-actions button:disabled { cursor: not-allowed; opacity: .32; }
.table-block table { min-width: 480px; }
.table-block th,
.table-block td { border-color: var(--border-soft); }
.table-block th { background: color-mix(in srgb, var(--surface-soft) 80%, var(--surface)); }
.table-block .table-cell { min-height: 42px; padding: 9px 11px; font-size: 12.5px; line-height: 1.65; }
.table-block th .table-cell { color: var(--text-secondary); font-weight: 650; }
.table-block .table-cell:focus { outline: none; box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 72%, transparent); background: color-mix(in srgb, var(--accent-soft) 42%, var(--surface)); }
.table-block .table-tip {
  display: flex;
  min-height: 30px;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-top: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--surface-soft) 62%, var(--surface));
  color: var(--text-tertiary);
  font-size: 9px;
}
.table-block .table-tip svg { width: 13px; height: 13px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 1.25; }

/* Formula */
.formula-block .formula-layout { display: grid; min-height: 170px; grid-template-columns: minmax(230px, .82fr) minmax(280px, 1.18fr); }
.formula-source-pane,
.formula-preview-pane { position: relative; min-width: 0; }
.formula-source-pane { border-right: 1px solid var(--border-soft); background: color-mix(in srgb, var(--surface-soft) 64%, var(--surface)); }
.formula-block .formula-source {
  width: 100%;
  min-height: 170px;
  padding: 34px 16px 16px !important;
  resize: vertical;
  border: 0 !important;
  background: transparent !important;
  font-size: 13px;
  line-height: 1.72;
}
.formula-preview-pane { background: var(--surface); }
.formula-block .formula-preview { min-height: 170px; padding: 36px 20px 20px !important; }
.block-shortcut { display: inline-flex; align-items: center; gap: 3px; margin-left: auto; color: var(--text-tertiary); font-size: 9px; }
.block-shortcut kbd { display: inline-grid; min-width: 16px; height: 17px; place-items: center; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); box-shadow: 0 1px 0 var(--border); font: inherit; }

/* Diagram and mind map */
.diagram-head { height: auto !important; min-height: 42px !important; }
.diagram-actions { display: flex; min-width: 0; align-items: center; gap: 4px; margin-left: auto; }
.diagram-status { margin: 0 3px 0 0; white-space: nowrap; color: var(--text-tertiary); font-size: 9px; }
.diagram-size-reset,
.diagram-source-toggle {
  display: inline-flex;
  height: 28px;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 10px;
}
.diagram-size-reset svg,
.diagram-source-toggle svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.35; }
.diagram-size-reset:hover,
.diagram-source-toggle:hover { border-color: var(--border); background: var(--surface); color: var(--text); }
.diagram-block .diagram-layout { display: grid; min-height: 280px; align-items: stretch; grid-template-columns: minmax(230px, .8fr) minmax(300px, 1.2fr); }
.diagram-block .diagram-layout.source-hidden { grid-template-columns: minmax(0, 1fr); }
.diagram-source-pane,
.diagram-preview-pane { position: relative; min-width: 0; }
.diagram-source-pane { border-right: 1px solid var(--border-soft); background: color-mix(in srgb, var(--surface-soft) 64%, var(--surface)); }
.diagram-source-pane.is-hidden { display: none; }
.diagram-block .diagram-source { width: 100%; min-height: 280px; padding: 34px 16px 16px !important; border: 0 !important; background: transparent !important; font-size: 12.5px; line-height: 1.72; }
.diagram-preview-pane { padding: 28px 12px 12px; background: var(--surface); }
.diagram-preview-pane > .pane-label { top: 10px; left: 13px; }
.diagram-block .diagram-preview {
  max-width: 100%;
  margin: 0 auto !important;
  border: 1px solid color-mix(in srgb, var(--border) 78%, transparent);
  border-radius: 10px;
  background-color: color-mix(in srgb, var(--surface-soft) 26%, var(--surface));
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 52%, transparent);
}

@media (max-width: 760px) {
  .special-block:not(.code-block) > .special-head { height: auto; min-height: 42px; padding-block: 6px; }
  .special-title small { display: none; }
  .diagram-status { display: none; }
  .diagram-block .diagram-layout,
  .formula-block .formula-layout { display: block; }
  .diagram-source-pane,
  .formula-source-pane { border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .diagram-block .diagram-source { min-height: 170px; }
  .formula-block .formula-source { min-height: 120px; }
  .formula-block .formula-preview { min-height: 135px; }
  .diagram-preview-pane { padding-inline: 8px; }
  .diagram-block .diagram-preview { width: 100% !important; min-width: 100%; resize: vertical; }
}

@media (max-width: 620px) {
  .color-preset-popover { width: min(286px, calc(100vw - 20px)); }
  .color-preset-grid { grid-template-columns: repeat(6, 1fr); }
  .color-preset-option { width: 100%; min-width: 38px; }
  #blockEditor > .block-row.type-quote { padding-left: 54px !important; }
  #blockEditor > .block-row.type-quote::before { left: 43px !important; }
  #blockEditor > .block-row.type-callout { padding-left: 62px !important; }
  #blockEditor > .block-row.type-callout > .callout-mark { left: 31px !important; width: 26px; height: 26px; }
  .table-block .table-head { align-items: flex-start !important; flex-wrap: wrap !important; }
  .table-block .table-actions { width: 100%; overflow-x: auto; margin-left: 34px; }
  .table-block .table-actions button { min-width: 48px; flex: 1; justify-content: center; }
  .table-block .table-tip span { line-height: 1.45; }
  .diagram-actions { gap: 2px; }
  .diagram-size-reset,
  .diagram-source-toggle { padding-inline: 6px; }
  .block-shortcut { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .color-preset-trigger,
  .color-preset-option,
  .special-block:not(.code-block) { transition: none; }
}
