/* ============================================
   Parish Council Directory — Editorial Atlas
   ============================================ */

/* ---- Self-hosted fonts ---- */
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('/fonts/bricolage-grotesque.woff2') format('woff2');
  font-weight: 400 800;
  font-stretch: 100%;
  font-display: swap;
}

@font-face {
  font-family: 'Outfit';
  src: url('/fonts/outfit.woff2') format('woff2');
  font-weight: 300 600;
  font-display: swap;
}

:root {
  --bg: #f5f2eb;
  --bg-grain: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  --surface: #fffdf8;
  --surface-elevated: #fff;
  --border: #d9d3c7;
  --border-light: #ebe7de;
  --text: #1e1c18;
  --text-secondary: #5c574e;
  --text-muted: #8a847a;
  --accent: #2b5f45;
  --accent-light: #3a7d5c;
  --accent-subtle: #e6f0ea;
  --accent-hover: #1e4733;
  --badge-council-bg: #dceee3;
  --badge-council-fg: #1a5638;
  --badge-meeting-bg: #f5e6c8;
  --badge-meeting-fg: #7a5518;
  --badge-covered-bg: #e8e4dc;
  --badge-covered-fg: #5c574e;
  --badge-defunct-bg: #f5dcd9;
  --badge-defunct-fg: #943830;
  --badge-other-bg: #e8e4dc;
  --badge-other-fg: #5c574e;
  --font-display: 'Bricolage Grotesque', 'Georgia', serif;
  --font-body: 'Outfit', system-ui, -apple-system, sans-serif;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow-sm: 0 1px 3px rgba(30, 28, 24, 0.06);
  --shadow-md: 0 4px 12px rgba(30, 28, 24, 0.08);
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
}

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

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

/* ---- Skip link (accessibility) ---- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 1000;
  padding: 0.75rem 1.25rem;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.9rem;
  border-radius: 0 0 var(--radius) var(--radius);
  text-decoration: none;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 0;
  outline: none;
}

/* ---- Base ---- */
body {
  margin: 0;
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 1rem;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grain);
  background-repeat: repeat;
  background-size: 256px 256px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ---- Focus styles (accessibility) ---- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ---- Links ---- */
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(43, 95, 69, 0.3);
  text-underline-offset: 0.15em;
  transition: color var(--transition-fast), text-decoration-color var(--transition-fast);
}

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

/* ---- Header ---- */
.site-header {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 2.5rem 0 2rem;
  position: relative;
}

.site-header::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 0;
  right: 0;
  height: 3px;
  background: repeating-linear-gradient(
    90deg,
    var(--accent) 0,
    var(--accent) 4px,
    transparent 4px,
    transparent 8px
  );
  opacity: 0.35;
}

.site-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  font-optical-sizing: auto;
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.site-title a {
  color: var(--text);
  text-decoration: none;
}

.site-title a:hover {
  color: var(--accent);
}

.site-subtitle {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---- Intro ---- */
.intro {
  padding: 2.25rem 0 0.75rem;
}

.intro p {
  font-size: 1.1rem;
  margin: 0 0 1rem;
  max-width: 640px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.intro strong {
  color: var(--text);
  font-weight: 600;
}

/* ---- Search ---- */
.search-wrap {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  background-image: var(--bg-grain);
  background-repeat: repeat;
  background-size: 256px 256px;
  padding: 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search-wrap::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 0;
  right: 0;
  height: 8px;
  background: linear-gradient(to bottom, rgba(245, 242, 235, 0.9), transparent);
  pointer-events: none;
}

#search {
  flex: 1;
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.7rem 1rem 0.7rem 2.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238a847a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.85rem center;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

#search::placeholder {
  color: var(--text-muted);
}

#search:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.search-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---- Directory ---- */
.directory {
  padding-bottom: 3rem;
}

.district {
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base), border-color var(--transition-base);
  overflow: hidden;
}

.district:hover {
  border-color: var(--border);
}

details[open].district {
  box-shadow: var(--shadow-md);
  border-color: var(--border);
}

.district-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.9rem 1.15rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background var(--transition-fast);
  border-radius: var(--radius);
}

.district-header::-webkit-details-marker {
  display: none;
}

.district-header:hover {
  background: var(--accent-subtle);
}

.district-header::before {
  content: '';
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
  margin-right: 0.75rem;
  flex-shrink: 0;
  transition: transform var(--transition-fast);
  position: relative;
  top: -0.05rem;
}

details[open] > .district-header::before {
  transform: rotate(45deg);
  top: -0.15rem;
}

.district-name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
  line-height: 1.35;
}

.district-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: 1rem;
  font-variant-numeric: tabular-nums;
}

/* ---- Parish table ---- */
.parish-list {
  padding: 0 1.15rem 1rem;
  border-top: 1px solid var(--border-light);
}

.parish-list table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.parish-list thead th {
  text-align: left;
  padding: 0.45rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}

