@font-face {
    font-family: 'DroplineRegular';
    src: url('../fonts/DroplineRegular-Wpegz.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Ubahin';
    src: url('../fonts/Ubahin-xRJ1r.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0;
    margin: 0;
}

.chat-container {
    width: 100%;
    max-width: none;
    height: 100vh;
    background: var(--bg-primary);
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 헤더 */
.chat-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem 0 1.5rem;
    flex-shrink: 0;
    position: relative;
    overflow: visible;
    min-height: 60px;
    /* Safe area support for mobile */
    padding-top: max(0.75rem, env(safe-area-inset-top));
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.bot-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: 75px;
}

.bot-avatar {
    width: 67px;
    height: 60px;
    position: absolute;
    bottom: 0;
    left: 1.5rem;
    z-index: 10;
    background: none;
    border-radius: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    overflow: visible;
}

.bot-avatar .avatar-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 0;
    position: absolute;
    bottom: -3px;
    left: 0;
    display: block;
    margin: 0;
    padding: 0;
    line-height: 0;
    vertical-align: bottom;
}

.bot-name {
    font-family: 'DroplineRegular', 'Inter', sans-serif;
    font-size: 1.5rem;
    font-weight: 600;
    color: #2563eb;
    margin-bottom: 0;
}

.bot-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.status-indicator {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--secondary-color);
    animation: pulse 2s infinite;
}

.status-indicator.preparing {
    background: #FF9800;
    box-shadow: 0 0 8px rgba(255, 152, 0, 0.6);
}

.status-indicator.online {
    background: #4CAF50;
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
}

.status-indicator.offline {
    background: #F44336;
    box-shadow: 0 0 8px rgba(244, 67, 54, 0.6);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.action-btn {
    width: 2.25rem;
    height: 2.25rem;
    border: none;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* 메시지 영역 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--bg-secondary);
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.message {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.message.user-message {
    flex-direction: row-reverse;
    gap: 0;
}

.message-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    flex-shrink: 0;
    overflow: hidden;
}

.bot-message .message-avatar {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
}

.message-avatar .avatar-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.user-message .message-avatar {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.message-content {
    flex: 1;
    max-width: 70%;
}

.user-message .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-width: 70%;
    margin-left: auto;
}

.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    line-height: 1.5;
}

.bot-message .message-bubble {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.user-message .message-bubble {
    background: var(--primary-color);
    color: white;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.user-message .message-time {
    text-align: right;
}

/* 타이핑 인디케이터 */
.typing-indicator {
    display: none;
    padding: 0 1rem;
    background: var(--bg-secondary);
}

.typing-indicator.show {
    display: block;
}

.typing {
    background: var(--bg-primary) !important;
    border: 1px solid var(--border-color) !important;
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
}

.typing-dots span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

/* 입력 영역 */
.chat-input-area {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    flex-shrink: 0;
}

.input-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

#user-input {
    flex: 1;
    min-height: 2.5rem;
    max-height: 8rem;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-family: inherit;
    font-size: 0.875rem;
    resize: none;
    transition: border-color 0.2s ease;
    line-height: 1.4;
}

#user-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

#user-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    background: var(--primary-color);
    color: white;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* 모달 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 2rem;
    height: 2rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.setting-group input[type="text"] {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
}

.setting-group input[type="checkbox"] {
    margin-right: 0.5rem;
}

.setting-group small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.btn-primary, .btn-secondary, .danger-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
}

.danger-btn {
    background: var(--error-color);
    color: white;
}

.danger-btn:hover {
    background: #dc2626;
}

/* 토스트 */
.toast {
    position: fixed;
    top: 2rem;
    right: 2rem;
    background: var(--error-color);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 1001;
    animation: slideIn 0.3s ease;
}

.toast.show {
    display: block;
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* 애니메이션 */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* 참고자료 링크 */
.reference-link {
    color: white;
    background: var(--primary-color);
    padding: 0.2rem 0.4rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--primary-dark);
    transition: all 0.2s ease;
    display: inline-block;
    margin: 0.15rem 0.2rem;
    font-size: 0.8rem;
    min-width: 1.5rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
    vertical-align: baseline;
}

.reference-link:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.reference-link-disabled {
    color: white;
    background: var(--text-muted);
    padding: 0.2rem 0.4rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-decoration: none;
    border: 1px solid #94a3b8;
    display: inline-block;
    margin: 0.15rem 0.2rem;
    font-size: 0.8rem;
    min-width: 1.5rem;
    text-align: center;
    opacity: 0.7;
    vertical-align: baseline;
}

/* 참고자료 모달 */
.reference-modal-content {
    max-width: 700px;
    max-height: 85vh;
    width: 95%;
}

