:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --border: #e3e3e6;
  --text: #1a1a1e;
  --text-muted: #6b6b73;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --user-bubble: #4f46e5;
  --user-bubble-text: #ffffff;
  --agent-bubble: #ffffff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --surface: #1c1c1f;
    --border: #2e2e33;
    --text: #ececee;
    --text-muted: #9a9aa2;
    --agent-bubble: #26262b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
}

.topbar nav a {
  margin-left: 1.25rem;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.topbar nav a:hover {
  color: var(--accent);
}

main {
  max-width: 820px;
  margin: 0 auto;
  padding: 1.25rem;
}

/* Chat page */

.chat-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0;
}

.subtitle a {
  color: var(--accent);
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.5rem 0.25rem;
}

.message {
  max-width: 78%;
  padding: 0.65rem 0.9rem;
  border-radius: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}

.message.agent {
  align-self: flex-start;
  background: var(--agent-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Markdown rendered inside agent replies */
.message.agent p {
  margin: 0 0 0.6em;
}

.message.agent p:last-child {
  margin-bottom: 0;
}

.message.agent ul,
.message.agent ol {
  margin: 0.3em 0 0.6em;
  padding-left: 1.3em;
}

.message.agent li {
  margin: 0.15em 0;
}

.message.agent code {
  background: rgba(127, 127, 127, 0.16);
  padding: 0.12em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

.message.agent strong {
  font-weight: 700;
}

.message.error {
  align-self: flex-start;
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.tool-indicator {
  align-self: flex-start;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 0.1rem 0.2rem;
}

.chat-form {
  display: flex;
  gap: 0.6rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.chat-input {
  flex: 1;
  resize: none;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  max-height: 8rem;
}

.chat-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 0.6rem 1.1rem;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

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

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

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

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

.btn-danger {
  background: var(--danger);
  color: white;
}

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

/* Overlay / confirm dialog */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.confirm-dialog {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 380px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

/* Tools page */

.tools-page h1 {
  margin-bottom: 0.25rem;
}

.tool-category {
  margin-top: 1.75rem;
}

.tool-category h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.75rem;
}

.tool-card {
  display: block;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 0.85rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}

.tool-card:hover {
  border-color: var(--accent);
}

.tool-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.tool-desc {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin: 0.5rem 0 0;
}

/* Tool tester page */

.back-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.88rem;
}

.tool-test-page h1 {
  margin: 0.5rem 0 0.25rem;
}

.tool-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-top: 1.5rem;
  max-width: 480px;
}

.tool-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.tool-field-label {
  font-size: 0.85rem;
  font-weight: 600;
}

.required-mark {
  color: var(--danger);
}

.tool-field input {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.tool-field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.tool-result-wrap {
  margin-top: 1.75rem;
  max-width: 720px;
}

.tool-result-wrap.hidden {
  display: none;
}

.tool-result-wrap h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.tool-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0;
}

.tool-result-wrap.result-error .tool-result {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
}
