:root {
  color-scheme: dark;
  --bg: #212121;
  --sidebar-bg: #171717;
  --surface: #2b2b2b;
  --surface-high: #303030;
  --surface-hover: #383838;
  --line: #3d3d3d;
  --line-soft: rgba(255, 255, 255, 0.08);
  --text: #ececec;
  --muted: #b4b4b4;
  --faint: #858585;
  --primary: #f4f4f4;
  --primary-text: #1f1f1f;
  --accent: #c9b8ff;
  --danger: #ffb1aa;
  --radius-sm: 6px;
  --radius: 8px;
  --sidebar: 272px;
  font-family: "Geist", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  height: 100vh;
  min-height: 620px;
  background: var(--bg);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line-soft);
  padding: 14px 12px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 2px 6px;
}

.eyebrow,
.section-label {
  margin: 0;
  color: var(--faint);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.sidebar h1 {
  margin: 5px 0 0;
  color: var(--text);
  font-size: 22px;
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: 0;
}

.nav-action,
.ghost-button,
.thread-item,
.icon-button,
.send-button,
.model-tab,
.mini-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, opacity 140ms ease;
}

.nav-action {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  justify-content: flex-start;
  background: transparent;
  border: 1px solid var(--line-soft);
  color: var(--text);
  font-size: 14px;
  font-weight: 560;
}

.nav-action:hover,
.nav-action.active {
  background: var(--surface);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  margin: 10px 0 20px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: #202020;
  color: var(--muted);
}

