/*
 * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

.tab-bar {
    position: absolute;
    top: var(--toolbar-height);
    left: 0;
    right: 0;
    height: var(--tab-bar-height);

    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;

    border-bottom: var(--tab-item-medium-border-style);

    background-image: linear-gradient(to bottom, hsl(0, 0%, 78%), hsl(0, 0%, 72%));
    background-size: 100% 200%;

    white-space: nowrap;
    overflow: hidden;

    outline: none;

    --tab-item-dark-border-color: hsl(0, 0%, 59%);
    --tab-item-medium-border-color: hsl(0, 0%, 65%);
    --tab-item-light-border-color: hsl(0, 0%, 85%);
    --tab-item-extra-light-border-color: hsl(0, 0%, 92%);

    --tab-item-medium-border-style: 1px solid var(--tab-item-medium-border-color);
    --tab-item-light-border-style: 1px solid var(--tab-item-light-border-color);
}

body.window-inactive .tab-bar {
    border-bottom-color: var(--tab-item-light-border-color);

    background-image: none !important;
    background-color: var(--tab-item-extra-light-border-color) !important;
}

.tab-bar > .top-border {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;

    background-color: var(--tab-item-medium-border-color);

    z-index: 0;
}

body.window-inactive .tab-bar > .top-border {
    background-color: var(--tab-item-light-border-color);
}

.tab-bar > .item {
    display: flex;
    flex: 1;

    position: relative;

    z-index: 1;

    align-items: center;

    padding: 0 6px;

    min-width: 24px;
    overflow: hidden;

    background-image: linear-gradient(to bottom, hsl(0, 0%, 78%), hsl(0, 0%, 72%));
    background-size: 100% 200%;

    border-top: var(--tab-item-medium-border-style);

    height: 100%;
    line-height: 15px;
    outline: none;

    /* FIXME: These cause noticeable transitions when focusing the window. Fix that with JavaScript? */
    /* transition-property: background-position, border-color; */
    /* transition-duration: 250ms; */
    /* transition-delay: 50ms; */
}

body[dir=ltr] .tab-bar > :nth-child(n + 2 of .item),
body[dir=ltr] .tab-bar.dragging-tab > .item.selected {
    border-left: var(--tab-item-medium-border-style);
}

body[dir=rtl] .tab-bar > :nth-child(n + 2 of .item),
body[dir=rtl] .tab-bar.dragging-tab > .item.selected {
    border-right: var(--tab-item-medium-border-style);
}

.tab-bar > .item.pinned {
    width: 24px;
    flex: none;
    justify-content: center;
}

.tab-bar > .item:not(.disabled).selected {
    border-top-color: hsl(0, 0%, 74%);
    background-image: linear-gradient(to bottom, hsl(0, 0%, 87%), hsl(0, 0%, 82%));
    background-size: 100% 100%;
}

.tab-bar:not(.animating) > .item:not(.selected, .disabled):hover {
    background-position: 0 100%;
    border-top-color: var(--tab-item-dark-border-color);
}

body[dir=ltr] .tab-bar:not(.animating) > .item:not(.selected, .disabled):hover,
body[dir=ltr] .tab-bar:not(.animating) > .item:not(.selected, .disabled):hover + .item {
    border-left-color: var(--tab-item-dark-border-color);
}

body[dir=rtl] .tab-bar:not(.animating) > .item:not(.selected, .disabled):hover,
body[dir=rtl] .tab-bar:not(.animating) > .item:not(.selected, .disabled):hover + .item {
    border-right-color: var(--tab-item-dark-border-color);
}

body.window-inactive .tab-bar > .item {
    border-top-color: var(--tab-item-light-border-color) !important;

    background-image: none !important;
    background-color: var(--tab-item-extra-light-border-color) !important;

    transition: none;
}

body[dir=ltr].window-inactive .tab-bar > .item {
    border-left-color: var(--tab-item-light-border-color) !important;
}

body[dir=rtl].window-inactive .tab-bar > .item {
    border-right-color: var(--tab-item-light-border-color) !important;
}

body.window-inactive .tab-bar > .item.selected {
    background-image: none !important;
    background-color: hsl(0, 0%, 96%) !important;
}

.tab-bar > .item > .close {
    width: 16px;
    height: 16px;

    min-width: 16px;
    min-height: 16px;

    opacity: 0;

    border-radius: 2px;

    background-image: url(../Images/Close.svg);
    background-repeat: no-repeat;

    transition-property: background-color, opacity;
    transition-duration: 250ms, 500ms;
    transition-delay: 0, 50ms;

    --tab-item-close-button-margin-end: 4px;
}

body[dir=ltr] .tab-bar > .item > .close {
    margin-right: var(--tab-item-close-button-margin-end);
}

body[dir=rtl] .tab-bar > .item > .close {
    margin-left: var(--tab-item-close-button-margin-end);
}

