:root {
  color-scheme: dark;
  --bg: #09090b;
  --surface: #111114;
  --surface-raised: #17171b;
  --surface-soft: #1d1d22;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.15);
  --text: #f4f2ed;
  --muted: #97949f;
  --subtle: #6d6974;
  --orange: #f06a2b;
  --orange-bright: #ff8a42;
  --orange-soft: rgba(240, 106, 43, 0.13);
  --purple: #8b5cf6;
  --success: #68d391;
  --danger: #fb7185;
  --sidebar-width: 310px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  overflow: hidden;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(circle at 73% 0%, rgba(139, 92, 246, 0.07), transparent 32%),
    radial-gradient(circle at 35% 100%, rgba(240, 106, 43, 0.07), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.noise {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0.022;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 140 140' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.95' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.7'/%3E%3C/svg%3E");
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(12, 12, 15, 0.94);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(22px);
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 22px 18px;
  border-bottom: 1px solid var(--line);
}

.brand-logo {
  display: block;
  width: 205px;
  height: auto;
  filter: drop-shadow(0 14px 20px rgba(0, 0, 0, 0.6));
  user-select: none;
  -webkit-user-drag: none;
}

.brand-kicker {
  margin: -2px 0 0;
  color: var(--subtle);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.library-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.library-count {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 11px;
}

.map-list {
  min-height: 0;
  padding: 4px 10px 18px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-soft) transparent;
}

.map-button {
  position: relative;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  width: 100%;
  margin: 4px 0;
  padding: 7px;
  overflow: hidden;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 13px;
  cursor: pointer;
  transition: 160ms ease;
}

.map-button::after {
  position: absolute;
  right: 0;
  width: 2px;
  height: 24px;
  content: "";
  background: var(--orange);
  border-radius: 3px 0 0 3px;
  opacity: 0;
  transform: scaleY(0.4);
  transition: 160ms ease;
}

.map-button:hover {
  background: rgba(255, 255, 255, 0.035);
}

.map-button.active {
  background: linear-gradient(90deg, var(--orange-soft), rgba(240, 106, 43, 0.025));
  border-color: rgba(240, 106, 43, 0.2);
}

.map-button.active::after {
  opacity: 1;
  transform: scaleY(1);
}

.map-cover {
  width: 48px;
  height: 48px;
  background-color: var(--surface-soft);
  background-position: center;
  background-size: cover;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.map-cover-all {
  position: relative;
  background:
    radial-gradient(circle at 34% 30%, var(--orange), transparent 18%),
    radial-gradient(circle at 68% 63%, var(--purple), transparent 19%),
    #1b171a;
}

.map-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding-left: 10px;
}

.map-copy strong {
  overflow: hidden;
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-copy small {
  overflow: hidden;
  color: var(--subtle);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-skeleton {
  height: 64px;
  margin: 4px 0;
  background: linear-gradient(90deg, #151519, #1c1c21, #151519);
  background-size: 200% 100%;
  border-radius: 13px;
  animation: shimmer 1.5s infinite;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--line);
}

.system-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
}

.status-dot,
.context-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  background: var(--success);
  border-radius: 999px;
  box-shadow: 0 0 10px rgba(104, 211, 145, 0.65);
}

.system-status.error .status-dot {
  background: var(--danger);
  box-shadow: 0 0 10px rgba(251, 113, 133, 0.6);
}

.ghost-button {
  width: 100%;
  padding: 9px 12px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: 160ms ease;
}

.ghost-button:hover {
  color: var(--text);
  background: var(--surface-raised);
  border-color: var(--line-strong);
}

.workspace {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: 72px minmax(0, 1fr) auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(20px, 3vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(9, 9, 11, 0.68);
  backdrop-filter: blur(20px);
}

.active-context {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.eyebrow {
  color: var(--subtle);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.eyebrow.accent {
  color: var(--orange-bright);
}

.active-context strong {
  overflow: hidden;
  margin-top: 2px;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.knowledge-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.knowledge-stats strong {
  color: var(--text);
  font-weight: 700;
}

.knowledge-stats > span {
  width: 3px;
  height: 3px;
  background: var(--subtle);
  border-radius: 50%;
}

.chat-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.chat {
  width: min(900px, calc(100% - 42px));
  height: 100%;
  margin: 0 auto;
  padding: 34px 0 50px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-soft) transparent;
}

.welcome {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  width: min(700px, calc(100% - 48px));
  text-align: center;
  transform: translate(-50%, -51%);
}

.welcome[hidden] {
  display: none;
}

.welcome-orbit {
  position: relative;
  width: 76px;
  height: 76px;
  margin: 0 auto 22px;
  border: 1px solid rgba(240, 106, 43, 0.28);
  border-radius: 50%;
  box-shadow:
    0 0 42px rgba(240, 106, 43, 0.13),
    inset 0 0 26px rgba(139, 92, 246, 0.1);
}

.welcome-orbit::before {
  position: absolute;
  inset: 19px;
  content: "K";
  display: grid;
  place-items: center;
  color: var(--orange-bright);
  font-family: Georgia, serif;
  font-size: 26px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
}

.welcome-orbit span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 5px;
  background: var(--orange);
  border-radius: 50%;
  transform-origin: 0 0;
  animation: orbit 6s linear infinite;
}

.welcome-orbit span:nth-child(2) {
  background: var(--purple);
  animation-duration: 8s;
  animation-direction: reverse;
}

.welcome-orbit span:nth-child(3) {
  width: 3px;
  height: 3px;
  animation-duration: 11s;
}

.welcome h1 {
  margin: 10px 0 16px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(36px, 5vw, 64px);
  font-weight: 500;
  letter-spacing: -0.045em;
  line-height: 0.98;
}

.welcome-copy {
  width: min(590px, 100%);
  margin: 0 auto;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 28px;
}

.quick-prompts button,
.map-suggestions button {
  padding: 9px 13px;
  color: #c9c5ce;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: 160ms ease;
}

.quick-prompts button:hover,
.map-suggestions button:hover {
  color: var(--text);
  background: var(--orange-soft);
  border-color: rgba(240, 106, 43, 0.3);
  transform: translateY(-1px);
}

.message {
  width: min(780px, 94%);
  margin-bottom: 28px;
  animation: message-in 220ms ease both;
}

.message.user {
  width: fit-content;
  max-width: min(680px, 88%);
  margin-left: auto;
}

.message > header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 9px;
  color: var(--subtle);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

.assistant-mark {
  display: grid;
  width: 21px;
  height: 21px;
  place-items: center;
  color: #16100d;
  background: linear-gradient(135deg, var(--orange-bright), var(--orange));
  border-radius: 6px;
  font-family: Georgia, serif;
  font-size: 12px;
  box-shadow: 0 0 14px rgba(240, 106, 43, 0.2);
}

.message-body {
  color: #dbd8df;
  font-size: 15px;
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.message.user .message-body {
  padding: 12px 16px;
  color: #f1edf2;
  background: linear-gradient(135deg, rgba(240, 106, 43, 0.18), rgba(139, 92, 246, 0.08));
  border: 1px solid rgba(240, 106, 43, 0.2);
  border-radius: 17px 17px 4px 17px;
}

.message.assistant .message-body {
  padding-left: 28px;
}

.message.error .message-body,
.message.clarification .message-body {
  padding: 14px 16px;
  background: rgba(251, 113, 133, 0.06);
  border: 1px solid rgba(251, 113, 133, 0.18);
  border-radius: 14px;
}

.message.clarification .message-body {
  background: var(--orange-soft);
  border-color: rgba(240, 106, 43, 0.2);
}

.message-body p {
  margin: 0 0 12px;
}

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

.message-body h3,
.message-body h4 {
  margin: 22px 0 8px;
  color: var(--text);
  font-family: Georgia, serif;
  font-weight: 500;
  letter-spacing: -0.015em;
}

.message-body h3 {
  font-size: 22px;
}

.message-body h4 {
  font-size: 18px;
}

.message-body ol,
.message-body ul {
  margin: 10px 0 16px;
  padding-left: 24px;
}

.message-body li {
  margin: 6px 0;
  padding-left: 4px;
}

.message-body li::marker {
  color: var(--orange);
  font-weight: 700;
}

.message-body strong {
  color: var(--text);
}

.message-body code {
  padding: 2px 6px;
  color: #f9b27d;
  background: rgba(240, 106, 43, 0.09);
  border: 1px solid rgba(240, 106, 43, 0.13);
  border-radius: 5px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.86em;
}

.message-images {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: auto;
  min-width: 0;
  max-width: 100%;
  margin: 18px 0 0 28px;
}

.message-images figure {
  position: relative;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: zoom-in;
  box-shadow: var(--shadow);
}

.message-images img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  transition: transform 260ms ease, filter 260ms ease;
}

.message-images figure:hover img {
  filter: brightness(1.08);
  transform: scale(1.025);
}

.message-images figcaption {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 24px 11px 9px;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.9);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.82));
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-sources {
  margin: 13px 0 0 28px;
  color: var(--subtle);
  font-size: 10px;
}

.message-sources summary {
  width: fit-content;
  cursor: pointer;
  transition: color 160ms ease;
}

.message-sources summary:hover {
  color: var(--muted);
}

.source-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
  padding-left: 13px;
  border-left: 1px solid var(--line);
}

.map-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 12px 0 0 28px;
}

