:root {
  --bg: #0a0a0f;
  --surface-1: #14141b;
  --surface-2: #1c1c26;
  --surface-3: #23232f;
  --border: #2a2a38;
  --accent: #f59e0b;
  --accent-dim: #7c5215;
  --accent-soft: rgba(245, 158, 11, 0.14);
  --text: #f5f5f7;
  --text-muted: #8b8b96;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --success: #22c55e;
  --font-ui: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', ui-monospace, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font-ui); background: var(--bg); color: var(--text); display: flex; }

.barra-lateral { width: 260px; flex-shrink: 0; background: var(--surface-1); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 0.8rem; gap: 0.8rem; }
.btn-novo-chat { padding: 0.7rem; background: var(--accent); color: #1a1206; border: none; border-radius: 10px; font-weight: 600; cursor: pointer; font-size: 0.9rem; font-family: var(--font-ui); transition: 0.15s; }
.btn-novo-chat:active { transform: scale(0.97); }
.lateral-lista { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.4rem; }
.lista-vazia { text-align: center; padding: 1.5rem 0.5rem; color: var(--text-muted); font-size: 0.8rem; }
.item-conversa { padding: 0.55rem 0.4rem 0.55rem 0.7rem; border-radius: 8px; cursor: pointer; font-size: 0.85rem; display: flex; align-items: center; justify-content: space-between; gap: 0.3rem; transition: background 0.1s; }
.item-conversa-titulo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.item-conversa-opcoes { flex-shrink: 0; background: transparent; border: none; color: var(--text-dim, currentColor); opacity: 0; width: 24px; height: 24px; border-radius: 6px; cursor: pointer; font-size: 1rem; line-height: 1; }
.item-conversa:hover .item-conversa-opcoes, .item-conversa.ativa .item-conversa-opcoes { opacity: 0.75; }
.item-conversa-opcoes:hover { opacity: 1 !important; background: var(--surface-1); }
@media (pointer: coarse) {
  .item-conversa-opcoes { opacity: 0.6; }
}
.item-conversa:hover { background: var(--surface-2); }
.item-conversa.ativa { background: var(--accent-soft); color: var(--accent); }
.lateral-base { display: flex; flex-direction: column; gap: 0.35rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.aba-lateral { padding: 0.5rem 0.7rem; background: transparent; border: none; border-radius: 8px; color: var(--text-muted); cursor: pointer; font-size: 0.85rem; text-align: left; font-family: var(--font-ui); transition: background 0.1s; }
.aba-lateral.ativa, .aba-lateral:hover { background: var(--accent-soft); color: var(--accent); }

.area-principal { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.cabecalho { flex-shrink: 0; padding: 0.9rem 1rem 0.7rem; border-bottom: 1px solid var(--border); }
.marca { display: flex; align-items: center; gap: 0.6rem; }
.marca-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); box-shadow: 0 0 0 3px transparent; transition: all 0.2s; flex-shrink: 0; }
.marca-dot.ok { background: var(--success); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }
.marca h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
#status-texto { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted); margin-top: 0.1rem; }
.paineis-wrap { flex: 1; min-height: 0; position: relative; }
.painel { display: none; height: 100%; flex-direction: column; }
.painel.visivel { display: flex; }

.mensagens { flex: 1; min-height: 0; overflow-y: auto; padding: 1rem 0.9rem; display: flex; flex-direction: column; gap: 0.7rem; -webkit-overflow-scrolling: touch; }
.vazio { margin: auto; text-align: center; color: var(--text-muted); padding: 2rem 1.2rem; }
.vazio-icone { font-size: 2rem; display: block; margin-bottom: 0.6rem; opacity: 0.7; }
.msg { max-width: 86%; padding: 0.7rem 0.9rem; border-radius: 14px; line-height: 1.5; font-size: 0.95rem; animation: subir 0.18s ease-out; }
@keyframes subir { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.msg.user { align-self: flex-end; background: var(--accent-soft); border: 1px solid var(--accent-dim); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.erro { align-self: center; background: var(--danger-soft); border: 1px solid rgba(239, 68, 68, 0.35); color: #fca5a5; font-size: 0.85rem; max-width: 95%; white-space: pre-wrap; font-family: var(--font-mono); }
.msg-imagem-anexa { max-width: 160px; border-radius: 8px; margin-bottom: 0.5rem; display: block; }
.msg-imagem-gerada { max-width: 100%; width: 320px; border-radius: 10px; display: block; margin-bottom: 0.5rem; }
.msg-imagem-legenda { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.5rem !important; }
.btn-baixar-imagem { background: var(--surface-3); border: 1px solid var(--border); color: var(--text); padding: 0.35rem 0.7rem; border-radius: 6px; font-size: 0.8rem; cursor: pointer; font-family: var(--font-ui); }
.btn-baixar-imagem:hover { border-color: var(--accent-dim); }
.msg-tag { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-muted); margin-top: 0.4rem; opacity: 0.8; }
.msg p { margin-bottom: 0.55rem; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0.3rem 0 0.5rem 1.1rem; }
.msg h1, .msg h2, .msg h3 { color: var(--accent); margin: 0.6rem 0 0.3rem; font-size: 1.02em; }
.msg code { background: var(--surface-3); padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.85em; font-family: var(--font-mono); color: #7dd3fc; }
.msg pre { position: relative; margin: 0.5rem 0; border-radius: 8px; overflow-x: auto; }
.msg pre code { background: none; padding: 0.9rem; display: block; font-family: var(--font-mono); }
.btn-copiar-bloco {
  position: sticky;
  float: right;
  top: 0.4rem;
  margin-left: 0.4rem;
  z-index: 2;
  padding: 0.25rem 0.55rem;
  font-size: 0.7rem;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
}
.btn-copiar-bloco:hover { background: var(--surface-2); }

.digitando { align-self: flex-start; display: flex; gap: 0.3rem; padding: 0.75rem 1rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; border-bottom-left-radius: 4px; }
.digitando span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: pulso 1.1s infinite ease-in-out; }
.digitando span:nth-child(2) { animation-delay: 0.15s; }
.digitando span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulso { 0%,60%,100% { opacity: 0.3; transform: scale(0.8); } 30% { opacity: 1; transform: scale(1); } }

.composer { flex-shrink: 0; border-top: 1px solid var(--border); background: var(--bg); padding: 0.7rem 0.8rem calc(0.7rem + env(safe-area-inset-bottom)); }
.composer-linha { display: flex; align-items: flex-end; gap: 0.5rem; }
textarea, input[type="text"], input[type="password"] { font-family: var(--font-ui); background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; color: var(--text); font-size: 0.95rem; outline: none; padding: 0.7rem 0.85rem; transition: border-color 0.15s; }
textarea:focus, input:focus { border-color: var(--accent-dim); }
.composer-linha textarea { flex: 1; resize: none; max-height: 120px; line-height: 1.4; }
.btn-anexo, .btn-enviar, .btn-icone, .btn-texto { border: none; cursor: pointer; transition: all 0.15s; font-family: var(--font-ui); }
.btn-anexo { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); border-radius: 10px; font-size: 1.1rem; }
.btn-anexo:hover { background: var(--surface-3); }
.btn-enviar { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; background: var(--accent); color: #1a1206; border-radius: 10px; font-weight: 600; }
.btn-enviar:disabled { opacity: 0.5; cursor: not-allowed; }
.composer-rodape { margin-top: 0.4rem; display: flex; gap: 0.8rem; }
.btn-texto { background: transparent; color: var(--text-muted); font-size: 0.8rem; padding: 0.3rem 0.5rem; border-radius: 6px; }
.btn-texto:hover { background: var(--surface-2); color: var(--text); }
.anexo-preview { margin-bottom: 0.5rem; display: flex; gap: 0.5rem; }
.anexo-item { position: relative; border-radius: 8px; overflow: hidden; }
.anexo-item img { max-width: 100px; max-height: 100px; display: block; }
.anexo-remover { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,0.7); color: white; border: none; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; font-size: 0.8rem; display: flex; align-items: center; justify-content: center; }

.config-caixa { max-width: 500px; margin: 2rem auto; padding: 1.5rem; }
.config-caixa h2 { margin-bottom: 0.8rem; color: var(--accent); font-size: 1.1rem; }
.config-desc { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1.2rem; line-height: 1.5; }
.campo-chave { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.campo-chave input { flex: 1; }
.btn-icone { padding: 0 0.8rem; background: var(--surface-2); color: var(--text); border-radius: 10px; font-size: 1rem; }
.config-botoes { display: flex; gap: 0.7rem; margin-bottom: 0.8rem; }
.config-botoes button { padding: 0.6rem 1.2rem; border: none; border-radius: 10px; font-weight: 500; cursor: pointer; background: var(--accent); color: #1a1206; transition: 0.15s; }
.config-botoes .btn-secundario { background: var(--surface-2); color: var(--text); }
.config-status { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; }
.divisor { border: none; height: 1px; background: var(--border); margin: 1.5rem 0; }
.lista-modelos { list-style: none; font-size: 0.85rem; color: var(--text-muted); line-height: 1.6; }
.lista-modelos b { color: var(--accent); }

.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; padding: 1rem; }
.galeria-item { background: var(--surface-2); border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.galeria-item img { width: 100%; height: 180px; object-fit: cover; display: block; }
.galeria-legenda { padding: 0.7rem; font-size: 0.8rem; color: var(--text-muted); }
.galeria-acoes { display: flex; gap: 0.5rem; padding: 0 0.7rem 0.7rem; }
.galeria-acoes button { flex: 1; padding: 0.4rem; font-size: 0.75rem; border: none; border-radius: 6px; background: var(--surface-3); color: var(--text); cursor: pointer; }
.galeria-carregando { text-align: center; padding: 2rem; color: var(--text-muted); font-size: 0.9rem; }

.menu-contexto { position: fixed; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0; min-width: 180px; z-index: 9999; box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.menu-contexto button { display: block; width: 100%; text-align: left; padding: 0.5rem 0.9rem; background: transparent; border: none; color: var(--text); font-size: 0.85rem; cursor: pointer; transition: background 0.1s; }
.menu-contexto button:hover { background: var(--surface-2); }
.menu-contexto .botao-perigo { color: var(--danger); }
.menu-contexto hr { border: none; height: 1px; background: var(--border); margin: 0.4rem 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px); opacity: 0; background: var(--surface-1); border: 1px solid var(--border); padding: 0.8rem 1.2rem; border-radius: 10px; color: var(--text); font-size: 0.9rem; z-index: 9999; transition: all 0.25s; }
.toast.mostrar { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.erro { border-color: var(--danger); background: var(--danger-soft); color: #fca5a5; }

@media (max-width: 768px) {
  .barra-lateral { position: fixed; left: -260px; top: 0; bottom: 0; z-index: 999; transition: left 0.2s; }
  .barra-lateral.aberto { left: 0; }
  .galeria { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
