// Sort Order page, in the same design as the GS Logo Slider Sort Order page.

$gs-accent: #5e6be5;
$gs-accent-dark: #4a57d3;
$gs-accent-soft: #eef0fd;
$gs-heading: #16213f;
$gs-text: #33405a;
$gs-muted: #5b6678;
$gs-border: #e6e9f0;

.wrap {
  margin: 0px 20px 0 2px;
}

// Tabs
.gs-plugins--sort-links {
  position: relative;
  z-index: 1000; // Above the Pro overlay, so free users can still switch tabs.
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 24px;
  padding: 0 30px;
  background: #fff;
  margin: 0px 0px 0 -20px;
  box-shadow: 0px 1px 10px rgba(63, 66, 87, 0.06);

  a {
    // Make like menu link
    color: #515365;
    font-size: 16px;
    text-decoration: none;
    transition: color .3s;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    line-height: 64px;
    box-shadow: none;
    outline: none;

    &.gs-sort-active {
      color: #242429;
      border-color: $gs-accent;
    }
  }
}

.gs-plugins--sort-content {
  padding-left: 10px; // Lines up with the tab labels.
  opacity: .55; // Readable, so users can see what Pro unlocks.
  pointer-events: none;
  user-select: none;

  &.gsp-book-premium-active {
    opacity: 1 !important;
    pointer-events: auto;
    user-select: auto;
  }
}

// Title
.gs-plugin-heading {
  max-width: 1600px;
  margin: 28px 0 22px;
  padding-left: 10px; // Lines up with the tab labels and the list.
}

.wrap h2.gs-plugin-title {
  margin: 0 0 6px;
  padding: 0;
  color: #1d2327;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;

  > * {
    display: inline-block;
    vertical-align: middle;
  }
}

.gs-plugin-subtitle {
  margin: 0;
  color: #6b7280;
  font-size: 14px;
}

#loading-animation,
#loading-animation-per-book {
  width: 20px;
  height: 20px;
  margin: 4px 0px 0px 8px;
  display: none;
}

// Pro overlay
.gs-book-disable--sort-page {
  position: fixed;
  width: calc(100% - 160px);
  margin-left: 160px;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gs-book-disable--sort-page {
  pointer-events: none; // Only the card takes clicks.
}

// Lock card: icon, title, what the tab does and the upgrade button.
.gs-book-disable--sort-inner {
  pointer-events: auto;
  box-sizing: border-box;
  width: 400px;
  max-width: calc(100% - 32px);
  padding: 28px 28px 24px;
  background: #fff;
  border: 1px solid #e3e6f0;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(24, 31, 66, 0.16);
  text-align: center;
}

.gs-book-disable--sort-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: rgba(100, 114, 239, 0.12);
  color: #6472ef;
}

.gs-book-disable--sort-title {
  margin: 0 0 6px;
  color: #1d2327;
  font-size: 17px;
  font-weight: 700;
}

.gs-book-disable--sort-text {
  margin: 0 0 18px;
  color: #50575e;
  font-size: 13px;
  line-height: 1.55;
}

.gs-book-disable--sort-message > a {
  display: inline-block;
  padding: 10px 22px;
  border-radius: 8px;
  background: #6472ef;
  box-shadow: 0 6px 16px rgba(100, 114, 239, 0.3);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color .15s ease;

  &:hover,
  &:focus {
    background: #4f5be0;
    color: #fff;
  }
}

// Locked Single Book Info: preview of the fields Pro adds.
.table-pro-preview--head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 16px 8px;
  border-top: 1px solid #e3e6f0;
  color: #1d2327;
  font-size: 13px;
  font-weight: 700;
}

.gs-book-pro-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(100, 114, 239, 0.12);
  color: #6472ef;
  font-size: 11px;
  font-weight: 700;
}

// Empty state
.gs-book-sort-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  padding: 48px 28px;
  background: #fff;
  border: 1px dashed #d5dae3;
  border-radius: 12px;
  text-align: center;

  h3 {
    margin: 0 0 6px;
    color: $gs-heading;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
  }

  p {
    margin: 0;
    color: $gs-muted;
    font-size: 14px;
    line-height: 1.55;
  }
}

