// Deck lays out core's own components (DiscussionList, NotificationList,
// PostList, Button, Bubble, Dropdown) and nothing else. Colours, type and
// spacing come from core's variables, so a theme that styles those components
// styles Deck too. The narrow-column overrides mirror .DiscussionListPane,
// which already shows DiscussionListItems at --pane-width.
//
// Up to two rows of columns share the height; within a row, columns share
// the width in proportion to their widths, and scroll sideways once they're
// wider than the screen.

// The page is core's PageStructure in its vertical form (as the Tags and
// Messages pages use), so the forum's side nav runs across the top. Below it,
// the deck fills the rest of the screen.
// Core keeps room at the bottom of every page for a minimised composer. The
// deck runs to the bottom of the screen instead, and only makes that room
// while a composer is open, so a draft never covers the bottom of the columns.
.App.App--deck {
  --deck-bottom-gap: 0px;
  padding-bottom: var(--deck-bottom-gap);

  &:has(.Composer.visible) {
    --deck-bottom-gap: var(--app-bottom-padding);
  }
}

// Full screen: just the deck. The forum's header and nav go, and the deck
// takes the whole height; the toolbar stays, with the way back.
.App.App--deckFullscreen {
  padding-top: 0;

  #header, #app-navigation, .DeckPage .Page-container, .DeckPageHero {
    display: none;
  }

  .DeckPage {
    height: calc(~"100vh - var(--deck-bottom-gap, 0px)");
    height: calc(~"100dvh - var(--deck-bottom-gap, 0px)");
  }
}

.DeckPage {
  --deck-edge-fade: 40px;

  display: flex;
  flex-direction: column;
  // The page itself never scrolls; columns do.
  height: calc(~"100vh - var(--header-height) - var(--deck-bottom-gap, 0px)");
  height: calc(~"100dvh - var(--header-height) - var(--deck-bottom-gap, 0px)");
  padding-bottom: 0;

  @media @phone {
    height: calc(~"100vh - var(--header-height-phone) - var(--deck-bottom-gap, 0px)");
    height: calc(~"100dvh - var(--header-height-phone) - var(--deck-bottom-gap, 0px)");
  }

  .Page-main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  // Core's centred container, holding only the side nav (DeckPageStructure
  // moves the deck out of it), so the nav lines up as on any other page.
  .Page-container {
    flex: none;
  }

  @media @desktop-up {
    .Page-sidebar {
      margin-top: 15px;
    }
  }
}

// Full width with the container's 15px gutter: the container itself caps out
// at 1200-1500px, about three columns.
.DeckPage-deck {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 15px;
}

.DeckPage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--control-bg);
}

.DeckPage-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
  font-size: 18px;
  color: var(--heading-color);
}

.DeckPage-actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.DeckPage-empty {
  padding: 60px 15px;
  text-align: center;
  color: var(--muted-color);
}

// Column chips: the switcher on phones.
.DeckPage-tabs {
  display: flex;
  gap: 6px;
  padding: 8px 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--control-bg);
  scrollbar-width: none;

  &::-webkit-scrollbar {
    display: none;
  }
}

.DeckPage-tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.DeckPage-tabCount {
  position: static;
}

.DeckPage-tab--ghost {
  opacity: 0.4;
}

