/* ==========================================================================
   GV-AI Agent — Capsid Index design system
   Flat, hairline-only (1px), monochrome, type-driven.
   Fonts: Bricolage Grotesque (display) · Inter (body) · Space Mono (mono labels)
   ========================================================================== */

:root {
  --bg: #ffffff;
  --fg: #0a0a0a;
  --hair: rgba(10, 10, 10, 0.16);
  --hair-soft: rgba(10, 10, 10, 0.05);
  --muted: rgba(10, 10, 10, 0.52);
  --guide: rgba(10, 10, 10, 0.035);

  --font-display: 'Bricolage Grotesque', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'Space Mono', 'Courier New', monospace;

  --maxw: 820px;
  --gutter: clamp(1.25rem, 4vw, 2.5rem);
  --ease: cubic-bezier(.16, 1, .3, 1);
  --t: .5s;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --fg: #fafafa;
  --hair: rgba(250, 250, 250, 0.18);
  --hair-soft: rgba(250, 250, 250, 0.06);
  --muted: rgba(250, 250, 250, 0.54);
  --guide: rgba(250, 250, 250, 0.05);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--fg) var(--bg);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}

/* Subtle 12-column grid background — matches the NeLLi main page */
.grid-guides { position: fixed; inset: 0; z-index: 0; pointer-events: none; display: flex; justify-content: center; opacity: 0; transition: opacity 1s var(--ease) .4s; }
.grid-guides.is-on { opacity: 1; }
.grid-guides .guide-inner { width: 100%; max-width: 1280px; margin: 0 clamp(1.25rem, 4vw, 3.5rem); display: grid; grid-template-columns: repeat(12, 1fr); }
.grid-guides span { border-left: 1px solid var(--guide); }
.grid-guides span:last-child { border-right: 1px solid var(--guide); }
@media (max-width: 900px) { .grid-guides { display: none; } }

/* Keep page content above the grid background */
main { position: relative; z-index: 1; }
.footer { position: relative; z-index: 1; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1;
}

a {
  color: inherit;
  text-decoration: none;
}

::selection {
  background: var(--fg);
  color: var(--bg);
}

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.6rem;
  z-index: 10000;
  transition: top 0.2s var(--ease);
}

.skip-link:focus {
  top: 1rem;
}

/* ==========================================================================
   Navigation
   ========================================================================== */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hair);
}

.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 clamp(1.25rem, 4vw, 3.5rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  gap: 1rem;
}

.nav-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  flex-shrink: 0;
}

.nav-logo {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.nav-links {
  display: flex;
  gap: clamp(0.4rem, 2.2vw, 1.6rem);
  list-style: none;
}

.nav-link {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.625rem;
  font-weight: 700;
  color: var(--muted);
  padding: 0.5rem 0;
  text-decoration: none;
  display: inline-flex;
  gap: 0.4em;
  align-items: baseline;
  transition: color 0.3s var(--ease);
}

.nav-link:hover,
.nav-link.is-active {
  color: var(--fg);
}

.nav-link-no {
  font-size: 0.5rem;
  opacity: 0.6;
}

.nav-utility {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

/* RAG status indicator — mono dot + label */
.rag-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.56rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

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

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

.status-dot.disconnected {
  background: var(--hair);
  box-shadow: inset 0 0 0 1px var(--muted);
}

.status-dot.connecting {
  background: var(--muted);
  animation: pulse-dot 1.4s var(--ease) infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.status-text {
  color: inherit;
}

.nav-clock {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.6rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0.3rem;
  cursor: pointer;
  transition: color 0.3s var(--ease);
}

.theme-toggle:hover {
  color: var(--fg);
}

.theme-toggle .ic-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .ic-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .ic-sun {
  display: inline-block;
}

@media (max-width: 980px) {
  .nav-links { display: none; }
}

@media (max-width: 620px) {
  .nav-clock { display: none; }
}

@media (max-width: 520px) {
  .rag-status .status-text { display: none; }
}

/* ==========================================================================
   Layout shell
   ========================================================================== */
main {
  flex: 1;
  display: flex;
  padding-top: 60px;
}

.chat-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0;
  min-height: calc(100vh - 60px);
}

/* ==========================================================================
   Agent header — static capsid glyph + title
   ========================================================================== */
.agent-header {
  padding: clamp(1.3rem, 3vw, 1.9rem) 0 1.3rem;
  border-bottom: 1px solid var(--hair);
}

.ah-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.agent-header .mark {
  width: 34px;
  height: 34px;
  flex: none;
  color: var(--fg);
}

.header-text {
  min-width: 0;
}

.agent-header h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.5rem, 3.6vw, 2.2rem);
  letter-spacing: -0.03em;
  line-height: 1.02;
  margin: 0;
}

