/* The merchant directory (lib/directory/pages.js), in the site's own look: Gelasio, burnt orange,
   cream paper and fine rules. The --d-* tokens below map the site's colors and type (site.css) to
   the directory's parts; the layout after them uses only those. The nav and footer around it are
   the site's (masthead.css, footer.css). */

/* ---------- Colors and type ---------- */
.dir {
  --d-bg: var(--paper2);
  --d-layer: var(--paper);
  --d-layer-hover: var(--wash);
  --d-border: var(--rule);
  --d-border-strong: var(--line);
  --d-ink: var(--ink);
  --d-text: var(--text);
  --d-muted: var(--muted);
  --d-accent: var(--accent);
  --d-accent-hover: var(--accent-hover);
  --d-link: var(--accent-text);
  --d-on-accent: var(--on-accent);
  --d-kicker: var(--accent-text);
  --d-mark-bg: var(--wash);
  --d-mark-ink: var(--accent-text);
  --d-ok-bg: transparent; --d-ok: var(--up);
  --d-warn-bg: transparent; --d-warn: var(--warn);
  --d-bad-bg: transparent; --d-bad: var(--down);
  --d-neutral-bg: transparent; --d-neutral: var(--muted);
  --d-chip-bg: transparent; --d-chip: var(--ink);
  --d-radius: var(--r-sm);
  --d-sans: var(--serif);
  --d-body: var(--serif);
  --d-label: var(--mono);
  --d-title-weight: 700;
  --d-title-tracking: -0.025em;
  --d-heading-weight: 700;
}

/* ---------- Shared layout ---------- */
.dir {
  background: var(--d-bg);
  color: var(--d-text);
  font-family: var(--d-body);
  font-size: var(--fs-16);
  line-height: 1.5;
  padding-block: var(--s5) var(--s7);
}
.dir a { color: var(--d-link); }
.dir a:hover { text-decoration: underline; text-underline-offset: 3px; }
.dir :focus-visible { outline: 2px solid var(--d-accent); outline-offset: 2px; border-radius: 0; }
.dir h1, .dir h2, .dir h3 { color: var(--d-ink); font-family: var(--d-sans); }
.dir-mono { font-family: var(--d-label); font-size: 0.875em; }

.dir-section-title, .dir-showing, .dir-count, .dir-dl dt, .dir-credit {
  font-family: var(--d-label);
}
.dir-head { display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.dir-title {
  font-size: clamp(2rem, 5vw, 3rem); line-height: 1.1;
  font-weight: var(--d-title-weight); letter-spacing: var(--d-title-tracking);
}
.dir-dek { font-size: var(--fs-18); color: var(--d-muted); text-wrap: pretty; }
/* A line break that only applies where there's room for both lines; phones wrap naturally */
@media (max-width: 719px) { .dir-wide-break { display: none; } }

/* The top of the index: the headline and subhead centered, then the globe of every region across
   the page's full width. The globe is sized so its top 35% shows before the reader scrolls
   (directory-globe.js sets the exact height; this is the first guess, so the page doesn't jump). */
.dir { overflow-x: clip; }
.dir-hero { display: grid; gap: var(--s3); justify-items: center; text-align: center; margin-bottom: var(--s4); }
.dir-hero .dir-head { margin-bottom: 0; justify-items: center; position: relative; z-index: 1; } /* above the globe's box, which overlaps it */
.dir-globe-figure { margin: 0; display: grid; gap: var(--s1); width: 100vw; margin-inline: calc(50% - 50vw); }
.dir-globe-figure .dir-note { position: relative; z-index: 1; }
/* The canvas is sized from this box, never the other way round; the box is roomier than the globe,
   so the glow around it isn't cut off */
.dir-globe { position: relative; overflow: hidden; width: 100%; height: min(calc((100svh - 240px) * 2.66), 152vw); opacity: 0; transition: opacity 0.6s ease; touch-action: pan-y; }
.dir-globe canvas { display: block; }
.dir-globe.is-ready { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .dir-globe { transition: none; } }
.dir-globe-figure .dir-note { text-align: center; }

/* Buttons */
.dir-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  font: inherit; font-size: var(--fs-16); font-weight: 500; white-space: nowrap;
  color: var(--d-ink); background: transparent;
  border: 1px solid var(--d-border-strong); border-radius: var(--d-radius); cursor: pointer;
}
.dir a.dir-btn { color: var(--d-ink); text-decoration: none; }
.dir-btn:hover { background: var(--d-layer-hover); }
.dir-btn-primary, .dir a.dir-btn-primary { background: var(--d-accent); border-color: var(--d-accent); color: var(--d-on-accent); }
.dir-btn-primary:hover, .dir a.dir-btn-primary:hover { background: var(--d-accent-hover); border-color: var(--d-accent-hover); }
.dir-btn[disabled] { opacity: 0.6; cursor: progress; }

