/* ============================================================
   MAPEADOS — CRM Pipeline Styles
   Dark theme, consistent with mapeados.css
   ============================================================ */

/* ---- Pipeline Stage Colors ---- */
:root {
  --stage-novo: #64748b;
  --stage-contato: #3b82f6;
  --stage-proposta: #f59e0b;
  --stage-negociacao: #8b5cf6;
  --stage-fechado: #22c55e;
  --stage-perdido: #ef4444;
  --temp-quente: #ef4444;
  --temp-morno: #f59e0b;
  --temp-frio: #3b82f6;
}

/* ---- Page Layout ---- */
.page-crm {
  overflow: hidden;
}

.page-crm #header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 72px;
  padding-bottom: 16px;
}

.crm-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 96px);
  margin-top: 96px;
  overflow: hidden;
}

/* ---- Header Nav Tabs ---- */
.header-nav {
  display: flex;
  gap: 0;
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

.nav-tab {
  padding: 8px 24px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}

.nav-tab:hover {
  color: var(--text-secondary);
}

.nav-tab.active {
  color: #fff;
  border-bottom-color: var(--accent);
}

/* ---- CRM Toolbar ---- */
.crm-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.crm-toolbar-left {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  flex: 1;
}

.crm-toolbar-right {
  display: flex;
  gap: 12px;
  align-items: center;
}

.crm-filter-select {
  padding: 6px 10px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
}

.crm-filter-select:focus {
  border-color: var(--accent);
  outline: none;
}

.search-box-sm {
  max-width: 250px;
}

.search-box-sm input {
  padding: 6px 10px;
  font-size: 13px;
}

.crm-result-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---- View Toggle ---- */
.view-toggle {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.view-toggle-btn {
  padding: 6px 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
}

.view-toggle-btn:hover {
  color: var(--text-primary);
}

.view-toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ---- KPI Dashboard ---- */
.crm-dashboard {
  display: flex;
  gap: 2px;
  padding: 12px 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.kpi-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px;
  min-width: 80px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
}

.kpi-card:hover {
  background: rgba(255, 255, 255, 0.05);
}

.kpi-card.kpi-active {
  background: rgba(59, 130, 246, 0.1);
}

.kpi-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.kpi-novo { color: #94a3b8; }
.kpi-contato { color: #60a5fa; }
.kpi-proposta { color: #fbbf24; }
.kpi-negociacao { color: #a78bfa; }
.kpi-fechado { color: #4ade80; }

.kpi-divider {
  width: 1px;
  background: var(--border);
  margin: 0 8px;
  align-self: stretch;
}

.kpi-alert .kpi-value {
  color: var(--danger);
}

/* ---- CRM Views ---- */
.crm-view {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.crm-view.hidden {
  display: none;
}

/* ---- Table ---- */
.crm-table-wrapper {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 16px 16px;
}

.crm-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.crm-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-secondary);
}

.crm-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: default;
}

.crm-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.crm-table th.sortable:hover {
  color: var(--text-primary);
}

.crm-table th.sort-asc .sort-icon::after { content: ' \25B2'; }
.crm-table th.sort-desc .sort-icon::after { content: ' \25BC'; }

.crm-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  vertical-align: middle;
  color: var(--text-primary);
}

.crm-table tbody tr {
  transition: background 0.15s;
}

.crm-table tbody tr:hover {
  background: rgba(59, 130, 246, 0.05);
}

.crm-table tbody tr.selected {
  background: rgba(59, 130, 246, 0.1);
}

.crm-table .empresa-name {
  font-weight: 600;
  font-size: 13px;
  display: block;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-table .empresa-razao {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-table .cell-truncate {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-table .icon-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  transition: color 0.15s;
}

.crm-table .icon-link:hover {
  color: var(--accent);
}

.crm-table .note-cell {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
}

.crm-table .note-cell:hover {
  color: var(--text-secondary);
}

/* ---- Temperature Badge ---- */
.temp-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.1s;
  user-select: none;
}

.temp-badge:hover {
  transform: scale(1.05);
}

.temp-quente {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.temp-morno {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.temp-frio {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}

.temp-none {
  background: rgba(100, 116, 139, 0.15);
  color: #94a3b8;
}

/* ---- Stage Badge ---- */
.stage-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  user-select: none;
  transition: transform 0.1s;
}

.stage-badge:hover {
  transform: scale(1.05);
}

.stage-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stage-novo { background: rgba(100,116,139,0.15); color: #94a3b8; }
.stage-novo::before { background: #64748b; }

.stage-contato { background: rgba(59,130,246,0.15); color: #60a5fa; }
.stage-contato::before { background: #3b82f6; }

.stage-proposta { background: rgba(245,158,11,0.15); color: #fbbf24; }
.stage-proposta::before { background: #f59e0b; }

.stage-negociacao { background: rgba(139,92,246,0.15); color: #a78bfa; }
.stage-negociacao::before { background: #8b5cf6; }

.stage-fechado { background: rgba(34,197,94,0.15); color: #4ade80; }
.stage-fechado::before { background: #22c55e; }

.stage-perdido { background: rgba(239,68,68,0.15); color: #f87171; }
.stage-perdido::before { background: #ef4444; }

/* Stage dropdown (inline) */
.stage-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 50;
  min-width: 160px;
  padding: 4px 0;
  margin-top: 4px;
}

.stage-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.1s;
}

.stage-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.stage-dropdown-item .stage-dot-sm {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- Follow-up Status ---- */
.followup-overdue {
  color: var(--danger);
  font-weight: 600;
  animation: pulse-subtle 2s infinite;
}

.followup-today {
  color: var(--warning);
  font-weight: 600;
}

.followup-future {
  color: var(--text-secondary);
}

.followup-none {
  color: var(--text-muted);
}

.followup-cell {
  cursor: pointer;
  white-space: nowrap;
}

.followup-cell:hover {
  text-decoration: underline;
}

@keyframes pulse-subtle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ---- Kanban Board ---- */
.kanban-board {
  display: flex;
  gap: 12px;
  padding: 0 16px 16px;
  overflow-x: auto;
  flex: 1;
  align-items: flex-start;
}

.kanban-column {
  min-width: 260px;
  max-width: 300px;
  flex: 1;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 220px);
  transition: border-color 0.2s, background 0.2s;
}

.kanban-column.drag-over {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.05);
}

.kanban-column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  border-radius: var(--radius) var(--radius) 0 0;
}

.kanban-column-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

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

.kanban-column-count {
  background: var(--bg-input);
  color: var(--text-secondary);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.kanban-column-body {
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

/* ---- Kanban Card ---- */
.kanban-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  cursor: grab;
  transition: transform 0.15s, box-shadow 0.15s;
}

.kanban-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.kanban-card.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
  cursor: grabbing;
}

.kanban-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.kanban-card-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.kanban-card-body {
  font-size: 12px;
  color: var(--text-secondary);
}

.kanban-card-field {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.kanban-card-label {
  color: var(--text-muted);
}

.kanban-card-note {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kanban-card-footer {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* ---- WhatsApp Button ---- */
.btn-whatsapp {
  background: rgba(37, 211, 102, 0.15) !important;
  color: #25d366 !important;
  border-color: rgba(37, 211, 102, 0.3) !important;
  text-decoration: none;
  font-weight: 600;
}
.btn-whatsapp:hover {
  background: rgba(37, 211, 102, 0.3) !important;
}

/* ---- Modal Small ---- */
.modal-sm {
  max-width: 480px;
}

.note-empresa-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--accent);
}

.note-history {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.note-entry {
  padding: 8px 12px;
  background: var(--bg-input);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 12px;
}

.note-entry-date {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.note-entry-text {
  color: var(--text-secondary);
}

.note-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}

.note-input:focus {
  border-color: var(--accent);
  outline: none;
}

/* ---- Follow-up Quick Dates ---- */
.followup-quick-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

/* ---- Danger Button ---- */
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: #dc2626;
}

/* ---- Bulk Actions Bar ---- */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-card);
  border-top: 2px solid var(--accent);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}

.bulk-bar.hidden {
  display: none;
}

.bulk-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

/* ---- Pipeline Button (in ficha modal) ---- */
.btn-pipeline {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 12px;
}

.btn-pipeline:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.btn-pipeline.in-pipeline {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  cursor: default;
  transform: none;
  box-shadow: none;
}

/* ---- Pipeline Marker (golden border on map) ---- */
.marker-pin.in-pipeline {
  border-color: #f59e0b !important;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

/* ---- Empty State ---- */
.crm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  flex: 1;
}

.crm-empty.hidden {
  display: none;
}

.crm-empty-icon {
  margin-bottom: 20px;
  opacity: 0.5;
}

.crm-empty h3 {
  font-size: 18px;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.crm-empty p {
  font-size: 14px;
  color: var(--text-muted);
}

.crm-empty a {
  color: var(--accent);
  text-decoration: none;
}

.crm-empty a:hover {
  text-decoration: underline;
}

/* ---- Toast notification ---- */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 5000;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease-out;
}

.toast.toast-success {
  border-color: var(--success);
  color: var(--success);
}

.toast.toast-error {
  border-color: var(--danger);
  color: var(--danger);
}

@keyframes toastIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---- Responsive ---- */
@media (max-width: 1400px) {
  .col-nota { display: none; }
}

@media (max-width: 1200px) {
  .col-cnpj, .col-bairro { display: none; }
}

@media (max-width: 900px) {
  .col-site, .col-gmaps, .col-followup { display: none; }
  .crm-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .crm-toolbar-right {
    justify-content: space-between;
  }
}

@media (max-width: 768px) {
  .col-cnpj, .col-bairro, .col-site,
  .col-gmaps, .col-nota { display: none; }

  .crm-dashboard {
    padding: 8px 12px;
  }

  .kpi-card {
    padding: 6px 10px;
    min-width: 60px;
  }

  .kpi-value {
    font-size: 16px;
  }

  .kpi-label {
    font-size: 9px;
  }

  .kanban-column {
    min-width: 220px;
  }

  .crm-table td, .crm-table th {
    padding: 8px 6px;
  }

  .bulk-bar {
    flex-wrap: wrap;
    gap: 6px;
  }

  .header-nav {
    position: static;
    transform: none;
    margin: 0 auto;
  }

  .page-crm #header {
    flex-wrap: wrap;
    height: auto;
    padding-bottom: 0;
  }

  .crm-layout {
    height: calc(100vh - 90px);
    margin-top: 90px;
  }
}
