@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #f8fafc;
    --accent-color: #64748b;
    --text-color: #1e293b;
    --text-light: #64748b;
    --background-color: #f1f5f9;
    --surface-color: #ffffff;
    --border-color: #e2e8f0;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    
    --border-radius: 16px;
    --border-radius-sm: 8px;
    --border-radius-lg: 24px;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
    color: var(--text-color);
    min-height: 100vh;
    padding: 1rem;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(120, 219, 255, 0.2) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

#app-container {
    width: 100%;
    max-width: 1000px;
    height: calc(100vh - 2rem);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.6s ease-out;
    margin: 0 auto;
}

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

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 2s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.model-selector label {
    font-weight: 500;
    color: var(--text-light);
    font-size: 0.875rem;
}

#modelSelect {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background: var(--surface-color);
    color: var(--text-color);
    transition: var(--transition);
    cursor: pointer;
    min-width: 200px;
}

#modelSelect:hover {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#modelSelect:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.logout-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 0.5rem 1.25rem;
    border-radius: var(--border-radius-sm);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.logout-btn::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;
}

.logout-btn:hover::before {
    left: 100%;
}

.logout-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

#chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#messages {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

#messages::-webkit-scrollbar {
    width: 6px;
}

#messages::-webkit-scrollbar-track {
    background: var(--secondary-color);
    border-radius: 3px;
}

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

#messages::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

.message {
    max-width: 85%;
    padding: 1rem 1.25rem;
    border-radius: var(--border-radius);
    line-height: 1.6;
    animation: messageSlide 0.4s ease-out;
    position: relative;
    word-wrap: break-word;
}

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

.message.user {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 8px;
    box-shadow: var(--shadow-md);
}

.message.bot {
    background: var(--surface-color);
    color: var(--text-color);
    align-self: flex-start;
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 8px;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.message.bot .copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: var(--primary-color);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition-fast);
    backdrop-filter: blur(10px);
}

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

.message.bot .copy-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.chat-input {
    display: flex;
    align-items: center;
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    gap: 1rem;
}

.upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, var(--success-color), #059669);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
    border: none;
    position: relative;
    overflow: hidden;
}

.upload-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transition: var(--transition);
    transform: translate(-50%, -50%);
}

.upload-btn:hover::before {
    width: 300px;
    height: 300px;
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.upload-btn svg {
    transition: var(--transition);
}

.upload-btn:hover svg {
    transform: rotate(180deg);
}

#questionInput {
    flex: 1;
    border: 1px solid var(--border-color);
    padding: 0.875rem 1rem;
    font-size: 1rem;
    border-radius: var(--border-radius-sm);
    outline: none;
    resize: none;
    transition: var(--transition);
    background: var(--surface-color);
    min-height: 48px;
    max-height: 120px;
}

#questionInput:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#questionInput:disabled {
    background: var(--secondary-color);
    cursor: not-allowed;
    opacity: 0.6;
}

#sendBtn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

#sendBtn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transition: var(--transition);
    transform: translate(-50%, -50%);
}

#sendBtn:hover::before {
    width: 100px;
    height: 100px;
}

#sendBtn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: var(--shadow-lg);
}

#sendBtn:active {
    transform: translateY(0) scale(0.95);
}

#sendBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.loader {
    position: relative;
    width: 40px;
    height: 40px;
    align-self: center;
    margin: 1rem;
}

.loader::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
}

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

/* Mobile Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    
    #app-container {
        height: 100vh;
        max-width: none;
        border-radius: 0;
        margin: 0;
    }
    
    header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    .header-controls {
        flex-direction: column;
        gap: 1rem;
        width: 100%;
    }
    
    .model-selector {
        flex-direction: column;
        width: 100%;
    }
    
    #modelSelect {
        width: 100%;
        min-width: auto;
    }
    
    #messages {
        padding: 1rem;
    }
    
    .message {
        max-width: 90%;
        padding: 0.75rem 1rem;
    }
    
    .chat-input {
        padding: 1rem;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    #questionInput {
        margin: 0;
        min-height: 44px;
    }
    
    .upload-btn {
        width: 100%;
        justify-content: center;
    }
    
    #sendBtn {
        width: 44px;
        height: 44px;
        align-self: flex-end;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.25rem;
    }
    
    .message {
        max-width: 95%;
        font-size: 0.9rem;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --text-color: #f1f5f9;
        --text-light: #cbd5e1;
        --background-color: #0f172a;
        --surface-color: #1e293b;
        --border-color: #334155;
        --secondary-color: #1e293b;
    }
    
    body {
        background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    }
    
    #app-container {
        background: rgba(30, 41, 59, 0.95);
    }
    
    header {
        background: rgba(30, 41, 59, 0.8);
    }
    
    .chat-input {
        background: rgba(30, 41, 59, 0.8);
    }
    
    #questionInput,
    #modelSelect {
        color: var(--text-color);
        background: var(--surface-color);
    }
    
    #questionInput::placeholder {
        color: var(--text-light);
    }
}

/* Floating animation for background elements */
@keyframes float {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(180deg); }
}

