/* =========================================
   1. 전역 변수 (색상 및 테마 정의)
   ========================================= */
:root {
    --bg-main: #f5f5f7;
    --bg-card: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --accent-color: #0071e3;
    --accent-hover: #0077ed;
    --danger-color: #ff3b30;
    --border-color: #d2d2d7;
    --input-bg: #e8e8ed;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --shadow-soft: 0 4px 20px rgba(0,0,0,0.08);

    --free-bg: #ffffff;
    --free-accent: #f2f2f7; 

    --comment-line: #e5e5ea;
    --reply-bg: #f5f5f7;
    
    /* 채택(Accepted) 전용 색상 (라이트) */
    --gold-main: #ffb340;
    --bg-accepted: #fffbf2;
    --border-accepted: #ffcc80;
}

[data-theme="dark"] {
    --bg-main: #000000;
    --bg-card: #1c1c1e;
    --text-primary: #f5f5f7;
    --text-secondary: #86868b;
    --accent-color: #2997ff;
    --accent-hover: #47a3ff;
    --input-bg: #2c2c2e;
    --glass-bg: rgba(28, 28, 30, 0.85);
    --border-color: #3a3a3c;
    --shadow-soft: 0 4px 20px rgba(0,0,0,0.4);

    --free-bg: #1c1c1e;
    --free-accent: #2c2c2e;

    --comment-line: #38383a;
    --reply-bg: #2c2c2e;

    --gold-main: #d4a036;
    --bg-accepted: rgba(255, 179, 64, 0.08);
    --border-accepted: rgba(255, 179, 64, 0.4);
}

/* =========================================
   2. 기본 리셋 및 유틸리티
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Pretendard', sans-serif; }
body { background-color: var(--bg-main); color: var(--text-primary); padding-bottom: 100px; transition: background 0.3s; }
a { text-decoration: none; color: inherit; }
button { font-family: inherit; }
.hidden { display: none !important; }

.desktop-only { display: block; }
.mobile-only { display: none; }

/* 헤더 */
.simple-header { height: 60px; background: var(--glass-bg); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 100; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; }
.header-flex { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
.logo { font-size: 1.3rem; font-weight: 800; color: var(--text-primary); }
.logo span { color: var(--accent-color); }
.header-right { display: flex; align-items: center; gap: 10px; }
.text-btn { background: none; border: none; color: var(--accent-color); font-size: 0.95rem; cursor: pointer; padding: 5px 10px; }
.text-btn.bold { font-weight: 600; }
.user-welcome { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); margin-right: 5px; }

/* =========================================
   3. 메인 레이아웃
   ========================================= */
.main-layout-container { display: flex; gap: 40px; margin-top: 30px; align-items: flex-start; min-height: 80vh; }

.sidebar-left { width: 220px; position: sticky; top: 90px; flex-shrink: 0; transition: opacity 0.3s; }
.sidebar-title { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 15px; padding-left: 10px; }
.category-nav { display: flex; flex-direction: column; gap: 5px; }
.cat-item { background: none; border: none; text-align: left; padding: 12px 15px; border-radius: 12px; color: var(--text-secondary); font-size: 1rem; cursor: pointer; display: flex; align-items: center; gap: 10px; transition: all 0.2s; }
.cat-item:hover { background: var(--bg-card); color: var(--text-primary); }
.cat-item.active { background: var(--bg-card); color: var(--accent-color); font-weight: 600; box-shadow: var(--shadow-soft); }

.mobile-category-bar { display: none; overflow-x: auto; gap: 8px; margin-bottom: 20px; padding-bottom: 5px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.mobile-category-bar::-webkit-scrollbar { display: none; }
.m-cat-item { white-space: nowrap; flex-shrink: 0; padding: 8px 16px; border-radius: 20px; border: 1px solid var(--border-color); background: var(--bg-card); color: var(--text-secondary); font-size: 0.9rem; font-weight: 500; cursor: pointer; transition: all 0.2s; }
.m-cat-item.active { background: var(--accent-color); color: white; border-color: var(--accent-color); font-weight: 600; }

.feed-content { flex: 1; min-width: 0; }
.feed-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.section-title { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); }
.sort-select { padding: 5px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-card); color: var(--text-primary); }

