/* 卡片 · 记录 · 动态 · 交易记录 (cards.js, records.js, activity.js, transactions.js). Built from design A's components
   (masthead, statement strip, filters, table / rlist, gallery + tile, segmented, badges); this file only
   adds the compositions those pages need. Tokens only, so the dark theme follows on its own. */

/* ---------------------------------------------------------------------------------------------
   Shared
   --------------------------------------------------------------------------------------------- */
.segmented__count:empty { display: none; }
/* the counts arrive after the first answer: keep their room so the filter row does not jump or re-wrap */
.records-filters .segmented__count:empty,
.cards-head .segmented__count:empty { display: inline-block; min-width: 1.25em; }

/* The Link account of a record (§13, §18): a quiet chip with the account email and its state dot;
   an account that is not connected gets a dashed outline */
.acct-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
  height: 20px;
  padding: 0 8px 0 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-muted);
  color: var(--text-3);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}
.acct-chip .icon { width: 12px; height: 12px; }
.acct-chip .acct-dot { width: 6px; height: 6px; box-shadow: none; }
.acct-chip .acct-dot[data-state="disconnected"] { box-shadow: inset 0 0 0 1.25px var(--text-3); }
.acct-chip--off { border-style: dashed; border-color: var(--border-strong); background: transparent; }
.acct-chip__text { min-width: 0; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }

/* Account filter next to a segmented control: same height as the control */
.masthead__actions .account-filter .select {
  min-height: 42px;
  padding-top: 6px;
  padding-bottom: 6px;
  border-color: var(--border);
  border-radius: 12px;
  font-size: var(--text-sm);
}
@media (max-width: 1023px) { .masthead__actions .account-filter .select { font-size: 16px; } }

/* ---------------------------------------------------------------------------------------------
   记录 — masthead, filter bar, table, list
   --------------------------------------------------------------------------------------------- */
.records-head .masthead__actions,
.cards-head .masthead__actions { align-items: center; }

.records-filters .filters__toggle { flex: none; }
.filters__count:not(:empty) {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}
@media (min-width: 768px) {
  .records-filters .filters__toggle { display: none; }
  .records-filters .filters__more { display: contents; }
  .records-filters .filters__search { order: 1; }
}
@media (max-width: 599px) {
  /* phones: a compact statement so the list starts on the first screen */
  .records-statement .statement__cell { gap: var(--space-1); padding-top: var(--space-3); padding-bottom: var(--space-3); }
  .records-statement .statement__value { font-size: 20px; }
  .records-filters .segmented__btn { padding: 0 10px; }
}
@media (max-width: 767px) {
  .records-filters .segmented { flex: 1 1 100%; }
  .records-filters .filters__search { flex: 1 1 0; }
  .records-filters .filters__more { display: none; flex: 1 1 100%; flex-wrap: wrap; gap: var(--space-3); min-width: 0; }
  .records-filters .filters__more.is-open { display: flex; }
  .records-filters .filters__more > * { flex: 1 1 calc(50% - var(--space-3)); min-width: 0; }
  .records-filters .filters__more > .date-range { flex-basis: 100%; }
}

/* Status multi-select: a button dressed as .select that opens a checkbox popover */
.status-select { text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-select.is-set { border-color: var(--text-3); color: var(--text); font-weight: var(--weight-medium); }
.status-popover { min-width: 220px; }
.status-pop__list { display: flex; flex-direction: column; gap: 1px; margin: 0; padding: 2px 0 4px; border: 0; }
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--text-sm);
  cursor: pointer;
}
.check-row:hover { background: var(--surface-muted); }
.check-row input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.check-row .dot { margin: 0 1px; }
@media (pointer: coarse) { .check-row { min-height: var(--tap); } }
.status-pop__foot {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: 2px;
  padding: 8px 4px 2px;
  border-top: 1px solid var(--border);
}

/* Date range with native date inputs (browser zone) and a clear button */
.records-filters .date-range input[type="date"] { width: 8.6em; min-width: 0; padding: 0 4px; }
@media (max-width: 767px) {
  .records-filters .date-range { min-height: var(--tap); }
  .records-filters .date-range input[type="date"] { flex: 1 1 0; width: 0; min-width: 0; font-size: 16px; }
}
.date-range__clear {
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  margin-left: 2px;
  border-radius: 6px;
  color: var(--text-3);
}
.date-range__clear:hover { background: var(--surface-muted); color: var(--text); }

/* Results panel */
.records-body { transition: opacity var(--dur-base) var(--ease-standard); }
.records-body.is-loading { opacity: 0.55; }
.records-body > .panel { border: 0; border-radius: 0; background: transparent; }

.th-sort {
  padding: 0;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}