.Deck {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.DeckRow {
  position: relative;
  // Its share of the height, from the divider between the rows.
  flex: var(--deck-row-grow, 1) 1 0;
  min-height: 0;
  display: flex;

  & + & {
    border-top: 1px solid var(--control-bg);
  }

  // An unused second row takes no room, until a column is being dragged and
  // it becomes somewhere to drop one.
  &--empty {
    flex: 0 0 0;
    overflow: hidden;

    & + .DeckRow, .DeckRow + & {
      border-top: 0;
    }
  }

  // Fades over whichever edge has more columns past it. Physical on purpose:
  // DeckRow sets --moreLeft/--moreRight from scrollLeft, which is physical
  // too, and a gradient has no inline-start/end form. Both go together when
  // the row's scrolling is made direction-aware.
  &::before, &::after {
    content: "";
    position: absolute;
    z-index: 2;
    top: 0;
    bottom: 0;
    width: var(--deck-edge-fade);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
  }
  &::before {
    left: 0;
    background: linear-gradient(to right, var(--body-bg), transparent);
  }
  &::after {
    right: 0;
    background: linear-gradient(to left, var(--body-bg), transparent);
  }
  &--moreLeft::before, &--moreRight::after {
    opacity: 1;
  }
}

.DeckRow-columns {
  flex: 1;
  min-width: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  border-inline-start: 1px solid var(--control-bg);
  scroll-snap-type: x proximity;
}

// For mouse users, who can't swipe sideways; touch and trackpad scroll as usual.
.DeckRow-scroll {
  position: absolute;
  z-index: 3;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  background: var(--body-bg);
  box-shadow: 0 2px 6px var(--shadow-color);

  &--left {
    left: 6px;
  }
  &--right {
    right: 6px;
  }
}

@media (hover: hover) {
  .DeckRow--moreLeft:hover .DeckRow-scroll--left, .DeckRow--moreRight:hover .DeckRow-scroll--right {
    display: inline-flex;
  }
}

.DeckRow-dropHint {
  // Not a drop target itself, so the row underneath gets the drag.
  pointer-events: none;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px;
  border: 2px dashed var(--control-bg);
  border-radius: var(--border-radius);
  color: var(--muted-color);
}

.Deck--dragging .DeckRow--empty {
  flex: 0 0 140px;
  border-top: 1px solid var(--control-bg);
}

.DeckColumn {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  // At least its width, and a share of any spare room in proportion to it, so
  // the columns fill the row; once they don't fit, exactly its width, and the
  // row scrolls.
  flex: var(--deck-column-grow, 280) 0 var(--deck-column-width, 280px);
  border-inline-end: 1px solid var(--control-bg);
  background: var(--body-bg);
  scroll-snap-align: start;

  &--resizing {
    user-select: none;
  }

  &--ghost {
    opacity: 0.4;
  }
  &--chosen {
    box-shadow: 0 2px 10px var(--shadow-color);
  }
}

.DeckColumn-handle {
  flex: none;
  margin-inline-start: -8px;
  padding: 6px 4px;
  color: var(--muted-more-color);
  cursor: grab;
  // Lets Sortable take the gesture on touch screens instead of the row scrolling.
  touch-action: none;

  &:hover {
    color: var(--muted-color);
  }
}

// Mirrors HeaderList's header, the closest thing core has to a column title.
.DeckColumn-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding-block: 4px;
  padding-inline: 15px 6px;
  border-bottom: 1px solid var(--control-bg);
}

.DeckColumn-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--muted-color);
}

.DeckColumn-titleText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.DeckColumn-controls {
  flex: none;
}

// Sits on the column's top edge without pushing the list down, so nothing
// moves until the member asks for the new items.
.DeckColumn-new {
  position: relative;
  z-index: 2;
  height: 0;
  display: flex;
  justify-content: center;
}

.DeckColumn-newButton {
  margin-top: 10px;
  box-shadow: 0 2px 6px var(--shadow-color);
}

.DeckColumn-body {
  // Deck keeps the reader's place itself when items arrive at the top.
  overflow-anchor: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 15px;
}

.DeckColumn-open {
  display: block;
  margin: 10px 15px;
  width: auto;
}

.DeckColumn {
  .DiscussionList {
    margin: 0;
  }

  .DiscussionList-loadMore, .PostList-loadMore {
    padding: 0 15px;
  }

  .PostList {
    padding: 10px 15px 0;
  }

  // The column header replaces NotificationList's own, whose controls core
  // moves into the app header on phones.
  .HeaderList-header {
    display: none;
  }
}

// HeaderList loads more when its own content scrolls, so it gets the column's
// height instead of the column body scrolling around it.
.DeckColumn--notifications {
  .DeckColumn-body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 0;
  }

  .HeaderList {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .HeaderList-content {
    flex: 1;
    min-height: 0;
    overflow: auto;
  }
}

.DeckColumn-badge {
  .Badge--size(20px);
  flex: none;
}

// Typing activity column.
.DeckTyping {
  margin: 0;
  padding: 0;
  list-style: none;
}

.DeckTyping-item {
  display: flex;
  gap: 10px;
  padding: 10px 15px;
  border-bottom: 1px solid var(--control-bg);
  color: var(--muted-color);

  &--active {
    color: var(--text-color);

    .DeckTyping-icon {
      color: var(--primary-color);
      animation: DeckTyping-pulse 1.2s ease-in-out infinite;
    }
  }
}

.DeckTyping-icon {
  margin-top: 3px;
}

