/* ==========================================================================
   Synapse — premium light identity & responsive layout
   Concept: a luminous observatory for your thinking. Warm off-white void,
   frosted-glass panels, metallic node accents, lead-gray crisp connections.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --void: #f4f5f9;
  --void-rgb: 244, 245, 249;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --panel-border: rgba(0, 0, 0, 0.08);
  --panel-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  --panel-shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.06);
  --ink: #0f172a;
  --ink-secondary: #334155;
  --ink-dim: #64748b;
  --ink-faint: #94a3b8;
  --accent-cool: #2563eb;
  --accent-cool-light: #dbeafe;
  --accent-violet: #7c3aed;
  --accent-violet-light: #ede9fe;
  --accent-amber: #d97706;
  --accent-amber-light: #fef3c7;
  --accent-rose: #e11d48;
  --accent-emerald: #059669;
  --gradient-primary: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --blur: blur(20px);
  --transition-smooth: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html, body {
  height: 100%;
  width: 100%;
  background: var(--void);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  z-index: 20;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--panel-border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.03);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.brand-mark {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--gradient-primary);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.5);
  animation: brand-pulse 3s ease-in-out infinite;
}
@keyframes brand-pulse {
  0%, 100% { box-shadow: 0 0 12px rgba(99, 102, 241, 0.5); }
  50% { box-shadow: 0 0 20px rgba(99, 102, 241, 0.8); }
}
.brand-mark.large {
  width: 28px; height: 28px;
  box-shadow: 0 0 30px rgba(99, 102, 241, 0.6);
}
.brand-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  color: var(--ink-dim);
  background: var(--accent-cool-light);
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---------- Search bar ---------- */
#search-bar {
  flex: 1;
  max-width: 320px;
  margin-left: auto;
  position: relative;
}
#search-bar input {
  width: 100%;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 14px 8px 36px;
  color: var(--ink);
  font-size: 13px;
  font-family: "Inter", sans-serif;
  transition: all 0.2s var(--transition-smooth);
}
#search-bar input:focus {
  outline: none;
  border-color: var(--accent-cool);
  background: white;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
#search-bar input::placeholder { color: var(--ink-faint); }
#search-bar .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-faint);
  font-size: 14px;
  pointer-events: none;
}

#reset-view-btn { margin-left: 6px; flex-shrink: 0; }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--gradient-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s var(--transition-smooth);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
  white-space: nowrap;
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.4);
}
.btn-primary:active { transform: translateY(0) scale(0.98); }
.btn-primary.small { padding: 7px 12px; font-size: 12px; }

.btn-ghost {
  background: rgba(0, 0, 0, 0.03);
  color: var(--ink-secondary);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--transition-smooth);
  white-space: nowrap;
}
.btn-ghost:hover {
  border-color: var(--accent-cool);
  color: var(--accent-cool);
  background: var(--accent-cool-light);
}
.btn-ghost.small { padding: 4px 10px; font-size: 11px; }

.btn-icon {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.03);
  color: var(--ink-dim);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.btn-icon:hover { color: var(--ink); border-color: var(--ink-faint); background: rgba(0,0,0,0.06); }
.btn-icon.accept:hover { color: var(--accent-emerald); border-color: var(--accent-emerald); background: rgba(5, 150, 105, 0.08); }
.btn-icon.dismiss:hover { color: var(--accent-rose); border-color: var(--accent-rose); background: rgba(225, 29, 72, 0.08); }

/* ---------- Scene ---------- */
#scene-container {
  position: absolute;
  inset: 0;
}
#scene-container canvas { display: block; }

/* ---------- Side panel ---------- */
#side-panel {
  position: absolute;
  top: 72px;
  right: 20px;
  width: min(340px, calc(100vw - 40px));
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  z-index: 15;
  box-shadow: var(--panel-shadow-lg);
  transition: opacity 0.25s var(--transition-smooth), transform 0.25s var(--transition-smooth);
}
#side-panel.hidden {
  opacity: 0;
  transform: translateX(16px) scale(0.98);
  pointer-events: none;
}
#close-panel-btn {
  position: absolute;
  top: 12px; right: 12px;
  background: rgba(0,0,0,0.04);
  border: none;
  color: var(--ink-faint);
  font-size: 18px;
  cursor: pointer;
  width: 26px; height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
