/**
 * GFMR Theme Variables - Dynamic Theme Support
 *
 * CSS variables for light/dark theme switching in code blocks
 * Provides smooth transitions and system theme integration
 *
 * @package MarkdownRendererForGitHub
 * @since 2.1.0
 */

/* ================================================
 * Root Theme Variables
 * ================================================ */

:root {

  /* Light theme (default) */
  --gfmr-theme-bg: #fff;
  --gfmr-theme-text: #24292f;
  --gfmr-theme-border: #d0d7de;
  --gfmr-theme-accent: #0969da;
  
  /* Code block specific */
  --gfmr-code-bg: #f6f8fa;
  --gfmr-code-text: #24292f;
  --gfmr-code-border: #d0d7de;
  --gfmr-code-line-height: 1.45;
  
  /* Syntax highlighting base colors */
  --gfmr-syntax-comment: #6e7781;
  --gfmr-syntax-keyword: #cf222e;
  --gfmr-syntax-string: #032f62;
  --gfmr-syntax-number: #0550ae;
  --gfmr-syntax-function: #8250df;
  --gfmr-syntax-variable: #953800;
  
  /* UI elements */
  --gfmr-copy-btn-bg: #f3f4f6;
  --gfmr-copy-btn-hover: #e5e7eb;
  --gfmr-copy-btn-text: #374151;
  
  /* Transitions */
  --gfmr-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ================================================
 * Dark Theme Variables
 * ================================================ */

[data-gfmr-theme="dark"],
.gfmr-dark-theme {
  --gfmr-theme-bg: #0d1117;
  --gfmr-theme-text: #e6edf3;
  --gfmr-theme-border: #30363d;
  --gfmr-theme-accent: #58a6ff;
  
  /* Code block specific */
  --gfmr-code-bg: #161b22;
  --gfmr-code-text: #e6edf3;
  --gfmr-code-border: #30363d;
  
  /* Syntax highlighting dark colors */
  --gfmr-syntax-comment: #8b949e;
  --gfmr-syntax-keyword: #ff7b72;
  --gfmr-syntax-string: #a5c9ea;
  --gfmr-syntax-number: #79c0ff;
  --gfmr-syntax-function: #d2a8ff;
  --gfmr-syntax-variable: #ffa657;
  
  /* UI elements */
  --gfmr-copy-btn-bg: #21262d;
  --gfmr-copy-btn-hover: #30363d;
  --gfmr-copy-btn-text: #f0f6fc;
}

/* ================================================
 * System Theme Auto Detection
 * ================================================ */

@media (prefers-color-scheme: dark) {

  [data-gfmr-theme="auto"],
  .gfmr-auto-theme {
    --gfmr-theme-bg: #0d1117;
    --gfmr-theme-text: #e6edf3;
    --gfmr-theme-border: #30363d;
    --gfmr-theme-accent: #58a6ff;
    
    --gfmr-code-bg: #161b22;
    --gfmr-code-text: #e6edf3;
    --gfmr-code-border: #30363d;
    
    --gfmr-syntax-comment: #8b949e;
    --gfmr-syntax-keyword: #ff7b72;
    --gfmr-syntax-string: #a5c9ea;
    --gfmr-syntax-number: #79c0ff;
    --gfmr-syntax-function: #d2a8ff;
    --gfmr-syntax-variable: #ffa657;
    
    --gfmr-copy-btn-bg: #21262d;
    --gfmr-copy-btn-hover: #30363d;
    --gfmr-copy-btn-text: #f0f6fc;
  }
}

@media (prefers-color-scheme: light) {

  [data-gfmr-theme="auto"],
  .gfmr-auto-theme {
    --gfmr-theme-bg: #fff;
    --gfmr-theme-text: #24292f;
    --gfmr-theme-border: #d0d7de;
    --gfmr-theme-accent: #0969da;
    
    --gfmr-code-bg: #f6f8fa;
    --gfmr-code-text: #24292f;
    --gfmr-code-border: #d0d7de;
    
    --gfmr-syntax-comment: #6e7781;
    --gfmr-syntax-keyword: #cf222e;
    --gfmr-syntax-string: #032f62;
    --gfmr-syntax-number: #0550ae;
    --gfmr-syntax-function: #8250df;
    --gfmr-syntax-variable: #953800;
    
    --gfmr-copy-btn-bg: #f3f4f6;
    --gfmr-copy-btn-hover: #e5e7eb;
    --gfmr-copy-btn-text: #374151;
  }
}

/* ================================================
 * Code Block Styling
 * ================================================ */

.gfmr-markdown-rendered pre,
.gfmr-markdown-container pre,
pre.shiki,
.wp-block-code pre {
  background-color: var(--gfmr-code-bg) !important;
  color: var(--gfmr-code-text) !important;
  border: 1px solid var(--gfmr-code-border);
  border-radius: 6px;
  padding: 16px;
  margin: 16px 0;
  overflow-x: auto;
  line-height: var(--gfmr-code-line-height);
  transition: var(--gfmr-transition);
  position: relative;
}

.gfmr-markdown-rendered code,
.gfmr-markdown-container code,
pre.shiki code,
.wp-block-code code {
  background: transparent !important;
  color: inherit !important;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 85%;
  word-break: normal;
  white-space: pre;
  padding: 0;
  margin: 0;
}

/* Inline code styling */
p code,
li code,
td code,
.gfmr-markdown-rendered :not(pre) > code,
.gfmr-markdown-container :not(pre) > code {
  background-color: var(--gfmr-code-bg) !important;
  color: var(--gfmr-code-text) !important;
  border: 1px solid var(--gfmr-code-border);
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 85%;
  transition: var(--gfmr-transition);
}

/* ================================================
 * Copy Button Integration
 * ================================================ */

.gfmr-copy-button {
  background-color: var(--gfmr-copy-btn-bg) !important;
  color: var(--gfmr-copy-btn-text) !important;
  border: 1px solid var(--gfmr-code-border);
  transition: var(--gfmr-transition);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  position: absolute;
  top: 8px;
  right: 8px;
  cursor: pointer;
  z-index: 10;
}

.gfmr-copy-button:hover {
  background-color: var(--gfmr-copy-btn-hover) !important;
  transform: translateY(-1px);
}

.gfmr-copy-button:active {
  transform: translateY(0);
}

/* Copy button for different parent elements */
pre:hover .gfmr-copy-button {
  opacity: 1;
}

.gfmr-copy-button {
  opacity: 0.7;
}

/* ================================================
 * Theme Transition Effects
 * ================================================ */

.gfmr-theme-transitioning * {
  transition: var(--gfmr-transition) !important;
}

/* Smooth theme switching animation */
@keyframes gfmr-theme-fade {

  0% { opacity: 0.8; }

  50% { opacity: 0.9; }

  100% { opacity: 1; }
}

.gfmr-theme-switching pre.shiki,
.gfmr-theme-switching .gfmr-markdown-rendered pre {
  animation: gfmr-theme-fade 0.4s ease-in-out;
}

/* ================================================
 * Accessibility Enhancements
 * ================================================ */

/* High contrast mode support */
@media (prefers-contrast: high) {

  :root {
    --gfmr-code-border: #000;
  }
  
  [data-gfmr-theme="dark"],
  .gfmr-dark-theme {
    --gfmr-code-border: #fff;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

  :root {
    --gfmr-transition: none;
  }
  
  .gfmr-theme-switching pre.shiki,
  .gfmr-theme-switching .gfmr-markdown-rendered pre {
    animation: none;
  }
}

/* ================================================
 * Print Styles
 * ================================================ */

@media print {

  .gfmr-markdown-rendered pre,
  .gfmr-markdown-container pre,
  pre.shiki,
  .wp-block-code pre {
    background-color: #fff !important;
    color: #000 !important;
    border: 1px solid #ccc !important;
    box-shadow: none !important;
  }
  
  .gfmr-copy-button {
    display: none !important;
  }
  
  /* Force light theme for printing */
  * {
    color: #000 !important;
    background-color: transparent !important;
  }
}

/* ================================================
 * Mobile Responsive Design
 * ================================================ */

@media (max-width: 768px) {

  .gfmr-markdown-rendered pre,
  .gfmr-markdown-container pre,
  pre.shiki,
  .wp-block-code pre {
    padding: 12px;
    margin: 12px 0;
    border-radius: 4px;
    font-size: 14px;
  }
  
  .gfmr-copy-button {
    padding: 4px 6px;
    font-size: 11px;
    top: 6px;
    right: 6px;
  }
}

/* ================================================
 * Browser Compatibility Fallbacks
 * ================================================ */

/* Fallback for browsers that don't support CSS variables */
.no-css-variables .gfmr-markdown-rendered pre,
.no-css-variables .gfmr-markdown-container pre {
  background-color: #f6f8fa;
  color: #24292f;
  border: 1px solid #d0d7de;
}

.no-css-variables .gfmr-dark-theme .gfmr-markdown-rendered pre,
.no-css-variables .gfmr-dark-theme .gfmr-markdown-container pre {
  background-color: #161b22;
  color: #e6edf3;
  border: 1px solid #30363d;
}

/* ================================================
 * WordPress Block Editor Compatibility
 * ================================================ */

.block-editor .gfmr-markdown-rendered pre,
.wp-admin .gfmr-markdown-rendered pre {
  background-color: var(--gfmr-code-bg) !important;
  color: var(--gfmr-code-text) !important;
  border: 1px solid var(--gfmr-code-border) !important;
}

/* ================================================
 * Admin Preview Syntax Highlighting
 * ================================================ */

.gfmr-admin-preview {
  background-color: var(--gfmr-code-bg) !important;
  color: var(--gfmr-code-text) !important;
  border: 1px solid var(--gfmr-code-border);
  border-radius: 6px;
  padding: 16px;
  margin: 16px 0;
  overflow-x: auto;
  line-height: var(--gfmr-code-line-height);
  transition: var(--gfmr-transition);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

.gfmr-admin-preview code {
  background: transparent !important;
  color: inherit !important;
  font-family: inherit;
  font-size: 85%;
  word-break: normal;
  white-space: pre;
  padding: 0;
  margin: 0;
}

/* Admin preview syntax highlighting classes */
.gfmr-admin-preview .gfmr-comment {
  color: var(--gfmr-syntax-comment);
  font-style: italic;
}

.gfmr-admin-preview .gfmr-keyword {
  color: var(--gfmr-syntax-keyword);
  font-weight: 700;
}

.gfmr-admin-preview .gfmr-property {
  color: var(--gfmr-syntax-function);
  font-weight: 500;
}

.gfmr-admin-preview .gfmr-string {
  color: var(--gfmr-syntax-string);
}

.gfmr-admin-preview .gfmr-number {
  color: var(--gfmr-syntax-number);
  font-weight: 500;
}

/* Admin theme switching animation */
.gfmr-theme-switching .gfmr-admin-preview {
  animation: gfmr-theme-fade 0.4s ease-in-out;
}

/* ================================================
 * Debug and Development Support
 * ================================================ */

.gfmr-debug-theme::before {
  content: "Theme: " attr(data-gfmr-theme);
  position: absolute;
  top: -20px;
  left: 0;
  font-size: 10px;
  color: var(--gfmr-theme-accent);
  font-family: monospace;
}