@use "../base/variables" as *;
@use "sass:color";

.layout {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    display: flex;
    flex-direction: column;

    header {
        height: 5em;
    }

    #footer-bar {
        height: 4em;
        padding: 0 10px;
        display: flex;

        .spacer {
            flex: auto;
        }
    }
}

#page-separator {
    display: none;
    width: 0;
    top: 0;
    bottom: 0;
    right: 0;
    cursor: col-resize;
    background-color: #9d9d9d;

    &.active {
        display: flex;
        width: 8px;
        flex: 0 0 8px;
    }
}

#main-content {
    flex: auto;
    display: flex;
    flex-direction: row;

    #editor-page, #serial-page {
        flex: 1 1 100%;
        display: none;
        flex-direction: column;

        &.active {
            display: flex;
        }
    }

    &.unsaved .file-path {
        color: #f60;
    }
}

#editor-bar, #serial-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 0 10px;
    min-height: 60px;
    height: 4em;
}

#editor-page {
    #editor {
        flex: 1 1 0%;
        background: #333;
    }
}

#serial-page {
    #plotter {
        flex: 2 1 0;
        background: #777;
        position: relative;
        width: 99%;
        overflow: hidden;
        padding: 10px 20px;

        &.hidden{
            display: none;
        }
    }
    #terminal {
        flex: 1 1 0%;
        background: #333;
        position: relative;
        width: 100%;
        overflow: hidden;

        .xterm .xterm-viewport {
            background-color: transparent;
            overflow-y: scroll;
            cursor: default;
            position: absolute;
            inset: 0;
            scrollbar-color: var(--highlight) var(--dark);
            scrollbar-width: thin;
            width: initial !important;

            &::-webkit-scrollbar {
                background-color: var(--dark);
                width: 5px;
            }

            &::-webkit-scrollbar-thumb {
                background: var(--highlight);
            }
        }
    }
    #buffer-size{
        width: 70px;
    }
}

#ble-instructions,
#web-instructions,
#usb-instructions {
    h1 {
        font-weight: 400;
    }

    p {
        margin-bottom: 16px;
    }

    h2 {
        border-bottom: 1px solid $gray-border;
        padding-bottom: .3em;
        margin-bottom: 16px;
        margin-top: 24px;
    }

    ul {
        margin-bottom: 16px;

        li {
            margin-top: .25em;
        }
    }

    a {
        color: #0062c7;
        text-decoration: underline;
    }
}

.connect-status-content {
    background-color: #eebbbb;
    color: #222222;
    border-radius: 10px;
    padding: 10px;
    margin: 10px;
}

.popup-modal {
    #message {
        a {
            color: #0062c7;
            text-decoration: underline;
        }
    }
}

.mode-button {
    display: inline-block;
    font-size: 1.1em;
    width: auto;
    padding: 0.5em 1em 0.5em 1em;
    margin-right: 0.5em;
    cursor: pointer;
    white-space: nowrap;
    border: none;
    color: #fff;
    background-color: $gray;

    &:hover {
        background-color: color.adjust($gray, $lightness: -15%);
    }

    &.active {
        color: #fff;
        background-color: $purple;
    }
}

@media (min-width: 650px) {
    .popup-modal.file-dialog {
        max-height: 365px;
        max-width: 650px;
    }
}

@media (max-width: 767px) {
    .popup-modal.file-dialog {
        #file-list a {

            span:nth-child(3),
            span:nth-child(4) {
                visibility: hidden;
            }
        }
    }
}

@media (min-width: 768px) {
    .popup-modal.connect-dialog {
        width: 768px;
    }
}

.loader {
    display: none;
    z-index: 9998;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    position: fixed;

    &.overlay {
        background-color: rgba(0, 0, 0, .35);
    }

    div {
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        transition: all 300ms ease-in-out;
        position: fixed;
        z-index: 9999;
    }

    &.busy {
        display: block;
    }
}

.body-blackout {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .65);
    display: none;

    &.is-blacked-out {
        display: block;
    }

    &.no-overlay {
        background-color: transparent;
    }
}

.popup-trigger {
    display: inline-block;
}

