/* ─────────────────────────────────────────────────────────
   Never Ask Twice — Memory Surface V1
   Design system: Geist variable fonts (self-hosted), one
   accent (#4ADE80 = memory green), two motion verbs only.
   ───────────────────────────────────────────────────────── */

/* ── Fonts ─────────────────────────────────────────────── */
@font-face {
  font-family: 'Geist';
  src: url('/static/fonts/Geist-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'GeistMono';
  src: url('/static/fonts/GeistMono-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ── Design tokens ─────────────────────────────────────── */
:root {
  /* Surfaces — pure zinc off-black (canonical, no blue hue) */
  --bg:            #0A0A0A;
  --surface:       #111111;
  --surface-raise: #1A1A1A;
  --surface-glass: rgba(10,10,10,0.85);
  --border:        #27272A;
  --border-strong: #3F3F46;

  /* Memory green — the ONLY accent; reserved for memory operations */
  --memory:        #4ADE80;
  --memory-dim:    hsla(142, 71%, 45%, 0.18);
  --memory-glow:   hsla(142, 71%, 45%, 0.35);
  --vk-glow-hair:  rgba(74,222,128,0.35);

  /* Semantic trace row (recalled fact) */
  --trace-semantic-border: hsla(142, 71%, 45%, 0.4);
  --trace-semantic-bg:     hsla(142, 71%, 45%, 0.06);

  /* Episodic trace row (event written) — zinc, no blue */
  --trace-episodic-border: rgba(63,63,70,0.6);
  --trace-episodic-bg:     rgba(17,17,17,0.6);

  /* Working pip — amber, only non-final state */
  --amber:         #F59E0B;
  --amber-dim:     hsla(38, 92%, 50%, 0.18);

  /* Text — zinc ramp */
  --text:          #FAFAFA;
  --text-muted:    #A1A1AA;
  --text-faint:    #71717A;

  /* Shadow system */
  --shadow-glow:   0 0 0 3px rgba(74,222,128,0.10);

  /* Primary (purple — UI chrome only, not memory) */
  --primary:       hsl(258, 74%, 64%);
  --primary-glow:  hsla(258, 74%, 64%, 0.18);

  /* Brand alias — maps to memory green so brand.js components resolve */
  --brand-green:   var(--memory);

  /* Type ramp */
  --font-sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'GeistMono', 'SF Mono', 'Fira Code', monospace;
  --text-2xs:  0.65rem;
  --text-xs:   0.72rem;
  --text-sm:   0.82rem;
  --text-base: 0.92rem;
  --text-lg:   1.05rem;
  --text-xl:   1.3rem;
  --text-2xl:  1.6rem;

  /* Spacing scale */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  background: var(--bg);
  background-image:
    radial-gradient(900px 500px at 88% -4%, rgba(74,222,128,0.05), transparent 60%),
    linear-gradient(rgba(255,255,255,0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.018) 1px, transparent 1px);
  background-size: 100% 100%, 64px 64px, 64px 64px;
  background-position: 0 0, 0 0, 0 0;
  color: var(--text);
  line-height: 1.55;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: #050505; }
::-webkit-scrollbar-thumb { background: #27272A; border-radius: 999px; border: 3px solid #050505; }

/* ── App layout ────────────────────────────────────────── */
.app-container {
  display: grid;
  grid-template-columns: 300px 1fr 380px; /* trace panel wider for visual primacy */
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "header header header"
    "nav    main   side";
  height: 100vh;
  background: transparent; /* grid lives on body */
}

/* ── Header ────────────────────────────────────────────── */
header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-6);
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  overflow: visible; /* allow tooltips, but children must stay inside header */
}

header .chat-controls {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
}

header .chat-controls > * {
  flex-shrink: 0;
  white-space: nowrap;
  min-width: 0;
}

.logo {
  font-weight: 800;
  font-size: var(--text-lg);
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--primary), var(--memory));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ── Nav panel ─────────────────────────────────────────── */
nav {
  grid-area: nav;
  background: var(--surface-glass);
  backdrop-filter: blur(6px);
  border-right: 1px solid var(--border);
  padding: var(--sp-6);
  overflow-y: auto;
}

/* ── Main thread ───────────────────────────────────────── */
main {
  grid-area: main;
  position: relative;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0; /* allow grid item to shrink when viewport is short or zoomed */
}

.chat-form {
  flex-shrink: 0;
  flex-basis: auto;
  padding: var(--sp-6);
  border-top: 1px solid var(--border);
  background: var(--bg);
}

#chat-form {
  display: flex;
  gap: var(--sp-3);
}

#chat-form input[type="text"] {
  flex: 1;
  min-width: 0;
}