/* ---------- Search and filters (the index's finder) ---------- */
.dir-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dir-icon { width: 16px; height: 16px; flex: none; }
/* Only as wide as the four filter boxes need side by side, each just wide enough for the longest
   category name ("Government & NGOs", 222px with its count) plus a little room for browsers that
   draw text wider; centered. Long region names in the Location box shorten with "…". */
.dir-finder {
  --facet-min: 226px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s2);
  width: 100%; max-width: calc(4 * var(--facet-min) + 3 * var(--s2)); margin: 0 auto var(--s5);
}
.dir-finder-bar { display: flex; }
.dir-finder-q {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 var(--s2) 0 14px;
  background: var(--d-layer); border: 1px solid var(--d-border); border-radius: var(--r-md); color: var(--d-muted); cursor: text;
}
.dir-finder-q:focus-within { border-color: var(--d-border-strong); }
.dir .dir-finder-q input {
  flex: 1; min-width: 0; width: 0; /* grows into the room the box leaves, never wider */ min-height: 42px; padding: 0; border: 0; background: transparent;
  font: inherit; font-size: var(--fs-16); color: var(--d-ink);
}
.dir .dir-finder-q input:focus { outline: none; }
.dir-finder-q input::placeholder { color: var(--d-muted); opacity: 1; }

/* The four filter boxes, open while the search bar is in use: four across, two on tablets, one on phones */
/* Four across when they fit, two on tablets, one on phones: never three and one */
.dir-facets { display: grid; gap: var(--s2); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 600px) { .dir-facets { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1004px) { .dir-facets { grid-template-columns: repeat(4, minmax(0, 1fr)); } } /* the finder's width plus the page's side gutters */
.dir-facets[hidden] { display: none; }
.dir-facet { margin: 0; padding: 0; min-width: 0; background: var(--d-layer); border: 1px solid var(--d-border); border-radius: var(--r-md); overflow: hidden; }
.dir .dir-facet-search {
  display: block; width: 100%; min-height: 38px; padding: 0 14px; border: 0; border-bottom: 1px solid var(--d-border);
  border-radius: 0; background: transparent; font: inherit; font-size: var(--fs-14); color: var(--d-ink);
}
.dir .dir-facet-search:focus { outline: none; background: var(--d-bg); }
.dir-facet-search::placeholder { color: var(--d-muted); opacity: 1; }
.dir-facet-list { list-style: none; margin: 0; padding: 4px; height: 240px; overflow-y: auto; overscroll-behavior: contain; }
.dir-facet-list li[hidden] { display: none; }
.dir-option {
  display: flex; align-items: center; gap: 10px; min-height: 32px; padding: 0 8px; border-radius: var(--r-sm);
  font-size: var(--fs-14); color: var(--d-ink); cursor: pointer;
}
/* Fingers need bigger rows than pointers */
@media (pointer: coarse) { .dir-option { min-height: 40px; } }
.dir-option:hover { background: var(--d-layer-hover); }
.dir-option input { flex: none; width: 15px; height: 15px; margin: 0; accent-color: var(--d-accent); cursor: pointer; }
.dir-option-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dir-option-count {
  flex: none; padding: 1px 6px; font-family: var(--d-label); font-size: 11px; color: var(--d-muted);
  background: var(--d-bg); border-radius: var(--r-sm);
}
.dir-facet-list li.is-empty .dir-option { color: var(--d-muted); }
.dir-facet-note { padding: 8px; font-size: var(--fs-14); color: var(--d-muted); }
.dir-near-status { margin: 0; }
/* The Apply button is for readers without scripts; with them, ticking a box applies it */
.dir-finder-apply { margin: 0; }
.dir-finder.is-live .dir-finder-apply { display: none; }

/* Sections */
.dir-section { margin-top: var(--s5); }
.dir-section-title {
  font-size: var(--fs-12); letter-spacing: 0.12em; text-transform: uppercase; color: var(--d-muted);
  font-weight: 500; font-family: var(--d-label);
}
.dir-section > .dir-section-title { margin-bottom: var(--s2); }

/* Results */
.dir-results-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: var(--s1); margin-bottom: var(--s2); }
.dir-showing { font-size: var(--fs-14); color: var(--d-muted); }
.dir-active { list-style: none; margin: 0 0 var(--s2); padding: 0; display: flex; flex-wrap: wrap; gap: var(--s1); align-items: center; }
.dir-clear { font-size: var(--fs-14); }

