/* 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. */

/* this controls the general appearance of the tab bar, not individual tabs. it
also controls the all tabs panel since the all tabs button is within the tab
bar. since the window controls and main menu bar are normally part of the
titlebar, this sheet controls their appearance as well. */

.browser-toolbox-background {
  background-color: var(--lwt-accent-color) !important;
}

#toolbar-menubar[inactive="true"] ~ #TabsToolbar,
#toolbar-menubar:not([inactive="true"]) {
  padding-inline-end: 6px !important;
}

.titlebar-spacer[type="pre-tabs"] {
  display: none;
}

.titlebar-spacer[type="post-tabs"],
#toolbar-menubar > spacer {
  width: var(--titlebar-spacer-width, 32px) !important;
  display: flex !important;
}

#nav-bar .titlebar-spacer[type="post-tabs"] {
  display: none !important;
}

#navigator-toolbox {
	will-change: revert !important;
	transition: none !important;
}

#toolbar-menubar:not([inactive="true"]) {
  /* split the width in half to center the menubar between the tabs and the titlebar buttons */
  > spacer,
  + #TabsToolbar .titlebar-spacer {
    width: calc(var(--titlebar-spacer-width, 32px) / 2) !important;
  }

  + #TabsToolbar {
    > .titlebar-buttonbox-container {
      display: none !important;
    }

    margin-inline-end: 472.817px !important;
  }
}

@media (-moz-platform: windows) {
  :root:not([chromehidden~="menubar"]) #toolbar-menubar:not([inactive]) + #TabsToolbar .titlebar-spacer {
    display: none;
  }
}

#titlebar {
  flex-flow: row nowrap !important;
}

#tabbrowser-tabs {
  background-color: var(--lwt-accent-color) !important;
}

/* menubar next to tabs (merge tabs bar with titlebar menubar and flow them horizontally) */
#toolbar-menubar {
  order: 2;
  position: absolute;
  right: 0;
  height: var(--tabstrip-min-height) !important;

  &[autohide=""][inactive="true"]:not([customizing="true"]) {
    max-width: 0 !important;
    min-width: 0 !important;
    width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 0 !important;
  }
}

:root[inFullscreen] {
  #toolbar-menubar {
    visibility: visible !important;
  }
}

/* menubar buttons */
#main-menubar {
  flex-grow: 1 !important;

  > menu > menupopup {
    margin-block: calc(0px - var(--menupopup-inner-box-margin) - ((var(--tab-min-height) - 16px - 4px - 5px) / 2)) !important;
    margin-inline: calc(0px - var(--menupopup-inner-box-margin) + 2px) !important;
  }
}

#toolbar-menubar {
  #main-menubar {
    > menu {
      appearance: none !important;
      background-color: transparent !important;
      padding-inline: 2px !important;
      margin-inline: 0 !important;

      > label {
        margin: 0 !important;
        padding: 4px 8px 5px 8px !important;
        border-radius: var(--toolbarbutton-border-radius) !important;
      }

      &[_moz-menuactive="true"] > label {
        background-color: var(--toolbarbutton-hover-background) !important;
      }

      &[open] > label {
        background-color: var(--toolbarbutton-active-background) !important;
      }
      
      > .menu-accel {
        display: none !important;
      }
    }
  }

  #search-container {
    padding: 0 !important;
    margin: 0 2px !important;
    min-height: 0 !important;
    min-width: var(--uc-menubar-searchbar-width) !important;
    resize: horizontal !important;
    height: 100% !important;
    box-sizing: border-box !important;
  }

  #searchbar {
    min-height: 28px !important;
    border: none !important;
    box-shadow: none !important;

    .searchbar-search-icon {
      margin-left: 5px !important;
    }

    .search-go-button {
      border-radius: 0 !important;
      margin: 0 !important;
    }
  }

  .searchbar-textbox {
    min-height: 28px !important;
  }
}

#tabs-newtab-button,
#newPrivateTab-button {
  display: none !important;
}

#tabbrowser-tabs[hasadjacentnewtabbutton]:not([overflow]) ~ #new-tab-button {
	display: revert !important;
}

/* get rid of drop shadow drawn on leftmost visible tab */
.tabbrowser-arrowscrollbox > .arrowscrollbox-overflow-start-indicator {
  visibility: collapse !important;
}

