:root {
  --bg: #0f1117;
  --surface: #161b27;
  --border: #252d3d;
  --text: #e8e6e1;
  --muted: #5a6478;
  --accent: #7eb8f7;
  --sidebar: var(--surface);
  --surface-soft: var(--surface);
  --border-strong: var(--border);
  --accent-ink: var(--bg);
  --muted-strong: var(--text);
  --danger: var(--accent);
  --selection: color-mix(in srgb, var(--accent) 20%, transparent);
  --radius: 4px;
  --radius-tight: 2px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-6: 48px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Geist", sans-serif;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
}

::selection {
  background: var(--selection);
  color: var(--text);
}

* {
  scrollbar-color: var(--border) var(--bg);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: var(--bg);
}

*::-webkit-scrollbar-thumb {
  background: var(--border);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1,
h2,
h3,
h4 {
  font-weight: 500;
  letter-spacing: -0.01em;
}

strong {
  font-weight: 500;
}

.app-shell {
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  padding: var(--space-3);
  border-right: 1px solid var(--border);
  background: var(--sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-tight);
  background: var(--surface);
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 500;
}

.brand h1,
.topbar h2,
.empty-state h3 {
  font-family: "Geist", sans-serif;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.brand h1 {
  font-size: 1rem;
  line-height: 1.1;
}

.brand p,
.eyebrow,
.section-label,
.message-label,
.source-tag,
.activity-tag,
.new-session-button,
.composer button,
.connection-pill {
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.brand p,
.eyebrow,
.section-label {
  color: var(--muted);
}

.new-session-button,
.composer button {
  border: 1px solid var(--accent);
  border-radius: var(--radius-tight);
  background: var(--accent);
  color: var(--accent-ink);
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.new-session-button {
  width: 100%;
  padding: 12px var(--space-2);
}

.new-session-button:hover,
.composer button:hover {
  background: var(--bg);
  color: var(--accent);
}

.new-session-button:disabled,
.composer button:disabled {
  cursor: not-allowed;
  opacity: 0.54;
}

.sidebar-section {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: var(--space-2);
}

.session-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: var(--space-1);
  overflow-y: auto;
  padding-right: 2px;
}

.session-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  gap: var(--space-1);
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted-strong);
  padding: var(--space-1);
}

.session-item:hover,
.session-item.active {
  border-color: var(--accent);
  color: var(--text);
}

.session-open {
  min-width: 0;
  border: 0;
  background: none;
  color: inherit;
  padding: 0;
  text-align: left;
}

.session-delete {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-tight);
  background: var(--surface-soft);
  color: var(--danger);
  font-size: 1rem;
  line-height: 1;
}

.trash-icon {
  position: relative;
  width: 13px;
  height: 15px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 var(--radius-tight) var(--radius-tight);
}

.trash-icon::before {
  position: absolute;
  top: -5px;
  left: -3px;
  width: 15px;
  height: 2px;
  background: currentColor;
  content: "";
}

.trash-icon::after {
  position: absolute;
  top: -8px;
  left: 3px;
  width: 5px;
  height: 3px;
  border: 2px solid currentColor;
  border-bottom: 0;
  border-radius: var(--radius-tight) var(--radius-tight) 0 0;
  content: "";
}

.session-delete:hover {
  border-color: var(--danger);
}

.session-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
  font-weight: 500;
}

.session-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: 88px;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  min-width: 0;
}

.topbar h2 {
  margin-top: var(--space-1);
  font-size: clamp(1.4rem, 2.5vw, 2.35rem);
  line-height: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.connection-pill {
  min-width: 92px;
  border: 1px solid var(--border);
  border-radius: var(--radius-tight);
  padding: var(--space-1) 12px;
  background: var(--surface);
  color: var(--accent);
  text-align: center;
}

.mobile-icon-button,
.sidebar-backdrop {
  display: none;
}

.mobile-icon-button {
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-tight);
  background: var(--surface);
  color: var(--accent);
  font-size: 1.25rem;
  line-height: 1;
}

.menu-button {
  gap: 4px;
}

.menu-button span {
  display: block;
  width: 15px;
  height: 1px;
  background: currentColor;
}

