/* App shell of the signed-in platform sites (Components/AppShell.razor), used by the MainLayout of WebbuilderWeb and
   WebbuilderClientArea. The ml- prefix is the shell's ("main layout"); a site's own parts inside the shell (such as
   WebbuilderWeb's sidebar plan card) keep the prefix and live in that site's CSS.
   Desktop (1200px and up): fixed sidebar, which the site can start as a narrow icon rail on some pages.
   Tablet and mobile: the sidebar is a drawer opened from the top bar. */

/* =========
     shell
   ========= */

.ml-shell {
    --ml-sidebar-width: 272px;
    --ml-rail-width: 88px;
    --ml-topbar-height: 72px;
    --ml-content-gutter: 32px;

    min-height: 100vh;
    min-height: 100dvh;
    background:
        radial-gradient(48% 40% at 100% 0%, rgba(118, 61, 232, 0.07), transparent 70%),
        radial-gradient(40% 36% at 30% 100%, rgba(255, 183, 165, 0.1), transparent 70%),
        var(--app-bg-soft);
    background-attachment: fixed;
    color: var(--app-text);
    /* Hidden pop-ups (closed menus, lists) never stretch the page past the shell into a band without the background.
       clip, unlike hidden, keeps the sticky sidebar and top bar working. */
    overflow: clip;
}

[data-theme="dark"] .ml-shell {
    background:
        radial-gradient(48% 40% at 100% 0%, rgba(156, 116, 255, 0.1), transparent 70%),
        radial-gradient(40% 36% at 30% 100%, rgba(255, 183, 165, 0.05), transparent 70%),
        var(--app-bg);
    background-attachment: fixed;
}

.ml-main {
    min-width: 0;
    margin-left: var(--ml-sidebar-width);
    transition: margin-left 0.4s var(--app-ease-out);
}

.ml-rail .ml-main {
    margin-left: var(--ml-rail-width);
}

/* The page behind an open drawer does not scroll */
html:has(.ml-drawer-open) {
    overflow: hidden;
}

/* =========
     shell
   ========= */


/* ===========
     sidebar
   =========== */

.ml-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    width: var(--ml-sidebar-width);
    border-right: 1px solid var(--app-line);
    background: var(--app-surface);
    overflow: hidden;
    transition: width 0.4s var(--app-ease-out), transform 0.45s var(--app-ease-out), box-shadow 0.3s ease;
}

.ml-rail .ml-sidebar {
    width: var(--ml-rail-width);
}

/* ---------- brand ---------- */

.ml-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: none;
    height: var(--ml-topbar-height);
    padding: 0 22px 0 26px;
    border-bottom: 1px solid var(--app-line);
}

/* Touch screens: the logo link, the drawer's close button, the avatar and the top bar's round buttons are tapped over at
   least 44 x 44 px, with the same unseen ::after as app-ui.css (touch hit areas) */
@media (pointer: coarse) {
    :where(.ml-brand-link, .ml-account, .app-bar-btn) {
        position: relative;
    }

    .ml-brand-link::after,
    .ml-drawer-close::after,
    .ml-account::after,
    .app-bar-btn::after {
        content: "";
        position: absolute;
        inset: min(0px, calc((100% - 44px) / 2));
    }
}

.ml-brand-link {
    display: inline-flex;
    align-items: center;
    border-radius: 10px;
    /* The logo is an image link: no link underline */
    text-decoration: none;
}

.ml-logo {
    display: block;
    width: auto;
    height: 34px;
}

.ml-logo-dark,
.ml-logo-icon,
[data-theme="dark"] .ml-logo-light {
    display: none;
}

[data-theme="dark"] .ml-logo-dark {
    display: block;
}

.ml-logo-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
}

.ml-rail .ml-brand {
    justify-content: center;
    padding: 0;
}

.ml-rail .ml-logo,
[data-theme="dark"] .ml-rail .ml-logo-dark {
    display: none;
}

.ml-rail .ml-logo-icon {
    display: block;
}

/* Close button: only inside the drawer. Two rounded bars form the cross (like the FrontEnd menu toggle), on a soft
   brand circle; it turns a quarter on hover and spins in when the drawer opens. */
