/*
 * Application Layout
 */
.app-shell {
    min-height: 100vh;

    display: grid;
    grid-template-columns:
        220px
        minmax(0, 1fr);
}

/*
 * Sidebar
 */
.sidebar {
    position: sticky;
    top: 0;
    z-index: 30;

    height: 100vh;
    min-height: 0;

    padding: 16px 12px;

    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);

    display: flex;
    flex-direction: column;
}

/*
 * Brand
 */
.brand {
    height: 52px;
    padding: 0 8px;

    flex: 0 0 auto;

    display: flex;
    align-items: center;
    gap: 11px;

    border-radius: 9px;

    color: var(--sidebar-text-strong);

    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.01em;

    text-decoration: none;

    transition:
        background-color 0.15s ease,
        color 0.15s ease;
}

.brand:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-active-text);
}

.brand:focus-visible {
    outline: 2px solid var(--sidebar-active-text);
    outline-offset: 2px;
}

.brand-mark {
    width: 30px;
    height: 30px;

    flex: 0 0 auto;

    border-radius: 9px;

    display: grid;
    place-items: center;

    background: var(--sidebar-brand-bg);
    color: var(--sidebar-brand-text);

    font-size: 13px;
    font-weight: 800;
}

/*
 * Navigation
 */
.nav {
    min-height: 0;

    margin-top: 14px;
    padding-right: 2px;

    flex: 1 1 auto;

    display: grid;
    align-content: start;
    gap: 3px;

    overflow-x: hidden;
    overflow-y: auto;

    scrollbar-width: thin;
    scrollbar-color:
        var(--sidebar-border)
        transparent;
}

.nav::-webkit-scrollbar {
    width: 5px;
}

.nav::-webkit-scrollbar-track {
    background: transparent;
}

.nav::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: var(--sidebar-border);
}

/*
 * First Level Menu
 */
.nav-item {
    position: relative;

    width: 100%;
    min-height: 42px;

    padding: 9px 11px;

    border: 0;
    border-radius: 9px;

    background: transparent;
    color: var(--sidebar-text);

    display: flex;
    align-items: center;
    gap: 11px;

    font-size: 14px;
    font-weight: 500;

    text-decoration: none;

    transition:
        background-color 0.15s ease,
        color 0.15s ease;
}

/*
 * Icon
 */
.nav-item .ui-icon {
    flex: 0 0 auto;

    color: currentColor;

    opacity: 0.9;
}

/*
 * Hover
 */
.nav-item:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-strong);
}

/*
 * Dashboard 등 Children 없는 메뉴 Active
 */
.nav > a.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);

    font-weight: 700;
}

.nav > a.nav-item.active::before {
    content: "";

    position: absolute;

    top: 8px;
    bottom: 8px;
    left: 0;

    width: 3px;

    border-radius:
        0
        4px
        4px
        0;

    background: var(--sidebar-active-text);
}

/*
 * Sidebar Footer
 */
.sidebar-footer {
    margin-top: auto;

    padding-top: 12px;

    border-top: 1px solid var(--sidebar-divider);
}

.ghost-btn {
    width: 100%;
    min-height: 38px;

    padding: 9px 12px;

    border: 1px solid var(--sidebar-border);
    border-radius: 9px;

    background: transparent;
    color: var(--sidebar-text);

    cursor: pointer;
}

.ghost-btn:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-strong);
}

/*
 * Mobile Backdrop
 */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;

    padding: 0;

    border: 0;

    background:
        rgba(0, 0, 0, 0.52);

    opacity: 0;
    visibility: hidden;

    pointer-events: none;

    transition:
        opacity 0.2s ease,
        visibility 0.2s ease;
}

/*
 * Main
 */
.main {
    min-width: 0;
    min-height: 100vh;

    display: flex;
    flex-direction: column;
}

