/* ══════════════════════════════════════════════════════════════
   app.css — Chat app layout dark space
   ══════════════════════════════════════════════════════════════ */

/* ── Canvas background ── */
#canvas-app { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

/* ── Layout ── */
#app { display: flex; height: 100dvh; overflow: hidden; position: relative; z-index: 1; }

/* ══ SIDEBAR ══════════════════════════════════════════════════ */
#sidebar {
  width: 260px; flex-shrink: 0;
  background: rgba(10,7,28,.85); backdrop-filter: blur(16px);
  border-right: 1px solid rgba(255,255,255,.07);
  display: flex; flex-direction: column;
  overflow: hidden; transition: transform .25s;
  position: relative; z-index: 10;
}

.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 14px 12px; border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}

/* Logo */
.logo { display: flex; align-items: center; gap: 9px; flex: 1; }
.logo-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #7C3AED, #A78BFA);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif; font-size: 17px; font-weight: 800; color: #fff;
  box-shadow: 0 4px 12px rgba(124,58,237,.5);
}
.logo-name {
  font-family: 'Syne', sans-serif; font-size: 18px; font-weight: 800;
  background: linear-gradient(135deg, #fff, #A78BFA);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

/* Nova conversa */
.btn-new-chat {
  background: rgba(124,58,237,.2); border: 1px solid rgba(124,58,237,.35);
  color: #C4B5FD; border-radius: 8px; padding: 6px 10px;
  font-size: 0.78rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .18s;
}
.btn-new-chat:hover { background: rgba(124,58,237,.35); }

/* Section titles */
.sidebar-section-title {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted); padding: 14px 14px 6px;
}

/* Tool list */
.tool-list { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }

.tool-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: 9px; cursor: pointer; font-size: 0.85rem; color: var(--text-secondary);
  border: 1px solid transparent; transition: all .15s; background: none;
  text-align: left; width: 100%; font-family: 'Inter', sans-serif;
}
.tool-item:hover { background: rgba(255,255,255,.05); color: var(--text-primary); }
.tool-item.active {
  background: rgba(124,58,237,.15); border-color: rgba(124,58,237,.3); color: #C4B5FD;
}
.tool-item-icon { font-size: 1rem; flex-shrink: 0; }
.tool-item-name { font-weight: 500; flex: 1; }

/* Área ativa */
#area-ativa-container { padding: 0 8px; }
.area-ativa-chip {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(16,185,129,.1); border: 1px solid rgba(16,185,129,.25);
  border-radius: 9px; padding: 7px 10px; font-size: 0.8rem; color: #6EE7B7;
  cursor: pointer; font-weight: 600; transition: background .15s;
}
.area-ativa-chip:hover { background: rgba(16,185,129,.17); }

/* Conv list */
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }

.conv-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  border-radius: 9px; cursor: pointer; border: 1px solid transparent;
  transition: background .15s; color: var(--text-secondary); font-size: 0.83rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item:hover { background: rgba(255,255,255,.05); color: var(--text-primary); }
.conv-item.active { background: rgba(124,58,237,.12); border-color: rgba(124,58,237,.2); color: #C4B5FD; }
.conv-item-icon { font-size: 0.9rem; flex-shrink: 0; }

/* Sidebar footer */
.sidebar-footer {
  padding: 10px 8px; border-top: 1px solid rgba(255,255,255,.06);
  display: flex; flex-direction: column; gap: 4px; flex-shrink: 0;
}

.user-info {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: 9px; cursor: pointer; border: 1px solid transparent;
  transition: background .15s; margin-bottom: 4px;
}
.user-info:hover { background: rgba(255,255,255,.05); }

.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: rgba(124,58,237,.25); border: 1px solid rgba(124,58,237,.4);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; color: #A78BFA;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-name { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.user-plan-badge {
  font-size: 0.7rem; font-weight: 600; color: var(--accent-light);
  background: var(--accent-dim); border-radius: 99px; padding: 1px 7px;
  border: 1px solid var(--accent-border); display: inline-block; margin-top: 2px;
}

/* Sidebar footer buttons */
.sidebar-footer .btn-ghost {
  font-size: 0.8rem; padding: 7px 10px; text-align: center;
  justify-content: center; border-radius: 9px;
}

/* ══ MAIN CHAT ════════════════════════════════════════════════ */
#main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: transparent;
}