.ml-drawer-close {
    position: relative;
    display: none;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--app-line);
    border-radius: 50%;
    background: var(--app-accent-soft);
    color: var(--app-accent);
    cursor: pointer;
    transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, transform 0.45s var(--app-ease-spring);
}

.ml-drawer-close-bar {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 2px;
    margin: -1px 0 0 -8px;
    border-radius: 2px;
    background: currentColor;
    transform: rotate(45deg);
}

.ml-drawer-close-bar + .ml-drawer-close-bar {
    transform: rotate(-45deg);
}

.ml-drawer-open .ml-drawer-close {
    animation: ml-close-in 0.55s var(--app-ease-spring) 0.12s both;
}

@keyframes ml-close-in {
    from {
        opacity: 0;
        transform: rotate(-90deg) scale(0.5);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@media (hover: hover) {
    .ml-drawer-close:hover {
        border-color: var(--app-color-primary);
        background: var(--app-color-primary);
        color: var(--app-color-white);
        box-shadow: 0 8px 20px rgba(118, 61, 232, 0.3);
        transform: rotate(90deg);
    }
}

.ml-drawer-close:focus-visible {
    outline: 2px solid var(--app-accent);
    outline-offset: 3px;
}

/* ---------- menu ---------- */

.ml-nav {
    flex: 1 1 auto;
    min-height: 0;
    padding: 20px 14px 12px;
    overflow-x: hidden;
    overflow-y: auto;
}

.ml-nav-title {
    margin: 0 0 10px;
    padding: 0 14px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--app-text-muted);
}

.ml-nav-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ml-nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 46px;
    padding: 0 14px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    color: var(--app-text);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.ml-nav-icon {
    flex: none;
    width: 24px;
    font-size: 21px;
    line-height: 1;
    text-align: center;
    color: var(--app-text-muted);
    transition: color 0.2s ease, transform 0.35s var(--app-ease-spring);
}

/* Beside its label the icon is optically centred (app-ui.css --app-icon-nudge); alone in the rail it is not */
.ml-nav-link .ml-nav-icon {
    position: relative;
    top: var(--app-icon-nudge);
}

.ml-rail .ml-nav-link .ml-nav-icon {
    top: 0;
}

/* A full line height, so letters that reach below the line (g, y, p) are not cut off by the overflow */
.ml-nav-text {
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

@media (hover: hover) {
    .ml-nav-link:hover {
        background: var(--app-accent-soft);
        color: var(--app-accent);
    }

    .ml-nav-link:hover .ml-nav-icon {
        color: var(--app-accent);
        transform: scale(1.12);
    }
}

.ml-nav-link-active {
    background: var(--app-accent-soft);
    font-weight: 600;
    color: var(--app-accent);
}

.ml-nav-link-active .ml-nav-icon {
    color: var(--app-accent);
}

/* Brand-gradient marker on the sidebar edge next to the active entry. The menu has one marker, on the list, that
   slides from the old entry to the new one: MainLayout writes the active entry's place into --ml-nav-active (entries
   are 46px tall with a 4px gap). It sits outside the links, so pressing a link never moves it. */
.ml-nav-list {
    position: relative;
}

.ml-nav-list::before,
.ml-sidebar-foot .ml-nav-link-active::before {
    content: "";
    position: absolute;
    top: 10px;
    left: -14px;
    width: 4px;
    height: 26px;
    border-radius: 0 4px 4px 0;
    background: linear-gradient(180deg, #763DE8 0%, #B57CDF 55%, #FFB7A5 100%);
}

.ml-nav-list::before {
    transform: translateY(calc(var(--ml-nav-active, 0) * 50px));
    transition: transform 0.5s var(--app-ease-out), opacity 0.25s ease;
}

/* No menu entry is open (e.g. the profile page): the marker fades out where it is */
.ml-nav-list[data-no-active]::before {
    opacity: 0;
}

/* "New" dot (Themes) */
.ml-nav-dot {
    flex: none;
    width: 8px;
    height: 8px;
    margin-left: auto;
    border-radius: 50%;
    background: var(--app-color-peach);
    box-shadow: 0 0 0 3px rgba(255, 183, 165, 0.3);
}

/* ---------- rail: icons only ---------- */

.ml-rail .ml-nav {
    padding-right: 12px;
    padding-left: 12px;
}

/* The section title is hidden in the rail; its height is kept, so the icons stay where they were */
.ml-rail .ml-nav-title {
    visibility: hidden;
}

.ml-rail .ml-nav-link {
    justify-content: center;
    padding: 0;
}

.ml-rail .ml-nav-list::before,
.ml-rail .ml-sidebar-foot .ml-nav-link-active::before {
    left: -12px;
}

.ml-rail .ml-nav-text {
    display: none;
}

.ml-rail .ml-nav-dot {
    position: absolute;
    top: 10px;
    right: 14px;
    margin: 0;
}

/* ---------- footer: the site's own content (a plan card, sign out) ---------- */

.ml-sidebar-foot {
    flex: none;
    padding: 14px;
    border-top: 1px solid var(--app-line);
}

/* Sign out: a menu entry that turns red on hover */
@media (hover: hover) {
    .ml-signout:hover,
    .ml-signout:hover .ml-nav-icon {
        background: var(--app-danger-soft);
        color: var(--app-danger);
    }

    .ml-signout:hover .ml-nav-icon {
        background: transparent;
    }
}

.ml-rail .ml-sidebar-foot {
    padding-right: 12px;
    padding-left: 12px;
}

/* Dimmed page behind the drawer (tablet and mobile) */
.ml-scrim {
    position: fixed;
    inset: 0;
    z-index: 1035;
    background: var(--app-scrim);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

/* ===========
     sidebar
   =========== */


/* ===========
     top bar
   =========== */

.ml-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--ml-topbar-height);
    padding: 0 var(--ml-content-gutter) 0 18px;
    border-bottom: 1px solid var(--app-line);
}

/* The frosted background sits on a layer of its own: a backdrop filter on the bar itself would make it the box that
   fixed elements inside it (the notification panel on phones) are placed in */
.ml-topbar::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--app-header-bg);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    backdrop-filter: blur(14px) saturate(160%);
    pointer-events: none;
}

