:root {
    /* Base Dark Theme Colors */
    --bg-main: #0f172a;
    --bg-secondary: #1e293b;
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    
    --primary-color: var(--dynamic-theme-color, #6366f1);
    --primary-hover: var(--dynamic-theme-hover, #818cf8);
    
    --msg-user-bg: linear-gradient(135deg, var(--primary-color) 0%, #4f46e5 100%);
    --msg-poke-bg: rgba(30, 41, 59, 0.85);
    
    /* Layout Variables */
    --border-radius-lg: 24px;
    --border-radius-md: 16px;
    --border-radius-sm: 8px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    
    --sidebar-width: 280px;
}

/* Light Theme Overrides */
body.light-theme {
    --bg-main: #f1f5f9;
    --bg-secondary: #ffffff;
    --bg-gradient: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(0, 0, 0, 0.08);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --msg-poke-bg: rgba(255, 255, 255, 0.9);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

/* App Container */
.app-container {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.messenger-window {
    width: 100%;
    max-width: 1200px;
    height: 100%;
    max-height: 90vh;
    border-radius: var(--border-radius-lg);
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    background: rgba(15, 23, 42, 0.3);
}

.sidebar-header {
    padding: var(--spacing-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-sm);
}

.chat-session-item {
    padding: 12px 16px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
}

.chat-session-item:hover, .chat-session-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.sidebar-footer {
    padding: var(--spacing-md);
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-around;
}

/* Main Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: var(--spacing-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(30, 41, 59, 0.2);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.mobile-only {
    display: none;
}

.avatar-container {
    position: relative;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #a855f7 0%, var(--primary-color) 100%);
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid var(--bg-main);
}

.header-info h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

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

.header-right {
    display: flex;
    gap: 8px;
}

/* Buttons */
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.icon-btn.primary {
    background: var(--primary-color);
    color: white;
}

.icon-btn.primary:hover {
    background: var(--primary-hover);
}

.primary-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--border-radius-sm);
    background: var(--primary-color);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 16px;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    padding: var(--spacing-lg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.message {
    max-width: 80%;
    display: flex;
    flex-direction: column;
    animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0;
    transform: translateY(10px);
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--border-radius-md);
    line-height: 1.6;
    font-size: 0.95rem;
    word-wrap: break-word;
    position: relative;
}

.user-message {
    align-self: flex-end;
}

.user-message .message-bubble {
    background: var(--msg-user-bg);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
}

.poke-message {
    align-self: flex-start;
}

.poke-message .message-bubble {
    background: var(--msg-poke-bg);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--glass-border);
}

/* Message Meta (Timestamps & Status) */
.message-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.status-ticks {
    color: var(--primary-color);
    font-size: 0.9rem;
}

/* Markdown Rendering in Poke Messages */
.markdown-content p {
    margin-bottom: 0.8em;
}
.markdown-content p:last-child {
    margin-bottom: 0;
}
.markdown-content strong {
    font-weight: 600;
    color: var(--text-primary);
}
.markdown-content ul, .markdown-content ol {
    margin-left: 20px;
    margin-bottom: 0.8em;
}
.markdown-content pre {
    background: #1a1b26; /* Tokyo Night Dark */
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid var(--glass-border);
}
.markdown-content code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}
.markdown-content p > code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Input Area */
.chat-input-wrapper {
    padding: var(--spacing-md) var(--spacing-lg);
    background: rgba(30, 41, 59, 0.4);
    border-top: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    position: relative;
}

#emoji-picker-container {
    position: absolute;
    bottom: calc(100% - 20px);
    left: 20px;
    z-index: 100;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    border-radius: 8px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#emoji-picker-container.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
}

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: rgba(15, 23, 42, 0.6);
    padding: 8px;
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--glass-border);
    transition: border-color 0.3s ease;
}

body.light-theme .chat-form {
    background: rgba(255, 255, 255, 0.8);
}

.chat-form:focus-within {
    border-color: var(--primary-hover);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    resize: none;
    padding: 10px 4px;
    max-height: 150px;
    line-height: 1.5;
}

#message-input::placeholder {
    color: var(--text-secondary);
}

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

/* Microphone Animation */
.mic-recording {
    color: #ef4444 !important;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}
.modal-overlay.hidden { opacity: 0; pointer-events: none; }
.modal-content {
    width: 90%; max-width: 450px; padding: 32px;
    border-radius: var(--border-radius-lg);
    background: var(--bg-secondary);
}
/* Animations & Utils */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 768px) {
    .messenger-window { border-radius: 0; }
    .sidebar { 
        display: flex;
        position: absolute;
        top: 0;
        left: -100%;
        height: 100%;
        z-index: 50;
        background: var(--bg-main);
        transition: left 0.3s ease;
    }
    .sidebar.mobile-open {
        left: 0;
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    }
    .mobile-only { display: flex; }
}
