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

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

:root {
    --bg-primary: #0f0a1e;
    --bg-secondary: #1a1333;
    --bg-tertiary: #251d3d;
    --bg-input: #0d0819;
    --sidebar-bg: #120e22;
    --accent: #a855f7;
    --accent-hover: #9333ea;
    --accent-glow: rgba(168, 85, 247, 0.3);
    --text: #f1f5f9;
    --text-dim: #94a3b8;
    --text-muted: #64748b;
    --border: rgba(168, 85, 247, 0.15);
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --radius: 12px;
    --sidebar-width: 280px;
}

html, body { height: 100%; overflow: hidden; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text);
    display: flex;
}

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}

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

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 28px; }
.logo-text {
    font-size: 22px;
    font-weight: 600;
    background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 28px;
    cursor: pointer;
}

.new-chat-btn {
    margin: 20px;
    padding: 14px 20px;
    background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
    border: none;
    border-radius: var(--radius);
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px var(--accent-glow);
}

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

.sidebar-section { flex: 1; overflow-y: auto; padding: 0 12px; }

.section-title {
    padding: 12px 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-title button {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}

.section-title button:hover { background: var(--bg-tertiary); }

.chat-list, .session-list { display: flex; flex-direction: column; gap: 4px; }

.chat-item, .session-item {
    padding: 12px 16px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-item:hover, .session-item:hover { background: var(--bg-tertiary); }
.chat-item.active { background: var(--bg-tertiary); border: 1px solid var(--border); }

.chat-item-icon { font-size: 16px; }
.chat-item-title {
    flex: 1;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
}

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

.session-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
    animation: pulse 2s infinite;
}

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

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-btn {
    padding: 12px 16px;
    background: none;
    border: none;
    border-radius: 10px;
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s ease;
    text-align: left;
}

.sidebar-btn:hover { background: var(--bg-tertiary); color: var(--text); }
.sidebar-btn.logout:hover { color: var(--error); }

/* MAIN */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.header {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
}

.header-title {
    font-weight: 600;
    font-size: 15px;
    flex: 1;
}

.model-select select {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: 20px;
    font-size: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
}

.status-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.offline { background: var(--error); }

.user-menu {
    width: 36px;
    height: 36px;
    background: var(--bg-tertiary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
}

/* CHAT AREA */
.chat-area { flex: 1; overflow-y: auto; padding: 24px; }

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.welcome.hidden { display: none; }

.welcome-logo {
    font-size: 72px;
    margin-bottom: 20px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.welcome h1 {
    font-size: 48px;
    font-weight: 700;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome p { color: var(--text-dim); font-size: 16px; margin-bottom: 40px; max-width: 500px; }

.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 600px;
}

.quick-action {
    padding: 20px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    color: var(--text);
    font-size: 13px;
}

.quick-action span:first-child { font-size: 24px; }
.quick-action:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
    transform: translateY(-2px);
}

/* MESSAGES */
.messages {
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 800px;
    margin: 0 auto;
}

.message { display: flex; gap: 16px; }

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

.message.user .message-avatar { background: var(--bg-tertiary); }
.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
}

.message-content { flex: 1; line-height: 1.7; }
.message-content p { margin-bottom: 12px; }
.message-content p:last-child { margin-bottom: 0; }

.message-content pre {
    background: var(--bg-input);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid var(--border);
}

.message-content code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
}

.message-content code:not(pre code) {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
}

/* INPUT AREA */
.input-area {
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 8px 12px;
    transition: border-color 0.2s ease;
}

.input-container:focus-within { border-color: var(--accent); }

.attach-btn {
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.attach-btn:hover { color: var(--text); background: var(--bg-tertiary); }
.attach-btn svg { width: 20px; height: 20px; }

#message-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    line-height: 1.5;
    padding: 8px 0;
}

#message-input:focus { outline: none; }
#message-input::placeholder { color: var(--text-muted); }

.send-btn {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn svg { width: 18px; height: 18px; color: white; }
.send-btn:hover { transform: scale(1.05); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.input-footer { max-width: 800px; margin: 8px auto 0; text-align: center; }
#agent-status { font-size: 12px; color: var(--text-muted); }

/* MODALS */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal.active { display: flex; }

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow: auto;
}

.modal-content.modal-lg { max-width: 640px; }

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
}

.modal-header h2 { font-size: 18px; display: flex; align-items: center; gap: 10px; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}

.modal-close:hover { background: var(--bg-tertiary); }

.modal-body { padding: 20px; }

.setting-group { margin-bottom: 20px; }

.setting-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-dim);
}

.setting-group input[type="text"],
.setting-group input[type="password"],
.setting-group select,
.setting-group textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}

.setting-group input:focus,
.setting-group select:focus,
.setting-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-group input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
    color: white;
}

.btn-primary:hover { transform: translateY(-1px); }

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg-input); }

/* Task & Memory Lists */
.task-form, .memory-search, .vault-form {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.task-form input, .memory-search input, .vault-form input {
    flex: 1;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
}

.task-list, .memory-list, .vault-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.task-item, .memory-item, .vault-item {
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.task-item .task-schedule, .memory-item .memory-date {
    font-size: 12px;
    color: var(--text-muted);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.vault-info {
    color: var(--text-dim);
    font-size: 13px;
    margin-bottom: 20px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

/* MOBILE */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
    }
    
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: block; }
    .menu-btn { display: block; }
    
    .quick-actions { grid-template-columns: repeat(2, 1fr); }
    .welcome h1 { font-size: 32px; }
    
    .header { padding: 12px 16px; }
    .chat-area { padding: 16px; }
    .input-area { padding: 12px 16px; }
    
    .header-title { display: none; }
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* Loading Animation */
.loading-dots {
    display: flex;
    gap: 6px;
    padding: 10px 0;
}

.loading-dots span {
    width: 10px;
    height: 10px;
    background: var(--accent);
    border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.loading-text {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 8px;
}

.message.loading .message-content {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 12px;
    display: inline-block;
}