/* ── Memory trace panel — visual primacy ───────────────── */
aside {
  grid-area: side;
  background: rgba(8,8,8,0.92);
  backdrop-filter: blur(6px);
  border-left: 2px solid hsla(142, 71%, 45%, 0.2); /* memory green border = primacy signal */
  padding: var(--sp-6);
  overflow-y: auto;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--surface-raise);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: var(--sp-4) var(--sp-5);
  margin-bottom: var(--sp-3);
}

.card:hover {
  border-color: var(--border-strong);
}

/* ── Trace row variants ────────────────────────────────── */

/* Semantic fact — recalled from memory store */
.card.trace-semantic {
  background: var(--trace-semantic-bg);
  border-color: var(--trace-semantic-border);
}

/* Episodic event — written to history */
.card.trace-episodic {
  background: var(--trace-episodic-bg);
  border-color: var(--trace-episodic-border);
}

/* Working / in-progress — amber, only non-final state */
.card.trace-working {
  border-color: hsla(38, 92%, 50%, 0.5);
  background: var(--amber-dim);
  animation: workingPulse 1.8s ease-in-out infinite;
}

/* Error — calm amber, never raw red */
.card.trace-error {
  border-color: hsla(38, 92%, 50%, 0.4);
  background: var(--amber-dim);
}

/* ── Motion verb 1: WRITE — row entry ──────────────────── */
/* Gentle fade+rise when a new trace row enters the panel */
@keyframes natRowIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card.trace-new {
  animation: natRowIn 280ms ease-out forwards;
}

/* ── Motion verb 2: RECALL — left-border pulse ─────────── */
/* Inset left border flash when a cited fact lights up */
@keyframes natRecall {
  0%, 100% { box-shadow: inset 3px 0 0 var(--memory), 0 0 0 1px var(--border); }
  45%      { box-shadow: inset 3px 0 0 var(--memory), 0 0 0 1px var(--vk-glow-hair), 0 0 22px rgba(74,222,128,0.20); }
}

.card.recall-glow {
  animation: natRecall 3.2s ease-in-out forwards;
}

/* ── Working pulse ─────────────────────────────────────── */
@keyframes workingPulse {
  0%, 100% { border-color: hsla(38, 92%, 50%, 0.3); }
  50%       { border-color: hsla(38, 92%, 50%, 0.7); }
}

/* ── Badges ────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem var(--sp-2);
  border-radius: 4px;
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}

.badge-semantic {
  background: hsla(142, 71%, 45%, 0.18);
  color: var(--memory);
}

.badge-episodic {
  background: rgba(63,63,70,0.4);
  color: var(--text-muted);
}

.badge-working {
  background: var(--amber-dim);
  color: var(--amber);
}

.badge-error {
  background: var(--amber-dim);
  color: var(--amber);
}

/* Legacy badge classes for existing non-trace cards */
.badge.done { background: hsla(142, 71%, 45%, 0.15); color: var(--memory); }
.badge.todo { background: hsla(38, 92%, 50%, 0.15);  color: var(--amber); }

/* ── Chat messages ─────────────────────────────────────── */
.message-list {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-8);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

.message {
  max-width: 78%;
  padding: var(--sp-4) var(--sp-5);
  border-radius: 16px;
  font-size: var(--text-base);
  animation: msgSlideUp 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.message.customer {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.agent {
  align-self: flex-end;
  background: linear-gradient(135deg,
    hsla(258, 74%, 64%, 0.09),
    hsla(258, 74%, 50%, 0.13));
  border: 1px solid hsla(258, 74%, 64%, 0.28);
  border-bottom-right-radius: 4px;
}

.message-meta {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-top: var(--sp-2);
}

@keyframes msgSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Recall chips — inline in agent messages ───────────── */
.recall-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

@keyframes natChip {
  0%, 100% { background: rgba(74,222,128,0.07); box-shadow: inset 0 0 0 1px rgba(74,222,128,0.22); }
  45%      { background: rgba(74,222,128,0.15); box-shadow: inset 0 0 0 1px rgba(74,222,128,0.45); }
}

.recall-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  padding: 0.12rem var(--sp-2);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--memory);
  letter-spacing: 0.02em;
  animation: natChip 3s ease-in-out infinite;
}

/* ── Trace panel empty state ───────────────────────────── */
.trace-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-8) var(--sp-4);
  color: var(--text-faint);
  font-size: var(--text-sm);
  text-align: center;
}

.trace-empty-ring {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid hsla(142, 71%, 45%, 0.2);
  border-top-color: hsla(142, 71%, 45%, 0.5);
  animation: ringIdle 3s linear infinite;
}

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

