/**
 * AI 프로젝트 생성 채팅 페이지 전용 스타일
 * 기존 chatting.jsp 스타일을 참고하되 별도 스타일로 관리
 */

/* ===== 페이지 레이아웃 ===== */
.ai-chat-page {
    min-height: 100vh;
    background: linear-gradient(180deg, #F0FDF4 0%, #F7F8F9 100%);
    padding-bottom: 40px;
}

.ai-chat-header {
    text-align: center;
    padding: 100px 20px 48px;
}

.ai-chat-title {
    font-size: 29px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0 0 8px 0;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
}

.ai-chat-title .enerai-brand {
    color: #23AB72;
    font-weight: 800;
}

.ai-chat-title .enerai-title-logo {
    height: 26px;
    width: auto;
    margin: -3px 2px;
}

.ai-chat-title .ai-suffix {
    font-style: italic;
}

.ai-chat-subtitle {
    font-size: var(--market-font-16);
    font-weight: 500;
    color: #727F85;
    margin: 0;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
}

.ai-chat-main {
    max-width: 1070px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ===== 뒤로가기 링크 ===== */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--market-font-15);
    font-weight: 500;
    color: #727F85;
    text-decoration: none;
    /*margin-bottom: 16px;*/
    transition: color 0.2s;
}

.back-link:hover {
    color: #304248;
}

/* ===== 채팅 컨테이너 ===== */
.ai-chat-container {
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ===== 채팅 메시지 영역 ===== */
.ai-chat-messages {
    flex: 1;
    min-height: 500px;
    height: 500px;
    max-height: 1000px;
    overflow-y: auto;
    padding: 0 24px 0 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: #FFFFFF;
    border: 1px solid #E2E5EC;
    border-radius: 16px;
    box-shadow: 0px 2px 16px rgba(17, 50, 59, 0.08);
    position: relative;
}

.chat-messages-overlay {
    position: sticky;
    pointer-events: none;
    z-index: 10;
    flex-shrink: 0;
    background: #FFFFFF;
}

.chat-messages-overlay-top {
    top: 0;
    height: 40px;
    margin-bottom: -40px;
    background: linear-gradient(to bottom, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%);
    order: -1;
}

.chat-messages-overlay-bottom {
    position: sticky;
    bottom: -1px;
    height: 24px;
    margin-top: -24px;
    background: linear-gradient(to top, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%);
    order: 999;
    align-self: stretch;
    /*border-radius: 0 0 16px 16px;*/
}

.ai-chat-messages::-webkit-scrollbar {
    width: 8px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #E2E5EC;
    border-radius: 4px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #C6CBCE;
}

/* ===== 메시지 공통 스타일 ===== */
.chat-message {
    display: flex;
    gap: 12px;
}

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

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

/* ===== 아바타 ===== */
.message-avatar {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #F7F8F9;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: none;
}

.user-message .message-avatar {
    background: #E2E5EC;
}

.user-message .message-avatar img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

/* ===== 메시지 내용 ===== */
.message-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 650px;
}

.message-bubble {
    padding: 12px;
    font-size: var(--market-font-15);
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
    word-wrap: break-word;
    max-width: 625px;
    width: fit-content;
    min-width: 0;
}

.ai-message .message-bubble {
    background: white;
    border-top-right-radius: 20px;
    border-bottom-right-radius: 20px;
    border-bottom-left-radius: 20px;
    outline: 1px #E2E5EC solid;
    outline-offset: -1px;
    color: #304248;
    font-weight: 500;
    line-height: 1.4;
}

/* 타이핑 애니메이션: 커서 (입력 중에는 고정, 완료 시 깜빡임) */
.ai-message .message-bubble .typing-cursor {
    display: inline;
    color: #304248;
    font-weight: 400;
    margin-left: 1px;
    vertical-align: text-bottom;
}

.ai-message .message-bubble .typing-cursor.typing-cursor-blink {
    animation: typing-cursor-blink 1000ms step-end infinite;
}

