* {
  box-sizing: border-box;
}

:root,
html,
body {
  height: 100%;
}

:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #5b6df8;
  --primary-soft: rgba(91, 109, 248, 0.1);
  --user: #5b6df8;
  --assistant: #ffffff;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background: linear-gradient(180deg, #f7f8fc 0%, #f3f4f6 100%);
  color: var(--text);
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.wide {
  width: 100%;
}

.page-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.simple-card {
  width: min(680px, 100%);
  padding: 28px;
  border-radius: 24px;
  border: 1px solid rgba(229, 231, 235, 0.9);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.simple-card h1,
.simple-card h2,
.simple-card p {
  margin-top: 0;
}

.simple-card p,
.simple-card li {
  color: var(--muted);
  line-height: 1.8;
}

.inline-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.button-link {
  min-height: 42px;
  padding: 10px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  text-decoration: none;
  font: inherit;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

.button-link:hover {
  transform: translateY(-1px);
}

.button-link.primary {
  background: linear-gradient(135deg, #6a7cff, #5367f8);
  color: #fff;
  box-shadow: 0 8px 20px rgba(83, 103, 248, 0.24);
}

.button-link.ghost {
  background: #fff;
  color: var(--muted);
  border: 1px solid rgba(229, 231, 235, 0.95);
}

.form-success {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(34, 197, 94, 0.24);
  background: rgba(34, 197, 94, 0.08);
  color: #166534;
  font-size: 13px;
}

.form-help {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.auth-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
  padding: 28px;
  border-radius: 24px;
  border: 1px solid rgba(229, 231, 235, 0.9);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.auth-brand h1,
.auth-copy h2 {
  margin-top: 0;
}

.auth-brand p,
.auth-copy p,
.auth-copy li {
  color: var(--muted);
  line-height: 1.8;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-form span {
  color: var(--muted);
  font-size: 13px;
}

.login-form input {
  border-radius: 14px;
  border: 1px solid rgba(209, 213, 219, 0.85);
  background: #fff;
  color: var(--text);
  padding: 14px 16px;
  font: inherit;
}

.login-form input:focus {
  outline: 2px solid rgba(91, 109, 248, 0.15);
  border-color: rgba(91, 109, 248, 0.45);
}

.oauth-entry {
  margin-top: 16px;
}

.oauth-button {
  width: 100%;
  min-height: 46px;
  padding: 12px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  text-decoration: none;
  background: #eef2ff;
  color: #374151;
  border: 1px solid rgba(91, 109, 248, 0.18);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.oauth-button:hover {
  transform: translateY(-1px);
  background: #e0e7ff;
  border-color: rgba(91, 109, 248, 0.3);
}

.form-error {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(239, 68, 68, 0.3);
  background: rgba(127, 29, 29, 0.36);
  color: #fecaca;
  font-size: 13px;
}

.chat-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(229, 231, 235, 0.9);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  z-index: 20;
  flex: 0 0 auto;
}

.topbar-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  border: 1px solid rgba(229, 231, 235, 0.95);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
}

.mobile-only {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.status-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid rgba(229, 231, 235, 0.95);
  font-size: 13px;
  color: var(--muted);
}

.status-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status-pill.open::before {
  background: var(--success);
}

.status-pill.connecting::before {
  background: var(--warning);
}

.status-pill.error::before,
.status-pill.closed::before {
  background: var(--danger);
}

.session-label {
  color: var(--muted);
  font-size: 12px;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  padding: 16px;
  min-height: 0;
  overflow: hidden;
}

.sidebar,
.main-panel {
  border: 1px solid rgba(229, 231, 235, 0.95);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.sidebar-brand h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: #111827;
}

.sidebar-brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-mobile-header {
  justify-content: space-between;
  align-items: center;
}

.user-card {
  padding: 14px;
  border-radius: 14px;
  background: var(--panel-soft);
  border: 1px solid rgba(229, 231, 235, 0.95);
}

.user-card strong {
  display: block;
  margin-bottom: 6px;
}

.user-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.sidebar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.sidebar-actions .button-link {
  flex: 1 1 auto;
}

.session-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.session-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.session-panel-header h3 {
  margin: 0;
}

.session-panel-header span {
  color: var(--muted);
  font-size: 12px;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.45) transparent;
}

.session-list::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.session-list::-webkit-scrollbar-track {
  background: transparent;
}

.session-list::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.32);
  border-radius: 999px;
}

.session-list::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.52);
}

.session-row {
  position: relative;
}