/* Chat header */
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid rgba(255,255,255,.07);
  background: rgba(10,7,28,.6); backdrop-filter: blur(10px); flex-shrink: 0;
}
.chat-header-left { display: flex; align-items: center; gap: 10px; }
#btn-menu { background: none; border: none; cursor: pointer; font-size: 1.2rem; color: var(--text-muted); display: none; }
.chat-title { font-family: 'Syne', sans-serif; font-size: 0.95rem; font-weight: 700; color: var(--text-primary); }
.chat-tool-label { font-size: 0.78rem; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: 8px; }

/* Theme toggle — mantemos mas de forma sutil */
.theme-toggle {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 0.78rem; font-weight: 500;
  color: var(--text-muted); cursor: pointer; transition: all .18s;
}
.theme-toggle:hover { background: rgba(255,255,255,.08); color: var(--text-primary); }

/* Messages container */
#messages-container {
  flex: 1; overflow-y: auto; padding: 24px 20px;
  display: flex; flex-direction: column; gap: 20px;
  scroll-behavior: smooth;
}

/* Mensagem */
.message { display: flex; gap: 12px; max-width: 820px; margin: 0 auto; width: 100%; }
.message.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}
.message.assistant .msg-avatar {
  background: linear-gradient(135deg, #7C3AED, #A78BFA); color: #fff;
}
.message.user .msg-avatar {
  background: rgba(255,255,255,.08); color: var(--text-secondary);
}

.msg-content {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 16px; font-size: 0.9rem;
  line-height: 1.65; color: var(--text-primary); max-width: calc(100% - 44px);
  backdrop-filter: blur(8px);
}
.message.user .msg-content {
  background: rgba(124,58,237,.15); border-color: rgba(124,58,237,.3);
}
.message.assistant .msg-content { border-radius: 4px 14px 14px 14px; }
.message.user      .msg-content { border-radius: 14px 4px 14px 14px; }

/* Botões de ação da mensagem */
.msg-actions {
  display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap;
}
.msg-action-btn {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px; padding: 5px 11px;
  font-size: 0.75rem; font-weight: 500; letter-spacing: .01em;
  color: rgba(200,190,255,.55); cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all .18s; white-space: nowrap;
}
.msg-action-btn:hover {
  background: rgba(124,58,237,.18);
  border-color: rgba(124,58,237,.45);
  color: #C4B5FD;
  transform: translateY(-1px);
}
.msg-action-btn:active { transform: translateY(0); }

/* Markdown dentro das mensagens */
.msg-content h1,.msg-content h2,.msg-content h3 { color:#fff; margin:12px 0 6px; }
.msg-content p  { margin-bottom: 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul,.msg-content ol { padding-left: 18px; margin-bottom: 10px; }
.msg-content li { margin-bottom: 4px; }
.msg-content code {
  background: rgba(124,58,237,.15); border: 1px solid rgba(124,58,237,.2);
  border-radius: 4px; padding: 1px 5px; font-size: 0.83em; font-family: monospace;
}
.msg-content pre {
  background: rgba(0,0,0,.3); border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px; padding: 14px; overflow-x: auto; margin: 10px 0;
}
.msg-content pre code { background: none; border: none; padding: 0; }
.msg-content strong { color: #fff; font-weight: 700; }
.msg-content blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px;
  color: var(--text-secondary); margin: 8px 0;
}
.msg-content a { color: var(--accent-light); }
.msg-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg-content table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 0.85em; }
.msg-content th { background: rgba(124,58,237,.15); padding: 8px 10px; text-align: left; font-weight: 600; }
.msg-content td { padding: 7px 10px; border-top: 1px solid rgba(255,255,255,.06); }

/* Typing indicator */
.typing-dots { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-light); animation: dot .9s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dot { 0%,80%,100% { opacity:.3; transform:scale(.8); } 40% { opacity:1; transform:scale(1.1); } }

/* Welcome state */
.welcome-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; padding: 40px 20px; text-align: center; gap: 16px;
}
.welcome-icon {
  width: 60px; height: 60px; border-radius: 18px;
  background: linear-gradient(135deg, #7C3AED, #A78BFA);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; box-shadow: 0 8px 24px rgba(124,58,237,.5);
}
.welcome-title {
  font-family: 'Syne', sans-serif; font-size: 1.4rem; font-weight: 800;
  background: linear-gradient(135deg, #fff 30%, #A78BFA);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.welcome-sub { font-size: 0.9rem; color: var(--text-muted); max-width: 340px; line-height: 1.5; }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.suggestion-chip {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 99px; padding: 8px 16px; font-size: 0.82rem; color: var(--text-secondary);
  cursor: pointer; transition: all .18s;
}
.suggestion-chip:hover { background: rgba(124,58,237,.12); border-color: rgba(124,58,237,.3); color: #C4B5FD; }

/* Input area */
.input-wrapper {
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px; padding: 10px 10px 10px 16px;
  display: flex; align-items: flex-end; gap: 8px;
  backdrop-filter: blur(8px); transition: border-color .18s;
}
.input-wrapper:focus-within { border-color: rgba(124,58,237,.45); }

#message-input {
  flex: 1; background: none; border: none; padding: 4px 0; font-size: 0.92rem;
  color: var(--text-primary); resize: none; max-height: 160px; min-height: 24px;
  line-height: 1.5; outline: none; font-family: 'Inter', sans-serif;
}
#message-input::placeholder { color: var(--text-muted); }

.input-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.input-btn {
  background: none; border: none; width: 34px; height: 34px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; cursor: pointer; color: var(--text-muted); transition: all .15s;
}
.input-btn:hover { background: rgba(255,255,255,.08); color: var(--text-primary); }

#btn-send {
  background: linear-gradient(135deg, #7C3AED, #A78BFA); color: #fff;
  border: none; width: 36px; height: 36px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; cursor: pointer; transition: filter .18s;
  box-shadow: 0 4px 12px rgba(124,58,237,.4);
}
#btn-send:hover { filter: brightness(1.1); }
#btn-send:disabled { opacity: .5; cursor: default; }

.input-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 2px 0; font-size: 0.72rem; color: var(--text-muted);
}
.usage-counter { color: var(--accent-light); font-size: 0.72rem; font-weight: 600; }

/* Recording badge */
.recording-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.3);
  border-radius: 99px; padding: 4px 12px; font-size: 0.78rem; color: #FCA5A5; font-weight: 600;
}
.recording-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #EF4444;
  animation: pulse-rec 1s infinite;
}
@keyframes pulse-rec { 0%,100% { opacity:1; } 50% { opacity:.3; } }