.tab-menu-container { display: flex; gap: 10px; margin-bottom: 25px; padding: 4px; background: var(--input-bg); border-radius: 16px; width: fit-content; }
.tab-btn { flex: 1; padding: 10px 24px; border-radius: 12px; border: none; background: transparent; color: var(--text-secondary); font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s ease; white-space: nowrap; }
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { background: var(--bg-card); color: var(--text-primary); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

/* =========================================
   4. 게시글 스타일
   ========================================= */
.qna-style { background: var(--bg-card); border-radius: 16px; padding: 24px; margin-bottom: 16px; border: 1px solid var(--border-color); cursor: pointer; transition: all 0.2s ease; }
.qna-style:hover { transform: translateY(-3px); box-shadow: var(--shadow-soft); border-color: var(--accent-color); }
.qna-style .post-meta-top { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 10px; }
.qna-style .badge { background: rgba(0,113,227,0.1); color: var(--accent-color); padding: 4px 8px; border-radius: 6px; font-weight: 600; font-size: 0.8rem; }
.qna-style .post-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 8px; color: var(--text-primary); }
.qna-style .post-preview { font-size: 0.95rem; color: var(--text-secondary); line-height: 1.5; margin-bottom: 15px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.free-style { background: var(--free-bg); border-radius: 20px; padding: 20px; margin-bottom: 16px; cursor: pointer; transition: all 0.2s; border: 1px solid transparent; box-shadow: 0 2px 8px rgba(0,0,0,0.05); display: flex; flex-direction: column; }
.free-style:hover { background: var(--free-accent); transform: scale(1.01); }
.free-style .post-header-flex { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.free-style .free-icon { color: #ff9f0a; font-size: 1.1rem; }
.free-style .post-title { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); margin: 0; flex: 1; }
.free-style .post-preview { font-size: 0.95rem; color: var(--text-secondary); margin-bottom: 10px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.post-footer { display: flex; justify-content: space-between; align-items: center; color: var(--text-secondary); border-top: 1px solid var(--border-color); padding-top: 12px; margin-top: auto;}
.free-style .post-footer { border-top-style: dashed; padding-top: 8px; font-size: 0.8rem; }
.post-stats { display: flex; gap: 12px; font-size: 0.85rem; }

/* =========================================
   5. 모달 및 폼
   ========================================= */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); backdrop-filter: blur(5px); z-index: 1000; display: flex; justify-content: center; align-items: center; opacity: 1; transition: opacity 0.3s; }
.modal-overlay.hidden { opacity: 0; pointer-events: none; }
.modal-box { background: var(--bg-card); width: 90%; max-width: 680px; border-radius: 16px; display: flex; flex-direction: column; max-height: 90vh; overflow: hidden; box-shadow: var(--shadow-soft); transition: transform 0.3s; transform: scale(0.95); opacity: 0; }
.modal-overlay:not(.hidden) .modal-box { transform: scale(1); opacity: 1; }

.modal-header { padding: 15px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; overflow-y: auto; }
.close-modal { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-secondary); }

.input-field { width: 100%; padding: 12px; margin-bottom: 12px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--input-bg); font-size: 0.95rem; color: var(--text-primary); outline: none; transition: border 0.2s; }
.input-field:focus { border-color: var(--accent-color); }
.textarea-field { width: 100%; padding: 12px; margin-bottom: 12px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--input-bg); font-size: 0.95rem; color: var(--text-primary); outline: none; resize: none; min-height: 100px; }
.textarea-field:focus { border-color: var(--accent-color); }

