/* ============================================================
   Web Tracker — Dark Theme Dashboard
   ============================================================ */

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --green: #22c55e;
  --cyan: #22d3ee;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 8px;
  --sidebar-w: 220px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================================
   LOGIN OVERLAY
   ============================================================ */
.overlay {
  position: fixed; inset: 0;
  background: var(--bg-primary);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.overlay.hidden { display: none; }

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.login-card p { color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 0.9rem; }
.login-card input {
  width: 100%; padding: 0.65rem 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  outline: none;
  transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%; padding: 0.65rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}
.login-card button:hover { background: var(--accent-hover); }
.error { color: var(--red); font-size: 0.85rem; margin-top: 0.5rem; }
.error.hidden { display: none; }

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app { display: flex; min-height: 100vh; }
.hidden { display: none !important; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h1 { font-size: 1.1rem; }
.sidebar-nav { flex: 1; padding: 0.5rem 0; }
.nav-item {
  display: block;
  padding: 0.6rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.nav-item:hover { color: var(--text-primary); background: var(--bg-hover); }
.nav-item.active {
  color: var(--text-primary);
  background: rgba(99, 102, 241, 0.1);
  border-left-color: var(--accent);
}
.sidebar-footer { padding: 0.75rem 1rem; border-top: 1px solid var(--border); }

/* Main */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 1.5rem 2rem;
  min-height: 100vh;
}

/* Top bar */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap;
}
.site-selector { display: flex; align-items: center; gap: 0.5rem; }
.site-selector label { color: var(--text-secondary); font-size: 0.85rem; }
.site-selector select {
  padding: 0.4rem 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  min-width: 240px;
}
.site-selector select:focus { border-color: var(--accent); }
.site-meta { color: var(--text-muted); font-size: 0.8rem; }

/* ============================================================
   STATS CARDS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.stat-label { color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.25rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ============================================================
   CHART
   ============================================================ */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  height: 320px;
}

/* ============================================================
   PANELS & TABLES
   ============================================================ */
.panel-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.panel h3 { font-size: 0.95rem; margin-bottom: 0.75rem; color: var(--text-secondary); }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
td { color: var(--text-secondary); }
td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: var(--bg-hover); }
.empty { text-align: center !important; color: var(--text-muted); padding: 2rem 0 !important; }

/* ============================================================
   CRAWLERS
   ============================================================ */
.crawlers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0 1.5rem;
}
.crawler-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  text-align: center;
}
.crawler-count { font-size: 1.5rem; font-weight: 700; color: var(--amber); }
.crawler-name { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.25rem; }
.crawler-last { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.15rem; }
.crawler-badge {
  display: inline-block;
  background: rgba(245, 158, 11, 0.15);
  color: var(--amber);
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ============================================================
   SITES
   ============================================================ */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card input {
  display: block; width: 100%; max-width: 320px;
  padding: 0.5rem 0.65rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  outline: none;
}
.card input:focus { border-color: var(--accent); }
.sites-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; margin-top: 1rem; }
.site-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.site-card-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.5rem; }
.site-domain { font-size: 0.8rem; color: var(--text-muted); font-family: monospace; }
.site-card-meta { display: flex; gap: 1rem; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.75rem; }
.site-card-actions { display: flex; gap: 0.5rem; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  max-width: 540px;
  width: 100%;
}
.modal-card h3 { margin-bottom: 0.5rem; }
.modal-card p { color: var(--text-secondary); margin-bottom: 1rem; font-size: 0.9rem; }
.modal-card pre {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  color: var(--cyan);
  font-size: 0.85rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 1rem;
}
.modal-card code { color: var(--green); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn, .btn-primary {
  display: inline-block;
  padding: 0.45rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
  text-decoration: none;
}
.btn:hover { background: var(--accent-hover); }
.btn-ghost {
  display: inline-block;
  padding: 0.45rem 1rem;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--text-muted); }
.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
  background: var(--bg-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-sm:hover { color: var(--text-primary); border-color: var(--text-muted); }
.btn-danger:hover { color: var(--red); border-color: var(--red); }
.top-actions { display: flex; gap: 0.5rem; }

/* ============================================================
   TABS
   ============================================================ */
.tab-content { display: none; }
.tab-content.active { display: block; }
.tab-content h2 { font-size: 1.15rem; margin-bottom: 1rem; color: var(--text-secondary); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-header h1, .nav-item { font-size: 0; }
  .nav-item::first-letter { font-size: 1rem; }
  .main-content { margin-left: 60px; padding: 1rem; }
  .panel-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
