:root {
  /* Design Tokens - Modern Dark Premium */
  --bg: #030712;
  --panel: rgba(17, 24, 39, 0.7);
  --panel-solid: #111827;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f9fafb;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --glass-blur: 12px;
  --sidebar-w: 260px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 0% 0%, rgba(59, 130, 246, 0.1) 0%, transparent 40%),
    radial-gradient(circle at 100% 100%, rgba(37, 99, 235, 0.05) 0%, transparent 40%);
  font-family: "Inter", "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

/* Typography & Base */
h1,
h2,
h3 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.025em;
}

p {
  margin: 0;
  color: var(--muted);
}

button,
input,
select {
  font-family: inherit;
  outline: none;
}

.hidden {
  display: none !important;
}

/* Glassmorphism Card */
.card {
  background: var(--panel);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 24px;
  transition: var(--transition);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(to bottom right, #030712, #111827);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 40px;
  border-radius: 24px;
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
  font-size: 1.5rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-form label,
.form-grid label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

/* Inputs */
input,
select {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 0.95rem;
  transition: var(--transition);
}

select option {
  background-color: var(--bg);
  color: var(--text);
}

input:focus,
select:focus {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

/* Headers Ordenáveis */
th.sortable {
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
  white-space: nowrap;
}

th.sortable:hover {
  background: rgba(255, 255, 255, 0.05) !important;
  color: var(--text);
}

th.sortable::after {
  content: "↕";
  margin-left: 8px;
  opacity: 0.3;
  font-size: 0.8rem;
  display: inline-block;
  width: 12px;
}

th.sortable.asc::after {
  content: "↑";
  opacity: 1;
  color: var(--accent);
}

th.sortable.desc::after {
  content: "↓";
  opacity: 1;
  color: var(--accent);
}

/* Barra de Filtros da Tabela */
.table-filters {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 12px;
  border: 1px solid var(--line);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 500;
}

.filter-group input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Buttons */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--transition);
  border: none;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px -5px rgba(59, 130, 246, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* App Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--panel-solid);
  border-right: 1px solid var(--line);
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
}

.sidebar-brand {
  margin-bottom: 40px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 1.25rem;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  padding: 12px 16px;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: var(--transition);
  background: transparent;
  width: 100%;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.nav-item.is-active {
  color: var(--text);
  background: rgba(59, 130, 246, 0.1);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.2);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  opacity: 0.7;
}

.nav-item.is-active svg {
  color: var(--accent);
  opacity: 1;
}

.sidebar-footer {
  margin-top: auto;
  padding: 24px 16px 0;
  border-top: 1px solid var(--line);
}

.sidebar-user {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: white;
}

.user-details {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.user-name {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Content */
.content {
  flex: 1;
  padding: 40px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.view-panel {
  animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-head {
  margin-bottom: 32px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 8px;
}

/* Home / Widgets */
.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.home-charts {
  margin-top: 32px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.home-chart-card {
  padding: 18px;
}

.home-chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.home-chart-header h3 {
  font-size: 0.95rem;
}

.home-chart-header p {
  font-size: 0.78rem;
  margin-top: 2px;
}

.home-chart-header strong {
  font-size: 1.35rem;
  color: var(--text);
}

.home-chart-insight {
  font-size: 0.78rem;
  color: #d1d5db;
  margin-bottom: 10px;
  min-height: 20px;
}

.trend-svg {
  display: block;
  width: 100%;
  height: 160px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
}

.stat-card {
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 100px;
  height: 100px;
  background: var(--accent-gradient);
  opacity: 0.05;
  border-radius: 50%;
  transform: translate(30%, -30%);
}

.stat-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  margin: 4px 0;
  background: var(--text);
  -webkit-background-clip: text;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  align-items: end;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.kpi-card {
  padding: 18px;
}

.kpi-label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 1.8rem;
  line-height: 1;
}

/* Tables */
.table-container {
  overflow-x: auto;
  margin-top: 24px;
  border-radius: 16px;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th {
  text-align: left;
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--line);
}

td {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

tr:last-child td {
  border-bottom: none;
}

tr.contact-row-enriched td {
  background: rgba(16, 185, 129, 0.08);
}

tr.contact-row-enriched:hover td {
  background: rgba(16, 185, 129, 0.14);
}

.enriched-email-tag {
  display: inline-flex;
  align-items: center;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #d1fae5;
  background: rgba(16, 185, 129, 0.22);
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
}

.badge-info {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
}

/* Toasts */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 1000;
}

.toast {
  padding: 16px 24px;
  border-radius: 12px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Components */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  padding: 0;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.wa {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.icon-btn.email {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
}

.wa-action-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  z-index: 30;
  padding: 12px;
  border-radius: 12px;
  background: #0f172a;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.wa-action-title {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.wa-action-number {
  margin: 4px 0 10px;
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 700;
}

.wa-action-buttons {
  display: flex;
  gap: 8px;
}

.wa-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.wa-action-btn.secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-color: var(--line);
}

.wa-action-btn.primary {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.4);
}

.wa-action-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 1024px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 8px;
  }

  .nav-item {
    white-space: nowrap;
  }

  .sidebar-footer {
    display: none;
  }

  .content {
    padding: 24px;
  }

  .hero-stats {
    grid-template-columns: 1fr;
  }

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

  .kpi-grid {
    grid-template-columns: 1fr;
  }
}
