:root {
    --bg-main: #131314;
    --bg-sidebar: #1e1f20;
    --text-primary: #e3e3e3;
    --text-secondary: #c4c7c5;
    --border-color: #333537;
    --accent: #a8c7fa;
    --accent-hover: #d3e3fd;
    --message-bot: transparent;
    --message-user: #333537;
    --font-family: 'Inter', sans-serif;
}

body, html {
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    font-size: 16px;
    letter-spacing: 0.2px;
}

* {
    box-sizing: border-box;
}

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

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 50;
    border-right: none;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 40;
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

.sidebar-header {
    padding: 24px 20px;
}

.sidebar-header h2 {
    margin: 0 0 20px 0;
    font-size: 1.2rem;
    font-weight: 600;
    background: linear-gradient(90deg, #fff, #a0a0b0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#new-chat-btn {
    width: 100%;
    background-color: var(--bg-main);
    color: var(--text-primary);
    border: none;
    border-radius: 24px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.2s, transform 0.1s;
}

#new-chat-btn:hover {
    background-color: #282a2c;
}

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

#new-chat-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.sidebar-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0 20px;
}

.section-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.history-item {
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 5px;
    color: var(--text-secondary);
    transition: background 0.2s, color 0.2s;
}

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

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

.footer-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 10px;
    width: 100%;
    border-radius: 8px;
    transition: background 0.2s;
}

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

.footer-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
    background-color: var(--bg-main);
}

.chat-header {
    padding: 15px 25px;
    display: flex;
    align-items: center;
    gap: 15px;
}

#model-selector {
    background: var(--message-user);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 8px;
    outline: none;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    margin-left: auto;
    transition: border-color 0.2s;
}

#model-selector:focus {
    border-color: var(--accent);
}

#model-selector option {
    background-color: var(--bg-sidebar);
    color: var(--text-primary);
}

.mobile-menu-btn {
    display: none;
    cursor: pointer;
}

.mobile-menu-btn svg {
    width: 24px;
    height: 24px;
    fill: var(--text-primary);
}

.chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 500;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    animation: fadeIn 0.5s ease;
    max-width: 850px;
    width: 100%;
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 20px;
}

.welcome-screen h1 {
    font-size: 2.5rem;
    margin: 0 0 10px 0;
    background: linear-gradient(135deg, #a8c0ff 0%, #3f2b96 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 600;
}

.welcome-screen p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 40px;
}

.suggestions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    width: 100%;
    max-width: 700px;
}

.suggestion-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    text-align: left;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.suggestion-card:hover {
    background: #333;
    transform: translateY(-2px);
}

.suggestion-card .title {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.suggestion-card .desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Messages */
.message-wrapper {
    display: flex;
    margin-bottom: 30px;
    animation: fadeIn 0.3s ease-in-out;
    width: 100%;
    max-width: 850px;
}

.message-wrapper.user {
    justify-content: flex-end;
}

.message-wrapper.bot {
    justify-content: flex-start;
}

.message {
    max-width: 80%;
    line-height: 1.6;
    font-size: 1rem;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.user-message {
    background: var(--message-user);
    padding: 12px 20px;
    border-radius: 20px 20px 4px 20px;
    color: var(--text-primary);
}

.bot-message {
    background: transparent;
    color: var(--text-primary);
}

/* Input Area */
.input-area {
    padding: 0 20px 30px 20px;
    background: var(--bg-main);
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#attachment-preview {
    position: relative;
    margin-bottom: 15px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    display: flex;
    align-items: flex-start;
    max-width: 850px;
    width: 100%;
}

#attachment-preview img {
    max-width: 120px;
    max-height: 120px;
    border-radius: 8px;
    object-fit: cover;
}

.remove-attachment {
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: absolute;
    top: -10px;
    right: -10px;
}

.input-container {
    background: var(--bg-sidebar);
    border: none;
    border-radius: 32px;
    display: flex;
    align-items: flex-end;
    padding: 10px 14px;
    transition: background-color 0.3s;
    max-width: 850px;
    width: 100%;
}

.input-container:focus-within {
    background: #282a2c;
}

#attach-btn {
    background: transparent;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: none; /* Hidden by default, changed to flex in JS */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background-color 0.3s, color 0.3s;
    margin-right: 8px;
    margin-bottom: 2px;
}
#attach-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.08);
}
#attach-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

