/* HealthQuery — overrides do design system td-agent-screen
   Mudanças que NÃO devem voltar pro design system original. */

/* -- Brand dot fixo em laranja (independente do tema) --
   O design system define .hq-brand__dot { background: var(--accent) },
   mas o accent vira preto em light. O dot é cor de marca, deve ser
   sempre laranja. */
.hq-brand__dot {
  background: #FF6B35 !important;
}

/* -- Segmented de idioma com bandeiras SVG -- */
.hq-lang-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: 9999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.hq-lang-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 9999px;
  transition: opacity 120ms ease, background 120ms ease, transform 120ms ease;
  opacity: 0.55;
  border: 1px solid transparent;
}

.hq-lang-chip:hover {
  opacity: 0.9;
  background: var(--bg-hover);
}

.hq-lang-chip.is-active {
  opacity: 1;
  background: var(--accent);
  border-color: var(--accent);
}

.hq-lang-chip svg {
  display: block;
  width: 20px;
  height: 14px;
  border-radius: 2px;
  /* Sombra discreta pra dar contorno sem precisar de border */
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

/* ------- Tela Chat ------- */

/* Bubble do usuário */
.msg-user {
  align-self: flex-end;
  max-width: 80%;
  background: var(--accent);
  color: var(--accent-on);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
}

/* Bubble do agente */
.msg-agent {
  align-self: flex-start;
  max-width: 92%;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 16px 16px 16px 4px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.55;
}

.msg-agent .agent-main { white-space: pre-wrap; }

.msg-agent details {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.msg-agent details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  user-select: none;
  list-style: none;
}
.msg-agent details summary::-webkit-details-marker { display: none; }
.msg-agent details summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transition: transform 120ms ease;
}
.msg-agent details[open] summary::before { transform: rotate(90deg); }
.msg-agent details pre {
  margin-top: 8px;
  padding: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  color: var(--text-primary);
}

.msg-agent .agent-reasoning {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.msg-agent .thinking-dots::after {
  content: "";
  display: inline-block;
  width: 1ch;
  animation: hq-dots 1.4s steps(4, end) infinite;
}
@keyframes hq-dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
}

/* Cards de sugestão clicáveis */
.suggestion-card {
  padding: 14px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-surface);
  transition: all 150ms ease;
}
.suggestion-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-1px);
}

/* Cor da progress bar em 3 níveis */
.hq-progress__fill[data-level="ok"]    { background: #16a34a; }
.hq-progress__fill[data-level="warn"]  { background: #d97706; }
.hq-progress__fill[data-level="alert"] { background: #dc2626; }

/* Textarea expansível leve */
textarea.hq-input { min-height: 44px; max-height: 160px; }

/* Avoid scroll cobrir input no mobile (tab bar fixa no rodapé) */
@media (max-width: 768px) {
  .msg-user, .msg-agent { font-size: 14px; }
}

/* ------- Markdown inline dentro do bubble do agente ------- */
.msg-agent strong {
  font-weight: 600;
  color: var(--text-primary);
}

.msg-agent code {
  font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.msg-agent hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

.msg-agent .agent-reasoning code {
  font-size: 11.5px;
}

/* ------- Chips de sugestão (renderizados após bubble do agente) ------- */
.suggestion-chips {
  align-self: flex-start;
  max-width: 92%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -4px 0 4px 0;
  padding-left: 2px;
}

.suggestion-chip {
  display: inline-block;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 9999px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  max-width: 100%;
  transition: all 120ms ease;
  font-family: inherit;
}

.suggestion-chip:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* ------- Tabela markdown dentro do bubble do agente ------- */
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 8px 0;
  overflow-x: auto;
  display: block;
}

.md-table th,
.md-table td {
  padding: 6px 10px;
  border: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.md-table th {
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-primary);
}

.md-table tr:hover td {
  background: var(--bg-hover);
}

/* ------- Tela Logs ------- */

.log-th {
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.log-td {
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-primary);
  vertical-align: middle;
}

.log-row {
  transition: background 100ms ease;
}
.log-row:hover {
  background: var(--bg-hover);
}

.log-expand-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-muted);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 120ms ease;
}
.log-expand-btn:hover { color: var(--text-primary); }

.log-chevron {
  display: block;
  transition: transform 200ms ease;
}

.log-detail-td {
  padding: 0 12px 14px 12px;
  background: var(--bg-elevated);
}

.log-detail-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.log-sql {
  padding: 10px 12px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  color: var(--text-primary);
  margin: 0;
  white-space: pre;
}

/* Intent badges — modificadores de cor */
.hq-badge--data-query            { background: var(--badge-data-bg);   color: var(--badge-data-text); }
.hq-badge--write-attempt         { background: var(--badge-write-bg);  color: var(--badge-write-text); }
.hq-badge--out-of-scope          { background: var(--badge-scope-bg);  color: var(--badge-scope-text); }
.hq-badge--greeting              { background: var(--badge-greet-bg);  color: var(--badge-greet-text); }
.hq-badge--clarification-needed  { background: var(--badge-clar-bg);   color: var(--badge-clar-text); }
.hq-badge--report-request        { background: var(--badge-report-bg); color: var(--badge-report-text); }

/* ------- Tela Docs ------- */
.docs-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
}

