:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-soft: #efefec;
  --surface-hover: #e9e9e5;
  --text: #20201e;
  --muted: #6f6f69;
  --line: #ddddda;
  --accent: #181817;
  --accent-text: #ffffff;
  --danger: #b42318;
  --focus: #2477d4;
  --shadow: 0 18px 50px rgb(0 0 0 / 0.09);
  --sidebar-width: 272px;
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  min-width: 320px;
  overflow: hidden;
}

button,
textarea,
input {
  font: inherit;
}

button {
  color: inherit;
}

button,
input,
textarea {
  outline: none;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent);
  border-color: var(--focus) !important;
}

[hidden] {
  display: none !important;
}

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

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

.sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  background: #ecece8;
  border-right: 1px solid var(--line);
  z-index: 30;
}

.sidebar-header {
  padding: 12px;
}

.new-chat-button {
  display: flex;
  width: 100%;
  min-height: 48px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  font-weight: 650;
  text-align: left;
}

.new-chat-button:hover {
  background: var(--surface-hover);
}

.new-chat-button kbd {
  margin-left: auto;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  font: 11px/1.4 inherit;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 21px;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.12);
}

.brand-mark.small {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 16px;
}

.brand-mark.large {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 18px;
  font-size: 28px;
}

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

.chat-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border-radius: 10px;
}

.chat-item.active {
  background: var(--surface-hover);
}

