/* Code Block Dark Theme for Leftover Labs
 * Provides dark background styling for <pre><code> blocks with copy functionality
 */

/* Base styling for all code blocks */
pre {
  position: relative;
  margin: 1em 0;
  padding: 0;
  background: transparent;
  font-size: 0.9375rem;
  border-radius: 6px;
  overflow: hidden;
}

pre code {
  display: block;
  margin: 0;
  padding: 3.5rem 1rem 1rem;
  border-radius: inherit;
  overflow-x: auto;
  font-family: 'Consolas', 'Monaco', 'Andale Mono', 'Ubuntu Mono', monospace;
  font-size: inherit;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Light mode styling */
pre code {
  background-color: #f6f8fa;
  color: #24292e;
  border: 1px solid #e1e4e8;
}

/* Dark mode styling */
[data-theme="dark"] pre code {
  background-color: #2a3c33; /* Dark green background matching project theme */
  color: #e6edf3;
  border: 1px solid #3a4d43; /* Dark border matching card-border */
}

/* Copy button styling */
.code-copy-button {
  position: absolute;
  top: 0.5em;
  right: 0.5em;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: #57606a;
  background-color: #f6f8fa;
  border: 1px solid #d0d7de;
  border-radius: 4px;
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.2s ease-in-out;
}

pre code:focus-visible,
.code-copy-button:focus-visible {
  outline: 3px solid var(--link-color, #2c6e49);
  outline-offset: -3px;
}

.code-copy-button:hover {
  background-color: #f3f4f6;
  color: #24292e;
}

/* Dark mode copy button */
[data-theme="dark"] .code-copy-button {
  color: #8bc2a8; /* Lighter green for better contrast */
  background-color: #2a3c33; /* Dark background matching code block */
  border: 1px solid #3a4d43; /* Dark border matching card-border */
}

[data-theme="dark"] .code-copy-button:hover {
  background-color: #3a4d43; /* Slightly lighter on hover */
  color: #a5d4bc;
}

/* Success state for copy button */
.code-copy-button.copied {
  color: #2c6e49; /* Darker green for better contrast in light mode */
  background-color: #e6f3eb;
}

[data-theme="dark"] .code-copy-button.copied {
  color: #f5f7f4;
  background-color: #2c6e49; /* Darker green background */
}

/* Syntax highlighting colors - light mode */
.hljs-comment,
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #57606a;
}

.token.punctuation {
  color: #24292e;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol {
  color: #005cc5;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.hljs-string,
.hljs-built_in {
  color: #032f62;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
  color: #b42335;
}

.token.atrule,
.token.attr-value,
.token.keyword,
.hljs-keyword,
.hljs-meta {
  color: #b42335;
}

.token.function,
.token.class-name,
.hljs-title {
  color: #6f42c1;
}

.token.regex,
.token.important,
.token.variable,
.hljs-variable {
  color: #953800;
}

/* Syntax highlighting colors - dark mode */
[data-theme="dark"] .hljs-comment,
[data-theme="dark"] .token.comment,
[data-theme="dark"] .token.prolog,
[data-theme="dark"] .token.doctype,
[data-theme="dark"] .token.cdata {
  color: #b0b8c1;
}

[data-theme="dark"] .token.punctuation {
  color: #e6edf3;
}

[data-theme="dark"] .token.property,
[data-theme="dark"] .token.tag,
[data-theme="dark"] .token.boolean,
[data-theme="dark"] .token.number,
[data-theme="dark"] .token.constant,
[data-theme="dark"] .token.symbol {
  color: #79c0ff;
}

[data-theme="dark"] .token.selector,
[data-theme="dark"] .token.attr-name,
[data-theme="dark"] .token.string,
[data-theme="dark"] .token.char,
[data-theme="dark"] .token.builtin,
[data-theme="dark"] .hljs-string,
[data-theme="dark"] .hljs-built_in {
  color: #a5d6ff;
}

[data-theme="dark"] .token.operator,
[data-theme="dark"] .token.entity,
[data-theme="dark"] .token.url,
[data-theme="dark"] .language-css .token.string,
[data-theme="dark"] .style .token.string {
  color: #ff7b72;
}

[data-theme="dark"] .token.atrule,
[data-theme="dark"] .token.attr-value,
[data-theme="dark"] .token.keyword,
[data-theme="dark"] .hljs-keyword,
[data-theme="dark"] .hljs-meta {
  color: #ff7b72;
}

[data-theme="dark"] .token.function,
[data-theme="dark"] .token.class-name,
[data-theme="dark"] .hljs-title {
  color: #d2a8ff;
}

[data-theme="dark"] .token.regex,
[data-theme="dark"] .token.important,
[data-theme="dark"] .token.variable,
[data-theme="dark"] .hljs-variable {
  color: #ffa657;
}

.code-example-source {
  margin: -0.5rem 0 1.5rem;
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}
