@import '../environment';

$embed-max-width: 912px;

$risk-levels: (
                (1, #2f9ee2),
                (2, #3a87d9),
                (3, #4b6ed3),
                (4, #5a56ce),
                (5, #8d499b),
                (6, #b91e6b),
                (7, #ed0039),
);

%risk-level
{
    @include font-dimensions(12px, 16px, 0.4px);
    @include antialiasing;

    position: relative;

    display: inline-block;
    width: steps(2);
    height: steps(2);
    padding-top: 4px;
    padding-left: 1px;

    color: $color-text-inverted-lighter;
    background: $color-background-inverted-lightest;
    text-align: center;

    &::after {
        content: "";

        position: absolute;
        top: 100%;
        left: 0;

        border: solid transparent;
        border-width: steps(0.5) steps(1);
        border-top-color: $color-background-inverted-lightest;
    }

    @each $level in $risk-levels {
        &.shield_#{nth($level, 1)} {
            $color: nth($level, 2);

            background-color: $color;

            &::after
            {
                border-top-color: $color;
            }
        }
    }
}

%fund-values
{
    .positive,
    .negative,
    .unchanged
    {
        .remark
        {
            @include visually-hidden;
        }
    }

    .positive,
    .negative,
    .unchanged
    {
        &::after
        {
            content: "";

            position: relative;
            top: -2px;

            display: inline-block;
            width: steps(2);
            height: steps(2);

            vertical-align: top;
        }
    }

    .positive
    {
        $color: darken($color-success, 12.5%);

        color: $color;

        &::after
        {
            content: svg-image-data-url("arrow-up", $color);
        }
    }

    .negative
    {
        $color: $color-alert;

        color: $color;

        &::after
        {
            content: svg-image-data-url("arrow-down", $color);
        }
    }
}

.embed-container {
    h1 {
        @include extra-large-heading;
    }
}

.table-box,
{
    @extend %fund-values;
}

.funds {
    .links {
        @include links;

        a.back {
            @include back-link;
        }
    }

    .field.investment-gain {
        margin-bottom: steps(4);
    }

    .shield_icon {
        @extend %risk-level;
    }

    .fund_list_table {
        .js &.hidden
        {
            display: none;
        }

        tbody th {
            font-size: 18px;
            font-weight: bold;
        }

        td {
            @include font-dimensions(14px, 20px, 0.3px);

            padding-top: steps(2.5);
            padding-bottom: steps(2.5);
        }

        .field {
            margin-bottom: 0;

            .control.checkbox {
                @include font-dimensions(14px, 20px, 0.5px);

                padding-top: 0;
                padding-bottom: 0;
                margin-bottom: 0;
            }
        }

        .shield_icon {
            margin-top: -3px;
        }

        .icon.download {
            margin-top: -3px;
        }

        .icon.pdf {
            color: $color-text-lighter;
        }

        .extra_data {
            @include clear-inside;

            padding-left: steps(3.5);
            margin-top: steps(1.5);

            .date {
                @include font-dimensions(12px, 20px);

                float: left;
                color: $color-text-lighter;
            }

            .price {
                font-weight: bold;
                float: right;
            }
        }

        .sort_button {
            color: $color-text-inverted-lighter;
        }

        > thead > tr > th:not(.sorted) .sort_button.sort_up {
            display: none;
        }

        > thead > tr > th.sorted .sort_button.sort_down {
            display: none;
        }

        > tbody > tr.selected {
            background-color: $color-background-normal;
        }

        &.comparing {
            > tbody > tr:not(.selected) {
                display: none;
            }
        }

        td.risk {
            text-align: center;
        }

        div.right {
            text-align: right;
        }
    }

    .fund_compare {
        @include antialiasing;

        position: fixed;
        z-index: 2;
        bottom: 0;
        left: 0;
        right: 0;

        background: $color-brand-normal;

        &.hidden {
            display: none;
        }

        .inner {
            @include font-dimensions(0, 0);

            padding: 30px 0 30px;
            margin-left: 20px;
            margin-right: 20px;
            text-align: center;
        }

        .text {
            display: inline-block;

            @include font-dimensions(16px, 30px);

            vertical-align: top;
            font-weight: normal;
            padding: 10px 0;
            margin-right: 37px;
            color: $color-text-inverted-lighter;

            .value {
                font-weight: bold;
            }
        }

        .button {
            border: 1px solid;
            padding-top: 14px;
            padding-bottom: 14px;

            &:hover, &:focus {
                background-color: $color-background-lightest;
                color: $color-brand-normal;
            }
        }

        &:not(.comparing) {
            .button.uncompare {
                display: none;
            }
        }

        &.comparing {
            .button.compare {
                display: none;
            }
        }
    }
}

.investment-directions
{
    li
    {
        border: 1px solid $color-border-normal;
        padding: steps(3);
        position: relative;
        margin-bottom: steps(2);

        &:last-child
        {
            margin-bottom: 0;
        }
    }

    .logo
    {
        padding: 0;

        color: #000;
        line-height: steps(3);

        .svg
        {
            vertical-align: top;
        }
    }

    .svg.ergo-logo
    {
        color: $color-brand-normal;
    }

    @include for-at-least-normal-tablets
    {
        li
        {
            padding: steps(4) steps(27) steps(4) steps(4);
        }

        .description
        {
            margin-bottom: 0;
        }

        .action
        {
            position: absolute;
            bottom: steps(4);
            right: steps(4);
        }
    }
}

main nav.side {
    .submenu {
        padding-left: 50px;

        > li {
            > a {
                font-size: 14px;
                padding-left: 20px;
                color: $color-text-normal;

                &:before {
                    display: none;
                }

                &:hover, &:focus {
                    color: $color-text-darker;
                    background: $color-background-lighter;
                }
            }

            &.active {
                > a {
                    color: $color-brand-normal;
                }
            }
        }
    }
}

.investment_program {
    .risk-meter {
        overflow: hidden;
        margin-top: steps(3);
        margin-bottom: steps(2);

        .range {
            @include inline-list;

            display: flex;
            align-items: flex-end;
            margin-bottom: steps(1);

            li {
                @include font-dimensions(12px, steps(3));

                flex: 2 1;

                text-align: center;

                &:first-child,
                &:last-child {
                    flex-grow: 1;
                }

                &:first-child {
                    text-align: left;
                }

                &:last-child {
                    text-align: right;
                }

                &.active {
                    position: relative;

                    margin-bottom: steps(1.5);

                    .value {
                        @include font-dimensions(16px, steps(2), 0.5px);
                        @include antialiasing;

                        position: relative;

                        display: inline-block;
                        width: steps(3);
                        padding-top: 9px;
                        padding-bottom: 2px;

                        color: $color-text-inverted-lighter;
                        background: $color-background-inverted-lightest;
                        text-align: center;

                        &::after {
                            content: "";

                            position: absolute;
                            top: 100%;
                            left: 0;

                            border: solid transparent;
                            border-width: 8px steps(1.5);
                            border-top-color: $color-background-inverted-lightest;
                        }
                    }

                    @each $level in $risk-levels {
                        &[data-level="#{nth($level, 1)}"] .value {
                            $color: nth($level, 2);

                            background-color: $color;

                            &::after
                            {
                                border-top-color: $color;
                            }
                        }
                    }


                    // trapezoids above meter gauge

                    &::before,
                    &::after {
                        content: "";

                        position: absolute;
                        top: 100%;
                        left: -50%;

                        width: calc(200% - 15px);
                        height: 13px;
                        border: solid $color-text-darker;
                        margin-left: 5px;
                    }

                    &::before {
                        border-width: 2px 2px 0;
                        margin-top: 14.5px;

                        transform: perspective(1.2px) rotateX(1deg);

                        @include for-at-least-tablets {
                            transform: perspective(3px) rotateX(1deg);
                        }
                    }

                    &::after {
                        border-width: 0 2px 2px;
                        margin-top: 30.5px;

                        transform: perspective(1.2px) rotateX(-1deg);

                        @include for-at-least-tablets {
                            transform: perspective(3px) rotateX(-1deg);
                        }
                    }

                    &:first-child,
                    &:last-child {
                        &::before,
                        &::after {
                            width: calc(300% - 8px);
                            margin-left: 0;
                        }

                        .value::before {
                            content: "";

                            position: absolute;
                            bottom: 0;

                            width: 2px;
                            height: steps(3) - 1px;
                            background: $color-text-darker;
                            margin-bottom: steps(-5) + 1px;
                        }
                    }

                    &:first-child {
                        &::before,
                        &::after {
                            left: -100%;
                        }

                        .value::before {
                            left: 0;
                        }
                    }

                    &:last-child {
                        &::before,
                        &::after {
                            left: auto;
                            right: -100%;
                        }

                        .value::before {
                            right: 0;
                        }
                    }
                }
            }
        }

        meter {
            @include hidden-text;

            display: block;
            width: 100%;
            height: steps(1);
            margin-bottom: steps(2);

            background: linear-gradient(to right, #2f9ee2, #5a48d2, #ed0039);

            appearance: none;

            // meter gauge
            &::-webkit-meter-bar {
                background: none;
            }

            // current value
            &::-webkit-meter-optimum-value {
                background: none;
            }
            &::-moz-meter-bar {
                background: none;
            }
        }

        .gradation {
            display: flex;
            justify-content: space-between;

            .stage {
                @include baseline-box(12px, steps(2), 0);

                margin: 0;

                &.high {
                    text-align: right;
                }
            }

            .name,
            .description {
                display: block;
            }

            .name {
                color: $color-text-darker;
            }

            .description {
                color: $color-text-lighter;
            }
        }
    }

    .richtext {
        margin-bottom: 30px;
    }

    .program_structure {
        margin-top: steps(5);

        h2 {
            @include large-heading;
        }
    }

    section.results {
        @extend %fund-values;

        @include content-padding;

        margin-top: steps(5);

        .heading {
            @include large-heading;
        }

        .search_bar {
            @include clear-inside;

            padding-top: steps(3);

            .right .field {
                margin-top: 30px;
                margin-bottom: 0;
            }
        }

        .chart_title {
            @include alternative-text;

            margin-top: steps(-1);
            margin-bottom: steps(1);

            text-align: center;

            &.hidden
            {
                display: none;
            }

            .result {
                @include font-dimensions(18px, steps(2.5), 0.6px);

                display: block;
                font-weight: bold;
                margin-top: 10px;

                &::after
                {
                    top: 1px;
                }
            }
        }
    }

    #result_chart {
        height: 318px;
        margin-bottom: 21px;

        .highcharts-range-selector-group {
            display: none;
        }
    }

    .tools {
        .compare {
            margin-bottom: steps(3.5);

            .field {
                margin-bottom: steps(2);
            }

            .action a {
                display: inline-block;
                line-height: steps(2);
                padding: steps(1.5) steps(3.5);
            }
        }

        .icons {
            @include font-dimensions(14px, 20px, 0.6px);

            text-align: center;

            @include for-at-least-tablets {
                text-align: left;
            }

            $icons: print export pdf jpg png svg;

            @each $icon in $icons
            {
                .#{$icon}
                {
                    @include icon($icon, $color-link-normal);
                }
            }

            .export_menu_cont {
                display: inline-block;
                margin-left: 25px;
                position: relative;

                .export_menu {
                    position: absolute;
                    z-index: 2;
                    border: 1px solid $color-border-normal;
                    background: $color-background-lightest;
                    top: 100%;
                    right: -30px;
                    margin-top: 12px;
                    width: 220px;
                    text-align: left;


                    &::before,
                    &::after
                    {
                        content: "";

                        position: absolute;
                        bottom: 100%;

                        border: solid transparent;
                    }

                    &::before
                    {
                        right: 60px;

                        border-bottom-color: $color-border-normal;
                        border-width: 8px;
                    }

                    &::after
                    {
                        right: 61px;

                        border-bottom-color: $color-background-lightest;
                        border-width: 7px;
                    }

                    a {
                        display: block;
                        padding: steps(2.5) steps(2.5) steps(2.5) steps(6);
                        border-top: 1px solid $color-border-normal;
                        margin-top: -1px;

                        text-align: left;
                    }
                }

                .js &:not(.open) {
                    .export_menu {
                        display: none;
                    }
                }
            }
        }

        @include for-desktops {
            display: flex;
            justify-content: space-between;
            align-items: flex-end;

            padding: 0 steps(4);

            .compare {
                display: flex;
                align-items: flex-end;

                margin-bottom: 0;

                .field {
                    margin-bottom: 0;
                    margin-right: steps(2);
                }
            }

            .icons {
                @include font-dimensions(16px, 20px, 0.5px);

                margin-bottom: steps(1.5);
            }
        }
    }

    .profitability_block {
        @include content-padding;

        margin-top: steps(5);

        h2 {
            @include large-heading;
        }

        .date {
            @include alternative-text;

            margin-bottom: steps(0.5);
        }

        #profitability_table {
            @extend %fund-values;

            display: table;
            width: 100%;
            border: 1px solid $color-border-normal;
            padding-right: 30px;

            > .tr {
                display: table-row;
            }

            > .tr > .td {
                display: table-cell;
                padding-left: 30px;
                vertical-align: top;
                position: relative;
            }

            > .tr.header_row {
                @include font-dimensions(14px, 20px, 0.5px);

                color: $color-text-darker;
                font-weight: bold;
                background: $color-background-lighter;

                > .td {
                    padding-top: 25px;
                    padding-bottom: 25px;
                    border-bottom: 1px solid $color-border-normal;

                    &:last-child {
                        position: relative;

                        &:before {
                            content: "";
                            position: absolute;
                            top: 0;
                            left: 100%;
                            height: 100%;
                            width: 30px;
                            background: $color-background-lighter;
                            border-bottom: 1px solid $color-border-normal;
                        }
                    }
                }
            }

            .data_row {
                @include font-dimensions(14px, 20px, 0.5px);

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

                padding-top: 25px;
                padding-bottom: 25px;
                color: $color-text-normal;

                &:before {
                    content: "";
                    position: absolute;
                    bottom: 0;
                    left: 30px;
                    right: 0;
                    border-bottom: 1px solid $color-border-normal;
                }
            }

            .right {
                padding-left: steps(2);

                white-space: nowrap;
            }

            .tr.dt_only.last_data_row {
                .data_row:before {
                    display: none;
                }
            }

            .header {
                @include font-dimensions(14px, 20px, 0.5px);

                color: $color-text-darker;
                font-weight: bold;
                background: $color-background-lighter;
                border-bottom: 1px solid $color-border-normal;
                padding-top: 25px;
                padding-bottom: 25px;
            }

            @include for-normal-tablets {
                .data_row {
                    display: block;
                }

                .right {
                    padding-left: 0;
                    margin-top: steps(1);
                }
            }
        }
    }
}

.investment_programs {
    .richtext {
        margin-bottom: steps(1.5);
    }

    .shield_icon {
        @extend %risk-level;
    }

    .program_list {
        > li {
            margin-bottom: steps(2.5);
        }

        h2 {
            @include normal-heading;
            @include sans-serif-font-family;
        }

        .graph {
            float: left;
            padding: 0;
            margin: 0;

            color: #379ae6;

            @include for-at-most-small-tablets
            {
                .svg,
                .svg > svg
                {
                    width: steps(5);
                    height: steps(5);
                }
            }
        }

        .part_meta {
            @include font-dimensions(14px, steps(2), 0.6px);
            @include clear-inside;

            padding-top: 3px;
            margin-left: steps(8);
            margin-bottom: steps(1);

            color: $color-text-darker;

            .name {
                margin-right: steps(0.5);
            }

            .value {
                font-weight: bold;
            }

            .profit {
                margin-bottom: steps(0.5);
            }

            .risk .value {
                @include font-dimensions(12px, steps(2), 0.4px);
            }
        }

        .links {
            margin-top: steps(-1);
        }
    }

    .panel.promo {
        .heading {
            @include normal-heading;
        }

        .text {
            @include baseline-box(16px, steps(2.5), 0.5px);
        }

        @include for-at-least-normal-tablets {
            .text {
                @include baseline-box(16px, steps(3), 0.5px);
            }

            .action {
                margin-top: steps(3);
            }
        }
    }
}


@include for-between($window-breakpoint-normal-tablet, steps(110) - 1px)
{
    .investment_program {
        .search_bar {
            .left {
                float: left;
            }

            .right {
                float: left;
                clear: left;
                margin-top: 20px;
            }
        }
    }
}

@include for-at-least(steps(110))
{
    .investment_program {
        .search_bar {
            .left {
                float: left;
            }

            .right {
                float: right;
            }
        }
    }
}

@include for-at-most-small-tablets
{
    .investment_program {
        .profitability_block {
            #profitability_table {
                padding-right: 0;

                .tr.header_row {
                    display: none;
                }

                .tr.dt_only {
                    display: none;
                }

                .tr.mob_only:not(.first_mob_row) {
                    > .header {
                        border-top: 1px solid $color-border-normal;
                    }
                }

                .header {
                    padding-right: 30px;
                    padding-left: 30px;
                    padding-top: 24px;
                    padding-bottom: 24px;
                }

                .data_row {
                    padding-right: 30px;
                    padding-left: 30px;
                    position: relative;

                    &:before {
                        right: 30px;
                    }

                    &:last-child:before {
                        display: none;
                    }
                }
            }
        }
    }
}

@include for-at-least-normal-tablets
{
    .funds {
        .field.investment-gain {
            margin-top: steps(4);
        }

        .fund_compare {
            .inner {
                margin-left: auto;
                margin-right: auto;
                max-width: 1200px;
            }
        }
    }

    .investment_program {
        .risk-meter {
            margin-top: steps(4);
            margin-bottom: steps(3);
        }

        section.results {
            .search_bar {
                padding-bottom: steps(3);

                .control.date {
                    width: steps(17.5);
                }

                .field {
                    float: left;
                    display: flex;

                    &:not(:last-child) {
                        margin-right: steps(2);
                    }

                    .label {
                        align-self: center;

                        padding: 0;
                        margin-right: steps(2) - 3px;
                    }
                }

                .right .field {
                    margin-top: 0;
                }
            }

            .chart_title {
                margin-top: steps(-2);

                .result {
                    display: inline-block;
                    margin-top: 0;
                    margin-left: 10px;
                }
            }
        }

        #result_chart {
            height: 380px;
            margin-bottom: 39px;
        }

        .profitability_block {
            .table_title {
                @include clear-inside;

                h2 {
                    float: left;
                    max-width: 80%;
                }

                .date {
                    float: right;
                    margin-top: steps(2);
                }
            }

            #profitability_table {
                table-layout: fixed;

                .tr.mob_only {
                    display: none;
                }
            }
        }
    }

    .investment_programs {
        .richtext {
            margin-bottom: steps(5);
        }

        .program_list {
            margin-bottom: 72px;

            > li {
                position: relative;

                margin-bottom: steps(6);
            }

            h2 {
                margin-left: 128px;
                margin-bottom: steps(0.5);
            }

            .graph {
                position: absolute;
                top: 0;
                left: 0;
            }

            .part_meta {
                padding-top: 0;
                margin-left: 128px;
                margin-bottom: steps(1.5);

                .name {
                    margin-right: 8px;
                }

                .profit {
                    float: left;
                    width: 50%;
                    padding-right: 20px;
                    margin-bottom: 0;

                    .value {
                        font-size: 16px;
                    }
                }

                .risk {
                    float: left;
                    width: 50%;

                    .shield_icon {
                        margin-top: -1px;
                    }
                }
            }

            .part_description {
                margin-left: 128px;
            }
        }
    }
}

.embed-container {

    .program_structure {
        --program-structure-rows: 0;
    }

    #structure_chart {
        min-height: calc(160px + 62px * var(--program-structure-rows));
    }
}

@include for-phones
{
    .funds {
        .fund_list_table {
            th[title]:before,
            td[title]:before {
                display: none;
            }

            tbody th {
                background: $color-background-lighter;
                font-size: 16px;
                padding-bottom: 22px;
            }

            .field .control.checkbox {
                @include font-dimensions(16px, 25px, 0.5px);
            }

            td:not(:first-child) {
                display: none;
            }
        }

        .fund_compare .text {
            margin-right: 0;
            padding-top: 0;
        }
    }
}

@include for-at-least-tablets
{
    .embed-container {

        #structure_chart {
            min-height: 200px;
            height: calc(52px * var(--program-structure-rows));
        }
    }

    .funds {
        .fund_list_table {
            .extra_data {
                display: none;
            }

            .sort_col,
            .positive,
            .negative {
                white-space: nowrap;
            }
        }
    }

    .investment_program {
        .search_bar {
            .control.radio .option {
                min-width: 96px;
            }
        }
    }
}

@include for-at-least($embed-max-width) {

    .embed-container {
        max-width: $embed-max-width;
    }

    .funds.embed-container,
    .investment_program.embed-container {
        margin: 0;

        .results,
        .content,
        .profitability_block{
            padding-left: 0;
            padding-right: 0;
        }

        section.results .search_bar {
            padding-top: steps(3);
            padding-bottom: steps(5);
        }

        .search_bar {
            display: flex;
            justify-content: space-between;

            &:after {
                display: none!important;
            }

            .right {
                float: none;
                margin-top: 0;
            }

            .left .field {
                margin-top: steps(2.5);
            }
        }

        .search_bar .field {
            display: flex;
            flex-direction: column;

            &:after {
                display: none;
            }

            .label {
                width: 100%;
            }

            .label label {
                margin-left: steps(2);
            }
        }
    }
}
