/* Board: columns side by side, each a header over a scrolling list of cards. While a card is
   dragged, a copy follows the pointer (board-ghost), the card leaves its column, which closes up,
   and a line (board-drop) shows where it will land, the cards beside it parting a little
   (runeui--board writes their transforms; they glide 250ms on the ease-out and retarget). */

@layer runeui.components {
  [data-slot="board"] {
    --ui-board-column-width: 18rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scroll-snap-type: x proximity;
  }

  [data-slot="board"][data-dragging] { scroll-snap-type: none; cursor: grabbing; user-select: none; }

  [data-slot="board-column"] {
    display: flex;
    flex: 0 0 var(--ui-board-column-width);
    flex-direction: column;
    gap: 0.5rem;
    max-height: var(--ui-board-height, 70dvh);
    padding: 0.5rem;
    border: 1px solid transparent;
    border-radius: var(--ui-radius-xl);
    background: color-mix(in oklab, var(--muted) 60%, transparent);
    scroll-snap-align: start;
    transition: border-color var(--ui-duration), background-color var(--ui-duration);
  }

  [data-slot="board-column"][data-drop] { border-color: var(--ring); background: var(--muted); }

  [data-slot="board-column-header"] { display: flex; align-items: center; gap: 0.5rem; min-height: var(--ui-h-sm); padding: 0 0.25rem 0 0.5rem; }
  [data-slot="board-column-title"] { margin: 0; overflow: hidden; font-size: var(--ui-text-sm); font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
  [data-slot="board-column-count"] { color: var(--muted-foreground); font-size: var(--ui-text-xs); font-variant-numeric: tabular-nums; }
  [data-slot="board-column-count"]:empty { display: none; }
  [data-slot="board-column-action"] { display: flex; margin-inline-start: auto; }

  /* A collapsible column's title is its toggle. */
  [data-slot="board-column-toggle"] {
    max-width: 100%;
    margin: 0 -0.375rem;
    padding: 0.125rem 0.375rem;
    overflow: hidden;
    border: 0;
    border-radius: var(--ui-radius-md);
    background: none;
    color: inherit;
    font: inherit;
    text-align: start;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    outline: none;
  }
  @media (hover: hover) and (pointer: fine) {
    [data-slot="board-column-toggle"]:hover { background: var(--accent); color: var(--accent-foreground); }
  }
  [data-slot="board-column-toggle"]:focus-visible { box-shadow: var(--ui-focus-ring); }

  /* Folded: a narrow strip the board's height, its dot, count and title running down it; a click
     anywhere on it opens it. */
  [data-slot="board-column"][data-collapsed] { position: relative; flex-basis: 2.75rem; align-self: stretch; padding: 0.5rem 0; cursor: pointer; }
  [data-slot="board-column"][data-collapsed]:hover { background: var(--muted); }
  [data-slot="board-column"][data-collapsed] [data-slot="board-column-header"] { flex-direction: column; padding: 0.25rem 0; }
  [data-slot="board-column"][data-collapsed] [data-slot="board-column-title"] { order: 2; max-height: 60dvh; writing-mode: vertical-rl; }
  [data-slot="board-column"][data-collapsed] [data-slot="board-column-count"] { order: 1; }
  [data-slot="board-column"][data-collapsed] [data-slot="board-column-toggle"] { margin: -0.375rem 0; padding: 0.375rem 0.125rem; }
  [data-slot="board-column"][data-collapsed] [data-slot="board-column-toggle"]::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
  [data-slot="board-column"][data-collapsed] [data-slot="board-column-toggle"]:hover { background: none; color: inherit; }
  [data-slot="board-column"][data-collapsed] :is([data-slot="board-list"], [data-slot="board-empty"], [data-slot="board-column-footer"], [data-slot="board-column-action"]) { display: none; }

  [data-slot="board-column-dot"] { flex-shrink: 0; width: 0.5rem; height: 0.5rem; border-radius: var(--ui-radius-full); background: var(--muted-foreground); }
  [data-slot="board-column"][data-tone="success"] [data-slot="board-column-dot"] { background: var(--success); }
  [data-slot="board-column"][data-tone="warning"] [data-slot="board-column-dot"] { background: var(--warning); }
  [data-slot="board-column"][data-tone="info"] [data-slot="board-column-dot"] { background: var(--info); }
  [data-slot="board-column"][data-tone="destructive"] [data-slot="board-column-dot"] { background: var(--destructive); }

  [data-slot="board-list"] {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0.5rem;
    margin: 0;
    overflow-y: auto;
    /* Room for the cards' focus rings, which the scroll container would clip. */
    padding: 3px;
    list-style: none;
    overscroll-behavior: contain;
  }

  /* Shown while the column has no card; the list stays, as somewhere to drop. */
  [data-slot="board-empty"] { display: none; margin: 0; padding: 0.75rem 0.5rem 1rem; color: var(--muted-foreground); font-size: var(--ui-text-sm); text-align: center; }
  [data-slot="board-column"]:is([data-empty], :not(:has([data-slot="board-card"]))):not([data-drop], [data-collapsed]) [data-slot="board-empty"] { display: block; }
  [data-slot="board-column-footer"] { display: flex; flex-direction: column; }

  /* The list's last item when more cards are still to load (a link to the next page). */
  [data-slot="board-more"] { flex-shrink: 0; padding: 0.25rem; color: var(--muted-foreground); font-size: var(--ui-text-xs); text-align: center; list-style: none; }

  [data-slot="board-card"], [data-slot="board-ghost"], [data-slot="board-flight"] {
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    gap: 0.375rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--ui-radius-lg);
    background: var(--card);
    color: var(--card-foreground);
    font-size: var(--ui-text-sm);
    list-style: none;
    box-shadow: var(--ui-shadow-xs);
  }

  [data-slot="board-card"] {
    outline: none;
    cursor: grab;
    user-select: none;
    -webkit-touch-callout: none;
    transition: box-shadow var(--ui-duration), border-color var(--ui-duration), opacity var(--ui-duration), transform var(--ui-duration-move) var(--ui-ease-out);
  }

  @media (hover: hover) and (pointer: fine) {
    [data-slot="board-card"]:hover { border-color: color-mix(in oklab, var(--ring) 60%, var(--border)); }
  }
  [data-slot="board-card"]:focus-visible { border-color: var(--ring); box-shadow: var(--ui-focus-ring); }
  [data-slot="board-card"][data-dragging] { display: none; }
  /* Its copy is still flying into the slot. */
  [data-slot="board-card"][data-landing] { visibility: hidden; }
  [data-slot="board-card"][aria-busy="true"] { cursor: progress; }
  [data-slot="board"][data-dragging] [data-slot="board-card"] { cursor: grabbing; }

  [data-slot="board-card-title"] { color: inherit; font-weight: 500; line-height: 1.35; text-decoration: none; -webkit-user-drag: none; }
  a[data-slot="board-card-title"]:hover { text-decoration: underline; text-underline-offset: 3px; }
  [data-slot="board-card-meta"] { color: var(--muted-foreground); font-size: var(--ui-text-xs); }
  [data-slot="board-card-body"] { color: var(--muted-foreground); }
  [data-slot="board-card-footer"] { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; margin-top: 0.25rem; }

  /* The copy that follows the pointer, and (board-flight) the one gliding into the slot on a drop. */
  [data-slot="board-ghost"], [data-slot="board-flight"] {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 200;
    margin: 0;
    rotate: 2deg;
    border-color: color-mix(in oklab, var(--ring) 70%, var(--border));
    box-shadow: var(--ui-shadow-lg);
    pointer-events: none;
    cursor: grabbing;
  }

  /* Where the card will land. */
  [data-slot="board-drop"] {
    flex-shrink: 0;
    height: 2px;
    margin: -1px 0.25rem;
    border-radius: var(--ui-radius-full);
    background: var(--primary);
    list-style: none;
  }

  @media (forced-colors: active) {
    [data-slot="board-ghost"] { border-color: Highlight; outline: 2px solid Highlight; }
    [data-slot="board-drop"] { background: Highlight; }
  }

  @media (max-width: 767px) {
    [data-slot="board"] { --ui-board-column-width: min(18rem, 82vw); }
  }
}
