/* ========================================
   CSS Variables - Locked Color Scheme
   ======================================== */
:root {
    --color-primary: #F03E3E;
    --color-text-primary: #111111;
    --color-text-secondary: #555555;
    --color-background: #FFFFFF;
    --color-border: #E5E5E5;
    --color-hover: #D73737;

    /* Derived colors for UI elements */
    --color-primary-light: rgba(240, 62, 62, 0.1);
    --color-shadow: rgba(0, 0, 0, 0.1);
    --color-shadow-hover: rgba(0, 0, 0, 0.15);
}

/* ========================================
   Reset & Base Styles
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   Floating Chat Button
   ======================================== */
.chat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: var(--color-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--color-shadow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: #ffffff;
    z-index: 9998;
}

.chat-button:hover {
    background: var(--color-hover);
    box-shadow: 0 6px 16px var(--color-shadow-hover);
    transform: scale(1.05);
}

.chat-button:active {
    transform: scale(0.95);
}

.chat-button svg {
    width: 28px;
    height: 28px;
    transition: opacity 0.2s ease;
}

.chat-button .hidden {
    display: none;
}

/* ========================================
   Chat Window
   ======================================== */
.chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    height: 600px;
    max-height: calc(100vh - 120px);
    /* Prevent going out of viewport on small desktop screens */
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    transform-origin: bottom right;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.hidden {
    display: none;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ========================================
   Chat Header
   ======================================== */
.chat-header {
    background: var(--color-background);
    border-bottom: 1px solid var(--color-border);
    padding: 16px 20px;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.chat-header-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin-right: -8px;
    color: var(--color-text-secondary);
    border-radius: 50%;
    display: flex;
    /* Always visible, but most useful on mobile */
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.chat-header-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--color-text-primary);
}

.chat-header-close svg {
    width: 24px;
    height: 24px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-avatar svg {
    width: 24px;
    height: 24px;
}

.chat-header-text h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.chat-header-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.chat-status {
    font-size: 13px;
    color: var(--color-text-secondary);
}

/* ========================================
   Messages Container
   ======================================== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #FAFAFA;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #D0D0D0;
}

/* ========================================
   Message Bubbles
   ======================================== */
.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.5;
}

.message.user .message-content {
    background: var(--color-primary);
    color: var(--color-background);
    border-bottom-right-radius: 4px;
}

.message.bot .message-content {
    background: var(--color-background);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}

.message-timestamp {
    font-size: 11px;
    color: var(--color-text-secondary);
    margin-top: 4px;
    padding: 0 4px;
}

.message.user .message-timestamp {
    text-align: right;
}

/* ========================================
   Typing Indicator
   ======================================== */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    margin: 0 20px 12px 20px;
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    width: fit-content;
    max-width: 60px;
}

.typing-indicator.hidden {
    display: none;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--color-text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.7;
    }

    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ========================================
   Input Area
   ======================================== */
.chat-input-container {
    border-top: 1px solid var(--color-border);
    background: var(--color-background);
    padding: 16px 20px;
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: var(--color-text-primary);
    resize: none;
    outline: none;
    transition: border-color 0.2s ease;
    max-height: 120px;
    line-height: 1.5;
}

.chat-input:focus {
    border-color: var(--color-primary);
}

.chat-input::placeholder {
    color: var(--color-text-secondary);
}

.chat-send-button {
    width: 44px;
    height: 44px;
    background: var(--color-primary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-button:hover {
    background: var(--color-hover);
}

.chat-send-button:active {
    transform: scale(0.95);
}

.chat-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-send-button svg {
    width: 20px;
    height: 20px;
}

/* ========================================
   Markdown Styles
   ======================================== */
.message-content p {
    margin: 0 0 8px 0;
}

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

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

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

.message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.message.user .message-content code {
    background: rgba(255, 255, 255, 0.2);
}

.message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

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

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

.message.user .message-content a {
    color: var(--color-background);
}

.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 4px 0;
}

.message-content blockquote {
    border-left: 3px solid var(--color-border);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--color-text-secondary);
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 13px;
}

.message-content th,
.message-content td {
    border: 1px solid var(--color-border);
    padding: 8px;
    text-align: left;
}

.message-content th {
    background: rgba(0, 0, 0, 0.03);
    font-weight: 600;
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 768px) {
    .chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 80vh;
        /* Reduced from 100% to 80% */
        border-radius: 16px 16px 0 0;
        /* Round top corners only */
        border: 1px solid var(--color-border);
        border-bottom: none;
        box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.1);
        z-index: 10000;
        transition: transform 0.3s cubic-bezier(0, 0, 0.2, 1);
    }

    .chat-button {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
    }

    .chat-button svg {
        width: 24px;
        height: 24px;
    }

    .message {
        max-width: 85%;
    }
}

/* ========================================
   Utility Classes
   ======================================== */
.hidden {
    display: none !important;
}

/* ========================================
   Accessibility
   ======================================== */
.chat-button:focus,
.chat-send-button:focus,
.chat-input:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}