:root {
    --bg-main: #212121;
    --bg-sidebar: #171717;
    --bg-input: #2f2f2f;
    --text-primary: #ececec;
    --text-secondary: #b4b4b4;
    --border-color: rgba(255, 255, 255, 0.1);
    --hover-bg: #2a2b32;
    --button-bg: #ececec;
    --button-text: #171717;
    --user-msg-bg: #2f2f2f;
    --primary-accent: #10a37f;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    padding: 12px;
    border-right: 1px solid var(--border-color);
    transition: width 0.3s ease;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    position: relative;
    font-family: 'Inter', sans-serif;
}

.new-chat-btn:hover {
    background-color: var(--hover-bg);
}

.new-chat-btn:active {
    transform: scale(0.98);
}

.new-chat-btn .tooltip {
    visibility: hidden;
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background-color: #000;
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    margin-left: 10px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 100;
}

.new-chat-btn:hover .tooltip {
    visibility: visible;
    opacity: 1;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    margin-top: 24px;
}

.chat-history::-webkit-scrollbar {
    width: 6px;
}
.chat-history::-webkit-scrollbar-thumb {
    background-color: rgba(255,255,255,0.2);
    border-radius: 3px;
}

.history-label {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 8px 12px;
    font-weight: 500;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    transition: background-color 0.2s;
}

.history-item:hover {
    background-color: var(--hover-bg);
}

.history-item.current {
    background-color: var(--hover-bg);
}

.history-item .truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
    margin-top: 12px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.user-profile:hover {
    background-color: var(--hover-bg);
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.user-avatar {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

/* --- MAIN CHAT AREA --- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--bg-main);
}

.chat-header {
    display: none; /* Hide on larger screens, show on mobile */
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
    font-size: 16px;
    font-weight: 500;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background-color: rgba(255,255,255,0.2);
    border-radius: 4px;
}

.message {
    padding: 24px 0;
    width: 100%;
}

.message.user {
    /* To align user similar to newer ChatGPT styles, we give it a specific look */
    display: flex;
    justify-content: flex-end;
    padding: 12px 24px;
}

.message.assistant {
    display: flex;
    justify-content: flex-start;
    padding: 12px 24px;
}

.message-content {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    gap: 20px;
}

.message.user .message-content {
    margin: 0;
    width: auto;
    max-width: 70%;
    background-color: var(--user-msg-bg);
    padding: 16px;
    border-radius: 16px;
    border-bottom-right-radius: 4px;
}

.message.user .avatar-wrapper {
    display: none; /* Hidden for user in new style */
}

.assistant-avatar {
    background-color: #ffffff;
    color: #171717;
    border: 1px solid var(--border-color);
}

.message-body {
    flex: 1;
    line-height: 1.6;
    font-size: 16px;
    min-width: 0;
    color: var(--text-primary);
}

.message-body pre {
    background-color: #0d0d0d;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
}

.message-body code {
    font-family: 'Courier New', Courier, monospace;
    background-color: #2f2f2f;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

.message-body pre code {
    background-color: transparent;
    padding: 0;
}

.message-body p {
    margin-bottom: 12px;
}

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

.message-body ul, .message-body ol {
    margin-left: 24px;
    margin-bottom: 12px;
}

/* --- INPUT AREA --- */
.chat-input-container {
    padding: 0 48px;
    padding-bottom: 24px;
    max-width: 850px;
    width: 100%;
    margin: 0 auto;
    background-image: linear-gradient(180deg, transparent 0%, var(--bg-main) 30%);
}

.input-form {
    position: relative;
    width: 100%;
}

.input-wrapper {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 12px 48px 12px 18px;
    display: flex;
    align-items: flex-end;
    box-shadow: 0 0 15px rgba(0,0,0,0.1);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-accent);
    box-shadow: 0 0 15px rgba(16, 163, 127, 0.1);
}

textarea {
    width: 100%;
    max-height: 200px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    resize: none;
    outline: none;
    overflow-y: auto;
    padding: 4px 0;
    line-height: 1.5;
}

textarea::placeholder {
    color: var(--text-secondary);
}

textarea::-webkit-scrollbar {
    width: 4px;
}
textarea::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 4px;
}

#send-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 32px;
    height: 32px;
    background-color: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

#send-btn:disabled {
    background-color: #2f2f2f;
    color: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.5;
}

#send-btn:not(:disabled):hover {
    transform: scale(1.05);
}

#send-btn:not(:disabled):active {
    transform: scale(0.95);
}

.footer-text {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 12px;
}

/* Loading animation dots */
.loading-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 20px;
}

.loading-dots span {
    display: block;
    width: 6px;
    height: 6px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); background-color: var(--text-primary); }
}

@media (max-width: 768px) {
    .sidebar {
        display: none; /* Hide sidebar on mobile for simplicity */
    }
    .chat-header {
        display: block;
    }
    .chat-input-container {
        padding: 0 16px;
        padding-bottom: 16px;
    }
    .message-content {
        padding: 0 16px;
    }
    .message.user {
        padding: 12px 16px;
    }
}

.ai-icon {
    width: 20px;
    height: 20px;
    filter: invert(1);
}
