:root {
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;

  --space-1: 0.375rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;

  --font-sans: "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --bg: #f3f6fb;
  --bg-accent: #e7eefc;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-strong: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --focus: rgba(37, 99, 235, 0.22);

  --shadow-card: 0 14px 38px rgba(2, 6, 23, 0.09);
  --shadow-soft: 0 2px 10px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-sans);
  color: var(--text);
  line-height: 1.5;
  background:
    radial-gradient(900px 500px at 12% -8%, rgba(255, 255, 255, 0.08) 0%, transparent 60%),
    radial-gradient(1000px 640px at 85% 110%, var(--bg-accent) 0%, transparent 60%),
    var(--bg);
  display: grid;
  place-items: center;
  padding: clamp(var(--space-4), 2vw, var(--space-6));
}

.app {
  width: 100%;
  max-width: 520px;
}

.card {
  width: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(10px) saturate(130%);
  -webkit-backdrop-filter: blur(10px) saturate(130%);
  box-shadow: var(--shadow-card);
  padding: clamp(var(--space-5), 2.5vw, 1.75rem);
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-3);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.34rem 0.76rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  box-shadow: var(--shadow-soft);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--primary);
}

.theme-toggle {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--muted);
  border-radius: 10px;
  padding: 0.38rem 0.62rem;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  min-width: 68px;
}

.card-header {
  margin-bottom: var(--space-5);
}

h1 {
  margin: 0;
  font-size: clamp(1.42rem, 3.6vw, 1.78rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.subtitle {
  margin: var(--space-2) 0 0;
  font-size: 0.96rem;
  color: var(--muted);
}

.banner {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.13);
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 600;
}

.form {
  display: grid;
  gap: var(--space-3);
}

.field {
  display: grid;
  gap: var(--space-1);
}

.field span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

input {
  width: 100%;
  min-height: 46px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-strong);
  padding: 0.78rem 0.86rem;
  font-size: 0.96rem;
  color: var(--text);
  transition: border-color 130ms ease, box-shadow 130ms ease;
}

input::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

input:hover {
  border-color: var(--line-strong);
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--focus);
}

.actions {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.btn {
  width: 100%;
  min-height: 46px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.74rem 1rem;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.24);
}

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

.btn-secondary {
  background: var(--surface-strong);
  border-color: var(--line);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--line-strong);
}

.command-box {
  margin: 0 0 var(--space-4);
  padding: 0.9rem 0.95rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #f5f9ff;
  border-color: #dbe7ff;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.kv-list {
  display: grid;
  gap: var(--space-1);
  margin: 0 0 var(--space-5);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
}

.kv {
  margin: 0;
  font-size: 0.93rem;
}

.kv strong {
  color: var(--muted);
}

@media (max-width: 520px) {
  .card {
    border-radius: 18px;
  }

  .top-row {
    margin-bottom: var(--space-4);
  }

  .card-header {
    margin-bottom: var(--space-4);
  }

  .actions {
    margin-top: var(--space-4);
  }
}

.chat-shell {
  --chat-gutter: 1.2rem;
  max-width: 430px;
  margin: 0 auto;
  border: 1px solid #e7edf6;
  background: #fff;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.1);
  padding: 0;
  display: flex;
  flex-direction: column;
  height: clamp(560px, 78vh, 700px);
  max-height: calc(100vh - 2.4rem);
  overflow: hidden;
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: calc(0.82rem + 10px) var(--chat-gutter);
  border-bottom: 1px solid #eef2f8;
}

.chat-topbar-left {
  display: flex;
  align-items: center;
  gap: 0.56rem;
}

.chat-topbar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  object-fit: cover;
}

.chat-topbar-name {
  margin: 0;
  font-size: 0.87rem;
  font-weight: 700;
  color: #111827;
  line-height: 1.1;
}

.chat-topbar-sub {
  margin: 0.06rem 0 0;
  font-size: 0.76rem;
  color: #6b7280;
  line-height: 1.15;
}

.chat-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
}

.chat-meta {
  margin: 0;
  font-size: 0.73rem;
  color: #8b96a8;
  line-height: 1.2;
  padding-left: 0.56rem;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 0;
  background: transparent;
  padding: 0.8rem var(--chat-gutter) 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.62rem;
  align-items: stretch;
}

.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
}

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

.chat-avatar {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  object-fit: cover;
  border: 0;
  box-shadow: 0 3px 9px rgba(2, 6, 23, 0.16);
  flex: 0 0 22px;
}

.chat-bubble {
  max-width: min(82%, 340px);
  width: fit-content;
  padding: 0.5rem 0.68rem;
  border-radius: 12px;
  border: 0;
  box-shadow: none;
}

.chat-agent {
  background: #f3f5f8;
  color: #1f2937;
  border-top-left-radius: 6px;
}

.chat-user {
  background: #635bff;
  color: #fff;
  font-weight: 500;
  border-top-right-radius: 6px;
}

.chat-text {
  margin: 0;
  font-size: 0.87rem;
  line-height: 1.36;
  white-space: pre-line;
}

.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  min-width: 44px;
  min-height: 28px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #98a2b3;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

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

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

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-2px);
    opacity: 1;
  }
}

.chat-composer {
  margin: 0.4rem var(--chat-gutter) 0.75rem;
  border: 2px solid #5c6dff;
  border-radius: 18px;
  background: #fff;
  padding: 0.45rem 0.52rem;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.45rem;
}

.chat-composer input {
  border: 0;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
  min-height: 34px;
  padding: 0.35rem 0.46rem;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: #111827;
}

.chat-composer input:focus {
  box-shadow: none;
  border-color: transparent;
}

.chat-composer .btn {
  min-width: 28px;
  width: 28px;
  min-height: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
  background: #5c6dff;
  box-shadow: none;
}

.chat-actions {
  margin-top: var(--space-2);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chat-actions .btn {
  width: auto;
  min-height: 30px;
  padding: 0.35rem 0.55rem;
  font-size: 0.75rem;
  border-radius: 8px;
}

.icon-send svg {
  width: 14px;
  height: 14px;
  fill: #fff;
}

@media (max-width: 520px) {
  .chat-shell {
    --chat-gutter: 1rem;
    height: min(82vh, 620px);
    max-height: calc(100vh - 1.4rem);
  }

  .chat-bubble {
    max-width: 86%;
  }
}
