:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-soft: #f0f2f7;
  --text: #181b24;
  --muted: #737987;
  --line: #e3e6ee;
  --accent: #2457ff;
  --accent-dark: #1742c8;
  --success: #0f8f6b;
  --danger: #d33d3d;
  --shadow: 0 24px 70px rgba(25, 31, 51, 0.12);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px 16px;
  background: #f1f3f8;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 8px;
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
}

.brand span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, #2457ff, #0f8f6b);
  font-weight: 800;
}

.brand-mark.large {
  width: 46px;
  height: 46px;
  margin: 0 auto 12px;
  font-size: 22px;
}

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  font-weight: 650;
}

.new-chat:hover,
.nav-item:hover,
.history-item:hover {
  background: #e8ebf4;
}

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-item {
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  color: #3f4654;
  background: transparent;
  text-align: left;
}

.nav-item.active {
  color: var(--accent);
  background: #e8edff;
  font-weight: 650;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding: 0 8px;
  color: #9aa0ad;
  font-size: 13px;
}

.history-head button {
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.history-list {
  display: grid;
  gap: 4px;
  overflow-y: auto;
}

.history-item {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  color: #333846;
  background: transparent;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item.active {
  background: var(--panel);
  font-weight: 650;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid #eef0f5;
}

.menu-button {
  display: none;
}

.model-select {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.model-select select {
  min-width: 190px;
  height: 38px;
  padding: 0 36px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
}

.topbar-actions {
  margin-left: auto;
}

.text-button,
.icon-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #3e4656;
  background: #fff;
}

.text-button {
  padding: 0 14px;
}

.icon-button {
  width: 38px;
}

.messages {
  position: relative;
  overflow-y: auto;
  padding: 48px 8vw 180px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 55vh;
  text-align: center;
}

.empty-state .spark {
  color: var(--accent);
  font-size: 34px;
}

.empty-state h1 {
  margin: 10px 0;
  font-size: clamp(30px, 4vw, 46px);
  font-weight: 720;
  letter-spacing: 0;
}

.empty-state p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.message {
  display: flex;
  gap: 14px;
  max-width: 920px;
  margin: 0 auto 24px;
}

.avatar {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: #1f2533;
  font-size: 13px;
  font-weight: 750;
}

.message.assistant .avatar {
  background: var(--accent);
}

.bubble {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  line-height: 1.75;
  white-space: pre-wrap;
}

.message.user {
  flex-direction: row-reverse;
}

.message.user .bubble {
  color: #fff;
  background: #1f2533;
  border-color: #1f2533;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.sources a {
  max-width: 280px;
  padding: 6px 10px;
  overflow: hidden;
  border: 1px solid #ccd7ff;
  border-radius: 8px;
  color: var(--accent-dark);
  background: #eef2ff;
  font-size: 12px;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-wrap {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 280px;
  padding: 18px max(24px, 8vw) 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff 22%);
}

.composer {
  max-width: 980px;
  margin: 0 auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  min-height: 38px;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 17px;
  line-height: 1.6;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  color: #3d4351;
  font-size: 14px;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #d8dce6;
  transition: background 0.2s ease;
}

.switch span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  content: "";
  transition: transform 0.2s ease;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(16px);
}

.send-button {
  display: grid;
  width: 44px;
  height: 44px;
  margin-left: auto;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: var(--accent);
  font-size: 22px;
}

.send-button:disabled {
  cursor: not-allowed;
  background: #b7bfce;
}

.hint {
  max-width: 980px;
  margin: 10px auto 0;
  color: #969ca8;
  font-size: 12px;
  text-align: center;
}

.login-layer {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 25% 20%, rgba(36, 87, 255, 0.13), transparent 28%),
    radial-gradient(circle at 75% 80%, rgba(15, 143, 107, 0.14), transparent 30%),
    rgba(246, 247, 251, 0.96);
  z-index: 10;
}

.login-layer.hidden {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card h2 {
  margin: 0 0 10px;
  font-size: 26px;
}

.login-card p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.7;
}

.login-card input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.turnstile-box {
  display: grid;
  min-height: 0;
  margin-top: 12px;
  place-items: center;
}

.login-card button {
  width: 100%;
  height: 46px;
  margin-top: 14px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.login-error {
  display: block;
  min-height: 20px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 5;
  }

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

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

  .messages {
    padding: 28px 18px 188px;
  }

  .composer-wrap {
    left: 0;
    padding: 16px;
  }

  .topbar {
    padding: 0 14px;
  }

  .model-select span {
    display: none;
  }

  .model-select select {
    min-width: 168px;
  }
}