.parish-list thead th:nth-child(3) {
  text-align: right;
}

.parish-list thead th:nth-child(4) {
  text-align: right;
}

.parish-list td {
  padding: 0.5rem 0.5rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-light);
}

.parish-list tr:last-child td {
  border-bottom: none;
}

.parish-list tr {
  transition: background var(--transition-fast);
}

.parish-list tr:hover {
  background: var(--accent-subtle);
}

.parish-name {
  font-weight: 450;
  min-width: 200px;
}

.welsh-name {
  color: var(--text-muted);
  font-size: 0.85em;
  font-style: italic;
}

.parish-pop {
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text-secondary);
  font-size: 0.85rem;
  white-space: nowrap;
}

.parish-links {
  white-space: nowrap;
  font-size: 0.8rem;
  text-align: right;
}

.parish-links a {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: 0.5rem;
  padding: 0.2em 0.45em;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 500;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.parish-links a:hover {
  background: var(--accent-subtle);
  text-decoration: none;
}

.map-link {
  color: var(--accent);
}

.wd-link {
  color: var(--text-muted);
}

.wd-link:hover {
  color: var(--text-secondary);
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.2em 0.55em;
  border-radius: 100px;
  text-transform: lowercase;
  white-space: nowrap;
  line-height: 1.4;
}

.badge-council {
  background: var(--badge-council-bg);
  color: var(--badge-council-fg);
}

.badge-meeting {
  background: var(--badge-meeting-bg);
  color: var(--badge-meeting-fg);
}

.badge-covered {
  background: var(--badge-covered-bg);
  color: var(--badge-covered-fg);
}

.badge-defunct {
  background: var(--badge-defunct-bg);
  color: var(--badge-defunct-fg);
}

.badge-other {
  background: var(--badge-other-bg);
  color: var(--badge-other-fg);
}

/* ---- Footer ---- */
.site-footer {
  border-top: 2px solid var(--border);
  padding: 2rem 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.7;
  position: relative;
}

.site-footer::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 0;
  right: 0;
  height: 3px;
  background: repeating-linear-gradient(
    90deg,
    var(--accent) 0,
    var(--accent) 4px,
    transparent 4px,
    transparent 8px
  );
  opacity: 0.35;
}

.site-footer p {
  margin: 0.3rem 0;
}

.site-footer a {
  color: var(--text-secondary);
  text-decoration-color: rgba(92, 87, 78, 0.3);
}

.site-footer a:hover {
  color: var(--accent);
}

/* ---- Prose (privacy page etc.) ---- */
.prose {
  max-width: 640px;
  padding: 2rem 0 3rem;
}

.prose h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  margin: 0 0 1.5rem;
  letter-spacing: -0.02em;
}

.prose p {
  margin: 0 0 1rem;
  line-height: 1.75;
  color: var(--text-secondary);
}

.prose a {
  font-weight: 500;
}

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

.intro {
  animation: fadeInUp 0.5s ease both;
}

.search-wrap {
  animation: fadeInUp 0.5s ease 0.1s both;
}

.district {
  animation: fadeInUp 0.35s ease both;
}

/* Stagger first 12 districts */
.district:nth-child(1) { animation-delay: 0.15s; }
.district:nth-child(2) { animation-delay: 0.19s; }
.district:nth-child(3) { animation-delay: 0.23s; }
.district:nth-child(4) { animation-delay: 0.27s; }
.district:nth-child(5) { animation-delay: 0.31s; }
.district:nth-child(6) { animation-delay: 0.35s; }
.district:nth-child(7) { animation-delay: 0.39s; }
.district:nth-child(8) { animation-delay: 0.43s; }
.district:nth-child(9) { animation-delay: 0.47s; }
.district:nth-child(10) { animation-delay: 0.51s; }
.district:nth-child(11) { animation-delay: 0.55s; }
.district:nth-child(12) { animation-delay: 0.59s; }

/* Inner content reveal */
.parish-list {
  animation: fadeInUp 0.3s ease both;
}

/* ---- Reduced motion (accessibility) ---- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .site-title {
    font-size: 1.5rem;
  }

  .intro p {
    font-size: 1rem;
  }

  .parish-list td:nth-child(3),
  .parish-list th:nth-child(3) {
    display: none;
  }

  .parish-name {
    min-width: 0;
  }

  .district-header {
    flex-wrap: wrap;
    padding: 0.8rem 0.9rem;
  }

  .district-name {
    font-size: 0.95rem;
  }

  .district-meta {
    margin-left: 1.35rem;
    width: 100%;
    margin-top: 0.15rem;
  }

  .parish-list {
    padding: 0 0.9rem 0.75rem;
  }

  #search {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
}

/* ---- Print ---- */
@media print {
  .search-wrap,
  .skip-link {
    display: none;
  }

  body {
    background: #fff;
    background-image: none;
  }

  .district {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
    animation: none;
  }

  details[open] {
    display: block;
  }
}
