/**
 * Copyright (c) Enalean, 2017-Present. All Rights Reserved.
 *
 * This file is a part of Tuleap.
 *
 * Tuleap is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Tuleap is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tuleap. If not, see <http://www.gnu.org/licenses/>.
 */

@use "variables-color-common";
@use "variables-common";

h2 {
    font-size: 2em;
}

h3 {
    font-size: 1.3em;
}

hr {
    margin: var(--tlp-medium-spacing) 0;
}

blockquote p {
    font-size: 1em;
}

button {
    font-family: var(--tlp-font-family);
}

textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
input[type="color"],
.uneditable-input,
select {
    box-sizing: border-box;
    height: 40px;
    padding: 0 12px;
    transition: border-color 150ms linear;
    border: 1px solid var(--tlp-neutral-dark-color-darker-05);
    border-radius: var(--tlp-medium-radius);
    background: var(--tlp-white-color);
    box-shadow: none;
    font-family: var(--tlp-font-family);
    font-size: 0.875rem;

    &::placeholder {
        color: var(--tlp-neutral-dark-color-darker-10);
    }

    &:focus {
        transition:
            border-color 150ms linear,
            box-shadow 350ms;
        border-color: var(--tlp-main-color);
        box-shadow: var(--tlp-shadow-focus);

        &:invalid {
            border-color: var(--tlp-danger-color);
            box-shadow: var(--tlp-shadow-focus-error);
        }
    }

    &:disabled {
        opacity: 0.5;
    }
}

textarea {
    padding: 8px 12px;

    &[cols] {
        width: auto;
    }

    &[rows] {
        height: auto;
    }
}

select {
    padding: 0 (12px * 2 + 8px) 0 12px;
    background: var(--tlp-white-color) url("@tuleap/tlp-styles/images/field-double-arrows.svg")
        no-repeat;
    background-position: right 12px center;
    -moz-appearance: none; // stylelint-disable-line property-no-vendor-prefix
    -webkit-appearance: none; // stylelint-disable-line property-no-vendor-prefix
    appearance: none;

    /* stylelint-disable-next-line selector-no-qualifying-type */
    &.small {
        height: 32px;
        padding: 0 calc(var(--tlp-small-spacing) * 2 + 6px) 0 var(--tlp-small-spacing);
        background: var(--tlp-white-color)
            url("@tuleap/tlp-styles/images/field-double-arrows-small.svg") no-repeat;
        background-position: right var(--tlp-small-spacing) center;
        font-size: 0.8125rem;
    }

    &[multiple] {
        height: auto;
        padding: 8px 12px;
        background: var(--tlp-white-color);
    }
}

input[type="file"] {
    margin-top: -13px;
}

.tooltip.in {
    opacity: 1;
}

.tooltip.right .tooltip-arrow {
    border-right-color: variables-color-common.$dark-grey;
}

.tooltip-inner {
    background-color: variables-color-common.$dark-grey;
}

kbd {
    display: inline-block;
    padding: 2px var(--tlp-small-spacing);
    border-radius: var(--tlp-medium-radius);
    background: var(--tlp-dark-color);
    color: var(--tlp-white-color);
    font-family: -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
    font-size: 0.875rem;
    line-height: 1.25rem;
    vertical-align: 1px;
}

.alert {
    margin: 10px 0;
    padding: 20px;
    border: 0;
    border-left: var(--tlp-alert-warning-border);
    border-radius: var(--tlp-medium-radius);
    background: var(--tlp-alert-warning-background);
    color: var(--tlp-alert-warning-color);
    list-style: none;
    text-shadow: none;

    h4 {
        margin: 0 0 20px;
        color: inherit;
    }

    code {
        border: 0;
        background: var(--tlp-warning-color-transparent-90);
        color: inherit;
    }
}

.alert-success {
    border-left: var(--tlp-alert-success-border);
    background: var(--tlp-alert-success-background);
    color: var(--tlp-alert-success-color);

    code {
        background: var(--tlp-success-color-transparent-90);
    }
}

