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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --message-user-bg: #eff6ff;
    --message-assistant-bg: #f1f5f9;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--surface);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.welcome-message {
    background: var(--message-assistant-bg);
    border-radius: 0.75rem;
    padding: 2rem;
    margin: 1rem 0;
    border-left: 4px solid var(--primary-color);
}

.welcome-message h2 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.welcome-message p {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.welcome-message ul {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
    color: var(--text-secondary);
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.3s ease-in;
}

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

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

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

.message-content {
    padding: 0.875rem 1.125rem;
    border-radius: 0.75rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user .message-content {
    background: var(--message-user-bg);
    border-bottom-right-radius: 0.25rem;
}

.message.assistant .message-content {
    background: var(--message-assistant-bg);
    border-bottom-left-radius: 0.25rem;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
    margin-top: 0;
}

.message-content p {
    margin-bottom: 0.75rem;
}

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

.message-content ul,
.message-content ol {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.message-content li {
    margin-bottom: 0.25rem;
}

.message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin-bottom: 0.75rem;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 1rem;
    margin-left: 0;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.75rem;
}

.message-content table th,
.message-content table td {
    border: 1px solid var(--border);
    padding: 0.5rem;
    text-align: left;
}

.message-content table th {
    background: var(--background);
    font-weight: 600;
}

.message-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    padding: 0 0.5rem;
}

.status-message {
    opacity: 0.9;
}

.status-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-style: italic;
}

.status-text {
    animation: pulse 2s ease-in-out infinite;
}

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

.chat-input-container {
    border-top: 1px solid var(--border);
    padding: 1rem 1.5rem;
    background: var(--surface);
    flex-shrink: 0;
}

/* Attachment Preview Area */
.attachment-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

.attachment-thumbnail {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 0.25rem;
}

.attachment-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: #dc2626;
    color: white;
    border-radius: 0.25rem;
}

.attachment-icon.pdf-icon {
    background: #dc2626;
}

.attachment-name {
    color: var(--text-secondary);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    background: var(--background);
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    transition: all 0.2s;
}

.attachment-remove:hover {
    background: var(--error);
    color: white;
}

/* Hidden file input */
.file-input-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.chat-form {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

/* Attachment Button */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: var(--background);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-icon:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.message-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    max-height: 150px;
    min-height: 44px;
    line-height: 1.5;
}

.message-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    min-height: 44px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--secondary-hover);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal[aria-hidden="false"] {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 0.75rem;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease-out;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
}

.modal-close:hover {
    background: var(--background);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

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

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

.form-group input[type="text"],
.form-group input[type="file"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 1rem;
}

.form-group input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group input[type="file"] {
    padding: 0.5rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.upload-status {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    display: none;
}

.upload-status.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid var(--success);
    display: block;
}

.upload-status.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border: 1px solid var(--error);
    display: block;
}

.upload-status.info {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    display: block;
}

.loading-indicator {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 0.5rem;
}

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

/* Mobile Responsive */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .header-actions {
        flex-direction: column;
    }

    .message {
        max-width: 95%;
    }

    .chat-messages {
        padding: 1rem;
    }

    .chat-input-container {
        padding: 0.75rem;
    }

    .modal-content {
        width: 95%;
        margin: 1rem;
    }
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--background);
}

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

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

/* Message Attachments (shown in chat) */
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.message-attachment-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.5rem;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 0.375rem;
    font-size: 0.75rem;
}

.message-attachment-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 0.25rem;
    border: 1px solid var(--border);
}

.message-attachment-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: #dc2626;
    color: white;
    border-radius: 0.25rem;
}

.message-attachment-name {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Notifications */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    background: var(--surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1100;
    max-width: 350px;
}

.notification.show {
    transform: translateY(0);
    opacity: 1;
}

.notification-info {
    border-left: 4px solid var(--primary-color);
}

.notification-error {
    border-left: 4px solid var(--error);
    background: #fef2f2;
}

.notification-success {
    border-left: 4px solid var(--success);
    background: #f0fdf4;
}

/* Drag and drop zone styling */
.chat-input-container.drag-over {
    background: rgba(37, 99, 235, 0.05);
    border-color: var(--primary-color);
}

.chat-input-container.drag-over::before {
    content: 'Drop files here';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--primary-color);
    font-weight: 500;
    pointer-events: none;
}

/* Mobile adjustments for attachments */
@media (max-width: 768px) {
    .attachment-preview {
        padding: 0.5rem;
    }
    
    .attachment-item {
        padding: 0.375rem 0.5rem;
        font-size: 0.8rem;
    }
    
    .attachment-name {
        max-width: 60px;
    }
    
    .btn-icon {
        width: 40px;
        height: 40px;
    }
    
    .notification {
        left: 10px;
        right: 10px;
        max-width: none;
    }
}

