/* ====== Design tokens ====== */
:root {
  --bg: #0b0c10;
  --bg-elev: #15171d;
  --bg-input: #1f222a;
  --border: #2a2e38;
  --border-strong: #3a3f4d;
  --text: #e7e9ee;
  --text-dim: #9aa0ad;
  --text-faint: #6c7280;
  --accent: #8b5cf6;      /* roxo — neutro, profissional, não cara de imobiliária */
  --accent-hover: #7c3aed;
  --success: #22c55e;
  --warn: #f59e0b;
  --error: #ef4444;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.view { min-height: 100vh; display: flex; flex-direction: column; }

/* ====== Auth cards (setup + login) ====== */

#view-setup, #view-login {
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}
/* Fundo com gradiente sutil + blobs roxos pra dar profundidade */
#view-setup::before, #view-login::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(800px 400px at 15% 20%, rgba(139, 92, 246, 0.12), transparent 60%),
    radial-gradient(700px 500px at 85% 80%, rgba(124, 58, 237, 0.10), transparent 60%);
  pointer-events: none;
  z-index: 0;
}
#view-setup .auth-card, #view-login .auth-card {
  position: relative;
  z-index: 1;
  animation: card-in 0.5s ease-out;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.brand-row h1 {
  font-size: 22px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-emoji { font-size: 28px; line-height: 1; }
.brand-sep { color: var(--text-faint); margin: 0 4px; }

.lead {
  color: var(--text-dim);
  font-size: 14px;
  margin: 0 0 24px;
}
.lead strong { color: var(--text); font-weight: 600; }

.badge-pill {
  display: inline-block;
  background: rgba(139, 92, 246, 0.15);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 16px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
}

input[type="text"],
input[type="email"],
input[type="password"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.15s;
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

.hint {
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 400;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 4px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.error-msg {
  color: var(--error);
  font-size: 13px;
  margin: 0;
  min-height: 18px;
}

/* ====== Office (escritório) ====== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}

.topbar .brand-row { margin: 0; }
.topbar strong { font-weight: 600; font-size: 15px; }
.topbar-right { display: flex; gap: 8px; }

.office {
  flex: 1;
  padding: 32px 24px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.office-header {
  margin-bottom: 32px;
}
.office-header h2 {
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.muted { color: var(--text-dim); font-size: 14px; margin: 0; }

.office-zone {
  margin-bottom: 32px;
}
.office-zone-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 600;
  margin-bottom: 12px;
  padding: 0 4px;
}
.office-zone-orchestrator #orchestrator-slot {
  display: grid;
  grid-template-columns: minmax(0, 480px);
  gap: 16px;
}
.office-zone-team .agents-grid {
  /* mesma grid, mas separada visualmente da do orq */
}

.link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.link:hover { color: var(--accent-hover); }

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

/* Fade-in escalonado dos cards na entrada do escritório */
.agent-card {
  opacity: 0;
  animation: card-in 0.34s ease-out forwards;
}
.agent-card:nth-child(1) { animation-delay: 0.02s; }
.agent-card:nth-child(2) { animation-delay: 0.08s; }
.agent-card:nth-child(3) { animation-delay: 0.14s; }
.agent-card:nth-child(4) { animation-delay: 0.20s; }
.agent-card:nth-child(5) { animation-delay: 0.26s; }
.agent-card:nth-child(6) { animation-delay: 0.32s; }
.agent-card:nth-child(n+7) { animation-delay: 0.38s; }

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

.agent-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.agent-card-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-faint);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}
.agent-card:hover .agent-card-edit {
  opacity: 1;
}
.agent-card-edit:hover {
  color: var(--accent);
  border-color: var(--border);
}
.agent-tasks-badge {
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: 999px;
  align-self: flex-start;
  margin-top: 2px;
}

.agent-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.agent-card.orchestrator {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.08) 0%, var(--bg-elev) 100%);
}

.agent-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agent-avatar {
  font-size: 32px;
  line-height: 1;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-input);
  overflow: hidden;
  flex-shrink: 0;
  transition: transform 0.4s ease, box-shadow 0.4s ease;
}
.agent-avatar .avatar-img {
  width: 100%;
  height: 100%;
  display: block;
}

/* Avatar nas topbars (chat e task) é menor e em formato circular */
.brand-row .brand-emoji,
#chat-avatar,
#task-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-input);
  flex-shrink: 0;
  font-size: 20px;
}
#chat-avatar .avatar-img,
#task-avatar .avatar-img,
.brand-row .brand-emoji .avatar-img {
  width: 100%;
  height: 100%;
}

/* Animação "trabalhando": card respira sutilmente */
.agent-card[data-status="working"] {
  border-color: var(--success);
  animation: card-breathe 2.6s ease-in-out infinite;
}
.agent-card[data-status="working"] .agent-avatar {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25), 0 0 20px rgba(34, 197, 94, 0.18);
}
@keyframes card-breathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

