:root {
    --bg-color: #1a1b26;
    --sidebar-bg: #16161e;
    --chat-bg: #1a1b26;
    --input-bg: #24283b;
    --text-color: #a9b1d6;
    --accent-color: #7aa2f7;
    --user-msg-bg: #3d59a1;
    --char-msg-bg: #24283b;
    --border-color: #414868;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: varেনি-bg-color;
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1200px;
    margin: 0 auto;
    background-color: var(--chat-bg);
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

/* Login Overlay */
#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.login-box {
    background-color: var(--sidebar-bg);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
    text-align: center;
    width: 90%;
    max-width: 400px;
}

.login-box h2 {
    margin-bottom: 20px;
    color: var(--accent-color);
}

.login-box input {
    width: 100%;
    padding: 12px;
    margin-bottom: 20px;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: #fff;
    font-size: 1rem;
}

.login-box button {
    width: 100%;
    padding: 12px;
    background-color: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.login-box button:hover {
    filter: brightness(1.1);
}

/* App Container Layout */
.app-container {
    display: flex;
    flex-direction: row; /* Changed to row for sidebar */
    height: 100%;
    max-width: 1600px; /* Increased max-width */
    margin: 0 auto;
    background-color: var(--chat-bg);
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    position: relative;
}

/* Sidebar for Characters */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    color: var(--accent-color);
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
}

.character-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.char-card {
    display: flex;
    align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    gap: 12px;
}

.char-card:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.char-card.active {
    background-color: var(--accent-color);
    color: #fff;
}

.char-card .char-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #333;
    object-fit: cover;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
}

.char-info h4 {
    font-size: 1rem;
    margin-bottom: 2px;
}

.char-info p {
    font-size: 0.8rem;
    color: #777;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.char-card.active .char-info p {
    color: rgba(255,255,255,0.8);
}

/* Main Chat Area Wrapper */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    min-width: 0; /* Fix flex child overflow */
}

/* Header adjustments */
.chat-header {
    padding: 15px 20px;
    background-color: rgba(22, 22, 30, 0.95);
    border-bottom: 1px solid var(--border-color);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .sidebar.open {
        max-height: 300px;
        border-bottom: 1px solid var(--border-color);
    }
    
    .mobile-menu-toggle {
        display: block;
        margin-right: 15px;
        cursor: pointer;
        font-size: 1.2rem;
    }
}


.avatar {
    width: 40px;
    height: 40px;
    background-color: var(--accent-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #fff;
}

.name-status h2 {
    font-size: 1.1rem;
    color: #fff;
}

.status {
    font-size: 0.8rem;
    color: #9ece6a;
}

.actions button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    margin-left: 10px;
    padding: 5px;
    transition: color 0.2s;
}

.actions button:hover {
    color: var(--accent-color);
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message {
    display: flex;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.char {
    align-self: flex-start;
}

.message.system {
    align-self: center;
    font-size: 0.9rem;
    color: #565f89;
    text-align: center;
    max-width: 90%;
}

.message .content {
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

.code-block {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 6px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
    white-space: pre-wrap; /* Preserve whitespace */
    margin: 10px 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.message.user .content {
    background-color: var(--user-msg-bg);
    color: #fff;
    border-bottom-right-radius: 2px;
}

.message.char .content {
    background-color: var(--char-msg-bg);
    border-bottom-left-radius: 2px;
}

/* Input Area */
.input-area {
    padding: 20px;
    background-color: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

textarea {
    flex: 1;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    color: #fff;
    resize: none;
    font-family: inherit;
    outline: none;
    max-height: 150px;
}

textarea:focus {
    border-color: var(--accent-color);
}

#send-btn {
    background-color: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 45px;
    height: 45px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#send-btn:hover {
    filter: brightness(1.1);
}

#send-btn:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.hidden {
    display: none;
}

.modal-content {
    background-color: var(--sidebar-bg);
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 5px 30px rgba(0,0,0,0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

.form-group input, .form-group textarea {
    width: 100%;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    color: #fff;
}

.modal-footer {
    margin-top: 20px;
    text-align: right;
}

#save-settings {
    background-color: var(--accent-color);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Markdown styling simplified */
.content p { margin-bottom: 0.5em; }
.content p:last-child { margin-bottom: 0; }
