/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


:root {
  --breakpoint-active-color: light-dark(rgba(44,187,15,.2), rgba(0,255,175,.4));
  --breakpoint-active-color-hover: light-dark(rgba(44,187,15,.5), rgba(0,255,175,.7););
  --gutter-background-color: var(--theme-sidebar-background);
  --gutter-border-color: light-dark(var(--theme-splitter-color), var(--theme-toolbar-background));
  --highlight-line-duration: 5000ms;
  &[forced-colors-active] {
    /* overriding variable in HCM so the border is actually visible (see Bug 1953376) */
    --gutter-border-color: var(--theme-splitter-color);
  }
}

/* We don't want the focus style to be displayed on the CodeMirror scrollbars.
 * See Bug 1590707.
 */
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar {
  outline: none !important;
}

.CodeMirror .errors {
  width: 16px;
}

.CodeMirror .error {
  display: inline-block;
  margin-left: 5px;
  width: 12px;
  height: 12px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  opacity: 0.75;
}

.CodeMirror .hit-counts {
  width: 6px;
}

.CodeMirror .hit-count {
  display: inline-block;
  height: 12px;
  border: solid rgba(0,0,0,0.2);
  border-width: 1px 1px 1px 0;
  border-radius: 0 3px 3px 0;
  padding: 0 3px;
  font-size: 10px;
  pointer-events: none;
}

.CodeMirror-linenumber:before {
  content: " ";
  display: block;
  width: calc(100% - 3px);
  position: absolute;
  top: 1px;
  left: 0;
  height: 12px;
  z-index: -1;
  background-size: calc(100% - 2px) 12px;
  background-repeat: no-repeat;
  background-position: right center;
  padding-inline-end: 9px;
}

.breakpoint .CodeMirror-linenumber {
  color: var(--theme-body-background);
}

.debug-line .CodeMirror-linenumber {
  background-color: var(--breakpoint-active-color);
}

.theme-dark .debug-line .CodeMirror-linenumber {
  color: #c0c0c0;
}

.debug-line .CodeMirror-line {
  background-color: var(--breakpoint-active-color) !important;
}

/* Don't display the highlight color since the debug line
   is already highlighted */
.debug-line .CodeMirror-activeline-background {
  display: none;
}

.CodeMirror {
  cursor: text;
  height: 100%;
}

.CodeMirror-gutters {
  cursor: default;
}

.cm-s-mozilla .CodeMirror-gutters,
.cm-editor .cm-gutters { /* vertical line next to line numbers */
  border-right-color: var(--gutter-border-color);
  background-color: var(--gutter-background-color);
}

.cm-trailingspace {
  background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAYAAAB/qH1jAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QUXCToH00Y1UgAAACFJREFUCNdjPMDBUc/AwNDAAAFMTAwMDA0OP34wQgX/AQBYgwYEx4f9lQAAAABJRU5ErkJggg==");
  opacity: 0.75;
  background-position: left bottom;
  background-repeat: repeat-x;
}

/* Search highlight style
 * cm-searching is used in Style Editor, cm-highlight in Debugger and searchMatch in Netmonitor */
.cm-searching,
.cm-highlight, .cm-editor .cm-searchMatch {
  border-bottom: 1px solid var(--theme-contrast-border);
  /* Use the translucent yellow background, because we want the text selection
     background (CodeMirror-selected) to show through this. */
  background-color: var(--theme-contrast-background-alpha);

  :root[forced-colors-active] & {
    border-bottom-width: 2px;
    color: var(--theme-contrast-color);
  }
}

/* CodeMirror 5 search addon input */
.cm5-search-container {
  display: flex;
  padding: 4px 2px;

  .CodeMirror-dialog:has(> &) {
    background-color: var(--theme-body-background);
    /* remove padding on the dialog so it's easier to style the focus indicator */
    padding: 0;
  }

  .cm5-search-input {
    margin-inline: 1em;
    flex-grow: 1;
  }

  &:focus-within {
    outline: var(--theme-focus-outline);
    outline-offset: -2px;
  }
}

.cm5-search-replace-input {
  width: 10em;

  &:focus {
    outline: var(--theme-focus-outline) !important;
  }
}

.cm5-search-replace-hint {
  color: var(--theme-text-color-alt);
  margin-inline-start: 8px;
}

/* CodeMirror 5 vim addon prompt/input */
.cm5-vim-prompt {
  font-family: monospace;
  white-space: pre;

  /* When there's a label, add some space before the input */
  & label input {
    margin-inline-start: 8px;
  }

  & input:focus {
    outline: var(--theme-focus-outline) !important;
  }
}

.cm5-vim-prompt-description {
  color: var(--theme-text-color-alt);
  margin-inline-start: 8px;
}

.cm5-vim-notification-error {
  color: var(--theme-text-color-error);
}

/* CodeMirror dialogs styling */

.CodeMirror-dialog {
  padding: 4px 3px;
}

.CodeMirror-dialog,
.CodeMirror-dialog input {
  font: message-box;
}

/* Fold addon */

