/* Lattice AI — design tokens + global styles
 * Blazor port: served from wwwroot/css/lattice-ai.css
 * Loaded via <HeadContent> in Components/app/ai/AI.razor so it only attaches
 * on the /ai page. The styles are intentionally NOT scoped through Blazor's
 * CSS isolation (no .razor.css files) — the cascade across Sidebar, Header,
 * Composer, Messages must work as one tree, just like the React demo.
 */
:root {
  /* Cool neutral grayscale */
  --bg-0: #0b0d10;          /* deepest canvas */
  --bg-1: #101317;          /* main app bg */
  --bg-2: #14181d;          /* sidebar */
  --bg-3: #1a1f25;          /* hover / cards */
  --bg-4: #222831;          /* active / borders strong */
  --bg-5: #2c333d;          /* input chrome */

  --line-1: rgba(255,255,255,0.05);
  --line-2: rgba(255,255,255,0.08);
  --line-3: rgba(255,255,255,0.12);

  --fg-0: #f3f5f8;          /* primary text */
  --fg-1: #c9cfd8;          /* secondary */
  --fg-2: #8a93a0;          /* tertiary */
  --fg-3: #5b636e;          /* quaternary / placeholder */
  --fg-4: #3a4049;          /* disabled */

  /* Accent — violet */
  --accent: #a78bfa;
  --accent-hi: #b9a3fc;
  --accent-lo: #8a6cf0;
  --accent-bg: rgba(167,139,250,0.12);
  --accent-bg-strong: rgba(167,139,250,0.18);
  --accent-line: rgba(167,139,250,0.28);

  /* Code colors (subtle, low-contrast palette) */
  --code-bg: #0d1014;
  --code-keyword: #c4a3ff;
  --code-string: #a8d6a4;
  --code-number: #f0b277;
  --code-comment: #5b636e;
  --code-fn: #93c5fd;
  --code-prop: #e2c089;
  --code-punct: #8a93a0;

  /* Status */
  --ok: #6ee7b7;
  --warn: #fbbf24;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-pop: 0 12px 32px -12px rgba(0,0,0,0.6), 0 2px 6px rgba(0,0,0,0.4);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* React demo set html/body/#root to height:100% and body overflow:hidden.
   In Blazor we don't touch the host page — MainLayout owns it. The .app
   block below scopes height/overflow to just the Lattice AI page tree. */

button, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
  padding: 0;
}
button { cursor: pointer; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.12); background-clip: padding-box; border: 2px solid transparent;}

/* ====== APP SHELL ====== */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100dvh;         /* fits the viewport exactly */
  max-height: 100dvh;
  overflow: hidden;       /* lock outer scroll — only .chat scrolls */
  background: var(--bg-1);
  font-family: var(--font-sans);
  color: var(--fg-0);
  font-size: 14px;
  line-height: 1.55;
}

/* ====== SIDEBAR ====== */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--line-1);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sb-head {
  padding: 14px 14px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sb-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  color: var(--fg-0);
}
.sb-logo .mark {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 6px;
  background: linear-gradient(180deg, #1c2129, #14181d);
  border: 1px solid var(--line-2);
}
.sb-spacer { flex: 1; }
.icon-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 7px;
  color: var(--fg-2);
  transition: background 120ms, color 120ms;
}
.icon-btn:hover { background: var(--bg-3); color: var(--fg-0); }
.icon-btn.sm { width: 24px; height: 24px; border-radius: 6px;}

.sb-new {
  margin: 4px 10px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  color: var(--fg-0);
  font-weight: 500;
  font-size: 13px;
  width: calc(100% - 20px);
  transition: background 120ms, border-color 120ms;
}
.sb-new:hover { background: var(--bg-4); border-color: var(--line-3); }
.sb-new .kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-3);
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 1px 5px;
}

.sb-search {
  margin: 0 10px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 9px;
  background: var(--bg-1);
  border: 1px solid var(--line-1);
  transition: border-color 120ms, background 120ms;
}
.sb-search:focus-within {
  border-color: var(--accent-line);
  background: var(--bg-3);
}
.sb-search input {
  flex: 1;
  font-size: 13px;
  color: var(--fg-0);
}
.sb-search input::placeholder { color: var(--fg-3); }

