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

/* all localizable skin settings shall live here */

@import url("chrome://global/skin/design-system/tokens-platform.css");
@import url("chrome://global/skin/design-system/panel.css");
@import url("chrome://global/skin/design-system/text-and-typography.css");
@import url("chrome://global/skin/design-system/toolbar.css");

@import url("chrome://global/locale/intl.css");
@import url("chrome://global/content/widgets.css");

@import url("close-icon.css");

@namespace xul url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
@namespace html url("http://www.w3.org/1999/xhtml");

:root {
  --default-focusring-width: 2px;
  --default-focusring: var(--default-focusring-width) dotted;

  --animation-easing-function: cubic-bezier(0.07, 0.95, 0, 1);

  --search-engine-name-max-width: 15em;

  @media (-moz-platform: macos) {
    /* On macOS we use native shadows via -moz-window-shadow */
    --panel-box-shadow-margin: 0px;
  }

  --panel-separator-color: color-mix(in srgb, currentColor 25%, transparent);

  --popup-notification-body-width: calc(31em - calc(2 * var(--panel-padding)));

  &[lwtheme] {
    &[lwt-icon-fill-attention="dark"] {
      --toolbarbutton-icon-fill-attention-text: var(--toolbarbutton-icon-fill-attention-text-light);
    }
    &[lwt-icon-fill-attention="light"] {
      --toolbarbutton-icon-fill-attention-text: var(--toolbarbutton-icon-fill-attention-text-dark);
    }
  }

  /* This color scheme should match --toolbar-text-color. However, note that
   * individual toolbars might override this (see ToolbarIconColor and the
   * brighttext attribute). */
  --toolbar-color-scheme: light dark;
  &[lwt-toolbar="light"] {
    --toolbar-color-scheme: light;
  }
  &[lwt-toolbar="dark"] {
    --toolbar-color-scheme: dark;
  }

  @media (prefers-contrast) {
    --panel-separator-color: currentColor;
  }

  background-color: -moz-Dialog;
  color: -moz-DialogText;
  font: message-box;
  -moz-box-collapse: legacy;

  &[dialogroot] {
    font: menu;
  }
}

:is(menupopup, panel):where([type="arrow"]) {
  --menuitem-border-radius: var(--panel-menuitem-border-radius);
  --menuitem-padding: var(--panel-menuitem-padding);
  --menuitem-margin: var(--panel-menuitem-margin);
}

@media -moz-pref("widget.macos.native-popovers") and (-moz-platform: macos) {
  panel:not([nonnative]) {
    background-color: transparent;
    --panel-background: transparent;
    --panel-box-shadow: none;
    --panel-border-color: transparent;
    --panel-box-shadow-margin: 0px;
    --panel-padding: 0px;
  }
}

/* Lightweight theme roots */

:root[lwtheme] {
  body,
  toolbar,
  &[lwt-popup="light"] panel {
    color-scheme: light;
  }
  &[lwtheme-brighttext] body,
  toolbar[brighttext],
  &[lwt-popup="dark"] panel {
    color-scheme: dark;
  }
}

:root[lwtheme-image] {
  text-shadow: 0 -0.5px 1.5px white;
}

:root[lwtheme-image][lwtheme-brighttext] {
  text-shadow: 1px 1px 1.5px black;
}

/* Rules for 'hiding' portions of the chrome for special
   kinds of windows with toolbars (not just browser windows) */
:root[chromehidden~="menubar"] .chromeclass-menubar,
:root[chromehidden~="directories"] .chromeclass-directories,
:root[chromehidden~="status"] .chromeclass-status,
:root[chromehidden~="extrachrome"] .chromeclass-extrachrome,
:root[chromehidden~="location"] .chromeclass-location,
:root[chromehidden~="location"][chromehidden~="toolbar"] .chromeclass-toolbar,
:root[chromehidden~="toolbar"] .chromeclass-toolbar-additional {
  display: none;
}

/* General styles */

moz-input-box,
html|input {
  min-width: 0;
}