.CodeMirror-foldmarker {
  display: inline-block;
  font-family: sans-serif;
  line-height: 10px;
  margin: 0 1px;
  padding: 0 2px;
  border-radius: 3px;
  border: solid 1px var(--theme-splitter-color);
  color: var(--theme-body-color);
  background-color: var(--theme-sidebar-background);
  cursor: pointer;
}

.CodeMirror-foldgutter {
  width: 16px; /* Same as breakpoints gutter above */
}

.CodeMirror-foldgutter-open,
.CodeMirror-foldgutter-folded {
  height: 14px;
  margin-top: 1px;
  background-image: url("chrome://devtools/skin/images/arrow.svg");
  background-position: center;
  background-repeat: no-repeat;
  -moz-context-properties: fill;
  fill: var(--theme-icon-dimmed-color);
  /* make the icons smaller than regular twistys (10->8px) */
  background-size: 8px;
  cursor: pointer;
}

.CodeMirror-foldgutter-folded {
  transform: rotate(-90deg);
}

.CodeMirror-hints {
  position: absolute;
  z-index: 10;
  overflow: hidden;
  list-style: none;
  margin: 0;
  padding: 2px;
  border-radius: 3px;
  font-size: 90%;
  max-height: 20em;
  overflow-y: auto;
}

.CodeMirror-hint {
  margin: 0;
  padding: 0 4px;
  border-radius: 2px;
  max-width: 19em;
  overflow: hidden;
  white-space: pre;
  cursor: pointer;
}

.CodeMirror-Tern-completion {
  padding-inline-start: 22px;
  position: relative;
  line-height: 18px;
}

.CodeMirror-Tern-completion:before {
  position: absolute;
  left: 2px;
  bottom: 2px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: bold;
  height: 15px;
  width: 15px;
  line-height: 16px;
  text-align: center;
  color: #ffffff;
  box-sizing: border-box;
}

.CodeMirror-Tern-completion-unknown:before {
  content: "?";
}

.CodeMirror-Tern-completion-object:before {
  content: "O";
}

.CodeMirror-Tern-completion-fn:before {
  content: "F";
}

.CodeMirror-Tern-completion-array:before {
  content: "A";
}

.CodeMirror-Tern-completion-number:before {
  content: "N";
}

.CodeMirror-Tern-completion-string:before {
  content: "S";
}

.CodeMirror-Tern-completion-bool:before {
  content: "B";
}

.CodeMirror-Tern-completion-guess {
  color: #999;
}

.CodeMirror-Tern-tooltip {
  border-radius: 3px;
  padding: 2px 5px;
  white-space: pre-wrap;
  max-width: 40em;
  position: absolute;
  z-index: 10;
}

.CodeMirror-Tern-hint-doc {
  max-width: 25em;
}

.CodeMirror-Tern-farg-current {
  text-decoration: underline;
}

.CodeMirror-Tern-fhint-guess {
  opacity: .7;
}

/* Override the background-color: white applied to filler elements in codemirror.css */
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
  appearance: auto;
  -moz-default-appearance: scrollcorner;
}

/* Markup view and Event tooltip styles */

.CodeMirror.cm-s-markup-view pre {
  font-size: var(--theme-code-font-size);
  line-height: var(--theme-code-line-height);
  min-height: 15px;
}

/* Make our own cursor-blink animation */
@keyframes cursor-blink {
  0% {}
  50% { opacity: 0; }
  100% {}
}

.CodeMirror-focused .CodeMirror-cursor {
  /*
   * We're using the --caret-blink-time custom property for the animation duration.
   * It is set in editor.js when we setup the CodeMirror instance, and will map either
   * to the value of the ui.caretBlinkTime preference, or to CodeMirror's default for
   * cursorBlinkRate. (See Bug 1609567 for more information on why this is needed).
   */
  /*
   * The animation should only be set when the editor is focused, otherwise the
   * animation will continue even when devtools is in a background tab.
   * This happens because the cursor is hidden using visiblity: hidden rather than
   * display: none in codemirror.css. See bug 1661054 for details.
   */
  animation: cursor-blink calc(var(--caret-blink-time, 0.53s) * 2) steps(1) infinite;
}


/*
 * Always align CodeMirror lines to the left.
 * See Bug 1651443 for more information.
 */
.CodeMirror-lines {
  text-align: left;
}

/* CodeMirror matchhighlight styling */
.cm-matchhighlight, .cm-searchMatch-selected {
  outline: 1px solid var(--theme-contrast-border);
  border-radius: 2px;
  /* Override cm6 inline */
  background-color: transparent !important;
}

/* Make the outline a bit more visible in High Contrast Mode */
:root[forced-colors-active] .cm-matchhighlight {
  outline-width: 2px;
  outline-offset: 2px;
}

.cm-non-printable-char {
  color: var(--theme-comment);
  font-size: 0.9em;
  border-radius: 2px;
  outline: 1px solid currentColor;
  margin-inline: 2px;
  padding-inline: 2px;
}