.gs-book-sort-empty--icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-bottom: 16px;
  background: $gs-accent-soft;
  border-radius: 14px;
  color: $gs-accent;

  .dashicons {
    width: 26px;
    height: 26px;
    font-size: 26px;
  }
}

.gs-book-sort-empty--actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.gs-plugins--sort-page .button-primary {
  background: $gs-accent;
  border-color: $gs-accent;

  &:hover,
  &:focus {
    background: $gs-accent-dark;
    border-color: $gs-accent-dark;
  }
}

// Layout
.gs-book-sorting-wrap {
  display: flex;
  width: 100%;
  gap: 40px;
  flex-wrap: wrap;

  .gs-book-sort--sort-area {
    flex: 3;
    min-width: 0;

    &.gs-book-sort--narrow {
      flex: 0 1 760px;
    }
  }

  .gs-book-sort--docs-area {
    position: sticky;
    top: 52px;
    flex: 2;
    align-self: flex-start;
    min-width: 300px;
  }
}

// Drag handle
.sortable-icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;

  svg {
    display: block;
    width: 14px;
    height: auto;
    fill: #a3acbd;
    transition: fill .15s ease-in-out;
  }
}

// Rows. Not .ui-sortable-handle: that class only arrives once the script runs.
.gs-book-sort-list {
  margin: 0;

  > li {
    display: flex;
    align-items: center;
    gap: 16px;
    box-sizing: border-box;
    min-height: 64px;
    margin-bottom: 8px;
    padding: 10px 18px 10px 14px;
    background: #fff;
    border: 1px solid $gs-border;
    border-radius: 10px;
    cursor: grab;
    transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;

    .sortable-thumbnail {
      flex: none;
      line-height: 0;

      span {
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        width: 40px;
        height: 52px;
        overflow: hidden;
        background: #f7f8fb;
        border-radius: 6px;
      }

      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }

    .sortable-title {
      flex: 1 1 auto;
      min-width: 0;
      color: $gs-heading;
      font-size: 14px;
      font-weight: 600;
      line-height: 1.4;
    }

    .sortable-group {
      flex: 0 1 auto;
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-end;
      gap: 6px;

      span {
        padding: 4px 10px;
        background: $gs-accent-soft;
        border-radius: 999px;
        color: $gs-accent-dark;
        font-size: 12px;
        font-weight: 500;
        line-height: 1.4;
        white-space: nowrap;
      }
    }

    &:hover {
      border-color: #c5cbf5;
      box-shadow: 0 2px 8px rgba(22, 33, 63, .06);

      .sortable-icon svg {
        fill: $gs-accent;
      }
    }

    &.ui-sortable-helper {
      border-color: $gs-accent;
      box-shadow: 0 8px 24px rgba(22, 33, 63, .16);
      cursor: grabbing;
    }
  }

  &.gs-book-sort-list--compact > li {
    min-height: 48px;
    padding: 8px 14px 8px 10px;
    background: #f7f8fb;
  }
}

// Side panel (query steps and per-book authors)
.gs-book-sort--docs-area-content {
  box-sizing: border-box;
  padding: 24px 26px;
  background: #fff;
  border: 1px solid $gs-border;
  border-radius: 12px;

  h3 {
    margin: 0 0 4px;
    color: $gs-heading;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.4;
  }

  > p {
    margin: 0 0 18px;
    color: $gs-muted;
    font-size: 13.5px;
  }

  ol {
    counter-reset: gs-book-sort-step;
    list-style: none;
    margin: 0;
    padding: 0;
  }

  ol li {
    counter-increment: gs-book-sort-step;
    position: relative;
    margin: 0 0 12px;
    padding-left: 36px;
    color: $gs-text;
    font-size: 14px;
    line-height: 24px;

    &::before {
      content: counter(gs-book-sort-step);
      position: absolute;
      top: 0;
      left: 0;
      width: 24px;
      height: 24px;
      background: $gs-accent-soft;
      border-radius: 50%;
      color: $gs-accent;
      font-size: 12px;
      font-weight: 700;
      line-height: 24px;
      text-align: center;
    }
  }

  strong {
    color: $gs-heading;
    font-weight: 600;
  }
}

.gs-book-sort--docs-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid $gs-border;

  a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: $gs-accent;
    font-size: 13.5px;
    font-weight: 600;
    text-decoration: none;
    box-shadow: none;

    &:hover,
    &:focus {
      color: $gs-accent-dark;
    }
  }

  .dashicons {
    width: 18px;
    height: 18px;
    font-size: 18px;
  }
}

