/*
 * Compact chrome for fenced code + mermaid headers.
 * Desktop: language + action buttons on one short row (hamburger hidden).
 * Narrow: hamburger opens a dropdown so the bar never wraps to two lines.
 */

.code-block-wrapper {
  margin: 16px 0;
  overflow: hidden;
  border: 1px solid var(--border-color, var(--border));
  border-radius: 8px;
  background: transparent;
}

.code-block-wrapper .code-content,
.code-block-wrapper .code-content code,
.code-block-wrapper .code-content .hljs,
.code-block-wrapper .code-content .hljs * {
  background: transparent;
}

.code-block-wrapper .code-content {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
}

.code-block-wrapper .code-content code {
  display: block;
  padding: 0;
  font-family: "Cascadia Code", "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  font-variant-ligatures: none;
  line-height: 1.5;
  tab-size: 2;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  height: 24px;
  padding: 0 8px 0 10px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color, var(--border));
  font-size: 11px;
  line-height: 1;
  color: var(--text-secondary);
}

.code-block-header > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
  letter-spacing: 0.22px;
}

.code-block-menu {
  display: contents;
}

.code-block-menu-trigger,
.code-block-header button.code-block-menu-trigger,
.mermaid-mobile-fullscreen {
  display: none;
}

.code-block-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 3px;
}

.code-block-actions button {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: 18px;
  min-height: 18px;
  padding: 0 6px;
  margin: 0;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-secondary);
  font: inherit;
  font-size: 11px;
  font-weight: 650;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
  box-shadow: none;
  cursor: pointer;
}

.code-block-actions button[data-mermaid-action="fullscreen"],
.code-block-actions button[data-mermaid-action="download-png"] {
  min-width: 18px;
  padding: 0 5px;
}

.code-block-header button:hover,
.code-block-actions button:hover {
  background: var(--surface);
  color: var(--pink);
}

.code-block-actions button.code-action-success {
  color: #2e946d;
}

/* Blog has no apply-to-workspace action; keep the bar to Copy only. */
.code-block-actions button[data-action="apply-code"] {
  display: none;
}

@media (max-width: 640px) {
  .code-block-header {
    position: relative;
  }

  .code-block-menu {
    display: flex;
    position: relative;
    flex: 0 0 auto;
    align-items: center;
    gap: 3px;
  }

  .code-block-menu-trigger,
  .mermaid-mobile-fullscreen {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 18px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
  }

  .code-block-menu-trigger:hover,
  .code-block-menu-trigger:focus-visible,
  .code-block-menu.open > .code-block-menu-trigger,
  .mermaid-mobile-fullscreen:hover,
  .mermaid-mobile-fullscreen:focus-visible {
    background: var(--surface);
    color: var(--pink);
    outline: none;
  }

  .code-block-menu .code-block-actions,
  .mermaid-block .code-block-menu .code-block-actions {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 20;
    min-width: 118px;
    padding: 4px;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  .code-block-menu.open .code-block-actions {
    display: flex;
  }

  .code-block-menu .code-block-actions button {
    width: 100%;
    height: 26px;
    min-height: 26px;
    justify-content: flex-start;
    padding: 0 8px;
  }

  .code-block-wrapper:has(.code-block-menu.open) {
    overflow: visible;
  }
}
