:root {
  --navy:        #0f1e42;
  --navy-dark:   #0a1530;
  --teal:        #178f8a;
  --orange:      #f2933a;
  --bg:          #ffffff;
  --bubble-bot:  #f2f4f8;
  --text:        #23283a;
  --muted:       #6c7488;
  --border:      #e6e9f0;
  --radius:      18px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Montserrat', -apple-system, Segoe UI, sans-serif;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ===== decorative maintenance-themed background ===== */
.bg-decor {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, #f7f9fc 0%, #ffffff 45%, #ffffff 100%);
}
.bg-decor .blueprint { position: absolute; inset: 0; }
.bg-decor .gear {
  position: absolute;
  color: var(--navy);
  opacity: 0.05;
}
.gear-1 { font-size: 220px; top: -60px; left: -60px; }
.gear-2 { font-size: 140px; top: 20%; right: -40px; color: var(--orange); opacity: 0.06; }
.gear-3 { font-size: 260px; bottom: -100px; right: 5%; }
.gear-4 { font-size: 160px; bottom: 8%; left: -50px; color: var(--teal); opacity: 0.06; }

/* ===== layout ===== */
.chat-page {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh; /* viewports com barra de endereço dinâmica (Safari/Chrome mobile) */
  display: flex;
  flex-direction: column;
}

.chat-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 16px 10px;
  padding-top: max(14px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.chat-card {
  width: 100%;
  max-width: 560px;
  flex: 1;
  min-height: 0;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 20px 50px rgba(15, 30, 66, 0.10);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
  color: #fff;
  flex-shrink: 0;
}
.chat-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.75);
  font-weight: 500;
  flex-shrink: 0;
}
.chat-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #2bb673;
  box-shadow: 0 0 0 3px rgba(43,182,115,.25);
}
.chat-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: #fff;
  object-fit: contain;
  padding: 5px;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.15);
}
.chat-header-info { display: flex; flex-direction: column; line-height: 1.3; }
.chat-header-info strong { font-size: 15px; font-weight: 700; }
.chat-header-info span { font-size: 12px; color: rgba(255,255,255,0.7); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafbfd;
}
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb { background: #d9dee8; border-radius: 10px; }

/* ===== messages ===== */
.msg-row { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.msg-row.bot { justify-content: flex-start; }
.msg-row.user { justify-content: flex-end; }

.msg-row .msg-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--navy);
  object-fit: contain;
  padding: 3px;
  flex-shrink: 0;
}

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.5;
  max-width: 78%;
  animation: pop .25s ease;
  white-space: pre-line;
  overflow-wrap: break-word;
  word-break: break-word;
}
.msg-row.bot .bubble {
  background: var(--bubble-bot);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.msg-row.user .bubble {
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: .25; }
  40% { opacity: 1; }
}

/* ===== composer / options / inputs ===== */
.chat-composer {
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  background: #fff;
  flex-shrink: 0;
}

.opt-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.opt-btn {
  border: 1.5px solid var(--navy);
  background: #fff;
  color: var(--navy);
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
  padding: 11px 16px;
  min-height: 44px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.opt-btn:hover { background: var(--navy); color: #fff; }
.opt-btn.primary {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
}
.opt-btn.primary:hover { background: #d97c1f; border-color: #d97c1f; }
.opt-btn.ghost { border-color: var(--border); color: var(--muted); }
.opt-btn.ghost:hover { background: #f2f4f8; color: var(--text); }
.opt-btn:disabled { opacity: .5; cursor: default; }

.field-form {
  display: flex;
  gap: 8px;
}
.field-form input {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 16px; /* evita zoom automático ao focar em iOS Safari */
  outline: none;
  transition: border-color .15s ease;
}
.field-form input:focus { border-color: var(--teal); }
.field-form button {
  border: none;
  background: var(--teal);
  color: #fff;
  width: 46px;
  min-height: 44px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.field-form button:hover { background: #12716e; }
.field-error {
  color: #d64545;
  font-size: 12px;
  margin-top: 6px;
  font-weight: 500;
}

.wa-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #25D366;
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 12px 20px;
  min-height: 44px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: filter .15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
}
.wa-btn:hover { filter: brightness(0.94); color: #fff; }
.wa-btn i { font-size: 20px; }

.composer-empty { height: 4px; }

.chat-footnote {
  max-width: 560px;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  margin: 8px 4px 0;
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .chat-shell {
    padding: 8px 8px 6px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  .chat-card { border-radius: 14px; }
  .bubble { max-width: 86%; }
}

@media (max-width: 360px) {
  .chat-header { padding: 12px 14px; gap: 8px; }
  .chat-avatar { width: 36px; height: 36px; }
  .chat-header-info strong { font-size: 14px; }
  .opt-btn { font-size: 13px; padding: 10px 13px; }
}

/* telas muito baixas (celular deitado) — encolhe cabeçalho/composer para não cortar os botões */
@media (max-height: 480px) {
  .chat-shell { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .chat-header { padding: 10px 16px; }
  .chat-avatar { width: 34px; height: 34px; }
  .chat-header-info span { display: none; }
  .chat-body { padding: 12px 16px; gap: 8px; }
  .chat-composer { padding: 8px 16px; }
  .chat-footnote { display: none; }
}
