:root {
  --bg: #0a0a0a;
  --card: #1a1a1a;
  --card-hover: #222;
  --border: #333;
  --text: #fff;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #a855f7;
  --accent-hover: #9333ea;
  --success: #22c55e;
  --warning: #eab308;
  --error: #ef4444;
  --note: #6366f1;
  --task: #22c55e;
  --event: #f59e0b;
  --transaction: #ec4899;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* Loading */
#loading { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Auth Gate */
#auth-gate { display: none; min-height: 100vh; align-items: center; justify-content: center; padding: 2rem; }
.login-card { background: var(--card); border: 1px solid var(--border); border-radius: 1rem; padding: 3rem; text-align: center; max-width: 400px; width: 100%; }
.login-logo { font-size: 4rem; margin-bottom: 1rem; }
.login-title { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.5rem; background: linear-gradient(135deg, #fff, #a855f7, #6366f1); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.login-subtitle { color: var(--text-secondary); margin-bottom: 2rem; }
.google-btn { display: flex; align-items: center; justify-content: center; gap: 0.75rem; width: 100%; padding: 0.875rem 1.5rem; background: #fff; color: #1f1f1f; border: none; border-radius: 0.5rem; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.google-btn:hover { background: #f3f4f6; transform: translateY(-2px); }
.google-btn svg { width: 20px; height: 20px; }
.login-note { margin-top: 1.5rem; font-size: 0.875rem; color: var(--text-muted); }

/* Main App */
#main-app { display: none; min-height: 100vh; }

/* Header */
.header { background: var(--card); border-bottom: 1px solid var(--border); padding: 1rem 2rem; position: sticky; top: 0; z-index: 100; }
.header-inner { max-width: 1600px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; }
.logo { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.25rem; text-decoration: none; color: var(--text); }
.logo-icon { font-size: 1.5rem; }
.user-section { display: flex; align-items: center; gap: 1rem; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 600; overflow: hidden; }
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.btn-signout { padding: 0.5rem 1rem; background: transparent; color: var(--text-secondary); border: 1px solid var(--border); border-radius: 0.5rem; font-size: 0.8rem; cursor: pointer; }
.btn-signout:hover { background: var(--card); color: var(--text); }

/* Universal Search */
.search-section { padding: 2rem; background: linear-gradient(180deg, var(--card) 0%, var(--bg) 100%); }
.search-container { max-width: 800px; margin: 0 auto; }
.search-box { position: relative; }
.search-input { width: 100%; padding: 1rem 1.5rem 1rem 3.5rem; background: var(--bg); border: 2px solid var(--border); border-radius: 1rem; font-size: 1.1rem; color: var(--text); transition: all 0.2s; }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.1); }
.search-input::placeholder { color: var(--text-muted); }
.search-icon { position: absolute; left: 1.25rem; top: 50%; transform: translateY(-50%); font-size: 1.25rem; color: var(--text-muted); }
.search-hint { text-align: center; margin-top: 0.75rem; font-size: 0.8rem; color: var(--text-muted); }

/* Search Results */
.search-results { margin-top: 1.5rem; display: none; }
.search-results.active { display: block; }
.result-group { margin-bottom: 1.5rem; }
.result-group-title { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.75rem; display: flex; align-items: center; gap: 0.5rem; }
.result-item { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 1rem; background: var(--card); border: 1px solid var(--border); border-radius: 0.5rem; margin-bottom: 0.5rem; cursor: pointer; transition: all 0.2s; }
.result-item:hover { background: var(--card-hover); border-color: var(--accent); }
.result-icon { font-size: 1.25rem; }
.result-content { flex: 1; }
.result-title { font-weight: 500; }
.result-title mark { background: var(--accent); color: #fff; padding: 0 2px; border-radius: 2px; }
.result-meta { font-size: 0.8rem; color: var(--text-muted); }

/* Daily Digest */
.digest-section { background: var(--card); border: 1px solid var(--border); border-radius: 1rem; padding: 1.5rem; margin-bottom: 2rem; }
.digest-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; }
.digest-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.digest-item { text-align: center; padding: 1rem; background: var(--bg); border-radius: 0.75rem; }
.digest-icon { font-size: 1.5rem; margin-bottom: 0.5rem; }
.digest-value { font-size: 1.5rem; font-weight: 700; }
.digest-label { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.25rem; }
.digest-detail { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.25rem; }
.digest-tasks { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.digest-tasks-title { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.5rem; }
.digest-task-item { font-size: 0.85rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.digest-task-item:last-child { border-bottom: none; }

/* Main Layout */
.main-content { max-width: 1600px; margin: 0 auto; padding: 0 2rem 2rem; display: grid; grid-template-columns: 1fr 360px; gap: 2rem; }

/* View Tabs */
.view-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.view-tab { padding: 0.5rem 1rem; background: var(--card); border: 1px solid var(--border); border-radius: 0.5rem; color: var(--text-secondary); font-size: 0.875rem; cursor: pointer; transition: all 0.2s; }
.view-tab:hover { background: var(--card-hover); color: var(--text); }
.view-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Knowledge Graph */
.graph-section { background: var(--card); border: 1px solid var(--border); border-radius: 1rem; overflow: hidden; }
.graph-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; }
.graph-header h2 { font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; }
.graph-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.graph-btn { padding: 0.4rem 0.75rem; background: var(--bg); border: 1px solid var(--border); border-radius: 0.375rem; color: var(--text-secondary); font-size: 0.75rem; cursor: pointer; transition: all 0.2s; }
.graph-btn:hover, .graph-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#graph-container { height: 500px; background: var(--bg); }
.graph-legend { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 1.5rem; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--text-secondary); }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; }
.legend-dot.note { background: var(--note); }
.legend-dot.task { background: var(--task); }
.legend-dot.event { background: var(--event); }
.legend-dot.transaction { background: var(--transaction); }

/* Timeline View */
#timeline-view { display: none; }
.timeline-container { background: var(--card); border: 1px solid var(--border); border-radius: 1rem; padding: 1.5rem; }
.timeline-day { margin-bottom: 1.5rem; }
.timeline-day:last-child { margin-bottom: 0; }
.timeline-date { font-size: 0.85rem; font-weight: 600; color: var(--accent); margin-bottom: 0.75rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.timeline-items { padding-left: 1rem; border-left: 2px solid var(--border); }
.timeline-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem; margin-left: -1rem; background: var(--bg); border-radius: 0.5rem; margin-bottom: 0.5rem; cursor: pointer; transition: all 0.2s; }
.timeline-item:hover { background: var(--card-hover); }
.timeline-item::before { content: ''; width: 8px; height: 8px; border-radius: 50%; margin-left: -0.5rem; }
.timeline-item.note::before { background: var(--note); }
.timeline-item.task::before { background: var(--task); }
.timeline-item.event::before { background: var(--event); }
.timeline-item.transaction::before { background: var(--transaction); }
.timeline-icon { font-size: 1rem; }
.timeline-title { flex: 1; font-size: 0.9rem; }
.timeline-amount { font-weight: 600; font-size: 0.85rem; }
.timeline-amount.income { color: var(--success); }
.timeline-amount.expense { color: var(--error); }

/* Sidebar */
.sidebar { display: flex; flex-direction: column; gap: 1.5rem; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 1rem; overflow: hidden; }
.card-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.card-header h3 { font-size: 0.95rem; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; }
.card-body { padding: 1rem 1.5rem; }

/* Node Details */
.node-type { display: inline-block; padding: 0.25rem 0.5rem; border-radius: 0.25rem; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; margin-bottom: 0.75rem; }
.node-type.note { background: rgba(99, 102, 241, 0.2); color: var(--note); }
.node-type.task { background: rgba(34, 197, 94, 0.2); color: var(--task); }
.node-type.event { background: rgba(245, 158, 11, 0.2); color: var(--event); }
.node-type.transaction { background: rgba(236, 72, 153, 0.2); color: var(--transaction); }
.node-title { font-size: 1rem; font-weight: 600; margin-bottom: 0.5rem; }
.node-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.node-content { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.75rem; line-height: 1.5; }
.node-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.tag { padding: 0.25rem 0.5rem; background: var(--bg); border-radius: 0.25rem; font-size: 0.7rem; color: var(--text-muted); }
.related-section { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.related-title { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.75rem; }
.related-item { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; cursor: pointer; font-size: 0.85rem; }
.related-item:hover { color: var(--accent); }
.connection-strength { font-size: 0.7rem; font-weight: 600; }
.connection-reasons { font-size: 0.7rem; color: var(--text-muted); padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); margin-bottom: 0.5rem; }

/* AI Insights / Weekly Insights */
.insight-item { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.insight-item:last-child { border-bottom: none; }
.insight-icon { display: inline-block; margin-right: 0.5rem; }
.insight-text { font-size: 0.9rem; color: var(--text-secondary); }
.insight-text strong { color: var(--text); }

/* Memory Editor */
.memory-category { margin-bottom: 1rem; }
.memory-category:last-of-type { margin-bottom: 0.75rem; }
.memory-category-title { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; color: var(--accent); margin-bottom: 0.5rem; }
.memory-item { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.memory-item:last-child { border-bottom: none; }
.memory-content { flex: 1; }
.memory-key { font-size: 0.8rem; color: var(--text-muted); display: block; }
.memory-value { font-size: 0.9rem; font-weight: 500; }
.memory-actions { display: flex; gap: 0.25rem; }
.memory-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.9rem; padding: 0.25rem 0.5rem; border-radius: 0.25rem; }
.memory-btn:hover { background: var(--bg); color: var(--text); }
.memory-btn.delete:hover { color: var(--error); }
.add-memory-btn { width: 100%; padding: 0.75rem; background: var(--bg); border: 1px dashed var(--border); border-radius: 0.5rem; color: var(--text-muted); font-size: 0.85rem; cursor: pointer; transition: all 0.2s; }
.add-memory-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Empty States */
.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); }
.empty-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.empty-text { font-size: 0.9rem; }