/*
 * Topbar
 */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;

    min-height: 68px;

    padding: 0 28px;

    border-bottom: 1px solid var(--border);

    background: var(--surface);

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar-left,
.topbar-actions {
    min-width: 0;

    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-title {
    min-width: 0;

    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-title strong {
    white-space: nowrap;
}

/*
 * User Badge
 */
.pill {
    padding: 6px 10px;

    border-radius: 999px;

    background: var(--surface-sub);
    color: var(--muted);

    font-size: 12px;
}

/*
 * Topbar Icon Button
 */
.topbar-icon-button {
    width: 38px;
    height: 38px;

    padding: 0;

    flex: 0 0 auto;

    border: 1px solid var(--border);
    border-radius: 10px;

    background: var(--surface);
    color: var(--muted);

    display: inline-grid;
    place-items: center;

    cursor: pointer;

    appearance: none;
    -webkit-appearance: none;

    transition:
        background-color 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease;
}

.topbar-icon-button:hover {
    background: var(--surface-sub);
    color: var(--primary);

    border-color: var(--primary);
}

.topbar-icon-button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.mobile-menu-button {
    display: none;
}

/*
 * Content
 */
.content {
    min-width: 0;
    padding: 28px;

    flex: 1 1 auto;
}

/*
 * Module Header
 */
.module-head {
    margin-bottom: 22px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.module-head h1 {
    margin: 0 0 5px;

    font-size: 24px;
    line-height: 1.3;
}

.module-head p {
    margin: 0;
}

/*
 * KPI
 */
.kpis {
    display: grid;
    grid-template-columns:
        repeat(
            4,
            minmax(0, 1fr)
        );

    gap: 14px;
}

/*
 * Module Grid
 */
.module-grid {
    margin-top: 14px;

    display: grid;
    grid-template-columns:
        minmax(0, 1fr)
        320px;

    gap: 14px;
}

.module-body {
    padding: 16px;
}

/*
 * Primary Button
 */
.primary-btn {
    min-height: 38px;

    padding: 9px 14px;

    border: 0;
    border-radius: 9px;

    background: var(--primary);
    color: var(--primary-contrast);

    font-weight: 700;

    cursor: pointer;

    appearance: none;
    -webkit-appearance: none;
}

.primary-btn:hover {
    opacity: 0.92;
}



/*
 * Application Footer
 */
.app-footer {
    min-height: 58px;

    padding: 16px 28px;

    border-top: 1px solid var(--border);

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;

    color: var(--muted);

    font-size: 12px;
    line-height: 1.5;
}

.app-footer-left {
    min-width: 0;

    display: flex;
    align-items: center;
    gap: 14px;

    flex-wrap: wrap;
}

.app-footer-copy {
    white-space: nowrap;
}

.app-footer-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-footer-links a {
    color: var(--muted);

    text-decoration: none;

    transition: color 0.15s ease;
}

.app-footer-links a:hover {
    color: var(--primary);
}

.app-footer-links a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;

    border-radius: 3px;
}

.app-footer-divider {
    color: var(--border);
}

.app-footer-version {
    flex: 0 0 auto;

    color: var(--muted);

    white-space: nowrap;
}

/*
 * Tablet
 */
@media (
    max-width: 1100px
) and (
    min-width: 721px
) {
    .app-shell {
        grid-template-columns:
            76px
            minmax(0, 1fr);
    }

    .sidebar {
        padding:
            16px
            10px;

        overflow: visible;
    }

    .nav {
        overflow: visible;
    }

    .brand {
        justify-content: center;

        padding: 0;
    }

    .brand > span:last-child,
    .nav-label {
        display: none;
    }

    .nav-item {
        justify-content: center;

        padding:
            10px
            8px;
    }

    .module-grid {
        grid-template-columns: 1fr;
    }

    .kpis {
        grid-template-columns:
            repeat(
                2,
                minmax(0, 1fr)
            );
    }

    .content {
        padding: 22px;
    }
}

/*
 * Mobile
 */
@media (max-width: 720px) {
    body.mobile-menu-open {
        overflow: hidden;
    }

    .app-shell {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 30;

        width: min(
            82vw,
            300px
        );

        height: 100%;

        transform:
            translateX(-102%);

        box-shadow:
            18px
            0
            45px
            rgba(
                0,
                0,
                0,
                0.25
            );

        transition:
            transform 0.22s ease;
    }

    body.mobile-menu-open .sidebar {
        transform:
            translateX(0);
    }

    body.mobile-menu-open
    .sidebar-backdrop {
        opacity: 1;
        visibility: visible;

        pointer-events: auto;
    }

    .brand {
        justify-content: flex-start;
    }

    .nav-item {
        min-height: 46px;

        padding:
            11px
            12px;
    }

    .mobile-menu-button {
        display: inline-grid;
    }

    .topbar {
        min-height: 60px;

        padding:
            8px
            14px;
    }

    .topbar-title {
        display: grid;
        gap: 1px;
    }

    .topbar-title strong {
        max-width: 44vw;

        overflow: hidden;

        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar-title .muted {
        display: none;
    }

    .pill {
        display: none;
    }

    .content {
        padding:
            18px
            14px
            28px;
    }

    .module-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .kpis,
    .module-grid {
        grid-template-columns: 1fr;
    }


    .app-footer {
        min-height: auto;

        padding: 16px 14px;

        align-items: flex-start;
        flex-direction: column;

        gap: 7px;
    }

    .app-footer-left {
        align-items: flex-start;
        flex-direction: column;

        gap: 6px;
    }

    .app-footer-copy {
        white-space: normal;
    }

    .app-footer-links {
        flex-wrap: wrap;
    }

    .app-footer-version {
        font-size: 11px;
    }
}

/*
 * Motion
 */
@media (
    prefers-reduced-motion: reduce
) {
    .sidebar,
    .sidebar-backdrop,
    .nav-item,
    .topbar-icon-button {
        transition: none;
    }
}