/* ============================================================
   CSS Variables – Light (default) & Dark themes
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  /* Primary palette */
  --primary: #4f67f0;
  --primary-light: #7b8ff5;
  --primary-dark: #3a4fd6;
  --accent: #22c55e;

  /* Surface colours – Light */
  --bg: #f0f4ff;
  --surface: #ffffff;
  --surface-hover: #f5f7ff;
  --border: #e2e8f5;
  --border-strong: #c7d2e8;

  /* Text */
  --text-primary: #1a1f36;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-on-primary: #ffffff;

  /* Header gradient */
  --header-bg: linear-gradient(135deg, #4f67f0 0%, #7c3aed 100%);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(79,103,240,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(79,103,240,.12), 0 2px 6px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 40px rgba(79,103,240,.16), 0 4px 12px rgba(0,0,0,.08);

  /* Badge colours */
  --badge-search: #dbeafe; --badge-search-text: #1d4ed8;
  --badge-development: #f0fdf4; --badge-development-text: #15803d;
  --badge-entertainment: #fef9c3; --badge-entertainment-text: #854d0e;
  --badge-reference: #fce7f3; --badge-reference-text: #be185d;
  --badge-social: #faf5ff; --badge-social-text: #7e22ce;
  --badge-default: #f1f5f9; --badge-default-text: #475569;

  /* Misc */
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.22s cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d2e;
  --surface-hover: #232640;
  --border: #2d3154;
  --border-strong: #3d4270;

  --text-primary: #e8ecff;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,.5);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.6);

  --badge-search: #1e3a5f; --badge-search-text: #60a5fa;
  --badge-development: #14532d; --badge-development-text: #4ade80;
  --badge-entertainment: #422006; --badge-entertainment-text: #fbbf24;
  --badge-reference: #500724; --badge-reference-text: #f472b6;
  --badge-social: #3b0764; --badge-social-text: #c084fc;
  --badge-default: #1e293b; --badge-default-text: #94a3b8;
}

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

html { scroll-behavior: smooth; }

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

/* ============================================================
   Header / Hero
   ============================================================ */
.site-header {
  background: var(--header-bg);
  padding: 48px 24px 64px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Ccircle cx='30' cy='30' r='10'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") repeat;
  pointer-events: none;
}

