/*
 * Tender in Nepal — base styles, layout and components.
 * Requires tokens.css. Plain CSS + semantic HTML so the Cloudflare Worker can render
 * every component on the server without a client framework.
 *
 * Visual rules: white backgrounds, borders over shadows, small radii, logo cobalt as the
 * one primary colour, serif headings,
 * results as dense rows rather than floating cards.
 */

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

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

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, figure, dl, dd, ul, ol, fieldset {
  margin: 0;
}

[hidden] { display: none !important; } /* components set display; hidden must still win */

fieldset { padding: 0; border: 0; min-width: 0; }
legend { padding: 0; }

ul[role="list"], ol[role="list"] {
  list-style: none;
  padding: 0;
}

img, svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--color-text-link);
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}
a:hover {
  color: var(--color-text-link-hover);
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

::selection {
  background: var(--color-primary-subtle-border);
}

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

/* Source-language text (notice titles, office names). Always add lang="ne". */
.source-text,
:lang(ne) {
  font-family: var(--font-source);
  line-height: var(--leading-source);
}

/* ── Accessibility helpers ───────────────────────────────────────────── */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -4rem;
  z-index: var(--z-modal);
  padding: var(--space-3) var(--space-4);
  background: var(--color-ink);
  color: var(--color-text-on-ink);
  font-weight: var(--weight-semibold);
}
.skip-link:focus { top: var(--space-4); }

/* ── Icons (sprite: icons.svg) ───────────────────────────────────────── */
.icon {
  width: 1.125rem;
  height: 1.125rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon--sm { width: 1rem; height: 1rem; }
.icon--lg { width: 1.5rem; height: 1.5rem; }

/* ── Layout ──────────────────────────────────────────────────────────── */
.container {
  width: min(100% - 2 * var(--gutter), var(--container-xl));
  margin-inline: auto;
}
.container--narrow { width: min(100% - 2 * var(--gutter), var(--container-lg)); }

.stack > * + * { margin-top: var(--stack-gap, var(--space-4)); }
.stack--sm { --stack-gap: var(--space-2); }
.stack--lg { --stack-gap: var(--space-8); }

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--cluster-gap, var(--space-3));
}
.cluster--sm { --cluster-gap: var(--space-2); }
.cluster--between { justify-content: space-between; }

