:root {
  --bg: #070a13;
  --panel: #0d1222;
  --bot: #131b31;
  --user: #059669;
  --user-hover: #047857;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --border: #1f2b48;
  --danger: #ef4444;
  --agent: #10b981;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 18, 34, 0.85);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 { margin: 0 0 2px; font-size: 18px; color: #6ee7b7; }
.header p { margin: 0; color: var(--muted); font-size: 13px; max-width: 650px; }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge-private {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  font-weight: 600;
}

.btn-secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
  transition: all 0.2s;
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

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

.msg {
  display: flex;
  width: 100%;
  min-width: 0;
}
.msg.user { justify-content: flex-end; }
.msg.bot { justify-content: flex-start; }

.bubble {
  max-width: 90%;
  min-width: 0;
  padding: 14px 18px;
  border-radius: 14px;
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg.bot .bubble { background: var(--bot); border: 1px solid var(--border); }
.msg.user .bubble { background: var(--user); color: #fff; }

/* Markdown dentro da bolha */
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 14px 0 8px;
  font-size: 1.1em;
  color: #fff;
}
.bubble ul, .bubble ol { margin: 6px 0 10px; padding-left: 22px; }
.bubble li { margin: 4px 0; }
.bubble strong { font-weight: 600; color: #fff; }
.bubble em { color: #cbd5e1; }
.bubble blockquote {
  border-left: 3px solid var(--agent);
  margin: 8px 0;
  padding: 4px 12px;
  background: rgba(16, 185, 129, 0.08);
  color: #cbd5e1;
}

/* Blocos de Código e Tags Inline sem Estourar */
.bubble code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.bubble pre {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
  max-width: 100%;
}

.bubble pre code {
  background: none;
  padding: 0;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

/* Tabelas */
.table-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  margin: 14px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
}

.bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  text-align: left;
  min-width: 450px;
}

.bubble th,
.bubble td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: top;
}

.bubble th:last-child,
.bubble td:last-child {
  border-right: none;
}

.bubble tr:last-child td {
  border-bottom: none;
}

.bubble th {
  background: rgba(255, 255, 255, 0.07);
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

/* Fontes */
.sources {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.sources strong { color: var(--muted); font-weight: 600; }
.sources a, .sources span.source-item {
  color: #6ee7b7;
  display: block;
  margin-top: 5px;
  text-decoration: none;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.typing { color: var(--muted); font-style: italic; }

/* Composer / Caixa de Envio */
.composer-container {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  border-top: 1px solid var(--border);
  background: rgba(13, 18, 34, 0.85);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.attachment-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 24px 0;
  font-size: 13px;
  color: #6ee7b7;
}

.attachment-name {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 2px 10px;
  border-radius: 6px;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-remove-attachment {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
}
.btn-remove-attachment:hover { color: var(--danger); }

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 24px 16px;
  align-items: center;
}

.btn-icon {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--agent);
}

.btn-icon.recording {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--danger);
  animation: pulse-mic 1s infinite;
}

@keyframes pulse-mic {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.composer input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
}
.composer input[type="text"]:focus { outline: none; border-color: var(--agent); }

.composer button[type="submit"] {
  padding: 0 22px;
  height: 44px;
  border-radius: 10px;
  border: none;
  background: var(--user);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.composer button[type="submit"]:hover { background: var(--user-hover); }
.composer button[type="submit"]:disabled { opacity: 0.5; cursor: not-allowed; }

.hidden { display: none !important; }
