/* =========================================
   BeeFit CRM Dashboard — Design System
   ========================================= */

/* ---------- CSS Variables ---------- */
:root {
  /* Brand Colors — BeeFit */
  --brand-yellow: #FFCC00;
  --brand-yellow-hover: #FFD633;
  --brand-red: #E63946;
  --brand-blue: #1D4ED8;

  /* Dark Theme */
  --bg-primary: #0F0F14;
  --bg-secondary: #16161D;
  --bg-card: #1C1C26;
  --bg-card-hover: #22222E;
  --bg-glass: rgba(28, 28, 38, 0.7);
  --bg-header: rgba(15, 15, 20, 0.85);

  /* Borders */
  --border-color: rgba(255, 255, 255, 0.06);
  --border-active: rgba(255, 204, 0, 0.3);

  /* Text */
  --text-primary: #F0F0F5;
  --text-secondary: #9898A6;
  --text-muted: #5C5C6E;
  --text-brand: var(--brand-yellow);

  /* Stage Colors */
  --stage-novo: #33FF00;
  --stage-1rec: #57EDC5;
  --stage-2rec: #8B4AD6;
  --stage-3rec: #FC005A;
  --stage-geladeira: #5C5C6E;

  /* Status */
  --status-overdue: #E63946;
  --status-warning: #FF8C00;
  --status-ok: #22C55E;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow-yellow: 0 0 20px rgba(255, 204, 0, 0.15);
  --shadow-glow-red: 0 0 20px rgba(230, 57, 70, 0.2);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ---------- Header ---------- */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-xl);
  background: var(--bg-header);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  gap: var(--space-lg);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-shrink: 0;
}

.header-logo {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(255, 204, 0, 0.3));
  transition: transform var(--transition-base);
}
.header-logo:hover {
  transform: scale(1.08) rotate(-3deg);
}

.header-title h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.header-subtitle {
  font-size: 0.73rem;
  color: var(--text-secondary);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ---------- Navigation ---------- */
#main-nav {
  display: flex;
  gap: var(--space-xs);
  background: rgba(255, 255, 255, 0.04);
  padding: 3px;
  border-radius: var(--radius-lg);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  white-space: nowrap;
}

.nav-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.nav-btn.active {
  color: var(--bg-primary);
  background: var(--brand-yellow);
  box-shadow: var(--shadow-glow-yellow);
}

.nav-btn.active svg {
  stroke: var(--bg-primary);
}

.nav-badge {
  background: var(--status-overdue);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  animation: pulse-badge 2s ease-in-out infinite;
}

@keyframes pulse-badge {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.85; }
}

/* ---------- Header Right ---------- */
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  flex-shrink: 0;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.filter-group label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.filter-group select {
  padding: var(--space-sm) var(--space-md);
  padding-right: var(--space-xl);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239898A6' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color var(--transition-base);
  min-width: 150px;
}

.filter-group select:hover,
.filter-group select:focus {
  border-color: var(--brand-yellow);
  outline: none;
}

.last-update {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.update-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-ok);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

/* ---------- Main ---------- */
#app-main {
  padding: var(--space-lg) var(--space-xl);
  max-width: 1600px;
  margin: 0 auto;
}

/* ---------- KPI Bar ---------- */
.kpi-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.kpi-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  transition: all var(--transition-base);
}

.kpi-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-card.kpi-danger {
  border-color: rgba(230, 57, 70, 0.2);
}

.kpi-card.kpi-danger:hover {
  box-shadow: var(--shadow-glow-red);
  border-color: rgba(230, 57, 70, 0.4);
}

.kpi-card.kpi-danger .kpi-value {
  color: var(--status-overdue);
}

.kpi-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: rgba(255, 204, 0, 0.1);
  color: var(--brand-yellow);
  flex-shrink: 0;
}

.kpi-card.kpi-danger .kpi-icon {
  background: rgba(230, 57, 70, 0.1);
  color: var(--status-overdue);
}

.organic-icon {
  background: rgba(34, 197, 94, 0.1) !important;
  color: var(--status-ok) !important;
}

.meta-icon {
  background: rgba(29, 78, 216, 0.1) !important;
  color: var(--brand-blue) !important;
}

.kpi-data {
  display: flex;
  flex-direction: column;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.kpi-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
  font-weight: 500;
}

/* ---------- Views ---------- */
.view {
  display: none;
}
.view.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

/* ---------- Kanban Board ---------- */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-md);
  min-height: 400px;
}

.kanban-column {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kanban-column-header {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.kanban-column-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

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

.kanban-column-name {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.kanban-column-counts {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.kanban-count {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.kanban-overdue-count {
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  background: var(--status-overdue);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  animation: pulse-badge 2s ease-in-out infinite;
}

.kanban-column-body {
  padding: var(--space-sm);
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-height: calc(100vh - 300px);
}

/* ---------- Lead Card (Kanban) ---------- */
.lead-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  cursor: default;
  transition: all var(--transition-base);
  position: relative;
}

.lead-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.lead-card.overdue {
  border-color: rgba(230, 57, 70, 0.4);
  box-shadow: var(--shadow-glow-red);
}

.lead-card.overdue::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--status-overdue), transparent);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.lead-card-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lead-card-assignee {
  font-size: 0.73rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: 4px;
}

.lead-card-assignee::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-yellow);
  flex-shrink: 0;
}