/* Results page: filter column + results */
.listing-layout {
  display: grid;
  gap: var(--space-6);
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 1024px) {
  .listing-layout { grid-template-columns: 17.5rem minmax(0, 1fr); align-items: start; }
  /* The panel is taller than a laptop screen when every section is open: it scrolls inside itself, so the lower
     filters and the submit button stay reachable while the results scroll. */
  .listing-layout > :first-child {
    position: sticky;
    top: calc(var(--header-height) + var(--space-4));
    max-height: calc(100vh - var(--header-height) - var(--space-8));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* Detail page: notice image + facts column */
.detail-layout {
  display: grid;
  gap: var(--space-6);
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 1024px) {
  .detail-layout { grid-template-columns: minmax(0, 1fr) 22rem; align-items: start; }
  .detail-layout__aside { position: sticky; top: calc(var(--header-height) + var(--space-4)); }
}

/* ── Typography ──────────────────────────────────────────────────────── */
.h1, .h2, .h3 {
  font-family: var(--font-serif);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  letter-spacing: -0.01em;
}
.h1 { font-size: clamp(var(--text-2xl), 4vw, var(--text-4xl)); line-height: var(--leading-tight); }
.h2 { font-size: var(--text-2xl); line-height: var(--leading-snug); }
.h3 { font-size: var(--text-xl); line-height: var(--leading-snug); }
.h4 { font-size: var(--text-lg); line-height: var(--leading-snug); font-weight: var(--weight-semibold); }
.lead { font-size: var(--text-lg); color: var(--color-text-secondary); max-width: 42rem; }
.body-sm { font-size: var(--text-sm); }
.caption { font-size: var(--text-xs); color: var(--color-text-muted); }
.muted { color: var(--color-text-muted); }
.tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: 0.88em; }

/* Section heading with a hairline, like a newspaper section rule */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--color-text);
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  --btn-bg: var(--color-surface);
  --btn-fg: var(--color-text);
  --btn-border: var(--color-border-control);
  --btn-bg-hover: var(--color-surface-sunken);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height-md);
  padding: 0 var(--space-4);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard);
}
.btn:hover { background: var(--btn-bg-hover); color: var(--btn-fg); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* Primary: logo cobalt. One per view. */
.btn--primary {
  --btn-bg: var(--color-primary);
  --btn-fg: var(--color-text-on-primary);
  --btn-border: var(--color-primary);
  --btn-bg-hover: var(--color-primary-hover);
}
/* Ink: logo navy, solid — "open the notice". */
.btn--ink {
  --btn-bg: var(--color-ink);
  --btn-fg: var(--color-text-on-ink);
  --btn-border: var(--color-ink);
  --btn-bg-hover: var(--color-ink-hover);
}
.btn--ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-fg: var(--color-text-secondary);
}
.btn--danger {
  --btn-fg: var(--color-danger);
  --btn-bg-hover: var(--color-danger-subtle);
}
.btn--sm { min-height: var(--control-height-sm); padding: 0 var(--space-3); }
.btn--lg { min-height: var(--control-height-lg); padding: 0 var(--space-6); font-size: var(--text-md); }
.btn--icon { width: var(--control-height-md); padding: 0; }
.btn--icon.btn--sm { width: var(--control-height-sm); }
.btn--block { width: 100%; }
.btn[aria-pressed="true"] {
  --btn-bg: var(--color-primary-subtle);
  --btn-fg: var(--color-primary-text);
  --btn-border: var(--color-primary-subtle-border);
  --btn-bg-hover: var(--color-primary-subtle);
}

/* Text-style action, e.g. "Clear all" */
.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-text-link);
  font: inherit;
  font-size: var(--text-sm);
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
}

/* ── Form controls ───────────────────────────────────────────────────── */
.field { display: grid; gap: var(--space-1); align-content: start; }
.label { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); }
.hint { font-size: var(--text-xs); color: var(--color-text-muted); }
.error-text { font-size: var(--text-sm); color: var(--color-danger); font-weight: var(--weight-semibold); }

.input, .select, .textarea {
  width: 100%;
  min-width: 0;
  min-height: var(--control-height-md);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-md); /* ≥16px avoids iOS zoom on focus */
}
.textarea { padding: var(--space-3); min-height: 6rem; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--color-text-muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 0;
  border-color: var(--color-focus-ring);
}
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: var(--color-danger);
  border-width: 2px;
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--color-surface-sunken);
  color: var(--color-text-disabled);
  cursor: not-allowed;
}

.select {
  appearance: none;
  padding-right: var(--space-10);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%23667085' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 7.5 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 1.125rem;
}