.chat-item-main,
.chat-item-menu {
  min-height: 44px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.chat-item-main {
  overflow: hidden;
  padding: 8px 10px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-menu {
  width: 40px;
  border-radius: 9px;
  color: var(--muted);
  opacity: 0;
}

.chat-item:hover {
  background: var(--surface-hover);
}

.chat-item:hover .chat-item-menu,
.chat-item-menu:focus-visible {
  opacity: 1;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--line);
}

.sidebar-footer p {
  margin: 9px 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.ghost-button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

.ghost-button:hover {
  background: var(--surface-hover);
}

.ghost-button.full {
  width: 100%;
}

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

.topbar {
  display: flex;
  min-height: 60px;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
  background: color-mix(in srgb, var(--surface) 91%, transparent);
  backdrop-filter: blur(16px);
  z-index: 10;
}

.chat-title {
  overflow: hidden;
  max-width: min(520px, 60vw);
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-title:hover {
  background: var(--surface-soft);
}

.model-pill {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22a06b;
  box-shadow: 0 0 0 3px rgb(34 160 107 / 0.12);
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 21px;
}

.icon-button:hover {
  background: var(--surface-soft);
}

.mobile-only {
  display: none;
}

.conversation {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.welcome {
  width: min(720px, calc(100% - 36px));
  margin: max(9vh, 48px) auto 60px;
  text-align: center;
}

.welcome h1 {
  margin: 22px 0 9px;
  font-size: clamp(28px, 5vw, 38px);
  letter-spacing: -0.035em;
}

.welcome > p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 32px;
}

.suggestions button {
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  cursor: pointer;
  line-height: 1.35;
  text-align: left;
}

.suggestions button:hover {
  background: var(--surface-soft);
  border-color: #c8c8c4;
}

.messages {
  width: min(820px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 64px;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 13px;
  margin: 0 0 30px;
}

.message-avatar {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 750;
}

.message.user .message-avatar {
  background: #e8e8e4;
  color: var(--text);
}

.message-body {
  min-width: 0;
  padding-top: 4px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 700;
}

.message-copy {
  min-height: 32px;
  margin-left: auto;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  opacity: 0;
}

.message:hover .message-copy,
.message-copy:focus-visible {
  opacity: 1;
}

.message-content {
  overflow-wrap: anywhere;
  line-height: 1.68;
}

.message-content > :first-child {
  margin-top: 0;
}

.message-content > :last-child {
  margin-bottom: 0;
}

.message-content p {
  margin: 0 0 13px;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 24px 0 10px;
  letter-spacing: -0.02em;
}

.message-content h1 {
  font-size: 24px;
}

.message-content h2 {
  font-size: 20px;
}

.message-content h3 {
  font-size: 17px;
}

.message-content ul,
.message-content ol {
  margin: 8px 0 15px;
  padding-left: 24px;
}

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

.message-content blockquote {
  margin: 14px 0;
  padding-left: 14px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.message-content a {
  color: #1264a3;
  text-underline-offset: 3px;
}

.message-content code {
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--surface-soft);
  font: 0.9em/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.message-content pre {
  overflow-x: auto;
  margin: 14px 0;
  padding: 15px;
  border: 1px solid #30302f;
  border-radius: 13px;
  background: #20201f;
  color: #f4f4f1;
}

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

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

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.2s infinite ease-in-out;
}

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

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

@keyframes pulse {
  0%,
  70%,
  100% {
    opacity: 0.28;
    transform: translateY(0);
  }
  35% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.composer-wrap {
  padding: 12px max(16px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: linear-gradient(to top, var(--surface) 75%, transparent);
}

.composer {
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 9px 10px 8px 16px;
  border: 1px solid #cfcfca;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 7px 28px rgb(0 0 0 / 0.08);
}

.composer:focus-within {
  border-color: #a7a7a1;
  box-shadow: 0 7px 28px rgb(0 0 0 / 0.08), 0 0 0 3px rgb(36 119 212 / 0.1);
}

.composer textarea {
  display: block;
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--text);
  line-height: 1.5;
}

.composer textarea::placeholder {
  color: #92928c;
}

.composer-actions {
  display: flex;
  min-height: 36px;
  align-items: end;
  gap: 8px;
}

.composer-hint {
  margin: auto 0 5px;
  color: var(--muted);
  font-size: 11px;
}

.send-button,
.stop-button {
  display: grid;
  width: 36px;
  height: 36px;
  margin-left: auto;
  place-items: center;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-size: 21px;
  font-weight: 750;
}

.stop-button {
  font-size: 13px;
}

.send-button:disabled {
  cursor: default;
  opacity: 0.28;
}

.disclaimer {
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.login-view {
  display: grid;
  min-height: 100dvh;
  padding: 24px;
  place-items: center;
  background:
    radial-gradient(circle at 12% 4%, rgb(47 112 183 / 0.09), transparent 32%),
    radial-gradient(circle at 90% 94%, rgb(83 162 124 / 0.1), transparent 32%),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card .brand-mark {
  margin-bottom: 25px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 32px;
  letter-spacing: -0.04em;
}

.login-card > p {
  margin: 0 0 28px;
  color: var(--muted);
}

.login-card label {
  display: block;
  margin: 0 0 7px;
  font-size: 13px;
  font-weight: 650;
}

.login-card input {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
}

.primary-button {
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 700;
}

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

.login-card small {
  display: block;
  margin-top: 20px;
  color: var(--muted);
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 11px 14px;
  border-radius: 11px;
  background: #20201f;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: 180ms ease;
  z-index: 100;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #171716;
    --surface: #20201f;
    --surface-soft: #2a2a28;
    --surface-hover: #30302d;
    --text: #f2f2ef;
    --muted: #aaa9a3;
    --line: #3a3a37;
    --accent: #f1f1ed;
    --accent-text: #20201f;
    --shadow: 0 18px 50px rgb(0 0 0 / 0.32);
  }

  .sidebar {
    background: #191918;
  }

  .message.user .message-avatar {
    background: #343431;
  }

  .message-content a {
    color: #72b7f0;
  }

  .status-dot {
    background: #57c792;
  }
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, var(--sidebar-width));
    box-shadow: 18px 0 45px rgb(0 0 0 / 0.15);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

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

  .sidebar-scrim {
    position: fixed;
    inset: 0;
    display: block;
    background: rgb(0 0 0 / 0.34);
    z-index: 20;
  }

  .main-panel {
    height: 100dvh;
  }

  .mobile-only {
    display: grid;
  }

  .topbar {
    min-height: 56px;
    padding: 6px 10px;
  }

  .chat-title {
    max-width: 46vw;
  }

  .model-pill {
    padding: 7px 9px;
  }

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

  .suggestions button {
    min-height: 58px;
  }

  .welcome {
    margin-top: 6vh;
  }

  .messages {
    width: min(100% - 22px, 820px);
    padding-top: 20px;
  }

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

  .message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    font-size: 13px;
  }

  .composer-wrap {
    padding-top: 8px;
  }

  .composer-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