#close-panel-btn:hover { color: var(--ink); background: rgba(0,0,0,0.08); }

.panel-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; margin-right: 24px; }
.tag-pill {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  color: var(--accent-violet);
  background: var(--accent-violet-light);
  border-radius: 20px;
  padding: 3px 10px;
}
#panel-content h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 10px;
  line-height: 1.3;
  color: var(--ink);
}
.panel-body {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-secondary);
  margin: 0 0 20px;
}
.panel-section-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin-bottom: 8px;
}
.related-list { display: flex; flex-direction: column; gap: 6px; }
.related-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  cursor: pointer;
  text-align: left;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.related-item:hover {
  border-color: var(--accent-cool);
  background: var(--accent-cool-light);
  transform: translateX(2px);
}
.related-score {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  color: var(--accent-cool);
  background: var(--accent-cool-light);
  padding: 2px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}

/* ---------- Suggestions tray ---------- */
#suggestions-tray {
  position: absolute;
  left: 20px;
  bottom: 20px;
  width: min(350px, calc(100vw - 40px));
  max-height: calc(50vh - 60px);
  overflow-y: auto;
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 0;
  z-index: 15;
  box-shadow: var(--panel-shadow-lg);
  transition: opacity 0.25s var(--transition-smooth), transform 0.25s var(--transition-smooth);
}
#suggestions-tray.hidden { opacity: 0; transform: translateY(10px); pointer-events: none; }
#suggestions-tray::before {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-amber), var(--accent-rose), var(--accent-violet));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.tray-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-amber);
  padding: 12px 14px 0;
  margin-bottom: 8px;
}
.suggestion-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--panel-border);
  font-size: 12px;
}
.suggestion-row:last-child { border-bottom: none; margin-bottom: 6px; }
.suggestion-pair {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  min-width: 0;
}
.suggestion-pair span:not(.suggestion-arrow) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 105px;
  font-weight: 500;
}
.suggestion-arrow { color: var(--ink-faint); flex-shrink: 0; }
.suggestion-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.suggestion-score {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  color: var(--accent-amber);
  background: var(--accent-amber-light);
  padding: 2px 6px;
  border-radius: 10px;
}

/* ---------- Agent dock (Fixed sizing & contained layout) ---------- */
#agent-dock {
  position: absolute;
  right: 20px;
  bottom: 20px;
  width: min(350px, calc(100vw - 40px));
  max-height: calc(100vh - 90px);
  height: min(400px, calc(100vh - 90px));
  display: flex;
  flex-direction: column;
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  z-index: 15;
  overflow: hidden;
  box-shadow: var(--panel-shadow-lg);
}
#agent-dock::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gradient-primary);
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  z-index: 2;
}

.agent-dock-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--panel-border);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255,255,255,0.7);
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
}
.agent-dock-header:active { cursor: grabbing; }

.btn-dock-control {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--panel-border);
  color: var(--ink-secondary);
  border-radius: 6px;
  width: 22px;
  height: 22px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.btn-dock-control:hover {
  background: var(--accent-violet-light);
  color: var(--accent-violet);
  border-color: var(--accent-violet);
}

#agent-dock.minimized {
  height: 46px !important;
  min-height: 46px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
#agent-dock.minimized #agent-log,
#agent-dock.minimized #agent-form,
#agent-dock.minimized .agent-suggestions {
  display: none !important;
}
.agent-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gradient-primary);
  box-shadow: 0 0 10px rgba(124, 58, 237, 0.6);
  animation: agent-pulse 2s ease-in-out infinite;
}
@keyframes agent-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.7; }
}
#agent-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.agent-msg {
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 90%;
  padding: 9px 12px;
  border-radius: 12px;
  animation: msg-in 0.2s var(--transition-smooth);
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.agent-msg-assistant {
  background: rgba(124, 58, 237, 0.08);
  border: 1px solid rgba(124, 58, 237, 0.12);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
  color: var(--ink-secondary);
}
.agent-msg-user {
  background: var(--gradient-primary);
  color: #ffffff;
  align-self: flex-end;
  border-bottom-right-radius: 3px;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}