.th-sort:hover { color: var(--text); }
.th-sort:focus-visible { outline-offset: 3px; border-radius: 3px; }

.records-table tbody tr[data-href] { cursor: pointer; }
.records-table td.records-table__merchant { width: 100%; max-width: 0; }
.records-table tr.is-archived td { color: var(--text-3); }
.merchant__line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.merchant__line .merchant__name { min-width: 0; }
.merchant__line .test-badge { flex: none; }
.merchant__line .acct-chip { flex: 0 1 auto; }

.rlist__item > .acct-chip { grid-column: 2 / -1; justify-self: start; margin-top: 4px; }

/* ---------------------------------------------------------------------------------------------
   卡片 — gallery states, tiles, 加载更多
   --------------------------------------------------------------------------------------------- */
@media (max-width: 599px) {
  /* phones: the filter first and full width, the account filter under it */
  .cards-head .masthead__actions { width: 100%; }
  .cards-head .segmented { order: -1; flex: 1 1 100%; }
  .cards-head .segmented__btn { flex: 1 1 auto; padding: 0 8px; }
  .cards-head .account-filter { flex: 1 1 100%; }
}
.cards-gallery--state { display: block; }
.cards-empty .empty { padding-top: var(--space-9); padding-bottom: var(--space-9); }
.tile { border-radius: var(--radius-card); }
.tile:focus-visible { outline-offset: 6px; }
.tile__name { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.tile__row--acct { justify-content: flex-start; }
.tile .vcard__holder .countdown { letter-spacing: inherit; }
.gallery-more {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-3) var(--space-4);
  margin-top: var(--space-9);
  color: var(--text-3);
  font-size: var(--text-sm);
}

/* ---------------------------------------------------------------------------------------------
   动态 — audit list grouped by day
   --------------------------------------------------------------------------------------------- */
.audit-day + .audit-day { margin-top: var(--space-7); }
.audit-day__title {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-heading);
  letter-spacing: var(--tracking-label);
}
.audit-day__count { color: var(--text-3); font-size: var(--text-xs); font-weight: var(--weight-regular); }
.audit { list-style: none; margin: 0; padding: 0; }
.audit__item {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
}
.audit__item + .audit__item { border-top: 1px solid var(--border); }
.audit__icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-2);
}
.audit__icon .icon { width: 16px; height: 16px; }
.audit__item[data-tone="danger"] .audit__icon { border-color: transparent; background: var(--danger-soft); color: var(--danger-text); }
.audit__item[data-tone="success"] .audit__icon { border-color: transparent; background: var(--accent-soft); color: var(--accent-text); }
.audit__item[data-tone="warning"] .audit__icon { border-color: transparent; background: var(--warning-soft); color: var(--warning-text); }
.audit__body { min-width: 0; padding-top: 5px; }
.audit__title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px var(--space-2); font-size: var(--text-sm); line-height: 1.6; }
.audit__label { color: var(--text); font-weight: var(--weight-heading); }
.audit__summary { min-width: 0; color: var(--text-2); overflow-wrap: anywhere; }
.audit__summary .test-badge { margin-left: 2px; }
.audit__meta { margin-top: 2px; font-size: var(--text-xs); }
.audit__meta .mono { font-size: 0.95em; letter-spacing: 0; }
.activity-foot { margin-top: var(--space-6); }
@media (max-width: 599px) {
  .audit__item { gap: var(--space-3); padding: var(--space-4); }
}

/* ---------------------------------------------------------------------------------------------
   交易记录 — the Link account's transactions as a ledger (SPEC §16), and the extra approval for it
   --------------------------------------------------------------------------------------------- */
.txn-head .masthead__actions { align-items: center; }
.txn-refresh[hidden] { display: none; }
/* §18 which Link account's transactions (more than one account seen) */
.txn-account .select { max-width: 34ch; }
@media (max-width: 599px) {
  .txn-head .masthead__actions { width: 100%; }
  .txn-head .txn-account { flex: 1 1 100%; }
  .txn-account .select { max-width: none; }
}

.txn-filters .date-range input[type="date"] { width: 8.6em; min-width: 0; padding: 0 4px; }
@media (max-width: 767px) {
  .txn-filters .segmented { flex: 1 1 100%; }
  .txn-filters .segmented__btn { flex: 1 1 auto; padding: 0 10px; }
  .txn-filters .date-range { flex: 1 1 100%; min-height: var(--tap); }
  .txn-filters .date-range input[type="date"] { flex: 1 1 0; width: 0; min-width: 0; font-size: 16px; }
  .txn-filters .filters__search { flex: 1 1 100%; }
}

.txn-summary { margin: var(--space-5) 0 var(--space-3); }
.txn-summary[hidden] { display: none; }
.txn-sum { color: var(--text); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; }
.txn-sum--in { color: var(--success-text); }

