/* upmystreet.org — minimal, system fonts, responsive */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Fira Code", Menlo, monospace;
  --bg: #fff;
  --fg: #1a1a1a;
  --muted: #666;
  --border: #ddd;
  --accent: #0055a4;
  --accent-hover: #003d7a;
  --data1: #882E72;
  --data2: #B84D00;
  --highlight: #fff3cd;
  --radius: 4px;
  --max-width: 48rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --fg: #e8e8e8;
    --muted: #999;
    --border: #333;
    --accent: #6bb3ff;
    --accent-hover: #8ec8ff;
    --data1: #CC79A7;
    --data2: #E69F00;
    --highlight: #3d3520;
  }
}

html {
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:hover {
  text-decoration-thickness: 2px;
}
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  z-index: 100;
  text-decoration: none;
  border-radius: var(--radius);
}
.skip-link:focus {
  top: 0.5rem;
}

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

/* Header */
header {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
}

.meta-stats {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  margin: 0;
  padding: 0.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

header nav {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.logo {
  text-decoration: none;
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--fg);
}
.logo:hover {
  text-decoration: none;
}

.search-form button {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.search-form button:hover {
  background: var(--accent-hover);
}

/* Header nav links — no underline (navigation context is clear) */
.nav-links {
  display: flex;
  gap: 0.75rem;
  font-size: 0.8125rem;
}
.nav-links a {
  text-decoration: none;
  flex-shrink: 0;
}

/* Main */
main {
  flex: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1rem;
  width: 100%;
}

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}
.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
}
.footer-nav a, .footer-social a {
  text-decoration: none;
}
.footer-nav a:hover, .footer-social a:hover {
  text-decoration: underline;
}
.footer-nav {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}
.footer-social {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.footer-attribution p {
  margin: 0;
}
.dev-errors {
  background: #ff0;
  color: #000;
  border: 3px solid #f00;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  font-family: var(--mono);
  font-size: 0.8125rem;
}
.dev-errors ul { margin: 0.25rem 0 0; padding-left: 1.5rem; }
.dev-errors li { margin: 0.125rem 0; }

.page-stats {
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.75rem;
}

/* Home */
.home {
  text-align: center;
  padding: 4rem 0 2rem;
}
.home h1 {
  font-size: 2.5rem;
  margin: 0 0 0.25rem;
}
.tagline {
  color: var(--muted);
  font-size: 1.125rem;
  margin: 0 0 2rem;
}
.changelog {
  text-align: left;
  max-width: 32rem;
  margin: 2rem auto 0;
}
.changelog h2 {
  font-size: 0.875rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 0.5rem;
}
.changelog ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.changelog li {
  font-size: 0.8125rem;
  color: var(--muted);
  padding: 0.2rem 0;
}
.changelog time {
  color: var(--fg);
}

.search-form {
  display: flex;
  gap: 0.5rem;
  max-width: 28rem;
  margin: 0 auto 1rem;
}
.search-form input {
  flex: 1;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 1.125rem;
  background: var(--bg);
  color: var(--fg);
}
.search-form button {
  font-size: 1.125rem;
  padding: 0.625rem 1.25rem;
}
.examples {
  color: var(--muted);
  font-size: 0.875rem;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Postcode page */

/* Postcode bar: replaces nav-search in header */
.postcode-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 12rem;
  font-size: 0.9375rem;
}
.postcode-bar label {
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.875rem;
}
.postcode-bar .pc-input {
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.9375rem;
  background: var(--bg);
  color: var(--fg);
  min-width: 5rem;
  flex: 1;
}
.postcode-bar .pc-current {
  font-family: var(--mono);
  font-weight: 600;
}
.postcode-bar button {
  padding: 0.375rem 0.875rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
}
.postcode-bar button:hover {
  background: var(--accent-hover);
}


.notice.terminated {
  background: var(--highlight);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
}

/* Area list (compact flat display) */
.area-list {
  margin: 1rem 0;
}
.area-list dl {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.area-item {
  display: flex;
  gap: 0.5rem;
  padding: 0.2rem 0.25rem;
  font-size: 0.8125rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}
.area-item dt {
  flex-shrink: 0;
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
}
.area-item dt a {
  color: var(--muted);
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}
.area-item dt a:hover {
  color: var(--accent);
  text-decoration-style: solid;
}
.area-item dd {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Share */
.share-links {
  margin: 2rem 0 0;
  padding: 1.5rem 0 0;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
}
.share-links h2 {
  font-size: 0.75rem;
  font-weight: normal;
  color: var(--muted);
  margin: 0 0 0.75rem;
}
.share-buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1.25rem;
}
.share-btn {
  text-decoration: none;
  font-size: 0.875rem;
  color: var(--accent);
  text-decoration: none;
}
.share-btn:hover {
  text-decoration: underline;
}

/* Map */
.map {
  height: 300px;
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f0f0f0;
}
@media (prefers-color-scheme: dark) {
  .map { background: #2a2a2a; }
}

/* Hierarchy page */
.hierarchy-level {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.hierarchy-table {
  width: 100%;
  border-collapse: collapse;
}
.hierarchy-table th,
.hierarchy-table td {
  text-align: left;
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.hierarchy-table thead th {
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}

/* Area page */
.area-type {
  color: var(--muted);
  margin: 0 0 1rem;
}

.child-areas {
  columns: 2;
  column-gap: 2rem;
  list-style: none;
  padding: 0;
}
.child-areas li {
  padding: 0.25rem 0;
  break-inside: avoid;
}
.child-areas .code {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.postcode-list {
  columns: 3;
  column-gap: 2rem;
  list-style: none;
  padding: 0;
}
.postcode-list li {
  padding: 0.125rem 0;
  font-family: var(--mono);
  font-size: 0.875rem;
}
.terminated {
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.75rem;
}

/* Compare page — area items with two values */
.compare-page .area-list dl {
  grid-template-columns: 1fr;
}
.compare-row dd {
  flex: 1;
  min-width: 0;
}
.compare-row.different dd {
}

/* Search results */
.search-results {
  list-style: none;
  padding: 0;
}
.search-results li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.search-results .type {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: 0.5rem;
}
.search-results .postcode {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: 0.5rem;
}

/* Breadcrumb */
.breadcrumb {
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* Static pages (about, privacy) */
.static-page {
  line-height: 1.7;
}
.static-page h1 {
  margin: 0 0 1.5rem;
}
.static-page h2 {
  font-size: 1.125rem;
  margin: 1.5rem 0 0.5rem;
}
.static-page p {
  margin: 0 0 0.75rem;
}
.static-page ul {
  padding-left: 1.25rem;
  margin: 0 0 0.75rem;
}
.static-page li {
  margin-bottom: 0.375rem;
}

/* Area subtitle (type label + representative postcode) */
.area-subtitle {
  font-size: 0.8125rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

/* Glossary */
.glossary {
  margin: 0 0 1.5rem;
}
.glossary > div {
  padding: 0.375rem 0;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: 1rem;
}
.glossary dt {
  font-weight: 600;
  font-size: 0.9375rem;
}
.glossary dd {
  margin: 0.125rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.5;
}

/* Key-value table (school detail, etc.) */
.kv-table { border-collapse: collapse; }
.kv-table td:first-child { font-weight: 600; padding-right: 1.5em; white-space: nowrap; }
.kv-table td { padding: 0.2em 0; }

/* Feedback note */
.feedback { font-size: 0.85em; margin-top: 1.5em; padding: 0.6em 1em; background: #f0f4ff; border-left: 3px solid #2b5ea7; border-radius: 3px; }
.feedback a { color: #2b5ea7; font-weight: 600; }

/* Coming soon placeholder */
.coming-soon { color: var(--muted); font-style: italic; }

/* Responsive */
@media (max-width: 40rem) {
  .area-list dl {
    grid-template-columns: 1fr;
  }
  .child-areas,
  .postcode-list {
    columns: 1;
  }
  .compare-table {
    font-size: 0.875rem;
  }
  .home h1 {
    font-size: 1.75rem;
  }
  .footer-nav,
  .footer-social {
    flex-wrap: wrap;
  }
}

/* Print */
@media print {
  header, footer, .postcode-bar, .nav-links, .search-form, .meta-stats {
    display: none;
  }
  main {
    max-width: none;
  }
  .map {
    height: 250px;
    break-inside: avoid;
    border: 1px solid #ccc;
  }
  .maplibregl-ctrl-group,
  .maplibregl-ctrl-attrib {
    display: none;
  }
}

/* Admin: error dashboard */
.admin-errors { max-width: 1200px; }
.error-filters { display: flex; gap: 1rem; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; }
.error-filters select, .error-filters button { padding: 0.3rem 0.6rem; }
.error-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.error-table th, .error-table td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.error-table th { font-weight: 600; }
.error-table .count { text-align: right; font-weight: 700; }
.error-table details summary { cursor: pointer; max-width: 40rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.error-table details[open] summary { white-space: normal; }
.stack-trace { background: var(--bg); padding: 0.75rem; border-radius: 4px; overflow-x: auto; font-size: 0.8rem; margin-top: 0.5rem; white-space: pre-wrap; word-break: break-all; }

/* Stat boxes (data blocks) */
.stat-box {
  margin: 1.5rem 0;
}
.stat-box h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.25rem;
  margin: 0 0 0.25rem;
}
.stat-box h2 a {
  text-decoration: none;
  color: inherit;
  text-decoration: none;
}
.stat-box h2 a:hover {
  text-decoration: underline;
}
.about-data {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
  line-height: 1.4;
}
.stat-box .subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}
.stat-box table {
  width: 100%;
  border-collapse: collapse;
}
.stat-box th,
.stat-box td {
  text-align: left;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.stat-box thead th {
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat-box td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.8125rem;
}
.stat-box .footer {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.5rem;
}
.stat-box .no-data {
  color: var(--muted);
  font-style: italic;
  padding: 0.75rem 0;
}

@media (max-width: 40rem) {
  .stat-box table {
    font-size: 0.8125rem;
  }
  .stat-box th,
  .stat-box td {
    padding: 0.25rem 0.3rem;
  }
}

/* Deprivation strip charts */
.dep-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.6875rem;
  color: var(--muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.dep-bar {
  width: 8rem;
}
.dep-bar svg {
  display: block;
  width: 100%;
  height: 12px;
}
.compare-page .dep-bar svg {
  height: 18px;
}
.stat-box thead th.dep-label-1 { color: var(--data1); }
.stat-box thead th.dep-label-2 { color: var(--data2); }

/* MP block */
.party-dot {
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  vertical-align: baseline;
  margin-right: 0.2em;
}
.mp-single p,
.mp-col p {
  margin: 0.15rem 0;
  font-size: 0.875rem;
}
.mp-name { font-weight: 600; }
.mp-name a { color: inherit; }
.mp-party { color: var(--muted); font-size: 0.8125rem; }
.mp-constituency { font-size: 0.8125rem; }
.mp-contact { font-size: 0.8125rem; }
.mp-contact a { color: var(--link); }
.mp-devolved {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.5rem;
  font-style: italic;
}
.mp-compare {
  display: flex;
  gap: 2rem;
}
.mp-col {
  flex: 1;
}
.mp-label {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.mp-col:first-child .mp-label { color: var(--data1); }
.mp-col:last-child .mp-label { color: var(--data2); }
.mp-no-data { color: var(--muted); }

/* MP detail page */
.mp-header {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}
.mp-photo {
  border-radius: 4px;
  flex-shrink: 0;
  object-fit: cover;
}
.mp-header-text h1 { margin: 0 0 0.25rem; }

/* Election bar chart */
.election-bars { margin: 0.5rem 0; }
.election-bar-row { margin: 0.35rem 0; }
.election-bar-name {
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.1rem;
}
.election-bar-track {
  background: var(--border);
  height: 1.25rem;
  border-radius: 2px;
  overflow: hidden;
}
.election-bar-fill {
  height: 100%;
  border-radius: 2px;
  min-width: 2px;
}
.election-bar-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.1rem;
}
.election-bar-votes {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
}
.election-bar-pct {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
}

/* House prices */
.hp-headline {
  text-align: center;
  margin: 1rem 0 0.75rem;
}
.hp-median {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.hp-period {
  color: var(--muted);
  font-size: 0.85rem;
}
.hp-types {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}
.hp-type-label {
  color: var(--muted);
}
.hp-type-price {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Sparklines and rank bars */
.sparkline-cell { width: 5rem; }
.sparkline-cell svg { width: 5rem; height: 1.25rem; vertical-align: middle; }
.rankbar-cell { width: 7rem; }
.rankbar-cell svg { width: 7rem; height: 0.75rem; vertical-align: middle; }

.data-block .footer .agg {
  display: inline;
  margin-right: 1em;
  white-space: nowrap;
}

@media (max-width: 40rem) {
  .rankbar-cell { display: none; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
