/* CSS Variables for themes */
:root {
    --bg-primary: #f0f2f5;
    --bg-secondary: white;
    --text-primary: #1a1a2e;
    --text-secondary: #666;
    --header-gradient-start: #667eea;
    --header-gradient-end: #764ba2;
    --user-message: #667eea;
    --user-message-text: white;
    --ai-message: #f1f3f4;
    --ai-message-text: #333;
    --border: #ddd;
    --sidebar-bg: #f8f9fa;
    --email-hover: #e3f2fd;
    --shadow: rgba(0,0,0,0.1);
}

[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --header-gradient-start: #0f3460;
    --header-gradient-end: #1a1a2e;
    --user-message: #0f3460;
    --user-message-text: #eee;
    --ai-message: #2a2a4a;
    --ai-message-text: #ddd;
    --border: #333;
    --sidebar-bg: #0f0f23;
    --email-hover: #1a1a3e;
    --shadow: rgba(0,0,0,0.3);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 10px;
    background: var(--bg-primary);
    transition: all 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: auto;
    background: var(--bg-secondary);
    border-radius: 15px;
    box-shadow: 0 2px 10px var(--shadow);
    overflow: hidden;
}

/* Header styles */
.header {
    background: linear-gradient(135deg, var(--header-gradient-start) 0%, var(--header-gradient-end) 100%);
    color: white;
    padding: 15px 20px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.header h1 {
    margin: 0;
    font-size: 1.5rem;
}

.badge {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.7rem;
    margin-left: 8px;
}

.controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.theme-toggle, .lang-select {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.theme-toggle:hover, .lang-select:hover {
    background: rgba(255,255,255,0.3);
}

.lang-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.status {
    font-size: 0.7rem;
    margin-top: 8px;
    opacity: 0.8;
}

/* Main content layout */
.content {
    display: flex;
    flex-direction: row;
    min-height: 500px;
}

/* Sidebar styles */
.sidebar {
    width: 300px;
    min-width: 250px;
    max-width: 320px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 15px;
    overflow-y: auto;
    transition: all 0.3s ease;
    max-height: 80vh;
    height: auto;
}

.sidebar h3 {
    margin-top: 0;
    margin-bottom: 10px;
}

.sidebar, .sidebar h3, .sidebar p, .sidebar small {
    color: var(--text-primary);
}

/* Chat area styles */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    min-height: 400px;
    max-height: 500px;
    background: var(--bg-secondary);
    scroll-behavior: smooth;
}

/* Input area styles */
.input-area textarea {
    flex: 1;
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 25px;
    font-size: 14px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    resize: vertical;
    min-height: 44px;
    max-height: 120px;
}

.input-area {
    padding: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    background: var(--bg-secondary);
    width: 100%;
}

.input-area textarea:focus {
    outline: none;
    border-color: var(--user-message);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.input-area button {
    padding: 12px 24px;
    background: var(--user-message);
    color: var(--user-message-text);
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
}

.input-area button:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.input-area button:active {
    transform: scale(0.97);
}

/* Message bubble styles */
.message {
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 85%;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.4;
    box-shadow: 0 1px 2px var(--shadow);
    transition: transform 0.1s ease;
}

.message:hover {
    transform: scale(1.01);
}

.user-message {
    background: var(--user-message);
    color: var(--user-message-text);
    margin-left: auto;
    text-align: right;
    border-bottom-right-radius: 4px;
}

.ai-message {
    background: var(--ai-message);
    color: var(--ai-message-text);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

/* Email list styles */
.email-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 350px;
    overflow-y: auto;
}

.email-item {
    padding: 8px;
    margin-bottom: 6px;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    word-break: break-word;
    white-space: normal;
}
.email-item:hover {
    background: var(--email-hover);
    transform: translateX(-3px);
}

.email-from {
    font-weight: bold;
    font-size: 0.85rem;
}

.email-subject {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.email-date {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Button styles */
.login-btn {
    background: white;
    color: #667eea;
    padding: 12px 24px;
    text-decoration: none;
    border-radius: 25px;
    display: inline-block;
    font-weight: bold;
    transition: all 0.2s ease;
}

.login-btn:hover {
    transform: scale(1.05);
}

.login-btn:active {
    transform: scale(0.97);
}

.logout-btn {
    background: #dc3545;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
    width: 100%;
    margin-bottom: 10px;
}

.model-select {
    width: 100%;
    padding: 8px;
    margin: 10px 0;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

/* Typing indicator animation */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-10px); opacity: 1; }
}

/* Chat history section */
.chat-history-section {
    margin-bottom: 15px;
}

.chat-history-list {
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 8px;
}

.chat-history-item {
    padding: 6px 10px;
    margin-bottom: 4px;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-item:hover {
    background: var(--email-hover);
}

.chat-history-item.active {
    background: var(--user-message);
    color: white;
}

.new-chat-btn {
    width: 100%;
    padding: 6px;
    background: var(--user-message);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.new-chat-btn:hover {
    opacity: 0.9;
}

hr {
    margin: 10px 0;
    border-color: var(--border);
}

/* Gmail link button */
.gmail-link {
    display: inline-block;
    background: #1a73e8;
    color: white !important;
    padding: 8px 16px;
    border-radius: 20px;
    text-decoration: none;
    margin-top: 8px;
    font-size: 13px;
}

.gmail-link:hover {
    background: #1557b0;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    
    .content {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    .message {
        max-width: 90%;
    }
    
    .header h1 {
        font-size: 1.2rem;
    }
    
    .theme-toggle, .lang-select {
        padding: 4px 10px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .header-top {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .controls {
        width: 100%;
        justify-content: space-between;
    }
    
    .input-area button {
        padding: 12px 16px;
    }
    
    .message {
        max-width: 95%;
    }
}

.chat-history-item-wrapper {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 4px;
}

.chat-history-item {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-actions {
    display: flex;
    gap: 3px;
}

.chat-history-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.7rem;
    opacity: 0.6;
    padding: 4px;
}

.chat-history-actions button:hover {
    opacity: 1;
}

/* Chat history action buttons */
.chat-history-item-wrapper {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 6px;
}

.chat-history-item {
    flex: 1;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.2s;
}

.chat-history-item:hover {
    background: var(--email-hover);
}

.chat-history-item.active {
    background: var(--user-message);
    color: white;
}

.chat-history-actions {
    display: flex;
    gap: 4px;
}

.chat-history-actions button {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.7rem;
    padding: 4px 6px;
    transition: all 0.2s;
    color: var(--text-primary);
}

.chat-history-actions button:hover {
    background: var(--email-hover);
    transform: scale(1.05);
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--user-message);
}

/* For Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--text-secondary) var(--bg-primary);
}

/* Email list scroll */
.email-list {
    max-height: 350px;
    overflow-y: auto;
}

/* Message area scroll */
.messages {
    overflow-y: auto;
    scroll-behavior: smooth;
}

.badge-unread {
    background: #dc3545;
    color: white;
    border-radius: 20px;
    padding: 2px 8px;
    font-size: 11px;
    margin-left: 8px;
}

body[data-theme="dark"] {
    background: #1a1a2e;
    color: #eee;
}
body[data-theme="dark"] .container {
    background: #16213e;
}
body[data-theme="dark"] .sidebar {
    background: #0f0f23;
    border-color: #333;
}
body[data-theme="dark"] .email-item {
    background: #1a1a3e;
    border-color: #333;
}
body[data-theme="dark"] .messages {
    background: #16213e;
}
body[data-theme="dark"] .ai-message {
    background: #2a2a4a;
    color: #ddd;
}
.info-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 5px 10px;
    border-radius: 20px;
    cursor: pointer;
}
.messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    min-height: 400px;
    max-height: 600px;
    background: white;
    word-wrap: break-word;
    overflow-x: hidden;
}

.message {
    max-width: 85%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
body {
    font-size: 16px;
}
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }
}

.settings-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}
.settings-btn:hover {
    background: rgba(255,255,255,0.3);
}

.chat-history-list {
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 8px;
    will-change: transform;
    contain: layout style paint;
}

.chat-history-item-wrapper {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 4px;
    contain: layout style paint;
}

.chat-history-item {
    flex: 1;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.2s;
}