.check {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 2rem;
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
}
.check input { width: 1.125rem; height: 1.125rem; margin: 0; accent-color: var(--color-primary); flex: none; }
.check__count { margin-left: auto; color: var(--color-text-muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }

/* Search: one bordered bar, button flush right */
.search {
  display: flex;
  align-items: stretch;
  background: var(--color-surface);
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
}
.search:focus-within { outline: 2px solid var(--color-focus-ring); outline-offset: 0; }
.search__icon { align-self: center; margin-left: var(--space-3); color: var(--color-text-muted); }
.search__input {
  flex: 1;
  min-width: 0;
  min-height: var(--control-height-lg);
  padding: 0 var(--space-3);
  border: 0;
  background: transparent;
  color: var(--color-text);
  font: inherit;
}
.search__input:focus-visible { outline: none; }
.search__input::placeholder { color: var(--color-text-muted); }
.search .btn { min-height: auto; border-radius: 0 calc(var(--radius-md) - 1px) calc(var(--radius-md) - 1px) 0; padding-inline: var(--space-6); }

/* ── Labels: status, tag, place ──────────────────────────────────────── */
/* Status — text label on a tint; colour is never the only signal. */
.status {
  --status-bg: var(--status-closed-bg);
  --status-fg: var(--status-closed-fg);
  display: inline-flex;
  align-items: center;
  padding: 0.0625rem 0.4375rem;
  border-radius: var(--radius-sm);
  background: var(--status-bg);
  color: var(--status-fg);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: 1.5;
  white-space: nowrap;
}
.status--open { --status-bg: var(--status-open-bg); --status-fg: var(--status-open-fg); }
.status--closing { --status-bg: var(--status-closing-bg); --status-fg: var(--status-closing-fg); }
.status--amended { --status-bg: var(--status-amended-bg); --status-fg: var(--status-amended-fg); }
.status--extended { --status-bg: var(--status-extended-bg); --status-fg: var(--status-extended-fg); }
.status--cancelled { --status-bg: var(--status-cancelled-bg); --status-fg: var(--status-cancelled-fg); }
.status--closed { --status-bg: var(--status-closed-bg); --status-fg: var(--status-closed-fg); }
.status--awarded { --status-bg: var(--status-awarded-bg); --status-fg: var(--status-awarded-fg); }

/* Tag — notice type or category; outlined, neutral. */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 0 0.4375rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  line-height: 1.5;
  white-space: nowrap;
}

/* Place — province/district marker */
.place {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  white-space: nowrap;
}
.place .icon { color: var(--color-text-muted); }

/* Provenance: where a value came from. Newspaper and official evidence stay distinct. */
.provenance {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  white-space: nowrap;
}
.provenance--official { color: var(--status-open-fg); }

/* ── Panel ───────────────────────────────────────────────────────────── */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.panel--padded { padding: var(--space-5); }
.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.panel__body { padding: var(--space-5); }

/* ── Tender list: results as rows ────────────────────────────────────── */
.tender-list {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.tender-row {
  position: relative;
  display: grid;
  gap: var(--space-3) var(--space-6);
  grid-template-columns: minmax(0, 1fr);
  padding: var(--space-5);
  border-top: 1px solid var(--color-border);
}
.tender-row:first-child { border-top: 0; }
.tender-row:hover { background: color-mix(in srgb, var(--color-surface-sunken) 60%, var(--color-surface)); }
@media (min-width: 768px) {
  .tender-row { grid-template-columns: minmax(0, 1fr) auto; }
}

.tender-row__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.tender-row__ref { color: var(--color-text-muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }

.tender-row__title {
  margin-top: var(--space-2);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-source);
}
.tender-row__title a { color: var(--color-text); text-decoration: none; }
.tender-row__title a:hover { text-decoration: underline; text-decoration-thickness: 1px; }
/* The title link covers the whole row: one tab stop, large hit area. */
.tender-row__title a::after { content: ""; position: absolute; inset: 0; }
.tender-row__title a:focus-visible { outline: none; }
.tender-row__title a:focus-visible::after { outline: 2px solid var(--color-focus-ring); outline-offset: -2px; }

.tender-row__office {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-1);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}
.tender-row__office .icon { color: var(--color-text-muted); }

.tender-row__facts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-5);
  margin-top: var(--space-3);
  font-size: var(--text-sm);
}
.tender-row__facts > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1); }
.tender-row__facts dt { color: var(--color-text-muted); white-space: nowrap; }
.tender-row__facts .days-left { margin-left: var(--space-1); }
.tender-row__facts dt::after { content: ":"; }
.tender-row__facts dd { color: var(--color-text); font-variant-numeric: tabular-nums; }

/* Right column: place + actions. Interactive children sit above the stretched link. */
/* The action stays on the same edge whether or not the notice has a place: on a phone the row is
   place (left) + action (right, always); from tablet up the action sits at the bottom of the column. */
