:root {
  --organizer-color: -moz-DialogText;
  --organizer-deemphasized-color: GrayText;

  --organizer-toolbar-background: -moz-Dialog;
  --organizer-pane-background: -moz-Dialog;
  --organizer-content-background: -moz-Dialog;

  --organizer-hover-background: SelectedItem;
  --organizer-hover-color: SelectedItemText;
  --organizer-selected-background: SelectedItem;
  --organizer-selected-color: SelectedItemText;
  --organizer-outline-color: SelectedItem;

  --organizer-separator-color: ThreeDDarkShadow;
  --organizer-border-color: ThreeDShadow;

  --organizer-toolbar-field-background: Field;
  --organizer-toolbar-field-background-focused: Field;
  --organizer-toolbar-field-border-color: ThreeDShadow;
  --organizer-toolbar-field-focus-border-color: var(--organizer-outline-color);
  --organizer-toolbar-field-focus-box-shadow: unset;
  --organizer-pane-field-border-color: ThreeDShadow;

  @include NotContrast {
    --organizer-color: var(--in-content-page-color);
    --organizer-deemphasized-color: var(--in-content-deemphasized-text);

    --organizer-toolbar-background: rgb(249, 249, 251); /* --toolbar-bgcolor */
    --organizer-pane-background: rgb(229, 229, 235); /* --lwt-accent-color */
    --organizer-content-background: var(--in-content-page-background);

    --organizer-hover-background: var(--in-content-button-background-hover);
    --organizer-hover-color: var(--organizer-color);
    --organizer-selected-background: var(--in-content-button-background-active);
    --organizer-selected-color: var(--organizer-color);
    --organizer-outline-color: var(--in-content-focus-outline-color);

    --organizer-separator-color: var(--organizer-pane-field-border-color);
    --organizer-border-color: var(--in-content-border-color);

    --organizer-toolbar-field-background: rgb(240, 240, 244); /* --lwt-accent-color */
    --organizer-toolbar-field-background-focused: Field;
    --organizer-toolbar-field-border-color: transparent;
    --organizer-toolbar-field-focus-border-color: color-mix(
      in srgb,
      var(--organizer-outline-color) 50%,
      transparent
    );
    --organizer-toolbar-field-focus-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.23);
    --organizer-pane-field-border-color: color-mix(in srgb, currentColor 41%, transparent);

    @include Dark {
      --organizer-color: rgb(251, 251, 254);
      --organizer-deemphasized-color: rgb(191, 191, 201);

      --organizer-toolbar-background: rgb(43, 42, 51);
      --organizer-pane-background: rgb(35, 34, 43);
      --organizer-content-background: rgb(28, 27, 34);

      --organizer-hover-background: rgb(82, 82, 94);
      --organizer-selected-background: rgb(91, 91, 102);

      --organizer-toolbar-field-background: var(--in-content-page-background);
      --organizer-toolbar-field-background-focused: rgb(66, 65, 77);
      scrollbar-color: rgba(249, 249, 250, 0.4) rgba(20, 20, 25, 0.3);
    }
  }
}

/*- Toolbar & Menus ------------------------------------------------------*/
#placesToolbar {
  appearance: none !important;
  background-color: var(--organizer-toolbar-background) !important;
  color: var(--organizer-color) !important;
  border-bottom: 1px solid var(--organizer-border-color) !important;
  padding: 4px !important;
  padding-inline-end: 6px !important;

  > toolbarbutton {
    appearance: none !important;
    padding: 5px !important;
    border-radius: 4px !important;

    @include Option("userChrome.rounding.square_button") {
      border-radius: 0 !important;
    }

    &[disabled] {
      opacity: 0.6 !important;
    }
    &:not([disabled]):hover {
      background-color: var(--organizer-hover-background) !important;
      color: var(--organizer-hover-color) !important;
      &:active {
        background-color: var(--organizer-selected-background) !important;
      }
    }
  }
}

#placesToolbar > toolbarbutton > .toolbarbutton-icon,
#placesMenu > menu > image,
#placesMenu > menu > :is(.menubar-text, .menu-text) {
  -moz-context-properties: fill !important;
  fill: currentColor !important;
}

