/* «Обмен» — the player trade (#7442 web/trade.js, #7441 the app.js hooks).
 * Forge-Glass (ADR-0013): glass, the one gold accent #c9a24b, dark only.
 * Built on app.css's .glass / .btn / .pill / .input / .qconfirm / .pinv-*;
 * everything of the window is scoped under .trd*. #tradeRoot is a sibling of
 * #app (z 3): the window (24) sits above the app, the finder (22) and the
 * chat dock (12/13); the request popup (26) above the window; the toast (30)
 * above all. */

/* ---- app.js hooks: the row button, the item sheet button ---------------- */
.party-trade {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-top: 6px;
}
.party-trade .trade-offer-btn {
  min-height: 30px;
  padding: 4px 10px;
  font-variant-numeric: tabular-nums;
}
.party-trade-why {
  font-size: 11px;
  color: var(--ink-muted);
}

/* ---- the request popup / result (the .qconfirm.pinv look) ---------------- */
#tradeRoot .trd-req {
  z-index: 26;
}
#tradeRoot .trd-result {
  z-index: 27;
  cursor: pointer;
}
.trd-result-lines {
  max-height: 40vh;
  overflow-y: auto;
}
.trd-result-tap {
  font-size: 11px;
  text-align: center !important;
}

/* ---- the outgoing request / walk card ------------------------------------- */
.trd-out {
  position: fixed;
  z-index: 23;
  left: 50%;
  transform: translateX(-50%);
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  width: calc(100% - 16px);
  max-width: 464px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(16, 18, 24, 0.94);
  border: 1px solid rgba(201, 162, 75, 0.35);
  box-shadow: var(--shadow-soft), 0 0 20px rgba(201, 162, 75, 0.12);
  animation: trd-drop 0.2s var(--ease);
}
.trd-out-body {
  flex: 1 1 auto;
  min-width: 0;
}
.trd-out-body .quest-travel {
  margin: 0;
}
.trd-out-text {
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink);
}
.trd-out-note {
  margin-top: 4px !important;
  font-size: 11px;
}
.trd-out-cancel {
  flex: none;
}
@keyframes trd-drop {
  from { transform: translate(-50%, -12px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ---- the window ------------------------------------------------------------- */
.trd {
  position: fixed;
  inset: 0;
  z-index: 24;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(6, 7, 10, 0.62);
  padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
  animation: trd-fade 0.18s var(--ease);
}
.trd-sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-radius: 18px 18px 0 0;
  border-bottom: 0;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(14, 15, 20, 0.95);
  animation: trd-rise 0.22s var(--ease);
}
@keyframes trd-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes trd-rise {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}
.trd-head {
  display: flex;
  align-items: center;
  gap: 4px;
}
.trd-titles {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.trd-titles b {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trd-sub {
  font-size: 11.5px;
  color: var(--ink-muted);
}
.trd-icon {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-size: 18px;
  line-height: 1;
  min-width: 40px;
  min-height: 40px;
  border-radius: 10px;
  cursor: pointer;
}
.trd-icon:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
}
.trd-icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* the line under the head: changed / confirmed / failed / swapping */
.trd-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.35;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
}
.trd-notice.gold {
  border-color: rgba(201, 162, 75, 0.45);
  background: rgba(201, 162, 75, 0.08);
  color: var(--accent-strong);
}
.trd-notice.warn {
  border-color: rgba(230, 193, 115, 0.45);
  background: rgba(230, 193, 115, 0.08);
  color: var(--warn);
}
.trd-notice.err {
  display: block;
  border-color: rgba(207, 91, 84, 0.5);
  background: rgba(207, 91, 84, 0.1);
  color: #e8a19c;
}
.trd-spin {
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 50%;
  border: 2px solid rgba(201, 162, 75, 0.3);
  border-top-color: var(--accent-strong);
  animation: trd-spin 0.8s linear infinite;
}
@keyframes trd-spin {
  to { transform: rotate(360deg); }
}

/* the halves: each scrolls on its own */
.trd-half {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: 8px 10px 10px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.18);
  transition: border-color 0.25s, box-shadow 0.25s;
}
.trd-half--partner {
  flex: 1 1 40%;
}
.trd-half--mine {
  flex: 1 1 52%;
}
.trd-half.is-confirmed {
  border-color: rgba(201, 162, 75, 0.75);
  box-shadow: 0 0 0 1px rgba(201, 162, 75, 0.35), 0 0 18px rgba(201, 162, 75, 0.18);
}
.trd-half-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink);
}
.trd-half-head > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trd-state {
  flex: none;
  font-family: var(--font-body);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  color: var(--ink-muted);
}
.trd-state.ok {
  color: var(--on-accent);
  border-color: transparent;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
}
.trd-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 auto;
}
.trd-empty {
  font-size: 12px;
  color: var(--ink-muted);
  padding: 10px 2px;
}
.trd-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid transparent;
}
.trd-line.is-flash,
.trd-adena-row.is-flash,
.trd-chip.is-flash {
  animation: trd-flash 1.5s var(--ease);
}
@keyframes trd-flash {
  0% { border-color: rgba(201, 162, 75, 0.9); background: rgba(201, 162, 75, 0.22); box-shadow: 0 0 14px rgba(201, 162, 75, 0.35); }
  100% { border-color: transparent; background: rgba(255, 255, 255, 0.025); box-shadow: none; }
}
.trd-ico {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--glass-border);
  overflow: hidden;
}
.trd-lname {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-align: left;
}
.trd-lname b {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trd-lmeta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-muted);
}
.trd-ctl {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.trd-step,
.trd-rm {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.trd-rm {
  color: var(--ink-muted);
  font-size: 13px;
}
.trd-step:disabled,
.trd-rm:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.trd-num {
  width: 52px;
  height: 30px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--ink);
}
.trd-num:focus,
.trd-adena-in:focus,
.trd-qty-in:focus {
  outline: none;
  border-color: var(--accent);
}

/* adena */
.trd-adena-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 10px;
  border: 1px solid transparent;
}
.trd-adena-lbl {
  flex: none;
  font-size: 12.5px;
  color: var(--accent-strong);
  min-width: 48px;
}
.trd-adena-ro b {
  font-size: 13px;
  color: var(--ink);
}
.trd-adena-in {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 14px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.trd-adena-held {
  font-size: 11px;
  color: var(--ink-muted);
  text-align: right;
  padding: 0 6px;
}
.trd-add {
  align-self: flex-start;
}

/* the footer */
.trd-foot {
  display: flex;
  gap: 10px;
  padding-top: 2px;
}
.trd-foot .btn {
  flex: 1 1 0;
  min-width: 0;
}
.trd-confirm {
  position: relative;
  overflow: hidden;
}
.trd-confirm-t {
  position: relative;
}
/* after the partner's change the button fills over 2 s before it is pressable */
.trd-confirm.is-holding::before {
  content: '';
  position: absolute;
  inset: 0;
  transform-origin: left center;
  background: rgba(255, 255, 255, 0.28);
  animation: trd-hold var(--trd-hold, 2000ms) linear forwards;
}
@keyframes trd-hold {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}
.trd-confirm.is-mine:disabled {
  opacity: 0.75;
}

/* the picker and the count prompt: over the window */
.trd-over {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(6, 7, 10, 0.55);
}
.trd-over--qty {
  align-items: center;
  padding: 16px;
}
.trd-pick {
  width: 100%;
  max-width: 480px;
  max-height: 82%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-radius: 18px 18px 0 0;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(16, 18, 24, 0.97);
  animation: trd-rise 0.2s var(--ease);
}
.trd-pick-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.trd-pick-head b {
  font-family: var(--font-display);
  font-size: 15px;
}
.trd-cats {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.trd-cat {
  flex: none;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
}
.trd-cat.is-on {
  color: var(--on-accent);
  border-color: transparent;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
}
.trd-pick-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  min-height: 0;
}
.trd-pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.trd-pick-row:hover:not(:disabled) {
  border-color: rgba(201, 162, 75, 0.5);
}
.trd-pick-row.is-in {
  border-color: rgba(201, 162, 75, 0.35);
}
.trd-pick-row.is-no {
  opacity: 0.45;
  cursor: not-allowed;
}
.trd-why {
  font-size: 11px;
  color: var(--ink-muted);
  white-space: normal;
}
.trd-in {
  font-size: 11px;
  color: var(--accent-strong);
}
.trd-qty {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: 16px;
  background: rgba(16, 18, 24, 0.97);
  border: 1px solid rgba(201, 162, 75, 0.35);
}
.trd-qty-item {
  display: flex;
  align-items: center;
  gap: 10px;
}
.trd-qty-item b {
  font-size: 14px;
}
.trd-qty-title {
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1.35;
}
.trd-qty-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.trd-qty-in {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.trd-qty .qconfirm-actions {
  margin-top: 0;
}

/* the folded window: a chip above the tab bar (and the chat dock) */
.trd-chip {
  position: fixed;
  z-index: 23;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--dock-bottom, 64px) + var(--chat-dock-h, 0px) + 8px);
  width: calc(100% - 24px);
  max-width: 456px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid rgba(201, 162, 75, 0.5);
  background: rgba(16, 18, 24, 0.94);
  box-shadow: var(--shadow-soft), 0 0 18px rgba(201, 162, 75, 0.15);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.trd-chip-ico {
  color: var(--accent-strong);
  font-size: 16px;
}
.trd-chip-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.trd-chip-open {
  flex: none;
  font-size: 12px;
  color: var(--accent-strong);
}

@media (prefers-reduced-motion: reduce) {
  .trd,
  .trd-sheet,
  .trd-pick,
  .trd-out,
  .trd-line.is-flash,
  .trd-adena-row.is-flash,
  .trd-chip.is-flash,
  .trd-confirm.is-holding::before {
    animation: none;
  }
}
