/**
 * CodeBlock styles
 * @countermeasure/web-components/display/code-block
 */

/* ============================================================================
   CODE BLOCK BASE
   ============================================================================ */
.cmm-code-block {
  --cmm-bg-primary: transparent;
  --cmm-bg-secondary: transparent;
  --cmm-text-primary: #0f172a;
  --cmm-text-secondary: #334155;
  --cmm-text-muted: #64748b;
  --cmm-border: #e2e8f0;
  --cmm-editor-keyword: #7c3aed;
  --cmm-editor-string: #059669;
  --cmm-editor-number: #d97706;
  --cmm-editor-comment: #6b7280;
  --cmm-editor-operator: #0891b2;
  --cmm-editor-variable: #1e40af;
  --cmm-editor-function: #2563eb;
  --cmm-editor-type: #0891b2;
  --cmm-editor-property: #7c3aed;
  --cmm-editor-atom: #d97706;
  --cmm-editor-meta: #6b7280;
  --cmm-editor-label: #2563eb;
  --cmm-editor-namespace: #0891b2;
  --cmm-editor-regexp: #dc2626;
  --cmm-editor-bracket: #6b7280;
  --cmm-editor-punctuation: #6b7280;
  --cmm-editor-tag: #dc2626;
  --cmm-editor-attribute: #d97706;
  --cmm-editor-selection: rgba(59, 130, 246, 0.15);
  --cmm-editor-active-line: transparent;
  --cmm-editor-bracket-match: rgba(59, 130, 246, 0.3);
  --cmm-editor-selection-match: rgba(34, 197, 94, 0.15);

  background-color: var(
    --cmm-code-block-bg,
    var(--color-glass-card, hsl(var(--card, 0 0% 100%)))
  );
  border: 1px solid var(--cmm-border, var(--color-border-glass, hsl(var(--border, 214 32% 91%))));
  border-radius: var(--radius-lg);
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas,
    'Liberation Mono', monospace;
}

.dark .cmm-code-block,
[data-theme='dark'] .cmm-code-block,
[data-theme='monokai'] .cmm-code-block,
[data-theme='glass'] .cmm-code-block,
.color-mode-dark .cmm-code-block,
.color-mode-midnight .cmm-code-block {
  --cmm-bg-primary: transparent;
  --cmm-bg-secondary: transparent;
  --cmm-code-block-bg: rgba(5, 7, 12, 0.72);
  --cmm-code-block-header-bg: rgba(15, 23, 42, 0.6);
  --cmm-text-primary: #e2e8f0;
  --cmm-text-secondary: #cbd5e1;
  --cmm-text-muted: #94a3b8;
  --cmm-border: rgba(148, 163, 184, 0.18);
  --cmm-editor-keyword: #a78bfa;
  --cmm-editor-string: #34d399;
  --cmm-editor-number: #fbbf24;
  --cmm-editor-comment: #9ca3af;
  --cmm-editor-operator: #67e8f9;
  --cmm-editor-variable: #93c5fd;
  --cmm-editor-function: #60a5fa;
  --cmm-editor-type: #67e8f9;
  --cmm-editor-property: #c4b5fd;
  --cmm-editor-atom: #fbbf24;
  --cmm-editor-meta: #9ca3af;
  --cmm-editor-label: #60a5fa;
  --cmm-editor-namespace: #67e8f9;
  --cmm-editor-regexp: #f87171;
  --cmm-editor-bracket: #9ca3af;
  --cmm-editor-punctuation: #9ca3af;
  --cmm-editor-tag: #f87171;
  --cmm-editor-attribute: #fbbf24;
  --cmm-editor-selection: rgba(96, 165, 250, 0.25);
  --cmm-editor-bracket-match: rgba(96, 165, 250, 0.35);
  --cmm-editor-selection-match: rgba(52, 211, 153, 0.2);
}

/* ============================================================================
   CODE BLOCK HEADER
   ============================================================================ */
.cmm-code-block__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background-color: var(
    --cmm-code-block-header-bg,
    var(--color-glass, hsl(var(--muted, 210 40% 96%)))
  );
  border-bottom: 1px solid var(--cmm-border, var(--color-border-glass, hsl(var(--border, 214 32% 91%))));
  font-size: 0.75rem;
}

.cmm-code-block__language {
  color: var(--cmm-text-secondary, var(--color-foreground-secondary, hsl(var(--muted-foreground, 215 16% 47%))));
  text-transform: uppercase;
  font-weight: 500;
  letter-spacing: 0.05em;
}

/* ============================================================================
   CODE BLOCK COPY BUTTON
   ============================================================================ */
.cmm-code-block__copy {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--cmm-text-muted, var(--color-foreground-muted, hsl(var(--muted-foreground, 215 16% 47%))));
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  transition:
    color var(--transition-fast),
    background-color var(--transition-fast);
}

.cmm-code-block__copy:hover {
  color: var(--cmm-text-primary, var(--color-foreground, hsl(var(--foreground, 222 47% 11%))));
  background-color: var(--color-glass-hover, var(--color-background, hsl(var(--background, 0 0% 100%))));
}

.cmm-code-block__copy:focus-visible {
  outline: 2px solid var(--cmm-focus-ring, var(--color-accent-primary, hsl(var(--focus-ring, 217 91% 60%))));
  outline-offset: 2px;
}

.cmm-code-block__copy--copied {
  color: var(--cmm-success, var(--color-status-success, hsl(var(--success, 142 71% 45%))));
}

/* ============================================================================
   CODE BLOCK BODY
   ============================================================================ */
.cmm-code-block__pre {
  margin: 0;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.7;
}

.cmm-code-block__code {
  white-space: pre;
}

/* ============================================================================
   CODE BLOCK LINE NUMBERS
   ============================================================================ */
.cmm-code-block__line-numbers {
  display: inline-block;
  text-align: right;
  color: var(--cmm-text-muted, var(--color-foreground-muted, hsl(var(--muted-foreground, 215 16% 47%))));
  padding-right: 1rem;
  margin-right: 1rem;
  border-right: 1px solid var(--cmm-border, var(--color-border-glass, hsl(var(--border, 214 32% 91%))));
  user-select: none;
  min-width: 2rem;
}
