/* ---------------------------------------------------------------------------
   history.css — the run history table.  Owned by A7.
   ---------------------------------------------------------------------------
   Twelve columns is a lot, and it is the right amount: the question this
   screen answers is "which run should I open", and that is answered by the
   funnel numbers side by side, not by a card that hides them behind a click.

   Below 900px the same rows become stacked records rather than a table with a
   horizontal scrollbar. A dense grid on a 390px phone is a grid nobody reads.
--------------------------------------------------------------------------- */

.history { display: flex; flex-direction: column; gap: var(--s-3); }

.history__bar { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.history__summary { margin: 0; font-size: var(--t-md); }
.history__live {
  display: inline-flex; align-items: center; gap: var(--s-2);
  margin-left: auto;
  font-size: var(--t-sm); color: var(--c-fg-muted);
}

.history__skeleton { display: flex; flex-direction: column; gap: var(--s-2); }
.history__empty-title { font-weight: var(--fw-semi); font-size: var(--t-lg); color: var(--c-fg); margin-bottom: var(--s-2); }
.empty-state .btn { margin-top: var(--s-3); }

.history-table-wrap {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-base);
}

/* The history screen is capped at 960px by the app shell and this table has
   twelve columns, so the horizontal budget is real: 8px gutters, no letter
   spacing on the numeric headers, and every text column capped in ch. The
   wrapper still scrolls if a translation or a long seller name pushes it. */
.history-table thead th {
  position: sticky; top: 0; z-index: 1;
  padding: var(--s-2);
  text-align: left;
  white-space: nowrap;
  font-size: var(--t-xs); font-weight: var(--fw-semi);
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--c-fg-muted);
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border);
}
.history-table th.is-num, .history-table td.is-num { text-align: right; }
.history-table th.is-num { letter-spacing: 0; }
.history-table td.is-num { white-space: nowrap; width: 1%; }

.history-table td {
  padding: var(--s-3) var(--s-2);
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}
.history-table tbody tr:last-child td { border-bottom: 0; }

.history-row { cursor: pointer; transition: background var(--m-fast) var(--m-ease); }
.history-row:hover { background: var(--c-primary-soft); }
.history-row:focus-visible { outline: 2px solid var(--c-primary); outline-offset: -2px; }
/* An active run gets a left edge as well as the pulsing dot in its chip, so
   the state is legible without relying on the animation or on colour. */
.history-row--active td:first-child { box-shadow: inset 3px 0 0 var(--c-ok); }

.history-row__day { display: block; font-weight: var(--fw-medium); white-space: nowrap; }
.history-row__time { display: block; font-size: var(--t-xs); color: var(--c-fg-muted); }

.history-row__label {
  font-weight: var(--fw-semi); color: var(--c-fg); text-decoration: none;
  display: inline-block; max-width: 20ch;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
}
.history-row:hover .history-row__label { color: var(--c-primary); text-decoration: underline; }
.history-row__city { display: block; font-size: var(--t-xs); }
.history-row__kw {
  display: inline-block; max-width: 22ch;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
  font-family: var(--f-mono); font-size: var(--t-xs);
}
.history-row__seller {
  display: inline-block; max-width: 18ch;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
}
.history-row__sellerid { display: block; font-size: var(--t-xs); color: var(--c-fg-faint); }
.history-row__dry { display: block; font-size: var(--t-xs); color: var(--c-fg-faint); white-space: nowrap; }
.history-table .tnum { font-variant-numeric: tabular-nums; }

/* ---- stacked records, below the point where 12 columns stop working ------- */
@media (max-width: 900px) {
  .history-table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .history-table, .history-table tbody { display: block; width: 100%; }
  .history-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

  /* `tr.history-row` on purpose: a bare `.history-row` loses to
     `.history-table tr` and the card silently falls back to one column. */
  .history-table tr.history-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s-2) var(--s-3);
    padding: var(--s-3);
    margin-bottom: var(--s-3);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-1);
  }
  .history-table tr.history-row--active { border-color: var(--c-ok); }
  .history-row--active td:first-child { box-shadow: none; }

  .history-table td {
    display: block;
    padding: 0;
    border: 0;
    min-width: 0; width: auto;
    text-align: left;
  }
  .history-table td.is-num { text-align: left; width: auto; }

  /* The label of every cell comes back as its own line, because without the
     header row a bare "3" is unreadable. */
  .history-table td::before {
    content: attr(data-label);
    display: block;
    font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .06em;
    color: var(--c-fg-faint);
  }

  /* Run + status lead the card; the funnel numbers sit under them in a strip. */
  .history-table td[data-label="Run"] { grid-column: 1 / -1; order: 1; }
  .history-table td[data-label="Run"]::before { display: none; }
  .history-table td[data-label="Run"] .history-row__label { max-width: 100%; font-size: var(--t-md); }
  .history-table td[data-label="Status"] { order: 2; }
  .history-table td[data-label="Started"] { order: 3; }
  .history-table td[data-label="Keywords"] { order: 4; grid-column: 1 / -1; }
  .history-table td[data-label="Keywords"] .history-row__kw { max-width: 100%; }
  .history-table td[data-label="Country"] { order: 5; }
  .history-table td[data-label="Seller"] { order: 6; }
  .history-table td[data-label="Seller"] .history-row__seller { max-width: 100%; }

  .history-table td[data-label="Leads"],
  .history-table td[data-label="Dropped"],
  .history-table td[data-label="Products"],
  .history-table td[data-label="Listings"],
  .history-table td[data-label="Emails"],
  .history-table td[data-label="Duration"] {
    order: 7;
    grid-column: span 1;
  }
}

@media (max-width: 430px) {
  /* Three funnel numbers per line still fit at 390px, so the six of them land
     as two tidy rows instead of six lines of label-then-number. */
  .history-table tr.history-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .history-table td[data-label="Started"] { grid-column: span 1; }
  .history-table td[data-label="Status"] { grid-column: span 2; }
  .history-table td[data-label="Country"] { grid-column: span 1; }
  .history-table td[data-label="Seller"] { grid-column: span 2; }
}