#placesMenu {
  margin-inline-start: 6px !important;

  > menu {
    appearance: none !important;
    color: var(--organizer-color) !important;
    padding-block: 5px !important;
    padding-inline-start: 5px !important;
    border-radius: 4px !important;
    margin-inline-end: 2px !important;

    @include Option("userChrome.rounding.square_button") {
      border-radius: 0 !important;
    }

    &[_moz-menuactive="true"],
    &:hover {
      background-color: var(--organizer-hover-background) !important;
      color: var(--organizer-hover-color) !important;
    }
    &:hover:active,
    &[open] {
      background-color: var(--organizer-selected-background) !important;
      color: var(--organizer-selected-color) !important;
    }
    > :is(.menubar-text, .menu-text) {
      margin-block: 0 !important; /* override menu.css */
      padding-inline-end: 4px !important;
    }
  }
}

/*- Search Bar & Input ---------------------------------------------------*/
#searchFilter,
#detailsPane html|input {
  appearance: none !important;
  background-color: var(--organizer-toolbar-field-background) !important;
  color: var(--organizer-color) !important;
  border: 1px solid var(--organizer-toolbar-field-border-color) !important;
  border-radius: 4px !important;
  margin: 0 !important;
  padding-block: 2px !important;
  min-height: 24px !important;

  @include Option("userChrome.rounding.square_field") {
    border-radius: 0 !important;
  }
}

#searchFilter[focused] {
  box-shadow: var(--organizer-toolbar-field-focus-box-shadow) !important;
  background-color: var(--organizer-toolbar-field-background-focused) !important;
  border-color: transparent !important;
  outline: 2px solid var(--organizer-toolbar-field-focus-border-color) !important;
  outline-offset: -2px !important;
}

/*- Sidebar & Splitter ---------------------------------------------------*/
#placesList {
  background-color: var(--organizer-pane-background) !important;
}

#placesView > splitter {
  border: 0 !important;
  border-inline-end: 1px solid var(--organizer-border-color) !important;
  min-width: 0 !important;
  width: 3px !important;
  background-color: transparent !important;
  margin-inline-start: -3px !important;
  position: relative !important;
}

/*- Downloads Pane -------------------------------------------------------*/
#downloadsRichListBox, /* Legacy - FF v98 */
#downloadsListBox {
  color: var(--organizer-color) !important;
  background-color: var(--organizer-content-background) !important;
}

#clearDownloadsButton:focus-visible {
  outline: 2px solid var(--organizer-outline-color) !important;
}

richlistitem[selected="true"],
richlistitem:hover {
  background-color: var(--organizer-hover-background) !important;
  color: var(--organizer-color) !important;
}

richlistbox:where(:focus) > richlistitem[selected="true"] {
  background-color: var(--organizer-selected-background) !important;
}

/*- Tree -----------------------------------------------------------------*/
#contentView treecol {
  /* Use box-shadow to draw a bottom border instead of border-bottom
     * because otherwise the items on contentView won't be perfectly
     * aligned with the items on the sidebar. */
  box-shadow: inset 0 -1px var(--organizer-border-color) !important;
}

tree {
  background-color: var(--organizer-content-background) !important;
  color: var(--organizer-color) !important;
}

treecol:not([hideheader="true"]),
treecolpicker {
  appearance: none !important;
  border: none !important;
  background-color: var(--in-content-button-background) !important;
  color: var(--organizer-color, inherit) !important;
  padding: 5px 10px !important;
}

treecol:not([hideheader="true"], [sortable="false"]):hover,
treecolpicker:hover {
  background-color: var(--organizer-hover-background) !important;
  color: var(--organizer-color) !important;

  &:active {
    background-color: var(--organizer-selected-background) !important;
  }
}

treecol:not([hideheader="true"], :first-child),
treecolpicker {
  padding-left: 10px !important;
  border-inline-start-width: 1px !important;
  border-inline-start-style: solid !important;
  border-image: linear-gradient(
      transparent 0%,
      transparent 20%,
      var(--organizer-border-color) 20%,
      var(--organizer-border-color) 80%,
      transparent 80%,
      transparent 100%
    )
    1 1 !important;
}

treecol[sortDirection]:not([hideheader="true"]) > xul|*.treecol-sortdirection {
  fill: currentColor !important;
  width: 18px !important;
  height: 18px !important;
}

