﻿/* ========================================= */
/* GPT 연구도우미 챗봇 스타일 - 반응형 + 리사이즈 가능 */
/* ========================================= */

:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #0ea5e9;
    --user-message-bg: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    --assistant-message-bg: #ffffff;
    --bg-light: #f8fafc;
    --border-color: #e2e8f0;
    --text-dark: #1e293b;
    --text-light: #64748b;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.2);
}

/* ========================================= */
/* 챗봇 팝업 - 반응형 + 리사이즈 가능 */
/* ========================================= */
.chat-popup {
    display: none;
    position: fixed;
    right: 24px;
    bottom: 100px;
    
    /* 🎯 반응형 크기 설정 */
    width: clamp(380px, 35vw, 600px);      /* 최소 380px, 최대 600px, 기본 35vw */
    height: clamp(500px, 70vh, 850px);     /* 최소 500px, 최대 850px, 기본 70vh */
    
    background: var(--bg-light);
    border-radius: 20px;
    box-shadow: var(--shadow-xl);
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    box-sizing: border-box;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    animation: slideUp 0.3s ease-out;
    
    /* ✅ 기본 크기 조절 (백업용) */
    resize: none; /* JavaScript로 직접 제어 */
    min-width: 380px;
    min-height: 500px;
    max-width: 90vw;
    max-height: 90vh;
}

/* ========================================= */
/* 크기 조절 핸들 - 8방향 */
/* ========================================= */

/* 오른쪽 하단 핸들 (기본) */
.resize-handle-br {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    z-index: 10;
}

.resize-handle-br::after {
    content: '⋮⋮';
    position: absolute;
    right: 4px;
    bottom: 4px;
    font-size: 16px;
    color: #94a3b8;
    line-height: 1;
    letter-spacing: -2px;
    transform: rotate(-45deg);
}

/* 오른쪽 핸들 */
.resize-handle-r {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 8px;
    cursor: ew-resize;
    z-index: 10;
}

.resize-handle-r::before {
    content: '';
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 30px;
    background: linear-gradient(to bottom, 
        transparent, 
        rgba(59, 130, 246, 0.3) 20%, 
        rgba(59, 130, 246, 0.3) 80%, 
        transparent
    );
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.2s;
}

.resize-handle-r:hover::before {
    opacity: 1;
}

/* 하단 핸들 */
.resize-handle-b {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 8px;
    cursor: ns-resize;
    z-index: 10;
}

.resize-handle-b::before {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 3px;
    background: linear-gradient(to right, 
        transparent, 
        rgba(59, 130, 246, 0.3) 20%, 
        rgba(59, 130, 246, 0.3) 80%, 
        transparent
    );
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.2s;
}

.resize-handle-b:hover::before {
    opacity: 1;
}

/* 왼쪽 핸들 */
.resize-handle-l {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 8px;
    cursor: ew-resize;
    z-index: 10;
}

.resize-handle-l::before {
    content: '';
    position: absolute;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 30px;
    background: linear-gradient(to bottom, 
        transparent, 
        rgba(59, 130, 246, 0.3) 20%, 
        rgba(59, 130, 246, 0.3) 80%, 
        transparent
    );
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.2s;
}

.resize-handle-l:hover::before {
    opacity: 1;
}

/* 상단 핸들 */
.resize-handle-t {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 8px;
    cursor: ns-resize;
    z-index: 10;
}

.resize-handle-t::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 3px;
    background: linear-gradient(to right, 
        transparent, 
        rgba(59, 130, 246, 0.3) 20%, 
        rgba(59, 130, 246, 0.3) 80%, 
        transparent
    );
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.2s;
}

.resize-handle-t:hover::before {
    opacity: 1;
}

/* 모서리 핸들들 */
.resize-handle-tl {
    position: absolute;
    left: 0;
    top: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    z-index: 10;
}

.resize-handle-tr {
    position: absolute;
    right: 0;
    top: 0;
    width: 20px;
    height: 20px;
    cursor: nesw-resize;
    z-index: 10;
}

