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

// Every independent row grid reserves the same space for all five actions.
// An auto track would size itself from each row's buttons (and the empty head).
$actions-width: 5 * 32px + 4 * 4px;
// Share the remaining space proportionally instead of giving it all to title.
$columns-tail: minmax(0, 2fr) minmax(160px, 1.6fr) minmax(96px, 1fr)
  minmax(88px, 1fr) minmax(108px, 1.1fr) $actions-width;
$columns: 18px $columns-tail;

@include m.scoped {
  .list {
    container-type: inline-size;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: t.$space-6;
  }

  .head {
    display: grid;
    grid-template-columns: $columns;
    gap: t.$space-7;
    padding: 0 t.$space-10;
    border: 1px solid transparent;
    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: $columns;
    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;
    cursor: pointer;
    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;
    }

    &:focus-visible {
      @include m.focus-ring-raised;
    }
  }

  // An unlisted event stays readable but recedes, as in the reference.
  .muted {
    opacity: 0.72;
  }

  // Reference: .row.is-picked — a brand wash, no border change.
  .picked {
    background: rgba(100, 54, 201, 0.06);
  }

  // The checkbox cell swallows the click so picking a row does not open it.
  .pick {
    display: flex;
    align-items: center;
  }

  // A list without selection drops the column rather than leaving a gap.
  .noPick {
    grid-template-columns: $columns-tail;
  }

  .event {
    display: flex;
    align-items: center;
    gap: t.$space-7;
    min-width: 0;
  }

  .eventText {
    min-width: 0;
  }

  .mark {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border: 1px solid t.$border;
    border-radius: 13px;
    background: t.$surface;
    box-shadow: t.$shadow-raised-sm;

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

  .markOffline {
    color: t.$primary;
  }

  .markOnline {
    color: t.$info;
  }

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

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

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

  .time {
    @include m.truncate;
    @include m.text(12, t.$weight-medium);
    color: t.$text-soft;
  }

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

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

  .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);
  }

  .statusLive {
    border-color: t.$success-border;
    background: t.$success-surface;
    color: t.$success-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);
  }

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

  .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 {
      background: t.$hover-surface;
      border-color: t.$hover-border;
      color: t.$primary;
    }
  }

  .actionDanger:hover {
    color: t.$danger-text;
    background: t.$danger-surface;
  }

  .count {
    padding: 0 t.$space-10;
    @include m.text(13, t.$weight-medium);
    color: t.$text-soft;
  }

  .cellLabel {
    display: none;
  }

  // Switch according to the available list width, including WordPress sidebar.
  @container (max-width: 1050px) {
    .head { display: none; }
    .row, .row.noPick {
      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, .event, .schedule, .visibility {
      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, .venue, .time {
      white-space: normal;
      overflow-wrap: anywhere;
    }
    .date, .status { max-width: 100%; height: auto; min-height: 26px; overflow-wrap: anywhere; }
  }

  @container (max-width: 480px) {
    .row, .row.noPick {
      grid-template-columns: minmax(0, 1fr);
      padding: 16px;
    }
  }
  .compactVisibility, .compactRecurrence { display: none; }

  // Tablet/laptop viewport: retain a compact table within the WordPress shell.
  @media (min-width: 1024px) and (max-width: 1280px) {
    @container (min-width: 600px) {
      .head, .head.noPick, .row, .row.noPick {
        grid-template-columns: 18px minmax(0, 2fr) minmax(150px, 1.6fr) minmax(0, 1.5fr) $actions-width;
        gap: t.$space-7;
        align-items: center;
      }
      .head.noPick, .row.noPick {
        grid-template-columns: minmax(0, 2fr) minmax(150px, 1.6fr) minmax(0, 1.5fr) $actions-width;
      }
      .head { display: grid; }
      .row, .row.noPick { padding: t.$space-9 t.$space-10; }
      .pick, .event, .schedule, .actions { grid-column: auto; }
      .cellLabel, .recurrence, .visibility { display: none; }
      .compactVisibility { display: block; margin-top: 6px; }
      .compactRecurrence { display: inline; }
      .format { overflow-wrap: anywhere; }
      .title, .venue { white-space: nowrap; }
      .actions {
        justify-content: flex-end;
        border-top: 0;
        padding-top: 0;
        gap: t.$space-2;
      }
      .action { flex-basis: 32px; width: 32px; height: 32px; }
    }
  }

}