.session-item {
  width: 100%;
  text-align: left;
  padding: 12px 60px 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(229, 231, 235, 0.95);
  background: #fff;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.session-item:hover {
  background: #f9fafb;
  border-color: rgba(91, 109, 248, 0.28);
}

.session-action-wrap {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
}

.session-item.active {
  border-color: rgba(91, 109, 248, 0.42);
  background: rgba(91, 109, 248, 0.08);
}

.session-item span,
.session-empty {
  color: var(--muted);
  font-size: 12px;
}

.sidebar h2,
.sidebar h3 {
  margin-top: 0;
}

.sidebar p,
.sidebar li,
.sidebar code {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.sidebar ul {
  padding-left: 18px;
}

.config-card {
  margin-top: 16px;
  padding: 14px;
  border-radius: 14px;
  background: #fbfcfe;
  border: 1px solid rgba(229, 231, 235, 0.95);
}

.config-card strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

.config-card code,
.config-card span {
  word-break: break-all;
}

.main-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  min-height: 0;
  overflow: hidden;
}

.messages {
  padding: 28px 24px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  background: linear-gradient(180deg, #fafbff 0%, #f5f7fb 100%);
}

.messages-empty {
  margin: auto;
  width: min(560px, 100%);
  padding: 24px 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.8;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.empty-logo {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 6px solid #111;
  position: relative;
  margin-bottom: 6px;
}

.empty-logo span {
  position: absolute;
  top: -12px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ff9d57;
}

.empty-logo span:nth-child(1) {
  left: 12px;
}

.empty-logo span:nth-child(2) {
  left: 24px;
}

.empty-logo span:nth-child(3) {
  left: 36px;
}

.messages-empty strong,
.empty-title {
  display: block;
  color: var(--text);
  font-size: 28px;
  font-weight: 700;
  margin: 0;
}

.messages-empty p,
.empty-desc {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.suggestion-list {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.suggestion-card {
  width: 100%;
  display: grid;
  grid-template-columns: 24px 1fr 24px;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(229, 231, 235, 0.95);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  text-align: left;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
}

.suggestion-card:hover {
  border-color: rgba(91, 109, 248, 0.26);
  background: #fff;
}

.suggestion-icon {
  color: var(--primary);
  font-size: 13px;
}

.suggestion-text {
  font-size: 14px;
}

.suggestion-arrow {
  color: var(--muted);
  justify-self: end;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.message.user {
  align-items: flex-end;
}

.message.assistant,
.message.system {
  align-items: flex-start;
}

.meta {
  font-size: 12px;
  color: var(--muted);
}

.action-menu {
  position: relative;
  flex: 0 0 auto;
}

.action-menu-trigger {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(229, 231, 235, 0.95);
  color: var(--muted);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.action-menu.compact,
.action-menu-trigger.compact {
  align-self: flex-start;
}

.action-menu-trigger.compact {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  box-shadow: none;
}

.action-menu-trigger span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  display: block;
}

.action-menu-trigger:hover,
.action-menu.open .action-menu-trigger {
  background: #fff;
  color: var(--text);
  border-color: rgba(91, 109, 248, 0.24);
}

.action-menu-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 132px;
  padding: 6px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(229, 231, 235, 0.95);
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.12);
  z-index: 15;
}

.action-menu.open .action-menu-panel {
  display: block;
}

.action-menu-item {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  color: var(--text);
}

.action-menu-item:hover {
  transform: none;
  background: #f8fafc;
}

.action-menu-item.danger {
  color: var(--danger);
}

.action-menu-item.danger:hover {
  background: rgba(239, 68, 68, 0.08);
}

.bubble {
  max-width: min(80%, 860px);
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.7;
  font-size: 14px;
  white-space: normal;
  word-break: break-word;
  border: 1px solid rgba(229, 231, 235, 0.95);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
}

.bubble .markdown-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bubble .markdown-content > * {
  margin: 0;
}

.bubble .markdown-content h1,
.bubble .markdown-content h2,
.bubble .markdown-content h3,
.bubble .markdown-content h4,
.bubble .markdown-content h5,
.bubble .markdown-content h6 {
  line-height: 1.35;
}

.bubble .markdown-content h1 {
  font-size: 1.45em;
}

.bubble .markdown-content h2 {
  font-size: 1.3em;
}

.bubble .markdown-content h3 {
  font-size: 1.15em;
}

.bubble .markdown-content ul,
.bubble .markdown-content ol {
  padding-left: 1.35em;
}

.bubble .markdown-content li + li {
  margin-top: 6px;
}

.bubble .markdown-content a {
  color: #3157f6;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble .markdown-content blockquote {
  padding: 10px 14px;
  border-left: 4px solid rgba(91, 109, 248, 0.35);
  background: rgba(91, 109, 248, 0.08);
  border-radius: 0 12px 12px 0;
  color: #4b5563;
}

.bubble .markdown-content hr {
  width: 100%;
  border: 0;
  border-top: 1px solid rgba(203, 213, 225, 0.9);
}

.bubble .markdown-content :not(pre) > code {
  padding: 2px 7px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.06);
  color: #c2410c;
  font-family: Consolas, "SFMono-Regular", Monaco, monospace;
  font-size: 0.95em;
}

.bubble .markdown-content .code-block {
  width: 100%;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: #0f172a;
}

.bubble .markdown-content .code-block-lang {
  padding: 10px 14px 0;
  color: rgba(226, 232, 240, 0.78);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.bubble .markdown-content pre {
  margin: 0;
  padding: 14px;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  font-family: Consolas, "SFMono-Regular", Monaco, monospace;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre;
  word-break: normal;
}

.bubble .markdown-content pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
}

.message.user .bubble {
  background: linear-gradient(135deg, var(--user), #4b5ef7);
  color: #fff;
  border-top-right-radius: 6px;
  border-color: transparent;
}

.message.assistant .bubble {
  background: #fff;
  border-top-left-radius: 6px;
}

.message.user .bubble .markdown-content a {
  color: #fff;
}

.message.user .bubble .markdown-content blockquote {
  color: rgba(255, 255, 255, 0.92);
  border-left-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.14);
}

.message.user .bubble .markdown-content :not(pre) > code {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.message.system .bubble {
  background: #fff7ed;
  border-color: rgba(251, 146, 60, 0.24);
}

.typing {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 24px 8px;
  color: var(--muted);
  font-size: 13px;
}

.typing.hidden {
  display: none;
}

.dots {
  display: inline-flex;
  gap: 5px;
}

.dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  animation: blink 1.4s infinite ease-in-out;
}

.dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    transform: scale(0.7);
    opacity: 0.45;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.composer {
  margin: 0 20px 20px;
  padding: 14px 16px;
  border: 1px solid rgba(229, 231, 235, 0.95);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  flex: 0 0 auto;
}

.composer textarea {
  width: 100%;
  min-height: 76px;
  max-height: 180px;
  resize: none;
  overflow-y: auto;
  border-radius: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 4px 2px 10px;
  font: inherit;
}

.composer textarea:focus {
  outline: none;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.button-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

button.primary {
  background: linear-gradient(135deg, #6a7cff, #5367f8);
  color: white;
  box-shadow: 0 8px 20px rgba(83, 103, 248, 0.24);
}

button.secondary {
  background: #eef2ff;
  color: var(--text);
}

button.ghost {
  background: #fff;
  color: var(--muted);
  border: 1px solid rgba(229, 231, 235, 0.95);
}

.hint {
  color: var(--muted);
  font-size: 12px;
}

.notice {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(229, 231, 235, 0.95);
  background: #fbfcfe;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.notice.compact {
  margin-top: 20px;
}

@media (max-width: 980px) {
  .auth-card {
    grid-template-columns: 1fr;
  }

  .status-group {
    align-items: flex-start;
  }

  .topbar {
    padding: 16px;
  }

  .topbar-main {
    width: 100%;
  }

  .mobile-only {
    display: inline-flex;
  }

  .sidebar-backdrop.visible {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.56);
    z-index: 30;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 340px);
    border-radius: 0 20px 20px 0;
    z-index: 40;
    transform: translateX(-110%);
    transition: transform 0.2s ease;
    overflow: hidden;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-mobile-header {
    display: flex;
  }

  .bubble {
    max-width: 100%;
  }

  .main-panel {
    min-width: 0;
  }

  .composer {
    margin: 0 16px 16px;
  }

  .messages {
    padding: 16px;
  }
}

@media (max-width: 640px) {
  .topbar {
    gap: 12px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .messages-empty strong,
  .empty-title {
    font-size: 22px;
  }

  .topbar p {
    font-size: 12px;
  }

  .status-group {
    width: 100%;
    align-items: flex-start;
  }

  .sidebar-actions,
  .composer-actions,
  .button-group {
    width: 100%;
  }

  .sidebar-actions button,
  .sidebar-actions .button-link,
  .composer-actions button {
    flex: 1 1 auto;
  }
}