/* ==========================================================================
   ByteYogi Theme — Code Highlighting Stylesheet
   Syntax theme for both <pre><code> blocks and .code-preview components
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Pre / Code Block Base Styles
   -------------------------------------------------------------------------- */
pre {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  overflow-x: auto;
  font-family: var(--font-code);
  font-size: 14px;
  line-height: 1.7;
  margin: 24px 0;
  position: relative;
  tab-size: 4;
  -moz-tab-size: 4;
  direction: ltr;
  text-align: left;
  white-space: pre;
  word-spacing: normal;
  word-break: normal;
  word-wrap: normal;
  hyphens: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

pre::-webkit-scrollbar {
  height: 6px;
}

pre::-webkit-scrollbar-track {
  background: transparent;
}

pre::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}

pre::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

pre code {
  display: block;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  font-size: inherit;
  line-height: inherit;
  color: var(--text-secondary);
  white-space: pre;
  overflow-wrap: normal;
}

/* Language label (top-right of code block) */
pre[data-language]::before {
  content: attr(data-language);
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 11px;
  font-family: var(--font-body);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  opacity: 0.5;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

pre:hover[data-language]::before {
  opacity: 0.8;
}

/* --------------------------------------------------------------------------
   2. Highlight.js Token Colors
   -------------------------------------------------------------------------- */

/* Background for hljs */
.hljs {
  display: block;
  overflow-x: auto;
  padding: 20px 24px;
  background: var(--bg-surface);
  color: var(--text-secondary);
}

/* Keywords — if, else, return, function, const, let, var, class, import, export, etc. */
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-section,
.hljs-deletion {
  color: #c084fc;
}

/* Strings — "text", 'text', `text` */
.hljs-string,
.hljs-template-variable,
.hljs-addition {
  color: #34d399;
}

/* Functions — function names, method calls */
.hljs-function,
.hljs-name {
  color: #38bdf8;
}

/* Numbers — 42, 3.14, 0xFF */
.hljs-number {
  color: #fbbf24;
}

/* Comments — // single line, /* multi line *\/ */
.hljs-comment,
.hljs-quote {
  color: #7c8da4;
  font-style: italic;
}

/* Types — int, string, boolean, Array, Object */
.hljs-type,
.hljs-class .hljs-title,
.hljs-title.class_ {
  color: #f472b6;
}

/* Attributes — HTML attributes, JSON keys, decorators */
.hljs-attr,
.hljs-attribute,
.hljs-meta .hljs-keyword {
  color: #fbbf24;
}

/* Built-ins — console, document, Math, window */
.hljs-built_in,
.hljs-builtin-name {
  color: #38bdf8;
}

/* Title — function/class declarations */
.hljs-title,
.hljs-title.function_ {
  color: #818cf8;
}

/* Variables */
.hljs-variable,
.hljs-template-tag {
  color: #e2e8f0;
}

/* Params — function parameters */
.hljs-params {
  color: #94a3b8;
}

/* Operators — =, +, -, *, /, ==, ===, =>, etc. */
.hljs-operator {
  color: #94a3b8;
}

/* Punctuation — braces, brackets, commas, semicolons */
.hljs-punctuation {
  color: #7c8da4;
}

/* Tags — HTML tags */
.hljs-tag {
  color: #f472b6;
}

.hljs-tag .hljs-name {
  color: #f472b6;
}

.hljs-tag .hljs-attr {
  color: #fbbf24;
}

.hljs-tag .hljs-string {
  color: #34d399;
}

/* Meta — preprocessor directives, pragmas */
.hljs-meta {
  color: #64748b;
}

.hljs-meta .hljs-string {
  color: #34d399;
}

/* RegExp */
.hljs-regexp {
  color: #fb923c;
}

/* CSS Selectors */
.hljs-selector-id,
.hljs-selector-class,
.hljs-selector-pseudo {
  color: #818cf8;
}

/* CSS Properties */
.hljs-property {
  color: #38bdf8;
}

/* Symbol — :symbol, atoms */
.hljs-symbol {
  color: #c084fc;
}

/* Emphasis & Strong */
.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: 700;
}

/* Links within code */
.hljs-link {
  color: #38bdf8;
  text-decoration: underline;
}

/* Subst — template literal expressions */
.hljs-subst {
  color: #e2e8f0;
}

/* Doctag — @param, @return, @throws */
.hljs-doctag {
  color: #818cf8;
  font-weight: 600;
}

