:root {
  --canvas: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #f1f3f5;
  --surface-hover: #e9edf0;
  --ink: #22272c;
  --muted: #70777e;
  --faint: #9ca3aa;
  --line: #dfe3e6;
  --accent: #3b6f96;
  --accent-hover: #2f5c7e;
  --accent-soft: #e8f0f5;
  --danger: #b8493f;
  --danger-soft: #f8e9e6;
  --shadow: 0 18px 50px rgb(35 43 49 / 9%);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

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

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

button {
  border: 0;
}

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

svg {
  display: block;
}

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

:focus-visible {
  outline: 3px solid rgb(59 111 150 / 22%);
  outline-offset: 2px;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  color: var(--muted);
  cursor: pointer;
  background: transparent;
  border-radius: 50%;
  transition:
    color 160ms ease,
    background 160ms ease;
}

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

.button {
  display: inline-flex;
  min-height: 44px;
  padding: 0 18px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    opacity 160ms ease;
}

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

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

.button-primary {
  color: #fff;
  background: var(--accent);
}

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

.button-secondary {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}

.button-secondary:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: #c9ccc5;
}

/* Chat shell */

.app-body {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.app-shell {
  display: flex;
  height: 100%;
}

.sidebar {
  z-index: 30;
  display: flex;
  width: 288px;
  min-width: 288px;
  height: 100%;
  flex-direction: column;
  background: var(--surface-soft);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  height: 68px;
  padding: 0 20px;
  align-items: center;
  gap: 11px;
  font-size: 0.98rem;
  font-weight: 720;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border-radius: 9px;
  box-shadow: 0 6px 16px rgb(59 111 150 / 20%);
}

.brand-mark .icon {
  width: 16px;
  height: 16px;
}

.sidebar-primary {
  margin: 8px 12px 16px;
}

.new-chat-button {
  width: 100%;
  justify-content: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 1px 1px rgb(27 31 28 / 3%);
}

.sidebar-section-label {
  padding: 0 18px 8px;
  color: var(--faint);
  font-size: 0.69rem;
  font-weight: 720;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

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

.conversation-empty {
  padding: 20px 12px;
  color: var(--faint);
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: center;
}

.conversation-button {
  display: flex;
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.84rem;
  text-align: left;
  cursor: pointer;
  background: transparent;
  border-radius: 9px;
  transition:
    color 150ms ease,
    background 150ms ease;
}

.conversation-button:hover {
  color: var(--ink);
  background: rgb(255 255 255 / 62%);
}

.conversation-button.active {
  color: var(--ink);
  font-weight: 620;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(31 36 32 / 5%);
}

.conversation-button .icon {
  width: 16px;
  height: 16px;
  color: var(--faint);
}

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

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

.account-row {
  display: flex;
  padding: 8px;
  align-items: center;
  gap: 10px;
}

.avatar {
  display: grid;
  width: 32px;
  height: 32px;
  flex: none;
  place-items: center;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 750;
  background: var(--accent-soft);
  border-radius: 50%;
}

.account-copy {
  min-width: 0;
  flex: 1;
}

.account-label {
  margin: 0 0 2px;
  color: var(--faint);
  font-size: 0.67rem;
  font-weight: 690;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.account-email {
  display: block;
  overflow: hidden;
  font-size: 0.78rem;
  font-weight: 560;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-actions {
  display: flex;
}

.chat-main {
  position: relative;
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  background: var(--surface);
}

.topbar {
  z-index: 10;
  display: flex;
  height: 68px;
  padding: 0 22px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgb(255 255 255 / 88%);
  border-bottom: 1px solid rgb(222 223 217 / 80%);
  backdrop-filter: blur(14px);
}

.topbar-left,
.topbar-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.mobile-menu-button {
  display: none;
}

.chat-heading {
  min-width: 0;
}

.chat-heading h1 {
  margin: 0;
  overflow: hidden;
  font-size: 0.93rem;
  font-weight: 680;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-heading p {
  margin: 3px 0 0;
  color: var(--faint);
  font-size: 0.7rem;
}

.delete-button:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.error-bar {
  z-index: 8;
  padding: 10px 20px;
  color: #8e3029;
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: center;
  background: var(--danger-soft);
  border-bottom: 1px solid #eccac5;
}

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

.message-list {
  width: min(820px, 100%);
  min-height: 100%;
  padding: 34px 28px 24px;
  margin: 0 auto;
}

.empty-state {
  display: flex;
  min-height: calc(100vh - 230px);
  min-height: calc(100dvh - 230px);
  align-items: center;
  justify-content: center;
}

.empty-state-inner {
  width: min(540px, 100%);
  text-align: center;
}

.empty-symbol {
  display: grid;
  width: 54px;
  height: 54px;
  margin: 0 auto 22px;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #cfdee9;
  border-radius: 18px;
}

.empty-symbol .icon {
  width: 25px;
  height: 25px;
}

.empty-state h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 4vw, 2.45rem);
  font-weight: 500;
  letter-spacing: -0.035em;
}

.empty-state p {
  max-width: 430px;
  margin: 13px auto 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.65;
}

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

.suggestion {
  min-height: 54px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition:
    color 150ms ease,
    border-color 150ms ease,
    transform 150ms ease,
    box-shadow 150ms ease;
}

.suggestion:hover {
  color: var(--ink);
  border-color: #c7cbc4;
  box-shadow: 0 8px 22px rgb(32 37 33 / 6%);
  transform: translateY(-1px);
}

.message {
  display: flex;
  margin-bottom: 28px;
  align-items: flex-start;
  gap: 12px;
  animation: message-in 220ms ease both;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
}

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

.message-avatar {
  display: grid;
  width: 30px;
  height: 30px;
  flex: none;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 9px;
}

.message-avatar .icon {
  width: 16px;
  height: 16px;
}

.message-content {
  max-width: min(690px, calc(100% - 42px));
  color: #303530;
  font-size: 0.93rem;
  line-height: 1.7;
}

.message.user .message-content {
  max-width: min(590px, 82%);
  padding: 11px 15px;
  color: #283943;
  white-space: pre-wrap;
  background: var(--accent-soft);
  border-radius: 17px 17px 4px 17px;
}

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

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

.message-content p {
  margin: 0 0 0.9em;
}

.message-content ul,
.message-content ol {
  padding-left: 1.45em;
  margin: 0.7em 0 1em;
}

.message-content li + li {
  margin-top: 0.35em;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 1.2em 0 0.45em;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.35;
}

.message-content code {
  padding: 0.16em 0.38em;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.84em;
  background: var(--surface-soft);
  border-radius: 5px;
}

.message-content pre {
  padding: 14px;
  overflow-x: auto;
  color: #e9eee9;
  background: #22282d;
  border-radius: 11px;
}

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

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

.typing-cursor::after {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: -0.15em;
  content: "";
  background: var(--accent);
  border-radius: 2px;
  animation: blink 850ms step-end infinite;
}

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

.sources {
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.sources summary {
  display: flex;
  padding: 12px 0 2px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 620;
  cursor: pointer;
  list-style: none;
}

.sources summary::-webkit-details-marker {
  display: none;
}

.sources summary::after {
  margin-left: auto;
  content: "＋";
  color: var(--faint);
  font-size: 0.9rem;
}

.sources[open] summary::after {
  content: "−";
}

.source-list {
  display: grid;
  padding: 10px 0 0;
  margin: 0;
  gap: 8px;
  list-style: none;
}

.source-item {
  padding: 11px 12px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
  white-space: pre-wrap;
  background: var(--surface-soft);
  border-radius: 9px;
}

.source-number {
  margin-right: 7px;
  color: var(--accent);
  font-weight: 750;
}

.message-content .katex-display {
  padding: 4px 0;
  margin: 0.8em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.composer-region {
  padding: 12px 24px 18px;
  background: linear-gradient(to bottom, rgb(255 255 255 / 10%), #fff 28%);
}

.composer {
  display: flex;
  width: min(820px, 100%);
  min-height: 58px;
  padding: 8px 8px 8px 17px;
  margin: 0 auto;
  align-items: flex-end;
  gap: 9px;
  background: var(--surface);
  border: 1px solid #d4d7d0;
  border-radius: 18px;
  box-shadow: 0 8px 30px rgb(35 40 36 / 8%);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.composer:focus-within {
  border-color: rgb(59 111 150 / 55%);
  box-shadow:
    0 8px 30px rgb(35 40 36 / 8%),
    0 0 0 3px rgb(59 111 150 / 8%);
}

.composer textarea {
  width: 100%;
  min-height: 40px;
  max-height: 160px;
  padding: 10px 0 7px;
  resize: none;
  overflow-y: auto;
  line-height: 1.45;
  background: transparent;
  border: 0;
  outline: 0;
}

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

.send-button {
  display: grid;
  width: 42px;
  height: 42px;
  flex: none;
  place-items: center;
  color: #fff;
  cursor: pointer;
  background: var(--accent);
  border-radius: 13px;
  transition:
    background 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

.send-button:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

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

.composer-hint {
  margin: 7px auto 0;
  color: var(--faint);
  font-size: 0.65rem;
  text-align: center;
}

.sidebar-backdrop {
  display: none;
}

/* Authentication */

.auth-body {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 28px;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 15%, rgb(229 239 246 / 85%), transparent 34%),
    radial-gradient(circle at 90% 85%, rgb(232 236 241 / 65%), transparent 30%),
    var(--canvas);
}

.auth-shell {
  position: relative;
  width: min(420px, 100%);
}

.auth-brand {
  display: flex;
  margin-bottom: 24px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.91rem;
  font-weight: 720;
}

.auth-card {
  padding: 38px;
  background: rgb(255 255 255 / 90%);
  border: 1px solid rgb(222 223 217 / 90%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 760;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.auth-card h1,
.settings-heading h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 500;
  letter-spacing: -0.035em;
}

.auth-subtitle {
  margin: 10px 0 28px;
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.55;
}

.field {
  margin-bottom: 17px;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: #4f554f;
  font-size: 0.76rem;
  font-weight: 650;
}

.control {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  background: var(--surface);
  border: 1px solid #d8dad4;
  border-radius: var(--radius-sm);
  outline: 0;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.control:focus {
  border-color: rgb(59 111 150 / 60%);
  box-shadow: 0 0 0 3px rgb(59 111 150 / 9%);
}

.control::placeholder {
  color: var(--faint);
}

select.control {
  appearance: none;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) 20px,
    calc(100% - 12px) 20px;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
}

.password-wrap {
  position: relative;
}

.password-wrap .control {
  padding-right: 48px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
}

.auth-submit {
  width: 100%;
  margin-top: 4px;
}

.auth-switch {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.text-button {
  padding: 3px;
  color: var(--accent);
  font-size: inherit;
  font-weight: 680;
  cursor: pointer;
  background: transparent;
}

.text-button:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.notice {
  padding: 11px 13px;
  margin-bottom: 18px;
  font-size: 0.78rem;
  line-height: 1.45;
  border-radius: 9px;
}

.notice.error {
  color: #8e3029;
  background: var(--danger-soft);
}

.notice.success {
  color: var(--accent-hover);
  background: var(--accent-soft);
}

/* Settings */

.settings-body {
  min-height: 100vh;
  background: var(--canvas);
}

.settings-topbar {
  display: flex;
  height: 68px;
  padding: 0 26px;
  align-items: center;
  justify-content: space-between;
  background: rgb(247 248 250 / 90%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 620;
}

.back-link:hover {
  color: var(--ink);
}

.settings-account {
  display: flex;
  align-items: center;
  gap: 9px;
}

.settings-email {
  max-width: 260px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-main {
  width: min(660px, calc(100% - 40px));
  padding: 64px 0 80px;
  margin: 0 auto;
}

.settings-heading {
  margin-bottom: 30px;
}

.settings-heading p:last-child {
  max-width: 500px;
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.6;
}

.settings-card {
  padding: 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 36px rgb(32 37 33 / 5%);
}

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

.field-full {
  grid-column: 1 / -1;
}

.field-help {
  margin: 7px 0 0;
  color: var(--faint);
  font-size: 0.7rem;
  line-height: 1.45;
}

.key-status {
  display: inline-flex;
  padding: 4px 8px;
  margin-left: 7px;
  align-items: center;
  color: var(--accent);
  font-size: 0.63rem;
  font-weight: 720;
  background: var(--accent-soft);
  border-radius: 999px;
  vertical-align: 1px;
}

.settings-actions {
  display: flex;
  margin-top: 8px;
  align-items: center;
  gap: 14px;
}

.save-status {
  color: var(--muted);
  font-size: 0.76rem;
}

.save-status.success {
  color: var(--accent);
}

.save-status.error {
  color: var(--danger);
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 310px);
    min-width: 0;
    box-shadow: 18px 0 50px rgb(25 30 26 / 18%);
    transform: translateX(-105%);
    transition: transform 220ms ease;
  }

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

  .sidebar-backdrop {
    position: fixed;
    z-index: 20;
    display: block;
    inset: 0;
    background: rgb(22 26 23 / 32%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-button {
    display: inline-grid;
  }

  .topbar {
    padding: 0 13px;
  }

  .chat-heading p {
    display: none;
  }

  .message-list {
    padding: 26px 17px 16px;
  }

  .message {
    margin-bottom: 23px;
  }

  .message-content {
    font-size: 0.9rem;
  }

  .message.user .message-content {
    max-width: 88%;
  }

  .empty-state {
    min-height: calc(100dvh - 215px);
  }

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

  .suggestion:nth-child(n + 3) {
    display: none;
  }

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

  .composer-hint {
    display: none;
  }

  .auth-body {
    padding: 18px;
  }

  .auth-card {
    padding: 30px 24px;
  }

  .settings-topbar {
    padding: 0 14px;
  }

  .settings-email {
    display: none;
  }

  .settings-main {
    width: min(100% - 28px, 660px);
    padding: 42px 0 60px;
  }

  .settings-card {
    padding: 23px 19px;
  }

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

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