/* THE PUEBLO LEDGER -- newspaper/ledger aesthetic. Self-contained, no CDN. */

:root {
  /* chart/palette roles, from the KCCS dataviz reference palette */
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --hairline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);

  --series-blue:    #2a78d6;
  --series-aqua:    #1baf7a;
  --series-yellow:  #eda100;
  --series-red:     #e34948;

  --status-good-bg:    #e5f6e5;
  --status-good-ink:   #0d5c0d;
  --status-warn-bg:    #fdf1d8;
  --status-warn-ink:   #8a5a00;
  --status-crit-bg:    #fbe2e1;
  --status-crit-ink:   #8a1f1f;

  --masthead-serif: Georgia, "Times New Roman", "Palatino Linotype", serif;
  --body-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #989691;
    --hairline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.12);

    --series-blue:    #3987e5;
    --series-aqua:    #199e70;
    --series-yellow:  #c98500;
    --series-red:     #e66767;

    --status-good-bg:    #123312;
    --status-good-ink:   #6fdb6f;
    --status-warn-bg:    #3a2c05;
    --status-warn-ink:   #f2c464;
    --status-crit-bg:    #3a1414;
    --status-crit-ink:   #f29a99;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: var(--body-sans);
  line-height: 1.55;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
a { color: var(--series-blue); text-decoration: none; }
a:hover, a:focus { text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--masthead-serif); font-weight: 700; line-height: 1.2; margin: 0 0 0.5rem; }
p { margin: 0 0 1rem; }
.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ---------- Masthead / nav ---------- */
.masthead {
  background: var(--surface-1);
  border-bottom: 3px solid var(--text-primary);
  padding: 1.25rem 0 0.75rem;
}
.masthead .wrap { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.35rem; }
.masthead .title {
  font-family: var(--masthead-serif);
  font-size: clamp(2rem, 8vw, 3.2rem);
  letter-spacing: 0.5px;
  margin: 0;
}
.masthead .tagline {
  font-family: var(--body-sans);
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0;
}
.masthead .dateline {
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  padding: 0.35rem 0;
  width: 100%;
  margin-top: 0.5rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

nav.primary {
  background: var(--surface-1);
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  z-index: 20;
}
nav.primary ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.9rem;
  margin: 0;
  padding: 0.6rem 1rem;
  max-width: 1080px;
  margin: 0 auto;
  overflow-x: auto;
  -ms-overflow-style: none;
  scrollbar-width: thin;
}
nav.primary a {
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
nav.primary a:hover { color: var(--series-blue); text-decoration: none; border-bottom: 2px solid var(--series-blue); }

/* ---------- Layout ---------- */
main { padding: 1.5rem 0 3rem; }
section { margin-bottom: 2.5rem; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 2px solid var(--text-primary);
  padding-bottom: 0.35rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.section-head h2 { font-size: 1.4rem; margin: 0; }
.section-head .see-all { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; }

/* ---------- Hero ---------- */
.hero {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  padding: 2rem 1.25rem;
  text-align: center;
  margin-bottom: 2rem;
}
.hero h1 { font-size: clamp(1.6rem, 5vw, 2.6rem); margin-bottom: 0.5rem; }
.hero p { color: var(--text-secondary); max-width: 640px; margin: 0 auto 1rem; }

/* ---------- Stat tiles ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}
@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  padding: 1rem;
  text-align: center;
}
.stat-tile .value {
  font-family: var(--masthead-serif);
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 700;
  display: block;
}
.stat-tile .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ---------- Cards / lists ---------- */
.card-list { display: flex; flex-direction: column; gap: 0.75rem; }
.card {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  padding: 0.9rem 1rem;
}
.card .card-title { font-weight: 700; margin-bottom: 0.15rem; }
.card .card-meta { font-size: 0.8rem; color: var(--text-secondary); }
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 700px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 980px) {
  .card-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
}
.card-grid .card { display: flex; flex-direction: column; gap: 0.4rem; }

/* ---------- Section (data-source) cards on home ---------- */
.section-card {
  display: block;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  padding: 1.1rem;
  height: 100%;
}
.section-card:hover { border-color: var(--series-blue); text-decoration: none; }
.section-card h3 { font-size: 1.1rem; margin-bottom: 0.35rem; }
.section-card p { color: var(--text-secondary); font-size: 0.88rem; margin-bottom: 0; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 0.2rem 0.55rem;
  border-radius: 3px;
  border-left: 3px solid currentColor;
  white-space: nowrap;
}
.badge-pass { background: var(--status-good-bg); color: var(--status-good-ink); }
.badge-reinspect { background: var(--status-warn-bg); color: var(--status-warn-ink); }
.badge-closed { background: var(--status-crit-bg); color: var(--status-crit-ink); }
.badge-neutral { background: var(--hairline); color: var(--text-secondary); border-left-color: var(--text-muted); }

/* ---------- Tables (mobile pan-not-shrink) ---------- */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--hairline);
  -webkit-overflow-scrolling: touch;
}
table.ledger {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--surface-1);
}
table.ledger th, table.ledger td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
table.ledger th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--text-primary);
  position: sticky;
  top: 0;
  background: var(--surface-1);
}
table.ledger tbody tr:hover { background: var(--page-plane); }
table.ledger td.wrap-cell { white-space: normal; min-width: 220px; }

/* Key-value detail table (permit/record fields) -- a row-label th, not a
   header row, so none of table.ledger's sticky/uppercase header treatment
   applies here. */