.tender-row__aside {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.tender-row__aside .place { min-width: 0; }
@media (min-width: 768px) {
  .tender-row__aside { flex-direction: column; align-items: flex-end; justify-content: flex-start; }
}
.tender-row__actions { position: relative; z-index: 1; display: flex; flex: none; gap: var(--space-2); margin-left: auto; }
@media (min-width: 768px) {
  .tender-row__actions { margin-left: 0; margin-top: auto; }
}

/* Deadline — the most time-critical fact. */
.deadline dd { color: var(--color-text); font-weight: var(--weight-semibold); }
.deadline--soon dt, .deadline--soon dd { color: var(--status-closing-fg); }
.deadline--passed dd { color: var(--color-text-muted); font-weight: var(--weight-regular); }

/* ── Fact list (detail page) ─────────────────────────────────────────── */
.facts { display: grid; }
.facts__row {
  display: grid;
  gap: var(--space-1) var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
}
.facts__row:first-child { border-top: 0; padding-top: 0; }
.facts dt { font-size: var(--text-sm); color: var(--color-text-muted); }
.facts dd { overflow-wrap: anywhere; }
.facts dd .provenance { display: flex; margin-top: var(--space-1); }
@media (min-width: 640px) {
  .facts--wide .facts__row { grid-template-columns: 12rem minmax(0, 1fr); }
}
/* Missing values are stated plainly; never invented, never hidden. */
.is-missing { color: var(--color-text-muted); font-style: italic; }

/* ── Evidence: the unaltered newspaper crop ──────────────────────────── */
.evidence {
  background: var(--color-evidence-backdrop);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.evidence__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
}
.evidence__stage {
  display: grid;
  justify-items: center;
  padding: clamp(var(--space-3), 3vw, var(--space-8));
  overflow-x: auto;
}
/* Never restyle the crop: no filters, no rounding, fit-to-width only. */
.evidence__stage img {
  max-width: 100%;
  height: auto;
  background: var(--color-evidence-paper);
  box-shadow: var(--shadow-sheet);
}
.evidence__caption {
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

/* ── Lifecycle timeline ──────────────────────────────────────────────── */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__item {
  --tl-line: var(--status-closed-line);
  position: relative;
  padding: 0 0 var(--space-5) var(--space-6);
  border-left: 2px solid var(--color-border-strong);
  margin-left: 0.3125rem;
}
.timeline__item:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline__item::before {
  content: "";
  position: absolute;
  left: -0.4375rem;
  top: 0.375rem;
  width: 0.75rem;
  height: 0.75rem;
  border: 2px solid var(--tl-line);
  border-radius: 50%;
  background: var(--color-surface);
}
.timeline__item[aria-current="step"]::before { background: var(--tl-line); }
.timeline__item--open { --tl-line: var(--status-open-line); }
.timeline__item--amended { --tl-line: var(--status-amended-line); }
.timeline__item--extended { --tl-line: var(--status-extended-line); }
.timeline__item--cancelled { --tl-line: var(--status-cancelled-line); }
.timeline__item--awarded { --tl-line: var(--status-awarded-line); }
.timeline__title { font-weight: var(--weight-semibold); line-height: 1.4; }
.timeline__date { color: var(--color-text-muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.timeline__body { margin-top: var(--space-1); color: var(--color-text-secondary); font-size: var(--text-sm); }

/* ── Header (masthead) ───────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--color-surface);
  border-top: 3px solid var(--color-primary);
  border-bottom: 1px solid var(--color-border);
}
.site-header__inner { display: flex; align-items: center; gap: var(--space-8); min-height: var(--header-height); }
.brand { display: inline-flex; align-items: center; flex: none; }
.brand img { height: 1.875rem; width: auto; }
/* .brand__light / .brand__dark swap the logo with the theme. Guarded by the same
   @supports as the dark tokens: browsers that stay light must keep the dark logo. */
.brand__dark { display: none; }
@supports (color: light-dark(#000, #fff)) {
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .brand__light { display: none; }
    :root:not([data-theme="light"]) .brand__dark { display: block; }
  }
  :root[data-theme="dark"] .brand__light { display: none; }
  :root[data-theme="dark"] .brand__dark { display: block; }
}

.site-nav { display: none; align-self: stretch; gap: var(--space-6); }
.site-nav a {
  display: inline-flex;
  align-items: center;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--color-text-secondary);
  font-weight: var(--weight-semibold);
  text-decoration: none;
}
.site-nav a:hover { color: var(--color-text); }
.site-nav a[aria-current="page"] { color: var(--color-text); border-bottom-color: var(--color-primary); }
.site-header__actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }
@media (min-width: 768px) { .site-nav { display: flex; } .site-menu { display: none; } }

/* No-JS mobile menu built on <details> */
.site-menu { position: relative; }
.site-menu summary { list-style: none; }
.site-menu summary::-webkit-details-marker { display: none; }
.site-menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  z-index: var(--z-dropdown);
  display: grid;
  min-width: 14rem;
  padding: var(--space-2) 0;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-menu);
}
.site-menu__panel a { padding: var(--space-3) var(--space-4); color: var(--color-text); text-decoration: none; }
.site-menu__panel a:hover { background: var(--color-surface-sunken); }

