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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #1e1e2e;
    color: #e0e0e0;
}

/* ===== Layout ===== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: #171723;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #2a2a3c;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #2a2a3c;
}

.new-chat-btn {
    width: 100%;
    padding: 10px 16px;
    background: #2a2a3c;
    color: #e0e0e0;
    border: 1px solid #3a3a4c;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: #3a3a4c;
}

.sidebar-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-item {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    color: #b0b0c0;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.2s;
}

.history-item:hover {
    background: #2a2a3c;
}

.history-placeholder {
    padding: 16px 12px;
    font-size: 12px;
    color: #666680;
    text-align: center;
}

/* ===== Main Chat Area ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 14px 20px;
    border-bottom: 1px solid #2a2a3c;
    font-size: 16px;
    font-weight: 600;
    background: #1e1e2e;
}

/* ===== Messages ===== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    max-width: 75%;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

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

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

.message-bubble {
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user .message-bubble {
    background: #4f46e5;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: #2a2a3c;
    color: #e0e0e0;
    border-bottom-left-radius: 4px;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 10px 16px;
    background: #2a2a3c;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.typing-indicator.visible {
    display: flex;
    align-items: center;
    gap: 5px;
}

.typing-indicator .dot {
    width: 8px;
    height: 8px;
    background: #888;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator .dot:nth-child(1) { animation-delay: 0s; }
.typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ===== Input Area ===== */
.input-area {
    padding: 12px 20px 16px;
    border-top: 1px solid #2a2a3c;
    background: #1e1e2e;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #2a2a3c;
    border-radius: 12px;
    padding: 8px 12px;
    border: 1px solid #3a3a4c;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: #4f46e5;
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #e0e0e0;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
}

.input-wrapper textarea::placeholder {
    color: #666680;
}

.send-btn {
    background: #4f46e5;
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.send-btn:hover {
    background: #4338ca;
}

.send-btn:disabled {
    background: #3a3a4c;
    cursor: not-allowed;
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

/* ===== Welcome Screen ===== */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #666680;
    gap: 8px;
}

.welcome-screen h2 {
    font-size: 22px;
    color: #b0b0c0;
}

.welcome-screen p {
    font-size: 14px;
}

/* ===== Sidebar Toggle (mobile) ===== */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: #e0e0e0;
    font-size: 22px;
    cursor: pointer;
    padding: 0 8px;
}

/* ===== Scrollbar ===== */
.messages-container::-webkit-scrollbar,
.sidebar-history::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track,
.sidebar-history::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb,
.sidebar-history::-webkit-scrollbar-thumb {
    background: #3a3a4c;
    border-radius: 3px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: -260px;
        height: 100%;
        z-index: 100;
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-toggle {
        display: block;
    }

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