/**
 * KAITRUST AI 어시스턴트 스타일
 * WIA Books 스타일 완전 적용
 */

/* ========== 다크모드 토글 (독립 플로팅) ========== */
.kt-theme-toggle {
    position: fixed;
    bottom: 145px;
    right: 30px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2c3e50, #34495e);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    z-index: 99997;
    transition: all 0.3s ease;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kt-theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.kt-theme-toggle .icon-sun,
.kt-theme-toggle .icon-moon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    line-height: 1;
    margin: 0;
    padding: 0;
}

.kt-theme-toggle .icon-moon {
    opacity: 1;
    visibility: visible;
}

.kt-theme-toggle .icon-sun {
    opacity: 0;
    visibility: hidden;
}

body.light-mode .kt-theme-toggle {
    background: linear-gradient(135deg, #f39c12, #f1c40f);
}

body.light-mode .kt-theme-toggle .icon-moon {
    opacity: 0;
    visibility: hidden;
}

body.light-mode .kt-theme-toggle .icon-sun {
    opacity: 1;
    visibility: visible;
}

/* ========== Ask AI FAB 버튼 ========== */
.kt-ai-fab {
    position: fixed;
    bottom: 105px;
    right: 30px;
    width: 56px;
    height: 56px;
    padding: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #a855f7 0%, #06b6d4 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(168, 85, 247, 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(168, 85, 247, 0.6);
}

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

/* Spinning animation for AI icon */
.kt-ai-fab .fab-icon.spinning {
    display: inline-block;
    animation: kt-spin 8s linear infinite;
}

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

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

/* ========== 모달 오버레이 ========== */
.kt-ai-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 99999;
    justify-content: center;
    align-items: center;
}

.kt-ai-overlay.show {
    display: flex;
}

/* ========== 모달 - WIA Books 사이즈 ========== */
.kt-ai-modal {
    position: relative;
    width: 960px;
    max-width: 95vw;
    height: 85vh;
    max-height: 95vh;
    min-width: 400px;
    min-height: 400px;
    background: linear-gradient(145deg, #0a0a1a, #1a1a3a);
    border: 1px solid rgba(168, 85, 247, 0.4);
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5), 0 0 60px rgba(168, 85, 247, 0.3);
    transition: none;
}

.kt-ai-modal.dragging {
    transition: none !important;
    user-select: none;
}

.kt-ai-modal.fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
}

/* 리사이즈 핸들 */
.kt-resize-handle {
    position: absolute;
    top: 60px;
    bottom: 0;
    width: 10px;
    cursor: ew-resize;
    z-index: 10;
    background: transparent;
}

.kt-resize-handle:hover {
    background: rgba(168, 85, 247, 0.3);
}

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

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

/* ========== 헤더 ========== */
.kt-ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(90deg, #a855f7, #06b6d4);
    color: white;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
}

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

.kt-modal-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
}

.kt-modal-logo {
    font-size: 26px;
}

.kt-header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

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

.kt-ai-close:hover {
    transform: rotate(90deg);
}

/* ========== AI 탭 ========== */
.kt-ai-tabs {
    display: flex;
    padding: 12px;
    gap: 10px;
    background: rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.kt-ai-tab {
    flex: 1;
    padding: 12px 16px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    color: #94a3b8;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.kt-ai-tab:hover {
    background: rgba(168, 85, 247, 0.2);
}

.kt-ai-tab.active {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.3), rgba(6, 182, 212, 0.3));
    border-color: #a855f7;
    color: white;
}

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

