/* TAMX 3-Step Status Timeline */
.tx-timeline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 12px 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  margin: 12px 0;
  position: relative;
  overflow: hidden;
  width: 100%;
  box-sizing: border-box;
}

.tx-timeline__step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  position: relative;
  min-width: 80px;
}

.tx-timeline__circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.12);
  color: #64748B;
  transition: all 0.3s cubic-bezier(.4, 0, .2, 1);
  position: relative;
  flex-shrink: 0;
}

.tx-timeline__step.is-active .tx-timeline__circle {
  background: linear-gradient(135deg, #D4AF37, #B8860B);
  border-color: rgba(212, 175, 55, 0.6);
  color: #0B1020;
  box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.15),
              0 4px 14px rgba(212, 175, 55, 0.4);
  animation: tx-timeline-pulse 2s ease-in-out infinite;
}

@keyframes tx-timeline-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.15), 0 4px 14px rgba(212, 175, 55, 0.4); }
  50%      { box-shadow: 0 0 0 8px rgba(212, 175, 55, 0.08), 0 4px 14px rgba(212, 175, 55, 0.6); }
}

.tx-timeline__step.is-done .tx-timeline__circle {
  background: linear-gradient(135deg, #22C55E, #16A34A);
  border-color: rgba(34, 197, 94, 0.5);
  color: #fff;
}

.tx-timeline__step.is-failed .tx-timeline__circle {
  background: linear-gradient(135deg, #EF4444, #DC2626);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fff;
  animation: tx-timeline-shake 0.5s ease;
}
@keyframes tx-timeline-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.tx-timeline__step.is-blocked .tx-timeline__circle {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  color: #475569;
  opacity: 0.5;
}

.tx-timeline__label {
  font-size: 0.78rem;
  color: #94A3B8;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
  max-width: 100px;
}

.tx-timeline__step.is-active .tx-timeline__label {
  color: #FCD34D;
}
.tx-timeline__step.is-done .tx-timeline__label {
  color: #86EFAC;
}
.tx-timeline__step.is-failed .tx-timeline__label {
  color: #FCA5A5;
}
.tx-timeline__step.is-blocked .tx-timeline__label {
  color: #64748B;
}

.tx-timeline__num {
  font-size: 0.68rem;
  color: #64748B;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.05);
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.tx-timeline__step.is-active .tx-timeline__num {
  background: rgba(212, 175, 55, 0.15);
  color: #FCD34D;
  border-color: rgba(212, 175, 55, 0.3);
}
.tx-timeline__step.is-done .tx-timeline__num {
  background: rgba(34, 197, 94, 0.15);
  color: #86EFAC;
  border-color: rgba(34, 197, 94, 0.3);
}

.tx-timeline__bar {
  flex: 1 1 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
  min-width: 12px;
}

.tx-timeline__bar.is-done {
  background: linear-gradient(90deg, #22C55E, #16A34A);
}
.tx-timeline__bar.is-blocked {
  background: rgba(239, 68, 68, 0.15);
}

.tx-timeline__footnote {
  font-size: 0.82rem;
  color: #94A3B8;
  text-align: center;
  padding: 8px 12px;
  margin-top: -4px;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 0 0 14px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tx-timeline__footnote--success {
  background: rgba(34, 197, 94, 0.08);
  color: #86EFAC;
  border-top-color: rgba(34, 197, 94, 0.2);
}

.tx-timeline__footnote--danger {
  background: rgba(239, 68, 68, 0.08);
  color: #FCA5A5;
  border-top-color: rgba(239, 68, 68, 0.2);
}

/* Mobile responsive */
@media (max-width: 520px) {
  .tx-timeline { padding: 14px 8px 6px; gap: 4px; }
  .tx-timeline__step { min-width: 70px; }
  .tx-timeline__circle { width: 38px; height: 38px; font-size: 15px; }
  .tx-timeline__label { font-size: 0.7rem; max-width: 80px; }
  .tx-timeline__num { font-size: 0.62rem; padding: 1px 5px; }
  .tx-timeline__bar { min-width: 8px; margin-bottom: 26px; }
}

/* ======================================================================
   COMPACT MODE — used inside transaction list cards.
   Goal: never overflow even on 320px screens. Uses CSS grid with equal
   columns so step circles are perfectly distributed and bars fill the gap.
   Labels become inline-truncated; nothing escapes the card.
   ====================================================================== */
.tx-timeline-target {
  width: 100%;
  box-sizing: border-box;
  overflow: hidden; /* hard guarantee against any leakage */
}
.tx-timeline-target .tx-timeline,
.tx-timeline--compact-wrap .tx-timeline {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 6px;
  row-gap: 4px;
  padding: 10px 10px 8px;
  margin: 6px 0 0;
  width: 100%;
  max-width: 100%;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  overflow: hidden;
}
.tx-timeline-target .tx-timeline__step,
.tx-timeline--compact-wrap .tx-timeline__step {
  min-width: 0;
  width: auto;
  gap: 4px;
  grid-row: 1 / 3;
  flex-direction: column;
}
.tx-timeline-target .tx-timeline__step:nth-of-type(1) { grid-column: 1; }
.tx-timeline-target .tx-timeline__step:nth-of-type(2) { grid-column: 3; }
.tx-timeline-target .tx-timeline__step:nth-of-type(3) { grid-column: 5; }
.tx-timeline--compact-wrap .tx-timeline__step:nth-of-type(1) { grid-column: 1; }
.tx-timeline--compact-wrap .tx-timeline__step:nth-of-type(2) { grid-column: 3; }
.tx-timeline--compact-wrap .tx-timeline__step:nth-of-type(3) { grid-column: 5; }

.tx-timeline-target .tx-timeline__bar,
.tx-timeline--compact-wrap .tx-timeline__bar {
  width: 100%;
  min-width: 8px;
  margin: 0;
  grid-row: 1;
  align-self: center;
  height: 3px;
}
.tx-timeline-target .tx-timeline__bar:nth-of-type(2) { grid-column: 2; }
.tx-timeline-target .tx-timeline__bar:nth-of-type(4) { grid-column: 4; }
.tx-timeline--compact-wrap .tx-timeline__bar:nth-of-type(2) { grid-column: 2; }
.tx-timeline--compact-wrap .tx-timeline__bar:nth-of-type(4) { grid-column: 4; }

.tx-timeline-target .tx-timeline__circle,
.tx-timeline--compact-wrap .tx-timeline__circle {
  width: 30px;
  height: 30px;
  font-size: 12px;
  border-width: 1.5px;
}

.tx-timeline-target .tx-timeline__label,
.tx-timeline--compact-wrap .tx-timeline__label {
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.1;
  max-width: 100%;
  width: 100%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-timeline-target .tx-timeline__num,
.tx-timeline--compact-wrap .tx-timeline__num {
  display: none; /* hide numeric badge in compact list rows */
}

.tx-timeline-target .tx-timeline__footnote,
.tx-timeline--compact-wrap .tx-timeline__footnote,
.tx-timeline-target + .tx-timeline__footnote,
.tx-timeline--compact-wrap + .tx-timeline__footnote {
  display: none; /* footnote is redundant in list view — badge already shows status */
}

/* Adjust active animation in compact mode so the pulse ring doesn't overflow */
.tx-timeline-target .tx-timeline__step.is-active .tx-timeline__circle,
.tx-timeline--compact-wrap .tx-timeline__step.is-active .tx-timeline__circle {
  box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.18),
              0 2px 8px rgba(212, 175, 55, 0.3);
  animation: tx-timeline-pulse-sm 2s ease-in-out infinite;
}
@keyframes tx-timeline-pulse-sm {
  0%, 100% { box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.18), 0 2px 8px rgba(212, 175, 55, 0.3); }
  50%      { box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.10), 0 2px 8px rgba(212, 175, 55, 0.45); }
}

/* On very small screens, drop labels — icons + bars communicate the state */
@media (max-width: 380px) {
  .tx-timeline-target .tx-timeline__label,
  .tx-timeline--compact-wrap .tx-timeline__label {
    display: none;
  }
  .tx-timeline-target .tx-timeline,
  .tx-timeline--compact-wrap .tx-timeline {
    padding: 8px;
  }
  .tx-timeline-target .tx-timeline__circle,
  .tx-timeline--compact-wrap .tx-timeline__circle {
    width: 26px;
    height: 26px;
    font-size: 11px;
  }
}

/* Standalone compact modifier (legacy) — keep working */
.tx-timeline--compact { padding: 10px 8px 4px; margin: 8px 0; }
.tx-timeline--compact .tx-timeline__circle { width: 32px; height: 32px; font-size: 13px; }
.tx-timeline--compact .tx-timeline__label { font-size: 0.7rem; }
.tx-timeline--compact .tx-timeline__num { display: none; }
.tx-timeline--compact .tx-timeline__bar { margin-bottom: 22px; }
.tx-timeline--compact + .tx-timeline__footnote { display: none; }

/* ======================================================================
   ITEM-CARD layout fix for transactions list.
   The .item-card normally is a flex row, but transactions.html injects a
   timeline as a 4th child with grid-column:1/-1 — which only works if the
   container is a grid. Promote to grid when a tx-timeline target exists.
   ====================================================================== */
.item-card:has([data-tx-timeline-target]) {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 6px;
  align-items: flex-start;
}
.item-card:has([data-tx-timeline-target]) > .item-card__icon {
  grid-column: 1;
  grid-row: 1;
}
.item-card:has([data-tx-timeline-target]) > .item-card__body {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  overflow: hidden;
}
.item-card:has([data-tx-timeline-target]) > div:nth-of-type(3) {
  /* amount + badge block */
  grid-column: 3;
  grid-row: 1;
  text-align: left;
  min-width: 0;
}
.item-card:has([data-tx-timeline-target]) > [data-tx-timeline-target] {
  grid-column: 1 / -1;
  grid-row: 2;
  width: 100%;
  margin-top: 4px;
}

/* Amount + badge stack — prevent text bleed and ensure currency line is below */
.item-card__amount {
  display: block;
  text-align: left;
  word-break: keep-all;
}
.item-card__body .item-card__title {
  flex-wrap: wrap;
  word-break: break-word;
}

/* On narrow mobiles, slightly shrink amount font so it doesn't overlap */
@media (max-width: 380px) {
  .item-card__amount { font-size: 13px; }
  .item-card:has([data-tx-timeline-target]) { column-gap: 8px; padding: 10px; }
  .item-card__icon { width: 34px; height: 34px; font-size: 14px; }
}

/* Safari fallback for browsers without :has() — keep existing flex layout
   but make the timeline wrapper span full width via a flex hack. */
@supports not (selector(:has(*))) {
  .item-card { flex-wrap: wrap; }
  .item-card > [data-tx-timeline-target] {
    flex: 1 0 100%;
    width: 100%;
    margin-top: 8px;
  }
}
