/* ==========================================================================
   1-Minute Philosophy: 대담(Dialogue) 전용 스타일시트 (css/chat.css)
   ========================================================================== */

/* 1. 기존 style.css 이관 스타일 */
/* 철학자와의 대담 페이지 전용 스타일 */
.philosopher-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px 0 80px 0;
    /* 하단 탭 바에 의해 카드가 가려지는 현상 예방 */
}

@media (min-width: 480px) {
    .philosopher-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.philosopher-card {
    background: #FFFFFF;
    border-radius: 18px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.03);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    gap: 16px;
}

.philosopher-card:active {
    transform: scale(0.98);
}

.philosopher-avatar {
    width: 36px;
    height: 43px;
    background: #F2F2F7;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
}

.philosopher-info {
    flex: 1;
}

.philosopher-name {
    font-family: 'Elms Sans', 'Isamanru', sans-serif;
    font-size: 16px;
    color: #1D1D1F;
    margin-bottom: 4px;
    font-weight: 700;
}

.philosopher-slogan {
    font-size: 12px;
    color: #86868B;
}

.chat-window {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    /* 사파리/크롬 높이 상속 유실 방지 */
    overflow: hidden;
    /* 영역 밖으로 흘러넘치는 컨텐츠 차단 */
    position: relative;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    /* 메시지 영역 오버플로우 방지 및 스크롤바 활성화 */
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    /* 모바일 부드러운 스크롤 */
    padding: 16px 16px 24px 16px;
    /* 과도한 하단 패딩 제거하고 깔끔한 24px 할당 */
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-bubble-wrapper {
    display: flex;
    gap: 10px;
    max-width: 98%;
}

.chat-bubble-wrapper.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-bubble-wrapper.ai {
    align-self: flex-start;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    background: #F2F2F7;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-bubble {
    font-family: 'Elms Sans', 'GothicA1', sans-serif;
    font-weight: 500;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-break: break-all;
}

.chat-bubble-wrapper.user .chat-bubble {
    background: #1D1D1F;
    color: #FFFFFF;
    border-top-right-radius: 4px;
}

.chat-bubble-wrapper.ai .chat-bubble {
    background: #F2F2F7;
    color: #1D1D1F;
    border-top-left-radius: 4px;
}

.chat-bubble-wrapper.system .chat-bubble {
    background: #FFF9E6;
    color: #8A6D3B;
    border: 1px solid #FBEED5;
    font-size: 12px;
}

.chat-input-bar {
    position: relative;
    /* absolute 포지셔닝 탈피하여 flex 흐름으로 안착 */
    background: #FFFFFF;
    padding: 10px 16px 14px 16px;
    /* 좌우 여백을 두어 모바일에서 인풋 창이 단정하게 배치되도록 개선 */
    display: flex;
    gap: 10px;
    align-items: flex-end;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    width: 100%;
}

.chat-input {
    flex: 1;
    border: none;
    background: #F2F2F7;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    font-family: 'GothicA1', sans-serif;
    color: #1D1D1F;
    resize: none;
    height: 38px;
    max-height: 120px;
    line-height: 1.4;
    box-sizing: border-box;
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    background: #1D1D1F;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.chat-send-btn:active {
    transform: scale(0.9);
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
    stroke: #FFFFFF;
    stroke-width: 2.5;
    fill: none;
}

.chat-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #F2F2F7;
    border-radius: 18px;
    border-top-left-radius: 4px;
    width: fit-content;
    align-self: flex-start;
    margin-left: 42px;
    align-items: center;
}

.chat-typing-dot {
    width: 6px;
    height: 6px;
    background: #86868B;
    border-radius: 50%;
    animation: typing-dot 1.2s infinite ease-in-out;
}

.chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-dot {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-4px);
    }
}

/* 대담 페이지 전체를 모바일 화면에 꽉 맞추는 Flex 컨테이너 아키텍처 */
#page-chat {
    display: none;
    /* 평소에는 완전히 숨겨 터치 간섭 원천 배제 */
    height: 100vh !important;
    height: 100dvh !important;
    /* 모던 모바일 브라우저 주소창 유동성 완벽 대응 */
    position: relative !important;
    box-sizing: border-box !important;
    padding-top: 20px !important;
    /* 파싱 실패 대비 폴백 */
    padding-top: calc(env(safe-area-inset-top) + 10px) !important;
    /* 상단 안전 구역 확보 (상단 짤림 방지) */
    padding-bottom: calc(65px + env(safe-area-inset-bottom)) !important;
    /* 하단 탭바 높이 차감 */
    overflow: hidden !important;
}

#page-chat.active {
    display: flex !important;
    flex-direction: column !important;
    /* 대담 활성화 시에만 켜짐 */
}

#chatPageHeader {
    flex-shrink: 0 !important;
    padding: 12px 24px 10px 24px !important;
    background: #FFFFFF !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03) !important;
    z-index: 10 !important;
}

#chatPageContent {
    flex: 1 !important;
    min-height: 0 !important;
    /* 자식 스크롤 가둠 (모바일 스크롤 먹통 완벽 해결) */
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    position: relative !important;
}

#chatPageContent:has(.chat-window) {
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    /* 자식이 전체 높이를 상속받아 flex할 수 있도록 배치 */
}

.fallback-warning-badge {
    background: rgba(255, 149, 0, 0.08);
    border: 1px solid rgba(255, 149, 0, 0.15);
    border-radius: 12px;
    padding: 8px 12px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fadeIn 0.3s ease-in-out;
}