/* Footer */
.footer { padding: 2rem; text-align: center; color: var(--text-muted); font-size: 0.8rem; border-top: 1px solid var(--border); margin-top: 2rem; }

/* Quick Capture */
.quick-capture { margin-top: 1.5rem; background: var(--card); border: 1px solid var(--border); border-radius: 0.75rem; padding: 1rem; }
.capture-type-selector { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.capture-type { padding: 0.5rem 1rem; background: var(--bg); border: 1px solid var(--border); border-radius: 0.5rem; color: var(--text-secondary); font-size: 0.85rem; cursor: pointer; transition: all 0.2s; }
.capture-type:hover { background: var(--card-hover); color: var(--text); }
.capture-type.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.capture-input-row { display: flex; gap: 0.5rem; }
.capture-input { flex: 1; padding: 0.75rem 1rem; background: var(--bg); border: 1px solid var(--border); border-radius: 0.5rem; color: var(--text); font-size: 0.95rem; }
.capture-input:focus { outline: none; border-color: var(--accent); }
.capture-input::placeholder { color: var(--text-muted); }
.capture-btn { padding: 0.75rem 1.25rem; background: var(--accent); border: none; border-radius: 0.5rem; color: #fff; font-size: 1.25rem; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.capture-btn:hover { background: var(--accent-hover); }

/* Chat Widget */
.chat-widget { position: fixed; bottom: 1.5rem; right: 1.5rem; width: 380px; background: var(--card); border: 1px solid var(--border); border-radius: 1rem; box-shadow: 0 10px 40px rgba(0,0,0,0.4); z-index: 1000; overflow: hidden; }
.chat-header { display: flex; align-items: center; gap: 0.5rem; padding: 1rem 1.25rem; background: linear-gradient(135deg, var(--accent), #6366f1); color: #fff; cursor: pointer; }
.chat-icon { font-size: 1.25rem; }
.chat-header span:nth-child(2) { flex: 1; font-weight: 600; }
.chat-status { font-size: 0.7rem; opacity: 0.8; }
.chat-toggle { font-size: 0.8rem; transition: transform 0.2s; }
.chat-toggle.collapsed { transform: rotate(180deg); }
.chat-body { max-height: 400px; display: flex; flex-direction: column; }
.chat-messages { flex: 1; padding: 1rem; overflow-y: auto; max-height: 300px; display: flex; flex-direction: column; gap: 0.75rem; }
.chat-message { padding: 0.75rem 1rem; border-radius: 0.75rem; font-size: 0.9rem; line-height: 1.5; max-width: 90%; }
.chat-message.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 0.25rem; }
.chat-message.assistant { background: var(--bg); color: var(--text); align-self: flex-start; border-bottom-left-radius: 0.25rem; }
.chat-message p { margin: 0; }
.chat-input-area { display: flex; gap: 0.5rem; padding: 0.75rem 1rem; border-top: 1px solid var(--border); background: var(--bg); }
.chat-input-area input { flex: 1; padding: 0.75rem 1rem; background: var(--card); border: 1px solid var(--border); border-radius: 0.5rem; color: var(--text); font-size: 0.9rem; }
.chat-input-area input:focus { outline: none; border-color: var(--accent); }
.chat-input-area input::placeholder { color: var(--text-muted); }
.chat-input-area button { padding: 0.75rem 1rem; background: var(--accent); border: none; border-radius: 0.5rem; color: #fff; font-size: 1rem; cursor: pointer; transition: all 0.2s; }
.chat-input-area button:hover { background: var(--accent-hover); }
.chat-input-area button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Source Badge */
.source-badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 0.25rem; font-size: 0.65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.025em; margin-left: 0.5rem; vertical-align: middle; }
.timeline-item .source-badge { margin-left: auto; flex-shrink: 0; }
.node-meta .source-badge { margin-left: 0; }

/* Responsive */
@media (max-width: 1024px) {
  .main-content { grid-template-columns: 1fr; }
  .sidebar { order: -1; }
  #graph-container { height: 400px; }
  .digest-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .header { padding: 1rem; }
  .search-section { padding: 1.5rem 1rem; }
  .main-content { padding: 0 1rem 1rem; }
  .graph-legend { flex-direction: column; gap: 0.5rem; }
  .digest-grid { grid-template-columns: 1fr 1fr; }
  .graph-controls { justify-content: center; }
  .chat-widget { width: calc(100% - 2rem); left: 1rem; right: 1rem; }
  .capture-type-selector { flex-wrap: wrap; }
}
