/* CSS Variables for Theme Management */
:root {
    /* Light Theme */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --border-color: #e2e8f0;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    --message-user-bg: #3b82f6;
    --message-user-text: #ffffff;
    --message-bot-bg: #f1f5f9;
    --message-bot-text: #1e293b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
}

.dark-mode {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --accent-primary: #60a5fa;
    --accent-hover: #3b82f6;
    --border-color: #475569;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    --message-user-bg: #3b82f6;
    --message-user-text: #ffffff;
    --message-bot-bg: #334155;
    --message-bot-text: #f1f5f9;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: background-color 0.3s ease, color 0.3s ease;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* App Container */
.app-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

/* Chatbot Container */
.chatbot-container {
    width: 100%;
    height: 100%;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 0;
    box-shadow: none;
    border: none;
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1000;
}

.theme-btn {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-size: 1.1rem;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
}

.theme-btn:hover {
    transform: scale(1.1);
    border-color: var(--accent-primary);
}

/* Header */
.chatbot-header {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-hover));
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    min-height: 70px;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-icon {
    font-size: 1.6rem;
    opacity: 0.9;
}

.header-text h2 {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 1.2rem;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-selector select {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 6px 10px;
    color: white;
    font-size: 0.8rem;
    backdrop-filter: blur(10px);
    max-width: 120px;
}

.model-selector select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Model Status Indicator */
.model-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

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

.status-error {
    background-color: var(--error-color);
    animation: pulse 1.5s infinite;
}

.status-loading {
    background-color: var(--warning-color);
    animation: pulse 1.5s infinite;
}

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

.clear-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 8px 10px;
    color: white;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

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

/* Messages Area */
.chatbot-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: var(--bg-primary);
    min-height: 0;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 30px 16px;
    color: var(--text-secondary);
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.welcome-icon {
    font-size: 2.5rem;
    margin-bottom: 16px;
    opacity: 0.7;
}

.welcome-message h3 {
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 1.3rem;
}

.model-info {
    margin-top: 12px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    display: inline-block;
    font-size: 0.9rem;
}

/* Message Bubbles */
.message {
    max-width: 85%;
    padding: 0;
    animation: messageAppear 0.3s ease-out;
}

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

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

.user-message .message-content {
    background: var(--message-user-bg);
    color: var(--message-user-text);
    border-bottom-right-radius: 4px;
}

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

.bot-message .message-content {
    background: var(--message-bot-bg);
    color: var(--message-bot-text);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-style: italic;
}

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

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typingBounce 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 typingBounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.chatbot-input {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.input-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#user-input {
    flex: 1;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 15px;
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: none;
    min-height: 48px;
    max-height: 100px;
    transition: border-color 0.3s ease;
    font-family: inherit;
}

#user-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

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

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

.action-btn {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.action-btn:hover {
    background: var(--accent-primary);
    color: white;
    transform: scale(1.05);
}

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

.send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
}

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

/* Scrollbar Styling */
.chatbot-messages::-webkit-scrollbar {
    width: 5px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Animation for new messages */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.new-message {
    animation: slideIn 0.3s ease-out;
}

/* Link styling in messages */
.message-content a {
    color: var(--accent-primary);
    text-decoration: underline;
    word-break: break-all;
}

.message-content a:hover {
    color: var(--accent-hover);
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .theme-toggle {
        top: 8px;
        right: 8px;
    }
    
    .theme-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .chatbot-header {
        padding: 12px 16px;
        min-height: 60px;
    }
    
    .header-content {
        gap: 8px;
    }
    
    .header-icon {
        font-size: 1.4rem;
    }
    
    .header-text h2 {
        font-size: 1.1rem;
        margin-bottom: 2px;
    }
    
    .model-selector select {
        font-size: 0.75rem;
        padding: 4px 8px;
        max-width: 100px;
    }
    
    .clear-btn {
        padding: 6px 8px;
        font-size: 0.8rem;
    }
    
    .chatbot-messages {
        padding: 12px;
        gap: 10px;
    }
    
    .welcome-message {
        padding: 20px 12px;
    }
    
    .welcome-icon {
        font-size: 2rem;
    }
    
    .welcome-message h3 {
        font-size: 1.1rem;
    }
    
    .message {
        max-width: 90%;
    }
    
    .message-content {
        padding: 10px 14px;
        font-size: 0.95rem;
    }
    
    .chatbot-input {
        padding: 12px;
    }
    
    .input-container {
        gap: 8px;
    }
    
    #user-input {
        padding: 10px 14px;
        font-size: 14px;
        min-height: 44px;
    }
    
    .action-btn, .send-btn {
        width: 40px;
        height: 40px;
        font-size: 0.9rem;
    }
    
    .input-footer {
        font-size: 0.7rem;
    }
}

@media (max-width: 480px) {
    .header-text h2 {
        font-size: 1rem;
    }
    
    .model-selector select {
        max-width: 90px;
        font-size: 0.7rem;
    }
    
    .message {
        max-width: 95%;
    }
    
    .message-content {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    .welcome-message h3 {
        font-size: 1rem;
    }
    
    .model-info {
        font-size: 0.8rem;
        padding: 6px 10px;
    }
}

/* Very small screens (like foldables) */
@media (max-width: 360px) {
    .chatbot-header {
        padding: 10px 12px;
        min-height: 55px;
    }
    
    .header-text h2 {
        font-size: 0.9rem;
    }
    
    .model-selector {
        flex-direction: column;
        gap: 4px;
        align-items: flex-start;
    }
    
    .model-selector select {
        max-width: 80px;
    }
    
    .chatbot-messages {
        padding: 10px;
    }
    
    .message-content {
        padding: 6px 10px;
    }
}

/* Landscape mode optimization */
@media (max-height: 500px) and (orientation: landscape) {
    .chatbot-header {
        padding: 8px 16px;
        min-height: 50px;
    }
    
    .header-icon {
        font-size: 1.2rem;
    }
    
    .header-text h2 {
        font-size: 0.9rem;
        margin-bottom: 0;
    }
    
    .welcome-message {
        padding: 15px 12px;
    }
    
    .welcome-icon {
        font-size: 1.5rem;
        margin-bottom: 8px;
    }
    
    .welcome-message h3 {
        font-size: 1rem;
        margin-bottom: 4px;
    }
    
    .chatbot-input {
        padding: 8px 12px;
    }
    
    #user-input {
        min-height: 40px;
        padding: 8px 12px;
    }
}