/* tab dragging and dropping icon */
.tab-drop-indicator {
  background-image: url(chrome://userchrome/content/tab-drag-indicator.svg) !important;
  -moz-context-properties: fill, fill-opacity, stroke, stroke-opacity !important;
  fill: var(--lwt-toolbarbutton-icon-fill, currentColor) !important;
  margin-bottom: -40px !important;
  z-index: 2500 !important;
  margin-inline-start: -20px !important;
  background-size: contain !important;
  width: 20px !important;
}

#tabs-newtab-button {
  padding-left: 4px !important;
  z-index: 1 !important;
  position: relative !important;
}

#tabbrowser-tabs {
  margin-inline: 3px !important;

  &:first-child {
    margin-inline-start: 0 !important;
  }

  &:last-child {
    margin-inline-end: 0 !important;
  }
}

:is(toolbarbutton, toolbaritem, toolbarpaletteitem) + #tabbrowser-tabs {
  margin-inline-start: 2px !important;
}

/* non-overflowing tabs shouldn't draw shadows on new tab button since
overflowing tabs don't draw shadows on the special new tab button */
#tabbrowser-tabs:not([overflow]) #tabs-newtab-button {
  z-index: 5 !important;
}

#TabsToolbar .customization-target {
  min-width: 0 !important;
  overflow-x: clip !important;
}

:root:not([sizemode="normal"]) {
  .arrowscrollbox-overflow-end-indicator,
  .tabbrowser-arrowscrollbox > .arrowscrollbox-overflow-start-indicator {
    visibility: collapse !important;
  }
}

:is(tabbrowser, #TabsToolbar) toolbarbutton[class^="scrollbutton"] {
  display: none !important;
}

#TabsToolbar .toolbarbutton-1 > :is(.toolbarbutton-icon, .toolbarbutton-text, .toolbarbutton-badge-stack) {
  border-radius: var(--toolbarbutton-border-radius) !important;
}

/* macOS style window controls */
.titlebar-button {
  border: none;
  margin: 0 !important;
  padding: 8px 17px;
  -moz-context-properties: fill, stroke !important;
  stroke: none !important;
  fill: none !important;
  content: none !important;
  
  > .toolbarbutton-icon {
    display: revert !important;
  }
}

:root:not([sizemode="maximized"], [inFullscreen]) .titlebar-restore,
:root:is([sizemode="maximized"], [inFullscreen]) .titlebar-max {
  display: none !important;
}

