/* ============================================================
   GESTOR DE TRÁFEGO — MAIN.CSS — Dark Theme Profissional
   ============================================================ */

/* --- Variáveis de Design --- */
:root {
  --bg-base:       #0D1117;
  --bg-surface:    #161B22;
  --bg-card:       #21262D;
  --bg-hover:      #2D333B;
  --border:        #30363D;
  --border-light:  #444C56;

  --text-primary:   #E6EDF3;
  --text-secondary: #8B949E;
  --text-muted:     #6E7681;

  --blue:    #1877F2;
  --blue-dk: #0d5fd4;
  --green:   #00C851;
  --red:     #FF4444;
  --yellow:  #FFB300;
  --orange:  #f97316;
  --purple:  #7c3aed;
  --cyan:    #06b6d4;

  --sidebar-w: 240px;
  --header-h:  64px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow:    0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);

  --font: 'Inter', system-ui, sans-serif;
  --transition: 0.2s ease;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

a { color: var(--blue); text-decoration: none; }
button { font-family: var(--font); cursor: pointer; border: none; outline: none; }
input, select, textarea { font-family: var(--font); }

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 200;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--blue), #7c3aed);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: #fff;
}

.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--blue), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-nav {
  padding: 12px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(24,119,242,0.15);
  color: var(--blue);
  font-weight: 600;
}

.nav-item i { width: 18px; text-align: center; font-size: 0.95rem; }
.nav-divider { height: 1px; background: var(--border); margin: 8px 4px; }

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 2s infinite;
}

.status-dot.online  { background: var(--green); }
.status-dot.offline { background: var(--red); animation: none; }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* --- Main Wrapper --- */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Header --- */
.top-header {
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0; z-index: 100;
  gap: 16px;
}

.header-left  { display: flex; align-items: center; gap: 12px; }
.header-center { display: flex; align-items: center; gap: 12px; flex: 1; justify-content: center; }
.header-right { display: flex; align-items: center; gap: 12px; }

.btn-menu {
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.1rem;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: none;
}

.breadcrumb {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.select-account {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  outline: none;
  min-width: 200px;
}

.date-range-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  color: var(--text-secondary);
}

.date-range-input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  width: 180px;
  outline: none;
}

.sync-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.countdown-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
}

.btn-sync {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--blue), var(--blue-dk));
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity var(--transition);
}

.btn-sync:hover { opacity: 0.85; }
.btn-sync:disabled { opacity: 0.4; cursor: not-allowed; }

.notification-btn {
  position: relative;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1rem;
  transition: all var(--transition);
}

.notification-btn:hover { border-color: var(--blue); color: var(--blue); }

.badge-count {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--red);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
}

/* --- Content Area --- */
.content-area {
  padding: 24px;
  flex: 1;
}

.section { display: none; }
.section.active { display: block; }

.section-title {
  margin-bottom: 24px;
}

.section-title h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.section-title p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* --- KPI Grid --- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
}

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

.kpi-card.kpi-danger { border-color: rgba(255,68,68,0.3); }

.kpi-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  color: #fff;
  flex-shrink: 0;
}

.kpi-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.kpi-value-sm { font-size: 1rem; }

.kpi-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* --- Charts Grid --- */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.charts-grid + .charts-grid {
  grid-template-columns: 1fr 1fr;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}

.chart-card.chart-wide { grid-column: 1 / -1; }

.chart-header {
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* --- Tables --- */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 24px;
}

.table-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.table-card-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.table-responsive { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.data-table thead th {
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-align: left;
}

.data-table tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(48,54,61,0.5);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* --- Status Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-active   { background: rgba(0,200,81,0.15);  color: var(--green); }
.badge-paused   { background: rgba(255,179,0,0.15); color: var(--yellow); }
.badge-archived { background: rgba(110,118,129,0.2); color: var(--text-secondary); }
.badge-error    { background: rgba(255,68,68,0.15);  color: var(--red); }

/* --- Score Indicator --- */
.score-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 0.82rem;
}

