:root {
  --primary-blue: #2C2C83;
  --primary-violet: #7b67a7;
  --secondary-raspberry: #a2137b;
  --accent-white: #ffffff;
  --accent-purple: #7b67a7;
  --accent-light-purple: #e6e6fa;
  --text-light: #1a1a2e;
  --text-muted: #6b7280;
  --glass-bg: #ffffff;
  --glass-border: #e5e7eb;
  --sidebar-w: 240px;
  --radius-lg: 12px;
  --radius-md: 8px;
  --bg-main: #f4f6fb;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', 'Poppins', sans-serif;
  background: var(--bg-main);
  color: var(--text-light);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  letter-spacing: -0.01em;
  position: relative;
}

body::before {
  display: none;
}

/* --- AUTH GATE --- */
#authGate {
  position: fixed;
  inset: 0;
  background: var(--primary-blue);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  text-align: center;
  color: white;
}

#authGate::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url('../../texture.svg');
  opacity: 0.2;
  pointer-events: none;
}

#authGate img { width: 220px; filter: brightness(0) invert(1); animation: pulse 2s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.98); opacity: 0.8; } }

#authGate p { font-size: 1.1rem; opacity: 0.7; max-width: 400px; line-height: 1.6; }
.auth-error { color: #ef4444; background: rgba(239,68,68,0.08); padding: 1rem 2rem; border-radius: var(--radius-md); border: 1px solid rgba(239,68,68,0.3); display: none; }

/* --- LAYOUT --- */
#dashboard { display: none; width: 100%; min-height: 100vh; }

/* --- SIDEBAR --- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary-blue);
  border-right: none;
  display: flex;
  flex-direction: column;
  padding: 2.5rem 1.25rem;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  box-shadow: 4px 0 24px rgba(44,44,131,0.10);
}

.sidebar-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 3rem; padding: 0 1rem; }
.sidebar-logo img { height: 35px; filter: brightness(0) invert(1); }
.sidebar-logo span { font-weight: 700; letter-spacing: 2px; text-transform: uppercase; font-size: 0.8rem; opacity: 0.5; color: white; }

.nav-group { display: flex; flex-direction: column; gap: 0.5rem; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  border: none; background: transparent;
  width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: white; }
.nav-item.active { background: rgba(255,255,255,0.15); color: white; box-shadow: none; }

.sidebar-footer { margin-top: auto; padding: 1.5rem 1rem; border-top: 1px solid rgba(255,255,255,0.1); display: flex; flex-direction: column; gap: 1rem; }
.admin-info { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; opacity: 0.7; color: white; }
.status-dot { width: 8px; height: 8px; background: #00ff88; border-radius: 50%; box-shadow: 0 0 10px #00ff88; }

/* --- MAIN --- */
.main-content { margin-left: var(--sidebar-w); flex: 1; padding: 3rem; max-width: 1600px; }
.tab-panel { display: none; animation: slideUp 0.5s ease forwards; }
.tab-panel.active { display: block; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3rem; }
.topbar h1 { font-size: 2.2rem; font-weight: 700; color: var(--text-light); }
.topbar h1 span { color: var(--primary-violet); }
.topbar small { display: block; color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; }

/* --- CARDS & KPIs --- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; margin-bottom: 2.5rem; }
.card { background: #ffffff; border: 1px solid var(--glass-border); border-radius: var(--radius-lg); padding: 2rem; box-shadow: 0 2px 8px rgba(44,44,131,0.06); }
.kpi-card { position: relative; overflow: hidden; }
.kpi-card::after { content: ""; position: absolute; top:0; right:0; width: 60px; height: 60px; background: radial-gradient(circle, var(--primary-violet) 0%, transparent 70%); opacity: 0.08; }

.kpi-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-muted); margin-bottom: 0.75rem; }
.kpi-value { font-size: 2.5rem; font-weight: 700; line-height: 1; margin-bottom: 0.5rem; color: var(--text-light); }
.kpi-trend { font-size: 0.8rem; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.trend-up { color: #16a34a; }
.trend-down { color: #dc2626; }

/* --- CHARTS --- */
.chart-grid { display: grid; gap: 1.5rem; margin-bottom: 2.5rem; }
.chart-grid-1 { grid-template-columns: 1fr; }
.chart-grid-2 { grid-template-columns: 1.5fr 1fr; }
.chart-grid-3 { grid-template-columns: repeat(3, 1fr); }

.chart-card h3 { font-size: 1rem; margin-bottom: 2rem; color: var(--text-light); font-weight: 600; }
canvas { max-height: 350px; }

/* --- TABLES --- */
.table-card { padding: 0; overflow: hidden; }
.table-header { padding: 1.5rem 2rem; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--glass-border); }
.search-input { background: var(--bg-main); border: 1px solid var(--glass-border); padding: 0.6rem 1.25rem; border-radius: var(--radius-md); color: var(--text-light); outline: none; width: 250px; font-size: 0.9rem; }
.search-input:focus { border-color: var(--primary-violet); }

.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 1rem 2rem; font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted); border-bottom: 1px solid var(--glass-border); }
td { padding: 1.25rem 2rem; font-size: 0.9rem; color: var(--text-light); border-bottom: 1px solid var(--glass-border); }
tr:hover td { background: #f8f9ff; }

.badge { padding: 4px 12px; border-radius: 99px; font-size: 0.75rem; font-weight: 600; }
.badge-admin { background: rgba(123, 103, 167, 0.12); color: var(--primary-violet); border: 1px solid rgba(123, 103, 167, 0.25); }
.word-tag { 
  display: inline-block; 
  margin: 4px; 
  color: var(--text-light) !important; 
  opacity: 0.7; 
  font-weight: 500;
  border-bottom: 1px solid var(--glass-border);
}

/* --- TERMINAL --- */
#debugTerminal {
  position: fixed; bottom: 30px; right: 30px;
  width: 450px; height: 320px;
  background: rgba(10, 10, 25, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid var(--accent-white);
  border-radius: 12px;
  z-index: 1000;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transform: translateY(120%); opacity: 0; transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}
#debugTerminal.active { transform: translateY(0); opacity: 1; }

.terminal-header { padding: 12px 18px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
.terminal-title { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; color: var(--accent-white); letter-spacing: 1px; }
.terminal-output { flex: 1; padding: 15px; overflow-y: auto; font-family: 'Fira Code', monospace; font-size: 0.8rem; color: var(--accent-white); line-height: 1.5; }

.btn-export { background: var(--primary-violet); color: white; border: none; padding: 0.6rem 1.5rem; border-radius: var(--radius-md); font-weight: 600; cursor: pointer; transition: 0.3s; font-size: 0.85rem; }
.btn-export:hover { filter: brightness(1.2); transform: translateY(-2px); }

/* --- RESPONSIVE --- */
@media (max-width: 1100px) {
  .chart-grid-2, .chart-grid-3 { grid-template-columns: 1fr; }
  .sidebar { width: 80px; padding: 2rem 0.5rem; }
  .sidebar-logo span, .nav-item span { display: none; }
  .main-content { margin-left: 80px; }
  .nav-item { justify-content: center; }
}
