#
tokens: 48642/50000 2/625 files (page 30/35)
lines: off (toggle) GitHub
raw markdown copy
This is page 30 of 35. Use http://codebase.md/doobidoo/mcp-memory-service?page={x} to view the full context.

# Directory Structure

```
├── .claude
│   ├── agents
│   │   ├── amp-bridge.md
│   │   ├── amp-pr-automator.md
│   │   ├── code-quality-guard.md
│   │   ├── gemini-pr-automator.md
│   │   └── github-release-manager.md
│   ├── settings.local.json.backup
│   └── settings.local.json.local
├── .commit-message
├── .dockerignore
├── .env.example
├── .env.sqlite.backup
├── .envnn#
├── .gitattributes
├── .github
│   ├── FUNDING.yml
│   ├── ISSUE_TEMPLATE
│   │   ├── bug_report.yml
│   │   ├── config.yml
│   │   ├── feature_request.yml
│   │   └── performance_issue.yml
│   ├── pull_request_template.md
│   └── workflows
│       ├── bridge-tests.yml
│       ├── CACHE_FIX.md
│       ├── claude-code-review.yml
│       ├── claude.yml
│       ├── cleanup-images.yml.disabled
│       ├── dev-setup-validation.yml
│       ├── docker-publish.yml
│       ├── LATEST_FIXES.md
│       ├── main-optimized.yml.disabled
│       ├── main.yml
│       ├── publish-and-test.yml
│       ├── README_OPTIMIZATION.md
│       ├── release-tag.yml.disabled
│       ├── release.yml
│       ├── roadmap-review-reminder.yml
│       ├── SECRET_CONDITIONAL_FIX.md
│       └── WORKFLOW_FIXES.md
├── .gitignore
├── .mcp.json.backup
├── .mcp.json.template
├── .pyscn
│   ├── .gitignore
│   └── reports
│       └── analyze_20251123_214224.html
├── AGENTS.md
├── archive
│   ├── deployment
│   │   ├── deploy_fastmcp_fixed.sh
│   │   ├── deploy_http_with_mcp.sh
│   │   └── deploy_mcp_v4.sh
│   ├── deployment-configs
│   │   ├── empty_config.yml
│   │   └── smithery.yaml
│   ├── development
│   │   └── test_fastmcp.py
│   ├── docs-removed-2025-08-23
│   │   ├── authentication.md
│   │   ├── claude_integration.md
│   │   ├── claude-code-compatibility.md
│   │   ├── claude-code-integration.md
│   │   ├── claude-code-quickstart.md
│   │   ├── claude-desktop-setup.md
│   │   ├── complete-setup-guide.md
│   │   ├── database-synchronization.md
│   │   ├── development
│   │   │   ├── autonomous-memory-consolidation.md
│   │   │   ├── CLEANUP_PLAN.md
│   │   │   ├── CLEANUP_README.md
│   │   │   ├── CLEANUP_SUMMARY.md
│   │   │   ├── dream-inspired-memory-consolidation.md
│   │   │   ├── hybrid-slm-memory-consolidation.md
│   │   │   ├── mcp-milestone.md
│   │   │   ├── multi-client-architecture.md
│   │   │   ├── test-results.md
│   │   │   └── TIMESTAMP_FIX_SUMMARY.md
│   │   ├── distributed-sync.md
│   │   ├── invocation_guide.md
│   │   ├── macos-intel.md
│   │   ├── master-guide.md
│   │   ├── mcp-client-configuration.md
│   │   ├── multi-client-server.md
│   │   ├── service-installation.md
│   │   ├── sessions
│   │   │   └── MCP_ENHANCEMENT_SESSION_MEMORY_v4.1.0.md
│   │   ├── UBUNTU_SETUP.md
│   │   ├── ubuntu.md
│   │   ├── windows-setup.md
│   │   └── windows.md
│   ├── docs-root-cleanup-2025-08-23
│   │   ├── AWESOME_LIST_SUBMISSION.md
│   │   ├── CLOUDFLARE_IMPLEMENTATION.md
│   │   ├── DOCUMENTATION_ANALYSIS.md
│   │   ├── DOCUMENTATION_CLEANUP_PLAN.md
│   │   ├── DOCUMENTATION_CONSOLIDATION_COMPLETE.md
│   │   ├── LITESTREAM_SETUP_GUIDE.md
│   │   ├── lm_studio_system_prompt.md
│   │   ├── PYTORCH_DOWNLOAD_FIX.md
│   │   └── README-ORIGINAL-BACKUP.md
│   ├── investigations
│   │   └── MACOS_HOOKS_INVESTIGATION.md
│   ├── litestream-configs-v6.3.0
│   │   ├── install_service.sh
│   │   ├── litestream_master_config_fixed.yml
│   │   ├── litestream_master_config.yml
│   │   ├── litestream_replica_config_fixed.yml
│   │   ├── litestream_replica_config.yml
│   │   ├── litestream_replica_simple.yml
│   │   ├── litestream-http.service
│   │   ├── litestream.service
│   │   └── requirements-cloudflare.txt
│   ├── release-notes
│   │   └── release-notes-v7.1.4.md
│   └── setup-development
│       ├── README.md
│       ├── setup_consolidation_mdns.sh
│       ├── STARTUP_SETUP_GUIDE.md
│       └── test_service.sh
├── CHANGELOG-HISTORIC.md
├── CHANGELOG.md
├── claude_commands
│   ├── memory-context.md
│   ├── memory-health.md
│   ├── memory-ingest-dir.md
│   ├── memory-ingest.md
│   ├── memory-recall.md
│   ├── memory-search.md
│   ├── memory-store.md
│   ├── README.md
│   └── session-start.md
├── claude-hooks
│   ├── config.json
│   ├── config.template.json
│   ├── CONFIGURATION.md
│   ├── core
│   │   ├── memory-retrieval.js
│   │   ├── mid-conversation.js
│   │   ├── session-end.js
│   │   ├── session-start.js
│   │   └── topic-change.js
│   ├── debug-pattern-test.js
│   ├── install_claude_hooks_windows.ps1
│   ├── install_hooks.py
│   ├── memory-mode-controller.js
│   ├── MIGRATION.md
│   ├── README-NATURAL-TRIGGERS.md
│   ├── README-phase2.md
│   ├── README.md
│   ├── simple-test.js
│   ├── statusline.sh
│   ├── test-adaptive-weights.js
│   ├── test-dual-protocol-hook.js
│   ├── test-mcp-hook.js
│   ├── test-natural-triggers.js
│   ├── test-recency-scoring.js
│   ├── tests
│   │   ├── integration-test.js
│   │   ├── phase2-integration-test.js
│   │   ├── test-code-execution.js
│   │   ├── test-cross-session.json
│   │   ├── test-session-tracking.json
│   │   └── test-threading.json
│   ├── utilities
│   │   ├── adaptive-pattern-detector.js
│   │   ├── context-formatter.js
│   │   ├── context-shift-detector.js
│   │   ├── conversation-analyzer.js
│   │   ├── dynamic-context-updater.js
│   │   ├── git-analyzer.js
│   │   ├── mcp-client.js
│   │   ├── memory-client.js
│   │   ├── memory-scorer.js
│   │   ├── performance-manager.js
│   │   ├── project-detector.js
│   │   ├── session-tracker.js
│   │   ├── tiered-conversation-monitor.js
│   │   └── version-checker.js
│   └── WINDOWS-SESSIONSTART-BUG.md
├── CLAUDE.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Development-Sprint-November-2025.md
├── docs
│   ├── amp-cli-bridge.md
│   ├── api
│   │   ├── code-execution-interface.md
│   │   ├── memory-metadata-api.md
│   │   ├── PHASE1_IMPLEMENTATION_SUMMARY.md
│   │   ├── PHASE2_IMPLEMENTATION_SUMMARY.md
│   │   ├── PHASE2_REPORT.md
│   │   └── tag-standardization.md
│   ├── architecture
│   │   ├── search-enhancement-spec.md
│   │   └── search-examples.md
│   ├── architecture.md
│   ├── archive
│   │   └── obsolete-workflows
│   │       ├── load_memory_context.md
│   │       └── README.md
│   ├── assets
│   │   └── images
│   │       ├── dashboard-v3.3.0-preview.png
│   │       ├── memory-awareness-hooks-example.png
│   │       ├── project-infographic.svg
│   │       └── README.md
│   ├── CLAUDE_CODE_QUICK_REFERENCE.md
│   ├── cloudflare-setup.md
│   ├── deployment
│   │   ├── docker.md
│   │   ├── dual-service.md
│   │   ├── production-guide.md
│   │   └── systemd-service.md
│   ├── development
│   │   ├── ai-agent-instructions.md
│   │   ├── code-quality
│   │   │   ├── phase-2a-completion.md
│   │   │   ├── phase-2a-handle-get-prompt.md
│   │   │   ├── phase-2a-index.md
│   │   │   ├── phase-2a-install-package.md
│   │   │   └── phase-2b-session-summary.md
│   │   ├── code-quality-workflow.md
│   │   ├── dashboard-workflow.md
│   │   ├── issue-management.md
│   │   ├── pr-review-guide.md
│   │   ├── refactoring-notes.md
│   │   ├── release-checklist.md
│   │   └── todo-tracker.md
│   ├── docker-optimized-build.md
│   ├── document-ingestion.md
│   ├── DOCUMENTATION_AUDIT.md
│   ├── enhancement-roadmap-issue-14.md
│   ├── examples
│   │   ├── analysis-scripts.js
│   │   ├── maintenance-session-example.md
│   │   ├── memory-distribution-chart.jsx
│   │   └── tag-schema.json
│   ├── first-time-setup.md
│   ├── glama-deployment.md
│   ├── guides
│   │   ├── advanced-command-examples.md
│   │   ├── chromadb-migration.md
│   │   ├── commands-vs-mcp-server.md
│   │   ├── mcp-enhancements.md
│   │   ├── mdns-service-discovery.md
│   │   ├── memory-consolidation-guide.md
│   │   ├── migration.md
│   │   ├── scripts.md
│   │   └── STORAGE_BACKENDS.md
│   ├── HOOK_IMPROVEMENTS.md
│   ├── hooks
│   │   └── phase2-code-execution-migration.md
│   ├── http-server-management.md
│   ├── ide-compatability.md
│   ├── IMAGE_RETENTION_POLICY.md
│   ├── images
│   │   └── dashboard-placeholder.md
│   ├── implementation
│   │   ├── health_checks.md
│   │   └── performance.md
│   ├── IMPLEMENTATION_PLAN_HTTP_SSE.md
│   ├── integration
│   │   ├── homebrew.md
│   │   └── multi-client.md
│   ├── integrations
│   │   ├── gemini.md
│   │   ├── groq-bridge.md
│   │   ├── groq-integration-summary.md
│   │   └── groq-model-comparison.md
│   ├── integrations.md
│   ├── legacy
│   │   └── dual-protocol-hooks.md
│   ├── LM_STUDIO_COMPATIBILITY.md
│   ├── maintenance
│   │   └── memory-maintenance.md
│   ├── mastery
│   │   ├── api-reference.md
│   │   ├── architecture-overview.md
│   │   ├── configuration-guide.md
│   │   ├── local-setup-and-run.md
│   │   ├── testing-guide.md
│   │   └── troubleshooting.md
│   ├── migration
│   │   └── code-execution-api-quick-start.md
│   ├── natural-memory-triggers
│   │   ├── cli-reference.md
│   │   ├── installation-guide.md
│   │   └── performance-optimization.md
│   ├── oauth-setup.md
│   ├── pr-graphql-integration.md
│   ├── quick-setup-cloudflare-dual-environment.md
│   ├── README.md
│   ├── remote-configuration-wiki-section.md
│   ├── research
│   │   ├── code-execution-interface-implementation.md
│   │   └── code-execution-interface-summary.md
│   ├── ROADMAP.md
│   ├── sqlite-vec-backend.md
│   ├── statistics
│   │   ├── charts
│   │   │   ├── activity_patterns.png
│   │   │   ├── contributors.png
│   │   │   ├── growth_trajectory.png
│   │   │   ├── monthly_activity.png
│   │   │   └── october_sprint.png
│   │   ├── data
│   │   │   ├── activity_by_day.csv
│   │   │   ├── activity_by_hour.csv
│   │   │   ├── contributors.csv
│   │   │   └── monthly_activity.csv
│   │   ├── generate_charts.py
│   │   └── REPOSITORY_STATISTICS.md
│   ├── technical
│   │   ├── development.md
│   │   ├── memory-migration.md
│   │   ├── migration-log.md
│   │   ├── sqlite-vec-embedding-fixes.md
│   │   └── tag-storage.md
│   ├── testing
│   │   └── regression-tests.md
│   ├── testing-cloudflare-backend.md
│   ├── troubleshooting
│   │   ├── cloudflare-api-token-setup.md
│   │   ├── cloudflare-authentication.md
│   │   ├── general.md
│   │   ├── hooks-quick-reference.md
│   │   ├── pr162-schema-caching-issue.md
│   │   ├── session-end-hooks.md
│   │   └── sync-issues.md
│   └── tutorials
│       ├── advanced-techniques.md
│       ├── data-analysis.md
│       └── demo-session-walkthrough.md
├── examples
│   ├── claude_desktop_config_template.json
│   ├── claude_desktop_config_windows.json
│   ├── claude-desktop-http-config.json
│   ├── config
│   │   └── claude_desktop_config.json
│   ├── http-mcp-bridge.js
│   ├── memory_export_template.json
│   ├── README.md
│   ├── setup
│   │   └── setup_multi_client_complete.py
│   └── start_https_example.sh
├── install_service.py
├── install.py
├── LICENSE
├── NOTICE
├── pyproject.toml
├── pytest.ini
├── README.md
├── run_server.py
├── scripts
│   ├── .claude
│   │   └── settings.local.json
│   ├── archive
│   │   └── check_missing_timestamps.py
│   ├── backup
│   │   ├── backup_memories.py
│   │   ├── backup_sqlite_vec.sh
│   │   ├── export_distributable_memories.sh
│   │   └── restore_memories.py
│   ├── benchmarks
│   │   ├── benchmark_code_execution_api.py
│   │   ├── benchmark_hybrid_sync.py
│   │   └── benchmark_server_caching.py
│   ├── database
│   │   ├── analyze_sqlite_vec_db.py
│   │   ├── check_sqlite_vec_status.py
│   │   ├── db_health_check.py
│   │   └── simple_timestamp_check.py
│   ├── development
│   │   ├── debug_server_initialization.py
│   │   ├── find_orphaned_files.py
│   │   ├── fix_mdns.sh
│   │   ├── fix_sitecustomize.py
│   │   ├── remote_ingest.sh
│   │   ├── setup-git-merge-drivers.sh
│   │   ├── uv-lock-merge.sh
│   │   └── verify_hybrid_sync.py
│   ├── hooks
│   │   └── pre-commit
│   ├── installation
│   │   ├── install_linux_service.py
│   │   ├── install_macos_service.py
│   │   ├── install_uv.py
│   │   ├── install_windows_service.py
│   │   ├── install.py
│   │   ├── setup_backup_cron.sh
│   │   ├── setup_claude_mcp.sh
│   │   └── setup_cloudflare_resources.py
│   ├── linux
│   │   ├── service_status.sh
│   │   ├── start_service.sh
│   │   ├── stop_service.sh
│   │   ├── uninstall_service.sh
│   │   └── view_logs.sh
│   ├── maintenance
│   │   ├── assign_memory_types.py
│   │   ├── check_memory_types.py
│   │   ├── cleanup_corrupted_encoding.py
│   │   ├── cleanup_memories.py
│   │   ├── cleanup_organize.py
│   │   ├── consolidate_memory_types.py
│   │   ├── consolidation_mappings.json
│   │   ├── delete_orphaned_vectors_fixed.py
│   │   ├── fast_cleanup_duplicates_with_tracking.sh
│   │   ├── find_all_duplicates.py
│   │   ├── find_cloudflare_duplicates.py
│   │   ├── find_duplicates.py
│   │   ├── memory-types.md
│   │   ├── README.md
│   │   ├── recover_timestamps_from_cloudflare.py
│   │   ├── regenerate_embeddings.py
│   │   ├── repair_malformed_tags.py
│   │   ├── repair_memories.py
│   │   ├── repair_sqlite_vec_embeddings.py
│   │   ├── repair_zero_embeddings.py
│   │   ├── restore_from_json_export.py
│   │   └── scan_todos.sh
│   ├── migration
│   │   ├── cleanup_mcp_timestamps.py
│   │   ├── legacy
│   │   │   └── migrate_chroma_to_sqlite.py
│   │   ├── mcp-migration.py
│   │   ├── migrate_sqlite_vec_embeddings.py
│   │   ├── migrate_storage.py
│   │   ├── migrate_tags.py
│   │   ├── migrate_timestamps.py
│   │   ├── migrate_to_cloudflare.py
│   │   ├── migrate_to_sqlite_vec.py
│   │   ├── migrate_v5_enhanced.py
│   │   ├── TIMESTAMP_CLEANUP_README.md
│   │   └── verify_mcp_timestamps.py
│   ├── pr
│   │   ├── amp_collect_results.sh
│   │   ├── amp_detect_breaking_changes.sh
│   │   ├── amp_generate_tests.sh
│   │   ├── amp_pr_review.sh
│   │   ├── amp_quality_gate.sh
│   │   ├── amp_suggest_fixes.sh
│   │   ├── auto_review.sh
│   │   ├── detect_breaking_changes.sh
│   │   ├── generate_tests.sh
│   │   ├── lib
│   │   │   └── graphql_helpers.sh
│   │   ├── quality_gate.sh
│   │   ├── resolve_threads.sh
│   │   ├── run_pyscn_analysis.sh
│   │   ├── run_quality_checks.sh
│   │   ├── thread_status.sh
│   │   └── watch_reviews.sh
│   ├── quality
│   │   ├── fix_dead_code_install.sh
│   │   ├── phase1_dead_code_analysis.md
│   │   ├── phase2_complexity_analysis.md
│   │   ├── README_PHASE1.md
│   │   ├── README_PHASE2.md
│   │   ├── track_pyscn_metrics.sh
│   │   └── weekly_quality_review.sh
│   ├── README.md
│   ├── run
│   │   ├── run_mcp_memory.sh
│   │   ├── run-with-uv.sh
│   │   └── start_sqlite_vec.sh
│   ├── run_memory_server.py
│   ├── server
│   │   ├── check_http_server.py
│   │   ├── check_server_health.py
│   │   ├── memory_offline.py
│   │   ├── preload_models.py
│   │   ├── run_http_server.py
│   │   ├── run_memory_server.py
│   │   ├── start_http_server.bat
│   │   └── start_http_server.sh
│   ├── service
│   │   ├── deploy_dual_services.sh
│   │   ├── install_http_service.sh
│   │   ├── mcp-memory-http.service
│   │   ├── mcp-memory.service
│   │   ├── memory_service_manager.sh
│   │   ├── service_control.sh
│   │   ├── service_utils.py
│   │   └── update_service.sh
│   ├── sync
│   │   ├── check_drift.py
│   │   ├── claude_sync_commands.py
│   │   ├── export_memories.py
│   │   ├── import_memories.py
│   │   ├── litestream
│   │   │   ├── apply_local_changes.sh
│   │   │   ├── enhanced_memory_store.sh
│   │   │   ├── init_staging_db.sh
│   │   │   ├── io.litestream.replication.plist
│   │   │   ├── manual_sync.sh
│   │   │   ├── memory_sync.sh
│   │   │   ├── pull_remote_changes.sh
│   │   │   ├── push_to_remote.sh
│   │   │   ├── README.md
│   │   │   ├── resolve_conflicts.sh
│   │   │   ├── setup_local_litestream.sh
│   │   │   ├── setup_remote_litestream.sh
│   │   │   ├── staging_db_init.sql
│   │   │   ├── stash_local_changes.sh
│   │   │   ├── sync_from_remote_noconfig.sh
│   │   │   └── sync_from_remote.sh
│   │   ├── README.md
│   │   ├── safe_cloudflare_update.sh
│   │   ├── sync_memory_backends.py
│   │   └── sync_now.py
│   ├── testing
│   │   ├── run_complete_test.py
│   │   ├── run_memory_test.sh
│   │   ├── simple_test.py
│   │   ├── test_cleanup_logic.py
│   │   ├── test_cloudflare_backend.py
│   │   ├── test_docker_functionality.py
│   │   ├── test_installation.py
│   │   ├── test_mdns.py
│   │   ├── test_memory_api.py
│   │   ├── test_memory_simple.py
│   │   ├── test_migration.py
│   │   ├── test_search_api.py
│   │   ├── test_sqlite_vec_embeddings.py
│   │   ├── test_sse_events.py
│   │   ├── test-connection.py
│   │   └── test-hook.js
│   ├── utils
│   │   ├── claude_commands_utils.py
│   │   ├── generate_personalized_claude_md.sh
│   │   ├── groq
│   │   ├── groq_agent_bridge.py
│   │   ├── list-collections.py
│   │   ├── memory_wrapper_uv.py
│   │   ├── query_memories.py
│   │   ├── smithery_wrapper.py
│   │   ├── test_groq_bridge.sh
│   │   └── uv_wrapper.py
│   └── validation
│       ├── check_dev_setup.py
│       ├── check_documentation_links.py
│       ├── diagnose_backend_config.py
│       ├── validate_configuration_complete.py
│       ├── validate_memories.py
│       ├── validate_migration.py
│       ├── validate_timestamp_integrity.py
│       ├── verify_environment.py
│       ├── verify_pytorch_windows.py
│       └── verify_torch.py
├── SECURITY.md
├── selective_timestamp_recovery.py
├── SPONSORS.md
├── src
│   └── mcp_memory_service
│       ├── __init__.py
│       ├── api
│       │   ├── __init__.py
│       │   ├── client.py
│       │   ├── operations.py
│       │   ├── sync_wrapper.py
│       │   └── types.py
│       ├── backup
│       │   ├── __init__.py
│       │   └── scheduler.py
│       ├── cli
│       │   ├── __init__.py
│       │   ├── ingestion.py
│       │   ├── main.py
│       │   └── utils.py
│       ├── config.py
│       ├── consolidation
│       │   ├── __init__.py
│       │   ├── associations.py
│       │   ├── base.py
│       │   ├── clustering.py
│       │   ├── compression.py
│       │   ├── consolidator.py
│       │   ├── decay.py
│       │   ├── forgetting.py
│       │   ├── health.py
│       │   └── scheduler.py
│       ├── dependency_check.py
│       ├── discovery
│       │   ├── __init__.py
│       │   ├── client.py
│       │   └── mdns_service.py
│       ├── embeddings
│       │   ├── __init__.py
│       │   └── onnx_embeddings.py
│       ├── ingestion
│       │   ├── __init__.py
│       │   ├── base.py
│       │   ├── chunker.py
│       │   ├── csv_loader.py
│       │   ├── json_loader.py
│       │   ├── pdf_loader.py
│       │   ├── registry.py
│       │   ├── semtools_loader.py
│       │   └── text_loader.py
│       ├── lm_studio_compat.py
│       ├── mcp_server.py
│       ├── models
│       │   ├── __init__.py
│       │   └── memory.py
│       ├── server.py
│       ├── services
│       │   ├── __init__.py
│       │   └── memory_service.py
│       ├── storage
│       │   ├── __init__.py
│       │   ├── base.py
│       │   ├── cloudflare.py
│       │   ├── factory.py
│       │   ├── http_client.py
│       │   ├── hybrid.py
│       │   └── sqlite_vec.py
│       ├── sync
│       │   ├── __init__.py
│       │   ├── exporter.py
│       │   ├── importer.py
│       │   └── litestream_config.py
│       ├── utils
│       │   ├── __init__.py
│       │   ├── cache_manager.py
│       │   ├── content_splitter.py
│       │   ├── db_utils.py
│       │   ├── debug.py
│       │   ├── document_processing.py
│       │   ├── gpu_detection.py
│       │   ├── hashing.py
│       │   ├── http_server_manager.py
│       │   ├── port_detection.py
│       │   ├── system_detection.py
│       │   └── time_parser.py
│       └── web
│           ├── __init__.py
│           ├── api
│           │   ├── __init__.py
│           │   ├── analytics.py
│           │   ├── backup.py
│           │   ├── consolidation.py
│           │   ├── documents.py
│           │   ├── events.py
│           │   ├── health.py
│           │   ├── manage.py
│           │   ├── mcp.py
│           │   ├── memories.py
│           │   ├── search.py
│           │   └── sync.py
│           ├── app.py
│           ├── dependencies.py
│           ├── oauth
│           │   ├── __init__.py
│           │   ├── authorization.py
│           │   ├── discovery.py
│           │   ├── middleware.py
│           │   ├── models.py
│           │   ├── registration.py
│           │   └── storage.py
│           ├── sse.py
│           └── static
│               ├── app.js
│               ├── index.html
│               ├── README.md
│               ├── sse_test.html
│               └── style.css
├── start_http_debug.bat
├── start_http_server.sh
├── test_document.txt
├── test_version_checker.js
├── tests
│   ├── __init__.py
│   ├── api
│   │   ├── __init__.py
│   │   ├── test_compact_types.py
│   │   └── test_operations.py
│   ├── bridge
│   │   ├── mock_responses.js
│   │   ├── package-lock.json
│   │   ├── package.json
│   │   └── test_http_mcp_bridge.js
│   ├── conftest.py
│   ├── consolidation
│   │   ├── __init__.py
│   │   ├── conftest.py
│   │   ├── test_associations.py
│   │   ├── test_clustering.py
│   │   ├── test_compression.py
│   │   ├── test_consolidator.py
│   │   ├── test_decay.py
│   │   └── test_forgetting.py
│   ├── contracts
│   │   └── api-specification.yml
│   ├── integration
│   │   ├── package-lock.json
│   │   ├── package.json
│   │   ├── test_api_key_fallback.py
│   │   ├── test_api_memories_chronological.py
│   │   ├── test_api_tag_time_search.py
│   │   ├── test_api_with_memory_service.py
│   │   ├── test_bridge_integration.js
│   │   ├── test_cli_interfaces.py
│   │   ├── test_cloudflare_connection.py
│   │   ├── test_concurrent_clients.py
│   │   ├── test_data_serialization_consistency.py
│   │   ├── test_http_server_startup.py
│   │   ├── test_mcp_memory.py
│   │   ├── test_mdns_integration.py
│   │   ├── test_oauth_basic_auth.py
│   │   ├── test_oauth_flow.py
│   │   ├── test_server_handlers.py
│   │   └── test_store_memory.py
│   ├── performance
│   │   ├── test_background_sync.py
│   │   └── test_hybrid_live.py
│   ├── README.md
│   ├── smithery
│   │   └── test_smithery.py
│   ├── sqlite
│   │   └── simple_sqlite_vec_test.py
│   ├── test_client.py
│   ├── test_content_splitting.py
│   ├── test_database.py
│   ├── test_hybrid_cloudflare_limits.py
│   ├── test_hybrid_storage.py
│   ├── test_memory_ops.py
│   ├── test_semantic_search.py
│   ├── test_sqlite_vec_storage.py
│   ├── test_time_parser.py
│   ├── test_timestamp_preservation.py
│   ├── timestamp
│   │   ├── test_hook_vs_manual_storage.py
│   │   ├── test_issue99_final_validation.py
│   │   ├── test_search_retrieval_inconsistency.py
│   │   ├── test_timestamp_issue.py
│   │   └── test_timestamp_simple.py
│   └── unit
│       ├── conftest.py
│       ├── test_cloudflare_storage.py
│       ├── test_csv_loader.py
│       ├── test_fastapi_dependencies.py
│       ├── test_import.py
│       ├── test_json_loader.py
│       ├── test_mdns_simple.py
│       ├── test_mdns.py
│       ├── test_memory_service.py
│       ├── test_memory.py
│       ├── test_semtools_loader.py
│       ├── test_storage_interface_compatibility.py
│       └── test_tag_time_filtering.py
├── tools
│   ├── docker
│   │   ├── DEPRECATED.md
│   │   ├── docker-compose.http.yml
│   │   ├── docker-compose.pythonpath.yml
│   │   ├── docker-compose.standalone.yml
│   │   ├── docker-compose.uv.yml
│   │   ├── docker-compose.yml
│   │   ├── docker-entrypoint-persistent.sh
│   │   ├── docker-entrypoint-unified.sh
│   │   ├── docker-entrypoint.sh
│   │   ├── Dockerfile
│   │   ├── Dockerfile.glama
│   │   ├── Dockerfile.slim
│   │   ├── README.md
│   │   └── test-docker-modes.sh
│   └── README.md
└── uv.lock
```

