/*
 * OneHealth Admin UI Redesign v6 scroll containment fix
 * 목적: 공통 UI 레이어가 html/body/.ke-shell을 100vh + overflow:hidden으로 고정한 상태에서
 *       관리/운영 페이지의 자연 높이 콘텐츠가 viewport 아래로 잘려 보이지 않는 문제를 해결한다.
 * 정책: 관리 페이지는 화면 자체를 강제로 압축하지 않고, 상단 네비게이션 아래의 .ke-content를
 *       명확한 세로 스크롤 컨테이너로 사용한다.
 */

@supports selector(:has(*)) {
    html:has(.oh-admin-redesign),
    body:has(.oh-admin-redesign) {
        width: 100% !important;
        height: 100% !important;
        min-height: 100% !important;
        overflow: hidden !important;
        background: var(--admin-bg, #edf5ff) !important;
    }

    body:has(.oh-admin-redesign) {
        margin: 0 !important;
    }

    .ke-shell:has(.oh-admin-redesign),
    .ke-shell-topnav:has(.oh-admin-redesign) {
        width: 100% !important;
        height: 100vh !important;
        min-height: 100vh !important;
        max-height: 100vh !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        background: var(--admin-bg, #edf5ff) !important;
    }

    .ke-global-header:has(+ .ke-main .oh-admin-redesign),
    .ke-shell:has(.oh-admin-redesign) .ke-global-header {
        flex: 0 0 auto !important;
    }

    .ke-main:has(.oh-admin-redesign) {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        height: auto !important;
        max-height: none !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        background: var(--admin-bg, #edf5ff) !important;
    }

    .ke-content:has(.oh-admin-redesign) {
        flex: 1 1 auto !important;
        width: 100% !important;
        min-width: 0 !important;
        min-height: 0 !important;
        height: auto !important;
        max-height: none !important;
        display: block !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: contain !important;
        scrollbar-gutter: stable !important;
        padding: .82rem .92rem 2.4rem !important;
        background: var(--admin-bg, #edf5ff) !important;
    }

    .ke-content:has(.oh-admin-redesign) > .oh-admin-redesign {
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        min-height: calc(100vh - var(--oh-header-height, 64px) - 1.65rem) !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        padding-bottom: 1.2rem !important;
    }
}

/* 관리 화면 내부에서는 카드/섹션이 부모 높이에 의해 잘리지 않도록 최종 방어 */
body .oh-admin-redesign,
body .oh-admin-redesign > *,
body .oh-admin-redesign .oh-grid,
body .oh-admin-redesign .oh-card,
body .oh-admin-redesign .panel,
body .oh-admin-redesign section,
body .oh-admin-redesign article {
    max-height: none !important;
    contain: none !important;
    clip-path: none !important;
}

body .oh-admin-redesign > *,
body .oh-admin-redesign .oh-card,
body .oh-admin-redesign .panel {
    overflow: visible !important;
}

/* 데이터가 많은 표/목록만 내부 스크롤을 사용한다. 페이지 전체 스크롤과 충돌하지 않도록 높이는 적당히 제한한다. */
body .oh-admin-redesign .oh-table-wrap,
body .oh-admin-redesign .data-table-wrapper,
body .oh-admin-redesign .oa-dataset-picker,
body .oh-admin-redesign .oh-scroll-region,
body .oh-admin-redesign .admin-scroll-region {
    min-height: 0 !important;
    overflow: auto !important;
    scrollbar-gutter: stable !important;
}

body .oh-admin-redesign .oh-table-wrap,
body .oh-admin-redesign .data-table-wrapper {
    max-height: min(52vh, 620px) !important;
}

/* 카드 내부의 마지막 표는 화면 하단에 붙어도 잘리지 않도록 여백을 확보한다. */
body .oh-admin-redesign > :last-child,
body .oh-admin-redesign .oh-card:last-child,
body .oh-admin-redesign section:last-child {
    margin-bottom: 1.2rem !important;
}

/* Bootstrap/table wrapper가 부모 카드 높이에 묶여 내용이 잘리는 경우 방어 */
body .oh-admin-redesign .table-responsive,
body .oh-admin-redesign .table-wrapper,
body .oh-admin-redesign .admin-table-wrapper {
    max-height: min(52vh, 620px) !important;
    overflow: auto !important;
    scrollbar-gutter: stable !important;
}

/* 특정 운영 페이지의 체크리스트/절차 카드가 viewport 아래로 내려갈 때 페이지 스크롤로 접근 가능하게 한다. */
body .oh-admin-redesign.oh-admin-page-ops-checklist,
body .oh-admin-redesign.oh-admin-page-ops-runbook,
body .oh-admin-redesign.oh-admin-page-operational-workboard,
body .oh-admin-redesign.oh-admin-page-data-quality,
body .oh-admin-redesign.oh-admin-page-data-linkage,
body .oh-admin-redesign.oh-admin-page-dataset-linkage,
body .oh-admin-redesign.oh-admin-page-taxonomy-aliases,
body .oh-admin-redesign.oh-admin-page-agency-links,
body .oh-admin-redesign.oh-admin-page-api-clients,
body .oh-admin-redesign.oh-admin-page-audit-logs {
    overflow: visible !important;
}

/* Stage2 운영 처리 상태 버튼/필터 */
body .oh-admin-redesign .oh-inline-check {
    display: inline-flex !important;
    align-items: center !important;
    gap: .45rem !important;
    font-weight: 800 !important;
    color: #334155 !important;
    white-space: nowrap !important;
}

body .oh-admin-redesign .oh-inline-check input[type="checkbox"] {
    width: 16px !important;
    height: 16px !important;
    min-width: 16px !important;
    min-height: 16px !important;
    margin: 0 !important;
}

body .oh-admin-redesign .oh-issue-actions,
body .oh-admin-redesign .ops-action-buttons {
    display: flex !important;
    align-items: center !important;
    gap: .4rem !important;
    flex-wrap: wrap !important;
}

body .oh-admin-redesign .secondary-button.danger,
body .oh-admin-redesign .btn.danger {
    border-color: #fecaca !important;
    color: #b91c1c !important;
    background: #fff !important;
}