.resize-handle-bl {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 20px;
    height: 20px;
    cursor: nesw-resize;
    z-index: 10;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-popup.open {
    display: flex;
}

/* ========================================= */
/* 챗봇 헤더 - 모던한 그라데이션 */
/* ========================================= */
.chat-header {
    padding: 20px 24px;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    font-weight: 600;
    font-size: 18px;
    box-sizing: border-box;
    position: relative;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.3);
    cursor: move; /* ✅ 드래그 가능 표시 */
}

.chat-header__content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.chat-header__title-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-header__title {
    font-size: 15px;
    color: white;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header__title::before {
    content: '🤖';
    font-size: 20px;
}

.chat-header__subtitle {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.85);
    font-weight: 400;
}

.chat-header__buttons {
    display: flex;
    gap: 6px;
    align-items: center;
}

.chat-header__btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
    color: rgba(255, 255, 255, 0.9);
}

.chat-header__btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.chat-header__btn--clear {
    font-size: 18px;
}

.chat-header__btn--close {
    font-size: 24px;
    line-height: 1;
}

/* ========================================= */
/* 메시지 영역 */
/* ========================================= */
.chat-messages {
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    background: var(--bg-light);
    box-sizing: border-box;
    scroll-behavior: smooth;
}

/* 스크롤바 스타일링 */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ========================================= */
/* 메시지 버블 */
/* ========================================= */
.chat-message {
    display: flex;
    margin-bottom: 16px;
    width: 100%;
    box-sizing: border-box;
    animation: messageSlide 0.3s ease-out;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.assistant {
    justify-content: flex-start;
}

.message-content {
    display: block;
    max-width: 85%;
    box-sizing: border-box;
    padding: 12px 16px;
    border-radius: 18px;
    overflow: hidden;
    word-break: break-word;
    white-space: normal;
    line-height: 1.6;
    box-shadow: var(--shadow-sm);
}

/* 사용자 메시지 - 보라색 그라데이션 */
.chat-message.user .message-content {
    background: var(--user-message-bg);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

/* 어시스턴트 메시지 - 깔끔한 흰색 */
.chat-message.assistant .message-content {
    background: var(--assistant-message-bg);
    color: var(--text-dark);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

/* ========================================= */
/* 마크다운 스타일 */
/* ========================================= */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    margin-top: 16px;
    margin-bottom: 10px;
    font-weight: 600;
    color: inherit;
}

.message-content h1 {
    font-size: 1.5em;
}

.message-content h2 {
    font-size: 1.3em;
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 6px;
}

.chat-message.user .message-content h2 {
    color: #ffffff;
    border-bottom-color: rgba(255, 255, 255, 0.5);
}

.message-content h3 {
    font-size: 1.15em;
    color: var(--text-dark);
}

.message-content h4 {
    font-size: 1em;
}

.message-content p {
    margin: 10px 0;
    line-height: 1.7;
}

.message-content ul,
.message-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 6px 0;
    line-height: 1.6;
}

.message-content strong {
    font-weight: 700;
    color: var(--primary-color);
}

.chat-message.user .message-content strong {
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-content em {
    font-style: italic;
}

.message-content code {
    background: rgba(100, 116, 139, 0.1);
    padding: 3px 8px;
    border-radius: 6px;
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    font-size: 0.88em;
    color: #db2777;
    border: 1px solid rgba(100, 116, 139, 0.15);
}

.chat-message.user .message-content code {
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.3);
}

.message-content pre {
    background: #1e293b;
    padding: 16px;
    border-radius: 12px;
    overflow-x: auto;
    margin: 16px 0;
    box-shadow: var(--shadow-md);
}

.message-content pre code {
    background: none;
    padding: 0;
    border: none;
    color: #e2e8f0;
    font-size: 0.9em;
}

.message-content .markdown-table-container {
    max-width: 100%;
    overflow-x: auto;
    margin: 16px 0;
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

.message-content table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
    font-size: 0.9em;
    background: white;
    border-radius: 10px;
    overflow: hidden;
}

.message-content table th,
.message-content table td {
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    text-align: left;
    white-space: normal;
    word-break: break-word;
    vertical-align: top;
}

.message-content table th {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    font-weight: 600;
    color: white;
    border: none;
}

.message-content table tr:nth-child(even) {
    background: #f8fafc;
}

.message-content table tr:hover {
    background: #f1f5f9;
}

.message-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 16px;
    margin: 16px 0;
    color: var(--text-light);
    background: #f1f5f9;
    padding: 16px;
    border-radius: 8px;
    font-style: italic;
}

