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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8f9fa;
    color: #333;
    height: 100vh;
    overflow: hidden;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    background: white;
    border-bottom: 1px solid #e1e5e9;
    position: relative;
}

.search-container {
    max-width: 400px;
    width: 250px;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 8px 16px 8px 40px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    outline: none;
    font-size: 14px;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: #3b82f6;
}

.search-container::before {
    content: "🔍";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: #9ca3af;
}

.status-dot {
    position: absolute;
    right: 20px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6b7280;
    transition: background-color 0.2s;
}

.status-dot.connected { background: #10b981; }
.status-dot.reconnecting { background: #f59e0b; }
.status-dot.offline { background: #6b7280; }

/* Main Container */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */


.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #e1e5e9;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 280px;
    position: relative;
    flex-shrink: 0;
}

.sidebar-icon {
    width: 18px;
    height: 18px;
    opacity: 1;
    transition: opacity 0.2s;
    cursor: pointer;
}

.history-groups {
    padding: 16px;
    opacity: 0;
    transition: opacity 0.2s;
    min-width: 280px;
}

.sidebar.visible .history-groups {
    opacity: 1;
}

.sidebar-actions {
    display: flex;
    gap: 4px;
}

.new-chat-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-chat-btn img {
    width: 16px;
    height: 16px;
}

.new-chat-btn:hover {
    background: #f3f4f6;
}

.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.close-sidebar-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 18px;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 16px;
}

.close-sidebar-btn:hover {
    background: #f3f4f6;
    color: #374151;
}

.pin-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.sidebar:hover .pin-btn,
.sidebar.pinned .pin-btn {
    opacity: 1;
}

.pin-btn:hover {
    background: #f3f4f6;
}

.history-groups {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
}

.history-group {
    margin-bottom: 24px;
}

.history-group-title {
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-item {
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    font-size: 14px;
    color: #374151;
    transition: background-color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.history-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

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

.delete-btn:hover {
    background: #fee2e2;
}

.history-item:hover {
    background: #f3f4f6;
}

.history-item.active {
    background: #dbeafe;
    color: #1d4ed8;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* Empty state with centered composer */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    gap: 24px;
    background: white;
    position: relative;
}

.chat-icons {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    gap: 8px;
    z-index: 11;
}

.history-toggle-btn,
.new-chat-btn-empty {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.history-toggle-btn:hover,
.new-chat-btn-empty:hover {
    background: #f3f4f6;
}

.history-toggle-btn img,
.new-chat-btn-empty img {
    width: 20px;
    height: 20px;
}

.sidebar {
    width: 0;
    height: 100%;
    background: white;
    border-right: 1px solid #e1e5e9;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
}

.sidebar.visible {
    width: 280px;
}

.empty-icon {
    max-width: 88px;
    height: auto;
}

.empty-state p {
    font-size: 18px;
    color: #000;
    margin: 0;
}

.empty-state .composer {
    width: 100%;
    max-width: 600px;
    background: transparent;
    border: none;
    padding: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 400px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    max-width: 100%;
}

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

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

.message-content {
    background: white;
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}

.progress-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-top: 2px;
    flex-shrink: 0;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px;
    color: #6b7280;
}

.loading-text {
    font-size: 14px;
}

.history-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    color: #6b7280;
    font-size: 14px;
}

.message.user .message-content {
    background: #83fff891;
    color: rgb(0, 0, 0);
}

.message-text {
    line-height: 1.6;
    min-width: 0;
    flex: 1;
}

.message-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #e1e5e9;
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.message-content:hover .message-copy-btn {
    opacity: 1;
}

.message-copy-btn:hover {
    background: #f3f4f6;
}

/* Hide excessive consecutive br tags */
.message-text br + br + br {
    display: none;
}

.message-text p {
    margin: 12px 0;
}

.message-text h1, .message-text h2, .message-text h3,
.message-text h4, .message-text h5, .message-text h6 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.message-text h1 { font-size: 1.5em; }
.message-text h2 { font-size: 1.3em; }
.message-text h3 { font-size: 1.1em; }

.message-text ul, .message-text ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-text li {
    margin: 4px 0;
}

.message-text blockquote {
    border-left: 3px solid #3b82f6;
    padding-left: 12px;
    margin: 8px 0;
    color: #6b7280;
    font-style: italic;
}

.message-text a {
    color: #3b82f6;
    text-decoration: none;
}

.message-text a:hover {
    text-decoration: underline;
}

.message-text strong {
    font-weight: 600;
}

.message-text .inline-code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.9em;
    color: #e11d48;
}

.message-text table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 0.95em;
}