@keyframes typing-cursor-blink {
    50% {
        opacity: 0;
    }
}

.user-message .message-bubble {
    background: #23AB72;
    border-radius: 16px 0 16px 16px;
    color: #FFFFFF;
}

.message-bubble p {
    margin: 0 0 8px 0;
    line-height: 1.4;
    letter-spacing: -0.1px;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

/* ===== 역할 태그 뱃지 (초기 메시지) ===== */
.role-tag-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.role-badge {
    padding: 8px 14px;
    background: #FFFFFF;
    border: 1px solid #E2E5EC;
    border-radius: 16px;
    font-size: var(--market-font-14);
    font-weight: 500;
    color: #304248;
    cursor: pointer;
    transition: all 0.2s;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
}

.role-badge:hover {
    background: #F0FDF4;
    border-color: #23AB72;
    color: #23AB72;
}

/* ===== 파일 칩 (메시지 내) ===== */
.message-files {
    display: flex !important;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}

.file-chip {
    display: inline-flex !important;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    padding: 6px 10px;
    background: #E2E5EC;
    border-radius: 8px;
    outline: 0.50px #E2E5EC solid;
    outline-offset: -0.50px;
    font-size: var(--market-font-13);
    font-weight: 500;
    color: #304248;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
    visibility: visible !important;
    opacity: 1 !important;
    word-wrap: break-word;
    max-width: 100%;
}

.file-chip .file-name {
    color: #304248;
    font-size: var(--market-font-13);
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 500;
    word-wrap: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-message .file-chip {
    background: #E2E5EC !important;
    outline: 0.50px #E2E5EC solid !important;
    outline-offset: -0.50px !important;
    color: #304248 !important;
}

/* ===== 로딩 스피너 (AI 응답 중) ===== */
.loading-spinner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0;
    background: transparent;
}

.loading-spinner .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    animation: loading-pulse 1.4s infinite ease-in-out both;
}

.loading-spinner .dot:nth-child(1) {
    background: #304248;
    animation-delay: -0.48s;
}

.loading-spinner .dot:nth-child(2) {
    background: #5A6A70;
    animation-delay: -0.32s;
}

.loading-spinner .dot:nth-child(3) {
    background: #8A9A9E;
    animation-delay: -0.16s;
}

.loading-spinner .dot:nth-child(4) {
    background: #C6CBCE;
    animation-delay: 0s;
}

@keyframes loading-pulse {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.6;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.loading-message .loading-message-text {
    margin: 12px 0 0 0;
    font-size: var(--market-font-14);
    color: #727F85;
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* ===== 액션 버튼 (매칭 의뢰하기 등) ===== */
.message-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.action-btn {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: var(--market-font-16);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
    border: none;
}

.action-btn.primary {
    background: #304248;
    color: #FFFFFF;
}

.action-btn.primary:hover {
    background: #1EA86E;
}

.action-btn.secondary {
    background: #304248;
    color: #FFFFFF;
}

.action-btn.secondary:hover {
    background: #1a2a30;
}

.action-btn.outline {
    background: #FFFFFF;
    color: #304248;
    border: 1px solid #E2E5EC;
}

.action-btn.outline:hover {
    background: #F7F8F9;
    border-color: #C6CBCE;
}

/* ===== 입력창 영역 (메시지 영역과 시각적 분리) ===== */
.ai-chat-input-area {
    flex-shrink: 0;
    padding: 20px 24px;
    background: #FFFFFF;
    border: 1px solid #E2E5EC;
    border-radius: 16px;
    box-shadow: 0px 2px 8px rgba(17, 50, 59, 0.06);
}

/* 첨부 파일 칩 컨테이너 */
.attached-files-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #E2E5EC;
}

.attached-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #F7F8F9;
    border: 1px solid #E2E5EC;
    border-radius: 16px;
    font-size: var(--market-font-13);
    font-weight: 500;
    color: #304248;
    max-width: 250px;
}

