.swap-margin-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}
.swap-choice, .swap-leverage-open {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.swap-choice {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-inline-size: 0;
  gap: 2px;
  margin: 0;
  padding: 2px;
}
.swap-choice label { position: relative; min-width: 0; cursor: pointer; }
.swap-choice label > span {
  display: block;
  overflow: hidden;
  border-radius: 5px;
  padding-inline: 1px;
  color: var(--text-2);
  line-height: 38px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color .14s ease, color .14s ease;
}
.swap-choice input:checked + span { background: var(--bg); box-shadow: inset 0 0 0 1px var(--line-2); color: var(--text); }
.swap-choice input:focus-visible + span { outline: 2px solid var(--spot-buy); outline-offset: -2px; }
.swap-choice label:active > span { background: var(--card-2); }
@media (hover: hover) and (pointer: fine) {
  .swap-choice label:hover > span { color: var(--text); }
}
@media (prefers-reduced-motion: reduce) {
  .swap-choice label > span { transition: none; }
}
.swap-quantity-unit {
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-block-start: 5px;
  border-color: var(--line);
  background: var(--card-2);
  font-size: 11px;
}
.swap-quantity-unit label > span { line-height: 36px; }
.swap-quantity-field:has(#spot-order-amount:focus) { border-color: var(--spot-buy); }
.swap-leverage-open {
  min-height: 44px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 8px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  white-space: nowrap;
}
.swap-leverage-open svg { width: 12px; height: 12px; transform: rotate(90deg); }
.swap-leverage-open[aria-expanded="true"] svg { transform: rotate(-90deg); }
.swap-leverage-open:active { background: var(--card-2); }

.swap-funding {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 1px 5px;
  padding: 3px 3px 6px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.swap-funding-label { flex-basis: 100%; color: var(--text-2); font-size: 10px; }
#swap-funding-value, #swap-funding-timer { white-space: nowrap; }
#swap-funding-value { font-weight: 650; }
#swap-funding-timer { color: var(--text-2); }

.swap-perp-badge {
  display: inline-flex;
  flex: none;
  align-items: center;
  padding: 1px 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--card-2);
  color: var(--yellow);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
[data-theme="light"] .swap-perp-badge { color: #805800; }
.swap-pair-label { display: flex; align-items: center; gap: 5px; min-width: 0; }
.spot-pair-option:has(> .swap-perp-badge) { grid-template-columns: 24px minmax(0, 1fr) auto auto; }

.swap-ticket-options, .swap-actions { display: grid; gap: 6px; min-width: 0; }
.swap-protection-side {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-2);
}
.swap-protection-side button {
  min-height: 30px;
  border-radius: 5px;
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
}
.swap-protection-side button[aria-pressed="true"] { background: var(--green-dim); color: var(--spot-buy); font-weight: 600; }
.swap-protection-side button:last-child[aria-pressed="true"] { background: var(--red-dim); color: var(--spot-sell); }

.swap-asset-metrics, .swap-leverage-summary {
  display: grid;
  gap: 3px;
  color: var(--text-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.swap-asset-metrics { padding-block: 3px; }
.swap-asset-metrics > *, .swap-leverage-summary > * {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1px 5px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.swap-asset-metrics > * > :last-child, .swap-leverage-summary > * > :last-child { color: var(--text); text-align: end; }
.swap-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1px 5px;
  width: 100%;
  min-height: 44px;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--green);
  color: #0a2117;
  font-size: 13px;
  font-weight: 650;
}
.swap-submit small { font-size: 10px; font-weight: 500; }
.swap-submit:is([data-side="short"], [data-side="sell"]) { background: var(--red); color: #221317; }
.swap-submit:disabled {
  border-color: var(--line);
  background: var(--green-dim);
  color: var(--spot-buy);
  cursor: not-allowed;
}
.swap-submit:is([data-side="short"], [data-side="sell"]):disabled { background: var(--red-dim); color: var(--spot-sell); }

.swap-leverage-dialog {
  position: fixed;
  inset: auto 0 calc(10px + max(var(--safe-bottom), env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px)));
  width: min(calc(100% - 24px), 26rem);
  max-width: none;
  max-height: min(79vh, 33rem);
  max-height: min(79dvh, 33rem);
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background: var(--elev);
  color: var(--text);
}
.swap-leverage-dialog[open] { display: flex; flex-direction: column; }
.swap-leverage-dialog::backdrop { background: var(--overlay); }
.swap-leverage-dialog button:focus-visible { outline: 2px solid var(--spot-buy); outline-offset: -2px; }
@media (min-width: 700px) {
  .swap-leverage-dialog { inset: 0; height: fit-content; margin: auto; }
}
.swap-leverage-body {
  display: grid;
  min-height: 0;
  gap: 9px;
  padding: 12px;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.swap-leverage-current {
  color: var(--text-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.swap-leverage-current :is(strong, output) { color: var(--text); font-weight: 600; }
.swap-leverage-input {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  width: min(100%, 17rem);
  justify-self: center;
  align-items: center;
  gap: clamp(5px, 2vw, 10px);
}
.swap-leverage-input button {
  display: grid;
  place-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
  font-size: 20px;
}
.swap-leverage-input button:disabled, .swap-leverage-presets button:disabled { color: var(--text-3); cursor: not-allowed; }
.swap-leverage-input button:not(:disabled):active { background: var(--card-2); }
.swap-leverage-number {
  display: grid;
  grid-template-columns: minmax(0, max-content) auto;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 54px;
  padding-inline: 5px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-2);
  font-size: clamp(27px, 8vw, 34px);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  cursor: text;
}
.swap-leverage-number:focus-within { outline: 2px solid var(--spot-buy); outline-offset: 1px; }
.swap-leverage-digits { position: relative; min-width: 0; max-width: 100%; line-height: 1.2; }
.swap-leverage-digits > span { display: block; visibility: hidden; min-width: 1ch; padding-inline: 1px; white-space: nowrap; }
.swap-leverage-digits input {
  position: absolute;
  inset: 0;
  appearance: textfield;
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 0;
  text-align: center;
}
.swap-leverage-symbol { font-size: .6em; line-height: 1; }
.swap-leverage-input input::-webkit-inner-spin-button,
.swap-leverage-input input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.swap-leverage-presets { display: grid; grid-template-columns: repeat(auto-fit, minmax(38px, 1fr)); gap: 4px; }
.swap-leverage-presets button {
  min-height: 40px;
  padding-inline: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.swap-leverage-presets button[aria-pressed="true"] {
  border-color: var(--spot-buy); background: var(--green-dim); color: var(--spot-buy); font-weight: 650;
}
@media (max-width: 302px) {
  .swap-leverage-presets:has(> button:nth-child(5)) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.swap-leverage-summary {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-2);
}
.swap-leverage-footer { flex: none; padding: 8px 12px 12px; border-block-start: 1px solid var(--line); }
.swap-leverage-confirm {
  width: 100%;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #0a2117;
  font-size: 14px;
  font-weight: 650;
}
.swap-leverage-confirm:disabled { border-color: var(--line); background: var(--bg-2); color: var(--text-2); cursor: not-allowed; }
.swap-leverage-note { color: var(--text-2); font-size: 11px; overflow-wrap: anywhere; }
