/*
 * Discussions.
 *
 * Colours come from the --ep-* tokens defined on :root in entity_picker.css,
 * which are themselves mapped onto the app's theme variables. That is the only
 * set in this codebase that is actually declared for light, dark and the manual
 * html[data-theme] override, so nothing here needs its own theme block.
 *
 * The chip and card classes a discussion renders (.cc-chip, .cc-card) live in
 * comment_composer.css and are shared - see the note at the top of that file.
 */

/* --- Index --------------------------------------------------------------- */

.discussion-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Tighter than the default .glass-card 1rem, matching .event-card - a list of
   these is scanned, not read. */
.discussion-card {
  display: block;
  margin: 0;
  padding: 0.65rem 0.85rem;
  text-decoration: none;
  color: inherit;
}

.discussion-card:hover {
  border-color: var(--accent-color);
}

/*
 * Kills the underline the global `a:hover { text-decoration: underline }` puts
 * on these. Both are link_to-wrapped cards, and the `text-decoration: none` on
 * their base rules does not hold on hover: a plain class scores (0,1,0) and
 * a:hover scores (0,1,1), so a:hover wins. Type-qualifying these to (0,2,1)
 * beats it on specificity rather than relying on which file the bundler happens
 * to emit last.
 */
a.discussion-card:hover,
a.pinned-discussion:hover {
  text-decoration: none;
}

/* Two columns, as on the events index: what it is on the left, when it last
   moved on the right. */
.discussion-card-layout {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.discussion-card-details {
  flex: 1;
  min-width: 0;
}

.discussion-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.discussion-card-title {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.3;
}

.discussion-card-badges {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

/* Usually empty now that the status badge only renders in the "all" view -
   without this the header's gap still reserves space after the title. */
.discussion-card-badges:empty {
  display: none;
}


/*
 * Starter, contributor avatars and attachment chips share one wrapping row, so
 * a card grows a line only when there is genuinely too much for one.
 *
 * A sibling of .discussion-card-layout rather than a child of its left column.
 * .discussion-card-side is flex-shrink: 0 and reserves its width for the full
 * height of the card, so anything inside the left column wraps against that
 * reserved width even where the card is visibly empty beside it - which on a
 * phone meant chips breaking onto their own line with half the card unused.
 * Down here the row gets the whole card.
 */
.discussion-card-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.75rem;
  margin-top: 0.25rem;
  font-size: 0.85rem;
}

.discussion-card-starter {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  opacity: 0.75;
}

.discussion-card-contributors {
  display: inline-flex;
  align-items: center;
}

/* The two lines here are what set the height of the whole top row - the title
   beside them is only one - so their leading is the other half of the gap above
   the info row, not just its margin. */
.discussion-card-side {
  flex-shrink: 0;
  text-align: right;
  font-size: 0.85rem;
  line-height: 1.35;
}

.discussion-card-replies {
  font-weight: 600;
  white-space: nowrap;
}

.discussion-card-age {
  opacity: 0.7;
  white-space: nowrap;
}

/* --- Badges --------------------------------------------------------------
 *
 * Geometry and the filled treatment mirror .event-status-badge in
 * application.css, so a discussion's status reads like an event's rather than
 * like a third badge vocabulary. Deliberately a parallel set of rules rather
 * than reusing that class: it is named for events, and discussions need their
 * own four states. If a third surface wants this, promote it to one shared name
 * instead of adding a second copy.
 *
 * Colours are declared three times, matching how the app themes everything
 * else: the light default, the html[data-theme="dark"] manual override, and the
 * prefers-color-scheme query for users who have not chosen.
 */

.discussion-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: 600;
  white-space: nowrap;
}

.discussion-badge--open {
  background: #dbeafe;
  color: #1e40af;
}

.discussion-badge--resolved {
  background: #d1fae5;
  color: #065f46;
}

.discussion-badge--pinned {
  background: #fef3c7;
  color: #92400e;
}

.discussion-badge--archived {
  background: #e5e7eb;
  color: #4b5563;
}

html[data-theme="dark"] .discussion-badge--open {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

html[data-theme="dark"] .discussion-badge--resolved {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}

html[data-theme="dark"] .discussion-badge--pinned {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

html[data-theme="dark"] .discussion-badge--archived {
  background: rgba(156, 163, 175, 0.2);
  color: #d1d5db;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .discussion-badge--open {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
  }

  html:not([data-theme="light"]) .discussion-badge--resolved {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
  }

  html:not([data-theme="light"]) .discussion-badge--pinned {
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
  }

  html:not([data-theme="light"]) .discussion-badge--archived {
    background: rgba(156, 163, 175, 0.2);
    color: #d1d5db;
  }
}

/* --- Show ----------------------------------------------------------------
 *
 * The page header sits outside the cards, as it does on the event and setlist
 * show pages: title and action buttons on one row, metadata under it, badges
 * under that. 30px below matches .messages-header, which is what those pages
 * use - not reused directly here because that class is a two-column flex and
 * this header is three stacked rows.
 */

.discussion-header {
  margin-bottom: 30px;
}

.discussion-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
}

