/**
 * 코리안투데이 AI 어시스턴트 스타일
 * 110% 확대 버전 (시니어 친화)
 */

/* 플로팅 버튼 - Ask AI 스타일 */
.kt-ai-fab {
    position: fixed;
    bottom: 80px;
    right: 30px;
    height: 54px;
    padding: 0 24px;
    border-radius: 27px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 17px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    transition: all 0.3s ease;
    animation: kt-pulse 2s infinite;
}

.kt-ai-fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px rgba(102, 126, 234, 0.6);
}

.kt-ai-fab .fab-icon {
    font-size: 22px;
}

@keyframes kt-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4); }
    50% { box-shadow: 0 4px 30px rgba(102, 126, 234, 0.7); }
}

/* 모달 오버레이 */
.kt-ai-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.kt-ai-overlay.show {
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
}

/* 모달 컨테이너 - 110% 확대 */
.kt-ai-modal {
    width: 960px;
    max-width: 960px;
    max-height: 95vh;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.kt-ai-overlay.show .kt-ai-modal {
    transform: translateY(0);
}

/* 헤더 */
.kt-ai-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 18px 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kt-ai-header h3 {
    color: white;
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.kt-ai-header h3 .logo-icon {
    font-size: 26px;
}

.kt-ai-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.kt-ai-close:hover {
    background: rgba(255,255,255,0.3);
}

/* AI 탭 */
.kt-ai-tabs {
    display: flex;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.kt-ai-tab {
    flex: 1;
    padding: 14px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: #64748b;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.kt-ai-tab:hover {
    background: #e2e8f0;
}

.kt-ai-tab.active {
    background: white;
    color: #667eea;
    border-bottom: 3px solid #667eea;
}

.kt-ai-tab .badge {
    background: #22c55e;
    color: white;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 10px;
}

/* API 키 영역 */
.kt-ai-api-section {
    padding: 12px 18px;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.kt-api-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex: 1;
}

.kt-api-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-size: 14px;
}

.kt-api-save {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s;
}

.kt-api-save:hover {
    background: #5a67d8;
}

.kt-api-link {
    font-size: 13px;
    color: #667eea;
    text-decoration: none;
    white-space: nowrap;
}

.kt-api-link:hover {
    text-decoration: underline;
}

/* AI 도구 */
.kt-ai-tools {
    padding: 14px 18px;
    background: #fefce8;
    border-bottom: 1px solid #fef08a;
}

.kt-ai-tools-title {
    font-size: 14px;
    font-weight: 600;
    color: #854d0e;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.kt-tools-grid {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.kt-tool-btn {
    background: white;
    border: 1px solid #e5e7eb;
    padding: 10px 16px;
    border-radius: 22px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.kt-tool-btn:hover {
    background: #f0f9ff;
    border-color: #667eea;
    transform: translateY(-1px);
}

.kt-tool-btn .icon {
    font-size: 18px;
}

.kt-tool-btn .label {
    color: #374151;
    font-weight: 500;
}

/* 대화 영역 */
.kt-ai-chat {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background: #f8fafc;
    min-height: 200px;
    max-height: 420px;
}

.kt-ai-welcome {
    text-align: center;
    padding: 30px 22px;
}

.kt-ai-welcome .icon {
    font-size: 48px;
    margin-bottom: 14px;
}

.kt-ai-welcome h4 {
    color: #1e293b;
    margin: 0 0 8px 0;
    font-size: 18px;
}

.kt-ai-welcome p {
    color: #64748b;
    font-size: 15px;
    margin: 0;
}

/* 메시지 */
.kt-message {
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
}

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

.kt-message.ai {
    align-items: flex-start;
}

.kt-message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.6;
}

.kt-message.user .kt-message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.kt-message.ai .kt-message-bubble {
    background: white;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

/* API 유도 메시지 */
.kt-api-prompt {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid #f59e0b;
    border-radius: 12px;
    padding: 14px 18px;
    margin-top: 12px;
    text-align: center;
}

.kt-api-prompt p {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #92400e;
}

.kt-api-prompt a {
    display: inline-block;
    background: #f59e0b;
    color: white;
    padding: 8px 18px;
    border-radius: 20px;
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
}

.kt-api-prompt a:hover {
    background: #d97706;
}

/* 입력 영역 */
.kt-ai-input-area {
    padding: 14px 18px;
    background: white;
    border-top: 1px solid #e2e8f0;
}

.kt-input-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.kt-message-input {
    flex: 1;
    padding: 12px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 28px;
    font-size: 15px;
    resize: none;
    max-height: 100px;
    transition: border-color 0.2s;
}

.kt-message-input:focus {
    outline: none;
    border-color: #667eea;
}

.kt-send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.kt-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.kt-send-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

/* 로딩 */
.kt-loading {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
}

.kt-loading span {
    width: 10px;
    height: 10px;
    background: #667eea;
    border-radius: 50%;
    animation: kt-bounce 1.4s infinite ease-in-out both;
}

.kt-loading span:nth-child(1) { animation-delay: -0.32s; }
.kt-loading span:nth-child(2) { animation-delay: -0.16s; }

@keyframes kt-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* 반응형 */
/* 리사이즈 핸들 */
.kt-ai-modal {
    min-width: 320px;
    max-width: 95vw;
}

.kt-resize-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
    cursor: ew-resize;
    z-index: 10;
}

.kt-resize-handle:hover {
    background: rgba(102, 126, 234, 0.3);
}

.kt-resize-handle.left {
    left: -4px;
    border-radius: 20px 0 0 20px;
}

.kt-resize-handle.right {
    right: -4px;
    border-radius: 0 20px 20px 0;
}

/* 드래그 힌트 */

.kt-ai-header {
    cursor: grab;
    user-select: none;
}

.kt-ai-header:active {
    cursor: grabbing;
}

/* 드래그 중 텍스트 선택 방지 */
.kt-ai-modal.dragging {
    user-select: none;
}

@media (max-width: 768px) {
    .kt-ai-fab {
        bottom: 70px;
        right: 20px;
        height: 50px;
        padding: 0 20px;
        font-size: 15px;
    }
    
    .kt-ai-modal {
        width: 95% !important;
        max-height: 95vh !important;
        border-radius: 14px;
        /* 모바일에서는 항상 중앙 고정 */
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%) !important;
    }
    
    /* 모바일에서 드래그 비활성화 */
    .kt-ai-header {
        cursor: default;
    }
    
    .kt-tools-grid {
        flex-wrap: wrap;
    }
    
    .kt-ai-api-section {
        flex-direction: column;
        align-items: stretch;
    }
    
    .kt-tool-btn {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* 접기/펼치기 애니메이션 */
.kt-collapsible .kt-ai-tools-title {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.kt-collapsible .kt-ai-tools-title:hover {
    opacity: 0.8;
}

.kt-toggle-icon {
    font-size: 12px;
    transition: transform 0.3s ease;
    color: #64748b;
}

.kt-collapsible-content {
    max-height: 200px;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.4s ease, opacity 0.3s ease;
    opacity: 1;
}

.kt-collapsible.collapsed .kt-collapsible-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

.kt-collapsible.collapsed .kt-ai-tools-title {
    margin-bottom: 0;
    padding-bottom: 10px;
}

.kt-collapsible.collapsed {
    padding-bottom: 0;
}

/* 모달 고정 높이 + 내부 flex 레이아웃 */
.kt-ai-modal {
    height: 85vh !important;
    max-height: 85vh !important;
    display: flex;
    flex-direction: column;
}

/* 대화 영역 - 남은 공간 모두 차지 */
.kt-ai-chat {
    flex: 1 1 auto !important;
    max-height: none !important;
    min-height: 150px !important;
}

/* 접히는 섹션들은 flex-shrink 허용 */
.kt-collapsible {
    flex-shrink: 0;
}

/* 입력 영역 고정 */
.kt-ai-input-area {
    flex-shrink: 0;
}
