/* ══════════════════════════════════════════════════════════
   어니스트 OS — 컴팩트 아이콘 사이드바 (v1)
   body.compact-sidebar 클래스가 활성일 때만 적용
   원본 CSS는 건드리지 않고 오버라이드만으로 구성
   ══════════════════════════════════════════════════════════ */

body.compact-sidebar {
    --ctx-w: 64px;
    --ctx-w-expanded: 240px;
}

/* ── 사이드바 본체: 64px 좁게 + 호버/포커스 시 240px 확장 ── */
body.compact-sidebar .context-panel {
    width: 64px;
    transition: width .18s ease;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    padding: 10px 0 24px;
    box-shadow: 1px 0 0 rgba(15, 23, 42, 0.02);
    overflow: visible; /* 호버 팝오버 위해 */
    position: relative;
    z-index: 20;
}
body.compact-sidebar .context-panel:hover,
body.compact-sidebar .context-panel:focus-within,
body.compact-sidebar .context-panel.compact-pinned {
    width: 240px;
    box-shadow: 4px 0 16px rgba(15, 23, 42, 0.06);
}

/* ── 섹션 헤더: 기본 숨김, 확장 시 표시
   (원본 .ctx-section-header + patch-ui-cleanup.js가 교체한 .v48-nav-group-toggle 둘 다 처리) ── */
body.compact-sidebar .ctx-section-header,
body.compact-sidebar .v48-nav-group-toggle {
    opacity: 0;
    height: 0 !important;
    padding: 0 16px !important;
    margin: 0 !important;
    overflow: hidden;
    transition: opacity .15s, height .18s;
    white-space: nowrap;
    border: 0;
}
body.compact-sidebar .context-panel:hover .ctx-section-header,
body.compact-sidebar .context-panel:focus-within .ctx-section-header,
body.compact-sidebar .context-panel.compact-pinned .ctx-section-header,
body.compact-sidebar .context-panel:hover .v48-nav-group-toggle,
body.compact-sidebar .context-panel:focus-within .v48-nav-group-toggle,
body.compact-sidebar .context-panel.compact-pinned .v48-nav-group-toggle {
    opacity: 1;
    height: auto !important;
    padding: 12px 16px 6px !important;
}

/* ── 구분선: 기본 좁은 점선, 확장 시 풀 라인 ── */
body.compact-sidebar .ctx-divider {
    margin: 6px 18px;
    background: #cbd5e1;
    height: 2px;
    border-radius: 2px;
    opacity: 0.4;
    transition: opacity .15s, margin .15s;
}
body.compact-sidebar .context-panel:hover .ctx-divider,
body.compact-sidebar .context-panel:focus-within .ctx-divider,
body.compact-sidebar .context-panel.compact-pinned .ctx-divider {
    opacity: 0.6;
    margin: 8px 12px;
    background: #e2e8f0;
}

/* ── 네비 버튼: 기본은 아이콘만, 확장 시 라벨 노출 ── */
body.compact-sidebar .ctx-nav-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 0 0 20px;
    height: 44px;
    margin: 2px 8px;
    border-radius: 10px;
    gap: 12px;
    overflow: hidden;
    position: relative;
    width: calc(100% - 16px);
    /* 축소 상태: 텍스트 노드(라벨)를 font-size:0으로 숨김 — 확장 시 13px로 복원 */
    font-size: 0;
    font-weight: 600;
    color: #475569;
    background: transparent;
    white-space: nowrap;
    transition: background .12s, color .12s, font-size .15s;
}
/* 확장 상태에서 라벨 텍스트 복원 */
body.compact-sidebar .context-panel:hover .ctx-nav-item,
body.compact-sidebar .context-panel:focus-within .ctx-nav-item,
body.compact-sidebar .context-panel.compact-pinned .ctx-nav-item {
    font-size: 13px;
}
body.compact-sidebar .ctx-nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    stroke-width: 1.8;
    transition: transform .12s;
}
body.compact-sidebar .ctx-nav-item > *:not(svg) {
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity .15s ease, transform .15s ease;
    pointer-events: none;
}
body.compact-sidebar .context-panel:hover .ctx-nav-item > *:not(svg),
body.compact-sidebar .context-panel:focus-within .ctx-nav-item > *:not(svg),
body.compact-sidebar .context-panel.compact-pinned .ctx-nav-item > *:not(svg) {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

/* ── 활성 상태: 파란 바 + 연한 배경 ── */
body.compact-sidebar .ctx-nav-item.ctx-active,
body.compact-sidebar .ctx-nav-item.active {
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 700;
}
body.compact-sidebar .ctx-nav-item.ctx-active::before,
body.compact-sidebar .ctx-nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10px;
    bottom: 10px;
    width: 3px;
    background: #2563eb;
    border-radius: 0 4px 4px 0;
}
body.compact-sidebar .ctx-nav-item.ctx-active svg,
body.compact-sidebar .ctx-nav-item.active svg {
    color: #2563eb;
}
body.compact-sidebar .ctx-nav-item:hover {
    background: #f1f5f9;
    color: #0f172a;
}
body.compact-sidebar .ctx-nav-item:hover svg {
    transform: scale(1.05);
}