/*
 * flex-basis rather than min-width: 0, deliberately. The title needs a floor to
 * shrink to, or it would keep shrinking and the buttons would never wrap - they
 * would just squeeze the title to a one-word column. 12rem is roughly where a
 * title stops being readable, so that is where the buttons drop underneath.
 */
/* No font-size: it is a page title now, so it takes the global h1 size the
   other show pages use. */
.discussion-title {
  margin: 0;
  line-height: 1.25;
  flex: 1 1 12rem;
}

/* gap is required alongside flex-wrap, or the wrapped row of buttons sits flush
   against the title. See docs/flex-wrap-gap.md. */
.discussion-header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Sits close under the title, so it reads as part of it rather than as its own
   line. gap is the only spacing knob in here - see the note in the template. */
.discussion-header-meta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.15rem;
  color: var(--text-muted);
  font-size: 0.9em;
  line-height: 1.4;
}

.discussion-header-badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.discussion-header-badges:empty {
  display: none;
}

.discussion-body {
  white-space: pre-wrap;
  line-height: 1.6;
}

.discussion-body-empty {
  font-style: italic;
  opacity: 0.6;
}

/* The resolution is the whole value proposition over a chat log, so it sits at
   the top of the page and looks like the answer rather than another message. */
.discussion-resolution {
  padding: 0.9rem 1rem;
  margin-bottom: 1.25rem;
  border: 1px solid #66c2a5;
  border-radius: 6px;
  background-color: color-mix(in srgb, #66c2a5 10%, transparent);
}

.discussion-resolution-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  font-weight: 600;
  color: #66c2a5;
  margin-bottom: 0.4rem;
}

.discussion-resolution-icon {
  width: 16px;
  height: 16px;
  flex: none;
}

.discussion-resolution-text {
  white-space: pre-wrap;
  line-height: 1.5;
}

/* Sits at the foot of the card, under the body and the attachment cards, so the
   rule separates it from the content it is asking about. */
.discussion-resolve {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--ep-border);
}

/* flex-wrap so the hint drops under the button on a narrow screen rather than
   forcing an awkward two-word second line beside it. gap goes with it - see
   docs/flex-wrap-gap.md. */
.discussion-resolve-prompt {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.discussion-resolve-hint {
  font-size: 0.85rem;
  opacity: 0.7;
}

/*
 * Overrides the global `form { margin: 20px 0 }`. That 20px is dead space in
 * every context this form appears in: inline on the show page it pushes the
 * Title field away from the top of the card, and on the new and edit pages the
 * .glass-card-title below its rule already provides the gap.
 */
.discussion-form {
  margin: 0;
}

.field-hint {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  opacity: 0.7;
}

/* --- Pinned discussions on the band home page ----------------------------- */

/*
 * A section of the band home page rather than a card on it, so it uses that
 * page's section spacing: 1rem below its own heading, like every .band-cards
 * grid, and 1.5rem before the next one, which is the top margin the headings
 * after the first carry.
 *
 * The gap lives here rather than on the Song Library heading below, because that
 * heading is the first section when nothing is pinned and has to stay at zero.
 */
.pinned-discussion-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 1rem 0 1.5rem;
}

/*
 * A tint rather than a surface colour. --ep-surface (an opaque --input-bg) made
 * the rows read as panels once the card behind them was gone; a few percent of
 * the text colour lifts them off the page without becoming a container. It also
 * needs no theme block: in light mode the text is dark so this reads as a faint
 * grey, in dark mode it is light so it reads as a faint lift.
 *
 * Kept well under --ep-hover, so the hover state is still a visible change.
 */
.pinned-discussion {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  background-color: color-mix(in srgb, var(--ep-text) 5%, transparent);
  border: 1px solid var(--ep-border);
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
}

.pinned-discussion:hover {
  background-color: var(--ep-hover);
  border-color: var(--accent-color);
}

.pinned-discussion-icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.pinned-discussion-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  flex: 1;
}

.pinned-discussion-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pinned-discussion-summary {
  font-size: 0.85rem;
  opacity: 0.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The reverse lookup distinguishes a discussion from a comment with its icon. */
.mentioned-in-icon {
  width: 14px;
  height: 14px;
  vertical-align: text-bottom;
  margin-right: 0.2rem;
}

/* --- Mobile -------------------------------------------------------------- */

@media (max-width: 640px) {
  .discussion-title {
    font-size: 1.25rem;
  }

  .discussion-resolve-hint {
    display: block;
    margin: 0.4rem 0 0;
  }

  /* Buttons wrap rather than squeeze; gap is what keeps the rows apart. */
  .discussion-actions {
    gap: 0.5rem;
  }
}
