:root {
    --primary-color: #2563eb;
    --primary-gradient: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    --bg-color: #f3f4f6;
    --chat-bg: #ffffff;
    --text-main: #1f2937;
    --text-secondary: #6b7280;
    --bubble-user-text: #ffffff;
    --bubble-bot-bg: #f3f4f6;
    --bubble-bot-text: #111827;
    --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);
}

/* Global Reset for Safety */
* {
    box-sizing: border-box;
}



body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    color: var(--text-main);
}

/* Responsive Wrapper */
.main-wrapper {
    width: 100%;
    max-width: 1000px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 20px;
    box-sizing: border-box;
}

/* Titles */
h1 {
    color: var(--text-main);
    margin: 0;
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.05rem;
    text-align: center;
    line-height: 1.2;
}

/* Chat Container Card */
#chat-container {
    width: 100%;
    max-width: 500px;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    height: 100%;
    transition: all 0.3s ease;
}

/* Layout for Larger Screens */
@media(min-width: 800px) {
    .main-wrapper {
        flex-direction: row;
        gap: 60px;
        padding: 40px;
    }

    h1 {
        text-align: right;
        flex: 1;
        font-size: 3.0rem;
        padding-top: 0;
        align-self: center;
    }

    #chat-container {
        flex: 1.2;
        max-width: 480px;
        height: 80vh;
        /* Floating card feel */
    }
}

/* Header */
#header {
    padding: 20px;
    font-weight: 600;
    font-size: 1.1rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.9);
    border-bottom: 1px solid #e5e7eb;
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Messages Area */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.message {
    padding: 12px 18px;
    border-radius: 20px;
    max-width: 85%;
    line-height: 1.6;
    font-size: 0.95rem;
    position: relative;
    animation: fadeIn 0.3s ease-out;
}

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

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

.user {
    align-self: flex-end;
    background: var(--primary-gradient);
    color: var(--bubble-user-text);
    border-bottom-right-radius: 4px;
    box-shadow: var(--shadow-md);
}

.assistant {
    align-self: flex-start;
    background: var(--bubble-bot-bg);
    color: var(--bubble-bot-text);
    border-bottom-left-radius: 4px;
    border: 1px solid #e5e7eb;
}

/* Typing Indicator */
.typing {
    font-style: normal;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0 0 16px 24px;
    display: none;
    /* Controlled by JS */
    align-items: center;
    gap: 6px;
}

.typing::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #cbd5e1;
    border-radius: 50%;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }

    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
}

/* Input Area */
#input-area {
    padding: 20px;
    background: #fff;
    display: flex;
    gap: 12px;
    border-top: 1px solid #f3f4f6;
}

input {
    flex: 1;
    min-width: 0;
    /* Critical: Allows input to shrink below content size */
    width: 100%;
    /* Ensure it tries to fill flex item */
    padding: 14px 20px;
    border: 2px solid #e5e7eb;
    border-radius: 999px;
    /* Pill shape */
    outline: none;
    font-size: 1rem;
    transition: border-color 0.2s;
    background: #f9fafb;
}

input:focus {
    border-color: var(--primary-color);
    background: #fff;
}

button {
    padding: 0 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: transform 0.1s, background 0.2s;
    box-shadow: var(--shadow-md);
    display: inline-block;
    /* Revert flex center */
    width: auto;
    /* Allow auto width */
    height: auto;
}

button:hover {
    transform: translateY(-1px);
    filter: brightness(110%);
}

button:active {
    transform: translateY(1px);
}

button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

/* Scrollbar polish */
#messages::-webkit-scrollbar {
    width: 6px;
}

#messages::-webkit-scrollbar-track {
    background: transparent;
}

#messages::-webkit-scrollbar-thumb {
    background-color: #d1d5db;
    border-radius: 20px;
}

/* Mobile Tweaks (Placed at end to override defaults) */
@media (max-width: 480px) {
    .main-wrapper {
        padding: 10px;
    }

    #input-area {
        padding: 12px;
        gap: 8px;
        justify-content: space-between;
        /* Ensure spacing */
    }

    input {
        padding: 10px 16px;
        width: 70%;
        /* Widened to 70% */
        flex: initial;
        /* Disable flex grow to strictly obey width */
    }

    button {
        padding: 10px 16px;
        /* Adjust padding for mobile */
        width: auto;
        height: auto;
        flex-shrink: 0;
    }

    h1 {
        font-size: 1.8rem;
    }
}