@use "../../../styles/tokens" as t;
@use "../../../styles/mixins" as m;

// The events list's "floating rows" (option A), carrying bookings instead of
// events. Which columns show is a per-browser preference, so the grid template
// arrives as an inline style and only the chrome lives here.
@include m.scoped {
  .list {
    container-type: inline-size;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: t.$space-6;
  }

  // The template rides in on a custom property rather than an inline
  // grid-template-columns, so the narrow layout below can still override it
  // without !important.
  .head {
    display: grid;
    grid-template-columns: var(--booking-cols);
    gap: t.$space-7;
    // The rows below have a 1px border; without the same inset here their
    // flexible columns resolve 2px narrower and every heading sits a pixel off.
    border: 1px solid transparent;
    padding: 0 t.$space-10;
    color: t.$text-placeholder;
    @include m.eyebrow;
    letter-spacing: t.$tracking-wide;
  }

  .row {
    min-width: 0;
    > div { min-width: 0; }
    display: grid;
    grid-template-columns: var(--booking-cols);
    gap: t.$space-7;
    align-items: center;
    width: 100%;
    padding: t.$space-9 t.$space-10;
    border: 1px solid t.$border;
    border-radius: t.$radius-2xl;
    background: t.$surface;
    box-shadow: 8px 8px 20px t.$shade, -4px -4px 12px t.$light;
    text-align: left;
    transition: background-color t.$duration t.$ease, color t.$duration-fast t.$ease, border-color t.$duration-fast t.$ease;

    &:hover {
      background-color: t.$hover-surface;
      border-color: t.$hover-border;
    }
  }

  // A cancelled booking stays readable but recedes.
  .muted {
    opacity: 0.72;
  }

  .picked {
    background: rgba(100, 54, 201, 0.06);
  }

  .pick {
    display: flex;
    align-items: center;
  }

  // --- Cells ----------------------------------------------------------------

  .strong {
    @include m.truncate;
    @include m.text(13, t.$weight-bold);
    color: t.$text;
  }

  .title {
    @include m.truncate;
    @include m.text(14, t.$weight-bold);
    letter-spacing: -0.01em;
  }

  .text {
    @include m.truncate;
    @include m.text(13, t.$weight-medium);
    color: t.$text-secondary;
  }

  .sub {
    @include m.truncate;
    margin-top: t.$space-1;
    @include m.text(12, t.$weight-medium);
    color: t.$text-soft;
  }

  .money {
    @include m.text(13, t.$weight-bold);
    color: t.$text;
  }

  .free {
    @include m.text(13, t.$weight-semibold);
    color: t.$text-soft;
  }

  .status {
    display: inline-flex;
    align-items: center;
    gap: t.$space-3;
    height: 26px;
    padding: 0 11px;
    border: 1px solid t.$border;
    border-radius: t.$radius-pill;
    background: t.$surface;
    color: t.$text-strong;
    box-shadow: t.$shadow-raised-sm;
    @include m.text(12, t.$weight-bold);
  }

  .statusActive {
    border-color: t.$success-border;
    background: t.$success-surface;
    color: t.$success-text;
  }

  .statusRefunded {
    border-color: t.$warning-border;
    background: t.$warning-surface;
    color: t.$warning-text;
  }

  .statusCanceled {
    border-color: t.$danger-border;
    background: t.$danger-surface;
    color: t.$danger-text;
  }

  .dot {
    width: 7px;
    height: 7px;
    flex: 0 0 7px;
    border-radius: t.$radius-pill;
    background: t.$text-placeholder;
    box-shadow: 0 0 0 3px rgba(142, 151, 171, 0.15);
  }

  .dotActive {
    background: t.$success;
    box-shadow: 0 0 0 3px rgba(23, 178, 106, 0.15);
  }

  .dotRefunded {
    background: t.$warning;
    box-shadow: 0 0 0 3px rgba(247, 144, 9, 0.15);
  }

  .dotCanceled {
    background: t.$danger;
    box-shadow: 0 0 0 3px rgba(240, 68, 56, 0.15);
  }

  // --- Actions --------------------------------------------------------------

  .actions {
    flex-wrap: wrap;
    display: flex;
    justify-content: flex-end;
    gap: t.$space-2;
  }

  .action {
    @include m.button-reset;
    @include m.wp-reset-button;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    border-radius: t.$radius-sm;
    color: t.$text-soft;
    transition: background t.$duration t.$ease, color t.$duration-fast t.$ease, border-color t.$duration-fast t.$ease;

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

    &:hover:not(:disabled) {
      background: t.$hover-surface;
      border-color: t.$hover-border;
      color: t.$primary;
    }

    &:disabled {
      opacity: 0.4;
      cursor: not-allowed;
    }
  }

  .actionDanger:hover:not(:disabled) {
    color: t.$danger-text;
    background: t.$danger-surface;
  }

  .cellLabel {
    display: none;
  }

  // Switch according to the available list width, including WordPress sidebar.
  @container (max-width: 1050px) {
    .head { display: none; }
    .row {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      align-items: start;
      gap: 16px;
      padding: 18px;
    }
    .cellLabel {
      display: block;
      margin-bottom: 6px;
      @include m.text(11, t.$weight-semibold);
      color: t.$text-placeholder;
    }
    .pick, .actions, .eventCell {
      grid-column: 1 / -1;
    }
    .actions {
      justify-content: flex-start;
      border-top: 1px solid t.$border;
      padding-top: 12px;
      gap: 8px;
    }
    .action { flex-basis: 44px; width: 44px; height: 44px; }
    .title, .strong, .text, .sub {
      white-space: normal;
      overflow-wrap: anywhere;
    }
    .money, .status { max-width: 100%; height: auto; min-height: 26px; overflow-wrap: anywhere; }
  }

  @container (max-width: 480px) {
    .row {
      grid-template-columns: minmax(0, 1fr);
      padding: 16px;
    }
  }
  .payment { display: flex; flex-direction: column; align-items: center; width: max-content; max-width: 100%; gap: 6px; text-align: center; }
  .compactDates, .compactDatesHeading { display: none; }

  @media (min-width: 1024px) and (max-width: 1280px) {
    @container (min-width: 600px) {
      .head, .row {
        grid-template-columns: var(--booking-compact-cols);
        gap: 10px;
        align-items: center;
      }
      .head { display: grid; }
      .row { height: 114px; padding: t.$space-9 t.$space-10; }
      .pick, .actions, .eventCell { grid-column: auto; }
      .cellLabel, .mergedColumn { display: none; }
      .title, .text {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        white-space: normal;
        overflow: hidden;
        overflow-wrap: anywhere;
        text-overflow: ellipsis;
      }
      .title { height: 40px; line-height: 20px; }
      .text { height: 36px; line-height: 18px; }
      .regularDates { display: none; }
      .compactDatesHeading { display: inline; }
      .compactDates { display: flex; flex-direction: column; gap: 8px; height: 76px; }
      .dateLabel { display: block; @include m.text(11, t.$weight-semibold); line-height: 16px; color: t.$text-placeholder; }
      .dateLine { @include m.truncate; @include m.text(12, t.$weight-bold); line-height: 18px; }
      .dateTime { color: t.$text-soft; font-weight: t.$weight-medium; }
      .actions {
        display: grid;
        grid-template-columns: repeat(2, 32px);
        justify-content: end;
        border-top: 0;
        padding-top: 0;
        gap: t.$space-2;
      }
      .action { flex-basis: 32px; width: 32px; height: 32px; }
    }
  }

}
