@import url('https://fonts.googleapis.com/css2?family=Bitter:wght@700&family=Inter:wght@400;500;600&display=swap');

:root {
    --primary-color: #9A1B82;
    /* Purple */
    --accent-color: #E30613;
    /* Red */
    --text-dark: #1d1d1f;
    --text-light: #555;
    --bg-light: #ffffff;
    --white: #ffffff;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-light);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased;
}

/* Chat Widget Button */
.chat-widget-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    background-color: var(--primary-color);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(154, 27, 130, 0.4);
    z-index: 1000;
    transition: transform 0.3s;
}

.chat-widget-btn:hover {
    transform: scale(1.1);
}

.chat-widget-btn svg {
    width: 30px;
    height: 30px;
    fill: var(--white);
}

.chat-window {
    position: fixed;
    bottom: 6rem;
    right: 2rem;
    width: 380px;
    height: 600px;
    background-color: var(--white);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    z-index: 1001;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.chat-window.active {
    transform: scale(1);
    opacity: 1;
}

.chat-header {
    background-color: var(--primary-color);
    color: var(--white);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.chat-close {
    cursor: pointer;
    background: none;
    border: none;
    color: var(--white);
    font-size: 1.2rem;
}

.chat-body {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background-color: #f7f9fc;
    /* Watermark Background */
    background-image: url('back-icon.webp');
    background-position: center;
    background-repeat: no-repeat;
    background-size: 70%;
    /* Adjust size as needed */
    background-blend-mode: soft-light;
    /* Fallback opacity handling if blend-mode isn't sufficient, but strictly for the image */
}

.message {
    max-width: 85%;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background-color: var(--primary-color);
    color: var(--white);
    border-bottom-right-radius: 2px;
}

.message.assistant {
    align-self: flex-start;
    background-color: var(--white);
    color: var(--text-dark);
    border-bottom-left-radius: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.chat-footer {
    padding: 1rem;
    background-color: var(--white);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.input-container {
    display: flex;
    gap: 0.5rem;
    background-color: #f0f2f5;
    padding: 0.5rem;
    border-radius: 24px;
    align-items: center;
}

.input-container input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.5rem;
    font-size: 0.95rem;
    outline: none;
}

.input-container button {
    background-color: var(--primary-color);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--white);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s;
}

.input-container button:hover {
    background-color: #7a1566;
    transform: scale(1.05);
}

.input-container button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* Citations */
.sources-container {
    margin-top: 0.8rem;
    border-top: 1px solid #eee;
    padding-top: 0.5rem;
    font-size: 0.8rem;
}

.sources-label {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.3rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.source-item {
    background: #f9f9f9;
    padding: 0.5rem;
    border-radius: 6px;
    margin-bottom: 0.4rem;
    border: 1px solid #eee;
    transition: transform 0.2s;
}

.source-item:hover {
    transform: translateX(2px);
    border-color: var(--primary-color);
}

.source-title {
    font-weight: 600;
    color: var(--text-dark);
    display: block;
    margin-bottom: 0.2rem;
    text-decoration: none;
}

.source-title:hover {
    text-decoration: underline;
}

.source-snippet {
    color: #666;
    font-size: 0.75rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Markdown Styles in Chat */
.message.assistant p {
    margin-bottom: 0.8rem;
}

.message.assistant p:last-child {
    margin-bottom: 0;
}

.message.assistant a {
    color: var(--primary-color);
    text-decoration: underline;
}

.message.assistant strong {
    font-weight: 600;
}

.message.assistant em {
    font-style: italic;
}

.message.assistant ul,
.message.assistant ol {
    margin: 0.5rem 0 0.8rem 1.2rem;
    padding-left: 0;
}

.message.assistant li {
    margin-bottom: 0.3rem;
}

.message.assistant blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 0.8rem;
    margin: 0.8rem 0;
    color: var(--text-light);
    font-style: italic;
}

.message.assistant code {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.message.assistant pre {
    background-color: #f4f4f4;
    padding: 0.8rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.8rem 0;
}

.message.assistant pre code {
    background: none;
    padding: 0;
}

/* Chat Image Styling */
.message.assistant img {
    max-width: 100%;
    max-height: 200px;
    width: auto;
    height: auto;
    border-radius: 8px;
    margin: 0.8rem 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: block;
    object-fit: contain;
}


/* Typing Indicator */
.typing {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
}

.typing span {
    width: 6px;
    height: 6px;
    background: #ccc;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Responsive */
@media (max-width: 768px) {
    header {
        padding: 1rem 1.5rem;
    }

    .hero {
        padding: 0 1.5rem;
        justify-content: flex-start;
    }

    .hero h1 {
        font-size: 3rem;
    }

    .chat-window {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
}

/* Embed Mode overrides */
body.embed-mode {
    background-color: transparent;
    /* Allow iframe transparent bg if needed */
}

body.embed-mode main {
    display: none !important;
    /* Hide the placeholder text */
}

body.embed-mode .chat-window {
    position: fixed;
    /* or relative, since main is hidden */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    transform: none;
    opacity: 1;
    z-index: 10;
}

body.embed-mode .chat-header {
    display: none;
}