/* ========== API 섹션 ========== */
.kt-api-section {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.kt-api-input {
    flex: 1;
    min-width: 200px;
    padding: 10px 14px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 10px;
    color: white;
    font-size: 14px;
}

.kt-api-input:focus {
    outline: none;
    border-color: #a855f7;
}

.kt-api-save {
    padding: 10px 20px;
    background: linear-gradient(135deg, #a855f7, #06b6d4);
    border: none;
    border-radius: 10px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.kt-api-save:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(168, 85, 247, 0.4);
}

.kt-api-link {
    color: #f59e0b;
    font-size: 12px;
    text-decoration: none;
}

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

/* ========== 도구/서비스 섹션 ========== */
.kt-tools-section, .kt-services-section {
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.kt-tools-section summary, .kt-services-section summary {
    padding: 14px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #a855f7;
    font-weight: 600;
    font-size: 14px;
    list-style: none;
}

.kt-tools-section summary::-webkit-details-marker,
.kt-services-section summary::-webkit-details-marker {
    display: none;
}

.kt-services-section summary {
    color: #06b6d4;
}

.kt-tools-grid, .kt-services-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 0 16px 16px;
}

.kt-tool-btn, .kt-service-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    color: #e2e8f0;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
}

.kt-tool-btn:hover, .kt-service-btn:hover {
    background: rgba(168, 85, 247, 0.2);
    border-color: #a855f7;
    transform: translateY(-2px);
}

/* ========== 채팅 영역 ========== */
.kt-chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.kt-chat-welcome {
    text-align: center;
    padding: 60px 20px;
}

.kt-welcome-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.kt-chat-welcome h3 {
    color: #06b6d4;
    margin: 0 0 12px;
    font-size: 1.4rem;
}

.kt-chat-welcome p {
    color: #94a3b8;
    margin: 0;
    font-size: 1rem;
}

.kt-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.kt-message {
    padding: 14px 18px;
    border-radius: 14px;
    max-width: 85%;
    font-size: 15px;
    line-height: 1.6;
}

.kt-message.user {
    background: linear-gradient(135deg, #a855f7, #7c3aed);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.kt-message.ai {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* ========== 입력 영역 ========== */
.kt-input-container {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.kt-input-container input {
    flex: 1;
    padding: 14px 20px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 30px;
    color: white;
    font-size: 15px;
}

.kt-input-container input:focus {
    outline: none;
    border-color: #a855f7;
}

.kt-input-container input::placeholder {
    color: #64748b;
}

.kt-send-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #a855f7, #06b6d4);
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kt-send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 20px rgba(168, 85, 247, 0.5);
}

/* ========== 모바일 반응형 ========== */
@media (max-width: 768px) {
    .kt-theme-toggle {
        width: 45px;
        height: 45px;
        bottom: 140px;
        right: 20px;
    }
    
    .kt-theme-toggle .icon-sun,
    .kt-theme-toggle .icon-moon {
        font-size: 20px;
    }

    .kt-ai-fab {
        width: 50px;
        height: 50px;
        padding: 0;
        font-size: 15px;
        bottom: 145px;
        right: 20px;
    }

    .kt-ai-modal {
        width: 95vw !important;
        height: 90vh !important;
        max-width: 95vw !important;
        max-height: 95vh !important;
        border-radius: 16px;
    }

    .kt-ai-modal.fullscreen {
        border-radius: 0 !important;
    }

    .kt-ai-header {
        cursor: default;
        padding: 14px 16px;
    }

    .kt-resize-handle {
        display: none;
    }

    .kt-tools-grid, .kt-services-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========== 라이트 모드 ========== */
body.light-mode .kt-ai-modal {
    background: linear-gradient(145deg, #ffffff, #f8fafc);
    border-color: #e2e8f0;
}

body.light-mode .kt-ai-tabs {
    background: #f1f5f9;
}

body.light-mode .kt-ai-tab {
    background: white;
    border-color: #e2e8f0;
    color: #475569;
}

body.light-mode .kt-ai-tab.active {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(6, 182, 212, 0.15));
    border-color: #a855f7;
    color: #1e293b;
}

body.light-mode .kt-api-section {
    background: #f8fafc;
    border-color: #e2e8f0;
}

body.light-mode .kt-api-input {
    background: white;
    border-color: #e2e8f0;
    color: #1e293b;
}

body.light-mode .kt-tool-btn,
body.light-mode .kt-service-btn {
    background: white;
    border-color: #e2e8f0;
    color: #475569;
}

body.light-mode .kt-chat-container {
    background: #ffffff;
}

body.light-mode .kt-chat-welcome h3 {
    color: #0891b2;
}

body.light-mode .kt-chat-welcome p {
    color: #64748b;
}

body.light-mode .kt-message.ai {
    background: #f1f5f9;
    color: #1e293b;
}

body.light-mode .kt-input-container {
    background: #f8fafc;
    border-color: #e2e8f0;
}

body.light-mode .kt-input-container input {
    background: white;
    border-color: #e2e8f0;
    color: #1e293b;
}

body.light-mode .kt-tools-section,
body.light-mode .kt-services-section {
    border-color: #e2e8f0;
}

/* ========== 접기/펼치기 섹션 ========== */
.kt-collapsible {
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
    overflow: hidden;
}

.kt-section-title {
    padding: 14px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #a855f7;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.2s;
}

.kt-section-title:hover {
    background: rgba(168, 85, 247, 0.1);
}

.kt-section-title.kt-services {
    color: #06b6d4;
}

.kt-section-title.kt-services:hover {
    background: rgba(6, 182, 212, 0.1);
}

.kt-toggle-icon {
    font-size: 12px;
    transition: transform 0.3s;
}

.kt-section-content {
    opacity: 1;
    max-height: 500px;
    transition: max-height 0.5s ease-out, padding 0.5s ease-out, opacity 0.4s ease-out;
    overflow: hidden;
}

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

/* 도구 버튼 아이콘+라벨 */
.kt-tool-btn .icon,
.kt-service-btn .icon {
    font-size: 18px;
}

.kt-tool-btn .label,
.kt-service-btn .label {
    font-size: 13px;
}

/* 라이트 모드 */
body.light-mode .kt-collapsible {
    border-color: #e2e8f0;
}

body.light-mode .kt-section-title:hover {
    background: rgba(168, 85, 247, 0.05);
}

body.light-mode .kt-section-title.kt-services:hover {
    background: rgba(6, 182, 212, 0.05);
}