// Per-book author order
.gsbook-sort--per-book-authors {

  .gsb-per-book-select-row {
    display: flex;
    align-items: center;

    #loading-animation-per-book {
      flex: none;
      margin-top: 0;
    }
  }

  select#gsb-per-book-author-select {
    flex: 1 1 auto;
    width: 100%;
    max-width: none;
    min-height: 40px;
    padding: 0 32px 0 12px;
    border: 1px solid #d5dae3;
    border-radius: 8px;
    color: $gs-heading;
    font-size: 14px;

    &:focus {
      border-color: $gs-accent;
      box-shadow: 0 0 0 1px $gs-accent;
    }
  }

  .gsb-per-book-note {
    margin: 12px 0 0;
    color: $gs-muted;
    font-size: 13px;
    line-height: 1.5;
  }

  #sortable-book-authors-list {
    display: none;
    margin-top: 14px;
  }

  #gsb-per-book-authors-reset-wrap {
    display: none;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid $gs-border;

    .gsb-per-book-note {
      margin-top: 8px;
    }
  }

  .gsb-per-book-reset-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
  }

  #gsb-per-book-authors-reset-status {
    color: $gs-muted;
    font-size: 13px;
  }
}

// Card used by the tables
.gs-book-sort-card {
  box-sizing: border-box;
  overflow: hidden;
  background: #fff;
  border: 1px solid $gs-border;
  border-radius: 12px;
}

.gs-book-sort-card--footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 18px;
  border-top: 1px solid $gs-border;
}

// Single Book Info
.table-visibility {
  box-sizing: border-box;
  background: #fff;
  border: 1px solid $gs-border;
  border-radius: 12px;

  .table-row {
    --item-width: max(15%, 72px);
    display: flex;
    align-items: center;
    width: 100%;
    margin: 0;
    padding: 0;
    background: #fff;

    > div {
      box-sizing: border-box;
      padding: 12px 16px;
    }

    > div:first-child {
      width: calc(100% - (var(--item-width) * 4));
      min-width: 0;
    }

    > div:not(:first-child) {
      width: var(--item-width);
      text-align: center;
    }
  }

  .table-head .table-row {
    border-bottom: 1px solid $gs-border;
    border-radius: 12px 12px 0 0;
    background: #f7f8fb;

    > div:first-child {
      color: $gs-muted;
      font-size: 12px;
      font-weight: 600;
      letter-spacing: .4px;
      text-transform: uppercase;
    }
  }

  .ui-sortable--table {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;

    .table-row {
      border-bottom: 1px solid $gs-border;
      cursor: grab;
      transition: background-color .15s ease-in-out, box-shadow .15s ease-in-out;

      &:last-child {
        border-bottom: 0;
        border-radius: 0 0 12px 12px;
      }

      &:hover {
        background: #fafbff;

        .sortable-icon svg {
          fill: $gs-accent;
        }
      }

      &.ui-sortable-helper {
        border: 1px solid $gs-accent;
        border-radius: 10px;
        box-shadow: 0 8px 24px rgba(22, 33, 63, .16);
        cursor: grabbing;
      }
    }
  }

  .sortable-icon-title {
    display: flex;
    align-items: center;
    gap: 12px;
    color: $gs-heading;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
  }

  .gs-checkbox-ui {
    display: inline-flex;

    input[type="checkbox"] {
      margin: 0;
      border-color: #c3c8d4;
      border-radius: 4px;

      &:checked {
        background: $gs-accent;
        border-color: $gs-accent;

        &::before {
          filter: brightness(0) invert(1);
        }
      }

      &:focus {
        border-color: $gs-accent;
        box-shadow: 0 0 0 1px $gs-accent;
      }
    }
  }

  .visibility-device {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 8px;
    background: $gs-accent-soft;
    border-radius: 6px;
    color: $gs-accent;

    span {
      position: absolute;
      bottom: calc(100% + 10px);
      left: 50%;
      z-index: 1;
      padding: 2px 6px;
      background: $gs-heading;
      border-radius: 4px;
      color: #fff;
      font-size: 12px;
      white-space: nowrap;
      opacity: 0;
      pointer-events: none;
      transform: translateX(-50%);
      transition: opacity .15s ease;

      &::after {
        content: "";
        position: absolute;
        top: 100%;
        left: calc(50% - 6px);
        border: 6px solid transparent;
        border-top-color: $gs-heading;
      }
    }

    svg {
      width: 16px;
      height: 16px;
    }

    &:hover span {
      opacity: 1;
    }
  }
}

