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

%filter substitution
%define glassActiveBorderColor rgb(37, 44, 51)
%define glassInactiveBorderColor rgb(102, 102, 102)

@media (-moz-os-version: windows-win7) {
  @media (-moz-windows-classic: 0) {
    #main-window[sizemode="normal"] > #navigator-toolbox > #toolbar-menubar {
      margin-top: 1px;
    }
  }
}

@media (-moz-windows-default-theme) {
  .menu-accel,
  .menu-iconic-accel {
    color: graytext;
  }
}

@media (-moz-windows-compositor) {
  @media not all and (-moz-os-version: windows-win7) {
    @media not all and (-moz-os-version: windows-win8) {
      @media (-moz-windows-default-theme) {
        :root[sizemode=normal][tabsintitlebar] {
          border-top: 1px solid -moz-win-accentcolor;
        }

        :root[sizemode=normal][tabsintitlebar]:-moz-window-inactive {
          border-top-color: rgba(0,0,0,.2);
        }

        :root:not(:-moz-lwtheme) {
          background-color: hsl(0, 0%, 78%);
        }

        @media (-moz-windows-accent-color-in-titlebar: 0) {
          :root[tabsintitlebar]:not(:-moz-lwtheme) {
            background-color: hsl(235,33%,19%);
          }
          :root[tabsintitlebar] .titlebar-color:not(:-moz-lwtheme) {
            color: hsl(240,9%,98%);
          }
        }

        @media (-moz-windows-accent-color-in-titlebar) {
          :root[tabsintitlebar]:not(:-moz-window-inactive):not(:-moz-lwtheme) {
            background-color: -moz-win-accentcolor;
          }
          :root[tabsintitlebar] .titlebar-color:not(:-moz-window-inactive):not(:-moz-lwtheme) {
            color: -moz-win-accentcolortext;
          }
        }

        :root[tabsintitlebar] .tab-label:-moz-window-inactive {
          /* Calculated to match the opacity change of Windows Explorer
             titlebar text change for inactive windows. */
          opacity: .6;
        }
      }

      @media (-moz-windows-default-theme: 0) {
        :root {
          background-color: transparent;
          -moz-appearance: -moz-win-glass;
        }

        /* On win10, if we don't set this on the entire browser container including
         * the sidebar, if the sidebar is open the accent color bleeds through in
         * the titlebar */
        #browser {
          -moz-appearance: -moz-win-exclude-glass;
        }
      }

      #titlebar-buttonbox,
      .titlebar-button {
        -moz-appearance: none !important;
      }

      .titlebar-button {
        border: none;
        margin: 0 !important;
        padding: 8px 17px;
        -moz-context-properties: stroke;
        stroke: currentColor;
      }

      .titlebar-button > .toolbarbutton-icon {
        width: 12px;
        height: 12px;
      }

      #titlebar-min {
        list-style-image: url(chrome://browser/skin/window-controls/minimize.svg);
      }

      #titlebar-max {
        list-style-image: url(chrome://browser/skin/window-controls/maximize.svg);
      }

      :root[sizemode="maximized"] #titlebar-max {
        list-style-image: url(chrome://browser/skin/window-controls/restore.svg);
      }

      #titlebar-close {
        list-style-image: url(chrome://browser/skin/window-controls/close.svg);
      }

      :root[lwtheme-image] .titlebar-button {
        -moz-context-properties: unset;
      }
      :root[lwtheme-image] #titlebar-min {
        list-style-image: url(chrome://browser/skin/window-controls/minimize-themes.svg);
      }
      :root[lwtheme-image] #titlebar-max {
        list-style-image: url(chrome://browser/skin/window-controls/maximize-themes.svg);
      }
      :root[lwtheme-image][sizemode="maximized"] #titlebar-max {
        list-style-image: url(chrome://browser/skin/window-controls/restore-themes.svg);
      }
      :root[lwtheme-image] #titlebar-close {
        list-style-image: url(chrome://browser/skin/window-controls/close-themes.svg);
      }

      /* the 12px image renders a 10px icon, and the 10px upscaled gets rounded to 12.5, which
       * rounds up to 13px, which makes the icon one pixel too big on 1.25dppx. Fix: */
      @media (min-resolution: 1.20dppx) and (max-resolution: 1.45dppx) {
        .titlebar-button > .toolbarbutton-icon {
          width: 11.5px;
          height: 11.5px;
        }
      }

      /* 175% dpi should result in the same device pixel sizes as 150% dpi. */
      @media (min-resolution: 1.70dppx) and (max-resolution: 1.95dppx) {
        .titlebar-button {
          padding-left: 14.1px;
          padding-right: 14.1px;
        }

        .titlebar-button > .toolbarbutton-icon {
          width: 10.8px;
          height: 10.8px;
        }
      }

      /* 225% dpi should result in the same device pixel sizes as 200% dpi. */
      @media (min-resolution: 2.20dppx) and (max-resolution: 2.45dppx) {
        .titlebar-button {
          padding-left: 15.3333px;
          padding-right: 15.3333px;
        }

        .titlebar-button > .toolbarbutton-icon {
          width: 10.8px;
          height: 10.8px;
        }
      }

      /* 275% dpi should result in the same device pixel sizes as 250% dpi. */
      @media (min-resolution: 2.70dppx) and (max-resolution: 2.95dppx) {
        /* NB: todo: this should also change padding on the buttons
         * themselves, but without a device to test this on, it's
         * impossible to know by how much. */
        .titlebar-button > .toolbarbutton-icon {
          width: 10.8px;
          height: 10.8px;
        }
      }

      @media (-moz-windows-default-theme) {
        #main-menubar > menu {
          color: inherit;
        }

        #main-menubar > menu[_moz-menuactive="true"],
        .titlebar-button:hover {
          background-color: hsla(0,0%,100%,.22);
        }
        .titlebar-button:hover:active {
          background-color: hsla(0,0%,100%,.32);
        }
        #main-menubar > menu[_moz-menuactive="true"]:-moz-lwtheme-darktext,
        .titlebar-button:-moz-lwtheme-darktext:hover {
          background-color: hsla(0,0%,0%,.12);
        }
        .titlebar-button:-moz-lwtheme-darktext:hover:active {
          background-color: hsla(0,0%,0%,.22);
        }

        .titlebar-button:not(:hover) > .toolbarbutton-icon:-moz-window-inactive {
          opacity: 0.5;
        }

        #titlebar-close:hover {
          stroke: white;
          background-color: hsl(355,86%,49%);
        }

        #titlebar-close:hover:active {
          background-color: hsl(355,82%,69%);
        }
      }

      @media (-moz-windows-default-theme: 0) {
        .titlebar-button {
          background-color: -moz-field;
          stroke: ButtonText;
        }
        .titlebar-button:hover {
          background-color: Highlight;
          stroke: HighlightText;
        }

        #titlebar-min {
          list-style-image: url(chrome://browser/skin/window-controls/minimize-highcontrast.svg);
        }

        #titlebar-max {
          list-style-image: url(chrome://browser/skin/window-controls/maximize-highcontrast.svg);
        }

        :root[sizemode="maximized"] #titlebar-max {
          list-style-image: url(chrome://browser/skin/window-controls/restore-highcontrast.svg);
        }

        #titlebar-close {
          list-style-image: url(chrome://browser/skin/window-controls/close-highcontrast.svg);
        }
      }
    }
  }

  @media (-moz-os-version: windows-win7),
         (-moz-os-version: windows-win8) {
    :root {
      background-color: transparent;
      -moz-appearance: -moz-win-borderless-glass;
    }

    :root[sizemode="maximized"] #titlebar-buttonbox {
      margin-inline-end: 3px;
    }

    /* These should be hidden w/ glass enabled. Windows draws its own buttons. */
    .titlebar-button {
      display: none;
    }

    /* The borders on the glass frame are ours, and inside #browser, and on
     * win7 we want to make sure they are "glassy", so we can't use #browser
     * as the exclude-glass container. We use #appcontent instead. */
    #appcontent {
      -moz-appearance: -moz-win-exclude-glass;
    }
  }

  @media (-moz-os-version: windows-win8) {
    /* Artificially draw window borders that are covered by lwtheme, see bug 591930.
     * Borders for win7 are below, win10 doesn't need them. */
    #main-window[sizemode="normal"] > #navigator-toolbox:-moz-lwtheme {
      border-top: 1px solid @glassShadowColor@;
    }
  }

  :root[darkwindowframe="true"] .titlebar-color:not(:-moz-window-inactive):not(:-moz-lwtheme) {
    color: white;
  }

  /* Show borders on Win 7 & 8, but not on 10 and later: */
  @media (-moz-os-version: windows-win7),
         (-moz-os-version: windows-win8) {
    /* Vertical toolbar border */
    #main-window[sizemode=normal] #navigator-toolbox > toolbar:not(#toolbar-menubar):not(#TabsToolbar):not(:-moz-lwtheme),
    #main-window[sizemode=normal] #navigator-toolbox > toolbar:-moz-lwtheme {
      border-left: 1px solid @glassShadowColor@;
      border-right: 1px solid @glassShadowColor@;
      background-clip: padding-box;
    }

    #main-window[sizemode=normal] #navigator-toolbox::after {
      box-shadow: 1px 0 0 @glassShadowColor@, -1px 0 0 @glassShadowColor@;
      margin-left: 1px;
      margin-right: 1px;
    }

    #main-window[sizemode=normal] #browser-border-start,
    #main-window[sizemode=normal] #browser-border-end {
      display: -moz-box;
      background-color: @glassShadowColor@;
      width: 1px;
    }

    #main-window[sizemode=normal] #browser-bottombox {
      border: 1px solid @glassShadowColor@;
      border-top-style: none;
      background-clip: padding-box;
    }
  }

  #appcontent:not(:-moz-lwtheme) {
    background-color: -moz-dialog;
  }
}

