:root {
  --bg0: #060a14;
  --bg1: #0c1224;
  --surface: rgba(255, 255, 255, 0.05);
  --surface2: rgba(255, 255, 255, 0.09);
  --border: rgba(56, 189, 248, 0.14);
  --border-soft: rgba(255, 255, 255, 0.1);
  --text: #e8f0ff;
  --muted: rgba(232, 240, 255, 0.52);
  --accent: #38bdf8;
  --accent2: #818cf8;
  --accent-glow: rgba(56, 189, 248, 0.35);
  --user-bubble: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(129, 140, 248, 0.2));
  --bot-bubble: rgba(8, 14, 28, 0.72);
  --danger: #fb7185;
  --ok: #34d399;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --scroll-track: rgba(255, 255, 255, 0.03);
  --scroll-thumb: rgba(56, 189, 248, 0.22);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --shell-max: 860px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

html,
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg0);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  height: 100%;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  position: relative;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(56, 189, 248, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 0%, black 20%, transparent 75%);
  opacity: 0.65;
}

.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  opacity: 0.45;
}

.bg-glow--a {
  width: 420px;
  height: 320px;
  top: -80px;
  left: -60px;
  background: rgba(56, 189, 248, 0.2);
}

.bg-glow--b {
  width: 360px;
  height: 280px;
  top: 0;
  right: -40px;
  background: rgba(129, 140, 248, 0.18);
}

.app-shell {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: var(--shell-max);
  margin: 0 auto;
  border-left: 1px solid transparent;
  border-right: 1px solid transparent;
}

@media (min-width: 900px) {
  .app-shell {
    border-left-color: var(--border-soft);
    border-right-color: var(--border-soft);
    box-shadow: 0 0 80px rgba(0, 0, 0, 0.35);
  }
}

.top-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(12, 18, 36, 0.94), rgba(12, 18, 36, 0.6));
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.brand-mark {
  flex-shrink: 0;
  display: flex;
  filter: drop-shadow(0 0 12px var(--accent-glow));
}

.brand-text {
  min-width: 0;
}

.app-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: linear-gradient(90deg, #e0f2fe, #c7d2fe);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.app-tagline {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
  letter-spacing: 0.04em;
}

.top-bar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-pill {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  font-size: 11px;
  color: var(--muted);
}

@media (min-width: 480px) {
  .status-pill {
    display: inline-flex;
  }
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.6);
}

.status-pill--busy .status-dot {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-pill--offline .status-dot {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(251, 113, 133, 0.5);
}

.voice-pill {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  font-size: 11px;
  color: var(--muted);
}

.voice-pill.is-active {
  display: inline-flex;
}

.voice-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.voice-pill--rec .voice-dot {
  background: #f87171;
  box-shadow: 0 0 10px rgba(248, 113, 113, 0.65);
  animation: pulse 0.9s ease-in-out infinite;
}

.voice-pill--stt .voice-dot {
  background: #fbbf24;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.55);
  animation: pulse 1.2s ease-in-out infinite;
}

.voice-pill--rec .voice-label {
  color: #fecaca;
}

.voice-pill--stt .voice-label {
  color: #fde68a;
}

.input-wrap.is-voice-recording {
  border-color: rgba(248, 113, 113, 0.55);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.12);
}

.input-wrap.is-voice-transcribing {
  border-color: rgba(251, 191, 36, 0.5);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.1);
}

.voice-toast {
  margin: 0 12px 8px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.4;
  color: #fde68a;
  border: 1px solid rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.1);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.5;
    transform: scale(0.9);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
}

.new-chat-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.new-chat-btn:hover {
  background: var(--surface2);
}

.new-chat-btn:active {
  transform: scale(0.98);
}

.chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 12px;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

