/* ══════════════════════════════════════════════════════════
   al-layout.css — 사이드바, 메인 영역, 탑바, 반응형
   ══════════════════════════════════════════════════════════ */

:root {
    --al-mobile-tabbar-height: 4.9rem;
    --al-mobile-tabbar-gap: .65rem;
    --al-mobile-bottom-space: calc(var(--al-mobile-tabbar-height) + var(--al-mobile-tabbar-gap) + env(safe-area-inset-bottom));
}

/* ── 사이드바 ── */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--al-sf);
    border-right: 1px solid var(--al-bdr);
    padding: 1.25rem 0;
    display: flex; flex-direction: column;
    z-index: 1030;
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--al-sf3) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--al-sf3); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.sidebar .brand {
    display: flex; align-items: center; gap: .65rem;
    padding: 0 1.25rem 1rem; margin-bottom: .5rem;
    border-bottom: 1px solid var(--al-bdr);
    font-size: 1.1rem; font-weight: 700;
    color: var(--al-tx); text-decoration: none;
    transition: opacity .2s;
}
.sidebar .brand:hover { opacity: .85; }

.sidebar .brand .logo-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 10px;
    background: linear-gradient(135deg, var(--al-pri), var(--al-pri-d));
    box-shadow: 0 4px 12px rgba(99,102,241,.35);
    flex-shrink: 0;
}
.sidebar .brand .logo-icon svg { display: block; }

.sidebar .nav-section {
    padding: .65rem 1.25rem .25rem;
    color: var(--al-txd);
    font-size: .65rem; text-transform: uppercase;
    letter-spacing: .1em; font-weight: 600;
}

.sidebar .nav-link {
    position: relative;
    display: flex; align-items: center; gap: .65rem;
    padding: .5rem 1.25rem; margin: 1px .5rem;
    border-radius: 10px;
    color: var(--al-txm); font-size: .85rem; font-weight: 500;
    text-decoration: none;
    transition: color .15s, background .15s;
}
.sidebar .nav-link:hover {
    color: var(--al-tx);
    background: rgba(99,102,241,.08);
}
.sidebar .nav-link.active {
    color: var(--sidebar-active-color);
    background: linear-gradient(135deg, var(--al-pri), var(--al-pri-d));
    box-shadow: 0 4px 12px rgba(99,102,241,.3);
}
/* 활성 항목 좌측 인디케이터 */
.sidebar .nav-link.active::before {
    content: '';
    position: absolute;
    left: -0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--al-pri-l);
    border-radius: 0 3px 3px 0;
    opacity: .7;
}
.sidebar .nav-link i {
    width: 20px; text-align: center;
    font-size: 1.05rem; flex-shrink: 0;
}
.sidebar .spacer { flex: 1; }
.sidebar .nav-divider {
    height: 1px;
    background: var(--al-bdr);
    margin: .5rem 1.25rem;
}

.sidebar .sidebar-footer {
    margin: .25rem 1rem 0;
    display: grid;
    gap: .5rem;
}

.sidebar .sidebar-footer-card {
    padding: .7rem .8rem;
    border: 1px solid var(--al-bdr);
    border-radius: 12px;
    background: linear-gradient(135deg, color-mix(in srgb, var(--al-sf2) 94%, var(--al-pri) 6%), var(--al-sf));
    box-shadow: 0 8px 18px rgba(15, 23, 42, .06);
}

.sidebar .sidebar-footer-label {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    margin: 0;
    color: var(--al-txd);
    font-size: .62rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    font-weight: 700;
}

.sidebar .sidebar-footer-title {
    color: var(--al-tx);
    font-size: .86rem;
    font-weight: 700;
    line-height: 1.2;
    word-break: keep-all;
}

.sidebar .sidebar-footer-subtitle {
    margin-top: .1rem;
    color: var(--al-txm);
    font-size: .72rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar .sidebar-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
    min-width: 0;
}

.sidebar .sidebar-version-pill {
    flex: 0 0 auto;
    padding: .18rem .5rem;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--al-pri), var(--al-pri-d));
    color: #fff;
    font-size: .64rem;
    font-weight: 800;
    letter-spacing: .04em;
    white-space: nowrap;
}

