// TODO: SCSSify

$page-margin: 15px;

$sidebar-padding: 12px;
$sidebar-width: 270px;

$content-width: 400px;
$content-margin: 12px;
$max-content-width: 4 * $sidebar-width + $page-margin;

$footer-height: 32px;

$site-width: ($page-margin * 2 + $sidebar-width + $sidebar-padding * 2 + $sidebar-border-width * 2 + $content-width + $content-margin * 2);
$page-width: ($sidebar-width + $sidebar-padding * 2 + $sidebar-border-width * 2 + $content-width + $content-margin * 2);

$grid-gap: 0;

html {
    height: 100vh;
    overflow-y: auto;
}

body {
    background-color: $white;
    display: grid;
    grid-column-gap: 5px;
    grid-row-gap: $grid-gap;
    grid-template-columns: ($sidebar-width + $sidebar-padding) minmax(auto, calc(100vw - $sidebar-width - $sidebar-padding));
    grid-template-rows: auto 1fr auto;

    &::backdrop {
        background: $white;
    }
}

#main-header {
    grid-column: 1 / 3;
    grid-row: 1 / 2;
}

#top-bar {
    height: 40px;
    min-width: $site-width;
    z-index: 1001; // High enough so it will be above the sidebar
}

#navigation-level-1 {
    align-content: stretch;
    align-items: stretch;
    background-color: $white;
    border-radius: 0 0 2px 2px;
    box-sizing: border-box;
    display: flex;
    justify-content: flex-start;
    min-width: $site-width;
    width: 100%;

    #top-logo {
        flex: 0 1 auto;
        margin-right: 12px;
        margin-top: -13px;
    }
}

#navigation-level-1-items {
    flex: 1;
    height: 55px;
}

/* --- Layouts -------------------------------------------------------------- */
#current-page-structure {
    background-color: #fff;
    border-radius: 0 0 2px 2px;
    position: relative;
    width: 100%;

    &.oversized {
        overflow: visible;
    }

    .colorblock {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: $page-margin;
    }

    .contextless & {
        .colorblock {
            width: 0;
        }
    }
}

#navigation-level-2 {
    #context-title {
        font-size: 1.1em;
        height: 30px;
        padding-left: $page-margin;
        max-height: 30px;
        overflow: hidden;

        background: linear-gradient(to bottom, $dark-gray-color-5, $dark-gray-color-10);

        > .context_icon {
            margin: 7px 1px 0 9px;
            vertical-align: text-bottom;
        }
    }

    .tabs_wrapper {
        align-items: stretch;
        background-color: $dark-gray-color-10;
        border-bottom: 1px solid $dark-gray-color-40;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        font-size: 0.9em;
        justify-content: space-between;
        padding-left: 27px;
    }

    .contextless & {
        #context-title {
            display: none;
        }

        .tabs_wrapper {
            padding-left: 0;
        }
    }
}

#tabs {
    width: 100%;
    flex: 1;
    padding-left: $page-margin;
    transition: margin-left;
    transition-duration: 300ms;
    transition-delay: 500ms;
}

#sidebar {
    border-left: 1px dashed $brand-color-darker;
    grid-column: 1 / 2;
    grid-row: 2 / 3;
}

#content-wrapper {
    background:
        linear-gradient(90deg, #fff 30%, hsla(0, 0%, 100%, 0)),
        linear-gradient(90deg, hsla(0, 0%, 100%, 0), #fff 70%) 100% 0,
        radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .2), transparent),
        radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .2), transparent) 100% 0;
    background-attachment: local, local, scroll, scroll;
    background-repeat: no-repeat;
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    display: inline-flex;
    grid-column: 2 / 3;
    grid-row: 2 / 3;
    justify-content: flex-start;
    overflow-x: auto;
    padding: $page-margin;
    padding-bottom: calc($page-margin + 35px);
    vertical-align: top;

    .oversized & {
        overflow: visible;
    }

    .no-sidebar & {
        grid-column: 1 / 3;
    }
}

#content {
    flex: 1;
    max-width: 100%;
}

// for old pages without template layout
#layout_table {
    background-color: $light-gray-color-60;
    border: 20px solid #fff;
    margin: 0;
    padding: 0;
    width: 100%;

    td { vertical-align: top; }
}

#page-title-container {
    float: left;
    background-color: #fff;
    line-height: 20px;
    margin-left: 15px;
    margin-right: 15px;
    min-height: 45px;
}

#context-title {
    font-size: 1.1em;
    height: 30px;
    padding-left: $page-margin;
    max-height: 30px;
    overflow: hidden;

    background: linear-gradient(to bottom, $dark-gray-color-5, $dark-gray-color-10);

    > .context_icon {
        margin: 7px 1px 0 9px;
        vertical-align: text-bottom;
    }
}

#page-title {
    font-weight: bold;
    font-size: 1.4em;
    position: relative;
    top: 20px;
}

#main-footer {
    background-color: $base-color;
    color: $white;
    display: flex;
    padding: 2px 0;
    grid-column: 1 / 3;
    grid-row: 3 / 4;
    justify-content: space-between;
    line-height: $footer-height - 4px;
}

#main-footer-info {
    margin-left: 8px;
}

#main-footer-navigation {
    ul {
        display: flex;
        flex: 1;
        flex-wrap: wrap;
        justify-content: flex-end;
        list-style-type: none;
        padding: 0;

        li {
            margin-left: 2px;
            margin-right: 2px;

            a {
                color: $white;
                margin: 0 6px;
                text-decoration: none;
                &:hover {
                    text-decoration: underline;
                }
            }
        }
    }
}

#navigation-level-1 {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-content: stretch;
    align-items: stretch;
    justify-content: space-between;

    width: 100%;
    min-width: $site-width;

    border-bottom: 1px solid $light-gray-color-40;
}

#top-bar {       // second row of flex-main
    flex: 0 1 auto;
    z-index: 1001; // High enough so it will be above the sidebar
}

body {
    width: 100%;

    #current-page-structure { // third row of flex-main
        display: flex;
        flex-direction: column;
        flex-wrap: nowrap;
        align-content: stretch;
        align-items: stretch;
        justify-content: flex-start;

        flex-grow: 1;

        min-width: $site-width;

        .tabs_wrapper {
            display: flex;
            flex-direction: row;
            align-items: stretch;
            justify-content: space-between;
            background-color: $dark-gray-color-10;
            font-size: 0.9em;
            min-height: 2.3em;
            border-bottom: 1px solid $dark-gray-color-40;
        }

        #tabs { // row 1 of layout_page
            padding-left: $page-margin;
            transition: margin-left;
            transition-duration: 300ms;
            transition-delay: 500ms;
        }

        > ul { // column 1 of flex-header
            flex: 1 1 auto;
        }

        #top-logo {
            flex: 0 1 auto;
            margin-right: 12px;
            margin-top: -13px;

        }
    }
}