/* Barra de upload */
.file-preview-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 14px;
  background: rgba(124,58,237,.1); border: 1px solid rgba(124,58,237,.2);
  border-radius: 10px; font-size: 0.82rem; color: #C4B5FD; margin-bottom: 8px;
}
.file-preview-bar button {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 14px; margin-left: auto;
}

/* ── Tela vazia (welcome/ferramenta) ── */
.chat-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; min-height: 60vh; padding: 40px 20px; text-align: center; gap: 14px;
  max-width: 560px; margin: 0 auto; width: 100%;
}
.chat-empty-icon {
  font-size: 48px; margin-bottom: 4px;
  filter: drop-shadow(0 0 12px rgba(124,58,237,.5));
}
.chat-empty h2 {
  font-family: 'Syne', sans-serif; font-size: 1.5rem; font-weight: 800;
  background: linear-gradient(135deg, #fff 30%, #A78BFA);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.chat-empty p {
  font-size: 0.9rem; color: var(--text-muted); line-height: 1.6; max-width: 340px;
}
.tool-tip {
  display: inline-block; margin: 6px auto 12px;
  background: rgba(124,58,237,.1); border: 1px solid rgba(124,58,237,.25);
  border-radius: 8px; padding: 7px 14px; font-size: 0.78rem;
  color: #C4B5FD; line-height: 1.5; max-width: 460px;
}
.quick-actions {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px;
}
.quick-action {
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.1);
  border-radius: 99px; padding: 9px 18px; font-size: 0.83rem; font-weight: 500;
  color: var(--text-secondary); cursor: pointer; transition: all .18s;
  font-family: 'Inter', sans-serif;
}
.quick-action:hover {
  background: rgba(124,58,237,.15); border-color: rgba(124,58,237,.4); color: #C4B5FD;
}

/* Diagnóstico opções */
.diag-options { display: flex; flex-direction: column; gap: 8px; }
.diag-opt {
  text-align: left; padding: 12px 16px; border-radius: 9px;
  background: var(--bg-secondary); border: 2px solid var(--border);
  color: var(--text-primary); font-size: 0.875rem; font-weight: 500;
  cursor: pointer; transition: all .15s;
}
.diag-opt:hover  { border-color: rgba(124,58,237,.4); background: var(--accent-dim); }
.diag-opt.selected { border-color: var(--accent); background: var(--accent-dim); color: #C4B5FD; font-weight: 700; }

/* ══ MOBILE ════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50; transform: translateX(-100%);
    width: min(280px, 85vw);
  }
  #sidebar.open { transform: translateX(0); }
  #btn-menu { display: flex !important; }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0; z-index: 49; background: rgba(0,0,0,.5);
  }
  .sidebar-overlay.visible { display: block; }
}
