:root {
  --red: #ef4444;
  --red-dark: #b91c1c;
  --bg: #f4f5f7;
  --border: #e2e4e9;
  --text: #1f2430;
  --muted: #6b7280;
  --green: #16a34a;
  --yellow: #d97706;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
}

.logo-img { border-radius: 8px; display: block; }
.attendant-badge { color: var(--red-dark); font-weight: 700; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px;
  width: 400px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.06);
}
.login-card .logo-img { width: 80px; margin: 0 auto 16px; }
.login-card h1 {
  font-size: 28px;
  margin: 0 0 6px;
  color: var(--red-dark);
  text-align: center;
}
.login-card p.sub {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 16px;
  text-align: center;
}
.login-card input {
  width: 100%;
  padding: 13px 15px;
  margin-bottom: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 18px;
}
.login-card button {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
  font-weight: 600;
  font-size: 18px;
  cursor: pointer;
}
.login-card button:hover { background: var(--red-dark); }
.error-msg { color: var(--red-dark); font-size: 15px; margin-bottom: 10px; min-height: 18px; }

/* ---------- Painel ---------- */
.topbar {
  height: 64px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  justify-content: space-between;
}
.topbar .brand { font-weight: 700; color: var(--red-dark); font-size: 20px; display: flex; align-items: center; gap: 10px; }
.topbar .brand .logo-img { width: 34px; height: 34px; }
.topbar .who { font-size: 17px; color: var(--muted); display: flex; gap: 14px; align-items: center; }
.topbar button.link {
  background: none; border: none; color: var(--red-dark); cursor: pointer; font-size: 17px; padding: 0;
}

.layout {
  display: grid;
  grid-template-columns: 620px 1fr;
  height: calc(100vh - 64px);
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: #fff;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tabs button {
  flex: 1;
  padding: 13px 6px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs button.active {
  color: var(--red-dark);
  border-bottom-color: var(--red);
  font-weight: 600;
}

.new-conv {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 6px;
}
.new-conv input {
  flex: 1;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
}
.contact-search {
  position: relative;
  padding: 10px 10px 0;
}
.contact-search input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
}
.contact-results {
  display: none;
  position: absolute;
  left: 10px;
  right: 10px;
  top: 44px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  max-height: 260px;
  overflow-y: auto;
  z-index: 15;
}
.contact-results.open { display: block; }
.contact-result-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.contact-result-item:last-child { border-bottom: none; }
.contact-result-item:hover { background: #fafafa; }
.contact-result-item .name { font-weight: 600; font-size: 15px; }
.contact-result-item .number { font-size: 13px; color: var(--muted); }
.contact-empty { padding: 10px 12px; font-size: 14px; color: var(--muted); }

.new-conv button {
  border: none;
  background: var(--red);
  color: #fff;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 15px;
}

.conv-list { overflow-y: auto; flex: 1; min-height: 0; }
.conv-item {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.conv-item:hover { background: #fafafa; }
.conv-item.selected { background: #fef2f2; }
.conv-item .row1 { display: flex; justify-content: space-between; align-items: center; }
.conv-item .name { font-weight: 600; font-size: 19px; }
.conv-item .phone { font-size: 16px; color: var(--muted); }
.badge {
  font-size: 13px;
  padding: 4px 11px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge.aberto { background: #fee2e2; color: var(--red-dark); }
.badge.em_atendimento { background: #fef3c7; color: var(--yellow); }
.badge.fechado { background: #dcfce7; color: var(--green); }
.conv-item .assigned { font-size: 15px; color: var(--muted); margin-top: 6px; }
.btn-cancel-item {
  margin-top: 8px;
  border: 1px solid var(--red);
  background: #fff;
  color: var(--red-dark);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-cancel-item:hover { background: #fef2f2; }

.chat-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-header h2 { margin: 0; font-size: 22px; }
.chat-header .sub { font-size: 16px; color: var(--muted); }
.chat-actions button {
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  margin-left: 8px;
}
.btn-claim { background: var(--red); color: #fff; }
.btn-close { background: #fff; border: 1px solid var(--border) !important; color: var(--text); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f9fafb;
  min-height: 0;
}
.msg {
  max-width: 62%;
  padding: 11px 15px;
  border-radius: 10px;
  font-size: 18px;
  line-height: 1.45;
}
.msg .meta { font-size: 13px; opacity: 0.7; margin-top: 6px; }
.msg.in { align-self: flex-start; background: #fff; border: 1px solid var(--border); }
.msg.out { align-self: flex-end; background: var(--red); color: #fff; }

.composer {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: #fff;
  display: flex;
  gap: 10px;
}
.composer textarea {
  flex: 1;
  resize: none;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 18px;
  min-height: 50px;
}
.composer button {
  border: none;
  background: var(--red);
  color: #fff;
  border-radius: 8px;
  padding: 0 22px;
  font-weight: 600;
  font-size: 17px;
  cursor: pointer;
}
.composer button:disabled { background: #d1d5db; cursor: not-allowed; }
.emoji-wrap { position: relative; }
.btn-emoji {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  font-size: 22px;
  padding: 0 12px;
  cursor: pointer;
}
.btn-emoji:hover { background: #fef2f2; }
.emoji-picker {
  display: none;
  position: absolute;
  bottom: 56px;
  left: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 10px;
  width: 260px;
  max-height: 220px;
  overflow-y: auto;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  z-index: 20;
}
.emoji-picker.open { display: grid; }
.emoji-opt {
  border: none;
  background: none;
  font-size: 22px;
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
}
.emoji-opt:hover { background: #f4f5f7; }
.btn-mic {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  font-size: 20px;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-mic:hover { background: #fef2f2; }
.btn-mic.recording {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
  font-size: 15px;
  font-weight: 600;
  min-width: 64px;
}



.reply-preview {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
  background: #fef2f2;
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--red);
  font-size: 14px;
  color: var(--text);
}
.reply-preview-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.reply-cancel {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 15px;
  color: var(--muted);
  padding: 0 4px;
}
.msg .reply-quote {
  border-left: 3px solid rgba(0,0,0,0.15);
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 13px;
  opacity: 0.8;
  border-radius: 4px;
  background: rgba(0,0,0,0.04);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.msg.out .reply-quote { background: rgba(255,255,255,0.18); border-left-color: rgba(255,255,255,0.5); }
.msg { cursor: pointer; }

.image-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.image-modal img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 8px;
}
.image-modal-close {
  position: absolute;
  top: 20px;
  right: 28px;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
}

.doc-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0,0,0,0.04);
  text-decoration: none;
  color: inherit;
  max-width: 230px;
}
.msg.out .doc-link { background: rgba(255,255,255,0.18); }
.doc-icon { font-size: 20px; flex-shrink: 0; }
.doc-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 18px;
}

.attendants-panel {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: 720px;
  max-width: 92vw;
  background: #fff;
  border-left: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  box-shadow: -4px 0 12px rgba(0,0,0,0.06);
}
.attendants-panel h3 { margin-top: 0; font-size: 20px; }
.attendants-panel h4 { font-size: 18px; }
.attendants-panel input {
  width: 100%;
  padding: 11px;
  margin-bottom: 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 17px;
}
.attendants-panel .att-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 17px;
}