/* ── Forms ─────────────────────────────────────────────── */
input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: var(--sp-3) var(--sp-4);
  border-radius: 8px;
  width: 100%;
  font-size: var(--text-base);
  font-family: var(--font-sans);
  transition: border-color 0.15s ease;
}

input:focus {
  outline: none;
  border-color: var(--primary);
}

button {
  background: var(--primary);
  color: white;
  border: none;
  padding: var(--sp-3) var(--sp-5);
  border-radius: 8px;
  font-weight: 600;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
  letter-spacing: 0.01em;
}

button:hover  { filter: brightness(1.12); }
button:active { transform: scale(0.97); }

.secondary-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.secondary-btn:hover {
  filter: none;
  border-color: var(--border-strong);
  color: var(--text);
}

/* ── Section labels ────────────────────────────────────── */
.panel-label {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: var(--sp-4);
}

/* ── Brand lockup ─────────────────────────────────────── */
.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-lockup-compact .brand-mark {
  width: 36px;
  height: 36px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-name {
  font-weight: 700;
  font-size: var(--text-base);
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand-descriptor {
  font-size: var(--text-2xs);
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

/* ── Brand glyph + status pip ─────────────────────────── */
.logo-glyph {
  font-family: var(--font-mono);
  color: var(--memory);
  letter-spacing: 0.05em;
  margin-right: 0.5rem;
  font-size: 0.75em;
  font-weight: 400;
  -webkit-text-fill-color: var(--memory); /* override logo gradient clip */
}

@keyframes natBlink {
  0%, 92%, 100% { opacity: 1; }
  96%           { opacity: 0.15; }
}

.vk-pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--memory);
  box-shadow: var(--shadow-glow);
  animation: natBlink 7s steps(1) infinite;
  flex-shrink: 0;
}

/* ── Single-panel page layout (dashboard, health) ──────── */
/* Resets grid-area placement set for the three-pane app container */
.page-simple {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 56px 1fr;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.page-simple > header {
  grid-area: unset;
  grid-row: 1;
  grid-column: 1;
}

.page-simple > main {
  grid-area: unset;
  grid-row: 2;
  grid-column: 1;
  overflow-y: auto;
}

/* ── VR-488 · UX1: Recall-moment clarity ──────────────── */

/* Bridge text: one-line connector between answer and chips */
.recall-bridge {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--memory);
  opacity: 0.75;
  margin-top: var(--sp-4);
  margin-bottom: var(--sp-2);
  font-family: var(--font-mono);
}

/* Muted "· remembered" suffix inside each chip */
.chip-remembered {
  color: var(--text-faint);
  font-weight: 400;
}

/* ── VR-489 · UX2: Inline proof card ──────────────────── */

.proof-card {
  background: rgba(74,222,128,0.03);
  border-color: var(--border-strong);
}

/* ── VR-490 · UX3: Trust and governance microcopy ──────── */

/* Trust strip under recalled chips in chat messages */
.trust-strip {
  margin-top: var(--sp-3);
  padding-top: var(--sp-2);
  border-top: 1px solid rgba(74,222,128,0.12);
  font-size: var(--text-2xs);
  font-family: var(--font-mono);
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

/* Governance badge row in manager dashboard fact cards */
.fact-governance-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

/* Calm, neutral governance badge — current / scoped / no-expiry */
.badge-governance {
  display: inline-block;
  padding: 0.1rem var(--sp-2);
  border-radius: 4px;
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  background: rgba(255,255,255,0.04);
  color: var(--text-faint);
}

/* Amber treatment for facts with an expiry date — calm, never red */
.badge-governance-warn {
  display: inline-block;
  padding: 0.1rem var(--sp-2);
  border-radius: 4px;
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  background: var(--amber-dim);
  color: var(--amber);
}

/* ── Mobile smoke test (VR-531) ────────────────────────── */
/* Bar: "degrades gracefully," not pixel-perfect responsive.
   Someone tapping through from the landing page on a phone
   should not hit a horizontal-scroll mess or overlapping
   panels. Judges use laptops; this is not judged on beauty. */
@media (max-width: 768px) {
  body {
    overflow: auto;
    height: auto;
  }

  .app-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas:
      "header"
      "main"
      "nav"
      "side";
    height: auto;
    min-height: 100vh;
  }

  nav {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: var(--sp-4);
  }

  aside {
    border-left: none;
    border-top: 2px solid hsla(142, 71%, 45%, 0.2);
    padding: var(--sp-4);
  }

  header {
    flex-wrap: wrap;
    height: auto;
    padding: var(--sp-2) var(--sp-4);
    gap: var(--sp-2);
  }

  .message {
    max-width: 92%;
  }

  .message-list {
    padding: var(--sp-4);
  }
}