.score-excellent { color: var(--green); }
.score-good      { color: #84cc16; }
.score-warning   { color: var(--yellow); }
.score-critical  { color: var(--red); }

/* --- Buttons --- */
.btn-export {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  transition: all var(--transition);
}

.btn-export:hover { border-color: var(--green); color: var(--green); }

.filter-select {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  outline: none;
}

.table-filters { display: flex; gap: 8px; align-items: center; }

.text-center { text-align: center; color: var(--text-secondary); padding: 32px !important; }

/* --- Loading --- */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.84rem;
  color: var(--text-primary);
  min-width: 280px;
  max-width: 380px;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.toast.toast-success { border-left-color: var(--green); }
.toast.toast-error   { border-left-color: var(--red); }
.toast.toast-warning { border-left-color: var(--yellow); }

@keyframes toastIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* --- Drawer --- */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 300;
}

.drawer {
  position: fixed;
  top: 0; right: -500px;
  width: 480px;
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: 301;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer.open { right: 0; }
.drawer-overlay.open { display: block; }

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

.drawer-header h3 { font-size: 1rem; font-weight: 600; }

.drawer-close {
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.drawer-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* --- Settings --- */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
}

.settings-card-wide { grid-column: 1 / -1; }

.settings-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.settings-card-header h3 { font-size: 0.95rem; font-weight: 600; flex: 1; }

.api-status {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.api-status.connected { color: var(--green); }
.api-status.error     { color: var(--red); }

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition);
}

.form-input:focus { border-color: var(--blue); }

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn .form-input { flex: 1; }

.btn-validate {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  transition: all var(--transition);
}

.btn-validate:hover { border-color: var(--blue); color: var(--blue); }

.btn-save {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--blue), var(--blue-dk));
  color: #fff;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  width: 100%;
  justify-content: center;
  transition: opacity var(--transition);
  margin-top: 6px;
}

.btn-save:hover { opacity: 0.85; }

.btn-sync-all {
  background: linear-gradient(135deg, var(--cyan), #0891b2);
  color: #fff;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity var(--transition);
}

.btn-sync-all:hover { opacity: 0.85; }

/* --- Sync Log --- */
.sync-log {
  max-height: 260px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  font-size: 0.78rem;
}

.log-line {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(48,54,61,0.4);
  align-items: flex-start;
}

.log-time { color: var(--text-muted); white-space: nowrap; }
.log-source { font-weight: 600; min-width: 70px; }
.log-msg { color: var(--text-secondary); flex: 1; }

.log-success .log-source { color: var(--green); }
.log-error   .log-source { color: var(--red); }
.log-warning .log-source { color: var(--yellow); }
.log-running .log-source { color: var(--blue); }

/* --- Leads Section --- */
.insights-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
}

.insights-main { display: flex; flex-direction: column; gap: 20px; }

.insights-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  align-self: start;
  position: sticky;
  top: calc(var(--header-h) + 24px);
  max-height: calc(100vh - var(--header-h) - 48px);
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--yellow);
}

.insights-list {
  overflow-y: auto;
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.insight-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.insight-card.insight-error   { border-left: 3px solid var(--red); }
.insight-card.insight-warning { border-left: 3px solid var(--yellow); }
.insight-card.insight-success { border-left: 3px solid var(--green); }
.insight-card.insight-info    { border-left: 3px solid var(--blue); }

/* --- Lead Timeline --- */
.lead-timeline {
  max-height: 400px;
  overflow-y: auto;
  padding: 8px 0;
}

.lead-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(48,54,61,0.4);
  transition: background var(--transition);
}

.lead-item:hover { background: var(--bg-hover); }

.lead-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.lead-info { flex: 1; min-width: 0; }
.lead-name { font-size: 0.84rem; font-weight: 600; color: var(--text-primary); }
.lead-campaign { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.lead-status-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  white-space: nowrap;
}

.lead-urgent { background: rgba(255,68,68,0.12); color: var(--red); }
.lead-new    { background: rgba(24,119,242,0.12); color: var(--blue); }
.lead-ok     { background: rgba(0,200,81,0.12);  color: var(--green); }

.live-badge {
  font-size: 0.7rem;
  color: var(--red);
  font-weight: 700;
  animation: pulse 1.5s infinite;
}

/* --- Responsive --- */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .insights-layout { grid-template-columns: 1fr; }
  .insights-panel { position: static; max-height: 400px; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .btn-menu { display: flex; }
  .settings-grid { grid-template-columns: 1fr; }
  .header-center { display: none; }
}

@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .content-area { padding: 16px; }
}
