/* FYP Brain v2 — Modern Dark Theme */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-card: #242736;
  --bg-input: #2a2d3a;
  --border: #333652;
  --text-primary: #e4e6f0;
  --text-secondary: #8b8fa3;
  --text-muted: #5c6072;
  --accent: #6c5ce7;
  --accent-hover: #7d6ff0;
  --accent-soft: rgba(108,92,231,0.15);
  --green: #48bb78;
  --red: #f5576c;
  --orange: #f6a945;
  --blue: #63b3ed;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.25);
  --transition: all 0.2s ease;
}

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

#app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
#sidebar { width: 320px; min-width: 320px; background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; transition: var(--transition); }
#sidebar.collapsed { width: 0; min-width: 0; overflow: hidden; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.sidebar-header h1 { font-size: 18px; font-weight: 700; }
.sidebar-header .version { font-size: 11px; color: var(--accent); font-weight: 600; background: var(--accent-soft); padding: 2px 8px; border-radius: 12px; }
#sidebar-toggle { background: none; border: 1px solid var(--border); color: var(--text-primary); font-size: 20px; cursor: pointer; width: 32px; height: 32px; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
#sidebar-toggle:hover { background: var(--bg-card); }

#sidebar-nav { display: flex; padding: 8px 12px; gap: 4px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.nav-btn { background: none; border: none; color: var(--text-muted); padding: 6px 12px; border-radius: 6px; font-size: 13px; cursor: pointer; transition: var(--transition); }
.nav-btn:hover { color: var(--text-primary); background: var(--bg-card); }
.nav-btn.active { color: var(--accent); background: var(--accent-soft); }

#sidebar-content { flex: 1; overflow-y: auto; padding: 16px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-group small { display: block; font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-group input[type="text"],
.form-group input[type="file"],
.form-group select,
.form-group textarea { width: 100%; padding: 8px 12px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); font-size: 13px; outline: none; transition: var(--transition); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); }
.form-group textarea { resize: vertical; min-height: 60px; font-family: inherit; }

.btn { padding: 8px 16px; border: none; border-radius: 6px; font-size: 13px; cursor: pointer; transition: var(--transition); font-weight: 500; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-accent { background: var(--green); color: #fff; }
.btn-accent:hover { filter: brightness(1.1); }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-card); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.status-box { margin-top: 10px; padding: 10px; background: var(--bg-card); border-radius: 6px; font-size: 12px; color: var(--text-secondary); max-height: 100px; overflow-y: auto; }
.status-box.success { border-left: 3px solid var(--green); }
.status-box.error { border-left: 3px solid var(--red); }
.status-box.loading { border-left: 3px solid var(--orange); }

/* Main Chat */
#chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.welcome-message { text-align: center; padding: 40px 20px; color: var(--text-secondary); }
.welcome-message h2 { font-size: 24px; margin-bottom: 8px; color: var(--text-primary); }
.welcome-message p { margin-bottom: 12px; }

.mode-cards { display: flex; gap: 12px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.mode-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: var(--transition); text-align: center; width: 140px; }
.mode-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.mode-card .mode-icon { font-size: 28px; display: block; margin-bottom: 6px; }
.mode-card strong { font-size: 13px; display: block; margin-bottom: 4px; }
.mode-card small { font-size: 11px; color: var(--text-muted); display: block; }

/* Messages */
.message { display: flex; gap: 10px; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.message.user { justify-content: flex-end; }
.message .avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.message.assistant .avatar { background: var(--accent-soft); color: var(--accent); }
.message.user .avatar { background: rgba(72,187,120,0.15); color: var(--green); }
.message .bubble { max-width: 75%; padding: 12px 16px; border-radius: var(--radius); font-size: 14px; line-height: 1.6; }
.message.assistant .bubble { background: var(--bg-card); border: 1px solid var(--border); }
.message.user .bubble { background: var(--accent-soft); border: 1px solid rgba(108,92,231,0.3); }
.message .bubble pre { background: var(--bg-primary); border: 1px solid var(--border); border-radius: 6px; padding: 12px; overflow-x: auto; font-size: 13px; line-height: 1.5; margin: 8px 0; }
.message .bubble code { font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace; font-size: 13px; }
.message .bubble p { margin-bottom: 8px; }
.message .bubble p:last-child { margin-bottom: 0; }
.message .bubble ul, .message .bubble ol { margin: 8px 0; padding-left: 20px; }
.message .bubble li { margin-bottom: 4px; }
.message .bubble h1, .message .bubble h2, .message .bubble h3 { margin: 12px 0 6px; font-size: 16px; }
.message .bubble h4 { margin: 8px 0 4px; font-size: 14px; }
.message .bubble blockquote { border-left: 3px solid var(--accent); padding-left: 12px; margin: 8px 0; color: var(--text-secondary); }
.message .bubble table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.message .bubble table th, .message .bubble table td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.message .bubble table th { background: var(--bg-primary); }

.message-meta { display: flex; gap: 8px; font-size: 11px; color: var(--text-muted); margin-top: 6px; flex-wrap: wrap; }
.message-actions { display: flex; gap: 6px; margin-top: 8px; }
.message-actions button { background: none; border: 1px solid var(--border); color: var(--text-muted); padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 11px; transition: var(--transition); }
.message-actions button:hover { color: var(--text-primary); border-color: var(--accent); }

.btn-restore {
  background: none;
  border: 1px solid var(--orange);
  color: var(--orange);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  transition: var(--transition);
}
.btn-restore:hover { background: rgba(246,169,69,0.12); color: #f8c16a; }

.edit-preview { background: var(--bg-primary); border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin-top: 8px; font-family: monospace; font-size: 12px; }
.edit-preview .diff-remove { color: var(--red); }
.edit-preview .diff-add { color: var(--green); }
.edit-actions { margin-top: 8px; display: flex; gap: 8px; }

/* Typing indicator */
#typing-indicator { padding: 8px 20px; color: var(--accent); font-size: 13px; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity: 0.6; } 50% { opacity: 1; } }

/* Chat input */
#chat-input-area { border-top: 1px solid var(--border); padding: 12px 20px; background: var(--bg-secondary); }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
#mic-btn { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-primary); width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; transition: var(--transition); flex-shrink: 0; }
#mic-btn:hover { border-color: var(--accent); }
#mic-btn.recording { border-color: var(--red); background: rgba(245,87,108,0.15); animation: pulse 1s infinite; }
#chat-input { flex: 1; background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; color: var(--text-primary); font-size: 14px; outline: none; resize: none; font-family: inherit; max-height: 120px; }
#chat-input:focus { border-color: var(--accent); }
#send-btn { background: var(--accent); border: none; color: #fff; width: 40px; height: 40px; border-radius: 8px; cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; transition: var(--transition); flex-shrink: 0; }
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.5; }
#mode-indicator { font-size: 11px; color: var(--text-muted); margin-top: 6px; text-align: center; }

/* Bank list */
.bank-list { margin-bottom: 12px; max-height: 300px; overflow-y: auto; }
.bank-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin-bottom: 8px; font-size: 12px; }
.bank-item .bank-q { font-weight: 600; margin-bottom: 4px; }
.bank-item .bank-a { color: var(--text-secondary); margin-bottom: 4px; }
.bank-item .bank-meta { font-size: 11px; color: var(--text-muted); display: flex; gap: 8px; }
.bank-item .bank-actions { margin-top: 4px; }
.bank-item .bank-actions button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 11px; padding: 2px 6px; }
.bank-item .bank-actions button:hover { color: var(--accent); }

