/* ============================================================
 * NextGen MIS — Comments & Activity (timeline)
 * ------------------------------------------------------------
 * Re-skins the shared comments-activity partial (the .cs-* hooks
 * are wired to JS, so the class NAMES are preserved — only the
 * look is rebuilt on design tokens). Used on the beneficiary +
 * applicant profiles and the registration list popup.
 *
 * Two parts:
 *   1. Composer — a quiet card: tabs (Take action / Comment), an
 *      action picker (pills), and a note/comment textarea.
 *   2. Feed — a vertical TIMELINE: each entry is an avatar node on
 *      a connecting rail, with author, a tonal source badge, time,
 *      and the comment body. System events read muted; user
 *      comments read in brand colour.
 * Authored in px; semantic tokens; legacy cs- hooks kept as-is.
 * ============================================================ */

/* ---------- PANEL + HEADER ---------- */
.cs-panel { margin: 0; }

.cs-panel-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding: 0 0 var(--space-3) 0;
  border-bottom: 1px solid var(--color-border-default);
  font-family: var(--font-family-display);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-lg);
  color: var(--color-text-strong);
  background: none;               /* was a dark #555 bar */
}
.cs-panel-header .cs-count {
  font-family: var(--font-family-data);
  font-weight: var(--font-weight-regular);
  font-size: var(--font-size-sm);
  color: var(--color-text-faint);
}
.cs-panel-body { border: 0; margin: 0; background: none; }

/* ---------- COMPOSER ---------- */
.cs-composer {
  margin-bottom: var(--space-5);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  background: var(--color-bg-raised);
  overflow: hidden;
}

/* Tabs — quiet underline tabs, brand-green active marker. */
.cs-tabs {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3) 0;
  border-bottom: 1px solid var(--color-border-default);
  background: none;
}
.cs-tab {
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-family: var(--font-family-ui);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  cursor: pointer;
  user-select: none;
  transition: color var(--motion-fast) var(--ease-standard),
              border-color var(--motion-fast) var(--ease-standard);
}
.cs-tab:hover { color: var(--color-text-default); }
.cs-tab.cs-active {
  color: var(--color-text-strong);
  font-weight: var(--font-weight-semibold);
  border-bottom-color: var(--color-brand-secondary);
  background: none;
}
.cs-tab.cs-active::after { content: none; }   /* drop the old overlap hack */

.cs-tab-pane { display: none; padding: var(--space-4); }
.cs-tab-pane.cs-active { display: block; }

.cs-label-hint {
  margin-bottom: var(--space-2);
  font-family: var(--font-family-ui);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
}

/* Action picker pills — quiet until selected; note block stays hidden
   until a pill is chosen (see .cs-action-followup). */
.cs-action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.cs-action-pill {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  background: var(--color-bg-surface);
  color: var(--color-text-default);
  font-family: var(--font-family-ui);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-snug);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-standard),
              box-shadow var(--motion-fast) var(--ease-standard),
              background-color var(--motion-fast) var(--ease-standard),
              color var(--motion-fast) var(--ease-standard);
}
.cs-action-pill:hover {
  border-color: var(--color-border-strong);
  background: var(--color-bg-raised);
  color: var(--color-text-strong);
}
.cs-action-pill.cs-selected {
  color: var(--color-text-strong);
  border-color: var(--color-brand-secondary);
  background: var(--color-brand-secondary-soft);
  box-shadow: inset 0 0 0 1px var(--color-brand-secondary);
}
/* Selected border + tint key to the action's dot colour:
   green = approve, orange = request edit, red = archive.
   Tints mix into the surface so they adapt in dark mode. */
.cs-action-pill.cs-selected[data-value="APPROVE"] {
  border-color: var(--color-success-500);
  background: color-mix(in srgb, var(--color-success-500) 14%, var(--color-bg-surface));
  box-shadow: inset 0 0 0 1px var(--color-success-500);
}
.cs-action-pill.cs-selected[data-value="EDIT"] {
  border-color: var(--color-warning-500);
  background: color-mix(in srgb, var(--color-warning-500) 14%, var(--color-bg-surface));
  box-shadow: inset 0 0 0 1px var(--color-warning-500);
}
.cs-action-pill.cs-selected[data-value="ARCHIVE"],
.cs-action-pill.cs-selected[data-value="REJECT"],
.cs-action-pill.cs-selected[data-value="UNAPPROVE"] {
  border-color: var(--color-danger-500);
  background: color-mix(in srgb, var(--color-danger-500) 14%, var(--color-bg-surface));
  box-shadow: inset 0 0 0 1px var(--color-danger-500);
}
.cs-action-pill .cs-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: var(--radius-full);
  background: var(--color-text-faint);
}
.cs-action-pill .cs-dot.cs-approve { background: var(--color-success-500); }
.cs-action-pill .cs-dot.cs-archive { background: var(--color-danger-500); }
.cs-action-pill .cs-dot.cs-reject  { background: var(--color-danger-500); }
.cs-action-pill .cs-dot.cs-edit    { background: var(--color-warning-500); }
.cs-action-pill .cs-pill-sub {
  display: block;
  margin-top: 2px;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

/* Note + submit follow-up — hidden until an action pill is selected. */
.cs-action-followup { display: none; margin-top: var(--space-3); }
.cs-action-followup.cs-visible { display: block; }


.cs-composer-row { display: flex; gap: var(--space-3); align-items: flex-start; }
.cs-composer textarea { resize: vertical; min-height: 60px; }

.cs-actions-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.cs-meta-text { font-size: var(--font-size-xs); color: var(--color-text-faint); }
.cs-meta-text strong { color: var(--color-text-muted); font-weight: var(--font-weight-semibold); }

/* ---------- FEED — TIMELINE ---------- */
#cs-comment-list { position: relative; }

.cs-comment {
  position: relative;
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) 0 var(--space-3) 0;
  background: none;
  border: 0;
}
/* The connecting rail: a vertical line through the avatar centres. */
.cs-comment::before {
  content: "";
  position: absolute;
  left: 17px;                      /* avatar (36px) centre */
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-border-default);
}
.cs-comment:first-child::before { top: 18px; }              /* start at the first node */
.cs-comment:last-child::before  { bottom: auto; height: 18px; }  /* stop at the last node */

