/* ============================================================
   blips-agents · chat
   Construído sobre tokens.css (design system blips-gate).
   Regras: neutros + brand yellow só em CTA, sem gradiente,
   bordas hairline, raio 8-10px, sombras mínimas.
   ============================================================ */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
}

/* ─── Topbar ───────────────────────────────────────────────── */
.topbar {
  height: 48px;
  flex: 0 0 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-logo { height: 18px; width: auto; opacity: 0.9; }
.topbar-divider { color: var(--muted-foreground); font-size: 14px; }
.topbar-title {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--muted-foreground);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* ─── Shell layout ─────────────────────────────────────────── */
.shell {
  flex: 1;
  display: grid;
  grid-template-columns: 16rem 1fr;
  min-height: 0;
}

/* ─── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  gap: 4px;
  min-height: 0;
  overflow-y: auto;
}
.side-group { padding: 4px 0; }
.side-group + .side-group { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--sidebar-border); }
.side-group-label {
  padding: 4px 8px 6px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: oklch(from var(--sidebar-foreground) l c h / 0.55);
}
.side-list { display: flex; flex-direction: column; gap: 2px; }
.side-spacer { flex: 1; }
.side-links { display: flex; flex-direction: column; gap: 4px; padding: 8px; }
.side-links a {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  text-decoration: none;
  padding: 2px 0;
}
.side-links a:hover { color: var(--foreground); }

.side-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--background);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-md);
}
.side-row-mono {
  flex: 1;
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-stats { display: flex; flex-direction: column; gap: 4px; padding: 0 8px; }
.side-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--text-xs);
}
.side-stat-row .mono { font-size: var(--text-xs); color: var(--foreground); }

/* Agent item na sidebar */
.agent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 0.12s;
  user-select: none;
}
.agent-item:hover:not(.disabled) { background: var(--sidebar-accent); }
.agent-item.active {
  background: var(--sidebar-accent);
  font-weight: 500;
}
.agent-item.active .agent-item-name { font-weight: 600; }
.agent-item.disabled { opacity: 0.45; cursor: not-allowed; }
.agent-item-body { flex: 1; min-width: 0; }
.agent-item-name {
  font-size: var(--text-sm);
  color: var(--sidebar-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.agent-item-desc {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-item-warn {
  color: var(--warning);
  font-size: 10px;
}

/* ─── Avatar com iniciais ──────────────────────────────────── */
.avatar {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--muted);
  border: 1px solid var(--border);
  color: var(--foreground);
  font-weight: 600;
  font-family: var(--font-sans);
  border-radius: 9999px;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-md { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 40px; height: 40px; font-size: 14px; }

/* ─── Main ─────────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--background);
}
.agent-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  flex: 0 0 auto;
}
.agent-header-left { display: flex; align-items: center; gap: 12px; }
.agent-name { margin: 0; }
.agent-meta {
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.meta-sep { color: var(--muted-foreground); font-size: 12px; }

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

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 320px;
}
.empty-state-title {
  font-size: var(--text-base);
  color: var(--foreground);
  font-weight: 500;
}
.empty-state-desc {
  margin-top: 4px;
  font-size: var(--text-xs);
  color: var(--muted-foreground);
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 760px;
}
.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-assistant { align-self: flex-start; }
.msg-error { align-self: flex-start; }
.msg-body {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  padding: 10px 12px;
  font-size: var(--text-sm);
  color: var(--foreground);
  word-wrap: break-word;
  min-width: 0;
}
.msg-user .msg-body {
  background: oklch(from var(--foreground) l c h / 0.04);
  border-color: oklch(from var(--foreground) l c h / 0.08);
}
.msg-error .msg-body {
  background: oklch(from var(--destructive) l c h / 0.08);
  border-color: oklch(from var(--destructive) l c h / 0.3);
  color: var(--destructive);
}
.msg-meta {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-xs);
  color: var(--muted-foreground);
}
.msg-meta a {
  color: var(--muted-foreground);
  text-decoration: none;
  border-bottom: 1px dotted var(--border);
}
.msg-meta a:hover { color: var(--foreground); border-color: var(--foreground); }

/* Markdown render dentro das bolhas */
.msg-body p { margin: 0; }
.msg-body p + p { margin-top: 6px; }
.msg-body code {
  background: var(--muted);
  border: 1px solid var(--border);
  padding: 0.05em 0.3em;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
}
.msg-body pre {
  background: var(--muted);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 6px 0;
}
.msg-body pre code { background: transparent; border: 0; padding: 0; }
.msg-body ul, .msg-body ol { padding-left: 1.25em; margin: 4px 0; }
.msg-body strong { font-weight: 600; }

/* Typing dots */
.typing { display: inline-flex; gap: 3px; padding: 4px 2px; }
.typing span {
  width: 5px; height: 5px;
  background: var(--muted-foreground);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

/* ─── Composer ─────────────────────────────────────────────── */
.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: var(--background);
  padding: 12px 24px 16px;
}
.composer-inner {
  max-width: 880px;
  margin: 0 auto;
}
.composer textarea {
  width: 100%;
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--foreground);
  resize: none;
  line-height: var(--leading-snug);
}
.composer textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px oklch(from var(--ring) l c h / 0.25);
}
.composer textarea:disabled {
  background: var(--muted);
  color: var(--muted-foreground);
  cursor: not-allowed;
}
.composer-actions {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.composer-hint { color: var(--muted-foreground); }

/* ─── Botões ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  padding: 0 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--foreground);
  white-space: nowrap;
  transition: background-color 0.12s, color 0.12s, border-color 0.12s;
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px oklch(from var(--ring) l c h / 0.4);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-xs { height: 24px; padding: 0 8px; font-size: var(--text-xs); }
.btn-sm { height: 32px; padding: 0 12px; font-size: var(--text-sm); }
.btn-icon { padding: 0; width: 28px; }
.btn-icon.btn-xs { width: 24px; height: 24px; }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) {
  background: oklch(from var(--primary) calc(l - 0.04) c h);
  border-color: oklch(from var(--primary) calc(l - 0.04) c h);
}

.btn-outline {
  background: var(--background);
  border-color: var(--border);
  color: var(--foreground);
}
.btn-outline:hover:not(:disabled) { background: var(--accent); }

.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover:not(:disabled) { background: var(--accent); }

/* ─── Status pill ──────────────────────────────────────────── */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  padding: 2px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.status-muted { color: var(--muted-foreground); }
.status-success {
  color: var(--success);
  border-color: oklch(from var(--success) l c h / 0.4);
  background: oklch(from var(--success) l c h / 0.08);
}
.status-warning {
  color: oklch(0.5 0.15 70);
  border-color: oklch(from var(--warning) l c h / 0.4);
  background: oklch(from var(--warning) l c h / 0.08);
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

/* ─── Modal ────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal-card h2 { margin: 0; }
.modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ─── Form inputs ──────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.field-label { font-size: var(--text-xs); color: var(--muted-foreground); }
.input {
  height: 36px;
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  padding: 0 10px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--foreground);
}
.input.mono { font-family: var(--font-mono); font-size: var(--text-xs); }
.input:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px oklch(from var(--ring) l c h / 0.25);
}

/* ─── Ícone genérico ───────────────────────────────────────── */
.icon { display: inline-block; flex-shrink: 0; }

/* ─── Responsivo ───────────────────────────────────────────── */
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
