:root {
  --sidebar: #fafafa;
  --sidebar-foreground: #09090b;
  --sidebar-border: #e4e4e7;
  --sidebar-accent: #f4f4f4;
  --sidebar-accent-foreground: #18181b;
  --background: #fafafa;
  --foreground: #0a0a0a;
  --card: #fafafa;
  --border: #e5e5e5;
  --primary: #171717;
  --primary-foreground: #fafafa;
  --muted-foreground: #737373;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--background);
  color: var(--foreground);
  font-family: "Inter", sans-serif;
}

.login-screen {
  min-height: 100vh;
  width: 100%;
  display: grid;
  grid-template-columns: 520px 1fr;
}

.login-left {
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  padding: 48px 40px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 20px;
}

.login-left-top {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-logo-box {
  width: 88px;
  height: 88px;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid var(--sidebar-border);
}

.login-logo-box img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.login-brand {
  margin: 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 44px;
  line-height: 1;
}

.login-tagline {
  margin: 0;
  font-size: 16px;
  line-height: 1.4;
  max-width: 340px;
}

.login-left-bottom {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.login-left-bottom p {
  margin: 0;
}

.login-right {
  display: grid;
  place-items: center;
  padding: 32px;
}

.login-card {
  width: min(460px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
}

.login-card-header {
  padding: 24px 24px 8px;
}

.login-card-header h2 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 600;
}

.login-card-header p {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 14px;
}

.login-card-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px 24px 20px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted-foreground);
}

.login-field input {
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 0 12px;
  font-size: 14px;
  outline: none;
}

.login-field input:focus {
  border-color: #b4b4b8;
}

.login-error {
  margin: 0;
  color: #b42318;
  font-size: 13px;
}

.login-card-actions {
  padding: 0 24px 24px;
}

.login-submit {
  width: 100%;
  height: 42px;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  width: 100%;
  min-height: 100vh;
}

.chat-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px 10px;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--sidebar-border);
}

.brand-mark,
.chat-logo {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--sidebar-accent);
  color: var(--sidebar-accent-foreground);
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.brand-mark img,
.chat-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand-copy h1 {
  margin: 0;
  line-height: 1;
  font-size: 14px;
  font-weight: 600;
}

.brand-copy p {
  margin: 3px 0 0;
  color: var(--muted-foreground);
  font-size: 12px;
}

.workspace-section,
.session-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  margin: 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted-foreground);
}

.workspace-item {
  appearance: none;
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  color: var(--sidebar-foreground);
}

.workspace-item.active {
  background: var(--sidebar-accent);
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  min-height: 120px;
}

.session-item {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--sidebar-foreground);
  padding: 8px 10px;
  text-align: left;
  display: grid;
  gap: 3px;
  transition: background-color 160ms ease;
}

.session-item:hover {
  background: var(--sidebar-accent);
}

.session-item.active {
  background: var(--sidebar-accent);
  border-color: var(--sidebar-border);
}

.session-title {
  font-size: 13px;
  font-weight: 600;
}

.session-meta {
  color: var(--muted-foreground);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-topbar {
  height: 72px;
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-title {
  margin: 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
}

.chat-status {
  margin: 4px 0 0;
  color: var(--muted-foreground);
  font-size: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--sidebar-accent);
  border: 1px solid var(--sidebar-border);
  color: var(--foreground);
  display: grid;
  place-items: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 600;
}

.chat-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
}

.thread-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 20px;
  gap: 16px;
}

