/**
 * Editor & Diff Viewer Styles
 * @countermeasure/web-components
 *
 * Syntax highlighting tokens and diff viewer layout.
 * Uses --cmm-editor-* variables that adapt to light/dark theme.
 *
 * TODO(phase-1): Hex literals here define syntax-highlight colour tokens
 * (--cmm-editor-*). These are intentionally editor-specific and not derived
 * from the semantic design tokens. A future pass can cross-reference them
 * against the Monokai/dark theme accent palette if colour unification is needed.
 */

/* ============================================================================
   SYNTAX HIGHLIGHTING TOKENS - Light Theme (Default)
   ============================================================================ */
:root {
  --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: rgba(0, 0, 0, 0.04);
  --cmm-editor-bracket-match: rgba(59, 130, 246, 0.3);
  --cmm-editor-selection-match: rgba(34, 197, 94, 0.15);
  --cmm-diff-added-bg: rgba(34, 197, 94, 0.12);
  --cmm-diff-removed-bg: rgba(239, 68, 68, 0.12);
  --cmm-diff-added-gutter: rgba(34, 197, 94, 0.08);
  --cmm-diff-removed-gutter: rgba(239, 68, 68, 0.08);
}

/* ============================================================================
   SYNTAX HIGHLIGHTING TOKENS - Dark Theme
   ============================================================================ */
.dark,
[data-theme="dark"] {
  --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-active-line: rgba(255, 255, 255, 0.04);
  --cmm-editor-bracket-match: rgba(96, 165, 250, 0.35);
  --cmm-editor-selection-match: rgba(52, 211, 153, 0.2);
  --cmm-diff-added-bg: rgba(34, 197, 94, 0.15);
  --cmm-diff-removed-bg: rgba(239, 68, 68, 0.15);
  --cmm-diff-added-gutter: rgba(34, 197, 94, 0.1);
  --cmm-diff-removed-gutter: rgba(239, 68, 68, 0.1);
}

/* ============================================================================
   EDITOR BASE
   ============================================================================ */
.cmm-editor {
  position: relative;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  overflow: hidden;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  background-color: hsl(var(--card));
}

.cmm-editor:focus-within {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: -1px;
}

.cmm-editor__toolbar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid hsl(var(--border));
  background-color: hsl(var(--secondary));
}

.cmm-editor__toolbar-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.75rem;
  width: 1.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: background-color var(--transition-fast, 150ms),
              color var(--transition-fast, 150ms);
}

.cmm-editor__toolbar-button:hover {
  background-color: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.cmm-editor__toolbar-separator {
  width: 1px;
  height: 1.25rem;
  margin: 0 0.25rem;
  background-color: hsl(var(--border));
}

/* ============================================================================
   DIFF VIEWER
   ============================================================================ */
.cmm-diff-viewer {
  display: flex;
  flex-direction: column;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: hsl(var(--card));
}

.cmm-diff-viewer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid hsl(var(--border));
  background-color: hsl(var(--secondary));
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
}

.cmm-diff-viewer__stats {
  display: flex;
  gap: 0.75rem;
  font-size: 0.75rem;
}

.cmm-diff-viewer__stat--added {
  color: hsl(var(--success));
}

.cmm-diff-viewer__stat--removed {
  color: hsl(var(--danger));
}

.cmm-diff-viewer__body {
  display: flex;
  overflow: auto;
  max-height: 600px;
}

/* Side-by-side diff panes */
.cmm-diff-viewer--split .cmm-diff-viewer__body {
  flex-direction: row;
}

.cmm-diff-viewer__pane {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
}

.cmm-diff-viewer--split .cmm-diff-viewer__pane + .cmm-diff-viewer__pane {
  border-left: 1px solid hsl(var(--border));
}

/* Unified diff (stacked) */
.cmm-diff-viewer--unified .cmm-diff-viewer__body {
  flex-direction: column;
}

/* Diff lines */
.cmm-diff-viewer__line {
  display: flex;
  white-space: pre;
}

.cmm-diff-viewer__gutter {
  flex-shrink: 0;
  width: 3.5rem;
  padding: 0 0.5rem;
  text-align: right;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  user-select: none;
}

.cmm-diff-viewer__content {
  flex: 1;
  padding: 0 0.75rem;
  min-width: 0;
}

.cmm-diff-viewer__line--added {
  background-color: var(--cmm-diff-added-bg);
}

.cmm-diff-viewer__line--added .cmm-diff-viewer__gutter {
  background-color: var(--cmm-diff-added-gutter);
}

.cmm-diff-viewer__line--removed {
  background-color: var(--cmm-diff-removed-bg);
}

.cmm-diff-viewer__line--removed .cmm-diff-viewer__gutter {
  background-color: var(--cmm-diff-removed-gutter);
}

.cmm-diff-viewer__line--context {
  color: hsl(var(--muted-foreground));
}

.cmm-diff-viewer__line--header {
  padding: 0.25rem 0.75rem;
  background-color: hsl(var(--secondary));
  color: hsl(var(--muted-foreground));
  font-weight: 500;
  font-size: 0.75rem;
}

/* Inline character-level diff highlights */
.cmm-diff-viewer__char--added {
  background-color: rgba(34, 197, 94, 0.3);
  border-radius: 2px;
}

.cmm-diff-viewer__char--removed {
  background-color: rgba(239, 68, 68, 0.3);
  border-radius: 2px;
}

/* Diff viewer empty state */
.cmm-diff-viewer__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}
