.msm-app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.msm-sidebar {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: var(--msm-sidebar-width);
    overflow-y: auto;
    border-right: 1px solid var(--msm-color-border);
    background: var(--msm-color-surface);
}

.msm-sidebar-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 70px;
    max-height: 78px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--msm-color-border);
    overflow: hidden;
    text-align: center;
}

.msm-wordmark {
    display: block;
    width: auto;
    height: 30px;
    max-width: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 .5px rgb(129 140 248 / .95)) drop-shadow(0 1px 5px rgb(99 102 241 / .45));
}

.msm-icon {
    display: block;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.msm-nav-section { padding: 8px 0; }

.msm-nav-section-title {
    padding: 8px 16px 4px;
    color: var(--msm-color-text-muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.msm-nav-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    margin: 0;
    border: 0;
    border-radius: var(--msm-radius-sm);
    background: transparent;
    box-shadow: none;
    color: var(--msm-color-text-muted);
    cursor: pointer;
    font: inherit;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .08em;
    text-align: left;
    text-transform: uppercase;
}

.msm-nav-toggle:hover {
    background: var(--msm-color-surface-2);
    color: var(--msm-color-text);
}

.msm-nav-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--msm-color-primary);
}

.msm-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--msm-touch-target);
    margin: 1px 8px;
    padding: 12px 16px;
    border-radius: var(--msm-radius);
    color: var(--msm-color-text-muted);
    cursor: pointer;
    font-size: 13.5px;
    text-decoration: none;
    transition: background .15s ease, color .15s ease;
}

.msm-nav-item:hover {
    background: var(--msm-color-surface-2);
    color: var(--msm-color-text);
    text-decoration: none;
}

.msm-nav-item.active,
.msm-nav-item[aria-current="page"] {
    background: rgb(99 102 241 / .2);
    color: var(--msm-color-primary-light);
    font-weight: 600;
}

.msm-nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.msm-main-area {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.msm-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-width: 0;
    height: var(--msm-header-height);
    padding: 0 24px;
    border-bottom: 1px solid var(--msm-color-border);
    background: var(--msm-color-surface);
}

.msm-topbar-left,
.msm-topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.msm-topbar-title {
    color: var(--msm-color-text);
    font-size: 15px;
    font-weight: 600;
}

.msm-topbar-page {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    max-width: min(52vw, 560px);
    line-height: 1.15;
}

.msm-topbar-page-title,
.msm-topbar-page-subtitle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.msm-topbar-page-title {
    color: var(--msm-color-text);
    font-size: 16px;
    font-weight: 700;
}

.msm-topbar-page-subtitle {
    color: var(--msm-color-text-muted);
    font-size: 11.5px;
}

.msm-user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--msm-color-surface-2);
    color: var(--msm-color-text-muted);
    font-size: 12.5px;
}

.msm-page-content {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    padding: var(--msm-space-6);
    overflow-y: auto;
}

.msm-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--msm-space-3);
    flex-wrap: wrap;
    margin-bottom: var(--msm-space-5);
}

.msm-page-header > * { min-width: 0; }

.msm-page-title {
    margin: 0;
    color: var(--msm-color-text);
    font-size: 20px;
    font-weight: 700;
}

.msm-page-subtitle {
    margin-top: 2px;
    color: var(--msm-color-text-muted);
    font-size: 13px;
}

.msm-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.msm-toolbar > * { min-width: 0; }
.msm-toolbar-spread { justify-content: space-between; width: 100%; }

.msm-tabs-bar {
    margin: 4px 0 20px;
    padding: 4px;
    overflow-x: auto;
    border: 1px solid var(--msm-color-border);
    border-radius: var(--msm-radius);
    background: var(--msm-color-surface);
    -webkit-overflow-scrolling: touch;
}

.msm-tabs {
    display: flex;
    gap: 4px;
    min-width: max-content;
}

.msm-tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 36px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--msm-radius-sm);
    background: transparent;
    color: var(--msm-color-text-muted);
    cursor: pointer;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    transition: background .15s ease, color .15s ease;
}

.msm-tab:hover {
    background: var(--msm-color-surface-2);
    color: var(--msm-color-text);
}

.msm-tab:focus-visible { outline: 2px solid var(--msm-color-primary); outline-offset: -1px; }
.msm-tab.active,
.msm-tab[aria-selected="true"] { background: var(--msm-color-primary); color: #fff; }
.msm-tab:disabled { opacity: .5; cursor: not-allowed; }

.msm-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    overflow: hidden;
    background: var(--msm-color-overlay);
    backdrop-filter: blur(2px);
}

.msm-dialog {
    width: min(560px, 95vw);
    max-width: calc(100vw - 24px);
    max-height: 90vh;
    padding: var(--msm-space-6);
    overflow-x: hidden;
    overflow-y: auto;
    border: 1px solid var(--msm-color-border);
    border-radius: var(--msm-radius-lg);
    background: var(--msm-color-surface);
    box-shadow: var(--msm-shadow);
    overscroll-behavior: contain;
}

.msm-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--msm-space-3);
    margin-bottom: var(--msm-space-5);
}

.msm-dialog-title {
    min-width: 0;
    margin: 0;
    color: var(--msm-color-text);
    font-size: 16px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.msm-dialog-body {
    min-width: 0;
}

dialog.msm-dialog-overlay {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    border: 0;
    color: var(--msm-color-text);
}
dialog.msm-dialog-overlay:not([open]) { display: none; }
dialog.msm-dialog-overlay::backdrop { background: transparent; }

.msm-dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: var(--msm-space-5);
    padding-top: var(--msm-space-4);
    border-top: 1px solid var(--msm-color-border);
}

@media (max-width: 960px) {
    .msm-sidebar {
        width: 260px;
        visibility: hidden;
        position: fixed;
        z-index: 200;
        inset: 0 auto 0 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }

    .msm-sidebar.is-open { transform: translateX(0); visibility: visible; box-shadow: 4px 0 24px rgb(0 0 0 / .45); }
    .msm-sidebar-logo { min-height: 62px; max-height: 66px; }
    .msm-page-content { padding: 16px; }
}

@media (max-width: 640px) {
    .msm-topbar { padding: 0 12px; }
    .msm-page-content { padding: 12px; }
    .msm-dialog {
        width: 100%;
        max-width: 100%;
        max-height: 88vh;
        padding: 20px 16px;
        border-radius: 16px 16px 0 0;
        position: fixed;
        bottom: 0;
        margin: 0;
    }
    .msm-dialog-footer {
        gap: 8px;
        flex-wrap: wrap;
    }
    .msm-dialog-footer .msm-btn {
        flex: 1;
        min-width: 100px;
    }
    dialog.msm-dialog-overlay { align-items: flex-end; padding: 0; }
}
