/* mailbox shell */
.mailbox {
    display: flex; flex-direction: column; position: relative; width: 100%;
    background-color: var(--gmail-surface); border-radius: 16px; flex: 1; overflow: hidden;
    min-width: 330px; margin-bottom: 16px; transition: opacity 150ms ease-out;

    &.hidden {
        opacity: 0; pointer-events: none;
    }
}

/* tray */
.mailbox .tray {
    display: flex; flex-direction: column; flex: 1; min-height: 0;

    &.hidden {
        display: none;
    }
}

/* category tabs */
.mailbox .mail-categories {
    display: flex; justify-content: left; align-items: center; height: fit-content; cursor: pointer;

    .tab {
        display: flex; align-items: center; position: relative; width: 100%; height: 56px;
        min-width: 126px; max-width: 253px;
        font-family: var(--display-font, "Google Sans", Roboto, RobotoDraft, Helvetica, Arial, sans-serif);
        font-weight: 500; font-size: calc(14px * var(--text-scale, 1)); line-height: 16px;
        color: #fff;

        &:hover {
            background-color: #454545;
        }

        &.active::before {
            content: ""; position: absolute; bottom: 0; left: 0; right: 0; height: 3px; width: 94%;
            background-color: white; transform: translateX(3%); border-top-left-radius: 3px;
            border-top-right-radius: 3px;
        }

        .icon {
            height: 14px; width: 14px; margin: 0 18px;

            svg {
                height: 14px; width: 14px;
            }
        }
    }
}

/* email list */
.mailbox .email-list {
    display: flex; flex: 1; flex-direction: column; min-height: 0; gap: 1px; overflow-y: auto;
    padding-right: 16px; container-type: inline-size;

    .email {
        display: flex; height: 40px; cursor: pointer; align-items: center; overflow: hidden;
        background-color: #161616;

        &:hover {
            box-shadow:
                0 -1px 0 rgba(255, 255, 255, .2),
                0 1px 0 rgba(255, 255, 255, .2),
                0 0 4px rgba(95, 99, 104, .6),
                0 0 6px 2px rgba(95, 99, 104, .6);
        }

        .icon {
            display: flex; align-items: center; justify-content: center; flex-shrink: 0;
            height: 40px; width: 40px;

            svg {
                fill: #ccc; height: 14px; width: 14px;
            }

            &.star {
                svg {
                    fill: #ccc;
                }

                svg.active {
                    display: none;
                }

                &.starred {
                    svg.active {
                        display: block; fill: gold;
                    }

                    svg.inactive {
                        display: none;
                    }
                }
            }
        }

        .name {
            flex-shrink: 0; font-size: calc(14px * var(--text-scale, 1)); width: 173px;
            height: 20px;
        }

        .title-summary {
            display: flex; flex: 1; min-width: 0; overflow: hidden;
        }

        .title {
            flex-shrink: 0; color: #bbb; font-size: calc(14px * var(--text-scale, 1));
        }

        .summary {
            flex: 1; min-width: 0; color: #888; overflow: hidden; text-overflow: ellipsis;
            white-space: nowrap;

            &::before {
                content: "\00a0-\00a0";
            }
        }

        .timestamp {
            flex-shrink: 0; min-width: fit-content; color: #888; margin-right: 10px;
            font-family: var(--display-font, "Google Sans", Roboto, RobotoDraft, Helvetica, Arial, sans-serif);
            font-size: calc(12px * var(--text-scale, 1));
        }
    }
}

/* email row, narrow container */
@container (max-width: 512px) {
    .mailbox .email-list .email {
        display: grid; height: auto; grid-template-columns: 30px 1fr 40px;
        grid-template-areas:
            "checkbox  name      timestamp"
            ".         title     .        "
            ".         summary   star     ";
        align-items: center; padding: 10px;

        .checkbox {
            grid-area: checkbox; height: 20px; width: 20px;
        }

        .star {
            grid-area: star; height: 20px; width: 20px; justify-self: right; fill: #ccc;
        }

        .name {
            grid-area: name; width: auto;
        }

        .title-summary {
            display: contents;
        }

        .title,
        .summary {
            overflow: hidden; white-space: nowrap; text-overflow: ellipsis; height: 20px;
        }

        .title {
            grid-area: title;
        }

        .summary {
            grid-area: summary;

            &::before {
                content: "";
            }
        }

        .timestamp {
            grid-area: timestamp; margin: 0; justify-self: end;
        }
    }
}

