@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap');

/* Tema "Aurum" — dark premium com dourado (inspirado na Central de Canais) */
:root {
  --bg: #0a0e1a;
  --bg-gradient:
    radial-gradient(1100px 560px at 50% -12%, rgba(250, 204, 21, 0.07), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(245, 158, 11, 0.05), transparent 50%),
    linear-gradient(180deg, #0a0e1a 0%, #0b1020 100%);
  --surface: #161c2e;
  --surface-2: #1e2740;
  --surface-3: #28324f;
  --surface-glass: rgba(18, 24, 40, 0.72);
  --text: #f9fafb;
  --text-muted: #99a2b8;
  --accent: #facc15;
  --accent-2: #f59e0b;
  --accent-soft: rgba(250, 204, 21, 0.13);
  --accent-text: #0a0e1a;
  --accent-gradient: linear-gradient(135deg, #fde047 0%, #facc15 50%, #f59e0b 100%);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --user-bubble: linear-gradient(135deg, #fde047 0%, #facc15 100%);
  --user-bubble-text: #0a0e1a;
  --danger: #f87171;
  --glow-gold:
    0 10px 30px -5px rgba(253, 224, 71, 0.40),
    0 4px 12px -2px rgba(234, 179, 8, 0.30),
    inset 0 1px 0 0 rgba(255, 255, 255, 0.30);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 16px 48px rgba(0, 0, 0, 0.55);
  --radius: 16px;
  --radius-sm: 12px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-head: 'Manrope', 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100dvh;
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .conv-title, strong { font-family: var(--font-head); }

button { font-family: inherit; }

.ico { width: 20px; height: 20px; flex-shrink: 0; display: block; }
.btn-send .ico { width: 19px; height: 19px; }

::selection { background: var(--accent-soft); }

/* Neutraliza o fundo claro do autofill do Chrome (mantém inputs escuros) */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--surface-2) inset;
  caret-color: var(--text);
  transition: background-color 9999s ease-out 0s;
}

/* scrollbars discretos */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Login ---------- */
.login-page {
  display: grid;
  place-items: center;
  padding: 20px;
  min-height: 100dvh;
}
.login-card {
  background: var(--surface-glass);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 36px;
  width: min(404px, 100%);
  text-align: center;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
}
.login-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 24px;
}
.login-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-sub { margin: 0 0 28px; color: var(--text-muted); font-size: 0.95rem; }
.login-field { text-align: left; margin-bottom: 16px; }
.login-field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.login-input-wrap { position: relative; display: flex; align-items: center; }
.login-input-wrap .field-icon {
  position: absolute;
  left: 15px;
  color: var(--text-muted);
  font-size: 1rem;
  pointer-events: none;
}
.login-card input {
  width: 100%;
  padding: 14px 16px 14px 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card input::placeholder { color: var(--text-muted); }
.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.login-card button {
  width: 100%;
  margin-top: 8px;
  padding: 15px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  color: var(--accent-text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--glow-gold);
  transition: transform 0.1s, filter 0.15s;
}
.login-card button:hover { filter: brightness(1.05); }
.login-card button:active { transform: scale(0.985); }
.login-error { color: var(--danger); margin-top: 16px; font-size: 0.9rem; }

/* ---------- Layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 5;
}
.topbar-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.conv-title {
  font-weight: 650;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer; /* clique para renomear */
}
.agent-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 13px 5px 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.agent-badge:hover { background: var(--surface-3); border-color: var(--accent); }
.agent-badge:active { transform: scale(0.97); }
.badge-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  background: rgba(250, 204, 21, 0.16);
  border: 1px solid rgba(250, 204, 21, 0.28);
}