html|input {
  margin: var(--space-xxsmall) var(--space-xsmall);
}

html|button,
html|input,
html|select,
html|textarea {
  font: inherit;
}

html|input:where(:not([type="radio" i], [type="checkbox" i], [type="range" i])),
html|textarea {
  appearance: none;
  padding: var(--space-small);
  border: 1px solid var(--input-border-color);
  border-radius: var(--border-radius-medium);
  margin: 0;
  background-color: var(--input-text-background-color);
  color: var(--input-text-color);

  &:where(:user-invalid) {
    border-color: var(--border-color-error);
  }

  &:where(:focus-visible) {
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-inset);
  }
}

/* adapted from toolkit/themes/shared/menulist.css */
html|select:where(:not([size], [multiple])) {
  --select-image-spacing: var(--space-small);
  --select-padding-inline-end: calc(var(--select-image-spacing) * 2 + var(--dimension-12)); /* padding plus image width */

  appearance: none;
  padding: var(--space-small) var(--space-large);
  padding-inline-end: var(--select-padding-inline-end);
  margin: var(--space-xsmall) var(--space-xxsmall);
  border: none;
  border-radius: var(--button-border-radius);

  font-weight: var(--font-weight-semibold);

  color: var(--button-text-color);
  background-color: var(--button-background-color);
  background-image: url(chrome://global/skin/icons/arrow-down-12.svg);
  background-position: right var(--select-image-spacing) center;
  background-repeat: no-repeat;
  -moz-context-properties: fill;
  fill: currentColor;

  &:-moz-locale-dir(rtl) {
    background-position-x: left 10px;
  }

  &:hover {
    background-color: var(--button-background-color-hover);
  }

  &:hover:active {
    background-color: var(--button-background-color-active);
  }

  &:focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-offset);
  }
}

.header {
  font-weight: var(--font-weight-heading);
}

.indent {
  margin-inline-start: var(--space-xlarge);
}

.box-padded {
  padding: var(--space-xsmall);
}

/* XUL iframe */

xul|iframe {
  border: none;
  min-width: var(--size-item-xsmall);
  min-height: var(--size-item-xsmall);
}

/* Label/description formatting */

xul|description,
xul|label {
  cursor: default;
  margin-block: var(--space-xxsmall);
  margin-inline: var(--space-xsmall);
}

xul|description {
  margin-bottom: var(--space-xsmall);
}

xul|label[disabled] {
  color: var(--text-color-disabled);
}

.tooltip-label {
  margin: 0;
  word-wrap: break-word;
  /* We must specify a min-width, otherwise word-wrap:break-word doesn't work.
     See Bug 630864. */
  min-width: 1px;
}

/* Links */

.text-link,
a,
::part(support-link) {
  color: var(--link-color);
  cursor: pointer;
  text-decoration: underline;

  &:hover {
    color: var(--link-color-hover);
  }

  &:hover:active {
    color: var(--link-color-active);
    text-decoration: none;
  }

  &:focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--link-focus-outline-offset);
    border-radius: var(--border-radius-xsmall);
  }
}

/* Override properties set on buttons, to display the links without unwanted styling */
button.text-link {
  appearance: none;
  background-color: transparent;
  border: none;
  min-width: 0;
  margin: 0;
  padding: 0;
  font: inherit;
}

button.text-link .button-text {
  /* Cancel out the default internal margin */
  margin: 0;
}

/* Textbox context menu */

.textbox-contextmenu:-moz-locale-dir(rtl) {
  direction: rtl;
}

/* Panel footer buttons */

.panel-footer {
  margin: var(--space-small) var(--space-large) var(--space-large);
}