.attached-file-chip .file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}

.attached-file-chip .remove-file {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: #727F85;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.attached-file-chip .remove-file:hover {
    background: #E53935;
}

.attached-file-chip .remove-file svg {
    width: 10px;
    height: 10px;
}

/* 메시지 입력 wrapper */
.chat-input-wrapper {
    margin-bottom: 12px;
}

.message-input {
    width: 100%;
    min-height: 24px;
    max-height: 120px;
    padding: 0;
    border: none;
    outline: none;
    resize: none;
    font-size: var(--market-font-16);
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 500;
    line-height: 1.6;
    color: #727F85;
    background: transparent;
}

.message-input::placeholder {
    color: #C6CBCE;
}

/* 하단 액션 영역 */
.chat-input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.attach-file-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.attach-file-btn:hover {
    background: #F7F8F9;
}

.attach-file-btn svg {
    color: #727F85;
}

.send-btn,
.send-btn,
.stop-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.send-btn {
    background: #23AB72;
    color: #FFFFFF;
}

.send-btn:disabled {
    background: #E2E5EC;
    color: #C6CBCE;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    background: #1EA86E;
}

.stop-btn {
    background: transparent;
    padding: 0;
}

.stop-btn-inner {
    width: 100%;
    height: 100%;
    padding: 8px;
    background: #E2E5EC;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.stop-btn-icon {
    width: 14px;
    height: 14px;
    background: #F16E5C;
    border-radius: 2px;
}

.stop-btn:hover .stop-btn-inner {
    background: #C6CBCE;
}

/* 비활성화 상태 입력창 */
.ai-chat-input-area.disabled {
    opacity: 0.7;
}

.ai-chat-input-area.disabled .message-input {
    background: transparent;
    pointer-events: none;
}

.ai-chat-input-area.disabled .attach-file-btn {
    pointer-events: none;
}

.ai-chat-input-area.disabled .stop-btn {
    pointer-events: auto;
    cursor: pointer;
}

/* 입력창 로딩 메시지 */
.input-loading-message {
    font-size: var(--market-font-15);
    font-weight: 500;
    color: #1a1a1a;
}

/* ===== 하단 경고 문구 ===== */
.ai-chat-disclaimer {
    text-align: center;
    font-size: var(--market-font-15);
    font-weight: 500;
    color: #304248;
    margin: 16px 0 0 0;
}

/* ===== 반응형 스타일 ===== */
@media (max-width: 768px) {
    .ai-chat-header {
        padding: 30px 16px 20px;
    }

    .ai-chat-title {
        font-size: 23px;
    }

    .ai-chat-title .enerai-title-logo {
        height: 22px;
    }

    .ai-chat-subtitle {
        font-size: var(--market-font-15);
    }

    .ai-chat-main {
        padding: 0 16px;
    }

    .ai-chat-messages {
        padding: 0 24px 0 24px;
    }

    .chat-message {
        max-width: 95%;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
    }

    .role-tag-badges {
        gap: 6px;
    }

    .role-badge {
        padding: 6px 12px;
        font-size: var(--market-font-13);
    }
}

/* ===== 완료 상태 스타일 ===== */
.chat-completed .ai-chat-input-area {
    display: none;
}

/* AI 메시지 마크다운 스타일 */
.ai-message .message-bubble h1,
.ai-message .message-bubble h2,
.ai-message .message-bubble h3,
.ai-message .message-bubble h4 {
    margin: 16px 0 8px 0;
    font-weight: 700;
    line-height: 1.4;
    color: #1a1a1a;
}

.ai-message .message-bubble h1:first-child,
.ai-message .message-bubble h2:first-child,
.ai-message .message-bubble h3:first-child,
.ai-message .message-bubble h4:first-child {
    margin-top: 0;
}

.ai-message .message-bubble h1 { font-size: 1.25rem; }
.ai-message .message-bubble h2 { font-size: 1.125rem; }
.ai-message .message-bubble h3 { font-size: 1rem; }
.ai-message .message-bubble h4 { font-size: 0.9375rem; }

