/**
 * TopCalc 댓글/피드 섹션 스타일시트
 * 유튜브 스타일 댓글 UI — 모바일 퍼스트 (480px 기준)
 * calculator_base.html 에서 로드
 */

/* ========================================
   댓글 섹션 컨테이너
   ======================================== */
.comment-section {
    background: var(--bg-gray);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    margin-top: 40px;
}

/* 섹션 공통 헤더 */
.comment-section-header {
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 2px solid var(--border);
}

.comment-section-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--text);
    margin: 0 0 4px 0;
    line-height: 1.3;
}

.comment-section-subtitle {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin: 0;
}

/* ========================================
   댓글 작성 폼
   ======================================== */
.comment-form {
    margin-bottom: var(--spacing-lg);
}

.comment-input-wrapper {
    display: flex;
    gap: var(--spacing-sm);
    align-items: flex-start;
}

/* 아바타 (사용자 아이콘 원형) */
.comment-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--border-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    margin-top: 2px;
}

/* 입력 영역 래퍼 */
.comment-input-area {
    flex: 1;
    min-width: 0;
}

/* 이름 입력 필드 */
.comment-name-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    color: var(--text);
    background: var(--bg);
    outline: none;
    margin-bottom: var(--spacing-sm);
    min-height: 36px;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* 댓글 텍스트 입력 필드 */
.comment-text-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    color: var(--text);
    background: var(--bg);
    resize: vertical;
    outline: none;
    line-height: 1.5;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 72px;
}

/* 포커스 시 파란색 테두리 */
.comment-name-input:focus,
.comment-text-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.12);
}

.comment-name-input::placeholder,
.comment-text-input::placeholder {
    color: var(--text-muted);
}

/* 폼 하단 액션 행 (글자수 + 제출 버튼) */
.comment-form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--spacing-sm);
}

/* 글자수 카운터 */
.comment-char-count {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.comment-char-count.near-limit {
    color: var(--warning);
    font-weight: 600;
}

/* 댓글 제출 버튼 */
.btn-comment-submit {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--primary);
    color: #ffffff;
    border: none;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    min-height: 36px;
}

.btn-comment-submit:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-comment-submit:disabled {
    background: var(--border-dark);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}

/* ========================================
   댓글 목록 헤더 (카운트 + 정렬)
   ======================================== */
.comments-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-sm) 0;
}

.comments-total-count {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text);
}

/* 정렬 셀렉트박스 */
.comment-sort-select {
    padding: 5px 10px;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    color: var(--text);
    background: var(--bg);
    cursor: pointer;
    outline: none;
    font-family: var(--font-family);
    transition: border-color 0.2s;
}

.comment-sort-select:focus {
    border-color: var(--primary);
}

/* ========================================
   댓글 목록 & 개별 댓글 아이템
   ======================================== */
.comments-list {
    max-height: 900px;
    overflow-y: auto;
}

/* 로딩 / 빈 상태 */
.comments-loading,
.comments-empty {
    text-align: center;
    padding: var(--spacing-xl) var(--spacing-lg);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

/* 개별 댓글 아이템 */
.comment-item {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) 0;
    border-bottom: 1px solid var(--border);
    animation: fadeInComment 0.3s ease;
}

.comment-item:last-child {
    border-bottom: none;
}

@keyframes fadeInComment {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 댓글 작성자 아바타 (소형) */
.comment-item-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
    margin-top: 2px;
}

/* 댓글 본문 컨테이너 */
.comment-item-body {
    flex: 1;
    min-width: 0;
}

/* 댓글 헤더 (작성자명 + 날짜) */
.comment-item-header {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-sm);
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.comment-author-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text);
}