.agent-tool-chip {
  align-self: flex-start;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  color: var(--accent-amber);
  background: var(--accent-amber-light);
  border-radius: 6px;
  padding: 3px 8px;
}
#agent-form {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.6);
  flex-shrink: 0;
}
#agent-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
  font-size: 12.5px;
  font-family: "Inter", sans-serif;
  min-width: 0;
}
#agent-input:focus { outline: none; border-color: var(--accent-cool); background: white; }
#agent-input::placeholder { color: var(--ink-faint); }

.agent-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 12px 10px;
  flex-shrink: 0;
}
.quick-prompt {
  font-size: 10.5px;
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 4px 10px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s ease;
}
.quick-prompt:hover {
  border-color: var(--accent-violet);
  color: var(--accent-violet);
  background: var(--accent-violet-light);
}

/* ---------- Keyboard shortcuts ---------- */
#shortcuts-panel {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  z-index: 25;
  box-shadow: var(--panel-shadow-lg);
  min-width: 280px;
  transition: all 0.2s var(--transition-smooth);
  opacity: 0;
  pointer-events: none;
}
#shortcuts-panel.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
#shortcuts-panel h3 {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--ink);
}
.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 12px;
  color: var(--ink-secondary);
}
.shortcut-key {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  background: rgba(0,0,0,0.06);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 2px 7px;
  color: var(--ink);
}

/* ---------- WebMCP badge ---------- */
#webmcp-badge {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  color: var(--ink-dim);
  background: var(--panel);
  backdrop-filter: var(--blur);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 4px 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  white-space: nowrap;
}

/* ---------- New Note Modal ---------- */
.modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  transition: opacity 0.25s ease;
}
.modal-overlay.hidden { opacity: 0; pointer-events: none; }

.modal-card {
  width: min(440px, calc(100vw - 32px));
  background: var(--panel-solid);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--panel-shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.modal-header h3 { font-size: 17px; font-weight: 700; color: var(--ink); }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-secondary);
}
.form-group input, .form-group textarea {
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: "Inter", sans-serif;
  color: var(--ink);
  transition: all 0.2s ease;
}
.form-group input:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent-cool);
  background: white;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
#webmcp-badge .badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 6px rgba(5, 150, 105, 0.6);
  animation: agent-pulse 2s ease-in-out infinite;
}

/* ---------- Intro overlay ---------- */
#intro-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(
    ellipse 120% 100% at 50% 40%,
    rgba(79, 70, 229, 0.1),
    rgba(var(--void-rgb), 0.96) 70%
  );
  transition: opacity 0.5s var(--transition-smooth);
}
#intro-overlay.hidden { opacity: 0; pointer-events: none; }
.intro-card {
  text-align: center;
  max-width: 460px;
  padding: 40px 36px;
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--panel-shadow-lg);
}
.intro-card h1 {
  font-size: 34px;
  font-weight: 800;
  margin: 16px 0 12px;
  letter-spacing: -0.02em;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.intro-card p {
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink-secondary);
  margin: 0 0 28px;
}
.intro-card .intro-features {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-bottom: 24px;
}
.intro-feature {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-dim);
  font-weight: 500;
}
.intro-feature-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  #side-panel { width: calc(100vw - 40px); top: 68px; }
  #agent-dock { width: calc(100vw - 40px); left: 20px; right: 20px; height: 280px; }
  #suggestions-tray { width: calc(100vw - 40px); bottom: 310px; }
  #search-bar { max-width: 180px; }
  #webmcp-badge { display: none; }
}
