:root {
    --bg-dark: #0f172a;
    --sidebar-bg: #1e293b;
    --card-bg: #1e293b;
    --text-primary: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #6366f1;
    --primary-light: #818cf8;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --border: rgba(148, 163, 184, 0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Outfit', sans-serif; }
body { background: var(--bg-dark); color: var(--text-primary); display: flex; height: 100vh; overflow: hidden; }

/* LAYOUT SHELL - EXPLICIT GRID PLACEMENT */
.app-shell { 
    display: grid; 
    grid-template-columns: 260px 1fr; 
    grid-template-rows: 70px 1fr; 
    height: 100%; 
    width: 100%; 
}

/* SIDEBAR - Full Height */
.sidebar { 
    grid-column: 1; 
    grid-row: 1 / -1; 
    background: var(--sidebar-bg); 
    border-right: 1px solid var(--border); 
    display: flex; 
    flex-direction: column; 
    padding: 25px; 
    z-index: 100;
}

/* HEADER - Top Row, Right Column */
.app-header { 
    grid-column: 2; 
    grid-row: 1; 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    padding: 0 30px; 
    border-bottom: 1px solid var(--border); 
    background: rgba(15, 23, 42, 0.95); 
    backdrop-filter: blur(5px); 
    z-index: 90;
}

/* MAIN CONTENT - Bottom Row, Right Column */
.main-content { 
    grid-column: 2; 
    grid-row: 2; 
    padding: 30px; 
    overflow-y: auto; 
    background: var(--bg-dark);
}

/* GENERAL UI COMPONENTS */
.brand { font-size: 1.2rem; font-weight: 700; display: flex; align-items: center; gap: 10px; margin-bottom: 40px; color: white; letter-spacing: 1px; }
.logo-icon { width: 32px; height: 32px; background: linear-gradient(135deg, var(--primary), #a855f7); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; box-shadow: 0 0 15px rgba(99, 102, 241, 0.5); }

.menu-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 700; margin-bottom: 15px; letter-spacing: 1.5px; }

.nav-item { display: flex; align-items: center; gap: 12px; padding: 12px 15px; color: var(--text-muted); text-decoration: none; border-radius: 10px; margin-bottom: 5px; transition: 0.2s; font-weight: 500; font-size: 0.9rem; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: white; transform: translateX(5px); }
.nav-item.active { background: linear-gradient(90deg, rgba(99, 102, 241, 0.2), transparent); color: var(--primary-light); border-left: 3px solid var(--primary); }
.nav-item span { font-size: 1.1rem; }

.card { background: var(--card-bg); border-radius: 16px; border: 1px solid var(--border); padding: 25px; transition: 0.3s; position: relative; overflow: hidden; }
.card:hover { border-color: rgba(99, 102, 241, 0.3); box-shadow: 0 10px 30px -10px rgba(0,0,0,0.3); }

.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid var(--border); padding-bottom: 15px; }
.card-title { font-size: 1.1rem; font-weight: 600; display: flex; align-items: center; gap: 10px; }

.btn { padding: 10px 20px; border-radius: 8px; font-weight: 600; cursor: pointer; transition: 0.2s; font-size: 0.9rem; display: inline-flex; align-items: center; text-decoration: none; border: none; }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4); }
.btn-primary:hover { background: var(--primary-light); transform: translateY(-2px); box-shadow: 0 8px 25px rgba(99, 102, 241, 0.5); }
.btn-glass { background: rgba(255,255,255,0.1); color: white; border: 1px solid var(--border); }
.btn-glass:hover { background: rgba(255,255,255,0.2); }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-size: 0.9rem; color: var(--text-muted); font-weight: 500; }
.form-group input, .form-group textarea { width: 100%; background: rgba(0,0,0,0.2); border: 1px solid var(--border); color: white; padding: 12px; border-radius: 8px; outline: none; transition: 0.2s;font-size: 0.95rem; }
.form-group input:focus, .form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2); }

/* CHAT WIDGET & MODAL */
.chat-widget-btn { position: fixed; bottom: 30px; right: 30px; width: 60px; height: 60px; background: var(--primary); border-radius: 50%; box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.3s; z-index: 1000; animation: bounce 3s infinite; }
.chat-widget-btn:hover { transform: scale(1.1); }
.chat-widget-btn .icon { font-size: 1.8rem; color: white; }

.chat-modal { position: fixed; bottom: 100px; right: 30px; width: 400px; height: 600px; background: rgba(15, 23, 42, 0.95); backdrop-filter: blur(20px); border: 1px solid var(--border); border-radius: 20px; display: none; flex-direction: column; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,0.5); z-index: 1000; }

