:root {
    --bg-dark: #050505;
    --sidebar-bg: #000000;
    --card-bg: #111111;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --accent: #7c3aed;
    --accent-glow: rgba(124, 58, 237, 0.4);
    --border: #27272a;
    --glass: rgba(255, 255, 255, 0.03);
    --glass-heavy: rgba(255, 255, 255, 0.08);
    --error: #ef4444;
    --success: #10b981;
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-hero: 'Outfit', sans-serif;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    background: radial-gradient(circle at 50% 50%, rgba(124, 58, 237, 0.05) 0%, transparent 100%);
}

/* Sidebar Styling - More Compact */
.sidebar {
    width: 220px;
    background-color: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 1rem 1rem;
}

.new-chat-btn {
    width: 100%;
    padding: 0.65rem;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
    font-size: 0.8rem;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    background: #8b5cf6;
    box-shadow: 0 8px 25px var(--accent-glow);
}

.knowledge-btn {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.65rem;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.8rem;
}

.knowledge-btn:hover {
    background: var(--glass-heavy);
    border-color: var(--text-secondary);
}

.history-container {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.history-item {
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    margin-bottom: 4px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.history-item:hover {
    background: var(--glass);
    border-color: var(--border);
}

.history-item.active {
    background: rgba(124, 58, 237, 0.1);
    border-color: rgba(124, 58, 237, 0.3);
}

.history-item .title {
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.history-item.active .title {
    color: var(--text-primary);
    font-weight: 500;
}

.history-item .actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
}

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

.delete-btn {
    color: var(--text-secondary);
    background: none;
    border: none;
    padding: 3px;
    cursor: pointer;
    border-radius: 4px;
}

.delete-btn:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

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

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avatar {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    color: white;
}

.username {
    font-size: 0.8rem;
}

/* Main Content Styling */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: transparent;
    min-width: 0;
    /* Critical for preventing overflow */
}

.top-bar {
    height: 50px;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: rgba(5, 5, 5, 0.8);
    backdrop-filter: blur(20px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
}

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

.model-selector {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.35rem 0.75rem;
    border-radius: 8px;
    font-size: 0.75rem;
    cursor: pointer;
    outline: none;
    transition: all 0.2s;
}

.model-selector:hover {
    border-color: var(--accent);
    box-shadow: 0 0 15px rgba(124, 58, 237, 0.1);
}

.agent-status {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.system-badges .agent-status {
    background: rgba(124, 58, 237, 0.12);
    color: #a78bfa;
    padding: 0.3rem 0.75rem;
    border-radius: 16px;
    border: 1px solid rgba(124, 58, 237, 0.2);
    font-size: 0.7rem;
}

.chat-viewport {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
}

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

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

::-webkit-scrollbar-thumb {
    background: #27272a;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3f3f46;
}

/* Welcome Screen - More Compact */
.welcome-screen {
    max-width: 750px;
    margin: auto;
    text-align: center;
    padding: 1.5rem;
    animation: fadeIn 0.8s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hero-title {
    font-family: var(--font-hero);
    font-size: 2.25rem;
    margin-bottom: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, #fff 0%, #a78bfa 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.feature-card {
    background: var(--card-bg);
    padding: 1.5rem 1.25rem;
    border-radius: 16px;
    border: 1px solid var(--border);
    text-align: left;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.feature-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.1), transparent);
    opacity: 0;
    transition: opacity 0.4s;
}

.feature-card:hover {
    transform: translateY(-8px);
    border-color: rgba(124, 58, 237, 0.5);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 20px rgba(124, 58, 237, 0.15);
}

.feature-card:hover::before {
    opacity: 1;
}

.feature-card i {
    color: var(--accent);
    margin-bottom: 1rem;
    width: 24px;
    height: 24px;
}

.feature-card h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
    position: relative;
    z-index: 1;
}

.feature-card p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    position: relative;
    z-index: 1;
}

/* Messages Interface - Compact */
.messages-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 1rem;
    padding-bottom: 3rem;
}