.message-content hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: 24px 0;
}

.message-content a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px solid var(--primary-color);
    transition: all 0.2s ease;
}

.message-content a:hover {
    color: var(--primary-hover);
    border-bottom-color: var(--primary-hover);
}

.chat-message.user .message-content a {
    color: #ffffff;
    border-bottom-color: rgba(255, 255, 255, 0.6);
}

.chat-message.user .message-content a:hover {
    border-bottom-color: #ffffff;
}

/* ========================================= */
/* 타이핑 인디케이터 */
/* ========================================= */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    gap: 4px;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--primary-color);
    border-radius: 50%;
    opacity: 0.4;
    animation: chat-dot 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chat-dot {
    0%, 100% {
        opacity: 0.4;
        transform: translateY(0) scale(1);
    }
    50% {
        opacity: 1;
        transform: translateY(-8px) scale(1.1);
    }
}

/* ========================================= */
/* 스트리밍 커서 */
/* ========================================= */
.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: var(--primary-color);
    margin-left: 3px;
    animation: blink 1s infinite;
    vertical-align: text-bottom;
}

.chat-message.user .streaming-cursor {
    background: #ffffff;
}

@keyframes blink {
    0%, 49% {
        opacity: 1;
    }
    50%, 100% {
        opacity: 0;
    }
}

/* ========================================= */
/* 에러 메시지 */
/* ========================================= */
.error-message {
    color: #dc2626 !important;
    background: #fee2e2 !important;
    border: 1px solid #fecaca !important;
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
}

/* ========================================= */
/* 챗봇 열기 버튼 */
/* ========================================= */
#openChatBtn {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    border: none;
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4);
    color: white;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

#openChatBtn::before {
    content: '💬';
}

#openChatBtn:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 12px 28px rgba(59, 130, 246, 0.5);
}

#openChatBtn:active {
    transform: scale(0.95);
}

/* ========================================= */
/* 입력 영역 */
/* ========================================= */
.chat-input-container {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
    resize: none;
    font-family: inherit;
    line-height: 1.5;
}

.chat-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-input::placeholder {
    color: #94a3b8;
}

.chat-send-btn {
    flex-shrink: 0;
    width: 70px;
    padding: 12px;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.chat-send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.chat-send-btn:active {
    transform: translateY(0);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-input-hint {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 8px;
    text-align: center;
}

/* ========================================= */
/* 반응형 - 태블릿 */
/* ========================================= */
@media (max-width: 1024px) {
    .chat-popup {
        width: clamp(360px, 45vw, 500px);
        height: clamp(480px, 65vh, 750px);
    }
}

/* ========================================= */
/* 반응형 - 모바일 */
/* ========================================= */
@media (max-width: 768px) {
    .chat-popup {
        width: calc(100vw - 32px);
        height: calc(100vh - 180px);
        right: 16px;
        bottom: 90px;
        border-radius: 16px;
        min-width: 320px;
    }

    /* 모바일에서는 모든 리사이즈 핸들 숨김 */
    .resize-handle-r,
    .resize-handle-b,
    .resize-handle-l,
    .resize-handle-t,
    .resize-handle-tl,
    .resize-handle-tr,
    .resize-handle-bl,
    .resize-handle-br {
        display: none;
    }

    #openChatBtn {
        width: 56px;
        height: 56px;
        font-size: 24px;
        right: 20px;
        bottom: 20px;
    }

    .message-content {
        max-width: 90%;
        padding: 10px 14px;
    }

    .chat-header {
        padding: 16px 20px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .chat-popup {
        width: calc(100vw - 16px);
        height: calc(100vh - 100px);
        right: 8px;
        bottom: 80px;
    }

    .message-content {
        font-size: 14px;
    }
}

/* ========================================= */
/* 다크 모드 */
/* ========================================= */
.dark-mode .chat-popup {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.1);
}

.dark-mode .chat-header {
    background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 100%);
}

