/*
 * 직원관리 하이브리드(모바일·PC) 공통 스타일
 * - 뷰포트 safe-area, 터치 영역, 모바일 edge-to-edge 레이아웃
 */
html { overflow-x: hidden; }
body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}
.main { padding-bottom: max(8px, env(safe-area-inset-bottom)); overflow-x: hidden; }
.app { overflow-x: hidden; max-width: 100%; }
.toast { bottom: max(12px, env(safe-area-inset-bottom)); }

button, a, [role="button"], .nav-item, .btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid var(--card-border, #E2E8F0);
    background: var(--card, #fff);
    border-radius: var(--radius, 6px);
    cursor: pointer;
    font-size: 18px;
    color: var(--primary-dark, #20509e);
    margin-right: 8px;
    flex-shrink: 0;
}
.mobile-menu-btn:hover { background: var(--primary-light, #E8F0FE); }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 998;
}
.sidebar-backdrop.show { display: block; }

/* ── 768px 이하: 드로어 + 화면 꽉 채우기 ── */
@media (max-width: 768px) {
    .mobile-menu-btn { display: flex; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        max-width: 85vw;
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.1);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar.open { transform: translateX(0); }

    .main {
        padding: 0 !important;
        margin: 0 !important;
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }
    .main-body {
        padding: 4px !important;
    }
    .main-header {
        padding: 6px 4px !important;
        gap: 6px !important;
    }
    .main-header h2 { font-size: 15px !important; }

    .card,
    .schedule-card {
        max-width: none;
        margin-left: 0;
        margin-right: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        box-shadow: none;
    }

    .v6-related-nav {
        padding: 4px 2px !important;
        gap: 4px !important;
        row-gap: 4px !important;
    }
    .v6-related-nav a,
    .v6-related-nav .current {
        padding: 4px 6px !important;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
    }
    .v6-related-nav .v6-related-label { display: none; }

    .filter-bar { gap: 4px !important; width: 100%; }
    .filter-bar input,
    .filter-bar select { flex: 1 1 auto; min-width: 0 !important; }

    .btn, .nav-item {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .nav-item { min-height: 44px; padding: 10px 12px; }

    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0; }
    .stat-row { grid-template-columns: repeat(2, 1fr) !important; gap: 6px; }
    .grid-2 { grid-template-columns: 1fr !important; gap: 8px; }
    .quick-links { gap: 4px; }
    .quick-link { padding: 6px 10px; font-size: 11px; flex: 0 0 auto; }
    .section-body { max-height: 220px; }
    .url-box { flex-direction: column; }
    .url-box input { width: 100%; }
    .perm-grid { grid-template-columns: 1fr !important; }
    .settings-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
    .settings-tab { white-space: nowrap; flex-shrink: 0; }

    .mobile-menu-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        margin-right: 4px !important;
    }

    /* 달력 */
    .cal-day .cal-chip-remove { display: none !important; }
    .cal-day .badge { max-width: 100%; box-sizing: border-box; }
    .cal-grid,
    .schedule-calendar-single,
    .schedule-calendar-wrap { max-width: 100%; overflow-x: hidden; }

    .col-visibility-wrap { margin: 0; }
    .toast { left: 4px; right: 4px; }

    /* 일정표 모바일 하단 고정 바 */
    .schedule-mobile-bar {
        display: none;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 900;
        gap: 8px;
        padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        background: rgba(255,255,255,0.96);
        border-top: 1px solid var(--card-border, #E2E8F0);
        box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
        backdrop-filter: blur(8px);
    }
    .schedule-mobile-bar-btn {
        flex: 1;
        min-height: 48px;
        border: 1px solid var(--card-border, #E2E8F0);
        border-radius: 10px;
        background: #fff;
        font-size: 14px;
        font-weight: 600;
        font-family: inherit;
        color: var(--text, #1E293B);
        cursor: pointer;
    }
    .schedule-mobile-bar-btn.primary {
        background: var(--primary, #31599A);
        border-color: var(--primary, #31599A);
        color: #fff;
    }
    .schedule-mobile-bar-btn:disabled {
        opacity: 0.45;
        cursor: not-allowed;
    }
    .main-body { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .schedule-mobile-bar { display: flex; }
    .main-body { padding-bottom: calc(64px + env(safe-area-inset-bottom)) !important; }
    .export-wrap .export-btn { min-height: 44px; font-size: 12px; }
    .cal-day { min-height: 52px; }
    .cal-day .badge { font-size: 10px; padding: 3px 4px; }
}

/* ── 480px 이하: 여백 추가 축소 ── */
@media (max-width: 480px) {
    .main-body { padding: 2px !important; }
    .main-header { padding: 4px 2px !important; gap: 4px !important; }

    .dashboard {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        padding: 6px 4px 0;
    }
    .dash-card .dash-value { font-size: 20px; }
    .settings-tabs { flex-wrap: wrap; }
    .settings-tab { padding: 8px 10px; font-size: 11px; }
    .cal-modal { min-width: 0; max-width: 100vw; border-radius: 0; }

    .v6-related-nav { padding: 2px 0 !important; }
    .filter-bar select,
    .filter-bar input { font-size: 11px; padding: 6px 8px; }
}

.v6-related-nav {
    display: none !important;
}

/* 출퇴근·관리 화면에서도 마이페이지로 항상 이동 가능 */
.jt-mypage-fab {
    position: fixed;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(18px, calc(12px + env(safe-area-inset-bottom)));
    z-index: 9800;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 11px 14px;
    border-radius: 999px;
    background: #2D78F5;
    color: #fff !important;
    text-decoration: none !important;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -0.02em;
    box-shadow: 0 8px 24px rgba(45, 120, 245, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.25);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.jt-mypage-fab:hover { filter: brightness(1.05); color: #fff !important; }
.jt-mypage-fab:active { transform: scale(0.97); }
.jt-mypage-fab[hidden] { display: none !important; }
.jt-mypage-fab-icon { font-size: 15px; line-height: 1; }

/* 멤버 하단 탭이 입력 UI에 가려지지 않도록 */
.bottom-nav {
    z-index: 5000 !important;
}

@media (max-width: 768px) {
    .jt-mypage-fab {
        bottom: max(18px, calc(12px + env(safe-area-inset-bottom)));
        padding: 12px 15px;
        font-size: 13px;
        min-height: 44px;
    }
    /* 하단 탭·일정표 저장바가 있을 때 FAB를 그 위로 올림 */
    body:has(.bottom-nav) .jt-mypage-fab,
    body:has(.schedule-mobile-bar) .jt-mypage-fab {
        bottom: max(78px, calc(72px + env(safe-area-inset-bottom)));
    }
}

/* ── 공통 네비게이션 사이드바 스타일 (데스크톱 및 공통) ── */
.app {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    width: 260px;
    min-width: 180px;
    max-width: 480px;
    flex-shrink: 0;
    background: var(--card, #fff) !important;
    border-right: 1px solid var(--card-border, rgba(217,222,233,0.6)) !important;
    display: flex !important;
    flex-direction: column !important;
    z-index: 10 !important;
}
.sidebar-header {
    padding: 16px 14px !important;
    background: linear-gradient(135deg, #2D78F5, #5B8DEF) !important;
    color: white !important;
}
.sidebar-header h1 {
    font-size: 16px !important;
    font-weight: 700 !important;
    letter-spacing: -0.03em !important;
    margin-bottom: 0 !important;
}
.sidebar-header p {
    font-size: 11px !important;
    opacity: 0.9 !important;
    margin-top: 3px !important;
    margin-bottom: 0 !important;
}
.sidebar-nav {
    padding: 12px !important;
    border-bottom: 1px solid var(--card-border, rgba(217,222,233,0.6)) !important;
    flex: 1 !important;
    overflow-y: auto !important;
}
aside.sidebar .nav-item, nav.sidebar-nav a {
    display: block !important;
    padding: 9px 12px !important;
    border-radius: 8px !important;
    color: var(--text-2, #515867) !important;
    text-decoration: none !important;
    font-weight: 600 !important;
    margin-bottom: 4px !important;
    transition: all 0.2s ease !important;
    border-left: none !important;
}
aside.sidebar .nav-item:hover, nav.sidebar-nav a:hover {
    background: var(--primary-light, #E7F0FD) !important;
    color: var(--primary-dark, #216EE3) !important;
}
aside.sidebar .nav-item.active, nav.sidebar-nav a.active {
    background: var(--primary, #2D78F5) !important;
    color: white !important;
    box-shadow: 0 2px 8px rgba(45,120,245,0.25) !important;
    font-weight: 700 !important;
    border-left: none !important;
}
.main {
    flex: 1;
    min-width: 0;
}

/* 일정표 2차 사이드바 조율 */
#main-navigation-sidebar {
    border-right: 1px solid var(--card-border, rgba(217,222,233,0.6));
}

/*
 * 직원일정표: PC에서는 메인 메뉴를 고정 컬럼으로 두지 않고 드로어로만 연다.
 * (직원목록 사이드바와 나란히 두면 ~520px을 먹음)
 * 「☰ 메뉴」 버튼 → #main-navigation-sidebar.open + backdrop
 */
@media (min-width: 769px) {
    .app:has(#schedule-sidebar) #main-navigation-sidebar {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: 260px !important;
        max-width: 85vw !important;
        z-index: 1000 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.25s ease !important;
        box-shadow: 4px 0 24px rgba(0,0,0,0.14) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .app:has(#schedule-sidebar) #main-navigation-sidebar.open {
        transform: translateX(0) !important;
    }
}

@media (max-width: 768px) {
    /* 모바일 반응형일 때 사이드바 둘 다 드로어 처리 */
    .sidebar {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: 260px !important;
        max-width: 85vw !important;
        z-index: 999 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.25s ease !important;
        box-shadow: 4px 0 20px rgba(0,0,0,0.1) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .sidebar.open {
        transform: translateX(0) !important;
    }
}
