/* Overview components shared by the admin and the customer portal (UI Phase 2, workstream C).
 *
 * One family, two renderers: the admin's Django templates (admin/nq/kpi_card.html, pipeline.html, fresh.html,
 * calm.html) and the portal's React components (portal/src/components/overview.tsx) emit the same markup with these
 * classes, so both overviews share one grid rhythm, one KPI card and one pipeline strip in both themes. Values come
 * from brand/ui-tokens.css only (loaded first); tests/test_overview.py keeps it that way.
 *
 *   .nq-overview   four-column grid (two on phones); a [data-span="2"] cell spans two
 *   .nq-kpi        KPI card: label, optional icon, value, optional context chip and trend; a link when it has one
 *   .nq-pipeline   connected order stages, each a link to the filtered list
 *   .nq-fresh      "Live counts as of HH:MM TZ", with the teal live dot (teal is for live indicators only)
 *   .nq-calm       the compact one-row empty state for "nothing needs attention"
 */

.nq-overview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.nq-overview > li {
  margin: 0;
  padding: 0;
  list-style: none;
  min-width: 0;
}
.nq-overview > [data-span="2"] {
  grid-column: span 2;
}
@media (min-width: 64rem) {
  .nq-overview {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
  }
}

/* ---------- KPI card ---------- */
.nq-kpi {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  height: 100%;
  min-height: 7.25rem;
  box-sizing: border-box;
  padding: 16px;
  border: 1px solid var(--nq-line);
  border-radius: var(--nq-radius-xl);
  background: var(--nq-surface);
  box-shadow: var(--nq-shadow-xs);
  color: var(--nq-fg);
  text-decoration: none;
  transition:
    background-color var(--nq-duration-fast) var(--nq-ease),
    border-color var(--nq-duration-fast) var(--nq-ease);
}
a.nq-kpi:hover {
  border-color: var(--nq-line-strong);
  background: var(--nq-hover);
  color: var(--nq-fg);
  text-decoration: none;
}
a.nq-kpi:active {
  background: var(--nq-pill);
}
a.nq-kpi:focus-visible,
.nq-stage:focus-visible,
.nq-calm a:focus-visible {
  outline: 2px solid var(--nq-focus);
  outline-offset: 2px;
}
.nq-kpi-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--nq-text-body);
  font-weight: 500;
  line-height: 1.35;
  color: var(--nq-muted);
}
.nq-kpi-icon {
  flex: none;
  display: inline-flex;
  color: var(--nq-muted);
}
.nq-kpi-value {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--nq-fg);
}
.nq-kpi-value[data-pending] {
  color: var(--nq-faint);
}
.nq-kpi-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  min-height: 22px;
}
/* A context chip may be longer than a narrow card: let it wrap rather than run out of the card. */
.nq-kpi-foot > * {
  max-width: 100%;
  white-space: normal;
}
.nq-kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--nq-text-meta);
  font-variant-numeric: tabular-nums;
  color: var(--nq-muted);
}
@media (min-width: 64rem) {
  .nq-kpi {
    min-height: 8.5rem;
    padding: 20px;
  }
  .nq-kpi-value {
    font-size: 2rem;
  }
}

/* ---------- Order pipeline strip ---------- */
.nq-pipeline {
  border: 1px solid var(--nq-line);
  border-radius: var(--nq-radius-xl);
  background: var(--nq-surface);
  box-shadow: var(--nq-shadow-xs);
  overflow-x: auto;
  scroll-snap-type: x proximity;
}
.nq-pipeline-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 14px 24px 0;
}
.nq-pipeline-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--nq-fg);
}
.nq-pipeline-total {
  font-size: var(--nq-text-table);
  color: var(--nq-muted);
  font-variant-numeric: tabular-nums;
}
.nq-pipeline ol {
  display: flex;
  margin: 0;
  padding: 8px;
  list-style: none;
  min-width: max-content;
}
.nq-pipeline li {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-width: max-content; /* labels stay on one line; on a phone the cut-off stage says the strip scrolls */
  margin: 0;
  padding: 0;
  list-style: none;
  scroll-snap-align: start;
}
/* The connector: a chevron on the boundary between two stages, pointing the way orders move. */
.nq-pipeline li + li::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -5px;
  width: 9px;
  height: 9px;
  border-top: 1.5px solid var(--nq-control);
  border-right: 1.5px solid var(--nq-control);
  transform: translateY(-50%) rotate(45deg);
  pointer-events: none;
}
.nq-stage {
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-sizing: border-box;
  padding: 10px 14px 12px 16px;
  border-radius: var(--nq-radius-md);
  color: var(--nq-fg);
  text-decoration: none;
  transition: background-color var(--nq-duration-fast) var(--nq-ease);
}
a.nq-stage:hover {
  background: var(--nq-hover);
  color: var(--nq-fg);
  text-decoration: none;
}
a.nq-stage:active {
  background: var(--nq-pill);
}
.nq-stage-label {
  font-size: var(--nq-text-table);
  font-weight: 500;
  color: var(--nq-muted);
  white-space: nowrap;
}
.nq-stage-value {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
/* What holds a stage up, e.g. "2 short of stock" under Reserved: a chip that links to those orders. */
.nq-stage-note {
  align-self: flex-start;
  min-height: 24px; /* WCAG 2.5.8 target size */
  margin: -6px 0 6px 16px;
  text-decoration: none;
}
.nq-stage-note:hover {
  text-decoration: underline;
}
.nq-stage-note:focus-visible {
  outline: 2px solid var(--nq-focus);
  outline-offset: 2px;
}
.nq-stage[data-empty] .nq-stage-value {
  color: var(--nq-muted);
}
@media (min-width: 64rem) {
  .nq-pipeline ol {
    min-width: 0;
  }
  .nq-stage-value {
    font-size: 1.75rem;
  }
}

/* ---------- Freshness line ---------- */
.nq-fresh {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 0;
  font-size: var(--nq-text-body);
  color: var(--nq-muted);
  font-variant-numeric: tabular-nums;
}
.nq-live {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--nq-live);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--nq-live) 20%, transparent);
}

/* ---------- Calm row: the compact empty state ---------- */
.nq-calm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  min-height: 48px;
  box-sizing: border-box;
  margin: 0;
  padding: 10px 16px;
  border: 1px solid var(--nq-line);
  border-radius: var(--nq-radius-xl);
  background: var(--nq-surface);
  font-size: var(--nq-text-body);
  color: var(--nq-muted);
}
.nq-calm-icon {
  flex: none;
  display: inline-flex;
  color: var(--nq-ok);
}
.nq-calm strong {
  font-weight: 600;
  color: var(--nq-fg);
}
.nq-calm a {
  margin-left: auto;
  font-weight: 500;
  color: var(--nq-accent-fg);
  text-decoration: none;
  border-radius: var(--nq-radius-sm);
}
.nq-calm a:hover {
  text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
  .nq-kpi,
  .nq-stage {
    transition: none;
  }
}
