:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.1);
    --secondary-color: #8b5cf6;
    --accent-color: #06b6d4;
    --bg-gradient: linear-gradient(135deg, #0c0c0c 0%, #1a1a2e 100%);
    --bg-color: #0a0a0a;
    --surface-color: #1a1a2e;
    --surface-light: #262640;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --border-color: #374151;
    --border-light: #4b5563;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    
    --border-radius: 16px;
    --border-radius-sm: 8px;
    --border-radius-lg: 24px;
    --box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    --box-shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
    overflow: hidden;
}

.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    gap: 20px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 32px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--box-shadow);
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.5), transparent);
}

.header h1 {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.025em;
}

.history-button {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    border-radius: var(--border-radius);
    padding: 12px 24px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    position: relative;
    overflow: hidden;
}

.history-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.history-button:hover::before {
    left: 100%;
}

.history-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

.history-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease-out;
}

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

.history-modal-content {
    background: var(--surface-color);
    border: 1px solid var(--border-light);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--box-shadow-lg);
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow: hidden;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { 
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to { 
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.history-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 32px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(99, 102, 241, 0.05);
}

.history-modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.close-modal {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.close-modal:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
    transform: scale(1.1);
}

.history-list {
    padding: 24px 32px;
    max-height: calc(80vh - 100px);
    overflow-y: auto;
}

.history-item {
    padding: 20px;
    border: 1px solid var(--border-color);
    background: var(--surface-light);
    border-radius: var(--border-radius);
    margin-bottom: 16px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.history-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(139, 92, 246, 0.05));
    opacity: 0;
    transition: var(--transition);
}

.history-item:hover::before {
    opacity: 1;
}

.history-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    position: relative;
    z-index: 1;
}

.history-item-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.history-item-date {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.history-item-preview {
    color: var(--text-secondary);
    line-height: 1.5;
    position: relative;
    z-index: 1;
}

.history-item-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    position: relative;
    z-index: 1;
}

.history-action-button {
    background: var(--surface-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
}

.history-action-button:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    transform: translateY(-1px);
}

.history-action-button.delete {
    color: var(--danger-color);
    border-color: rgba(239, 68, 68, 0.3);
}

.history-action-button.delete:hover {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: white;
}

.no-history {
    text-align: center;
    color: var(--text-muted);
    padding: 60px 20px;
    font-size: 1.1rem;
}

.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    box-shadow: var(--box-shadow);
    position: relative;
}

.chat-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.5), transparent);
}

.status-bar {
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-dot.connected {
    background-color: var(--success-color);
}

.status-dot.disconnected {
    background-color: var(--danger-color);
}

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

.mgs {
    margin-top: auto;
    margin-bottom: auto;
    font-family: 'Inter', sans-serif;
    font-size: 2.5rem;
    font-weight: 300;
    text-align: center;
    color: var(--text-muted);
    opacity: 0.7;
}

.message {
    padding: 16px 20px;
    border-radius: var(--border-radius);
    max-width: 75%;
    position: relative;
    animation: messageSlide 0.3s ease-out;
}

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

.message.user {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.message.bot {
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    margin-right: auto;
    border-bottom-left-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.message-metadata {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.message.user .message-metadata {
    color: rgba(255, 255, 255, 0.8);
}

.message-content {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6;
}

.message-content code {
    background: rgba(0, 0, 0, 0.4);
    color: var(--accent-color);
    padding: 4px 8px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.markdown p {
    margin: 8px 0;
}

.markdown pre {
    background: #1a1a1a;
    border: 1px solid var(--border-color);
    padding: 16px;
    border-radius: var(--border-radius-sm);
    overflow-x: auto;
    margin: 12px 0;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.markdown pre code {
    background: none;
    padding: 0;
    color: #e2e8f0;
}

.input-area {
    padding: 20px 24px;
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid var(--border-color);
}

.input-controls {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    max-width: 1200px;
    margin: 0 auto;
}

.input-wrapper {
    flex: 1;
    position: relative;
}

.message-input {
    width: 100%;
    padding: 16px 20px;
    border: 1px solid var(--border-color);
    background: var(--surface-color);
    color: var(--text-primary);
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    min-height: 56px;
    max-height: 200px;
    overflow-y: auto;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.message-input::placeholder {
    color: var(--text-muted);
}

.message-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
    background: var(--surface-light);
}

.send-button {
    padding: 16px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 1.2rem;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    position: relative;
    overflow: hidden;
    min-width: 56px;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-button::after {
    content: '→';
    font-size: 1.5rem;
    font-weight: bold;
    transform: translateX(0);
    transition: transform 0.2s ease;
}

.send-button:hover::after {
    transform: translateX(2px);
}

.send-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.send-button:hover::before {
    left: 100%;
}

.send-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

.send-button:disabled {
    background: var(--surface-color);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.send-button:disabled::after {
    content: '→';
    opacity: 0.5;
}

.loader {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

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

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
        gap: 10px;
    }
    
    .header {
        padding: 16px 20px;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .message {
        max-width: 85%;
    }
    
    .input-controls {
        gap: 12px;
    }
    
    .send-button {
        min-width: 56px;
        padding: 16px;
    }
    
    .history-modal-content {
        width: 95%;
        margin: 20px;
    }
    
    .history-modal-header,
    .history-list {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.25rem;
    }
    
    .mgs {
        font-size: 2rem;
    }
    
    .message {
        max-width: 95%;
        padding: 12px 16px;
    }
    
    .messages {
        padding: 16px;
    }
    
    .input-area {
        padding: 16px;
    }
}

/* Dark mode enhancements */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-gradient: linear-gradient(135deg, #000000 0%, #1a1a2e 100%);
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --border-color: #ffffff;
        --text-secondary: #ffffff;
    }
}