.sb-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 6px 12px;
}
.sb-section {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
  padding: 12px 10px 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sb-section .count {
  font-weight: 500;
  color: var(--fg-4);
  letter-spacing: 0;
  text-transform: none;
  font-size: 11px;
}

.sb-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  text-align: left;
  color: var(--fg-1);
  position: relative;
  transition: background 100ms, color 100ms;
  font-size: 13px;
}
.sb-item:hover { background: var(--bg-3); color: var(--fg-0); }
.sb-item.active {
  background: var(--bg-3);
  color: var(--fg-0);
}
.sb-item.active::before {
  content: "";
  position: absolute;
  left: -6px; top: 8px; bottom: 8px;
  width: 2px;
  background: var(--accent);
  border-radius: 2px;
}
.sb-item .title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-item .pin {
  color: var(--accent);
  opacity: 0.85;
}
.sb-item .meta {
  font-size: 11px;
  color: var(--fg-3);
}
.sb-item:hover .meta { color: var(--fg-2); }

.sb-foot {
  border-top: 1px solid var(--line-1);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sb-foot .avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2c333d, #1a1f25);
  border: 1px solid var(--line-2);
  display: grid; place-items: center;
  color: var(--fg-1);
  font-size: 11px;
  font-weight: 600;
}
.sb-foot .who { display: flex; flex-direction: column; line-height: 1.2; }
.sb-foot .who .name { color: var(--fg-0); font-size: 13px; font-weight: 500; }
.sb-foot .who .org { color: var(--fg-3); font-size: 11px; }

/* ====== MAIN ====== */
.main {
  display: grid;
  grid-template-rows: 56px 1fr auto;
  min-height: 0;
}

.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line-1);
  background: var(--bg-1);
}
.model-select {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 10px 6px 8px;
  border-radius: 8px;
  background: transparent;
  color: var(--fg-0);
  font-weight: 500;
  font-size: 13px;
  transition: background 120ms;
  position: relative;
}
.model-select:hover { background: var(--bg-3); }
.model-select .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(110,231,183,0.12);
}
.model-select .name { color: var(--fg-0); }
.model-select .sub { color: var(--fg-3); font-size: 12px; font-weight: 400; }

.h-spacer { flex: 1; }
.h-title {
  font-size: 13px;
  color: var(--fg-2);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.h-title .acct {
  color: var(--fg-1);
  background: var(--bg-3);
  padding: 2px 8px;
  border-radius: 5px;
  border: 1px solid var(--line-1);
  font-size: 12px;
}

.h-actions { display: flex; gap: 4px; }

/* ====== CHAT ====== */
.chat {
  overflow-y: auto;
  min-height: 0;
}
.chat-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 28px 40px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg.ai { align-items: flex-start; }

.msg-meta {
  font-size: 11px;
  color: var(--fg-3);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-meta .who { color: var(--fg-1); font-weight: 500; }

.bubble-user {
  background: var(--accent-bg);
  border: 1px solid var(--accent-line);
  color: var(--fg-0);
  padding: 11px 15px;
  border-radius: 16px 16px 4px 16px;
  max-width: 78%;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.ai-body {
  width: 100%;
  color: var(--fg-0);
  font-size: 14px;
  line-height: 1.7;
}
.ai-body p { margin: 0 0 12px; }
.ai-body p:last-child { margin-bottom: 0; }
.ai-body strong { color: var(--fg-0); font-weight: 600; }
.ai-body em { color: var(--fg-1); font-style: italic; }
.ai-body ul, .ai-body ol { margin: 8px 0 14px; padding-left: 22px; }
.ai-body li { margin: 3px 0; color: var(--fg-1); }
.ai-body li::marker { color: var(--fg-3); }
.ai-body h3 { font-size: 14px; font-weight: 600; margin: 18px 0 8px; color: var(--fg-0);}
.ai-body code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--bg-3);
  border: 1px solid var(--line-1);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--fg-0);
}
.ai-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed rgba(167,139,250,0.4);
}
.ai-body a:hover { border-bottom-style: solid; }

