:root {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-elevated: #f0f4fb;
  --surface-soft: rgba(31, 77, 143, 0.08);
  --text: #0e1726;
  --muted: #5b6b87;
  --border: rgba(15, 23, 42, 0.12);
  --accent: #1f4d8f;
  --accent-strong: #163a6b;
  --accent-soft: rgba(31, 77, 143, 0.15);
  --success: #2ea37c;
  --warning: #c77a17;
  --danger: #c2334d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(180deg, #f5f6f9 0%, #eef2f9 45%, #e4ebf7 100%);
  color: var(--text);
}

.app-shell {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.hero {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 18px 40px rgba(14, 23, 38, 0.12);
}

.hero-primary {
  flex: 2;
  min-width: 260px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.68rem;
  color: var(--accent);
  margin: 0 0 0.5rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.3rem, 5vw, 3.4rem);
  color: var(--accent-strong);
  font-family: 'Playfair Display', 'Georgia', serif;
  letter-spacing: 0.02em;
}

.hero-subtitle {
  color: var(--muted);
  max-width: 560px;
  font-size: 1rem;
  line-height: 1.6;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1.5rem;
}

.meta-pill {
  background: var(--surface-elevated);
  border-radius: 999px;
  padding: 0.85rem 1.3rem;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.meta-pill span {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.meta-pill strong {
  font-size: 0.95rem;
}

.hero-stats {
  flex: 1;
  min-width: 220px;
  display: grid;
  gap: 1rem;
}

.hero-card {
  background: var(--surface);
  border-radius: 1rem;
  padding: 1.25rem;
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
}

.hero-label {
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 0.7rem;
  color: var(--muted);
}

.hero-value {
  font-size: 2.4rem;
  margin: 0.25rem 0 0;
}

.hero-foot {
  color: var(--muted);
  font-size: 0.8rem;
}

.alert {
  border-radius: 1rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
  background: var(--surface);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.alert ul {
  margin: 0.5rem 0 0 1.2rem;
}

.alert.warning {
  background: rgba(199, 122, 23, 0.08);
  border-color: rgba(199, 122, 23, 0.4);
}

.alert.error {
  background: rgba(194, 51, 77, 0.08);
  border-color: rgba(194, 51, 77, 0.45);
}

.quick-nav {
  display: inline-flex;
  gap: 0.4rem;
  padding: 0.35rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  margin-bottom: 1.5rem;
  border: 1px solid rgba(15, 23, 42, 0.1);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.05);
}

.quick-nav a {
  text-decoration: none;
  color: var(--text);
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  transition: background 0.2s ease, color 0.2s ease;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.quick-nav a:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.quick-nav a:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.panel {
  background: var(--surface);
  border-radius: 1rem;
  padding: 1.5rem;
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
  box-shadow: 0 18px 35px rgba(15, 23, 42, 0.15);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.panel-head h2 {
  margin: 0;
  font-family: 'Playfair Display', 'Georgia', serif;
  letter-spacing: 0.04em;
}

.panel-metrics {
  display: flex;
  gap: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.filters-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: var(--surface-elevated);
  margin-bottom: 0.85rem;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.filter-field label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.filter-field input,
.filter-field select {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: 0.55rem;
  border: 1px solid rgba(15, 23, 42, 0.18);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.filter-reset {
  align-self: end;
  justify-self: start;
  border: 1px solid rgba(31, 77, 143, 0.25);
  background: rgba(31, 77, 143, 0.08);
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.filter-summary {
  margin: 0 0 0.9rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.stat-box {
  background: var(--surface-elevated);
  border-radius: 0.9rem;
  padding: 1rem;
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  font-size: 1.4rem;
  margin-top: 0.35rem;
  color: var(--accent-strong);
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.site-breakdown,
.histogram-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.site-breakdown li,
.histogram-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--border);
}

.site-breakdown li strong,
.histogram-list li strong {
  color: var(--accent-strong);
}

.insight-panel {
  background: linear-gradient(140deg, #ffffff, #f5f8ff);
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.insight-grid.solo {
  grid-template-columns: minmax(240px, 1fr);
}

.insight-card {
  background: var(--surface);
  border-radius: 0.95rem;
  padding: 1rem 1.2rem;
  border: 1px solid rgba(15, 23, 42, 0.1);
  box-shadow: 0 15px 30px rgba(15, 23, 42, 0.12);
}

.insight-card .label {
  text-transform: uppercase;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.12em;
}

.map-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.9rem;
}

.map-load-btn {
  border: 1px solid rgba(31, 77, 143, 0.28);
  background: rgba(31, 77, 143, 0.08);
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.map-load-btn:disabled {
  opacity: 0.65;
  cursor: progress;
}

.map-status {
  margin: 0;
  font-size: 0.9rem;
}

.map-canvas {
  width: 100%;
  height: 360px;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  overflow: hidden;
  background: linear-gradient(180deg, #f7f9fe, #edf2fb);
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  background: var(--surface);
}

th,
td {
  padding: 0.75rem 0.4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

thead th {
  text-align: left;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: rgba(15, 23, 42, 0.03);
  border-bottom: 1px solid rgba(15, 23, 42, 0.12);
}

tbody tr:hover {
  background: rgba(31, 77, 143, 0.04);
}

.listing-title {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.site-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.85rem;
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 0.85rem;
  border: 1px solid rgba(31, 77, 143, 0.35);
  color: var(--accent-strong);
}

.sort-trigger {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 0;
}

.sort-trigger::after {
  content: '↕';
  font-size: 0.75rem;
  margin-left: 0.35rem;
  color: var(--muted);
}

.sort-trigger[data-direction='asc']::after {
  content: '↑';
  color: var(--accent);
}

.sort-trigger[data-direction='desc']::after {
  content: '↓';
  color: var(--accent);
}

.change-feed {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.change-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 1rem;
}

.change-actions .map-load-btn[hidden] {
  display: none;
}

.change-item {
  background: var(--surface);
  border-radius: 1rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--border);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  border-left: 3px solid var(--accent);
}

.change-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.change-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.change-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  text-transform: capitalize;
  font-weight: 600;
  border: 1px solid transparent;
}

.badge-new {
  background: rgba(46, 163, 124, 0.15);
  color: var(--success);
  border-color: rgba(46, 163, 124, 0.3);
}

.badge-price {
  background: rgba(199, 122, 23, 0.15);
  color: var(--warning);
  border-color: rgba(199, 122, 23, 0.35);
}

.badge-attr {
  background: rgba(31, 77, 143, 0.18);
  color: var(--accent-strong);
  border-color: rgba(31, 77, 143, 0.4);
}

.badge-removed {
  background: rgba(194, 51, 77, 0.16);
  color: var(--danger);
  border-color: rgba(194, 51, 77, 0.4);
}

.badge-default {
  background: rgba(15, 23, 42, 0.08);
  border-color: rgba(15, 23, 42, 0.15);
}

.inline-link,
a {
  color: var(--accent);
}

.price-cell {
  min-width: 140px;
  font-weight: 600;
}

.link-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(31, 77, 143, 0.25);
  background: rgba(31, 77, 143, 0.08);
  color: var(--accent-strong);
  font-weight: 600;
  text-decoration: none;
}

.link-pill::after {
  content: '↗';
  font-size: 0.75rem;
}

.muted {
  color: var(--muted);
}

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

@media (max-width: 640px) {
  .hero,
  .panel,
  .hero-card,
  .insight-card {
    padding: 1rem;
  }

  th,
  td {
    padding: 0.65rem 0.3rem;
  }
}