.ai-message .message-bubble ul,
.ai-message .message-bubble ol {
    margin: 8px 0;
    padding-left: 1.5em;
}

.ai-message .message-bubble ol {
    list-style-type: decimal;
}

.ai-message .message-bubble ul {
    list-style-type: disc;
}

.ai-message .message-bubble ol > li {
    margin-bottom: 4px;
    display: list-item;
    list-style: decimal;
}

.ai-message .message-bubble ul > li {
    margin-bottom: 4px;
    display: list-item;
    list-style: disc;
}

.ai-message .message-bubble strong {
    font-weight: 700;
}

.ai-message .message-bubble code {
    background: #E2E5EC;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

.ai-message .message-bubble a {
    color: #23AB72;
    text-decoration: underline;
}

.ai-message .message-bubble a:hover {
    color: #1EA86E;
}

/* ===== 진행중인 대화 확인 모달 ===== */
.existing-chat-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.existing-chat-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.existing-chat-modal-content {
    position: relative;
    background: #FFFFFF;
    border-radius: 16px;
    padding: 24px;
    max-width: 430px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(17, 50, 59, 0.2);
    z-index: 10001;
}

.existing-chat-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.existing-chat-modal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.existing-chat-modal-title {
    font-size: var(--market-font-19);
    font-weight: 700;
    color: #304248;
    margin: 0;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
}

.existing-chat-modal-message {
    font-size: var(--market-font-14);
    font-weight: 400;
    color: #304248;
    line-height: 20px;
    margin: 0 0 24px 0;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
}

.existing-chat-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 32px;
}

.existing-chat-modal-btn {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: var(--market-font-15);
    font-weight: 700;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    width: 128px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.existing-chat-modal-btn-cancel {
    background: #F7F8F9;
    color: #304248;
}

.existing-chat-modal-btn-cancel:hover {
    background: #E2E5EC;
}

.existing-chat-modal-btn-continue {
    background: #23AB72;
    color: #FFFFFF;
}

.existing-chat-modal-btn-continue:hover {
    background: #23AB72;
}

.existing-chat-modal-btn-new {
    background: #E2E5EC;
    color: #304248;
}

.existing-chat-modal-btn-new:hover {
    background: #E2E5EC;
}

/* ===== 페이지 이탈 방지 모달 ===== */
.leave-confirm-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.leave-confirm-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.leave-confirm-modal-content {
    position: relative;
    background: #FFFFFF;
    border-radius: 16px;
    padding: 32px;
    max-width: 431px;
    max-height: 214px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(17, 50, 59, 0.2);
    z-index: 10001;
}

.leave-confirm-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    padding: 0;
}

.leave-confirm-modal-close:hover {
    background: #F7F8F9;
}

.leave-confirm-modal-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    padding-right: 32px;
}

.leave-confirm-modal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.leave-confirm-modal-title {
    font-size: var(--font-17);
    font-weight: 700;
    color: #304248;
    margin: 0;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
}

.leave-confirm-modal-message {
    font-size: var(--font-14);
    font-weight: 500;
    color: #304248;
    line-height: 22px;
    margin: 0;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
}

.leave-confirm-modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 28px;
}

.leave-confirm-modal-btn {
    padding: 12px 24px;
    border-radius: 12px;
    font-size: var(--market-font-15);
    font-weight: 700;
    font-family: Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    min-width: 100px;
    min-height: 38px;
}

.leave-confirm-modal-btn-leave {
    background: #F7F8F9;
    color: #304248;
    border: 1px solid #E2E5EC;
}

.leave-confirm-modal-btn-leave:hover {
    background: #E2E5EC;
}

.leave-confirm-modal-btn-create {
    background: #23AB72;
    color: #FFFFFF;
    border: none;
}

.leave-confirm-modal-btn-create:hover {
    background: #1E9A66;
}

.leave-confirm-modal-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