#chat-input {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    padding: 10px 12px;
    outline: none;
    font-family: var(--font-family);
    resize: none;
    max-height: 200px;
    min-height: 24px;
    line-height: 1.5;
}

#send-btn {
    background: var(--text-primary);
    color: var(--bg-main);
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    margin-left: 8px;
}

#send-btn:hover {
    opacity: 0.9;
}

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

#send-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

#send-btn:disabled {
    background: var(--border-color);
    opacity: 0.5;
    cursor: not-allowed;
}

#send-btn svg {
    width: 20px;
    height: 20px;
    fill: var(--bg-main);
    margin-left: 2px;
}

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

/* Gemini Style Thinking Indicator */
.gemini-thinking {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    margin-bottom: 5px;
}

.gemini-sparkle {
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #4285f4, #9b72cb, #d96570, #f4b400);
    background-size: 200% 200%;
    border-radius: 50%;
    animation: gradientSpin 2s linear infinite;
    position: relative;
    box-shadow: 0 0 12px rgba(155, 114, 203, 0.4);
}

.gemini-sparkle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    background-color: var(--bg-main);
    border-radius: 50%;
}

.thinking-text {
    font-size: 14px;
    background: linear-gradient(90deg, #c4c7c5, #ffffff, #c4c7c5);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: textShimmer 2s linear infinite;
    font-weight: 500;
}

.thinking-timer {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 8px;
    font-variant-numeric: tabular-nums;
}

@keyframes gradientSpin {
    0% { background-position: 0% 50%; transform: rotate(0deg); }
    50% { background-position: 100% 50%; transform: rotate(180deg); }
    100% { background-position: 0% 50%; transform: rotate(360deg); }
}

@keyframes textShimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

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

/* Modals */
.custom-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.custom-modal.show {
    display: flex;
    opacity: 1;
}

.custom-modal .modal-content {
    background: var(--bg-sidebar);
    width: 400px;
    border-radius: 16px;
    padding: 25px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.custom-modal.show .modal-content {
    transform: translateY(0);
}

.custom-modal h4 {
    margin: 0 0 15px 0;
    font-size: 1.2rem;
}

.custom-modal p {
    margin: 0 0 25px 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.custom-modal textarea {
    width: 100%;
    height: 100px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 12px;
    font-family: inherit;
    resize: none;
    margin-bottom: 20px;
    outline: none;
}

.custom-modal textarea:focus {
    border-color: var(--accent);
}

#report-modal .modal-content {
    width: 600px;
    max-width: 90vw;
}

#report-modal textarea {
    height: 150px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.modal-actions button {
    padding: 10px 20px;
    border-radius: 20px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-cancel {
    background: transparent;
    color: var(--text-primary);
}

.btn-cancel:hover {
    background: rgba(255,255,255,0.1);
}

.btn-primary {
    background: var(--text-primary);
    color: var(--bg-main);
}

.btn-primary:hover {
    background: #fff;
}

/* Toasts */
#toast-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--bg-sidebar);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 15px 20px;
    border-radius: 12px;
    font-size: 0.95rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideUp 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
}

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

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Action Buttons (Copy, Retry, etc) */
.action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
}

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

.action-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* Markdown Styles */
.message pre {
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    max-width: 100%;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.9rem;
    margin: 15px 0;
}

.message code {
    background-color: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.9em;
    color: #ff7b72;
}

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

.message table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
}

.message th, .message td {
    border: 1px solid var(--border-color);
    padding: 10px;
}

.message th {
    background-color: var(--message-user);
}

.message img {
    max-width: 100%;
    border-radius: 8px;
}

