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

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #242424;
    --text-primary: #e8e8e8;
    --text-secondary: #888;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --border: #2a2a2a;
    --danger: #ef4444;
    --user-msg: #2563eb;
    --assistant-msg: #1a1a1a;
    --sidebar-width: 280px;
}

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

/* Auth Page */
.auth-page { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--bg-primary); }
.auth-container { width: 100%; max-width: 400px; padding: 20px; }
.auth-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 16px; padding: 40px; }
.auth-card h1 { text-align: center; font-size: 1.5rem; margin-bottom: 4px; color: var(--accent); }
.auth-card .subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 24px; font-size: 0.9rem; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 0.85rem; color: var(--text-secondary); }
.form-group input { width: 100%; padding: 10px 14px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 8px; color: var(--text-primary); font-size: 0.95rem; outline: none; transition: border-color 0.2s; }
.form-group input:focus { border-color: var(--accent); }
.btn { display: block; width: 100%; padding: 10px; border: none; border-radius: 8px; font-size: 0.95rem; cursor: pointer; font-weight: 500; transition: all 0.2s; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.auth-toggle { text-align: center; margin-top: 16px; font-size: 0.85rem; color: var(--text-secondary); }
.auth-toggle a { color: var(--accent); text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 0.85rem; background: #3b1111; color: #fca5a5; border: 1px solid #7f1d1d; }

/* App Layout */
.app { display: flex; height: 100vh; }

/* Sidebar */
.sidebar { width: var(--sidebar-width); background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; transition: transform 0.3s; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 1rem; color: var(--text-primary); }
.conversation-list { flex: 1; overflow-y: auto; padding: 8px; }
.conversation-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-radius: 8px; cursor: pointer; transition: background 0.15s; margin-bottom: 2px; }
.conversation-item:hover { background: var(--bg-tertiary); }
.conversation-item.active { background: var(--bg-tertiary); }
.convo-title { flex: 1; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-icon, .btn-icon-sm { background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 4px; border-radius: 4px; display: flex; align-items: center; justify-content: center; transition: color 0.15s; }
.btn-icon:hover, .btn-icon-sm:hover { color: var(--text-primary); }
.btn-icon-sm { opacity: 0; transition: opacity 0.15s; }
.conversation-item:hover .btn-icon-sm { opacity: 1; }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--border); }
.user-info { font-size: 0.85rem; color: var(--text-secondary); }

/* Chat Main */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg-secondary); }
.chat-header h3 { font-size: 0.95rem; font-weight: 500; flex: 1; }
.sidebar-toggle { display: none; }
.btn-teach { display: flex; align-items: center; gap: 6px; padding: 6px 12px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 8px; color: var(--text-secondary); font-size: 0.8rem; cursor: pointer; transition: all 0.2s; }
.btn-teach:hover { color: var(--accent); border-color: var(--accent); }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 20px; scroll-behavior: smooth; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-secondary); text-align: center; }
.empty-icon { margin-bottom: 16px; opacity: 0.3; }
.empty-state h2 { font-size: 1.3rem; margin-bottom: 8px; color: var(--text-primary); }
.empty-state p { font-size: 0.9rem; }