/* 2. js/chat.js 인라인 스타일 마이그레이션 클래스 */

/* 시스템 메시지 마진 */
.chat-bubble-wrapper.system {
    align-self: center;
    margin: 10px 0;
}

/* 타이핑 대기 상태 */
.chat-bubble-wrapper.ai.typing {
    align-self: flex-start;
    margin-top: 6px;
}

.chat-bubble.typing-bubble {
    background: #F2F2F7;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    border-radius: 18px;
    border-top-left-radius: 4px;
}

.chat-typing-text {
    font-size: 12px;
    color: #86868B;
    font-weight: 600;
    font-family: 'GothicA1', sans-serif;
    margin-right: 4px;
}

/* 프리미엄 멤버십 배너 */
.chat-premium-banner {
    background: #F2F2F7;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid rgba(0, 0, 0, 0.02);
}

.chat-premium-title {
    font-size: 14px;
    font-weight: 700;
    color: #1D1D1F;
    margin-bottom: 4px;
}

.chat-premium-subtitle {
    font-size: 12px;
    color: #86868B;
}

.chat-premium-btn {
    font-family: 'Elms Sans', 'Isamanru', sans-serif;
    font-size: 11px;
    padding: 6px 12px;
    margin: 0;
}

/* 대담방 리스트 화살표 */
.chat-list-chevron {
    color: #C7C7CC;
    font-size: 18px;
}

/* 대담 소개글 */
.chat-intro-desc {
    font-size: 14px;
    color: #86868B;
    margin-bottom: 16px;
    line-height: 1.5;
    font-family: 'GothicA1', sans-serif;
}

/* 대담방 헤더 영역 */
.chat-room-header {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.chat-back-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
}

.chat-back-icon {
    width: 24px;
    height: 24px;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-title {
    font-size: 17px;
    font-family: 'Isamanru', sans-serif;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-header-slogan {
    font-size: 11px;
    color: #86868B;
    font-weight: 400;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 폴백 경고 배지 내부 */
.fallback-warning-emoji {
    font-size: 14px;
}

.fallback-warning-text {
    flex: 1;
}

.fallback-warning-title {
    font-size: 11px;
    font-weight: 700;
    color: #FF9500;
    margin: 0;
    font-family: 'Elms Sans', 'Isamanru', sans-serif;
}

.fallback-warning-subtitle {
    font-size: 9px;
    color: #FF9500;
    opacity: 0.85;
    margin: 2px 0 0 0;
    font-family: 'GothicA1', sans-serif;
    line-height: 1.3;
}

/* AI 에러 상황 */
.chat-bubble-wrapper.ai.error {
    margin-top: 6px;
}

.chat-bubble.error-bubble {
    background: rgba(255, 59, 48, 0.08);
    border: 1px solid rgba(255, 59, 48, 0.15);
    color: #FF3B30;
    font-size: 12px;
    font-family: 'GothicA1', sans-serif;
    line-height: 1.4;
    padding: 10px 14px;
    border-radius: 18px;
    border-top-left-radius: 4px;
}

.chat-error-detail {
    font-size: 10px;
    margin: 4px 0 0 0;
    opacity: 0.8;
    font-family: 'GothicA1', sans-serif;
    word-break: break-all;
}

/* 철학자 고해상도 PNG 아바타 이미지 스타일 */
.philosopher-avatar img,
.chat-avatar img,
.chat-header-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.chat-header-avatar {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

/* ==========================================================================
   잡담/대담 모드용 애플 순정형 Segmented Control 스타일
   ========================================================================== */
.chat-mode-control {
    display: inline-flex;
    background: #E5E5EA;
    /* Apple System Gray 6 */
    border-radius: 8px;
    padding: 2px;
    flex-shrink: 0;
    align-items: center;
    margin-right: 20px;
}

.chat-mode-btn {
    border: none;
    background: none;
    font-size: 11px;
    font-family: 'Elms Sans', 'Isamanru', sans-serif;
    font-weight: 600;
    color: #8E8E93;
    /* Apple System Gray */
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

.chat-mode-btn.active {
    background: #FFFFFF;
    color: #1D1D1F;
    /* Apple Primary Text */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chat-mode-btn:active:not(.active) {
    background: rgba(0, 0, 0, 0.05);
}

/* AI 답변 신고/리포트 UGC 대응 스타일 */
.chat-report-btn {
    background: none;
    border: none;
    font-size: 10px;
    color: #8E8E93;
    cursor: pointer;
    padding: 2px 4px;
    display: flex;
    align-items: center;
    gap: 3px;
    opacity: 0.6;
    transition: opacity 0.2s;
    font-family: 'Elms Sans', 'GothicA1', sans-serif;
}

.chat-report-btn:hover,
.chat-report-btn:active {
    opacity: 1;
}

/* ==========================================================================
   모바일 키보드 활성화 시 네이티브/웹뷰 리사이즈 대응 스타일 
   ========================================================================== */
body.keyboard-visible #page-chat {
    padding-bottom: env(safe-area-inset-bottom) !important;
    height: 100% !important;
}

/* 키보드가 보일 때 하단 탭 바도 물리적으로 사라지거나 숨김 처리 */
body.keyboard-visible .tab-bar,
body.keyboard-visible #tab-bar {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(100%) !important;
    transition: opacity 0.15s ease, transform 0.15s ease !important;
}