.sidebar .sidebar-footer-value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── 메인 영역 ── */
.main-area {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
}
.skip-link {
    position: absolute;
    top: .75rem;
    left: 1rem;
    z-index: 2000;
    padding: .55rem .9rem;
    border-radius: 10px;
    background: var(--al-pri);
    color: #fff;
    text-decoration: none;
    transform: translateY(-140%);
    transition: transform .2s ease;
}
.skip-link:focus-visible {
    transform: translateY(0);
}
.topbar {
    height: 60px;
    background: var(--topbar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--al-bdr);
    display: flex; align-items: center;
    justify-content: flex-end; gap: .5rem;
    padding: 0 max(1.5rem, env(safe-area-inset-right)) 0 max(1.5rem, env(safe-area-inset-left));
    position: sticky; top: 0; z-index: 1020;
}
.skin-workspace-ribbon {
    display: none !important;
}
.topbar .user-badge {
    display: flex; align-items: center; gap: .5rem;
    padding: .4rem .85rem; border-radius: 10px;
    background: var(--al-sf2); color: var(--al-txm);
    font-size: .85rem;
}
.topbar .user-badge i { color: var(--al-pri-l); }
/* ── 탑바 밀도/줄바꿈 및 드롭다운 팝업 레이어 ── */
.topbar {
    overflow: visible !important;
}
.skin-switch-menu,
.topbar .dropdown-menu {
    z-index: 2000 !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25) !important;
    border: 1px solid var(--al-bdr) !important;
    border-radius: 16px !important;
}
.topbar .topbar-new-transaction,
.topbar-command-button,
.topbar .topbar-help-button,
.topbar .skin-switch,
.topbar .theme-toggle,
.topbar .dropdown,
.topbar .al-topbar-ai-status {
    flex: 0 0 auto;
}
.topbar .topbar-new-transaction {
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar .notification-badge {
    top: -.15rem !important;
    right: -.15rem !important;
    transform: none !important;
    min-width: 1.45rem;
    height: 1.45rem;
    padding: 0 .35rem;
    border: 2px solid var(--topbar-bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 4px 10px rgba(220, 53, 69, .25);
}
.topbar form {
    flex: 0 1 280px;
    min-width: 0;
}
.topbar form label {
    flex: 0 0 auto;
    white-space: nowrap;
}
.topbar form .form-select {
    min-width: 0;
    max-width: 180px;
}
.topbar .user-badge {
    flex: 0 1 15rem;
    max-width: 15rem;
    overflow: hidden;
}
.topbar .user-badge > i,
.topbar .user-badge .badge {
    flex: 0 0 auto;
}
.topbar .user-badge span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: normal;
}
@media (max-width: 1399.98px) {
    .topbar form { max-width: 240px; }
    .topbar .user-badge .badge.bg-secondary-subtle { display: none; }
}
@media (max-width: 1199.98px) {
    .topbar form { display: none !important; }
    .topbar .user-badge { max-width: 12rem; }
}

.topbar .topbar-new-transaction {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    font-weight: 700;
    min-height: 38px;
    white-space: nowrap;
}

.sidebar .nav-link,
.topbar .btn,
.topbar .dropdown > .btn,
.skin-switch-toggle,
.theme-toggle,
.btn-close,
.dropdown-item,
.page-link,
.al-combo-option,
.al-enhanced-multi-control,
.al-enhanced-multi-option {
    min-height: 44px;
}

.btn-close {
    min-width: 44px;
    min-height: 44px;
    background-position: center;
}

.theme-toggle {
    background: var(--al-sf2);
    border: 1px solid var(--al-bdr);
    color: var(--al-txm);
    width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: color .2s, background .2s, transform .2s;
    font-size: 1.1rem;
}
.theme-toggle:hover {
    color: var(--al-tx);
    background: rgba(99,102,241,.12);
    transform: rotate(15deg);
}

.content-area {
    padding: 1.1rem max(1.5rem, env(safe-area-inset-right)) calc(1.5rem + env(safe-area-inset-bottom)) max(1.5rem, env(safe-area-inset-left));
}

.main-area,
.content-area,
.page-header,
.page-header > *,
.page-header .page-actions,
.topbar,
.topbar > *,
.topbar .user-badge,
.card,
.card-header,
.card-body,
.card-footer,
.table-responsive {
    min-width: 0;
}

img,
video {
    max-width: 100%;
    height: auto;
}

.page-header h2,
.card-header h5 {
    overflow-wrap: anywhere;
}

/* ── 사이드바 백드롭 (모바일) ── */
.sidebar-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 1029;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.sidebar-backdrop.show { display: block; }

/* ── 모바일 하단 탭바 / 바텀시트 ── */
.al-mobile-tabbar,
.al-mobile-more-sheet,
.al-mobile-nav-backdrop {
    display: none;
}

.al-mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1044;
    background: rgba(15, 23, 42, .58);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
}