.message p {
    margin-top: 0;
    margin-bottom: 10px;
}
.message p:last-child {
    margin-bottom: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: -280px;
        z-index: 50;
        height: 100%;
    }
    
    .sidebar.open {
        transform: translateX(280px);
    }
    
    .mobile-menu-btn {
        display: block;
    }
    
    .chat-messages {
        padding: 15px 5%;
    }
    
    .input-area {
        padding: 0 5% 15px 5%;
    }
    
    .message {
        max-width: 95%;
    }
    
    .welcome-screen h1 {
        font-size: 1.8rem;
    }
    
    .suggestions-grid {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .suggestion-card {
        padding: 12px;
    }
    
    .suggestion-card .title {
        font-size: 0.9rem;
    }
    
    .suggestion-card .desc {
        font-size: 0.8rem;
    }
}

/* =========================================
   Model Themes
========================================= */

/* Ceylex Theme (Default Dark) */
body.theme-ceylex {
    --accent: #4285f4;
    --accent-hover: #3b76d6;
}
body.theme-ceylex .welcome-screen h1 {
    background: linear-gradient(135deg, #a8c0ff 0%, #3f2b96 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Gemma Theme (Google Light Theme - now Dark Theme adapted) */
body.theme-gemma {
    --message-user: rgba(26, 115, 232, 0.2);
    --message-bot: transparent;
    --accent: #1a73e8;
    --accent-hover: #1558d6;
}
body.theme-gemma .welcome-screen h1 {
    background: linear-gradient(135deg, #4285f4, #ea4335, #fbbc05, #34a853);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
body.theme-gemma .gemini-sparkle {
    background: linear-gradient(135deg, #4285f4, #ea4335, #fbbc05, #34a853);
    box-shadow: 0 0 12px rgba(66, 133, 244, 0.4);
}
body.theme-gemma .thinking-text {
    background: linear-gradient(90deg, #5f6368, #202124, #5f6368);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
body.theme-gemma .gemini-sparkle::before {
    background-color: var(--bg-main);
}
body.theme-gemma .suggestion-card {
    background: rgba(26, 115, 232, 0.1);
    border: 1px solid rgba(26, 115, 232, 0.3);
}
body.theme-gemma .suggestion-card:hover {
    background: rgba(26, 115, 232, 0.2);
}

/* Llama 3.2 Theme (Meta Dark Blue) */
body.theme-llama3 {
    --message-user: rgba(37, 99, 235, 0.2);
    --accent: #3b82f6;
    --accent-hover: #2563eb;
}
body.theme-llama3 .welcome-screen h1 {
    background: linear-gradient(135deg, #38bdf8 0%, #3b82f6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
body.theme-llama3 .suggestion-card {
    background: rgba(37, 99, 235, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
}
body.theme-llama3 .suggestion-card:hover {
    background: rgba(37, 99, 235, 0.2);
}
body.theme-llama3 .user-message {
    color: white;
}

/* Image Generator Theme (Vibrant Pink/Orange) */
body.theme-imggen {
    --message-user: rgba(219, 39, 119, 0.2);
    --accent: #ec4899;
    --accent-hover: #be185d;
}
body.theme-imggen .welcome-screen h1 {
    background: linear-gradient(135deg, #f472b6, #fb923c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
body.theme-imggen .gemini-sparkle {
    background: linear-gradient(135deg, #f472b6, #fb923c);
    box-shadow: 0 0 12px rgba(244, 114, 182, 0.4);
}
body.theme-imggen .suggestion-card {
    background: rgba(219, 39, 119, 0.1);
    border: 1px solid rgba(236, 72, 153, 0.3);
}
body.theme-imggen .suggestion-card:hover {
    background: rgba(219, 39, 119, 0.2);
}
body.theme-imggen .user-message {
    color: white;
}

/* CEYLEX_x Theme (Raw / Grey) */
body.theme-ceylex-x {
    --accent: #9e9e9e;
    --accent-hover: #757575;
}
body.theme-ceylex-x .welcome-screen h1 {
    background: linear-gradient(135deg, #e0e0e0, #9e9e9e);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
