.admin-editor-markdown {
  --admin-editor-markdown-min-height: 320px;
  display: grid;
  grid-template-rows: auto auto;
  gap: 6px;
  min-width: 0;
  min-height: var(--admin-editor-markdown-min-height);
}

.admin-editor-markdown-head {
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.admin-editor-markdown-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.admin-editor-markdown-toggle {
  width: auto;
  min-width: 32px;
  height: 20px;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--admin-border);
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Monaco,
    Consolas,
    "Liberation Mono",
    "Courier New",
    monospace;
  font-weight: 800;
  color: var(--admin-muted);
  line-height: 1;
}

.admin-editor-markdown-copy.is-floating {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
}

.admin-editor-markdown-toggle.is-on {
  border-color: var(--admin-accent-soft-border);
  background: var(--admin-accent-weak);
  color: var(--admin-text);
}

.admin-editor-markdown-toggle:hover {
  border-color: rgba(96, 100, 108, 0.35);
}

.admin-editor-markdown-toggle:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.admin-editor-markdown-surface {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto;
  width: 100%;
  min-height: var(--admin-editor-markdown-surface-min-height, 0);
  border: 1px solid var(--admin-border);
  border-radius: var(--r);
  background: #fff;
  overflow: hidden;
  position: relative;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.admin-editor-markdown-formatted,
.admin-editor-markdown-textarea {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
  min-width: 0;
  min-height: var(--admin-editor-markdown-surface-min-height, 0);
  box-sizing: border-box;
}

.admin-editor-markdown-formatted[hidden],
.admin-editor-markdown-textarea[hidden] {
  display: none !important;
}

.admin-editor-markdown-formatted {
  padding: 1.2rem 54px 1.2rem 1.2rem;
  box-sizing: border-box;
  overflow: auto;
  outline: none;
  cursor: text;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-editor-markdown-formatted > *,
.admin-editor-markdown-formatted [contenteditable="true"],
.admin-markdown-block,
.admin-markdown-block-content,
.admin-markdown-code-content {
  outline: none;
  cursor: text;
}

.admin-markdown-block {
  position: relative;
  min-height: auto;
  margin: 0;
  border: none;
  background: transparent;
  color: var(--admin-text);
  font: inherit;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  caret-color: var(--admin-text);
  border-radius: 12px;
  outline: none;
}

.admin-markdown-block:empty::before,
.admin-markdown-block-content:empty::before,
.admin-markdown-code-content:empty::before {
  content: "";
  display: inline-block;
}

.admin-markdown-block-paragraph {
  font-size: 14px;
  line-height: 1.6;
}

.admin-markdown-block-h1 {
  font-size: 30px;
  line-height: 1.18;
  font-weight: 800;
  padding-bottom: 2px;
}

.admin-markdown-block-h2 {
  font-size: 24px;
  line-height: 1.24;
  font-weight: 800;
  padding-bottom: 2px;
}

.admin-markdown-block-h3 {
  font-size: 20px;
  line-height: 1.3;
  font-weight: 800;
  padding-bottom: 2px;
}

.admin-markdown-block + .admin-markdown-block-h1 {
  padding-top: 25px;
}

.admin-markdown-block + .admin-markdown-block-h2 {
  padding-top: 20px;
}

.admin-markdown-block + .admin-markdown-block-h3 {
  padding-top: 15px;
}

.admin-markdown-block-bullet {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 1px 0;
  font-size: 14px;
  line-height: 1.6;
}

.admin-markdown-block-bullet::before {
  content: "•";
  font-size: 1em;
  line-height: 1;
  display: flex;
  align-items: center;
}

.admin-markdown-bullet-marker {
  display: none;
}

.admin-markdown-block-checklist {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 1px 0;
  font-size: 14px;
  line-height: 1.6;
}

.admin-markdown-check {
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(55, 53, 47, 0.24);
  border-radius: 4px;
  background: #fff;
  color: var(--admin-text);
  cursor: pointer;
  transform: translateY(0);
}

.admin-markdown-check:hover {
  background: rgba(55, 53, 47, 0.04);
}

.admin-markdown-check:focus-visible {
  outline: 2px solid rgba(96, 100, 108, 0.18);
  outline-offset: 2px;
}

.admin-markdown-block-checklist[data-checked="true"] .admin-markdown-check {
  background: rgba(55, 53, 47, 0.82);
  border-color: rgba(55, 53, 47, 0.82);
}

.admin-markdown-block-checklist[data-checked="true"] .admin-markdown-check::after {
  content: "";
  width: 8px;
  height: 4px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}

.admin-markdown-block-checklist[data-checked="true"] .admin-markdown-block-content {
  opacity: 0.6;
  text-decoration: line-through;
}

.admin-markdown-block-checklist.checked .text {
  opacity: 0.6;
  text-decoration: line-through;
}

.admin-markdown-block-content {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 1.45em;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
  cursor: text;
}

.admin-markdown-separator-block {
  padding: 9px 0;
  cursor: default;
}

.admin-markdown-separator-line {
  height: 1px;
  background: var(--admin-border);
}

.admin-markdown-inline-code {
  display: inline;
  padding: 0.2em 0.4em;
  border-radius: 6px;
  background: rgba(135, 131, 120, 0.15);
  border: none;
  font: inherit;
  color: #eb5757;
  vertical-align: baseline;
  line-height: 1.1;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.admin-markdown-code-block {
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 1px solid var(--admin-border);
  border-radius: 14px;
  background: #f7f7f8;
  overflow: hidden;
  line-height: normal;
  white-space: normal;
  word-break: normal;
}

.admin-markdown-code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  margin: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--admin-border);
  background: #f1f3f5;
}

.admin-markdown-code-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--admin-muted);
}

