@use 'apps/dashboard/src/variables' as *;

// ── Page layout override ──────────────────────────────────────────────────
//
// Strategy: let <main> (the app scroll container) scroll naturally through the
// page header → toolbar → stat cards.  Once the table reaches the top of <main>
// it becomes sticky there, and the CDK virtual-scroll viewport handles row
// scrolling internally.  This avoids a locked viewport while still giving the
// table the full remaining height once it is pinned.

.page-spacing {
  height: auto;
  min-height: unset;
  overflow: visible;
  display: flex;
  flex-direction: column;
  padding-bottom: rhythm(2);
}

// ── Page header ───────────────────────────────────────────────────────────

.page-header {
  margin-bottom: rhythm(4);
}

// ── Toolbar ───────────────────────────────────────────────────────────────

.activity-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: rhythm(2);
  margin-bottom: rhythm(4);

  .month-picker {
    width: rhythm(18);
  }

  .toolbar-search {
    flex: 1;
    min-width: rhythm(24);
    max-width: rhythm(36);
  }

  .toolbar-actions {
    display: flex;
    align-items: center;
    gap: rhythm(2);

    pa-dropdown {
      position: absolute;
    }
  }
}

// ── Stat cards (projected from page components) ───────────────────────────

:host ::ng-deep {
  .stat-cards {
    display: flex;
    gap: rhythm(2);
    flex-wrap: wrap;
    margin-bottom: rhythm(4);
  }

  .stat-card {
    flex: 1;
    min-width: rhythm(20);
    padding: rhythm(2.5);
    border: 1px solid $color-neutral-lighter;
    border-radius: rhythm(1);

    .title-xxs {
      text-transform: uppercase;
      color: $color-neutral-regular;
      margin-bottom: rhythm(0.5);
    }

    .display-s {
      margin-bottom: rhythm(0.5);
    }
  }

  .stat-card--active {
    border-color: var(--color-primary-regular);
  }

  .stat-card-footer {
    display: flex;
    align-items: center;
    gap: rhythm(0.75);
  }

  .stat-card-view-all {
    font-size: font-size(xs);
    line-height: rhythm(3);
    color: var(--color-primary-regular);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;

    &:hover {
      color: var(--color-primary-strong);
      text-decoration: underline;
    }
  }

  .stat-card-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: rhythm(2);
    height: rhythm(2);
    border-radius: 50%;
    border: 1px solid $color-neutral-lighter;
    background: none;
    padding: 0;
    cursor: pointer;
    font-size: font-size(xxs);
    line-height: 1;
    color: $color-neutral-regular;
    transition:
      background 0.15s,
      color 0.15s;

    &:hover {
      background: $color-neutral-lighter;
      color: $color-neutral-regular;
    }
  }
}

// ── Table ─────────────────────────────────────────────────────────────────

.table-container {
  // Stick at the top of the <main> scroll container once the above-table
  // content has scrolled out of view.
  position: sticky;
  top: 0;
  height: calc(100vh - var(--app-topbar-height) - rhythm(4));
  flex: none;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-top: rhythm(1);

  nsi-spinner {
    display: block;
    margin: rhythm(4) auto;
  }
}

.table-viewport {
  flex: 1;
  height: 100%;
  min-height: 200px;
  width: 100%;
  overflow: auto;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: rhythm(20);
  color: $color-neutral-light;
}

.clickable-row {
  cursor: pointer;

  &:hover ::ng-deep .pa-table-grid--cell {
    background-color: var(--color-neutral-lightest);
  }
}

pa-table {
  display: block;
  width: 100%;

  // Keep sticky headers in correct position with virtual scroll
  ::ng-deep .pa-table-grid--header {
    top: var(--table-header-top);
  }

  ::ng-deep .pa-table-grid--cell {
    height: var(--table-row-height);
  }
}

.cell-value {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remi-score-low {
  color: var(--color-danger-regular) !important;
  font-weight: 600;
}

.remi-score-mid {
  color: var(--color-secondary-regular) !important;
  font-weight: 600;
}

.remi-score-high {
  color: var(--color-success-regular) !important;
  font-weight: 600;
}

// ── Side panel overlay ────────────────────────────────────────────────────

.side-panel-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
}

.side-panel {
  position: fixed;
  top: var(--app-topbar-height, 0);
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 90vw;
  background: var(--color-neutral-lightest, #fff);
  border-left: 1px solid $color-neutral-lighter;
  z-index: 101;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
  transition: width 0.2s ease;

  &.expanded {
    width: 65vw;
  }
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: rhythm(2) rhythm(3);
  border-bottom: 1px solid $color-neutral-lighter;
  position: sticky;
  top: 0;
  background: inherit;
  z-index: 1;
}

.side-panel-header-actions {
  display: flex;
  align-items: center;
  gap: rhythm(0.5);
}

.side-panel-body {
  padding: rhythm(2);
  flex: 1;
  overflow-y: auto;
}

// ── Section titles ────────────────────────────────────────────────────────

.section-title {
  margin-bottom: rhythm(1.5);
  color: var(--color-neutral-dark);
}

.detail-section {
  margin-bottom: rhythm(3);
}

// ── Card-like containers (grey background boxes for grouping) ─────────────

.detail-card {
  background: $color-neutral-lightest;
  border: 1px solid $color-neutral-lighter;
  border-radius: rhythm(1);
  padding: rhythm(1.5);
}

// ── Inner cards for large text fields (Question, Answer) ──────────────────

.detail-inner-card {
  background: white;
  border: 1px solid $color-neutral-lighter;
  border-radius: rhythm(0.75);
  padding: 0;
  margin: rhythm(0.75) 0;

  pa-expander {
    ::ng-deep .pa-expander-header {
      padding: rhythm(1) rhythm(1.5);
    }

    ::ng-deep .pa-expander:not(.pa-expander-card).pa-collapsed .pa-expander-header {
      box-shadow: none;
    }
  }

  .detail-inner-label {
    font-size: font-size(xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: $color-neutral-regular;
    font-weight: 600;
  }

  .detail-expandable-content {
    padding: rhythm(1) rhythm(2) rhythm(2) rhythm(2);
    word-break: break-word;
    white-space: pre-wrap;
  }
}

// ── Standard key-value rows ───────────────────────────────────────────────

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: rhythm(0.75) 0;
  gap: rhythm(2);

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

  &:not(:last-child) {
    border-bottom: 1px solid rgba($color-neutral-lighter, 0.5);
  }

  .detail-label {
    color: $color-neutral-regular;
    flex-shrink: 0;
    min-width: 100px;
  }

  .detail-value {
    text-align: right;
    word-break: break-word;
    color: var(--color-neutral-dark);
  }
}

// ── Row action column ─────────────────────────────────────────────────────

.action-col-header,
.action-col-cell {
  width: 48px;
  min-width: 48px;
  text-align: center;
}

.inline-action-btn {
  opacity: 0;
}

.clickable-row:hover .inline-action-btn {
  opacity: 1;
}

// ── Inline action (rendered inside a cell, e.g. remiScore column) ─────────

.cell-inline-action-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 4px;
}