/* Citations */
.cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  color: var(--fg-1);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  margin: 0 2px;
  vertical-align: 1px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.cite:hover {
  background: var(--accent-bg);
  border-color: var(--accent-line);
  color: var(--accent-hi);
}

/* Inline cards (contact / deal) */
.entity-card {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  margin: 6px 0 14px;
  transition: border-color 120ms, background 120ms;
  cursor: pointer;
}
.entity-card:hover { border-color: var(--line-3); background: var(--bg-3); }
.entity-card .ec-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2c333d, #1a1f25);
  display: grid; place-items: center;
  color: var(--fg-0);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line-2);
}
.entity-card .ec-body { display: flex; flex-direction: column; min-width: 0;}
.entity-card .ec-name { color: var(--fg-0); font-weight: 600; font-size: 13.5px; }
.entity-card .ec-sub  { color: var(--fg-2); font-size: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;}
.entity-card .ec-sub .pill {
  font-family: var(--font-mono); font-size: 10.5px;
  background: var(--bg-3); border: 1px solid var(--line-1);
  border-radius: 4px; padding: 1px 6px; color: var(--fg-1);
}
.entity-card .ec-stage {
  font-size: 11px; color: var(--accent);
  background: var(--accent-bg);
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

/* Deal card variant */
.deal-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  margin: 6px 0 14px;
}
.deal-card .dc-name { color: var(--fg-0); font-weight: 600; font-size: 13.5px; }
.deal-card .dc-meta { color: var(--fg-2); font-size: 12px; margin-top: 2px;}
.deal-card .dc-amount { color: var(--fg-0); font-weight: 600; font-family: var(--font-mono); font-size: 14px; }
.deal-card .dc-stage { color: var(--fg-3); font-size: 11px; text-align: right; margin-top: 2px;}

/* Code block */
.codewrap {
  margin: 4px 0 14px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  overflow: hidden;
  background: var(--code-bg);
}
.codehead {
  display: flex; align-items: center;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line-1);
  background: rgba(255,255,255,0.02);
}
.codehead .lang {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
}
.codehead .copy {
  margin-left: auto;
  font-size: 11px;
  color: var(--fg-2);
  display: flex; align-items: center; gap: 5px;
  padding: 3px 7px;
  border-radius: 5px;
  transition: background 120ms, color 120ms;
}
.codehead .copy:hover { color: var(--fg-0); background: var(--bg-3); }
.codeblock {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--fg-0);
}
.tok-k { color: var(--code-keyword); }
.tok-s { color: var(--code-string); }
.tok-n { color: var(--code-number); }
.tok-c { color: var(--code-comment); font-style: italic;}
.tok-f { color: var(--code-fn); }
.tok-p { color: var(--code-prop); }
.tok-pn { color: var(--code-punct); }

/* Email draft block */
.email-draft {
  margin: 4px 0 14px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-2);
}
.email-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-1);
  display: grid;
  grid-template-columns: 50px 1fr;
  gap: 6px 14px;
  font-size: 12.5px;
}
.email-head .lbl { color: var(--fg-3); }
.email-head .val { color: var(--fg-0); }
.email-body {
  padding: 14px;
  font-size: 13.5px;
  color: var(--fg-1);
  line-height: 1.65;
  white-space: pre-wrap;
}
.email-foot {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line-1);
  background: rgba(255,255,255,0.015);
}

/* Action chips (suggested actions on AI message) */
.action-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 14px;
}
.action-chip {
  display: inline-flex;
  align-items: center; gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  color: var(--fg-1);
  font-size: 12.5px;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.action-chip:hover {
  background: var(--bg-3);
  border-color: var(--line-3);
  color: var(--fg-0);
}
.action-chip.primary {
  background: var(--accent-bg);
  border-color: var(--accent-line);
  color: var(--accent-hi);
}
.action-chip.primary:hover {
  background: var(--accent-bg-strong);
}

/* AI message tools (under bubble) */
.ai-tools {
  display: flex;
  gap: 2px;
  margin-top: 10px;
  opacity: 0.7;
  transition: opacity 120ms;
}
.msg.ai:hover .ai-tools { opacity: 1; }
.ai-tools .icon-btn { width: 26px; height: 26px; }

/* ====== EMPTY / WELCOME ====== */
.welcome {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  padding: 60px 28px;
  gap: 20px;
}
.welcome h1 {
  font-size: 26px; font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--fg-0);
  margin: 0;
}
.welcome p { color: var(--fg-2); font-size: 14px; margin: 0; max-width: 460px;}
.prompt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  margin-top: 6px;
}
.prompt-card {
  text-align: left;
  padding: 14px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 120ms, border-color 120ms;
}
.prompt-card:hover { background: var(--bg-3); border-color: var(--line-3); }
.prompt-card .pc-title { color: var(--fg-0); font-size: 13px; font-weight: 500;}
.prompt-card .pc-sub { color: var(--fg-3); font-size: 12px;}

