/* ============================================================
   BabyLLM — Design System
   Aesthetic: Warm industrial / soft brutalism
   ============================================================ */

:root {
    --bg-primary: #0e0f11;
    --bg-secondary: #161719;
    --bg-tertiary: #1c1d20;
    --bg-card: #1a1b1e;
    --bg-hover: #222326;
    --bg-input: #131416;

    --text-primary: #e8e6e3;
    --text-secondary: #9b9a97;
    --text-muted: #5f5e5b;

    --accent: #f0a500;
    --accent-dim: #c48800;
    --accent-glow: rgba(240, 165, 0, 0.15);

    --success: #4ade80;
    --error: #f87171;
    --info: #60a5fa;

    --border: #2a2b2e;
    --border-subtle: #1f2023;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);

    --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --sidebar-width: 260px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ---- Layout ---- */
.app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    gap: 24px;
}

.sidebar-header { padding-bottom: 4px; }

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    color: var(--accent);
    flex-shrink: 0;
}

.logo-icon svg { width: 100%; height: 100%; }

.logo h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.tagline {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 500;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.nav-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--accent-glow);
    border-color: var(--accent-dim);
    color: var(--accent);
}

.sidebar-stats {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.stat-item { display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-size: 20px; font-weight: 700; font-family: var(--font-mono); color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

.sidebar-footer { padding-top: 8px; }

.health-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background var(--transition);
}

.health-indicator.connected .dot { background: var(--success); box-shadow: 0 0 8px rgba(74,222,128,0.4); }
.health-indicator.error .dot { background: var(--error); }

/* ---- Main Content ---- */
.main-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.mode-panel {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.mode-panel.active { display: flex; }

/* ---- Chat Mode ---- */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 80px 40px;
    gap: 16px;
    animation: fadeInUp 0.6s ease-out;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    color: var(--accent);
    margin-bottom: 8px;
}

.welcome-icon svg { width: 100%; height: 100%; }

.welcome-message h2 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.welcome-message p {
    font-size: 15px;
    color: var(--text-secondary);
    max-width: 420px;
    line-height: 1.6;
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 12px;
    max-width: 740px;
    animation: fadeInUp 0.3s ease-out;
}

.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
}

.message.user .msg-avatar { background: var(--accent); color: var(--bg-primary); }
.message.assistant .msg-avatar { background: var(--bg-tertiary); border: 1px solid var(--border); color: var(--accent); }

.msg-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.msg-content {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}

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

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

.msg-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 4px;
}

.msg-feedback-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all var(--transition);
}

.msg-feedback-btn:hover {
    border-color: var(--accent-dim);
    color: var(--accent);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-6px); opacity: 1; }
}

/* Chat Input */
.chat-input-area {
    padding: 16px 32px 24px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-primary);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 8px 8px 8px 20px;
    transition: border-color var(--transition);
    max-width: 740px;
    margin: 0 auto;
}

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

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    padding: 6px 0;
}

.input-wrapper textarea::placeholder { color: var(--text-muted); }

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
}

.send-btn:hover { transform: scale(1.05); background: var(--accent-dim); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.send-btn svg { width: 18px; height: 18px; }

/* ---- Teach Mode ---- */
.teach-container {
    padding: 40px 32px;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
}

.teach-header {
    margin-bottom: 32px;
}

.teach-header h2 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
}

.teach-header p {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.6;
}

.teach-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.teach-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: border-color var(--transition);
}

.teach-card:hover { border-color: var(--accent-dim); }

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-header svg { width: 20px; height: 20px; color: var(--accent); flex-shrink: 0; }
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

.teach-card textarea,
.teach-card input[type="text"] {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition);
    width: 100%;
}

.teach-card textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
.teach-card textarea:focus,
.teach-card input[type="text"]:focus { border-color: var(--accent-dim); }
.teach-card textarea::placeholder,
.teach-card input[type="text"]::placeholder { color: var(--text-muted); }

.teach-meta {
    display: flex;
    gap: 12px;
}

.teach-meta input { flex: 1; }

/* File Upload */
.file-upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 32px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-muted);
}

.file-upload-area:hover {
    border-color: var(--accent-dim);
    background: var(--accent-glow);
    color: var(--accent);
}

.file-upload-area svg { width: 32px; height: 32px; }
.file-upload-area span { font-size: 13px; }

.file-upload-area.dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

/* Buttons */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
}

.action-btn svg { width: 16px; height: 16px; }

.action-btn.primary {
    background: var(--accent);
    color: var(--bg-primary);
}

.action-btn.primary:hover { background: var(--accent-dim); }

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

.action-btn.secondary:hover { border-color: var(--accent-dim); color: var(--accent); }

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

.result-msg {
    font-size: 13px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    display: none;
    animation: fadeInUp 0.3s ease-out;
}

.result-msg.success { display: block; background: rgba(74,222,128,0.1); color: var(--success); border: 1px solid rgba(74,222,128,0.2); }
.result-msg.error { display: block; background: rgba(248,113,113,0.1); color: var(--error); border: 1px solid rgba(248,113,113,0.2); }

/* ---- Memory Mode ---- */
.memory-container {
    padding: 40px 32px;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
}

.memory-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
}

.memory-header h2 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.memory-header p {
    color: var(--text-secondary);
    font-size: 15px;
    flex: 1;
}

.memory-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.memory-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition);
    animation: fadeInUp 0.3s ease-out;
}

.memory-item:hover { border-color: var(--accent-dim); }

.memory-badge {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    flex-shrink: 0;
}

.memory-badge.taught { background: rgba(96,165,250,0.15); color: var(--info); }
.memory-badge.correction { background: rgba(248,113,113,0.15); color: var(--error); }
.memory-badge.verified { background: rgba(74,222,128,0.15); color: var(--success); }
.memory-badge.uploaded { background: rgba(240,165,0,0.15); color: var(--accent); }

.memory-text {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.memory-meta {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    font-family: var(--font-mono);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.modal-overlay.visible { display: flex; }

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px;
    width: 90%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h3 { font-size: 18px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

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

.feedback-buttons {
    display: flex;
    gap: 12px;
}

.fb-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.fb-btn svg { width: 18px; height: 18px; }

.fb-btn.good:hover { border-color: var(--success); color: var(--success); background: rgba(74,222,128,0.08); }
.fb-btn.bad:hover { border-color: var(--error); color: var(--error); background: rgba(248,113,113,0.08); }

.correction-area {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.correction-area textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    min-height: 80px;
    outline: none;
    resize: vertical;
}

.correction-area textarea:focus { border-color: var(--accent-dim); }

/* ---- Animations ---- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s ease;
    }

    .sidebar.open { left: 0; }

    .app { flex-direction: column; }
    .main-content { height: 100vh; }

    .chat-messages { padding: 20px 16px; }
    .chat-input-area { padding: 12px 16px 20px; }
    .teach-container, .memory-container { padding: 24px 16px; }
    .teach-meta { flex-direction: column; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    :root { --sidebar-width: 220px; }
}