/* ── 뱃지(ex: todoBadge) 위치: 축소 상태에서 아이콘 우상단 ── */
body.compact-sidebar .ctx-nav-item .todo-badge-style,
body.compact-sidebar .ctx-nav-item [class*="Badge"] {
    position: absolute;
    top: 6px;
    left: 32px;
    margin: 0 !important;
    font-size: 9px;
    padding: 1px 5px;
    min-width: 14px;
    text-align: center;
    background: #ef4444;
    color: white;
    border-radius: 999px;
    font-weight: 900;
    line-height: 1.3;
}
body.compact-sidebar .context-panel:hover .ctx-nav-item .todo-badge-style,
body.compact-sidebar .context-panel:focus-within .ctx-nav-item .todo-badge-style,
body.compact-sidebar .context-panel.compact-pinned .ctx-nav-item .todo-badge-style {
    position: static;
    margin-left: auto !important;
    background: #fef3c7;
    color: #92400e;
}

/* ── 워크스페이스 셀렉트(프로젝트 드롭다운): 기본 숨김, 확장 시 노출 ── */
body.compact-sidebar .ctx-workspace-select {
    opacity: 0;
    height: 0;
    overflow: hidden;
    padding: 0 10px;
    transition: opacity .15s, height .18s;
}
body.compact-sidebar .context-panel:hover .ctx-workspace-select,
body.compact-sidebar .context-panel:focus-within .ctx-workspace-select,
body.compact-sidebar .context-panel.compact-pinned .ctx-workspace-select {
    opacity: 1;
    height: auto;
    padding: 4px 10px 8px;
}

