/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1C3D5C;
  --primary-dark: #102840;
  --accent: #00B4C6;
  --accent-hover: #009BB0;
  --accent-light: #E0F7FA;
  --text-dark: #1A2E3D;
  --text-gray: #5A6A7A;
  --bg-light: #F4F8FC;
  --white: #ffffff;
  --shadow: 0 2px 12px rgba(28, 61, 92, 0.1);
  --radius: 10px;
  --sidebar-width: 240px;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text-dark);
  background: var(--bg-light);
  font-size: 14px;
  line-height: 1.5;
}

img { max-width: 100%; display: block; }

/* ===== LOGIN SCREEN ===== */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--primary-dark) 0%, var(--primary) 100%);
  padding: 20px;
}

.login-card {
  background: var(--white);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-logo {
  height: 48px;
  margin: 0 auto 8px;
  object-fit: contain;
}

.login-title {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-gray);
  font-size: 0.85rem;
  margin-bottom: 32px;
}

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

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #e5e9ee;
  border-radius: var(--radius);
  font-size: 0.93rem;
  color: var(--text-dark);
  background: var(--bg-light);
  transition: border-color 0.2s;
  outline: none;
  font-family: inherit;
}

.form-group input:focus {
  border-color: var(--accent);
  background: var(--white);
}

.form-group input[readonly] {
  opacity: 0.6;
  cursor: default;
}

.btn-login {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  margin-top: 8px;
}

.btn-login:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.login-error {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #dc2626;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-top: 12px;
  display: none;
}

.login-error.visible {
  display: block;
}

/* ===== DASHBOARD LAYOUT ===== */
#dashboard-screen {
  display: none;
  min-height: 100vh;
}

#dashboard-screen.visible {
  display: block;
}

.admin-header {
  background: var(--primary-dark);
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.header-logo {
  height: 32px;
  object-fit: contain;
  filter: brightness(1.05);
}

.header-spacer { flex: 1; }

.header-info {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.82rem;
  margin-right: 20px;
}

.btn-logout {
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-logout:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--white);
}

.admin-content {
  padding: 32px 28px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Section titles */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title i {
  color: var(--accent);
}

.dashboard-divider {
  height: 1px;
  background: rgba(28, 61, 92, 0.08);
  margin: 36px 0;
}

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 36px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(28, 61, 92, 0.06);
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: transform 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.stat-icon.blue { background: #e8f0fe; color: #1a73e8; }
.stat-icon.teal { background: var(--accent-light); color: var(--accent); }
.stat-icon.green { background: #e6f4ea; color: #1e8e3e; }
.stat-icon.orange { background: #fef3e2; color: #f9ab00; }

.stat-body { flex: 1; }

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-dark);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-gray);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* ===== FUNNEL ===== */
.funnel-table {
  width: 100%;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid rgba(28, 61, 92, 0.06);
}

.funnel-table table {
  width: 100%;
  border-collapse: collapse;
}

.funnel-table th {
  background: var(--primary);
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
}

.funnel-table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(28, 61, 92, 0.05);
  vertical-align: middle;
}

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

.funnel-table tr:hover td {
  background: var(--bg-light);
}

.funnel-step-name {
  font-weight: 600;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.funnel-step-name i {
  color: var(--accent);
  width: 16px;
  text-align: center;
}

.funnel-count {
  font-weight: 700;
  color: var(--text-dark);
}

.funnel-bar-cell { width: 50%; min-width: 200px; }

.funnel-bar-wrap {
  background: #eef2f6;
  border-radius: 4px;
  height: 20px;
  overflow: hidden;
  position: relative;
}

.funnel-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  border-radius: 4px;
  transition: width 0.6s ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  min-width: 30px;
}

.funnel-bar-pct {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--white);
  white-space: nowrap;
}

/* ===== QUALIFICATION CHARTS ===== */
.qual-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 36px;
}

.qual-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(28, 61, 92, 0.06);
  padding: 20px;
}

.qual-card-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-gray);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.qual-card-title i { color: var(--accent); }

.qual-bar-item {
  margin-bottom: 12px;
}

.qual-bar-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.qual-bar-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dark);
}

.qual-bar-count {
  font-size: 0.78rem;
  color: var(--text-gray);
  font-weight: 600;
}

.qual-bar-track {
  height: 8px;
  background: #eef2f6;
  border-radius: 4px;
  overflow: hidden;
}

.qual-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #0099aa);
  border-radius: 4px;
  transition: width 0.6s ease;
  min-width: 4px;
}

.qual-empty {
  color: var(--text-gray);
  font-size: 0.85rem;
  text-align: center;
  padding: 16px 0;
}

