/* reset */
/* =========================
   RESET
========================= */

*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    font-family: var(--display-font, Arial, sans-serif);
}

img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
}

button,
input,
textarea,
select {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

ul,
ol {
    list-style: none;
}

/* layout */
/* =========================
   APP
========================= */

.app {
    display: flex;
    flex-direction: column;

    width: 100%;
    height: 100vh;

    background-color: var(--gmail-canvas);
    color: var(--gmail-ink);
}

/* =========================
   WORKSPACE
========================= */

.workspace {
    display: flex;
    flex: 1;
    padding-right: 16px;
    overflow: hidden;
    position: relative;
}

/* =========================
   GENERICS
========================= */
.flip-horizontal {
    transform: scaleX(-1);
}

/* =========================
   PLACEHOLDER STYLING
========================= */

.topbar-left,
.topbar-center,
.topbar-right,
.sidebar-compose,
.sidebar-nav,
.sidebar-labels,
.sidebar-footer,
.mail-categories,
.mail-toolbar,
.email-row,
.mail-footer {
    font-size: calc(14px * var(--text-scale, 1));
    color: #9aa0a6;
}

.sidebar.collapsed~.mailbox {
    margin-left: 72px;
}

/* ─── Topbar ─────────────────────────────────────────────────────── */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    & .icon {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 40px;
        width: 40px;
        border: none;
        border-radius: 50%;
        background-color: transparent;
        stroke: white;
        cursor: pointer;
        transition: background-color 0.22s ease-in-out;
        &:hover {
            background-color: #515151;
        }
        & svg {
            height: 24px;
            width: 24px;
        }
    }
    & .links {
        stroke: none;
        fill: white;
        margin-right: 8px;
    }

    /* ─── Left ───────────────────────────────────────────────────── */

    & .topbar-left {
        display: flex;
        align-items: center;
        height: 100%;
        font-size: 1.6em;
        padding-left: 12px;
        min-width: 256px;
        width: 240px;
        & .menu-toggle {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 48px;
            width: 48px;
            border-radius: 50%;
            &:hover {
                background-color: rgba(232, 234, 237, 0.12);
            }
        }
        & .hamburger {
            display: block;
            height: 18px;
            width: 18px;
            stroke: white;
        }
        & .logo {
            border: none;
            padding: 0;
            background: none;
            font: inherit;
            cursor: pointer;
            &:focus-visible { outline: 2px solid var(--gmail-accent); outline-offset: 4px; border-radius: 4px; }
            display: flex;
            align-items: center;
            gap: 8px;
            & svg {
                height: 28px;
                width: 28px;
                margin-left: 10px;
            }
            & span {
                color: #fff;
            }
        }
    }

    /* ─── Center ─────────────────────────────────────────────────── */

    & .topbar-center {
        display: flex;
        align-items: center;
        flex: 1;
        justify-content: left;
        height: 100%;
        width: 500px;
        position: relative;
        & .searchbar {
            display: flex;
            position: relative;
            align-items: center;
            width: 100%;
            max-width: 720px;
            height: 48px;
            min-height: 48px;
            border-radius: 24px;
            background-color: #474747;
            transition: background-color 0.22s ease-in-out;
            &:focus-within {
                background-color: #fff;
                & .icon {
                    stroke: #5f6368;
                    &:hover {
                        background-color: #fbfbfb;
                    }
                }
                & .searchbox {
                    color: #000;
                    &::placeholder {
                        color: #5f6368;
                    }
                }
            }
            & .searchbox {
                background-color: transparent;
                display: block;
                flex: 1;
                height: 24px;
                border: none;
                outline: none;
                color: white;
                font-size: calc(16px * var(--text-scale, 1));
                &::placeholder {
                    color: white;
                }
            }
            & .magnifying-glass {
                margin: 0 7px;
                & svg {
                    height: 18px;
                    width: 18px;
                }
            }
            & .settings {
                margin: 0 9px 0 5px;
                & svg {
                    height: 18px;
                    width: 18px;
                }
            }
        }
    }

    /* ─── Right ──────────────────────────────────────────────────── */

    & .topbar-right {
        display: flex;
        align-items: center;
        width: fit-content;
        padding-right: 14px;
        & .profile {
            cursor: default;
            & img {
                height: 32px;
                width: 32px;
                border-radius: 50%;
            }
        }
        & .icon.info svg {
            height: 20px;
            width: 20px;
        }
    }
}

