.app-shell {
    display: grid;
    grid-template-columns: var(--elev-sidebar-collapsed-width) minmax(0, 1fr);
    min-height: 100vh;
    min-height: 100dvh;
    background: #fff;
    transition: grid-template-columns 0.1s ease;
}

.app-shell:has(.sidebar:hover),
.app-shell:has(.sidebar:focus-within) {
    grid-template-columns: var(--elev-sidebar-width) minmax(0, 1fr);
}

.app-shell__main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    align-self: start;
    gap: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    padding: 0 1.25rem 0;
    background: var(--elev-bg-white-card);
    border: 0;
    overflow: hidden;
    transition: align-items 0.1s ease, border-radius 0.1s ease;
    z-index: 10;
}

.sidebar:hover,
.sidebar:focus-within {
    align-items: flex-start;
    /* Top-right only — flush with the bottom edge, like .app-shell__content. */
    border-radius: 0 1.25rem 0 0;
}

.brand-mark {
    position: relative;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 3.25rem;
    height: var(--elev-topbar-height);
    padding: 0;
    border: 0;
    background: transparent;
    text-decoration: none;
    transition: width 0.1s ease;
}

.sidebar:hover .brand-mark,
.sidebar:focus-within .brand-mark {
    justify-content: flex-start;
    width: 11.25rem;
    height: var(--elev-topbar-height);
}

.sidebar-logo {
    display: block;
    object-fit: contain;
    object-position: left center;
    transition: opacity 0.1s ease, transform 0.1s ease;
}

.sidebar-logo-full {
    position: absolute;
    left: 0;
    width: 8.7rem;
    height: 2.4rem;
    opacity: 0;
    transform: translateX(-0.5rem);
}

.sidebar-logo-icon {
    width: 3.25rem;
    height: 2.412rem;
    opacity: 1;
}

.sidebar:hover .sidebar-logo-full,
.sidebar:focus-within .sidebar-logo-full {
    opacity: 1;
    transform: translateX(0);
}

.sidebar:hover .sidebar-logo-icon,
.sidebar:focus-within .sidebar-logo-icon {
    opacity: 0;
    transform: scale(0.86);
}

.sidebar-nav {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    width: 3.25rem;
    min-height: 0;
    padding: 0.25rem;
    margin: 0;
    /* Top rounded only — bottom flush with the viewport edge. */
    border-radius: var(--elev-radius-pill) var(--elev-radius-pill) 0 0;
    background: var(--elev-bg-pale);
    /* Clip children to the radius so the scrollbar never sits outside. */
    overflow: hidden;
    transition: width 0.1s ease, border-radius 0.1s ease;
}

.sidebar:hover .sidebar-nav,
.sidebar:focus-within .sidebar-nav {
    width: 100%;
    border-radius: 1.25rem 1.25rem 0 0;
}

.sidebar-nav__menu {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    min-height: 0;
    padding-bottom: 0.75rem;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* Collapsed / mid-transition: scroll without chrome. */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar-nav__menu::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.sidebar-nav__menu::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: transparent;
}

.sidebar-nav__menu::-webkit-scrollbar-track {
    background: transparent;
}

/* Reveal scrollbar after expand settles (delay independent of width speed). */
.sidebar:hover .sidebar-nav__menu,
.sidebar:focus-within .sidebar-nav__menu {
    animation: elev-sidebar-scrollbar-in 0s linear 0.24s forwards;
}

.sidebar:hover .sidebar-nav__menu::-webkit-scrollbar,
.sidebar:focus-within .sidebar-nav__menu::-webkit-scrollbar {
    animation: elev-sidebar-scrollbar-webkit-in 0s linear 0.24s forwards;
}

.sidebar:hover .sidebar-nav__menu::-webkit-scrollbar-thumb,
.sidebar:focus-within .sidebar-nav__menu::-webkit-scrollbar-thumb {
    animation: elev-sidebar-scrollbar-thumb-in 0s linear 0.24s forwards;
}

.sidebar:hover .sidebar-nav__menu::-webkit-scrollbar-track,
.sidebar:focus-within .sidebar-nav__menu::-webkit-scrollbar-track {
    margin-block-start: 0.85rem;
    margin-block-end: 0;
}

@keyframes elev-sidebar-scrollbar-in {
    to {
        scrollbar-width: thin;
        scrollbar-color: rgba(10, 13, 18, 0.12) transparent;
    }
}

@keyframes elev-sidebar-scrollbar-webkit-in {
    to {
        width: 0.25rem;
    }
}

