/* Merge PDF — file ordering step
   Values taken from the approved artboard (Main.dc.html + PDF Doctor tokens).
   Tokens are scoped to .merge-reorder so nothing leaks into the global sheet. */

.merge-reorder {
  --mr-blue: #145283;
  --mr-blue-ink: #0a2540;
  --mr-gray-400: #858585;
  --mr-gray-450: #757878;
  --mr-text-body: #474747;
  --mr-border-tile: #cdd6e2;
  --mr-border-soft: #f1f1f1;
  --mr-danger: #ef4444;
  --mr-danger-wash: #fef2f2;
  --mr-hover-bg: #f3f4f6;
  --mr-row-flash: #eaf3fc;
  --mr-shadow-card: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
  --mr-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

  width: 100%;
  max-width: 760px;
  /* The list sits inside an auto-sized flex item. Without this the rows'
     intrinsic width inflates that ancestor past the viewport on narrow
     screens, and body{overflow-x:hidden} silently clips both edges. */
  min-width: 0;
}

/* ---------- Sort preset row ---------- */

.mr-sortbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.mr-sortbar__label {
  font-size: 13px;
  color: var(--mr-gray-450);
  font-weight: 500;
  flex-shrink: 0;
}

.mr-pill {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 9999px;
  cursor: pointer;
  font-family: inherit;
  background: #ffffff;
  color: var(--mr-blue);
  border: 1px solid var(--mr-border-tile);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.mr-pill:hover {
  background: var(--mr-hover-bg);
}

.mr-pill[aria-pressed="true"] {
  background: var(--mr-blue);
  color: #ffffff;
  border-color: var(--mr-blue);
}

.mr-sortbar__hint {
  margin-left: auto;
  font-size: 12px;
  color: var(--mr-gray-400);
}

/* ---------- List + rows ---------- */

.mr-list {
  display: flex;
  flex-direction: column;
}

.mr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #ffffff;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 10px 16px;
  margin-bottom: 12px;
  box-shadow: var(--mr-shadow-card);
  transition: background-color 0.3s ease, border-color 0.15s ease, opacity 0.15s ease;
  position: relative;
}

/* Flash after a keyboard / preset move — artboard `justMovedId` state. */
.mr-row.is-moved {
  background: var(--mr-row-flash);
}

/* SortableJS drag states, mapped onto the artboard's drag visuals. */
.mr-row--ghost {
  opacity: 0.4;
  border-color: var(--mr-blue);
}

.mr-row--chosen {
  cursor: grabbing;
}

.mr-row--drag {
  box-shadow: var(--mr-shadow-lg);
}

.mr-row__main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex-grow: 1;
}

.mr-handle {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--mr-gray-400);
  cursor: grab;
  border-radius: 8px;
  /* Stops the browser claiming the gesture so touch drag works. */
  touch-action: none;
}

.mr-handle:active {
  cursor: grabbing;
}

.mr-position {
  color: var(--mr-blue);
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.mr-glyph {
  flex-shrink: 0;
}

.mr-row__text {
  min-width: 0;
  /* The page wrapper sets text-center; rows are left-aligned per the artboard. */
  text-align: left;
  /* Takes the space left by the handle, badge and glyph, which is what
     .mr-name's min-width:100% then resolves against. */
  flex: 1 1 0;
}

.mr-name {
  font-size: 16px;
  line-height: 1.4;
  color: var(--mr-text-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* The filename never wraps, so its intrinsic width would otherwise push the
     auto-sized flex ancestor past the viewport on narrow screens. width:0
     drops its min-content contribution to zero; min-width:100% makes it fill
     the space actually available at layout time. */
  width: 0;
  min-width: 100%;
}

.mr-meta {
  font-size: 12px;
  color: var(--mr-gray-450);
  margin-top: 2px;
}

/* ---------- Controls ---------- */

.mr-row__controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.mr-iconbtn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  border: none;
  background: transparent;
  color: var(--mr-blue);
  cursor: pointer;
  font-size: 18px;
  transition: background-color 0.2s ease;
}

.mr-iconbtn:hover:not(:disabled) {
  background: var(--mr-hover-bg);
}

.mr-iconbtn:disabled {
  opacity: 0.35;
  cursor: default;
}

.mr-iconbtn--muted {
  color: var(--mr-gray-450);
}

.mr-iconbtn--danger {
  color: var(--mr-danger);
}

.mr-iconbtn--danger:hover:not(:disabled) {
  background: var(--mr-danger-wash);
}

.mr-iconbtn svg {
  width: 18px;
  height: 18px;
}

.mr-remove-wrap {
  margin-left: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--mr-border-soft);
  display: inline-flex;
}

/* ---------- Overflow menu (lists over five files) ---------- */

.mr-menu-wrap {
  position: relative;
  display: inline-flex;
}

.mr-menu-wrap[hidden] {
  display: none;
}

.mr-menu {
  position: absolute;
  top: 46px;
  right: 0;
  z-index: 5;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: var(--mr-shadow-lg);
  min-width: 160px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mr-menu[hidden] {
  display: none;
}

.mr-menu__item {
  text-align: left;
  background: transparent;
  border: none;
  padding: 10px 12px;
  /* Artboard has no explicit height here; 44px keeps the touch target legal. */
  min-height: 44px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--mr-text-body);
  font-family: inherit;
  cursor: pointer;
}

.mr-menu__item:hover:not(:disabled) {
  background: var(--mr-hover-bg);
}

.mr-menu__item:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ---------- Undo toast ---------- */

.mr-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--mr-blue-ink);
  color: #ffffff;
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: var(--mr-shadow-lg);
  font-size: 14px;
  max-width: calc(100vw - 32px);
}

.mr-toast[hidden] {
  display: none;
}

.mr-toast__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mr-toast__undo {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

.mr-toast__undo:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ---------- Focus visibility ---------- */

.mr-pill:focus-visible,
.mr-iconbtn:focus-visible,
.mr-menu__item:focus-visible,
.mr-toast__undo:focus-visible,
.mr-handle:focus-visible {
  outline: 2px solid var(--mr-blue);
  outline-offset: 2px;
}

.mr-toast__undo:focus-visible {
  outline-color: #ffffff;
}

/* ---------- Screen-reader-only live region ---------- */

.mr-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Mobile (no artboard; derived per the agreed rules) ---------- */

@media (max-width: 767px) {
  .mr-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Handle, position, glyph, name and meta stay together on the first line.
     Gaps tighten from 12px to 8px to buy the filename back some width at
     375px; the artboard's own 12px is kept everywhere else. */
  .mr-row__main {
    flex: 1 1 100%;
    gap: 8px;
  }

  /* Controls drop to a second line, right-aligned. */
  .mr-row__controls {
    flex: 0 0 auto;
    margin-left: auto;
  }

  .mr-sortbar__hint {
    margin-left: 0;
    flex: 1 1 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mr-row,
  .mr-pill,
  .mr-iconbtn {
    transition: none;
  }
}
