* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 10px;
}

.chat-container {
    width: 100%;
    max-width: 500px;
    height: 600px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    text-align: center;
}

.chat-header h1 {
    font-size: 24px;
    margin-bottom: 5px;
}

.chat-header p {
    font-size: 12px;
    opacity: 0.9;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    display: flex;
    margin-bottom: 10px;
    animation: slideIn 0.3s ease-in;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-items: flex-end;
}

.message.bot {
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
}

.message.user .message-time {
    text-align: right;
}

.message.bot .message-time {
    text-align: left;
}

.message {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.message p {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
}

.message-time {
    font-size: 11px;
    color: #999;
    padding: 0 15px;
    font-style: italic;
}

.message.user p {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 2px;
}

.message.bot p {
    background: #f0f0f0;
    color: #333;
    border-bottom-left-radius: 2px;
}

/* 상담사 아바타 */
.bot-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.bot-avatar img {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bot-avatar-icon {
    font-size: 22px;
    line-height: 1;
}

/* 봇 메시지 본문 래퍼 */
.message-body {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* 이미지 미리보기 영역 */
.img-preview-area {
    padding: 8px 15px 0;
    background: #fafafa;
    border-top: 1px solid #eee;
}

.img-preview-inner {
    display: inline-flex;
    position: relative;
    border-radius: 10px;
    overflow: visible;
}

.img-preview-inner img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 10px;
    border: 2px solid #667eea;
}

.img-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ef4444;
    color: white;
    border: none;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-weight: bold;
}

.img-preview-remove:hover {
    background: #dc2626;
}

/* 첨부 버튼 */
.attach-btn {
    background: transparent;
    color: #667eea;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 12px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.attach-btn:hover {
    background: #eef2ff;
}

/* 사용자 전송 이미지 */
.user-sent-image {
    width: 160px;
    max-width: 100%;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.3);
    display: block;
    margin-bottom: 4px;
}

.chat-input-area {
    display: flex;
    padding: 15px;
    gap: 10px;
    border-top: 1px solid #eee;
    background: #fafafa;
}

#question {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
}

#question:focus {
    border-color: #667eea;
}

button {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 10px 25px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

button:hover {
    background: #764ba2;
}

button:active {
    transform: scale(0.98);
}

.loading {
    display: none;
}

.loading.hidden {
    display: none !important;
}

/* 로딩 스피너 애니메이션 */
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 타이핑 지시자 (점 애니메이션) */
.typing-indicator {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 10px 15px;
    background: #f0f0f0;
    border-radius: 10px;
    width: fit-content;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: #667eea;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.5;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

.error {
    background: #ffebee;
    color: #c62828;
    padding: 10px;
    border-radius: 5px;
    margin: 10px;
    font-size: 12px;
}

.error.hidden {
    display: none;
}

/* 스크롤바 스타일 */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

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

/* 모바일 반응형 */
@media (max-width: 600px) {
    .chat-container {
        max-width: 100%;
        height: 100vh;
        border-radius: 0;
    }

    .message p {
        max-width: 90%;
    }
}

/* 채팅 이미지 */
.chat-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.chat-image-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.chat-image {
    width: 180px;
    max-width: 100%;
    border-radius: 10px;
    border: 1px solid rgba(0,0,0,0.08);
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-image:hover {
    transform: scale(1.03);
}

.chat-image-label {
    font-size: 11px;
    color: #888;
}

/* 이미지 라이트박스 */
.img-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    cursor: zoom-out;
}

.img-lightbox.open {
    display: flex;
}

.img-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
    cursor: default;
    animation: lbFadeIn 0.2s ease;
}

@keyframes lbFadeIn {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

.img-lightbox-close {
    position: fixed;
    top: 18px;
    right: 24px;
    color: #fff;
    font-size: 36px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.img-lightbox-close:hover {
    opacity: 1;
}