.popup-modal {
    max-height: 100vh;
    max-width: 100vw;
    /*width: 768px;*/
    background-color: #fff;
    border: 2px solid $purple;
    border-radius: 5px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 25px 20px 10px;
    opacity: 0;
    pointer-events: none;
    transition: all 300ms ease-in-out;
    display: none;

    &.prompt {
        max-height: 365px;
    }

    &.shadow {
        filter: drop-shadow(0px 0px 6px rgba(0, 0, 0, .6));
    }

    &.is--visible {
        opacity: 1;
        pointer-events: auto;
        display: block;
    }

    &__close {
        position: absolute;
        font-size: 1.2rem;
        right: 8px;
        top: 5px;
        cursor: pointer;
        background: #fff;
        line-height: 25px;
    }

    &.no-padding,
    &.connect-dialog {
        padding: 0;
    }

    .label {
        margin-bottom: 5px;

        &.centered {
            text-align: center;
        }
    }

    .buttons {
        display: flex;
        text-align: right;
        margin-top: 10px;

        button {
            margin-left: 10px;

            &:first-child {
                margin-left: 0;
            }

            &.purple-button-link {
                min-width: 250px;
            }
        }

        input {
            margin: 10px 0;
            flex-grow: 1;
            font-size: 1.2em;
            padding: 0 5px;
            border: 1px solid #888;

            &:disabled {
                background-color: #eee;
            }
        }

        &.centered {
            justify-content: center;
        }

        &.stacked {
            flex-direction: column;

            button {
                margin: 5px 0;
                width: 250px;
            }
        }

    }

    &.file-dialog {
        #current-path {
            position: absolute;
            font-size: 1.2rem;
            top: 12px;
            left: 30px;
            max-width: 570px;
            text-overflow: ellipsis;
            overflow: hidden;
        }

        #file-list {
            font-size: 1.4em;
            overflow: auto;
            height: 200px;
            padding: 5px 0;
            border: 1px solid #888;

            a {
                padding-left: 5px;
                display: grid;
                grid-template-columns: 30px minmax(60px, 1fr) 60px 1fr;
                grid-gap: 10px;
                cursor: default;
                user-select:none;

                &.hidden-file {

                    i,
                    span {
                        opacity: 0.65;
                    }
                }

                &.selected {
                    background-color: $light-purple;
                }

                i {
                    text-align: center;
                }

                span {
                    text-overflow: ellipsis;
                    overflow: hidden;
                    white-space: nowrap;
                }
            }
        }

        .buttons {
            button {
                i {
                    padding-left: 0;
                }
            }
        }
    }

    &[data-popup-modal="folder-select"] {
        #file-list {
            margin-top: 20px;
        }
    }

    &[data-popup-modal="device-discovery"],
    &[data-popup-modal="device-info"] {
        .device-info {
            margin-top: 5px;
            width: 100%;
            border-collapse: collapse;
            filter: drop-shadow(0px 0px 2px rgba(0, 0, 0, .5));

            thead tr {
                background-color: $light-purple;
                color: #ffffff;
                text-align: center;

                th {
                    border-top-left-radius: 5px;
                    border-top-right-radius: 5px;
                }
            }

            th,
            td {
                padding: 5px 10px;
            }

            tbody {
                tr {
                    border-bottom: 1px solid #ddd;

                    &:nth-of-type(even) {
                        background-color: #f3f3f3;
                    }

                    &:nth-of-type(odd) {
                        background-color: #fff;
                    }

                    &:last-of-type {
                        border-bottom: 2px solid #aaa;
                    }

                    td {
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;

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

        h3 {
            margin: 10px auto 5px;

            i {
                margin-left: 10px;
                cursor: pointer;

                &:hover {
                    color: $purple;
                }
            }
        }

        #devices {
            max-width: 500px;
            font-size: 1.2rem;
            height: 120px;
            border: 1px solid #333;
            text-overflow: ellipsis;
            overflow-y: scroll;

            a {
                cursor: pointer;
                display: block;
            }
        }
    }

    &[data-popup-modal="progress"] {
        progress {
            width: 100%;
        }
    }

}