/* footer */
.mailbox .footer {
    display: flex; justify-content: space-between; align-items: center; margin: 12px 16px;
    min-width: 500px;

    .reading-progress {
        display: flex; flex-direction: column; width: fit-content; padding: 0;
        border: none; background: transparent; color: var(--gmail-muted); text-align: left; font: inherit; cursor: pointer;
        &:disabled { cursor: default; }
        &:focus-visible { outline: 2px solid var(--gmail-accent); outline-offset: 4px; border-radius: 3px; }
        &:hover:not(:disabled) .text { text-decoration: underline; }
        .bar {
            display: block; background: var(--gmail-line); height: 6px; min-width: 160px; width: 100%;
            border-radius: 3px; margin: 7px 0;
            .usage { display: block; background: var(--gmail-accent); width: 0; height: 100%; border-radius: inherit; }
        }
        .text { min-height: 20px; font-size: calc(12px * var(--text-scale, 1)); }
    }

    .disclaimer,
    .activity {
        width: fit-content; height: 20px;

        span {
            color: #bbb; font-size: calc(12px * var(--text-scale, 1));
            font-family: var(--display-font, "Google Sans", Roboto, RobotoDraft, Helvetica, Arial, sans-serif);
        }
    }

    .disclaimer {
        display: flex; flex-direction: column; justify-content: center; align-items: center;
    }
}

/* Public links retain the existing mailbox typography and SPA navigation. */
.mail-categories a.tab, .email-list a.title { color: inherit; text-decoration: none; }
.email-list a.title:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.public-archive[hidden] { display: none; }

/* TOP BAR */
.mailbox .top-bar {
    display: flex; justify-content: space-between; height: 48px; align-items: center;
    padding: 0 8px;

    .option-group {
        display: flex; align-items: center; position: relative;

        .bulk-select {
            display: flex; align-items: center; justify-content: center; height: 40px;
            padding: 0 10px; gap: 9px; border: none; background: none; cursor: pointer;

            .box {
                height: 14px; width: 14px; fill: #ccc;
            }

            .arrow {
                height: 8px; width: 8px; fill: #ccc;
            }
        }

        .options {
            display: flex; align-items: center;
            transition:
                opacity 120ms ease-out,
                transform 120ms ease-out;

            &.unselected {
                opacity: 1; pointer-events: auto;
            }

            &.selected {
                position: absolute; left: 48px; opacity: 0; pointer-events: none;
            }

            .option {
                display: flex; align-items: center; justify-content: center; height: 40px;
                border: none; background: none; cursor: pointer;

                svg {
                    height: 14px; width: 14px; fill: #ccc;
                }

                &.square {
                    width: 40px;

                    &:active {
                        border: 1px solid white; border-radius: 50%;
                    }
                }

                &.rect {
                    padding: 0 10px; width: fit-content; border: 1px solid transparent;

                    &:active {
                        border: 1px solid white; border-radius: 5px;
                    }
                }

                &.other svg {
                    height: 15px; width: 15px;
                }

                &.message-count {
                    width: fit-content; font-size: calc(12px * var(--text-scale, 1)); color: #ccc;
                    font-family: var(--display-font, 'Google Sans', Roboto, RobotoDraft, Helvetica, Arial, sans-serif);
                    line-height: 12px;
                }

                &.page {
                    width: 40px; border-radius: 50%;

                    svg {
                        height: 9px; width: 9px; fill: #6c6c6c;
                    }

                    &.active svg {
                        fill: #c0c0c0;
                    }

                    &:hover svg {
                        fill: #fff;
                    }

                    &.prev {
                        transform: rotateZ(90deg);
                    }

                    &.next {
                        transform: rotateZ(270deg);
                    }
                }
            }

            .more-menu {
                position: absolute; top: 40px; left: 40px; z-index: 10; width: 256px;
                padding: 4px 0; border-radius: 4px; background: #fff;
                box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); opacity: 1; transform: translateY(0);
                transition:
                    opacity 100ms ease-out,
                    transform 100ms ease-out;

                &.hidden {
                    opacity: 0; transform: translateY(-4px); pointer-events: none;
                }

                .more-menu-options.selected {
                    display: none;
                }

                &.has-selection {
                    .options.unselected {
                        opacity: 0; pointer-events: none;
                    }

                    .options.selected {
                        opacity: 1; pointer-events: auto;
                    }

                    .more-menu-options.unselected {
                        display: none;
                    }

                    .more-menu-options.selected {
                        display: flex;
                    }
                }

                .more-menu-item {
                    display: flex; align-items: center; gap: 14px; width: 100%; padding: 8px 16px;
                    border: none; background: none;
                    font-family: var(--display-font, 'Google Sans', Roboto, RobotoDraft, Helvetica, Arial, sans-serif);
                    font-size: calc(14px * var(--text-scale, 1)); color: #202124; cursor: pointer;

                    svg {
                        height: 16px; width: 16px;
                    }

                    button {
                        background-color: transparent; border: none;
                        font-size: calc(14px * var(--text-scale, 1)); line-height: 16px;
                    }

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

    &.has-selection {
        .options.unselected {
            opacity: 0; pointer-events: none;
        }

        .options.selected {
            opacity: 1; pointer-events: auto;
        }
    }
}