.al-mobile-more-sheet {
    position: fixed;
    left: max(.65rem, env(safe-area-inset-left));
    right: max(.65rem, env(safe-area-inset-right));
    bottom: max(.65rem, env(safe-area-inset-bottom));
    z-index: 1045;
    max-height: min(76vh, 42rem);
    overflow: auto;
    padding: .55rem .85rem calc(1rem + env(safe-area-inset-bottom));
    border: 1px solid color-mix(in srgb, var(--al-bdr) 82%, var(--al-pri) 18%);
    border-radius: 20px;
    background: color-mix(in srgb, var(--al-sf) 94%, transparent);
    box-shadow: 0 -1rem 3rem rgba(15, 23, 42, .42);
    transform: translateY(calc(100% + 1rem));
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform .24s cubic-bezier(.2,.8,.2,1), opacity .2s ease, visibility 0s linear .24s;
    overscroll-behavior: contain;
}

.al-mobile-sheet-handle {
    width: 3.4rem;
    height: .32rem;
    margin: .2rem auto .8rem;
    border-radius: 999px;
    background: var(--al-sf3);
}

.al-mobile-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--al-bdr);
}

.al-mobile-sheet-header h2 {
    margin: 0;
    font-size: 1.12rem;
    line-height: 1.2;
}

.al-mobile-more-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .55rem;
    padding-top: .85rem;
}

.al-mobile-more-link {
    display: flex;
    align-items: center;
    gap: .55rem;
    width: 100%;
    min-height: 48px;
    padding: .65rem .75rem;
    border: 1px solid var(--al-bdr);
    border-radius: 14px;
    background: var(--al-sf2);
    color: var(--al-tx);
    text-decoration: none;
    text-align: left;
    font-size: .9rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
}

.al-mobile-more-link i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    color: var(--al-pri-l);
    flex: 0 0 auto;
}

.al-mobile-more-link span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.al-mobile-more-link.active {
    border-color: color-mix(in srgb, var(--al-pri) 58%, var(--al-bdr));
    background: color-mix(in srgb, var(--al-pri) 18%, var(--al-sf2));
}

.al-mobile-nav-open {
    overflow: hidden;
}

.al-mobile-nav-open .al-mobile-nav-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.al-mobile-nav-open .al-mobile-more-sheet {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
}


.al-pull-refresh-indicator {
    position: fixed;
    top: calc(.75rem + env(safe-area-inset-top));
    left: 50%;
    z-index: 1042;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .55rem .9rem;
    border: 1px solid var(--al-bdr);
    border-radius: 999px;
    background: var(--al-sf);
    color: var(--al-tx);
    box-shadow: 0 .75rem 1.6rem rgba(15, 23, 42, .26);
    transform: translate(-50%, -140%);
    opacity: 0;
    pointer-events: none;
    transition: transform .2s ease, opacity .2s ease;
    font-size: .82rem;
    font-weight: 800;
}

.al-pull-refresh-indicator.is-visible {
    transform: translate(-50%, 0);
    opacity: 1;
}

.al-pull-refresh-indicator.is-ready {
    border-color: color-mix(in srgb, var(--al-pri) 62%, var(--al-bdr));
    color: var(--al-pri-l);
}

@media (max-width: 991.98px) {
    html,
    body {
        overflow-x: hidden;
    }

    body {
        padding-bottom: var(--al-mobile-bottom-space);
    }

    .sidebar-toggle-button {
        display: none !important;
    }

    .content-area {
        padding-bottom: calc(1.5rem + var(--al-mobile-bottom-space));
        max-width: 100vw;
    }


    .al-back-to-top {
        bottom: calc(var(--al-mobile-bottom-space) + .6rem) !important;
    }

    .al-mobile-tabbar {
        position: fixed;
        left: max(.65rem, env(safe-area-inset-left));
        right: max(.65rem, env(safe-area-inset-right));
        bottom: max(.55rem, env(safe-area-inset-bottom));
        z-index: 1038;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: end;
        gap: .18rem;
        min-height: var(--al-mobile-tabbar-height);
        padding: .5rem .5rem .55rem;
        border: 1px solid color-mix(in srgb, var(--al-bdr) 82%, var(--al-pri) 18%);
        border-radius: 22px;
        background: color-mix(in srgb, var(--al-sf) 94%, transparent);
        box-shadow: 0 1rem 2.5rem rgba(15, 23, 42, .34);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
    }

    .al-mobile-tab-item,
    .al-mobile-tab-action {
        position: relative;
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: .18rem;
        min-width: 0;
        min-height: 48px;
        border: 0;
        border-radius: 15px;
        background: transparent;
        color: var(--al-txm);
        text-decoration: none;
        font-size: .68rem;
        font-weight: 800;
        line-height: 1.1;
        letter-spacing: 0;
        touch-action: manipulation;
    }

    .al-mobile-tab-item i,
    .al-mobile-tab-action i {
        font-size: 1.18rem;
        line-height: 1;
    }

    .al-mobile-tab-item span,
    .al-mobile-tab-action span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .al-mobile-tab-item.active {
        color: var(--al-pri-l);
        background: color-mix(in srgb, var(--al-pri) 12%, transparent);
    }

    .al-mobile-tab-action {
        min-height: 58px;
        transform: translateY(-.55rem);
        color: #fff;
        background: linear-gradient(135deg, var(--al-pri), var(--al-pri-d));
        box-shadow: 0 .8rem 1.8rem rgba(99, 102, 241, .32);
    }

    .al-mobile-tab-action i {
        font-size: 1.35rem;
    }

    .al-mobile-more-sheet,
    .al-mobile-nav-backdrop {
        display: block;
    }
}

