/* =============================================
   Analytics Dashboard — Dark Theme
   ============================================= */

:root {
  --bg: #0f1117;
  --bg2: #161b27;
  --bg3: #1e2536;
  --border: #2a3147;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --purple: #6366f1;
  --purple-hover: #4f51d6;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --blue: #3b82f6;
  --sidebar-w: 240px;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

a { color: var(--purple); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

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

.sidebar-logo .logo-icon {
  width: 34px; height: 34px;
  background: var(--purple);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.sidebar-logo span {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.sidebar-section {
  padding: 12px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
}

.sidebar-nav { flex: 1; padding: 8px 12px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
  text-decoration: none;
}

.nav-item:hover, .nav-item.active {
  background: var(--bg3);
  color: var(--text);
  text-decoration: none;
}

.nav-item.active { color: var(--purple); }
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: var(--bg3);
}

.user-avatar {
  width: 32px; height: 32px;
  background: var(--purple);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff;
  flex-shrink: 0;
}

.user-details { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-muted); }

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

.topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-title { font-size: 18px; font-weight: 700; }
.page-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.content-area { padding: 24px 28px; flex: 1; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  font-family: inherit;
}

.btn-primary { background: var(--purple); color: #fff; }
.btn-primary:hover { background: var(--purple-hover); text-decoration: none; color: #fff; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); text-decoration: none; color: var(--text); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--red); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); text-decoration: none; color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #0d9e6e; text-decoration: none; color: #fff; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-blue:hover { background: #2563eb; text-decoration: none; color: #fff; }

/* ---- KPI Cards ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--purple);
  border-radius: 12px 12px 0 0;
}

.kpi-card.green::before { background: var(--green); }
.kpi-card.blue::before { background: var(--blue); }
.kpi-card.yellow::before { background: var(--yellow); }
.kpi-card.red::before { background: var(--red); }

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  margin-bottom: 6px;
}

.kpi-sub { font-size: 12px; color: var(--text-muted); }
.kpi-icon { position: absolute; top: 16px; right: 16px; font-size: 22px; opacity: .4; }

/* ---- Cards / Panels ---- */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

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

.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ---- Tables ---- */
.table-wrapper { overflow-x: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table thead th {
  background: var(--bg3);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}

table.data-table tbody tr:hover { background: var(--bg3); }
table.data-table tbody tr:last-child { border-bottom: none; }
table.data-table td { padding: 10px 14px; vertical-align: middle; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}

.badge-purple { background: rgba(99,102,241,.2); color: #818cf8; }
.badge-green { background: rgba(16,185,129,.2); color: #34d399; }
.badge-blue { background: rgba(59,130,246,.2); color: #60a5fa; }
.badge-yellow { background: rgba(245,158,11,.2); color: #fbbf24; }
.badge-gray { background: var(--bg3); color: var(--text-muted); }

/* ---- Form Inputs ---- */
.form-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  box-sizing: border-box;
}
.form-input:focus { border-color: var(--purple); }
.form-input::placeholder { color: var(--text-muted); }

/* ---- Live Activity Feed ---- */
.live-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px; animation: fadeIn .3s ease;
}
.live-row:last-child { border-bottom: none; }
.live-icon { font-size: 16px; flex-shrink: 0; width: 22px; text-align: center; }
.live-text { flex: 1; min-width: 0; }
.live-text span { display: block; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-text small { color: var(--text-muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.live-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---- Grid layouts ---- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

@media (max-width: 900px) {
  .two-col, .three-col { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ---- Site cards ---- */
.site-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color .2s;
}

.site-card:hover { border-color: var(--purple); }
.site-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.site-name { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.site-url { font-size: 12px; color: var(--text-muted); }

.site-key-badge {
  font-family: monospace;
  font-size: 11px;
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--text-muted);
  white-space: nowrap;
}

.site-stats { display: flex; gap: 24px; }
.site-stat { text-align: center; }
.site-stat-val { font-size: 22px; font-weight: 700; color: var(--text); }
.site-stat-lbl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; margin-top: 2px; }
.site-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Snippet box ---- */
.snippet-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 80px 12px 14px;
  font-family: monospace;
  font-size: 12px;
  color: #a5b4fc;
  word-break: break-all;
  position: relative;
  line-height: 1.6;
}

.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  padding: 4px 10px;
  font-size: 11px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
}

.copy-btn:hover { color: var(--text); background: var(--border); }

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }

.form-control {
  width: 100%;
  padding: 9px 13px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}

.form-control:focus { border-color: var(--purple); }
.form-control::placeholder { color: var(--text-muted); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
}

.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 20px; }
.modal-footer { margin-top: 20px; display: flex; gap: 10px; justify-content: flex-end; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }

.tab-btn {
  padding: 8px 16px;
  border-radius: 8px 8px 0 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  font-family: inherit;
}

.tab-btn.active { color: var(--purple); border-bottom-color: var(--purple); }
.tab-btn:hover { color: var(--text); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---- Chart containers ---- */
.chart-container { position: relative; height: 220px; }

/* ---- Auth pages ---- */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}

.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.auth-logo { text-align: center; margin-bottom: 28px; }

.auth-logo .logo-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px;
  background: var(--purple);
  border-radius: 12px;
  font-size: 22px;
  margin-bottom: 10px;
}

.auth-logo h1 { font-size: 22px; font-weight: 700; }
.auth-logo p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.auth-error {
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #fca5a5;
  margin-bottom: 16px;
}

/* ---- Misc ---- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 14px; }
.empty-state p { font-size: 14px; }

.sites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center { display: flex; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.text-muted { color: var(--text-muted); }
.text-small { font-size: 12px; }

.export-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.refresh-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--green);
  border-radius: 50%;
  margin-right: 5px;
  animation: pulse 2s infinite;
}

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

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */

/* ── Hamburger button (hidden on desktop) ── */
.mob-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  color: var(--text);
  transition: background .15s;
}
.mob-menu-btn:hover { background: var(--bg3); }
.mob-menu-btn span {
  display: block;
  width: 22px; height: 2px;
  background: var(--text);
  margin: 5px 0;
  border-radius: 2px;
  transition: transform .25s, opacity .25s;
}
.mob-menu-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.mob-menu-btn.open span:nth-child(2) { opacity: 0; }
.mob-menu-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
  /* Show hamburger */
  .mob-menu-btn { display: flex; flex-direction: column; justify-content: center; }

  /* Sidebar slides in/out */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .28s ease;
    z-index: 200;
  }
  .sidebar.mob-open { transform: translateX(0); }

  /* Main content full width */
  .main-content { margin-left: 0; }

  /* Topbar */
  .topbar {
    padding: 0 14px;
    height: 54px;
    gap: 10px;
  }
  .page-title { font-size: 15px; }
  .page-subtitle { font-size: 11px; }
  .topbar-actions .btn span,
  .topbar-actions .btn-sm { font-size: 12px; padding: 7px 11px; }

  /* Content area */
  .content-area { padding: 14px; }

  /* Modal full screen on mobile */
  .modal {
    max-width: 100%;
    margin: 12px;
    padding: 20px;
    border-radius: 12px;
  }
  .modal-overlay { align-items: flex-end; }

  /* KPI grid */
  .kpi-grid { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }

  /* Auth card */
  .auth-card { margin: 16px; padding: 24px; }

  /* Two/three col grids */
  .two-col, .three-col { grid-template-columns: 1fr !important; }
}