.icon-btn {
  background: none;
  border: 0;
  color: var(--text);
  font-size: 1.2rem;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { background: var(--surface-3); }

/* ---------- Mensagens ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.messages > * {
  width: 100%;
  max-width: 820px;
  margin-inline: auto;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  padding: 24px 16px;
  max-width: 600px;
}
.empty-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: var(--accent-gradient);
  box-shadow: var(--glow-gold);
  color: var(--accent-text);
}
.empty-logo .ico { width: 32px; height: 32px; }
.empty-state h2 {
  color: var(--text);
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.empty-state p { margin: 0 0 26px; line-height: 1.55; font-size: 0.95rem; }
.agent-chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(154px, 1fr));
  gap: 10px;
  max-width: 540px;
  margin-inline: auto;
}
.agent-chip {
  display: flex;
  align-items: center;
  gap: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
}
.agent-chip:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  background: var(--surface-2);
}
.chip-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1rem;
  background: rgba(250, 204, 21, 0.14);
  border: 1px solid rgba(250, 204, 21, 0.26);
  flex-shrink: 0;
}

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

.msg {
  line-height: 1.6;
  overflow-wrap: break-word;
  animation: msg-in 0.18s ease-out;
}

/* Usuário — balão neutro elevado, texto claro, à direita */
.msg.user {
  align-self: flex-end;
  margin-left: auto;
  max-width: min(600px, 86%);
  padding: 12px 16px;
  background: #9ca3af;
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: #15182a;
  white-space: pre-wrap;
  border-radius: 18px;
  border-bottom-right-radius: 6px;
}

/* Assistente — avatar do agente + conteúdo fluido (estilo documento) */
.msg.assistant {
  align-self: stretch;
  display: flex;
  gap: 12px;
  max-width: 100%;
  position: relative;
}
.msg-avatar {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  background: radial-gradient(120% 120% at 30% 20%, rgba(250, 204, 21, 0.22), rgba(245, 158, 11, 0.08));
  border: 1px solid rgba(250, 204, 21, 0.28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.msg-content { flex: 1; min-width: 0; padding-top: 3px; }
.msg-body { font-size: 12px; }
.msg.error {
  align-self: center;
  margin-inline: auto;
  max-width: min(560px, 92%);
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  font-size: 0.9rem;
  text-align: center;
}
.msg-agent-tag {
  display: block;
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--accent);
  margin-bottom: 6px;
}

.routing-note {
  align-self: center;
  margin-inline: auto;
  width: fit-content;
  max-width: 92%;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 5px 14px;
  background: var(--surface-2);
  border-radius: 999px;
  animation: msg-in 0.18s ease-out;
}

/* indicador de "digitando" */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  width: fit-content;
}
.typing .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing .dot:nth-child(2) { animation-delay: 0.15s; }
.typing .dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.msg.assistant { position: relative; }
.msg.assistant pre {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  padding-top: 30px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}
.code-copy {
  position: absolute;
  top: 5px;
  right: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 7px;
  padding: 2px 9px;
  font-size: 0.72rem;
  cursor: pointer;
}
.code-copy:hover { color: var(--text); border-color: var(--accent); }
.msg-copy {
  position: absolute;
  top: 2px;
  right: 0;
  border: 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  padding: 4px;
  display: inline-flex;
}
.msg-copy .ico { width: 16px; height: 16px; }
.msg-copy:hover { color: var(--accent); }
.msg.assistant:hover .msg-copy { opacity: 0.7; }
@media (pointer: coarse) { .msg-copy { opacity: 0.45; } }
.msg.assistant code {
  background: var(--surface-2);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.86em;
}
.msg.assistant pre code { background: none; padding: 0; border: 0; }
.msg.assistant p:first-child, .msg.assistant ul:first-child, .msg.assistant ol:first-child { margin-top: 0; }
.msg.assistant p:last-child, .msg.assistant ul:last-child, .msg.assistant ol:last-child { margin-bottom: 0; }
.msg.assistant a { color: var(--accent); }
.msg.assistant blockquote {
  margin: 8px 0;
  padding: 4px 14px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
}
.msg.assistant table { border-collapse: collapse; width: 100%; font-size: 0.9em; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg.assistant th { background: var(--surface-2); }

.cursor-blink::after {
  content: '▍';
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Composer ---------- */
.composer-area {
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  max-width: 860px;
  margin-inline: auto;
  width: 100%;
}

.pending-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px 0;
}
.attach-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.8rem;
  max-width: 240px;
}
.attach-chip img {
  width: 38px;
  height: 38px;
  object-fit: cover;
  border-radius: 7px;
}
.attach-icon { font-size: 1.3rem; }
.attach-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-remove {
  border: 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px;
  border-radius: 6px;
}
.attach-remove:hover { color: var(--danger); background: var(--surface-3); }

/* anexos dentro das bolhas */
.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.msg-attachments img {
  max-width: min(260px, 100%);
  max-height: 220px;
  border-radius: var(--radius-sm);
  display: block;
  cursor: zoom-in;
}
.attach-file-chip {
  display: inline-block;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: inherit;
  text-decoration: none;
  font-size: 0.85rem;
}
.msg.assistant .attach-file-chip {
  background: var(--surface-2);
  border-color: var(--border);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 13px 18px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* evita zoom automático no iOS */
  line-height: 1.45;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn-send {
  min-width: 48px;
  min-height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--accent-text);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 6px 18px -4px rgba(250, 204, 21, 0.45);
  transition: transform 0.1s, filter 0.15s;
  display: grid;
  place-items: center;
}
.btn-send:hover:not(:disabled) { filter: brightness(1.08); }
.btn-send:active:not(:disabled) { transform: scale(0.94); }
.btn-send:disabled { opacity: 0.45; cursor: default; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(310px, 86vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.22s cubic-bezier(0.3, 0.9, 0.4, 1);
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  box-shadow: none;
}
.drawer.open { transform: translateX(0); box-shadow: var(--shadow-md); }
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 6px;
}
.drawer-header strong { font-size: 1.05rem; }

.search-wrap { position: relative; margin: 10px 12px 0; }
.search-wrap .search-ico {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 11px 14px 11px 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px; /* evita zoom automático no iOS */
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.drawer-actions {
  display: flex;
  gap: 8px;
  margin: 10px 12px;
}
.btn-new {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-new:hover { border-color: var(--accent); color: var(--accent); }
.btn-new .ico { width: 18px; height: 18px; }
.btn-new-folder { flex: 0 0 auto; padding: 12px 13px; color: var(--text-muted); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 16px;
}

.folder { margin-bottom: 2px; }
.folder summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--text-muted);
  list-style: none;
  user-select: none;
  transition: background 0.15s;
}
.folder summary::-webkit-details-marker { display: none; }
.folder summary::before {
  content: '▸';
  font-size: 0.75rem;
  transition: transform 0.15s;
}
.folder[open] summary::before { transform: rotate(90deg); }
.folder summary:hover { background: var(--surface-2); }
.folder-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder .conv-item { margin-left: 14px; }
.folder summary .conv-action { visibility: hidden; }
.folder summary:hover .conv-action { visibility: visible; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 11px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  text-align: left;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.12s;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active {
  background: var(--accent-soft);
  font-weight: 600;
}
.conv-item .conv-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-action {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 5px;
  border-radius: 7px;
  transition: background 0.12s, color 0.12s;
}
.conv-action .ico { width: 16px; height: 16px; }
.conv-action:hover { background: var(--surface-3); }
.conv-item .conv-action { visibility: hidden; }
.conv-item:hover .conv-action,
.conv-item.active .conv-action { visibility: visible; }
.conv-delete:hover { color: var(--danger); }

/* touch: sem hover — ações sempre visíveis */
@media (pointer: coarse) {
  .conv-item .conv-action,
  .folder summary .conv-action { visibility: visible; }
}

.list-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 18px 8px;
  line-height: 1.5;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 20, 0.45);
  backdrop-filter: blur(2px);
  z-index: 10;
}

