/* ==========================================================================
   Card sorter products and #403 X1PRO Gen 1 controls
   Scoped to #modalSorter throughout, so nothing here can reach the rest of
   the scan page.
   ========================================================================== */

#modalSorter .sorter-modal {
  max-width: 720px;
  width: calc(100% - 32px);
  box-sizing: border-box;
  padding-bottom: 20px;
}

#modalSorter [hidden] {
  display: none !important;
}

/* #490: the title bar stays at the top of the scrolling window, like Settings' header (a member could not find
   the close button after scrolling down to the rules). Sticky inside the box that scrolls (.sorter-modal, 10 px
   padding); the negative margins reach over that padding so the bar covers the box edge to edge. */
#modalSorter .sorter-header {
  position: sticky;
  top: -10px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: -10px -10px 8px;
  padding: 10px;
  background: #fff;
  border-bottom: 1px solid #ddd;
}

#modalSorter .sorter-header .close {
  float: none;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
  /* A real button (Enter and Space close the window too), drawn like the other windows' close cross. */
  background: none;
  border: 0;
  font-family: inherit;
}

/* Tabbing down the form: a field never hides under the bar. */
#modalSorter .sorter-modal {
  scroll-padding-top: 60px;
}

#modalSorter .sorter-title {
  color: #e0a83a;
  font-size: 1.3em;
  margin: 0 32px 8px 0;
}

/* In the bar the close button is a flex item next to the title: no room to keep for it, no gap under it. Only
   there: scan_classic.html (the previous Scan page, kept a week after #588) still has the old title. */
#modalSorter .sorter-header .sorter-title {
  margin: 0;
}

#modalSorter .sorter-products {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border, #ccc);
}

#modalSorter .sorter-products button {
  height: auto;
  padding: 10px 12px;
  white-space: normal;
  text-align: left;
  background: transparent;
  color: inherit;
  border: 1px solid var(--border, #aaa);
  border-radius: 6px;
  line-height: 1.4;
}

#modalSorter .sorter-products button[aria-selected="true"] {
  border-color: #e0a83a;
  box-shadow: inset 0 -3px #e0a83a;
  font-weight: 700;
}

#modalSorter .sorter-products button span {
  font-size: 0.85em;
  font-weight: 400;
}

#modalSorter .sorter-products button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#modalSorter .sorter-products button:focus-visible,
#modalSorter .sorter-product-links a:focus-visible {
  outline: 2px solid #e0a83a;
  outline-offset: 3px;
}

#modalSorter .sorter-legacy-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 10px 0 18px;
  font-size: 0.82em;
}

#modalSorter .sorter-legacy-toggle input {
  margin: 0;
}

#modalSorter .sorter-product-panel h3 {
  font-size: 1.05em;
  margin: 0 0 10px;
}

#modalSorter .sorter-product-links {
  display: flex;
  gap: 12px 20px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.9em;
}

#modalSorter .sorter-extension-link {
  background: #e0a83a;
  color: #1a1a1a;
  padding: 10px 14px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 700;
}

#modalSorter .sorter-extension-status {
  margin: 18px 0;
  padding: 12px 14px;
  border-left: 3px solid #aaa;
  background: rgba(127, 127, 127, 0.08);
  font-size: 0.88em;
  line-height: 1.5;
}

#modalSorter .sorter-extension-status.is-detected {
  border-color: #1a7f37;
}

#modalSorter .sorter-extension-status p {
  margin: 4px 0 0;
}

#modalSorter .sorter-setup-steps {
  margin: 12px 0;
  padding-left: 22px;
  font-size: 0.9em;
  line-height: 1.6;
}

#modalSorter .sorter-setup-steps li + li {
  margin-top: 6px;
}

#modalSorter .sorter-legacy-notice {
  margin-bottom: 12px;
}

#modalSorter .sorter-lede {
  margin: 0 0 14px;
  font-size: 0.9em;
  line-height: 1.5;
  color: #555;
}

#modalSorter .sorter-buy {
  font-weight: 700;
  white-space: nowrap;
}

#modalSorter fieldset {
  margin-bottom: 12px;
  padding: 10px 12px;
}

#modalSorter legend {
  font-weight: 700;
}

/* One criterion row: field, operator, value, remove. The value cell is the
   one that grows, because a colour chip strip is much wider than a number. */
#modalSorter .sorter-row {
  display: grid;
  grid-template-columns: minmax(0, 150px) minmax(0, 150px) minmax(0, 1fr) 28px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

/* Field and operator own their whole grid cell. The value cell is a flex row
   that may hold several controls (between = two numbers), so its children are
   sized by flex instead - width:100% there would make each one full width. */
#modalSorter .sorter-row > select {
  width: 100%;
  margin: 0;
}

#modalSorter .sorter-value select,
#modalSorter .sorter-value input[type="text"],
#modalSorter .sorter-value input[type="number"] {
  margin: 0;
  min-width: 0;
  flex: 1 1 90px;
}

#modalSorter .sorter-value input[type="number"] {
  flex: 0 1 110px;
}

#modalSorter .sorter-value {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

#modalSorter .sorter-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #c00;
  font-size: 1.1em;
  line-height: 1;
  padding: 0;
}

/* Colour chips. Checkbox stays reachable for keyboard and screen readers;
   the pill is the visible control. */
