:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-alt: #ecebe7;
  --text: #202123;
  --muted: #6e6e73;
  --border: #d9d9d2;
  --accent: #10a37f;
  --accent-dark: #0c7f63;
  --danger-bg: #fff1f0;
  --danger-text: #b42318;
}

* {
  box-sizing: border-box;
}

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

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

button,
textarea,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 100vh;
  padding: 14px;
  background: #171717;
  color: #f8f8f8;
}

.sidebar-top {
  display: grid;
  gap: 14px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  font-weight: 650;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand-mark.small {
  width: 30px;
  height: 30px;
  font-size: 0.85rem;
}

.sidebar-spacer {
  flex: 1;
}

.full-width {
  width: 100%;
}

.secondary-button,
.ghost-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 12px;
  text-align: left;
}

.secondary-button {
  background: #2f2f2f;
  color: #fff;
}

.ghost-button {
  background: transparent;
  color: #d7d7d7;
}

.secondary-button:hover,
.ghost-button:hover {
  background: #3a3a3a;
}

.chat-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 100vh;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(247, 247, 245, 0.86);
  backdrop-filter: blur(10px);
}

.chat-header h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.chat-header p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.message-list {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: 32px 20px 120px;
}

.message-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 16px;
  padding: 22px 0;
}

.message-row + .message-row {
  border-top: 1px solid var(--border);
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #222;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}

.message-row.assistant .avatar {
  background: var(--accent);
}

.message-content {
  min-width: 0;
  padding-top: 4px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.markdown-content {
  white-space: normal;
}

.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 table {
  margin: 0 0 1rem;
}

.markdown-content ul,
.markdown-content ol {
  padding-left: 1.45rem;
}

.markdown-content li + li {
  margin-top: 0.25rem;
}

.markdown-content code {
  border-radius: 5px;
  padding: 0.12rem 0.3rem;
  background: var(--surface-alt);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.markdown-content pre {
  overflow-x: auto;
  border-radius: 8px;
  padding: 14px;
  background: #202123;
  color: #f7f7f5;
}

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

.markdown-content blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  color: var(--muted);
}

.markdown-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.markdown-content th,
.markdown-content td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.6rem;
  text-align: left;
}

.message-row.pending .message-content {
  color: var(--muted);
}

.message-row.pending .message-content::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: thinking-dots 1.2s steps(4, end) infinite;
}

@keyframes thinking-dots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75%,
  100% {
    content: "...";
  }
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 48vh;
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  font-size: clamp(1.7rem, 4vw, 2.45rem);
  font-weight: 650;
}

.composer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 10px;
  width: min(calc(100% - 32px), 820px);
  min-height: 138px;
  margin: 0 auto 22px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.10);
}

.composer textarea {
  width: 100%;
  height: 116px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 10px 6px 8px 10px;
  color: var(--text);
  background: transparent;
  line-height: 1.45;
  overflow-y: auto;
}

.composer button {
  align-self: end;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--text);
  color: #fff;
  font-size: 1.2rem;
}

.composer button:hover {
  background: var(--accent-dark);
}

.composer[aria-busy="true"] {
  opacity: 0.72;
}

.composer[aria-busy="true"] textarea {
  color: var(--muted);
}

.composer button:disabled {
  cursor: wait;
  background: var(--accent);
}

.error-banner {
  width: min(calc(100% - 32px), 820px);
  margin: 18px auto 0;
  padding: 12px 14px;
  border: 1px solid #ffd3cf;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger-text);
}

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: #f4f2ee;
}

.auth-panel {
  width: min(100%, 390px);
  padding: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.08);
}

.auth-panel h1 {
  margin: 22px 0;
  font-size: 1.8rem;
}

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

.auth-form label {
  font-weight: 650;
}

.auth-form input {
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
}

.auth-form input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(16, 163, 127, 0.16);
}

.auth-form button {
  min-height: 46px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.auth-form button:hover {
  background: var(--accent-dark);
}

.form-error {
  margin: 0;
  color: var(--danger-text);
}

.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;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    flex-direction: row;
    align-items: center;
    min-height: 0;
  }

  .sidebar-top {
    display: flex;
    align-items: center;
    flex: 1;
  }

  .brand-row span:last-child {
    display: none;
  }

  .secondary-button,
  .ghost-button {
    min-width: 98px;
    text-align: center;
  }

  .sidebar-spacer {
    display: none;
  }

  .chat-header {
    min-height: 58px;
    padding: 10px 16px;
  }

  .message-list {
    padding: 18px 16px 110px;
  }

  .message-row {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
    padding: 18px 0;
  }

  .composer {
    width: calc(100% - 20px);
    margin-bottom: 10px;
  }
}
