/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    height: 100vh;
    overflow: hidden;
    touch-action: pan-y;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

/* Header Styles */
.chat-header {
    background: linear-gradient(135deg, #10a37f 0%, #0d8c6d 100%);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
    position: relative;
}

.menu-btn, .new-chat-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.menu-btn:hover, .new-chat-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.header-content {
    flex: 1;
    margin: 0 15px;
    text-align: center;
}

.header-content h1 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.model-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 12px;
}

.model-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 500;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 5px;
}

.connection-status .fa-circle {
    color: #4caf50;
    font-size: 10px;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 20px;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar {
    width: 4px;
}

.chat-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

.chat-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

/* Message Styles */
.message {
    display: flex;
    margin-bottom: 20px;
    animation: messageAppear 0.3s ease-out;
    max-width: 95%;
}

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

.message.user {
    flex-direction: row-reverse;
    margin-left: auto;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 4px;
}

.message.user .avatar {
    background: linear-gradient(135deg, #10a37f 0%, #0d8c6d 100%);
    color: white;
}

.message.ai .avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message-content {
    margin: 0 12px;
    max-width: calc(100% - 48px);
}

.message.user .message-content {
    align-items: flex-end;
}

.message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 12px;
    color: #666;
}

.sender {
    font-weight: 600;
}

.time {
    opacity: 0.7;
}

.message-text {
    background: white;
    padding: 14px 16px;
    border-radius: 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    line-height: 1.5;
    font-size: 15px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user .message-text {
    background: linear-gradient(135deg, #10a37f 0%, #0d8c6d 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.ai .message-text {
    background: #f5f5f5;
    border-bottom-left-radius: 4px;
}

.message-text p {
    margin-bottom: 10px;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    font-size: 14px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.message-text code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
}

.message.user .message-text code {
    background: rgba(255, 255, 255, 0.2);
}

.message-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.action-icon {
    background: none;
    border: none;
    color: #666;
    font-size: 14px;
    cursor: pointer;
    padding: 4px;
    transition: color 0.3s ease;
}

.action-icon:hover {
    color: #10a37f;
}

.message.user .action-icon {
    color: rgba(255, 255, 255, 0.7);
}

.message.user .action-icon:hover {
    color: white;
}

.welcome-message {
    text-align: center;
    max-width: 100%;
    justify-content: center;
}

.welcome-message .message-content {
    max-width: 600px;
}

.welcome-message .message-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    margin: 0 16px 20px 16px;
    align-items: flex-start;
    display: none;
}

.typing-indicator.active {
    display: flex;
}

.typing-content {
    margin-left: 12px;
    background: #f5f5f5;
    padding: 12px 16px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #10a37f;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.6; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Container */
.input-container {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #eee;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: #f5f5f5;
    border-radius: 24px;
    padding: 8px;
    border: 1px solid #ddd;
    transition: border-color 0.3s ease;
}

.input-wrapper:focus-within {
    border-color: #10a37f;
}

textarea#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    padding: 10px 12px;
    font-size: 16px;
    line-height: 1.4;
    max-height: 120px;
    min-height: 44px;
    outline: none;
    font-family: inherit;
    color: #333;
}

textarea#messageInput::placeholder {
    color: #888;
}

.input-actions {
    display: flex;
    gap: 6px;
    align-items: flex-end;
}

.action-btn, .send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 16px;
}

.action-btn {
    background: rgba(255, 255, 255, 0.7);
    color: #666;
}

.send-btn {
    background: linear-gradient(135deg, #10a37f 0%, #0d8c6d 100%);
    color: white;
}

.action-btn:hover, .send-btn:hover {
    transform: scale(1.05);
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}

.quick-actions::-webkit-scrollbar {
    display: none;
}

.quick-btn {
    flex-shrink: 0;
    background: rgba(16, 163, 127, 0.1);
    border: 1px solid rgba(16, 163, 127, 0.2);
    color: #10a37f;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.quick-btn:hover {
    background: rgba(16, 163, 127, 0.2);
    transform: translateY(-1px);
}

/* Sidebar Styles */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    display: block;
}

.sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    height: 100%;
    background: white;
    z-index: 1001;
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.1);
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar.active {
    left: 0;
}

