:root {
    --bg-color: #0b0e14;
    --container-bg: #161a22;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --mic-active: #ef4444;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --bot-msg-bg: #1e2430;
    --user-msg-bg: #3b82f6;
    --sidebar-bg: #0f1115;
}

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

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

/* Layout */
.app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex-shrink: 0;
}

.new-chat-btn {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}
.new-chat-btn:hover { background: var(--primary-color); border-color: var(--primary-color); }

.history-list {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid transparent;
}
.history-item:hover { background: rgba(255, 255, 255, 0.08); color: white; }
.history-item.active { background: rgba(59, 130, 246, 0.2); border-color: var(--primary-color); color: white;}

/* Chat Area */
.chat-wrapper {
    flex-grow: 1;
    padding: 20px;
    display: flex;
    justify-content: center;
}

.chat-container {
    width: 100%;
    max-width: 900px;
    background: rgba(22, 26, 34, 0.8);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.chat-header {
    background: rgba(0, 0, 0, 0.25);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.header-info h1 { font-size: 1.2rem; background: linear-gradient(to right, #60a5fa, #c084fc); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.status-indicator { font-size: 0.8rem; color: #10b981; }

.header-controls { display: flex; gap: 15px; }
.control-btn { background: none; border: none; font-size: 1.3rem; cursor: pointer; opacity: 0.7; transition: 0.2s; }
.control-btn:hover { opacity: 1; transform: scale(1.1); }

/* Messages */
.chat-messages {
    flex-grow: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.message { display: flex; align-items: flex-end; gap: 12px; max-width: 85%; animation: fadeIn 0.3s ease; }
.user-message { align-self: flex-end; flex-direction: row-reverse; }
.bot-message { align-self: flex-start; }

.profile-image { width: 36px; height: 36px; border-radius: 50%; background: #334155; padding: 2px; }

.message-content {
    padding: 14px 20px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.6;
    word-wrap: break-word;
}
.user-message .message-content { background: var(--user-msg-bg); color: #fff; border-bottom-right-radius: 6px; }
.bot-message .message-content { background: var(--bot-msg-bg); border-bottom-left-radius: 6px; border: 1px solid rgba(255,255,255,0.05); }

/* Markdown & Code Blocks */
.message-content pre { position: relative; background: #0d1117; padding: 14px; border-radius: 10px; overflow-x: auto; margin: 10px 0; border: 1px solid rgba(255,255,255,0.05); }
.message-content code { font-family: 'Courier New', monospace; background: rgba(0,0,0,0.3); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.message-content pre code { background: transparent; padding: 0; }

.copy-btn {
    position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,0.1); border: none; color: white; padding: 4px 8px; border-radius: 4px; font-size: 0.75rem; cursor: pointer; transition: 0.2s;
}
.copy-btn:hover { background: rgba(255,255,255,0.2); }

/* Image Preview */
#image-preview-container { padding: 10px 24px; display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,0.2); border-top: 1px solid rgba(255,255,255,0.05); }
#image-preview { height: 60px; border-radius: 8px; border: 1px solid var(--primary-color); object-fit: cover; }
#remove-image { background: rgba(239, 68, 68, 0.2); border: none; color: #ef4444; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; }

/* Input Footer */
.chat-input-container { padding: 20px 24px; background: rgba(0, 0, 0, 0.2); display: flex; align-items: flex-end; gap: 12px; border-top: 1px solid rgba(255, 255, 255, 0.05); }

#user-input { flex-grow: 1; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 14px; padding: 14px; color: var(--text-main); font-family: inherit; resize: none; max-height: 120px; outline: none; }
#user-input:focus { border-color: var(--primary-color); }

.icon-btn { border: none; border-radius: 14px; width: 48px; height: 48px; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: 0.2s; flex-shrink: 0; background: rgba(255, 255, 255, 0.05); color: var(--text-main); font-size: 1.2rem;}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }

#mic-button.listening { background: rgba(239, 68, 68, 0.2); color: var(--mic-active); animation: pulse 1.5s infinite; }
.send-style { background: var(--primary-color); color: white; }
.send-style:hover { background: var(--primary-hover); transform: translateY(-2px); }

@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); } 70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
::-webkit-scrollbar { width: 6px; } ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 10px; }

/* --- Login Screen --- */
.login-screen {
    position: absolute;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: radial-gradient(circle at center, #1a202c, #0b0e14);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.login-box {
    background: rgba(22, 26, 34, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 40px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.5s ease;
}

.login-box h1 {
    font-size: 1.8rem;
    margin-bottom: 10px;
    background: linear-gradient(to right, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-box p { color: var(--text-muted); margin-bottom: 25px; font-size: 0.95rem; }

#username-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    color: white;
    font-size: 1rem;
    margin-bottom: 20px;
    outline: none;
    transition: 0.3s;
}

#username-input:focus { border-color: var(--primary-color); background: rgba(255,255,255,0.08); }

.login-btn {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    color: white;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.3s;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.login-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4); }

.logout-btn {
    width: 100%;
    padding: 12px;
    margin-top: auto;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}
.logout-btn:hover { background: rgba(239, 68, 68, 0.2); }