.comment-posted-time {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

/* 댓글 본문 텍스트 */
.comment-item-text {
    font-size: var(--font-size-sm);
    color: var(--text);
    line-height: 1.6;
    margin-bottom: var(--spacing-sm);
    word-break: break-word;
    white-space: pre-wrap;
}

/* 댓글 액션 버튼 행 (좋아요 / 싫어요 / 답글) */
.comment-item-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

/* 좋아요 / 싫어요 그룹 */
.comment-like-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

/* 좋아요 / 싫어요 버튼 공통 */
.btn-comment-like,
.btn-comment-dislike {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: none;
    border: none;
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-family: var(--font-family);
    transition: color 0.15s, background 0.15s;
    min-height: 28px;
}

.btn-comment-like:hover {
    color: var(--primary);
    background: rgba(0, 102, 204, 0.08);
}

.btn-comment-dislike:hover {
    color: var(--error);
    background: rgba(196, 43, 43, 0.08);
}

/* 이미 투표한 상태 */
.btn-comment-like.voted {
    color: var(--primary);
    font-weight: 700;
}

.btn-comment-dislike.voted {
    color: var(--error);
    font-weight: 700;
}

/* 버튼 비활성화 */
.btn-comment-like:disabled,
.btn-comment-dislike:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 답글 버튼 */
.btn-comment-reply {
    background: none;
    border: none;
    padding: 3px 6px;
    cursor: pointer;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-family: var(--font-family);
    font-weight: 500;
    transition: color 0.15s;
    min-height: 28px;
}

.btn-comment-reply:hover {
    color: var(--primary);
}

/* ========================================
   대댓글 (답글) 영역
   ======================================== */
/* 답글 입력 폼 (댓글 바로 아래) */
.reply-form-wrapper {
    margin-top: var(--spacing-sm);
    margin-left: 44px;
    display: none;
}

.reply-form-wrapper.visible {
    display: block;
}

.reply-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-family: var(--font-family);
    color: var(--text);
    background: var(--bg);
    resize: vertical;
    outline: none;
    min-height: 60px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.reply-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.10);
}

.reply-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    margin-top: 6px;
}

/* 답글 취소 버튼 */
.btn-reply-cancel {
    background: none;
    border: 1px solid var(--border-dark);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    color: var(--text-light);
    font-family: var(--font-family);
    cursor: pointer;
    transition: background 0.2s;
    min-height: 30px;
}

.btn-reply-cancel:hover {
    background: var(--border);
}

/* 답글 등록 버튼 */
.btn-reply-submit {
    background: var(--primary);
    color: #ffffff;
    border: none;
    padding: 5px 14px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: background 0.2s;
    min-height: 30px;
}

.btn-reply-submit:hover {
    background: var(--primary-dark);
}

.btn-reply-submit:disabled {
    background: var(--border-dark);
    cursor: not-allowed;
}

/* 대댓글 목록 */
.replies-list {
    margin-top: var(--spacing-sm);
    padding-left: 44px;
}

/* 대댓글 개별 아이템 */
.reply-item {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border);
}

.reply-item:last-child {
    border-bottom: none;
}

.reply-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.reply-body {
    flex: 1;
    min-width: 0;
}

.reply-header {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-sm);
    margin-bottom: 3px;
}

.reply-author {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text);
}

.reply-time {
    font-size: 11px;
    color: var(--text-muted);
}

.reply-text {
    font-size: var(--font-size-xs);
    color: var(--text);
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

/* 더보기 버튼 */
.btn-load-more-comments {
    display: block;
    width: 100%;
    margin-top: var(--spacing-md);
    padding: 10px;
    background: var(--bg);
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    font-size: var(--font-size-sm);
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    text-align: center;
    transition: background 0.2s, color 0.2s;
}

.btn-load-more-comments:hover {
    background: var(--primary);
    color: #ffffff;
}

.comments-pagination {
    margin-top: var(--spacing-sm);
}

/* ========================================
   모바일 반응형 (480px 이하)
   ======================================== */
@media (max-width: 480px) {
    .comment-section {
        padding: var(--spacing-md);
        margin-top: 28px;
    }

    /* 폼: 아바타 숨기고 전폭 입력 */
    .comment-input-wrapper {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .comment-user-avatar {
        display: none;
    }

    .comment-input-area {
        width: 100%;
    }

    /* 목록 헤더: 세로 정렬 */
    .comments-list-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }

    /* 대댓글 들여쓰기 축소 */
    .reply-form-wrapper {
        margin-left: 20px;
    }

    .replies-list {
        padding-left: 20px;
    }

    /* 댓글 액션 버튼: 간격 축소 */
    .comment-item-actions {
        gap: 4px;
    }
}
