/* Sara Brain — Web App Styles */

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --accent-dim: #1f6feb;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --concept-color: #a8d8ea;
  --property-color: #ffcfdf;
  --relation-color: #fefdca;
  --association-color: #c4b5fd;
  --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas",
    monospace;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-mono);
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ── Loading Screen ── */

#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  transition: opacity 0.5s ease;
}

#loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.loading-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.progress-container {
  width: 320px;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 3px;
  transition: width 0.3s ease;
}

.loading-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── App Layout ── */

#app {
  display: none;
  height: 100vh;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr auto;
  gap: 0;
}

#app.visible {
  display: grid;
}

/* ── Header ── */

.header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.header-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-title .brain-icon {
  font-size: 1.2rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
  background: var(--border);
}

.btn-accent {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.btn-accent:hover {
  background: var(--accent-dim);
  color: #fff;
}

/* ── REPL Panel ── */

.repl-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.repl-output {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.repl-output .cmd-line {
  color: var(--accent);
}

.repl-output .cmd-output {
  color: var(--text-secondary);
}

.repl-output .cmd-error {
  color: var(--red);
}

.repl-output .welcome {
  color: var(--text-muted);
}

.repl-input-container {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 0.5rem 0.75rem;
}

.repl-prompt {
  color: var(--green);
  font-size: 0.8rem;
  margin-right: 0.5rem;
  user-select: none;
}

.repl-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: transparent;
  border: none;
  color: var(--text-primary);
  outline: none;
  caret-color: var(--accent);
}

/* ── Graph Panel ── */

.graph-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.graph-legend {
  display: flex;
  gap: 1rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.concept {
  background: var(--concept-color);
}
.legend-dot.property {
  background: var(--property-color);
}
.legend-dot.relation {
  background: var(--relation-color);
}
.legend-dot.association {
  background: var(--association-color);
}

#graph-container {
  flex: 1;
  background: var(--bg-primary);
  position: relative;
}

#graph-container svg {
  display: block;
}

.graph-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  pointer-events: none;
}

/* ── Detail Panel (Bottom) ── */

.detail-panel {
  grid-column: 1 / -1;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  max-height: 180px;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-secondary);
  white-space: pre-wrap;
}

.detail-panel .detail-label {
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

/* ── Vision Panel ── */

.vision-panel {
  grid-column: 1 / -1;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
}

.vision-section {
  margin-bottom: 0.25rem;
}

.vision-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.vision-spacer {
  flex: 1;
}

.vision-hint {
  font-size: 0.75rem;
  opacity: 0.6;
  font-style: italic;
}

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

.status-dot.connected {
  background: var(--green);
}

.vision-instructions {
  color: var(--text-muted);
  font-size: 0.7rem;
  margin-bottom: 0.35rem;
}

.vision-instructions code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 3px;
}

.vision-panel input {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  padding: 0.25rem 0.5rem;
}

.vision-panel input[type="password"] {
  width: 160px;
}

.vision-panel input[type="text"] {
  width: 220px;
}

.vision-panel label {
  color: var(--text-muted);
}

.source-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.7rem;
}

.source-link:hover {
  text-decoration: underline;
}

/* Perception output phases */
.perception-phase {
  color: var(--yellow);
}

.perception-obs {
  color: var(--green);
}

/* ── Code Viewer Modal ── */

.code-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
}

.code-modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.code-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.code-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  font-size: 0.7rem;
  line-height: 1.5;
  color: var(--text-primary);
  margin: 0;
}

/* ── Scrollbar ── */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border);
}

/* ── Docs Modal ── */

.docs-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
}

.docs-modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 92%;
  max-width: 960px;
  height: 80vh;
  display: flex;
  overflow: hidden;
}

