/* Dialog submit dock with the error panel rising from behind it, and the
   error-details popup. */

/*
   The dock sticks to the bottom of the dialog's scroll area on every screen
   size. The error panel sits BEHIND the button (button is z-index 2),
   rests hidden, and rises above it with the banner's bounce; the bar along
   its bottom edge drains over the same dwell time as the page banner.
   Resting states are static (like #banner) so reduced-motion still shows it. */
.t-dock {
  --t-btn-h: 3.1rem;
  --t-gap: 0.45rem;
  --t-pad-b: 0.5rem;
  --t-rise: calc(-1 * (var(--t-btn-h) + var(--t-gap)));
  position: sticky;
  /* Sticky offsets stop at the dialog's inner padding edge; pull the dock down
     by exactly that padding so it sits flush with the scrollport's bottom
     edge (the dialog's transparent scrollbar inset sits below it, painted
     in the same surface) and no scrolled field shows beneath it. */
  bottom: var(--t-stick, calc(-1.5rem + var(--dlg-gut-y, 0px)));
  z-index: 2;
  margin-top: 1.1rem;
  padding: 0.6rem 0 var(--t-pad-b);
  background: var(--surface-2);
}
/* Soft fade so scrolled fields do not end in a hard edge above the dock. */
.t-dock::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 0.9rem;
  background: linear-gradient(rgba(22, 22, 23, 0), var(--surface-2));
  pointer-events: none;
  z-index: -1;
}
.t-dock button.primary,
#trade-form .t-dock button.primary,
#account-dialog-body .t-dock button.primary,
#ledger-dialog-body .t-dock button.primary,
#group-dialog-body .t-dock button.primary {
  position: relative;
  z-index: 2;
  width: 100%;
  min-height: var(--t-btn-h);
  margin: 0;
}

/* Busy state while a record is being saved: spinner + label, not clickable. */
#t-submit.is-busy,
.t-dock button.primary.is-busy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  cursor: progress;
  pointer-events: none;
}
#t-submit.is-busy:disabled,
.t-dock button.primary.is-busy:disabled { opacity: 0.88; }
.btn-spin {
  flex-shrink: 0;
  width: 1.05em;
  height: 1.05em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btnSpin 0.7s linear infinite;
}
@keyframes btnSpin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  /* Feedback, not decoration: keep it turning (slower) under reduced motion. */
  .btn-spin { animation: btnSpin 1.6s linear infinite !important; }
}

.t-err {
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: var(--t-pad-b); /* aligned with the button's bottom edge: fully behind it at rest */
  z-index: 0;
  min-height: 2.5rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--red-line);
  border-radius: var(--radius);
  background: linear-gradient(var(--red-bg), var(--red-bg)), var(--surface-3);
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  transform: translateY(0);
  will-change: transform;
  pointer-events: none;
}
.t-err[hidden] { display: none; }
.t-err.show { transform: translateY(var(--t-rise)); pointer-events: auto; animation: tErrIn var(--banner-in, 600ms) both; }
.t-err.hide { transform: translateY(0); pointer-events: none; animation: tErrOut var(--banner-out, 550ms) both; }

/* Mirror of bannerIn/bannerOut flipped to rise from the bottom: overshoot
   upward, settle just above the button. Opacity fades in during the first
   quarter so a tall (wrapped) message never peeks out above the button. */
@keyframes tErrIn {
  0%   { transform: translateY(0); opacity: 0; animation-timing-function: ease-out; }
  25%  { opacity: 1; }
  55%  { transform: translateY(calc(var(--t-rise) - 8px)); animation-timing-function: ease-in-out; }
  78%  { transform: translateY(calc(var(--t-rise) + 3px)); animation-timing-function: ease-in-out; }
  100% { transform: translateY(var(--t-rise)); opacity: 1; }
}
@keyframes tErrOut {
  0%   { transform: translateY(var(--t-rise)); opacity: 1; animation-timing-function: ease-out; }
  25%  { transform: translateY(calc(var(--t-rise) - 8px)); animation-timing-function: ease-in; }
  75%  { opacity: 1; }
  100% { transform: translateY(0); opacity: 0; }
}

.t-err-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.35rem 0.3rem 0.8rem; flex: 1; }
.t-err-text { flex: 1; min-width: 0; margin: 0; font-size: 0.86rem; line-height: 1.3; overflow-wrap: anywhere; }
.t-err-close {
  flex-shrink: 0;
  min-height: 1.8rem;
  min-width: 1.8rem;
  padding: 0.1rem 0.45rem;
  background: none;
  border-color: transparent;
  color: inherit;
  font-weight: 700;
  border-radius: 999px;
}
.t-err-close:hover { background: rgba(255, 255, 255, 0.1); border-color: transparent; }

/* Time-remaining bar: drains right-to-left after the rise. */
.t-err-progress { width: 100%; height: 2px; background: rgba(255, 255, 255, 0.08); flex-shrink: 0; }
.t-err-bar {
  height: 100%;
  width: 100%;
  background: var(--red);
  opacity: 0.85;
  transform: scaleX(1);
  transform-origin: left;
}
.t-err.run .t-err-bar { animation: bannerProgress var(--banner-dwell, 5000ms) linear var(--banner-lead, 0ms) both; }

@media (prefers-reduced-motion: reduce) {
  /* Timer, not decoration: exempt it from the global animation:none rule. */
  .t-err.run .t-err-bar {
    animation: bannerProgress var(--banner-dwell, 5000ms) linear var(--banner-lead, 0ms) both !important; }
}

/* ————— Error-details popup: fixed box, scrolling list ————— */
#error-dialog[open] {
  width: min(520px, 94vw);
  height: min(430px, 82vh);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#error-dialog .dialog-head { flex-shrink: 0; margin-bottom: 0.5rem; }
#error-dialog-message { margin: 0.2rem 0 0; line-height: 1.6; }
#error-dialog-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0 0.25rem 0.5rem 0;
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 auto;
}
#error-dialog-list li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}
#error-dialog-list li:last-child { border-bottom: none; }