@media (prefers-reduced-motion: reduce) {
    .al-mobile-nav-backdrop,
    .al-mobile-more-sheet,
    .al-mobile-tab-item,
    .al-mobile-tab-action {
        transition: none !important;
    }
}

/* ── 페이지 헤더 공통 ── */
.page-header {
    display: flex; flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.5rem;
}
.page-header h2 { margin-bottom: .15rem; }
.page-header .page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── 반응형 (태블릿 ~992px) ── */
@media (max-width: 991px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); box-shadow: var(--al-shadow-xl); }
    .main-area { margin-left: 0; }
}

/* ── 반응형 (모바일 ~768px) ── */
@media (max-width: 767px) {
    .content-area {
        padding: .75rem max(.85rem, env(safe-area-inset-right)) calc(.75rem + var(--al-mobile-bottom-space)) max(.85rem, env(safe-area-inset-left));
    }
    .topbar {
        gap: .4rem;
        min-height: 60px;
        padding: 0 max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left));
    }
    .topbar-command-button {
        width: 44px;
        height: 44px;
        min-height: 44px;
        padding: 0;
        justify-content: center;
    }
    .topbar-command-button span,
    .topbar-new-transaction,
    .topbar .skin-switch,
    .topbar .al-topbar-ai-status {
        display: none !important;
    }
    .topbar .theme-toggle,
    .topbar .dropdown > .btn,
    .topbar > .btn {
        flex: 0 0 auto;
    }
    .topbar .user-badge {
        max-width: min(36vw, 9rem);
        padding: .35rem .55rem;
        gap: .35rem;
    }
    .topbar .user-badge span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .topbar .user-badge .badge {
        display: none;
    }
    .card { border-radius: 12px !important; }
    .card-header { padding: .75rem 1rem; }
    .table-responsive { -webkit-overflow-scrolling: touch; }
    .row > [class*="col-md-"],
    .row > [class*="col-lg-"] { margin-bottom: .75rem; }
}

@media (max-width: 575.98px) {
    .content-area {
        padding: .6rem max(.65rem, env(safe-area-inset-right)) calc(.65rem + var(--al-mobile-bottom-space)) max(.65rem, env(safe-area-inset-left));
    }
    .topbar {
        padding-left: max(.75rem, env(safe-area-inset-left));
        padding-right: max(.75rem, env(safe-area-inset-right));
    }
    .topbar .user-badge {
        max-width: min(32vw, 7.5rem);
    }
    .topbar .user-badge i {
        display: none;
    }
    .page-header {
        align-items: stretch;
        gap: .45rem;
        margin-bottom: .65rem;
    }
    .page-header > div:first-child {
        width: 100%;
    }
    .page-header h2 {
        font-size: clamp(1.28rem, 6.2vw, 1.65rem);
        line-height: 1.2;
        text-wrap: balance;
    }
    .page-header .page-actions,
    .page-header > .d-flex {
        width: 100%;
    }
    .page-header .page-actions {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        width: 100% !important;
    }
    .page-header .page-actions .btn-group {
        display: flex !important;
        flex-wrap: wrap !important;
        width: 100% !important;
        gap: 0.35rem !important;
    }
    .page-header .page-actions .btn-group .btn {
        flex: 1 1 auto !important;
        border-radius: 10px !important;
    }
    .content-area,
    .main-area {
        padding-bottom: var(--al-mobile-bottom-space) !important;
    }
}

/* ── 스크롤 프로그레스 바 ── */
#al-scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    z-index: var(--z-progress, 9998);
    background: linear-gradient(90deg, var(--al-pri), var(--al-acc));
    transition: width .08s linear;
    pointer-events: none;
    border-radius: 0 2px 2px 0;
}

/* ── 사이드바 뱃지 (알림 수) ── */
.nav-link .nav-badge {
    margin-left: auto;
    font-size: .6rem;
    padding: .15em .5em;
    border-radius: 20px;
    background: var(--al-pri);
    color: #fff;
    font-weight: 700;
    line-height: 1.4;
    min-width: 18px;
    text-align: center;
}
.nav-link.active .nav-badge {
    background: rgba(255,255,255,.25);
}

