/* Sales page. Tokens and shared components (totals, cards, charts, tables, tooltip) come from style.css. */

#main[aria-busy], #totals[aria-busy] { opacity: 0.6; transition: opacity var(--mid) ease; }

/* The period chips, labelled */
.range-bar { gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-2); }
.range-bar .eyebrow { margin: 0; color: var(--muted); }

/* Header totals: a note under each figure (promote to style.css) */
.totals .sub { margin: 0.1rem 0 0; font-size: var(--step--2); color: var(--muted); }
.totals > div:first-child { border-top-color: var(--chart-sell); }

/* Charts and shares: two cards a row from tablet up, one on phones */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(28rem, 100%), 1fr)); gap: var(--sp-4); }
.board > .card { margin-top: 0; min-width: 0; }
.board > .card.wide { grid-column: 1 / -1; }
.board > .card[hidden] { display: none; }
.skeleton.board { gap: var(--sp-4); }
.skeleton.board span { height: 18rem; }

/* Share of the platinum: a single gold bar per entry, its value written beside it */
.hbars { list-style: none; margin: var(--sp-1) 0 0; padding: 0; display: grid; gap: 0.55rem; }
.hbars li { display: grid; grid-template-columns: minmax(0, 11rem) minmax(3rem, 1fr) auto; align-items: center; gap: var(--sp-3); font-size: var(--step--1); }
.hbar-label { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.hbar-label > :last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-label img, .hbar-label .no-thumb { width: 1.5rem; height: 1.5rem; flex: none; object-fit: contain; }
.hbar-label a { color: inherit; text-decoration: none; transition: color var(--fast) ease; }
.hbar-label a:hover { color: var(--gold-hi); }
.hbar-track { height: 0.6rem; overflow: hidden; background: var(--line-soft); }
.hbar {
  display: block;
  height: 100%;
  min-width: 2px;
  background: linear-gradient(90deg, var(--chart-sell), var(--gold));
  transform-origin: left;
}
.sales-enter .hbar {
  animation: grow-x 560ms var(--ease) backwards;
  animation-delay: calc(var(--i) * 40ms);
}
.hbar-value { white-space: nowrap; text-align: right; }
.hbar-value strong { font: 600 var(--step-0) var(--num); font-variant-numeric: tabular-nums; color: var(--ivory); }
@keyframes grow-x { from { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .hbar { animation: none; } }

.filter { margin-bottom: 0; }
.none { margin: var(--sp-3) 0 var(--sp-1); font-size: var(--step--1); }
/* Item names link to the Market page, coloured like text */
a.cell-name { color: inherit; text-decoration: none; }
a.cell-name span { transition: color var(--fast) ease; }
a.cell-name:hover span, tbody tr:hover a.cell-name span { color: var(--gold-hi); }
/* The items table scrolls sideways on phones, keeping its sort headers */
#items-table th { white-space: nowrap; }
#items-table td:first-child { min-width: 12rem; }
#history td.act { width: 1%; white-space: nowrap; }
/* Row deletes stay quiet until hovered or waiting for the second click */
#history .ghost.danger:not(.confirm, :hover) { color: var(--muted); }

/* Adding a sale by hand: a toggle, then a boxed form */
details.add { margin: var(--sp-1) 0 var(--sp-3); font-size: var(--step--1); }
details.add summary {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: rgba(13, 18, 36, 0.45);
  color: var(--void);
  cursor: pointer;
  list-style: none;
  transition: border-color var(--fast) ease, background var(--fast) ease;
}
details.add summary::-webkit-details-marker { display: none; }
details.add summary::before { content: "+"; font-weight: 600; transition: transform var(--mid) var(--ease); }
details.add[open] summary::before { transform: rotate(45deg); }
details.add summary:hover { border-color: var(--void); background: var(--void-soft); }
details.add[open] summary { border-color: var(--void); }
form.add {
  display: grid;
  grid-template-columns: minmax(12rem, 2fr) minmax(5rem, 0.6fr) minmax(7rem, 0.8fr) minmax(8rem, 1fr) minmax(11rem, 1.2fr) auto;
  align-items: end;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line-soft);
  border-left: 2px solid var(--void);
  border-radius: var(--r-ctl);
  background: rgba(13, 18, 36, 0.45);
}
form.add label { display: grid; gap: var(--sp-1); min-width: 0; color: var(--muted); }
form.add input { width: 100%; min-width: 0; min-height: 2.3rem; }
form.add input.num { text-align: right; }
.form-error { grid-column: 1 / -1; margin: 0; color: var(--danger); }
.form-error:empty { display: none; }

@media (max-width: 64rem) {
  form.add { grid-template-columns: repeat(auto-fit, minmax(min(10rem, 100%), 1fr)); }
  form.add label:first-child { grid-column: 1 / -1; }
}

/* Only phones need the sort beside the search; wider screens sort by the table headers */
.items-sort { display: none; }

@media (max-width: 40rem) {
  .items-sort { display: flex; flex: 1 1 100%; align-items: center; justify-content: space-between; gap: var(--sp-2); font-size: var(--step--1); color: var(--muted); }
  .items-sort select { flex: 0 1 13rem; min-width: 0; }
  .hbars li { grid-template-columns: minmax(0, 1fr) auto; row-gap: var(--sp-1); }
  .hbar-track { grid-column: 1 / -1; grid-row: 2; }
  form.add { grid-template-columns: 1fr 1fr; padding: var(--sp-3); }
  form.add button[type="submit"] { grid-column: 1 / -1; }
  form.add label:has([name="partner"]), form.add label:has([name="sold_at"]) { grid-column: 1 / -1; }
  /* Stacked item and sale rows: the fields two by two under the item, each label above its value */
  :is(#items-table, #history) table.stack tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-2) var(--sp-4); }
  :is(#items-table, #history) table.stack td:first-child { grid-column: 1 / -1; }
  :is(#items-table, #history) table.stack td[data-label] { flex-direction: column; align-items: flex-start; gap: 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  #history td.act { grid-column: 1 / -1; width: auto; justify-content: flex-end; }
}