.agent-name {
  font-weight: 600;
  font-size: 15px;
}

.agent-role-badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  font-weight: 600;
}

.agent-description {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.45;
}

.agent-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 4px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}
.status-dot.idle { background: var(--text-faint); }
.status-dot.working {
  background: var(--success);
  animation: pulse 1.4s ease-in-out infinite;
}
.status-dot.waiting_user { background: var(--warn); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.3); }
}

/* ====== Workspace picker (topbar do escritório) ====== */

.workspace-picker, .mission-picker {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mission-picker .select { min-width: 200px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.muted-label {
  font-size: 12px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  min-width: 180px;
  cursor: pointer;
}
.select:focus { outline: none; border-color: var(--accent); }

/* ====== Office empty state ====== */

.office-empty {
  text-align: center;
  padding: 60px 24px 40px;
  max-width: 580px;
  margin: 0 auto;
}
.empty-illustration {
  width: 200px;
  height: 140px;
  margin-bottom: 12px;
}
.office-empty .empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
}
.office-empty h2 {
  margin: 0 0 12px;
  font-size: 22px;
  font-weight: 600;
}
.office-empty p {
  margin: 0 0 28px;
  font-size: 14.5px;
  line-height: 1.55;
}
.office-empty code {
  background: var(--bg-input);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* ====== Modal genérico ====== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-box.modal-wide { max-width: 640px; }
.modal-box textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  line-height: 1.5;
  resize: vertical;
  min-height: 120px;
}
.modal-box textarea:focus { outline: none; border-color: var(--accent); }
.modal-box h2 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* Workspace indicator na topbar do chat */
.chat-workspace {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 400;
}

/* ====== Settings view ====== */

.settings {
  flex: 1;
  padding: 32px 24px;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.settings-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.settings-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
}
.settings-card > p { margin: 0 0 18px; font-size: 14px; }
.settings-card .modal-actions { margin-top: 12px; }

/* ====== Toggle Grid/Sala ====== */

.view-toggle {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.vt-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
  transition: all 0.15s;
}
.vt-btn:hover { color: var(--text); }
.vt-btn.active {
  background: var(--bg-elev);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* ====== Sala (canvas) ====== */

#room-stage {
  position: relative;
  width: 100%;
  /* Mantém uma altura confortável que escala com o viewport */
  height: min(720px, calc(100vh - 240px));
  min-height: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
#room-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
}
.room-tooltip {
  position: absolute;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  pointer-events: none;
  max-width: 240px;
  box-shadow: var(--shadow);
  z-index: 10;
  transition: opacity 0.1s;
}
.room-tooltip .name { font-weight: 600; margin-bottom: 2px; }
.room-tooltip .role { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; }
.room-tooltip .desc { color: var(--text-dim); margin-top: 4px; font-size: 11.5px; line-height: 1.45; }
.room-tooltip .status {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 6px; font-size: 11px;
}

@media (max-width: 640px) {
  #room-stage { height: min(560px, calc(100vh - 200px)); }
}

/* ====== Search modal ====== */

.search-box {
  padding: 0;
  overflow: hidden;
}
.search-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.search-icon { font-size: 18px; }
#search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  padding: 0;
}
kbd {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  color: var(--text-dim);
}
.search-results {
  max-height: 60vh;
  overflow-y: auto;
}
.search-hit {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.search-hit:last-child { border-bottom: none; }
.search-hit:hover { background: var(--bg-input); }
.search-hit-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.search-hit-head .badge {
  background: var(--bg-input);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10.5px;
  color: var(--text-dim);
}
.search-hit-snippet {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
}
.search-hit-snippet mark {
  background: rgba(139, 92, 246, 0.35);
  color: var(--text);
  border-radius: 2px;
  padding: 0 2px;
}

.suggest-box {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}
.suggest-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
}
.suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover { background: var(--bg-elev); }
.suggest-item .icon { font-size: 18px; }
.suggest-item .info { flex: 1; min-width: 0; }
.suggest-item .name { font-weight: 600; }
.suggest-item .path {
  color: var(--text-faint);
  font-family: ui-monospace, monospace;
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.suggest-item .hint-tag {
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.template-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}
@media (max-width: 640px) { .template-list { grid-template-columns: 1fr; } }
.template-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.template-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.template-card-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 4px;
}
.template-card-head .icon { font-size: 22px; }
.template-card-head .name { font-weight: 600; font-size: 15px; }
.template-card-desc {
  font-size: 12.5px; color: var(--text-dim); margin-bottom: 8px;
}
.template-card-agents {
  font-size: 11.5px; color: var(--text-faint);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.status-cell {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.status-cell-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 600;
}
.status-cell-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ====== Task transcript view ====== */

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.status-pill.idle { background: rgba(108, 114, 128, 0.15); color: var(--text-faint); }
.status-pill.working { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.status-pill.done { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.status-pill.failed { background: rgba(239, 68, 68, 0.15); color: var(--error); }
.status-pill.working::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 6px;
  animation: pulse 1.4s ease-in-out infinite;
}

.task-instruction {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 24px 0;
  font-size: 13px;
  color: var(--text-dim);
}
.task-instruction strong {
  color: var(--text);
  font-weight: 600;
}
.task-instruction .label {
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-right: 8px;
}

.task-summary {
  max-width: 900px;
  width: 100%;
  margin: 0 auto 16px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: var(--radius);
}
.task-summary h3 {
  margin: 0 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 600;
}

/* ====== Chat view ====== */

#view-chat { background: var(--bg); }

.metrics {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-dim);
}
.metric { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.metric-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); }
.metric span:last-child { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

#chat-back { padding: 4px 10px; font-size: 16px; line-height: 1; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.msg {
  max-width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 14.5px;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.user {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  align-self: flex-end;
  max-width: 75%;
}

.msg.assistant {
  background: transparent;
  padding: 4px 0;
}

.msg .role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 4px;
  font-weight: 600;
}

