:root {
  --bg: #000000;
  --surface: #080808;
  --surface2: #0f0f0f;
  --border: rgba(240,220,0,0.18);
  --accent: #f0dc00;
  --accent2: #c4b400;
  --danger: #ff2244;
  --success: #00e676;
  --warning: #ff9100;
  --text: #f5f5e8;
  --text-dim: #8a8a6a;
  --text-muted: #3a3a28;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* Animations */
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes glitch {
  0%,100% { clip-path: inset(0 0 100% 0); }
  10%  { clip-path: inset(20% 0 60% 0); transform: translate(-2px); }
  20%  { clip-path: inset(60% 0 10% 0); transform: translate(2px); }
  30%  { clip-path: inset(40% 0 40% 0); transform: translate(-1px); }
  40%  { clip-path: inset(80% 0 5%  0); transform: translate(1px); }
  50%  { clip-path: inset(10% 0 70% 0); transform: translate(-2px); }
  100% { clip-path: inset(0 0 100% 0); }
}
@keyframes flicker {
  0%,100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.6; }
  94% { opacity: 1; }
  96% { opacity: 0.8; }
  97% { opacity: 1; }
}
@keyframes scanin {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.blink { animation: blink 1s step-end infinite; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  animation: flicker 8s infinite;
}

/* Scanlines */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(240,220,0,0.018) 2px,
    rgba(240,220,0,0.018) 4px
  );
  pointer-events: none;
  z-index: 9998;
}

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

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

.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
  font-family: var(--mono);
}
.sidebar-logo .logo-tag {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-dim);
  letter-spacing: 0.1em;
  margin-top: 4px;
}

.sidebar-nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav-section-label {
  font-size: 9px;
  font-family: var(--mono);
  color: var(--text-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 10px 20px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--mono);
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: all 0.1s;
  border-left: 2px solid transparent;
  text-decoration: none;
}
.nav-item:hover { color: var(--accent); background: rgba(240,220,0,0.04); text-decoration: none; }
.nav-item.active { color: var(--accent); border-left-color: var(--accent); background: rgba(240,220,0,0.06); }
.nav-item .icon { width: 16px; text-align: center; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.sidebar-user { font-size: 11px; font-family: var(--mono); color: var(--text-muted); margin-bottom: 8px; }
.sidebar-user span { color: var(--text-dim); }

.main { margin-left: 220px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title {
  font-size: 13px;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  flex: 1;
}
.topbar-title::before { content: '> '; color: var(--text-muted); }

.search-bar {
  display: flex;
  align-items: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0 12px;
  gap: 8px;
  width: 280px;
}
.search-bar input {
  background: none;
  border: none;
  color: var(--text);
  font-size: 12px;
  font-family: var(--mono);
  outline: none;
  padding: 7px 0;
  width: 100%;
}
.search-bar input::placeholder { color: var(--text-muted); }

.content { padding: 24px; flex: 1; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.stat-card:hover { border-color: var(--accent); box-shadow: 0 0 12px rgba(240,220,0,0.08); }
.stat-card.active { border-color: var(--accent); border-left: 3px solid var(--accent); background: rgba(240,220,0,0.04); }
.stat-count { font-size: 28px; font-weight: 700; font-family: var(--mono); color: var(--accent); }
.stat-label { font-size: 10px; font-family: var(--mono); color: var(--text-dim); margin-top: 3px; text-transform: uppercase; letter-spacing: 0.08em; }

/* Table */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 2px; overflow: hidden; }
.table-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
tbody tr { border-bottom: 1px solid var(--border); transition: all 0.08s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { border-left: 2px solid var(--accent); background: rgba(240,220,0,0.03); cursor: pointer; }
td { padding: 10px 16px; font-size: 13px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.badge-active    { background: rgba(0,230,118,0.1);  color: var(--success); border: 1px solid rgba(0,230,118,0.25); }
.badge-inactive  { background: rgba(138,138,106,0.1); color: var(--text-dim); border: 1px solid rgba(138,138,106,0.2); }
.badge-deceased  { background: rgba(255,34,68,0.1);  color: var(--danger); border: 1px solid rgba(255,34,68,0.25); }
.badge-incarcerated { background: rgba(255,145,0,0.1); color: var(--warning); border: 1px solid rgba(255,145,0,0.25); }
.badge-category  { background: transparent; color: var(--accent); border: 1px solid rgba(240,220,0,0.35); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 2px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.1s;
  text-decoration: none;
  position: relative;
}
.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: #fff500;
  box-shadow: 0 0 16px rgba(240,220,0,0.4);
  text-decoration: none;
  color: #000;
}
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: rgba(240,220,0,0.2);
}
.btn-ghost:hover { color: var(--accent); border-color: var(--accent); background: rgba(240,220,0,0.05); text-decoration: none; }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(255,34,68,0.35); }
.btn-danger:hover { background: rgba(255,34,68,0.1); box-shadow: 0 0 8px rgba(255,34,68,0.2); text-decoration: none; }
.btn-sm { padding: 4px 10px; font-size: 11px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-dim);
  margin-bottom: 6px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.form-label::before { content: '// '; color: var(--text-muted); }
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--mono);
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(240,220,0,0.12);
}
.form-select { cursor: pointer; }
.form-select option { background: var(--surface2); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-input::placeholder { color: var(--text-muted); font-family: var(--mono); }
.form-row { display: grid; gap: 12px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* Profile */
.profile-header {
  display: flex;
  gap: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 24px;
  margin-bottom: 20px;
  align-items: flex-start;
  box-shadow: inset 0 0 40px rgba(240,220,0,0.02);
}
.profile-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }
.profile-photo {
  aspect-ratio: 1;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.1s;
}
.profile-photo:hover { border-color: var(--accent); }
.profile-photo img { width: 100%; height: 100%; object-fit: cover; }
.profile-photo-add {
  aspect-ratio: 1;
  border-radius: 2px;
  border: 1px dashed rgba(240,220,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 20px;
  transition: all 0.1s;
}
.profile-photo-add:hover { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 8px rgba(240,220,0,0.1); }

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  margin-bottom: 14px;
}
.section-card-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface2);
}
.section-card-title {
  font-size: 9px;
  font-family: var(--mono);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.section-card-title::before { content: '[ '; }
.section-card-title::after  { content: ' ]'; }
.section-card-body { padding: 16px; }

/* Timeline */
.timeline { list-style: none; }
.timeline-item {
  display: flex;
  gap: 12px;
  padding-bottom: 16px;
  position: relative;
}
.timeline-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 5px; top: 14px; bottom: 0;
  width: 1px;
  background: var(--border);
}
.timeline-dot {
  width: 12px; height: 12px;
  border-radius: 0;
  background: var(--accent);
  border: 2px solid var(--bg);
  flex-shrink: 0;
  margin-top: 4px;
  transform: rotate(45deg);
}
.timeline-date { font-size: 10px; font-family: var(--mono); color: var(--text-muted); margin-bottom: 2px; }
.timeline-desc { font-size: 13px; color: var(--text); }

