body {
  background: linear-gradient(180deg, color-mix(in oklab, var(--edge-bg) 84%, #e6efff 16%) 0%, var(--edge-bg) 100%);
}

/* Align controls and modal actions with shared design tokens */
.form-control,
.form-select {
  border-color: var(--edge-border-strong);
  border-radius: var(--edge-control-radius);
  background: var(--edge-surface);
  min-height: var(--edge-control-height);
}

.form-control:focus,
.form-select:focus {
  border-color: color-mix(in oklab, var(--edge-primary) 70%, white 30%);
  box-shadow: var(--edge-focus-ring);
}

.btn {
  border-radius: var(--edge-control-radius);
  min-height: var(--edge-control-height);
  vertical-align: middle;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.form-control-sm,
.form-select-sm,
.btn-sm {
  min-height: var(--edge-control-height-sm);
}

.btn-primary {
  background: linear-gradient(180deg, color-mix(in oklab, var(--edge-primary) 84%, white 16%), var(--edge-primary));
  border-color: color-mix(in oklab, var(--edge-primary) 84%, #234772 16%);
  box-shadow: 0 8px 16px rgba(31, 66, 110, 0.18);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  background: var(--edge-primary-hover) !important;
  border-color: var(--edge-primary-hover) !important;
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(28, 62, 105, 0.2);
}

.btn-outline-primary {
  border-color: color-mix(in oklab, var(--edge-primary) 56%, white 44%);
  color: color-mix(in oklab, var(--edge-primary) 74%, #2d4d7b 26%);
}

.btn-outline-primary:hover,
.btn-outline-primary:focus,
.btn-outline-primary:active {
  background: color-mix(in oklab, var(--edge-primary) 13%, var(--edge-surface) 87%) !important;
  border-color: color-mix(in oklab, var(--edge-primary) 72%, white 28%) !important;
  color: color-mix(in oklab, var(--edge-primary) 84%, #1f3f68 16%) !important;
}

.btn-outline-secondary {
  border-color: color-mix(in oklab, var(--edge-border-strong) 82%, #a1b6d2 18%);
  color: color-mix(in oklab, var(--edge-muted) 88%, #465a78 12%);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus,
.btn-outline-secondary:active {
  background: color-mix(in oklab, var(--edge-surface-alt) 65%, #e3edff 35%) !important;
  border-color: color-mix(in oklab, var(--edge-border-strong) 70%, #95afd0 30%) !important;
  color: color-mix(in oklab, var(--edge-text) 62%, #455a79 38%) !important;
}

.btn-outline-danger {
  border-color: #e1b7bf;
  color: #a03a4c;
}

.btn-outline-danger:hover,
.btn-outline-danger:focus,
.btn-outline-danger:active {
  background: #fff2f5 !important;
  border-color: #cf7f8e !important;
  color: #8f2f41 !important;
}

.modal-content {
  border: 1px solid var(--edge-border);
  border-radius: var(--edge-radius-lg);
  box-shadow: var(--edge-modal-shadow);
}

.modal-header,
.modal-footer {
  border-color: var(--edge-border);
}

.modal-backdrop.modal-stack {
  opacity: 0.35;
}

.modal-footer .btn {
  min-width: 120px;
}

.back-btn {
  border-radius: var(--edge-control-radius) !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--edge-control-height);
  line-height: 1;
  padding-top: 0;
  padding-bottom: 0;
}

.card {
  background: var(--edge-surface);
  border: 1px solid var(--edge-border);
  border-radius: var(--edge-radius);
  box-shadow: var(--edge-shadow);
  overflow: visible;
}

.result-col {
  padding: 0.35rem;
}

#cards-results {
  margin-left: -0.35rem;
  margin-right: -0.35rem;
}

.result-card {
  background: var(--edge-surface);
  border: 1px solid var(--edge-border);
  border-radius: var(--edge-radius);
  box-shadow: var(--edge-shadow-soft);
  overflow: hidden;
}

.card-image-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 63 / 88;
  background: #1f2936;
  overflow: hidden;
  border-radius: var(--edge-radius);
  margin: 0;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: var(--edge-radius) var(--edge-radius) 0 0;
}

.card-image-empty {
  color: var(--edge-border);
  font-size: var(--text-xs);
  display: flex;
  align-items: center;
  justify-content: center;
}

.foil-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.8;
  pointer-events: none;
}

.price-change-badge {
  font-size: var(--text-xs);
  box-shadow: 0 4px 10px rgba(20, 36, 58, 0.2);
}

.result-content {
  padding: 0.65rem 0.75rem 0.75rem;
}

.result-title {
  font-weight: 600;
  font-size: var(--text-base);
  margin-bottom: 0.25rem;
  line-height: var(--lh-snug);
}

.result-meta {
  color: var(--edge-muted);
  font-size: var(--text-sm);
  line-height: var(--lh-snug);
}

.price-line {
  font-size: var(--text-base);
  font-weight: 600;
}

.result-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.result-meta-left {
  min-width: 0;
}

.result-meta-right {
  flex: 0 0 auto;
  text-align: right;
  white-space: nowrap;
}

.admin-block {
  border-top: 1px solid var(--edge-border);
  padding-top: 0.4rem;
}

.card-admin-icon-btn {
  width: 30px;
  min-width: 30px;
  padding-left: 0;
  padding-right: 0;
  line-height: 1;
}

.price-history-chart-wrap {
  height: 140px;
  max-height: 200px;
  position: relative;
}

#price-history-canvas {
  width: 100% !important;
  height: 100% !important;
}

.offers {
  max-height: 120px;
  overflow: auto;
}

.set-icon {
  width: 11px;
  height: 11px;
  vertical-align: -1px;
  margin-right: 3px;
}

.set-icon-fallback {
  display: inline-block;
  width: 11px;
  text-align: center;
  margin-right: 3px;
  color: var(--edge-muted);
}

.set-option-line {
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-option-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ts-dropdown {
  z-index: 2100 !important;
}

.ts-dropdown .ts-dropdown-content {
  max-height: 42vh !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
}

#manualAddEditModal .ts-wrapper,
#priceHistoryModal .ts-wrapper {
  position: relative;
  z-index: 1;
}

#manualAddEditModal .ts-dropdown,
#priceHistoryModal .ts-dropdown {
  z-index: 2200 !important;
}

#manual-add-location-select + .ts-wrapper,
#card-edit-location-select + .ts-wrapper {
  width: 100%;
  font-size: var(--text-sm);
}

#manual-add-location-select + .ts-wrapper .ts-control,
#card-edit-location-select + .ts-wrapper .ts-control {
  min-height: calc(1.5em + 0.5rem + 2px);
  padding: 0.25rem 0.5rem;
  border-radius: var(--edge-control-radius);
}

#manual-add-location-select + .ts-wrapper.focus .ts-control,
#card-edit-location-select + .ts-wrapper.focus .ts-control {
  border-color: color-mix(in oklab, var(--edge-primary) 70%, white 30%);
  box-shadow: var(--edge-focus-ring);
}

#manual-add-location-select + .ts-wrapper .ts-dropdown,
#card-edit-location-select + .ts-wrapper .ts-dropdown {
  max-height: 260px;
  overflow: hidden;
}

#manual-add-location-select + .ts-wrapper .ts-dropdown .ts-dropdown-content,
#card-edit-location-select + .ts-wrapper .ts-dropdown .ts-dropdown-content {
  max-height: 260px !important;
  overflow-y: auto !important;
}

.card-option-thumb {
  width: 24px;
  height: 33px;
  border-radius: 4px;
  object-fit: cover;
  flex: 0 0 24px;
  border: 1px solid var(--edge-border);
  background: #1f2936;
}

.card-option-thumb-fallback {
  width: 24px;
  height: 33px;
  border-radius: 4px;
  flex: 0 0 24px;
  border: 1px solid var(--edge-border);
  background: #1f2936;
  color: #7d8797;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
}

.card-option-text {
  min-width: 0;
}

.card-option-title {
  font-size: var(--text-sm);
  line-height: var(--lh-snug);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-option-meta {
  font-size: var(--text-xs);
  color: var(--edge-muted);
}

.order-item-remove-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: #98a1ad;
  cursor: pointer;
  user-select: none;
  font-size: 15px;
  line-height: 1;
  transition: color 0.15s ease;
}

.order-item-remove-icon:hover,
.order-item-remove-icon:focus-visible {
  color: #b73549;
}

.ts-dropdown {
  z-index: 1080;
}

.search-with-colors {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 0.75rem;
  align-items: end;
}

.search-with-colors-main {
  min-width: 0;
}

.search-with-colors-colors {
  min-width: 0;
}

.search-with-colors-colors .mana-checks-wrap {
  min-width: 0;
}

.filters-line {
  display: grid;
  gap: 0.5rem 0.75rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  margin-bottom: 0.35rem;
}

.filter-item {
  min-width: 0;
}

.filter-item-btn {
  display: flex;
  flex-direction: column;
}

.admin-refresh-mode {
  min-width: 330px;
  height: var(--edge-control-height);
}

.filters-line .form-control-sm,
.filters-line .form-select-sm,
.filters-line .ts-wrapper.single .ts-control,
.filters-line .ts-wrapper.multi .ts-control {
  min-height: var(--edge-control-height);
  border-radius: var(--edge-control-radius);
}

.filters-line .ts-wrapper.single .ts-control {
  padding-top: 8px;
  padding-bottom: 8px;
}

.filters-line .btn {
  height: var(--edge-control-height);
  min-height: var(--edge-control-height);
  white-space: nowrap;
  border-radius: var(--edge-control-radius);
}

.btn-outline-primary.active,
.btn-check:checked + .btn-outline-primary {
  background: color-mix(in oklab, var(--edge-primary) 18%, var(--edge-surface) 82%) !important;
  border-color: color-mix(in oklab, var(--edge-primary) 75%, white 25%) !important;
  color: color-mix(in oklab, var(--edge-primary) 86%, #1f3f68 14%) !important;
}

.btn-outline-secondary.active,
.btn-check:checked + .btn-outline-secondary {
  background: color-mix(in oklab, var(--edge-surface-alt) 48%, #d6e6ff 52%) !important;
  border-color: color-mix(in oklab, var(--edge-border-strong) 62%, #8aa8cf 38%) !important;
  color: color-mix(in oklab, var(--edge-text) 56%, #3f5577 44%) !important;
}

.filters-line .ts-wrapper {
  width: 100%;
}

.filters-line .ts-control {
  flex-wrap: nowrap !important;
  overflow: hidden;
}

.filters-line .ts-control > .item {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  max-width: calc(100% - 32px);
}

.filters-line .ts-wrapper.multi .ts-control {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  white-space: nowrap;
}

.filters-line .ts-wrapper.multi .ts-control > .item {
  flex: 0 0 auto;
  max-width: none;
}

.filters-line .ts-wrapper.multi .ts-control > input {
  min-width: 130px;
  flex: 0 0 130px;
}

.mana-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: var(--edge-control-height);
  height: auto;
  width: 100%;
  min-width: 0;
  align-items: center;
  justify-content: flex-start;
  overflow: visible;
}

.mana-checks-wrap {
  min-height: var(--edge-control-height);
  height: auto;
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 0;
  padding: 0 2px;
  display: flex;
  align-items: center;
  background: transparent;
  overflow: visible;
}

.mana-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--edge-control-height);
  height: var(--edge-control-height);
  border: 1px solid var(--edge-border-strong);
  border-radius: var(--edge-control-radius);
  background: var(--edge-surface);
  cursor: pointer;
  margin: 0;
}

#filter-search.form-control-sm,
.form-control.form-control-sm#filter-search,
.admin-refresh-mode,
#refresh-btn.btn,
#export-topdeck-btn.btn,
#cart-open-btn.btn,
#filter-search,
#filter-foil + .ts-wrapper .ts-control,
#filter-rarity + .ts-wrapper .ts-control,
#filter-types + .ts-wrapper .ts-control,
#filter-sort + .ts-wrapper .ts-control,
#filter-dir + .ts-wrapper .ts-control,
#filter-sets + .ts-wrapper .ts-control {
  border-radius: var(--edge-control-radius) !important;
}

#filter-search {
  height: var(--edge-control-height);
  min-height: var(--edge-control-height);
}

