:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --wa: #16a34a;
  --wa-hover: #15803d;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 18px rgba(15, 23, 42, 0.08);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--wa);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  display: grid;
  place-items: center;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
}

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

.kpis {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.kpi-pill, .status-pill {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.kpi-label {
  color: var(--muted);
}

.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}

.status-open .dot { background: var(--wa); }
.status-close .dot, .status-unreachable .dot { background: var(--danger); }

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.actions input[type="search"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 13px;
  min-width: 210px;
  background: var(--surface-alt);
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary-outline { background: #eff6ff; color: var(--primary); border-color: #bfdbfe; }
.btn-primary-outline:hover { background: #dbeafe; }
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn-whatsapp { background: var(--wa); color: #fff; }
.btn-whatsapp:hover { background: var(--wa-hover); }

.btn-icon {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.board-wrapper {
  flex: 1;
  overflow-x: auto;
  padding: 18px 20px;
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(270px, 1fr));
  gap: 14px;
  align-items: start;
  min-height: calc(100vh - 110px);
}

.kanban-column {
  background: #e9eef5;
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 460px;
  border: 2px solid transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.kanban-column.drag-over {
  border-color: var(--primary);
  background: #dbeafe;
}

.column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 4px 6px;
  border-bottom: 2px solid rgba(15, 23, 42, 0.08);
}

.column-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stage-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--primary);
}

.column-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
}

.column-meta {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}

.column-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.lead-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 11px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.lead-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.lead-card.dragging {
  opacity: 0.45;
}

.lead-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.lead-name {
  font-weight: 700;
  font-size: 13px;
  margin: 0;
}

.lead-value {
  font-size: 11px;
  font-weight: 700;
  color: var(--wa);
  white-space: nowrap;
}

.lead-phone {
  font-size: 12px;
  color: var(--muted);
  margin: 3px 0 6px;
}

.lead-preview {
  font-size: 12px;
  color: #334155;
  margin: 0 0 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lead-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}

.tags-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  background: #f1f5f9;
  color: #475569;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 600;
}

.lead-time {
  font-size: 10px;
  color: var(--muted);
}

.empty-col {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 20px 8px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
}

/* Drawer & Modals */
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; margin: 2px 0 0; }

.drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.drawer-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, 100vw);
  height: 100vh;
  background: var(--surface);
  box-shadow: -8px 0 30px rgba(15, 23, 42, 0.16);
  display: flex;
  flex-direction: column;
  z-index: 41;
}

.drawer-header, .modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-header h2, .modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.drawer-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.card-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.chat-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header h3 {
  margin: 0;
  font-size: 14px;
}

.chat-messages {
  background: #efeae2;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  min-height: 200px;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-bubble {
  max-width: 82%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: var(--shadow-sm);
}

.msg-inbound {
  align-self: flex-start;
  background: #ffffff;
}

.msg-outbound {
  align-self: flex-end;
  background: #d9fdd3;
}

.msg-time {
  display: block;
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  text-align: right;
}

.chat-send-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-input-row textarea {
  flex: 1;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-card {
  position: relative;
  z-index: 51;
  width: min(480px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-wide {
  width: min(760px, 100%);
}

.modal-card .card-form {
  padding: 16px 18px;
}

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
}

.table-wrap {
  max-height: 60vh;
  overflow: auto;
  padding: 12px 18px 18px;
}

.queue-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.queue-table th, .queue-table td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.badge-status {
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 11px;
}
.badge-pendente { background: #fef9c3; color: #854d0e; }
.badge-processando { background: #dbeafe; color: #1e40af; }
.badge-enviado { background: #dcfce7; color: #166534; }
.badge-erro { background: #fee2e2; color: #991b1b; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 60;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
}