/* Formula (LaTeX, etc.) */
.hljs-formula {
  color: #fbbf24;
}

/* --------------------------------------------------------------------------
   3. Line Numbers
   -------------------------------------------------------------------------- */
.hljs-ln-numbers {
  user-select: none;
  text-align: right;
  padding-right: 16px;
  min-width: 32px;
  color: var(--text-muted);
  opacity: 0.35;
  vertical-align: top;
}

.hljs-ln-code {
  padding-left: 16px;
}

/* Code preview component line numbers */
.code-preview .ln {
  color: var(--text-muted);
  opacity: 0.35;
  user-select: none;
  min-width: 24px;
  text-align: right;
  padding-right: 16px;
  display: inline-block;
}

/* --------------------------------------------------------------------------
   4. Inline Code Styles
   -------------------------------------------------------------------------- */

/* Inline code within paragraphs and list items */
p code,
li code,
td code,
th code,
.article-content :not(pre) > code,
.page-content :not(pre) > code {
  font-family: var(--font-code);
  font-size: 0.88em;
  padding: 3px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--accent-blue);
  white-space: nowrap;
  word-break: break-word;
}

/* Inline code in headings */
h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {
  font-size: 0.85em;
  padding: 2px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--accent-blue);
}

/* Inline code in blockquotes */
blockquote code {
  background: rgba(56, 189, 248, 0.08);
  border-color: rgba(56, 189, 248, 0.15);
}

/* --------------------------------------------------------------------------
   5. Copy Code Button
   -------------------------------------------------------------------------- */
.code-copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast);
  z-index: 5;
}

.code-copy-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
  color: var(--text-secondary);
}

.code-copy-btn:active {
  transform: scale(0.95);
}

.code-copy-btn.copied {
  color: var(--accent-green);
  border-color: rgba(52, 211, 153, 0.3);
}

.code-copy-btn.copied svg {
  color: var(--accent-green);
}

