/* =============================================================================
   UBIide Editor System - CodeMirror Theme & Linter Marker Styling
   ============================================================================= */

.CodeMirror {
  font-family: var(--font-code) !important;
  font-size: 13.5px !important;
  line-height: 1.6 !important;
  height: 100% !important;
  width: 100% !important;
  background-color: var(--bg-body) !important;
  color: var(--text-main) !important;
}

/* Gutters */
.CodeMirror-gutters {
  background-color: var(--bg-sidebar) !important;
  border-right: 1px solid var(--border-color) !important;
  white-space: nowrap !important;
  padding-right: 4px !important;
}

.CodeMirror-linenumber {
  color: var(--text-dim) !important;
  font-size: 12px !important;
  padding: 0 8px 0 5px !important;
}

/* Active Line */
.CodeMirror-activeline-background {
  background: rgba(56, 189, 248, 0.07) !important;
}

.CodeMirror-activeline .CodeMirror-linenumber {
  color: var(--accent-cyan) !important;
  font-weight: 700 !important;
}

/* Cursor & Selection */
.CodeMirror-cursor {
  border-left: 2px solid var(--accent-cyan) !important;
}

.CodeMirror-selected {
  background: rgba(2, 132, 199, 0.35) !important;
}

.CodeMirror-focused .CodeMirror-selected {
  background: rgba(2, 132, 199, 0.45) !important;
}

/* Matching brackets */
.CodeMirror-matchingbracket {
  color: #ffffff !important;
  background-color: rgba(56, 189, 248, 0.3) !important;
  border-bottom: 2px solid var(--accent-cyan) !important;
  font-weight: 700 !important;
}

.CodeMirror-nonmatchingbracket {
  color: #ffffff !important;
  background-color: rgba(244, 63, 94, 0.4) !important;
  border-bottom: 2px solid var(--accent-rose) !important;
}

/* =============================================================================
   Dark Theme (cm-s-ubi-dark)
   ============================================================================= */
.cm-s-ubi-dark .cm-keyword {
  color: #38bdf8 !important;
  font-weight: 600 !important;
}

.cm-s-ubi-dark .cm-def {
  color: #60a5fa !important;
  font-weight: 700 !important;
}

.cm-s-ubi-dark .cm-variable {
  color: #f8fafc !important;
}

.cm-s-ubi-dark .cm-variable-2 {
  color: #93c5fd !important;
}

.cm-s-ubi-dark .cm-variable-3 {
  color: #a7f3d0 !important;
}

.cm-s-ubi-dark .cm-builtin {
  color: #c084fc !important;
  font-weight: 600 !important;
}

.cm-s-ubi-dark .cm-string {
  color: #34d399 !important;
}

.cm-s-ubi-dark .cm-number {
  color: #fbbf24 !important;
}

.cm-s-ubi-dark .cm-comment {
  color: #64748b !important;
  font-style: italic !important;
}

.cm-s-ubi-dark .cm-operator {
  color: #cbd5e1 !important;
}

.cm-s-ubi-dark .cm-property {
  color: #7dd3fc !important;
}

.cm-s-ubi-dark .cm-atom {
  color: #f472b6 !important;
  font-weight: 600 !important;
}

/* =============================================================================
   Light Theme (cm-s-ubi-light & [data-theme="light"] Overrides)
   Fixes: ensures dark, crisp, visible text and tokens in light mode
   ============================================================================= */
[data-theme="light"] .CodeMirror,
.cm-s-ubi-light.CodeMirror {
  background-color: #ffffff !important;
  color: #0f172a !important;
}

[data-theme="light"] .CodeMirror pre.CodeMirror-line,
[data-theme="light"] .CodeMirror-line span,
.cm-s-ubi-light pre.CodeMirror-line,
.cm-s-ubi-light .CodeMirror-line span {
  color: #0f172a;
}

[data-theme="light"] .CodeMirror-gutters,
.cm-s-ubi-light .CodeMirror-gutters {
  background-color: #f8fafc !important;
  border-right: 1px solid #e2e8f0 !important;
}

[data-theme="light"] .CodeMirror-linenumber,
.cm-s-ubi-light .CodeMirror-linenumber {
  color: #94a3b8 !important;
}

[data-theme="light"] .CodeMirror-activeline-background,
.cm-s-ubi-light .CodeMirror-activeline-background {
  background: rgba(2, 132, 199, 0.08) !important;
}

[data-theme="light"] .CodeMirror-activeline .CodeMirror-linenumber,
.cm-s-ubi-light .CodeMirror-activeline .CodeMirror-linenumber {
  color: #0284c7 !important;
  font-weight: 700 !important;
}

[data-theme="light"] .CodeMirror-cursor,
.cm-s-ubi-light .CodeMirror-cursor {
  border-left: 2px solid #0284c7 !important;
}

[data-theme="light"] .CodeMirror-selected,
[data-theme="light"] .CodeMirror-focused .CodeMirror-selected,
.cm-s-ubi-light .CodeMirror-selected,
.cm-s-ubi-light.CodeMirror-focused .CodeMirror-selected {
  background: rgba(2, 132, 199, 0.22) !important;
}

[data-theme="light"] .CodeMirror-line::selection,
[data-theme="light"] .CodeMirror-line *::selection,
.cm-s-ubi-light .CodeMirror-line::selection,
.cm-s-ubi-light .CodeMirror-line *::selection {
  background: rgba(2, 132, 199, 0.3) !important;
  color: #0f172a !important;
}

[data-theme="light"] .CodeMirror-matchingbracket,
.cm-s-ubi-light .CodeMirror-matchingbracket {
  color: #0f172a !important;
  background-color: rgba(2, 132, 199, 0.25) !important;
  border-bottom: 2px solid #0284c7 !important;
}

