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

:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-dark: #1e3a8a;
  --accent: #0ea5e9;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #273549;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --transition: .25s ease;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--primary-light); border-radius: 3px; }

/* ===== LOGIN ===== */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 60% 40%, #1e3a8a 0%, #0f172a 70%);
  z-index: 1000;
  transition: opacity .4s, visibility .4s;
}

#login-screen.hidden { opacity: 0; visibility: hidden; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3rem 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo img {
  height: 60px;
  margin-bottom: .75rem;
}

.login-logo h1 {
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, #60a5fa, #0ea5e9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-logo p { font-size: .85rem; color: var(--text-muted); }

.form-group { margin-bottom: 1.25rem; }

.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .4rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.form-group input {
  width: 100%;
  padding: .75rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: .95rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-group input:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}

.btn-login {
  width: 100%;
  padding: .85rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  margin-top: .5rem;
}

.btn-login:hover { opacity: .9; transform: translateY(-1px); }
.btn-login:active { transform: translateY(0); }
.btn-login:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.login-error {
  margin-top: 1rem;
  padding: .7rem 1rem;
  background: rgba(239,68,68,.15);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 8px;
  color: #fca5a5;
  font-size: .85rem;
  text-align: center;
  display: none;
}

/* ===== HEADER ===== */
header {
  position: sticky; top: 0;
  background: rgba(15,23,42,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  padding: 0 2rem;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 64px;
  gap: 2rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}

.brand-dot {
  width: 10px; height: 10px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 8px var(--accent); }
  50% { box-shadow: 0 0 18px var(--accent); }
}

nav {
  display: flex;
  gap: .25rem;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

nav::-webkit-scrollbar { display: none; }

nav a {
  padding: .4rem .9rem;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}

nav a:hover { background: var(--surface2); color: var(--text); }
nav a.active { background: var(--primary); color: #fff; }

.header-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-shrink: 0;
}

.btn-refresh {
  padding: .4rem .9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: .85rem;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: .4rem;
}

.btn-refresh:hover { border-color: var(--primary-light); color: var(--text); }

.btn-logout {
  padding: .4rem .9rem;
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: 6px;
  color: #fca5a5;
  font-size: .85rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-logout:hover { background: rgba(239,68,68,.2); }

/* ===== MAIN CONTENT ===== */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* ===== SECTION HEADER ===== */
.section-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

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

.section-icon.blue { background: rgba(59,130,246,.15); }
.section-icon.green { background: rgba(16,185,129,.15); }
.section-icon.yellow { background: rgba(245,158,11,.15); }
.section-icon.purple { background: rgba(139,92,246,.15); }
.section-icon.red { background: rgba(239,68,68,.15); }

.section-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.section-header p {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: .1rem;
}

/* ===== DASHBOARD SECTIONS ===== */
.dashboard-section {
  margin-bottom: 3rem;
  scroll-margin-top: 80px;
}

/* ===== KPI CARDS ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}

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

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.kpi-card.blue::before { background: linear-gradient(90deg, var(--primary), var(--accent)); }
.kpi-card.green::before { background: linear-gradient(90deg, var(--success), #34d399); }
.kpi-card.yellow::before { background: linear-gradient(90deg, var(--warning), #fbbf24); }
.kpi-card.purple::before { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }

.kpi-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .5rem;
}

.kpi-value {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}

.kpi-sub {
  font-size: .78rem;
  color: var(--text-dim);
  margin-top: .4rem;
}

.kpi-icon {
  position: absolute;
  top: 1.25rem; right: 1.25rem;
  font-size: 1.6rem;
  opacity: .3;
}

/* ===== CHART CARDS ===== */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
  gap: 1.5rem;
}

.chart-grid.single { grid-template-columns: 1fr; }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.chart-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
}

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

.chart-card-header span {
  font-size: .75rem;
  color: var(--text-dim);
  margin-top: .2rem;
}

.chart-badge {
  font-size: .7rem;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-weight: 600;
  background: rgba(59,130,246,.15);
  color: var(--primary-light);
}

.chart-wrapper { position: relative; height: 280px; }

/* ===== TABLE ===== */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: .75rem;
}

.table-toolbar h3 {
  font-size: 1rem;
  font-weight: 600;
}

.search-box {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .4rem .8rem;
  transition: border-color var(--transition);
}

.search-box:focus-within { border-color: var(--primary-light); }

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: .88rem;
  width: 200px;
}

.search-box input::placeholder { color: var(--text-dim); }

.search-icon { color: var(--text-dim); font-size: .9rem; }

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

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

thead tr {
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

thead th {
  padding: .85rem 1.25rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid rgba(51,65,85,.5);
  transition: background var(--transition);
}

tbody tr:hover { background: var(--surface2); }
tbody tr:last-child { border-bottom: none; }

td {
  padding: .85rem 1.25rem;
  color: var(--text);
  vertical-align: middle;
}

.tag {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
}

.tag.whatsapp { background: rgba(16,185,129,.15); color: #34d399; }
.tag.form { background: rgba(59,130,246,.15); color: #60a5fa; }
.tag.phone { background: rgba(245,158,11,.15); color: #fbbf24; }
.tag.other { background: rgba(100,116,139,.15); color: #94a3b8; }

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .85rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: .82rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: .5rem;
}

.pagination {
  display: flex;
  gap: .4rem;
}

.pagination button {
  padding: .3rem .65rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: .8rem;
  cursor: pointer;
  transition: all var(--transition);
}

.pagination button:hover { border-color: var(--primary-light); color: var(--text); }
.pagination button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

/* ===== LOADING SKELETON ===== */
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.toast {
  padding: .8rem 1.2rem;
  border-radius: 8px;
  font-size: .88rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: slideIn .3s ease;
  max-width: 340px;
}

.toast.success { background: rgba(16,185,129,.9); color: #fff; }
.toast.error   { background: rgba(239,68,68,.9);  color: #fff; }
.toast.info    { background: rgba(59,130,246,.9);  color: #fff; }

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

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; opacity: .5; }
.empty-state p { font-size: .9rem; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  main { padding: 1rem; }
  .chart-grid { grid-template-columns: 1fr; }
  nav { display: none; }
  .header-inner { gap: 1rem; }
  .kpi-value { font-size: 1.8rem; }
}

/* ===== LAST UPDATED ===== */
.last-updated {
  font-size: .72rem;
  color: var(--text-dim);
  text-align: right;
  margin-top: .5rem;
}
