:root {
  --bg: #070b14;
  --bg-elevated: #0d1424;
  --surface: #121c31;
  --surface-hover: #18243d;
  --border: rgba(107, 164, 217, 0.18);
  --border-strong: rgba(107, 164, 217, 0.35);
  --text: #edf3fb;
  --text-muted: #8fa3c1;
  --primary: #116cb5;
  --primary-light: #6ba4d9;
  --primary-mid: #207fc3;
  --accent: #3d9eef;
  --success: #3ecf8e;
  --warning: #f0b429;
  --danger: #f07178;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-width: 300px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  background:
    radial-gradient(circle at top left, rgba(17, 108, 181, 0.18), transparent 28%),
    radial-gradient(circle at bottom right, rgba(32, 127, 195, 0.12), transparent 32%),
    var(--bg);
}

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

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 18px;
  border-right: 1px solid var(--border);
  background: rgba(10, 16, 28, 0.82);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 42px;
  height: 42px;
  filter: drop-shadow(0 8px 18px rgba(17, 108, 181, 0.35));
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(18, 28, 49, 0.72);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary-light);
}

.panel-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  outline: none;
}

.select:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(17, 108, 181, 0.18);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: 0.18s ease;
}

.btn-primary {
  padding: 12px 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-mid));
  color: white;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(17, 108, 181, 0.28);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(17, 108, 181, 0.34);
}

.btn-ghost {
  padding: 10px 12px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.btn-sm {
  padding: 8px 10px;
  font-size: 0.82rem;
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
}

.btn-send {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  color: white;
}

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

.toggle {
  position: relative;
  width: 42px;
  height: 24px;
  display: inline-block;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #24324d;
  border-radius: 999px;
  transition: 0.2s ease;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: white;
  transition: 0.2s ease;
}

.toggle input:checked + .toggle-slider {
  background: linear-gradient(135deg, var(--primary), var(--accent));
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

.mcp-tools {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.mcp-tool {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(7, 11, 20, 0.55);
  border: 1px solid var(--border);
}

.mcp-tool strong {
  display: block;
  font-size: 0.84rem;
  margin-bottom: 4px;
}

.mcp-tool span {
  display: block;
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.mcp-tool.error {
  border-color: rgba(240, 113, 120, 0.35);
}

.sidebar-footer {
  margin-top: auto;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(18, 28, 49, 0.9);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 12px rgba(240, 180, 41, 0.45);
}

.status-badge.online .status-dot {
  background: var(--success);
  box-shadow: 0 0 12px rgba(62, 207, 142, 0.45);
}

.status-badge.offline .status-dot {
  background: var(--danger);
  box-shadow: 0 0 12px rgba(240, 113, 120, 0.45);
}

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 11, 20, 0.55);
  backdrop-filter: blur(12px);
}

.chat-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.chat-header p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.setting {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.setting input[type="range"] {
  accent-color: var(--accent);
}

.messages {
  overflow: auto;
  padding: 28px;
  scroll-behavior: smooth;
}

.welcome {
  max-width: 720px;
  margin: 8vh auto 0;
  text-align: center;
}

.welcome-logo {
  width: 72px;
  height: 72px;
  margin-bottom: 18px;
  opacity: 0.95;
}

.welcome h3 {
  margin: 0 0 10px;
  font-size: 1.8rem;
}

.welcome p {
  margin: 0 auto;
  max-width: 520px;
  color: var(--text-muted);
  line-height: 1.6;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

.suggestion {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(18, 28, 49, 0.72);
  color: var(--text);
  cursor: pointer;
}

.suggestion:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.message {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 14px;
  max-width: 900px;
  margin: 0 auto 22px;
  animation: fadeUp 0.28s ease;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.message.user .message-avatar {
  background: rgba(17, 108, 181, 0.22);
  color: var(--primary-light);
  border: 1px solid var(--border);
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, rgba(17, 108, 181, 0.35), rgba(32, 127, 195, 0.25));
  border: 1px solid var(--border-strong);
}

.message-body {
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(18, 28, 49, 0.72);
  line-height: 1.65;
}

.message.user .message-body {
  background: rgba(17, 108, 181, 0.12);
}

.message-image {
  max-width: 280px;
  border-radius: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

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

.message-body > :last-child {
  margin-bottom: 0;
}

.message-body h1,
.message-body h2,
.message-body h3 {
  margin: 18px 0 10px;
  line-height: 1.3;
}

.message-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: rgba(7, 11, 20, 0.7);
  padding: 0.15em 0.4em;
  border-radius: 6px;
}

.message-body pre {
  position: relative;
  overflow: auto;
  padding: 14px;
  border-radius: 12px;
  background: #0a101d;
  border: 1px solid var(--border);
}

.message-body pre code {
  padding: 0;
  background: transparent;
}

.copy-code {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(18, 28, 49, 0.92);
  color: var(--text-muted);
  font-size: 0.72rem;
  cursor: pointer;
}

.message-body blockquote {
  padding-left: 14px;
  border-left: 3px solid var(--primary-light);
  color: var(--text-muted);
}

.message-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.message-body th,
.message-body td {
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.message-body th {
  background: rgba(7, 11, 20, 0.55);
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-height: 24px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary-light);
  animation: bounce 1.2s infinite ease-in-out;
}

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

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

.tool-activity {
  margin: 0 28px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(18, 28, 49, 0.72);
  overflow: hidden;
}

.tool-activity.hidden {
  display: none;
}

.tool-activity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--primary-light);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tool-activity-header button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}

.tool-activity-body {
  max-height: 160px;
  overflow: auto;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: pre-wrap;
}

.composer {
  padding: 0 28px 22px;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  background: rgba(13, 20, 36, 0.92);
  box-shadow: var(--shadow);
}

.composer-box:focus-within {
  border-color: rgba(61, 158, 239, 0.55);
  box-shadow: 0 0 0 4px rgba(17, 108, 181, 0.14), var(--shadow);
}

#promptInput {
  flex: 1;
  min-height: 28px;
  max-height: 180px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  line-height: 1.5;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer-note {
  margin: 10px 8px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.76rem;
}

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

  .sidebar {
    display: none;
  }

  .chat-header,
  .messages,
  .composer,
  .tool-activity {
    padding-left: 16px;
    padding-right: 16px;
  }

  .tool-activity {
    margin-left: 16px;
    margin-right: 16px;
  }
}