.dark-mode .chat-header__subtitle {
    color: rgba(255, 255, 255, 0.8);
}

.dark-mode .chat-header__btn {
    color: rgba(255, 255, 255, 0.85);
}

.dark-mode .chat-header__btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.dark-mode .chat-messages {
    background: #0f172a;
}

.dark-mode .chat-message.assistant .message-content {
    background: #1e293b;
    color: #e2e8f0;
    border-color: #334155;
}

.dark-mode .chat-message.user .message-content {
    background: var(--user-message-bg);
    color: #ffffff;
}

.dark-mode .message-content h2 {
    color: #60a5fa;
    border-bottom-color: #60a5fa;
}

.dark-mode .message-content h3,
.dark-mode .message-content h4 {
    color: #e2e8f0;
}

.dark-mode .message-content strong {
    color: #60a5fa;
}

.dark-mode .message-content code {
    background: rgba(148, 163, 184, 0.15);
    color: #f472b6;
    border-color: rgba(148, 163, 184, 0.25);
}

.dark-mode .message-content pre {
    background: #0f172a;
    border: 1px solid #334155;
}

.dark-mode .message-content pre code {
    color: #cbd5e1;
}

.dark-mode .message-content table {
    background: #1e293b;
    border-color: #334155;
}

.dark-mode .message-content table th {
    background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 100%);
    color: white;
}

.dark-mode .message-content table td {
    border-color: #334155;
    color: #e2e8f0;
}

.dark-mode .message-content table tr:nth-child(even) {
    background: #0f172a;
}

.dark-mode .message-content table tr:hover {
    background: #334155;
}

.dark-mode .message-content blockquote {
    background: #1e293b;
    border-left-color: #60a5fa;
    color: #94a3b8;
}

.dark-mode .message-content hr {
    border-top-color: #334155;
}

.dark-mode .message-content a {
    color: #60a5fa;
    border-bottom-color: #60a5fa;
}

.dark-mode .message-content a:hover {
    color: #93c5fd;
    border-bottom-color: #93c5fd;
}

.dark-mode .chat-input-container {
    background: #1e293b;
    border-top-color: #334155;
}

.dark-mode .chat-input {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

.dark-mode .chat-input:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

.dark-mode .chat-input::placeholder {
    color: #64748b;
}

.dark-mode .chat-send-btn {
    background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 100%);
}

.dark-mode .chat-send-btn:hover {
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.5);
}

.dark-mode .chat-input-hint {
    color: #64748b;
}

.dark-mode .typing-indicator span {
    background: #60a5fa;
}

.dark-mode .chat-messages::-webkit-scrollbar-thumb {
    background: #475569;
}

.dark-mode .chat-messages::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

.dark-mode .error-message {
    color: #fca5a5 !important;
    background: #450a0a !important;
    border-color: #991b1b !important;
}

.dark-mode .chat-popup::after {
    color: #64748b;
}

/* 다크모드 리사이즈 핸들 */
.dark-mode .resize-handle-r::before,
.dark-mode .resize-handle-b::before,
.dark-mode .resize-handle-l::before,
.dark-mode .resize-handle-t::before {
    background: linear-gradient(to bottom, 
        transparent, 
        rgba(96, 165, 250, 0.3) 20%, 
        rgba(96, 165, 250, 0.3) 80%, 
        transparent
    );
}

.dark-mode .resize-handle-br::after {
    color: #64748b;
}