.alert-info {
    border-left: var(--tlp-alert-info-border);
    background: var(--tlp-alert-info-background);
    color: var(--tlp-alert-info-color);

    code {
        background: var(--tlp-info-color-transparent-90);
    }
}

.alert-error {
    border-left: var(--tlp-alert-danger-border);
    background: var(--tlp-alert-danger-background);
    color: var(--tlp-alert-danger-color);

    code {
        background: var(--tlp-danger-color-transparent-90);
    }
}

.tlp-alert-title,
.tlp-alert-title:last-child {
    margin: 0 0 var(--tlp-small-spacing);
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.5rem;
}

legend {
    box-sizing: border-box;
}

.popover {
    z-index: 4000;

    .project-privacy {
        font-size: 0.9em;
    }
}

.dropdown-submenu.pull-left.glued > .dropdown-menu {
    left: 0;
    margin: 0;
    transform: translateX(-100%);
}

.nav-list {
    padding-right: var(--tlp-medium-spacing);
    padding-left: var(--tlp-medium-spacing);
}

.nav-tabs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    margin: var(--tlp-large-spacing) 0 var(--tlp-medium-spacing);
    padding: 0 var(--tlp-medium-spacing);
    border-bottom: 0;
    background: none;
    box-shadow: inset 0 -1px 0 var(--tlp-neutral-normal-color);
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: capitalize;

    label {
        letter-spacing: normal;
        text-transform: none;
    }

    > li {
        display: flex;
        box-sizing: border-box;
        align-self: stretch;
        min-height: var(--tlp-jumbo-spacing);
        margin: 0;
        border: 0;
        border-bottom: 3px solid transparent;

        /* stylelint-disable selector-no-qualifying-type */
        &.active,
        &:hover,
        &:focus {
            transition: border-bottom-color 75ms ease-out;
            border-bottom-color: var(--tlp-main-color);

            > a,
            > a:hover,
            > a:focus {
                transition: color 75ms ease-out;
                border: 0;
                background: none;
                color: var(--tlp-main-color);
                cursor: pointer;

                > .caret {
                    border-top-color: var(--tlp-main-color);
                    border-bottom-color: var(--tlp-main-color);
                }
            }
        }

        > a {
            display: flex;
            align-items: center;
            margin: 0;
            padding: 0 var(--tlp-large-spacing);
            border: 0;
            border-radius: 0;
            background: none;
            color: var(--tlp-dimmed-color);

            > .caret {
                margin: 0 0 0 var(--tlp-small-spacing);
                border-top-color: var(--tlp-dimmed-color);
                border-bottom-color: var(--tlp-dimmed-color);
            }

            > i {
                margin: 0 var(--tlp-small-spacing) 0;
                font-size: 0.75rem;
            }
        }
    }

    .open .dropdown-toggle,
    .dropdown-toggle {
        border-color: transparent;
        background-color: transparent;
        color: var(--tlp-dimmed-color);
    }

    .dropdown-menu {
        margin: 3px 0 0;
        border-radius: 0 0 var(--tlp-large-radius) var(--tlp-large-radius);

        > li:first-child > a {
            border-radius: 0;
        }
    }

    > li > .dropdown-toggle > .caret {
        margin-top: 0;
        border-top-color: var(--tlp-dimmed-color);
        border-bottom-color: var(--tlp-dimmed-color);
    }
}

.tabs-left > .nav-tabs .active > a,
.tabs-left > .nav-tabs .active > a:hover,
.tabs-left > .nav-tabs .active > a:focus {
    border-color: transparent;
}

.nav li.dropdown.open .caret,
.nav li.dropdown.open.active .caret,
.nav li.dropdown.open a:focus .caret,
.nav li.dropdown.open a:hover .caret {
    border-top-color: var(--tlp-main-color);
    border-bottom-color: var(--tlp-main-color);
}

.nav > li.dropdown.open {
    &.active {
        a:hover,
        a:focus {
            border-color: transparent;
            background-color: transparent;
            color: var(--tlp-main-color);
        }
    }
}