#modalSorter .sorter-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 26px;
  padding: 0 7px;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.25));
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.85em;
  user-select: none;
}

#modalSorter .sorter-chip input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

#modalSorter .sorter-chip.is-on {
  background: #e0a83a;
  border-color: #e0a83a;
  color: #1a1a1a;
}

#modalSorter .sorter-note {
  font-size: 0.82em;
  line-height: 1.45;
  color: #777;
  margin: 6px 0 0;
}

#modalSorter .sorter-warn {
  font-size: 0.85em;
  line-height: 1.45;
  color: #b3541e;
  margin: 8px 0 0;
}

#modalSorter .sorter-run {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

#modalSorter .sorter-run button {
  height: 30px;
  border-radius: 5px;
  padding: 0 14px;
}

#modalSorter #sorterRunStatus {
  font-size: 0.9em;
  color: #555;
}

#modalSorter #sorterRunStatus.is-live {
  color: #1a7f37;
  font-weight: 700;
}

/* The end-of-run report. Dropped cards are the point of it, so they are not
   tucked away behind a scroll unless the list is genuinely long. */
#modalSorter .sorter-report {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.2));
  border-radius: 8px;
}

#modalSorter .sorter-report h4 {
  margin: 0 0 8px;
  font-size: 0.95em;
}

#modalSorter .sorter-report p {
  margin: 8px 0 0;
}

#modalSorter .sorter-tallies {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 0.9em;
}

#modalSorter .sorter-tally b {
  font-size: 1.25em;
}

#modalSorter .sorter-dropped {
  margin: 10px 0 0;
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.85em;
  padding-left: 18px;
}

@media (prefers-color-scheme: dark) {
  #modalSorter .sorter-lede { color: #bbb; }
  #modalSorter .sorter-note { color: #aaa; }
  #modalSorter #sorterRunStatus { color: #bbb; }
  #modalSorter .sorter-warn { color: #f0a868; }
  #modalSorter #sorterRunStatus.is-live { color: #6ee7a0; }
}

/* #490: one list per X1PRO Gen 2 tray. The second picker sits under the main
   list on the Scan page; the window only holds the switch and the tray. */
#modalSorter .sorter-trays {
  margin: 6px 0 14px;
}

#modalSorter .sorter-trays-on {
  display: flex;
  gap: 6px;
  align-items: baseline;
  font-size: 0.92em;
  line-height: 1.6;
}

#modalSorter .sorter-trays .sorter-note,
#modalSorter .sorter-trays .sorter-warn {
  margin: 8px 0 0 22px;
}

/* "Pause the machine when the right tray has [1000] cards": room for 100000. */
#modalSorter .sorter-trays-on input[type="number"] {
  width: 6.5em;
}

/* "Save a location on these cards: Box [1] Row [2], with [4] rows per box", under the pause it follows. */
#modalSorter .sorter-location {
  margin: 10px 0 0 22px;
  padding-top: 8px;
  border-top: 1px dashed #ddd;
}

#modalSorter .sorter-location .sorter-trays-on span {
  min-width: 0;
}

#modalSorter .sorter-location .sorter-trays-on input[type="number"] {
  width: 3.8em;
}

#modalSorter .sorter-location-next {
  font-size: 0.92em;
  margin: 6px 0 0 22px;
}

.sorter-trays-box {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #ddd;
}

.sorter-trays-box .sorter-trays-label {
  margin-bottom: 6px;
}

.sorter-trays-line {
  font-size: 0.85em;
  color: #444;
  margin-top: 6px;
  max-width: 24rem;
  line-height: 1.45;
}

.sorter-trays-line b {
  color: #1a1a1a;
}

.sorter-trays-line div + div {
  margin-top: 3px;
}

/* #490: Gen 2 with "Decided by Gestic". The radios read as one choice per line;
   "Copies I already own" has one choice per line in its value cell. */
#modalSorter .sorter-radio input[type="radio"] {
  width: auto;
  flex: none;
  margin: 0 6px 0 0;
}

#modalSorter .sorter-radio {
  justify-content: flex-start;
  text-align: left;
  margin-top: 4px;
}

#modalSorter .sorter-value .sorter-owned,
#modalSorter .sorter-value .sorter-owned-lists {
  flex: 1 1 100%;
}

#modalSorter .sorter-owned-lists {
  min-height: 5.5em;
}

#modalSorter .sorter-unrecognised {
  margin: 10px 0 14px;
}

#modalSorter .sorter-unrecognised select {
  margin-left: 6px;
  max-width: 100%;
}

/* A fieldset is at least as wide as its widest content by default: the rule box
   was 30 px wider than the window on a 390 px phone. */
#modalSorter #sorterRules {
  min-inline-size: 0;
}

#modalSorter #sorterRules legend {
  max-width: 100%;
  white-space: normal;
}

/* On a phone the value goes on its own line under field and operator: the
   four-column grid left it no room (Gen 1's rows too). */
@media (max-width: 600px) {
  #modalSorter .sorter-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 28px;
  }
  #modalSorter .sorter-row > .sorter-value {
    grid-column: 1 / 3;
    grid-row: 2;
  }
  #modalSorter .sorter-row > .sorter-remove {
    grid-column: 3;
    grid-row: 1;
  }
}