.message {
    width: 100%;
    padding: 1rem 1rem;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    animation: messageEntry 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes messageEntry {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message-inner {
    display: flex;
    gap: 0.75rem;
}

.message.human {
    background: transparent;
}

.message.ai {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.msg-avatar i {
    width: 16px;
    height: 16px;
}

.human .msg-avatar {
    background: radial-gradient(circle at top left, #6366f1, #a855f7);
    box-shadow: 0 3px 10px rgba(99, 102, 241, 0.3);
}

.ai .msg-avatar {
    background: radial-gradient(circle at top left, #10b981, #059669);
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
}

.msg-content-wrapper {
    flex: 1;
    min-width: 0;
    /* Critical for text overflow */
    overflow: hidden;
}

.msg-content {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

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

/* Code Blocks - Fix Overflow */
.msg-content pre {
    background: #000;
    padding: 1rem;
    border-radius: 10px;
    margin: 1rem 0;
    border: 1px solid var(--border);
    overflow-x: auto;
    max-width: 100%;
}

.msg-content code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    white-space: pre;
    display: block;
}

.msg-content :not(pre)>code {
    background: rgba(124, 58, 237, 0.15);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
    display: inline;
    white-space: normal;
}

/* Agent Step Cards - Inside Thought */
.agent-step {
    margin: 0.75rem 0;
    border-radius: 10px;
    background: rgba(124, 58, 237, 0.04);
    border: 1px solid rgba(124, 58, 237, 0.15);
    overflow: hidden;
    animation: fadeIn 0.4s ease;
}

.step-header {
    background: rgba(124, 58, 237, 0.07);
    padding: 0.6rem 1rem;
    font-weight: 700;
    font-size: 0.65rem;
    color: #a78bfa;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.step-header i {
    width: 14px;
    height: 14px;
}

.step-body {
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    max-height: 300px;
    overflow-y: auto;
}

.step-body pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.75rem;
    border-radius: 8px;
    margin: 0.5rem 0;
    overflow-x: auto;
    max-width: 100%;
}

.step-body code {
    font-size: 0.75rem;
    white-space: pre;
}

/* Agent Thought (Collapsible) - Contains Implementation Details */
.agent-thought {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    overflow: hidden;
    max-height: 42px;
    display: flex;
    flex-direction: column;
}

.agent-thought:hover {
    background: rgba(255, 255, 255, 0.04);
}

.thought-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.75rem;
    min-height: 42px;
}

.thought-bar i {
    width: 16px;
    height: 16px;
}

.thought-summary {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chevron {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    opacity: 0.5;
    transition: transform 0.3s;
}

.agent-thought.expanded {
    max-height: 2000px;
    background: rgba(0, 0, 0, 0.1);
    border-color: rgba(124, 58, 237, 0.4);
    cursor: default;
}

.agent-thought.expanded .thought-bar {
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.agent-thought.expanded .thought-summary {
    white-space: normal;
    font-weight: 600;
    color: var(--text-primary);
}

.agent-thought.expanded .chevron {
    transform: rotate(180deg);
}

.thought-details {
    padding: 0.5rem 0.75rem 0.75rem;
    background: rgba(0, 0, 0, 0.15);
    max-height: 500px;
    overflow-y: auto;
}

.agent-thought.has-process.expanded {
    background: rgba(124, 58, 237, 0.03);
}

.thought-details .agent-step {
    border-radius: 8px;
    margin-top: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
}

.thought-details .agent-step:first-child {
    margin-top: 0;
}

.agent-thought i {
    color: var(--accent);
    flex-shrink: 0;
}

/* Floating Input Box - Compact */
.input-area {
    padding: 1rem 0 1.5rem;
    background: linear-gradient(to top, var(--bg-dark) 60%, transparent);
    position: relative;
    z-index: 60;
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 1rem;
}

.attachment-preview {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.preview-item {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.text-input-container {
    background: #18181b;
    border: 1px solid #27272a;
    border-radius: 16px;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.8), 0 0 30px rgba(124, 58, 237, 0.05);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.text-input-container:focus-within {
    border-color: var(--accent);
    background: #1d1d21;
    transform: translateY(-2px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9), 0 0 40px rgba(124, 58, 237, 0.1);
}

textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    resize: none;
    font-size: 0.9rem;
    padding: 0.5rem 0.25rem;
    max-height: 150px;
    outline: none;
    line-height: 1.4;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 10px;
    transition: all 0.2s;
}

.icon-btn i {
    width: 18px;
    height: 18px;
}

.icon-btn:hover {
    color: var(--text-primary);
    background: var(--glass-heavy);
}

.send-btn {
    background: var(--accent);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
}

.send-btn i {
    width: 16px;
    height: 16px;
}

.send-btn:hover:not(:disabled) {
    background: #8b5cf6;
    transform: scale(1.08);
    box-shadow: 0 0 15px var(--accent-glow);
}

.send-btn:disabled {
    background: #27272a;
    color: #52525b;
    cursor: not-allowed;
}

.input-footer {
    font-size: 0.65rem;
    color: #71717a;
    text-align: center;
    margin-top: 0.75rem;
    letter-spacing: 0.025em;
}

/* Modals - Compact */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(15px);
}

.modal-content {
    background: #09090b;
    margin: 10% auto;
    padding: 2rem;
    border: 1px solid var(--border);
    width: 90%;
    max-width: 450px;
    border-radius: 20px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
    position: relative;
    animation: modalSlide 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.modal-header h2 {
    font-family: var(--font-hero);
    font-size: 1.5rem;
    font-weight: 700;
}

.modal-body p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.close-modal {
    font-size: 1.25rem;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.2s;
    padding: 0.25rem;
}

.close-modal:hover {
    color: white;
}

.upload-zone {
    border: 2px dashed #3f3f46;
    border-radius: 14px;
    padding: 40px 15px;
    text-align: center;
    transition: 0.3s;
    cursor: pointer;
}

.upload-zone i {
    width: 32px;
    height: 32px;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.upload-zone p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.upload-zone:hover {
    border-color: var(--accent);
    background: rgba(124, 58, 237, 0.05);
}

/* Progress Bar for Knowledge Base */
.kb-progress-container {
    width: 100%;
    margin-top: 0.75rem;
    background-color: var(--border);
    border-radius: 9999px;
    height: 4px;
    overflow: hidden;
    position: relative;
    display: none;
}

.kb-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 9999px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Knowledge Base Status Items */
.kb-status-list {
    margin-top: 1rem;
    max-height: 200px;
    overflow-y: auto;
}

.kb-status-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.4rem;
    font-size: 0.75rem;
    color: var(--text-primary);
    transition: all 0.2s;
}

.kb-status-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--text-secondary);
}

.kb-status-item .delete-btn {
    opacity: 0.7;
    transition: opacity 0.2s;
    padding: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.kb-status-item:hover .delete-btn {
    opacity: 1;
    color: var(--error);
}

/* Spinner animation */
.spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Recording indicator */
.recording {
    color: var(--error) !important;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }

    .messages-container {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        position: absolute;
        height: 100%;
    }

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

    .menu-toggle {
        display: block;
    }

    .features-grid {
        grid-template-columns: 1fr;
    }

    .hero-title {
        font-size: 1.75rem;
    }

    .top-bar {
        padding: 0 1rem;
    }
}