.docs-summary {
  padding: 14px 18px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  user-select: none;
}

.docs-summary::-webkit-details-marker { display: none; }

.docs-summary::before {
  content: "▶";
  font-size: 10px;
  color: var(--text-secondary);
  transition: transform 0.2s;
  flex-shrink: 0;
}

details[open] > .docs-summary::before {
  transform: rotate(90deg);
}

.docs-body {
  padding: 18px;
  background: var(--bg-page);
  border-top: 1px solid var(--border);
}

.docs-sub-heading {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.docs-list {
  padding-left: 0;
  list-style: none;
}

.docs-list--ordered {
  counter-reset: docs-counter;
}

.docs-list li {
  padding: 6px 0 6px 28px;
  position: relative;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.docs-list li:last-child { border-bottom: none; }

.docs-list--ordered li::before {
  counter-increment: docs-counter;
  content: counter(docs-counter);
  position: absolute;
  left: 0;
  top: 6px;
  width: 20px;
  height: 20px;
  background: var(--bg-elevated);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.docs-table-wrap {
  overflow-x: auto;
}

.docs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.docs-table th {
  text-align: left;
  padding: 8px 12px;
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}

.docs-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: top;
}

.docs-table tr:last-child td { border-bottom: none; }
.docs-table tr:hover td { background: var(--bg-hover); }

.docs-situations { display: flex; flex-direction: column; gap: 10px; }

.docs-situation {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px;
  border-radius: 8px;
  background: var(--bg-elevated);
}

.docs-situation-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.docs-situation-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.docs-code {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
  overflow-x: auto;
  white-space: pre;
}

.docs-changelog-entry { padding: 12px; border-radius: 8px; background: var(--bg-elevated); }
.docs-print-btn { font-size: 13px; padding: 8px 14px; white-space: nowrap; }

/* ------- Print (Download PDF) ------- */
@media print {
  /* Esconde nav e tab bar */
  [data-topbar], nav, .hq-topbar, .hq-tabbar,
  footer, [data-tabbar], .docs-print-btn { display: none !important; }

  /* Expande todos os acordeões */
  details { display: block !important; }
  details > * { display: block !important; }

  /* Remove bordas coloridas de fundo */
  body, .docs-page { background: white !important; color: black !important; }
  .docs-section { border-color: #ddd !important; break-inside: avoid; }
  .docs-summary { background: #f5f5f5 !important; color: black !important; }
  .docs-body { background: white !important; }
  .docs-table th { background: #f0f0f0 !important; color: black !important; }
  .docs-situation { background: #fafafa !important; }
  .docs-situation-num { background: #333 !important; }
  .docs-code { background: #f8f8f8 !important; color: black !important; }
  .docs-changelog-entry { background: #fafafa !important; }
  .hq-badge { border: 1px solid #999 !important; background: #eee !important; color: black !important; }
}