/* ---------- Dialogs ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  width: min(420px, 92vw);
  padding: 22px;
  box-shadow: var(--shadow-md);
}
dialog::backdrop { background: rgba(8, 10, 20, 0.5); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 14px; font-size: 1.1rem; }

.dialog-hint {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.agent-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
  max-height: 55dvh;
  overflow-y: auto;
}
.agent-option {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.agent-option:hover { background: var(--surface-2); border-color: var(--accent); }
.agent-option.current { border-color: var(--accent); background: var(--accent-soft); }
.agent-option small { color: var(--text-muted); line-height: 1.4; }

.btn-secondary {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.12s;
}
.btn-secondary:hover { background: var(--surface-2); }

/* ---------- Memórias ---------- */
.memory-list {
  max-height: 42dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.memory-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.87rem;
}
.memory-text { flex: 1; line-height: 1.45; }
.memory-item small { color: var(--text-muted); white-space: nowrap; font-size: 0.74rem; padding-top: 2px; }
.memory-delete { visibility: visible !important; }
.memory-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 12px;
}
.memory-form textarea {
  flex: 1;
  resize: none;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.memory-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.memory-form .btn-send { min-width: 44px; min-height: 44px; }
.dialog-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  cursor: pointer;
}

/* ---------- Dialogs auxiliares ---------- */
.dialog-row { display: flex; gap: 8px; }
.btn-primary {
  flex: 1;
  padding: 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  color: var(--accent-text);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px -6px rgba(250, 204, 21, 0.4);
  transition: filter 0.15s;
}
.btn-primary:hover { filter: brightness(1.05); }
.dialog-row .btn-secondary { flex: 1; }
.context-textarea {
  width: 100%;
  resize: vertical;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  margin-bottom: 12px;
}
.context-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.agent-option.disabled { opacity: 0.45; cursor: default; }

/* ---------- Estatísticas ---------- */
.stats-summary {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.stats-summary > div {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: center;
}
.stats-summary strong { font-size: 1.05rem; }
.stats-summary small { color: var(--text-muted); font-size: 0.72rem; }
.stats-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  max-height: 32dvh;
  overflow-y: auto;
}
.stats-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.stats-row span:last-child { color: var(--text-muted); white-space: nowrap; }

/* ---------- Microfone ---------- */
.recording {
  background: color-mix(in srgb, var(--danger) 18%, transparent) !important;
  animation: mic-pulse 1.2s infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 40%, transparent); }
  50% { box-shadow: 0 0 0 7px transparent; }
}

/* ---------- Mobile ---------- */
@media (max-width: 899px) {
  /* dialogs viram bottom-sheet */
  dialog {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
    animation: sheet-in 0.22s ease-out;
  }
  @keyframes sheet-in {
    from { transform: translateY(40px); opacity: 0.4; }
    to { transform: none; opacity: 1; }
  }
  .msg { max-width: 94%; }
  .messages { padding: 14px 10px 10px; }
}

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
  .drawer {
    position: static;
    transform: none;
    flex-shrink: 0;
    box-shadow: none;
  }
  body { display: flex; }
  .app { flex: 1; }
  .overlay { display: none !important; }
  #btn-drawer { display: none; }
}