.typing-message {
  margin-bottom: 18px;
}

.typing {
  display: flex;
  gap: 5px;
  padding-left: 29px;
}

.typing span {
  width: 6px;
  height: 6px;
  background: var(--orange);
  border-radius: 50%;
  animation: typing 1.2s ease-in-out infinite;
}

.typing span:nth-child(2) {
  animation-delay: 120ms;
}

.typing span:nth-child(3) {
  animation-delay: 240ms;
}

.composer-shell {
  padding: 0 clamp(20px, 3vw, 42px) 24px;
  background: linear-gradient(transparent, var(--bg) 24%);
}

.composer {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 11px 12px 9px;
  background: rgba(22, 22, 26, 0.94);
  border: 1px solid var(--line-strong);
  border-radius: 17px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(18px);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.composer:focus-within {
  border-color: rgba(240, 106, 43, 0.38);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.36),
    0 0 0 3px rgba(240, 106, 43, 0.06);
}

.composer-context {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 4px 7px;
  color: var(--subtle);
  font-size: 10px;
}

.composer-context .context-dot {
  width: 5px;
  height: 5px;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#message-input {
  width: 100%;
  min-height: 38px;
  max-height: 160px;
  padding: 7px 5px;
  resize: none;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 16px;
  line-height: 1.5;
}

