:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --danger: #ef4444;
  --secondary: #1e293b;
  --text-muted: #64748b;
  --bg: #f8fafc;
  --white: #ffffff;
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --border: #e2e8f0;
  --warning: #f59e0b;
  --info: #3b82f6;
  --soft-green: #f0fdf4;
  --soft-yellow: #fffbeb;
  --soft-red: #fff1f2;
  --soft-blue: #eff6ff;
  --soft-slate: #f8fafc;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--secondary);
  padding-bottom: 80px;
}

header {
  background: var(--white);
  padding: 12px 5%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--primary);
}

.logo span {
  color: var(--secondary);
}

.nav-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn-nav {
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  user-select: none;
}

.btn-creditos {
  background: #eff6ff;
  color: #3b82f6;
  border-color: #dbeafe;
}

.btn-resultados {
  background: #f0fdf4;
  color: var(--primary);
  border-color: #dcfce7;
}

.btn-sair {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fee2e2;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.container {
  max-width: 520px;
  margin: 20px auto;
  padding: 0 15px;
}

.credit-card {
  background: linear-gradient(135deg, var(--secondary), #334155);
  color: white;
  padding: 20px;
  border-radius: 24px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-lg);
}

.credit-card strong {
  font-size: 1.8rem;
  font-weight: 800;
}

.context-form {
  background: white;
  padding: 20px;
  border-radius: 24px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.label-pergunta {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.grid-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 25px;
}

.chip {
  padding: 12px 4px;
  border: 2px solid #f1f5f9;
  border-radius: 18px;
  background: #ffffff;
  cursor: pointer;
  text-align: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.chip img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 14px;
  margin-bottom: 6px;
}

.chip span {
  font-size: 0.55rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
}

.chip.active {
  border-color: var(--primary);
  background: #f0fdf4;
  transform: translateY(-4px);
  box-shadow: 0 8px 12px rgba(16, 185, 129, 0.15);
}

.chip.active img {
  transform: scale(1.05);
}

.chip.active span {
  color: var(--primary-dark);
}

.whatsapp-float {
  position: fixed;
  width: 56px;
  height: 56px;
  bottom: 25px;
  right: 20px;
  background-color: #25d366;
  color: #fff;
  border-radius: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  text-decoration: none;
}

.whatsapp-float svg {
  width: 30px;
  height: 30px;
  fill: white;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 15px;
}

.photo-slot {
  aspect-ratio: 1 / 1;
  background: #f1f5f9;
  border: 2px dashed #cbd5e1;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.photo-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-slot.active {
  border: 2px solid var(--primary);
  background: white;
}

.btn-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-weight: 900;
}

.btn-analisar {
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  padding: 18px;
  border-radius: 16px;
  font-weight: 800;
  cursor: pointer;
  font-size: 0.95rem;
  transition: 0.2s;
}

.btn-analisar:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 1000;
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-content {
  background: white;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  border-radius: 28px;
  position: relative;
  overflow-y: auto;
  padding: 25px;
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  background: #f1f5f9;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-weight: 800;
}

.diag-header {
  padding: 15px;
  border-radius: 18px;
  margin-bottom: 15px;
}

.critico {
  background: #fff1f2;
  color: #9f1239;
}

.atencao {
  background: #fffbeb;
  color: #92400e;
}

.normal {
  background: #f0fdf4;
  color: #166534;
}

.section-title {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 16px;
  margin-bottom: 8px;
}

.mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.mini-card {
  background: var(--soft-slate);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

.mini-card .mini-label {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 800;
  margin-bottom: 6px;
}

.mini-card .mini-value {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--secondary);
  line-height: 1.4;
}

.item-card {
  font-size: 0.75rem;
  padding: 10px;
  border-radius: 12px;
  margin-bottom: 6px;
  line-height: 1.45;
}

.item-neutral {
  background: #f8fafc;
  border-left: 4px solid #94a3b8;
}

.item-safe {
  background: #f0fdf4;
  border-left: 4px solid var(--primary);
}

.item-danger {
  background: #fff1f2;
  border-left: 4px solid var(--danger);
}

.item-warn {
  background: #fffbeb;
  border-left: 4px solid var(--warning);
}

.item-info {
  background: #eff6ff;
  border-left: 4px solid var(--info);
}

.history-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.history-btn {
  border: 1px solid var(--border);
  background: white;
  color: var(--secondary);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
}

.history-btn.agent {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

#loading {
  display: none;
  text-align: center;
  padding: 15px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 10px auto;
}

@keyframes spin {
  100% {
    transform: rotate(360deg);
  }
}

select {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 2px solid #f1f5f9;
  background: #f8fafc;
  font-weight: 600;
  outline: none;
  margin-bottom: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 20px;
  background: #1e293b;
  color: white;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 0.8rem;
  display: none;
  z-index: 2000;
}

.agent-fab {
  position: fixed;
  bottom: 95px;
  right: 20px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(16, 185, 129, 0.28);
  z-index: 1001;
}

.agent-panel {
  position: fixed;
  right: 20px;
  bottom: 165px;
  width: 360px;
  max-width: calc(100vw - 30px);
  height: 520px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 1002;
}

.agent-panel.active {
  display: flex;
}

.agent-header {
  background: linear-gradient(135deg, var(--secondary), #334155);
  color: white;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.agent-header-title {
  display: flex;
  flex-direction: column;
}

.agent-header-title strong {
  font-size: 0.95rem;
  font-weight: 800;
}

.agent-header-title span {
  font-size: 0.7rem;
  opacity: 0.85;
}

.agent-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  cursor: pointer;
  font-weight: 800;
}

.agent-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  background: #f8fafc;
}

.agent-msg {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 16px;
  margin-bottom: 10px;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.agent-msg.bot {
  background: white;
  color: #334155;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 6px;
}

.agent-msg.user {
  background: #dcfce7;
  color: #14532d;
  margin-left: auto;
  border: 1px solid #bbf7d0;
  border-bottom-right-radius: 6px;
}

.agent-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px 0;
  background: white;
  border-top: 1px solid #eef2f7;
}

.agent-chip {
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.agent-footer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #eef2f7;
  background: white;
}

.agent-input {
  flex: 1;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.82rem;
  outline: none;
}

.agent-send {
  border: none;
  border-radius: 14px;
  padding: 0 16px;
  background: var(--primary);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

.agent-typing {
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0 14px 10px;
  background: white;
  display: none;
}

.historico-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  margin-bottom: 10px;
}

.historico-thumb {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 10px;
  background: #e2e8f0;
  flex-shrink: 0;
}

@media (max-width: 520px) {
  .agent-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 150px;
    height: 62vh;
  }

  .grid-options {
    gap: 6px;
  }

  .chip img {
    width: 52px;
    height: 52px;
  }

  .mini-grid {
    grid-template-columns: 1fr;
  }

  .history-actions {
    flex-direction: column;
  }
}