<!DOCTYPE html>
<html lang="ko">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Project Master Overseas 관리자</title>
    <link rel="stylesheet" as="style" crossorigin
        href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css" />
    <link rel="stylesheet" href="style/common.css">
    <link rel="stylesheet" href="style/dashboard.css">
</head>

<body>

    <nav class="topbar">
        <div class="topbar-header">
            <a href="/">
                <h2>Project Master Test</h2>
            </a>
        </div>
        <ul class="nav-list">
            <li class="nav-item active" onclick="location.href='/dashboard'">대시보드</li>
            <li class="nav-item" onclick="location.href='/inquiries'">문의사항</li>
            <li class="nav-item" onclick="location.href='/mailTest'">메일관리</li>
            <li class="nav-item" onclick="location.href='/analysis'">분석</li>
        </ul>
    </nav>

    <main class="main-content">
        <header>
            <h2>프로젝트 현황</h2>
            <div class="header-actions" style="display: flex; align-items: center; gap: 15px;">
                <div class="base-date-info">기준날짜: <strong id="baseDate">-</strong></div>
                <button id="syncBtn" class="sync-btn" onclick="syncData()">
                    <span class="spinner"></span>
                    데이터 동기화
                </button>
                <div class="admin-info">접속자: <strong>이태훈[전체관리자]</strong></div>
            </div>
        </header>

        <!-- 프로젝트 활성도 대시보드 (전체 너비 래퍼) -->
        <div class="activity-dashboard-wrapper">
            <div id="activityDashboard" class="activity-dashboard">
                <!-- JS에서 동적 삽입 -->
            </div>
        </div>

        <!-- 실시간 로그 콘솔 (본문 내부로 복구) -->
        <div id="logConsole" class="log-console" style="display:none;">
            <div class="log-console-header">실시간 수집 로그 [PM Overseas]</div>
            <div id="logBody"></div>
        </div>

        <div id="projectAccordion">
            <!-- Multi-level Accordion items will be generated here -->
        </div>
    </main>

    <!-- 모달 레이어 (공통 규격 적용) -->
    <div id="authModal" class="modal-overlay">
        <div class="modal-content" style="max-width: 440px; padding: 40px; text-align: center;" onclick="event.stopPropagation()">
            <div class="auth-header" style="margin-bottom: 32px;">
                <i class="fas fa-lock" style="font-size: 32px; color: var(--primary-color); margin-bottom: 16px; display: block;"></i>
                <h3 style="font-size: 20px; font-weight: 800; color: #111; margin-bottom: 8px;">크롤링 권한 인증</h3>
                <p style="font-size: 13px; color: var(--text-sub);">시스템 동기화를 위해 관리자 계정으로 로그인하세요.</p>
            </div>
            <div class="auth-body" style="display: flex; flex-direction: column; gap: 20px; text-align: left; margin-bottom: 32px;">
                <div class="input-group">
                    <label>관리자 아이디</label>
                    <input type="text" id="authId" placeholder="아이디를 입력하세요">
                </div>
                <div class="input-group">
                    <label>비밀번호</label>
                    <input type="password" id="authPw" placeholder="비밀번호를 입력하세요"
                        onkeyup="if(event.key==='Enter') submitAuth()">
                </div>
                <div id="authErrorMessage" class="error-text" style="display:none; color: var(--error-color); font-size: 12px; font-weight: 600; text-align: center; margin-top: -10px;">크롤링을 할 수 없습니다.</div>
            </div>
            <div class="auth-footer" style="display: grid; grid-template-columns: 1fr 1.5fr; gap: 12px;">
                <button class="btn btn-secondary" style="height: 48px;" onclick="ModalManager.close('authModal')">취소</button>
                <button class="btn btn-primary" style="height: 48px;" onclick="submitAuth()">인증 및 실행</button>
            </div>
        </div>
    </div>

    <div id="activityDetailModal" class="modal-overlay" onclick="ModalManager.close('activityDetailModal')">
        <div class="modal-content" style="max-width: 600px; padding: 0; overflow: hidden;" onclick="event.stopPropagation()">
            <div class="modal-header" style="padding: 20px; margin-bottom: 0;">
                <h3 id="modalTitle">상세 목록</h3>
                <span class="modal-close" onclick="ModalManager.close('activityDetailModal')">&times;</span>
            </div>
            <div class="modal-body" style="padding: 20px; max-height: 70vh; overflow-y: auto;">
                <table class="data-table">
                    <thead>
                        <tr>
                            <th>프로젝트명</th>
                            <th>담당부서</th>
                            <th>담당자</th>
                        </tr>
                    </thead>
                    <tbody id="modalTableBody">
                        <!-- JS에서 동적 삽입 -->
                    </tbody>
                </table>
            </div>
            <div style="padding: 16px 20px; border-top: 1px solid var(--border-color); text-align: right; background: #fdfdfd;">
                <button class="btn btn-secondary" onclick="ModalManager.close('activityDetailModal')">닫기</button>
            </div>
        </div>
    </div>

    <script src="js/common.js"></script>
    <script src="js/dashboard.js"></script>
</body>

</html>