/* Pulse animation for active elements */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Enhanced hover effects */
.message:hover {
    transform: translateY(-1px);
    transition: var(--transition);
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Focus visible for accessibility */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Settings Button */
.settings-btn {
    background: linear-gradient(135deg, var(--accent-color), #475569);
    color: white;
    border: none;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.settings-btn:hover {
    transform: rotate(90deg) scale(1.1);
    box-shadow: var(--shadow-md);
}

.settings-btn svg {
    width: 20px;
    height: 20px;
    transition: var(--transition);
}

/* Settings Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

body.modal-open {
    overflow: hidden;
}

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

.settings-content {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideIn 0.3s ease-out;
    position: relative;
}

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

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
}

.settings-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
}

.close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    transition: var(--transition);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    backdrop-filter: blur(10px);
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-color);
    transform: rotate(90deg);
}

.settings-body {
    padding: 2rem;
}

.settings-section {
    margin-bottom: 2rem;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 1rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    transition: var(--transition);
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3), 0 4px 12px rgba(99, 102, 241, 0.15);
    background: rgba(255, 255, 255, 0.15);
}

.form-group textarea {
    resize: vertical;
    min-height: 140px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    border-radius: var(--border-radius);
    padding: 1rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 400;
    letter-spacing: 0.01em;
}

.form-group textarea::placeholder {
    color: var(--text-light);
    opacity: 0.6;
    font-style: italic;
    font-weight: 300;
}

.form-group small {
    display: block;
    color: var(--text-light);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.btn-group {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border: none;
    padding: 0.875rem 1.5rem;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.875rem;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.875rem 1.5rem;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.875rem;
    backdrop-filter: blur(10px);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.error-message {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

.success-message {
    color: var(--success-color);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Dark mode for settings */
@media (prefers-color-scheme: dark) {
    .settings-content {
        background: rgba(30, 41, 59, 0.95);
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .settings-header {
        border-bottom-color: rgba(255, 255, 255, 0.1);
        background: rgba(255, 255, 255, 0.05);
    }
    
    .close-btn {
        background: rgba(255, 255, 255, 0.1);
        color: var(--text-light);
    }
    
    .close-btn:hover {
        background: rgba(255, 255, 255, 0.15);
    }
    
    .form-group input,
    .form-group textarea {
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.1);
        color: var(--text-color);
    }
    
    .form-group input:focus,
    .form-group textarea:focus {
        background: rgba(255, 255, 255, 0.08);
        border-color: var(--primary-color);
    }
    
    .btn-secondary {
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.1);
        color: var(--text-color);
    }
    
    .btn-secondary:hover {
        background: rgba(255, 255, 255, 0.08);
    }
}

/* Responsive settings modal */
@media (max-width: 768px) {
    .modal {
        padding: 1rem;
    }
    
    .settings-content {
        width: 100%;
        max-width: none;
        margin: 0;
        max-height: 90vh;
        border-radius: var(--border-radius);
    }
    
    .settings-header {
        padding: 1.25rem 1.5rem;
    }
    
    .settings-body {
        padding: 1.5rem;
    }
    
    .form-group textarea {
        min-height: 100px;
    }
    
    .btn-group {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .btn-primary,
    .btn-secondary {
        width: 100%;
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .settings-content {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .settings-header {
        padding: 1rem;
    }
    
    .settings-body {
        padding: 1rem;
    }
    
    .settings-header h2 {
        font-size: 1.25rem;
    }
}