/* ---------- the top bar's round buttons ----------
   The sidebar and menu buttons here, the theme toggle (PreferenceControls) and the bell (NotificationBell) keep the top
   bar's own design, apart from the platform's round buttons (app-icon-btn): a 42px circle on the surface colour with a
   thin neutral line; pointing at it turns the icon and line purple with a soft purple shadow; open, the focused
   field's purple line and halo. app-bar-btn-plain has no line or fill until pointed at, then a soft purple tint. A
   press shrinks it to 0.92 (data-press="soft", js/app-motion.js). */
.app-bar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--app-line);
    border-radius: 50%;
    background: var(--app-surface);
    color: var(--app-text);
    font-size: 20px;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.app-bar-btn-plain {
    border-color: transparent;
    background: transparent;
}

@media (hover: hover) {
    .app-bar-btn:hover {
        color: var(--app-accent);
        border-color: var(--app-accent);
        box-shadow: 0 8px 20px rgba(118, 61, 232, 0.12);
    }

    .app-bar-btn-plain:hover {
        border-color: transparent;
        background: var(--app-accent-soft);
        box-shadow: none;
    }
}

.app-bar-btn[aria-expanded="true"] {
    color: var(--app-accent);
    border-color: var(--app-accent);
    box-shadow: var(--app-field-focus);
}

/* Menu button: tablet and mobile only */
.ml-menu-btn {
    display: none;
}

.ml-collapse-btn {
    font-size: 22px;
    color: var(--app-text-muted);
}

.ml-topbar-title {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--app-text-strong);
}

/* A name that does not fit (the narrowest phones) is not shown cut off: app-ui.js marks it, and the page's heading below
   names the page; it keeps its place, so the bar does not move */
.ml-topbar-title[data-ml-title-hidden] {
    visibility: hidden;
}

.ml-topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

/* ---------- account ---------- */

