/* ═══════════════════════════════════════════════════════════════
   TN Foreclosure Intelligence Dashboard — Design System
   Dark mode · Glassmorphism · Electric gold accent
   ═══════════════════════════════════════════════════════════════ */

/* ─── CSS Custom Properties ───────────────────────────── */
:root {
  /* Base palette */
  --bg-primary: #07070d;
  --bg-secondary: #0c0c16;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --bg-glass: rgba(255, 255, 255, 0.04);
  --bg-modal: rgba(12, 12, 22, 0.97);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(245, 197, 24, 0.25);
  --border-glass: rgba(255, 255, 255, 0.08);

  /* Text */
  --text-primary: #f0f0f5;
  --text-secondary: #8a8a9e;
  --text-muted: #55556a;
  --text-accent: #f5c518;

  /* Accent — Electric Gold */
  --accent: #f5c518;
  --accent-dim: rgba(245, 197, 24, 0.15);
  --accent-glow: rgba(245, 197, 24, 0.3);
  --accent-bright: #ffd84d;

  /* Status */
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 30px rgba(245, 197, 24, 0.08);

  /* Glass */
  --glass-blur: 20px;
  --glass-border: 1px solid var(--border-glass);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing */
  --gap-xs: 4px;
  --gap-sm: 8px;
  --gap-md: 16px;
  --gap-lg: 24px;
  --gap-xl: 32px;
  --gap-2xl: 48px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
  padding: var(--gap-lg);
  padding-top: var(--gap-md);
  position: relative;
}

/* ─── Animated Background ─────────────────────────────── */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
  animation: glow-float 20s ease-in-out infinite alternate;
}

.bg-glow--1 {
  width: 500px;
  height: 500px;
  background: rgba(245, 197, 24, 0.04);
  top: -100px;
  right: -100px;
  animation-delay: 0s;
}

.bg-glow--2 {
  width: 400px;
  height: 400px;
  background: rgba(59, 130, 246, 0.03);
  bottom: -150px;
  left: -100px;
  animation-delay: -7s;
}

.bg-glow--3 {
  width: 350px;
  height: 350px;
  background: rgba(245, 197, 24, 0.025);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -14s;
}

@keyframes glow-float {
  0% { transform: translate(0, 0) scale(1); opacity: 0.5; }
  50% { transform: translate(30px, -20px) scale(1.1); opacity: 0.8; }
  100% { transform: translate(-20px, 30px) scale(0.95); opacity: 0.6; }
}

/* ─── Header ──────────────────────────────────────────── */
.header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap-lg) var(--gap-xl);
  margin-bottom: var(--gap-xl);
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
}

.header__icon {
  font-size: 2.5rem;
  filter: drop-shadow(0 0 10px rgba(245, 197, 24, 0.3));
  animation: pulse-icon 3s ease-in-out infinite;
}

@keyframes pulse-icon {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.header__title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header__subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 0.5px;
}

.header__status {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot--loading {
  background: var(--warning);
  animation: blink 1.5s ease-in-out infinite;
}

.status-dot--connected {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-dot--error {
  background: var(--error);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ─── Stats Grid ──────────────────────────────────────── */
.stats-grid {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap-lg);
  margin-bottom: var(--gap-xl);
}

.stat-card {
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--gap-lg);
  text-align: center;
  transition: all var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 0%, rgba(245, 197, 24, 0.02) 100%);
  opacity: 0;
  transition: opacity var(--transition-smooth);
}

.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.stat-card:hover::before {
  opacity: 1;
}

.stat-card--accent {
  border-color: rgba(245, 197, 24, 0.15);
  background: linear-gradient(135deg, rgba(245, 197, 24, 0.05) 0%, var(--bg-glass) 100%);
}

.stat-card__icon {
  font-size: 1.5rem;
  margin-bottom: var(--gap-sm);
}

.stat-card__value {
  font-size: 2.5rem;
  font-weight: 900;
  font-family: var(--font-mono);
  color: var(--text-primary);
  line-height: 1.1;
  margin-bottom: var(--gap-xs);
}

.stat-card--accent .stat-card__value {
  color: var(--accent);
  text-shadow: 0 0 20px rgba(245, 197, 24, 0.2);
}

.stat-card__label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}

.stat-card__trend {
  font-size: 0.7rem;
  margin-top: var(--gap-xs);
  font-weight: 500;
}

/* ─── Filters Bar ─────────────────────────────────────── */
.filters-bar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  gap: var(--gap-md);
  padding: var(--gap-lg);
  margin-bottom: var(--gap-xl);
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
}

.filter-group--search {
  flex: 1;
  min-width: 200px;
}

.filter-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}

.filter-select,
.filter-input {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  outline: none;
  transition: all var(--transition-fast);
  min-width: 140px;
}

.filter-select:focus,
.filter-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.filter-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.search-input-wrapper {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input-wrapper .filter-input {
  padding-left: 36px;
  width: 100%;
}

/* ─── Buttons ─────────────────────────────────────────── */
.btn {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--gap-sm);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn--export {
  background: linear-gradient(135deg, var(--accent), #d4a912);
  color: #07070d;
  font-weight: 700;
  box-shadow: 0 2px 10px rgba(245, 197, 24, 0.2);
}

.btn--export:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(245, 197, 24, 0.35);
}

.btn--export:active {
  transform: translateY(0);
}

.btn--page {
  background: var(--bg-glass);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  padding: 8px 16px;
  font-size: 0.8rem;
}

.btn--page:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn--page:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ─── Table Container ─────────────────────────────────── */
.table-container {
  position: relative;
  z-index: 10;
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--gap-xl);
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap-lg) var(--gap-xl);
  border-bottom: 1px solid var(--border-subtle);
}