.agent-header .sub {
  font-weight: 300;
  color: var(--muted);
  font-size: 1rem;
  margin-top: 0.4rem;
}

.clear-chat-btn {
  margin-left: auto;
  align-self: flex-start;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--muted);
  background: none;
  border: 1px solid var(--hair);
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  transition: color 0.25s var(--ease), border-color 0.25s var(--ease);
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  flex-shrink: 0;
}

.clear-chat-btn svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
}

.clear-chat-btn:hover {
  color: var(--fg);
  border-color: var(--fg);
}

/* ==========================================================================
   Chat container + messages
   ========================================================================== */
.chat-container {
  flex: 1;
  min-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2.2rem;
  padding: 2.2rem var(--gutter) 1.5rem;
}

.message {
  display: grid;
  gap: 1.1rem;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
}

.message.agent {
  grid-template-columns: 1fr;
}

.message.user {
  grid-template-columns: 1fr;
}

.message-avatar {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg);
  border: 1px solid var(--hair);
  border-radius: 50%;
  padding: 6px;
}

.message-avatar svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
}

/* No per-message capsid avatar — the headline glyph is the single brand mark */
.message-avatar {
  display: none;
}

.message-content {
  min-width: 0;
}

.message.user .message-content {
  border: 1px solid var(--hair);
  padding: 1rem 1.1rem;
  max-width: 46ch;
  margin-left: auto;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.message.user .message-header {
  justify-content: flex-end;
}

.message-author {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.56rem;
  color: var(--muted);
}

.message-copy-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--hair);
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.52rem;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.message-copy-btn svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
}

.message-copy-btn:hover {
  color: var(--fg);
  border-color: var(--fg);
}

.message-copy-btn.is-copied {
  color: var(--fg);
  border-color: var(--fg);
}

.message-body {
  font-weight: 300;
  font-size: 1rem;
  line-height: 1.62;
  color: var(--fg);
}

.message.user .message-body {
  font-weight: 300;
}

.message-body strong {
  font-weight: 500;
}

.message-body h1,
.message-body h2,
.message-body h3,
.message-body h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.15;
  margin: 1.3rem 0 0.6rem;
  color: inherit;
}

.message-body h1 { font-size: 1.3rem; }
.message-body h2 { font-size: 1.18rem; }
.message-body h3 { font-size: 1.08rem; }
.message-body h4 { font-size: 0.98rem; }

.message-body > :first-child {
  margin-top: 0;
}

.message-body p {
  margin: 0 0 0.8rem;
  max-width: 64ch;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-body ul,
.message-body ol {
  margin: 0.75rem 0;
  padding-left: 1.3rem;
  max-width: 64ch;
}

.message-body li {
  margin-bottom: 0.4rem;
}

.message-body a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--hair);
  transition: text-decoration-color 0.2s var(--ease);
}

.message-body a:hover {
  text-decoration-color: var(--fg);
}

/* inline code + kbd */
.message-body code,
kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.08rem 0.35rem;
  border: 1px solid var(--hair);
  background: var(--hair-soft);
  color: var(--fg);
}

.message-body pre {
  margin: 0.9rem 0;
  padding: 0.95rem 1.05rem;
  border: 1px solid var(--hair);
  background: var(--hair-soft);
  overflow-x: auto;
  max-width: 100%;
}

.message-body pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: 0.82rem;
  line-height: 1.55;
}

/* tables → hairline grammar */
.message-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.88rem;
}

.message-body th,
.message-body td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--hair);
  text-align: left;
  vertical-align: top;
}

.message-body thead th {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.56rem;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 1px solid var(--fg);
}

.message-body tbody tr:last-child td {
  border-bottom: 1px solid var(--hair);
}

/* ==========================================================================
   Suggestion chips
   ========================================================================== */