.txn-body { transition: opacity var(--dur-base) var(--ease-standard); }
.txn-body.is-loading { opacity: 0.55; }

/* desktop ledger: the description column takes the room and wraps rather than truncating */
.txn-table td.txn-table__desc { width: 100%; max-width: 0; }
.txn-table td { vertical-align: top; }
.txn-table td.is-time, .txn-table td.is-num { padding-top: 15px; }
.txn-desc { display: flex; align-items: flex-start; gap: 6px; min-width: 0; }
.txn-desc__text { min-width: 0; padding-top: 1px; color: var(--text); font-weight: var(--weight-medium); line-height: 1.5; overflow-wrap: anywhere; }
.txn-copy {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  color: var(--text-3);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-standard), background-color var(--dur-fast) var(--ease-standard);
}
.txn-copy .icon { width: 14px; height: 14px; }
.txn-copy:hover { background: var(--surface-muted); color: var(--text); }
.txn-table tr:hover .txn-copy, .txn-copy:focus-visible, .txn-copy[data-copied] { opacity: 1; }
.txn-copy[data-copied] { color: var(--success-text); }
@media (hover: none) { .txn-copy { opacity: 1; } }

.txn-amount { color: var(--text); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; white-space: nowrap; }
.txn-amount--in { color: var(--success-text); }
.txn-amount__code { color: var(--text-3); font-size: var(--text-xs); font-weight: var(--weight-regular); }
.txn-cat { white-space: nowrap; }
.txn-origin { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.txn-origin .icon { color: var(--text-3); }

/* phones: one row per transaction */
.txn-list { display: flex; flex-direction: column; }
.txn-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 4px var(--space-3);
  padding: 14px var(--space-4);
  border-top: 1px solid var(--border);
}
.txn-item:first-child { border-top: 0; }
.txn-item__amount { justify-self: end; padding-top: 2px; }
.txn-item__sub { align-self: center; min-width: 0; overflow: hidden; font-size: var(--text-xs); color: var(--text-3); text-overflow: ellipsis; white-space: nowrap; }
.txn-item__status { justify-self: end; }
.txn-item .txn-copy { width: 30px; height: 30px; margin: -3px 0 -3px -2px; }

/* why Link refuses, in its own words */
.txn-why { display: block; }
.txn-why + .txn-why { margin-top: var(--space-1); }
.txn-reason { quotes: "「" "」"; color: var(--text); font-weight: var(--weight-medium); overflow-wrap: anywhere; }

/* the authorization intro (connect.js in upgrade mode): what the permission reads */
.txn-reads { display: flex; flex-direction: column; gap: var(--space-2); max-width: 40em; margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); line-height: 1.65; color: var(--text-2); }
.txn-reads li { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: var(--space-2); align-items: start; }
.txn-reads .icon { width: 16px; height: 16px; margin-top: 4px; color: var(--accent); }
.lc-lapse { flex: 1 1 22em; text-align: right; }
@media (max-width: 599px) { .lc-lapse { text-align: left; } }

/* ---------------------------------------------------------------------------------------------
   §17 a card's use (records, cards, dashboard, transactions)
   --------------------------------------------------------------------------------------------- */
.rec-status { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.rlist__status { display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 4px 6px; }
/* 已使用 (自动识别 / 手动标记) and 「不再同步」: quiet chips beside the status badge */
.use-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 8px 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-muted);
  color: var(--text-3);
  font-size: var(--text-xs);
  line-height: 1;
  white-space: nowrap;
}
.use-chip[data-by="auto"] { border-color: var(--success-border); background: var(--success-soft); color: var(--success-text); }
.use-chip .icon { width: 12px; height: 12px; }
.use-chip--lost { border-style: dashed; }
/* 实扣 under the authorized amount */
.rec-paid { display: block; margin-top: 2px; color: var(--success-text); font-size: var(--text-xs); font-weight: var(--weight-regular); }

/* the console card a transaction belongs to */
.txn-card {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  margin-top: 4px;
  padding: 2px 8px 2px 6px;
  border: 1px solid var(--info-border);
  border-radius: var(--radius-pill);
  background: var(--info-soft);
  color: var(--info-text);
  font-size: var(--text-xs);
  line-height: 1.4;
  text-decoration: none;
}
.txn-card:hover { color: var(--info-text); text-decoration: underline; }
.txn-card .icon { flex: none; width: 12px; height: 12px; }
.txn-card__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-item__card { grid-column: 1 / -1; min-width: 0; }
.txn-item__card .txn-card { margin-top: 0; }
.txn-card--ambiguous { border-color: var(--warning-border); background: var(--warning-soft); color: var(--warning-text); }
.txn-card--ambiguous:hover { color: var(--warning-text); }
