/* =========================================================
   GLOBAL TRANSACTION ALERT
   Renders in the OUTER shell document (index.html), never inside
   an iframe — this is what lets it sit above the sidebar. RIZQ
   Matrix / TradeFi run inside iframes, so their own DOM can never
   out-z-index elements in the parent page; the iframe's own box
   is what gets stacked, not its internal z-index values. Any
   in-app tx alert is forwarded here via window.parent.showTxAlert().

   Card layout uses CSS Grid (not flex) — 4 fixed columns:
   [icon] [title + hash/status] [amount] [close]
   ========================================================= */

#global-txa-container {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 0.75rem);
  right: 0.75rem;
  width: 35%;
  min-width: 150px;
  max-width: 420px;
  z-index: 999999; /* above .sidebar (100) and .sidebar.open (200) */
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.txa {
  display: grid;
  grid-template-columns: 24px 1fr auto auto;
  align-items: center;
  column-gap: 8px;
  width: 100%;
  box-sizing: border-box;
  padding: 9px 8px 9px 10px;
  border-radius: var(--radius-lg, 14px);
  background: linear-gradient(180deg, rgba(30,32,40,0.94), rgba(18,19,24,0.94));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--bb-border);
  border-left: 3px solid var(--text-sky);
  box-shadow: 0 10px 30px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,255,255,0.02) inset;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-10px) scale(0.98);
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s ease, border-color 0.3s ease;
}
.txa.txa-show { opacity: 1; transform: translateY(0) scale(1); }
.txa.txa-success { border-left-color: #a5a512; }
.txa.txa-error   { border-left-color: #ef4444; }
.txa.txa-warning { border-left-color: #f59e0b; }
.txa-warning .txa-icon { background: rgba(245,158,11,0.14); color: #f59e0b; }

/* Plain-message variant (showToast) — no hash/amount row, so let the
   title wrap across lines instead of ellipsis-truncating a sentence. */
.txa-msg .txa-title {
  white-space: normal;
  word-break: break-word;
  font-weight: 600;
  font-size: 12px;
  line-height: 1.4;
}

/* Column 1 — status icon */
.txa-icon {
  grid-column: 1;
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(var(--accent-sky-rgb), 0.12);
  color: var(--text-sky);
  transition: background 0.3s ease, color 0.3s ease;
}
.txa-success .txa-icon { background: rgba(138,138,10,0.22); color: #a5a512; }
.txa-error   .txa-icon { background: rgba(239,68,68,0.14); color: #ef4444; }
.txa-ico-svg { width: 12px; height: 12px; }
.txa-spinner {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(var(--accent-sky-rgb), 0.25);
  border-top-color: var(--text-sky);
  animation: txa-spin 0.7s linear infinite;
}
@keyframes txa-spin { to { transform: rotate(360deg); } }

/* Column 2 — title + hash/status */
.txa-body {
  grid-column: 2;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.txa-title {
  font-family: "Montserrat", sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-normal-tier, #f0f0f5);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.txa-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 9.5px;
  color: var(--text-muted-tier, rgba(255,255,255,.6));
  white-space: nowrap; overflow: hidden;
}
.txa-hash {
  font-family: "SF Mono","Fira Code",ui-monospace,monospace;
  color: var(--text-sky);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
}
.txa-hash:hover { text-decoration: underline; }
.txa-dot { opacity: 0.5; flex-shrink: 0; }
.txa-status { overflow: hidden; text-overflow: ellipsis; }
.txa-success .txa-status { color: #a5a512; }
.txa-error   .txa-status { color: #ef4444; }

/* Column 3 — amount */
.txa-amount {
  grid-column: 3;
  display: none; /* hidden at narrow (35%) width */
  font-family: "SF Mono","Fira Code",ui-monospace,monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-normal-tier, #f0f0f5);
  white-space: nowrap;
}
@media (min-width: 620px) { .txa-amount { display: inline-block; } }

/* Column 4 — close button */
.txa-close {
  grid-column: 4;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted-tier, rgba(255,255,255,.5));
  font-size: 14px; line-height: 1;
  border-radius: 50%;
  transition: background 0.15s ease, color 0.15s ease;
}
.txa-close:hover { background: rgba(255,255,255,0.08); color: var(--text-normal-tier, #fff); }

body.theme-light .txa {
  background: linear-gradient(180deg, #ffffff, #f7f7fc);
  border-color: var(--bb-border);
}
body.theme-light .txa-title  { color: #15151c; }
body.theme-light .txa-amount { color: #15151c; }

/* Inline variant — used to embed a tx-alert card directly in a flow of
   content (e.g. the AI agent chat log) instead of the floating overlay.
   Same look, no close button, so 3 columns instead of 4.

   NOTE: #ai-log is `display:flex; flex-direction:column` with the
   browser default `align-items:stretch`, so any bare child gets forced
   to 100% width unless it opts out — that's what was stretching this
   into a long bar instead of a compact pill. align-self + width:auto
   below fix that. */
.txa-inline {
  grid-template-columns: 24px 1fr auto;
  align-self: flex-start;
  width: auto;
  max-width: min(300px, 92%);
  margin: 4px 0 10px;
}
.txa-inline .txa-title { font-size: 12px; }
.txa-inline .txa-meta  { font-size: 10.5px; }
.txa-inline .txa-amount { display: inline-block; font-size: 12px; }