.reference-info {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.reference-info h3 {
    color: var(--text-primary);
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.reference-source,
.reference-group {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0.25rem 0;
}

.reference-content h4 {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    border-left: 3px solid var(--primary-color);
    padding-left: 0.75rem;
}

.reference-text {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    max-height: 400px;
    overflow-y: auto;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.reference-text::-webkit-scrollbar {
    width: 6px;
}

.reference-text::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.reference-text::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.reference-text::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* 반응형 */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    
    .chat-container {
        height: 100vh;
        border-radius: 0;
        max-width: none;
        width: 100%;
    }
    
    .chat-header {
        padding: 0.5rem 1rem 0 1rem;
        padding-top: max(0.5rem, env(safe-area-inset-top));
        min-height: 55px;
    }
    
    .bot-avatar {
        width: 55px;
        height: 50px;
        left: 1rem;
    }
    
    .bot-info {
        margin-left: 72px;
    }
    
    .bot-name {
        font-size: 1.1rem;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .chat-input-area {
        padding: 1rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 1rem;
    }
    
    .toast {
        right: 1rem;
        left: 1rem;
        top: 1rem;
    }
    
    .reference-modal-content {
        width: 98%;
        max-height: 90vh;
        margin: 1rem;
    }
    
    .reference-text {
        max-height: 300px;
        padding: 0.75rem;
    }
    
    .modal-footer {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .modal-footer button {
        width: 100%;
    }
}

/* 모바일 앱 환경 최적화 */
@media (max-width: 480px) {
    .chat-header {
        padding: 0.25rem 0.75rem 0 0.75rem;
        padding-top: max(0.25rem, env(safe-area-inset-top));
        min-height: 50px;
    }
    
    .bot-avatar {
        width: 50px;
        height: 45px;
        left: 0.75rem;
    }
    
    .bot-info {
        margin-left: 65px;
    }
    
    .bot-name {
        font-size: 1rem;
    }
    
    .header-content {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .bot-info {
        flex: 1;
    }
    
    .input-footer {
        flex-direction: column;
        gap: 0.25rem;
        align-items: flex-start;
    }
}

/* Child Text Highlight Styling */
.child-highlight {
    background-color: #ffff00;  /* 밝은 노란색 */
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(255, 255, 0, 0.3);
    border: 1px solid #ffeb3b;
    transition: all 0.2s ease;
}

.child-highlight:hover {
    background-color: #fff9c4;
    box-shadow: 0 2px 6px rgba(255, 255, 0, 0.4);
}

/* Reference Content Header Styling */
.reference-text h1 {
    background: linear-gradient(135deg, #1e40af, #1d4ed8);
    color: white;
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-md);
    margin: 1.2rem 0 0.6rem 0;
    font-weight: 600;
    font-size: 1.1rem;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid rgba(255, 255, 255, 0.3);
}

.reference-text h2 {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius-md);
    margin: 1rem 0 0.5rem 0;
    font-weight: 600;
    font-size: 1rem;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid rgba(255, 255, 255, 0.3);
}

.reference-text h3 {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-sm);
    margin: 0.8rem 0 0.4rem 0;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: var(--shadow-sm);
    border-left: 3px solid rgba(255, 255, 255, 0.3);
}

.reference-text h4 {
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    color: white;
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    margin: 0.6rem 0 0.3rem 0;
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: var(--shadow-sm);
    border-left: 3px solid rgba(255, 255, 255, 0.3);
}

.reference-text h5,
.reference-text h6 {
    background: linear-gradient(135deg, #93c5fd, #60a5fa);
    color: white;
    padding: 0.25rem 0.4rem;
    border-radius: var(--radius-sm);
    margin: 0.5rem 0 0.25rem 0;
    font-weight: 500;
    font-size: 0.85rem;
    box-shadow: var(--shadow-sm);
    border-left: 2px solid rgba(255, 255, 255, 0.3);
}

/* Disclaimer Message Styling */
.disclaimer-message {
    margin-bottom: 0.5rem;
}

.disclaimer-message .message-avatar {
    background: linear-gradient(135deg, var(--warning-color), #e69500);
    color: white;
}

.disclaimer-bubble {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #92400e;
    border: 1px solid #f59e0b;
    border-left: 4px solid var(--warning-color);
}

.disclaimer-bubble p {
    margin: 0;
    font-weight: 500;
}

/* Reference List Box Styling */
.reference-list-box {
    margin: 1rem 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    max-width: 85%;
    margin-left: 0;
    margin-right: auto;
}

.reference-list-header {
    background: linear-gradient(135deg, #374151, #4b5563);
    color: white;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.reference-list-header i {
    font-size: 1rem;
    color: #fbbf24;
}

.reference-list-content {
    padding: 1rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-primary);
}

.reference-list-content h1,
.reference-list-content h2,
.reference-list-content h3,
.reference-list-content h4,
.reference-list-content h5,
.reference-list-content h6 {
    background: none;
    color: var(--text-primary);
    padding: 0;
    margin: 0.5rem 0 0.25rem 0;
    font-weight: 600;
    border: none;
    box-shadow: none;
}

.reference-list-content h1 { font-size: 1rem; }
.reference-list-content h2 { font-size: 0.95rem; }
.reference-list-content h3 { font-size: 0.9rem; }
.reference-list-content h4 { font-size: 0.85rem; }
.reference-list-content h5,
.reference-list-content h6 { font-size: 0.8rem; }

/* 참고자료 리스트 박스 내 참고자료 링크도 동일한 스타일 적용 */
.reference-list-content .reference-link {
    color: white;
    background: var(--primary-color);
    padding: 0.15rem 0.3rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--primary-dark);
    display: inline-block;
    margin: 0.12rem 0.15rem;
    font-size: 0.75rem;
    min-width: 1.3rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
    vertical-align: baseline;
}

.reference-list-content .reference-link-disabled {
    color: white;
    background: var(--text-muted);
    padding: 0.15rem 0.3rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-decoration: none;
    border: 1px solid #94a3b8;
    display: inline-block;
    margin: 0.12rem 0.15rem;
    font-size: 0.75rem;
    min-width: 1.3rem;
    text-align: center;
    opacity: 0.7;
    vertical-align: baseline;
}

.reference-list-time {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-muted);
}