:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-col: #eef1f6;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --brand: #ec2a27;
  --brand-hover: #c81e1b;
  --brand-soft: #fef2f2;
  --emerald: #15803d;
  --emerald-soft: #f0fdf4;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --radius: 12px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 24px -8px rgba(15, 23, 42, 0.14);
  --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, 0.18);
  --font-sans: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

.wrap {
  width: min(1600px, calc(100% - 2rem));
  margin-inline: auto;
}

/* Header */
.topbar {
  background: var(--surface);
  border-block-end: 1px solid var(--border);
  position: sticky;
  inset-block-start: 0;
  z-index: 20;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-brand img {
  height: 34px;
  width: auto;
  display: block;
}

.topbar-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--ink-2);
  border: 1px solid var(--border);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

/* Botões e inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 40px;
  padding: 0.5rem 0.95rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn-outline:hover { background: #f1f5f9; }
.btn-whatsapp { background: #16a34a; color: #fff; }
.btn-whatsapp:hover { background: #15803d; }

input, select, textarea {
  font: inherit;
  font-size: max(1rem, 1em);
  min-height: 42px;
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}

textarea { min-height: 92px; resize: vertical; }

/* Tela de Login */
.auth-shell {
  min-height: calc(100svh - 64px);
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 1rem;
}

.auth-card h1 { margin: 0; font-size: 1.35rem; }
.auth-card p { margin: 0; font-size: 0.9rem; color: var(--ink-2); }

.field { display: grid; gap: 0.35rem; }
.field label { font-size: 0.84rem; font-weight: 600; color: var(--ink); }

.error-banner {
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  background: var(--brand-soft);
  color: #991b1b;
  font-size: 0.875rem;
  font-weight: 500;
}

/* Dashboard Principal */
.main { padding-block: 1.25rem 2.5rem; display: grid; gap: 1rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.05rem;
  box-shadow: var(--shadow-xs);
}

.stat-label { font-size: 0.74rem; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 1.55rem; font-weight: 800; margin-top: 0.15rem; line-height: 1.2; }

/* Barra de controle do Kanban */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  box-shadow: var(--shadow-xs);
}

.funnel-tabs {
  display: inline-flex;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 9px;
  gap: 2px;
}

.funnel-tab {
  border: none;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 0.42rem 0.85rem;
  border-radius: 7px;
  cursor: pointer;
}

.funnel-tab:hover { color: var(--ink); }

.funnel-tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}

.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  justify-content: flex-end;
}

.search-box {
  width: min(300px, 100%);
}

.search-box input {
  min-height: 38px;
  font-size: 0.9rem;
}

.view-switch {
  display: inline-flex;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 9px;
  gap: 2px;
}

.view-btn {
  border: none;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: 7px;
  cursor: pointer;
}

.view-btn.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}

/* ==========================================================================
   KANBAN BOARD
   ========================================================================== */
.kanban-board {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  overflow-x: auto;
  padding-block: 0.2rem 1rem;
  min-height: 62vh;
  scrollbar-width: thin;
}

.kanban-col {
  flex: 0 0 296px;
  background: var(--surface-col);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  max-height: calc(100svh - 245px);
  min-height: 340px;
  transition: border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease;
}

.kanban-col.is-drop-target {
  border-color: var(--brand);
  background: #fef2f2;
  box-shadow: 0 0 0 2px rgba(236, 42, 39, 0.18);
}

.kanban-col-head {
  padding: 0.85rem 0.9rem 0.7rem;
  border-block-end: 1px solid rgba(15, 23, 42, 0.06);
  display: grid;
  gap: 0.2rem;
}

.kanban-col-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.kanban-col-title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
}

.stage-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.kanban-count {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.08rem 0.5rem;
}

.kanban-col-sum {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-3);
  padding-inline-start: 1.05rem;
}

.kanban-list {
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow-y: auto;
  flex: 1;
}

.kanban-empty {
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-3);
  padding: 1.5rem 0.75rem;
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
}

/* Card do Kanban */
.lead-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 0.85rem 0.9rem;
  box-shadow: var(--shadow-xs);
  cursor: grab;
  display: grid;
  gap: 0.5rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.lead-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.lead-card.is-dragging {
  opacity: 0.45;
  cursor: grabbing;
}

.lead-card.is-high-priority {
  border-inline-start: 3.5px solid var(--brand);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.card-badges {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.card-name {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}

.card-meta {
  font-size: 0.81rem;
  color: var(--ink-2);
  display: grid;
  gap: 0.15rem;
}

.card-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-block-start: 0.5rem;
  border-block-start: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--ink-3);
}

.card-value {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--emerald);
}

.card-open-btn {
  border: none;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
}

.card-open-btn:hover {
  background: #f1f5f9;
  color: var(--ink);
}

/* Toast sutil de feedback */
.toast {
  position: fixed;
  inset-block-end: 1.25rem;
  inset-inline-end: 1.25rem;
  z-index: 60;
  background: var(--ink);
  color: #ffffff;
  padding: 0.75rem 1.1rem;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
}

/* Tabela alternativa (modo Lista) */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-xs);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
  font-size: 0.88rem;
}

th, td {
  padding: 0.8rem 1rem;
  text-align: left;
  border-block-end: 1px solid var(--border);
  vertical-align: middle;
}

thead th {
  background: #f8fafc;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-3);
}

tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-block-end: none; }

.mono { font-family: var(--font-mono); font-size: 0.77rem; font-weight: 600; color: var(--ink-3); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill-clcb { background: var(--emerald-soft); color: var(--emerald); }
.pill-avcb { background: var(--brand-soft); color: var(--brand); }
.pill-verificar { background: var(--amber-soft); color: var(--amber); }
.pill-alta { background: #fee2e2; color: #991b1b; }
.pill-status { background: #f1f5f9; color: var(--ink); }

.empty-state {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--ink-3);
}

/* Modal de Detalhe (<dialog>) */
dialog.lead-dialog {
  width: min(680px, calc(100% - 1.5rem));
  max-height: 90svh;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
  color: var(--ink);
}

dialog.lead-dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.35rem;
  border-block-end: 1px solid var(--border);
  position: sticky;
  inset-block-start: 0;
  background: var(--surface);
}

.dialog-body {
  padding: 1.35rem;
  display: grid;
  gap: 1.25rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.meta-item dt { font-size: 0.72rem; text-transform: uppercase; color: var(--ink-3); font-weight: 700; }
.meta-item dd { margin: 0.15rem 0 0; font-size: 0.9rem; font-weight: 500; }

.edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.edit-grid .full { grid-column: 1 / -1; }

.events-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.events-list li {
  font-size: 0.84rem;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
}

.events-list time {
  display: block;
  font-size: 0.74rem;
  color: var(--ink-3);
}

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .meta-grid, .edit-grid { grid-template-columns: 1fr; }
  .toolbar-right { justify-content: flex-start; }
}