.site-header .orb {
  position: absolute;
  border-radius: 50%;
  opacity: 0.15;
  filter: blur(60px);
  pointer-events: none;
}
.orb-1 { width: 300px; height: 300px; background: #a78bfa; top: -80px; left: -60px; }
.orb-2 { width: 250px; height: 250px; background: #38bdf8; bottom: -80px; right: -40px; }

.header-inner { position: relative; z-index: 1; max-width: 720px; margin: 0 auto; }

.header-logo {
  display: inline-flex; align-items: center; gap: 14px;
  margin-bottom: 16px;
}

.logo-icon {
  width: 56px; height: 56px;
  background: rgba(255,255,255,.2);
  backdrop-filter: blur(12px);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  border: 1.5px solid rgba(255,255,255,.3);
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

.header-title {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.header-subtitle {
  font-size: 1rem;
  color: rgba(255,255,255,.75);
  font-weight: 400;
  margin-top: 4px;
}

/* Theme toggle inside header */
.theme-toggle {
  position: absolute;
  top: 20px; right: 20px;
  background: rgba(255,255,255,.15);
  backdrop-filter: blur(12px);
  border: 1.5px solid rgba(255,255,255,.25);
  border-radius: 50px;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  color: #fff;
  transition: background var(--transition), transform var(--transition);
  font-family: inherit;
  z-index: 10;
}
.theme-toggle:hover { background: rgba(255,255,255,.25); transform: scale(1.04); }
.theme-toggle .toggle-icon { font-size: 1rem; transition: transform 0.4s; }

/* Stats bar in header */
.stats-bar {
  display: flex; justify-content: center; gap: 32px;
  margin-top: 28px;
  flex-wrap: wrap;
}

.stat-item {
  display: flex; flex-direction: column; align-items: center;
  color: rgba(255,255,255,.9);
}

.stat-value {
  font-size: 1.6rem; font-weight: 700; line-height: 1;
  color: #fff;
}

.stat-label { font-size: 0.72rem; color: rgba(255,255,255,.65); text-transform: uppercase; letter-spacing: .06em; margin-top: 2px; }

/* ============================================================
   Main Container
   ============================================================ */
main { max-width: 1200px; margin: 0 auto; padding: 0 20px 60px; }

/* ============================================================
   Table Card
   ============================================================ */
.table-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  margin-top: -32px;
  overflow: hidden;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

/* Toolbar */
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.toolbar-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.table-title {
  font-size: 1rem; font-weight: 600;
  color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}

.site-count {
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 50px;
  min-width: 24px; text-align: center;
}

/* Search input */
.search-wrapper {
  position: relative;
  display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 12px;
  color: var(--text-muted);
  pointer-events: none; font-size: 0.9rem;
}
#searchInput {
  padding: 9px 12px 9px 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  width: 220px;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  outline: none;
}
#searchInput::placeholder { color: var(--text-muted); }
#searchInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,103,240,.15);
  background: var(--surface);
}

/* Category filter */
#categoryFilter {
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
#categoryFilter:focus { border-color: var(--primary); }

/* Per-page selector */
#perPage {
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
#perPage:focus { border-color: var(--primary); }

/* ============================================================
   Data Table
   ============================================================ */
.table-wrapper { overflow-x: auto; }

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

thead th {
  background: var(--surface-hover);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 12px 20px;
  text-align: left;
  border-bottom: 1.5px solid var(--border);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

thead th:hover { color: var(--primary); background: var(--bg); }
thead th .sort-icon { margin-left: 4px; opacity: .5; font-size: .75rem; }
thead th.sorted { color: var(--primary); }
thead th.sorted .sort-icon { opacity: 1; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  cursor: pointer;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-hover); }

tbody td { padding: 14px 20px; vertical-align: middle; }

/* Site name cell */
.site-name-cell {
  display: flex; align-items: center; gap: 12px;
}

.site-favicon {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  object-fit: contain;
  padding: 3px;
  flex-shrink: 0;
  transition: transform var(--transition), box-shadow var(--transition);
}
.site-favicon:hover { transform: scale(1.1); box-shadow: var(--shadow-sm); }

.site-name { font-weight: 600; color: var(--text-primary); }
.site-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }

/* URL cell */
.site-url {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  display: flex; align-items: center; gap: 4px;
  transition: color var(--transition);
  word-break: break-all;
}
.site-url:hover { color: var(--primary-dark); text-decoration: underline; }
.site-url .ext-icon { opacity: .6; font-size: .75rem; flex-shrink: 0; }

/* Category badge */
.badge {
  display: inline-flex; align-items: center;
  padding: 4px 10px;
  border-radius: 50px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  text-transform: capitalize;
}
.badge-search       { background: var(--badge-search); color: var(--badge-search-text); }
.badge-development  { background: var(--badge-development); color: var(--badge-development-text); }
.badge-entertainment{ background: var(--badge-entertainment); color: var(--badge-entertainment-text); }
.badge-reference    { background: var(--badge-reference); color: var(--badge-reference-text); }
.badge-social       { background: var(--badge-social); color: var(--badge-social-text); }
.badge-default      { background: var(--badge-default); color: var(--badge-default-text); }

/* Action button */
.visit-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.visit-btn:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79,103,240,.35); }
.visit-btn:active { transform: translateY(0); }

/* Row number */
td.row-num { color: var(--text-muted); font-size: 0.8rem; font-weight: 500; }

/* ============================================================
   Empty / Loading states
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; display: block; }
.empty-state h3 { font-size: 1rem; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 0.85rem; }

.loading-row td {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.spinner {
  display: inline-block;
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Pagination
   ============================================================ */
.table-footer {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.pagination {
  display: flex; align-items: center; gap: 4px;
}

.page-btn {
  min-width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition);
  padding: 0 8px;
}
.page-btn:hover:not(:disabled):not(.active) { border-color: var(--primary); color: var(--primary); background: var(--surface-hover); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  text-align: center;
  padding: 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.site-footer a { color: var(--primary); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* ============================================================
   Animations
   ============================================================ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.table-card { animation: fadeInUp .4s ease both; }

tbody tr {
  animation: fadeInUp .25s ease both;
}
tbody tr:nth-child(1) { animation-delay: .02s; }
tbody tr:nth-child(2) { animation-delay: .04s; }
tbody tr:nth-child(3) { animation-delay: .06s; }
tbody tr:nth-child(4) { animation-delay: .08s; }
tbody tr:nth-child(5) { animation-delay: .10s; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  .site-header { padding: 36px 16px 52px; }
  .table-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left, .toolbar-right { flex-direction: column; }
  #searchInput { width: 100%; }
  thead th:nth-child(5) { display: none; }
  tbody td:nth-child(5) { display: none; }
  .stats-bar { gap: 20px; }
  .theme-toggle span:not(.toggle-icon) { display: none; }
}

@media (max-width: 520px) {
  .site-desc { display: none; }
  thead th:nth-child(2) { display: none; }
  tbody td:nth-child(2) { display: none; }
}