// Book Icons
.gsbks-icon-form .gsbks-icon-table {
  width: 100%;
  border-collapse: collapse;

  th {
    padding: 12px 18px;
    background: #f7f8fb;
    border-bottom: 1px solid $gs-border;
    color: $gs-muted;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .4px;
    text-align: left;
    text-transform: uppercase;
  }

  td {
    padding: 10px 18px;
    border-bottom: 1px solid $gs-border;
    vertical-align: middle;
  }

  tbody tr:last-child td {
    border-bottom: 0;
  }

  .gsbks-icon-field {
    width: 34%;
    color: $gs-heading;
    font-size: 14px;
    font-weight: 600;
  }

  .gsbks-icon-control {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .gsbks-icon-preview {
    flex: none;
    width: 36px;
    height: 36px;
    background: $gs-accent-soft;
    border-radius: 8px;
    color: $gs-accent;
    font-size: 16px;
    line-height: 36px;
    text-align: center;
  }

  .gsbks-icon-input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 36px;
    border-color: #d5dae3;
    border-radius: 8px;

    &:focus {
      border-color: $gs-accent;
      box-shadow: 0 0 0 1px $gs-accent;
    }
  }

  .gsbks-icon-btn {
    flex: none;
    min-height: 36px;
    border-radius: 8px;
  }
}

@media (max-width: 960px) {
  .gs-book-disable--sort-page {
    width: calc(100% - 36px);
    margin-left: 36px;
  }
}

@media (max-width: 782px) {
  .gs-book-disable--sort-page {
    width: 100%;
    margin-left: 0;
  }

  .gs-book-disable--sort-message > a {
    white-space: nowrap;
  }

  // Six tabs don't fit a phone, so they scroll sideways in one row.
  .gs-plugins--sort-links {
    flex-wrap: nowrap;
    column-gap: 20px;
    padding: 0 16px;
    overflow-x: auto;
    scrollbar-width: none;

    a {
      flex: none;
      font-size: 14px;
      line-height: 52px;
      white-space: nowrap;
    }
  }

  .gs-book-sorting-wrap {
    flex-direction: column;
    gap: 24px;
  }

  .gs-book-sorting-wrap .gs-book-sort--sort-area,
  .gs-book-sorting-wrap .gs-book-sort--sort-area.gs-book-sort--narrow,
  .gs-book-sorting-wrap .gs-book-sort--docs-area {
    flex: none;
    width: 100%;
    min-width: 0;
  }

  .gs-book-sorting-wrap .gs-book-sort--docs-area {
    position: static;
  }

  .gs-book-sorting-wrap .sortable-group {
    display: none !important;
  }

  .table-visibility .table-row {
    --item-width: 52px;

    > div {
      padding: 10px 8px;
    }
  }

  // Field name above its icon controls.
  .gsbks-icon-form .gsbks-icon-table {
    thead {
      display: none;
    }

    &,
    tbody,
    tr,
    td {
      display: block;
    }

    .gsbks-icon-input {
      width: 0; // Let flex size it.
    }

    tr {
      padding: 12px 14px;
      border-bottom: 1px solid $gs-border;
    }

    tbody tr:last-child {
      border-bottom: 0;
    }

    td,
    .gsbks-icon-field {
      width: auto;
      padding: 0;
      border-bottom: 0;
    }

    .gsbks-icon-field {
      margin-bottom: 8px;
    }
  }
}


// List on the left, lock card and tips on the right.
.gs-plugins--sort-layout {
  display: grid;
  // The list keeps its own width (up to 980px); the cards sit right beside it.
  grid-template-columns: fit-content(980px) minmax(300px, 1fr); // Cards fill the rest of the row.
  max-width: 1600px;
  align-items: start;
  gap: 32px;

  .gs-book-sorting-wrap,
  .gs-book-sort--sort-area,
  .gs-book-sort--narrow {
    max-width: 100%;
  }

  // Short lists (filters, icons) keep a comfortable width.
  @media (min-width: 1101px) {
    > .gs-plugins--sort-content {
      min-width: 600px;
    }
  }

  @media (max-width: 1100px) {
    grid-template-columns: minmax(0, 1fr);

    .gs-plugins--sort-aside {
      order: -1;
      position: static;
    }
  }
}