.suggestion-list {
  list-style: none;
  padding: 0;
  margin: 1.1rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.suggestion-btn {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.58rem;
  color: var(--muted);
  background: none;
  border: 1px solid var(--hair);
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
  text-align: left;
}

.suggestion-btn:hover {
  color: var(--fg);
  border-color: var(--fg);
}

/* ==========================================================================
   Loading state
   ========================================================================== */
.loading-container {
  display: flex;
  justify-content: center;
  padding: 1rem 0;
}

.loading-content {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.58rem;
  color: var(--muted);
}

.loading-spinner {
  position: relative;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.spinner-ring {
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.spinner-ring:nth-child(2) {
  inset: 4px;
  border-top-color: var(--muted);
  animation-delay: -0.3s;
}

.spinner-ring:nth-child(3) {
  inset: 8px;
  border-top-color: var(--hair);
  animation-delay: -0.6s;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: var(--muted);
}

.loading-cancel {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.56rem;
  font-weight: 700;
  color: var(--muted);
  background: none;
  border: 1px solid var(--hair);
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.loading-cancel svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
}

.loading-cancel:hover {
  color: var(--fg);
  border-color: var(--fg);
}

/* ==========================================================================
   Input area (composer)
   ========================================================================== */
.input-area {
  position: sticky;
  bottom: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--hair);
  padding: 1rem var(--gutter) 1.4rem;
}

.staged-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  max-width: var(--maxw);
  margin: 0 auto 0.75rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--hair);
}

.staged-file-info {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.56rem;
  color: var(--muted);
  min-width: 0;
}

.staged-file-info svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  flex-shrink: 0;
}

.staged-file-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.staged-file-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--hair);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.staged-file-remove svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
}

.staged-file-remove:hover {
  color: var(--fg);
  border-color: var(--fg);
}

.input-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: var(--maxw);
  margin: 0 auto;
  border: 1px solid var(--hair);
  padding: 0.3rem 0.3rem 0.3rem 0.9rem;
}

.input-wrapper {
  flex: 1;
  min-width: 0;
}

#messageInput {
  width: 100%;
  min-height: 24px;
  max-height: 200px;
  padding: 0.6rem 0;
  border: none;
  background: none;
  color: var(--fg);
  resize: none;
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.5;
}

#messageInput::placeholder {
  color: var(--muted);
}

#messageInput:focus {
  outline: none;
}

/* control buttons in composer */
.input-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  background: none;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.input-btn svg {
  stroke: currentColor;
}

/* attach + stop: hairline ghost buttons */
.attach-btn,
.stop-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--hair);
  color: var(--muted);
}

.attach-btn svg,
.stop-btn svg {
  width: 16px;
  height: 16px;
}

.attach-btn:hover,
.stop-btn:hover {
  color: var(--fg);
  border-color: var(--fg);
}

/* send: solid fg block, mono feel */
.send-btn {
  height: 38px;
  padding: 0 1rem;
  border: 1px solid var(--fg);
  background: var(--fg);
  color: var(--bg);
}

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

.send-btn:hover {
  background: var(--fg);
  color: var(--bg);
  opacity: 0.85;
}

.send-btn:disabled,
.input-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.input-hints {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: var(--maxw);
  margin: 0.7rem auto 0;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.52rem;
  color: var(--muted);
}

.input-hints kbd {
  text-transform: none;
  letter-spacing: 0;
}

.hint-separator {
  color: var(--hair);
}

/* ==========================================================================
   Debug info (collapsible) — restyled to mono/hairline
   ========================================================================== */
details.debug-info {
  margin-top: 1.2rem;
  border-top: 1px solid var(--hair);
  padding-top: 0.6rem;
}

details.debug-info summary {
  cursor: pointer;
  padding: 0.25rem 0;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.56rem;
  color: var(--muted);
  list-style: none;
  transition: color 0.2s var(--ease);
}

details.debug-info summary:hover {
  color: var(--fg);
}

details.debug-info summary::-webkit-details-marker {
  display: none;
}

details.debug-info summary::before {
  content: '+ ';
}

details.debug-info[open] summary::before {
  content: '– ';
}

details.debug-info pre {
  margin: 0.6rem 0 0;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--hair);
  background: var(--hair-soft);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.5;
  overflow-x: auto;
}

/* ==========================================================================
   Plotly figures
   ========================================================================== */
.plotly-figure-card {
  margin-top: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--hair);
  background: transparent;
}

.plotly-figure {
  width: 100%;
  min-height: 420px;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.footer {
  border-top: 1px solid var(--hair);
  padding: 1.4rem 0;
}

.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 clamp(1.25rem, 4vw, 3.5rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.6rem;
  color: var(--muted);
}

.footer-mark {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--fg);
  letter-spacing: -0.01em;
}

/* ==========================================================================
   Scrollbars
   ========================================================================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

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

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

* {
  scrollbar-width: thin;
  scrollbar-color: var(--hair) var(--bg);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 680px) {
  .ah-row {
    flex-wrap: wrap;
  }

  .clear-chat-btn {
    margin-left: 0;
  }

  .clear-chat-label {
    display: none;
  }

  .chat-container,
  .input-area {
    padding-left: var(--gutter);
    padding-right: var(--gutter);
  }

  .input-hints {
    display: none;
  }

  .message.user .message-content {
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root { --t: 0s; }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