.sidebar {
    --sidebar-delay: 0.5s;
    --expand: 0.2s ease var(--sidebar-delay);
    --retract: 0.2s ease;
    --text-reveal: 0.15s ease calc(var(--sidebar-delay) + 0.08s);
    display: flex;
    flex-direction: column;
    width: 256px;
    transition: width 0.2s ease;
    overflow: hidden;
    & .compose {
        margin: 8px 8px 16px;
        & .button {
            display: flex;
            align-items: center;
            border: none;
            height: 56px;
            width: 142px;
            border-radius: 16px;
            padding-right: 24px;
            & .icon {
                flex-shrink: 0;
                height: 18px;
                width: 18px;
                margin: 0 12px 0 18px;
                stroke: #5f6368;
                fill: none;
            }
        }
    }
    & .nav {
        display: flex;
        flex-direction: column;
        width: 256px;
        height: fit-content;
        & .link {
            display: flex;
            align-items: center;
            width: 240px;
            height: 32px;
            border-radius: 0 50px 50px 0;
            padding: 0 12px 0 20px;
            cursor: pointer;
            &:hover {
                background-color: #414141;
            }
            &.active {
                background-color: #595959;
            }
            &.toggle svg {
                fill: #ccc;
            }
            & .icon {
                display: block;
                flex-shrink: 0;
                fill: #ccc;
                height: 14px;
                width: 14px;
                margin: 0 8px;
            }
            & .title {
                flex: 1;
                white-space: nowrap;
                font-size: calc(14px * var(--text-scale, 1));
                margin-left: 8px;
                font-family: var(--display-font, "Google Sans", Roboto, RobotoDraft, Helvetica, Arial, sans-serif);
                font-weight: 700;
            }
            & .unread-count {
                font-size: calc(12px * var(--text-scale, 1));
                font-weight: bold;
            }
        }
    }
}
.sidebar.collapsed {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    width: 72px;
    background-color: #000;
    transition: width var(--retract);
    & .compose .button {
        width: 56px;
        padding-right: 0;
        transition: width var(--retract), padding var(--retract);
    }
    & .nav .link {
        width: 56px;
        transition: width var(--retract);
    }

}
.sidebar.collapsed:is(:hover, :has(:focus-visible)) {
    width: 256px;
    transition: width var(--expand);
    & .compose .button {
        width: 142px;
        padding-right: 24px;
        transition: width var(--expand), padding var(--expand);
    }
    & .nav .link {
        width: 240px;
        transition: width var(--expand);
    }

}

/* Every sidebar label follows one reveal timeline while the panel clips content to its current width. */
@media (width >= 800px) {
    .sidebar :is(.nav .title, .unread-count, .compose .button span, .labels-heading h2, .labels-heading button,
        .label-filter > span, .label-filter small, .label-clear) { opacity: 1; transition: opacity 0.15s ease; }
    .sidebar.collapsed :is(.nav .title, .unread-count, .compose .button span, .labels-heading h2, .labels-heading button,
        .label-filter > span, .label-filter small, .label-clear) { opacity: 0; }
    .sidebar.collapsed:is(:hover, :has(:focus-visible)) :is(.nav .title, .unread-count, .compose .button span,
        .labels-heading h2, .labels-heading button, .label-filter > span, .label-filter small, .label-clear) {
        opacity: 1; transition: opacity var(--text-reveal);
    }
}

.topbar .topbar-center {
    min-width: 0;
    .searchbar {
        .magnifying-glass { color: #ccc; }
        .settings svg { stroke-width: 8px; }
        .searchbox { min-width: 0; width: 0; }
        .search-clear { flex-shrink: 0; color: #e8eaed; font-size: calc(24px * var(--text-scale, 1)); &[hidden] { display: none; } }
        &:focus-within .search-clear { color: #5f6368; }
        &:focus-within .magnifying-glass { color: #5f6368; }
        button:focus-visible { outline: 2px solid #8ab4f8; outline-offset: -3px; }
    }
}
.search-options {
    position: absolute;
    top: 60px;
    left: 0;
    z-index: 20;
    width: min(100%, 720px);
    max-height: calc(100dvh - 80px);
    overflow-y: auto;
    padding: 16px 20px;
    border: 1px solid #dadce0;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 4px 18px #0005;
    color: #202124;
    font: 14px Arial, Helvetica, sans-serif;
    &[hidden] { display: none; }
    .search-options-header { display: flex; align-items: center; justify-content: space-between; }
    h2 { font-size: calc(16px * var(--text-scale, 1)); font-weight: 500; }
    .search-options-close { width: 28px; height: 28px; border: none; border-radius: 50%; background: none;
        font-size: calc(24px * var(--text-scale, 1)); cursor: pointer;
        &:hover { background: #f1f3f4; } }
    .search-scope, .search-help { margin: 6px 0 12px; font-size: calc(12px * var(--text-scale, 1)); line-height: 1.5; color: #5f6368; }
    label { display: block; margin-bottom: 10px; }
    input:not([type="checkbox"]), select {
        display: block;
        width: 100%;
        height: 32px;
        margin-top: 4px;
        padding: 4px 8px;
        border: 1px solid #dadce0;
        border-radius: 4px;
        background: #ffffff;
        color: #202124;
    }
    .search-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .search-photo { display: flex; align-items: center; gap: 8px; margin-top: 22px; }
    .search-options-error { color: #b3261e; &:not(:empty) { margin-bottom: 10px; } }
    .search-apply { padding: 8px 24px; border: none; border-radius: 20px; background: #0b57d0; color: #ffffff; cursor: pointer;
        &:hover { background: #0842a0; } }
    button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #1a73e8; outline-offset: 2px; }
}
.search-status {
    flex-shrink: 0;
    padding: 8px 16px;
    color: #bdc1c6;
    font-size: calc(13px * var(--text-scale, 1));
    &[hidden] { display: none; }
    &.search-error { color: #f2b8b5; }
}
.search-empty { padding: 24px 16px; color: #bdc1c6; font-size: calc(14px * var(--text-scale, 1)); }

@media (max-width: 800px) {
    .topbar .topbar-left { min-width: 72px; width: 72px; flex-shrink: 0; .logo { display: none; } }
    .topbar .topbar-right .links { display: none; }
    .search-options { position: fixed; top: 64px; left: 8px; right: 8px; width: auto; }
}