.dropdown-menu {
    z-index: 3000;
    padding: 0;
    border: 0;
    border-radius: var(--tlp-large-radius);
    letter-spacing: normal;
    text-transform: none;

    > li {
        &.divider {
            margin: var(--tlp-small-spacing) 0;
            border: 0;
            background: var(--tlp-neutral-light-color);
        }

        &.dropdown-menu-title {
            margin: var(--tlp-small-spacing) 0 0;
            padding: var(--tlp-medium-spacing) var(--tlp-medium-spacing) var(--tlp-small-spacing);
            border-top: 1px solid var(--tlp-neutral-light-color);
            color: var(--tlp-dimmed-color);
            font-size: 0.625rem;
            font-weight: 600;
            letter-spacing: 0.5px;
            line-height: 1rem;
            text-transform: uppercase;

            &:first-child {
                margin: 0;
                padding: var(--tlp-small-spacing) var(--tlp-medium-spacing);
                border-top: 0;
            }
        }

        &:first-child > a,
        &:first-child > form > .btn-link {
            border-radius: var(--tlp-large-radius) var(--tlp-large-radius) 0 0;
        }

        &:last-child > a,
        &:last-child > form > .btn-link {
            border-radius: 0 0 var(--tlp-large-radius) var(--tlp-large-radius);
        }

        > form {
            margin: revert;

            > .btn-link {
                width: 100%;
                text-align: left;
                text-decoration: none;
            }
        }

        > a,
        > form > .btn-link,
        &.dropdown-submenu:hover > a,
        &.dropdown-submenu:hover > form > .btn-link,
        &.dropdown-submenu:focus > a,
        &.dropdown-submenu:focus > form > .btn-link {
            padding: var(--tlp-small-spacing) var(--tlp-medium-spacing);
            background: none;
            color: var(--tlp-dark-color);
            font-size: 0.8125rem;
            font-weight: 500;
            line-height: 1rem;

            &:hover,
            &:focus {
                border-color: transparent;
                background: var(--tlp-main-color-hover-background);
                color: var(--tlp-main-color);
            }

            &.text-error {
                color: var(--tlp-danger-dark-color);

                &:hover,
                &:focus {
                    background: var(--tlp-danger-color-transparent-90);
                    color: var(--tlp-danger-dark-color);
                }
            }
        }

        &.dropdown-submenu:hover > a,
        &.dropdown-submenu:hover > form > .btn-link {
            border-color: transparent;
            background: var(--tlp-main-color-hover-background);
            color: var(--tlp-main-color);

            &::after {
                border-left-color: var(--tlp-main-color);
            }
        }
    }
}
/* stylelint-enable */

.tabs-left > .nav-tabs {
    box-shadow: none;
}

/************
 * BUTTONS
 ************/

@mixin btn($background-color, $background-color-disabled, $background-color-active, $color) {
    padding: 9px var(--tlp-medium-spacing); // match TLP buttons
    border-color: $background-color !important;
    outline: none;
    background: $background-color !important;
    color: $color;
    font-weight: 500;
    text-shadow: none;

    &:not(.btn-link) {
        box-shadow: var(--tlp-button-shadow);
    }

    &.btn-large {
        padding: 11px var(--tlp-large-spacing); // match TLP buttons
        font-size: 1.25rem;
        line-height: 1.5rem;

        .caret {
            margin-top: 8px;
        }
    }

    &.btn-small {
        padding: 3px var(--tlp-medium-spacing); // match TLP buttons
        font-size: 0.75rem;
        line-height: 1.5rem;

        > .caret:not(:only-child) {
            margin-top: 10px;
        }
    }

    &.btn-mini {
        padding: 2px var(--tlp-small-spacing); // match TLP buttons
        font-size: 0.75rem;
        line-height: 1.15rem;
    }

    &:disabled,
    &.disabled {
        border-color: transparent !important;
        background: $background-color-disabled !important;
        box-shadow: none;
        cursor: not-allowed;
    }

    &.active:not(.disabled, :disabled) {
        border-color: $background-color-active !important;
        background: $background-color-active !important;
    }

    > i {
        margin-right: 2px;
    }
}