.chat-header { padding: 20px; background: linear-gradient(90deg, var(--primary), #a855f7); color: white; font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.chat-display { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; scroll-behavior: smooth; }
.msg { padding: 12px 16px; border-radius: 12px; max-width: 85%; font-size: 0.9rem; line-height: 1.5; position: relative; animation: fadeIn 0.3s ease; }
.msg.user { background: var(--primary); align-self: flex-end; color: white; border-bottom-right-radius: 4px; }
.msg.ai { background: rgba(255,255,255,0.1); align-self: flex-start; color: var(--text-primary); border-bottom-left-radius: 4px; border: 1px solid var(--border); }

.chat-input-area { padding: 20px; border-top: 1px solid var(--border); background: rgba(0,0,0,0.2); display: flex; gap: 10px; }
.chat-input-area input { flex: 1; background: rgba(255,255,255,0.05); border: 1px solid var(--border); border-radius: 12px; padding: 10px; color: white; outline: none; }
.chat-input-area button { padding: 10px 20px; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

.pulse { width: 8px; height: 8px; background: var(--success); border-radius: 50%; display: inline-block; margin-right: 5px; box-shadow: 0 0 10px var(--success); animation: pulse 2s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

/* VISUAL DIAGRAM STYLES */
.system-diagram { padding: 40px; background: rgba(0,0,0,0.2); border-radius: 20px; border: 1px solid var(--border); overflow: hidden; position: relative; }
.diagram-container { display: flex; justify-content: space-between; align-items: center; max-width: 900px; margin: 0 auto; position: relative; }

.node { 
    background: var(--card-bg); border: 2px solid var(--border); border-radius: 16px; padding: 20px; 
    text-align: center; width: 140px; position: relative; z-index: 5; transition: 0.3s;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}
.node:hover { transform: translateY(-5px); border-color: var(--primary); }
.node-icon { font-size: 2.5rem; margin-bottom: 10px; display: block; }
.node-label { font-size: 0.9rem; font-weight: 700; color: white; display: block; }
.node-sub { font-size: 0.7rem; color: var(--text-muted); display: block; }

.node.highlight-brain { border-color: var(--primary); box-shadow: 0 0 30px rgba(99, 102, 241, 0.3); }
.node.highlight-memory { border-color: var(--success); }
.node.highlight-llm { border-color: #A855F7; }

.data-packet { 
    position: absolute; width: 8px; height: 8px; background: var(--success); border-radius: 50%; 
    top: 50%; transform: translateY(-50%); box-shadow: 0 0 10px var(--success); opacity: 0; z-index: 10;
}

@keyframes flow-right {
    0% { left: 15%; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { left: 85%; opacity: 0; }
}

.flow-line { height: 2px; background: rgba(255,255,255,0.1); width: 100%; position: absolute; top: 50%; margin-top: -1px; z-index: 1; }
.brain-pulse {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 140px; height: 140px; border-radius: 50%;
    border: 2px solid var(--primary); opacity: 0;
    animation: ripple 2s infinite; pointer-events: none;
}
@keyframes ripple {
    0% { width: 140px; height: 140px; opacity: 0.6; }
    100% { width: 250px; height: 250px; opacity: 0; }
}

/* AUTH PAGES */
.auth-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 24px;
    width: 100%;
    max-width: 440px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.auth-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
}

/* MODAL SYSTEM */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0; 
    top: 0; 
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.6); 
    backdrop-filter: blur(5px);
    justify-content: center; 
    align-items: center; 
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background-color: var(--card-bg);
    margin: auto;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    animation: scaleUp 0.3s ease;
}

@keyframes scaleUp {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal .close {
    color: var(--text-muted);
    font-size: 28px;
    font-weight: bold;
    transition: 0.2s;
}

.modal .close:hover,
.modal .close:focus {
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
}


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

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 340px; /* Adjusted sidebar width */
    gap: 30px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    margin-top: 20px;
}

.content-area {
    overflow-y: auto;
    padding-right: 15px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.dashboard-grid .sidebar {
    grid-column: 2;
    grid-row: 1;
    background: transparent; /* Override dark bg */
    border-right: none;
    border-left: 1px solid var(--border);
    padding: 0 0 0 25px;
    display: flex;
    flex-direction: column;
    gap: 30px;
    overflow-y: auto;
    height: auto; /* Allow sizing by grid area */
}

/* Header Adjustments for Container Layout */
.container > header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    flex-shrink: 0;
}

.header-left h1 {
    font-size: 1.5rem;
    background: linear-gradient(90deg, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    padding-bottom: 20px;
}

.knowledge-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    position: relative;
    transition: 0.3s;
    height: 100%;
    display: flex;
    flex-direction: column;
}
.knowledge-card:hover {
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

.card-body {
    flex: 1;
    margin: 15px 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.intent-badge {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-light);
    border: 1px solid rgba(99, 102, 241, 0.3);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.confidence-badge {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--success);
}

.sidebar-section h3 {
    margin-bottom: 15px;
    font-size: 0.9rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.log-container {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.log-entry {
    font-size: 0.8rem;
    padding: 10px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    border-left: 2px solid var(--text-muted);
}
.log-entry.info { border-color: var(--primary); }
.log-entry.warning { border-color: var(--warning); }
.log-entry.error { border-color: var(--danger); }