table.kv {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--surface-1);
}
table.kv th, table.kv td {
  padding: 0.5rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--hairline);
  vertical-align: top;
}
table.kv th {
  width: 38%;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
table.kv td.wrap-cell { white-space: normal; }

/* ---------- Filters ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.filter-bar input[type="search"] {
  flex: 1 1 220px;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--baseline);
  border-radius: 3px;
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 0.95rem;
}
.chip {
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip[aria-pressed="true"] {
  background: var(--series-blue);
  border-color: var(--series-blue);
  color: #fff;
}
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
  border: 1px dashed var(--baseline);
}

/* ---------- Data-unavailable state ---------- */
.data-pending {
  border: 1px dashed var(--baseline);
  background: var(--surface-1);
  padding: 1.25rem;
  text-align: center;
  color: var(--text-secondary);
}
.data-pending strong { color: var(--text-primary); }

/* ---------- Pending-access state (distinct from a scraper error) ---------- */
.callout-pending {
  border: 1px solid var(--series-blue);
  background: var(--surface-1);
  padding: 1.25rem 1.4rem;
}
.callout-pending h3 { font-size: 1.05rem; margin-bottom: 0.5rem; }
.callout-pending p:last-child { margin-bottom: 0; }
.ribbon {
  display: inline-block;
  background: var(--series-blue);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  margin-bottom: 0.6rem;
}
.section-card .ribbon { margin-bottom: 0.4rem; }

/* ---------- Callout ---------- */
.callout {
  border: 1px solid var(--status-crit-ink);
  background: var(--status-crit-bg);
  padding: 1rem 1.1rem;
  margin-bottom: 1.5rem;
}
.callout h3 { color: var(--status-crit-ink); font-size: 1rem; margin-bottom: 0.5rem; }
.callout ul { margin: 0; padding-left: 1.1rem; }
.callout li { margin-bottom: 0.3rem; font-size: 0.9rem; }

/* ---------- Establishment detail ---------- */
.detail-head { margin-bottom: 1.25rem; }
.detail-head .addr { color: var(--text-secondary); }
.insp-item {
  border: 1px solid var(--hairline);
  margin-bottom: 0.75rem;
}
.insp-item summary {
  cursor: pointer;
  list-style: none;
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-weight: 600;
}
.insp-item summary::-webkit-details-marker { display: none; }
.insp-item summary::after { content: "+"; font-weight: 700; color: var(--text-muted); }
.insp-item[open] summary::after { content: "\2212"; }
.insp-item .violations { padding: 0 1rem 1rem; border-top: 1px solid var(--hairline); }
.insp-item .violation { padding: 0.6rem 0; border-bottom: 1px solid var(--hairline); font-size: 0.9rem; }
.insp-item .violation:last-child { border-bottom: none; }
.insp-item .violation .code { font-weight: 700; }
.insp-item .violation .corrective { color: var(--text-secondary); margin-top: 0.25rem; }
.no-violations { padding: 1rem; color: var(--text-secondary); font-size: 0.9rem; }
.source-line { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.5rem; }
.source-link { display: inline-block; font-size: 0.78rem; font-weight: 600; margin-top: 0.35rem; }

/* ---------- Sparkline / SVG charts ---------- */
.viz-root svg { display: block; width: 100%; height: auto; }
.viz-root .grid-line { stroke: var(--hairline); stroke-width: 1; }
.viz-root .axis-label { fill: var(--text-muted); font-size: 10px; font-family: var(--body-sans); }
.viz-root .legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.78rem; margin-top: 0.5rem; color: var(--text-secondary); }
.viz-root .legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 0.35rem; vertical-align: -1px; }

/* ---------- Ads ---------- */
.house-ad {
  border: 1px solid var(--hairline);
  background: var(--surface-1);
  padding: 1rem;
  display: flex;
  gap: 0.9rem;
  align-items: center;
}
.house-ad .ad-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.25rem;
}
.house-ad img { width: 64px; height: 64px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.house-ad .ad-copy strong { display: block; margin-bottom: 0.2rem; }
.house-ad .ad-copy span { font-size: 0.85rem; color: var(--text-secondary); }
.house-ad img[data-ad-img].broken { display: none; }

/* ---------- Toggle (businesses admin filter) ---------- */
.toggle-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; font-size: 0.85rem; }
.toggle-row input { width: 16px; height: 16px; }
.hidden-by-toggle { display: none; }

/* ---------- Footer ---------- */
footer.site-footer {
  border-top: 3px solid var(--text-primary);
  background: var(--surface-1);
  padding: 1.5rem 0;
  margin-top: 2rem;
}
footer.site-footer .wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
}
footer.site-footer a { font-weight: 600; }
footer.site-footer .fine-print { color: var(--text-muted); font-size: 0.72rem; }

/* ---------- Methodology page ---------- */
.source-entry { border-bottom: 1px solid var(--hairline); padding: 0.9rem 0; }
.source-entry:last-child { border-bottom: none; }
.source-entry h3 { font-size: 1rem; margin-bottom: 0.25rem; }
.source-entry .meta { font-size: 0.8rem; color: var(--text-muted); }

/* ---------- Misc ---------- */
.pill-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.small-note { font-size: 0.78rem; color: var(--text-muted); }
.two-col { display: grid; grid-template-columns: 1fr; gap: 2rem; }
@media (min-width: 800px) {
  .two-col { grid-template-columns: 2fr 1fr; }
}