.DeckTyping-time {
  display: block;
  font-size: 12px;
  color: var(--muted-more-color);
}

@keyframes DeckTyping-pulse {
  50% {
    opacity: 0.4;
  }
}

@media (prefers-reduced-motion: reduce) {
  .DeckTyping-item--active .DeckTyping-icon {
    animation: none;
  }
}

@media @tablet-up {
  .DeckColumn {
    .DiscussionListItem {
      margin: 0;
      padding: 0;
      border-radius: 0;
    }
    .DiscussionListItem-content {
      padding-inline: 16px 28px;
    }
    .DiscussionListItem-title {
      font-size: 14px;
    }
    .DiscussionListItem-stats {
      top: 12px;
      right: 12px;
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .DiscussionListItem-info {
      overflow: hidden;
      text-overflow: ellipsis;

      .item-excerpt {
        margin-right: 0;
      }
    }
  }
}

.DeckPage--flat .DeckColumn-menu {
  // Both rows share one strip here, so moving between them would look like nothing happened.
  .item-moveRow {
    display: none;
  }
}

@media @phone {
  .DeckPage-toolbar {
    padding: 8px 0;
  }

  .DeckPage-title {
    font-size: 16px;
  }

  // Icon-only, so the title keeps its room: core's round icon button, which
  // also drops the gap the icon keeps beside a label.
  .DeckPage-action {
    .Button--icon();
  }

  // Full bleed: the page gutter would clip chips and columns mid-swipe.
  .DeckPage-tabs, .Deck {
    margin: 0 -15px;
  }
  .DeckPage-tabs {
    padding: 8px 15px;
  }

  .DeckRow-columns {
    border-inline-start: 0;
    scroll-snap-type: x mandatory;
  }

  // One column per screen; swiping replaces the fades and scroll buttons.
  .DeckRow::before, .DeckRow::after, .DeckRow-scroll {
    display: none !important;
  }

  .DeckColumn {
    flex: none;
    width: 100%;
    min-width: 0;
    border-inline-end: 0;
    scroll-snap-stop: always;
  }

  // Columns are reordered by dragging the chips on phones, and fill the screen.
  .DeckColumn-handle, .DeckColumn-resize {
    display: none;
  }

  // Widths and rows only mean something side by side.
  .DeckColumn-menu {
    .item-resetWidth, .item-separator3, .item-moveRow {
      display: none;
    }
  }
}

// "In your deck", on a column type and on a picker result.
.AddColumnModal-added, .DeckPickerModal-added {
  margin-inline-start: 8px;
  font-size: 12px;
  font-weight: normal;
  color: var(--muted-color);
  white-space: nowrap;
}

.DeckPickerModal-result--added > a {
  display: flex;
  align-items: center;

  .DeckPickerModal-added {
    margin-inline-start: auto;
  }
}

// A search field: shows the choice, opens the picker.
.AddColumnModal-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: start;
  cursor: pointer;

  .Avatar {
    --size: 24px;
  }
}

.AddColumnModal-pickValue {
  flex-grow: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.AddColumnModal-pickPlaceholder {
  color: var(--muted-color);
}

// A column's edge, which resizes it. It stays inside the column: anything
// past the last column's edge would make the row scroll.
.DeckColumn-resize {
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  inset-inline-end: 0;
  width: 6px;
  cursor: col-resize;
  touch-action: none;

  &::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    inset-inline-end: 0;
    width: 2px;
  }

  &:hover::after, &:focus-visible::after, .DeckColumn--resizing > &::after {
    background: var(--primary-color);
  }

  &:focus-visible {
    outline: none;
  }
}

// Between the two rows, sharing the height between them.
.DeckRowSplit {
  position: relative;
  flex: none;
  height: 7px;
  margin: -3px 0;
  z-index: 3;
  cursor: row-resize;
  touch-action: none;

  &::after {
    content: "";
    position: absolute;
    inset-inline: 0;
    top: 3px;
    height: 1px;
    background: var(--control-bg);
  }

  &:hover::after, &:focus-visible::after, &--dragging::after {
    top: 2px;
    height: 3px;
    background: var(--primary-color);
  }

  &:focus-visible {
    outline: none;
  }
}


// Writing a column's filters in the search modal.
.DeckFilterModal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 15px;
  text-align: start;
}

.DeckFilterModal-error {
  margin: 0;
  margin-inline-end: auto;
}
