/*
 * KAB RAG 시스템 스타일시트
 * 채팅 인터페이스 + PDF 뷰어
 */

* {
    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 {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.password-container {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.password-container h1 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 1.5rem;
}

.password-container .subtitle {
    color: #7f8c8d;
    margin-bottom: 30px;
}

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

.password-container input[type="password"] {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e1e5eb;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.password-container input[type="password"]:focus {
    outline: none;
    border-color: #3498db;
}

.password-container .btn {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
}

.password-error {
    color: #e74c3c;
    margin-top: 15px;
    font-size: 0.9rem;
    min-height: 20px;
}

/* 메인 레이아웃 (2열) */
.main-layout {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* 왼쪽 패널 (채팅) */
.left-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: flex 0.3s ease;
    max-width: 1000px;
    margin: 0 auto;
}

.left-panel.with-pdf {
    flex: 0 0 50%;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* 헤더 */
.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;
    flex-wrap: wrap;
    gap: 10px;
}

.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;
    flex-wrap: wrap;
}

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

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

/* 모델 선택 드롭다운 */
.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:focus {
    border-color: #3498db;
}

.model-select option {
    background: #2c3e50;
    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: #2c3e50;
    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: #3498db;
}

/* 메시지 스타일 */
.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: #3498db;
    color: #fff;
    border-bottom-right-radius: 4px;
}

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

/* 답변 내 출처 링크 */
.source-link {
    color: #3498db;
    text-decoration: underline;
    cursor: pointer;
    background: #e8f4fd;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

.source-link:hover {
    background: #d0e8f9;
}

/* 출처 섹션 */
.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;
}

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

.sources-header h4 {
    font-size: 0.9rem;
    color: #7f8c8d;
    margin: 0;
}

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

/* 출처 목록 (접기/펼치기) */
.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-card {
    background: #f8f9fa;
    border: 1px solid #e1e5eb;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.source-card:hover {
    background: #e8f4fd;
    border-color: #3498db;
}

.source-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.source-card-title {
    font-weight: 500;
    color: #2c3e50;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.source-card-page {
    color: #7f8c8d;
    font-size: 0.85rem;
}

.source-card-summary {
    font-size: 0.85rem;
    color: #666;
    line-height: 1.5;
}

.source-card-relevance {
    margin-top: 8px;
    font-size: 0.8rem;
    color: #27ae60;
}

/* 입력 영역 */
.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: #3498db;
}

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

/* 오른쪽 PDF 패널 */
.pdf-panel {
    flex: 0 0 50%;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-left: 1px solid #ddd;
}

.pdf-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #2c3e50;
    color: #fff;
}

#pdf-title {
    font-size: 0.9rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 10px;
}

.btn-close {
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 5px 12px;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 4px;
}

.btn-close:hover {
    background: rgba(255,255,255,0.1);
}

.pdf-viewer {
    flex: 1;
    border: none;
    width: 100%;
    height: 100%;
}

/* 버튼 */
.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: #3498db;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #2980b9;
}

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

.btn-secondary:hover:not(:disabled) {
    background: #7f8c8d;
}

.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;
    flex-wrap: wrap;
}

.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 #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

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

/* 하이라이트 텍스트 */
.highlight-text {
    background: #ffeb3b;
    padding: 2px 4px;
    border-radius: 2px;
}

/* 반응형 */
@media (max-width: 1024px) {
    .main-layout {
        flex-direction: column;
    }

    .left-panel,
    .left-panel.with-pdf {
        flex: none;
        height: auto;
        min-height: 50vh;
    }

    .pdf-panel {
        flex: 1;
        min-height: 50vh;
    }

    .header {
        flex-direction: column;
        text-align: center;
    }

    .header-actions {
        justify-content: center;
    }
}

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

    .message {
        max-width: 95%;
    }

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

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