/* static/css/history.css — the Insights tab's upload history (static/js/history.js).
 *
 * Its own file: app.css is at its size cap. Every rule is scoped under #bx-history, and the
 * palette is the dashboard's: insights.css defines its --pk-* tokens for #bx-insights AND
 * #bx-history, so the two sections read as one page in both themes.
 *
 * One upload is one tile. The cover mosaic (up to four of the batch's own thumbnails) is the
 * one loud thing; everything around it is quiet 12-15px text. A batch tile opens in place by
 * spanning its whole row ([data-open]), the same move the results Grid makes.
 *
 * Both <section>s set padding explicitly: app.css carries a landing-page
 * `section { padding: 60px 28px }` that would otherwise apply here.
 */
#bx-history {
  margin: 0 -22px -20px;
  padding: 0;
  background: var(--pk-bg);
  color: var(--pk-text);
  font-family: var(--pk-font);
  font-variant-numeric: tabular-nums;
}
#bx-history *, #bx-history *::before, #bx-history *::after { box-sizing: border-box; }
#bx-history .hx-wrap {
  max-width: 1760px;
  margin: 0 auto;
  padding: 8px clamp(16px, 2.5vw, 40px) 40px;
}

/* ---------- Header ---------- */
#bx-history .hx-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 12px 24px; margin-bottom: 8px;
}
#bx-history .hx-head__text { min-width: 0; }
#bx-history .hx-title { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -.01em; color: var(--pk-text); }
#bx-history .hx-sub { margin: 4px 0 0; font-size: 13px; line-height: 1.45; color: var(--pk-muted); max-width: 72ch; }
#bx-history .hx-sub span { color: var(--pk-text); font-weight: 600; }
#bx-history .hx-head__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

#bx-history .hx-btn {
  height: 32px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--pk-border-strong); background: var(--pk-card);
  font: inherit; font-size: 13px; font-weight: 600; color: var(--pk-text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; white-space: nowrap;
}
#bx-history .hx-btn:hover { border-color: var(--pk-gold); }
#bx-history .hx-btn.is-primary { background: var(--pk-gold-tint); border-color: var(--pk-gold); color: var(--pk-gold-ink); }
#bx-history .hx-btn:focus-visible,
#bx-history .hx-pill:focus-visible,
#bx-history .hx-hit:focus-visible { outline: 2px solid var(--pk-video); outline-offset: 2px; }

#bx-history .hx-filter {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px;
  background: var(--pk-track); border: 1px solid var(--pk-border);
}
#bx-history .hx-filter[hidden] { display: none; }
#bx-history .hx-pill {
  height: 26px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent;
  font: inherit; font-size: 13px; font-weight: 500; color: var(--pk-muted); cursor: pointer;
}
#bx-history .hx-pill:hover { color: var(--pk-text); }
#bx-history .hx-pill[aria-pressed="true"] {
  background: var(--pk-card); color: var(--pk-text); font-weight: 600;
  box-shadow: 0 0 0 1px var(--pk-border-strong);
}

/* ---------- Day groups + grid ---------- */
#bx-history .hx-day { padding: 0; margin-top: 24px; }
#bx-history .hx-day__title { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--pk-muted); }
#bx-history .hx-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
@media (max-width: 520px) {
  #bx-history .hx-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

/* ---------- Tile ---------- */
#bx-history .hx-tile {
  min-width: 0;
  background: var(--pk-card);
  border: 1px solid var(--pk-border);
  border-radius: var(--pk-radius);
  overflow: hidden;
  transition: border-color .15s, transform .15s;
}
#bx-history .hx-tile:hover { border-color: var(--pk-border-strong); }
#bx-history .hx-tile:not([data-open]):hover { transform: translateY(-1px); }
#bx-history .hx-hit { display: block; cursor: pointer; border-radius: inherit; }
#bx-history .hx-hit:focus-visible { outline-offset: -2px; }