.code-copy-btn .copy-label {
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   6. Code Block — Language-Specific Overrides
   -------------------------------------------------------------------------- */

/* Diff syntax */
.hljs-addition {
  background: rgba(52, 211, 153, 0.08);
  color: #34d399;
}

.hljs-deletion {
  background: rgba(248, 113, 113, 0.08);
  color: #f87171;
}

/* Shell / Bash */
.language-bash .hljs-built_in,
.language-shell .hljs-built_in,
.language-sh .hljs-built_in {
  color: #38bdf8;
}

.language-bash .hljs-variable,
.language-shell .hljs-variable {
  color: #c084fc;
}

/* JSON */
.language-json .hljs-attr {
  color: #38bdf8;
}

.language-json .hljs-string {
  color: #34d399;
}

.language-json .hljs-number {
  color: #fbbf24;
}

.language-json .hljs-literal {
  color: #c084fc;
}

/* YAML */
.language-yaml .hljs-attr {
  color: #38bdf8;
}

.language-yaml .hljs-string {
  color: #34d399;
}

/* SQL */
.language-sql .hljs-keyword {
  color: #c084fc;
}

.language-sql .hljs-built_in {
  color: #818cf8;
}

.language-sql .hljs-string {
  color: #34d399;
}

/* CSS */
.language-css .hljs-selector-class,
.language-css .hljs-selector-id {
  color: #818cf8;
}

.language-css .hljs-attribute {
  color: #38bdf8;
}

.language-css .hljs-number {
  color: #fbbf24;
}

/* HTML */
.language-html .hljs-tag {
  color: #f472b6;
}

.language-html .hljs-attr {
  color: #fbbf24;
}

.language-html .hljs-string {
  color: #34d399;
}

/* Python */
.language-python .hljs-decorator,
.language-python .hljs-meta {
  color: #fbbf24;
}

.language-python .hljs-built_in {
  color: #38bdf8;
}

/* TypeScript */
.language-typescript .hljs-type,
.language-ts .hljs-type {
  color: #f472b6;
}

/* Markdown */
.language-markdown .hljs-section {
  color: #818cf8;
  font-weight: 700;
}

.language-markdown .hljs-bullet {
  color: #38bdf8;
}

.language-markdown .hljs-emphasis {
  font-style: italic;
  color: #c084fc;
}

.language-markdown .hljs-strong {
  font-weight: 700;
  color: #f472b6;
}

/* --------------------------------------------------------------------------
   7. Code Preview Component Tokens (used in featured card, etc.)
   -------------------------------------------------------------------------- */
.code-preview .keyword {
  color: #c084fc;
}

.code-preview .string {
  color: #34d399;
}

.code-preview .func {
  color: #38bdf8;
}

.code-preview .number {
  color: #fbbf24;
}

.code-preview .comment {
  color: #64748b;
  font-style: italic;
}

.code-preview .type {
  color: #f472b6;
}

.code-preview .operator {
  color: #94a3b8;
}

.code-preview .bracket {
  color: #64748b;
}

.code-preview .attr {
  color: #fbbf24;
}

.code-preview .tag {
  color: #f472b6;
}

.code-preview .builtin {
  color: #38bdf8;
}

.code-preview .variable {
  color: #e2e8f0;
}

.code-preview .decorator {
  color: #fbbf24;
}

/* --------------------------------------------------------------------------
   8. Code Block Inside WordPress Gutenberg Blocks
   -------------------------------------------------------------------------- */
.wp-block-code {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0;
  margin: 24px 0;
  position: relative;
  font-family: var(--font-code);
}

.wp-block-code code {
  display: block;
  padding: 20px 24px;
  font-family: var(--font-code);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
  overflow-x: auto;
  white-space: pre;
}

/* WordPress preformatted block */
.wp-block-preformatted {
  font-family: var(--font-code);
  font-size: 14px;
  line-height: 1.7;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  overflow-x: auto;
  color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   9. Code Diffs & Highlights
   -------------------------------------------------------------------------- */

/* Highlighted line (e.g., for emphasizing specific lines) */
.code-highlight-line,
.highlight-line {
  display: block;
  background: rgba(56, 189, 248, 0.06);
  margin: 0 -24px;
  padding: 0 24px;
  border-left: 3px solid var(--accent-blue);
}

/* Added line */
.code-added-line,
.added-line {
  display: block;
  background: rgba(52, 211, 153, 0.06);
  margin: 0 -24px;
  padding: 0 24px;
  border-left: 3px solid var(--accent-green);
}

/* Removed line */
.code-removed-line,
.removed-line {
  display: block;
  background: rgba(248, 113, 113, 0.06);
  margin: 0 -24px;
  padding: 0 24px;
  border-left: 3px solid #f87171;
  text-decoration: line-through;
  opacity: 0.7;
}

/* --------------------------------------------------------------------------
   10. Responsive Code Blocks
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {

  pre {
    padding: 16px 16px;
    font-size: 13px;
    border-radius: var(--radius-sm);
    margin: 20px 0;
  }

  .hljs {
    padding: 16px;
  }

  pre[data-language]::before {
    font-size: 10px;
    top: 6px;
    right: 8px;
  }

  .code-copy-btn {
    opacity: 1;
    padding: 5px 10px;
    font-size: 11px;
    top: 6px;
    right: 6px;
  }

  p code,
  li code,
  td code,
  .article-content :not(pre) > code,
  .page-content :not(pre) > code {
    font-size: 0.85em;
    padding: 2px 6px;
  }

  .wp-block-code code {
    padding: 16px;
    font-size: 13px;
  }

  .code-highlight-line,
  .highlight-line,
  .code-added-line,
  .added-line,
  .code-removed-line,
  .removed-line {
    margin: 0 -16px;
    padding: 0 16px;
  }

  .code-preview {
    padding: 16px;
    font-size: 12px;
  }
}

/* --------------------------------------------------------------------------
   11. Print Styles for Code
   -------------------------------------------------------------------------- */
@media print {

  pre {
    background: #f8f9fa !important;
    border: 1px solid #dee2e6 !important;
    color: #212529 !important;
    white-space: pre-wrap;
    word-wrap: break-word;
    page-break-inside: avoid;
  }

  pre code {
    color: #212529 !important;
  }

  .code-copy-btn {
    display: none !important;
  }

  .hljs-keyword { color: #6f42c1 !important; }
  .hljs-string { color: #28a745 !important; }
  .hljs-comment { color: #6c757d !important; }
  .hljs-number { color: #fd7e14 !important; }
  .hljs-function, .hljs-name { color: #007bff !important; }
  .hljs-type { color: #e83e8c !important; }

  p code, li code {
    background: #f8f9fa !important;
    border: 1px solid #dee2e6 !important;
    color: #007bff !important;
  }
}