.lead-card-sla {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.lead-card-time {
  font-size: 0.7rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.lead-card-time.ok { color: var(--status-ok); }
.lead-card-time.warning { color: var(--status-warning); }
.lead-card-time.overdue { color: var(--status-overdue); }

.lead-card-link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.68rem;
  color: var(--brand-yellow);
  text-decoration: none;
  font-weight: 500;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.lead-card:hover .lead-card-link {
  opacity: 1;
}

.lead-card-link:hover {
  text-decoration: underline;
}

/* ---------- Overdue View ---------- */
.overdue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.overdue-header h2 {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--status-overdue);
}

.overdue-count {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.overdue-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* ---------- Overdue Card ---------- */
.overdue-card {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto auto;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-lg) var(--space-xl);
  background: var(--bg-card);
  border: 1px solid rgba(230, 57, 70, 0.15);
  border-radius: var(--radius-lg);
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.overdue-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--status-overdue);
}

.overdue-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(230, 57, 70, 0.3);
  transform: translateX(2px);
  box-shadow: var(--shadow-md);
}

.overdue-card-name {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.overdue-card-name strong {
  font-size: 0.95rem;
  font-weight: 600;
}

.overdue-card-name small {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.overdue-card-phone {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-family: 'Inter', monospace;
  letter-spacing: 0.02em;
}

.overdue-card-time {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.overdue-card-time strong {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--status-overdue);
}

.overdue-card-time small {
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Stage Badge */
.stage-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.stage-badge.novo_lead { background: rgba(51, 255, 0, 0.12); color: var(--stage-novo); }
.stage-badge.recontato-1 { background: rgba(87, 237, 197, 0.12); color: var(--stage-1rec); }
.stage-badge.recontato-2 { background: rgba(139, 74, 214, 0.12); color: var(--stage-2rec); }
.stage-badge.recontato-3 { background: rgba(252, 0, 90, 0.12); color: var(--stage-3rec); }
.stage-badge.geladeira { background: rgba(92, 92, 110, 0.12); color: var(--stage-geladeira); }

.overdue-card-assignee {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.overdue-card-assignee::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-yellow);
}

/* CTA Button */
.btn-chatwoot {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--brand-yellow);
  color: var(--bg-primary);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition-base);
  white-space: nowrap;
}

.btn-chatwoot:hover {
  background: var(--brand-yellow-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow-yellow);
}

.btn-chatwoot svg {
  width: 14px;
  height: 14px;
}

/* ---------- Origins View ---------- */
.origins-container {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: var(--space-2xl);
  max-width: 1000px;
}

.origins-chart-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
}

.origins-chart-wrapper h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: var(--space-lg);
}

.origins-period-filter {
  display: flex;
  gap: var(--space-xs);
  margin-bottom: var(--space-xl);
  background: rgba(255, 255, 255, 0.04);
  padding: 3px;
  border-radius: var(--radius-md);
  width: fit-content;
}

.period-btn {
  padding: var(--space-sm) var(--space-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-base);
}

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

.period-btn.active {
  background: var(--brand-yellow);
  color: var(--bg-primary);
}

.chart-container {
  position: relative;
  max-width: 350px;
  margin: 0 auto;
}

.origins-stats {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  justify-content: center;
}

.origin-stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  transition: all var(--transition-base);
}

.origin-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-active);
}

.origin-stat-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.origin-stat-dot.organico { background: var(--status-ok); }
.origin-stat-dot.meta { background: var(--brand-blue); }
.origin-stat-dot.desconhecido { background: var(--text-muted); }

.origin-stat-data {
  flex: 1;
}

.origin-stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.origin-stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.origin-stat-percent {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
}

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
  text-align: center;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-md);
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.9rem;
  font-weight: 500;
}

/* ---------- Loading Skeleton ---------- */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(90deg,
    var(--bg-card) 25%,
    var(--bg-card-hover) 50%,
    var(--bg-card) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .kanban-board {
    grid-template-columns: repeat(3, 1fr);
  }
  .kpi-bar {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  #app-header {
    flex-wrap: wrap;
    padding: var(--space-md);
  }
  .header-center {
    order: 3;
    width: 100%;
  }
  #main-nav {
    width: 100%;
    justify-content: center;
  }
  .kanban-board {
    grid-template-columns: repeat(2, 1fr);
  }
  .kpi-bar {
    grid-template-columns: repeat(2, 1fr);
  }
  .overdue-card {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }
  .origins-container {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  html { font-size: 14px; }
  #app-main { padding: var(--space-md); }
  .kanban-board {
    grid-template-columns: 1fr;
  }
  .kpi-bar {
    grid-template-columns: 1fr;
  }
  .nav-btn span.nav-text {
    display: none;
  }
}
.custom-date:hover { border-color: var(--brand-yellow) !important; }
.custom-date:focus { border-color: var(--brand-yellow) !important; box-shadow: 0 0 0 2px rgba(255, 204, 0, 0.2); }
