:root {
  color-scheme: light;
  --bg: #f7f7f7;
  --surface: #ffffff;
  --surface-2: #f1f1f1;
  --surface-3: #e7e7e7;
  --text: #111111;
  --muted: #6f6f6f;
  --line: #dedede;
  --accent: #111111;
  --accent-2: #6a6a6a;
  --accent-ink: #ffffff;
  --danger: #333333;
  --shadow: 0 18px 54px rgba(0, 0, 0, 0.12);
  --radius: 8px;
  --sidebar-width: 292px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #101010;
    --surface: #171717;
    --surface-2: #202020;
    --surface-3: #2b2b2b;
    --text: #f4f4f4;
    --muted: #a8a8a8;
    --line: #343434;
    --accent: #f4f4f4;
    --accent-2: #8d8d8d;
    --accent-ink: #111111;
    --danger: #d0d0d0;
    --shadow: 0 20px 70px rgba(0, 0, 0, 0.34);
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7f7;
  --surface: #ffffff;
  --surface-2: #f1f1f1;
  --surface-3: #e7e7e7;
  --text: #111111;
  --muted: #6f6f6f;
  --line: #dedede;
  --accent: #111111;
  --accent-2: #6a6a6a;
  --accent-ink: #ffffff;
  --danger: #333333;
  --shadow: 0 18px 54px rgba(0, 0, 0, 0.12);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101010;
  --surface: #171717;
  --surface-2: #202020;
  --surface-3: #2b2b2b;
  --text: #f4f4f4;
  --muted: #a8a8a8;
  --line: #343434;
  --accent: #f4f4f4;
  --accent-2: #8d8d8d;
  --accent-ink: #111111;
  --danger: #d0d0d0;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  letter-spacing: 0;
}

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

button {
  color: inherit;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100vh;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.brand-mark,
.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 760;
}

.brand-copy {
  display: grid;
  min-width: 0;
}

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

.brand-copy span,
.topbar-title span,
.modal-head span,
.message-meta,
.composer-note {
  color: var(--muted);
  font-size: 12px;
}

.primary-action,
.secondary-button,
.text-button,
.sidebar-tool,
.icon-button,
.send-button,
.conversation-row {
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 120ms ease;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.primary-action.compact {
  min-height: 38px;
}

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

.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
}

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

.conversation-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.conversation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 9px;
  text-align: left;
}

.conversation-row:hover,
.conversation-row.active,
.icon-button:hover,
.sidebar-tool:hover,
.secondary-button:hover,
.text-button:hover {
  background: var(--surface-3);
}

.conversation-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-row time {
  color: var(--muted);
  font-size: 11px;
}

.sidebar-footer {
  display: grid;
  gap: 6px;
}

.sidebar-tool {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding: 0 9px;
  color: var(--muted);
  text-align: left;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
}

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

.topbar-actions,
.composer-actions,
.message-actions,
.modal-actions,
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.send-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
}

.icon-button {
  color: var(--muted);
}

.danger-soft:hover {
  background: var(--surface-3);
  color: var(--danger);
}

.send-button {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 28px 18px 20px;
  scroll-behavior: smooth;
}

.empty-state {
  display: grid;
  align-content: center;
  gap: 24px;
  width: min(760px, 100%);
  min-height: 100%;
  margin: 0 auto;
}

.empty-title {
  display: grid;
  gap: 8px;
  text-align: center;
}

.empty-title h1 {
  margin: 0;
  font-size: clamp(30px, 6vw, 52px);
  line-height: 1.04;
  letter-spacing: 0;
}

.empty-title p {
  margin: 0;
  color: var(--muted);
}

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

.prompt-chip {
  min-height: 74px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.prompt-chip:hover {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
  background: var(--surface-2);
}

.thread {
  width: min(820px, 100%);
  margin: 0 auto;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 12px;
  padding: 18px 0;
}

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

.message.user .avatar {
  background: var(--accent-2);
  color: #fff;
}

.message-body {
  min-width: 0;
}

.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 28px;
}

.message-name {
  font-weight: 730;
}

.message-actions {
  opacity: 0;
  transition: opacity 140ms ease;
}

.message:hover .message-actions,
.message:focus-within .message-actions {
  opacity: 1;
}

.mini-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

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

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

.message-text p {
  margin: 0 0 12px;
}

.message-text h1,
.message-text h2,
.message-text h3 {
  margin: 18px 0 10px;
  line-height: 1.25;
  letter-spacing: 0;
}

.message-text h1 {
  font-size: 1.42rem;
}

.message-text h2 {
  font-size: 1.22rem;
}

.message-text h3 {
  font-size: 1.06rem;
}

.message-text ul,
.message-text ol {
  margin: 0 0 12px;
  padding-left: 24px;
}

.message-text li + li {
  margin-top: 5px;
}

.message-text blockquote {
  margin: 12px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--muted);
  background: var(--surface-2);
  color: var(--text);
}

.message-text a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.message-text p:last-child,
.message-text pre:last-child {
  margin-bottom: 0;
}

.message-text pre {
  overflow: auto;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.message-text code {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.message-text :not(pre) > code {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--surface-2);
}

.message-meta {
  min-height: 18px;
  margin-top: 8px;
}

.typing-caret::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-left: 3px;
  vertical-align: -0.2em;
  background: var(--accent);
  animation: blink 900ms steps(2, start) infinite;
}

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

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

.composer-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

.composer textarea {
  width: 100%;
  max-height: 210px;
  min-height: 42px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 10px 9px;
  background: transparent;
  color: var(--text);
  line-height: 1.5;
}

.composer-note {
  width: min(820px, 100%);
  min-height: 18px;
  margin: 7px auto 0;
  text-align: center;
}

.modal {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 12px;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.modal-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.modal-head > div {
  display: grid;
  gap: 2px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span,
.section-title strong {
  font-size: 13px;
  font-weight: 740;
}

.field textarea,
.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  padding: 10px;
  background: var(--surface-2);
  color: var(--text);
}

.field textarea:focus,
.field input:focus,
.field select:focus,
.search-box:focus-within,
.composer-inner:focus-within {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
}

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

.model-settings {
  display: grid;
  gap: 10px;
}

.section-title {
  justify-content: space-between;
}

.model-list {
  display: grid;
  gap: 7px;
  max-height: 270px;
  overflow: auto;
}

.model-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.model-row label {
  display: grid;
  min-width: 0;
}

.model-row small {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-order {
  display: flex;
  gap: 4px;
}

.secondary-button,
.text-button {
  min-height: 36px;
  padding: 0 12px;
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface-2);
}

.text-button {
  color: var(--accent);
}

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.mobile-only {
  display: none;
}

.scrim {
  display: none;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

@media (max-width: 820px) {
  .app {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-width), calc(100vw - 42px));
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

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

  .scrim {
    position: fixed;
    z-index: 15;
    inset: 0;
    background: rgba(0, 0, 0, 0.28);
  }

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

  .mobile-only {
    display: grid;
  }

  .chat-shell {
    height: 100vh;
  }

  .topbar {
    padding-inline: 10px;
  }

  .prompt-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .messages {
    padding-inline: 14px;
  }

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

  .message-actions {
    opacity: 1;
  }

  .composer {
    padding-inline: 10px;
  }
}