.docs-modal-sidebar {
  width: 240px;
  min-width: 240px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

.docs-modal-title {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.docs-sidebar-section-label {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.docs-changelog {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.75rem 0.75rem;
}

.changelog-entry {
  padding: 0.5rem 0.5rem;
  border-left: 2px solid var(--border);
  margin-bottom: 0.25rem;
  padding-left: 0.75rem;
}

.changelog-entry.changelog-current {
  border-left-color: var(--accent);
}

.changelog-version {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 2px;
}

.changelog-badge {
  font-size: 0.55rem;
  font-weight: 400;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 1px 5px;
  border-radius: 3px;
}

.changelog-date {
  font-size: 0.6rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: auto;
}

.changelog-summary {
  font-size: 0.6rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.docs-modal-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.docs-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

.docs-header-actions {
  display: flex;
  gap: 0.5rem;
}

.docs-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  font-size: 0.75rem;
  line-height: 1.7;
  color: var(--text-primary);
}

.docs-placeholder {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding-top: 3rem;
}

/* Docs rendered content */
.docs-modal-body h1 { font-size: 1.3rem; margin: 1.5rem 0 0.75rem; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.docs-modal-body h2 { font-size: 1rem; margin: 1.25rem 0 0.5rem; color: var(--text-primary); }
.docs-modal-body h3 { font-size: 0.85rem; margin: 1rem 0 0.4rem; color: var(--text-secondary); }
.docs-modal-body h4 { font-size: 0.75rem; margin: 0.75rem 0 0.3rem; color: var(--text-muted); font-weight: 700; }
.docs-modal-body p { margin-bottom: 0.6rem; }
.docs-modal-body ul, .docs-modal-body ol { margin: 0.4rem 0 0.6rem 1.5rem; }
.docs-modal-body li { margin-bottom: 0.2rem; }
.docs-modal-body blockquote {
  border-left: 3px solid var(--accent-dim);
  padding: 0.5rem 1rem;
  margin: 0.75rem 0;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border-radius: 0 4px 4px 0;
  font-style: italic;
}
.docs-modal-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.docs-modal-body a { color: var(--accent); text-decoration: none; }
.docs-modal-body a:hover { text-decoration: underline; }
.docs-modal-body strong { color: var(--text-primary); }

.docs-code {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem 1rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  font-size: 0.7rem;
  line-height: 1.5;
}

.docs-inline-code {
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.7rem;
}

.docs-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.7rem;
}

.docs-table th, .docs-table td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  text-align: left;
}

.docs-table th {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 700;
}

.docs-table td {
  color: var(--text-primary);
}

@media (max-width: 700px) {
  .docs-modal-content {
    flex-direction: column;
    width: 98%;
    height: 90vh;
  }
  .docs-modal-sidebar {
    width: 100%;
    min-width: 0;
    max-height: 30%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

/* ── Mode Toggle ── */

.mode-toggle {
  display: flex;
  gap: 0;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.mode-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn:first-child {
  border-radius: 4px 0 0 4px;
}

.mode-btn:last-child {
  border-radius: 0 4px 4px 0;
  border-left: none;
}

.mode-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.mode-btn:hover:not(.active) {
  color: var(--text-secondary);
}

/* ── Guided Container ── */

.guided-container {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.guided-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.guided-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.guided-btn {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}

.guided-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.guided-btn:hover .guided-btn-hint {
  opacity: 1;
}

.guided-btn-hint {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.6rem;
  color: var(--text-muted);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 10;
  margin-top: 4px;
}

.guided-btn--followup {
  border-color: var(--yellow);
  color: var(--yellow);
}

.guided-btn--followup:hover {
  background: rgba(210, 153, 34, 0.15);
  color: var(--text-primary);
}

/* ── Guided Flow Panel ── */

.guided-flow {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  margin-top: 0.5rem;
}

.guided-flow-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.guided-flow-title {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
}

.guided-flow-input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  padding: 0.4rem 0.5rem;
  margin-bottom: 0.25rem;
  outline: none;
  caret-color: var(--accent);
}

.guided-flow-input:focus {
  border-color: var(--accent-dim);
}

.guided-flow-hint {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.guided-flow-actions {
  display: flex;
  gap: 0.5rem;
}

.guided-flow-progress {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.guided-flow-status {
  font-size: 0.7rem;
  color: var(--yellow);
}

/* ── Panel Tabs (Graph / Image) ── */

.panel-tabs {
  display: flex;
  gap: 0;
}

.panel-tab {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.panel-tab:first-child {
  border-radius: 4px 0 0 4px;
}

.panel-tab:last-child {
  border-radius: 0 4px 4px 0;
  border-left: none;
}

.panel-tab.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.panel-tab:hover:not(.active) {
  color: var(--text-secondary);
}

/* ── Image Viewer ── */

#image-viewer-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.iv-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  max-height: 80px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
}

.iv-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 10px;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.iv-label.visible {
  opacity: 1;
  transform: scale(1);
}

.iv-label--initial {
  background: rgba(63, 185, 80, 0.2);
  color: var(--green);
  border: 1px solid rgba(63, 185, 80, 0.3);
}

.iv-label--directed-1,
.iv-label--directed-2,
.iv-label--directed-3 {
  background: rgba(88, 166, 255, 0.2);
  color: var(--accent);
  border: 1px solid rgba(88, 166, 255, 0.3);
}

.iv-label--verification {
  background: rgba(210, 153, 34, 0.2);
  color: var(--yellow);
  border: 1px solid rgba(210, 153, 34, 0.3);
}

.iv-label--region {
  background: rgba(196, 181, 253, 0.2);
  color: var(--association-color);
  border: 1px solid rgba(196, 181, 253, 0.3);
}

.iv-canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
}

.iv-canvas-area canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#iv-image-canvas {
  z-index: 1;
}

#iv-overlay-canvas {
  z-index: 2;
  cursor: crosshair;
}

.iv-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  pointer-events: none;
  z-index: 3;
}

.iv-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.iv-tool-btn {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.iv-tool-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.iv-tool-btn:hover:not(.active) {
  color: var(--text-secondary);
}

.iv-coords {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* ── Responsive ── */

@media (max-width: 800px) {
  #app.visible {
    grid-template-columns: 1fr;
    grid-template-rows: auto 2fr 3fr auto;
  }

  .repl-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .header-actions {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .graph-legend {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .detail-panel {
    grid-column: 1;
    max-height: 120px;
  }
}

@media (max-width: 480px) {
  .header-title {
    font-size: 0.85rem;
  }

  .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.65rem;
  }

  .legend-item span {
    font-size: 0.65rem;
  }

  .repl-prompt {
    font-size: 0.7rem;
  }

  .repl-input {
    font-size: 0.7rem;
  }
}

/* ── Ask Sara Suggestion Chips ── */

.guided-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.25rem;
}

.guided-suggestion-chip {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--accent-dim);
  border-radius: 12px;
  background: rgba(31, 111, 235, 0.1);
  color: var(--accent);
  cursor: pointer;
  transition: all 0.15s ease;
}

.guided-suggestion-chip:hover {
  background: var(--accent-dim);
  color: #fff;
}
