/* Public interaction system. Keep motion independent of business components. */
.exchange-app {
  --motion-fast: 120ms;
  --motion-enter: 180ms;
  --ease-responsive: cubic-bezier(.2, .8, .2, 1);
}

/* Network state stays separate from form validation and never clears a draft. */
.exchange-app .network-notice {
  margin: 0 0 14px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--warning);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 13px;
  line-height: 1.7;
}
.exchange-app .network-notice[hidden] { display: none; }
.exchange-app :is(.panel, .history-query-panel) { min-width: 0; }
.exchange-app :is(.message, .field-feedback) { overflow-wrap: anywhere; }
@media (max-width: 700px) {
  .exchange-app :is(input:not([type="checkbox"]):not([type="radio"]), textarea, select) { font-size: 16px; }
  .exchange-app :is(.text-button, .icon-button) { min-height: 44px; }
}

/* Switching between short and long workspaces must not move the whole shell. */
html:has(.exchange-app) { min-width: 0; scrollbar-gutter: stable; }
html:has(.exchange-app .session-help-dialog[open]) { overflow: hidden; }

.exchange-app .view {
  animation: workspace-arrive var(--motion-enter) var(--ease-responsive);
}
.exchange-app :is(.tabs button, .button, .text-button, .icon-button) {
  touch-action: manipulation;
  transition: color var(--motion-fast), background-color var(--motion-fast),
    border-color var(--motion-fast), box-shadow var(--motion-fast),
    transform var(--motion-fast) var(--ease-responsive);
}
.exchange-app .text-button {
  /* Text actions still need a deliberate hit area on pointer devices. */
  min-height: 36px;
  padding: 6px 8px;
  border-radius: 7px;
}
.exchange-app .text-button:hover:not(:disabled) {
  text-decoration: none;
  background: var(--primary-soft);
}
.exchange-app .text-button:active:not(:disabled) {
  color: var(--primary-hover);
  background: color-mix(in srgb, var(--primary-soft) 78%, var(--surface));
  box-shadow: inset 0 2px 4px color-mix(in srgb, var(--primary) 18%, transparent);
}
.exchange-app .tabs button:active:not(:disabled) { transform: scale(.985); }
.exchange-app :is(.tabs button, .button, .text-button, .icon-button):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}
.exchange-app :is(input, textarea, select) {
  scroll-margin-block: 24px 170px;
  transition: background-color var(--motion-fast), border-color var(--motion-fast),
    box-shadow var(--motion-fast);
}
.exchange-app :is(.recharge-plan-options, .upgrade-plan-options) label > span {
  transition: background-color var(--motion-fast), border-color var(--motion-fast),
    color var(--motion-fast);
}

/* Both labels share one in-flow cell. An absolutely positioned grid child
   with an automatic end line starts at the content edge but ends at the
   padding edge, shifting feedback down/right by half the button padding. */
.exchange-app .button[aria-busy="true"] {
  display: inline-grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  align-content: center;
  opacity: 1;
  cursor: progress;
  transform: none;
}
.exchange-app #validateSessionBtn[aria-busy="true"] { display: inline-grid; }
.exchange-app :is(.button-label-reserve, .button-label-feedback) {
  grid-area: 1 / 1;
  display: inline-flex;
  min-inline-size: max-content;
  text-align: center;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.exchange-app .button-label-reserve { visibility: hidden; pointer-events: none; }
.exchange-app .button-label-feedback {
  position: static;
  padding: 0;
  gap: 6px;
  font-size: 12px;
  white-space: nowrap;
}
.exchange-app .button-label-feedback::before {
  content: '';
  box-sizing: border-box;
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: feedback-spin .75s linear infinite;
}
/* Compact verification actions must also fit their spinner and status text. */
.exchange-app .access-controls { grid-template-columns: minmax(0, 1fr) minmax(110px, max-content); }
.exchange-app .actions .button { min-inline-size: 110px; }
.exchange-app .session-help-dialog { overscroll-behavior: contain; }
.exchange-app .session-help-dialog[open] {
  animation: dialog-arrive var(--motion-enter) var(--ease-responsive);
}
.exchange-app .session-help-dialog[open]::backdrop {
  animation: feedback-appear var(--motion-enter) ease-out;
}
.exchange-app .toast:not(.hidden) {
  animation: feedback-appear var(--motion-enter) ease-out;
}

/* Only animate composited properties, with no outgoing copy of sensitive UI. */
@keyframes workspace-arrive {
  from { opacity: .35; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
@keyframes dialog-arrive {
  from { opacity: 0; transform: translateY(8px) scale(.99); }
  to { opacity: 1; transform: none; }
}
@keyframes feedback-appear { from { opacity: 0; } to { opacity: 1; } }
@keyframes feedback-spin { to { transform: rotate(360deg); } }

@media (hover: hover) and (pointer: fine) {
  .exchange-app .tabs button:not(.active):hover { background: var(--surface-soft); }
  .exchange-app .button:not(:disabled):not([aria-busy="true"]):hover {
    transform: none;
  }
}
@media (hover: none) {
  .exchange-app .button:hover { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .exchange-app .view,
  .exchange-app .session-help-dialog[open],
  .exchange-app .session-help-dialog[open]::backdrop,
  .exchange-app .toast:not(.hidden),
  .exchange-app .button-label-feedback::before { animation: none; }
  .exchange-app :is(.tabs button, .button, .text-button, .icon-button, input, textarea, select),
  .exchange-app :is(.recharge-plan-options, .upgrade-plan-options) label > span {
    transition: none;
  }
  .exchange-app :is(.tabs button, .button, .text-button, .icon-button):active,
  .exchange-app .button:not(:disabled):not([aria-busy="true"]):hover { transform: none; }
}


/* Calm tactile feedback: pressing a control compresses its existing surface
   instead of adding a dark inset halo. The label, color and border remain
   stable, so mouse and touch presses feel deliberate without flashing. */
.exchange-app :is(.button, .icon-button, .tabs button) {
  transform-origin: center;
}
.exchange-app .button:active:not(:disabled):not([aria-busy="true"]) {
  transform: scale(.985);
  filter: none;
}
.exchange-app .button.primary:active:not(:disabled):not([aria-busy="true"]) {
  border-color: transparent;
  color: var(--on-primary);
  background: var(--primary-hover);
  box-shadow: 0 2px 7px color-mix(in srgb, var(--primary) 18%, transparent);
}
.exchange-app .button.ghost:active:not(:disabled):not([aria-busy="true"]) {
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--surface-soft) 72%, var(--surface));
  box-shadow: 0 1px 3px color-mix(in srgb, var(--text) 9%, transparent);
}
.exchange-app .icon-button:active:not(:disabled) {
  transform: scale(.955);
  border-color: var(--line-strong);
  background: var(--surface-soft);
  box-shadow: 0 1px 3px color-mix(in srgb, var(--text) 9%, transparent);
  filter: none;
}
.exchange-app .tabs button:active:not(:disabled) {
  transform: scale(.99);
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 74%, transparent);
  box-shadow: none;
  filter: none;
}
.exchange-app .tabs button.active:active:not(:disabled) {
  background: var(--surface);
  box-shadow: 0 1px 3px color-mix(in srgb, var(--text) 8%, transparent);
}
.exchange-app .text-button:active:not(:disabled) {
  transform: none;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary-soft) 74%, transparent);
  box-shadow: none;
  filter: none;
}

