/* This Source Code Form is subject to the terms of the Creative Commons
 * Attribution-NonCommercial-ShareAlike International License, v. 4.0.
 * If a copy of the CC BY-NC-SA 4.0 was not distributed with this
 * file, You can obtain one at http://creativecommons.org/licenses/by-nc-sa/4.0/
 * or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. */

/* handles context menus opened in devtools processes,
and a few elements like checkboxes */

@-moz-document url-prefix("chrome://devtools/content/") {
  :root,
  menupopup {
    --focus-outline-color: var(--purple-30) !important;
    --focus-outline-width: 2px;
    --menu-background-color: var(--uc-arrowpanel-background) !important;
    --menu-color: var(--ui-text-80) !important;
    --menuitem-hover-background-color: var(--uc-arrowpanel-dimmed) !important;
    --menuitem-disabled-hover-background-color: initial !important;
    --menu-disabled-color: var(--uc-menu-disabled-color) !important;
    --menu-border-color: var(--uc-menu-border-color) !important;
    --arrowpanel-border-color: var(--uc-menu-border-color) !important;
    --menu-icon-opacity: 1 !important;
    --panel-separator-margin: var(--uc-panel-separator-margin) !important;
    --checkbox-border-color: var(--uc-checkbox-border-color) !important;
    --checkbox-checked-border-color: var(--uc-checkbox-checked-border-color) !important;
    --checkbox-unchecked-bgcolor: var(--uc-checkbox-unchecked-bgcolor) !important;
    --checkbox-unchecked-hover-bgcolor: var(--uc-checkbox-unchecked-hover-bgcolor) !important;
    --checkbox-unchecked-active-bgcolor: var(--uc-checkbox-unchecked-active-bgcolor) !important;
    --checkbox-checked-bgcolor: var(--uc-checkbox-checked-bgcolor) !important;
    --checkbox-checked-color: var(--uc-checkbox-checked-color) !important;
    --checkbox-checked-hover-bgcolor: var(--uc-checkbox-checked-hover-bgcolor) !important;
    --checkbox-checked-active-bgcolor: var(--uc-checkbox-checked-active-bgcolor) !important;
    --error-text-color: var(--warning-color) !important;
  }

  .theme-light {
    --checkbox-border-color: #aaa !important;
    --checkbox-unchecked-bgcolor: #eee !important;
    --checkbox-unchecked-hover-bgcolor: #e6e6e6 !important;
    --checkbox-unchecked-active-bgcolor: #ddd !important;
  }

  menupopup > :is(menuitem, menu, menucaption, menugroup, menuseparator, search-textbox),
  panel > richlistbox > richlistitem {
    margin-inline: var(--menupopup-inner-padding-magnitude);
  }

  input:is([type="checkbox"], [type="radio"]) {
    appearance: none !important;
    width: 14px;
    height: 14px;
    min-width: 14px;
    min-height: 14px;
    fill: currentColor;
    -moz-context-properties: fill, fill-opacity, stroke;
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    border: 1px solid var(--checkbox-border-color);
    background-color: var(--checkbox-unchecked-bgcolor);
    color: var(--uc-parent-primary-button-text-color);
  }

  input[type="checkbox"] {
    border-radius: 2px;
    margin-inline: 4px;
    margin-block: 3px 2px;
  }

  .ruleview-enableproperty {
    background-color: transparent !important;
  }

  .devtools-checkbox-label:not([hidden]) {
    display: flex;
    align-items: center;
  }

  .devtools-checkbox-label input[type="checkbox"] {
    margin-block: 3px;
  }

  input:is([type="checkbox"], [type="radio"]):is(:hover, :focus-visible) {
    background-color: var(--checkbox-unchecked-hover-bgcolor);
  }

  input:is([type="checkbox"], [type="radio"]):is(:hover, :focus-visible):active {
    background-color: var(--checkbox-unchecked-active-bgcolor);
  }

  input:is([type="checkbox"], [type="radio"]):is([checked="true"], :checked):is(:hover, :focus-visible) {
    background-color: var(--checkbox-checked-hover-bgcolor);
  }

  input:is([type="checkbox"], [type="radio"]):is([checked="true"], :checked):is(:hover, :focus-visible):active {
    background-color: var(--checkbox-checked-active-bgcolor);
  }

  input[type="checkbox"]:is([checked="true"], :checked) {
    background-image: url(chrome://userchrome/content/check.svg);
    border-color: var(--checkbox-checked-border-color);
    background-color: var(--checkbox-checked-bgcolor);
  }

  input[type="radio"] {
    border-radius: 100%;
    margin-inline: 4px;
  }

  input[type="radio"]:is([checked="true"], :checked) {
    background-image: url(chrome://userchrome/content/radio.svg);
    border-color: var(--checkbox-checked-border-color);
    background-color: var(--checkbox-checked-bgcolor);
  }

  menupopup {
    appearance: none !important;
    background: var(--menupopup-background) !important;
    border: none !important;
    border-radius: var(--menupopup-border-radius) !important;
    margin: var(--menupopup-margin) !important;
    overflow: hidden !important;
    -moz-window-shadow: none !important;
  }

  menupopup menu > menupopup {
    margin-inline-start: var(--menupopup-child-margin-inline-start) !important;
    margin-block-start: var(--menupopup-child-margin-block-start) !important;
  }

  menupopup:not([height], .in-menulist) {
    --menupopup-overflowing-inner-box-margin: 0;
  }

  .menupopup-arrowscrollbox {
    background-color: var(--menu-background-color) !important;
    color: var(--menu-color) !important;
    border-radius: var(--menupopup-border-radius) !important;
    box-shadow: var(--uc-menupopup-shadow) !important;
  }

  .menupopup-arrowscrollbox[orient="vertical"][overflowing="true"] {
    margin-block: var(--menupopup-overflowing-inner-box-margin, var(--menupopup-inner-box-margin)) !important;
  }

  :is(menuitem, menu),
  panel[type="autocomplete-richlistbox"] > richlistbox > richlistitem {
    appearance: none !important;
    color: var(--menu-color) !important;
    padding: 0 !important;
    min-height: var(--menuitem-height) !important;
    border-radius: var(--context-menuitem-border-radius);
  }

  :is(menuitem, menu)[disabled="true"],
  panel[type="autocomplete-richlistbox"] > richlistbox > richlistitem[disabled="true"] {
    appearance: none !important;
    color: var(--menu-disabled-color) !important;
    background-color: initial !important;
  }

  :is(menuitem, menu) .menu-icon {
    padding: 0 !important;
    appearance: none !important;
    margin-inline-end: 0 !important;
  }

  :is(menuitem, menu) .menu-iconic-icon {
    margin-inline: var(--context-iconic-margin);
  }

  panel[type="autocomplete-richlistbox"] > richlistbox > richlistitem :is(.ac-site-icon, .ac-type-icon) {
    margin-inline: var(--context-iconic-margin) !important;
    margin-inline-start: 0 !important;
  }

  menugroup {
    padding: 0 !important;
    background-color: transparent !important;
  }

  .menu-right {
    appearance: none !important;
    padding: 0 !important;
    margin-right: var(--menu-right-margin) !important;
    min-width: 0 !important;
    width: var(--menu-right-size) !important;
    height: var(--menu-right-size) !important;
    fill: currentColor !important;
    -moz-context-properties: fill, fill-opacity, stroke, stroke-opacity !important;
    fill-opacity: 0.6 !important;
    background-size: 10px 10px !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    background-image: var(--menu-right-bg) !important;
    list-style-image: var(--menu-right-img) !important;
  }

  menu[disabled="true"] > .menu-right {
    visibility: collapse;
  }

  :is(menu, menuitem)[_moz-menuactive="true"]:not([disabled="true"]) {
    appearance: none !important;
    background-color: var(--menuitem-hover-background-color) !important;
  }

  :is(menu, menuitem)[_moz-menuactive="true"][disabled="true"] {
    background: none !important;
    appearance: none !important;
  }

  .subviewbutton:is(:hover, :focus-visible, [_moz-menuactive="true"])[disabled="true"] {
    color: var(--menu-disabled-color) !important;
  }

  menu.subviewbutton:not([disabled="true"])[_moz-menuactive="true"]:active {
    background: var(--menuitem-hover-background-color) !important;
    box-shadow: none !important;
  }

  menupopup menuitem:is([type="checkbox"], [type="radio"])::before {
    position: relative;
    display: -moz-inline-box;
    width: 14px;
    height: 14px;
    margin-inline: var(--context-checkbox-margin);
    box-sizing: border-box;
    fill: currentColor;
    -moz-context-properties: fill, fill-opacity, stroke;
    content: "";
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    border: 1px solid var(--checkbox-border-color);
    background-color: var(--checkbox-unchecked-bgcolor);
    color: var(--uc-parent-primary-button-text-color);
  }

  menupopup menuitem[type="checkbox"]::before {
    border-radius: 2px;
  }

  menupopup menuitem:is([type="checkbox"], [type="radio"])[_moz-menuactive="true"]::before {
    background-color: var(--checkbox-unchecked-hover-bgcolor);
  }

  menupopup menuitem:is([type="checkbox"], [type="radio"])[_moz-menuactive="true"]:active::before {
    background-color: var(--checkbox-unchecked-active-bgcolor);
  }

  menupopup menuitem:is([type="checkbox"], [type="radio"])[checked="true"][_moz-menuactive="true"]::before {
    background-color: var(--checkbox-checked-hover-bgcolor);
  }

  menupopup menuitem:is([type="checkbox"], [type="radio"])[checked="true"][_moz-menuactive="true"]:active::before {
    background-color: var(--checkbox-checked-active-bgcolor);
  }

  menupopup menuitem[type="checkbox"][checked="true"]::before {
    background-image: url(chrome://userchrome/content/check.svg);
    border-color: var(--checkbox-checked-border-color);
    background-color: var(--checkbox-checked-bgcolor);
  }

  menupopup menuitem[type="radio"]::before {
    border-radius: 100%;
  }

  menupopup menuitem[type="radio"][checked="true"]::before {
    background-image: url(chrome://userchrome/content/radio.svg);
    border-color: var(--checkbox-checked-border-color);
    background-color: var(--checkbox-checked-bgcolor);
  }

  menupopup menuitem:is([type="checkbox"], [type="radio"]) .menu-icon {
    display: none;
  }

  #ContentSelectDropdown > menupopup > :where(menucaption, menuitem) > .menu-iconic-text,
  menupopup.in-menulist > :where(menucaption, menuitem) > .menu-iconic-text {
    padding-block: unset !important;
  }

  :is(#ContentSelectDropdown, menupopup.in-menulist, .contentSelectDropdown-ingroup) :is(menu, menuitem, menucaption),
  panel[type="autocomplete-richlistbox"] > richlistbox > richlistitem {
    padding-inline: 8px !important;
    min-height: var(--menuitem-height) !important;
    border: none !important;
  }

  :is(#ContentSelectDropdown, menupopup.in-menulist, .contentSelectDropdown-ingroup) :is(menu, menuitem, menucaption) > :is(label, .menu-iconic-text, .menu-text) {
    padding-inline: 0 !important;
    font: menu !important;
  }

  :is(#ContentSelectDropdown, menupopup.in-menulist, .contentSelectDropdown-ingroup) menucaption {
    font-weight: inherit !important;
    min-height: 26px !important;
    padding-block: 1px 2px !important;
    padding-inline: 0 !important;
    color: var(--panel-description-color) !important;
  }

  :is(#ContentSelectDropdown, menupopup.in-menulist, .contentSelectDropdown-ingroup) menucaption > :is(label, .menu-iconic-text, .menu-text) {
    padding: 4px 5px !important;
    border-bottom: 1px solid var(--menu-separator-color) !important;
    font-weight: var(--uc-font-weight-bold, 600) !important;
  }

  #ContentSelectDropdown > menupopup {
    background-color: transparent !important;
    --content-select-background-image: none !important;
    color: var(--menu-color) !important;
    background-image: unset !important;
  }

  #ContentSelectDropdown > menupopup > menuitem:not([_moz-menuactive="true"]),
  menupopup.in-menulist > menuitem:not([_moz-menuactive="true"]) {
    background-color: transparent !important;
    color: var(--menu-color) !important;
  }

  #ContentSelectDropdown > menupopup > menuitem[disabled="true"],
  menupopup.in-menulist > menuitem[disabled="true"] {
    appearance: none !important;
    color: var(--menu-disabled-color) !important;
    background-color: initial !important;
  }

  menupopup.in-menulist {
    appearance: none !important;
    border: none !important;
    border-radius: var(--menupopup-border-radius) !important;
    margin: var(--menupopup-margin) !important;
    overflow: hidden !important;
    color: var(--menu-color) !important;
    background-image: unset !important;
  }

  #ContentSelectDropdown > menupopup .contentSelectDropdown-searchbox {
    appearance: none !important;
    color: inherit !important;
    border-radius: var(--context-menuitem-border-radius);
    margin-block: 0 !important;
    margin-inline: var(--menupopup-inner-padding-magnitude) !important;
    padding-inline-start: 3px !important;
    background-color: var(--menuitem-hover-background-color) !important;
    padding-block: 0 !important;
    transition: 300ms background-color !important;
    min-height: var(--menuitem-height) !important;
    -moz-user-modify: read-write !important;
  }

  #ContentSelectDropdown > menupopup .contentSelectDropdown-searchbox:focus-within {
    background-color: var(--search-box-focus) !important;
    transition: 300ms background-color !important;
  }

  #ContentSelectDropdown > menupopup .contentSelectDropdown-searchbox + :is(menu, menuitem) {
    margin-top: 4px;
  }

  panel[type="autocomplete-richlistbox"] > richlistbox {
    background: none !important;
    color: var(--menu-color) !important;
  }

  .grid-element-width-resizer {
    --inline-inset: 3px !important;
    width: 4px !important;
  }

  menu,
  menuitem {
    &:not([type="checkbox"]) > .menu-text {
      padding-inline: var(--context-padding-inline) !important;
    }
  }

  :is(.menu-accel, .menu-iconic-accel)[value] {
    margin-inline: 1.55em calc(var(--menu-right-margin) + 4px) !important;
    padding-block: 0 !important;
  }

  menuitem:not([disabled="true"]) :is(.menu-accel, .menu-iconic-accel) {
    color: var(--uc-panel-shortcut-color);
  }

  menuitem[disabled="true"] :is(.menu-accel, .menu-iconic-accel) {
    opacity: 0.6;
  }

  menuseparator {
    appearance: none !important;
    border-color: var(--menu-separator-color) !important;
    margin: var(--menu-separator-margin) !important;
    margin-inline: var(--menupopup-inner-padding-magnitude) !important;
    padding: 0 !important;
  }

  menupopup[menu-api] menuitem:is([type="checkbox"], [type="radio"]) .menu-icon {
    display: none !important;
  }

  .CodeMirror-dialog.CodeMirror-dialog-top {
    display: flex !important;
    flex-flow: row nowrap;
    align-items: center !important;
    padding-inline: 6px !important;
  }

  .CodeMirror-dialog.CodeMirror-dialog-top .CodeMirror-search-field {
    width: auto !important;
    flex-grow: 1 !important;
    flex-shrink: 1 !important;
  }

  .CodeMirror-search-hint {
    margin-inline-end: 4px !important;
  }

  /* highlight stylesheets owned by the user so they're easier to find */
  #style-editor-chrome-window .stylesheet-name label {
    &[tooltiptext^="file://"],
    &[tooltiptext^="chrome://userchrome/"],
    &[tooltiptext^="chrome://userstyles/"] {
      text-decoration: underline !important;
      color: var(--attention-color) !important;
    }
  }

  .ruleview-rule-source-label {
    &[href^="file://"],
    &[href^="chrome://userchrome/"],
    &[href^="chrome://userstyles/"] {
      text-decoration: underline !important;
      color: var(--pink-action) !important;
    }
  }

  /* make the highlighting on unsaved stylesheets more obvious */
  #style-editor-chrome-window li.unsaved:not(.splitview-active) {
    background-color: var(--uc-content-box-background) !important;
  }

  #style-editor-chrome-window li.unsaved > hgroup .stylesheet-name label,
  #style-editor-chrome-window li.unsaved > hgroup .stylesheet-name::before,
  #style-editor-chrome-window li.unsaved > hgroup .stylesheet-name::after {
    color: var(--low-warning-text-color) !important;
  }

  /* stylelint-disable-next-line media-query-no-invalid */
  @media -moz-pref("userChrome.css.mac-ui-fonts") {
    menupopup {
      font-family: SF Pro Text, SF Arabic, Segoe UI, sans-serif !important;
      font-kerning: normal !important;
    }

    :is(#ContentSelectDropdown, menupopup.in-menulist, .contentSelectDropdown-ingroup) :is(menu, menuitem, menucaption) > :is(label, .menu-iconic-text, .menu-text) {
      font-family: SF Pro Text, SF Arabic, Segoe UI, sans-serif !important;
      font-kerning: normal !important;
    }
  }

  /* stylelint-disable-next-line media-query-no-invalid */
  @media -moz-pref("userChrome.css.remove-menu-borders") {
    .menupopup-arrowscrollbox {
      border: none !important;
    }
  }
}