@mixin btn-hover($color) {
    transition:
        box-shadow 75ms ease-in-out,
        background 75ms ease-in-out,
        border-color 75ms ease-in-out;
    border-color: $color !important;
    background: $color !important;
    box-shadow: var(--tlp-button-shadow-hover);
}

.btn:not(.btn-link) {
    @include btn(
        var(--tlp-neutral-light-color),
        var(--tlp-neutral-light-color-lighter-30),
        var(--tlp-neutral-light-color-darker-10),
        var(--tlp-dark-color)
    );

    &.btn-primary {
        @include btn(
            var(--tlp-main-color),
            var(--tlp-main-color-lighter-30),
            var(--tlp-main-color-darker-10),
            var(--tlp-white-color)
        );
    }

    &.btn-danger {
        @include btn(
            var(--tlp-danger-color),
            var(--tlp-danger-color-lighter-30),
            var(--tlp-danger-color-darker-10),
            var(--tlp-white-color)
        );
    }

    &.btn-success {
        @include btn(
            var(--tlp-success-color),
            var(--tlp-success-color-lighter-30),
            var(--tlp-success-color-darker-10),
            var(--tlp-white-color)
        );
    }

    &.btn-warning {
        @include btn(
            var(--tlp-warning-color),
            var(--tlp-warning-color-lighter-30),
            var(--tlp-warning-color-darker-10),
            var(--tlp-white-color)
        );
    }

    &.btn-info {
        @include btn(
            var(--tlp-info-color),
            var(--tlp-info-color-lighter-30),
            var(--tlp-info-color-darker-10),
            var(--tlp-white-color)
        );
    }

    &:hover:not(:disabled, .disabled, .active) {
        @include btn-hover(var(--tlp-neutral-light-color-darker-05));

        &.btn-primary {
            @include btn-hover(var(--tlp-main-color-darker-05));
        }

        &.btn-danger {
            @include btn-hover(var(--tlp-danger-color-darker-05));
        }

        &.btn-success {
            @include btn-hover(var(--tlp-success-color-darker-05));
        }

        &.btn-warning {
            @include btn-hover(var(--tlp-warning-color-darker-05));
        }

        &.btn-info {
            @include btn-hover(var(--tlp-info-color-darker-05));
        }
    }
}

.form-inline .input-prepend,
.form-inline .input-append,
.input-prepend,
.input-append {
    display: inline-flex;
    border-radius: var(--tlp-medium-radius);

    > span:only-child {
        display: flex;
    }

    .btn {
        // @bdauton approved this crappy thing
        display: flex;
        align-items: center;
        box-shadow: none !important;
    }

    > input,
    > select {
        border-radius: 0;

        &:first-child {
            border-top-left-radius: var(--tlp-medium-radius);
            border-bottom-left-radius: var(--tlp-medium-radius);
        }

        &:last-child {
            border-top-right-radius: var(--tlp-medium-radius);
            border-bottom-right-radius: var(--tlp-medium-radius);
        }
    }

    /* stylelint-disable selector-no-qualifying-type */
    > select.add-on-select {
        flex: 0 0 auto;
        width: auto;
        border-right: 0;
    }
    /* stylelint-enable selector-no-qualifying-type */

    .add-on {
        display: flex;
        align-items: center;
        height: auto;
        padding: 0 12px;
        background: var(--tlp-main-color-transparent-90);
        color: var(--tlp-main-color);
    }
}

// stylelint-disable-next-line selector-no-qualifying-type
select.input-small {
    width: auto;
}

/************
 * MODALS
 ************/

.modal {
    z-index: 2006;
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: var(--tlp-x-large-radius);
    box-shadow: var(--tlp-modal-shadow);
    font-size: 14px;

    form {
        margin: 0;
    }
}