.dir-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.dir-card {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--s2); align-items: start;
  padding: var(--s3); background: var(--d-layer); border: 1px solid var(--d-border); border-radius: var(--d-radius);
}
.dir-card:hover { background: var(--d-layer-hover); }
.dir-card-body { display: grid; gap: 6px; min-width: 0; }
.dir-card-name { font-size: var(--fs-18); line-height: 1.3; font-weight: var(--d-heading-weight); overflow-wrap: anywhere; }
.dir .dir-card-name a { color: var(--d-ink); text-decoration: none; }
/* The whole card is the link */
.dir-card-name a::after { content: ""; position: absolute; inset: 0; }
.dir-card:focus-within { outline: 2px solid var(--d-accent); outline-offset: -2px; }
.dir-card-name a:focus-visible { outline: 0; }
.dir-km { font-family: var(--d-label); font-size: var(--fs-14); color: var(--d-ink); white-space: nowrap; }
.dir-meta { font-size: var(--fs-14); color: var(--d-muted); overflow-wrap: anywhere; }

.dir-mark {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  background: var(--d-mark-bg); color: var(--d-mark-ink); border-radius: var(--d-radius);
  font-family: var(--d-sans); font-size: var(--fs-18); font-weight: 600;
}
.dir-mark-lg { width: 72px; height: 72px; font-size: var(--fs-32); }

/* Status tags and chips */
.dir-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.dir-tag, .dir-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 0 8px;
  font-family: var(--d-label); font-size: var(--fs-12); line-height: 1; white-space: nowrap; border-radius: var(--d-radius);
}
.dir-tag-ok { background: var(--d-ok-bg); color: var(--d-ok); }
.dir-tag-warn { background: var(--d-warn-bg); color: var(--d-warn); }
.dir-tag-bad { background: var(--d-bad-bg); color: var(--d-bad); }
.dir-tag-neutral { background: var(--d-neutral-bg); color: var(--d-neutral); }
.dir-chip { background: var(--d-chip-bg); color: var(--d-chip); }
.dir a.dir-chip-remove { min-height: 32px; color: var(--d-chip); text-decoration: none; }
.dir a.dir-chip-remove:hover { background: var(--d-layer-hover); }

/* Pages */
.dir-pages { display: flex; flex-wrap: wrap; gap: var(--s1); align-items: center; justify-content: center; margin-top: var(--s5); }
.dir-pages ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.dir-pages a, .dir-gap {
  display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0 12px;
  font-family: var(--d-label); font-size: var(--fs-14); color: var(--d-ink); border-radius: var(--d-radius);
}
.dir .dir-pages a { color: var(--d-ink); text-decoration: none; border: 1px solid var(--d-border); background: var(--d-layer); }
.dir .dir-pages a:hover { background: var(--d-layer-hover); }
.dir .dir-pages a[aria-current="page"] { background: var(--d-accent); border-color: var(--d-accent); color: var(--d-on-accent); }
.dir-gap { color: var(--d-muted); }

.dir-empty { display: grid; gap: var(--s2); justify-items: start; padding: var(--s5) var(--s4); background: var(--d-layer); border: 1px solid var(--d-border); border-radius: var(--d-radius); }
.dir-empty h3 { font-size: var(--fs-24); font-weight: var(--d-title-weight); }
.dir-empty p { max-width: 60ch; color: var(--d-muted); }

/* ---------- A merchant's page ---------- */
.dir-crumbs { display: flex; flex-wrap: wrap; gap: var(--s1); font-size: var(--fs-14); color: var(--d-muted); margin-bottom: var(--s3); }
.dir-merchant-head { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s3); align-items: start; }
.dir-merchant-title { display: grid; gap: var(--s1); min-width: 0; }
.dir-merchant-title .dir-meta { font-size: var(--fs-16); }
.dir-visit { grid-column: 1 / -1; justify-self: start; }
@media (min-width: 760px) {
  .dir-merchant-head { grid-template-columns: auto minmax(0, 1fr) auto; }
  .dir-visit { grid-column: auto; }
}

