:root {
  --bg: #f3f7fc;
  --bg-soft: #fbfdff;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-strong: #ffffff;
  --line: rgba(15, 23, 42, 0.08);
  --line-strong: rgba(15, 23, 42, 0.16);
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --danger: #b6492e;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --sidebar-width: 320px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  font-family: "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(96, 165, 250, 0.16), transparent 28%),
    radial-gradient(circle at bottom right, rgba(125, 211, 252, 0.12), transparent 24%),
    linear-gradient(180deg, #f9fbff 0%, #edf4ff 100%);
}

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

button {
  cursor: pointer;
}

.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 {
  height: 100%;
}

.view {
  display: none;
  height: 100%;
}

.view.active {
  display: block;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 16px;
  transition: 0.18s ease;
}

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

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.2);
}

.btn-secondary,
.btn-ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.5);
  border-color: var(--line);
}

.btn-secondary strong {
  margin-left: 6px;
  font-weight: 600;
}

.btn-ghost:hover,
.btn-secondary:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.75);
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  color: var(--text);
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.82);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.login-shell {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 440px);
  padding: 36px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 32px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 58px;
  height: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.login-brand h1,
.sidebar-head h2,
.workspace-topbar h2,
.chat-welcome h3,
.model-panel-head h3 {
  margin: 0;
}

.login-brand p {
  margin: 6px 0 0;
  color: var(--text-muted);
}

.login-form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 13px;
  color: var(--text-muted);
}

.field input,
.device-select-field select,
#chat-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--text);
  outline: none;
}

.field input,
.device-select-field select {
  padding: 12px 14px;
}

.field input:focus,
.device-select-field select:focus,
#chat-input:focus {
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

.error-text {
  margin: 0;
  font-size: 13px;
  color: var(--danger);
}

.workspace-shell {
  display: flex;
  gap: 16px;
  height: 100%;
  padding: 16px;
}

.conversation-sidebar,
.chat-shell,
.model-panel {
  border: 1px solid rgba(255, 255, 255, 0.58);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.conversation-sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.session-list,
.model-list,
.chat-messages {
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.session-list {
  flex: 1;
  display: grid;
  gap: 10px;
  padding-right: 4px;
}

.session-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid transparent;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.56);
  color: var(--text);
  text-align: left;
}

.session-item:hover {
  border-color: var(--line-strong);
}

.session-item.is-active {
  border-color: rgba(37, 99, 235, 0.18);
  background: rgba(37, 99, 235, 0.08);
}

.session-item-body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}

.session-item-body strong,
.model-item strong {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item-body span,
.model-item span {
  font-size: 12px;
  color: var(--text-muted);
}

.session-delete-btn {
  width: 34px;
  height: 34px;
  flex: none;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
}

.session-delete-btn:hover {
  background: rgba(182, 73, 46, 0.08);
  color: var(--danger);
}

.chat-shell {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: calc(var(--radius-lg) + 4px);
  overflow: hidden;
}

.workspace-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.topbar-left,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-left {
  min-width: 0;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.device-select-field select {
  min-width: 220px;
  appearance: none;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.45);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}

.status-online .status-dot {
  background: #1a8f65;
  box-shadow: 0 0 0 5px rgba(26, 143, 101, 0.12);
}

.status-offline .status-dot {
  background: #8f4d3d;
}

.chat-messages {
  flex: 1;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-welcome,
.loading-state,
.empty-state {
  margin: auto;
  max-width: 520px;
  text-align: center;
}

.chat-welcome {
  padding: 34px 28px;
  border: 1px dashed rgba(37, 99, 235, 0.18);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.48);
}

.welcome-kicker {
  display: inline-block;
  margin-bottom: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-welcome p,
.loading-state p,
.empty-state p,
.composer-meta {
  color: var(--text-muted);
}

.loading-state,
.empty-state {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 40px 20px;
}

.loading-state.compact,
.empty-state.compact {
  padding: 28px 12px;
}

.message-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-row.user {
  align-items: flex-end;
}

.message-row.assistant {
  align-items: flex-start;
}

.message-bubble {
  max-width: min(820px, 82%);
  padding: 15px 18px;
  border-radius: 24px;
  border: 1px solid transparent;
  line-height: 1.65;
  word-break: break-word;
}

.message-bubble.user {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #fff;
  border-bottom-right-radius: 8px;
}

.message-bubble.assistant {
  background: var(--panel-strong);
  border-color: rgba(15, 23, 42, 0.08);
  border-bottom-left-radius: 8px;
}

.message-bubble.assistant.assistant-history {
  display: block;
  width: min(820px, 82%);
  max-width: min(820px, 82%);
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(15, 23, 42, 0.06);
  border-radius: 22px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.05);
}

.message-bubble.streaming::after {
  content: "";
  display: inline-block;
  width: 9px;
  height: 1.15em;
  margin-left: 2px;
  vertical-align: bottom;
  background: rgba(37, 99, 235, 0.55);
  animation: blink 0.8s step-end infinite;
}

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

.message-bubble p,
.message-bubble ul,
.message-bubble ol,
.message-bubble pre,
.message-bubble blockquote {
  margin: 0 0 12px;
}

.message-bubble p:last-child,
.message-bubble ul:last-child,
.message-bubble ol:last-child,
.message-bubble pre:last-child,
.message-bubble blockquote:last-child {
  margin-bottom: 0;
}

.message-bubble pre {
  overflow: hidden;
  border-radius: 16px;
  background: #142220;
}

.message-bubble pre code {
  display: block;
  overflow: auto;
  padding: 16px;
  color: #f7f8fa;
}

.message-bubble code:not(pre code) {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.08);
  font-family: "IBM Plex Mono", monospace;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
}

