:root {
    /* Color Palette - Light Mode */
    --bg-primary: #ffffff;
    --bg-secondary: #f9f9f9;
    --text-primary: #0d0d0d;
    --text-secondary: #6ec06e;
    /* Using a 4HB-ish green as accent/secondary text where appropriate, or grey */
    --text-muted: #8e8ea0;
    --border-color: #e5e5e5;

    --input-bg: #ececec;
    --button-hover: #d2d2d2;

    --user-msg-bg: #f4f4f4;
    --ai-msg-bg: transparent;

    --accent-color: #10a37f;
    /* OpenAI-ish green, fits 4HB generic health vibe too */

    --sidebar-hover: #e6e6e6;
    --sidebar-active: #ffffff;
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --bg-primary: #343541;
    --bg-secondary: #444654;
    --text-primary: #ececf1;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    --border-color: #565869;

    --input-bg: #40414f;
    --button-hover: #202123;

    /* Explicitly setting message backgrounds if they differ from bg properties */
    --user-msg-bg: transparent;
    --ai-msg-bg: var(--bg-secondary);

    /* Sidebar specific */
    --sidebar-hover: #2A2B32;
    --sidebar-active: #343541;
    /* Matches main chat window bg */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
    display: flex;
    flex-direction: row;
    /* Changed to row for Sidebar */
    height: 100%;
    max-width: 100%;
    margin: 0 auto;
    position: relative;
    width: 100%;
    overflow: hidden;
    /* Prevent body scroll when sidebar is open */
}

/* Main Content Wrapper */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    min-width: 0;
    /* Important for flex shrinking */
    overflow: hidden;
}

/* Header */
.chat-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid transparent;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}


.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand .logo {
    height: 32px;
    width: auto;
    border-radius: 30%;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-button:hover {
    background-color: var(--button-hover);
}

/* Mobile Only elements hidden by default - defined after icon-button to override display:flex */
.mobile-only {
    display: none !important;
}

/* Theme Toggle Icons */
.sun-icon {
    display: none;
}

.moon-icon {
    display: block;
}

[data-theme="dark"] .sun-icon {
    display: block;
}

[data-theme="dark"] .moon-icon {
    display: none;
}


/* Main Chat Window */
.chat-window {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 120px;
    /* Space for fixed input area */
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.welcome-message {
    margin-top: 20vh;
    text-align: center;
    color: var(--text-primary);
    font-size: 1.5rem;
    opacity: 0.8;
}

.message-row {
    width: 100%;
    padding: 1.5rem 1rem;
    display: flex;
    justify-content: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    /* Very subtle separator */
}

[data-theme="dark"] .message-row {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.message-row.user {
    background-color: var(--bg-primary);
    /* Often transparent or distinct in some designs, trying minimal */
}

/* Giving user messages a specific look can help distinguish. OpenAI does backgrounds. */
.message-row.user {
    background-color: var(--bg-primary);
}

.message-row.ai {
    background-color: var(--bg-secondary);
}


.message-content {
    max-width: 768px;
    /* Standard reading width */
    width: 100%;
    display: flex;
    gap: 1.5rem;
    font-size: 1rem;
    line-height: 1.6;
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 2px;
    /* ChatGPT style is squared with slight radius */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: bold;
    font-size: 0.8rem;
}

.user .avatar {
    background-color: #5436da;
    /* User arbitrary color */
    color: white;
}

.ai .avatar {
    background-color: #19c37d;
    /* OpenAI green-ish */
    color: white;
}

.text {
    flex: 1;
    word-wrap: break-word;
    /* Ensure long words wrap */
    overflow-wrap: break-word;
}

.text p {
    margin-bottom: 1rem;
}

.text p:last-child {
    margin-bottom: 0;
}


/* Input Area */
.input-area {
    position: absolute;
    /* Changed from fixed so it stays within main-content */
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 20;
    /* Ensure it stays above chat messages */
    background-color: var(--bg-primary);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, var(--bg-primary) 20%);
    padding: 2rem 1rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

[data-theme="dark"] .input-area {
    background: linear-gradient(180deg, rgba(52, 53, 65, 0) 0%, var(--bg-primary) 20%);
}

.input-container {
    max-width: 768px;
    width: 100%;
    position: relative;
    display: flex;
    align-items: flex-end;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    max-height: 200px;
    outline: none;
    padding: 0;
    margin: 0;
    line-height: 1.5;
}

textarea::placeholder {
    color: var(--text-muted);
}

#send-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    margin-left: 0.5rem;
    transition: color 0.2s;
}

#send-btn:not(:disabled) {
    color: var(--accent-color);
}

#send-btn:disabled {
    cursor: not-allowed;
}


.disclaimer {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
    text-align: center;
}

/* Loading Dot Animation */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
}

.dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) {
    animation-delay: -0.32s;
}

.dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Mobile Tweak */
@media (max-width: 768px) {

    /* Specific overrides if needed */
    .chat-header {
        padding: 0.75rem;
    }

    .chat-window {
        padding-bottom: 140px;
    }

    .message-row {
        padding: 1rem 0.5rem;
    }

    .message-content {
        gap: 0.75rem;
        /* Reduce gap between avatar and text */
        padding: 0;
    }

    .avatar {
        width: 24px;
        height: 24px;
        font-size: 0.7rem;
    }

    .input-area {
        padding: 0.75rem;
        background: var(--bg-primary);
        /* Solid background on mobile */
        border-top: 1px solid var(--border-color);
        /* Separator helps on mobile */
    }

    .input-container {
        padding: 0.5rem 0.75rem;
    }

    .disclaimer {
        font-size: 0.7rem;
        margin-top: 0.5rem;
    }

    .welcome-message {
        margin: auto 10px;
    }
}