.chat-scroll:hover {
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

.welcome-card {
  margin: 8vh auto 24px;
  max-width: 520px;
  padding: 22px 20px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: linear-gradient(145deg, rgba(12, 20, 40, 0.85), rgba(8, 12, 24, 0.6));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  text-align: center;
}

.welcome-title {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 600;
}

.welcome-title strong {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.welcome-desc {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.welcome-chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(56, 189, 248, 0.08);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.welcome-chip:hover {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.35);
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.msg-user {
  align-items: flex-end;
}

.msg-bot {
  align-items: stretch;
  width: 100%;
}

.msg-meta {
  font-size: 11px;
  color: var(--muted);
  padding: 0 4px;
}

.msg-body {
  max-width: min(92%, 560px);
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  line-height: 1.55;
  font-size: 15px;
  word-break: break-word;
}

.msg-user .msg-body {
  background: var(--user-bubble);
  border-color: rgba(56, 189, 248, 0.2);
}

.msg-bot .msg-body {
  background: var(--bot-bubble);
  max-width: none;
  width: 100%;
  border-color: var(--border-soft);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.04);
}

.msg-bot .msg-body.is-streaming {
  min-height: 2.75em;
}

.msg-body p {
  margin: 0 0 8px;
}

.msg-body p:last-child {
  margin-bottom: 0;
}

.msg-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.msg-body a {
  color: var(--accent);
}

.md-content {
  word-break: break-word;
}

.md-content > :first-child {
  margin-top: 0;
}

.md-content > :last-child {
  margin-bottom: 0;
}

.md-content h1,
.md-content h2,
.md-content h3,
.md-content h4 {
  margin: 14px 0 8px;
  line-height: 1.35;
  font-weight: 600;
}

.md-content h1 {
  font-size: 1.25em;
}

.md-content h2 {
  font-size: 1.15em;
}

.md-content h3 {
  font-size: 1.05em;
}

.md-content p {
  margin: 0 0 8px;
}

.md-content ul,
.md-content ol {
  margin: 0 0 8px;
  padding-left: 1.35em;
}

.md-content li {
  margin: 4px 0;
}

.md-content blockquote {
  margin: 0 0 8px;
  padding: 6px 10px;
  border-left: 3px solid rgba(56, 189, 248, 0.45);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0 8px 8px 0;
}

.md-content pre {
  margin: 0 0 10px;
  padding: 10px 12px;
  overflow-x: auto;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
}

.md-content pre code {
  padding: 0;
  border: 0;
  background: transparent;
  font-size: inherit;
}

.md-content table {
  width: 100%;
  margin: 0 0 10px;
  border-collapse: collapse;
  font-size: 14px;
}

.md-content th,
.md-content td {
  padding: 6px 8px;
  border: 1px solid var(--border-soft);
  text-align: left;
}

.md-content th {
  background: rgba(56, 189, 248, 0.08);
}

.md-fallback {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-body-content + .msg-body-content {
  margin-top: 8px;
}

.msg-bot .msg-body-content {
  color: rgba(232, 240, 255, 0.78);
}

.msg-bot .msg-body-content .md-content {
  color: inherit;
}

.tool-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}

.tool-panel--after {
  margin-bottom: 0;
  margin-top: 14px;
}

.tool-panel--after-tool {
  margin-top: 12px;
}

.tool-panel + .tool-panel {
  margin-top: 12px;
}

.tool-panel + .msg-body-content {
  margin-top: 14px;
}

.tool-inline {
  display: inline-block;
  max-width: 100%;
  padding: 5px 10px;
  font-family: var(--mono), "Segoe UI Emoji", "Apple Color Emoji", sans-serif;
  font-size: 12px;
  line-height: 1.45;
  color: rgba(232, 240, 255, 0.82);
  word-break: break-all;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px dashed rgba(255, 255, 255, 0.14);
}

.tool-inline--running {
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.08);
}

.tool-inline--done {
  border-color: rgba(52, 211, 153, 0.28);
  background: rgba(52, 211, 153, 0.06);
}

.tool-card {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
  cursor: default;
}

.tool-card--running {
  border-color: rgba(56, 189, 248, 0.35);
  box-shadow: inset 3px 0 0 var(--accent);
}

.tool-card--done {
  border-color: rgba(52, 211, 153, 0.28);
  box-shadow: inset 3px 0 0 var(--ok);
}

.tool-card--collapsed {
  cursor: pointer;
}

.tool-card--collapsed .tool-card-body {
  display: none;
}

.tool-card--collapsed.tool-card--expanded .tool-card-body {
  display: block;
}

.tool-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.tool-card--collapsed:not(.tool-card--expanded) .tool-card-head {
  padding-bottom: 10px;
}

.tool-icon {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 18px;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.tool-card--done .tool-icon {
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.25);
}

.tool-head-text {
  flex: 1;
  min-width: 0;
}

.tool-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tool-summary {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  font-family: var(--mono), "Segoe UI Emoji", sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-status {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

.tool-status--running {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.tool-status--running::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
  animation: tool-pulse 1.2s ease-in-out infinite;
}

@keyframes tool-pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

.tool-status--done {
  color: var(--ok);
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.28);
}

.tool-status--done::before {
  content: "✓";
  margin-right: 4px;
}

.tool-card-body {
  padding: 0 12px 10px 58px;
}

.tool-detail {
  margin: 0;
  font-family: var(--mono), "Segoe UI Emoji", "Apple Color Emoji", sans-serif;
  font-size: 12px;
  line-height: 1.45;
  color: rgba(232, 240, 255, 0.78);
  word-break: break-all;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.tool-detail-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 4px;
  font-family: var(--font);
  letter-spacing: 0.06em;
}

.tool-detail--result {
  margin-top: 8px;
}

.msg-error {
  color: var(--danger);
}

.msg-muted {
  color: var(--muted);
}

.typing-dot::after {
  content: "…";
  animation: blink 1.2s infinite steps(1);
}

@keyframes blink {
  0% {
    opacity: 0.2;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.2;
  }
}

.composer {
  flex: 0 0 auto;
  padding: 10px 12px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border-soft);
  background: linear-gradient(0deg, rgba(6, 10, 20, 0.97), rgba(6, 10, 20, 0.75));
  backdrop-filter: blur(14px);
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.input-wrap {
  flex: 1;
  min-width: 0;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-wrap:focus-within {
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

.message-input {
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  font-family: inherit;
}

.voice-hold-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  color: var(--accent);
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.voice-hold-btn:hover:not(:disabled) {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.08);
}

.voice-hold-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.voice-hold-btn.is-holding,
.voice-hold-btn.is-recording {
  color: #fff;
  border-color: rgba(248, 113, 113, 0.65);
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.35), rgba(251, 113, 133, 0.28));
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.15);
}

