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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --message-user: #2563eb;
    --message-assistant: #1e293b;
    --sidebar-width: 260px;
    --header-height: 60px;
    --workflow-bg: #1a2332;
    --workflow-border: #2d3748;
    --workflow-header-bg: #2d3748;
    --workflow-prompt-bg: #252f3f;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

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

/* Sidebar Styles */
.sidebar {
    width: var(--sidebar-width);
    min-width: 200px;
    max-width: 50vw;
    background-color: var(--surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    position: relative;
    resize: none;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-buttons {
    display: flex;
    gap: 8px;
    width: 100%;
}

.new-chat-btn {
    flex: 1;
    padding: 10px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.2s;
}

.new-chat-btn:hover {
    background-color: var(--primary-hover);
}

.new-folder-btn {
    background: var(--surface-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-folder-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.conversation-item {
    padding: 12px 16px;
    margin-bottom: 5px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation-item:hover {
    background-color: var(--surface-hover);
}

.conversation-item.active {
    background-color: var(--surface-hover);
    border-left: 3px solid var(--primary-color);
}

.conversation-title {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.conversation-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.delete-conversation {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
}

.conversation-item:hover .delete-conversation {
    opacity: 1;
}

.delete-conversation:hover {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.clear-all-btn {
    width: 100%;
    padding: 10px;
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.clear-all-btn:hover {
    color: #ef4444;
    border-color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    background: transparent;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.resize-handle:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.resize-handle-line {
    width: 2px;
    height: 100%;
    background: transparent;
    transition: background-color 0.2s;
}

.resize-handle:hover .resize-handle-line {
    background-color: var(--primary-color);
}

/* Resizing state */
.sidebar.resizing {
    transition: none;
    user-select: none;
}

.sidebar.resizing .resize-handle {
    background-color: rgba(0, 0, 0, 0.1);
}

.sidebar.resizing .resize-handle-line {
    background-color: var(--primary-color);
}

/* Hide resize handle on mobile */
@media (max-width: 768px) {
    .resize-handle {
        display: none;
    }
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-header {
    height: var(--header-height);
    background-color: var(--surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.chat-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-admin, .btn-logout, .btn-login {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background-color 0.2s;
}

.btn-admin:hover, .btn-logout:hover, .btn-login:hover {
    background: var(--primary-hover);
}

.btn-logout {
    background: #dc2626;
}

.btn-logout:hover {
    background: #b91c1c;
}

.auth-required {
    display: flex;
    align-items: center;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.menu-toggle:hover {
    background-color: var(--surface-hover);
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
}

.welcome-message i {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

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

/* Message Styles */
.message {
    display: flex;
    gap: 12px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}

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

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background-color: var(--message-user);
    color: white;
}

.message.assistant .message-avatar {
    background-color: var(--surface-hover);
    color: var(--text-primary);
}

.message-content {
    flex: 1;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.6;
}

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

.message.assistant .message-content {
    background-color: var(--message-assistant);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.message-content pre {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 10px 0;
}

.message-content code {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
}

/* Markdown styles */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin-top: 16px;
    margin-bottom: 8px;
    font-weight: 600;
}

.message-content h1 { font-size: 1.5rem; }
.message-content h2 { font-size: 1.3rem; }
.message-content h3 { font-size: 1.1rem; }

.message-content p {
    margin: 8px 0;
    line-height: 1.6;
}

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

.message-content li {
    margin: 4px 0;
    line-height: 1.5;
}

.message-content blockquote {
    margin: 12px 0;
    padding-left: 16px;
    border-left: 4px solid var(--primary-color);
    color: var(--text-secondary);
    font-style: italic;
}

.message-content a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s;
}

.message-content a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.message-content table {
    margin: 12px 0;
    border-collapse: collapse;
    width: 100%;
}

.message-content th,
.message-content td {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    text-align: left;
}

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

.message-content hr {
    margin: 16px 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

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

.message-content em {
    font-style: italic;
}

/* Code blocks with syntax highlighting background */
.message-content pre code {
    display: block;
    padding: 12px;
    background: none;
    line-height: 1.5;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-secondary);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

/* Input Container */
.input-container {
    padding: 20px;
    background-color: var(--surface);
    border-top: 1px solid var(--border-color);
}

.attachment-preview {
    margin-bottom: 10px;
    padding: 10px;
    background-color: var(--background);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
}

.attachment-item i {
    color: var(--primary-color);
    font-size: 1.2rem;
}

.attachment-item span {
    flex: 1;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-attachment {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
    transition: color 0.2s;
}

.remove-attachment:hover {
    color: #ef4444;
}

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

#messageInput {
    flex: 1;
    background-color: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 0.95rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    max-height: 120px;
    overflow-y: auto;
}

#messageInput:focus {
    border-color: var(--primary-color);
}

.send-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 12px 20px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: scale(1.05);
}

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

.attach-btn {
    padding: 10px 12px;
    background-color: var(--surface-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.attach-btn.has-attachment {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.input-info {
    text-align: right;
    margin-top: 5px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Workflow Display Styles */
.workflow-status {
    color: var(--text-secondary);
    font-style: italic;
    padding: 8px 12px;
    background: var(--workflow-bg);
    border-radius: 6px;
    margin: 8px 0;
    border-left: 3px solid var(--primary-color);
}

.workflow-section {
    margin: 16px 0;
    background: var(--workflow-bg);
    border: 1px solid var(--workflow-border);
    border-radius: 8px;
    overflow: hidden;
}

.workflow-header {
    background: var(--workflow-header-bg);
    padding: 10px 16px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--workflow-border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.workflow-content {
    padding: 16px;
    color: var(--text-primary);
    line-height: 1.6;
}

.workflow-prompt {
    padding: 16px;
    background: var(--workflow-prompt-bg);
    color: var(--text-secondary);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
    border-radius: 4px;
    margin: 12px;
    border: 1px solid var(--workflow-border);
}

.final-section {
    border: 2px solid var(--primary-color);
    background: linear-gradient(135deg, var(--workflow-bg), var(--surface));
}

.final-section .workflow-header {
    background: var(--primary-color);
    color: white;
}

.workflow-raw {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    background: var(--workflow-prompt-bg);
    padding: 12px;
    border-radius: 4px;
    border: 1px solid var(--workflow-border);
    margin: 8px 0;
    /* Preserve all whitespace and line breaks */
    word-break: break-all;
    overflow-wrap: break-word;
    max-height: 400px;
    overflow-y: auto;
}

.synthesis-header {
    background: linear-gradient(135deg, #059669, #047857) !important;
    border-left: 4px solid #10b981;
    font-weight: 700;
}

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-toggle {
        display: block !important;
    }

    .chat-container {
        padding: 10px;
    }

    .message {
        max-width: 100%;
    }

    .input-wrapper {
        max-width: 100%;
    }
}

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

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

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

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

/* Generated Images */
.generated-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
    cursor: pointer;
    transition: transform 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.generated-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Image Modal */
.image-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    animation: fadeIn 0.3s;
}

.image-modal-content {
    position: relative;
    margin: auto;
    padding: 20px;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.image-modal-content img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
}

.image-modal-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.image-modal-close:hover {
    color: #fff;
}

.image-modal-caption {
    color: #ccc;
    text-align: center;
    padding: 10px 20px;
    margin-top: 10px;
    font-size: 14px;
}

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