/* Avatar node — sits on top of the rail (opaque bg masks the line). */
.cs-icon {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family-display);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  line-height: 1;
  border: 2px solid var(--color-bg-surface);   /* ring so the rail doesn't touch the disc */
}
.cs-icon.cs-user   { background: var(--color-brand-primary-soft); color: var(--color-brand-primary); }
.cs-icon.cs-system { background: var(--color-bg-sunken);          color: var(--color-text-muted); }

.cs-body { flex: 1 1 auto; min-width: 0; padding-top: 2px; }
.cs-meta { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.cs-name {
  font-family: var(--font-family-ui);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  color: var(--color-text-strong);
}
.cs-time { margin-left: auto; font-family: var(--font-family-data); font-size: var(--font-size-xs); color: var(--color-text-faint); }
.cs-text {
  margin: var(--space-1) 0 0;
  font-family: var(--font-family-ui);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-base);
  color: var(--color-text-default);
  overflow-wrap: anywhere;
}
/* Free-text a person typed (notes, status-change / unapprove reasons). */
.cs-text__user {
  font-style: italic;
}

/* Source badge — small tonal chip mirroring .ng-status-pill tones. */
.cs-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px var(--space-2);
  border-radius: var(--radius-full);
  font-family: var(--font-family-ui);
  font-size: 10px;
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-uppercase);
  line-height: 1.5;
}
.cs-badge.cs-badge-user   { background: var(--color-brand-primary-soft); color: var(--color-brand-primary); }
.cs-badge.cs-badge-system { background: var(--color-bg-sunken);          color: var(--color-text-muted); }

/* A system entry reads a touch quieter. */
.cs-comment.cs-system .cs-name { color: var(--color-text-default); }

.cs-loading {
  padding: var(--space-6);
  text-align: center;
  font-family: var(--font-family-ui);
  font-size: var(--font-size-sm);
  color: var(--color-text-faint);
}

/* ---------- AUDIT TRAIL TAB ----------
 * Value tones reuse ng-audit__* from _data-display.css. While the trail is
 * active the comment feed + count hide — it replaces them, not stacks. */
.cs-panel.cs-audit-active #cs-comment-list,
.cs-panel.cs-audit-active #cs-count { display: none; }

/* Bare pane: list content brings its own rhythm, no composer padding box. */
.cs-tab-pane--bare.cs-active { padding: var(--space-2) var(--space-4); }

.cs-badge.cs-badge-update { background: var(--color-brand-primary-soft); color: var(--color-brand-primary); }

.ng-trail__entry {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border-default);
}
.ng-trail__entry:last-child { border-bottom: 0; }

.ng-trail__head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.ng-trail__title {
  font-family: var(--font-family-ui);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  color: var(--color-text-strong);
}
.ng-trail__time {
  margin-left: auto;
  font-family: var(--font-family-data);
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
}

.ng-trail__changes {
  list-style: none;
  margin: var(--space-1) 0 0;
  padding: 0;
  font-family: var(--font-family-ui);
  font-size: var(--font-size-sm);
  color: var(--color-text-default);
}
.ng-trail__change { padding: 2px 0; overflow-wrap: anywhere; }
.ng-trail__label {
  display: inline-block;
  min-width: 140px;
  padding-right: var(--space-2);
  color: var(--color-text-muted);
}
.ng-trail__note {
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
}

.ng-trail__meta {
  margin-top: var(--space-1);
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
}

.ng-trail__footer {
  margin-top: 5px;
}

/* ---------- AUDIT LINE ACTION ----------
 * An action offered against one timeline entry (today: withdrawing an open
 * Request Edit). The reason box expands in place rather than in a modal, so the
 * entry it acts on stays on screen. */
.cs-line-action {
  margin-top: var(--space-2);
  padding: 0;
  background: none;
  border: 0;
  font-family: var(--font-family-ui);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-brand-primary);
  cursor: pointer;
}
.cs-line-action:hover { text-decoration: underline; }

.cs-line-form {
  margin-top: var(--space-2);
  padding: var(--space-3);
  background: var(--color-bg-sunken);
  border-radius: var(--radius-md);
}
.cs-line-form__label {
  display: block;
  margin-bottom: var(--space-2);
  font-family: var(--font-family-ui);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}
.cs-line-form__note {
  margin: 0 0 var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  background: var(--color-feedback-warning-bg);
  color: var(--color-feedback-warning);
}
.cs-line-form__error {
  margin: var(--space-2) 0 0;
  font-size: var(--font-size-xs);
  color: var(--color-feedback-danger);
}
.cs-line-form__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* Event-type filter above the audit-trail feed (issue 822). */
.ng-trail__filter {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.ng-trail__filter-label {
  margin: 0;
  font-family: var(--font-family-ui);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
}
.ng-trail__filter-select {
  flex: 0 1 220px;
  width: auto;
}