.gs-plugins--sort-aside {
  position: sticky;
  top: 56px; // Below the WordPress toolbar.
  display: flex;
  flex-direction: column;
  gap: 16px;

  .gs-book-disable--sort-inner {
    width: 100%;
    max-width: none;
    padding: 24px;
    box-shadow: 0 10px 30px rgba(24, 31, 66, 0.08);
  }
}

.gs-sort-tips {
  padding: 20px 22px;
  background: #fff;
  border: 1px solid #e3e6f0;
  border-radius: 14px;

  .gs-sort-tips--title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px;
    color: #1d2327;
    font-size: 14px;
    font-weight: 700;

    svg {
      color: #6472ef;
    }
  }

  ul {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  li {
    position: relative;
    margin: 0;
    padding: 8px 0 8px 18px;
    border-top: 1px solid #eef0f4;
    color: #50575e;
    font-size: 13px;
    line-height: 1.55;

    &::before {
      content: "";
      position: absolute;
      top: 15px;
      left: 2px;
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: #6472ef;
    }

    &:first-child {
      border-top: 0;
      padding-top: 0;

      &::before {
        top: 7px;
      }
    }
  }
}


// Per-tab column widths (Books and Authors use the default above).

// Groups: list, Query Settings and the cards in three equal columns.
.gs-plugins--sort-layout--gs_book_group {
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);

  .gs-book-sorting-wrap {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 32px;

    .gs-book-sort--sort-area,
    .gs-book-sort--docs-area {
      min-width: 0;
    }
  }
}

// Filters, Single Book Info and Book Icons: the list fills the row, the cards keep a fixed width.
.gs-plugins--sort-layout--gs_book_filters,
.gs-plugins--sort-layout--gs_book_fields_visibility,
.gs-plugins--sort-layout--gs_book_icons {
  grid-template-columns: minmax(0, 1fr) 360px;

  > .gs-plugins--sort-content {
    min-width: 0;
  }

  .gs-book-sort--sort-area.gs-book-sort--narrow,
  .gs-book-sort--sort-area {
    flex: 1 1 auto;
  }
}

.gs-plugins--sort-layout--gs_book_filters,
.gs-plugins--sort-layout--gs_book_fields_visibility {
  max-width: 1240px;
}

// Book Icons: two tables side by side.
.gsbks-icon-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;

  .gsbks-icon-table + .gsbks-icon-table,
  > table:nth-child(2) {
    border-left: 1px solid #e3e6f0;
  }

  @media (max-width: 1400px) {
    grid-template-columns: minmax(0, 1fr);

    > table:nth-child(2) {
      border-left: 0;
      border-top: 1px solid #e3e6f0;
    }
  }
}

@media (max-width: 1100px) {
  .gs-plugins--sort-layout--gs_book_group,
  .gs-plugins--sort-layout--gs_book_filters,
  .gs-plugins--sort-layout--gs_book_fields_visibility,
  .gs-plugins--sort-layout--gs_book_icons {
    grid-template-columns: minmax(0, 1fr);
  }
}


// Book Filters: icon before each name and a Search / Filter badge on the right.
.gs-book-sort-list > li {
  .gs-filter-icon {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(100, 114, 239, 0.1);
    color: #6472ef;
    font-size: 14px;
    line-height: 1;
  }

  .gs-filter-type {
    flex: none;
    margin-left: auto;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .3px;
    text-transform: uppercase;
  }

  .gs-filter-type--search {
    background: #e8f7f2;
    color: #0f766e;
  }

  .gs-filter-type--filter {
    background: #f1f2fb;
    color: #5b63c7;
  }
}


// Single Book Info: icon before each field name.
.table-visibility .gs-field-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-right: 2px;
  border-radius: 7px;
  background: rgba(100, 114, 239, 0.1);
  color: #6472ef;
  font-size: 13px;
  line-height: 1;
}

.table-visibility .sortable-icon-title {
  gap: 10px;
}