.dir-detail { display: grid; gap: var(--s3); margin-top: var(--s5); }
@media (min-width: 960px) { .dir-detail { grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr); align-items: start; } }
.dir-detail-main, .dir-detail-side { display: grid; gap: var(--s3); min-width: 0; }
.dir-panel { display: grid; gap: var(--s2); padding: var(--s4); background: var(--d-layer); border: 1px solid var(--d-border); border-radius: var(--d-radius); }
.dir-panel .dir-section-title { display: flex; gap: var(--s1); align-items: baseline; }
.dir-prose { display: grid; gap: 0.8em; color: var(--d-text); }
.dir-note { font-size: var(--fs-14); color: var(--d-muted); }

.dir-steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: grid; gap: var(--s2); }
.dir-steps li { counter-increment: step; display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: var(--s2); color: var(--d-text); }
.dir-steps li::before {
  content: counter(step); display: inline-grid; place-items: center; width: 32px; height: 32px;
  font-family: var(--d-label); font-size: var(--fs-14); background: var(--d-mark-bg); color: var(--d-mark-ink); border-radius: var(--d-radius);
}

.dir-dl { margin: 0; display: grid; }
.dir-dl > div { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: var(--s2); padding: 10px 0; border-top: 1px solid var(--d-border); }
.dir-dl > div:first-child { border-top: 0; padding-top: 0; }
.dir-dl dt { font-size: var(--fs-12); letter-spacing: 0.08em; text-transform: uppercase; color: var(--d-muted); padding-top: 3px; }
.dir-dl dd { margin: 0; overflow-wrap: anywhere; color: var(--d-ink); }

.dir-branches { list-style: none; margin: 0; padding: 0; display: grid; }
.dir-branches li { display: grid; gap: 2px; padding: var(--s2) 0; border-top: 1px solid var(--d-border); }
.dir-branches li:first-child { border-top: 0; padding-top: 0; }
.dir-branch-name { color: var(--d-ink); font-weight: 500; }

.dir-map { height: 340px; background: var(--d-layer); border: 1px solid var(--d-border); border-radius: var(--d-radius); z-index: 0; }
@media (min-width: 960px) { .dir-map { height: 400px; } }
.dir .leaflet-container { font-family: var(--d-body); }
.dir .leaflet-popup-content { font-size: var(--fs-14); margin: 10px 14px; }
:root[data-theme="dark"] .dir .leaflet-tile-pane { filter: brightness(0.75) contrast(1.1) saturate(0.6); }

.dir-credit { margin-top: var(--s5); font-size: var(--fs-12); color: var(--d-muted); }
.dir-credit a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- The site's touches: rules instead of boxes, like the story lists ---------- */
.dir { padding-top: var(--pad-y); }
.dir .dir-head { border-bottom: 1px solid var(--d-border-strong); padding-bottom: var(--s3); max-width: none; }
/* The top section's space below the subhead, with no rule: the search bar follows */
.dir .dir-hero { padding-bottom: var(--s3); }
.dir .dir-hero .dir-head { border-bottom: 0; padding-bottom: 0; }
.dir .dir-dek { font-style: italic; }
.dir .dir-btn { font-family: var(--d-label); font-size: var(--fs-14); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.dir .dir-cards { gap: 0 var(--col-gap); border-top: 1px solid var(--d-border-strong); }
.dir .dir-card { background: transparent; border: 0; border-bottom: 1px solid var(--d-border); border-radius: 0; padding: var(--s3) 0; }
.dir .dir-card:hover { background: transparent; }
.dir .dir-card:hover .dir-card-name a { color: var(--d-link); }
.dir .dir-mark { border-radius: 50%; }
.dir .dir-tag, .dir .dir-chip { padding: 0; min-height: 0; text-transform: uppercase; letter-spacing: 0.06em; }
.dir .dir-tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.dir .dir-tags { gap: 4px 14px; }
.dir a.dir-chip-remove { border: 1px solid var(--d-border); padding: 0 10px; min-height: 0; }
.dir .dir-panel { background: transparent; border: 0; border-top: 1px solid var(--d-border-strong); border-radius: 0; padding: var(--s3) 0 0; }
.dir .dir-empty { background: transparent; border: 0; border-top: 1px solid var(--d-border-strong); padding-inline: 0; }
.dir .dir-steps li::before { border-radius: 50%; }
