@include ccs-exports("ccs/component/ccs-header") {
  $ccs-header-background: $ccs-brand-colour;
  $ccs-header-service-authentication-background: ccs-colour("black");
  $ccs-header-text: ccs-colour("white");
  $ccs-header-link-active-border-color: ccs-colour("white");
  $ccs-header-nav-item-border-color: ccs-colour("dark-red");
  $ccs-header-link-underline-thickness: 3px;

  .ccs-header {
    @include govuk-font($size: 16);

    color: $ccs-header-text;
    background: $ccs-header-background;
  }

  .ccs-header__container--full-width {
    padding: 0 govuk-spacing(3);

    .ccs-header__menu-button {
      right: govuk-spacing(3);
    }
  }

  .ccs-header__container,
  .ccs-header__service-authentication-container {
    @include govuk-clearfix;
    position: relative;
  }

  .ccs-header__container {
    padding-top: govuk-spacing(2);
  }

  .ccs-header__service-authentication-container {
    padding-top: govuk-spacing(1);
    padding-bottom: govuk-spacing(1);
  }

  .ccs-header__service-authentication {
    background: $ccs-header-service-authentication-background;
    text-align: right;
  }

  .ccs-header__service-authentication-item {
    display: inline-block;
    margin-right: govuk-spacing(3);
    padding: govuk-spacing(2) 0;
    border: 0;

    @include govuk-media-query ($from: desktop) {
      padding: govuk-spacing(1) 0;
    }

    a {
      @include govuk-font($size: 16, $weight: regular);
    }
  }

  .ccs-header__service-authentication-list .ccs-header__service-authentication-item:last-child {
    margin-right: 0;
    border-bottom: 0;
  }

  .ccs-header__link {
    // Avoid using the `govuk-link-common` mixin because the links in the header
    // get a special treatment, because:
    //
    // - underlines are only visible on hover
    // - all links get a 3px underline regardless of text size, as there are
    //   multiple grouped elements close to one another and having slightly
    //   different underline widths looks unbalanced
    @include govuk-typography-common;
    @include govuk-link-style-inverse;

    border-bottom: solid .125rem transparent;
    text-decoration: none;

    &:hover {
      text-decoration: underline;
      text-decoration-thickness: $ccs-header-link-underline-thickness;

      @if $govuk-link-underline-offset {
        text-underline-offset: $govuk-link-underline-offset;
      }
    }

    &:focus {
      @include govuk-focused-text;
    }
  }

  .ccs-header__link--homepage {
    // Font size needs to be set on the link so that the box sizing is correct
    // in Firefox
    @include govuk-font($size: false, $weight: bold);

    display: inline-block;
    margin-right: govuk-spacing(2);
    font-size: 30px; // We don't have a mixin that produces 30px font size
    line-height: 1;

    &:link,
    &:visited {
      text-decoration: none;
    }

    &:hover:not(:focus),
    &:active:not(:focus) {
      // Negate the added border
      margin-bottom: -1px;
      // Omitting colour will use default value of currentColor – if we
      // specified currentColor explicitly IE8 would ignore this rule.
      border-bottom: $ccs-header-link-underline-thickness solid;
    }

    // Remove any borders that show when focused and hovered.
    &:focus {
      margin-bottom: 0;
    }
  }

  .ccs-header__link--service-name {
    display: inline-block;
    margin-bottom: govuk-spacing(2);
    @include govuk-font($size: 24, $weight: bold);
  }

  .ccs-header__logo,
  .ccs-header__content {
    box-sizing: border-box;
  }

  .ccs-header__logo {
    @include govuk-responsive-padding(2, "bottom");
    padding-right: govuk-spacing(8);

    @include govuk-media-query ($from: desktop) {
      width: 25%;
      padding-right: $govuk-gutter-half;
      float: left;
      vertical-align: top;
    }
  }

  .ccs-header__content {
    text-align: left;

    @include govuk-media-query ($from: desktop) {
      width: 75%;
      padding-left: $govuk-gutter-half;
      float: left;
    }
  }

  .ccs-header__menu-button {
    @include govuk-font($size: 16);
    display: none;
    position: absolute;
    top: govuk-spacing(4);
    right: 0;
    margin: 0;
    padding: 0;
    border: 0;
    color: govuk-colour("white");
    background: none;
    cursor: pointer;

    &:hover {
      -webkit-text-decoration: solid underline $ccs-header-link-underline-thickness;
              text-decoration: solid underline $ccs-header-link-underline-thickness;

      @if $govuk-link-underline-offset {
        text-underline-offset: $govuk-link-underline-offset;
      }
    }

    &:focus {
      @include govuk-focused-text;
    }

    &:after {
      @include govuk-shape-arrow($direction: down, $base: 10px, $display: inline-block);
      content: "";
      margin-left: govuk-spacing(1);
    }

    @include govuk-media-query ($from: tablet) {
      top: govuk-spacing(3);
    }
  }

  .ccs-header__menu-button--open {
    &:after {
      @include govuk-shape-arrow($direction: up, $base: 10px, $display: inline-block);
    }
  }

  .ccs-header__navigation {
    @include govuk-media-query ($from: desktop) {
      margin-bottom: govuk-spacing(2);
    }
  }

  .ccs-header__service-authentication-list,
  .ccs-header__navigation-primary-list,
  .ccs-header__navigation-secondary-list {
    // Reset user-agent default list styles
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .ccs-header__navigation--no-second-list {
    @include govuk-media-query ($from: desktop) {
      padding-top: govuk-spacing(7);
    }
  }

  .js-enabled {
    .ccs-header__menu-button {
      display: block;
      @include govuk-media-query ($from: desktop) {
        display: none;
      }
    }

    .ccs-header__navigation-lists {
      display: none;
      @include govuk-media-query ($from: desktop) {
        display: block;
      }
    }

    .ccs-header__navigation-lists--open {
      display: block;
    }
  }

  .ccs-header__navigation--end {
    @include govuk-media-query ($from: desktop) {
      margin: 0;
      padding: govuk-spacing(1) 0;
      text-align: right;
    }
  }

  .ccs-header__navigation--no-service-name {
    @include govuk-media-query ($from: desktop) {
      padding-top: govuk-spacing(7);
    }
  }

  .ccs-header__navigation-secondary-list {
    .ccs-header__navigation-item {
      a {
        @include govuk-font($size: 16, $weight: regular);
      }
    }
  }

  .ccs-header__navigation-item {
    padding: govuk-spacing(2) 0;
    border-bottom: 1px solid $ccs-header-nav-item-border-color;

    @include govuk-media-query ($from: desktop) {
      display: inline-block;
      margin-right: govuk-spacing(3);
      padding: govuk-spacing(1) 0;
      border: 0;
    }

    a {
      @include govuk-font($size: 16, $weight: bold);
      white-space: nowrap;
    }
  }

  .ccs-header__navigation-item--active {
    a {
      &:link,
      &:hover,
      &:visited {
        // color: $ccs-header-link-active;
        border-color: $ccs-header-link-active-border-color;
        color: inherit;
        background-color: transparent;
      }

      // When focussed, the text colour needs to be darker to ensure that colour
      // contrast is still acceptable
      &:focus {
        @include govuk-focused-text;

        border-color: $govuk-focus-colour;
      }
    }
  }

  .ccs-header__navigation-primary-list .ccs-header__navigation-item:last-child {
    margin-right: 0;
    border-bottom: 0;
  }

  .ccs-header__navigation-secondary-list .ccs-header__navigation-item:last-child {
    margin-right: govuk-spacing(3);
    border-bottom: 1px solid $ccs-header-nav-item-border-color;

    @include govuk-media-query ($from: desktop) {
      margin-right: 0;
      border-bottom: 0;
    }
  }

  @include govuk-media-query($media-type: print) {
    .ccs-header {
      border-bottom-width: 0;
      color: govuk-colour("black");
      background: transparent;
    }

    .ccs-header__link {
      &:link,
      &:visited {
        color: govuk-colour("black");
      }

      // Do not append link href to GOV.UK link when printing (e.g. '(/)')
      &:after {
        display: none;
      }
    }
  }
}
