:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f4f6fb;
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --primary-600: #4338ca;
  --primary-soft: #eef2ff;
  --primary-grad: linear-gradient(135deg, #6366f1 0%, #4f46e5 55%, #4338ca 100%);
  --green: #16a34a;
  --green-soft: #e7f6ee;
  --red: #dc2626;
  --red-soft: #fdecec;
  --amber: #d97706;
  --amber-soft: #fef3e2;
  --text: #111827;
  --text-2: #4b5563;
  --text-3: #9ca3af;
  --border: #e5e7eb;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 40px rgba(17, 24, 39, 0.10);
  --shadow-lg: 0 18px 50px rgba(17, 24, 39, 0.16);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1100px 520px at 15% -10%, #e0e7ff 0%, transparent 60%),
    radial-gradient(900px 480px at 100% 0%, #dbeafe 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; padding: 0; color: inherit; }
input, textarea { font-family: inherit; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  transition: transform .06s ease, box-shadow .15s ease, background .15s ease, opacity .15s ease;
  letter-spacing: .1px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary-grad); color: #fff; box-shadow: 0 6px 18px rgba(79, 70, 229, .28); }
.btn-primary:hover:not(:disabled) { box-shadow: 0 8px 22px rgba(79, 70, 229, .38); }
.btn-green { background: var(--green); color: #fff; box-shadow: 0 6px 16px rgba(22, 163, 74, .24); }
.btn-green:hover:not(:disabled) { background: #15803d; }
.btn-red { background: var(--red); color: #fff; box-shadow: 0 6px 16px rgba(220, 38, 38, .22); }
.btn-red:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost { background: #fff; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: #d1d5db; }
.btn-sm { padding: 8px 13px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }

/* ---------- Campos ---------- */
input[type="text"], input[type="email"], input[type="password"], textarea {
  width: 100%; padding: 11px 14px; border: 1px solid var(--border); border-radius: 12px;
  font-size: 14px; background: #fff; color: var(--text); outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:hover, textarea:hover { border-color: #d1d5db; }
input:focus, textarea:focus { border-color: var(--primary-2); box-shadow: 0 0 0 4px rgba(99, 102, 241, .14); }
textarea { resize: none; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.muted { color: var(--text-3); }

/* ---------- Pílulas de status ---------- */
.status-pill { font-size: 10.5px; padding: 3px 9px; border-radius: 999px; font-weight: 700; white-space: nowrap; letter-spacing: .2px; }
.status-pill.open { background: var(--amber-soft); color: var(--amber); }
.status-pill.active { background: var(--primary-soft); color: var(--primary-600); }
.status-pill.resolved { background: var(--green-soft); color: var(--green); }
.status-pill.unresolved { background: var(--red-soft); color: var(--red); }

/* ---------- Bolhas de mensagem (compartilhado) ---------- */
.msg { display: flex; animation: msg-in .18s ease both; }
.msg.mine { justify-content: flex-end; }
.msg.theirs { justify-content: flex-start; }
.msg.system { justify-content: center; }

.msg-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; margin-top: 2px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; background: var(--primary-soft); color: var(--primary-600);
  box-shadow: 0 1px 3px rgba(17, 24, 39, .10);
  user-select: none;
}
.msg-avatar.avatar-img { object-fit: cover; background: #fff; }
.msg.theirs .msg-avatar { margin-right: 8px; }
.msg.grouped .msg-avatar { visibility: hidden; }
.msg.grouped { margin-top: -4px; }

.bubble {
  max-width: 76%; padding: 10px 13px; border-radius: 16px;
  background: #fff; color: var(--text); border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(17, 24, 39, .06);
}
.msg.mine .bubble { background: var(--primary-grad); color: #fff; border: none; border-bottom-right-radius: 6px; box-shadow: 0 4px 12px rgba(79, 70, 229, .22); }
.msg.theirs .bubble { border-bottom-left-radius: 6px; }
.msg.system .bubble { background: transparent; border: none; box-shadow: none; color: var(--text-3); font-size: 12px; text-align: center; padding: 4px 12px; max-width: 100%; }
.msg.system .bubble .text { font-size: 12px; }
.bubble .sender { font-size: 12px; font-weight: 700; color: var(--primary-600); margin-bottom: 3px; }
.bubble .text { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.5; }
.bubble .meta { font-size: 10.5px; margin-top: 5px; display: flex; align-items: center; gap: 4px; justify-content: flex-end; color: var(--text-3); }
.msg.mine .meta { color: rgba(255, 255, 255, .82); }
.ticks { letter-spacing: -2px; }
.ticks.read { color: #a7f3d0; }
.attach-img { max-width: 220px; max-height: 220px; border-radius: 10px; display: block; margin: 4px 0 2px; cursor: zoom-in; }
.attach-file { display: inline-flex; align-items: center; gap: 7px; color: var(--primary-600); text-decoration: none; font-weight: 600; font-size: 13px; }
.msg.mine .attach-file { color: #fff; }

.day-sep { text-align: center; margin: 12px 0 4px; }
.day-sep span { font-size: 11px; color: var(--text-3); background: rgba(255, 255, 255, .8); padding: 4px 12px; border-radius: 999px; box-shadow: 0 1px 2px rgba(17, 24, 39, .06); }

@keyframes msg-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }

/* ---------- Indicador "digitando" ---------- */
.typing { padding: 4px 18px 10px; font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 5px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); display: inline-block; animation: blink 1.2s infinite; }
.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; } }

/* ---------- Botão de ícone ---------- */
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; background: transparent; color: var(--text-3);
  display: flex; align-items: center; justify-content: center; font-size: 18px; flex: none;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-2); }

/* ---------- Emoji picker ---------- */
.emoji-wrap { position: relative; flex: none; }
.emoji-pop {
  position: absolute; bottom: 46px; left: 0; width: 264px; background: #fff;
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 8px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; z-index: 40;
}
.emoji-pop button { font-size: 20px; padding: 4px; border-radius: 8px; line-height: 1; }
.emoji-pop button:hover { background: var(--surface-2); }

/* ---------- Pré-visualização de anexo + progresso ---------- */
.upload-preview { padding: 10px 14px 0; }
.preview-card {
  position: relative; display: flex; align-items: center; gap: 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px;
}
.preview-thumb {
  width: 52px; height: 52px; border-radius: 8px; object-fit: cover; flex: none;
  background: #fff; border: 1px solid var(--border);
}
.preview-thumb.file { display: flex; align-items: center; justify-content: center; font-size: 24px; }
.preview-info { flex: 1; min-width: 0; }
.preview-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-size { font-size: 11px; color: var(--text-3); }
.preview-remove {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(17, 24, 39, .55); color: #fff; font-size: 12px; line-height: 1;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.preview-remove:hover { background: rgba(17, 24, 39, .8); }
.preview-progress {
  position: absolute; left: 0; right: 0; bottom: 0; height: 4px;
  background: rgba(17, 24, 39, .08); border-radius: 0 0 12px 12px; overflow: hidden;
}
.preview-progress-bar { height: 100%; width: 0; background: var(--primary-grad); transition: width .15s ease; }

/* ---------- Assistente IA ---------- */
.msg.ai { justify-content: flex-start; }
.msg.ai .msg-avatar {
  margin-right: 8px;
  background: linear-gradient(135deg, #c084fc, #7c3aed);
  color: #fff;
  box-shadow: 0 2px 6px rgba(124, 58, 237, .30);
}
.msg.ai .bubble {
  background: #faf5ff;
  border-color: #eadcfb;
  border-bottom-left-radius: 6px;
  max-width: 84%;
}
.msg.ai .sender { color: #7c3aed; }

.ai-wrap { position: relative; flex: none; }
.ai-pop {
  position: absolute; bottom: 48px; left: 0; width: 300px;
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: 12px; z-index: 30;
  display: flex; flex-direction: column; gap: 8px;
}
.ai-pop .ai-hint { font-size: 11.5px; color: var(--text-3); line-height: 1.4; }
.ai-pop textarea {
  width: 100%; min-height: 62px; border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; font-size: 13.5px; resize: none; outline: none;
}
.ai-pop textarea:focus { border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(99, 102, 241, .14); }
.ai-pop select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 13.5px; background: #fff; color: var(--text); outline: none;
}
.ai-pop .ai-actions { display: flex; gap: 6px; justify-content: flex-end; }