#bx-history .hx-cover {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--pk-subtle);
  display: grid;
  gap: 2px;
  overflow: hidden;
}
#bx-history .hx-cover img { width: 100%; height: 100%; object-fit: cover; display: block; min-height: 0; }
#bx-history .hx-cover[data-n="2"] { grid-template-columns: 1fr 1fr; }
#bx-history .hx-cover[data-n="3"] { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
#bx-history .hx-cover[data-n="3"] img:first-child { grid-row: 1 / 3; }
#bx-history .hx-cover[data-n="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
#bx-history .hx-cover__glyph {
  place-self: center; width: 40px; height: 40px; color: var(--pk-faint);
}
#bx-history .hx-cover__glyph svg {
  width: 100%; height: 100%; fill: none; stroke: currentColor;
  stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round;
}
#bx-history .hx-cover__chips { position: absolute; top: 8px; left: 8px; display: flex; gap: 4px; }
#bx-history .hx-chip,
#bx-history .hx-more {
  font-size: 12px; font-weight: 600; line-height: 1; padding: 5px 8px; border-radius: 6px;
  background: rgba(14, 16, 28, .72); color: #fff;
}
#bx-history .hx-more { position: absolute; right: 8px; bottom: 8px; }

#bx-history .hx-body { padding: 10px 12px 12px; min-width: 0; }
#bx-history .hx-name {
  font-size: 14px; font-weight: 600; line-height: 1.35; color: var(--pk-text);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}
#bx-history .hx-meta {
  margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
  font-size: 12px; color: var(--pk-muted);
}
#bx-history .hx-status { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--pk-muted); }
#bx-history .hx-status.is-ok { color: var(--pk-risk-passed); }
#bx-history .hx-status.is-warn { color: var(--pk-risk-medium); }
#bx-history .hx-score { margin-left: auto; color: var(--pk-muted); }
#bx-history .hx-score b { font-size: 15px; font-weight: 600; color: var(--pk-gold-text); }
#bx-history .hx-close { display: none; }

/* ---------- Open tile: spans the row, header becomes one line ---------- */
#bx-history .hx-tile[data-open] {
  grid-column: 1 / -1;
  border-color: var(--pk-gold);
  transform: none;
  overflow: visible;   /* the Agency CSV menu drops below the actions row (the cover is its own rounded box here) */
}
#bx-history .hx-tile[data-open] .hx-hit {
  display: flex; align-items: center; gap: 16px; padding: 12px; border-radius: 0;
}
#bx-history .hx-tile[data-open] .hx-cover { width: 120px; flex: none; border-radius: 8px; }
#bx-history .hx-tile[data-open] .hx-cover__chips,
#bx-history .hx-tile[data-open] .hx-more { display: none; }
#bx-history .hx-tile[data-open] .hx-body { flex: 1; padding: 0; }
#bx-history .hx-tile[data-open] .hx-name { font-size: 15px; }
#bx-history .hx-tile[data-open] .hx-status { margin-left: 0; }
#bx-history .hx-tile[data-open] .hx-close { display: inline-flex; flex: none; }

#bx-history .hx-detail { padding: 4px 12px 16px; border-top: 1px solid var(--pk-border); }
#bx-history .hx-detail[hidden] { display: none; }
#bx-history .hx-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0; }
#bx-history .hx-files {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 16px 12px;
}
#bx-history .hx-file { min-width: 0; }
#bx-history .hx-file__thumb {
  aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--pk-subtle);
  border: 1px solid var(--pk-border);
}
#bx-history .hx-file__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
#bx-history .hx-file.is-failed .hx-file__thumb { opacity: .55; }
#bx-history .hx-file__name {
  margin-top: 8px; font-size: 12px; color: var(--pk-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#bx-history .hx-file__title {
  margin-top: 2px; font-size: 13px; line-height: 1.4; color: var(--pk-text);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
#bx-history .hx-file__kw { margin-top: 4px; font-size: 12px; color: var(--pk-faint); }
#bx-history .hx-file__kw .hx-status { margin-left: 0; }

#bx-history .hx-loading { padding: 16px 0; font-size: 13px; color: var(--pk-muted); }
#bx-history .hx-older { display: flex; margin: 24px auto 0; }

@media (max-width: 520px) {
  #bx-history .hx-tile[data-open] .hx-cover { width: 72px; }
  #bx-history .hx-files { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  #bx-history .hx-tile { transition: none; }
  #bx-history .hx-tile:not([data-open]):hover { transform: none; }
}