.table-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.table-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.table-wrapper {
  overflow-x: auto;
}

/* ─── Leads Table ─────────────────────────────────────── */
.leads-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.leads-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.leads-table th {
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  user-select: none;
}

.leads-table th.sortable {
  cursor: pointer;
  transition: color var(--transition-fast);
}

.leads-table th.sortable:hover {
  color: var(--accent);
}

.leads-table th.active-sort {
  color: var(--accent);
}

.sort-arrow {
  font-size: 0.65rem;
  margin-left: 4px;
}

.leads-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.025);
  color: var(--text-secondary);
  white-space: nowrap;
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leads-table td:first-child {
  color: var(--text-primary);
  font-weight: 500;
}

.leads-table tbody tr {
  transition: all var(--transition-fast);
  cursor: pointer;
}

.leads-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.leads-table tbody tr:hover td {
  color: var(--text-primary);
}

.leads-table tbody tr:hover td:first-child {
  color: var(--accent);
}

/* County badge in table */
.county-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--accent-dim);
  color: var(--accent);
  letter-spacing: 0.5px;
}

/* View button */
.btn-view {
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}

.btn-view:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 10px rgba(245, 197, 24, 0.1);
}

/* Loading state */
.loading-row td {
  text-align: center;
  padding: 60px;
  color: var(--text-muted);
}

.loading-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state__icon {
  font-size: 3rem;
  margin-bottom: var(--gap-md);
  opacity: 0.5;
}

.empty-state__text {
  font-size: 0.9rem;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-lg);
  padding: var(--gap-lg);
  border-top: 1px solid var(--border-subtle);
}

.pagination__info {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ─── Modal ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gap-xl);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-smooth);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-modal);
  border: var(--glass-border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 700px;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(30px) scale(0.96);
  transition: transform var(--transition-bounce);
  box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
  transform: translateY(0) scale(1);
}

.modal__close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.8rem;
  cursor: pointer;
  transition: color var(--transition-fast);
  line-height: 1;
  z-index: 10;
}

.modal__close:hover {
  color: var(--accent);
}

.modal__header {
  padding: var(--gap-xl) var(--gap-xl) var(--gap-md);
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  border-bottom: 1px solid var(--border-subtle);
}

.modal__title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal__badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--accent-dim);
  color: var(--accent);
}

.modal__body {
  padding: var(--gap-xl);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-lg);
  margin-bottom: var(--gap-xl);
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
}

.detail-item--full {
  grid-column: 1 / -1;
}

.detail-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}

.detail-value {
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 500;
}

.detail-value--highlight {
  color: var(--accent);
  font-weight: 700;
  font-size: 1rem;
}

.detail-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: opacity var(--transition-fast);
}

.detail-link:hover {
  opacity: 0.8;
}

/* Confidence bar */
.confidence-bar {
  position: relative;
  height: 24px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--error), var(--warning), var(--success));
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  width: 0%;
}

.confidence-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* Notice text */
.detail-notice {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.notice-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.7;
  max-height: 250px;
  overflow-y: auto;
  padding: var(--gap-md);
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  white-space: pre-wrap;
  word-break: break-word;
}

.notice-text::-webkit-scrollbar {
  width: 6px;
}

.notice-text::-webkit-scrollbar-track {
  background: transparent;
}

.notice-text::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 3px;
}

/* ─── Footer ──────────────────────────────────────────── */
.footer {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap-md) var(--gap-xl);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer__left {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
}

.footer__separator {
  opacity: 0.3;
}

.footer__right {
  display: flex;
  align-items: center;
  gap: var(--gap-xs);
}

.footer__right strong {
  color: var(--accent);
  font-weight: 600;
}

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

.stat-card { animation: fadeInUp 0.6s ease-out both; }
.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.1s; }
.stat-card:nth-child(3) { animation-delay: 0.15s; }
.stat-card:nth-child(4) { animation-delay: 0.2s; }

.filters-bar { animation: fadeInUp 0.6s ease-out 0.25s both; }
.table-container { animation: fadeInUp 0.6s ease-out 0.35s both; }

/* Row stagger animation */
@keyframes fadeInRow {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.leads-table tbody tr {
  animation: fadeInRow 0.3s ease-out both;
}

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

  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  body {
    padding: var(--gap-md);
  }

  .header {
    flex-direction: column;
    gap: var(--gap-md);
    text-align: center;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--gap-md);
  }

  .stat-card__value {
    font-size: 1.8rem;
  }

  .filters-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-select,
  .filter-input {
    width: 100%;
  }

  .leads-table {
    font-size: 0.75rem;
  }

  .leads-table th,
  .leads-table td {
    padding: 10px 8px;
  }

  .modal {
    max-height: 90vh;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .header__title {
    font-size: 1.2rem;
  }

  .footer {
    flex-direction: column;
    gap: var(--gap-sm);
    text-align: center;
  }
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}