@keyframes elev-sidebar-scrollbar-thumb-in {
    to {
        background: rgba(10, 13, 18, 0.12);
    }
}

.nav-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 100%;
    min-height: 2.75rem;
    padding: 0;
    border: 0;
    border-radius: var(--elev-radius-pill);
    color: var(--elev-text-bold);
    font-family: var(--elev-font-sans);
    font-size: var(--elev-text-md-size);
    font-weight: 500;
    line-height: var(--elev-text-md-line);
    text-decoration: none;
    background: transparent;
    cursor: pointer;
    outline: 0;
    transition: background 0.18s ease, color 0.18s ease;
}

.sidebar:hover .nav-item,
.sidebar:focus-within .nav-item {
    justify-content: flex-start;
    gap: 0.5rem;
}

.nav-item.active {
    color: var(--elev-text-bold);
    font-weight: 500;
    background: transparent;
}

.nav-item:hover,
.nav-item:focus-visible {
    background: #fff;
    color: var(--elev-text-bold);
    text-decoration: none;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon,
.nav-item:focus-visible .nav-icon {
    color: #fff;
    background: var(--elev-primary);
}

.nav-item.active .nav-label {
    font-weight: 500;
}

.nav-icon {
    display: grid;
    place-items: center;
    /* Slightly under the 2.75rem content slot so overflow:hidden on .sidebar-nav
       does not clip the active/hover disc (esp. with subpixel rounding). */
    width: 2.5rem;
    height: 2.5rem;
    flex: 0 0 2.5rem;
    border-radius: var(--elev-radius-pill);
    color: var(--elev-text-bold);
    background: var(--elev-bg-pale);
    transition: background 0.18s ease, color 0.18s ease;
}

.nav-icon .mud-icon-root {
    font-size: 1.25rem;
}

.nav-label {
    max-width: 0;
    overflow: hidden;
    opacity: 0;
    white-space: nowrap;
    font-weight: 500;
    transform: translateX(-0.375rem);
    /* max-width snaps — width reveal is driven only by .sidebar-nav */
    transition: opacity 0.1s ease, transform 0.1s ease;
}

.sidebar:hover .nav-label,
.sidebar:focus-within .nav-label {
    max-width: 13.75rem;
    opacity: 1;
    transform: translateX(0);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: var(--elev-topbar-height);
    min-height: var(--elev-topbar-height);
    padding: 0.875rem 1.5rem 0.875rem 0;
    background: #fff;
    border: 0;
}

.topbar-menu-button {
    display: none;
    flex: 0 0 auto;
    place-items: center;
    box-sizing: border-box;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 0;
    border-radius: var(--elev-radius-pill);
    color: var(--elev-text-bold);
    background: var(--elev-surface);
    cursor: pointer;
    box-shadow: none;
}

.topbar-menu-button:hover,
.topbar-menu-button:focus-visible {
    background: var(--elev-bg-pale);
}

.topbar-menu-button .mud-icon-root,
.topbar-menu-button svg {
    display: block;
    font-size: 1.25rem;
}

.topbar-menu-button__open,
.topbar-menu-button__close {
    display: inline-grid;
    place-items: center;
}

.topbar-menu-button__close {
    display: none;
}

.app-nav-toggle {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sidebar-backdrop {
    display: none;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.global-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: min(25rem, 100%);
    height: 3.25rem;
    padding: 0 1.25rem;
    border-radius: var(--elev-radius-pill);
    color: var(--elev-text-sheen);
    background: var(--elev-bg-pale);
    font-family: var(--elev-font-sans);
    font-size: var(--elev-text-sm-size);
    font-weight: 500;
    line-height: 1.3;
}

.global-search__icon {
    flex: 0 0 auto;
    color: var(--elev-text-sheen);
}

.global-search__input {
    width: 100%;
    min-width: 0;
    border: 0;
    color: var(--elev-foreground);
    background: transparent;
    font-family: var(--elev-font-sans);
    font-size: var(--elev-text-sm-size);
    font-weight: 500;
    outline: none;
}

.global-search__input::placeholder {
    color: var(--elev-text-sheen);
}

.global-search__suggestions {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    z-index: 40;
    margin: 0;
    padding: 0.5rem;
    list-style: none;
    border-radius: var(--elev-radius-lg, 1rem);
    background: var(--elev-surface, #fff);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
    text-align: left;
}

.global-search__suggestions > li {
    display: block;
    width: 100%;
}

.global-search__suggestion {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 0;
    border-radius: 0.75rem;
    color: var(--elev-foreground);
    background: transparent;
    font: inherit;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}

.global-search__suggestion:hover,
.global-search__suggestion.is-active {
    background: var(--elev-surface-strong);
}

.global-search__suggestion-icon {
    flex: 0 0 auto;
    margin: 0;
    color: var(--elev-text-sheen);
}

.global-search__suggestion-icon.mud-icon-root {
    margin: 0;
}

.global-search__suggestion-label {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
}

.global-search--compact {
    width: min(11rem, 42vw);
    height: 2.5rem;
    padding: 0 0.75rem;
    gap: 0.5rem;
}

.global-search--compact .global-search__icon {
    display: none;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 0 0 auto;
}

.company-context {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.company-context--logo-only {
    gap: 0;
}

.company-context__logo--placeholder {
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--elev-bg-pale);
    color: var(--elev-foreground);
    font-weight: 700;
    text-transform: uppercase;
}

.company-context__logo {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 6.25rem;
    max-height: 3.125rem;
    overflow: hidden;
    flex: 0 0 auto;
}

.company-context__logo-img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 3.125rem;
    object-fit: contain;
}

.company-context__text {
    display: grid;
    gap: 0.125rem;
    min-width: 0;
}

.company-context__name {
    font-family: var(--elev-font-sans);
    font-size: var(--elev-text-md-size);
    font-weight: 600;
    line-height: var(--elev-text-md-line);
    color: var(--elev-foreground);
}

.company-context__branch {
    font-family: var(--elev-font-sans);
    font-size: var(--elev-text-sm-size);
    line-height: var(--elev-text-sm-line);
    color: var(--elev-muted);
}

.profile-text__name,
.profile-text__role {
    font-family: var(--elev-font-sans);
}

.topbar:has(.profile-menu-shell.is-open) {
    z-index: 100;
}

/* Profile menu open must not drop below in-shell detail dialogs
   (.topbar:has(.is-open) is more specific than body:has(.dialog) .topbar). */
body:has(.customer-detail-dialog) .topbar:has(.profile-menu-shell.is-open),
body:has(.service-order-detail-dialog) .topbar:has(.profile-menu-shell.is-open) {
    z-index: calc(var(--mud-zindex-dialog, 1400) + 20);
}

.profile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 99;
    background: transparent;
}

.profile-menu-shell {
    position: relative;
}

.profile-menu-shell.is-open {
    z-index: 100;
}

.profile-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0;
    border: 0;
    color: var(--elev-text-bold);
    background: transparent;
    font-family: var(--elev-font-sans);
    cursor: pointer;
}