/* 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); }

/* ── Beautiful Notes — Callout Boxes ── */
.callout {
  border-left: 4px solid;
  padding: 12px 16px;
  margin: 14px 0;
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  line-height: 1.6;
  position: relative;
}
.callout strong { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 700; }
.callout-tip     { border-color: var(--green);  background: rgba(72,187,120,0.07); }
.callout-tip strong     { color: var(--green); }
.callout-warning { border-color: var(--orange); background: rgba(246,169,69,0.07); }
.callout-warning strong { color: var(--orange); }
.callout-note    { border-color: var(--blue);   background: rgba(99,179,237,0.07); }
.callout-note strong    { color: var(--blue); }
.callout-key     { border-color: var(--accent); background: var(--accent-soft); }
.callout-key strong     { color: var(--accent); }
.callout-danger  { border-color: var(--red);    background: rgba(245,87,108,0.07); }
.callout-danger strong  { color: var(--red); }

/* ── Beautiful Notes — Study Content Styling ── */
.key-term {
  color: var(--accent);
  font-weight: 600;
  border-bottom: 1px dashed rgba(108,92,231,0.3);
  cursor: help;
}
.definition {
  border: 1px dashed var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  margin: 10px 0;
  background: var(--bg-primary);
  font-size: 13px;
}
.definition strong { color: var(--accent); }
.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
  opacity: 0.6;
}
.big-picture {
  background: linear-gradient(135deg, rgba(108,92,231,0.08), rgba(72,187,120,0.05));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin: 20px 0;
  position: relative;
}
.big-picture::before {
  content: 'The Big Picture';
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 600;
}

/* ── Beautiful Notes — Key Takeaways ── */
.key-takeaways {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin: 18px 0;
}
.key-takeaways::before {
  content: 'Key Takeaways';
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--green);
  margin-bottom: 10px;
  font-weight: 600;
}
.key-takeaways ul { margin: 0; padding-left: 18px; }
.key-takeaways li { margin-bottom: 6px; font-size: 13px; }
.key-takeaways li:last-child { margin-bottom: 0; }

/* ── Beautiful Notes — Code Walkthrough ── */
.code-walkthrough {
  margin: 16px 0;
}
.code-walkthrough pre {
  border-radius: 8px 8px 0 0 !important;
  margin: 0 !important;
}
.code-walkthrough .walkthrough-lines {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 12px 16px;
}
.walkthrough-line {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(51,54,82,0.4);
  font-size: 12px;
  align-items: baseline;
}
.walkthrough-line:last-child { border-bottom: none; }
.walkthrough-line .line-num {
  color: var(--text-muted);
  font-family: monospace;
  flex-shrink: 0;
  min-width: 28px;
}
.walkthrough-line .line-explanation { color: var(--text-secondary); }