.modal-header {
    display: flex;
    box-sizing: border-box;
    flex: 1 1 auto;
    align-items: baseline;
    padding: var(--tlp-medium-spacing);
    border-bottom: 1px solid var(--tlp-neutral-light-color);
    border-top-left-radius: var(--tlp-x-large-radius);
    border-top-right-radius: var(--tlp-x-large-radius);
    color: var(--tlp-dark-color);

    &.modal-header-error {
        background: var(--tlp-danger-color);
    }

    h1,
    h2,
    h3 {
        flex: 1;
        order: 1;
        border: 0;
        color: var(--tlp-dark-color);
        font-size: 1.375rem;
        font-weight: 500;
        line-height: 1.75rem;
    }

    p {
        order: 2;
        color: var(--tlp-white-color);
    }

    > .close {
        order: 3;
        width: 1rem;
        height: 1rem;
        margin: 0;
        border-radius: 50%;
        opacity: 1;
        color: var(--tlp-dimmed-color);
        font-family: inherit;
        font-style: normal;
        line-height: 0;
        text-shadow: none;

        &:hover {
            transition:
                border-color 100ms linear,
                box-shadow 350ms,
                opacity 100ms ease-in-out;
            opacity: 0.5;
        }

        > .modal-close-icon {
            font-size: 0.85rem;
            line-height: 0;
        }
    }
}

.modal-footer {
    box-sizing: border-box;
    padding: var(--tlp-medium-spacing);
    border-top: 1px solid var(--tlp-neutral-light-color);
    border-radius: 0 0 var(--tlp-x-large-radius) var(--tlp-x-large-radius);
    background-color: var(--tlp-white-color);
    text-align: right;
}

.modal-backdrop,
.modal-backdrop.fade.in {
    z-index: 2005;
    opacity: 0.5;
}

.tuleap-artifact-modal .modal-header .title {
    font-size: 24px;
}

.tuleap-artifact-modal .column {
    background-color: transparent;

    h4 {
        color: var(--tlp-white-color);
    }
}

.tuleap-artifact-modal .modal-body .column {
    padding: 15px;
}

.tuleap-artifact-modal .modal-body fieldset {
    margin: 0 0 20px;
}

/**
 * Table
 */
%tlp-table-th {
    padding: 10px;
    color: var(--tlp-main-color);
    font-weight: 600;

    > a {
        color: var(--tlp-main-color);
        text-decoration: none;
    }
}

.table {
    > thead > tr > th {
        @extend %tlp-table-th;

        border-bottom: 2px solid var(--tlp-main-color);
    }

    > .table-sticky-header > tr > th {
        position: sticky;
        top: variables-common.$navbar-height;
        border-bottom: 0;
        background: var(--tlp-white-color);
        background-clip: padding-box;
        box-shadow: inset 0 -2px 0 0 var(--tlp-main-color);
    }

    > tfoot > tr > th {
        @extend %tlp-table-th;

        border-top: 2px solid var(--tlp-main-color);
    }

    > tbody {
        + tbody {
            border-top: 0;
        }

        > tr:nth-child(even) > td {
            background: var(--tlp-table-row-background-even);
        }

        > tr:nth-child(odd) > td {
            background: var(--tlp-table-row-background-odd);
        }

        > tr:hover > td {
            background: var(--tlp-main-color-hover-background);
        }

        /* stylelint-disable selector-no-qualifying-type */
        > tr > td {
            padding: 10px;
            border-bottom: 1px solid #e3e5ed;
            line-height: normal;
            vertical-align: middle;

            &.table-cell-section {
                padding: 5px 10px;
                background: var(--tlp-background-color);
                color: var(--tlp-main-color);
                font-size: 11px;
                font-weight: 600;
                letter-spacing: 0.3px;
                text-transform: uppercase;
            }

            &.table-cell-empty {
                height: 100px;
                background: #fcfcfc;
                color: var(--tlp-main-color-transparent-70);
                font-style: italic;
                text-align: center;
                vertical-align: middle;
            }
        }
        /* stylelint-enable */

        > tr:first-child > td {
            border-top: 0;
        }

        > tr:last-child > td {
            border: 0;
        }
    }

    > thead > tr > th a,
    > tbody > tr > td a {
        text-decoration: none;
    }
}
