:root {
  --navy: #082f5b;
  --blue: #005a9c;
  --blue-2: #0f6bc2;
  --text: #123155;
  --muted: #62748a;
  --bg: #eef4fb;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-border: rgba(132, 159, 190, 0.24);
  --shadow: 0 18px 50px rgba(8, 47, 91, 0.14);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(0, 90, 156, 0.12), transparent 30%),
    radial-gradient(circle at top right, rgba(8, 47, 91, 0.08), transparent 28%),
    linear-gradient(180deg, #fbfdff 0%, var(--bg) 45%, #e5edf7 100%);
}

.chat-app {
  width: min(1480px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0 1.25rem;
}

.chat-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.1rem 1.2rem;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(8, 47, 91, 0.98), rgba(0, 90, 156, 0.95));
  color: #fff;
  box-shadow: var(--shadow);
}

.chat-hero__brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.chat-hero h1 {
  margin: 0;
  font-size: clamp(1.4rem, 2.3vw, 2.35rem);
  font-weight: 700;
  line-height: 1.06;
  text-align: center;
}

.chat-main {
  margin-top: 1rem;
}

.chat-stream {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.chat-message {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
}

.chat-result-card {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.chat-result-card:focus-visible {
  outline: 3px solid rgba(0, 90, 156, 0.25);
  outline-offset: 4px;
  border-radius: 28px;
}

.chat-message--assistant .chat-bubble {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(245, 250, 255, 0.96));
}

.chat-bubble.chat-bubble--warning {
  background:
    linear-gradient(180deg, rgba(255, 248, 216, 0.98), rgba(255, 238, 169, 0.98));
  border-color: rgba(198, 154, 16, 0.26);
}

.chat-bubble.chat-bubble--warning .chat-bubble__title,
.chat-bubble.chat-bubble--warning p {
  color: #6d5200;
}

.chat-bubble.chat-bubble--error {
  background:
    linear-gradient(180deg, rgba(255, 237, 237, 0.98), rgba(255, 218, 218, 0.98));
  border-color: rgba(183, 28, 28, 0.24);
}

.chat-bubble.chat-bubble--error .chat-bubble__title,
.chat-bubble.chat-bubble--error p {
  color: #8f1111;
}

.chat-bubble {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  border-radius: 24px 24px 24px 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  padding: 1rem 1.05rem;
}

.chat-bubble p {
  margin: 0;
  color: var(--text);
  line-height: 1.55;
}

.chat-highlight {
  color: #c1121f;
  font-weight: 700;
}

.chat-bubble__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(0, 90, 156, 0.08);
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.chat-avatar {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(0, 90, 156, 0.12), rgba(8, 47, 91, 0.2));
  border: 1px solid rgba(8, 47, 91, 0.12);
  overflow: hidden;
  flex: 0 0 auto;
  box-shadow: 0 10px 20px rgba(8, 47, 91, 0.12);
}

.chat-avatar--lg {
  width: 74px;
  height: 74px;
  border-radius: 22px;
}

.chat-avatar--rgb {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
  margin-top: 0.9rem;
}

.chat-stat {
  padding: 0.8rem 0.85rem;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(232, 238, 245, 0.95), rgba(249, 252, 255, 0.98));
  border: 1px solid rgba(154, 181, 208, 0.28);
}

.chat-stat span,
.chat-field span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.chat-stat strong,
.chat-field strong {
  display: block;
  color: var(--navy);
  font-size: 0.98rem;
  line-height: 1.35;
  word-break: break-word;
}

.chat-composer {
  padding: 1rem 1.05rem;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(132, 159, 190, 0.22);
  box-shadow: var(--shadow);
}

.chat-composer__label {
  display: block;
  margin-bottom: 0.55rem;
  color: var(--navy);
  font-weight: 700;
  font-size: 0.92rem;
}

.chat-composer__bar {
  display: flex;
  gap: 0.65rem;
}

.chat-composer__bar input {
  flex: 1 1 auto;
  border: 1px solid #c4d4e6;
  border-radius: 16px;
  padding: 0.95rem 1rem;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.chat-composer__bar button {
  border: 0;
  border-radius: 16px;
  padding: 0.95rem 1.2rem;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 12px 26px rgba(0, 90, 156, 0.24);
}

.chat-composer__clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.95rem 1.15rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--navy);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid rgba(132, 159, 190, 0.22);
  box-shadow: 0 10px 20px rgba(8, 47, 91, 0.08);
}

.chat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.92rem;
  padding: 0 0.2rem;
}

.chat-meta__summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
}

.chat-meta__summary span {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(132, 159, 190, 0.18);
}

.chat-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1rem;
  border-radius: 14px;
  background: linear-gradient(135deg, #b00020, #d62828);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 10px 22px rgba(176, 0, 32, 0.2);
}

.chat-download:hover {
  filter: brightness(1.06);
}

.chat-download:focus-visible {
  outline: 3px solid rgba(176, 0, 32, 0.24);
  outline-offset: 3px;
}

.chat-feed {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.chat-message--bot .chat-bubble {
  border-radius: 24px 24px 24px 10px;
}

.chat-bubble--record {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(246, 250, 255, 0.96));
}

