/* ==========================================================================
   The WRENN Report — Main Stylesheet
   ========================================================================== */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  color: #1a1a1a;
  line-height: 1.7;
  /* Faint dot grid — architectural graph paper nod */
  background-color: #fff;
  background-image: radial-gradient(circle, #c0c0c0 0.5px, transparent 0.5px);
  background-size: 20px 20px;
  /* Very subtle — just barely visible */
  background-blend-mode: normal;
  /* The dots are light grey on white, so inherently faint.
     If needed, overlay a semi-transparent white to reduce further. */
}

/* Overlay to soften the dot grid */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.2);
  z-index: -1;
  pointer-events: none;
}

/* --- Typography --- */
h1, h2, h3, h4 {
  font-family: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  font-weight: normal;
  line-height: 1.3;
}

h1 {
  font-size: 2rem;
  color: #EC0505;
  margin-bottom: 1rem;
}

h2 {
  font-size: 1.4rem;
  color: #EC0505;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

h3 {
  font-size: 1.15rem;
  color: #333;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

p {
  margin-bottom: 1rem;
}

a {
  color: #EC0505;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* --- Layout --- */
.site-header {
  background: #fff;
  padding: 0.75rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
  /* Solid white header over dot grid */
  background-image: none;
}

/* Red divider between nav and content — spans most of page width */
.site-header::after {
  content: '';
  display: block;
  margin: 0.75rem auto 0;
  width: 92%;
  height: 2px;
  background: #EC0505;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.site-logo {
  font-family: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  font-size: 1.25rem;
  color: #EC0505;
  text-decoration: none;
  font-weight: normal;
  letter-spacing: 0.02em;
}

.site-logo:hover {
  text-decoration: none;
}

.header-inner nav {
  display: flex;
  align-items: center;
  gap: 1.75rem;
  flex-wrap: wrap;
}

.header-inner nav a {
  font-size: 0.85rem;
  color: #333;
  text-decoration: none;
  letter-spacing: 0.03em;
  padding-bottom: 2px;
}

.header-inner nav a:hover,
.header-inner nav a[aria-current="page"] {
  text-decoration: underline;
  text-underline-offset: 4px;
  color: #1a1a1a;
}

.nav-auth {
  margin-left: auto;
}

.nav-auth a {
  font-size: 0.8rem;
  padding: 0.25rem 0.75rem;
  border: 1px solid #EC0505;
  border-radius: 4px;
  color: #EC0505;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.nav-auth a:hover {
  background: #EC0505;
  color: #fff;
  text-decoration: none;
}

#nav-signout {
  border-color: #6b7280;
  color: #6b7280;
}

#nav-signout:hover {
  background: #6b7280;
  color: #fff;
}

main {
  max-width: 780px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

.site-footer {
  border-top: 1px solid #e5e7eb;
  padding: 1.5rem 0;
  text-align: center;
  background: #fff;
  background-image: none;
}

.site-footer p {
  font-size: 0.85rem;
  color: #EC0505;
  margin: 0;
}

/* --- Building Summary (answers-first paragraph) --- */
.building-summary {
  font-size: 1.05rem;
  line-height: 1.75;
  color: #333;
  margin-bottom: 1.5rem;
  /* This is the most important element on the page for AI discovery.
     It appears before the h1 in the HTML. */
}

/* --- Building Facts (definition list) --- */
.building-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1.25rem;
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.building-facts dt {
  color: #6b7280;
  font-weight: normal;
}

.building-facts dd {
  color: #1a1a1a;
}

/* --- WRENN ID (three-word identifier) --- */
.wrenn-id {
  font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.9rem;
  color: #EC0505;
  letter-spacing: 0.02em;
}

/* --- Grade Badges --- */
.grade-badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.grade-i {
  background: #fef3c7;
  color: #92400e;
}

.grade-ii-star {
  background: #dbeafe;
  color: #1e40af;
}

.grade-ii {
  background: #f3f4f6;
  color: #374151;
}

/* Scotland/NI grades */
.grade-a {
  background: #fef3c7;
  color: #92400e;
}

.grade-b {
  background: #dbeafe;
  color: #1e40af;
}

.grade-c {
  background: #f3f4f6;
  color: #374151;
}

/* --- Building Description --- */
.building-description {
  margin-bottom: 2rem;
}

.building-description p {
  line-height: 1.8;
}

/* --- Gated Content (sign-in required) --- */
.gated-section {
  margin-top: 2rem;
  margin-bottom: 2rem;
}

.gate {
  background: #fafafa;
  border: 1px dashed #d1d5db;
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
}

.gate-message {
  color: #6b7280;
  font-size: 0.95rem;
  line-height: 1.7;
  margin: 0;
}

.auth-link {
  color: #EC0505;
  font-weight: 600;
}

/* Gated content revealed after sign-in */
.gated-content {
  display: none;
}

.gated-section.unlocked .gate {
  display: none;
}

.gated-section.unlocked .gated-content {
  display: block;
}

/* --- Search Page Header (text left, jump buttons right) --- */
.search-page-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2rem;
  align-items: start;
  margin-bottom: 1.5rem;
}

.search-page-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  /* Align with first paragraph, not the h1 — roughly h1 size + margin */
  padding-top: 3.5rem;
}