.msg.thinking-block {
  color: var(--text-dim);
  font-style: italic;
  border-left: 2px solid var(--border);
  padding-left: 12px;
}

/* Markdown bodies — flip from white-space:pre-wrap to normal so <p>/<pre>/<ul>
   render correctly. */
.body.markdown { white-space: normal; }
.body.markdown > *:first-child { margin-top: 0; }
.body.markdown > *:last-child { margin-bottom: 0; }
.body.markdown p { margin: 0 0 8px; }
.body.markdown ul, .body.markdown ol { margin: 0 0 8px; padding-left: 22px; }
.body.markdown li { margin: 2px 0; }
.body.markdown li > p { margin: 0; }
.body.markdown h1, .body.markdown h2, .body.markdown h3, .body.markdown h4 {
  margin: 12px 0 6px;
  line-height: 1.3;
  font-weight: 600;
}
.body.markdown h1 { font-size: 1.3em; }
.body.markdown h2 { font-size: 1.15em; }
.body.markdown h3 { font-size: 1.05em; }
.body.markdown code {
  background: var(--bg-input);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
}
.body.markdown pre {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.45;
}
.body.markdown pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}
.body.markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Tool calls + results (collapsible) */

details.tool-call, details.tool-result {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
}
details.tool-call summary, details.tool-result summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
details.tool-call summary::-webkit-details-marker,
details.tool-result summary::-webkit-details-marker { display: none; }
.tool-name { font-weight: 600; color: var(--text); }
.tool-summary, .tool-result .preview {
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
details.tool-call pre, details.tool-result pre {
  margin: 8px 0 4px;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg-input);
  border-radius: 4px;
  padding: 8px;
  max-height: 320px;
  overflow-y: auto;
}
details.tool-result.error { border-color: var(--error); }

/* Task notifications (custom event types from delegar_tarefa) */
.task-event {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-size: 13px;
}
.task-event.started { border-left: 3px solid var(--warn); }
.task-event.finished { border-left: 3px solid var(--success); }
.task-event-icon { font-size: 18px; line-height: 1; }
.task-event-body { flex: 1; }
.task-event-title { font-weight: 600; color: var(--text); margin-bottom: 2px; }
.task-event-detail { color: var(--text-dim); font-size: 12px; }
.task-event-meta { color: var(--text-faint); font-size: 11px; margin-top: 4px; font-variant-numeric: tabular-nums; }

.error-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* Composer */

.chat-composer {
  display: flex;
  gap: 8px;
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

#chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  min-height: 44px;
  max-height: 200px;
  transition: border-color 0.15s;
}
#chat-input:focus { outline: none; border-color: var(--accent); }
#chat-send.stopping { background: var(--error); }
#chat-send.stopping:hover { background: #dc2626; }

/* ====== Responsive ====== */

@media (max-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
  }
  .topbar-right {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px 12px;
    justify-content: flex-start;
  }
  .workspace-picker, .mission-picker {
    flex: 1 1 auto;
    min-width: 0;
  }
  .workspace-picker .select, .mission-picker .select {
    min-width: 0;
    flex: 1;
  }
  .muted-label { display: none; }
}

@media (max-width: 640px) {
  .auth-card { padding: 24px; }
  .office { padding: 20px 16px; }
  .agents-grid { grid-template-columns: 1fr; }
  .office-zone-orchestrator #orchestrator-slot { grid-template-columns: 1fr; }
  .chat-messages { padding: 16px; }
  .chat-composer { padding: 10px 16px 14px; }
  .metrics { gap: 10px; }
  .metric-label { font-size: 9px; }
  .empty-illustration { width: 160px; height: 110px; }
  .office-empty h2 { font-size: 18px; }
}