.chat-record-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(260px, 1.35fr);
  grid-template-areas:
    "ne favorecido descricao"
    "processo saldo descricao";
  gap: 0.75rem;
}

.chat-field {
  padding: 0.8rem 0.85rem;
  border-radius: 16px;
  background: #f7fbff;
  border: 1px solid rgba(154, 181, 208, 0.22);
}

.chat-field span {
  display: block;
  font-size: 0.8rem;
  color: #000000;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.chat-field--ne { grid-area: ne; }
.chat-field--favorecido { grid-area: favorecido; }
.chat-field--descricao { grid-area: descricao; }
.chat-field--processo { grid-area: processo; }
.chat-field--saldo { grid-area: saldo; }

.chat-field--saldo strong {
  font-size: 1.08rem;
}

.chat-field strong {
  display: block;
  color: #082f5b;
  font-weight: 700;
  line-height: 1.35;
  text-align: justify;
  text-justify: inter-word;
  word-break: break-word;
}

.chat-field--saldo-positive strong {
  color: #0b7a2a;
}

.chat-field--saldo-negative strong {
  color: #b00020;
}

.chat-field--saldo strong {
  text-align: left;
}

.chat-bubble--isolated {
  width: min(100%, 920px);
  padding: 1rem;
}

.card-modal__body .chat-message {
  align-items: flex-start;
}

.card-modal__body .chat-avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
}

.card-modal__body .chat-bubble {
  width: 100%;
}

.card-modal__body .chat-avatar img {
  object-fit: contain;
}

.card-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.card-modal.is-open {
  display: flex;
}

.card-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 47, 91, 0.42);
  backdrop-filter: blur(4px);
}

.card-modal__dialog {
  position: relative;
  z-index: 1;
  width: min(96vw, 1120px);
  max-height: 90vh;
  overflow: auto;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 251, 255, 0.98));
  border: 1px solid rgba(154, 181, 208, 0.24);
  box-shadow: 0 26px 80px rgba(8, 47, 91, 0.28);
  padding: 1rem;
}

.card-modal__close {
  position: absolute;
  top: 0.75rem;
  right: 0.85rem;
  width: 2.4rem;
  height: 2.4rem;
  border: 0;
  border-radius: 999px;
  background: rgba(8, 47, 91, 0.08);
  color: var(--navy);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.card-modal__header {
  padding: 0.2rem 0.3rem 0.85rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid rgba(154, 181, 208, 0.22);
}

.card-modal__eyebrow {
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-modal__header h2 {
  margin: 0;
  color: var(--navy);
  font-size: clamp(1.2rem, 2vw, 1.65rem);
}

.card-modal__body .chat-message {
  width: 100%;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.chat-note {
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 1080px) {
  .chat-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-record-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "ne favorecido"
      "descricao descricao"
      "processo saldo";
  }
}

@media (max-width: 820px) {
  .chat-hero {
    flex-direction: column;
    align-items: center;
  }

  .chat-composer__bar {
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .chat-app {
    width: min(100%, calc(100% - 0.7rem));
    padding-top: 0.35rem;
  }

  .chat-hero {
    padding: 0.8rem 0.85rem;
    border-radius: 18px;
  }

  .chat-hero h1 {
    font-size: clamp(1.1rem, 4.8vw, 1.45rem);
  }

  .chat-stream {
    gap: 0.7rem;
  }

  .chat-message {
    gap: 0.55rem;
  }

  .chat-avatar--lg {
    width: 52px;
    height: 52px;
    border-radius: 16px;
  }

  .chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  .chat-bubble,
  .chat-composer,
  .chat-stat,
  .chat-field {
    border-radius: 18px;
  }

  .chat-bubble,
  .chat-composer {
    padding: 0.8rem 0.85rem;
  }

  .chat-bubble p {
    line-height: 1.48;
  }

  .chat-bubble__title {
    flex-direction: column;
    align-items: flex-start;
  }

  .chat-stats {
    grid-template-columns: 1fr;
    gap: 0.55rem;
    margin-top: 0.7rem;
  }

  .chat-stat {
    padding: 0.7rem 0.75rem;
  }

  .chat-meta {
    font-size: 0.85rem;
    gap: 0.35rem 0.5rem;
    align-items: stretch;
  }

  .chat-meta__summary span {
    padding: 0.3rem 0.55rem;
  }

  .chat-download {
    width: 100%;
  }

  .chat-record-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "ne"
      "favorecido"
      "descricao"
      "processo"
      "saldo";
  }

  .chat-field strong {
    text-align: left;
  }

  .card-modal__dialog {
    width: 100%;
    max-height: 92vh;
    border-radius: 20px;
    padding: 0.8rem;
  }

  .card-modal {
    padding: 0.45rem;
  }

  .card-modal__header {
    padding-bottom: 0.65rem;
    margin-bottom: 0.45rem;
  }

  .card-modal__close {
    top: 0.55rem;
    right: 0.55rem;
    width: 2.1rem;
    height: 2.1rem;
  }

  .chat-bubble--isolated {
    padding: 0.8rem;
  }
}