/* ===== LEADS TABLE ===== */
.leads-section {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(28, 61, 92, 0.06);
  overflow: hidden;
}

.leads-header {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(28, 61, 92, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.leads-header .section-title { margin: 0; }

.leads-count {
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 50px;
}

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

.leads-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.leads-table th {
  background: var(--primary);
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.leads-table th:hover {
  background: var(--primary-dark);
  color: var(--white);
}

.leads-table th.sorted-asc::after { content: ' ↑'; color: var(--accent); }
.leads-table th.sorted-desc::after { content: ' ↓'; color: var(--accent); }

.leads-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(28, 61, 92, 0.05);
  font-size: 0.85rem;
  color: var(--text-dark);
  white-space: nowrap;
}

.leads-table tr:nth-child(even) td {
  background: rgba(244, 248, 252, 0.5);
}

.leads-table tr:hover td {
  background: var(--accent-light);
}

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

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 50px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-sim { background: #e6f4ea; color: #1e8e3e; }
.badge-nao { background: #fef3e2; color: #f9ab00; }
.badge-demo { background: var(--accent-light); color: var(--accent); }
.badge-nao-cont { background: #fef2f2; color: #dc2626; }
.badge-none { background: #f0f0f0; color: var(--text-gray); }

.no-leads {
  text-align: center;
  padding: 48px;
  color: var(--text-gray);
}

.no-leads i {
  font-size: 2.5rem;
  color: #d0d9e2;
  margin-bottom: 12px;
}

/* ===== LOADING ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.4s;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .qual-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .admin-content { padding: 20px 16px; }
  .admin-header { padding: 0 16px; }
  .header-info { display: none; }
  .login-card { padding: 32px 24px; }
}

@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ===== TABS ===== */
.admin-tabs {
  background: var(--white);
  border-bottom: 2px solid rgba(28, 61, 92, 0.08);
  display: flex;
  padding: 0 28px;
  position: sticky;
  top: 60px;
  z-index: 90;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.tab-btn {
  padding: 14px 20px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-gray);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: all 0.2s;
  margin-bottom: -2px;
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn i { font-size: 0.85rem; }

/* ===== TAB PANELS ===== */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== SECTION HINT ===== */
.section-hint {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-gray);
  margin-left: 4px;
}

/* ===== FUNNEL CLICKABLE ROWS ===== */
.funnel-row {
  cursor: pointer;
  transition: background 0.15s;
}
.funnel-row:hover td { background: var(--accent-light) !important; }
.funnel-drill {
  width: 32px;
  text-align: center;
  color: var(--text-gray);
  font-size: 0.75rem;
}
.funnel-row:hover .funnel-drill { color: var(--accent); }

/* ===== DETAIL DRAWER ===== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 25, 41, 0.45);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.drawer-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.detail-drawer {
  position: fixed;
  top: 0;
  right: -640px;
  width: 640px;
  max-width: 95vw;
  height: 100vh;
  background: var(--white);
  z-index: 210;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0,0,0,0.18);
  transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.detail-drawer.open { right: 0; }

.drawer-header {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(28, 61, 92, 0.08);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: var(--primary);
}

.drawer-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--white);
}

.drawer-subtitle {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
  margin-top: 2px;
}

.drawer-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: rgba(255,255,255,0.8);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.drawer-close:hover { background: rgba(255,255,255,0.2); color: #fff; }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* ===== DRAWER TABLE ===== */
.drawer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}
.drawer-table th {
  background: var(--bg-light);
  color: var(--text-gray);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  padding: 10px 16px;
  text-align: left;
  position: sticky;
  top: 0;
}
.drawer-table td {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(28, 61, 92, 0.05);
  color: var(--text-dark);
  vertical-align: top;
}
.drawer-table tr:hover td { background: var(--bg-light); }
.drawer-table tr:last-child td { border-bottom: none; }

.session-id {
  font-family: monospace;
  font-size: 0.78rem;
  color: var(--text-gray);
}

.event-data { max-width: 200px; }

.data-chip {
  display: inline-block;
  background: var(--accent-light);
  color: var(--primary);
  font-size: 0.72rem;
  padding: 1px 7px;
  border-radius: 4px;
  margin: 1px 2px;
  font-weight: 500;
}

/* ===== VISITORS TABLE ===== */
.event-count-badge {
  background: var(--bg-light);
  color: var(--text-dark);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 50px;
  border: 1px solid rgba(28,61,92,0.1);
}

.badge-teal { background: var(--accent-light); color: var(--accent); }

/* ===== REFRESH BUTTON ===== */
.btn-refresh {
  padding: 8px 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  margin-right: 10px;
}
.btn-refresh:hover { background: rgba(255,255,255,0.15); }