/* ====== COMPOSER ====== */
.composer-wrap {
  padding: 12px 28px 18px;
  background: linear-gradient(180deg, transparent, var(--bg-1) 30%);
}
.composer {
  max-width: 760px;
  margin: 0 auto;
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 16px;
  transition: border-color 150ms, box-shadow 150ms, background 150ms;
}
.composer:focus-within {
  border-color: var(--accent-line);
  background: var(--bg-3);
  box-shadow: 0 0 0 4px rgba(167,139,250,0.06);
}
.composer textarea {
  width: 100%;
  resize: none;
  padding: 14px 16px 4px;
  background: transparent;
  color: var(--fg-0);
  font-size: 14px;
  line-height: 1.55;
  max-height: 200px;
  min-height: 24px;
  display: block;
}
.composer textarea::placeholder { color: var(--fg-3); }

.composer-bar {
  display: flex; align-items: center;
  gap: 4px;
  padding: 8px 10px 8px 8px;
}
.composer-bar .grow { flex: 1; }
.composer-bar .hint {
  font-size: 11px;
  color: var(--fg-3);
  margin-right: 8px;
  font-family: var(--font-mono);
}
.send-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--bg-4);
  color: var(--fg-2);
  display: grid; place-items: center;
  transition: background 120ms, color 120ms, transform 120ms;
}
.send-btn.active {
  background: var(--accent);
  color: #0e0c1a;
}
.send-btn.active:hover { background: var(--accent-hi); }
.send-btn:disabled { cursor: not-allowed; }

.composer-foot {
  text-align: center;
  font-size: 11px;
  color: var(--fg-3);
  margin-top: 8px;
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}

/* Slash menu */
.slash-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  width: 320px;
  background: var(--bg-3);
  border: 1px solid var(--line-3);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  padding: 6px;
  z-index: 30;
}
.slash-head {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
  padding: 8px 8px 6px;
  font-weight: 600;
}
.slash-item {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 8px;
  border-radius: 7px;
  color: var(--fg-1);
  transition: background 100ms;
}
.slash-item .si-cmd { font-family: var(--font-mono); font-size: 12.5px; color: var(--fg-0); }
.slash-item .si-desc { font-size: 11.5px; color: var(--fg-3); margin-top: 1px;}
.slash-item.active, .slash-item:hover { background: var(--bg-4); }

/* Streaming caret */
.caret {
  display: inline-block;
  width: 7px; height: 14px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
  border-radius: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* Toast */
.toast {
  position: fixed;
  left: 50%; bottom: 96px;
  transform: translateX(-50%) translateY(8px);
  background: var(--bg-4);
  color: var(--fg-0);
  font-size: 12.5px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line-3);
  box-shadow: var(--shadow-pop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms, transform 200ms;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Model dropdown */
.popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg-3);
  border: 1px solid var(--line-3);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  padding: 6px;
  width: 280px;
  z-index: 50;
}
.popover-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 7px;
  width: 100%;
  text-align: left;
  transition: background 100ms;
}
.popover-item:hover { background: var(--bg-4); }
.popover-item .pi-name { color: var(--fg-0); font-size: 13px; font-weight: 500;}
.popover-item .pi-desc { color: var(--fg-3); font-size: 11.5px; margin-top: 1px;}
.popover-item .pi-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-2);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 2px 6px;
}
.popover-item.active { background: var(--bg-4); }
.popover-item .check { color: var(--accent); }
