:root {
  color-scheme: light;
  --bg: #fbfbfe;
  --surface: #ffffff;
  --panel: #f1f2fa;
  --text: #1c1d27;
  --muted: #686c80;
  --line: #e6e7f2;
  --accent: #6d5bf0;
  --accent-strong: #5847d8;
  --accent-weak: #ecebfd;
  --user-bubble: #ecebfd;
  --brand-1: #4f6df5;
  --brand-2: #8b5cf6;
  --brand-3: #14b8a6;
  --shadow-sm: 0 1px 3px rgba(20, 20, 50, 0.07);
  --shadow-md: 0 16px 40px -16px rgba(30, 35, 90, 0.22);
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Segoe UI",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(680px 480px at 8% -10%, rgba(79, 109, 245, 0.1), transparent 60%),
    radial-gradient(620px 460px at 108% 6%, rgba(20, 184, 166, 0.08), transparent 60%);
  pointer-events: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 24px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.hamburger-btn {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 6px;
  margin-left: -6px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
}

.hamburger-btn:hover {
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2), var(--brand-3));
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 15;
}

.drawer-overlay.hidden {
  display: none;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 85vw);
  background: var(--surface);
  z-index: 16;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.08);
}

.drawer:not(.hidden) {
  transform: translateX(0);
}

.drawer.hidden {
  display: none;
}

/* Persistent sidebar on wide screens instead of a mobile off-canvas overlay */
@media (min-width: 900px) {
  .drawer-overlay {
    display: none !important;
  }

  .drawer {
    transform: none !important;
    transition: width 0.2s ease, padding 0.2s ease, border-color 0.2s ease;
    box-shadow: none;
    border-right: 1px solid var(--line);
  }

  .drawer.hidden {
    display: flex !important;
    width: 0;
    padding: 16px 0;
    border-right-color: transparent;
    overflow: hidden;
  }

  .drawer:not(.hidden) ~ .app {
    margin-left: min(300px, 85vw);
  }

  .app {
    transition: margin-left 0.2s ease;
  }
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 12px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.new-chat-btn:hover {
  background: var(--accent-weak);
  color: var(--accent);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

.conversation-item:hover {
  background: var(--panel);
}

.conversation-item.active {
  background: var(--accent-weak);
  color: var(--accent);
}

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

.conversation-delete {
  border: none;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  cursor: pointer;
  display: flex;
  flex-shrink: 0;
}

.conversation-item:hover .conversation-delete {
  opacity: 1;
}

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

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

.drawer-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2), var(--brand-3));
}

.drawer-account-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-settings-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
}

.drawer-logout-btn {
  width: 100%;
  margin-top: 4px;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 12px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.drawer-logout-btn:hover {
  background: var(--panel);
  border-color: var(--muted);
}

.thread {
  flex: 1;
  overflow-y: auto;
  overflow-anchor: none;
  scrollbar-gutter: stable;
  padding: 24px 16px 12px;
  scroll-behavior: smooth;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.empty-sparkle {
  display: flex;
}

.empty-title {
  font-size: 32px;
  font-weight: 500;
  background: linear-gradient(90deg, var(--brand-1) 0%, var(--brand-2) 50%, var(--brand-3) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.message-row {
  width: min(720px, 100%);
  margin: 0 auto 18px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: message-in 0.25s ease-out;
}

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

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

.message-row.assistant {
  justify-content: flex-start;
}

.avatar-dot {
  width: 22px;
  height: 22px;
  margin-top: 4px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2), var(--brand-3));
}

.bubble {
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  font-size: 15px;
}

.message-row.user .bubble {
  background: var(--user-bubble);
  color: var(--text);
  border-radius: 18px;
  padding: 10px 16px;
  box-shadow: var(--shadow-sm);
}

.message-row.assistant .bubble {
  background: transparent;
  color: var(--text);
  padding: 4px 0;
}

.attachment-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.attachment-thumb {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.attachment-chip {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  text-decoration: none;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.4;
  animation: blink 1.2s infinite ease-in-out;
}

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

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

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

.error-text {
  color: #c93232;
}

.composer-bar {
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  background: var(--bg);
  box-shadow: 0 -6px 12px -8px rgba(0, 0, 0, 0.12);
}

.composer-footnote {
  width: min(720px, 100%);
  margin: 8px auto 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.composer {
  width: min(720px, 100%);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--panel);
  border-radius: 28px;
  padding: 10px 10px 10px 12px;
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(109, 91, 240, 0.18);
}

.composer-attach {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-bottom: 1px;
}

.composer-attach:hover {
  background: var(--accent-weak);
  color: var(--accent);
}

.pending-attachments {
  width: min(720px, 100%);
  margin: 0 auto 8px;
  padding: 0 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pending-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 12px;
  border-radius: 14px;
  background: var(--panel);
  font-size: 12px;
  color: var(--text);
  max-width: 220px;
}

.pending-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-chip-remove {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.composer-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  max-height: 200px;
  font-family: inherit;
  color: var(--text);
  padding: 6px 0;
  transition: height 0.1s ease;
}

.composer-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.composer-send:hover:not(:disabled) {
  background: var(--accent-strong);
}

.composer-send:active:not(:disabled) {
  transform: scale(0.92);
}

.composer-send:disabled {
  background: #c3c4d4;
  cursor: default;
}

.gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}

.gate.hidden {
  display: none;
}

.gate::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(620px 420px at 15% 12%, rgba(79, 109, 245, 0.14), transparent 60%),
    radial-gradient(560px 420px at 100% -4%, rgba(20, 184, 166, 0.12), transparent 60%);
  pointer-events: none;
}

.gate-card {
  position: relative;
  width: min(380px, 100%);
  padding: 36px 32px 32px;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.gate-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 26px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.gate-brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2), var(--brand-3));
}

.gate-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  justify-content: center;
}

.gate-tab {
  border: none;
  background: transparent;
  padding: 8px 18px;
  border-radius: 18px;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
}

.gate-tab.active {
  background: var(--accent-weak);
  color: var(--accent);
  font-weight: 500;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gate-hint {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

.gate-input {
  width: 100%;
  padding: 11px 16px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.gate-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

.gate-submit {
  width: 100%;
  margin-top: 2px;
  padding: 11px 14px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.gate-submit:hover {
  background: var(--accent-strong);
}

.gate-divider {
  margin: 18px 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.gate-disabled {
  width: 100%;
  margin-bottom: 8px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: #9a9cae;
  font-size: 14px;
  cursor: not-allowed;
}

.gate-error {
  margin-top: 10px;
  color: #c93232;
  font-size: 13px;
  min-height: 16px;
}

button:focus-visible,
.gate-input:focus-visible,
.composer-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
