/*
 * KFQ RAG 시스템 스타일시트
 */

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

/* 비밀번호 화면 */
.password-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f5f7fa;
    z-index: 9999;
}

.password-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(30, 58, 95, 0.15);
    padding: 48px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.password-container h1 {
    color: #1a5f7a;
    margin-bottom: 8px;
    font-size: 24px;
}

.password-container .subtitle {
    color: #666;
    margin-bottom: 32px;
    font-size: 14px;
}

.password-container .form-group {
    margin-bottom: 20px;
}

.password-container input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s;
}

.password-container input:focus {
    outline: none;
    border-color: #1a5f7a;
}

.password-container .btn-primary {
    width: 100%;
    padding: 14px;
    background: #1a5f7a;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.password-container .btn-primary:hover {
    background: #145068;
}

.password-error {
    color: #e53935;
    font-size: 14px;
    margin-top: 16px;
    min-height: 20px;
}

/* 메인 레이아웃 */
.main-layout {
    display: flex;
    height: 100vh;
    width: 100%;
    justify-content: center;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 900px;
}

/* 헤더 */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
    height: 60px;
    background: linear-gradient(135deg, #1e3a5f 0%, #2c5282 100%);
    color: #fff;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.header-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.header-logo-icon {
    width: 36px;
    height: 36px;
    background: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #1e3a5f;
    font-size: 14px;
}

.header-logo:hover .header-logo-icon {
    opacity: 0.9;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    background: #27ae60;
}

.doc-count {
    font-size: 0.8rem;
    opacity: 0.8;
}

/* 섹션 선택 드롭다운 */
.section-select {
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
    font-weight: 500;
}

.section-select:hover {
    background: rgba(255, 255, 255, 0.25);
}

.section-select option {
    background: #1a5f7a;
    color: #fff;
}

/* 모델 선택 드롭다운 */
.model-select {
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
}

.model-select:hover {
    background: rgba(255, 255, 255, 0.2);
}

.model-select option {
    background: #1a5f7a;
    color: #fff;
}

/* 채팅 메시지 영역 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 환영 메시지 */
.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.welcome-message h2 {
    color: #1a5f7a;
    margin-bottom: 10px;
}

.welcome-message .examples {
    margin-top: 20px;
    font-weight: 500;
}

.welcome-message ul {
    list-style: none;
    margin-top: 10px;
}

.welcome-message li {
    padding: 10px 15px;
    background: #fff;
    border: 1px solid #e1e5eb;
    border-radius: 8px;
    margin: 8px auto;
    max-width: 400px;
    cursor: pointer;
    transition: all 0.2s;
}

.welcome-message li:hover {
    background: #e8f4fd;
    border-color: #1a5f7a;
}

/* 메시지 스타일 */
.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

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

.message.assistant {
    align-self: flex-start;
}

.message-content {
    padding: 15px 18px;
    border-radius: 18px;
    line-height: 1.6;
}

.message.user .message-content {
    background: #1a5f7a;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: #fff;
    border: 1px solid #e1e5eb;
    border-bottom-left-radius: 4px;
}

/* 출처 섹션 */
.sources-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e1e5eb;
}

.sources-header {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 8px;
    transition: background 0.2s;
    font-size: 0.9rem;
    color: #666;
}

.sources-header:hover {
    background: #e8f4fd;
}

.sources-toggle {
    font-size: 0.8rem;
    color: #7f8c8d;
}

.sources-list {
    margin-top: 10px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 2000px;
    opacity: 1;
}

.sources-list.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

.source-item {
    background: #f8f9fa;
    border: 1px solid #e1e5eb;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.source-item:hover {
    background: #e8f4fd;
    border-color: #1a5f7a;
}

.source-item:hover .source-view-hint {
    opacity: 1;
}

.source-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.source-view-hint {
    font-size: 0.75rem;
    color: #1a5f7a;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.source-title {
    font-weight: 600;
    color: #1a5f7a;
    margin-bottom: 4px;
}

.source-meta {
    font-size: 0.85rem;
    color: #666;
}

.source-category {
    font-size: 0.8rem;
    color: #888;
    margin: 4px 0;
}

.source-summary {
    font-size: 0.85rem;
    color: #555;
    margin-top: 8px;
    line-height: 1.5;
}

/* 인라인 출처 링크 (답변 내 클릭 가능한 출처) */
.source-link {
    color: #1a5f7a;
    cursor: pointer;
    text-decoration: underline;
    font-weight: 500;
    transition: all 0.2s;
}

.source-link:hover {
    color: #134b61;
    background: #e8f4fd;
    border-radius: 3px;
    padding: 0 2px;
}

/* 입력 영역 */
.input-area {
    display: flex;
    gap: 10px;
    padding: 15px 20px;
    background: #fff;
    border-top: 1px solid #e1e5eb;
}

#question-input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #e1e5eb;
    border-radius: 24px;
    font-size: 1rem;
    resize: none;
    font-family: inherit;
    min-height: 48px;
    max-height: 120px;
}

#question-input:focus {
    outline: none;
    border-color: #1a5f7a;
}

.input-area .btn {
    padding: 12px 24px;
    border-radius: 24px;
}

/* 버튼 */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s;
}

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

.btn-primary {
    background: #1a5f7a;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #134b61;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-warning {
    background: #e67e22;
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background: #d35400;
}

.btn-small {
    padding: 5px 12px;
    font-size: 0.8rem;
}

/* 알림 */
.alert {
    padding: 12px 20px;
    margin: 0 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.alert-info {
    background: #e8f4fd;
    border: 1px solid #3498db;
    color: #2980b9;
}

.alert-success {
    background: #e8f8f0;
    border: 1px solid #27ae60;
    color: #1e8449;
}

.alert-error {
    background: #fdeaea;
    border: 1px solid #e74c3c;
    color: #c0392b;
}

/* 로딩 */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 20px;
    color: #7f8c8d;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e1e5eb;
    border-top: 3px solid #1a5f7a;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* 스트리밍 커서 (ChatGPT 스타일) */
.streaming-cursor {
    display: inline;
    color: #1a5f7a;
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* AI 생각 표시 */
.ai-thought {
    background: #fff9e6;
    border-left: 4px solid #f39c12;
    padding: 10px 15px;
    margin: 10px 0;
    border-radius: 0 6px 6px 0;
}

/* 문서 뷰어 패널 */
.doc-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #e1e5eb;
    background: #fff;
    height: 100vh;
    position: relative;
}

.doc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #1a5f7a;
    color: #fff;
    min-height: 50px;
}

#doc-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 10px;
}

.doc-viewer-frame {
    flex: 1;
    width: 100%;
    border: none;
}

/* 문서 로딩 표시 */
.doc-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    color: #7f8c8d;
    font-size: 0.95rem;
    z-index: 10;
}

.doc-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e1e5eb;
    border-top: 4px solid #1a5f7a;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    background: #fff;
}

/* Split layout when doc panel is visible */
.main-layout.with-doc-panel {
    justify-content: flex-start;
}

.main-layout.with-doc-panel .chat-container {
    max-width: 50%;
    flex: 0 0 50%;
}

.main-layout.with-doc-panel .doc-panel {
    flex: 0 0 50%;
    display: flex;
}

/* 반응형 */
@media (max-width: 600px) {
    .header h1 {
        font-size: 1.1rem;
    }

    .message {
        max-width: 95%;
    }

    .input-area {
        flex-direction: column;
    }

    .input-area .btn {
        width: 100%;
    }
}
