:root {
  --bg: #0b0c10;
  --panel: #12141a;
  --panel2: #0f1220;
  --border: #2a3144;
  --muted: #b9c0d0;
  --text: #e8e8e8;

  --primary: #4b7bec;
  --secondary: #2a3144;

  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }

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

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
}

.select { display: grid; gap: 6px; font-size: 14px; }

select {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  padding: 8px;
}

.chat {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 55vh;
  overflow: auto;
  scroll-behavior: smooth;
  border: 1px solid rgba(255,255,255,0.05);
}

.msg {
  padding: 10px 12px;
  border-radius: var(--radius);
  margin: 10px 0;
  line-height: 1.35;
  word-wrap: break-word;
}

.msg.user { background: #1d2433; }
.msg.bot { background: #151a24; border: 1px solid #232a3a; }

.composer {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
  margin-top: 12px;

  /* melhora no mobile: mantém o compositor visível */
  position: sticky;
  bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

textarea {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  padding: 10px;
  resize: vertical;
  min-height: 56px;
}

button {
  border-radius: var(--radius);
  border: 0;
  background: var(--primary);
  color: white;
  font-weight: 700;
  cursor: pointer;
  padding: 10px 12px;
}

button.secondary { background: var(--secondary); }

button:disabled, textarea:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* Foco visível (acessibilidade) */
button:focus-visible, textarea:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid rgba(75,123,236,0.9);
  outline-offset: 2px;
}

/* ----- MODAL / OVERLAY (TERMO) ----- */
.overlay[hidden] { display: none !important; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none; /* aparece ao adicionar .show pelo JS */
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(6px);
}

.overlay.show { display: flex; }

.modal {
  width: min(860px, 100%);
  max-height: min(84vh, 720px);
  overflow: hidden;
  border-radius: 16px;
  background: #0e1118;
  border: 1px solid rgba(255,255,255,0.10);
  box-shadow: 0 20px 60px rgba(0,0,0,0.55);
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.modalHead {
  padding: 16px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.modalHead h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.modalSub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.modalBody {
  padding: 14px 16px;
  overflow: auto;
  line-height: 1.45;
  color: var(--text);
}

.modalBody p { margin: 0 0 10px; }
.modalBody ul { margin: 0 0 12px 20px; }
.modalBody li { margin: 6px 0; }

.modalFooter {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.modalActions {
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: grid;
  gap: 10px;
}

.checkRow {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 14px;
  color: var(--text);
}

.checkRow input {
  margin-top: 2px;
  transform: scale(1.15);
}

.btnRow {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ----- RESPONSIVO ----- */
@media (max-width: 720px) {
  .wrap { padding: 12px; }

  .controls {
    align-items: stretch;
  }

  .controls button,
  .controls select {
    width: 100%;
  }

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

  #send {
    width: 100%;
  }

  .modal {
    max-height: 88vh;
  }

  .modalHead h2 { font-size: 16px; }
}

/* ---- impressão (PDF simples via Print) ---- */
@media print {
  body { background: #fff; color: #000; }
  .controls, .composer, #openTerms { display: none !important; }
  .chat { border: 0; background: transparent; padding: 0; }
  .msg { border: 0; background: transparent !important; padding: 0; margin: 10px 0; }
  .msg.user::before { content: "Você: "; font-weight: 700; }
  .msg.bot::before { content: "IZA: "; font-weight: 700; }

  /* nunca imprimir o overlay */
  .overlay { display: none !important; }
}