.message { margin-bottom: 20px; display: flex; gap: 12px; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }
.message-avatar { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 600; flex-shrink: 0; }
.message.user .message-avatar { background: var(--user-msg); color: white; order: 2; }
.message.assistant .message-avatar { background: var(--bg-tertiary); color: var(--accent); }
.message-content { width: 100%; padding: 12px 16px; border-radius: 16px; font-size: 0.9rem; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; }
.message.user .message-content { background: var(--user-msg); color: white; border-bottom-right-radius: 4px; }
.message.assistant .message-content { background: var(--assistant-msg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.message-content-wrapper { max-width: 70%; display: flex; flex-direction: column; gap: 6px; }
.message.user .message-content-wrapper { align-items: flex-end; }
.message.assistant .message-content-wrapper { align-items: flex-start; }
.btn-analyze { align-self: flex-start; padding: 4px 12px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 6px; color: var(--text-secondary); font-size: 0.75rem; cursor: pointer; transition: all 0.2s; }
.btn-analyze:hover { color: var(--accent); border-color: var(--accent); }
.btn-analyze:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-analyze.analyzed { color: #10b981; border-color: #10b981; cursor: default; }

.typing-indicator { display: flex; gap: 4px; padding: 8px 0; }
.typing-dot { width: 6px; height: 6px; background: var(--text-secondary); border-radius: 50%; animation: typing 1.4s infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

/* Input Area */
.input-area { padding: 16px 20px 12px; border-top: 1px solid var(--border); background: var(--bg-primary); }
.input-wrapper { display: flex; align-items: flex-end; gap: 8px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 16px; padding: 8px 8px 8px 16px; transition: border-color 0.2s; }
.input-wrapper:focus-within { border-color: var(--accent); }
#messageInput { flex: 1; border: none; background: none; color: var(--text-primary); font-size: 0.9rem; resize: none; outline: none; max-height: 200px; line-height: 1.5; font-family: inherit; }
.btn-send { width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--accent); color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.2s; flex-shrink: 0; }
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
.input-hint { text-align: center; font-size: 0.75rem; color: var(--text-secondary); margin-top: 6px; }

/* Mobile */
@media (max-width: 768px) {
    .sidebar { position: fixed; z-index: 100; height: 100%; transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: flex; }
    .message-content-wrapper { max-width: 85%; }
}

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center; z-index: 200; }
.modal-overlay.open { display: flex; }
.modal { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 16px; width: 90%; max-width: 480px; padding: 24px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h3 { font-size: 1rem; }
.modal-desc { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 16px; }
.modal .form-group textarea { width: 100%; padding: 10px 14px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 8px; color: var(--text-primary); font-size: 0.9rem; resize: vertical; outline: none; font-family: inherit; line-height: 1.5; }
.modal .form-group textarea:focus { border-color: var(--accent); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-primary { width: auto; padding: 8px 20px; }

/* MySkills modal */
.skills-input-row { display: flex; gap: 8px; margin-bottom: 12px; }
.skills-input-row input { flex: 1; padding: 10px 14px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 8px; color: var(--text-primary); font-size: 0.9rem; outline: none; }
.skills-input-row input:focus { border-color: var(--accent); }
.btn-add-skill { width: auto; padding: 8px 16px; font-size: 0.85rem; }
.my-skills-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 200px; overflow-y: auto; }
.my-skill-item { display: flex; align-items: center; gap: 6px; padding: 5px 10px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 8px; font-size: 0.8rem; }
.my-skill-item span { color: var(--text-primary); }
.my-skill-item .btn-icon-sm { opacity: 0.5; }
.my-skill-item:hover .btn-icon-sm { opacity: 1; }

/* Modal tabs */
.modal-wide { max-width: 560px; }
.modal-tabs { display: flex; border-bottom: 1px solid var(--border); }
.modal-tab { flex: 1; padding: 10px; background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-secondary); font-size: 0.85rem; cursor: pointer; transition: all 0.2s; }
.modal-tab:hover { color: var(--text-primary); }
.modal-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Approaches */
.approach-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.approach-form input, .approach-form textarea { width: 100%; padding: 10px 14px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 8px; color: var(--text-primary); font-size: 0.9rem; outline: none; font-family: inherit; resize: vertical; }
.approach-form input:focus, .approach-form textarea:focus { border-color: var(--accent); }
.btn-add-approach { align-self: flex-end; width: auto; padding: 8px 16px; font-size: 0.85rem; }
.my-approaches-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; }
.approach-item { padding: 10px 14px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 8px; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.approach-item-info { flex: 1; }
.approach-item-title { font-size: 0.85rem; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.approach-item-desc { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.4; }
.approach-item .btn-icon-sm { flex-shrink: 0; opacity: 0.5; margin-top: 2px; }
.approach-item:hover .btn-icon-sm { opacity: 1; }

/* Rules section */
.sidebar-section { border-top: 1px solid var(--border); }
.sidebar-section-toggle { display: flex; align-items: center; gap: 8px; width: 100%; padding: 12px 16px; background: none; border: none; color: var(--text-secondary); font-size: 0.85rem; cursor: pointer; transition: color 0.15s; }
.sidebar-section-toggle:hover { color: var(--text-primary); }
.rules-count { background: var(--accent); color: white; font-size: 0.7rem; padding: 1px 6px; border-radius: 10px; margin-left: auto; }
.rules-list { max-height: 0; overflow: hidden; transition: max-height 0.3s; }
.rules-list.open { max-height: 300px; overflow-y: auto; }
.rule-item { display: flex; align-items: flex-start; gap: 8px; padding: 8px 16px; font-size: 0.8rem; color: var(--text-secondary); }
.rule-item .rule-text { flex: 1; line-height: 1.4; }
.rule-item .btn-icon-sm { flex-shrink: 0; margin-top: 2px; opacity: 0.5; }
.rule-item:hover .btn-icon-sm { opacity: 1; }

/* Toast */
.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px); background: #16a34a; color: white; padding: 10px 20px; border-radius: 10px; font-size: 0.85rem; opacity: 0; transition: all 0.3s; z-index: 300; pointer-events: none; box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-error { background: #ef4444; }

/* Analytics */
.analytics-content { padding: 24px; overflow-y: auto; flex: 1; }
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px; padding: 20px; text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.chart-card h3 { font-size: 0.95rem; margin-bottom: 16px; }
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 140px; font-size: 0.8rem; color: var(--text-secondary); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 24px; background: var(--bg-tertiary); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; transition: width 0.5s ease; min-width: 4px; }
.bar-fill-alt { background: #10b981; }
.bar-value { width: 30px; font-size: 0.8rem; color: var(--text-primary); font-weight: 600; }
.empty-chart { display: none; color: var(--text-secondary); font-size: 0.85rem; text-align: center; padding: 20px; }
.table-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.table-card h3 { font-size: 0.95rem; margin-bottom: 16px; }
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.75rem; color: var(--text-secondary); padding: 8px 12px; border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: 0.5px; }
td { padding: 10px 12px; font-size: 0.85rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { background: var(--bg-tertiary); color: var(--accent); padding: 2px 8px; border-radius: 6px; font-size: 0.75rem; white-space: nowrap; }
.tag-alt { color: #10b981; }
.preview-text { color: var(--text-secondary); font-size: 0.8rem; max-width: 250px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

@media (max-width: 768px) {
    .stats-row { grid-template-columns: 1fr; }
    .charts-row { grid-template-columns: 1fr; }
    .analytics-content { padding: 16px; }
}