/* Loading is a stable progress state, not a permanently depressed button. */
.exchange-app .button[aria-busy="true"] {
  border-color: color-mix(in srgb, var(--primary) 24%, var(--line));
  background: color-mix(in srgb, var(--primary-soft) 54%, var(--surface));
  color: var(--primary);
  filter: none;
  box-shadow: 0 2px 7px color-mix(in srgb, var(--text) 7%, transparent);
}
.exchange-app .button.primary[aria-busy="true"] {
  border-color: transparent;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 3px 10px color-mix(in srgb, var(--primary) 18%, transparent);
}
.exchange-app .button[aria-busy="true"] .button-label-feedback {
  padding: 0;
  gap: 8px;
}
.exchange-app .button[aria-busy="true"] .button-label-feedback::before {
  width: 13px;
  height: 13px;
  flex-basis: 13px;
  border-width: 2px;
  opacity: .86;
}
@media (prefers-reduced-motion: reduce) {
  .exchange-app :is(.button, .icon-button, .tabs button):active:not(:disabled) { transform: none; }
}

/* UI audit polish: option controls and form surfaces share the same tactile language. */
.exchange-app :is(.recharge-plan-options label, .upgrade-plan-options label, .credits-presets button, .renewal-switch) {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--motion-fast) var(--ease-responsive),
    border-color var(--motion-fast), background-color var(--motion-fast),
    box-shadow var(--motion-fast), color var(--motion-fast), filter var(--motion-fast);
}
.exchange-app :is(.recharge-plan-options label, .upgrade-plan-options label, .credits-presets button, .renewal-switch):hover {
  border-color: color-mix(in srgb, var(--primary) 30%, var(--line));
}
.exchange-app :is(.recharge-plan-options label, .upgrade-plan-options label, .credits-presets button, .renewal-switch):active {
  transform: scale(.992);
  filter: none;
  box-shadow: 0 1px 4px color-mix(in srgb, var(--text) 8%, transparent);
}
.exchange-app :is(.recharge-plan-options label, .upgrade-plan-options label):active > span {
  border-color: color-mix(in srgb, var(--primary) 42%, var(--line));
  background: color-mix(in srgb, var(--primary-soft) 38%, var(--surface));
}
.exchange-app :is(.recharge-plan-options label, .upgrade-plan-options label, .credits-presets button, .renewal-switch):focus-within {
  outline: 2px solid color-mix(in srgb, var(--primary) 58%, transparent);
  outline-offset: 3px;
}
.exchange-app .recharge-plan-options input:checked + span,
.exchange-app .upgrade-plan-options input:checked + span,
.exchange-app .credits-presets button.active {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 56%, var(--line)),
    0 4px 12px color-mix(in srgb, var(--primary) 9%, transparent);
}
.exchange-app .upgrade-plan-options input:checked + span {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--upgrade-accent) 60%, var(--line)),
    0 4px 12px color-mix(in srgb, var(--upgrade-accent) 10%, transparent);
}
.exchange-app .credits-presets button.active {
  border-color: color-mix(in srgb, var(--credits-accent) 58%, var(--line));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--credits-accent) 58%, var(--line)),
    0 4px 12px color-mix(in srgb, var(--credits-accent) 10%, transparent);
}
.exchange-app .action-dock {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
@media (max-width: 640px) {
  .exchange-app .action-dock { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .exchange-app .editor-actionbar { padding-bottom: 2px; }
}
@media (prefers-reduced-motion: reduce) {
  .exchange-app :is(.recharge-plan-options label, .upgrade-plan-options label, .credits-presets button, .renewal-switch):active {
    transform: none;
    filter: none;
  }
  .exchange-app :is(.recharge-plan-options label, .upgrade-plan-options label, .credits-presets button, .renewal-switch) { transition: none; }
}

/* A horizontal flex basis becomes a 220px height once mobile stacks the link
   and copy button. Let the readable URL determine its height instead. */
@media (max-width: 640px) {
  .exchange-app .verification-link-text { flex: 0 1 auto; }
}