@-moz-document url-prefix("about:devtools-toolbox") {
  /* replace icons for devtools tabs added by extensions with dark mode responsive icons.
    e.g., react devtools, angular devtools, angular state inspector. */
  .devtools-tab[data-extension-id="@react-devtools"] > img {
    padding-inline: 0 16px !important;
    max-width: 16px !important;
    box-sizing: border-box !important;
    background-image: url(chrome://userchrome/content/devtools/sources/react.svg);
    background-size: 16px;
    background-position: center;
    background-repeat: no-repeat;
  }

  .devtools-tab[data-extension-id="angular-devtools@aminomancer"] > img {
    padding-inline: 0 16px !important;
    max-width: 16px !important;
    box-sizing: border-box !important;
    background-image: url(chrome://userchrome/content/devtools/sources/angular.svg);
    background-size: 16px;
    background-position: center;
    background-repeat: no-repeat;
  }

  .devtools-tab[data-extension-id="{8c161eb2-86b5-49e8-8e49-c789821be12e}"] > img {
    padding-inline: 0 16px !important;
    max-width: 16px !important;
    box-sizing: border-box !important;
    background-image: url(chrome://userchrome/content/devtools/sources/angular-state.svg);
    background-size: 16px;
    background-position: center;
    background-repeat: no-repeat;
  }

  .chrome-debug-toolbar {
    background-color: var(--theme-sidebar-background) !important;
  }

  .chrome-debug-toolbar__modes label.selected {
    border-color: hsla(0, 0%, 50%, 0.5) !important;
    background-color: hsla(0, 0%, 50%, 0.15);
  }
}
