:host {
    --radius: 0.375rem;
    --card: 220 18% 10%;
    --border: 220 15% 18%;
    --primary: 160 60% 45%;
    --radius: 0.375rem;
    --destructive: 0 70% 50%;
    --muted: 220 15% 13%;
    --muted-foreground: 220 10% 50%;
    --primary-foreground: 220 20% 7%;
    --scroll-track: 220 16% 12%;
    --scroll-thumb: 220 12% 34%;
    --scroll-thumb-hover: 160 45% 44%;

    font-family:
        ui-monospace,
        SFMono-Regular,
        Menlo,
        Monaco,
        Consolas,
        Liberation Mono,
        Courier New,
        monospace;

    height: 100%;
    width: 100%;

    border: 1px solid hsl(var(--border));
    background-color: hsl(var(--card));
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    container-type: inline-size;

    .listing {
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        min-height: 0;

        header {
            height: 30px;
            background: rgba(28, 31, 38, 0.6);
            border-bottom: 1px solid hsl(var(--border));

            display: flex;
            align-items: center;
            justify-content: space-between;

            .actions {
                display: flex;
                align-items: center;

                .action {
                    cursor: pointer;
                    padding: 4px;
                    display: flex;
                    align-items: center;
                    z-index: 1;

                    img {
                        height: 14px;
                        padding: 4px;
                        border-radius: 4px;
                    }

                    &:hover {
                        background-color: hsl(var(--border) / 0.6);
                    }
                }
            }

            .title {
                color: hsl(var(--primary));
                height: 14px;
                padding: 0 12px;
                display: flex;
                align-items: center;
                font-size: 0.75rem;
                line-height: 1rem;

                img {
                    height: 14px;
                    margin-right: 5px;
                }

                .text {
                    display: flex;
                    flex-direction: row;
                    justify-content: center;
                    margin-top: 2px;

                    .name {
                        margin-right: 10px;
                    }

                    .description {
                        color: hsl(var(--muted-foreground));
                    }
                }
            }
        }

        main {
            flex: 1;
            display: flex;
            flex-direction: column;
            position: relative;
            min-height: 0;
            overflow: hidden;

            .loader {
                color: hsl(var(--muted-foreground));
                font-size: 13px;
                animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
                text-align: center;
                display: flex;
                align-items: center;
                justify-content: center;
                position: absolute;
                height: 100%;
                width: 100%;
                background: rgba(28, 31, 38, 0);
                backdrop-filter: blur(4px);
            }

            .error {
                font-size: 13px;
                text-align: center;
                color: hsl(var(--destructive));
                height: 100%;
                display: flex;
                align-items: center;
                justify-content: center;
            }

            .navigation {
                height: 25px;
                padding: 10px;
                font-size: 0.75rem;
                line-height: 1rem;
                background-color: hsl(var(--card));
                display: flex;
                align-items: center;
                justify-content: space-between;
                border-bottom: 1px solid hsl(var(--border));
                position: sticky;
                top: 0;
                z-index: 3;

                .breadcrumbs {
                    display: flex;
                    align-items: center;
                    margin-right: 10px;

                    .breadcrumb-container {
                        white-space: nowrap;

                        .breadcrumb {
                            color: hsl(var(--primary));
                            margin-right: 4px;
                            cursor: pointer;

                            &:after {
                                margin-left: 4px;
                            }

                            &:hover {
                                color: rgb(189, 219, 209);
                            }

                            &:last-child {
                                margin-right: 0;
                                color: rgb(189, 219, 209);
                                cursor: default;
                            }
                        }
                    }

                    .arrow {
                        height: 12px;
                        width: 12px;
                        opacity: 0.6;
                        top: 2px;
                        margin-right: 4px;
                        position: relative;
                    }
                }

                .actions {
                    display: flex;
                    align-items: center;
                    gap: 8px;
                }

                .action {
                    border: none;
                    background: transparent;
                    color: rgb(189, 219, 209);
                    font-size: 1.1rem;
                    line-height: 1;
                    padding: 2px 4px;
                    border-radius: 4px;
                    cursor: pointer;

                    &:hover {
                        background-color: hsl(var(--border) / 0.6);
                    }

                    img {
                        height: 14px;
                        width: 14px;
                        display: block;
                    }
                }

                .action.disconnect {
                    color: #ff4d5f;
                    font-size: 0.65rem;
                    letter-spacing: 0.08em;
                    padding: 4px 8px;

                    &:hover {
                        color: #ff6b7a;
                        background-color: hsl(var(--destructive) / 0.12);
                    }
                }
            }

            .content {
                flex: 1;
                min-height: 0;
                overflow: auto;
                font-size: 0.75rem;
                line-height: 1rem;
                scrollbar-width: thin;
                scrollbar-color: hsl(var(--scroll-thumb)) hsl(var(--scroll-track));

                &::-webkit-scrollbar {
                    width: 10px;
                    height: 10px;
                }

                &::-webkit-scrollbar-track {
                    background: hsl(var(--scroll-track));
                }

                &::-webkit-scrollbar-thumb {
                    background: hsl(var(--scroll-thumb));
                    border-radius: 999px;
                    border: 2px solid hsl(var(--scroll-track));
                }

                &::-webkit-scrollbar-thumb:hover {
                    background: hsl(var(--scroll-thumb-hover));
                }

                table {
                    width: 100%;
                    border-collapse: separate;
                    border-spacing: 0;
                    table-layout: auto;

                    thead {
                        background-color: hsl(var(--muted));
                        border-bottom: 1px solid hsl(var(--border));

                        th {
                            padding: 8px 10px;
                            text-align: left;
                            color: hsl(var(--muted-foreground));
                            position: sticky;
                            top: 0;
                            z-index: 2;
                            background-color: hsl(var(--muted));
                            border-bottom: 1px solid hsl(var(--border));
                            line-height: 0.95rem;

                            &.action-col {
                                width: 58px;
                                min-width: 58px;
                                padding: 0 10px;
                            }

                            &:first-child {
                                width: 30%;
                                min-width: 180px;
                                max-width: 195px;
                            }

                            &:nth-child(2),
                            &:nth-child(3),
                            &:nth-child(4),
                            &:nth-child(5) {
                                white-space: nowrap;
                                width: 1%;
                            }
                        }
                    }

                    tbody {
                        padding: 10px 10px;
                        tr {
                            border-bottom: 1px solid hsl(var(--border) / 0.4);

                            td {
                                padding: 10px 10px 9px;
                                color: hsl(var(--muted-foreground));

                                &:first-child {
                                    min-width: 180px;
                                    max-width: 195px;
                                    white-space: nowrap;

                                    .name {
                                        display: inline-block;
                                        max-width: calc(100% - 26px);
                                        overflow: hidden;
                                        text-overflow: ellipsis;
                                        vertical-align: middle;
                                    }
                                }

                                &:nth-child(2),
                                &:nth-child(3),
                                &:nth-child(4),
                                &:nth-child(5) {
                                    white-space: nowrap;
                                }

                                &.action-col {
                                    width: 58px;
                                    min-width: 58px;
                                    text-align: center;
                                    padding-left: 1px;
                                    padding-right: 1px;

                                    .file-actions {
                                        display: flex;
                                        align-items: center;
                                        justify-content: center;
                                        gap: 8px;
                                    }

                                    .file-action {
                                        border: none;
                                        background: transparent;
                                        color: hsl(var(--muted-foreground));
                                        width: 16px;
                                        height: 16px;
                                        border-radius: 3px;
                                        cursor: pointer;
                                        opacity: 0;
                                        visibility: hidden;
                                        pointer-events: none;
                                        transition: opacity 120ms ease;
                                        padding: 0;

                                        svg {
                                            width: 12px;
                                            height: 12px;
                                            display: block;
                                            margin: 0 auto;
                                        }

                                        &:hover {
                                            color: hsl(var(--primary));
                                        }

                                        &.delete:hover {
                                            color: hsl(var(--destructive));
                                        }
                                    }
                                }

                                .name {
                                    &.file {
                                        color: rgb(189, 219, 209);
                                    }
                                    &.folder {
                                        color: hsl(var(--primary));
                                    }
                                }

                                .kind {
                                    height: 14px;
                                    width: 14px;
                                    margin-right: 5px;
                                    top: 3px;
                                    position: relative;
                                }
                            }

                            &:hover {
                                cursor: pointer;
                                background-color: hsl(var(--muted) / 0.4);

                                td.action-col .file-action {
                                    opacity: 1;
                                    visibility: visible;
                                    pointer-events: auto;
                                    color: hsl(var(--primary));
                                }
                            }

                            &.selected {
                                background-color: hsl(var(--primary) / 0.3);

                                td.action-col .file-action {
                                    opacity: 1;
                                    visibility: visible;
                                    pointer-events: auto;
                                }

                                &:hover {
                                    background-color: hsl(var(--primary) / 0.4);
                                }
                            }
                        }
                    }
                }
            }
        }

        footer {
            height: 25px;
            background: rgba(28, 31, 38, 0.6);
            border-top: 1px solid hsl(var(--border));
            font-size: 0.75rem;
            line-height: 1rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 10px;

            .status {
                font-size: 0.65rem;
                color: hsl(var(--muted-foreground));

                .selected-item {
                    margin-left: 10px;
                    color: hsl(var(--primary));
                }
            }

            .version {
                font-size: 0.65rem;
                color: hsl(var(--muted-foreground));
            }
        }
    }

    .creds {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;

        /* display: none; */

        &.blurred {
            background: rgba(28, 31, 38, 0);
            backdrop-filter: blur(4px);
        }

        .auth {
            display: flex;
            flex-direction: column;
            background: hsl(var(--card));
            position: relative;
            background-color: rgba(21, 24, 30, 0.95);
            border: 1px solid hsl(var(--border));
            padding: 30px;
            box-shadow:
                rgba(0, 0, 0, 0) 0px 0px 0px 0px,
                rgba(0, 0, 0, 0) 0px 0px 0px 0px,
                rgba(0, 0, 0, 0.5) 0px 25px 50px -12px;
            border-radius: var(--radius);

            .title {
                margin-bottom: 12px;
                color: hsl(var(--primary));
            }

            label {
                font-size: 0.75rem;
                line-height: 1rem;
                margin-bottom: 1rem;
                color: hsl(var(--muted-foreground));
            }

            input {
                font-size: 0.875rem;
                line-height: 1.25rem;
                padding-top: 0.5rem;
                padding-bottom: 0.5rem;
                padding-left: 0.75rem;
                padding-right: 0.75rem;
                background-color: rgb(28, 31, 38);
                border-color: rgb(39, 44, 53);
                border-width: 1px;
                border-radius: calc(var(--radius) - 2px);
                width: 100%;
                margin-bottom: 12px;
                color: rgb(189, 219, 209);
                box-sizing: border-box;

                &:focus {
                    outline: none;
                    border-color: hsl(var(--primary));
                    box-shadow: 0 0 0 1px hsl(var(--primary));
                }
            }

            button[type='submit'] {
                margin-top: 12px;
                width: 100%;
                background-color: hsl(var(--primary));
                color: hsl(var(--primary-foreground));
                letter-spacing: 0.05em;
                font-size: 13px;
                font-weight: 500;
                padding: 0.5rem 1rem;
                border-radius: calc(var(--radius) - 2px);
                height: 2rem;
                cursor: pointer;
                border: none;

                &:hover {
                    background-color: hsl(var(--primary) / 0.9);
                }
            }
        }
    }

    .upload-modal,
    .download-modal,
    .delete-modal {
        position: absolute;
        inset: 0;
        display: none;
        align-items: center;
        justify-content: center;
        background: rgba(28, 31, 38, 0);
        backdrop-filter: blur(4px);
        z-index: 6;

        &.visible {
            display: flex;
        }

        .upload-dialog,
        .download-dialog,
        .delete-dialog {
            width: min(360px, calc(100% - 24px));
            background-color: rgba(21, 24, 30, 0.96);
            border: 1px solid hsl(var(--border));
            border-radius: var(--radius);
            padding: 16px;
            box-shadow:
                rgba(0, 0, 0, 0) 0px 0px 0px 0px,
                rgba(0, 0, 0, 0) 0px 0px 0px 0px,
                rgba(0, 0, 0, 0.5) 0px 25px 50px -12px;

            .title {
                color: hsl(var(--primary));
                font-size: 0.8rem;
                margin-bottom: 8px;
            }

            .file-name {
                color: rgb(189, 219, 209);
                font-size: 0.72rem;
                line-height: 1rem;
                margin-bottom: 10px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }

            .progress-track {
                width: 100%;
                height: 10px;
                border-radius: 999px;
                background-color: hsl(var(--muted));
                overflow: hidden;
                border: 1px solid hsl(var(--border));

                .progress-fill {
                    height: 100%;
                    width: 0;
                    background: linear-gradient(90deg, hsl(var(--primary) / 0.7), hsl(var(--primary)));
                    transition: width 140ms ease;
                }
            }

            .progress-meta {
                margin-top: 8px;
                margin-bottom: 12px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                gap: 10px;
            }

            .progress-speed {
                color: hsl(var(--muted-foreground));
                font-size: 0.75rem;
                font-variant-numeric: tabular-nums;
                line-height: 1.4;
                text-align: left;
            }

            .progress-value {
                color: hsl(var(--muted-foreground));
                font-size: 0.75rem;
                font-variant-numeric: tabular-nums;
                line-height: 1.4;
                text-align: right;
            }

            .cancel {
                margin-top: 14px;
                width: 100%;
                height: 2rem;
                border: 1px solid hsl(var(--border));
                border-radius: calc(var(--radius) - 2px);
                background: hsl(var(--muted));
                color: rgb(189, 219, 209);
                font-size: 0.75rem;
                letter-spacing: 0.03em;
                cursor: pointer;

                &:hover {
                    border-color: hsl(var(--primary));
                    color: hsl(var(--primary));
                }

                &.finished {
                    background-color: hsl(var(--primary));
                    border-color: hsl(var(--primary));
                    color: hsl(var(--primary-foreground));

                    &:hover {
                        background-color: hsl(var(--primary) / 0.9);
                        border-color: hsl(var(--primary) / 0.9);
                        color: hsl(var(--primary-foreground));
                    }
                }
            }

            .message {
                color: rgb(189, 219, 209);
                font-size: 0.74rem;
                line-height: 1rem;
                margin-bottom: 8px;
            }

            .modal-actions {
                margin-top: 14px;
                display: grid;
                grid-template-columns: 1fr 1fr;
                gap: 8px;

                .btn {
                    height: 2rem;
                    border: 1px solid hsl(var(--border));
                    border-radius: calc(var(--radius) - 2px);
                    font-size: 0.75rem;
                    letter-spacing: 0.03em;
                    cursor: pointer;

                    &:disabled {
                        opacity: 0.65;
                        cursor: not-allowed;
                    }
                }

                .btn.secondary {
                    background: hsl(var(--muted));
                    color: rgb(189, 219, 209);

                    &:hover {
                        border-color: hsl(var(--primary));
                        color: hsl(var(--primary));
                    }
                }

                .btn.destructive {
                    background: hsl(var(--destructive));
                    border-color: hsl(var(--destructive));
                    color: white;

                    &:hover {
                        background: hsl(var(--destructive) / 0.9);
                        border-color: hsl(var(--destructive) / 0.9);
                    }
                }
            }

            .delete-loader {
                margin-top: 4px;
                display: flex;
                justify-content: center;

                .spinner {
                    width: 16px;
                    height: 16px;
                    border: 2px solid hsl(var(--muted-foreground) / 0.35);
                    border-top-color: hsl(var(--primary));
                    border-radius: 50%;
                    animation: spin 0.7s linear infinite;
                }
            }
        }
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

:host(.max) {
    height: 100vh;
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
}

@container (max-width: 699px) {
    :host .listing main .content table thead th:nth-child(4),
    :host .listing main .content table tbody td:nth-child(4) {
        display: none;
    }
}

@container (max-width: 635px) {
    :host .listing main .content table thead th:nth-child(3),
    :host .listing main .content table tbody td:nth-child(3) {
        display: none;
    }
}

@container (max-width: 530px) {
    :host .listing main .content table thead th:nth-child(5),
    :host .listing main .content table tbody td:nth-child(5) {
        display: none;
    }

    :host .listing footer .status {
        display: none;
    }
}

@container (max-width: 370px) {
    :host .listing main .content table thead th:nth-child(2),
    :host .listing main .content table tbody td:nth-child(2) {
        display: none;
    }

    :host .listing main .content table thead th:first-child,
    :host .listing main .content table tbody td:first-child {
        width: 100%;
        min-width: 0;
        max-width: none;
    }

    :host .listing main .content table tbody td:first-child .name {
        max-width: 100%;
    }
}

@container (max-width: 295px) {
    :host .listing main .content table tbody td:first-child .name {
        max-width: 120px;
    }
}