.filter-actions-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 10px !important;
}

.filter-actions-row .btn {
  height: var(--edge-control-height);
  min-height: var(--edge-control-height);
  border-radius: var(--edge-control-radius);
  font-weight: 600;
}

#apply-filters {
  grid-column: span 2;
}

#reset-filters {
  grid-column: span 1;
}

.mana-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mana-symbol {
  width: 18px;
  height: 18px;
}

.mana-check.is-checked {
  border-color: var(--edge-primary);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--edge-primary) 28%, transparent);
}

.mana-multi {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: #fff;
  border-radius: 50%;
  background: conic-gradient(#f5f5f5 0deg 72deg, #9ac7ff 72deg 144deg, #b5b5b5 144deg 216deg, #ff9b9b 216deg 288deg, #9be59d 288deg 360deg);
}

@media (max-width: 1399.98px) {
  .filters-line {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 991.98px) {
  .search-with-colors {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-refresh-mode {
    min-width: 0;
  }

  .filters-line {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-actions-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #apply-filters,
  #reset-filters {
    grid-column: span 1;
  }
}

@media (max-width: 767.98px) {
  .search-with-colors {
    grid-template-columns: 1fr;
  }

  .search-with-colors-colors .mana-checks-wrap {
    min-width: 0;
  }

  .filters-line {
    grid-template-columns: 1fr;
  }

  .filter-actions-row {
    grid-template-columns: 1fr;
  }

  #apply-filters,
  #reset-filters {
    grid-column: span 1;
  }
}