.connection-pill.busy {
  border-color: var(--accent);
}

.connection-pill.error {
  border-color: var(--danger);
  color: var(--danger);
}

.response-panel,
.activity-panel,
.composer {
  border: 0;
  border-radius: 0;
  background: var(--bg);
}

.response-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4);
  scroll-behavior: smooth;
}

.empty-state {
  display: grid;
  min-height: 100%;
  align-content: center;
  gap: var(--space-2);
  color: var(--muted-strong);
}

.empty-state h3 {
  color: var(--text);
  font-size: clamp(2rem, 5vw, 4.5rem);
  line-height: 0.95;
}

.empty-state p {
  max-width: 680px;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.65;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: min(960px, 100%);
  margin: 0 auto;
}

.chat-message {
  width: 100%;
}

.chat-message.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.chat-message.assistant {
  display: block;
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
}

.message-label {
  margin-bottom: var(--space-1);
  color: var(--muted);
}

.chat-message.user .message-label {
  color: var(--accent);
}

.message-body {
  color: var(--text);
  font-family: "Source Serif 4", serif;
  font-size: 0.98rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.75;
}

.chat-message.user .message-body {
  max-width: min(760px, 88%);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-tight);
  background: var(--surface);
  color: var(--text);
  padding: 12px var(--space-2);
  line-height: 1.75;
}

.message-body:empty {
  display: none;
}

.message-body.thinking {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-tight);
  background: var(--surface);
  padding: 10px 12px;
  color: var(--muted-strong);
}

.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-family: "Geist", sans-serif;
  font-size: 0.88rem;
  font-weight: 500;
}

.thinking-indicator::after {
  width: 8px;
  color: var(--accent);
  content: "_";
  animation: cursorBlink 1s steps(1) infinite;
}

.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.thinking-dots span {
  width: 5px;
  height: 5px;
  border-radius: var(--radius-tight);
  background: var(--accent);
  animation: thinkingPulse 1s ease-in-out infinite;
  opacity: 0.3;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 140ms;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 280ms;
}

@keyframes thinkingPulse {
  0%,
  80%,
  100% {
    opacity: 0.28;
  }

  40% {
    opacity: 1;
  }
}

@keyframes cursorBlink {
  0%,
  48% {
    opacity: 1;
  }

  49%,
  100% {
    opacity: 0;
  }
}

.message-body h3 {
  margin: var(--space-4) 0 var(--space-1);
  color: var(--accent);
  font-family: "Geist", sans-serif;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}

.message-body strong {
  font-weight: 500;
}

.message-body p {
  margin: 0 0 var(--space-2);
}

.message-body code,
.message-body pre {
  border: 1px solid var(--border-strong);
  background: var(--surface-soft);
}

.message-body code {
  padding: 1px 4px;
  border-radius: var(--radius-tight);
}

.message-body a,
.source-card a {
  color: var(--accent);
  text-decoration: none;
}

.message-body a:hover,
.source-card a:hover {
  text-decoration: underline;
}

.sources {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-2);
  width: min(960px, 100%);
  margin: var(--space-4) auto 0;
}

.source-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-tight);
  background: var(--surface);
  padding: var(--space-2);
}

.source-tag,
.activity-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-tight);
  padding: 2px 6px;
  background: var(--surface-soft);
  color: var(--accent);
}

.source-card h4 {
  margin: var(--space-1) 0;
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.45;
}

.source-card p {
  color: var(--muted-strong);
  font-size: 0.8rem;
  line-height: 1.65;
}

.activity-panel {
  min-height: 96px;
  max-height: 128px;
  overflow-y: auto;
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.activity-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

.activity-item {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-tight);
  background: var(--surface-soft);
  padding: 6px var(--space-1);
  color: var(--muted-strong);
  font-size: 0.78rem;
}