#message-input::placeholder {
  color: #66636c;
}

.send-button {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  background: linear-gradient(135deg, var(--orange-bright), var(--orange));
  border: 0;
  border-radius: 12px;
  box-shadow: 0 7px 20px rgba(240, 106, 43, 0.22);
  cursor: pointer;
  transition: 160ms ease;
}

.send-button:hover:not(:disabled) {
  box-shadow: 0 9px 28px rgba(240, 106, 43, 0.34);
  transform: translateY(-1px);
}

.send-button:disabled {
  cursor: wait;
  filter: saturate(0.4);
  opacity: 0.55;
}

.send-button svg {
  width: 19px;
  fill: none;
  stroke: #1a0d07;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.composer-hint {
  display: flex;
  justify-content: space-between;
  padding: 6px 4px 0;
  color: #57545c;
  font-size: 9px;
}

.image-modal {
  width: min(1200px, calc(100vw - 24px));
  width: min(1200px, calc(100dvw - 24px));
  max-width: calc(100vw - 24px);
  max-width: calc(100dvw - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  padding: 0;
  overflow: hidden;
  background: transparent;
  border: 0;
}

.image-modal::backdrop {
  background: rgba(4, 4, 6, 0.92);
  backdrop-filter: blur(12px);
}

.image-modal figure {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: 100%;
  max-width: 100%;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  margin: 0;
}

.image-modal img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: calc(100vh - 66px);
  max-height: calc(100dvh - 66px);
  margin: 0 auto;
  object-fit: contain;
  background: #050506;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.image-modal figcaption {
  padding: 11px 6px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 38px;
  height: 38px;
  background: var(--text);
  border: 0;
  border-radius: 50%;
  color: var(--bg);
  font-size: 24px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.menu-toggle,
.sidebar-backdrop {
  display: none;
}

.load-error {
  padding: 14px;
  color: var(--danger);
  font-size: 12px;
}

@keyframes shimmer {
  to { background-position: -200% 0; }
}

@keyframes orbit {
  from { transform: rotate(0deg) translateX(38px) rotate(0deg); }
  to { transform: rotate(360deg) translateX(38px) rotate(-360deg); }
}

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

@keyframes typing {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

@media (max-width: 900px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(var(--sidebar-width), 86vw);
    box-shadow: var(--shadow);
    transform: translateX(-102%);
    transition: transform 220ms ease;
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9;
    display: block;
    visibility: hidden;
    background: rgba(0, 0, 0, 0.58);
    border: 0;
    opacity: 0;
    transition: 220ms ease;
  }

  .sidebar-open .sidebar-backdrop {
    visibility: visible;
    opacity: 1;
  }

  .workspace {
    height: 100vh;
    height: 100dvh;
  }

  .menu-toggle {
    display: flex;
    width: 36px;
    height: 36px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0;
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: 10px;
  }

  .menu-toggle span {
    width: 15px;
    height: 1px;
    background: var(--text);
  }

  .topbar {
    justify-content: flex-start;
    gap: 13px;
  }

  .knowledge-stats {
    margin-left: auto;
  }
}

@media (max-width: 640px) {
  .workspace {
    grid-template-rows: 62px minmax(0, 1fr) auto;
  }

  .topbar {
    padding: 0 13px;
  }

  .knowledge-stats {
    display: none;
  }

  .welcome {
    width: calc(100% - 28px);
  }

  .welcome h1 {
    font-size: clamp(35px, 11vw, 48px);
  }

  .welcome-copy {
    font-size: 13px;
  }

  .quick-prompts {
    margin-top: 20px;
  }

  .quick-prompts button {
    padding: 8px 10px;
    font-size: 11px;
  }

  .chat {
    width: calc(100% - 24px);
    padding: 24px 0 36px;
  }

  .message,
  .message.assistant,
  .message.error,
  .message.clarification {
    width: 100%;
    max-width: 100%;
  }

  .message.user {
    max-width: 92%;
  }

  .message.assistant .message-body {
    padding-inline: 2px;
  }

  .message-images {
    grid-template-columns: 1fr;
    width: 100%;
    margin-right: 0;
    margin-left: 0;
  }

  .message-sources,
  .map-suggestions {
    margin-left: 0;
  }

  .composer-shell {
    padding: 0 10px max(10px, env(safe-area-inset-bottom));
  }

  .composer {
    border-radius: 15px;
  }

  .composer-hint span:first-child {
    display: none;
  }

  .composer-hint {
    justify-content: flex-end;
  }

  .image-modal {
    width: calc(100vw - 16px);
    width: calc(100dvw - 16px);
    max-width: calc(100vw - 16px);
    max-width: calc(100dvw - 16px);
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }

  .image-modal figure {
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }

  .image-modal img {
    max-height: calc(100vh - 58px);
    max-height: calc(100dvh - 58px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