.footer-button {
  appearance: none;
  border: var(--button-border);
  border-radius: var(--button-border-radius);
  color: var(--button-text-color);
  background-color: var(--button-background-color);
  padding: var(--space-small) var(--space-large);
  min-height: var(--size-item-large);
  font-weight: var(--font-weight-semibold);
  min-width: 0;
  margin-inline: var(--space-small) 0;
  margin-bottom: 0;

  &.small-button {
    margin: 0;
    min-height: var(--size-item-medium);
    font-size: var(--font-size-small);
    align-items: center;
  }

  &[disabled] {
    background-color: var(--button-background-color-disabled);
    color: var(--button-text-color-disabled);
    opacity: var(--button-opacity-disabled);
  }

  &[default][disabled],
  &.primary[disabled] {
    background-color: var(--button-background-color-primary-disabled);
    color: var(--button-text-color-primary-disabled);
  }

  &:focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-offset);
  }

  &:not([disabled]) {
    &:hover {
      color: var(--button-text-color-hover);
      background-color: var(--button-background-color-hover);
      border-color: var(--button-border-color-hover);
    }
    &:hover:active,
    &[open] {
      color: var(--button-text-color-active);
      background-color: var(--button-background-color-active);
      border-color: var(--button-border-color-active);
    }
    &[default],
    &.primary {
      color: var(--button-text-color-primary);
      background-color: var(--button-background-color-primary);
      border-color: var(--button-border-color-primary);
      &:hover {
        color: var(--button-text-color-primary-hover);
        background-color: var(--button-background-color-primary-hover);
        border-color: var(--button-border-color-primary-hover);
      }
      &:hover:active,
      &[open] {
        color: var(--button-text-color-primary-active);
        background-color: var(--button-background-color-primary-active);
        border-color: var(--button-border-color-primary-active);
      }
    }
  }

  &[type="menu"] > .button-box > .button-menu-dropmarker {
    appearance: none;
    display: flex;
    content: url("chrome://global/skin/icons/arrow-down-12.svg");
    -moz-context-properties: fill;
    fill: currentColor;
  }
}

/* Autoscroll popup */

.autoscroller {
  appearance: none;

  /* Resets the native styles in windows and macOS */
  border: none;
  background-color: transparent;
  -moz-window-shadow: none;

  --autoscroll-background-image: url("chrome://global/skin/icons/autoscroll.svg");
  --panel-border-color: rgba(0, 0, 0, 0.4);
  --panel-padding: 0;
  --panel-background-color: rgba(249, 249, 250, 0.8) no-repeat center var(--autoscroll-background-image);
  --panel-box-shadow: 0 0 var(--panel-box-shadow-margin) rgba(0, 0, 0, 0.2);
  --panel-box-shadow-margin: 4px;
  --panel-border-radius: 100%;

  /* Set pointer-events: none; so that mousemove events can be handled by AutoScrollChild.sys.mjs. */
  pointer-events: none;

  &::part(content) {
    background-clip: padding-box;
    width: 100%;
    height: 100%;
  }

  &[scrolldir="NS"] {
    --autoscroll-background-image: url("chrome://global/skin/icons/autoscroll-vertical.svg");
  }

  &[scrolldir="EW"] {
    --autoscroll-background-image: url("chrome://global/skin/icons/autoscroll-horizontal.svg");
  }
}

/* Combobox dropdown renderer */
#ContentSelectDropdown > menupopup {
  /* The menupopup itself should always be rendered LTR to ensure the scrollbar aligns with
   * the dropdown arrow on the dropdown widget. If a menuitem is RTL, its style will be set accordingly */
  direction: ltr;
}

#ContentSelectDropdown > menupopup::part(arrowscrollbox-scrollbox) {
  scrollbar-width: var(--content-select-scrollbar-width, auto);
}

#ContentSelectDropdown > menupopup[customoptionstyling="true"]::part(arrowscrollbox) {
  /* When authors specify a custom background, we use background-image to specify the author-supplied color.
   * In that case, we don't want stuff like custom appearance or custom
   * backgrounds, so we make sure to apply it on top of the default background. */
  background-image: var(--content-select-background-image, none);
  background-color: -moz-Combobox;
}

/* Full width separator in select */
#ContentSelectDropdown menuseparator {
  padding-inline: 0;
}

/* Indent options in optgroups */
#ContentSelectDropdown menuitem[indented] > .menu-text {
  padding-inline-start: var(--space-xxlarge);
}
