:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --sidebar: #f9f9f8;
  --sidebar-hover: #ececec;
  --surface-hover: #f4f4f3;
  --text: #0d0d0d;
  --muted: #6b6b65;
  --faint: #8f8f89;
  --border: #e5e5e0;
  --bubble: #f4f4f4;
  --accent: #10a37f;
  --danger: #b45309;
  --code-bg: #171717;
  --code-text: #f7f7f2;
  --shadow: 0 18px 55px rgb(0 0 0 / 16%);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #212121;
  --surface: #212121;
  --sidebar: #181818;
  --sidebar-hover: #2f2f2f;
  --surface-hover: #2f2f2f;
  --text: #ececec;
  --muted: #b4b4b4;
  --faint: #8e8e8e;
  --border: #333333;
  --bubble: #303030;
  --accent: #19c37d;
  --danger: #f59e0b;
  --code-bg: #0d0d0d;
  --code-text: #f7f7f2;
  --shadow: 0 18px 55px rgb(0 0 0 / 40%);
}

* {
  box-sizing: border-box;
}

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

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

button,
textarea,
select,
input {
  font: inherit;
}

button {
  color: inherit;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--sidebar);
  color: var(--text);
}

.sidebar-top,
.sidebar-bottom {
  padding: 10px;
}

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

.new-chat,
.sidebar-action,
.conversation,
.icon-button,
.title-button,
.send-button,
.tool-button,
.prompt-card,
.auth-panel button,
.message-action {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease, transform 0.14s ease;
}

.new-chat,
.sidebar-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 40px;
  padding: 0 10px;
  background: transparent;
  text-align: left;
}

.sidebar-action.compact {
  color: var(--muted);
}

.new-chat:hover,
.sidebar-action:hover,
.conversation:hover,
.icon-button:hover,
.title-button:hover,
.tool-button:hover,
.prompt-card:hover,
.message-action:hover {
  background: var(--sidebar-hover);
}

.brand-mark,
.auth-mark,
.assistant-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--text);
  color: var(--bg);
  font-weight: 720;
}

.conversation-list {
  flex: 1;
  min-height: 0;
  padding: 8px;
  overflow-y: auto;
}

.conversation {
  display: block;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  overflow: hidden;
  background: transparent;
  text-align: left;
}

.conversation span {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation.active {
  background: var(--sidebar-hover);
}

.sidebar-bottom {
  display: grid;
  gap: 4px;
}

.sidebar-bottom .sidebar-action {
  color: var(--muted);
}

.chat-pane {
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
}

.topbar-spacer {
  flex: 1;
}

.title-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 40px;
  padding: 0 12px;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
}

.title-button svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: transparent;
  color: var(--muted);
}

.mobile-only {
  display: none;
}

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

.message {
  padding: 12px 20px;
}

.message-inner {
  width: min(768px, 100%);
  margin: 0 auto;
}

.user-inner {
  display: grid;
  justify-items: end;
}

.user-bubble {
  max-width: min(620px, 80%);
  padding: 10px 16px;
  border-radius: 18px;
  background: var(--bubble);
  color: var(--text);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.assistant-inner {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 12px;
}

.assistant-mark {
  width: 28px;
  height: 28px;
  margin-top: 2px;
  border-radius: 50%;
  background: var(--surface-hover);
  color: var(--text);
  font-size: 13px;
}

.assistant-content {
  min-width: 0;
}

.sent-attachments {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  max-width: min(620px, 80%);
  margin-top: 8px;
}

.sent-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 280px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.sent-attachment span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message.error .message-content {
  color: var(--danger);
}

.message-content,
.user-bubble {
  font-size: 16px;
}

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

.message-content p,
.user-bubble p {
  margin: 0 0 12px;
}

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

.message-content ul,
.user-bubble ul {
  margin: 0 0 12px 20px;
  padding: 0;
}

.message-content li,
.user-bubble li {
  margin: 5px 0;
}

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

.message-content code,
.user-bubble code {
  border-radius: 5px;
  background: var(--surface-hover);
  padding: 2px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

pre {
  margin: 14px 0;
  overflow: hidden;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
}

pre code {
  display: block;
  overflow-x: auto;
  background: transparent !important;
  padding: 16px;
  color: inherit;
  white-space: pre;
}

.codebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 34px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid rgb(255 255 255 / 10%);
  color: #cacac4;
  font-size: 12px;
}

.copy-code {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.copy-code:hover {
  color: #fff;
}

.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.14s ease;
}

.message:hover .message-actions {
  opacity: 1;
}

.message-action {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  background: transparent;
  color: var(--muted);
}

.message-action svg {
  width: 17px;
  height: 17px;
}

.status-line {
  color: var(--muted);
}

.image-grid {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}

.generated-image-card {
  width: min(520px, 100%);
  margin: 0;
}

.generated-image-card a {
  display: block;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-hover);
}