.thread-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.assistant-bubble {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-wrap {
  display: flex;
  justify-content: flex-end;
}

.user-bubble {
  width: min(620px, 100%);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble-meta {
  margin: 0;
  font-family: "JetBrains Mono", monospace;
  color: var(--muted-foreground);
  font-size: 12px;
}

.user-bubble .bubble-meta {
  color: #d8d8d8;
}

.bubble-content {
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.markdown-content > :first-child {
  margin-top: 0;
}

.markdown-content > :last-child {
  margin-bottom: 0;
}

.markdown-content p,
.markdown-content ul,
.markdown-content ol,
.markdown-content pre,
.markdown-content blockquote,
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
  margin: 0 0 10px;
}

.markdown-content ul,
.markdown-content ol {
  padding-left: 20px;
}

.markdown-content li + li {
  margin-top: 4px;
}

.markdown-content li > ul,
.markdown-content li > ol {
  margin-top: 6px;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
  font-family: "JetBrains Mono", monospace;
  line-height: 1.25;
}

.markdown-content h1 {
  font-size: 19px;
}

.markdown-content h2 {
  font-size: 17px;
}

.markdown-content h3 {
  font-size: 16px;
}

.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
  font-size: 14px;
}

.markdown-content code {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  background: #f1f1f3;
  border: 1px solid #ececee;
  border-radius: 6px;
  padding: 1px 5px;
}

.markdown-content pre {
  background: #f6f6f7;
  border: 1px solid #ececee;
  border-radius: 8px;
  padding: 10px;
  overflow: auto;
}

.markdown-content pre code {
  border: 0;
  background: transparent;
  padding: 0;
}

.markdown-content blockquote {
  border-left: 3px solid #d1d1d5;
  padding-left: 10px;
  color: var(--muted-foreground);
}

.markdown-content a {
  color: #0f4cc6;
  text-decoration: underline;
}

.user-bubble .markdown-content code {
  background: #2d2d2f;
  border-color: #404045;
}

.user-bubble .markdown-content pre {
  background: #2b2b2d;
  border-color: #404045;
}

.user-bubble .markdown-content blockquote {
  border-left-color: #7f7f83;
  color: #e3e3e3;
}

.user-bubble .markdown-content a {
  color: #fff;
}

.snippet-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.snippet-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f7f9;
  padding: 8px 10px;
}

.snippet-meta {
  margin: 0 0 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--muted-foreground);
}

.snippet-code {
  margin: 0;
  background: #efeff2;
  border: 1px solid #e5e5ea;
  border-radius: 7px;
  padding: 8px 10px;
  overflow: auto;
}

.snippet-code code {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 1.4;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted-foreground);
  opacity: 0.3;
  animation: typing-pulse 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-pulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.composer {
  display: block;
}

.composer-input-wrap {
  position: relative;
  width: 100%;
}

.chat-input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  padding: 0 56px 0 16px;
  outline: none;
  background: #fff;
}

.chat-input:focus {
  border-color: #b4b4b8;
}

.send-btn {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: #000;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.send-btn:hover {
  background: #111;
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.send-icon {
  display: block;
}

.primary-btn,
.ghost-btn {
  border: 1px solid transparent;
  border-radius: 10px;
  height: 40px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: "Inter", sans-serif;
}

.primary-btn {
  background: var(--primary);
  color: var(--primary-foreground);
}

.primary-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ghost-btn {
  color: var(--foreground);
  background: transparent;
  border-color: var(--border);
  height: 32px;
  font-size: 12px;
}

.context-col {
  border-left: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.context-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  font-family: "JetBrains Mono", monospace;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

.source-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--card);
}

.source-card h4 {
  margin: 0 0 4px;
  font-size: 13px;
}

.source-card p {
  margin: 0 0 6px;
  color: var(--muted-foreground);
  font-size: 12px;
}

.source-card a {
  color: var(--foreground);
  font-size: 12px;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  background: var(--card);
}

.empty-state h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.empty-state p {
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--muted-foreground);
}

.small-message {
  color: var(--muted-foreground);
  font-size: 13px;
  margin: 0;
}

.sr-only {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

.hidden {
  display: none;
}

@media (max-width: 1100px) {
  .chat-body {
    grid-template-columns: 1fr;
  }

  .context-col {
    display: none;
  }
}

@media (max-width: 900px) {
  .login-screen {
    grid-template-columns: 1fr;
  }

  .login-left {
    border-right: 0;
    border-bottom: 1px solid var(--sidebar-border);
    padding: 28px 20px;
    gap: 24px;
  }

  .login-brand {
    font-size: 36px;
  }

  .login-right {
    padding: 18px;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--sidebar-border);
    padding-bottom: 14px;
  }

  .session-list {
    max-height: 156px;
  }

  .chat-topbar {
    padding: 14px;
  }

  .thread-col {
    padding: 14px;
  }
}

@media (min-width: 901px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }

  .chat-sidebar {
    min-height: 0;
    overflow: hidden;
  }

  .session-section {
    flex: 1;
    min-height: 0;
  }

  .session-list {
    flex: 1;
    min-height: 0;
  }

  .chat-main {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .chat-body {
    min-height: 0;
    overflow: hidden;
  }

  .thread-col {
    min-height: 0;
    overflow: hidden;
  }

  .thread-list {
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
  }

  .context-col {
    min-height: 0;
    overflow: hidden;
  }

  .sources-list {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }
}

@media (min-width: 1101px) {
  .chat-body {
    /* Keep sources pinned to the far right while centering the chat thread
       with equal whitespace on both sides. */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1030px) minmax(0, 1fr) 320px;
    column-gap: 0;
  }

  .thread-col {
    grid-column: 2;
  }

  .context-col {
    grid-column: 4;
  }
}