/* ── Beautiful Notes — Heading Styles ── */
.message .bubble h1 {
  font-size: 20px;
  font-weight: 700;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
  margin: 20px 0 10px !important;
}
.message .bubble h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 22px 0 8px !important;
  color: var(--text-primary);
}
.message .bubble h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 16px 0 6px !important;
  color: var(--text-secondary);
}
.message .bubble h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 4px !important;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Beautiful Notes — Horizontal Rules ── */
.message .bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
  opacity: 0.5;
}

/* ── Beautiful Notes — Blockquote Enhancements ── */
.message .bubble blockquote {
  border-left: 3px solid var(--accent);
  background: rgba(108,92,231,0.05);
  padding: 10px 14px;
  margin: 12px 0;
  border-radius: 0 6px 6px 0;
  font-style: italic;
}

/* ── Beautiful Notes — Table Zebra Striping ── */
.message .bubble table {
  border-radius: 8px;
  overflow: hidden;
}
.message .bubble table tr:nth-child(even) td {
  background: rgba(255,255,255,0.02);
}
.message .bubble table tr:hover td {
  background: rgba(108,92,231,0.05);
}

/* ── Beautiful Notes — Strong emphasis ── */
.message .bubble strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ── Study Mode — Overview badge ── */
.overview-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Mobile */
@media (max-width: 768px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; }
  #sidebar.collapsed { transform: translateX(-100%); min-width: 320px; width: 320px; }
  .message .bubble { max-width: 90%; }
}

/* Toast notification */
.toast {
  position: fixed; top: 16px; right: 16px;
  padding: 10px 18px; border-radius: 8px; font-size: 13px;
  color: #fff; z-index: 999; animation: toastIn 0.3s ease;
  max-width: 320px; box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes toastIn { from { opacity:0; transform:translateX(40px); } to { opacity:1; transform:translateX(0); } }

/* Apply button states */
.btn-apply { padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 11px; transition: var(--transition); }
.btn-apply.enabled { background: var(--green); color: #fff; border: none; }
.btn-apply.enabled:hover { filter: brightness(1.15); }
.btn-apply.disabled { background: var(--bg-input); color: var(--text-muted); border: 1px solid var(--border); cursor: not-allowed; }

/* ── Batch Edit Modal ── */
.batch-edit-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.batch-edit-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 90%; max-width: 680px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}
.batch-edit-header {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.batch-edit-header h3 { font-size: 16px; margin: 0; }
.batch-edit-count { font-size: 12px; color: var(--text-muted); margin-left: 12px; }
.batch-edit-close {
  background: none; border: none; color: var(--text-muted); font-size: 22px;
  cursor: pointer; padding: 0 4px; line-height: 1;
}
.batch-edit-close:hover { color: var(--red); }
.batch-edit-select-all {
  padding: 10px 22px; border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.batch-edit-select-all label { cursor: pointer; display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.batch-edit-list {
  flex: 1; overflow-y: auto; padding: 8px 16px;
  max-height: 320px;
}
.batch-edit-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  transition: var(--transition);
}
.batch-edit-item:hover { border-color: var(--accent); }
.batch-edit-item:has(input:checked) { border-color: var(--green); background: rgba(72,187,120,0.04); }
.batch-edit-check {
  display: flex; gap: 10px; padding: 10px 14px;
  cursor: pointer; font-size: 12px; align-items: flex-start;
}
.batch-edit-check input[type="checkbox"] { margin-top: 2px; flex-shrink: 0; accent-color: var(--green); }
.batch-edit-info { flex: 1; min-width: 0; }
.batch-edit-file { margin-bottom: 4px; font-size: 12px; }
.batch-edit-file strong { color: var(--text-primary); }
.batch-edit-confidence { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.batch-edit-context {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 11px;
  margin: 0;
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 80px;
  color: var(--text-secondary);
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}
.batch-edit-old { color: var(--red); font-weight: 500; }
.batch-edit-new { color: var(--green); font-weight: 500; }
.batch-edit-preview {
  padding: 12px 22px; border-top: 1px solid var(--border);
  font-size: 12px;
}
.batch-edit-preview strong { display: block; margin-bottom: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.batch-edit-preview pre {
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px; font-size: 12px;
  color: var(--green); margin: 0; white-space: pre-wrap; overflow-x: auto;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}
.batch-edit-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 22px; border-top: 1px solid var(--border);
}
.batch-edit-result {
  padding: 10px 22px; font-size: 12px;
  border-top: 1px solid var(--border);
}
.batch-edit-success { color: var(--green); }
.batch-edit-error { color: var(--red); background: rgba(245,87,108,0.05); }
.batch-edit-error small { display: block; margin-top: 4px; }
