/* Botao chat no header (partilhado) */
.chat-launch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--white);
  text-decoration: none;
  cursor: pointer;
  transition:
    background 0.2s,
    border-color 0.2s,
    color 0.2s,
    box-shadow 0.2s;
}
.chat-launch:hover {
  border-color: rgba(255, 202, 19, 0.55);
  color: var(--yellow);
  box-shadow: 0 0 0 3px rgba(255, 202, 19, 0.1);
}
.chat-launch:focus-visible {
  outline: 2px solid rgba(255, 202, 19, 0.55);
  outline-offset: 2px;
}
.chat-launch svg {
  width: 18px;
  height: 18px;
  display: block;
}
[data-theme="light"] .chat-launch {
  background: rgba(255, 255, 255, 0.85);
  border-color: rgba(0, 0, 0, 0.08);
  color: #333;
}
.chat-launch--mobile {
  display: none;
}

/* Pagina chat */
.chat-page {
  min-height: 100vh;
  padding: 5.5rem 0 2rem;
  display: flex;
  flex-direction: column;
}
.chat-shell {
  width: min(720px, calc(100% - 2rem));
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface-soft);
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.chat-head {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.chat-head-icon {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--yellow);
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-head-icon svg {
  width: 20px;
  height: 20px;
}
.chat-head h1 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}
.chat-head p {
  margin: 0.15rem 0 0;
  font-size: 0.82rem;
  color: var(--muted, #888);
}
.chat-messages {
  flex: 1;
  min-height: 420px;
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.chat-msg {
  max-width: 88%;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.45;
  animation: chatIn 0.25s ease;
}
@keyframes chatIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.chat-msg--bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.chat-msg--user {
  align-self: flex-end;
  background: rgba(255, 202, 19, 0.15);
  border: 1px solid rgba(255, 202, 19, 0.35);
  border-bottom-right-radius: 4px;
}
.chat-msg--system {
  align-self: center;
  font-size: 0.8rem;
  color: var(--muted, #888);
  padding: 0.25rem 0.5rem;
  background: transparent;
}
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.5rem;
}
.chat-chip {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s;
}
.chat-chip:hover,
.chat-chip.is-selected {
  border-color: var(--yellow);
  background: rgba(255, 202, 19, 0.12);
  color: var(--yellow);
}
.chat-download {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.65rem;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  background: var(--yellow);
  color: #111;
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  border: 0;
  cursor: pointer;
}
.chat-download:hover {
  filter: brightness(1.05);
}
.chat-download[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.chat-download--ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: inherit;
}
.chat-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.85rem;
  align-items: flex-start;
}
.chat-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  isolation: isolate;
}
.chat-modal[hidden] {
  display: none;
}
.chat-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.chat-modal-card {
  position: relative;
  z-index: 2;
  width: min(520px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
  padding: 1.35rem;
  border-radius: 16px;
  border: 1px solid rgba(255, 202, 19, 0.35);
  background: #141414;
  color: #f5f5f5;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.75);
}
[data-theme="light"] .chat-modal-card {
  background: #ffffff;
  color: #111111;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.25);
}
[data-theme="light"] .chat-modal-backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.chat-modal-card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}
.chat-modal-lead {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted, #888);
  line-height: 1.4;
}
.chat-stats-row {
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem;
  margin-bottom: 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
}
[data-theme="light"] .chat-stats-row {
  border-color: rgba(0, 0, 0, 0.1);
  background: rgba(0, 0, 0, 0.03);
}
.chat-stats-row label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted, #888);
  margin-bottom: 0.2rem;
}
.chat-stats-row select,
.chat-stats-row input[type="file"] {
  width: 100%;
  font: inherit;
  font-size: 0.88rem;
  color: inherit;
}
.chat-stats-row select {
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #0a0a0a;
  color: inherit;
}
[data-theme="light"] .chat-modal-card .chat-stats-row select {
  background: #f5f5f5;
  border-color: rgba(0, 0, 0, 0.12);
}
.chat-stats-file {
  margin: 0;
  font-size: 0.78rem;
  color: var(--accent, #ffca13);
}
body.chat-modal-open {
  overflow: hidden;
}
.chat-stats-remove {
  justify-self: start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted, #888);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}
.chat-stats-add {
  width: 100%;
  margin-bottom: 1rem;
  padding: 0.55rem;
  border-radius: 10px;
  border: 1px dashed var(--line);
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.chat-modal-actions {
  display: flex;
  gap: 0.65rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.chat-compose {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 0.65rem;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  min-height: 44px;
  max-height: 200px;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-input);
  color: var(--white);
  font: inherit;
  resize: none;
  line-height: 1.45;
  overflow-y: hidden;
}
.chat-input::placeholder {
  color: var(--muted, #888);
}
.chat-input:focus {
  outline: none;
  border-color: rgba(255, 202, 19, 0.45);
}
[data-theme="light"] .chat-input {
  background: #ffffff;
  color: #111111;
  border-color: rgba(17, 17, 17, 0.14);
}
[data-theme="light"] .chat-input::placeholder {
  color: rgba(17, 17, 17, 0.45);
}
[data-theme="light"] .chat-input:focus {
  border-color: rgba(255, 204, 0, 0.65);
  box-shadow: 0 0 0 3px rgba(255, 204, 0, 0.12);
}
.chat-send {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 0;
  background: var(--yellow);
  color: #111;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.chat-send svg {
  width: 18px;
  height: 18px;
}
.chat-typing {
  align-self: flex-start;
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  color: var(--muted, #888);
}
[data-theme="light"] .chat-shell {
  background: rgba(255, 255, 255, 0.92);
}
[data-theme="light"] .chat-msg--bot {
  background: rgba(0, 0, 0, 0.04);
}

@media (max-width: 900px) {
  .chat-launch--desktop {
    display: none;
  }
  .chat-launch--mobile {
    display: inline-flex;
  }
  .chat-messages {
    min-height: 360px;
  }
}