.btn-primary { background: var(--accent-color); color: white; border: none; padding: 12px; border-radius: 12px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: background 0.2s; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--input-bg); color: var(--text-primary); border: none; padding: 10px 16px; border-radius: 10px; cursor: pointer; font-weight: 500; transition: 0.2s; }
.btn-secondary:hover { background: #dcdce0; }
.full-width { width: 100%; }

.file-input-wrapper { margin-bottom: 15px; display: flex; align-items: center; }
.hidden-file-input { display: none; }
.file-label { background: var(--input-bg); padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; color: var(--text-primary); transition: background 0.2s; border: 1px solid var(--border-color); display: flex; align-items: center; gap: 6px; }
.file-label:hover { background: var(--border-color); }

.detail-image-area { margin-bottom: 20px; text-align: center; }
.detail-post-image { max-width: 100%; max-height: 400px; border-radius: 12px; box-shadow: var(--shadow-soft); object-fit: contain; }

.board-type-selector { display: flex; gap: 10px; margin-bottom: 15px; }
.radio-label { flex: 1; cursor: pointer; }
.radio-label input { display: none; }
.radio-btn-ui { display: flex; justify-content: center; align-items: center; padding: 10px; border-radius: 10px; border: 1px solid var(--border-color); background: var(--input-bg); color: var(--text-secondary); font-weight: 600; transition: all 0.2s; }
.radio-label input:checked + .radio-btn-ui { background: var(--accent-color); color: white; border-color: var(--accent-color); box-shadow: 0 4px 10px rgba(0,113,227,0.3); }

/* 게시글 상세 */
.detail-box { height: 90vh; }
.detail-header-info { padding: 0 20px; margin-top: 15px; }
.badge-large { font-size: 0.9rem; background: rgba(0,113,227,0.1); color: var(--accent-color); padding: 5px 10px; border-radius: 6px; font-weight: 600; }
.detail-title { font-size: 1.4rem; margin: 10px 0; color: var(--text-primary); }
.detail-meta-row { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 10px; }
.post-detail-body { flex: 1; overflow-y: auto; padding-top: 0; }
.detail-content-text { font-size: 1rem; line-height: 1.6; color: var(--text-primary); min-height: 100px; white-space: pre-wrap; }
.detail-actions { margin-top: 20px; display: flex; justify-content: flex-end; }

/* 댓글 시스템 UI */
.comment-section { margin-top: 30px; border-top: 1px solid var(--border-color); padding-top: 25px; }
.comment-header { margin-bottom: 20px; font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.comment-list { display: flex; flex-direction: column; gap: 0; margin-bottom: 25px; }

.comment-item { padding: 18px 0; border-bottom: 1px solid var(--comment-line); display: flex; flex-direction: column; }
.comment-flex-container { display: flex; gap: 15px; width: 100%; }

.c-avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--input-bg); color: var(--text-secondary); display: flex; align-items: center; justify-content: center; font-size: 1.6rem; flex-shrink: 0; }
.c-main { flex: 1; min-width: 0; }
.c-meta { margin-bottom: 5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.c-author { font-weight: 700; font-size: 0.95rem; color: var(--text-primary); }
.c-date { font-size: 0.8rem; color: var(--text-secondary); }
.c-text { font-size: 1rem; color: var(--text-primary); line-height: 1.5; white-space: pre-wrap; margin-bottom: 8px; word-break: break-word; }

.c-actions-row { display: flex; gap: 12px; align-items: center; }
.c-act-btn { background: none; border: none; font-size: 0.85rem; color: var(--text-secondary); cursor: pointer; padding: 0; font-weight: 500; transition: color 0.2s; }
.c-act-btn:hover { color: var(--text-primary); text-decoration: underline; }
.c-act-btn.delete { color: var(--danger-color); }

/* 채택 버튼 */
.c-act-btn.adopt { 
    color: var(--gold-main); 
    border: 1.5px solid var(--gold-main); 
    padding: 4px 12px; 
    border-radius: 20px; 
    font-size: 0.8rem; 
    text-decoration: none !important; 
    font-weight: 700;
    transition: all 0.2s;
}
.c-act-btn.adopt:hover { background: var(--gold-main); color: white; transform: scale(1.05); }

/* 대댓글 */
.reply-wrapper { margin-top: 10px; margin-left: 50px; display: flex; flex-direction: column; gap: 10px; }
.reply-item { background: var(--reply-bg); padding: 12px 15px; border-radius: 12px; display: flex; gap: 10px; position: relative; }
.reply-item::before { content: ''; position: absolute; left: -15px; top: 15px; width: 10px; height: 10px; border-left: 2px solid var(--border-color); border-bottom: 2px solid var(--border-color); border-bottom-left-radius: 8px; }

/* 채택된 댓글 */
.comment-item.accepted { background: var(--bg-accepted); border: 1px solid var(--border-accepted); border-radius: 16px; padding: 20px; margin-bottom: 10px; border-bottom: none; box-shadow: 0 4px 12px rgba(255, 179, 64, 0.15); }
.comment-item.accepted::after { content: "✨ 채택된 답변"; display: block; width: fit-content; margin-top: 10px; font-size: 0.8rem; font-weight: bold; color: #d48806; background: rgba(255, 215, 0, 0.2); padding: 4px 10px; border-radius: 20px; }

/* 댓글 입력창 */
.comment-input-area { display: flex; gap: 8px; position: relative; }
.comment-input-area input { flex: 1; padding: 12px 15px; border-radius: 24px; border: 1px solid var(--border-color); background: var(--input-bg); color: var(--text-primary); outline: none; transition: all 0.2s; }
.comment-input-area input:focus { background: var(--bg-card); border-color: var(--accent-color); box-shadow: 0 0 0 3px rgba(0,113,227,0.1); }
.comment-input-area button { width: 42px; height: 42px; border-radius: 50%; background: var(--accent-color); color: white; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1rem; transition: transform 0.2s; }
.comment-input-area button:hover { transform: scale(1.1); background: var(--accent-hover); }

/* 하단 독 */
.bottom-dock-container { position: fixed; bottom: 20px; left: 0; width: 100%; display: flex; justify-content: center; pointer-events: none; z-index: 500; }
.glass-dock { pointer-events: auto; background: rgba(255, 255, 255, 0.7); backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px); border: 1px solid rgba(255, 255, 255, 0.5); padding: 10px 20px; border-radius: 24px; display: flex; align-items: center; gap: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); transition: background 0.3s; }
[data-theme="dark"] .glass-dock { background: rgba(30, 30, 30, 0.7); border-color: rgba(255, 255, 255, 0.1); box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.dock-icon-btn { width: 44px; height: 44px; border-radius: 50%; border: none; background: rgba(255,255,255,0.5); font-size: 1.2rem; color: var(--text-primary); cursor: pointer; transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); display: flex; justify-content: center; align-items: center; }
.dock-icon-btn:hover { transform: scale(1.15) translateY(-5px); background: #fff; box-shadow: 0 5px 15px rgba(0,0,0,0.1); }
[data-theme="dark"] .dock-icon-btn { background: rgba(255,255,255,0.1); }
[data-theme="dark"] .dock-icon-btn:hover { background: rgba(255,255,255,0.2); }
.dock-divider { width: 1px; height: 24px; background: var(--border-color); }
.dock-icon-btn.main-accent { background: var(--accent-color); color: white; box-shadow: 0 4px 12px rgba(0,113,227,0.3); }
.dock-icon-btn.ai-accent { background: linear-gradient(135deg, #6e45e2, #88d3ce); color: white; box-shadow: 0 4px 12px rgba(110,69,226,0.3); }
.dock-icon-btn.main-accent:hover, .dock-icon-btn.ai-accent:hover { background: var(--accent-hover); color: white; box-shadow: 0 4px 12px rgba(0,113,227,0.3); }

.ai-chat-body { padding: 20px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; background: var(--bg-main); }
.ai-input-area { padding: 15px; background: var(--bg-card); display: flex; gap: 10px; border-top: 1px solid var(--border-color); }
.ai-input-area input { flex: 1; padding: 12px; border-radius: 20px; border: 1px solid var(--border-color); background: var(--input-bg); outline: none; color: var(--text-primary); }
.ai-input-area button { background: var(--accent-color); color: white; border: none; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; }
.chat-message { display: flex; }
.user-msg { justify-content: flex-end; } .ai-msg { justify-content: flex-start; }
.bubble { max-width: 80%; padding: 12px 16px; border-radius: 18px; line-height: 1.5; font-size: 0.95rem; }
.user-msg .bubble { background: var(--accent-color); color: white; border-bottom-right-radius: 4px; }
.ai-msg .bubble { background: var(--bg-card); border: 1px solid var(--border-color); border-bottom-left-radius: 4px; color: var(--text-primary); }

.level-info-card { background: var(--input-bg); border-radius: 16px; padding: 20px; margin: 20px 0; display: flex; justify-content: space-between; align-items: center; }
.profile-avatar-large { width: 80px; height: 80px; background: var(--input-bg); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 2.5rem; margin: 0 auto 10px; color: var(--text-secondary); border: 2px solid var(--border-color); }
.rank-badge { font-size: 1.1rem; font-weight: bold; padding: 6px 15px; background: white; border-radius: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); color: #333; }
.point-display { text-align: right; }
.point-value { font-size: 1.5rem; font-weight: 800; color: var(--accent-color); }
.center-text { text-align: center; }
.alert-modal { text-align: center; padding: 30px; width: 300px; }
.alert-modal p { font-size: 1.1rem; margin-bottom: 20px; word-break: keep-all; }
.z-high { z-index: 2000; }

/* 로그인 체크박스 스타일 */
.login-options { margin-bottom: 20px; display: flex; align-items: center; }
.custom-checkbox-wrapper { display: flex; align-items: center; cursor: pointer; user-select: none; font-size: 0.95rem; color: var(--text-primary); }
.custom-checkbox-wrapper input { display: none; }
.custom-checkbox-icon { width: 20px; height: 20px; border: 2px solid var(--border-color); border-radius: 6px; display: flex; align-items: center; justify-content: center; margin-right: 8px; color: white; transition: all 0.2s; background: var(--bg-card); }
.custom-checkbox-wrapper input:checked + .custom-checkbox-icon { background-color: var(--accent-color); border-color: var(--accent-color); }
.custom-checkbox-wrapper:hover .custom-checkbox-icon { border-color: var(--accent-color); }

@media (max-width: 768px) {
    .main-layout-container { display: block; margin-top: 10px; }
    .sidebar-left { display: none; }
    .mobile-only { display: flex; }
    .board-wrapper { padding-bottom: 80px; }
    .qna-style { padding: 20px; }
    .modal-box { width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
    .bottom-dock-container { bottom: 15px; }
}