.admin-markdown-code-copy {
  border: 1px solid var(--admin-border);
  background: #fff;
  border-radius: 10px;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--admin-text);
  cursor: pointer;
}

.admin-markdown-code-copy:hover {
  filter: brightness(0.98);
}

.admin-markdown-code-content {
  min-height: 60px;
  margin: 0;
  padding: 12px;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.75;
  color: var(--admin-text);
  background: #f7f7f8;
  cursor: text;
}

.admin-editor-markdown-textarea {
  width: 100%;
  border: none;
  resize: none;
  padding: 1.2rem 54px 1.2rem 1.2rem;
  box-sizing: border-box;
  overflow: auto;
  min-height: var(--admin-editor-markdown-surface-min-height, 0);
  height: auto;
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Monaco,
    Consolas,
    "Liberation Mono",
    "Courier New",
    monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  outline: none;
  color: var(--admin-text);
  background: transparent;
}

.admin-editor-markdown-textarea:focus {
  outline: none;
  box-shadow: none;
}

.admin-editor-markdown-surface:focus-within {
  border-color: rgba(55, 53, 47, 0.2);
  box-shadow: 0 0 0 1px rgba(55, 53, 47, 0.08);
}

.admin-editor-markdown.is-disabled .admin-editor-markdown-formatted {
  pointer-events: none;
}

.admin-editor-markdown.is-disabled .admin-editor-markdown-surface {
  opacity: 0.72;
}

.admin-markdown-command-menu {
  position: fixed;
  z-index: 3000;
  width: min(220px, calc(100vw - 20px));
  border: 1px solid var(--admin-border);
  border-radius: var(--r);
  background: #fff;
  box-shadow: var(--admin-shadow);
  padding: 6px;
}

.admin-markdown-command-menu[hidden] {
  display: none !important;
}

.admin-markdown-command-option {
  width: 100%;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border: 1px solid transparent;
  border-radius: calc(var(--r) - 2px);
  background: #fff;
  padding: 6px 10px;
  color: var(--admin-text);
  text-align: left;
  font: inherit;
  font-size: var(--admin-fs-sm);
  font-weight: var(--admin-fw-medium);
  line-height: var(--admin-lh-normal);
  cursor: pointer;
}

.admin-markdown-command-option:hover,
.admin-markdown-command-option.is-active {
  border-color: transparent;
}

.admin-markdown-command-option:hover {
  background: rgba(55, 53, 47, 0.06);
}

.admin-markdown-command-option.is-active {
  background: rgba(55, 53, 47, 0.08);
}

.admin-markdown-command-option-title {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--admin-text);
}