.search-box:focus-within {
  border-color: var(--line);
  background: #242424;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.search-box input::placeholder,
textarea::placeholder,
.token-form input::placeholder {
  color: color-mix(in srgb, var(--muted) 70%, transparent);
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.section-label {
  padding: 0 8px 10px;
}

.thread-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.thread-item {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.thread-item:hover,
.thread-item.active {
  background: var(--surface);
  color: var(--text);
}

.thread-title {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 520;
}

.thread-meta {
  color: var(--faint);
  font-size: 12px;
}

.empty-thread {
  padding: 8px 10px;
}

.sidebar-footer {
  padding-top: 12px;
}

.ghost-button {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  justify-content: flex-start;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

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

.chat-stage {
  position: relative;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
  background: var(--bg);
  overflow: hidden;
}

.animated-lines {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0.68;
  background:
    linear-gradient(180deg, rgba(33, 33, 33, 0.06), rgba(33, 33, 33, 0.62) 76%, #212121),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.055) 0 1px, transparent 1px 88px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 88px);
}

.animated-lines::before,
.animated-lines::after {
  content: "";
  position: absolute;
  inset: -45%;
  background:
    repeating-linear-gradient(
      115deg,
      transparent 0 68px,
      rgba(230, 230, 230, 0.12) 69px 70px,
      transparent 71px 148px
    );
  animation: line-drift 28s linear infinite;
  will-change: transform;
}

.animated-lines::after {
  background:
    repeating-linear-gradient(
      65deg,
      transparent 0 112px,
      rgba(210, 210, 210, 0.07) 113px 114px,
      transparent 115px 210px
    );
  animation-duration: 42s;
  animation-direction: reverse;
}

@keyframes line-drift {
  from {
    transform: translate3d(-56px, 36px, 0);
  }

  to {
    transform: translate3d(56px, -36px, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .animated-lines::before,
  .animated-lines::after {
    animation: none;
  }
}

.topbar,
.conversation,
.composer-wrap {
  z-index: 1;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(44px, 1fr) auto minmax(44px, 1fr);
  align-items: center;
  padding: 12px 22px;
}

.topbar-actions {
  display: flex;
  justify-content: flex-end;
}

.model-tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  min-height: 38px;
  padding: 3px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #272727;
}

.model-tab {
  min-width: 122px;
  min-height: 30px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 560;
}

.model-tab.active {
  background: #3a3a3a;
  color: var(--text);
}

.icon-button,
.mini-button {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover,
.mini-button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-button svg,
.send-button svg,
.nav-action svg,
.ghost-button svg,
.search-box svg,
.mini-button svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.9;
}

.conversation {
  min-height: 0;
  overflow-y: auto;
  padding: 18px clamp(18px, 6vw, 84px) 26px;
  scroll-behavior: smooth;
}

.conversation-inner {
  display: flex;
  flex-direction: column;
  gap: 26px;
  width: min(100%, 800px);
  margin: 0 auto;
  padding-bottom: 22px;
}

.message {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.message-avatar {
  display: none;
}

.message-body {
  min-width: 0;
  max-width: 100%;
}

.message.user .message-body {
  width: fit-content;
  max-width: min(78%, 680px);
  margin-left: auto;
  border-radius: var(--radius);
  background: var(--surface-high);
  padding: 11px 14px;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 24px;
  margin-bottom: 4px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 620;
}

.message.user .message-meta {
  display: none;
}

.mini-button {
  width: 30px;
  height: 30px;
  opacity: 0;
}

.message:hover .mini-button {
  opacity: 1;
}

.message-content {
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.68;
  overflow-wrap: anywhere;
}

.message.user .message-content {
  line-height: 1.5;
}

.message-content p {
  margin: 0 0 14px;
}

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

.message-content code {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: #1b1b1b;
  padding: 1px 5px;
  color: #f2f2f2;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.message-content pre {
  margin: 12px 0;
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #171717;
  padding: 14px;
}

.message-content pre code {
  border: 0;
  padding: 0;
  background: transparent;
  white-space: pre;
}

.message-content a {
  color: var(--accent);
}

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

.typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 900ms infinite ease-in-out;
}

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

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

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.composer-wrap {
  width: min(100%, 800px);
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 28px) 16px;
}

.prompt-surface {
  position: absolute;
  left: clamp(18px, 6vw, 84px);
  right: clamp(18px, 6vw, 84px);
  top: 45%;
  display: none;
  max-width: 800px;
  margin: 0 auto;
  transform: translateY(-50%);
  text-align: center;
  pointer-events: none;
}

.prompt-surface.visible {
  display: block;
}

.prompt-surface h2 {
  margin: 10px 0 0;
  color: var(--text);
  font-size: clamp(30px, 4vw, 42px);
  font-weight: 620;
  line-height: 1.15;
  letter-spacing: 0;
}

.composer {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  align-items: end;
  gap: 8px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-high);
  padding: 8px;
}

.composer:focus-within {
  border-color: #606060;
}

textarea {
  width: 100%;
  max-height: 180px;
  min-height: 40px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  line-height: 1.5;
  padding: 8px 2px;
}

.send-button {
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: var(--primary-text);
}

.send-button:hover {
  background: #ffffff;
}

.send-button[disabled] {
  opacity: 0.58;
  cursor: not-allowed;
}

.fine-print {
  margin: 9px 0 0;
  color: var(--faint);
  font-size: 11px;
  text-align: center;
}

.modal-backdrop,
.scrim {
  position: fixed;
  inset: 0;
}

.modal-backdrop {
  display: grid;
  place-items: center;
  z-index: 50;
  background: rgba(0, 0, 0, 0.56);
  backdrop-filter: blur(10px);
  padding: 18px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.modal h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.token-form {
  display: grid;
  gap: 12px;
}

.token-form input {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: #1f1f1f;
  color: var(--text);
  padding: 0 12px;
}

.token-form input:focus {
  border-color: #666666;
}

.primary-button {
  min-height: 44px;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 700;
}

.primary-button:hover {
  background: #ffffff;
}

.scrim {
  display: none;
  z-index: 20;
  background: rgba(0, 0, 0, 0.42);
}

.mobile-only {
  display: none;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #4a4a4a;
  border-radius: 8px;
}

@media (max-width: 780px) {
  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, 320px);
    transform: translateX(-100%);
    transition: transform 180ms ease;
    z-index: 30;
  }

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

  body.sidebar-open .scrim {
    display: block;
  }

  .mobile-only {
    display: inline-flex;
  }

  .chat-stage {
    height: 100vh;
    grid-template-rows: 62px minmax(0, 1fr) auto;
  }

  .topbar {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    padding: 10px 12px;
  }

  .model-tabs {
    width: 100%;
  }

  .model-tab {
    min-width: 0;
    padding: 0 8px;
  }

  .conversation {
    padding: 12px 14px 20px;
  }

  .message.user .message-body {
    max-width: 88%;
  }

  .composer-wrap {
    padding-inline: 12px;
  }

  .prompt-surface {
    left: 18px;
    right: 18px;
    top: 44%;
  }

  .prompt-surface h2 {
    font-size: 32px;
  }
}
