.segments {
    height: 100dvh;
    display: flex;

    aside {
        z-index: 2;
        width: 28ex;
        max-width: 90%;
        height: 100%;
        background-color: #EDE6E1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-between;
        transition: transform .3s cubic-bezier(.16, 1, .3, 1);

        .top {
            padding: 16px 4px 4px 4px;
            position: relative;
            display: flex;
            flex-direction: column;
            gap: 1.5em;
            width: 100%;
            overflow-y: auto;

            .logo {
                display: flex;
                justify-content: center;

                > svg {
                    border-radius: 4px;
                    height: 3em;
                }
            }

            .new-segment {
                display: flex;
                align-items: center;
                justify-content: center;
                width: 100%;
                background-color: #E6DDD5;
                color: var(--dark-text);
                padding: 12px 0;
                border: none;
                font-size: .75em;
                font-weight: 600;
                text-decoration: none;

                &:hover {
                    background-color: var(--beige-light-3);
                }
            }

            .history {
                width: 100%;
                display: flex;
                flex-direction: column;
                gap: 1.5em;

                section {
                    width: 100%;

                    > * {
                        width: 100%;
                    }
                    .history-subcontainer{
                        padding-bottom: 1.5rem;
                    }
                }

                h3 {
                    font-size: .5em;
                    font-weight: 600;
                    text-transform: uppercase;
                    opacity: 60%;
                }

                .history-item {
                    display: block;
                    width: 100%;
                    color: var(--dark-text);
                    text-decoration: none;
                    font-size: .75em;
                    font-weight: 600;
                    padding: 10px 4px;
                    text-align: left;
                    background: none;
                    border: none;
                    text-overflow: ellipsis;
                    overflow: hidden;
                    white-space: nowrap;
                    border-radius: 4px;
                    cursor: pointer;

                    &.selected {
                        background-color: var(--beige-light-3);
                    }

                    &:not(.selected):hover {
                        background-color: #E6DDD5;
                    }
                }
            }
        }
    }

    .mobile-menu {
        position: sticky;
        top: 0;
        display: none;
        justify-content: space-between;
        background: #EDE6E1;
        padding: .5rem;
        z-index: 2;


        > .actions {
            flex-shrink: 0;
        }

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

            button {
                color: var(--dark-text);
                opacity: 60%;
                cursor: pointer;
                background: none;
                border: none;

                svg {
                    height: 2rem;
                }
            }
        }

        .logo {
            display: flex;
            justify-content: right;

            svg {
                border-radius: 4px;
                height: 2rem;
            }
        }
    }

    .main-wrapper {
        position: relative;
        display: flex;
        flex-direction: column;
        width: 100%;
        padding-bottom: 2rem;
    }

    main header .actions, .mobile-menu .actions {
        flex-shrink: 0;
        display: flex;
        gap: .275rem;

        >:nth-child(1) a, >:nth-child(1) button, >a:nth-child(1), >button:nth-child(1) {
            background-color: var(--chocolate);
            border: 2px solid var(--dark-chocolate);
            color: white;

            &:hover {
                background-color: var(--dark-chocolate);
            }
        }

        >:nth-child(2) a, >:nth-child(2) button, >a:nth-child(2), >button:nth-child(2) {
            color: var(--dark-text);
            background-color: rgba(59, 66, 62, 0.1);
            border: 2px solid rgba(59, 66, 62, 0.1);

            &:hover {
                background-color: rgba(59, 66, 62, 0.2);
            }
        }

        a, button {
            display: flex;
            align-self: flex-start;
            gap: .275rem;
            border-radius: 0.2rem;
            cursor: pointer;
            padding: .275rem .5rem;
            text-decoration: none;

            svg {
                height: 1lh;
            }
        }
    }

    main {
        flex-grow: 1;
        width: 100%;
        display: flex;
        justify-content: center;
        overflow-y: auto;

        > .wrapper {
            width: 100%;
            max-width: 80ch;
            padding: 1rem;


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

                .greeting {
                    margin-top: 1rem;
                    font-weight: 600;
                    font-size: var(--lg-text);
                    margin-bottom: .2lh;
                }
            }

            .name-wrapper {
                display: flex;
                gap: .5rem;
                font-weight: 600;
                font-size: var(--lg-text);
                align-items: center;

                .number {
                    opacity: .5;
                }

                .name {
                    position: relative;
                }
            }

            .search-box {
                margin-top: 1rem;
                width: 100%;
                outline: 2px solid var(--beige-light-7);
                border-radius: .375rem;
                background: white;
                overflow: hidden;

                &:has(:focus) {
                    outline: 2px solid var(--beige-light-3);
                }

                form {
                    display: flex;
                    flex-direction: row;

                    .inner-wrapper {
                        width: 100%;
                        padding: 5px;
                    }

                    .inner {
                        position: relative;
                        width: 100%;
                        color: transparent;

                        > * {
                            width: 100%;
                            padding: 2px 8px;
                            box-sizing: border-box;
                            line-height: 1.5em;
                            min-height: 1.2lh;
                            word-break: break-word;
                            white-space: break-spaces;
                            overflow-wrap: break-word;
                            word-wrap: break-word;
                            font-weight: 500;
                        }

                        > textarea {
                            overflow-y: hidden;
                            position: absolute;
                            top: 0;
                            left: 0;
                            height: 100%;
                            z-index: 1;
                            border: none;
                            resize: none;
                            outline: none;
                            background: transparent;
                        }

                    }

                    .search-button {
                        width: unset;
                        display: flex;

                        button {
                            border: none;
                            background: rgba(59, 66, 62, 3%);
                            padding: 0 12px;
                            color: var(--dark-text);
                            height: 100%;
                            width: unset;
                            margin-bottom: 0;
                            cursor: pointer;

                            svg {
                                height: 1lh;
                            }
                        }
                    }
                }

                &.debug {
                    color: black;

                    div {
                        background-color: rgba(60, 210, 255, 0.2);
                        color: red;
                        text-decoration: underline;
                        text-decoration-style: dashed;
                        text-decoration-color: red;
                    }

                    textarea {
                        text-decoration: underline;
                        text-decoration-color: rgba(0, 0, 0, 0.3);
                        background: repeating-linear-gradient(-45deg, rgba(222, 157, 212, 0.2), rgba(222, 157, 212, 0.2) 2px, transparent 2px, transparent 5px) !important;
                    }
                }
            }
        }
    }

    .error {
        flex: 1 1 150px;
        background-color: white;
        padding: 1.5rem;
        border-radius: .375rem;
        border: 1px solid rgb(229 231 235);
        margin-top: 1.0rem;
        text-align: center;
    }

    .empty-segment {
        flex: 1 1 150px;
        background-color: white;
        padding: 1.5rem;
        border-radius: .375rem;
        border: 1px solid rgb(229 231 235);
        margin-top: 1.0rem;
        text-align: center;
    }

    .results {
        margin-top: 0.75rem;

        .summary-cards {
            display: flex;
            gap: 1rem;
            margin-bottom: .75rem;
            flex-wrap: wrap;

            > div {
                flex: 1 1 150px;
                background-color: white;
                padding: 1.5rem;
                border-radius: .375rem;
                border: 1px solid rgb(229 231 235);

                .value {
                    text-align: center;
                    font-size: var(--xl-text);
                    font-weight: 600;
                }

                .label {
                    text-align: center;
                    font-size: var(--xs-text);
                    opacity: 80%;
                    font-weight: 600;
                }

            }
        }


        .top-sellers {
            flex: 1 1 150px;
            background-color: white;
            padding-top: 1.5rem;
            padding-bottom: 1rem;
            margin-top: 1.0rem;
            border-radius: .375rem;

            .header{
                padding-left: 1.5rem;
                font-weight: 600;
                font-size: 1rem;
                margin-bottom: 1lh;
            }

            .table-container{
                overflow-x: auto;
            }

            table {
                width: 100%;
                border-radius: 0.375rem;
            }

            thead {
                background: rgb(244	241	238	);
                border-bottom-width: 1px;
            }
            .quantity-header{
                text-align: end;
            }

            th {
                padding: 0.5rem 1.5rem;
                font-size: var(--xs-text);
                line-height: 1rem;
                font-weight: 600;
                letter-spacing: 0.05em;
                text-align: left;
                /*border-radius: .375rem;*/


            }

            tbody {
                border-top-width: 1px;
                border-color: #E5E7EB;
            }

            tr {
                .quantity{
                    text-align: end;
                    font-family: monospace;
                }
            }

            tbody tr:hover {
                background-color: #F9FAFB;
            }

            td {
                padding: 0.5rem 1.5rem;
                font-size: 0.875rem;
                line-height: 1.25rem;
                color: #374151;
                white-space: nowrap;
            }
        }

        .segment-rules-debug {
            flex: 1 1 150px;
            background-color: white;
            padding: 1.5rem;
            border-radius: .375rem;
            border: 1px solid rgb(229 231 235);
            margin-bottom: 1.0rem;
            font-family: monospace;
            a {
                text-decoration: none;

                &:hover {
                    background-color: #EDE6E1;
                }
            }
            .variable{
                color: #417A95;
            }
            .constant{
                color: #687837;
            }
            .parameter{
                color: #9C2D41;
            }
            .line_reference{
                color: #3B423E;
                font-weight: bold;
            }
            .combinator{
                color: #417A95;
            }
            .segment_rule_header{
                font-weight: bolder;
            }
        }


        .country-breakdown {
            flex: 1 1 150px;
            background-color: white;
            padding: 1.5rem;
            border-radius: .375rem;
            border: 1px solid rgb(229 231 235);

            .header{
                font-weight: 600;
                font-size: 1rem;
                margin-bottom: 1lh;
            }

            .customer_count{
                font-weight: bolder;
            }

            .value{
                text-align: end;
            }

            table {
                width: 100%;
                border-collapse: collapse;

                tr {
                    border: none;

                    &:nth-child(3n) {
                        td:nth-child(2) .line {
                            background-color: rgb(136, 149, 141);
                        }
                    }

                    &:nth-child(3n+1) {
                        td:nth-child(2) .line {
                            background-color: rgb(188, 156, 176);
                        }
                    }

                    &:nth-child(3n+2) {
                        td:nth-child(2) .line {
                            background-color: rgb(250, 207, 154);
                        }
                    }
                }

                td {
                    border: none;
                    padding: .5rem;
                    font-size: var(--md-text);

                    &:first-child {
                        padding-left: 0;
                        white-space: nowrap;
                    }

                    &:last-child {
                        padding-right: 0;
                        white-space: nowrap;
                    }

                    &:nth-child(2) {
                        width: 100%;
                    }
                }

                .line {
                    height: 1rem;
                    background-color: var(--dark-text);
                    opacity: 50%;
                    border-radius: .375rem;
                }
            }
        }

        .total-size {
            margin-top: 0.5rem;
            font-size: 0.875rem;
            line-height: 1.25rem;
            text-align: center;
        }
    }

    strong {
        font-weight: bold;
    }

    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(255, 255, 255, 0.5); /* Semi-opaque white */
        backdrop-filter: blur(2px); /* Optional subtle blur effect */
        z-index: 999;
    }

    .delete-segment-button {
        color: white;
        background-color: var(--chocolate);
        border-radius: 0.2rem;
        border: 2px solid var(--dark-chocolate);
        cursor: pointer;
        width: 100%;
        padding: .5rem;
        margin-top: .5rem;
        margin-bottom: .5rem;

        &:hover {
            background-color: var(--dark-chocolate);
        }
    }

    /* For naming and saving segments */

    .open-save-form-button {
        background-color: var(--chocolate);
        border-radius: 0.2rem;
        border: 2px solid var(--dark-chocolate);
        color: white;
        cursor: pointer;
        width: 100%;
        padding: .5rem;
        margin-top: .5rem;
        margin-bottom: .5rem;

        &:hover {
            background-color: var(--dark-chocolate);
        }
    }

    .pop-up {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: white;
        padding: 2rem;
        border-radius: 8px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        z-index: 1000;
        width: 90%;
        max-width: 600px;
    }

    .pop-up form {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .pop-up .cancel {
        position: absolute;
        top: 15px;
        right: 15px;
        cursor: pointer;
        background: none;
        border: none;
        padding: 5px;
        transition: opacity 0.2s ease;
    }

    .bottom {
        width: 100%;

        .shop-switcher {
            position: relative;
            width: 100%;

            .popup {
                background-color: white;
                position: absolute;
                bottom: 100%;
                left: 0;
                border-radius: .2em;
                width: 100%;
                box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
                border: 1px solid var(--beige-light-5);
                z-index: 2;

                &.hidden {
                    display: none;
                }

                > div {

                    &:not(:last-child) {
                        border-bottom: 1px solid var(--beige-light-5);
                    }

                    a {
                        display: flex;
                        gap: .625em;
                        padding: .8em;
                        font-size: .8em;
                        color: inherit;
                        opacity: .875;
                        text-decoration: none;
                        align-items: center;

                        svg {
                            width: 1em;
                        }

                        &:hover {
                            background-color: var(--beige-light-9);
                            cursor: pointer;
                        }
                    }
                }
            }

            .button {
                display: flex;
                align-items: center;
                justify-content: center;
                gap: .5em;
                padding: 0.75em;
                border-radius: .2em;

                > img {
                    border-radius: 4px;
                }

                &:hover {
                    background-color: var(--beige-light-6);
                    cursor: pointer;
                }

                .shop-name, .user-name {
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    width: 20ex;
                    font-size: .8em;
                }

                .shop-name {
                    font-weight: 600;
                }

                .user-name {
                    opacity: .8;
                }

                .icon-wrapper > svg {
                    height: 20px;
                    width: 20px;
                    opacity: .5;
                }
            }
        }
    }

}

@media (max-width: 500px) {
    body:has(.segments.open) {
        overflow: hidden;
    }

    .segments {
        .mobile-menu {
            display: flex;
        }

        main header .actions {
            display: none;
        }

        &:not(.open) {
            > aside {
                transform: translateX(-100%);
            }
        }

        &:is(.open) {
            .main-wrapper {
                opacity: 20%;

                > * {
                    pointer-events: none;
                }
            }
        }

        aside {
            position: fixed;
            font-size: 18px;
        }
    }
}

@media (hover: hover) and (pointer: fine) {
    .segments {
        .search-button button:hover {
            background: rgba(59, 66, 62, 10%);
        }
    }
}