.ml-account {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: 220px;
    /* As tall as the language, theme and bell buttons beside it (42px), the avatar 3px in from the pill's edge */
    height: 42px;
    padding: 3px 16px 3px 3px;
    border: 1px solid var(--app-line);
    border-radius: 999px;
    background: var(--app-surface);
    color: var(--app-text);
    text-decoration: none;
    transition: border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.ml-account-active {
    border-color: var(--app-accent);
}

@media (hover: hover) {
    .ml-account:hover {
        border-color: var(--app-accent);
        color: var(--app-accent);
        box-shadow: 0 8px 20px rgba(118, 61, 232, 0.12);
    }
}

.ml-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--app-gradient-brand);
    font-size: 15px;
    font-weight: 600;
    color: #FFFFFF;
}

.ml-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ml-account-name {
    min-width: 0;
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* ===========
     top bar
   =========== */


/* ===========
     content
   =========== */

.ml-content {
    min-height: calc(100vh - var(--ml-topbar-height));
    min-height: calc(100dvh - var(--ml-topbar-height));
}

/* ===========
     content
   =========== */


/* ==============
     responsive
   ============== */

/* Tablet and mobile: the sidebar becomes a drawer, always shown in full */
@media (max-width: 1199.98px) {
    .ml-shell {
        --ml-content-gutter: 24px;
    }

    .ml-main,
    .ml-rail .ml-main {
        margin-left: 0;
    }

    .ml-sidebar,
    .ml-rail .ml-sidebar {
        width: min(300px, 86vw);
        transform: translateX(-100%);
    }

    .ml-drawer-open .ml-sidebar {
        transform: none;
        box-shadow: var(--app-shadow-menu);
    }

    .ml-drawer-open .ml-scrim {
        opacity: 1;
        visibility: visible;
    }

    .ml-drawer-close,
    .ml-menu-btn {
        display: inline-flex;
    }

    .ml-collapse-btn {
        display: none;
    }

    /* The drawer always shows labels, even on rail pages */
    .ml-rail .ml-brand {
        justify-content: space-between;
        padding: 0 16px 0 22px;
    }

    .ml-rail .ml-logo-light {
        display: block;
    }

    [data-theme="dark"] .ml-rail .ml-logo-light,
    .ml-rail .ml-logo-icon {
        display: none;
    }

    [data-theme="dark"] .ml-rail .ml-logo-dark {
        display: block;
    }

    .ml-rail .ml-nav-title {
        visibility: visible;
    }

    .ml-rail .ml-nav-link .ml-nav-icon {
        top: var(--app-icon-nudge);
    }

    .ml-rail .ml-nav-link {
        justify-content: flex-start;
        padding: 0 14px;
    }

    .ml-rail .ml-nav-list::before,
    .ml-rail .ml-sidebar-foot .ml-nav-link-active::before {
        left: -14px;
    }

    .ml-rail .ml-nav,
    .ml-rail .ml-sidebar-foot {
        padding-right: 14px;
        padding-left: 14px;
    }

    .ml-rail .ml-nav-text {
        display: inline;
    }

    .ml-rail .ml-nav-dot {
        position: static;
        margin-left: auto;
    }
}

@media (max-width: 767.98px) {
    .ml-shell {
        --ml-topbar-height: 64px;
        --ml-content-gutter: 16px;
    }

    .ml-topbar {
        gap: 6px;
        padding-left: 10px;
    }

    /* A longer page name (e.g. in Malay) takes a second line instead of being cut off; one whose longest word still
       does not fit is hidden (above) */
    .ml-topbar-title {
        display: -webkit-box;
        font-size: 15px;
        line-height: 1.25;
        white-space: normal;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }

    .ml-topbar-actions {
        gap: 6px;
    }

    /* Every round control in the bar (the menu button too) is 40px here, as PreferenceControls makes its language and
       theme buttons, so the row has one height */
    .ml-topbar .app-bar-btn {
        width: 40px;
        height: 40px;
    }

    /* Avatar only, the same 40px circle */
    .ml-account {
        height: auto;
        padding: 0;
        border: 0;
        background: none;
    }

    .ml-avatar {
        width: 40px;
        height: 40px;
    }

    .ml-account-name {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ml-main,
    .ml-sidebar,
    .ml-scrim,
    .ml-nav-icon,
    .ml-nav-list::before {
        transition: none;
    }

    .ml-drawer-open .ml-drawer-close {
        animation: none;
    }

    .ml-drawer-close {
        transition: none;
    }
}

/* ==============
     responsive
   ============== */
