/* PDF page styles. The shell, theme, tab strip, buttons and modals come from app.BG15.css;
 * this file only adds the page grid. */

@layer app {
  .page-grid {
    list-style: none;
    margin: 0;
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    min-height: 200px;
  }

  .page-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    cursor: grab;
    transition:
      border-color 0.15s ease,
      box-shadow 0.15s ease;
  }

  .page-card:hover {
    border-color: var(--line-strong);
    box-shadow: var(--shadow-md);
  }

  .page-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .page-card.is-unselected {
    background: var(--surface-2);
    border-style: dashed;
  }

  .page-card.is-unselected .page-thumb {
    opacity: 0.45;
  }

  .page-card.is-dragging {
    opacity: 0.4;
  }

  .page-card.drop-before {
    border-left: 3px solid var(--accent);
  }

  .page-card.drop-after {
    border-right: 3px solid var(--accent);
  }

  .page-thumb {
    position: relative;
    container-type: size;
    aspect-ratio: 3 / 4;
    background: #ffffff;
    display: grid;
    place-items: center;
    overflow: hidden;
  }

  .page-thumb img {
    max-width: 100%;
    max-height: 100%;
    display: block;
  }

  /* A quarter-turned thumbnail swaps its extents, so its limits swap with it. Container units
   * are what makes this work: the frame's height comes from its aspect ratio rather than a
   * stated length, so a percentage max-height resolves against nothing and is dropped. */
  .page-thumb.is-turned img {
    max-width: 100cqh;
    max-height: 100cqw;
  }

  .page-thumb .page-pending {
    color: #6b7890;
    font-size: 12px;
  }

  .page-check {
    position: absolute;
    top: 6px;
    left: 6px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: blur(6px);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
  }

  .page-check input {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    margin: 0;
    cursor: pointer;
  }

  .page-number {
    position: absolute;
    right: 6px;
    top: 6px;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: 7px;
    background: color-mix(in srgb, var(--text) 78%, transparent);
    color: var(--bg);
    font-size: 11px;
    font-weight: 800;
    display: grid;
    place-items: center;
  }

  .page-rot {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 3px 7px;
    border-radius: 6px;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 10.5px;
    font-weight: 800;
  }

  .page-body {
    padding: 8px 10px 0;
  }

  .page-source {
    font-size: 11.5px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .page-buttons {
    display: flex;
    gap: 4px;
    padding: 8px;
  }

  .page-btn {
    flex: 1;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--text-2);
    border-radius: 7px;
    padding: 5px 0;
    font-size: 12px;
    font-weight: 650;
    line-height: 1.2;
  }

  .page-btn:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
  }

  .page-btn.danger:hover:not(:disabled) {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 40%, var(--line-strong));
  }

  .page-grid-empty {
    grid-column: 1 / -1;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-3);
  }

  .page-preview-dialog {
    width: min(860px, calc(100% - 32px));
  }

  .page-preview-stage {
    display: grid;
    place-items: center;
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 12px;
    max-height: 66vh;
    overflow: auto;
  }

  .page-preview-stage img {
    max-width: 100%;
    background: #fff;
    box-shadow: var(--shadow-md);
    border-radius: 4px;
  }

  @media (max-width: 680px) {
    .page-grid {
      grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
      gap: 10px;
      padding: 10px;
    }
  }
}