.message-text th, .message-text td {
    border: 1px solid #e1e5e9;
    padding: 8px 12px;
    text-align: left;
}

.message-text th {
    background: #f8f9fa;
    font-weight: 600;
}

.message-text tr:nth-child(even) {
    background: #f9fafb;
}

.message-text .md-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 12px 0;
    display: block;
}

.image-container {
    position: relative;
    display: inline-block;
    margin: 12px 0;
}

.image-download-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #e1e5e9;
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.image-container:hover .image-download-btn {
    opacity: 1;
}

.image-download-btn:hover {
    background: #f3f4f6;
}

.code-block {
    background: #1e293b;
    border-radius: 8px;
    padding: 0;
    margin: 12px 0;
    position: relative;
    overflow: hidden;
    max-width: 100%;
}

.code-lang {
    background: #0f172a;
    color: #94a3b8;
    padding: 6px 12px;
    font-size: 11px;
    font-family: 'Monaco', 'Menlo', monospace;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.code-block pre {
    margin: 0;
    padding: 16px;
    overflow: auto;
    max-height: 400px;
    white-space: pre;
}

.code-block code {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 13px;
    color: #e2e8f0;
    line-height: 1.5;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #475569;
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s;
}

.copy-btn:hover {
    background: #64748b;
}

.code-block:hover .copy-btn {
    opacity: 1;
}

.typing-indicator {
    padding: 20px;
    display: flex;
    justify-content: flex-start;
}

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

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

.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* Bottom composer for chat state */
.composer-bottom {
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid #e1e5e9;
    padding: 16px 20px;
}

/* Composer */
.composer {
    transition: all 0.2s ease;
}

.composer-content {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    max-width: 800px;
    margin: 0 auto;
}

.input-container {
    flex: 1;
    position: relative;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    background: white;
}

.message-input {
    width: 100%;
    border: none;
    border-radius: 12px;
    padding: 12px 50px 12px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    min-height: 44px;
    max-height: 120px;
    background: transparent;
}

.message-input:focus {
    outline: none;
}

.send-btn {
    position: absolute;
    right: 8px;
    bottom: 8px;
    background: #f3f4f6;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #cdd3de;
    transition: all 0.2s;
    transform: scale(1);
}

.send-btn.enabled {
    background: #400ef7;
    color: white;
}

.send-arrow {
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.send-btn:hover:not(:disabled) {
    background: #2563eb;
    transform: scale(1.05);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.send-btn:disabled {
    background: #83fff891;
    cursor: not-allowed;
    transform: scale(1);
}

.send-btn.enabled {
    background: #6c61ff96;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.send-btn.enabled:hover {
    background: #6c61fff5;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.send-btn.processing {
    background: #f59e0b;
    animation: pulse-processing 1.5s infinite;
}

@keyframes pulse-processing {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Mobile responsive */
@media (max-width: 768px) {
    .empty-icon {
        max-width: 64px;
    }
    
    .mode-toggle {
        display: none;
    }
    
    .composer-content {
        gap: 8px;
    }
}

/* Mobile menu toggle */
.mobile-menu-btn {
    display: none;
    position: absolute;
    left: 20px;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.mobile-menu-btn:hover {
    background: #f3f4f6;
}

/* Focus styles for accessibility */
.search-input:focus,
.message-input:focus,
.mode-selector:focus,
.send-btn:focus,
.mic-btn:focus,
.pin-btn:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .sidebar {
        border-right: 2px solid #000;
    }
    
    .topbar {
        border-bottom: 2px solid #000;
    }
    
    .composer {
        border-top: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }
    
    .sidebar {
        position: absolute;
        z-index: 10;
        height: 100%;
        transform: translateX(-100%);
        transition: transform 0.28s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .message {
        max-width: 100%;
    }
    
    .messages {
        padding: 20px;
    }
    
    .composer-content {
        gap: 8px;
    }
    
    .mode-selector {
        display: none;
    }
}