.sidebar-header {
    background: linear-gradient(135deg, #10a37f 0%, #0d8c6d 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h3 {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.close-sidebar {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
}

.sidebar-content > * {
    margin-bottom: 25px;
}

.sidebar-content h4 {
    font-size: 14px;
    color: #666;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.model-item {
    background: #f5f5f5;
    border: 1px solid #eee;
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.model-item:hover {
    background: #e8f5e9;
    border-color: #10a37f;
    transform: translateX(2px);
}

.model-item.active {
    background: #e8f5e9;
    border-color: #10a37f;
    border-left: 4px solid #10a37f;
}

.model-item .model-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.model-item .model-desc {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.model-item .model-specs {
    font-size: 11px;
    color: #888;
    display: flex;
    gap: 8px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: #f5f5f5;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

.history-item:hover {
    background: #e3f2fd;
    border-color: #2196f3;
}

.history-item .history-preview {
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.clear-history {
    width: 100%;
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ffcdd2;
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 15px;
}

.clear-history:hover {
    background: #ffcdd2;
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: #333;
    display: flex;
    justify-content: space-between;
}

.setting-item input[type="range"] {
    width: 100%;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: #10a37f;
    border-radius: 50%;
    cursor: pointer;
}

.info {
    background: #e8f5e9;
    border: 1px solid #c8e6c9;
    border-radius: 12px;
    padding: 15px;
    font-size: 13px;
    color: #2e7d32;
}

.info p {
    margin-bottom: 8px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.info p:last-child {
    margin-bottom: 0;
}

.info i {
    margin-top: 2px;
}

/* Voice Modal */
.voice-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(10px);
}

.voice-modal.active {
    display: flex;
}

.voice-content {
    background: white;
    border-radius: 24px;
    width: 100%;
    max-width: 400px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.voice-header {
    background: linear-gradient(135deg, #10a37f 0%, #0d8c6d 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.voice-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.voice-header button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
}

.voice-body {
    padding: 40px 20px;
    text-align: center;
}

.voice-visualizer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 100px;
    margin-bottom: 30px;
}

.voice-visualizer .bar {
    width: 8px;
    background: linear-gradient(to top, #10a37f, #4caf50);
    border-radius: 4px;
    animation: soundWave 1.5s infinite ease-in-out;
}

.voice-visualizer .bar:nth-child(2) { animation-delay: 0.1s; }
.voice-visualizer .bar:nth-child(3) { animation-delay: 0.2s; }
.voice-visualizer .bar:nth-child(4) { animation-delay: 0.3s; }
.voice-visualizer .bar:nth-child(5) { animation-delay: 0.4s; }

@keyframes soundWave {
    0%, 100% { height: 20px; }
    50% { height: 80px; }
}

#voiceStatus {
    font-size: 16px;
    color: #666;
    margin-bottom: 30px;
    min-height: 24px;
}

.voice-record-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10a37f 0%, #0d8c6d 100%);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 30px;
    box-shadow: 0 10px 30px rgba(16, 163, 127, 0.4);
}

.voice-record-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 15px 40px rgba(16, 163, 127, 0.6);
}

.voice-record-btn.recording {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.7); }
    70% { box-shadow: 0 0 0 20px rgba(244, 67, 54, 0); }
    100% { box-shadow: 0 0 0 0 rgba(244, 67, 54, 0); }
}

.voice-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.voice-action-btn {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 14px;
    color: #666;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.voice-action-btn:hover {
    background: #e0e0e0;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .sidebar {
        width: 85%;
        left: -85%;
    }
    
    .message-content {
        max-width: calc(100% - 40px);
    }
    
    .quick-actions {
        padding-bottom: 8px;
    }
    
    .quick-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    }
    
    .container {
        background: rgba(18, 18, 18, 0.95);
        color: #e0e0e0;
    }
    
    .chat-container {
        background: #121212;
    }
    
    .message-text {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    .message.ai .message-text {
        background: #2d2d2d;
    }
    
    .input-container {
        background: #1e1e1e;
        border-top: 1px solid #333;
    }
    
    .input-wrapper {
        background: #2d2d2d;
        border-color: #444;
    }
    
    textarea#messageInput {
        color: #e0e0e0;
    }
    
    textarea#messageInput::placeholder {
        color: #888;
    }
    
    .sidebar {
        background: #1e1e1e;
        color: #e0e0e0;
    }
    
    .model-item {
        background: #2d2d2d;
        border-color: #444;
    }
    
    .model-item:hover {
        background: #333;
    }
    
    .history-item {
        background: #2d2d2d;
        border-color: #444;
    }
    
    .quick-btn {
        background: rgba(16, 163, 127, 0.2);
        border-color: rgba(16, 163, 127, 0.3);
        color: #4db6ac;
    }
    
    .action-btn {
        background: rgba(255, 255, 255, 0.1);
        color: #aaa;
    }
    
    .voice-content {
        background: #1e1e1e;
        color: #e0e0e0;
    }
    
    .setting-item label {
        color: #e0e0e0;
    }
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(16, 163, 127, 0.3);
    border-radius: 50%;
    border-top-color: #10a37f;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 2000;
    transition: transform 0.3s ease;
    backdrop-filter: blur(10px);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* Connection Status Animation */
@keyframes reconnectPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.reconnecting {
    animation: reconnectPulse 1.5s infinite;
}

/* In styles.css */
.message-text {
    white-space: pre-wrap; /* This preserves newlines and wraps text */
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.5;
}

/* For code blocks, keep pre formatting */
.message-text pre,
.message-text code {
    white-space: pre;
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
}

.message-text code:not(pre code) {
    white-space: pre-wrap;
}