.profile-photo {
    flex: 0 0 auto;
    width: 3rem;
    height: 3rem;
    font-size: 1rem;
    font-weight: 700;
}

.profile-photo.mud-avatar {
    width: 3rem;
    height: 3rem;
    font-size: 1rem;
}

.profile-text {
    display: grid;
    gap: 0.25rem;
    padding-right: 0.75rem;
    white-space: nowrap;
    text-align: left;
}

.profile-text__name {
    font-size: var(--elev-text-sm-size);
    font-weight: 600;
    line-height: var(--elev-text-sm-line);
    color: var(--elev-foreground);
}

.profile-text__role {
    font-size: var(--elev-text-sm-size);
    line-height: var(--elev-text-sm-line);
    color: var(--elev-muted);
}

.profile-menu__chevron {
    color: var(--elev-muted);
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 0.75rem);
    right: 0;
    z-index: 90;
    display: grid;
    min-width: 14.375rem;
    padding: 0.5rem;
    border: 1px solid var(--elev-border);
    border-radius: var(--elev-radius);
    background: #fff;
    box-shadow: 0 16px 36px rgba(10, 13, 18, 0.14);
}

.profile-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.625rem;
    width: 100%;
    min-height: 2.625rem;
    padding: 0.625rem 0.75rem;
    border: 0;
    border-radius: 0.625rem;
    color: var(--elev-foreground);
    background: #fff;
    font-family: var(--elev-font-sans);
    font-size: var(--elev-text-sm-size);
    font-weight: 600;
    line-height: var(--elev-text-sm-line);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    box-sizing: border-box;
}

.profile-dropdown-item:hover {
    background: var(--elev-surface-strong);
}

.profile-dropdown-item.is-active {
    color: var(--elev-primary);
    background: var(--elev-primary-soft);
}

.profile-dropdown-submenu {
    display: grid;
}