.breadcrumb ol { display: flex; flex-wrap: wrap; gap: var(--space-2); list-style: none; padding: 0; margin: 0; font-size: var(--text-sm); }
.breadcrumb li + li::before { content: "›"; margin-right: var(--space-2); color: var(--color-text-muted); }
.breadcrumb a { color: var(--color-text-muted); }
.breadcrumb [aria-current="page"] { color: var(--color-text); }

.tabs { display: flex; gap: var(--space-6); border-bottom: 1px solid var(--color-border-strong); overflow-x: auto; }
.tabs a {
  padding: var(--space-3) 0;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--color-text-muted);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  white-space: nowrap;
}
.tabs a:hover { color: var(--color-text); }
.tabs a[aria-current="page"] { color: var(--color-text); border-bottom-color: var(--color-primary); }

.pagination { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); }
.pagination a, .pagination span {
  display: inline-grid;
  place-items: center;
  min-width: var(--control-height-md);
  min-height: var(--control-height-md);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.pagination span:not([aria-current]) { border-color: transparent; background: none; }
.pagination a:hover { background: var(--color-surface-sunken); }
.pagination [aria-current="page"] { background: var(--color-ink); border-color: var(--color-ink); color: var(--color-text-on-ink); font-weight: var(--weight-semibold); }

/* ── Filters ─────────────────────────────────────────────────────────── */
.filter-panel { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
.filter-panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.filter-panel__title { font-weight: var(--weight-bold); font-size: var(--text-md); }
.filter-panel__foot { padding: var(--space-4); border-top: 1px solid var(--color-border); }

/* Each filter is an accordion section, open by default when it has a value. */
.filter-section { border-top: 1px solid var(--color-border); }
.filter-section:first-of-type { border-top: 0; }
.filter-section > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height-md);
  padding: 0 var(--space-4);
  cursor: pointer;
  list-style: none;
  font-weight: var(--weight-semibold);
}
.filter-section > summary::-webkit-details-marker { display: none; }
.filter-section > summary .icon { margin-left: auto; color: var(--color-text-muted); transition: transform var(--duration-base) var(--ease-standard); }
.filter-section[open] > summary .icon { transform: rotate(180deg); }
.filter-section__count {
  display: inline-grid;
  place-items: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.3125rem;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-text-on-primary);
  font-size: 0.75rem;
  font-weight: var(--weight-bold);
}
.filter-section__body { padding: 0 var(--space-4) var(--space-4); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 2rem;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}
.chip:hover { border-color: var(--color-border-control); }
.chip[aria-pressed="true"],
.chip[aria-current="true"] {
  background: var(--color-primary-subtle);
  border-color: var(--color-primary-subtle-border);
  color: var(--color-primary-text);
  font-weight: var(--weight-semibold);
}
.chip--removable { background: var(--color-surface-sunken); border-color: var(--color-border); }
.chip--removable .icon { width: 0.875rem; height: 0.875rem; color: var(--color-text-muted); }
.chip--removable:hover .icon { color: var(--color-text); }