treechildren {
  &::-moz-tree-row {
    background-color: transparent !important;
  }
  &::-moz-tree-row(hover) {
    background-color: var(--organizer-hover-background) !important;
  }
  &::-moz-tree-row(selected) {
    background-color: var(--organizer-selected-background) !important;
    color: var(--organizer-selected-color) !important;
    border: 1px solid transparent !important;
  }

  &::-moz-tree-image(hover),
  &::-moz-tree-twisty(hover),
  &::-moz-tree-cell-text(hover) {
    color: var(--organizer-hover-color) !important;
  }
  &::-moz-tree-image(selected),
  &::-moz-tree-twisty(selected),
  &::-moz-tree-cell-text(selected) {
    color: var(--organizer-selected-color) !important;
  }

  &::-moz-tree-separator {
    height: 1px !important;
    border-color: var(--organizer-separator-color) !important;
  }
  &::-moz-tree-separator(hover) {
    border-color: var(--organizer-hover-color) !important;
  }
  &::-moz-tree-separator(selected) {
    border-color: var(--organizer-selected-color) !important;
  }

  &::-moz-tree-cell-text(primary, dropOn),
  &::-moz-tree-drop-feedback {
    background-color: var(--organizer-outline-color) !important;
  }
}

/*- Info Box -------------------------------------------------------------*/
#detailsPane {
  background-color: var(--organizer-pane-background) !important;
  color: var(--organizer-color) !important;
  padding: 5px !important;
  border-top: 1px solid var(--organizer-border-color) !important;
}

#editBookmarkPanelRows .expander-up,
#editBookmarkPanelRows .expander-down {
  appearance: none !important;
  min-width: 0 !important;
  padding: 5px !important;
  margin: 0 !important;
  margin-inline-end: 4px !important;
  border: 1px solid var(--organizer-pane-field-border-color) !important;
  border-radius: 4px !important;
  color: var(--organizer-color) !important;
  background-color: var(--organizer-content-background) !important;
  -moz-context-properties: fill !important;
  fill: currentColor !important;

  @include Option("userChrome.rounding.square_button") {
    border-radius: 0 !important;
  }

  &:hover {
    background-color: var(--organizer-hover-background) !important;
    color: var(--organizer-hover-color) !important;

    &:active {
      background-color: var(--organizer-selected-background) !important;
      color: var(--organizer-selected-color) !important;
    }
  }
  &:focus-visible {
    outline: 2px solid var(--organizer-outline-color) !important;
    outline-offset: -1px !important;
  }

  > .button-box {
    padding: 0 !important;
  }
}

#editBookmarkPanelRows {
  .expander-up {
    list-style-image: url("chrome://global/skin/icons/arrow-up-12.svg");
  }
  .expander-down {
    list-style-image: url("chrome://global/skin/icons/arrow-down-12.svg");
  }
}

#places input {
  border: 1px solid var(--organizer-pane-field-border-color) !important;
  border-radius: 4px !important;
  background-color: var(--organizer-content-background) !important;
  color: var(--organizer-color) !important;
  min-height: 20px !important;
  padding-inline: 4px !important;

  @include Option("userChrome.rounding.square_field") {
    border-radius: 0 !important;
  }

  &:focus {
    outline: 2px solid var(--organizer-outline-color) !important;
    outline-offset: -1px !important;
  }
  &:not(:read-write):focus {
    outline: none !important;
  }
}

.caption-label {
  margin-inline-start: 8px !important;
  color: var(--organizer-deemphasized-color) !important;
}

#editBMPanel_tagsSelectorRow > richlistbox {
  appearance: none !important;
  color: var(--organizer-color) !important;
  background-color: var(--organizer-content-background) !important;
  border: 1px solid var(--organizer-border-color) !important;
  border-radius: 4px !important;

  @include Option("userChrome.rounding.square_field") {
    border-radius: 0 !important;
  }

  > richlistitem {
    border: 1px solid transparent !important;

    &:hover {
      background-color: var(--organizer-hover-background) !important;
      color: var(--organizer-hover-color) !important;
    }
    &[selected] {
      background-color: var(--organizer-selected-background) !important;
      color: var(--organizer-selected-color) !important;
    }
  }
}