.generated-image-card img {
  display: block;
  width: 100%;
  height: auto;
}

.generated-image-card figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.generated-image-card.unavailable {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--muted);
}

.cursor-dot {
  display: inline-block;
  width: 7px;
  height: 18px;
  margin-left: 2px;
  border-radius: 3px;
  background: var(--text);
  vertical-align: -3px;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 100%;
  padding: 30px 20px 120px;
  text-align: center;
}

.empty-state h1 {
  margin: 0 0 26px;
  color: var(--text);
  font-size: 30px;
  font-weight: 520;
  letter-spacing: 0;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(190px, 290px));
  gap: 10px;
}

.prompt-card {
  min-height: 62px;
  padding: 13px 14px;
  border-color: var(--border);
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.composer-wrap {
  padding: 14px 20px 14px;
}

.composer {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 8px;
  width: min(768px, 100%);
  margin: 0 auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 6px 28px rgb(0 0 0 / 8%);
}

.file-input {
  display: none;
}

textarea {
  width: 100%;
  max-height: 220px;
  min-height: 30px;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  padding: 2px 8px 0;
  font-size: 16px;
  line-height: 1.45;
}

textarea::placeholder {
  color: var(--faint);
}

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

.composer-controls,
.composer-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.tool-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-color: var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}

.tool-button svg {
  width: 18px;
  height: 18px;
}

.chip-select {
  display: block;
  min-width: 0;
}

.chip-select select {
  max-width: 174px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 0 28px 0 12px;
  font-size: 14px;
}

.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-width: 0;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 100%;
  height: 34px;
  padding: 0 8px 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-hover);
  color: var(--text);
  font-size: 13px;
}

.attachment-kind,
.attachment-size {
  color: var(--muted);
}

.attachment-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-remove {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.attachment-remove:hover {
  background: var(--sidebar-hover);
  color: var(--text);
}

.send-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
}

.send-button:hover {
  transform: translateY(-1px);
}

.send-button.stop {
  background: var(--text);
  color: var(--bg);
}

.send-button svg {
  width: 18px;
  height: 18px;
}

.fineprint {
  width: min(768px, 100%);
  margin: 8px auto 0;
  color: var(--faint);
  font-size: 12px;
  text-align: center;
}

.hidden {
  display: none !important;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 40;
  background: rgb(0 0 0 / 48%);
  padding: 20px;
}

.auth-panel {
  display: grid;
  gap: 14px;
  width: min(360px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-mark {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  font-size: 20px;
}

.auth-panel h1 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0;
}

.auth-panel input {
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

.auth-panel button {
  height: 42px;
  background: var(--text);
  color: var(--bg);
}

.auth-error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
}

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

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

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

  .mobile-only {
    display: grid;
  }

  .chat-pane {
    grid-template-rows: 54px minmax(0, 1fr) auto;
  }

  .topbar {
    padding: 7px 8px;
  }

  .title-button {
    max-width: calc(100vw - 140px);
    padding: 0 8px;
    font-size: 17px;
  }

  .message {
    padding: 12px 12px;
  }

  .assistant-inner {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px;
  }

  .assistant-mark {
    width: 25px;
    height: 25px;
    font-size: 12px;
  }

  .message-content,
  .user-bubble {
    font-size: 15px;
  }

  .user-bubble {
    max-width: 88%;
  }

  .prompt-grid {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .composer-wrap {
    padding: 10px;
  }

  .composer {
    border-radius: 24px;
  }

  .composer-toolbar {
    align-items: flex-end;
  }

  .composer-controls {
    overflow-x: auto;
    padding-bottom: 1px;
  }

  .chip-select select {
    max-width: 132px;
    font-size: 13px;
  }

  .empty-state {
    padding-bottom: 90px;
  }

  .empty-state h1 {
    font-size: 26px;
  }
}