/* Tags */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 3px 10px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tag-remove { cursor: pointer; color: var(--text-muted); font-size: 14px; line-height: 1; }
.tag-remove:hover { color: var(--danger); }

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% 50%, rgba(240,220,0,0.04) 0%, transparent 70%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 40px;
  width: 380px;
  box-shadow: 0 0 60px rgba(240,220,0,0.06), inset 0 0 40px rgba(240,220,0,0.02);
  animation: scanin 0.4s ease;
}
.login-logo { text-align: left; margin-bottom: 32px; }
.login-logo .name {
  font-size: 18px;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: 0.08em;
  color: var(--accent);
}
.login-logo .tag {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
  margin-top: 4px;
}
.login-error {
  color: var(--danger);
  font-size: 11px;
  font-family: var(--mono);
  margin-top: 10px;
}
.login-error::before { content: '> ERROR: '; }

/* Utilities */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8  { margin-bottom: 8px; }
.text-dim    { color: var(--text-dim); }
.text-muted  { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-sm  { font-size: 12px; }
.mono     { font-family: var(--mono); }
.w-full   { width: 100%; }
.hidden   { display: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(240,220,0,0.2); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: rgba(240,220,0,0.4); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 24px;
  width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(240,220,0,0.08);
  animation: scanin 0.2s ease;
}
.modal-title {
  font-size: 12px;
  font-weight: 700;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 20px;
}
.modal-title::before { content: '// '; color: var(--text-muted); }

/* Filters bar */
.filters-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.filter-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--mono);
  padding: 6px 10px;
  outline: none;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--accent); }

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

/* Bottom nav */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 58px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 150;
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 9px;
  font-family: var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 0;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s;
}
.bottom-nav-item .bn-icon { font-size: 18px; line-height: 1; }
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item:active { opacity: 0.6; }

/* ──────────── Mobile ──────────── */
@media (max-width: 768px) {
  html, body { overflow-x: hidden; max-width: 100%; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    width: 240px;
    min-width: 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 4px 0 30px rgba(0,0,0,0.8);
  }
  .sidebar.open { transform: translateX(0); }

  .main {
    margin-left: 0 !important;
    width: 100%;
    min-width: 0;
    padding-bottom: 58px;
  }

  .topbar { padding: 0 14px; gap: 10px; height: 48px; }
  .topbar-title { font-size: 12px; }
  .search-bar { display: none; }

  .content { padding: 12px; }

  .form-row-2, .form-row-3 { grid-template-columns: 1fr !important; }

  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
  .stat-count { font-size: 22px; }

  .table-wrap { overflow-x: unset; }
  table { width: 100%; min-width: 0; }
  table th:nth-child(2), table td:nth-child(2) { display: none; }
  table th:nth-child(n+6), table td:nth-child(n+6) { display: none; }
  td, th { padding: 10px 12px; }

  .profile-header { flex-direction: column; gap: 12px; }
  .profile-cols { grid-template-columns: 1fr !important; }
  .profile-photo-grid { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); }

  .modal { width: 95vw; max-width: none; padding: 16px; }
  .modal-overlay { align-items: flex-end; padding-bottom: 58px; }

  .filters-bar { flex-wrap: wrap; gap: 6px; }
  .filters-bar > a.btn { order: -1; width: 100%; justify-content: center; margin-left: 0 !important; }
  .filter-select { flex: 1; min-width: 100px; }
  #result-count { display: none; }

  .btn { min-height: 38px; }
  .btn-sm { min-height: 32px; }
  .bottom-nav { display: flex; }
  .login-card { width: 92vw; padding: 28px 20px; }
  .section-card { margin-bottom: 10px; }
  .section-card-body { padding: 12px; }
}