.profile-dropdown-item--parent.is-open {
    background: var(--elev-surface-strong);
}

.profile-dropdown-item__icon {
    flex: 0 0 auto;
    color: var(--elev-muted);
}

.profile-dropdown-item .profile-dropdown-item__icon.mud-icon-root {
    width: 1.25rem;
    height: 1.25rem;
    font-size: 1.25rem;
}

.profile-dropdown-item__chevron {
    margin-left: auto;
    flex: 0 0 auto;
    color: var(--elev-muted);
}

.profile-dropdown-submenu__items {
    display: grid;
    gap: 0.125rem;
    padding: 0.125rem 0;
}

.profile-dropdown-item--child {
    font-weight: 500;
    justify-content: flex-start;
}

.profile-dropdown-item__flag {
    flex: 0 0 auto;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    object-fit: cover;
}

.language-dropdown {
    min-width: 11rem;
}

.language-dropdown__flag {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    object-fit: cover;
}

.app-shell__main {
    background: #fff;
}

.app-shell__content {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    display: grid;
    align-content: start;
    gap: 0;
    padding: 1.25rem !important;
    border-radius: 1.25rem 0 0;
    background: var(--elev-bg-pale);
}

@media (max-width: 960px) {
    :root {
        /* Keep dialog/shell offsets in sync with the compact mobile topbar. */
        --elev-topbar-height: 4rem;
    }

    .app-shell {
        grid-template-columns: minmax(0, 1fr);
    }

    .app-shell:has(.sidebar:hover),
    .app-shell:has(.sidebar:focus-within) {
        grid-template-columns: minmax(0, 1fr);
    }

    .topbar {
        box-sizing: border-box;
        height: var(--elev-topbar-height);
        min-height: var(--elev-topbar-height);
        padding: 0.75rem;
        flex-wrap: nowrap;
        gap: 0.5rem;
    }

    .topbar-menu-button {
        display: inline-grid;
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 70;
        border: 0;
        padding: 0;
        margin: 0;
        background: rgba(10, 13, 18, 0.42);
        opacity: 0;
        pointer-events: none;
        cursor: pointer;
        transition: opacity 0.22s ease;
    }

    .app-shell:has(.app-nav-toggle:checked) .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .app-shell:has(.app-nav-toggle:checked) .topbar-menu-button__open {
        display: none;
    }

    .app-shell:has(.app-nav-toggle:checked) .topbar-menu-button__close {
        display: inline-grid;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 80;
        align-items: flex-start;
        align-self: auto;
        width: min(20rem, 86vw);
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        min-height: 0;
        padding: 0 1.25rem 1.25rem;
        border-radius: 0 1.25rem 1.25rem 0;
        overflow: hidden;
        transform: translateX(-105%);
        transition: transform 0.24s ease;
        box-shadow: none;
    }

    .app-shell:has(.app-nav-toggle:checked) .sidebar {
        transform: translateX(0);
        box-shadow: 12px 0 40px rgba(10, 13, 18, 0.18);
    }

    /* Always expanded chrome while the drawer is the mobile nav surface */
    .sidebar .brand-mark {
        justify-content: flex-start;
        width: 11.25rem;
        height: var(--elev-topbar-height);
    }

    .sidebar .sidebar-logo-full {
        opacity: 1;
        transform: translateX(0);
    }

    .sidebar .sidebar-logo-icon {
        opacity: 0;
        transform: scale(0.86);
    }

    .sidebar .sidebar-nav {
        width: 100%;
        max-width: 100%;
        border-radius: 1.25rem 1.25rem 0 0;
    }

    .sidebar .nav-item {
        justify-content: flex-start;
        gap: 0.5rem;
    }

    .sidebar .nav-label {
        max-width: 13.75rem;
        opacity: 1;
        transform: translateX(0);
    }

    .global-search,
    .global-search--compact {
        width: min(11rem, 42vw);
        flex: 1 1 auto;
        min-width: 0;
        height: 2.5rem;
        padding: 0 0.75rem;
        gap: 0.5rem;
    }

    .global-search__icon {
        display: none;
    }

    .topbar-actions {
        flex: 0 0 auto;
        width: auto;
        justify-content: flex-end;
        gap: 0.5rem;
    }

    .company-context__text {
        display: none;
    }

    .app-shell__content {
        padding: 1rem !important;
        border-radius: 1rem 0 0;
    }

    body:has(.app-shell .app-nav-toggle:checked) {
        overflow: hidden;
    }
}
