:root {
  --page: #f7f7f4;
  --surface: #ffffff;
  --surface-raised: #fbfbf8;
  --sidebar: #141612;
  --sidebar-raised: #1f231c;
  --sidebar-line: rgba(255, 255, 255, 0.1);
  --text: #171916;
  --muted: #686d63;
  --muted-strong: #454b42;
  --inverse: #f4f6ef;
  --inverse-muted: #b8c0b2;
  --line: #deded7;
  --line-strong: #c7c8bf;
  --accent: #2f7d58;
  --accent-strong: #225f43;
  --accent-soft: #e7f2eb;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --shadow: 0 18px 48px rgba(20, 22, 18, 0.14);
  --sidebar-width: 280px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--page);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.sidebar {
  min-width: 0;
  height: 100dvh;
  min-height: 100vh;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--sidebar);
  color: var(--inverse);
  border-right: 1px solid var(--sidebar-line);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 760;
  font-size: 16px;
}

.brand-mark {
  display: block;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 9px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: currentColor;
  cursor: pointer;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-close {
  display: none;
}

.new-chat-button {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--sidebar-line);
  border-radius: 8px;
  background: var(--sidebar-raised);
  color: var(--inverse);
  cursor: pointer;
  font-weight: 650;
}

.new-chat-button:hover,
.prompt-button:hover,
.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-section {
  display: grid;
  gap: 8px;
}

.sidebar-section h2 {
  margin: 0;
  padding: 0 4px;
  color: var(--inverse-muted);
  font-size: 12px;
  font-weight: 720;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.prompt-list {
  display: grid;
  gap: 4px;
}

.prompt-button,
.sidebar-nav a {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--inverse-muted);
  cursor: pointer;
  text-align: left;
  line-height: 1.25;
}

.prompt-button {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-nav {
  margin-top: auto;
  padding-top: 12px;
  display: grid;
  gap: 2px;
  border-top: 1px solid var(--sidebar-line);
}

.endpoint-card {
  min-height: 38px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--inverse-muted);
  font-size: 12px;
  border: 1px solid var(--sidebar-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #62d18f;
  box-shadow: 0 0 0 4px rgba(98, 209, 143, 0.14);
}

.sidebar-backdrop {
  display: none;
}

.chat-main {
  min-width: 0;
  height: 100dvh;
  min-height: 100vh;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) auto;
  background: var(--page);
}

.topbar {
  min-width: 0;
  height: 64px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 247, 244, 0.92);
  backdrop-filter: blur(14px);
}

.menu-button {
  display: none;
  color: var(--muted-strong);
}

.menu-button:hover {
  background: rgba(23, 25, 22, 0.06);
}

.topbar-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar-title strong,
.topbar-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-title strong {
  font-size: 15px;
  font-weight: 720;
}

.topbar-title span {
  color: var(--muted);
  font-size: 12px;
}

.clear-button {
  min-height: 36px;
  margin-left: auto;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted-strong);
  cursor: pointer;
  font-weight: 650;
}

.clear-button:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.message-region {
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.message-stack {
  width: min(880px, 100%);
  min-height: 100%;
  margin: 0 auto;
  padding: 36px 22px 32px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.welcome-panel {
  min-height: calc(100dvh - 256px);
  display: grid;
  align-content: center;
  gap: 18px;
  padding: 24px 0;
}

.welcome-panel.is-hidden {
  display: none;
}

.welcome-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 760;
  text-align: center;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.welcome-panel h1 {
  margin: 0;
  font-size: clamp(34px, 6vw, 54px);
  line-height: 1.04;
  font-weight: 760;
  text-align: center;
  letter-spacing: 0;
}

.welcome-copy {
  width: min(620px, 100%);
  margin: 0 auto 8px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
  text-align: center;
}

.starter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.starter-card {
  min-height: 112px;
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 1px 0 rgba(23, 25, 22, 0.03);
}

.starter-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.starter-card strong {
  font-size: 14px;
  font-weight: 720;
}

.starter-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.message-row {
  display: flex;
  gap: 12px;
}

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

.message-row.assistant,
.message-row.error {
  justify-content: flex-start;
}

.avatar {
  width: 32px;
  height: 32px;
  margin-top: 22px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.message-row.user .avatar {
  order: 2;
  background: #ecece6;
  color: var(--muted-strong);
}

.message-bubble {
  max-width: min(690px, calc(100% - 44px));
  display: grid;
  gap: 6px;
}

.message-author {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.message-row.user .message-author {
  text-align: right;
}

.message-content {
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-row.user .message-content {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.message-row.error .message-content {
  background: var(--danger-soft);
  border-color: rgba(180, 35, 24, 0.22);
  color: var(--danger);
}

.message-meta {
  color: var(--muted);
  font-size: 12px;
}

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

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
  animation: typingPulse 1s infinite ease-in-out;
}

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

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

.composer {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line);
  background: rgba(247, 247, 244, 0.94);
  backdrop-filter: blur(14px);
}

.composer-box {
  width: min(880px, 100%);
  margin: 0 auto;
  padding: 9px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(23, 25, 22, 0.08);
}

#chatInput {
  min-height: 28px;
  max-height: 180px;
  padding: 5px 6px;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  line-height: 1.45;
}

#chatInput::placeholder {
  color: #8b9086;
}

.send-button {
  min-width: 72px;
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 720;
}

.send-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

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

.composer-note {
  width: min(880px, 100%);
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
}

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

body.sidebar-open {
  overflow: hidden;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }

  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(86vw, 300px);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

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

  .sidebar-close,
  .menu-button {
    display: inline-grid;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    background: rgba(20, 22, 18, 0.42);
  }

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

  .topbar {
    padding: 0 12px;
  }

  .topbar-title span {
    display: none;
  }

  .clear-button {
    min-height: 34px;
    padding: 0 10px;
  }

  .message-stack {
    padding: 28px 14px 22px;
  }

  .welcome-panel {
    min-height: calc(100dvh - 238px);
  }

  .starter-grid {
    grid-template-columns: 1fr;
  }

  .message-row {
    gap: 8px;
  }

  .avatar {
    display: none;
  }

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

  .composer {
    padding: 10px 10px 12px;
  }
}

@media (max-width: 520px) {
  .welcome-panel h1 {
    font-size: 34px;
  }

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

  .composer-box {
    grid-template-columns: 1fr;
  }

  .send-button {
    width: 100%;
  }
}