/* matching brackets highlight */
.cm-s-mozilla .CodeMirror-matchingbracket,
/* Codemirror 6 */
.cm-editor .cm-matchingBracket {
  text-decoration: 1px underline solid currentColor;
  text-decoration-skip-ink: none;
  text-underline-offset: 3px;
}

.cm-s-mozilla.CodeMirror-focused .CodeMirror-selected { /* selected text (focused) */
  background: var(--theme-text-selection-background);
}

.cm-s-mozilla .CodeMirror-selected { /* selected text (unfocused) */
  background: var(--theme-text-selection-unfocused-background);
}

/* cm5 High Contrast Mode override */
:root[forced-colors-active] {
  .CodeMirror-selectedtext {
    /* Set the color on the actual span elements */
    color: var(--theme-text-selection-color);
    /* We also need to set the background color to avoid the backplating and keep it readable  */
    background-color: var(--theme-text-selection-background);

    /* Set the background for the "active match" (i.e. when double clicking a word) */
    &.cm-matchhighlight {
      forced-color-adjust: auto;
      background-color: var(--theme-text-selection-background) !important;
      color: var(--theme-text-selection-color);
    }
  }

  /* Matching brackets */
  div.CodeMirror span.CodeMirror-matchingbracket {
    background-color: Mark;
    color: MarkText;
  }
}

/****************************************/
/***** CodeMirror 6 specific styles *****/
/****************************************/

.cm-editor {
  max-height: 100%;
  height: 100%;
}

/* This makes sure we use the font-family set for devtools */
.cm-editor .cm-scroller {
  font-family: unset;
}

/* Remove the default selection match background, as search results might have the
.cm-selectionMatch class after the current search term has been removed, these should not be styled`` */
.cm-editor .cm-selectionMatch {
  background-color: transparent;
}

.cm-editor .cm-selectionBackground {
  background: var(--theme-text-selection-background) !important;
}

.cm-editor .cm-content ::selection {
  /* We don't want forced colors on selection so we can adjust the colors as we want.
     This especially helps for the unfocused selected text */
  forced-color-adjust: none;
  color: inherit;
}

.cm-editor .cm-line ::selection {
  color: inherit;
}

:root[forced-colors-active] .cm-editor .cm-line ::selection,
:root[forced-colors-active] .cm-editor .cm-line::selection {
  background-color: var(--theme-text-selection-background) !important;
  color: var(--theme-text-selection-color) !important;
}

.cm6-dt-foldgutter__toggle-button {
  height: 20px;
  width: 20px;
  padding-inline: 3px;
  /* By default, the icon is a bit too low */
  translate: 0px -4px;
  background-image: url("chrome://devtools/skin/images/arrow.svg");
  background-position: center;
  background-repeat: no-repeat;
  background-color: transparent;
  border: none;
  outline-offset: -2px;
  -moz-context-properties: fill;
  fill: var(--theme-icon-dimmed-color);
  /* make the icons smaller than regular twistys (10->8px) */
  background-size: 8px;
  cursor: pointer;

  &[aria-expanded=false] {
    transform: rotate(-90deg);
  }
}

.cm-editor .cm-gutter.cm-lineNumbers {
  user-select: none;
}

.cm-editor .cm-foldPlaceholder {
  font-family: sans-serif;
  padding: 0 2px;
  border-radius: 3px;
  border: solid 1px var(--theme-splitter-color);
  color: var(--theme-body-color);
  background-color: var(--theme-sidebar-background);
  vertical-align: middle;
}

/* Repeat .cm-matchingBracket to get a higher specificity than the default codemirror rule */
.cm-editor .cm-matchingBracket.cm-matchingBracket {
  /* Removing the default background color */
  background-color: unset;
  /* Applying the same color that was set in cm5. Set the color on the parent so the
     underline set on the parent has the correct color */
  color: #0b0;

  :root[forced-colors-active] & {
    background-color: Mark;
    color: MarkText;
  }

  .tok-punctuation {
    color: currentColor;
  }
}

.highlight-line .CodeMirror-line,
/* For CM6 */
.cm-editor .cm-line.highlight-line {
  animation-name: fade-highlight-out;
  animation-duration: var(--highlight-line-duration);
  animation-timing-function: ease-out;
  animation-fill-mode: forwards;
}

@keyframes fade-highlight-out {

  0%,
  30% {
    /* We want to use a color with some transparency so text selection is visible through it */
    background-color: var(--theme-contrast-background-alpha);
  }
  100% {
    background-color: transparent;
  }
}

.cm-editor .cm-panels {
  background-color: var(--theme-toolbar-background);
  color: var(--theme-body-color);
}

.cm-editor .cm-panels-top {
  border-color: var(--theme-splitter-color);
}

/* Default search panel */
.cm-search .cm-textfield {
  width: 100%;
  font-size: inherit;
  background-color: transparent;
  border-color: var(--theme-splitter-color);
  margin: 0 !important;
}

/* Hide all other elements of the search except the text input */
.cm-search .cm-button, .cm-search label, .cm-search button[name="close"] {
  display: none;
}