.activity-item.failed,
.activity-item.rate_limited {
  border-color: var(--danger);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer textarea {
  width: 100%;
  min-height: 56px;
  max-height: 144px;
  resize: vertical;
  border: 1px solid var(--border-strong);
  border-radius: 0;
  outline: none;
  background: var(--bg);
  color: var(--text);
  padding: 12px var(--space-2);
  font-family: "Geist", sans-serif;
  line-height: 1.65;
}

.composer textarea:focus {
  border-color: var(--accent);
}

.composer textarea::placeholder {
  color: var(--muted);
}

.composer button {
  min-height: 56px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand action"
      "sessions sessions";
    gap: var(--space-2);
    min-height: 0;
    max-height: 180px;
    padding: var(--space-2) var(--space-3);
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand {
    grid-area: brand;
    min-width: 0;
  }

  .brand h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .new-session-button {
    grid-area: action;
    width: auto;
    min-width: 132px;
    padding: 10px 12px;
  }

  .sidebar-section {
    grid-area: sessions;
    min-width: 0;
    gap: var(--space-1);
  }

  .session-list {
    flex-direction: row;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0 2px;
  }

  .session-item {
    min-width: 220px;
    max-width: 260px;
  }

  .topbar,
  .response-panel,
  .activity-panel,
  .composer {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
}

@media (max-width: 620px) {
  body {
    font-size: 14px;
  }

  .app-shell {
    position: relative;
    grid-template-rows: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 20;
    width: min(86vw, 320px);
    height: 100vh;
    height: 100dvh;
    max-height: none;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "brand"
      "sessions";
    padding: 12px var(--space-2);
    border-bottom: 0;
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 180ms ease;
  }

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

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10;
    border: 0;
    background: color-mix(in srgb, var(--bg) 72%, transparent);
  }

  .sessions-open .sidebar-backdrop {
    display: block;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand h1 {
    font-size: 0.95rem;
  }

  .brand p {
    display: none;
  }

  .new-session-button {
    display: none;
  }

  .section-label {
    font-size: 0.64rem;
  }

  .session-list {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0 2px 0 0;
  }

  .session-item {
    min-width: 0;
    max-width: none;
  }

  .session-name {
    font-size: 0.8rem;
  }

  .session-meta {
    font-size: 0.68rem;
  }

  .workspace {
    min-height: 0;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    gap: var(--space-1);
    min-height: auto;
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
  }

  .topbar h2 {
    max-width: 100%;
    overflow-wrap: anywhere;
    font-size: clamp(1.15rem, 7vw, 1.7rem);
    line-height: 1.05;
  }

  .topbar-title {
    flex: 1;
  }

  .topbar-actions {
    flex: 0 0 auto;
  }

  .connection-pill {
    min-width: 0;
    padding: 6px var(--space-1);
    font-size: 0.64rem;
  }

  .mobile-icon-button {
    display: grid;
  }

  .response-panel {
    gap: var(--space-2);
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
  }

  .empty-state {
    align-content: start;
    padding-top: var(--space-4);
  }

  .empty-state h3 {
    font-size: clamp(2rem, 12vw, 3.1rem);
  }

  .empty-state p {
    font-size: 0.92rem;
  }

  .chat-thread {
    gap: var(--space-3);
  }

  .chat-message.assistant {
    padding-top: var(--space-2);
  }

  .chat-message.user {
    align-items: stretch;
  }

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

  .message-body {
    font-size: 0.96rem;
  }

  .sources {
    grid-template-columns: 1fr;
    gap: var(--space-1);
    margin-top: var(--space-2);
  }

  .source-card {
    padding: 12px;
  }

  .activity-panel {
    display: none;
  }

  .composer {
    grid-template-columns: 1fr;
    gap: var(--space-1);
    padding-top: var(--space-1);
    padding-bottom: var(--space-1);
  }

  .composer textarea {
    min-height: 48px;
    max-height: 104px;
    font-size: 16px;
    line-height: 1.5;
  }

  .composer button {
    width: 100%;
    min-height: 44px;
  }
}

@media (max-width: 420px) {
  .sidebar {
    width: min(90vw, 300px);
  }

  .brand-mark {
    display: none;
  }

  .session-item {
    min-width: 168px;
  }

  .topbar,
  .response-panel,
  .activity-panel,
  .composer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .brand p,
  .eyebrow,
  .section-label,
  .message-label,
  .source-tag,
  .activity-tag,
  .new-session-button,
  .composer button,
  .connection-pill {
    letter-spacing: 1px;
  }
}