.search-page-buttons .btn {
  white-space: nowrap;
  text-align: center;
}

@media (max-width: 768px) {
  .search-page-header {
    grid-template-columns: 1fr;
  }

  .search-page-buttons {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

/* --- About Page Layout (image left, text right) --- */
.about-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3rem;
  align-items: start;
}

.about-image-placeholder {
  width: 100%;
  aspect-ratio: 4 / 5;
  background: #f9fafb;
  border: 1px dashed #d1d5db;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.about-image img {
  width: 100%;
  height: auto;
  border-radius: 8px;
}

@media (max-width: 768px) {
  .about-layout {
    grid-template-columns: 1fr;
  }
}

/* --- Home Page Layout --- */
.home-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3rem;
  align-items: start;
}

.home-image-placeholder {
  width: 100%;
  aspect-ratio: 4 / 5;
  background: #f9fafb;
  border: 1px dashed #d1d5db;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.home-image img {
  width: 100%;
  height: auto;
  border-radius: 8px;
}

@media (max-width: 768px) {
  .home-layout {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .home-image {
    order: -1; /* Image above text on mobile */
  }
}

/* --- Attribute Tags (for gated content once unlocked) --- */
.attribute-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.attribute-tag {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  font-size: 0.8rem;
  color: #374151;
  background: #f9fafb;
}

.attribute-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* --- Attribute Definition Lists (gated content) --- */
.attribute-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 1rem;
  margin: 0.5rem 0 1rem;
  font-size: 0.9rem;
}

.attribute-list dt {
  color: #6b7280;
  font-weight: normal;
}

.attribute-list dd {
  margin: 0;
  color: #1a1a1a;
}

/* --- Risk Badges --- */
.risk-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