.voice-hold-btn.is-transcribing {
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.55);
  background: rgba(251, 191, 36, 0.12);
}

.send-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  color: #041018;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  background: linear-gradient(135deg, #7dd3fc, #a5b4fc);
  box-shadow: 0 8px 24px var(--accent-glow);
}

.send-icon,
.stop-icon {
  display: none;
}

.stop-icon {
  display: none;
}

.send-btn.is-stop {
  color: #fff;
  background: linear-gradient(135deg, #f87171, #fb7185);
  box-shadow: 0 8px 24px rgba(251, 113, 133, 0.35);
}

.send-btn.is-stop:hover {
  filter: brightness(1.06);
}

.send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.model-load-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 10, 20, 0.82);
  backdrop-filter: blur(8px);
}

.model-load-overlay[hidden] {
  display: none !important;
}

.model-load-card {
  width: min(420px, 100%);
  padding: 22px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(12, 18, 36, 0.95);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}

.model-load-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.model-load-stage {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--accent);
}

.model-load-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface2);
  overflow: hidden;
  margin-bottom: 12px;
}

.model-load-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.25s ease;
}

.model-load-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.status-pill--loading .status-dot {
  background: #fbbf24;
  animation: pulse 1s ease-in-out infinite;
}

@media (max-width: 420px) {
  .send-btn .btn-text {
    display: none;
  }
  .send-btn:not(.is-stop) .send-icon {
    display: block;
  }
  .send-btn.is-stop .stop-icon {
    display: block;
  }
  .send-btn {
    min-width: 44px;
    padding: 0;
  }
}