/* ── 고정(핀) 버튼: 사이드바 하단에 추가 ── */
body.compact-sidebar .compact-pin-btn {
    position: absolute;
    bottom: 12px;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 32px; height: 32px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    color: #64748b;
    z-index: 10;
    transition: all .12s;
}
body.compact-sidebar .compact-pin-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}
body.compact-sidebar .context-panel.compact-pinned .compact-pin-btn {
    background: #dbeafe;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

/* ── 메인 콘텐츠: 좁아진 사이드바만큼 가용 너비 증가 ── */
body.compact-sidebar .main-content {
    min-width: 0;
}
body.compact-sidebar .content-area {
    max-width: none;           /* 1400px 제한 풀기 */
    padding: 24px 28px 40px;   /* 좌우 패딩 축소 */
}

/* ══════════════════════════════════════════════════════════
   Flat-Design Patch — 프레임-인-프레임(박스 안 박스) 제거
   재무 대시보드 / 팀관리 / 전사집계 영역의 중첩 카드 평탄화
   ══════════════════════════════════════════════════════════ */

/* 중첩된 카드가 한 번 더 감싸질 때 바깥 박스의 테두리/그림자를 지움
   (.ctx-card / .card / .box 안에 .ctx-card / .card 가 또 들어가는 경우) */
body.compact-sidebar .ctx-card .ctx-card,
body.compact-sidebar .ctx-card .card,
body.compact-sidebar .card .ctx-card,
body.compact-sidebar .card .card,
body.compact-sidebar .bg-white.rounded-xl .bg-white.rounded-xl,
body.compact-sidebar .bg-white.rounded-2xl .bg-white.rounded-xl,
body.compact-sidebar .bg-white.rounded-2xl .bg-white.rounded-2xl {
    box-shadow: none !important;
    border: 0 !important;
    background: transparent !important;
    padding: 12px !important;
}

/* 대시보드 위젯 헤더: 어두운 배경 바 대신 플랫 텍스트 헤더 */
body.compact-sidebar .dashboard-widget-title,
body.compact-sidebar .widget-header-dark,
body.compact-sidebar .section-header-dark {
    background: transparent !important;
    color: #0f172a !important;
    border-bottom: 1px solid #e2e8f0;
    padding: 14px 16px;
    font-weight: 800;
    font-size: 13px;
    letter-spacing: 0.01em;
}

/* 테이블 헤더의 무거운 진한-회색 톤을 플랫화 */
body.compact-sidebar table thead th[style*="background:#1e293b"],
body.compact-sidebar table thead th[style*="background: #1e293b"],
body.compact-sidebar table thead[style*="background:#0f172a"] th {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    font-weight: 800;
    border-bottom: 2px solid #cbd5e1 !important;
}

/* 홈 대시보드의 기능 카드 영역: 일관된 라운드/패딩 */
body.compact-sidebar .home-widget,
body.compact-sidebar .dashboard-card {
    border-radius: 14px;
    border: 1px solid #e5e7eb;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
body.compact-sidebar .home-widget .home-widget,
body.compact-sidebar .dashboard-card .dashboard-card {
    border: 0;
    box-shadow: none;
    background: transparent;
}

/* ── 칸반 보드가 잘리지 않도록 가로 스크롤 허용 ── */
body.compact-sidebar #todoKanban,
body.compact-sidebar .kanban-container,
body.compact-sidebar .todo-kanban {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding-bottom: 12px;
}
body.compact-sidebar #todoKanban > *,
body.compact-sidebar .kanban-container > *,
body.compact-sidebar .todo-kanban > * {
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* ── 햄버거 트리거 버튼 (기본 숨김, 모바일에서만 표시) ── */
body.compact-sidebar .compact-ham-btn {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 100;
    width: 40px; height: 40px;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    color: #0f172a;
}

/* 오버레이 배경 (사이드바 열릴 때) */
body.compact-sidebar .compact-overlay-bg {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 30;
}
body.compact-sidebar.mob-menu-open .compact-overlay-bg {
    display: block;
}

/* ── 모바일: 컴팩트 사이드바는 숨기고 풀스크린 오버레이로 전환 ── */
@media (max-width: 900px) {
    body.compact-sidebar .compact-ham-btn {
        display: flex;
    }
    body.compact-sidebar .context-panel {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        width: 260px;
        max-width: 80vw;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
        z-index: 40;
        transition: transform .22s ease;
        padding-top: 56px;
    }
    body.compact-sidebar.mob-menu-open .context-panel {
        transform: translateX(0);
    }
    /* 모바일 오버레이 모드에서는 확장된 모습 강제 */
    body.compact-sidebar .context-panel .ctx-nav-item {
        font-size: 13px !important;
    }
    body.compact-sidebar .context-panel .ctx-section-header,
    body.compact-sidebar .context-panel .v48-nav-group-toggle {
        opacity: 1 !important;
        height: auto !important;
        padding: 12px 16px 6px !important;
    }
    /* 핀 버튼은 모바일에서 숨김 (항상 오버레이 모드) */
    body.compact-sidebar .compact-pin-btn {
        display: none;
    }
}

/* ══════════════════════════════════════════════════════════
   모바일 폴리시 (v342+) — 홈 헤더, WBS 테이블, 프로젝트 상세
   ══════════════════════════════════════════════════════════ */

/* 홈 헤더 — 태블릿 이하: 6카드 → 3열 */
@media (max-width: 900px) {
    #homeHeader > div[style*="grid-template-columns"]:first-of-type {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    #homeHeader > div[style*="grid-template-columns"] button {
        min-width: 0 !important;
    }
}

/* 홈 헤더 — 모바일: 6카드 → 2열, 확장 카드(주간 마감/최근 프로젝트) → 1열 */
@media (max-width: 600px) {
    #homeHeader {
        padding: 14px 12px !important;
    }
    #homeHeader > div[style*="grid-template-columns"]:first-of-type {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }
    #homeHeader > div[style*="grid-template-columns"]:first-of-type button {
        padding: 8px 10px !important;
    }
    #homeHeader > div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    /* 인사말 영역 폰트 축소 */
    #homeHeader .text-xl {
        font-size: 1rem !important;
    }
}

/* WBS/이슈 등 넓은 테이블 — 모바일에서 가로 스크롤 + 얇은 스크롤바 */
@media (max-width: 900px) {
    .content-area table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    .content-area table thead,
    .content-area table tbody,
    .content-area table tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }
    .content-area table::-webkit-scrollbar { height: 6px; }
    .content-area table::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
}

/* 프로젝트 상세 — 카드 패딩 축소, 헤더 2줄 허용 */
@media (max-width: 600px) {
    .content-area .ctx-card,
    .content-area .bg-white.rounded-xl {
        padding: 12px !important;
    }
    .content-area .ctx-card h1,
    .content-area .ctx-card h2 {
        font-size: 1rem !important;
        line-height: 1.3 !important;
    }
    /* 툴바/헤더 버튼은 가로 스크롤 허용 */
    .toolbar, .ctx-toolbar, #projectToolbar {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    /* 모달 본체 모바일 최적화 — 좌우 여백 축소 */
    .modal-body, [id$="ModalBody"] {
        padding: 16px !important;
    }
    /* 재무 카드 그리드 2열 → 1열 */
    .fin-grid, .fin-summary-grid {
        grid-template-columns: 1fr !important;
    }
}

/* 홈 나의 일정 위젯 — 모바일 패딩 축소 */
@media (max-width: 600px) {
    #myScheduleWidget {
        padding: 12px !important;
    }
    #myScheduleWidget .ms-list-item {
        font-size: 12px !important;
    }
}

/* ══════════════════════════════════════════════════════════
   홈 헤더 확장 extras 그리드 — 반응형 열 축소 (v5.1)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
    .home-header-extras {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}
@media (max-width: 640px) {
    .home-header-extras {
        grid-template-columns: 1fr !important;
    }
}