[data-theme="light"] .CodeMirror-nonmatchingbracket,
.cm-s-ubi-light .CodeMirror-nonmatchingbracket {
  color: #e11d48 !important;
  background-color: rgba(244, 63, 94, 0.25) !important;
  border-bottom: 2px solid #e11d48 !important;
}

/* Light Theme Syntax Tokens */
[data-theme="light"] .CodeMirror .cm-variable,
.cm-s-ubi-light .cm-variable {
  color: #0f172a !important;
}

[data-theme="light"] .CodeMirror .cm-keyword,
.cm-s-ubi-light .cm-keyword {
  color: #0284c7 !important;
  font-weight: 600 !important;
}

[data-theme="light"] .CodeMirror .cm-def,
.cm-s-ubi-light .cm-def {
  color: #1d4ed8 !important;
  font-weight: 700 !important;
}

[data-theme="light"] .CodeMirror .cm-variable-2,
.cm-s-ubi-light .cm-variable-2 {
  color: #0369a1 !important;
}

[data-theme="light"] .CodeMirror .cm-variable-3,
.cm-s-ubi-light .cm-variable-3 {
  color: #0f766e !important;
}

[data-theme="light"] .CodeMirror .cm-builtin,
.cm-s-ubi-light .cm-builtin {
  color: #7c3aed !important;
  font-weight: 600 !important;
}

[data-theme="light"] .CodeMirror .cm-string,
.cm-s-ubi-light .cm-string {
  color: #047857 !important;
}

[data-theme="light"] .CodeMirror .cm-number,
.cm-s-ubi-light .cm-number {
  color: #b45309 !important;
}

[data-theme="light"] .CodeMirror .cm-comment,
.cm-s-ubi-light .cm-comment {
  color: #64748b !important;
  font-style: italic !important;
}

[data-theme="light"] .CodeMirror .cm-operator,
.cm-s-ubi-light .cm-operator {
  color: #334155 !important;
}

[data-theme="light"] .CodeMirror .cm-property,
.cm-s-ubi-light .cm-property {
  color: #0284c7 !important;
}

[data-theme="light"] .CodeMirror .cm-atom,
.cm-s-ubi-light .cm-atom {
  color: #db2777 !important;
  font-weight: 600 !important;
}

/* Code Folding */
.CodeMirror-foldmarker {
  color: #38bdf8;
  text-shadow: none;
  font-family: var(--font-body);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0 4px;
  border-radius: 3px;
  cursor: pointer;
}

.CodeMirror-foldgutter-open:after {
  content: "▾";
  color: var(--text-dim);
  font-size: 11px;
}

.CodeMirror-foldgutter-folded:after {
  content: "▸";
  color: var(--accent-cyan);
  font-size: 11px;
}

/* =============================================================================
   CodeMirror Lint Addon Styling (Squiggles and Gutters)
   ============================================================================= */
.CodeMirror-lint-markers {
  width: 16px;
}

.CodeMirror-lint-marker-error,
.CodeMirror-lint-marker-warning,
.CodeMirror-lint-marker-info {
  width: 14px;
  height: 14px;
  background-position: center center;
  background-repeat: no-repeat;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  border-radius: 50%;
  margin-top: 3px;
}

.CodeMirror-lint-marker-error {
  background: #f43f5e !important;
  color: #ffffff;
}
.CodeMirror-lint-marker-error::after {
  content: "✕";
  font-weight: 900;
  font-size: 9px;
}

.CodeMirror-lint-marker-warning {
  background: #f59e0b !important;
  color: #000000;
}
.CodeMirror-lint-marker-warning::after {
  content: "!";
  font-weight: 900;
  font-size: 9px;
}

.CodeMirror-lint-marker-info {
  background: #38bdf8 !important;
  color: #000000;
}
.CodeMirror-lint-marker-info::after {
  content: "i";
  font-weight: 900;
  font-size: 9px;
}

/* Squiggle underlines */
.CodeMirror-lint-mark-error {
  background-position: left bottom;
  background-repeat: repeat-x;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%206%203%22%20width%3D%226%22%20height%3D%223%22%3E%3Cpath%20d%3D%22M0%203%20L3%200%20L6%203%22%20fill%3D%22none%22%20stroke%3D%22%23f43f5e%22%20stroke-width%3D%221%22%2F%3E%3C%2Fsvg%3E") !important;
  padding-bottom: 2px;
}

.CodeMirror-lint-mark-warning {
  background-position: left bottom;
  background-repeat: repeat-x;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%206%203%22%20width%3D%226%22%20height%3D%223%22%3E%3Cpath%20d%3D%22M0%203%20L3%200%20L6%203%22%20fill%3D%22none%22%20stroke%3D%22%23f59e0b%22%20stroke-width%3D%221%22%2F%3E%3C%2Fsvg%3E") !important;
  padding-bottom: 2px;
}

/* Linter Tooltip */
.CodeMirror-lint-tooltip {
  background: var(--bg-card) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text-white) !important;
  font-family: var(--font-body) !important;
  font-size: 12px !important;
  padding: 6px 10px !important;
  box-shadow: var(--shadow-lg) !important;
  max-width: 420px !important;
  z-index: 250 !important;
}

.CodeMirror-lint-message-error {
  background: none !important;
  padding-left: 0 !important;
  color: #fca5a5 !important;
}

.CodeMirror-lint-message-warning {
  background: none !important;
  padding-left: 0 !important;
  color: #fde047 !important;
}

/* (Linter toggle button is now integrated into standard ide-toolbar in components.css) */