@media (-moz-windows-glass) {
  /* Set to full fill-opacity to improve visibility of toolbar buttons on aero glass. */
  #TabsToolbar:not(:-moz-lwtheme) {
    --toolbarbutton-icon-fill-opacity: 1;
  }

  #toolbar-menubar:not(:-moz-lwtheme) {
    text-shadow: 0 0 .5em white, 0 0 .5em white, 0 1px 0 rgba(255,255,255,.4);
  }

  #main-menubar:not(:-moz-lwtheme):not(:-moz-window-inactive) {
    background-color: rgba(255,255,255,.5);
    color: black;
    border-radius: 4px;
  }

  /* Artificially draw window borders that are covered by lwtheme, see bug 591930.
   * We use a different border for win8, and this is not necessary on win10+ */
  #main-window[sizemode="normal"] > #navigator-toolbox:-moz-lwtheme {
    border-top: 1px solid @glassActiveBorderColor@;
    padding-top: 1px;
    box-shadow: 0 1px 0 rgba(255,255,255,.6) inset;
  }

  #main-window[sizemode="normal"] > #navigator-toolbox:-moz-lwtheme:-moz-window-inactive {
    border-top-color: @glassInactiveBorderColor@;
  }
}

/* Aero Basic */
@media (-moz-windows-compositor: 0) {
  @media (-moz-windows-default-theme) {
    #main-window {
      background-color: rgb(185,209,234);
    }
    #main-window:-moz-window-inactive {
      background-color: rgb(215,228,242);
    }

    /* Render a window top border for lwthemes: */
    #main-window[tabsintitlebar][sizemode="normal"] > #navigator-toolbox:-moz-lwtheme {
      background-image: linear-gradient(to bottom,
            @glassActiveBorderColor@ 0, @glassActiveBorderColor@ 1px,
            rgba(255,255,255,.6) 1px, rgba(255,255,255,.6) 2px, transparent 2px);
    }

    #main-window[tabsintitlebar][sizemode="normal"] > #navigator-toolbox:-moz-lwtheme:-moz-window-inactive {
      background-image: linear-gradient(to bottom,
            @glassInactiveBorderColor@ 0, @glassInactiveBorderColor@ 1px,
            rgba(255,255,255,.6) 1px, rgba(255,255,255,.6) 2px, transparent 2px);
    }
  }

  #print-preview-toolbar:not(:-moz-lwtheme) {
    -moz-appearance: -moz-win-browsertabbar-toolbox;
  }
}