.risk-high {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.risk-medium {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

.risk-low {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* --- EPC Rating Badges --- */
.epc-badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
}

.epc-a { background: #008054; }
.epc-b { background: #19b459; }
.epc-c { background: #8dce46; }
.epc-d { background: #ffd500; color: #1a1a1a; }
.epc-e { background: #fcaa65; color: #1a1a1a; }
.epc-f { background: #ef8023; }
.epc-g { background: #e9153b; }

/* --- Data Tables (price history, EPC history) --- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin: 0.5rem 0 1rem;
}

.data-table th {
  text-align: left;
  font-weight: 600;
  color: #6b7280;
  border-bottom: 2px solid #e5e7eb;
  padding: 0.4rem 0.6rem;
}

.data-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
}

.data-table tr:hover td {
  background: #f9fafb;
}

/* --- EPC History Expandable --- */
.epc-history {
  margin: 0.5rem 0;
}

.epc-history summary {
  cursor: pointer;
  padding: 0.3rem 0;
}

.epc-history summary:hover {
  color: #374151;
}

/* --- EPC Selector Table --- */
.epc-selector tr.epc-row:hover td {
  background: #f0f4ff;
}

.epc-selector tr.epc-row-selected td {
  background: #e8edf5;
  font-weight: 600;
}

/* --- LBC Application Decision Badges --- */
.decision-approved {
  color: #166534;
  font-weight: 600;
}

.decision-refused {
  color: #991b1b;
  font-weight: 600;
}

.decision-withdrawn {
  color: #6b7280;
  font-style: italic;
}

/* --- Related Links --- */
.related-links {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e5e7eb;
}

.related-links ul {
  list-style: none;
  padding: 0;
}

.related-links li {
  margin-bottom: 0.4rem;
}

.related-links a {
  font-size: 0.95rem;
}

/* --- Building Card (for index/listing pages) --- */
.building-list {
  list-style: none;
  padding: 0;
}

.building-card {
  padding: 1rem 0;
  border-bottom: 1px solid #f3f4f6;
}

.building-card:last-child {
  border-bottom: none;
}

.building-card-title {
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}

.building-card-title a {
  color: #EC0505;
}

.building-card-meta {
  font-size: 0.85rem;
  color: #6b7280;
}

/* --- Buttons --- */
.btn {
  display: inline-block;
  padding: 0.5rem 1.25rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: opacity 0.15s;
}

.btn:hover {
  opacity: 0.9;
  text-decoration: none;
}

.btn-primary {
  background: #EC0505;
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: #EC0505;
  border: 1.5px solid #EC0505;
}

/* --- Search Widget Container --- */
.search-container {
  background: #fafafa;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
}

.search-input-group {
  display: flex;
  gap: 0;
}

.search-input-group input {
  flex: 1;
  padding: 0.6rem 1rem;
  border: 1px solid #d1d5db;
  border-radius: 6px 0 0 6px;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
}

.search-input-group input:focus {
  border-color: #EC0505;
}

.search-input-group button {
  padding: 0.6rem 1rem;
  background: #EC0505;
  color: #fff;
  border: 1px solid #EC0505;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  font-size: 0.95rem;
}

/* --- Suggestion Chips --- */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.suggestion-chip {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border: 1px solid #EC0505;
  border-radius: 16px;
  font-size: 0.8rem;
  color: #EC0505;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}

.suggestion-chip:hover {
  background: #EC0505;
  color: #fff;
  text-decoration: none;
}

/* --- Pagination --- */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
}

.pagination a,
.pagination span {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border-radius: 4px;
}

.pagination a {
  color: #EC0505;
  border: 1px solid #e5e7eb;
}

.pagination a:hover {
  background: #f9fafb;
  text-decoration: none;
}

.pagination .current {
  background: #EC0505;
  color: #fff;
  border: 1px solid #EC0505;
}

/* --- Tables (for tabular data — AI-friendly) --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

th, td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

th {
  color: #6b7280;
  font-weight: normal;
  font-size: 0.85rem;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .header-inner nav {
    gap: 1rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  h2 {
    font-size: 1.2rem;
  }

  .building-facts {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .building-facts dt {
    margin-top: 0.5rem;
    font-weight: 600;
    color: #374151;
  }

  main {
    padding: 1.5rem 1rem 2rem;
  }
}

@media (max-width: 480px) {
  .header-inner nav {
    gap: 0.75rem;
    font-size: 0.8rem;
  }

  .site-logo {
    font-size: 1.1rem;
  }
}

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

.muted {
  color: #6b7280;
}

.text-small {
  font-size: 0.85rem;
}

/* --- Auth Modal --- */
#auth-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.auth-modal {
  background: #fff;
  border-radius: 10px;
  padding: 2rem 2.5rem;
  max-width: 400px;
  width: 90%;
  position: relative;
  font-family: inherit;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.auth-modal h2 {
  color: #EC0505;
  font-size: 1.3rem;
  margin-top: 0;
  margin-bottom: 1rem;
}

.auth-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #6b7280;
  cursor: pointer;
  line-height: 1;
}

.auth-close:hover {
  color: #1a1a1a;
}

.auth-modal label {
  display: block;
  font-size: 0.85rem;
  color: #374151;
  margin-bottom: 0.25rem;
  margin-top: 0.75rem;
}

.auth-modal input[type="email"],
.auth-modal input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
}

.auth-modal input:focus {
  outline: none;
  border-color: #EC0505;
}

.auth-error {
  color: #dc2626;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.auth-switch {
  text-align: center;
  font-size: 0.85rem;
  color: #6b7280;
  margin-top: 1rem;
  margin-bottom: 0;
}

.auth-switch a {
  color: #EC0505;
}

/* ==========================================================================
   Stats & Indices Page
   ========================================================================== */

/* --- Page layout: wider main + sidebar nav --- */
body.page-stats main {
  max-width: 1200px;
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 2.5rem;
  align-items: start;
}

body.page-stats main > h1,
body.page-stats main > .stats-intro,
body.page-stats main > .stats-freshness {
  grid-column: 1 / -1; /* full width */
}

/* --- Section nav (sticky sidebar) --- */
.stats-nav {
  position: sticky;
  top: 5rem;     /* below sticky header */
  grid-row: 4 / 20; /* span all section rows */
}

.stats-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 2px solid #e0e0e0;
}

.stats-nav li {
  margin: 0;
}

.stats-nav a {
  display: block;
  padding: 0.5rem 0 0.5rem 1rem;
  font-size: 0.82rem;
  color: #666;
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.stats-nav a:hover,
.stats-nav a.active {
  color: #EC0505;
  border-left-color: #EC0505;
  text-decoration: none;
}

.stats-intro {
  font-size: 1.05rem;
  color: #333;
  margin-bottom: 0.5rem;
}

.stats-freshness {
  font-size: 0.8rem;
  color: #999;
  margin-top: 0;
  margin-bottom: 2rem;
}

/* --- Stats Grid --- */
.stats-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stats-grid--4col { grid-template-columns: repeat(4, 1fr); }
.stats-grid--3col { grid-template-columns: repeat(3, 1fr); }
.stats-grid--2col { grid-template-columns: repeat(2, 1fr); }
.stats-grid--1col { grid-template-columns: 1fr; }

/* --- Stat Cards (base) --- */
.stat-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* --- Number cards: prominent data points --- */
.stat-card--number {
  text-align: center;
  border-top: 3px solid #EC0505;
  padding: 1.5rem 1rem 1.25rem;
}

.stat-card--number figure {
  margin: 0;
}

.stat-value {
  font-family: 'Palatino Linotype', Palatino, Georgia, serif;
  font-size: 2.25rem;
  font-weight: bold;
  color: #1a1a1a;
  line-height: 1.2;
  margin: 0.35rem 0;
}

.stat-label {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.stat-detail {
  font-size: 0.75rem;
  color: #aaa;
  margin-top: 0.3rem;
}

.stat-up { color: #166534; }
.stat-down { color: #991b1b; }

/* --- Chart cards --- */
.stat-card h3 {
  margin-top: 0;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: #555;
  font-weight: 600;
}

.chart-wrap {
  position: relative;
  height: 360px;
}

.chart-wrap--tall {
  height: 500px;
}

/* --- Stats tables --- */
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.stats-table th {
  text-align: left;
  font-weight: 600;
  color: #6b7280;
  border-bottom: 2px solid #e5e7eb;
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stats-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
}

.stats-table tr:hover td {
  background: #f9fafb;
}

/* --- Section headers --- */
.stats-section {
  margin-bottom: 3rem;
  scroll-margin-top: 5rem; /* offset for sticky header */
}

.stats-section h2 {
  font-size: 1.3rem;
  border-bottom: 2px solid #EC0505;
  padding-bottom: 0.5rem;
  margin-bottom: 1.25rem;
}

/* --- Responsive --- */
@media (max-width: 1000px) {
  /* Collapse sidebar nav on narrower screens */
  body.page-stats main {
    display: block;
    max-width: 900px;
  }

  .stats-nav {
    position: static;
    margin-bottom: 2rem;
  }

  .stats-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    border-left: none;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 0.5rem;
  }

  .stats-nav a {
    border-left: none;
    margin-left: 0;
    padding: 0.4rem 0.9rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
  }

  .stats-nav a:hover,
  .stats-nav a.active {
    border-left-color: transparent;
    border-bottom-color: #EC0505;
  }
}

@media (max-width: 900px) {
  .stats-grid--4col { grid-template-columns: repeat(2, 1fr); }
  .stats-grid--3col { grid-template-columns: repeat(2, 1fr); }
  .stats-grid--2col { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .stats-grid--4col,
  .stats-grid--3col { grid-template-columns: 1fr; }

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

  .chart-wrap { height: 260px; }
  .chart-wrap--tall { height: 360px; }
}