.code-copy-btn,
.msg-action-btn {
  border: none;
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
}

.message-actions {
  display: flex;
  justify-content: flex-start;
}

.assistant-history-block + .assistant-history-block,
.assistant-history-card + .assistant-history-block,
.assistant-history-block + .assistant-history-card,
.assistant-history-card + .assistant-history-card {
  margin-top: 10px;
}

.assistant-history-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.assistant-history-head-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.assistant-history-head-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.assistant-history-steps {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.assistant-history-block {
  line-height: 1.7;
  padding: 2px 2px 2px 0;
  color: var(--text);
}

.assistant-history-answer {
  padding: 2px 2px 2px 0;
}

.assistant-history-answer.streaming::after {
  content: "";
  display: inline-block;
  width: 9px;
  height: 1.15em;
  margin-left: 2px;
  vertical-align: bottom;
  background: rgba(37, 99, 235, 0.55);
  animation: blink 0.8s step-end infinite;
}

.assistant-history-card {
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 16px;
  background: #f8fafc;
  overflow: hidden;
  box-shadow: none;
}

.assistant-history-card summary {
  list-style: none;
  cursor: pointer;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.assistant-history-card summary::-webkit-details-marker {
  display: none;
}

.assistant-history-summary-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.assistant-history-summary-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.assistant-history-summary-right {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.assistant-history-summary-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: #64748b;
  flex: none;
}

.assistant-history-summary-title {
  display: inline-block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.assistant-history-summary-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(226, 232, 240, 0.92);
  color: #475569;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.assistant-history-summary-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  flex: none;
  transition: transform 0.16s ease;
}

.assistant-history-card[open] .assistant-history-summary-chevron {
  transform: rotate(180deg);
}

.assistant-history-card-body {
  padding: 0 14px 14px;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.9);
}

.assistant-history-card-body p,
.assistant-history-card-body ul,
.assistant-history-card-body ol,
.assistant-history-card-body pre {
  margin-top: 12px;
}

.assistant-history-card-thought summary {
  background: rgba(248, 250, 252, 0.96);
}

.assistant-history-card-tool summary {
  background: rgba(248, 250, 252, 0.96);
}

.assistant-history-card-tool .assistant-history-card-body code {
  font-size: 12px;
}

.msg-action-btn {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent-strong);
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.4);
  animation: typing 1s infinite ease-in-out;
}

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

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

@keyframes typing {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.message-status {
  align-self: center;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(33, 27, 18, 0.07);
  color: var(--text-muted);
  font-size: 13px;
}

.composer-shell {
  padding: 18px 22px calc(18px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 252, 245, 0.62);
}

.composer-frame {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

#chat-input {
  min-height: 58px;
  max-height: 220px;
  resize: none;
  padding: 16px 18px;
}

.composer-send {
  min-width: 88px;
}

.composer-meta {
  margin-top: 10px;
  font-size: 13px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(34, 29, 21, 0.32);
  backdrop-filter: blur(4px);
  z-index: 40;
}

.model-panel {
  position: fixed;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: min(420px, calc(100vw - 32px));
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 18px;
  border-radius: 28px;
}

.model-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.model-list {
  padding-top: 14px;
}

.model-group + .model-group {
  margin-top: 18px;
}

.model-group-title {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.model-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--text);
  text-align: left;
}

.model-item + .model-item {
  margin-top: 10px;
}

.model-item.is-active {
  border-color: rgba(37, 99, 235, 0.26);
  background: rgba(37, 99, 235, 0.08);
}

.model-item em {
  font-style: normal;
  font-size: 12px;
  color: var(--text-muted);
}

.mobile-only {
  display: none;
}

@media (max-width: 960px) {
  .workspace-shell {
    padding: 12px;
  }

  .conversation-sidebar {
    position: fixed;
    top: 12px;
    left: 12px;
    bottom: 12px;
    z-index: 60;
    width: min(var(--sidebar-width), calc(100vw - 24px));
    transform: translateX(calc(-100% - 16px));
    transition: transform 0.22s ease;
  }

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

  .mobile-only {
    display: inline-flex;
  }

  .workspace-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-left,
  .topbar-actions {
    width: 100%;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .device-select-field,
  .device-select-field select {
    width: 100%;
  }

  .status-badge,
  .btn-secondary,
  .btn-ghost {
    width: 100%;
    justify-content: center;
  }

  .message-bubble {
    max-width: 100%;
  }

  .message-bubble.assistant.assistant-history {
    width: 100%;
    max-width: 100%;
  }

  .assistant-history-block {
    padding-right: 0;
  }
}

@media (max-width: 640px) {
  .login-panel {
    padding: 28px 22px;
    border-radius: 26px;
  }

  .chat-shell {
    border-radius: 24px;
  }

  .workspace-shell {
    padding: 8px;
  }

  .workspace-topbar,
  .chat-messages,
  .composer-shell {
    padding-left: 16px;
    padding-right: 16px;
  }

  .composer-frame {
    flex-direction: column;
    align-items: stretch;
  }

  .composer-send {
    width: 100%;
  }

  .model-panel {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: min(78vh, 720px);
    max-width: 100%;
    border-radius: 28px 28px 0 0;
  }
}
