:root {
  color-scheme: dark;
  --bg: #212121;
  --panel: #262626;
  --bubble: #2f2f2f;
  --bubble-user: #313131;
  --muted: #9e9e9e;
  --btn: #404040;
  --btn-active: #3fb950;
  --text: #f2f2f2;
  --accent: #d6d6d6;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #2a2a2a 0%, #212121 60%);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.layout {
  position: relative;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-btn {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: none;
  background: transparent;
  color: #bfbfbf;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.top-btn:hover {
  background: #2a2a2a;
  color: #fff;
}

.top-btn svg {
  width: 22px;
  height: 22px;
}

.api-panel {
  display: none;
}

.chat {
  flex: 1;
  padding: 32px 24px 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.chat::after {
  content: "";
  display: block;
  height: 28px;
}

.chat::-webkit-scrollbar {
  width: 8px;
}

.chat::-webkit-scrollbar-thumb {
  background: #3a3a3a;
  border-radius: 999px;
}

.composer {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(680px, 88vw);
  transition: all 0.4s ease;
}

.layout.has-output .composer {
  top: auto;
  bottom: 32px;
  transform: translateX(-50%);
}

.input-shell {
  background: var(--panel);
  border-radius: 22px;
  padding: 16px 16px 52px;
  box-shadow: var(--shadow);
  position: relative;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #2f2f2f;
  border: 1px solid #3a3a3a;
  border-radius: 12px;
  padding: 6px 10px;
  font-size: 12px;
  color: #e6e6e6;
}

.attachment-icon {
  width: 14px;
  height: 14px;
  border: 1.5px solid #a8a8a8;
  border-radius: 3px;
  position: relative;
}

.attachment-icon::after {
  content: "";
  position: absolute;
  right: -2px;
  top: -2px;
  width: 6px;
  height: 6px;
  border-top: 1.5px solid #a8a8a8;
  border-right: 1.5px solid #a8a8a8;
  border-radius: 0 2px 0 0;
}

.attachment-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-remove {
  border: none;
  background: transparent;
  color: #cfcfcf;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}

.attachment-remove:hover {
  color: #fff;
}

#messageInput {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  min-height: 36px;
  max-height: 160px;
}

#messageInput::placeholder {
  color: #7a7a7a;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.actions {
  position: absolute;
  right: 14px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: none;
  background: var(--btn);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, opacity 0.2s ease;
  color: var(--accent);
}

.action-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.action-btn.circle {
  border-radius: 999px;
}

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

.action-btn.enabled {
  background: var(--btn-active);
  color: #0f1a10;
}

.action-btn.agent-on {
  background: #1f6feb;
  color: #0b1020;
}

.terminal-card {
  width: min(720px, 92vw);
  background: #101010;
  border-radius: 14px;
  border: 1px solid #242424;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.terminal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #161616;
  border-bottom: 1px solid #242424;
  color: #d6d6d6;
  font-size: 12px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.terminal-body {
  padding: 12px;
  max-height: 260px;
  overflow: auto;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 12px;
  color: #e6e6e6;
  white-space: pre-wrap;
}

.terminal-row {
  display: block;
  margin-bottom: 6px;
}

.terminal-command {
  color: #9cdcfe;
}

.terminal-output {
  color: #d4d4d4;
}

.terminal-error {
  color: #fca5a5;
}

.terminal-actions {
  display: flex;
  gap: 8px;
}

.terminal-download {
  border: none;
  background: #2d2d2d;
  color: #e7e7e7;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

.terminal-download:hover {
  background: #3a3a3a;
}

.terminal-download.disabled {
  pointer-events: none;
  opacity: 0.45;
}

.action-btn:not(:disabled):hover {
  transform: translateY(-1px);
}

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

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

.message.assistant {
  align-items: center;
}

.bubble {
  padding: 14px 16px;
  border-radius: 18px;
  max-width: min(640px, 90vw);
  white-space: pre-wrap;
  box-shadow: var(--shadow);
}

.typing-bubble {
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.message.user .bubble {
  background: var(--bubble-user);
  color: #fff;
  border-top-right-radius: 6px;
  margin-right: 70px;
}

.message.assistant .bubble.answer {
  background: transparent;
  box-shadow: none;
  padding: 0;
  color: #fff;
}

.md-h1,
.md-h2,
.md-h3 {
  margin: 6px 0 4px;
  font-weight: 600;
}

.md-h1 {
  font-size: 26px;
}

.md-h2 {
  font-size: 22px;
}

.md-h3 {
  font-size: 17px;
}

.md-p {
  font-size: 15px;
  line-height: 1.5;
}

.md-link {
  color: #9bd1ff;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.md-link:hover {
  color: #c7e6ff;
}

.md-table {
  width: min(720px, 92vw);
  background: #1a1a1a;
  border-radius: 14px;
  border: 1px solid #2a2a2a;
  overflow: hidden;
}

.md-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.md-table th,
.md-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #262626;
  vertical-align: top;
}

.md-table th {
  background: #202020;
  color: #f0f0f0;
  font-weight: 600;
}

.md-table tr:nth-child(even) td {
  background: #171717;
}

.md-space {
  height: 8px;
}

.inline-code {
  font-family: "JetBrains Mono", "Fira Code", monospace;
  background: #2b2b2b;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.95em;
}

.code-block {
  width: min(560px, 88vw);
  background: #171717;
  border-radius: 16px;
  border: 1px solid #2a2a2a;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #1a1a1a;
  border-bottom: 1px solid #242424;
  font-size: 12px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: #cfcfcf;
}

.code-lang {
  font-weight: 600;
}

.code-copy {
  border: none;
  background: #2d2d2d;
  color: #e7e7e7;
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s ease, color 0.2s ease;
}

.code-copy:hover {
  background: #3a3a3a;
  color: #fff;
}

.code-copy svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.code-block pre {
  margin: 0;
  padding: 16px 18px 20px;
  overflow-x: auto;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #e8e8e8;
  background: #121212;
  border-top: 1px solid #202020;
}

.token.keyword {
  color: #7dd3fc;
}

.token.string {
  color: #a7f3d0;
}

.token.comment {
  color: #9ca3af;
}

.token.number {
  color: #fca5a5;
}

.token.tag {
  color: #fdba74;
}

.token.attr-name {
  color: #f9a8d4;
}

.token.attr-value {
  color: #c4b5fd;
}

.thinking {
  width: min(640px, 90vw);
  background: #2b2b2b;
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.3s ease;
}

.web-results {
  width: min(640px, 90vw);
  background: #1f1f1f;
  border-radius: 14px;
  border: 1px solid #2a2a2a;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.web-header {
  padding: 8px 12px;
  background: #181818;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #c9c9c9;
  border-bottom: 1px solid #2a2a2a;
}

.web-body {
  margin: 0;
  padding: 12px;
  max-height: 260px;
  overflow: auto;
}

.web-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.web-item {
  background: #171717;
  border: 1px solid #242424;
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.web-title {
  font-size: 14px;
  font-weight: 600;
  color: #f0f0f0;
}

.web-url {
  font-size: 12px;
  color: #9aa4b2;
  word-break: break-all;
}

.web-snippet {
  font-size: 12px;
  color: #d4d4d4;
  line-height: 1.4;
  max-height: 96px;
  overflow: hidden;
}

.web-empty {
  font-size: 12px;
  color: #bdbdbd;
}

.thinking.collapsed .thinking-body {
  max-height: 0;
  opacity: 0;
}

.thinking.collapsed .thinking-arrow {
  transform: rotate(-90deg);
}

.thinking-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.thinking-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bulb {
  width: 16px;
  height: 16px;
  border: 1px solid #6c6c6c;
  border-radius: 999px;
  position: relative;
}

.bulb::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  border: 1px solid #6c6c6c;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.thinking-arrow {
  width: 14px;
  height: 14px;
  border-right: 2px solid #7a7a7a;
  border-bottom: 2px solid #7a7a7a;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}

.thinking-body {
  font-size: 14px;
  color: #d5d5d5;
  white-space: pre-wrap;
  max-height: 420px;
  overflow: auto;
  opacity: 1;
  transition: max-height 0.25s ease, opacity 0.2s ease;
}

.dots {
  display: inline-flex;
  gap: 6px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #8c8c8c;
  animation: pulse 1s infinite ease-in-out;
}

.dot:nth-child(2) {
  animation-delay: 0.2s;
}

.dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(0.9);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
}

.copy-row {
  margin-top: 8px;
  display: flex;
  justify-content: center;
}

.copy-btn {
  border: none;
  background: transparent;
  color: #bdbdbd;
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
  transition: background 0.2s ease, color 0.2s ease;
}

.copy-btn:hover {
  background: #3a3a3a;
  color: #fff;
}

.copy-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

@media (max-width: 640px) {
  .chat {
    padding: 24px 16px 140px;
  }

  .input-shell {
    padding: 14px 14px 52px;
  }
}