# Files

--------------------------------------------------------------------------------
/scripts/installation/install.py:
--------------------------------------------------------------------------------

```python
#!/usr/bin/env python3
"""
Installation script for MCP Memory Service with cross-platform compatibility.
This script guides users through the installation process with the appropriate
dependencies for their platform.
"""
import os
import sys
import platform
import subprocess
import argparse
import shutil
from pathlib import Path
from typing import Tuple, Dict, Any, Optional
import re

# Import shared GPU detection utilities
try:
    from mcp_memory_service.utils.gpu_detection import detect_gpu as shared_detect_gpu
except ImportError:
    # Fallback for scripts directory context
    sys.path.insert(0, str(Path(__file__).parent.parent.parent))
    from src.mcp_memory_service.utils.gpu_detection import detect_gpu as shared_detect_gpu

def is_python_version_at_least(major, minor):
    """Check if current Python version is at least the specified version.

    Args:
        major: Major version number
        minor: Minor version number

    Returns:
        bool: True if current Python version >= specified version
    """
    return sys.version_info >= (major, minor)

def get_python_version_string():
    """Get Python version as a string (e.g., '3.12').

    Returns:
        str: Python version string
    """
    return f"{sys.version_info.major}.{sys.version_info.minor}"

def get_package_version():
    """Get the current package version from pyproject.toml.

    Returns:
        str: The version string from pyproject.toml or fallback version
    """
    fallback_version = "7.2.0"

    try:
        # Get path to pyproject.toml relative to this script
        pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml"

        if not pyproject_path.exists():
            print_warning(f"pyproject.toml not found at {pyproject_path}, using fallback version {fallback_version}")
            return fallback_version

        with open(pyproject_path, "r", encoding="utf-8") as f:
            content = f.read()

        # Extract version using regex - matches standard pyproject.toml format
        version_pattern = r'^version\s*=\s*["\']([^"\'\n]+)["\']'
        version_match = re.search(version_pattern, content, re.MULTILINE)

        if version_match:
            version = version_match.group(1).strip()
            if version:  # Ensure non-empty version
                return version
            else:
                print_warning("Empty version found in pyproject.toml, using fallback")
                return fallback_version
        else:
            print_warning("Version not found in pyproject.toml, using fallback")
            return fallback_version

    except (OSError, IOError) as e:
        print_warning(f"Failed to read pyproject.toml: {e}, using fallback version {fallback_version}")
        return fallback_version
    except Exception as e:
        print_warning(f"Unexpected error parsing version: {e}, using fallback version {fallback_version}")
        return fallback_version

def print_header(text):
    """Print a formatted header."""
    print("\n" + "=" * 80)
    print(f" {text}")
    print("=" * 80)

def print_step(step, text):
    """Print a formatted step."""
    print(f"\n[{step}] {text}")

def print_info(text):
    """Print formatted info text."""
    print(f"  → {text}")

def print_error(text):
    """Print formatted error text."""
    print(f"  ❌ ERROR: {text}")

def print_success(text):
    """Print formatted success text."""
    print(f"  ✅ {text}")

def print_warning(text):
    """Print formatted warning text."""
    print(f"  ⚠️  {text}")

def run_command_safe(cmd, success_msg=None, error_msg=None, silent=False,
                     timeout=None, fallback_in_venv=False):
    """
    Run a subprocess command with standardized error handling.

    Args:
        cmd: Command to run (list of strings)
        success_msg: Message to print on success
        error_msg: Custom error message
        silent: If True, suppress stdout/stderr
        timeout: Command timeout in seconds
        fallback_in_venv: If True and command fails, warn instead of error when in virtual environment

    Returns:
        tuple: (success: bool, result: subprocess.CompletedProcess or None)
    """
    # Validate command input
    if not cmd or not isinstance(cmd, (list, tuple)):
        print_error("Invalid command: must be a non-empty list or tuple")
        return False, None

    if not all(isinstance(arg, (str, int, float)) for arg in cmd if arg is not None):
        print_error("Invalid command arguments: all arguments must be strings, numbers, or None")
        return False, None

    # Filter out None values and convert to strings
    cmd_clean = [str(arg) for arg in cmd if arg is not None]
    if not cmd_clean:
        print_error("Command is empty after filtering")
        return False, None

    try:
        kwargs = {'capture_output': False, 'text': True}
        if silent:
            kwargs.update({'stdout': subprocess.DEVNULL, 'stderr': subprocess.DEVNULL})
        if timeout:
            kwargs['timeout'] = timeout

        result = subprocess.run(cmd_clean, check=True, **kwargs)
        if success_msg:
            print_success(success_msg)
        return True, result
    except subprocess.TimeoutExpired as e:
        if error_msg:
            timeout_msg = error_msg
        elif hasattr(e, 'timeout') and e.timeout:
            timeout_msg = f"Command timed out after {e.timeout}s"
        else:
            timeout_msg = "Command timed out"
        print_error(timeout_msg)
        return False, None
    except subprocess.CalledProcessError as e:
        if fallback_in_venv:
            in_venv = sys.prefix != sys.base_prefix
            if in_venv:
                fallback_msg = error_msg or "Command failed, but you're in a virtual environment. If you're using an alternative package manager, this may be normal."
                print_warning(fallback_msg)
                print_warning("Note: Installation may not have succeeded. Please verify manually if needed.")
                return True, None  # Proceed anyway in venv with warning

        if error_msg:
            print_error(error_msg)
        else:
            # Safe command formatting for error messages
            cmd_str = ' '.join(f'"{arg}"' if ' ' in str(arg) else str(arg) for arg in cmd_clean)
            print_error(f"Command failed (exit code {e.returncode}): {cmd_str}")
        return False, None
    except FileNotFoundError:
        if error_msg:
            print_error(error_msg)
        else:
            print_error(f"Command not found: {cmd_clean[0]}")
        return False, None
    except PermissionError:
        permission_msg = error_msg or f"Permission denied executing: {cmd_clean[0]}"
        print_error(permission_msg)
        return False, None

def install_package_safe(package, success_msg=None, error_msg=None, fallback_in_venv=True):
    """
    Install a Python package with standardized error handling.

    Args:
        package: Package name or requirement string
        success_msg: Message to print on success
        error_msg: Custom error message
        fallback_in_venv: If True, warn instead of error when in virtual environment

    Returns:
        bool: True if installation succeeded OR if fallback was applied (see warning messages)
    """
    cmd = [sys.executable, '-m', 'pip', 'install', package]
    default_success = success_msg or f"{package} installed successfully"
    default_error = error_msg or f"Failed to install {package}"

    if fallback_in_venv:
        default_error += ". If you're using an alternative package manager like uv, please install manually."

    success, _ = run_command_safe(
        cmd,
        success_msg=default_success,
        error_msg=default_error,
        silent=True,
        fallback_in_venv=fallback_in_venv
    )
    return success

def detect_system():
    """Detect the system architecture and platform."""
    system = platform.system().lower()
    machine = platform.machine().lower()
    python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
    
    is_windows = system == "windows"
    is_macos = system == "darwin"
    is_linux = system == "linux"
    is_arm = machine in ("arm64", "aarch64")
    is_x86 = machine in ("x86_64", "amd64", "x64")
    
    print_info(f"System: {platform.system()} {platform.release()}")
    print_info(f"Architecture: {machine}")
    print_info(f"Python: {python_version}")
    
    # Check for virtual environment
    in_venv = sys.prefix != sys.base_prefix
    if not in_venv:
        print_warning("Not running in a virtual environment. It's recommended to install in a virtual environment.")
    else:
        print_info(f"Virtual environment: {sys.prefix}")
    
    # Check for Homebrew PyTorch installation
    has_homebrew_pytorch = False
    homebrew_pytorch_version = None
    if is_macos:
        try:
            # Check if pytorch is installed via brew
            result = subprocess.run(
                ['brew', 'list', 'pytorch', '--version'],
                capture_output=True,
                text=True
            )
            if result.returncode == 0:
                has_homebrew_pytorch = True
                # Extract version from output
                version_line = result.stdout.strip()
                homebrew_pytorch_version = version_line.split()[1] if len(version_line.split()) > 1 else "Unknown"
                print_info(f"Detected Homebrew PyTorch installation: {homebrew_pytorch_version}")
        except (subprocess.SubprocessError, FileNotFoundError):
            pass
    
    return {
        "system": system,
        "machine": machine,
        "python_version": python_version,
        "is_windows": is_windows,
        "is_macos": is_macos,
        "is_linux": is_linux,
        "is_arm": is_arm,
        "is_x86": is_x86,
        "in_venv": in_venv,
        "has_homebrew_pytorch": has_homebrew_pytorch,
        "homebrew_pytorch_version": homebrew_pytorch_version
    }

def detect_gpu():
    """Detect GPU and acceleration capabilities.

    Wrapper function that uses the shared GPU detection module.
    """
    system_info = detect_system()

    # Use shared GPU detection module
    gpu_info = shared_detect_gpu(system_info)

    # Print GPU information (maintain installer output format)
    if gpu_info.get("has_cuda"):
        cuda_version = gpu_info.get("cuda_version")
        print_info(f"CUDA detected: {cuda_version or 'Unknown version'}")
    if gpu_info.get("has_rocm"):
        rocm_version = gpu_info.get("rocm_version")
        print_info(f"ROCm detected: {rocm_version or 'Unknown version'}")
    if gpu_info.get("has_mps"):
        print_info("Apple Metal Performance Shaders (MPS) detected")
    if gpu_info.get("has_directml"):
        directml_version = gpu_info.get("directml_version")
        if directml_version:
            print_info(f"DirectML detected: {directml_version}")
        else:
            print_info("DirectML detected")

    if not (gpu_info.get("has_cuda") or gpu_info.get("has_rocm") or
            gpu_info.get("has_mps") or gpu_info.get("has_directml")):
        print_info("No GPU acceleration detected, will use CPU-only mode")

    return gpu_info

def check_dependencies():
    """Check for required dependencies.
    
    Note on package managers:
    - Traditional virtual environments (venv, virtualenv) include pip by default
    - Alternative package managers like uv may not include pip or may manage packages differently
    - We attempt multiple detection methods for pip and only fail if:
      a) We're not in a virtual environment, or
      b) We can't detect pip AND can't install dependencies
    
    We proceed with installation even if pip isn't detected when in a virtual environment,
    assuming an alternative package manager (like uv) is handling dependencies.
    
    Returns:
        bool: True if all dependencies are met, False otherwise.
    """
    print_step("2", "Checking dependencies")
    
    # Check for pip
    pip_installed = False
    
    # Try subprocess check first
    success, _ = run_command_safe(
        [sys.executable, '-m', 'pip', '--version'],
        success_msg="pip is installed",
        silent=True,
        fallback_in_venv=True
    )

    if success:
        pip_installed = True
    else:
        # Fallback to import check
        try:
            import pip
            pip_installed = True
            print_info(f"pip is installed: {pip.__version__}")
        except ImportError:
            # Check if we're in a virtual environment
            in_venv = sys.prefix != sys.base_prefix
            if in_venv:
                print_warning("pip could not be detected, but you're in a virtual environment. "
                            "If you're using uv or another alternative package manager, this is normal. "
                            "Continuing installation...")
                pip_installed = True  # Proceed anyway
            else:
                print_error("pip is not installed. Please install pip first.")
                return False
    
    # Check for setuptools
    try:
        import setuptools
        print_info(f"setuptools is installed: {setuptools.__version__}")
    except ImportError:
        print_warning("setuptools is not installed. Will attempt to install it.")
        # If pip is available, use it to install setuptools
        if pip_installed:
            success = install_package_safe("setuptools")
            if not success:
                return False
        else:
            # Should be unreachable since pip_installed would only be False if we returned earlier
            print_error("Cannot install setuptools without pip. Please install setuptools manually.")
            return False
    
    # Check for wheel
    try:
        import wheel
        print_info(f"wheel is installed: {wheel.__version__}")
    except ImportError:
        print_warning("wheel is not installed. Will attempt to install it.")
        # If pip is available, use it to install wheel
        if pip_installed:
            success = install_package_safe("wheel")
            if not success:
                return False
        else:
            # Should be unreachable since pip_installed would only be False if we returned earlier
            print_error("Cannot install wheel without pip. Please install wheel manually.")
            return False
    
    return True

def install_pytorch_platform_specific(system_info, gpu_info):
    """Install PyTorch with platform-specific configurations."""
    if system_info["is_windows"]:
        return install_pytorch_windows(gpu_info)
    elif system_info["is_macos"] and system_info["is_x86"]:
        return install_pytorch_macos_intel()
    else:
        # For other platforms, let the regular installer handle it
        return True

def install_pytorch_macos_intel():
    """Install PyTorch specifically for macOS with Intel CPUs."""
    print_step("3a", "Installing PyTorch for macOS Intel CPU")
    
    # Use the versions known to work well on macOS Intel and with Python 3.13+
    try:
        # For Python 3.13+, we need newer PyTorch versions
        python_version = sys.version_info
        
        if python_version >= (3, 13):
            # For Python 3.13+, try to install latest compatible version
            print_info(f"Installing PyTorch for macOS Intel (Python {python_version.major}.{python_version.minor})...")
            print_info("Attempting to install latest PyTorch compatible with Python 3.13...")
            
            # Try to install without version specifiers to get latest compatible version
            cmd = [
                sys.executable, '-m', 'pip', 'install',
                "torch", "torchvision", "torchaudio"
            ]
            success, _ = run_command_safe(
                cmd,
                success_msg="Latest PyTorch installed successfully",
                silent=False
            )

            if success:
                st_version = "3.0.0"  # Newer sentence-transformers for newer PyTorch
            else:
                print_warning("Failed to install latest PyTorch, trying fallback version...")
                # Fallback to a specific version
                torch_version = "2.1.0"
                torch_vision_version = "0.16.0"
                torch_audio_version = "2.1.0"
                st_version = "3.0.0"

                print_info(f"Trying fallback to PyTorch {torch_version}...")

                cmd = [
                    sys.executable, '-m', 'pip', 'install',
                    f"torch=={torch_version}",
                    f"torchvision=={torch_vision_version}",
                    f"torchaudio=={torch_audio_version}"
                ]
                success, _ = run_command_safe(
                    cmd,
                    success_msg=f"PyTorch {torch_version} installed successfully",
                    error_msg="Failed to install PyTorch fallback version",
                    silent=False
                )
                if not success:
                    return False
        else:
            # Use traditional versions for older Python
            torch_version = "1.13.1"
            torch_vision_version = "0.14.1"
            torch_audio_version = "0.13.1"
            st_version = "2.2.2"
            
            print_info(f"Installing PyTorch {torch_version} for macOS Intel (Python {python_version.major}.{python_version.minor})...")
            
            # Install PyTorch first with compatible version
            packages = [f"torch=={torch_version}", f"torchvision=={torch_vision_version}", f"torchaudio=={torch_audio_version}"]
            success, _ = run_command_safe(
                [sys.executable, '-m', 'pip', 'install'] + packages,
                success_msg=f"PyTorch {torch_version} installed successfully"
            )
            if not success:
                raise RuntimeError(f"Failed to install PyTorch {torch_version}")
        
        # Install a compatible version of sentence-transformers
        print_info(f"Installing sentence-transformers {st_version}...")
        success, _ = run_command_safe(
            [sys.executable, '-m', 'pip', 'install', f"sentence-transformers=={st_version}"],
            success_msg=f"sentence-transformers {st_version} installed successfully"
        )
        if not success:
            raise RuntimeError(f"Failed to install sentence-transformers {st_version}")
        
        print_success(f"PyTorch {torch_version} and sentence-transformers {st_version} installed successfully for macOS Intel")
        return True
    except RuntimeError as e:
        print_error(f"Failed to install PyTorch for macOS Intel: {e}")
        
        # Provide fallback instructions
        if python_version >= (3, 13):
            print_warning("You may need to manually install compatible versions for Python 3.13+ on Intel macOS:")
            print_info("pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0")
            print_info("pip install sentence-transformers==3.0.0")
        else:
            print_warning("You may need to manually install compatible versions for Intel macOS:")
            print_info("pip install torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1")
            print_info("pip install sentence-transformers==2.2.2")
        
        return False

def install_pytorch_windows(gpu_info):
    """Install PyTorch on Windows using the appropriate index URL."""
    print_step("3a", "Installing PyTorch for Windows")
    
    # Determine the appropriate PyTorch index URL based on GPU
    if gpu_info["has_cuda"]:
        # Get CUDA version and determine appropriate index URL
        cuda_version = gpu_info.get("cuda_version", "")
        
        # Extract major version from CUDA version string
        cuda_major = None
        if cuda_version:
            # Try to extract the major version (e.g., "11.8" -> "11")
            try:
                cuda_major = cuda_version.split('.')[0]
            except (IndexError, AttributeError):
                pass
        
        # Default to cu118 if we couldn't determine the version or it's not a common one
        if cuda_major == "12":
            cuda_suffix = "cu121"  # CUDA 12.x
            print_info(f"Detected CUDA {cuda_version}, using cu121 channel")
        elif cuda_major == "11":
            cuda_suffix = "cu118"  # CUDA 11.x
            print_info(f"Detected CUDA {cuda_version}, using cu118 channel")
        elif cuda_major == "10":
            cuda_suffix = "cu102"  # CUDA 10.x
            print_info(f"Detected CUDA {cuda_version}, using cu102 channel")
        else:
            # Default to cu118 as a safe choice for newer NVIDIA GPUs
            cuda_suffix = "cu118"
            print_info(f"Using default cu118 channel for CUDA {cuda_version}")
            
        index_url = f"https://download.pytorch.org/whl/{cuda_suffix}"
    else:
        # CPU-only version
        index_url = "https://download.pytorch.org/whl/cpu"
        print_info("Using CPU-only PyTorch for Windows")
    
    # Install PyTorch with the appropriate index URL
    try:
        # Use a stable version that's known to have Windows wheels
        torch_version = "2.1.0"  # This version has Windows wheels available
        
        cmd = [
            sys.executable, '-m', 'pip', 'install',
            f"torch=={torch_version}",
            f"torchvision=={torch_version}",
            f"torchaudio=={torch_version}",
            f"--index-url={index_url}"
        ]
        
        success, _ = run_command_safe(
            cmd,
            success_msg="PyTorch installed successfully for Windows",
            error_msg="Failed to install PyTorch for Windows",
            silent=False
        )
        if not success:
            return False
        
        # Check if DirectML is needed
        if gpu_info["has_directml"]:
            success = install_package_safe(
                "torch-directml>=0.2.0",
                success_msg="torch-directml installed successfully for DirectML support",
                error_msg="Failed to install torch-directml"
            )
            if not success:
                print_warning("DirectML support may not be available")
            
        print_success("PyTorch installed successfully for Windows")
        return True
    except RuntimeError as e:
        print_error(f"Failed to install PyTorch for Windows: {e}")
        print_warning("You may need to manually install PyTorch using instructions from https://pytorch.org/get-started/locally/")
        return False

def detect_storage_backend_compatibility(system_info, gpu_info):
    """Detect which storage backends are compatible with the current environment."""
    print_step("3a", "Analyzing storage backend compatibility")
    
    compatibility = {
        "cloudflare": {"supported": True, "issues": [], "recommendation": "production"},
        "sqlite_vec": {"supported": True, "issues": [], "recommendation": "development"},
        "chromadb": {"supported": True, "issues": [], "recommendation": "team"},
        "hybrid": {"supported": True, "issues": [], "recommendation": "recommended"}
    }
    
    # Check ChromaDB compatibility issues
    chromadb_issues = []
    
    # macOS Intel compatibility issues
    if system_info["is_macos"] and system_info["is_x86"]:
        chromadb_issues.append("ChromaDB has known installation issues on older macOS Intel systems")
        chromadb_issues.append("May require specific dependency versions")
        compatibility["chromadb"]["recommendation"] = "problematic"
        compatibility["sqlite_vec"]["recommendation"] = "recommended"
    
    # Memory constraints
    total_memory_gb = 0
    try:
        import psutil
        total_memory_gb = psutil.virtual_memory().total / (1024**3)
    except ImportError:
        # Fallback memory detection
        try:
            with open('/proc/meminfo', 'r') as f:
                for line in f:
                    if line.startswith('MemTotal:'):
                        total_memory_gb = int(line.split()[1]) / (1024**2)
                        break
        except (FileNotFoundError, IOError):
            pass
    
    if total_memory_gb > 0 and total_memory_gb < 4:
        chromadb_issues.append(f"System has {total_memory_gb:.1f}GB RAM - ChromaDB may consume significant memory")
        compatibility["sqlite_vec"]["recommendation"] = "recommended"
    
    # Older Python versions
    python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
    if sys.version_info < (3, 9):
        chromadb_issues.append(f"Python {python_version} may have ChromaDB compatibility issues")
    
    # ARM architecture considerations
    if system_info["is_arm"]:
        print_info("ARM architecture detected - both backends should work well")
    
    compatibility["chromadb"]["issues"] = chromadb_issues
    
    # Print compatibility analysis
    print_info("Storage Backend Compatibility Analysis:")
    
    for backend, info in compatibility.items():
        status = "✅" if info["supported"] else "❌"
        rec_text = {
            "production": "☁️ PRODUCTION (Cloud)",
            "development": "🪶 DEVELOPMENT (Local)",
            "team": "👥 TEAM (Multi-client)",
            "recommended": "🌟 RECOMMENDED",
            "default": "📦 Standard",
            "problematic": "⚠️  May have issues",
            "lightweight": "🪶 Lightweight"
        }.get(info["recommendation"], "")
        
        print_info(f"  {status} {backend.upper()}: {rec_text}")
        
        if info["issues"]:
            for issue in info["issues"]:
                print_info(f"    • {issue}")
    
    return compatibility

def choose_storage_backend(system_info, gpu_info, args):
    """Choose storage backend based on environment and user preferences."""
    compatibility = detect_storage_backend_compatibility(system_info, gpu_info)
    
    # Check if user specified a backend via environment
    env_backend = os.environ.get('MCP_MEMORY_STORAGE_BACKEND')
    if env_backend:
        print_info(f"Using storage backend from environment: {env_backend}")
        return env_backend
    
    # Check for command line argument (we'll add this)
    if hasattr(args, 'storage_backend') and args.storage_backend:
        print_info(f"Using storage backend from command line: {args.storage_backend}")
        return args.storage_backend
    
    # Auto-select based on compatibility
    recommended_backend = None
    for backend, info in compatibility.items():
        if info["recommendation"] == "recommended":
            recommended_backend = backend
            break
    
    if not recommended_backend:
        recommended_backend = "sqlite_vec"  # Default fallback for local development

    # Interactive backend selection
    print_step("3b", "Storage Backend Selection")
    print_info("Choose the storage backend that best fits your use case:")
    print_info("")
    print_info("Usage scenarios:")
    print_info("  1. Production/Shared (Cloudflare) - Cloud storage, multi-user access, requires credentials")
    print_info("  2. Development/Personal (SQLite-vec) - Local, lightweight, single-user")
    print_info("  3. Team/Multi-client (ChromaDB) - Local server, multiple clients")
    print_info("  4. Hybrid (Recommended) - Fast local SQLite + background Cloudflare sync")
    print_info("  5. Auto-detect - Try optimal backend based on your system")
    print_info("")

    # Show compatibility analysis
    for i, (backend, info) in enumerate(compatibility.items(), 1):
        if backend == "auto_detect":
            continue
        status = "✅" if info["supported"] else "❌"
        rec_text = {
            "production": "☁️ PRODUCTION (Cloud)",
            "development": "🪶 DEVELOPMENT (Local)",
            "team": "👥 TEAM (Multi-client)",
            "recommended": "🌟 RECOMMENDED",
            "problematic": "⚠️  May have issues"
        }.get(info["recommendation"], "")
        print_info(f"  {status} {i}. {backend.upper()}: {rec_text}")
        if info["issues"]:
            for issue in info["issues"]:
                print_info(f"     • {issue}")

    print_info("")
    default_choice = "2" if compatibility["chromadb"]["recommendation"] == "problematic" else "2"

    while True:
        try:
            choice = input(f"Choose storage backend [1-5] (default: 4 - hybrid): ").strip()
            if not choice:
                choice = "4"  # Default to hybrid

            if choice == "1":
                return "cloudflare"
            elif choice == "2":
                return "sqlite_vec"
            elif choice == "3":
                return "chromadb"
            elif choice == "4":
                return "hybrid"
            elif choice == "5":
                return "auto_detect"
            else:
                print_error("Please enter 1, 2, 3, 4, or 5")
        except (EOFError, KeyboardInterrupt):
            print_info(f"\nUsing recommended backend: hybrid")
            return "hybrid"

def setup_cloudflare_credentials():
    """Interactive setup of Cloudflare credentials."""
    print_step("3c", "Cloudflare Backend Setup")
    print_info("Cloudflare backend requires API credentials for D1 database and Vectorize index.")
    print_info("You'll need:")
    print_info("  • Cloudflare API Token (with D1 and Vectorize permissions)")
    print_info("  • Account ID")
    print_info("  • D1 Database ID")
    print_info("  • Vectorize Index name")
    print_info("")
    print_info("Visit https://dash.cloudflare.com to get these credentials.")
    print_info("")

    credentials = {}

    try:
        # Get API Token
        while True:
            token = input("Enter Cloudflare API Token: ").strip()
            if token:
                credentials['CLOUDFLARE_API_TOKEN'] = token
                break
            print_error("API token is required")

        # Get Account ID
        while True:
            account_id = input("Enter Cloudflare Account ID: ").strip()
            if account_id:
                credentials['CLOUDFLARE_ACCOUNT_ID'] = account_id
                break
            print_error("Account ID is required")

        # Get D1 Database ID
        while True:
            d1_id = input("Enter D1 Database ID: ").strip()
            if d1_id:
                credentials['CLOUDFLARE_D1_DATABASE_ID'] = d1_id
                break
            print_error("D1 Database ID is required")

        # Get Vectorize Index
        vectorize_index = input("Enter Vectorize Index name (default: mcp-memory-index): ").strip()
        if not vectorize_index:
            vectorize_index = "mcp-memory-index"
        credentials['CLOUDFLARE_VECTORIZE_INDEX'] = vectorize_index

        # Set storage backend
        credentials['MCP_MEMORY_STORAGE_BACKEND'] = 'cloudflare'

        return credentials

    except (EOFError, KeyboardInterrupt):
        print_info("\nCloudflare setup cancelled.")
        return None

def save_credentials_to_env(credentials):
    """Save credentials to .env file and current environment."""
    env_file = Path('.env')

    # Read existing .env content if it exists
    existing_lines = []
    if env_file.exists():
        with open(env_file, 'r') as f:
            existing_lines = f.readlines()

    # Filter out any existing Cloudflare variables
    filtered_lines = [
        line for line in existing_lines
        if not any(key in line for key in credentials.keys())
    ]

    # Add new credentials
    with open(env_file, 'w') as f:
        # Write existing non-Cloudflare lines
        f.writelines(filtered_lines)

        # Add separator if file wasn't empty
        if filtered_lines and not filtered_lines[-1].endswith('\n'):
            f.write('\n')
        if filtered_lines:
            f.write('\n# Cloudflare Backend Configuration\n')

        # Write Cloudflare credentials
        for key, value in credentials.items():
            f.write(f'{key}={value}\n')

    # Also set credentials in current environment for immediate use
    for key, value in credentials.items():
        os.environ[key] = value

    print_success(f"Credentials saved to .env file and current environment")

def test_cloudflare_connection(credentials):
    """Test Cloudflare API connection."""
    print_info("Testing Cloudflare API connection...")

    try:
        import requests

        headers = {
            'Authorization': f"Bearer {credentials['CLOUDFLARE_API_TOKEN']}",
            'Content-Type': 'application/json'
        }

        # Test API token validity
        response = requests.get(
            "https://api.cloudflare.com/client/v4/user/tokens/verify",
            headers=headers,
            timeout=10
        )

        if response.status_code == 200:
            data = response.json()
            if data.get("success"):
                print_success("API token is valid")
                return True
            else:
                print_error(f"API token validation failed: {data.get('errors')}")
                return False
        else:
            print_error(f"API connection failed with status {response.status_code}")
            return False

    except ImportError:
        print_warning("Could not test connection (requests not installed)")
        print_info("Connection will be tested when the service starts")
        return True
    except Exception as e:
        print_warning(f"Could not test connection: {e}")
        print_info("Connection will be tested when the service starts")
        return True

def install_storage_backend(backend, system_info):
    """Install the chosen storage backend."""
    print_step("3c", f"Installing {backend} storage backend")

    if backend == "cloudflare":
        print_info("Cloudflare backend uses cloud services - no local dependencies needed")

        # Setup credentials interactively
        credentials = setup_cloudflare_credentials()
        if not credentials:
            print_warning("Cloudflare setup cancelled. Falling back to SQLite-vec.")
            return install_storage_backend("sqlite_vec", system_info)

        # Save credentials to .env file
        save_credentials_to_env(credentials)

        # Test connection
        connection_ok = test_cloudflare_connection(credentials)
        if connection_ok:
            print_success("Cloudflare backend configured successfully")
            return "cloudflare"
        else:
            print_warning("Cloudflare connection test failed. You can continue and fix credentials later.")
            fallback = input("Continue with Cloudflare anyway? [y/N]: ").strip().lower()
            if fallback.startswith('y'):
                return "cloudflare"
            else:
                print_info("Falling back to SQLite-vec for local development.")
                return install_storage_backend("sqlite_vec", system_info)

    elif backend == "sqlite_vec":
        return install_package_safe(
            "sqlite-vec",
            success_msg="SQLite-vec installed successfully",
            error_msg="Failed to install SQLite-vec"
        )

    elif backend == "hybrid":
        print_info("Hybrid backend combines fast local SQLite with background Cloudflare sync")

        # First install SQLite-vec for local storage
        print_info("Installing SQLite-vec for local storage...")
        sqlite_success = install_package_safe(
            "sqlite-vec",
            success_msg="SQLite-vec installed successfully",
            error_msg="Failed to install SQLite-vec"
        )
        if not sqlite_success:
            print_error("Hybrid backend requires SQLite-vec. Installation failed.")
            return False

        # Setup Cloudflare credentials for cloud sync
        print_info("Configuring Cloudflare for background synchronization...")
        credentials = setup_cloudflare_credentials()
        if not credentials:
            print_warning("Cloudflare setup cancelled.")
            fallback = input("Continue with SQLite-vec only? [Y/n]: ").strip().lower()
            if not fallback or fallback.startswith('y'):
                print_info("Falling back to SQLite-vec for local-only operation.")
                return "sqlite_vec"
            else:
                return False

        # Update credentials to set hybrid backend
        credentials['MCP_MEMORY_STORAGE_BACKEND'] = 'hybrid'

        # Save credentials to .env file
        save_credentials_to_env(credentials)

        # Test connection
        connection_ok = test_cloudflare_connection(credentials)
        if connection_ok:
            print_success("Hybrid backend configured successfully")
            print_info("  • Local storage: SQLite-vec (5ms reads)")
            print_info("  • Cloud sync: Cloudflare (background)")
            return "hybrid"
        else:
            print_warning("Cloudflare connection test failed.")
            fallback = input("Continue with hybrid (will sync when connection available)? [Y/n]: ").strip().lower()
            if not fallback or fallback.startswith('y'):
                print_info("Hybrid backend will sync to Cloudflare when connection is available")
                return "hybrid"
            else:
                print_info("Falling back to SQLite-vec for local development.")
                return "sqlite_vec"

    elif backend == "chromadb":
        chromadb_version = "0.5.23"
        success = install_package_safe(
            f"chromadb=={chromadb_version}",
            success_msg=f"ChromaDB {chromadb_version} installed successfully",
            error_msg="Failed to install ChromaDB"
        )
        if not success:
            print_info("This is a known issue on some systems (especially older macOS Intel)")
        return success
            
    elif backend == "auto_detect":
        print_info("Attempting auto-detection...")
        print_info("Auto-detect will prioritize local backends (SQLite-vec, ChromaDB)")
        print_info("For production use, manually select Cloudflare backend.")

        # For auto-detect, try SQLite-vec first (most reliable)
        print_info("Trying SQLite-vec installation...")
        if install_storage_backend("sqlite_vec", system_info):
            print_success("SQLite-vec installed successfully")
            return "sqlite_vec"

        print_warning("SQLite-vec installation failed, trying ChromaDB...")
        if install_storage_backend("chromadb", system_info):
            print_success("ChromaDB installed successfully as fallback")
            return "chromadb"

        print_error("All local storage backends failed to install")
        print_info("Consider manually configuring Cloudflare backend for production use")
        return False
    
    return False

def _detect_installer_command():
    """Detect available package installer (pip or uv)."""
    # Check if pip is available
    pip_available, _ = run_command_safe(
        [sys.executable, '-m', 'pip', '--version'],
        silent=True
    )

    # Detect if uv is available
    uv_path = shutil.which("uv")
    uv_available = uv_path is not None

    # Decide installer command prefix
    if pip_available:
        return [sys.executable, '-m', 'pip']
    elif uv_available:
        print_warning("pip not found, but uv detected. Using 'uv pip' for installation.")
        return ['uv', 'pip']
    else:
        print_error("Neither pip nor uv detected. Cannot install packages.")
        return None

def _setup_storage_and_gpu_environment(args, system_info, gpu_info, env):
    """Set up storage backend and GPU environment variables."""
    # Choose and install storage backend
    chosen_backend = choose_storage_backend(system_info, gpu_info, args)

    # Check if chromadb was chosen but flag not provided
    if chosen_backend == "chromadb" and not args.with_chromadb:
        print_warning("ChromaDB backend selected but --with-chromadb flag not provided")
        print_info("ChromaDB requires heavy ML dependencies (~1-2GB).")
        print_info("To use ChromaDB, run: python scripts/installation/install.py --with-chromadb")
        print_info("Switching to SQLite-vec backend instead...")
        chosen_backend = "sqlite_vec"

    # ChromaDB automatically includes ML dependencies
    if args.with_chromadb:
        args.with_ml = True

    if chosen_backend == "auto_detect":
        # Handle auto-detection case - prefer sqlite_vec if chromadb not explicitly requested
        if not args.with_chromadb:
            print_info("Auto-detection: Using SQLite-vec (lightweight option)")
            chosen_backend = "sqlite_vec"
        else:
            actual_backend = install_storage_backend(chosen_backend, system_info)
            if not actual_backend:
                print_error("Failed to install any storage backend")
                return False
            chosen_backend = actual_backend
    else:
        # Install the chosen backend
        if not install_storage_backend(chosen_backend, system_info):
            print_error(f"Failed to install {chosen_backend} storage backend")
            return False

    # Set environment variable for chosen backend
    if chosen_backend in ["sqlite_vec", "hybrid", "cloudflare"]:
        env['MCP_MEMORY_STORAGE_BACKEND'] = chosen_backend
        if chosen_backend == "sqlite_vec":
            print_info("Configured to use SQLite-vec storage backend")
        elif chosen_backend == "hybrid":
            print_info("Configured to use Hybrid storage backend (SQLite + Cloudflare)")
        elif chosen_backend == "cloudflare":
            print_info("Configured to use Cloudflare storage backend")
    else:
        env['MCP_MEMORY_STORAGE_BACKEND'] = 'chromadb'
        print_info("Configured to use ChromaDB storage backend")

    # Set environment variables based on detected GPU
    if gpu_info.get("has_cuda"):
        print_info("Configuring for CUDA installation")
    elif gpu_info.get("has_rocm"):
        print_info("Configuring for ROCm installation")
        env['MCP_MEMORY_USE_ROCM'] = '1'
    elif gpu_info.get("has_mps"):
        print_info("Configuring for Apple Silicon MPS installation")
        env['PYTORCH_ENABLE_MPS_FALLBACK'] = '1'
    elif gpu_info.get("has_directml"):
        print_info("Configuring for DirectML installation")
        env['MCP_MEMORY_USE_DIRECTML'] = '1'
    else:
        print_info("Configuring for CPU-only installation")
        env['MCP_MEMORY_USE_ONNX'] = '1'

    # Check for Homebrew PyTorch installation
    using_homebrew_pytorch = False
    if system_info.get("has_homebrew_pytorch"):
        print_info(f"Using existing Homebrew PyTorch installation (version: {system_info.get('homebrew_pytorch_version')})")
        using_homebrew_pytorch = True
        # Set the environment variable to use ONNX for embeddings
        env['MCP_MEMORY_USE_ONNX'] = '1'
        # Skip the PyTorch installation step
        pytorch_installed = True
    else:
        # Handle platform-specific PyTorch installation
        pytorch_installed = install_pytorch_platform_specific(system_info, gpu_info)
        if not pytorch_installed:
            print_warning("Platform-specific PyTorch installation failed, but will continue with package installation")

    try:
        # SQLite-vec with ONNX for macOS with homebrew PyTorch or compatibility issues
        if (system_info["is_macos"] and system_info["is_x86"] and 
            (sys.version_info >= (3, 13) or using_homebrew_pytorch or args.skip_pytorch)):
            
            if using_homebrew_pytorch:
                print_info("Using Homebrew PyTorch - installing with SQLite-vec + ONNX configuration")
            elif args.skip_pytorch:
                print_info("Skipping PyTorch installation - using SQLite-vec + ONNX configuration")
            else:
                print_info("Using Python 3.13+ on macOS Intel - using SQLite-vec + ONNX configuration")
            
            # First try to install without ML dependencies
            try:
                cmd = installer_cmd + ['install', '--no-deps'] + install_mode + ['.']
                success, _ = run_command_safe(
                    cmd,
                    success_msg="Package installed with --no-deps successfully",
                    error_msg="Failed to install package with --no-deps",
                    silent=False
                )
                if not success:
                    raise Exception("Installation failed")
                
                # Install core dependencies except torch/sentence-transformers
                print_info("Installing core dependencies except ML libraries...")
                
                # Create a list of dependencies to install
                # Note: mcp and tokenizers are already in core dependencies
                dependencies = [
                    "onnxruntime>=1.14.1"  # ONNX runtime for lightweight embeddings
                ]

                # Add backend-specific dependencies (sqlite-vec, mcp, tokenizers are already in core)
                if args.with_chromadb:
                    dependencies.append("chromadb==0.5.23")
                
                # Install dependencies
                cmd = [sys.executable, '-m', 'pip', 'install'] + dependencies
                success, _ = run_command_safe(
                    cmd,
                    success_msg="Core dependencies installed successfully",
                    error_msg="Failed to install core dependencies",
                    silent=False
                )
                if not success:
                    raise Exception("Core dependency installation failed")
                
                # Set environment variables for ONNX
                print_info("Configuring to use ONNX runtime for inference without PyTorch...")
                env['MCP_MEMORY_USE_ONNX'] = '1'
                if chosen_backend != "sqlite_vec":
                    print_info("Switching to SQLite-vec backend for better compatibility")
                    env['MCP_MEMORY_STORAGE_BACKEND'] = 'sqlite_vec'
                
                print_success("MCP Memory Service installed successfully (SQLite-vec + ONNX)")
                
                if using_homebrew_pytorch:
                    print_info("Using Homebrew PyTorch installation for embedding generation")
                    print_info("Environment configured to use SQLite-vec backend and ONNX runtime")
                else:
                    print_warning("ML libraries (PyTorch/sentence-transformers) were not installed due to compatibility issues")
                    print_info("The service will use ONNX runtime for inference instead")
                
                return True
            except Exception as e:
                print_error(f"Failed to install with ONNX approach: {e}")
                # Fall through to try standard installation
        
        # Standard installation with appropriate optional dependencies
        install_target = ['.']

        # Determine which optional dependencies to include based on backend and flags
        if args.with_chromadb:
            install_target = ['.[chromadb]']
            print_info("Installing with ChromaDB backend support (includes ML dependencies)")
        elif args.with_ml:
            if chosen_backend == "sqlite_vec":
                install_target = ['.[sqlite-ml]']
                print_info("Installing SQLite-vec with full ML capabilities (torch + sentence-transformers)")
            else:
                install_target = ['.[ml]']
                print_info("Installing with ML dependencies for semantic search and embeddings")
        elif chosen_backend == "sqlite_vec":
            install_target = ['.[sqlite]']
            print_info("Installing SQLite-vec with lightweight ONNX embeddings (recommended)")
            print_info("For full ML capabilities with SQLite-vec, use --with-ml flag")
        else:
            print_info("Installing lightweight version (no ML dependencies by default)")
            print_info("For full functionality, use --with-ml flag or install with: pip install mcp-memory-service[ml]")

        cmd = installer_cmd + ['install'] + install_mode + install_target
        success, _ = run_command_safe(
            cmd,
            success_msg="MCP Memory Service installed successfully",
            error_msg="Failed to install MCP Memory Service",
            silent=False
        )
        return success
    except Exception as e:
        print_error(f"Failed to install MCP Memory Service: {e}")
        
        # Special handling for macOS with compatibility issues
        if system_info["is_macos"] and system_info["is_x86"]:
            print_warning("Installation on macOS Intel is challenging")
            print_info("Try manually installing with:")
            print_info("1. pip install --no-deps .")
            print_info("2. pip install sqlite-vec>=0.1.0 mcp>=1.0.0,<2.0.0 onnxruntime>=1.14.1")
            print_info("3. export MCP_MEMORY_USE_ONNX=1")
            print_info("4. export MCP_MEMORY_STORAGE_BACKEND=sqlite_vec")
            
            if system_info.get("has_homebrew_pytorch"):
                print_info("Homebrew PyTorch was detected but installation still failed.")
                print_info("Try running: python install.py --storage-backend sqlite_vec --skip-pytorch")
            
        return False

def get_platform_base_dir() -> Path:
    """Get platform-specific base directory for MCP Memory storage.

    Returns:
        Path: Platform-appropriate base directory
    """
    home_dir = Path.home()

    PLATFORM_PATHS = {
        'Darwin': home_dir / 'Library' / 'Application Support' / 'mcp-memory',
        'Windows': Path(os.environ.get('LOCALAPPDATA', '')) / 'mcp-memory',
    }

    system = platform.system()
    return PLATFORM_PATHS.get(system, home_dir / '.local' / 'share' / 'mcp-memory')


def setup_storage_directories(backend: str, base_dir: Path, args) -> Tuple[Path, Path, bool]:
    """Setup storage and backup directories for the specified backend.

    Args:
        backend: Storage backend type
        base_dir: Base directory for storage
        args: Command line arguments

    Returns:
        Tuple of (storage_path, backups_path, success)
    """
    if backend in ['sqlite_vec', 'hybrid', 'cloudflare']:
        storage_path = args.chroma_path or (base_dir / 'sqlite_vec.db')
        storage_dir = storage_path.parent if storage_path.name.endswith('.db') else storage_path
    else:  # chromadb
        storage_path = args.chroma_path or (base_dir / 'chroma_db')
        storage_dir = storage_path

    backups_path = args.backups_path or (base_dir / 'backups')

    try:
        os.makedirs(storage_dir, exist_ok=True)
        os.makedirs(backups_path, exist_ok=True)

        # Test writability
        test_file = Path(storage_dir) / '.write_test'
        test_file.write_text('test')
        test_file.unlink()

        print_info(f"Storage path: {storage_path}")
        print_info(f"Backups path: {backups_path}")
        return storage_path, backups_path, True

    except (OSError, IOError, PermissionError) as e:
        print_error(f"Failed to configure storage paths: {e}")
        return storage_path, backups_path, False
    except Exception as e:
        print_error(f"Unexpected error configuring storage paths: {e}")
        return storage_path, backups_path, False


def build_mcp_env_config(storage_backend: str, storage_path: Path,
                         backups_path: Path) -> Dict[str, str]:
    """Build MCP environment configuration for Claude Desktop.

    Args:
        storage_backend: Type of storage backend
        storage_path: Path to storage directory/file
        backups_path: Path to backups directory

    Returns:
        Dict of environment variables for MCP configuration
    """
    env_config = {
        "MCP_MEMORY_BACKUPS_PATH": str(backups_path),
        "MCP_MEMORY_STORAGE_BACKEND": storage_backend
    }

    if storage_backend in ['sqlite_vec', 'hybrid']:
        env_config["MCP_MEMORY_SQLITE_PATH"] = str(storage_path)
        env_config["MCP_MEMORY_SQLITE_PRAGMAS"] = "busy_timeout=15000,cache_size=20000"

    if storage_backend in ['hybrid', 'cloudflare']:
        cloudflare_vars = [
            'CLOUDFLARE_API_TOKEN',
            'CLOUDFLARE_ACCOUNT_ID',
            'CLOUDFLARE_D1_DATABASE_ID',
            'CLOUDFLARE_VECTORIZE_INDEX'
        ]
        for var in cloudflare_vars:
            value = os.environ.get(var)
            if value:
                env_config[var] = value

    if storage_backend == 'chromadb':
        env_config["MCP_MEMORY_CHROMA_PATH"] = str(storage_path)

    return env_config


def update_claude_config_file(config_path: Path, env_config: Dict[str, str],
                              project_root: Path, is_windows: bool) -> bool:
    """Update Claude Desktop configuration file with MCP Memory settings.

    Args:
        config_path: Path to Claude config file
        env_config: Environment configuration dictionary
        project_root: Root directory of the project
        is_windows: Whether running on Windows

    Returns:
        bool: True if update succeeded
    """
    try:
        config_text = config_path.read_text()
        config = json.loads(config_text)

        if not isinstance(config, dict):
            print_warning(f"Invalid config format in {config_path}")
            return False

        if 'mcpServers' not in config:
            config['mcpServers'] = {}

        # Create server configuration
        if is_windows:
            script_path = str((project_root / "memory_wrapper.py").resolve())
            config['mcpServers']['memory'] = {
                "command": "python",
                "args": [script_path],
                "env": env_config
            }
        else:
            config['mcpServers']['memory'] = {
                "command": "uv",
                "args": [
                    "--directory",
                    str(project_root.resolve()),
                    "run",
                    "memory"
                ],
                "env": env_config
            }

        config_path.write_text(json.dumps(config, indent=2))
        print_success("Updated Claude Desktop configuration")
        return True

    except (OSError, PermissionError, json.JSONDecodeError) as e:
        print_warning(f"Failed to update Claude Desktop configuration: {e}")
        return False


def configure_paths(args):
    """Configure paths for the MCP Memory Service."""
    print_step("4", "Configuring paths")

    # Get system info
    system_info = detect_system()

    # Get platform-specific base directory
    base_dir = get_platform_base_dir()
    storage_backend = os.environ.get('MCP_MEMORY_STORAGE_BACKEND', 'chromadb')

    # Setup storage directories
    storage_path, backups_path, success = setup_storage_directories(
        storage_backend, base_dir, args
    )
    if not success:
        print_warning("Continuing with Claude Desktop configuration despite storage setup failure")

    # Test backups directory
    try:
        test_file = Path(backups_path) / '.write_test'
        test_file.write_text('test')
        test_file.unlink()
        print_success("Storage directories created and are writable")
    except (OSError, PermissionError) as e:
        print_error(f"Failed to test backups directory: {e}")
        print_warning("Continuing with Claude Desktop configuration")

    # Configure Claude Desktop
    env_config = build_mcp_env_config(storage_backend, storage_path, backups_path)
    project_root = Path(__file__).parent.parent.parent

    home_dir = Path.home()
    claude_config_paths = [
        home_dir / 'Library' / 'Application Support' / 'Claude' / 'claude_desktop_config.json',
        home_dir / '.config' / 'Claude' / 'claude_desktop_config.json',
        Path('claude_config') / 'claude_desktop_config.json'
    ]

    for config_path in claude_config_paths:
        if config_path.exists():
            print_info(f"Found Claude Desktop config at {config_path}")
            if update_claude_config_file(config_path, env_config, project_root,
                                        system_info["is_windows"]):
                break

    return True

def verify_installation():
    """Verify the installation."""
    print_step("5", "Verifying installation")
    
    # Get system info
    system_info = detect_system()
    
    # Check if the package is installed
    try:
        import mcp_memory_service
        print_success(f"MCP Memory Service is installed: {mcp_memory_service.__file__}")
    except ImportError:
        print_error("MCP Memory Service is not installed correctly")
        return False
    
    # Check if the entry point is available
    memory_script = shutil.which('memory')
    if memory_script:
        print_success(f"Memory command is available: {memory_script}")
    else:
        print_warning("Memory command is not available in PATH")
    
    # Check storage backend installation
    storage_backend = os.environ.get('MCP_MEMORY_STORAGE_BACKEND', 'sqlite_vec')
    
    if storage_backend == 'sqlite_vec':
        try:
            import sqlite_vec
            print_success(f"SQLite-vec is installed: {sqlite_vec.__version__}")
        except ImportError:
            print_error("SQLite-vec is not installed correctly")
            return False
    elif storage_backend == 'chromadb':
        try:
            import chromadb
            print_success(f"ChromaDB is installed: {chromadb.__version__}")
        except ImportError:
            print_error("ChromaDB is not installed correctly")
            return False
    
    # Check for ONNX runtime
    try:
        import onnxruntime
        print_success(f"ONNX Runtime is installed: {onnxruntime.__version__}")
        use_onnx = os.environ.get('MCP_MEMORY_USE_ONNX', '').lower() in ('1', 'true', 'yes')
        if use_onnx:
            print_info("Environment configured to use ONNX runtime for embeddings")
            # Check for tokenizers (required for ONNX)
            try:
                import tokenizers
                print_success(f"Tokenizers is installed: {tokenizers.__version__}")
            except ImportError:
                print_warning("Tokenizers not installed but required for ONNX embeddings")
                print_info("Install with: pip install tokenizers>=0.20.0")
    except ImportError:
        print_warning("ONNX Runtime is not installed. This is recommended for PyTorch-free operation.")
        print_info("Install with: pip install onnxruntime>=1.14.1 tokenizers>=0.20.0")
    
    # Check for Homebrew PyTorch
    homebrew_pytorch = False
    if system_info.get("has_homebrew_pytorch"):
        homebrew_pytorch = True
        print_success(f"Homebrew PyTorch detected: {system_info.get('homebrew_pytorch_version')}")
        print_info("Using system-installed PyTorch instead of pip version")
    
    # Check ML dependencies as optional
    pytorch_installed = False
    try:
        import torch
        pytorch_installed = True
        print_info(f"PyTorch is installed: {torch.__version__}")
        
        # Check for CUDA
        if torch.cuda.is_available():
            print_success(f"CUDA is available: {torch.version.cuda}")
            print_info(f"GPU: {torch.cuda.get_device_name(0)}")
        # Check for MPS (Apple Silicon)
        elif hasattr(torch.backends, 'mps') and torch.backends.mps.is_available():
            print_success("MPS (Metal Performance Shaders) is available")
        # Check for DirectML
        else:
            try:
                import torch_directml
                version = getattr(torch_directml, '__version__', 'Unknown version')
                print_success(f"DirectML is available: {version}")
            except ImportError:
                print_info("Using CPU-only PyTorch")
        
        # For macOS Intel, verify compatibility with sentence-transformers
        if system_info["is_macos"] and system_info["is_x86"]:
            torch_version = torch.__version__.split('.')
            major, minor = int(torch_version[0]), int(torch_version[1])
            
            print_info(f"Verifying torch compatibility on macOS Intel (v{major}.{minor})")
            if major < 1 or (major == 1 and minor < 6):
                print_warning(f"PyTorch version {torch.__version__} may be too old for sentence-transformers")
            elif major > 2 or (major == 2 and minor > 1):
                print_warning(f"PyTorch version {torch.__version__} may be too new for sentence-transformers 2.2.2")
                print_info("If you encounter issues, try downgrading to torch 2.0.1")
            
    except ImportError:
        print_warning("PyTorch is not installed via pip. This is okay for basic operation with SQLite-vec backend.")
        if homebrew_pytorch:
            print_info("Using Homebrew PyTorch installation instead of pip version")
        else:
            print_info("For full functionality including embedding generation, install with: pip install 'mcp-memory-service[ml]'")
        pytorch_installed = False
    
    # Check if sentence-transformers is installed correctly (only if PyTorch is installed)
    if pytorch_installed or homebrew_pytorch:
        try:
            import sentence_transformers
            print_success(f"sentence-transformers is installed: {sentence_transformers.__version__}")
            
            if pytorch_installed:
                # Verify compatibility between torch and sentence-transformers
                st_version = sentence_transformers.__version__.split('.')
                torch_version = torch.__version__.split('.')
                
                st_major, st_minor = int(st_version[0]), int(st_version[1])
                torch_major, torch_minor = int(torch_version[0]), int(torch_version[1])
                
                # Specific compatibility check for macOS Intel
                if system_info["is_macos"] and system_info["is_x86"]:
                    if st_major >= 3 and (torch_major < 1 or (torch_major == 1 and torch_minor < 11)):
                        print_warning(f"sentence-transformers {sentence_transformers.__version__} requires torch>=1.11.0")
                        print_info("This may cause runtime issues - consider downgrading sentence-transformers to 2.2.2")
            
            # Verify by trying to load a model (minimal test)
            try:
                print_info("Testing sentence-transformers model loading...")
                test_model = sentence_transformers.SentenceTransformer('paraphrase-MiniLM-L3-v2')
                print_success("Successfully loaded test model")
            except Exception as e:
                print_warning(f"Model loading test failed: {e}")
                print_warning("There may be compatibility issues between PyTorch and sentence-transformers")
                
        except ImportError:
            print_warning("sentence-transformers is not installed. This is okay for basic operation with SQLite-vec backend.")
            print_info("For full functionality including embedding generation, install with: pip install 'mcp-memory-service[ml]'")
    
    # Check for SQLite-vec + ONNX configuration
    if storage_backend == 'sqlite_vec' and os.environ.get('MCP_MEMORY_USE_ONNX', '').lower() in ('1', 'true', 'yes'):
        print_success("SQLite-vec + ONNX configuration is set up correctly")
        print_info("This configuration can run without PyTorch dependency")
        
        try:
            # Import the key components to verify installation
            from mcp_memory_service.storage.sqlite_vec import SqliteVecMemoryStorage
            from mcp_memory_service.models.memory import Memory
            print_success("SQLite-vec + ONNX components loaded successfully")
            
            # Check paths
            sqlite_path = os.environ.get('MCP_MEMORY_SQLITE_PATH', '')
            if sqlite_path:
                print_info(f"SQLite-vec database path: {sqlite_path}")
            else:
                print_warning("MCP_MEMORY_SQLITE_PATH is not set")
            
            backups_path = os.environ.get('MCP_MEMORY_BACKUPS_PATH', '')
            if backups_path:
                print_info(f"Backups path: {backups_path}")
            else:
                print_warning("MCP_MEMORY_BACKUPS_PATH is not set")
            
        except ImportError as e:
            print_error(f"Failed to import SQLite-vec components: {e}")
            return False
            
    # Check if MCP Memory Service package is installed correctly
    try:
        import mcp_memory_service
        print_success(f"MCP Memory Service is installed correctly")
        return True
    except ImportError:
        print_error("MCP Memory Service is not installed correctly")
        return False

def install_claude_hooks(args, system_info):
    """Install Claude Code memory awareness hooks."""
    print_step("5", "Installing Claude Code Memory Awareness Hooks")

    try:
        # Check if Claude Code is available
        claude_available = shutil.which("claude") is not None
        if not claude_available:
            print_warning("Claude Code CLI not found")
            print_info("You can install hooks manually later using:")
            print_info("  cd claude-hooks && python install_hooks.py --basic")
            return

        print_info("Claude Code CLI detected")

        # Use unified Python installer for cross-platform compatibility
        claude_hooks_dir = Path(__file__).parent.parent.parent / "claude-hooks"
        unified_installer = claude_hooks_dir / "install_hooks.py"

        if not unified_installer.exists():
            print_error("Unified hook installer not found at expected location")
            print_info("Please ensure the unified installer is available:")
            print_info(f"  Expected: {unified_installer}")
            return

        # Prepare installer command with appropriate options
        version = get_package_version()
        if args.install_natural_triggers:
            print_info(f"Installing Natural Memory Triggers v{version}...")
            installer_cmd = [sys.executable, str(unified_installer), "--natural-triggers"]
        else:
            print_info("Installing standard memory awareness hooks...")
            installer_cmd = [sys.executable, str(unified_installer), "--basic"]

        # Run the unified Python installer
        print_info(f"Running unified hook installer: {unified_installer.name}")
        result = subprocess.run(
            installer_cmd,
            cwd=str(claude_hooks_dir),
            capture_output=True,
            text=True
        )

        if result.returncode == 0:
            print_success("Claude Code memory awareness hooks installed successfully")
            if args.install_natural_triggers:
                print_info(f"✅ Natural Memory Triggers v{version} enabled")
                print_info("✅ Intelligent trigger detection with 85%+ accuracy")
                print_info("✅ Multi-tier performance optimization")
                print_info("✅ CLI management tools available")
                print_info("")
                print_info("Manage Natural Memory Triggers:")
                print_info("  node ~/.claude/hooks/memory-mode-controller.js status")
                print_info("  node ~/.claude/hooks/memory-mode-controller.js profile balanced")
            else:
                print_info("✅ Standard memory awareness hooks enabled")
                print_info("✅ Session-start and session-end hooks active")
        else:
            print_warning("Hook installation completed with warnings")
            if result.stdout:
                print_info("Installer output:")
                print_info(result.stdout)
            if result.stderr:
                print_warning("Installer warnings:")
                print_warning(result.stderr)

    except Exception as e:
        print_warning(f"Failed to install hooks automatically: {e}")
        print_info("You can install hooks manually later using the unified installer:")
        print_info("  cd claude-hooks && python install_hooks.py --basic")
        if args.install_natural_triggers:
            print_info("For Natural Memory Triggers:")
            print_info("  cd claude-hooks && python install_hooks.py --natural-triggers")

def detect_development_context():
    """Detect if user is likely a developer (has .git directory).

    Returns:
        bool: True if .git directory exists
    """
    git_dir = Path(".git")
    return git_dir.exists() and git_dir.is_dir()

def recommend_editable_install(args):
    """Recommend editable install for developers.

    If .git directory detected and --dev not specified, prompts user to use
    editable install mode. This prevents the common "stale venv vs source code"
    issue where MCP servers load from site-packages instead of source files.

    Args:
        args: Parsed command line arguments

    Returns:
        bool: True if editable install should be used
    """
    # If already in dev mode, nothing to do
    if args.dev:
        return True

    # Detect development context
    if detect_development_context():
        print_warning("Detected git repository - you may be a developer!")
        print("")
        print_info("For development, EDITABLE install is strongly recommended:")
        print_info("  pip install -e .")
        print("")
        print_info("Why this matters:")
        print_info("  • MCP servers load from site-packages, not source files")
        print_info("  • Without -e flag, source changes won't take effect")
        print_info("  • System restart won't help - it just relaunches stale code")
        print_info("  • Common symptom: Code shows v8.23.0 but server reports v8.5.3")
        print("")
        print_info("Editable install ensures:")
        print_info("  • Source changes take effect immediately (after server restart)")
        print_info("  • No need to reinstall package after every change")
        print_info("  • Easier debugging and development workflow")
        print("")

        response = input("Install in EDITABLE mode (recommended for development)? [Y/n]: ").lower().strip()
        if response == '' or response == 'y' or response == 'yes':
            args.dev = True
            print_success("Enabled editable install mode")
            return True
        else:
            print_warning("Proceeding with standard install (not editable)")
            print_warning("Remember: You'll need to reinstall after every source change!")
            return False

    return False

def main():
    """Main installation function."""
    parser = argparse.ArgumentParser(description="Install MCP Memory Service")
    parser.add_argument('--dev', action='store_true', help='Install in development mode')
    parser.add_argument('--chroma-path', type=str, help='Path to ChromaDB storage')
    parser.add_argument('--backups-path', type=str, help='Path to backups storage')
    parser.add_argument('--force-compatible-deps', action='store_true',
                        help='Force compatible versions of PyTorch (2.0.1) and sentence-transformers (2.2.2)')
    parser.add_argument('--fallback-deps', action='store_true',
                        help='Use fallback versions of PyTorch (1.13.1) and sentence-transformers (2.2.2)')
    parser.add_argument('--storage-backend', choices=['cloudflare', 'sqlite_vec', 'chromadb', 'hybrid', 'auto_detect'],
                        help='Choose storage backend: cloudflare (production), sqlite_vec (development), chromadb (team), hybrid (production + local), or auto_detect')
    parser.add_argument('--skip-pytorch', action='store_true',
                        help='Skip PyTorch installation and use ONNX runtime with SQLite-vec backend instead')
    parser.add_argument('--use-homebrew-pytorch', action='store_true',
                        help='Use existing Homebrew PyTorch installation instead of pip version')
    parser.add_argument('--install-hooks', action='store_true',
                        help='Install Claude Code memory awareness hooks after main installation')
    parser.add_argument('--install-natural-triggers', action='store_true',
                        help='Install Natural Memory Triggers (requires Claude Code)')
    parser.add_argument('--with-ml', action='store_true',
                        help='Include ML dependencies (torch, sentence-transformers) for semantic search and embeddings')
    parser.add_argument('--with-chromadb', action='store_true',
                        help='Include ChromaDB backend support (automatically includes ML dependencies)')
    args = parser.parse_args()

    # Check if this is a development context and recommend editable install
    recommend_editable_install(args)

    print_header("MCP Memory Service Installation")
    
    # Step 1: Detect system
    print_step("1", "Detecting system")
    system_info = detect_system()
    
    # Check if user requested force-compatible dependencies for macOS Intel
    if args.force_compatible_deps:
        if system_info["is_macos"] and system_info["is_x86"]:
            print_info("Installing compatible dependencies as requested...")
            # Select versions based on Python version
            python_version = sys.version_info
            if python_version >= (3, 13):
                # Python 3.13+ compatible versions
                torch_version = "2.3.0"
                torch_vision_version = "0.18.0"
                torch_audio_version = "2.3.0"
                st_version = "3.0.0"
            else:
                # Older Python versions
                torch_version = "2.0.1"
                torch_vision_version = "2.0.1"
                torch_audio_version = "2.0.1"
                st_version = "2.2.2"
                
            cmd = [
                sys.executable, '-m', 'pip', 'install',
                f"torch=={torch_version}", f"torchvision=={torch_vision_version}", f"torchaudio=={torch_audio_version}",
                f"sentence-transformers=={st_version}"
            ]
            success, _ = run_command_safe(
                cmd,
                success_msg="Compatible dependencies installed successfully",
                error_msg="Failed to install compatible dependencies",
                silent=False
            )
        else:
            print_warning("--force-compatible-deps is only applicable for macOS with Intel CPUs")
    
    # Check if user requested fallback dependencies for troubleshooting
    if args.fallback_deps:
        print_info("Installing fallback dependencies as requested...")
        # Select versions based on Python version
        python_version = sys.version_info
        if python_version >= (3, 13):
            # Python 3.13+ compatible fallback versions
            torch_version = "2.3.0"
            torch_vision_version = "0.18.0"
            torch_audio_version = "2.3.0"
            st_version = "3.0.0"
        else:
            # Older Python fallback versions
            torch_version = "1.13.1"
            torch_vision_version = "0.14.1"
            torch_audio_version = "0.13.1"
            st_version = "2.2.2"
            
        cmd = [
            sys.executable, '-m', 'pip', 'install',
            f"torch=={torch_version}", f"torchvision=={torch_vision_version}", f"torchaudio=={torch_audio_version}",
            f"sentence-transformers=={st_version}"
        ]
        success, _ = run_command_safe(
            cmd,
            success_msg="Fallback dependencies installed successfully",
            error_msg="Failed to install fallback dependencies",
            silent=False
        )
    
    # Step 2: Check dependencies
    if not check_dependencies():
        sys.exit(1)
    
    # Step 3: Install package
    if not install_package(args):
        # If installation fails and we're on macOS Intel, suggest using the force-compatible-deps option
        if system_info["is_macos"] and system_info["is_x86"]:
            print_warning("Installation failed on macOS Intel.")
            print_info("Try running the script with '--force-compatible-deps' to force compatible versions:")
            print_info("python install.py --force-compatible-deps")
        sys.exit(1)
    
    # Step 4: Configure paths
    if not configure_paths(args):
        print_warning("Path configuration failed, but installation may still work")
    
    # Step 5: Verify installation
    if not verify_installation():
        print_warning("Installation verification failed, but installation may still work")
        # If verification fails and we're on macOS Intel, suggest using the force-compatible-deps option
        if system_info["is_macos"] and system_info["is_x86"]:
            python_version = sys.version_info
            print_info("For macOS Intel compatibility issues, try these steps:")
            print_info("1. First uninstall current packages: pip uninstall -y torch torchvision torchaudio sentence-transformers")
            print_info("2. Then reinstall with compatible versions: python install.py --force-compatible-deps")
            
            if python_version >= (3, 13):
                print_info("For Python 3.13+, you may need to manually install the following:")
                print_info("pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0")
                print_info("pip install sentence-transformers==3.0.0")
    
    print_header("Installation Complete")
    
    # Get final storage backend info
    final_backend = os.environ.get('MCP_MEMORY_STORAGE_BACKEND', 'chromadb')
    use_onnx = os.environ.get('MCP_MEMORY_USE_ONNX', '').lower() in ('1', 'true', 'yes')
    
    print_info("You can now run the MCP Memory Service using the 'memory' command")
    print_info(f"Storage Backend: {final_backend.upper()}")

    if final_backend == 'sqlite_vec':
        print_info("✅ Using SQLite-vec - lightweight, fast, minimal dependencies")
        print_info("   • No complex dependencies or build issues")
        print_info("   • Excellent performance for typical use cases")
    elif final_backend == 'hybrid':
        print_info("✅ Using Hybrid Backend - RECOMMENDED for production")
        print_info("   • Fast local SQLite-vec storage (5ms reads)")
        print_info("   • Background Cloudflare sync for multi-device access")
        print_info("   • SQLite pragmas configured for concurrent access")
        print_info("   • Zero user-facing latency for cloud operations")
    elif final_backend == 'cloudflare':
        print_info("✅ Using Cloudflare Backend - cloud-only storage")
        print_info("   • Distributed edge storage with D1 database")
        print_info("   • Vectorize index for semantic search")
        print_info("   • Multi-device synchronization")
    else:
        print_info("✅ Using ChromaDB - full-featured vector database")
        print_info("   • Advanced features and extensive ecosystem")
    
    if use_onnx:
        print_info("✅ Using ONNX Runtime for inference")
        print_info("   • Compatible with Homebrew PyTorch")
        print_info("   • Reduced dependencies for better compatibility")

    # Show ML dependencies status
    if args.with_ml or args.with_chromadb:
        print_info("✅ ML Dependencies Installed")
        print_info("   • Full semantic search and embedding generation enabled")
        print_info("   • PyTorch and sentence-transformers available")
    else:
        print_info("ℹ️  Lightweight Installation (No ML Dependencies)")
        print_info("   • Basic functionality without semantic search")
        print_info("   • To enable full features: pip install mcp-memory-service[ml]")
    
    print_info("For more information, see the README.md file")

    # Install hooks if requested
    if args.install_hooks or args.install_natural_triggers:
        install_claude_hooks(args, system_info)
    
    # Print macOS Intel specific information if applicable
    if system_info["is_macos"] and system_info["is_x86"]:
        print_info("\nMacOS Intel Notes:")
        
        if system_info.get("has_homebrew_pytorch"):
            print_info("- Using Homebrew PyTorch installation: " + system_info.get("homebrew_pytorch_version", "Unknown"))
            print_info("- The MCP Memory Service is configured to use SQLite-vec + ONNX runtime")
            print_info("- To start the memory service, use:")
            print_info("  export MCP_MEMORY_USE_ONNX=1")
            print_info("  export MCP_MEMORY_STORAGE_BACKEND=sqlite_vec")
            print_info("  memory")
        else:
            print_info("- If you encounter issues, try the --force-compatible-deps option")
            
            python_version = sys.version_info
            if python_version >= (3, 13):
                print_info("- For optimal performance on Intel Macs with Python 3.13+, torch==2.3.0 and sentence-transformers==3.0.0 are recommended")
                print_info("- You can manually install these versions with:")
                print_info("  pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 sentence-transformers==3.0.0")
            else:
                print_info("- For optimal performance on Intel Macs, torch==2.0.1 and sentence-transformers==2.2.2 are recommended")
                print_info("- You can manually install these versions with:")
                print_info("  pip install torch==2.0.1 torchvision==2.0.1 torchaudio==2.0.1 sentence-transformers==2.2.2")
                
        print_info("\nTroubleshooting Tips:")
        print_info("- If you have a Homebrew PyTorch installation, use: --use-homebrew-pytorch")
        print_info("- To completely skip PyTorch installation, use: --skip-pytorch")
        print_info("- To force the SQLite-vec backend, use: --storage-backend sqlite_vec")
        print_info("- For lightweight installation without ML, use: (default behavior)")
        print_info("- For full ML capabilities, use: --with-ml")
        print_info("- For ChromaDB with ML, use: --with-chromadb")
        print_info("- For a quick test, try running: python test_memory.py")
        print_info("- To install Claude Code hooks: --install-hooks")
        print_info("- To install Natural Memory Triggers: --install-natural-triggers")

if __name__ == "__main__":
    main()
```