.date-presets { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.date-range { display: grid; gap: var(--space-3); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.date-range .input { padding-inline: var(--space-2); font-size: var(--text-sm); }

.active-filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.active-filters__label { color: var(--color-text-muted); }

.results-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.results-bar__count { font-weight: var(--weight-semibold); }
.results-bar__sort { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.results-bar__sort .select { width: auto; min-height: var(--control-height-sm); font-size: var(--text-sm); }

/* Below lg the filter panel collapses behind a button; at lg it is always shown. Showing a closed <details> needs
   ::details-content (Chrome 131+, Safari 18.4+). Without it the button stays visible at lg, so the panel can still be
   opened: hiding the button there would leave the filters unreachable. */
.filters-collapsible > summary { list-style: none; cursor: pointer; }
.filters-collapsible > summary::-webkit-details-marker { display: none; }
.filters-collapsible > .filter-panel { margin-top: var(--space-2); }
@media (min-width: 1024px) {
  @supports selector(::details-content) {
    .filters-collapsible > summary { display: none; }
    .filters-collapsible::details-content { content-visibility: visible; display: block; }
    .filters-collapsible > .filter-panel { margin-top: 0; }
  }
}

/* ── Feedback ────────────────────────────────────────────────────────── */
.alert {
  --alert-line: var(--status-awarded-line);
  --alert-fg: var(--status-awarded-fg);
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--alert-line);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.alert .icon { color: var(--alert-fg); margin-top: 0.15rem; }
.alert__title { font-weight: var(--weight-bold); }
.alert--success { --alert-line: var(--status-open-line); --alert-fg: var(--status-open-fg); }
.alert--warning { --alert-line: var(--status-closing-line); --alert-fg: var(--status-closing-fg); }
.alert--danger { --alert-line: var(--status-cancelled-line); --alert-fg: var(--status-cancelled-fg); }

.empty {
  display: grid;
  justify-items: start;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.skeleton {
  min-height: 1em;
  background: var(--color-surface-sunken);
  border-radius: var(--radius-xs);
  animation: skeleton 1.2s ease-in-out infinite alternate;
}
@keyframes skeleton { to { opacity: 0.45; } }

/* ── Footer ──────────────────────────────────────────────────────────── */
.site-footer {
  margin-top: var(--space-16);
  padding-block: var(--space-8);
  border-top: 1px solid var(--color-border-strong);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.site-footer a { color: var(--color-text-secondary); }

/* ── Data table ──────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th, .data-table td { padding: var(--space-3) var(--space-4); text-align: left; vertical-align: top; }
.data-table th { color: var(--color-text-muted); font-weight: var(--weight-semibold); border-bottom: 1px solid var(--color-border-strong); white-space: nowrap; }
.data-table td { border-top: 1px solid var(--color-border); }
.data-table tr:first-child td { border-top: 0; }

/* ── Browse links: crawlable entry points (provinces, offices, types) ── */
/* Filters are a GET form, which crawlers do not submit. Every indexable landing page
   (e.g. /tenders/province/bagmati/) also needs a plain link like these. */
.link-list { display: grid; gap: 0 var(--space-6); grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); list-style: none; margin: 0; padding: 0; }
.link-list a {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  text-decoration: none;
}
.link-list a:hover { color: var(--color-text-link); }
.link-list a:hover span:first-child { text-decoration: underline; }
.link-list__count { color: var(--color-text-muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }

/* ── Tender row extras: thumbnail variant, meta line, notes ──────────── */
/* Used when a notice has no extracted title: the crop thumbnail is what lets you scan
   the list. It is a preview for finding the notice, not the evidence (see .evidence). */
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.tender-row--thumb {
  grid-template-columns: 4.5rem minmax(0, 1fr);
  grid-template-areas: "thumb main" "aside aside";
}
.tender-row--thumb > .tender-row__thumb { grid-area: thumb; }
.tender-row--thumb > .tender-row__main { grid-area: main; min-width: 0; }
.tender-row--thumb > .tender-row__aside { grid-area: aside; }
@media (min-width: 768px) {
  .tender-row--thumb { grid-template-columns: 5.5rem minmax(0, 1fr) auto; grid-template-areas: "thumb main aside"; }
}
.tender-row__thumb {
  width: 100%;
  height: auto; /* an <img height="…"> attribute would otherwise set the height */
  align-self: start;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: top;
  background: var(--color-evidence-paper);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}
.tender-row__reasons { margin-top: var(--space-2); color: var(--color-text-secondary); font-size: var(--text-sm); }
.tender-row__main > :first-child { margin-top: 0; }

/* Page body spacing under the header */
.page-main { padding-block: var(--space-8) var(--space-12); }

/* ── Notice view: printed notice + sectioned facts panel ────────────── */
/* Modelled on how Bolpatra Nepal lays out a notice: the notice large on the left with
   Download and Print, facts grouped on the right. Unlike an empty "—", a field the pipeline has
   not read yet says "See notice image". */
.evidence__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.panel-section { padding: var(--space-5); }
.panel-section + .panel-section { border-top: 1px solid var(--color-border); }
.panel-section__title {
  margin-bottom: var(--space-3);
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
}

/* Two kinds of missing value. "Not stated": the notice does not say. "Pending": the notice may say,
   but extraction has not read it yet, so point at the image instead of implying it is absent. */
.is-pending { color: var(--color-text-muted); }
.is-pending a { color: var(--color-text-link); }

/* Days left until the deadline: calm when far, amber inside a week, grey once passed. */
.days-left {
  display: inline-flex;
  align-items: center;
  margin-left: var(--space-2);
  padding: 0 0.4375rem;
  border-radius: var(--radius-sm);
  background: var(--status-open-bg);
  color: var(--status-open-fg);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: 1.5;
  white-space: nowrap;
}
.days-left--soon { background: var(--status-closing-bg); color: var(--status-closing-fg); }
.days-left--passed { background: var(--status-closed-bg); color: var(--status-closed-fg); }

/* Printing a notice page prints the notice and its facts, nothing else, always on white. */
@media print {
  :root, :root[data-theme] { color-scheme: light; }
  .site-header, .site-footer, .skip-link, .breadcrumb, .evidence__actions, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .container { width: 100%; }
  .detail-layout { display: block; }
  .detail-layout__aside { position: static; margin-top: var(--space-4); }
  .evidence, .panel { border: 0; background: none; box-shadow: none; }
  .evidence__bar, .evidence__caption { background: none; border-color: #ccc; }
  .evidence__stage { padding: 0; overflow: visible; }
  .evidence__stage img { max-width: 100%; box-shadow: none; }
  .panel-section { padding-inline: 0; break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}

/* ── Adaptive: touch, notches, short screens ─────────────────────────── */
/* Fingers need 44px. Applied to touch devices and to any narrow window (a narrow desktop window is
   often a phone-sized one), not only to coarse pointers. */
@media (pointer: coarse), (max-width: 640px) {
  .btn--sm, .chip { min-height: var(--control-height-md); }
  .check { min-height: var(--control-height-md); }
  .check input { width: 1.375rem; height: 1.375rem; }
  .brand, .link-btn, .site-footer a, .breadcrumb a { display: inline-flex; align-items: center; min-height: var(--control-height-md); }
  .site-footer .cluster { gap: 0 var(--space-4); }
}

/* Phones with a notch or rounded corners (the viewport uses viewport-fit=cover). */
body { padding-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
.site-footer { padding-bottom: calc(var(--space-8) + env(safe-area-inset-bottom)); }

/* A sticky header takes a third of a landscape phone's height; let it scroll away. */
@media (max-height: 500px) and (orientation: landscape) {
  .site-header { position: static; }
  .listing-layout > :first-child, .detail-layout__aside { position: static; }
}