body:not(.window-inactive) .tab-bar > .item:hover > .close {
    opacity: 0.6;
}

body:not(.window-inactive) .tab-bar.single-tab > .item.default-tab:hover > .close {
    opacity: 0;
}

.tab-bar.single-tab > .item.default-tab > .close {
    pointer-events: none;
}

.tab-bar > .item > .close:hover {
    background-color: hsla(0, 0%, 0%, 0.2);
}

.tab-bar > .item > .close:active {
    opacity: 0.8 !important;
}

.tab-bar > .item > .flex-space {
    display: flex;
    flex: 1;
}

.tab-bar > .item:not(.pinned) > .flex-space:last-child {
    --tab-item-unpinned-trailing-flex-space-margin-end: 16px;
}

body[dir=ltr] .tab-bar > .item:not(.pinned) > .flex-space:last-child {
    margin-right: var(--tab-item-unpinned-trailing-flex-space-margin-end);
}

body[dir=rtl] .tab-bar > .item:not(.pinned) > .flex-space:last-child {
    margin-left: var(--tab-item-unpinned-trailing-flex-space-margin-end);
}

.tab-bar > .item > .icon {
    width: 16px;
    height: 16px;

    min-width: 16px;
    min-height: 16px;

    opacity: 0.55; /* Assumes black glyphs. */

    -webkit-user-drag: none;
}

.tab-bar > .item.pinned > .icon {
    width: 15px;
    height: 15px;
    min-width: 15px;
    min-height: 15px;
}

.tab-bar > .item.selected > .icon {
    opacity: 0.7;
}

.tab-bar > .item.disabled > .icon {
    opacity: 0.35;
}

.tab-bar:not(.animating) > .item:not(.selected, .disabled):hover > .icon {
    opacity: 0.6;
}

.tab-bar > .item > .title {
    color: hsla(0, 0%, 0%, 0.55);

    display: flex;

    min-width: 0;
    max-width: 400px;

    --tab-item-title-margin-start: 6px;
}

body[dir=ltr] .tab-bar > .item > .title {
    margin-left: var(--tab-item-title-margin-start);
}

body[dir=rtl] .tab-bar > .item > .title {
    margin-right: var(--tab-item-title-margin-start);
}

.tab-bar > .item > .title > .content {
    min-width: 0;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab-bar:not(.animating) > .item:not(.selected):hover > .title {
    color: hsla(0, 0%, 0%, 0.6);
}

.tab-bar > .item.selected > .title {
    color: hsla(0, 0%, 0%, 0.7);
}

.tab-bar.collapsed > .item {
    justify-content: center;
}

.tab-bar.collapsed > .item > .flex-space {
    display: none;
}

.tab-bar.collapsed > .item > .close {
    display: none;
    --tab-item-close-button-margin-end: 0;
}

body[dir=ltr] .tab-bar.collapsed > .item > .close {
    margin-right: var(--tab-item-close-button-margin-end);
}

body[dir=rtl] .tab-bar.collapsed > .item > .close {
    margin-left: var(--tab-item-close-button-margin-end);
}

.tab-bar.hide-titles > .item > .title {
    display: none;
}

.tab-bar.collapsed:not(.hide-titles) > .item:not(.pinned):hover > .icon,
.tab-bar.hide-titles > .item.selected:hover > .icon {
    display: none;
}

.tab-bar.collapsed:not(.hide-titles) > .item:hover > .close,
.tab-bar.hide-titles > .item.selected:hover > .close {
    display: inline-block;
}

.tab-bar.static-layout {
    position: relative;
}

.tab-bar.static-layout > .item {
    position: absolute !important;
    top: 0;
}

.tab-bar.animating.closing-tab > .item {
    transition-property: left;
    transition-duration: 250ms;
    transition-timing-function: ease-in-out;
}

.tab-bar.animating:matches(.expanding-tabs, .inserting-tab) > .item {
    transition-property: left, width;
    transition-duration: 250ms;
    transition-timing-function: ease-in-out;
}

.tab-bar.animating.inserting-tab > .item.being-inserted {
    z-index: 2;
    min-width: 0 !important;
    padding: 0 !important;
}

.tab-bar.dragging-tab > .item.selected,
.tab-bar.static-layout:not(.animating.inserting-tab):not(.dragging-tab) > .item:nth-last-child(1 of :not(.pinned)),
.tab-bar.animating.closing-tab > .item.selected {
    border-right: var(--tab-item-medium-border-style);
}

body.window-inactive .tab-bar.dragging-tab > .item.selected,
body.window-inactive .tab-bar.static-layout:not(.animating.inserting-tab):not(.dragging-tab) > .item:nth-last-child(1 of :not(.pinned)),
body.window-inactive .tab-bar.animating.closing-tab > .item.selected {
    border-right-color: var(--tab-item-light-border-color) !important;
}

.tab-bar.dragging-tab > .item.selected {
    z-index: 2;
    pointer-events: none;
}