--------------------------------------------------------------------------------
/src/mcp_memory_service/web/static/style.css:
--------------------------------------------------------------------------------

```css
/* MCP Memory Service Dashboard Styles */

/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Custom Properties */
:root {
    /* Color Palette */
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #8b5cf6;
    --accent: #06d6a0;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --neutral-50: #f9fafb;
    --neutral-100: #f3f4f6;
    --neutral-200: #e5e7eb;
    --neutral-300: #d1d5db;
    --neutral-400: #9ca3af;
    --neutral-500: #6b7280;
    --neutral-600: #4b5563;
    --neutral-700: #374151;
    --neutral-800: #1f2937;
    --neutral-900: #111827;

    /* Typography */
    --font-primary: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;

    /* Font Sizes */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;

    /* Spacing Scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;

    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;

    /* Breakpoints */
    --mobile-max: 768px;
    --tablet-min: 769px;
    --tablet-max: 1024px;
    --desktop-min: 1025px;
}

/* Base Typography */
body {
    font-family: var(--font-primary);
    font-size: var(--text-base);
    line-height: 1.5;
    color: var(--neutral-900);
    background-color: var(--neutral-50);
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.25;
    margin-bottom: var(--space-4);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }

/* App Layout */
.app-container {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto auto auto 1fr auto;
    grid-template-areas:
        "header"
        "nav"
        "sync"
        "main"
        "footer";
}

/* Header Styles */
.app-header {
    grid-area: header;
    background: white;
    border-bottom: 1px solid var(--neutral-200);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-4) var(--space-6);
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: var(--space-6);
    align-items: center;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.app-title {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--primary);
    margin: 0;
}

.version-badge {
    background: var(--neutral-100);
    color: var(--neutral-600);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    font-weight: 500;
}

/* Search Section */
.search-section {
    flex: 1;
    max-width: 600px;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    padding-right: var(--space-12);
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-lg);
    font-size: var(--text-base);
    background: var(--neutral-50);
    transition: var(--transition-base);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.search-btn {
    position: absolute;
    right: var(--space-2);
    padding: var(--space-2);
    background: none;
    border: none;
    color: var(--neutral-500);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition-base);
}

.search-btn:hover {
    color: var(--primary);
    background: var(--neutral-100);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: var(--space-3);
    align-items: center;
}

/* Button Components */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-base);
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--neutral-200);
    color: var(--neutral-700);
}

.btn-secondary:hover {
    background: var(--neutral-300);
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Navigation */
.main-nav {
    grid-area: nav;
    background: white;
    border-bottom: 1px solid var(--neutral-200);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-6);
    display: flex;
    gap: var(--space-2);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
    border: none;
    background: none;
    color: var(--neutral-600);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: var(--transition-base);
}

.nav-item:hover {
    color: var(--primary);
    background: var(--neutral-50);
}

.nav-item.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Sync Status Bar */
.sync-status-bar {
    grid-area: sync;
    display: none; /* Hidden by default, shown by JavaScript for hybrid mode */
    background: var(--neutral-50);
    border-bottom: 1px solid var(--neutral-200);
    padding: var(--space-3) var(--space-6);
    transition: all 0.3s ease;
}

.sync-status-bar.visible {
    display: block;
}

.sync-status-bar.synced {
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.05) 0%, rgba(34, 197, 94, 0) 100%);
    border-bottom-color: var(--success-light);
}

.sync-status-bar.syncing {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.1) 0%, rgba(59, 130, 246, 0) 100%);
    border-bottom-color: var(--primary-light);
}

.sync-status-bar.pending {
    background: linear-gradient(90deg, rgba(251, 191, 36, 0.1) 0%, rgba(251, 191, 36, 0) 100%);
    border-bottom-color: var(--warning-light);
}

.sync-status-bar.error {
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.1) 0%, rgba(239, 68, 68, 0) 100%);
    border-bottom-color: var(--danger-light);
}

.sync-status-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.sync-status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
}

#syncStatusIcon {
    font-size: var(--text-lg);
    animation: sync-pulse 2s ease-in-out infinite;
}

.sync-status-bar.syncing #syncStatusIcon {
    animation: sync-rotate 1s linear infinite;
}

#syncStatusText {
    font-weight: 600;
    color: var(--neutral-900);
}

.sync-details {
    color: var(--neutral-600);
    margin-left: var(--space-2);
}

.sync-button {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sync-button:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.sync-button:active:not(:disabled) {
    transform: translateY(0);
}

.sync-button:disabled {
    background: var(--neutral-300);
    cursor: not-allowed;
    opacity: 0.6;
}

.sync-button-icon {
    font-size: var(--text-base);
}

@keyframes sync-rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes sync-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* Main Content */
.main-content {
    grid-area: main;
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-6);
    width: 100%;
}

/* View Containers */
.view-container {
    display: none;
}

.view-container.active {
    display: block;
}

/* Dashboard Grid Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 400px;
    grid-template-rows: auto auto;
    gap: var(--space-8);
    grid-template-areas:
        "welcome quick-actions"
        "recent quick-actions";
}

.welcome-card {
    grid-area: welcome;
    background: white;
    padding: var(--space-8);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

.welcome-card h2 {
    color: var(--neutral-900);
    margin-bottom: var(--space-3);
}

.welcome-card p {
    color: var(--neutral-600);
    margin-bottom: var(--space-6);
}

.quick-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-6);
}

.stat-item {
    text-align: center;
}

.stat-number {
    display: block;
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--primary);
    margin-bottom: var(--space-1);
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--neutral-600);
}

.recent-memories {
    grid-area: recent;
    background: white;
    padding: var(--space-6);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

.quick-actions {
    grid-area: quick-actions;
    background: white;
    padding: var(--space-6);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

.action-grid {
    display: grid;
    gap: var(--space-4);
}

.action-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--neutral-50);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: var(--transition-base);
    font-size: var(--text-sm);
    font-weight: 500;
}

.action-card:hover {
    background: var(--neutral-100);
    border-color: var(--primary);
}

/* Compact Sync Control Styles */
.sync-control-compact {
    margin-top: var(--space-4);
    padding: var(--space-3);
    background: var(--neutral-50);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--neutral-400);
}

.sync-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.sync-status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
    min-width: 0;
}

.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--neutral-400);
    flex-shrink: 0;
}

.sync-text-sm {
    font-size: var(--text-sm);
    color: var(--neutral-700);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sync-progress-sm {
    font-size: var(--text-xs);
    color: var(--neutral-500);
    flex-shrink: 0;
    white-space: nowrap;
}

.sync-buttons-sm {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.btn-icon-sm {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--neutral-500);
    transition: all var(--transition-fast);
}

.btn-icon-sm:hover {
    background: var(--neutral-200);
    color: var(--neutral-700);
}

.btn-icon-sm:active {
    transform: scale(0.95);
}

.btn-icon-sm.btn-icon-primary {
    color: var(--primary);
}

.btn-icon-sm.btn-icon-primary:hover {
    background: rgba(59, 130, 246, 0.15);
    color: var(--primary-dark);
}

.btn-icon-sm:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Sync Control Status States */
.sync-control-compact.synced {
    border-left-color: var(--success);
}

.sync-control-compact.synced .sync-dot {
    background: var(--success);
}

.sync-control-compact.syncing {
    border-left-color: var(--primary);
}

.sync-control-compact.syncing .sync-dot {
    background: var(--primary);
    animation: spinner 1s linear infinite;
}

.sync-control-compact.pending {
    border-left-color: var(--warning);
}

.sync-control-compact.pending .sync-dot {
    background: var(--warning);
}

.sync-control-compact.error {
    border-left-color: var(--error);
}

.sync-control-compact.error .sync-dot {
    background: var(--error);
}

.sync-control-compact.paused {
    border-left-color: var(--neutral-400);
}

.sync-control-compact.paused .sync-dot {
    background: var(--neutral-400);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes spinner {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Backup Settings in Modal */
.backup-settings {
    margin-top: var(--space-2);
}

.backup-actions {
    margin-top: var(--space-3);
    display: flex;
    gap: var(--space-2);
}

/* Small button variant */
.btn-sm {
    padding: var(--space-2);
    font-size: var(--text-xs);
    min-width: auto;
}

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

/* Memory List/Grid Components */
.memory-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    max-height: 600px;
    overflow-y: auto;
}

.memory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-6);
}

.memory-card {
    background: white;
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    transition: var(--transition-base);
    cursor: pointer;
}

.memory-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.memory-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-3);
}

.memory-meta {
    font-size: var(--text-xs);
    color: var(--neutral-500);
}

.memory-content {
    color: var(--neutral-700);
    line-height: 1.6;
    margin-bottom: var(--space-4);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.memory-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.tag {
    background: var(--neutral-100);
    color: var(--neutral-700);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 500;
}

/* Document Group Styles */
.document-group {
    background: white;
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    transition: var(--transition-base);
    cursor: pointer;
    margin-bottom: var(--space-4);
}

.document-group:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.document-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.document-icon {
    font-size: var(--text-xl);
    flex-shrink: 0;
}

.document-info {
    flex: 1;
    min-width: 0;
}

.document-title {
    font-weight: 600;
    color: var(--neutral-900);
    margin-bottom: var(--space-1);
    word-break: break-word;
}

.document-meta {
    font-size: var(--text-sm);
    color: var(--neutral-500);
}

.document-preview {
    color: var(--neutral-700);
    line-height: 1.6;
    margin-bottom: var(--space-3);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.document-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.document-actions {
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
}

.document-actions .btn-icon {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    background: var(--neutral-100);
    color: var(--neutral-700);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    transition: var(--transition-fast);
    cursor: pointer;
}

.document-actions .btn-icon:hover {
    background: var(--neutral-200);
    border-color: var(--neutral-300);
}

.document-actions .btn-remove:hover {
    background: var(--error);
    color: white;
    border-color: var(--error);
}

/* Document Chunks Modal */
.document-chunks {
    max-height: 70vh;
    overflow-y: auto;
}

.chunk-item {
    background: var(--neutral-50);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.chunk-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
}

.chunk-number {
    font-weight: 600;
    color: var(--neutral-900);
}

.chunk-meta {
    font-size: var(--text-sm);
    color: var(--neutral-500);
}

.chunk-content {
    color: var(--neutral-700);
    line-height: 1.6;
    margin-bottom: var(--space-3);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
    padding: var(--space-3);
    background: white;
    border-radius: var(--radius-sm);
}

.chunk-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

/* Dark mode: Fix white backgrounds in document chunk modals */
body.dark-mode .chunk-item {
    background: #1f2937 !important;
    border-color: #374151 !important;
}

body.dark-mode .chunk-content {
    background: #111827 !important;
    color: #d1d5db !important;
}

body.dark-mode .chunk-number {
    color: #60a5fa !important;
}

body.dark-mode .chunk-meta {
    color: #9ca3af !important;
}

body.dark-mode .chunk-header {
    color: #f3f4f6 !important;
}

/* Search Layout */
.search-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: var(--space-8);
}

.search-filters {
    background: white;
    padding: var(--space-6);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    height: fit-content;
}

.filter-section {
    margin-bottom: var(--space-5);
}

.filter-section label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--neutral-700);
    margin-bottom: var(--space-2);
}

.filter-section input,
.filter-section select {
    width: 100%;
    padding: var(--space-3);
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
}

.search-results {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.search-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--neutral-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.results-meta {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.view-options {
    display: flex;
    gap: var(--space-1);
}

.view-btn {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--neutral-300);
    background: white;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: var(--transition-base);
}

.view-btn:first-child {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.view-btn:last-child {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    border-left: none;
}

.view-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

#searchResultsList {
    padding: var(--space-6);
}

/* Modal Components */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-4);
}

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

.modal-content {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--neutral-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    padding: var(--space-2);
    cursor: pointer;
    color: var(--neutral-500);
    border-radius: var(--radius-md);
    transition: var(--transition-base);
}

.modal-close:hover {
    background: var(--neutral-100);
    color: var(--neutral-700);
}

.modal-body {
    padding: var(--space-6);
    flex: 1;
    overflow-y: auto;
}

.modal-footer {
    padding: var(--space-6);
    border-top: 1px solid var(--neutral-200);
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

/* Form Components */
.form-group {
    margin-bottom: var(--space-5);
}

.form-group label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--neutral-700);
    margin-bottom: var(--space-2);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: var(--space-3);
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    transition: var(--transition-base);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 120px;
}

/* System Info in Settings Modal */
.system-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--neutral-100);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    font-size: var(--text-sm);
    color: var(--neutral-600);
    font-weight: 500;
}

.info-value {
    font-size: var(--text-sm);
    color: var(--neutral-900);
    font-weight: 600;
    font-family: 'Monaco', 'Courier New', monospace;
}

/* Loading and Status Components */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: var(--space-4);
    z-index: 2000;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--neutral-200);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: var(--space-6);
    right: var(--space-6);
    z-index: 1500;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.toast {
    background: white;
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    animation: slideIn 0.3s ease-out;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--error);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Connection Status */
.connection-status {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    background: white;
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    z-index: 100;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

.status-indicator.disconnected {
    background: var(--error);
}

.status-indicator.connecting {
    background: var(--warning);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: var(--space-4);
        text-align: center;
    }

    .search-section {
        max-width: none;
    }

    .action-buttons {
        justify-content: center;
    }

    .btn-text {
        display: none;
    }

    .nav-container {
        flex-wrap: wrap;
        justify-content: center;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "welcome"
            "recent"
            "quick-actions";
    }

    .search-layout {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .search-filters {
        order: 2;
    }

    .search-results {
        order: 1;
    }

    .memory-grid {
        grid-template-columns: 1fr;
    }

    .quick-stats {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr 300px;
    }

    .search-layout {
        grid-template-columns: 250px 1fr;
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Browse View - Tags Cloud */
.browse-content {
    padding: var(--space-6);
}

.tags-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    justify-content: center;
    margin-bottom: var(--space-8);
    padding: var(--space-6);
    background: var(--neutral-50);
    border-radius: var(--radius-lg);
}

.tag-bubble {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--neutral-100);
    color: var(--neutral-700);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.tag-bubble:hover {
    background: var(--neutral-200);
    border-color: var(--neutral-300);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tag-bubble .count {
    background: var(--neutral-200);
    color: var(--neutral-700);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 600;
}

.tagged-memories {
    margin-top: var(--space-8);
}

.tagged-memories .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-4);
    border-bottom: 2px solid var(--neutral-200);
}

.tagged-memories h3 {
    color: var(--neutral-800);
    font-size: var(--text-xl);
}

#selectedTagName {
    color: var(--primary);
    font-weight: 600;
}

/* Memory Details Metadata Styles */
.memory-metadata {
    margin-top: var(--space-4);
    border: 1px solid var(--neutral-200);
    border-radius: 8px;
    overflow: hidden;
}

.metadata-toggle {
    background: var(--neutral-50);
    padding: var(--space-3) var(--space-4);
    margin: 0;
    border-bottom: 1px solid var(--neutral-200);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--neutral-700);
    transition: background-color 0.2s ease;
}

.metadata-toggle:hover {
    background: var(--neutral-100);
}

.toggle-icon {
    display: inline-block;
    margin-right: var(--space-2);
    transition: transform 0.2s ease;
    font-size: 0.8em;
}

.memory-metadata.expanded .toggle-icon {
    transform: rotate(90deg);
}

.metadata-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.memory-metadata.expanded .metadata-content {
    max-height: 500px;
    padding: var(--space-4);
}

.metadata-items {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.metadata-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2);
    background: var(--neutral-50);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

.metadata-key {
    font-weight: 600;
    color: var(--neutral-700);
    min-width: 120px;
    flex-shrink: 0;
}

.metadata-value {
    color: var(--neutral-600);
    word-break: break-word;
}

.metadata-string {
    color: var(--success);
}

.metadata-number {
    color: var(--primary);
}

.metadata-boolean {
    color: var(--warning);
}

.metadata-array {
    color: var(--secondary);
}

.metadata-object {
    color: var(--neutral-500);
}

.metadata-empty {
    color: var(--neutral-400);
    font-style: italic;
    padding: var(--space-4);
    text-align: center;
}

/* Memory Type Styling */
.memory-meta p {
    margin-bottom: var(--space-2);
}

.memory-meta strong {
    color: var(--neutral-700);
    margin-right: var(--space-2);
}

/* Print Styles */
@media print {
    .app-header,
    .main-nav,
    .modal-overlay,
    .toast-container,
    .connection-status {
        display: none !important;
    }

    .main-content {
        max-width: none;
        padding: 0;
    }
}

/* API Documentation Styles */
#apiDocsView {
    padding: var(--space-6);
}

.api-docs-header {
    text-align: center;
    margin-bottom: var(--space-8);
}

.api-docs-header h2 {
    color: var(--neutral-800);
    margin-bottom: var(--space-3);
}

.api-docs-header p {
    color: var(--neutral-600);
    font-size: var(--text-lg);
    margin-bottom: var(--space-6);
}

.api-docs-links {
    display: flex;
    gap: var(--space-4);
    justify-content: center;
    flex-wrap: wrap;
}

.api-endpoints-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: var(--space-6);
    max-width: 1200px;
    margin: 0 auto;
}

.endpoint-section {
    background: var(--neutral-50);
    border-radius: var(--radius-lg);
    border: 1px solid var(--neutral-200);
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.endpoint-section:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
}

.endpoint-section h3 {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: var(--space-4);
    margin: 0;
    font-size: var(--text-lg);
}

.endpoint-list {
    padding: var(--space-4);
}

.endpoint-item {
    background: white;
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.endpoint-item:last-child {
    margin-bottom: 0;
}

.endpoint-item:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

.endpoint-item .method {
    display: inline-block;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    margin-right: var(--space-3);
    min-width: 60px;
    text-align: center;
}

.endpoint-item .method.get {
    background: var(--success);
    color: white;
}

.endpoint-item .method.post {
    background: var(--primary);
    color: white;
}

.endpoint-item .method.delete {
    background: var(--error);
    color: white;
}

.endpoint-item .path {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--neutral-700);
    font-size: var(--text-sm);
}

.endpoint-item .description {
    display: block;
    color: var(--neutral-600);
    font-size: var(--text-sm);
    margin-top: var(--space-2);
    line-height: 1.5;
}

/* Responsive adjustments for API docs */
@media (max-width: 768px) {
    .api-endpoints-grid {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .api-docs-links {
        flex-direction: column;
        align-items: center;
    }

    .api-docs-links .btn {
        width: 100%;
        max-width: 300px;
    }
}

/* ============================= */
/* Search Filter Enhancements   */
/* ============================= */

/* Tooltips */
.tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    color: var(--neutral-400);
    font-size: var(--text-sm);
    margin-left: var(--space-2);
    transition: all 0.2s ease;
    vertical-align: middle;
}

.tooltip svg {
    display: block;
    transition: all 0.2s ease;
}

.tooltip:hover {
    color: var(--primary);
    transform: scale(1.1);
}

.tooltip:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--neutral-800);
    color: white;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--space-2);
    font-size: var(--text-xs);
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    min-width: 150px;
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.tooltip:hover::before {
    content: '';
    position: absolute;
    bottom: calc(100% - 5px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--neutral-800);
    z-index: 1001;
}

/* Help Text */
.help-text {
    display: block;
    font-size: var(--text-xs);
    color: var(--neutral-500);
    margin-top: var(--space-1);
    line-height: 1.4;
}

/* Filter Actions */
.filter-actions {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--neutral-200);
}

.filter-actions .btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    font-weight: 500;
    border-radius: var(--space-2);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-actions .btn-primary {
    background: var(--primary);
    color: white;
}

.filter-actions .btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.filter-actions .btn-secondary {
    background: var(--neutral-100);
    color: var(--neutral-700);
    border: 1px solid var(--neutral-300);
}

.filter-actions .btn-secondary:hover {
    background: var(--neutral-200);
}

/* Active Filters Display */
.active-filters {
    margin-top: var(--space-4);
    padding: var(--space-4);
    background: var(--neutral-50);
    border-radius: var(--space-2);
    border: 1px solid var(--neutral-200);
}

.active-filters h4 {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--neutral-700);
    margin-bottom: var(--space-3);
}

.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--primary);
    color: white;
    font-size: var(--text-xs);
    border-radius: 9999px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-pill:hover {
    background: var(--primary-dark);
}

.filter-pill .remove-filter {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
}

.filter-pill .remove-filter:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Enhanced filter section styling */
.filter-section {
    margin-bottom: var(--space-4);
}

.filter-section label {
    display: flex;
    align-items: center;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--neutral-700);
    margin-bottom: var(--space-2);
}

.filter-section input,
.filter-section select {
    width: 100%;
    padding: var(--space-3);
    border: 1px solid var(--neutral-300);
    border-radius: var(--space-2);
    font-size: var(--text-sm);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-section input:focus,
.filter-section select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Loading states */
.filter-actions .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.filter-actions .btn.loading {
    position: relative;
    color: transparent;
}

.filter-actions .btn.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Mobile responsiveness for filter improvements */
@media (max-width: 768px) {
    .filter-actions {
        flex-direction: column;
    }

    .filter-pills {
        gap: var(--space-1);
    }

    .filter-pill {
        font-size: 11px;
        padding: var(--space-1) var(--space-2);
    }

    .tooltip:hover::after {
        max-width: 250px;
        font-size: 11px;
    }
}

/* Filters Header with Toggle */
.filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--neutral-200);
}

.filters-header h3 {
    margin: 0;
    display: flex;
    align-items: center;
}

.mode-toggle-compact {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.mode-toggle-compact .toggle-switch {
    width: 48px;
    height: 24px;
}

.mode-toggle-compact .slider:before {
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
}

.mode-toggle-compact input:checked + .slider:before {
    transform: translateX(24px);
}

/* Search Mode Indicator */
.search-mode-indicator {
    margin-bottom: var(--space-4);
    padding: var(--space-3);
    background: var(--neutral-50);
    border-radius: var(--space-2);
    border: 1px solid var(--neutral-200);
    text-align: center;
}

.mode-status {
    font-size: var(--text-sm);
    color: var(--neutral-600);
    font-weight: 500;
}

.mode-status #searchModeText {
    color: var(--primary);
    font-weight: 600;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #666;
    transition: .3s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #2563eb; /* Cache bust: fixed 2025-10-03 */
}

input:checked + .slider:before {
    transform: translateX(32px);
    background-color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.mode-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 600;
    color: var(--neutral-700);
}

#searchModeText {
    min-width: 120px;
}


/* ============================================================
   DARK MODE - VARIABLE REDEFINITION APPROACH
   Appended 2025-10-04: Redefine color variables for dark theme
   ============================================================ */

/* Utility Classes */
.hidden {
    display: none !important;
}

.settings-section-heading {
    margin-top: 0;
    color: var(--neutral-600);
}

.settings-divider {
    margin: var(--space-6) 0;
    border: none;
    border-top: 1px solid var(--neutral-200);
}

/* Dark Mode Theme - Redefine Color Variables */
body.dark-mode {
    /* Invert neutral color scale for dark mode */
    --neutral-50: #111827;   /* Darkest background (was lightest) */
    --neutral-100: #1f2937;  /* Surface/card background */
    --neutral-200: #374151;  /* Borders/dividers */
    --neutral-300: #4b5563;  /* Subtle borders */
    --neutral-400: #6b7280;  /* Disabled text */
    --neutral-500: #9ca3af;  /* Muted text */
    --neutral-600: #d1d5db;  /* Body text (was dark, now light) */
    --neutral-700: #e5e7eb;  /* Strong text */
    --neutral-800: #f3f4f6;  /* Stronger text */
    --neutral-900: #f9fafb;  /* Headings/emphasis (was dark, now lightest) */

    /* Apply inverted variables to body */
    background-color: var(--neutral-50);
    color: var(--neutral-600);
}

/* Specific overrides that can't use variables - Cache bust: v8.1.1 fix */
body.dark-mode .app-header,
body.dark-mode .main-nav,
body.dark-mode .sync-status-bar,
body.dark-mode .welcome-card,
body.dark-mode .recent-memories,
body.dark-mode .quick-actions,
body.dark-mode .memory-card,
body.dark-mode .action-card,
body.dark-mode .document-group,
body.dark-mode .search-filters,
body.dark-mode .search-results,
body.dark-mode .modal-content,
body.dark-mode .toast,
body.dark-mode .endpoint-item {
    background: var(--neutral-100) !important;  /* Dark card background */
}

/* Dark mode sync status bar gradients */
body.dark-mode .sync-status-bar.synced {
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.15) 0%, rgba(34, 197, 94, 0) 100%) !important;
}

body.dark-mode .sync-status-bar.syncing {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.2) 0%, rgba(59, 130, 246, 0) 100%) !important;
}

body.dark-mode .sync-status-bar.pending {
    background: linear-gradient(90deg, rgba(251, 191, 36, 0.15) 0%, rgba(251, 191, 36, 0) 100%) !important;
}

body.dark-mode .sync-status-bar.error {
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.15) 0%, rgba(239, 68, 68, 0) 100%) !important;
}

body.dark-mode .memory-card,
body.dark-mode .welcome-card,
body.dark-mode .action-card,
body.dark-mode .modal-content,
body.dark-mode .search-filters,
body.dark-mode .search-results {
    border-color: var(--neutral-200) !important;
}

body.dark-mode .memory-card:hover,
body.dark-mode .action-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

body.dark-mode .nav-item:hover {
    background: var(--neutral-200);
    color: var(--primary);
}

body.dark-mode .nav-item.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Override specific element colors that need explicit dark mode values - Cache bust: v8.1.1 */
body.dark-mode .memory-content {
    color: var(--neutral-900) !important;  /* Brightest text for readability */
}

body.dark-mode .memory-meta {
    color: var(--neutral-600) !important;  /* Lighter but still readable for metadata */
}

body.dark-mode .memory-meta strong {
    color: var(--neutral-900) !important;  /* Bright labels for readability */
}

body.dark-mode .action-card h3,
body.dark-mode .action-card p,
body.dark-mode .action-card span {
    color: var(--neutral-900);
}

/* Connection status indicator dark mode */
body.dark-mode .connection-status {
    background: var(--neutral-100) !important;
    border-color: var(--neutral-200) !important;
    color: var(--neutral-900) !important;
}

body.dark-mode .action-card svg {
    color: var(--primary);
}

body.dark-mode h4 {
    color: var(--neutral-600);
}

body.dark-mode .filter-chip.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

body.dark-mode .toast.success {
    border-left-color: var(--success);
}

body.dark-mode .toast.error {
    border-left-color: var(--error);
}

body.dark-mode .toast.info {
    border-left-color: var(--primary);
}

/* Scrollbars (webkit browsers) */
body.dark-mode ::-webkit-scrollbar {
    background: var(--neutral-50);
}

body.dark-mode ::-webkit-scrollbar-thumb {
    background: var(--neutral-200);
}

body.dark-mode ::-webkit-scrollbar-thumb:hover {
    background: var(--neutral-300);
}

/* ===================================
   Footer Styles
   =================================== */

.app-footer {
    grid-area: footer;
    margin-top: 4rem;
    padding: 3rem 2rem 2rem;
    background: var(--neutral-50);
    border-top: 1px solid var(--neutral-100);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3rem;
}

.footer-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--neutral-900);
    margin: 0 0 1rem 0;
}

.footer-links {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-links li {
    margin-bottom: 0.75rem;
}

.footer-links a {
    color: var(--neutral-700);
    text-decoration: none;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.2s ease;
}

.footer-links a:hover {
    color: var(--blue-600);
}

.footer-links svg {
    flex-shrink: 0;
}

.footer-description {
    font-size: 0.875rem;
    color: var(--neutral-600);
    margin: 0 0 1.5rem 0;
    line-height: 1.6;
}

.footer-license {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.footer-license svg {
    color: var(--neutral-500);
    flex-shrink: 0;
}

.footer-license a {
    color: var(--neutral-700);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.2s ease;
}

.footer-license a:hover {
    color: var(--blue-600);
}

.footer-copyright {
    font-size: 0.75rem;
    color: var(--neutral-500);
}

/* Dark mode footer styles */
body.dark-mode .app-footer {
    background: var(--neutral-100) !important;  /* Dark surface background */
    border-top-color: var(--neutral-200) !important;
}

body.dark-mode .footer-section h4 {
    color: var(--neutral-900) !important;  /* Light text for readability */
}

body.dark-mode .footer-links a {
    color: var(--neutral-700) !important;  /* Medium-light link text */
}

body.dark-mode .footer-links a:hover {
    color: var(--blue-400);
}

body.dark-mode .footer-description {
    color: var(--neutral-600) !important;  /* Readable body text */
}

body.dark-mode .footer-license svg {
    color: var(--neutral-500);
}

body.dark-mode .footer-license a {
    color: var(--neutral-700) !important;  /* Match link colors */
}

body.dark-mode .footer-license a:hover {
    color: var(--blue-400);
}

body.dark-mode .footer-copyright {
    color: var(--neutral-500) !important;  /* Muted text */
}

/* ===================================
   Documents View Styles
   =================================== */

.documents-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
    padding: var(--space-6);
}

.documents-section {
    background: white;
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
}

.documents-section h2 {
    margin: 0 0 var(--space-6) 0;
    color: var(--neutral-900);
    font-size: var(--text-xl);
    font-weight: 600;
}

/* Upload Area */
.upload-area {
    margin-bottom: var(--space-6);
}

.drop-zone {
    border: 2px dashed var(--neutral-300);
    border-radius: var(--radius-lg);
    padding: var(--space-12);
    text-align: center;
    transition: var(--transition-base);
    background: var(--neutral-50);
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
}

.drop-zone-content svg {
    color: var(--neutral-400);
    opacity: 0.7;
}

.drop-zone-content h3 {
    margin: 0;
    color: var(--neutral-900);
    font-size: var(--text-xl);
    font-weight: 500;
}

.drop-zone-content p {
    margin: 0;
    color: var(--neutral-600);
}

.supported-formats {
    font-size: var(--text-sm) !important;
    color: var(--neutral-500) !important;
}

.link-button {
    background: none;
    border: none;
    color: var(--primary);
    text-decoration: underline;
    cursor: pointer;
    font-size: inherit;
    padding: 0;
}

.link-button:hover {
    color: var(--primary-dark);
}

/* Upload Configuration */
.upload-config {
    margin-bottom: var(--space-6);
}

.config-section {
    margin-bottom: var(--space-4);
}

.config-section label {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: 500;
    color: var(--neutral-700);
    font-size: var(--text-sm);
}

.config-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
    margin-bottom: var(--space-4);
}

.form-control {
    width: 100%;
    padding: var(--space-3);
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    transition: var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-control[type="range"] {
cursor: pointer;
}

/* Processing Mode Toggle */
.processing-mode-toggle {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-md);
    background: var(--neutral-50);
    color: var(--neutral-700);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    flex: 1;
    justify-content: center;
}

.mode-btn:hover {
    background: var(--neutral-100);
    border-color: var(--neutral-400);
}

.mode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.mode-btn.active:hover {
    background: var(--primary-dark);
}

.mode-description {
    font-size: var(--text-xs);
    color: var(--neutral-500);
    margin-top: var(--space-1);
}

.form-help {
    display: block;
    font-size: var(--text-xs);
    color: var(--neutral-500);
    margin-top: var(--space-1);
}

/* Upload Actions */
.upload-actions {
    text-align: center;
    margin-bottom: var(--space-8);
}

/* Upload History */
.upload-history {
    min-height: 200px;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.upload-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    background: var(--neutral-50);
}

.upload-item.success {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.05);
}

.upload-item.error {
    border-color: var(--error);
    background: rgba(239, 68, 68, 0.05);
}

.upload-item.processing {
    border-color: var(--warning);
    background: rgba(245, 158, 11, 0.05);
}

.upload-info {
    flex: 1;
}

.upload-filename {
    font-weight: 500;
    color: var(--neutral-900);
    margin-bottom: var(--space-1);
}

.upload-meta {
    font-size: var(--text-sm);
    color: var(--neutral-600);
}

.upload-status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    font-weight: 500;
}

.upload-status.success {
    color: var(--success);
}

.upload-status.error {
    color: var(--error);
}

.upload-status.processing {
    color: var(--warning);
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--neutral-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-top: var(--space-2);
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: var(--radius-sm);
    transition: width var(--transition-base);
}

/* Dark mode for documents */
body.dark-mode .documents-section {
    background: var(--neutral-100);
    border-color: var(--neutral-200);
}

body.dark-mode .drop-zone {
    border-color: var(--neutral-200);
    background: var(--neutral-100);
}

body.dark-mode .drop-zone:hover,
body.dark-mode .drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

body.dark-mode .drop-zone-content h3 {
    color: var(--neutral-900);
}

body.dark-mode .drop-zone-content p {
    color: var(--neutral-700);
}

body.dark-mode .upload-item {
    background: var(--neutral-200);
    border-color: var(--neutral-300);
}

body.dark-mode .upload-item.success {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.1);
}

body.dark-mode .upload-item.error {
    border-color: var(--error);
    background: rgba(16, 185, 129, 0.1);
}

body.dark-mode .upload-item.processing {
    border-color: var(--warning);
    background: rgba(245, 158, 11, 0.1);
}

body.dark-mode .upload-filename {
    color: var(--neutral-900);
}

body.dark-mode .upload-meta {
    color: var(--neutral-600);
}

/* Dark mode - Chunking Help Section */
body.dark-mode .chunking-help {
    background: var(--neutral-100) !important;
    border-color: var(--neutral-200) !important;
}

body.dark-mode .help-header {
    border-bottom-color: var(--neutral-200) !important;
    color: var(--neutral-900) !important;
}

body.dark-mode .help-content {
    color: var(--neutral-700) !important;
}

body.dark-mode .help-note {
    background: rgba(245, 158, 11, 0.15) !important;
    border-left-color: var(--warning) !important;
    color: var(--neutral-900) !important;
}

body.dark-mode .help-option {
    background: var(--neutral-50) !important;
    border-color: var(--neutral-200) !important;
}

body.dark-mode .help-option:hover {
    border-color: var(--primary) !important;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2) !important;
}

body.dark-mode .help-option-header strong {
    color: var(--neutral-900) !important;
}

body.dark-mode .help-option p {
    color: var(--neutral-700) !important;
}

body.dark-mode .help-option p strong {
    color: var(--neutral-900) !important;
}

body.dark-mode .help-tips {
    background: rgba(59, 130, 246, 0.15) !important;
    border-left-color: var(--primary) !important;
}

body.dark-mode .help-tips strong {
    color: var(--neutral-900) !important;
}

body.dark-mode .help-tips li {
    color: var(--neutral-700) !important;
}

body.dark-mode .help-tips li strong {
    color: var(--primary) !important;
}

body.dark-mode .close-help {
    color: var(--neutral-600) !important;
}

body.dark-mode .close-help:hover {
    color: var(--error) !important;
}

/* Dark mode - Overlap diagram */
body.dark-mode .help-example {
    background: var(--neutral-50) !important;
    border-color: var(--neutral-200) !important;
}

body.dark-mode .help-example strong {
    color: var(--neutral-900) !important;
}

body.dark-mode .chunk-demo {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

body.dark-mode .chunk-part.unique {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.3) 0%, rgba(59, 130, 246, 0.2) 100%) !important;
    color: var(--blue-300) !important;
    border-color: var(--primary) !important;
}

body.dark-mode .chunk-part.overlap {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.3) 0%, rgba(245, 158, 11, 0.2) 100%) !important;
    color: #fbbf24 !important;
    border-color: var(--warning) !important;
}

body.dark-mode .chunk-demo:hover .chunk-part.overlap {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.4) 0%, rgba(245, 158, 11, 0.3) 100%) !important;
}

/* Responsive */
@media (max-width: 768px) {
    .documents-layout {
        padding: var(--space-4);
        gap: var(--space-6);
    }

    .documents-section {
        padding: var(--space-4);
    }

    .drop-zone {
        padding: var(--space-8);
    }

    .config-row {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .upload-item {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-2);
    }
}

/* Responsive footer */
@media (max-width: 768px) {
.footer-content {
grid-template-columns: 1fr;
gap: 2rem;
}

.app-footer {
padding: 2rem 1rem 1.5rem;
margin-top: 3rem;
}
}

/* Manage View Styles */
.manage-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
    padding: var(--space-6);
}

.manage-section {
    background: white;
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
}

.manage-section h2 {
    margin: 0 0 var(--space-6) 0;
    color: var(--neutral-900);
    font-size: var(--text-xl);
    font-weight: 600;
}

.bulk-ops-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-6);
}

.bulk-op-card {
    background: var(--neutral-50);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    transition: var(--transition-base);
}

.bulk-op-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.bulk-op-card h3 {
    margin: 0 0 var(--space-2) 0;
    color: var(--neutral-900);
    font-size: var(--text-lg);
    font-weight: 600;
}

.bulk-op-card p {
    margin: 0 0 var(--space-4) 0;
    color: var(--neutral-600);
    font-size: var(--text-sm);
}

.op-controls {
    display: flex;
    gap: var(--space-3);
    align-items: center;
}

.op-controls .form-control {
    min-width: 200px;
    flex: 1;
}

.system-ops-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--space-4);
}

.system-op-card {
    background: var(--neutral-50);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    text-align: center;
}

.system-op-card h3 {
    margin: 0 0 var(--space-2) 0;
    font-size: var(--text-base);
    font-weight: 600;
}

.system-op-card p {
    margin: 0 0 var(--space-4) 0;
    font-size: var(--text-sm);
    color: var(--neutral-600);
}

/* Analytics View Styles */
.analytics-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
    padding: var(--space-6);
}

.analytics-section {
    background: white;
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
}

.analytics-section h2 {
    margin: 0 0 var(--space-6) 0;
    color: var(--neutral-900);
    font-size: var(--text-xl);
    font-weight: 600;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
}

.metric-card {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    text-align: center;
    box-shadow: var(--shadow-md);
}

.metric-value {
    font-size: var(--text-3xl);
    font-weight: 700;
    margin-bottom: var(--space-2);
    font-variant-numeric: tabular-nums;
}

.metric-label {
    font-size: var(--text-sm);
    opacity: 0.9;
    font-weight: 500;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--space-6);
}

.chart-card {
    background: var(--neutral-50);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
}

.chart-card h3 {
    margin: 0 0 var(--space-4) 0;
    color: var(--neutral-900);
    font-size: var(--text-lg);
    font-weight: 600;
}

.chart-controls {
    margin-bottom: var(--space-4);
}

.chart-container {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: var(--space-3);
    color: var(--neutral-500);
}

.reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-6);
}

.report-card {
    background: var(--neutral-50);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
}

.report-card h3 {
    margin: 0 0 var(--space-4) 0;
    color: var(--neutral-900);
    font-size: var(--text-lg);
    font-weight: 600;
}

.report-content {
    color: var(--neutral-700);
}

/* Tag Management Styles */
.tag-stats-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: var(--space-4);
}

.tag-stats-table th,
.tag-stats-table td {
    padding: var(--space-3);
    text-align: left;
    border-bottom: 1px solid var(--neutral-200);
}

.tag-stats-table th {
    background: var(--neutral-100);
    font-weight: 600;
    color: var(--neutral-900);
}

.tag-stats-table .tag-name {
    font-weight: 500;
    color: var(--primary);
}

.tag-stats-table .tag-count {
    font-weight: 600;
    color: var(--neutral-900);
}

.tag-actions {
    display: flex;
    gap: var(--space-2);
}

.tag-action-btn {
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-sm);
    background: var(--neutral-50);
    color: var(--neutral-700);
    font-size: var(--text-xs);
    cursor: pointer;
    transition: var(--transition-base);
}

.tag-action-btn:hover {
    background: var(--neutral-200);
    border-color: var(--neutral-400);
}

.tag-action-btn.danger:hover {
    background: var(--error);
    color: white;
    border-color: var(--error);
}

/* Dark mode support for Manage/Analytics - Fixed v8.5.5 */
body.dark-mode .manage-section,
body.dark-mode .analytics-section {
    background: var(--neutral-100) !important;  /* Dark card background */
    color: var(--neutral-900) !important;  /* Light text */
}

body.dark-mode .manage-section h2,
body.dark-mode .analytics-section h2 {
    color: var(--neutral-900) !important;
}

body.dark-mode .bulk-op-card,
body.dark-mode .system-op-card,
body.dark-mode .chart-card,
body.dark-mode .report-card {
    background: var(--neutral-50) !important;  /* Darker nested card background */
    border-color: var(--neutral-200) !important;
    color: var(--neutral-900) !important;
}

body.dark-mode .bulk-op-card h3,
body.dark-mode .system-op-card h3,
body.dark-mode .chart-card h3,
body.dark-mode .report-card h3 {
    color: var(--neutral-900) !important;
}

body.dark-mode .bulk-op-card p,
body.dark-mode .system-op-card p,
body.dark-mode .chart-card p,
body.dark-mode .report-card p {
    color: var(--neutral-600) !important;
}

/* Activity Heatmap Styles */
.activity-heatmap {
    font-family: var(--font-mono);
}

.heatmap-stats {
    display: flex;
    gap: var(--space-6);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
    color: var(--neutral-600);
}

.heatmap-month {
    margin-bottom: var(--space-4);
}

.month-label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--neutral-700);
    margin-bottom: var(--space-2);
}

.month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--neutral-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.heatmap-cell {
    aspect-ratio: 1;
    background: var(--neutral-100);
    border: 1px solid var(--neutral-200);
    cursor: pointer;
    transition: var(--transition-base);
}

.heatmap-cell:hover {
    opacity: 0.8;
}

.heatmap-cell.empty {
    background: transparent;
    border: none;
}

.heatmap-cell.level-0 {
    background: var(--neutral-100);
}

.heatmap-cell.level-1 {
    background: #9be9a8;
}

.heatmap-cell.level-2 {
    background: #40c463;
}

.heatmap-cell.level-3 {
    background: #30a14e;
}

.heatmap-cell.level-4 {
    background: #216e39;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-4);
    font-size: var(--text-sm);
    color: var(--neutral-600);
}

.legend-cell {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

/* Enhanced Tags Report */
.enhanced-tags-report .report-period {
    font-size: var(--text-sm);
    color: var(--neutral-600);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--neutral-200);
}

.enhanced-tags-report .tags-list {
    list-style: none;
    padding: 0;
}

.enhanced-tags-report .tags-list li {
    padding: var(--space-3);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-2);
    background: white;
}

.enhanced-tags-report .tag-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
}

.enhanced-tags-report .tag-count {
    font-weight: 600;
    color: var(--primary);
}

.enhanced-tags-report .tag-cooccurrence {
    font-size: var(--text-sm);
    color: var(--neutral-600);
    font-style: italic;
}

/* Activity Breakdown */
.activity-breakdown .activity-summary {
    display: flex;
    gap: var(--space-6);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.activity-breakdown .activity-stat {
    font-size: var(--text-sm);
    color: var(--neutral-600);
}

.activity-breakdown .peak-times {
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
    color: var(--neutral-700);
}

.activity-breakdown .activity-chart {
    margin-top: var(--space-4);
}

.activity-bar-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
    padding: var(--space-2);
    background: var(--neutral-50);
    border-radius: var(--radius-sm);
}

.activity-label {
    min-width: 60px;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--neutral-700);
}

.activity-bar {
    flex: 1;
    height: 8px;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    border-radius: 4px;
    transition: var(--transition-base);
}

.activity-count {
    min-width: 30px;
    text-align: right;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--primary);
}

/* Storage Report */
.storage-report .storage-summary {
    display: flex;
    gap: var(--space-6);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.storage-report .storage-stat {
    font-size: var(--text-sm);
    color: var(--neutral-600);
}

.storage-report h4 {
    margin: var(--space-4) 0 var(--space-2) 0;
    color: var(--neutral-900);
    font-size: var(--text-lg);
    font-weight: 600;
}

.storage-report .largest-memories {
    list-style: none;
    padding: 0;
}

.storage-report .largest-memories li {
    padding: var(--space-3);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-2);
    background: white;
}

.storage-report .memory-size {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: var(--space-1);
}

.storage-report .memory-preview {
    font-size: var(--text-sm);
    color: var(--neutral-700);
    margin-bottom: var(--space-1);
    word-break: break-word;
}

.storage-report .memory-meta {
    font-size: var(--text-xs);
    color: var(--neutral-500);
}

/* Dark mode support for new analytics features */
body.dark-mode .heatmap-cell.level-0 {
    background: var(--neutral-200);
}

body.dark-mode .heatmap-cell.level-1 {
    background: #238636;
}

body.dark-mode .heatmap-cell.level-2 {
    background: #1a7f37;
}

body.dark-mode .heatmap-cell.level-3 {
    background: #0f5132;
}

body.dark-mode .heatmap-cell.level-4 {
    background: #033a16;
}

body.dark-mode .enhanced-tags-report .tags-list li,
body.dark-mode .activity-bar-row,
body.dark-mode .storage-report .largest-memories li {
    background: var(--neutral-100);
    border-color: var(--neutral-300);
    color: var(--neutral-900);
}

/* Form controls in Manage/Analytics dark mode */
body.dark-mode .bulk-op-card input,
body.dark-mode .bulk-op-card select,
body.dark-mode .chart-card input,
body.dark-mode .chart-card select,
body.dark-mode .manage-section .form-control,
body.dark-mode .analytics-section .form-control {
    background: var(--neutral-100) !important;
    border-color: var(--neutral-200) !important;
    color: var(--neutral-900) !important;
}

body.dark-mode .bulk-op-card input:focus,
body.dark-mode .bulk-op-card select:focus,
body.dark-mode .chart-card input:focus,
body.dark-mode .chart-card select:focus {
    border-color: var(--primary) !important;
    background: var(--neutral-50) !important;
}

/* Buttons in Manage/Analytics dark mode */
body.dark-mode .bulk-op-card .btn,
body.dark-mode .system-op-card .btn,
body.dark-mode .chart-card .btn {
    opacity: 1;
}

body.dark-mode .metric-card {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary)) !important;
    color: white !important;
}

body.dark-mode .metric-value,
body.dark-mode .metric-label {
    color: white !important;
}

/* Tag management table dark mode */
body.dark-mode .tag-stats-table {
    color: var(--neutral-900);
}

body.dark-mode .tag-stats-table th {
    background: var(--neutral-200) !important;
    color: var(--neutral-900) !important;
}

body.dark-mode .tag-stats-table td {
    border-bottom-color: var(--neutral-200) !important;
    color: var(--neutral-900) !important;
}

body.dark-mode .tag-stats-table .tag-name {
    color: var(--primary) !important;
}

body.dark-mode .tag-stats-table .tag-count {
    color: var(--neutral-900) !important;
}

/* Tag action buttons dark mode */
body.dark-mode .tag-action-btn {
    background: var(--neutral-200) !important;
    border-color: var(--neutral-300) !important;
    color: var(--neutral-900) !important;
}

body.dark-mode .tag-action-btn:hover {
    background: var(--neutral-300) !important;
    border-color: var(--neutral-400) !important;
}

body.dark-mode .tag-action-btn.danger:hover {
    background: var(--error) !important;
    color: white !important;
    border-color: var(--error) !important;
}

/* Simple Chart Styles */
.simple-chart {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    width: 100%;
    overflow: hidden;
}

.chart-header {
    font-weight: 600;
    margin-bottom: var(--space-4);
    color: var(--neutral-900);
}

.chart-row {
    display: flex;
    align-items: center;
    margin-bottom: var(--space-2);
    gap: var(--space-3);
    min-height: 24px;
    width: 100%;
    max-width: 100%;
}

.chart-bar {
    height: 18px;
    background: var(--primary);
    border-radius: var(--radius-sm);
    transition: width 0.3s ease;
    min-width: 10px;
    max-width: 200px;
    position: relative;
    flex-shrink: 0;
}

.chart-label {
    flex: 1;
    min-width: 0;
    color: var(--neutral-700);
    font-size: var(--text-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0) 100%);
    border-radius: var(--radius-sm);
}

.chart-value {
    min-width: 100px;
    text-align: right;
    color: var(--neutral-900);
    font-weight: 500;
    font-size: 1rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.chart-value small {
    color: var(--neutral-600);
    font-weight: 400;
    font-size: 0.9rem;
}

.tags-list, .activity-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tags-list li, .activity-list li {
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--neutral-200);
}

.tags-list li:last-child, .activity-list li:last-child {
    border-bottom: none;
}

.tags-list li strong {
    color: var(--primary);
}

/* Dark mode for charts - Fixed v8.5.5 contrast */
body.dark-mode .chart-label {
    color: #e5e5e5 !important;  /* Much brighter text for labels */
    font-weight: 500;  /* Slightly bolder for readability */
}

body.dark-mode .chart-value {
    color: #ffffff !important;  /* Pure white for maximum readability */
    font-weight: 600;  /* Slightly bolder in dark mode */
}

body.dark-mode .chart-value small {
    color: var(--neutral-300) !important;  /* Lighter text for small elements */
}

body.dark-mode .chart-bar {
    background: var(--primary) !important;
}

body.dark-mode .chart-container {
    color: var(--neutral-700) !important;  /* Loading/placeholder text */
}

body.dark-mode .tags-list li,
body.dark-mode .activity-list li {
    border-bottom-color: var(--neutral-200) !important;
    color: var(--neutral-900) !important;
}

body.dark-mode .tags-list li strong {
    color: var(--primary) !important;
}

body.dark-mode .activity-list li {
    color: var(--neutral-700) !important;
}

/* Dark mode: Document chunks modal */
body.dark-mode .modal-content .chunk-item {
    background: #1f2937 !important;
    border-color: #374151 !important;
}

body.dark-mode .modal-content .chunk-header {
    color: #f3f4f6 !important;
}

body.dark-mode .modal-content .chunk-content {
    color: #d1d5db !important;
}

body.dark-mode .modal-content .chunk-meta {
    color: #9ca3af !important;
}

body.dark-mode .modal-content .chunk-number {
    color: #60a5fa !important;
}

/* Document Management Features */
.upload-actions-container {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.upload-actions {
    display: flex;
    gap: var(--space-2);
}

.btn-icon {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-md);
    background: white;
    cursor: pointer;
    transition: all var(--transition-base);
    font-size: var(--text-sm);
    color: var(--neutral-700);
}

.btn-icon:hover {
    background: var(--neutral-50);
    border-color: var(--neutral-400);
    transform: translateY(-1px);
}

.btn-icon svg {
    flex-shrink: 0;
}

.btn-view-memory {
    color: var(--primary);
    border-color: var(--primary-light);
}

.btn-view-memory:hover {
    background: rgba(99, 102, 241, 0.05);
    border-color: var(--primary);
}

.btn-remove {
    color: var(--error);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-remove:hover {
    background: rgba(239, 68, 68, 0.05);
    border-color: var(--error);
}

/* Document Search Section */
.doc-search-container {
    display: flex;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.doc-search-container .search-input {
    flex: 1;
}

.doc-search-results {
    margin-top: var(--space-4);
}

.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 2px solid var(--neutral-200);
}

.search-results-header h3 {
    margin: 0;
    font-size: var(--text-lg);
    color: var(--neutral-900);
}

.results-count {
    color: var(--neutral-600);
    font-size: var(--text-sm);
}

.search-results-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.search-result-item {
    padding: var(--space-4);
    background: white;
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    transition: var(--transition-base);
}

.search-result-item:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--primary-light);
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
}

.result-header strong {
    color: var(--neutral-900);
}

.similarity-score {
    font-size: var(--text-sm);
    color: var(--primary);
    font-weight: 600;
}

.result-content {
    color: var(--neutral-700);
    margin-bottom: var(--space-3);
    line-height: 1.6;
}

.result-tags {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.section-description {
    color: var(--neutral-600);
    margin-bottom: var(--space-4);
}

/* Memory Viewer Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-4);
}

.memory-viewer-content {
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
}

.memory-viewer-content .modal-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--neutral-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.memory-viewer-content .modal-header h2 {
    margin: 0;
    font-size: var(--text-xl);
    color: var(--neutral-900);
}

.memory-viewer-content .modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    color: var(--neutral-500);
    padding: var(--space-2);
    border-radius: var(--radius-md);
    transition: var(--transition-base);
}

.memory-viewer-content .modal-close:hover {
    background: var(--neutral-100);
    color: var(--neutral-700);
}

.memory-viewer-content .modal-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-6);
}

.memory-viewer-content .modal-footer {
    padding: var(--space-6);
    border-top: 1px solid var(--neutral-200);
    display: flex;
    justify-content: flex-end;
}

.document-info {
    margin-bottom: var(--space-6);
}

.document-info h3 {
    margin: 0 0 var(--space-2) 0;
    color: var(--neutral-900);
    font-size: var(--text-lg);
}

.memory-chunks-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.memory-chunk-item {
    padding: var(--space-4);
    background: var(--neutral-50);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
}

.chunk-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--neutral-200);
}

.chunk-number {
    font-weight: 600;
    color: var(--primary);
    font-size: var(--text-sm);
}

.chunk-hash {
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: var(--text-xs);
    color: var(--neutral-500);
}

.chunk-tags {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* Dark Mode Support for New Components */
body.dark-mode .btn-icon {
    background: var(--neutral-200);
    border-color: var(--neutral-300);
    color: var(--neutral-900);
}

body.dark-mode .btn-icon:hover {
    background: var(--neutral-300);
}

body.dark-mode .search-result-item,
body.dark-mode .memory-chunk-item {
    background: var(--neutral-200);
    border-color: var(--neutral-300);
}

body.dark-mode .memory-viewer-content {
    background: var(--neutral-100);
}

body.dark-mode .section-description,
body.dark-mode .result-content {
    color: var(--neutral-300);
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .upload-actions-container {
        flex-direction: column;
        align-items: flex-start;
    }

    .upload-actions {
        width: 100%;
    }

    .btn-icon {
        flex: 1;
        justify-content: center;
    }

    .doc-search-container {
        flex-direction: column;
    }

    .memory-viewer-content {
        max-height: 95vh;
        margin: var(--space-2);
    }
}

/* ============================================
   Chunking Help Section Styles
   ============================================ */

.info-icon {
    cursor: pointer;
    font-size: 1.1em;
    margin-left: var(--space-1);
    opacity: 0.7;
    transition: all var(--transition-base);
    -webkit-user-select: none;
    user-select: none;
}

.info-icon:hover {
    opacity: 1;
    transform: scale(1.2);
}

.chunking-help {
    margin-top: var(--space-3);
    padding: var(--space-3);
    background: var(--neutral-50);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.help-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 2px solid var(--neutral-200);
    color: var(--neutral-800);
}

.help-header strong {
    font-size: 1.1em;
}

.close-help {
    background: none;
    border: none;
    font-size: 1.5em;
    color: var(--neutral-500);
    cursor: pointer;
    padding: 0 var(--space-2);
    line-height: 1;
    transition: color var(--transition-base);
}

.close-help:hover {
    color: var(--error);
}

.help-content {
    color: var(--neutral-700);
}

.help-note {
    background: var(--warning);
    background: linear-gradient(135deg, #fff3cd 0%, #fcf8e3 100%);
    border-left: 4px solid var(--warning);
    padding: var(--space-2);
    margin-bottom: var(--space-3);
    border-radius: var(--radius-base);
    font-size: 0.95em;
}

.help-recommendations {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.help-option {
    background: white;
    padding: var(--space-3);
    border-radius: var(--radius-base);
    border: 1px solid var(--neutral-200);
    transition: all var(--transition-base);
}

.help-option:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

.help-option-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
}

.help-option-header strong {
    color: var(--neutral-800);
}

.help-tag {
    background: var(--success);
    color: white;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.help-option p {
    margin: var(--space-1) 0;
    font-size: 0.9em;
    line-height: 1.5;
}

.help-option p strong {
    color: var(--neutral-700);
}

.help-tips {
    background: linear-gradient(135deg, #e0f2fe 0%, #dbeafe 100%);
    padding: var(--space-3);
    border-radius: var(--radius-base);
    border-left: 4px solid var(--primary);
}

.help-tips strong {
    color: var(--neutral-800);
    display: block;
    margin-bottom: var(--space-2);
}

.help-tips ul {
    margin: 0;
    padding-left: var(--space-4);
}

.help-tips li {
    margin: var(--space-1) 0;
    font-size: 0.9em;
    line-height: 1.6;
    color: var(--neutral-700);
}

.help-tips li strong {
    display: inline;
    color: var(--primary-dark);
    font-weight: 600;
}

/* Overlap Visual Diagram */
.help-example {
    margin: var(--space-3) 0;
    padding: var(--space-3);
    background: white;
    border-radius: var(--radius-base);
    border: 1px solid var(--neutral-200);
}

.help-example strong {
    display: block;
    margin-bottom: var(--space-2);
    color: var(--neutral-800);
}

.overlap-diagram {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.chunk-demo {
    display: flex;
    border-radius: var(--radius-base);
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chunk-part {
    padding: var(--space-2);
    font-family: monospace;
    font-size: 0.85em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
}

.chunk-part.unique {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    color: var(--primary-dark);
    flex: 1;
    border: 2px solid var(--primary);
}

.chunk-part.overlap {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
    flex: 0 0 35%;
    border: 2px solid var(--warning);
    font-weight: 600;
}

.chunk-demo:hover .chunk-part.overlap {
    background: linear-gradient(135deg, #fde68a 0%, #fbbf24 100%);
    transform: scale(1.02);
}

/* Mobile responsiveness for help section */
@media (max-width: 768px) {
    .chunking-help {
        padding: var(--space-2);
    }

    .help-option {
        padding: var(--space-2);
    }

    .help-tips {
        padding: var(--space-2);
    }

    .help-example {
        padding: var(--space-2);
    }

    .chunk-part {
        font-size: 0.75em;
        padding: var(--space-1);
    }

    .chunk-part.overlap {
        flex: 0 0 40%;
    }
}

```
Page 30/35FirstPrevNextLast