/* vhsys · MCP Connector POC — tema
   Paleta escura de "livro-razão": tons de ardósia + tinta cobre, com as
   chamadas de tool renderizadas como linhas de lançamento contábil
   (monoespaçada, barra lateral, selo ok/erro) — o único elemento com
   personalidade forte da interface; o resto fica discreto de propósito. */

:root {
  --bg: #f2f1ed;
  --surface: #ffffff;
  --surface-raised: #fbfaf7;
  --border: #ddd9d0;
  --text: #201e1a;
  --text-dim: #6b675e;
  --accent: #a9683a;
  --accent-ink: #ffffff;
  --ok: #3f7a57;
  --ok-bg: #e7f1ea;
  --error: #a83b34;
  --error-bg: #f6e8e6;
  --radius: 10px;
  --font-ui: -apple-system, "Segoe UI", "Inter", system-ui, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f26;
    --surface-raised: #22262f;
    --border: #2a2e37;
    --text: #e8e6e1;
    --text-dim: #8a8f9c;
    --accent: #c08552;
    --accent-ink: #14161a;
    --ok: #6fa787;
    --ok-bg: #1c2b23;
    --error: #c25450;
    --error-bg: #2c1c1b;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  cursor: pointer;
}

/* ---------------- login ---------------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.login-eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 6px;
}

.login-card h1 {
  margin: 0 0 24px;
  font-size: 20px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font: inherit;
}

.field input:focus-visible {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

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

.form-error {
  min-height: 18px;
  color: var(--error);
  font-size: 13px;
  margin-top: 12px;
}

/* ---------------- app shell ---------------- */

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}

.topbar .brand {
  font-weight: 700;
}

.topbar .brand-mark {
  color: var(--accent);
}

.topbar .meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}

.topbar .spacer {
  flex: 1;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  user-select: none;
}

.btn-secondary {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 13px;
}

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

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------------- messages ---------------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  max-width: 70ch;
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  animation: fade-in 0.15s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
}

.msg-assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
}

.msg-system {
  align-self: center;
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
}

.msg-error {
  align-self: flex-start;
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid var(--error);
  font-family: var(--font-mono);
  font-size: 13px;
}

/* Lançamento de tool call — a peça de assinatura desta UI: uma linha de
   "livro-razão" (monoespaçada, barra lateral, selo ok/erro), separada
   visualmente das falas de chat. */
.ledger-entry {
  align-self: flex-start;
  max-width: 70ch;
  width: 100%;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--surface-raised);
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow: hidden;
}

.ledger-entry summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.ledger-entry summary::-webkit-details-marker {
  display: none;
}

.ledger-entry summary::before {
  content: "▸";
  color: var(--text-dim);
  transition: transform 0.1s;
}

.ledger-entry[open] summary::before {
  transform: rotate(90deg);
}

.ledger-tool {
  color: var(--accent);
  font-weight: 600;
}

.ledger-server {
  color: var(--text-dim);
}

.ledger-status {
  margin-left: auto;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.03em;
}

.ledger-status.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.ledger-status.error {
  background: var(--error-bg);
  color: var(--error);
}

.ledger-body {
  padding: 0 12px 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.ledger-body pre {
  margin: 0 0 8px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-dim);
}

.ledger-body pre:last-child {
  margin-bottom: 0;
}

.raw-json {
  align-self: stretch;
  max-width: 70ch;
}

.raw-json summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
}

.raw-json pre {
  margin-top: 6px;
  padding: 10px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  overflow-x: auto;
  max-height: 320px;
  overflow-y: auto;
}

/* ---------------- composer ---------------- */

.composer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font: inherit;
}

.composer textarea:focus-visible {
  border-color: var(--accent);
}

.composer .btn-primary {
  width: auto;
  padding: 0 20px;
}

.hint {
  color: var(--text-dim);
  font-size: 12px;
  padding: 0 20px 10px;
}

.loading-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: pulse 1s infinite ease-in-out;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .msg,
  .loading-dot {
    animation: none;
  }
}

@media (max-width: 640px) {
  .topbar .meta {
    display: none;
  }
  .msg,
  .ledger-entry {
    max-width: 100%;
  }
}
