:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #111827;
  --success: #0f7a4b;
  --success-bg: #eaf7f0;
  --warning: #946200;
  --warning-bg: #fff7dd;
  --danger: #b42318;
  --danger-bg: #fff0ee;
  --info: #2457a7;
  --info-bg: #edf4ff;
  --radius: 14px;
  --shadow: 0 12px 36px rgba(17, 24, 39, .07);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(17,24,39,.05), transparent 30%),
    linear-gradient(180deg, #fafafa, #f3f4f6);
}
.login-card {
  width: min(100%, 390px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 30px;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: -.04em;
  margin-bottom: 18px;
}
.eyebrow { margin: 0 0 7px; font-size: 12px; font-weight: 800; letter-spacing: .12em; color: var(--muted); }
.login-card h1 { margin: 0 0 8px; font-size: 28px; letter-spacing: -.035em; }
.login-card > .muted { margin: 0 0 24px; font-size: 14px; }
label { display: block; font-size: 13px; font-weight: 700; margin: 14px 0 7px; }
input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #fff;
  color: var(--text);
  outline: none;
  padding: 0 13px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus { border-color: #9ca3af; box-shadow: 0 0 0 4px rgba(17,24,39,.06); }
.password-row { position: relative; }
.password-row input { padding-right: 76px; }
.icon-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: #f3f4f6;
  color: #374151;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
}
.primary-btn, .secondary-btn, .ghost-btn, .action-btn {
  border: 0;
  border-radius: 10px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 750;
}
.primary-btn { background: var(--primary); color: white; }
.secondary-btn { background: #fff; color: var(--text); border: 1px solid var(--border); }
.ghost-btn { background: transparent; color: var(--muted); }
.full { width: 100%; margin-top: 20px; min-height: 46px; }
.form-error { min-height: 18px; margin: 10px 0 0; color: var(--danger); font-size: 13px; text-align: center; }
.local-hint { margin: 12px 0 0; font-size: 12px; color: var(--warning); text-align: center; }

.app-shell { width: min(1500px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 32px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.brand-line { display: flex; align-items: center; gap: 8px; font-size: 12px; letter-spacing: .11em; color: #374151; }
.brand-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); display: inline-block; }
.topbar h1 { margin: 5px 0 0; font-size: clamp(22px, 3vw, 30px); letter-spacing: -.035em; }
.topbar-actions { display: flex; gap: 8px; }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: 0 4px 18px rgba(17,24,39,.035); }
.stat-card span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat-card strong { font-size: 27px; letter-spacing: -.04em; }

.toolbar { display: grid; grid-template-columns: minmax(230px, 1.7fr) repeat(3, minmax(160px, .75fr)); gap: 10px; margin-bottom: 12px; }
.search-wrap input { background: #fff; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0 0 2px; font-size: 17px; }
.panel-head p { margin: 0; font-size: 12px; }
.sync-status { color: var(--muted); font-size: 12px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 880px; }
th { padding: 12px 16px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; text-align: left; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); }
td { padding: 14px 16px; border-bottom: 1px solid #eef0f2; vertical-align: middle; font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfbfc; }
.client-name { font-weight: 750; }
.client-email { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.phone-link { color: var(--text); text-decoration: none; font-variant-numeric: tabular-nums; }
.badge { display: inline-flex; align-items: center; min-height: 27px; border-radius: 999px; padding: 0 10px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.badge.pending { color: var(--warning); background: var(--warning-bg); }
.badge.expired { color: var(--danger); background: var(--danger-bg); }
.badge.paid { color: var(--success); background: var(--success-bg); }
.badge.unknown { color: var(--muted); background: #f3f4f6; }
.status-select { width: 132px; min-height: 34px; border-radius: 9px; font-size: 12px; padding: 0 8px; }
.action-group { display: flex; flex-wrap: wrap; gap: 6px; }
.action-btn { min-height: 34px; padding: 0 10px; font-size: 11px; background: #f3f4f6; color: #374151; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.action-btn.whatsapp { background: var(--success-bg); color: var(--success); }
.action-btn.danger { background: var(--danger-bg); color: var(--danger); }
.actions-col { min-width: 220px; }

.empty-state { min-height: 230px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; padding: 30px; text-align: center; }
.empty-state span { color: var(--muted); font-size: 13px; }
.mobile-cards { display: none; }
.footer-note { display: flex; justify-content: center; gap: 7px; color: #9ca3af; font-size: 11px; padding: 16px 0 0; }
.toast { position: fixed; right: 18px; bottom: 18px; max-width: min(360px, calc(100vw - 36px)); background: #111827; color: #fff; padding: 12px 14px; border-radius: 11px; box-shadow: var(--shadow); font-size: 13px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; z-index: 50; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 950px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search-wrap { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .app-shell { width: min(100% - 20px, 1500px); padding-top: 14px; }
  .topbar { align-items: flex-start; }
  .topbar-actions { flex-direction: column; }
  .topbar-actions button { min-height: 34px; }
  .stats-grid { grid-template-columns: 1fr 1fr 1fr; gap: 7px; }
  .stat-card { padding: 12px 10px; }
  .stat-card span { font-size: 10px; }
  .stat-card strong { font-size: 22px; }
  .toolbar { grid-template-columns: 1fr; }
  .search-wrap { grid-column: auto; }
  .table-wrap { display: none; }
  .mobile-cards { display: grid; gap: 10px; padding: 10px; }
  .lead-card { border: 1px solid var(--border); border-radius: 13px; padding: 14px; background: #fff; }
  .lead-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
  .lead-card h3 { margin: 0 0 3px; font-size: 16px; }
  .lead-card .date { color: var(--muted); font-size: 11px; }
  .lead-card-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 9px 0; font-size: 12px; }
  .lead-card-row > span:first-child { color: var(--muted); }
  .lead-card .status-select { width: 150px; }
  .lead-card .action-group { margin-top: 13px; }
  .lead-card .action-btn { flex: 1; min-height: 38px; }
  .panel-head { padding: 14px; }
}

/* v1.2.0 — fluxo de classificação após WhatsApp */
body.modal-open { overflow: hidden; }
.status-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.failure-mini { display: inline-flex; max-width: 160px; font-size: 10px; line-height: 1.2; color: var(--danger); }
.truncate { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, .52);
  backdrop-filter: blur(4px);
}
.action-modal {
  width: min(100%, 620px);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 28px 90px rgba(17,24,39,.24);
  padding: 22px;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.modal-head .eyebrow { margin-bottom: 4px; }
.modal-head h2 { margin: 0; font-size: 23px; letter-spacing: -.03em; }
.modal-close { width: 38px; height: 38px; border: 0; border-radius: 11px; background: #f3f4f6; color: #374151; font-size: 26px; line-height: 1; }
.action-feedback { border-radius: 11px; padding: 10px 12px; margin-bottom: 13px; font-size: 12px; line-height: 1.4; }
.action-feedback.success { color: var(--success); background: var(--success-bg); }
.action-feedback.danger { color: var(--danger); background: var(--danger-bg); }
.action-feedback.info { color: var(--info); background: var(--info-bg); }
.contact-summary { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; border: 1px solid var(--border); border-radius: 14px; padding: 14px; background: var(--surface-2); }
.contact-summary-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.contact-summary-main strong { font-size: 17px; }
.contact-summary-main span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.contact-summary-meta { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 7px; }
.contact-summary-meta small { color: var(--muted); }
.message-box { margin-top: 12px; border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.message-box-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.message-box-head strong { font-size: 12px; }
.tiny-btn { border: 0; border-radius: 8px; background: #f3f4f6; color: #374151; padding: 7px 9px; font-size: 10px; font-weight: 800; }
.message-box p { white-space: pre-wrap; margin: 10px 0 0; color: #374151; font-size: 12px; line-height: 1.55; }
.classification-block { margin-top: 17px; }
.classification-title { margin: 0 0 10px; font-size: 13px; font-weight: 800; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result-btn { text-align: left; border: 1px solid var(--border); border-radius: 13px; background: #fff; padding: 14px; min-height: 82px; }
.result-btn strong, .result-btn span { display: block; }
.result-btn strong { font-size: 13px; margin-bottom: 5px; }
.result-btn span { font-size: 11px; color: var(--muted); line-height: 1.35; }
.result-btn.success:hover { border-color: #8fd1ae; background: var(--success-bg); }
.result-btn.danger:hover { border-color: #efaaa4; background: var(--danger-bg); }
.failure-panel { margin-top: 12px; padding: 14px; border: 1px solid #f2c2be; border-radius: 14px; background: #fffafa; }
.failure-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.failure-options label { display: flex; align-items: center; gap: 8px; margin: 0; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: #fff; font-size: 11px; cursor: pointer; }
.failure-options input { width: auto; min-height: 0; margin: 0; }
.failure-panel > label { margin-top: 12px; }
.failure-panel textarea { width: 100%; resize: vertical; border: 1px solid var(--border); border-radius: 11px; padding: 10px 12px; outline: none; font: inherit; font-size: 12px; }
.failure-panel textarea:focus { border-color: #9ca3af; box-shadow: 0 0 0 4px rgba(17,24,39,.06); }
.failure-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.danger-solid-btn { border: 0; border-radius: 10px; min-height: 40px; padding: 0 14px; background: var(--danger); color: #fff; font-weight: 800; }
.modal-secondary-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 15px; padding-top: 14px; border-top: 1px solid var(--border); }
.mini-status-btn { border: 1px solid var(--border); border-radius: 999px; background: #fff; color: #4b5563; padding: 8px 10px; font-size: 10px; font-weight: 800; }
.modal-hint { margin: 12px 0 0; text-align: center; color: var(--muted); font-size: 10px; }
.badge.info { color: var(--info); background: var(--info-bg); }
.badge.failed { color: var(--danger); background: var(--danger-bg); }
.badge.ignored { color: var(--muted); background: #f3f4f6; }

@media (max-width: 600px) {
  .modal-backdrop { padding: 10px; align-items: end; }
  .action-modal { width: 100%; max-height: calc(100vh - 20px); border-radius: 18px 18px 12px 12px; padding: 17px; }
  .result-grid, .failure-options { grid-template-columns: 1fr; }
  .contact-summary { flex-direction: column; }
  .contact-summary-meta { align-items: flex-start; }
  .message-box-head { align-items: flex-start; }
}
