/* =========================================
    테마(Dark/Light) 변수 설정 (다크모드 기본)
    ========================================= */
html { background-color: #121212; }

:root {
    --bg-main: #ffffff;
    --bg-sidebar: #f7f7f5;
    --text-main: #333333;
    --text-muted: #666666;
    --border-color: #e3e3e1;
    --card-bg: #f8fbff;
    --box-bg: #fafafa;
    --hover-bg: #e8e8e5;
    --input-bg: #ffffff;
    --insight-bg: #fff4e5;
    --insight-border: #ffb067;
    --perfect-bg: #e6f4ea;
    --perfect-border: #34a853;
}

body.dark-mode {
    --bg-main: #121212;
    --bg-sidebar: #1e1e1e;
    --text-main: #e0e0e0;
    --text-muted: #999999;
    --border-color: #333333;
    --card-bg: #1e293b;
    --box-bg: #1a1a1a;
    --hover-bg: #2d2d2d;
    --input-bg: #2a2a2a;
    --insight-bg: #3d2a15;
    --insight-border: #8c5c2a;
    --perfect-bg: #132b1a;
    --perfect-border: #216e37;
}

/* 기본 리셋 및 레이아웃 (수정됨) */
body { font-family: 'Pretendard', -apple-system, sans-serif; margin: 0; padding: 0; background-color: var(--bg-main); color: var(--text-main); height: 100vh; overflow: hidden; transition: background-color 0.3s, color 0.3s; }

/* [핵심 수정] 메인 앱 화면 가로 정렬 고정 */
#appView { display: none; width: 100%; height: 100%; flex-direction: row; }
#appView[style*="block"] { display: flex !important; }

/* 로그인 컨테이너 */
.login-container { display: flex; justify-content: center; align-items: center; width: 100%; height: 100vh; background-color: var(--bg-sidebar); }
.login-box { background-color: var(--bg-main); padding: 50px; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); text-align: center; border: 1px solid var(--border-color); max-width: 400px; width: 90%; }
.login-box h1 { margin-top: 0; color: var(--text-main); font-size: 28px; }
.login-box p { color: var(--text-muted); margin-bottom: 30px; font-size: 15px; line-height: 1.5; }
.login-btn { display: inline-flex; align-items: center; justify-content: center; width: 100%; padding: 14px 20px; font-size: 16px; cursor: pointer; border: none; border-radius: 8px; background: #007AFF; color: white; font-weight: bold;}

/* 사이드바 */
.sidebar { width: 260px; flex-shrink: 0; background-color: var(--bg-sidebar); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; padding: 15px 10px; box-sizing: border-box; transition: background-color 0.3s; height: 100%; }

.sidebar-header { padding: 10px; font-weight: 600; font-size: 14px; color: var(--text-muted); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }

/* 다크모드 토글 버튼 */
.theme-toggle-btn { position: fixed; top: 20px; right: 30px; z-index: 1100; background: var(--box-bg); border: 1px solid var(--border-color); color: var(--text-main); font-size: 20px; cursor: pointer; border-radius: 50%; width: 45px; height: 45px; display: flex; justify-content: center; align-items: center; box-shadow: 0 4px 10px rgba(0,0,0,0.1); transition: transform 0.2s, background-color 0.3s; }
.theme-toggle-btn:hover { transform: scale(1.1); }

.add-project-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); padding: 0 5px; border-radius: 4px; }
.add-project-btn:hover { background-color: var(--hover-bg); color: var(--text-main); }
.sidebar-item { padding: 8px 10px; margin-bottom: 2px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; font-size: 14px; color: var(--text-main); transition: background 0.1s; }
.sidebar-item:hover { background-color: var(--hover-bg); }
.sidebar-item.active { background-color: #007AFF20; color: #007AFF; font-weight: bold; }
.sidebar-icon { margin-right: 8px; font-size: 16px; }

/* 메인 영역 */
.main-content { flex: 1; min-width: 0; padding: 40px 60px; overflow-y: auto; box-sizing: border-box; height: 100%; }
.main-container { max-width: 900px; width: 100%; margin: 0 auto; }

input.title-edit { font-family: 'Pretendard', sans-serif; font-size: 36px; font-weight: 700; border: none; outline: none; border-bottom: 2px dashed var(--text-muted); width: 100%; color: var(--text-main); background: transparent; padding: 5px 0; margin-bottom: 10px; }
input.title-edit:focus { border-bottom-color: #007AFF; }
h1.project-title { font-size: 36px; margin-top: 0; margin-bottom: 10px; font-weight: 700; color: var(--text-main); display: flex; align-items: center; gap: 10px; }
.meta-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 30px; border-bottom: 1px solid var(--border-color); padding-bottom: 20px; }
.type-badge { display: inline-block; padding: 6px 12px; background: var(--hover-bg); color: var(--text-main); border-radius: 6px; font-size: 14px; font-weight: 600; margin-right: 10px; }
.dday-badge { display: inline-block; padding: 6px 12px; background: #ffe8e6; color: #d73a49; border-radius: 6px; font-size: 14px; font-weight: 600; }
.lifetime-badge { display: inline-block; padding: 6px 12px; background: var(--perfect-bg); color: #34a853; border-radius: 6px; font-size: 14px; font-weight: 600; }

button.btn-primary { padding: 10px 20px; background-color: #007AFF; color: white; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 14px; transition: background 0.2s; }
button.btn-primary:hover { background-color: #0056b3; }
button.btn-edit { padding: 10px 20px; background-color: var(--hover-bg); color: var(--text-main); border: none; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 14px; transition: background 0.2s; }
button.btn-edit:hover { background-color: #d1d1d1; }

.input-grid { display: grid; gap: 10px; margin-bottom: 30px; background: var(--card-bg); padding: 25px; border-radius: 12px; border: 1px dashed var(--border-color); }
.input-label { font-size: 12px; color: #007AFF; margin-bottom: 6px; display: block; font-weight: 600; }
input[type="text"], input[type="date"], input[type="time"], select { padding: 10px 12px; border: 1px solid var(--border-color); border-radius: 6px; font-size: 14px; outline: none; width: 100%; box-sizing: border-box; background: var(--input-bg); color: var(--text-main); }

/* 테이블 (리스트) - 선으로 칸 나누기 적용 */
table { width: 100%; border-collapse: collapse; margin-bottom: 40px; border-top: 1px solid var(--border-color); }
th, td { padding: 15px 10px; text-align: left; border-bottom: 1px solid var(--border-color); border-right: 1px solid var(--border-color); } /* 세로선 추가 */
th:last-child, td:last-child { border-right: none; } /* 마지막 열은 세로선 제거 */
th { color: var(--text-muted); font-weight: 600; font-size: 13px; border-bottom: 2px solid var(--border-color); background-color: var(--box-bg); }
td.completed-text { text-decoration: line-through; color: var(--text-muted); }
input[type="checkbox"] { transform: scale(1.3); cursor: pointer; accent-color: #007AFF; margin: 0; }
.delete-btn { background: none; border: none; color: #ff4d4f; cursor: pointer; font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 4px; }
.time-badge { background: var(--hover-bg); padding: 4px 8px; border-radius: 6px; font-size: 12px; color: #007AFF; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }

/* 차트 및 인사이트 */
.charts-container { display: flex; flex-direction: column; gap: 40px; background: var(--box-bg); border-radius: 12px; padding: 40px; border: 1px solid var(--border-color); margin-top: 20px; }
.chart-box { position: relative; width: 100%; display: flex; justify-content: center; }
.doughnut-wrapper { height: 220px; width: 100%; max-width: 300px; margin: 0 auto; }
.line-wrapper { height: 240px; width: 100%; }

.chart-info { text-align: center; margin-bottom: 15px; font-size: 15px; font-weight: 600; }
.chart-legend { display: inline-flex; gap: 15px; font-size: 13px; font-weight: 500; margin-top: 5px; color: var(--text-muted); }
.legend-dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }

.insight-box { padding: 20px; border-radius: 12px; font-size: 15px; line-height: 1.6; border: 1px solid; margin-top: 30px; }
.insight-box.warning { background-color: var(--insight-bg); border-color: var(--insight-border); color: var(--text-main); }
.insight-box.perfect { background-color: var(--perfect-bg); border-color: var(--perfect-border); color: var(--text-main); }

#welcomeView, #projectView { display: none; }
#welcomeView.active, #projectView.active { display: block; }

/* =========================================
   커스텀 모달 (중앙 경고창/확인창)
   ========================================= */
.custom-modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); z-index: 9999; display: flex; justify-content: center; align-items: center; backdrop-filter: blur(3px); }
.custom-modal-box { background: var(--bg-main); padding: 35px 30px 25px; border-radius: 12px; border: 1px solid var(--border-color); box-shadow: 0 10px 40px rgba(0,0,0,0.3); text-align: center; min-width: 320px; max-width: 80%; animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.custom-modal-box p { color: var(--text-main); font-size: 15px; margin-top: 0; margin-bottom: 25px; line-height: 1.6; white-space: pre-wrap; font-weight: 500; }
.custom-modal-buttons { display: flex; justify-content: center; gap: 10px; }
.custom-modal-buttons button { min-width: 80px; }
@keyframes popIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* =========================================
   📱 모바일 반응형 디자인 (비율 축소 및 폼 숨김 해결)
   ========================================= */
@media screen and (max-width: 768px) {
    body { height: auto !important; overflow-y: auto !important; }
    #appView { display: flex !important; flex-direction: column !important; height: auto !important; min-height: 100vh; }
    
    .sidebar { width: 100% !important; min-width: 0 !important; max-width: 100% !important; height: auto !important; max-height: 250px; border-right: none !important; border-bottom: 1px solid var(--border-color) !important; overflow-y: auto !important; }
    .main-content { width: 100% !important; padding: 20px 15px !important; height: auto !important; overflow-y: visible !important; }

    .meta-header { flex-direction: column !important; gap: 15px !important; }
    .meta-header > div { width: 100% !important; }
    .meta-header div[style*="display: flex"] { flex-wrap: wrap !important; justify-content: flex-start !important; }

    /* [수정됨] display: flex 대신, grid를 1열(1fr)로 강제 변환하여 세로로 쌓습니다! */
    .input-grid {
        grid-template-columns: 1fr !important; 
        gap: 10px !important;
        padding: 15px !important;
    }
    .input-grid > div { width: 100% !important; }
    .input-grid button { width: 100% !important; padding: 12px !important; font-size: 15px !important; margin-top: 5px; }

    /* [수정됨] 할 일 목록 표 크기 '반 토막' 내기 */
    table { 
        display: table !important;
        width: 100% !important; 
        table-layout: fixed !important; /* 비율 고정 */
    }
    table th, table td { 
        font-size: 11px !important; /* 글씨 크기 대폭 축소 */
        padding: 6px 3px !important; /* 위아래, 좌우 여백 절반으로 축소 */
        white-space: normal !important; 
        word-break: break-word !important; 
    }
    
    /* 각 칸의 가로 비율 지정 (체크박스 15%, 시간 25%, 제목 30%, 내용 30%) */
    th:nth-child(1), td:nth-child(1) { width: 15% !important; } 
    th:nth-child(2), td:nth-child(2) { width: 25% !important; } 
    th:nth-child(3), td:nth-child(3) { width: 30% !important; } 
    th:nth-child(4), td:nth-child(4) { width: 30% !important; } 

    /* 안쪽 시간 배지(파란색) 크기도 축소 */
    .time-badge { font-size: 9px !important; padding: 3px 5px !important; }
    /* 체크박스 크기도 모바일에 맞게 축소 */
    input[type="checkbox"] { transform: scale(1) !important; }
}

/* =========================================
   모바일 전용: 사이드바 + 버튼 위치 왼쪽으로 이동
   ========================================= */
@media screen and (max-width: 768px) {
    #sidebarHeaderDiv {
        justify-content: flex-start !important;
        gap: 10px !important;
    }
    #sidebarAddBtn {
        order: 1 !important; /* + 버튼을 왼쪽(첫 번째)으로 배치 */
    }
    #sidebarTitleText {
        order: 2 !important; /* 글자를 오른쪽(두 번째)으로 배치 */
        flex: none !important; 
    }
}

/* =========================================
   🚀 랜딩 페이지(히어로 + 상세 설명) 스타일 
   ========================================= */
.landing-title {
    font-size: 3.5rem;
    font-weight: 900;
    line-height: 1.3;
    margin-bottom: 20px;
    letter-spacing: -1.5px;
    color: var(--text-main);
    word-break: keep-all;
}

.landing-subtitle {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 45px;
    line-height: 1.6;
    word-break: keep-all;
}

.landing-btn {
    font-size: 1.1rem;
    padding: 16px 32px;
    border-radius: 50px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: none;
    cursor: pointer;
    color: white;
    font-weight: bold;
}

.landing-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

/* 🌟 상세 설명 영역 (지그재그 레이아웃) */
.landing-features-container {
    width: 100%;
    max-width: 1000px;
    margin: 120px auto 0 auto;
    display: flex;
    flex-direction: column;
    gap: 120px;
    padding: 0 20px;
    text-align: left;
}

.feature-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 60px;
}

.feature-row.reverse {
    flex-direction: row-reverse;
}

.feature-text {
    flex: 1;
}

.feature-text h3 {
    font-size: 2.2rem;
    font-weight: 800;
    margin-bottom: 20px;
    line-height: 1.4;
    color: var(--text-main);
    word-break: keep-all;
    letter-spacing: -1px;
}

.feature-text p {
    font-size: 1.15rem;
    color: var(--text-muted);
    line-height: 1.6;
    word-break: keep-all;
}

.feature-img-box {
    flex: 1;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    border: 1px solid var(--border-color);
    background-color: var(--hover-bg); /* 이미지가 없을 때 빈 공간 색상 */
    min-height: 250px; 
    display: flex;
    align-items: center;
    justify-content: center;
}

.feature-img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

/* 모바일 반응형 조정 */
@media (max-width: 768px) {
    .landing-title { font-size: 2.2rem; }
    .landing-subtitle { font-size: 1rem; }
    .landing-features-container { gap: 80px; margin-top: 80px; }
    .feature-row, .feature-row.reverse { flex-direction: column; text-align: center; gap: 30px; }
    .feature-text h3 { font-size: 1.8rem; }
}