:root {
    --bg-primary: #212121;
    --bg-secondary: #171717;
    --bg-sidebar: #171717;
    --text-primary: #ececec;
    --text-secondary: #b4b4b4;

    --accent: #10a37f;
    /* Original AI green */
    --accent-hover: #0d8a6b;

    --message-user: #212121;
    --message-ai: #212121;
    /* Transparent/same as bg for clean look */

    --border-color: rgba(255, 255, 255, 0.1);
    --input-bg: #2f2f2f;

    --radius-md: 0.75rem;
    --font-sans: 'Inter', 'Cairo', sans-serif;
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

.sidebar-header {
    padding: 1rem;
    /* padding-top: 1rem; */
}

.new-chat {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.new-chat:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* History Item */
.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: background-color 0.2s, color 0.2s;
    position: relative;
    overflow: hidden;
}

.history-item:hover,
.history-item.active {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.history-item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.delete-btn-icon {
    opacity: 0;
    transition: opacity 0.2s;
    font-size: 1rem;
    display: grid;
    place-items: center;
    padding: 4px;
    border-radius: 4px;
}

.history-item:hover .delete-btn-icon {
    opacity: 1;
}

.delete-btn-icon:hover {
    background-color: rgba(255, 0, 0, 0.2);
    color: #ff5252;
}

/* User Profile */
.user-profile {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar-small {
    width: 2rem;
    height: 2rem;
    background-color: #7c3aed;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-info .name {
    font-size: 0.875rem;
    font-weight: 600;
}

.user-info .status {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Chat Main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
}

/* Header */
.chat-header {
    height: 3.5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 0.375rem;
}

.icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Model Selector & Dropdown */
.model-menu-container {
    position: relative;
    z-index: 20;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.model-selector:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.chevron-icon {
    transition: transform 0.2s;
}

.model-menu-container.open .chevron-icon {
    transform: rotate(180deg);
}

.model-dropdown {
    position: absolute;
    top: 120%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    width: 320px;
    max-height: 500px;
    overflow-y: auto;
    background-color: #2f2f2f;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    padding: 0.5rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.model-menu-container.open .model-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.model-group-label {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.05em;
    margin-top: 0.5rem;
}

.model-group-label:first-child {
    margin-top: 0;
}

.model-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
    justify-content: space-between;
}

.model-option:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.model-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.model-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.model-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.model-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Model Colors */
.gpt-4 {
    color: #ab68ff;
}

.gpt-mini {
    color: var(--text-secondary);
}

.gpt-4-legacy {
    color: #a2adb8;
}

.o1-circle {
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.claude {
    color: #d97757;
}

.gemini {
    background: linear-gradient(45deg, #4b90ff, #ff5546);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.llama {
    color: #0080ff;
}

.mistral {
    color: #fca048;
    /* Mistral Orange-ish */
}

.grok {
    color: #ffffff;
    /* Grok is usually black/white */
}

.deepseek {
    color: #4b67e1;
    /* Deep Blue */
}

.qwen {
    color: #615ced;
    /* Qwen Purple */
}

.check-icon {
    color: var(--text-primary);
    opacity: 0;
}

.model-option.active .check-icon {
    opacity: 1;
}

.header-spacer {
    width: 24px;
    /* Balance the menu button */
}

#mobile-menu-btn {
    display: none;
}

/* Messages Area */
.messages-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    padding-bottom: 2rem;
}

.message {
    padding: 1.5rem 0;
    /* border-bottom: 1px solid rgba(0,0,0,0.05); */
}

.message-content {
    max-width: 48rem;
    margin: 0 auto;
    display: flex;
    gap: 1.5rem;
    padding: 0 1rem;
}

.avatar-container {
    flex-shrink: 0;
    width: 2rem;
    /* reduced from 30px */
}

.avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 0.875rem;
    font-weight: 500;
}

.ai-avatar-icon {
    background-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.avatar.user {
    background-color: transparent;
    /* No bg for user avatar in new design usually */
}

/* .message.user .avatar { display: none; } */
/* Optional: hide user avatar like modern ChatGPT */

.text {
    flex: 1;
    line-height: 1.7;
    font-size: 1rem;
    overflow-wrap: break-word;
}

/* Welcome Message Specifics */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.welcome-message .message-content {
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.welcome-message .avatar {
    background-color: white;
    color: black;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
}

.welcome-message .text {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Input Area */
.input-area {
    flex-shrink: 0;
    padding: 0 1rem 1.5rem 1rem;
    background: linear-gradient(180deg, rgba(33, 33, 33, 0) 0%, var(--bg-primary) 30%);
}

.input-container-wrapper {
    max-width: 48rem;
    margin: 0 auto;
    width: 100%;
}

.input-box {
    background-color: var(--input-bg);
    border-radius: 1.5rem;
    padding: 0.75rem 1rem;
    border: 1px solid transparent;
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
    transition: border-color 0.2s;
}

.input-box:focus-within {
    border-color: rgba(255, 255, 255, 0.2);
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-size: 1rem;
    padding: 0.25rem 0;
    resize: none;
    max-height: 200px;
    outline: none;
    line-height: 1.5;
}

textarea::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.send-btn {
    background-color: white;
    /* Enabled state is white in dark mode */
    border: none;
    color: black;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: opacity 0.2s, background-color 0.2s;
}

.send-btn[disabled] {
    background-color: transparent;
    color: rgba(255, 255, 255, 0.2);
    cursor: default;
}

.input-footer {
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    padding-top: 0.75rem;
}

/* Markdown & Highlight.js Overrides */
.text pre {
    margin: 1rem 0;
    padding: 0;
    /* Let code block handle padding */
    border-radius: 0.5rem;
    overflow: hidden;
    background-color: #0d0d0d;
    /* Darker than bg */
}

.text code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.9em;
}

/* Inline code */
.text :not(pre)>code {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 0.2em 0.4em;
    border-radius: 0.25rem;
}

/* Code Block wrapper from app.js (if we add one) or hljs default */
.hljs {
    background: #0d0d0d !important;
    /* Force match container */
    padding: 1rem !important;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(100%);
        /* Hidden by default on mobile RTL? Check dir */
    }

    html[dir="rtl"] .sidebar {
        transform: translateX(100%);
        /* Right side hidden */
        right: 0;
        left: auto;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    #mobile-menu-btn {
        display: block;
    }

    .header-spacer {
        display: none;
    }

    .message-content {
        gap: 1rem;
    }
}

/* Attach Button */
.attach-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 50%;
    display: grid;
    place-items: center;
    transition: all 0.2s;
}

.attach-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Image Preview */
.image-preview-container {
    padding: 0.5rem 1rem;
    padding-bottom: 0;
}

.image-preview-container.hidden {
    display: none;
}

.preview-wrapper {
    position: relative;
    display: inline-block;
}

#image-preview {
    max-height: 70px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.remove-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background-color: #2f2f2f;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.remove-image-btn:hover {
    background-color: #ef4444;
    border-color: #ef4444;
}

/* User Image in Message */
.message-image {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    margin-top: 0.5rem;
    display: block;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
}