/* ===== CSS Custom Properties ===== */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --sidebar-bg: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-active: #6366f1;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,.07);
  --sidebar-width: 240px;
  --topbar-height: 60px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

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

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-brand i { font-size: 1.3rem; color: var(--primary); }
.sidebar-nav { flex: 1; padding: 1rem 0; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem 1.5rem;
  color: var(--sidebar-text);
  font-size: .875rem;
  font-weight: 500;
  transition: all .2s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(99,102,241,.15); color: var(--primary); border-left-color: var(--primary); }
.nav-item i { width: 18px; text-align: center; }
.nav-logout { margin-top: auto; color: #f87171; }
.nav-logout:hover { background: rgba(239,68,68,.1); color: #f87171; }
.sidebar-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 1rem 1.5rem;
  color: var(--sidebar-text);
  font-size: .8rem;
  border-top: 1px solid rgba(255,255,255,.07);
  overflow: hidden;
}
.sidebar-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

/* ===== Topbar ===== */
.topbar {
  height: var(--topbar-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.sidebar-toggle { display: none; background: none; border: none; font-size: 1.1rem; color: var(--text-muted); padding: .25rem; }
.topbar-title { font-size: 1rem; font-weight: 600; color: var(--text); flex: 1; }
.topbar-user { font-size: .8125rem; color: var(--text-muted); display: flex; align-items: center; gap: .4rem; }

/* ===== Page Body ===== */
.page-body { padding: 1.5rem; flex: 1; }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: #fff; flex-shrink: 0;
}
.bg-blue { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.bg-green { background: linear-gradient(135deg, #22c55e, #16a34a); }
.bg-orange { background: linear-gradient(135deg, #f59e0b, #d97706); }
.bg-purple { background: linear-gradient(135deg, #a855f7, #7c3aed); }
.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; margin-top: .2rem; }

/* ===== Dashboard Grid ===== */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* ===== Card ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: .9375rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.card-title i { color: var(--primary); }

/* ===== Table ===== */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .8125rem; }
.data-table th {
  background: #f8fafc;
  padding: .75rem 1rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td { padding: .8rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }
.empty-state { text-align: center; color: var(--text-muted); padding: 2.5rem !important; font-size: .9rem; }
.row-num { color: var(--text-muted); font-size: .75rem; }
.date-cell { color: var(--text-muted); font-size: .8rem; white-space: nowrap; }
.ip-cell { font-family: monospace; font-size: .8rem; color: var(--text-muted); }
.email-link { color: var(--primary); }
.email-link:hover { text-decoration: underline; }

/* ===== Badge ===== */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-count {
  background: var(--primary);
  color: #fff;
  font-size: .7rem;
  padding: .15rem .5rem;
}

/* ===== Sources List ===== */
.sources-list { padding: .75rem 1.25rem; }
.source-row { display: flex; align-items: center; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .875rem; }
.source-row:last-child { border-bottom: none; }
.source-rank { font-weight: 700; color: var(--primary); width: 24px; }
.source-domain { flex: 1; font-weight: 500; }
.source-count { color: var(--text-muted); font-size: .8rem; }

/* ===== Embed Section ===== */
.embed-section { padding: .75rem 1.25rem 1.25rem; }
.embed-label { font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .4rem; }
.code-block {
  background: #1e293b;
  color: #e2e8f0;
  padding: .75rem 1rem;
  border-radius: 8px;
  font-size: .78rem;
  font-family: 'Courier New', monospace;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
}

/* ===== Filter Card ===== */
.filter-card { margin-bottom: 1.25rem; padding: 1.25rem; }
.filters-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .875rem; }
.filter-actions { display: flex; gap: .75rem; margin-top: 1rem; flex-wrap: wrap; }

/* ===== Form Controls ===== */
.form-group { display: flex; flex-direction: column; }
.form-group label { font-size: .78rem; font-weight: 600; color: var(--text-muted); margin-bottom: .35rem; text-transform: uppercase; letter-spacing: .03em; }
.form-control {
  padding: .55rem .875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  color: var(--text);
  background: var(--card-bg);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  border: 2px solid transparent;
  transition: all .2s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-sm { padding: .3rem .65rem; font-size: .78rem; }
.btn-block { width: 100%; justify-content: center; padding: .75rem; font-size: 1rem; }

/* ===== Pagination ===== */
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; padding: 1rem; border-top: 1px solid var(--border); }
.page-btn { display: inline-flex; align-items: center; gap: .3rem; padding: .45rem .9rem; background: var(--primary-light); color: var(--primary); border-radius: 8px; font-size: .8125rem; font-weight: 600; transition: background .2s; }
.page-btn:hover { background: var(--primary); color: #fff; }
.page-info { font-size: .8rem; color: var(--text-muted); }

/* ===== Login Page ===== */
.login-wrapper { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; background: linear-gradient(135deg, #1e293b 0%, #334155 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 2.5rem; width: 100%; max-width: 400px; box-shadow: 0 24px 48px rgba(0,0,0,.25); }
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo i { font-size: 2.5rem; color: var(--primary); }
.login-logo h1 { font-size: 1.5rem; font-weight: 800; color: var(--text); margin-top: .4rem; }
.login-logo p { color: var(--text-muted); font-size: .875rem; }
.input-icon { position: relative; }
.input-icon > i:first-child { position: absolute; left: .875rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: .875rem; }
.input-icon .form-control { padding-left: 2.5rem; }
.toggle-password { position: absolute; right: .875rem; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--text-muted); font-size: .875rem; }

/* ===== Alerts ===== */
.alert { padding: .875rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .875rem; font-weight: 500; display: flex; align-items: center; gap: .5rem; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #86efac; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  padding: .875rem 1.25rem;
  border-radius: 10px;
  font-size: .875rem; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  z-index: 9999;
  transform: translateY(100px);
  opacity: 0;
  transition: all .3s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast-success { background: #22c55e; color: #fff; }
.toast-error { background: #ef4444; color: #fff; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 9998; backdrop-filter: blur(2px); }
.modal { background: #fff; border-radius: 16px; padding: 2rem; max-width: 380px; width: 90%; text-align: center; box-shadow: 0 24px 48px rgba(0,0,0,.2); }
.modal-icon { font-size: 2.5rem; color: var(--warning); margin-bottom: .75rem; }
.modal h3 { font-size: 1.125rem; font-weight: 700; margin-bottom: .4rem; }
.modal p { color: var(--text-muted); font-size: .875rem; margin-bottom: 1.5rem; }
.modal-actions { display: flex; gap: .75rem; justify-content: center; }

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

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .sidebar-toggle { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .filters-grid { grid-template-columns: 1fr; }
  .topbar-user { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-body { padding: 1rem; }
  .filter-actions { flex-direction: column; }
  .filter-actions .btn { width: 100%; justify-content: center; }
}