:root:-moz-window-inactive:not([customizing]) .titlebar-buttonbox > toolbarbutton:not(:hover) {
  list-style-image: url(chrome://userchrome/content/window/inactive.svg) !important;
}

.titlebar-buttonbox {
  appearance: none !important;

  .titlebar-button > .toolbarbutton-icon {
    appearance: none !important;
    width: 15.3px !important;
    height: 15.3px !important;
    stroke: inherit !important;
    opacity: 1 !important;
  }
}

.titlebar-max,
.titlebar-restore {
  appearance: none !important;
  padding: 0 !important;
  padding-left: 7px !important;
  padding-right: 7px !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  background-color: transparent !important;
  list-style-image: url(chrome://userchrome/content/window/maximize.svg) !important;

  &.titlebar-max {
    &:hover,
    &:focus-visible {
      list-style-image: url(chrome://userchrome/content/window/maximize-hover.svg) !important;

      :root:is([sizemode="maximized"], [inFullscreen]) & {
        list-style-image: url(chrome://userchrome/content/window/maximize-restore.svg) !important;
      }
    }
  }

  &.titlebar-restore {
    &:hover,
    &:focus-visible {
      list-style-image: url(chrome://userchrome/content/window/maximize-restore.svg) !important;
    }
  }
}

.titlebar-min {
  appearance: none !important;
  padding: 0 !important;
  padding-left: 7px !important;
  padding-right: 7px !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  background-color: transparent !important;
  list-style-image: url(chrome://userchrome/content/window/minimize.svg) !important;

  &:hover,
  &:focus-visible {
    list-style-image: url(chrome://userchrome/content/window/minimize-hover.svg) !important;
  }
}

.titlebar-close {
  appearance: none !important;
  padding: 0 !important;
  padding-left: 7px !important;
  padding-right: 7px !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  background-color: transparent !important;
  list-style-image: url(chrome://userchrome/content/window/close.svg) !important;

  &:hover,
  &:focus-visible {
    list-style-image: url(chrome://userchrome/content/window/close-hover.svg) !important;
  }
}

/* private browsing indicator next to window controls */
.accessibility-indicator,
.private-browsing-indicator-with-label {
  height: auto !important;
  width: auto !important;
  box-sizing: border-box !important;
  padding: 0 var(--toolbarbutton-outer-padding) !important;
  margin: 0 !important;
  background: none !important;
  border: 0 !important;
  outline: 0;
  fill: currentColor !important;
  -moz-context-properties: fill, fill-opacity !important;
  align-items: center !important;
}

.private-browsing-indicator-with-label {
  background: none !important;
  appearance: none !important;

  > image {
    content: "";
    box-sizing: border-box !important;
    width: calc(2 * var(--toolbarbutton-inner-padding) + 16px) !important;
    height: calc(2 * var(--toolbarbutton-inner-padding) + 16px) !important;
    background-image: url(chrome://userchrome/content/skin/privateBrowsing.svg) !important;
    background-size: 16px !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    padding: var(--toolbarbutton-inner-padding) !important;
    border-radius: var(--toolbarbutton-border-radius) !important;
  }

  > label {
    display: none !important;
  }
}

.private-browsing-indicator-with-label {
  -moz-context-properties: fill, fill-opacity !important;
  fill: currentColor !important;
}

.accessibility-indicator {
  > .button-box {
    width: calc(2 * var(--toolbarbutton-inner-padding) + 16px) !important;
    height: calc(2 * var(--toolbarbutton-inner-padding) + 16px) !important;
    padding: var(--toolbarbutton-inner-padding) !important;
    border-radius: var(--toolbarbutton-border-radius) !important;

    > .button-icon {
      width: 16px !important;
      height: 16px !important;
      list-style-image: url(chrome://userchrome/content/devtools/tool-accessibility.svg) !important;
    }
  }
}

.accessibility-indicator:is(:hover, :focus-visible) > .button-box,
toolbarbutton.private-browsing-indicator-with-label:is(:hover, :focus-visible) > image {
  background-color: var(--arrowpanel-dimmed) !important;
}

.accessibility-indicator:is(:hover:active, [open]) > .button-box,
toolbarbutton.private-browsing-indicator-with-label:is(:hover:active, [open]) > image {
  background-color: var(--arrowpanel-dimmed-further) !important;
}

:root:not([privatebrowsingmode="temporary"]) :is(#firefox-view-button, #wrapper-firefox-view-button) + #tabbrowser-tabs {
  border-inline-start: revert !important;
  padding-inline-start: revert !important;
}

#TabsToolbar-customization-target > :is(toolbarbutton, toolbaritem, toolbarpaletteitem):first-child {
  margin-inline-start: 2px !important;
}

/* all tabs button popup */
.panel-subview-body > .all-tabs-item {
  border-radius: var(--arrowpanel-menuitem-border-radius) !important;
  box-shadow: none !important;
  margin-inline: 4px !important;
  min-height: 28px !important;
  align-items: center;
  padding-inline-end: 2px;
}

#allTabsMenu-allTabsViewTabs,
#allTabsMenu-hiddenTabsView > .panel-subview-body {
  margin: var(--panel-subview-body-padding) !important;
  margin-top: 0 !important;
  padding-block: 0 !important;
}

#allTabsMenu-searchTabs {
  list-style-image: url(chrome://global/skin/icons/search-glass.svg) !important;
}

#allTabsMenu-containerTabsButton {
  list-style-image: url(chrome://userchrome/content/skin/container-plus.svg);
}

#allTabsMenu-hiddenTabsButton {
  list-style-image: url(chrome://userchrome/content/hide-password.svg);
}

#allTabsMenu-containerTabsButton,
#allTabsMenu-searchTabs,
#allTabsMenu-hiddenTabsButton {
  .toolbarbutton-text {
    padding-inline-start: var(--arrowpanel-subviewbutton-iconic-gap, 8px) !important;
  }
}

.all-tabs-item {
  &[selected] {
    font-weight: normal !important;
    background-color: var(--arrowpanel-dimmed-further) !important;
    --main-stripe-color: var(--arrowpanel-dimmed-even-further);
  }

  &:not([multiselected]) > .all-tabs-container-indicator {
    --main-stripe-color: var(--identity-tab-color);
  }

  &:not([selected]) {
    &:is(:hover, :focus-within, [multiselected]) {
      background-color: var(--arrowpanel-dimmed) !important;
    }

    &:hover:active {
      background-color: var(--arrowpanel-dimmed-further) !important;
    }
  }

  &[multiselected] {
    --main-stripe-color: var(--multiselected-color, var(--lwt-selected-tab-background-color));

    &:not([selected]):hover {
      background-color: var(--arrowpanel-dimmed-further) !important;
    }
  }

  &[pending] {
    &:not([selected]):is(:hover, :focus-within, [multiselected]) {
      background-color: var(--arrowpanel-faint, color-mix(in srgb, var(--arrowpanel-dimmed) 60%, transparent)) !important;
    }

    > .all-tabs-button {
      opacity: 0.6;
    }
  }

  .all-tabs-button {
    background: none !important;
  }

  .all-tabs-secondary-button {
    width: 18px;
    height: 18px;
    border-radius: var(--tab-button-border-radius, 2px) !important;
    color: white !important;
    background-color: transparent !important;
    opacity: 0.7 !important;
    min-height: revert !important;
    min-width: revert !important;
    padding: 0 !important;
    display: flex !important;
    position: relative !important;

    &.all-tabs-mute-button {
      list-style-image: none !important;
      background-image: url(chrome://userchrome/content/audioUnmutedButton.svg) !important;
      background-size: 14px !important;
      background-repeat: no-repeat !important;
      background-position: center !important;
      padding: 0 !important;
      margin-inline-start: -23px !important;
      margin-inline-end: 4px !important;
      transition: 0.25s cubic-bezier(0.07, 0.78, 0.21, 0.95) transform, 0.2s cubic-bezier(0.07, 0.74, 0.24, 0.95) margin, 0.075s linear opacity !important;

      &[hidden] {
        transform: translateX(14px);
        opacity: 0 !important;
      }
    }

    &[soundplaying] {
      transform: none !important;
      opacity: 0.7 !important;
      margin-inline-start: 0 !important;
    }

    &[muted] {
      list-style-image: none !important;
      background-image: url(chrome://userchrome/content/audioMutedButton.svg) !important;
      transform: none !important;
      opacity: 0.7 !important;
      margin-inline-start: 0 !important;
    }

    &[activemedia-blocked] {
      list-style-image: none !important;
      background-image: url(chrome://userchrome/content/glyph-play-12.svg) !important;
      background-size: 10px !important;
      background-position: 4.5px center !important;
      transform: none !important;
      opacity: 0.7 !important;
      margin-inline-start: 0 !important;
    }

    &[pictureinpicture] {
      transform: none !important;
      opacity: 0.7 !important;
      margin-inline-start: 0 !important;
    }

    &.all-tabs-close-button {
      transform: translateX(14px);
      opacity: 0 !important;
      margin-inline-start: -23px !important;
      margin-inline-end: 3px !important;
      transition: 0.25s cubic-bezier(0.07, 0.78, 0.21, 0.95) transform, 0.2s cubic-bezier(0.07, 0.74, 0.24, 0.95) margin, 0.075s linear opacity;
      -moz-context-properties: fill, fill-opacity, stroke !important;
      fill: currentColor !important;
      fill-opacity: 0 !important;
      border-radius: var(--tab-button-border-radius, 2px) !important;
      list-style-image: url(chrome://userchrome/content/textbox-clear.svg) !important;
    }

    > .toolbarbutton-icon {
      min-width: 18px !important;
      min-height: 18px !important;
      fill: inherit !important;
      fill-opacity: inherit !important;
      -moz-context-properties: inherit !important;
      margin: 0 !important;
    }

    > label:empty {
      display: none !important;
    }
  }

  .all-tabs-secondary-button,
  &:is(:hover, :focus-within) .all-tabs-secondary-button.all-tabs-close-button {
    &:is(:hover, :focus):not([disabled]) {
      background-color: var(--arrowpanel-dimmed) !important;
      opacity: 1 !important;
      color: white !important;
    }

    &:hover:active:not([disabled]) {
      background-color: var(--arrowpanel-dimmed-further) !important;
    }
  }

  &:is(:hover, :focus-within) .all-tabs-secondary-button.all-tabs-mute-button {
    transform: translateX(48px);
  }

  &:not(:hover, :focus-within) .all-tabs-secondary-button[pictureinpicture] {
    list-style-image: none !important;
    background-image: url(chrome://userchrome/content/tab-picture-in-picture.svg) !important;
    border-radius: 0 !important;
  }

  &:is(:hover, :focus-within) .all-tabs-secondary-button.all-tabs-close-button {
    transform: none !important;
    opacity: 0.7 !important;
    margin-inline-start: 0 !important;
  }
}

:root[italic-unread-tabs] {
  .all-tabs-item[notselectedsinceload] {
    &:not([pending]) > .all-tabs-button,
    &[pending] > .all-tabs-button[busy] {
      font-style: italic !important;
    }
  }
}

#vertical-tabs-pane {
  .all-tabs-item[pinned]:not([muted], [soundplaying], [activemedia-blocked]) .all-tabs-button .toolbarbutton-icon {
    mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><circle cx="100%" cy="100%" r="9"/></svg>') exclude 0/100% 100% no-repeat, linear-gradient(#fff, #fff);
    mask-position: 8px 8px;
    transition-property: mask;
    transition-timing-function: ease-in-out;
    transition-duration: calc(var(--pane-transition-duration) / 2);
  }

  &[unpinned] {
    &:not([expanded]) {
      .all-tabs-item[pinned] {
        .all-tabs-button .toolbarbutton-icon {
          mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><circle cx="100%" cy="100%" r="9"/></svg>') exclude 0/100% 100% no-repeat, linear-gradient(#fff, #fff);
        }

        &:not([muted], [soundplaying], [activemedia-blocked]) .sound-overlay {
          opacity: 1;
          pointer-events: auto;
        }
      }

      #vertical-tabs-list .all-tabs-item .all-tabs-secondary-button {
        transform: translateX(23px) !important;
        margin-inline: revert !important;
        opacity: 0 !important;
      }
    }

    .all-tabs-item[pinned]:not([muted], [soundplaying], [activemedia-blocked]) .sound-overlay {
      display: block !important;
      position: absolute;
      left: calc(var(--arrowpanel-menuitem-padding-inline) + 7px) !important;
      top: calc(var(--arrowpanel-menuitem-padding-block) + 8px) !important;
      width: 14px;
      height: 14px;
      -moz-context-properties: fill, fill-opacity;
      fill: currentColor;
      fill-opacity: 0.7 !important;
      opacity: 0;
      pointer-events: none;
      transition-property: opacity;
      transition-timing-function: ease-in-out;
      transition-duration: var(--pane-transition-duration);
      background: url(chrome://userchrome/content/material/pin-45.svg) center/11px no-repeat !important;
    }

    .all-tabs-item[selected][pinned]:not([muted], [soundplaying], [activemedia-blocked]) .sound-overlay {
      fill-opacity: inherit !important;
    }
  }
}

.all-tabs-item[pinned] > .all-tabs-button.subviewbutton > .toolbarbutton-text {
  background: url(chrome://userchrome/content/material/pin-45.svg) no-repeat 5px/12px !important;
}

#vertical-tabs-pin-button {
  list-style-image: url(chrome://userchrome/content/material/unpin-315.svg) !important;
}

#vertical-tabs-pane[unpinned] #vertical-tabs-pin-button {
  list-style-image: url(chrome://userchrome/content/material/pin-315.svg) !important;
}

.subviewbutton[command="Browser:OpenAboutContainers"]:not(.subviewbutton-iconic, [image]) {
  list-style-image: url(chrome://userchrome/content/settings.svg) !important;

  > .toolbarbutton-text {
    padding-inline-start: var(--arrowpanel-subviewbutton-iconic-gap, 8px) !important;
  }
}

/* move titlebar buttons to the left on macOS and linux
or if the user sets a pref */
/* stylelint-disable-next-line media-query-no-invalid */
@media (-moz-platform: macos), (-moz-platform: linux), -moz-pref("userChrome.css.titlebar-buttons-on-left") {
  .titlebar-buttonbox-container,
  #toolbar-menubar > .titlebar-buttonbox-container {
    order: 0 !important;
  }

  #toolbar-menubar > spacer,
  .titlebar-spacer[type="pre-tabs"] {
    order: 1 !important;
  }

  #toolbar-menubar > *,
  .toolbar-items {
    order: 2 !important;
  }

  #toolbar-menubar {
    order: 0 !important;
  }

  .titlebar-min {
    order: 2 !important;
  }

  .titlebar-max,
  .titlebar-restore {
    order: 3 !important;
  }

  .titlebar-close {
    order: 1 !important;
  }

  #TabsToolbar,
  #toolbar-menubar[inactive="true"] ~ #TabsToolbar {
    padding-inline: 4px 3px !important;
  }

  #toolbar-menubar:not([inactive="true"]) {
    padding-inline: 4px !important;
  }

  #toolbar-menubar > spacer,
  .titlebar-spacer[type="pre-tabs"] {
    width: 8px !important;
    display: flex !important;
  }

  .titlebar-spacer[type="post-tabs"] {
    display: none !important;
  }

  #toolbar-menubar:not([inactive="true"]) {
    > spacer {
      width: 8px !important;
    }

    + #TabsToolbar .titlebar-spacer[type="pre-tabs"] {
      display: none !important;
    }
  }

  :root {
    --titlebar-background: var(--lwt-accent-color) var(--titlebar-gradient-left);
  }
}
