/**
 * CourseGlade Discussion/Q&A Styles
 * Course and lesson discussions
 */

/* ==========================================================================
   Discussions Section
   ========================================================================== */
.courseglade-discussions {
  margin-top: 40px;
}

.courseglade-discussions__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--courseglade-surface-high);
}

.courseglade-discussions__title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  color: var(--courseglade-on-surface);
}

.courseglade-discussions__title svg {
  color: var(--courseglade-primary);
}

.courseglade-discussions__count {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--courseglade-on-surface-muted);
}

.courseglade-discussions__new-btn {
  border-radius: var(--courseglade-radius);
}

/* ==========================================================================
   New Discussion Form
   ========================================================================== */
.courseglade-discussions__form {
  display: none;
  background: var(--courseglade-surface-lowest);
  border-radius: var(--courseglade-radius-nav);
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid var(--courseglade-surface-high);
}

.courseglade-discussions__form.is-visible {
  display: block;
}

.courseglade-discussions__form-group {
  margin-bottom: 16px;
}

.courseglade-discussions__form-group:last-child {
  margin-bottom: 0;
}

.courseglade-discussions__label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--courseglade-on-surface-muted);
  margin-bottom: 6px;
}

.courseglade-discussions__input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--courseglade-surface-high);
  border-radius: var(--courseglade-radius);
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--courseglade-on-surface);
  background: var(--courseglade-surface-lowest);
  transition: border-color var(--courseglade-transition), box-shadow var(--courseglade-transition);
}

.courseglade-discussions__input:focus {
  outline: none;
  border-color: var(--courseglade-primary) !important;
  border-style: solid !important;
  box-shadow: none;
}

.courseglade-discussions__textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px 14px;
  border: 1px solid var(--courseglade-surface-high);
  border-radius: var(--courseglade-radius);
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--courseglade-on-surface);
  background: var(--courseglade-surface-lowest);
  line-height: 1.6;
  resize: vertical;
  transition: border-color var(--courseglade-transition), box-shadow var(--courseglade-transition);
}

.courseglade-discussions__textarea:focus {
  outline: none;
  border-color: var(--courseglade-primary);
  border-style: solid;
  box-shadow: none;
}

.courseglade-discussions__form-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.courseglade-discussions__submit {
  border-radius: var(--courseglade-radius);
}

/* Cancel is the way out, not a second choice: as a filled grey block it
   carried nearly as much weight as the action beside it. Text only here —
   btn-ghost keeps its fill everywhere else in the plugin.
   Scoped past base.css's .courseglade-btn-ghost:focus:not(:disabled), which
   otherwise repaints the fill the moment the button is focused. */
.courseglade-discussions .courseglade-discussions__cancel {
  border: 0;
  border-radius: var(--courseglade-radius);
  background: none;
  color: var(--courseglade-on-surface-secondary);
  font-weight: 600;
}

/* The fill arrives on hover instead of sitting there permanently: it confirms
   the target without competing with the action at rest. Keeps its padding so
   the fill has something to cover. */
.courseglade-discussions .courseglade-discussions__cancel:is(:hover, :focus, :active):not(:disabled) {
  background: var(--courseglade-surface-low);
  border-color: transparent;
  color: var(--courseglade-on-surface);
}

/* ==========================================================================
   Discussion List
   ========================================================================== */
.courseglade-discussions__list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* One shell for both states the list can be in before it has content:
   loading, and empty. Declared together so the section keeps the same shape
   and the page does not jump when one becomes the other.

   Solid border, not the draft's dashed one: dashed reads as a slot waiting to
   be filled, and these are finished states rather than gaps in the page. */
.courseglade-discussions__empty,
.courseglade-discussions__loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 32px 20px;
  border: 1px solid var(--courseglade-border);
  border-radius: var(--courseglade-radius-lg);
  background: var(--courseglade-surface-lowest);
  text-align: center;
}

.courseglade-discussions__empty-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 14px;
  border-radius: 50%;
  background: var(--courseglade-primary-surface);
  color: var(--courseglade-primary);
}

.courseglade-discussions__empty-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--courseglade-on-surface);
}

.courseglade-discussions__empty-text {
  max-width: 44ch;
  margin: 0 0 16px;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--courseglade-on-surface-muted);
}

/* What a student most wants to know before asking in public. */
.courseglade-discussions__empty-hint {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--courseglade-on-surface-muted);
}

/* An error is not one of those states: no card, just the line, in the danger
   colour. A failure should not look like a considered piece of the page. */
.courseglade-discussions__empty--error {
  display: block;
  min-height: 0;
  padding: 4px 0 8px;
  border: 0;
  background: none;
  text-align: left;
  font-size: 0.8125rem;
  color: var(--courseglade-danger);
}

/* Held back until the list has resolved. Two reasons: while loading we do not
   yet know whether the empty card — which carries the same action — will take
   its place, and offering to ask before the questions have appeared invites a
   duplicate of one already there. */
.courseglade-discussions__ask.is-pending {
  display: none;
}

.courseglade-discussions__loading {
  gap: 12px;
}

.courseglade-discussions__loading p {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--courseglade-on-surface-muted);
}

.courseglade-discussions__error-text {
  color: var(--courseglade-danger);
  padding: 12px;
  margin: 0;
  font-size: 0.9375rem;
}

.courseglade-discussions__replies-loading {
  text-align: center;
  padding: 12px;
  color: var(--courseglade-on-surface-muted);
}

/* ==========================================================================
   Discussion Item
   ========================================================================== */
.courseglade-discussion {
  background: var(--courseglade-surface-lowest);
  border-radius: var(--courseglade-radius-nav);
  border: 1px solid var(--courseglade-surface-high);
  overflow: hidden;
}

.courseglade-discussion__main {
  padding: 16px 20px;
}


.courseglade-discussion__author {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--courseglade-on-surface);
  margin: 0 0 2px;
}

.courseglade-discussion__time {
  font-size: 0.75rem;
  color: var(--courseglade-on-surface-muted);
  display: block;
}

.courseglade-discussion__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--courseglade-on-surface);
  margin: 0 0 8px;
  line-height: 1.4;
}

.courseglade-discussion__title a {
  color: inherit;
  text-decoration: none;
}

.courseglade-discussion__title a:hover {
  color: var(--courseglade-primary);
}

.courseglade-discussion__content {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--courseglade-on-surface-muted);
  margin-bottom: 12px;
}

.courseglade-discussion__content p:last-child {
  margin-bottom: 0;
}

.courseglade-discussion__footer {
  display: flex;
  align-items: center;
  gap: 16px;
}


/* ==========================================================================
   Thread detail
   ========================================================================== */

/* Separated from the question by a rule rather than a panel: the replies are
   part of the question, not a second card. */
.courseglade-discussion__detail {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--courseglade-surface-high);
}

.courseglade-discussion__empty {
  margin: 0 0 14px;
  font-size: 0.8125rem;
  color: var(--courseglade-on-surface-muted);
}

.courseglade-reply {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--courseglade-surface-high);
}

.courseglade-reply:last-child {
  border-bottom: 0;
}

.courseglade-reply__avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.courseglade-reply__body {
  flex: 1;
  min-width: 0;
}

.courseglade-reply__header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.courseglade-reply__author {
  font-size: 0.875rem;
  color: var(--courseglade-on-surface);
}

/* Who is speaking matters more than when: the instructor's answer and the
   asker's follow-up are read differently from a stranger's. */
.courseglade-reply__badge {
  padding: 2px 7px;
  border-radius: var(--courseglade-radius-pill);
  background: var(--courseglade-primary-surface);
  color: var(--courseglade-primary);
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.courseglade-reply__badge--asker {
  background: var(--courseglade-surface-low);
  color: var(--courseglade-on-surface-muted);
}

.courseglade-reply__time {
  font-size: 0.75rem;
  color: var(--courseglade-on-surface-muted);
}

.courseglade-reply__content {
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--courseglade-on-surface-secondary);
}

.courseglade-reply__content p {
  margin: 0;
}

.courseglade-reply__content p + p {
  margin-top: 0.75em;
}

.courseglade-reply__badge--best {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--courseglade-success-bg);
  color: var(--courseglade-success-text);
}

.courseglade-reply__actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
}

/* Quiet by default: a vote is an offer, not a call to action. */
.courseglade-reply__helpful {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--courseglade-on-surface-muted);
  cursor: pointer;
}

.courseglade-reply__helpful:hover,
.courseglade-reply__helpful:focus {
  background: none;
  color: var(--courseglade-primary);
}

.courseglade-reply__helpful.is-voted {
  color: var(--courseglade-primary);
}

/* Filled once you have voted, so your own mark is distinguishable from a
   count you merely contributed to. */
.courseglade-reply__helpful.is-voted svg {
  fill: currentColor;
}

.courseglade-reply__helpful.is-static {
  cursor: default;
}

/* A different kind of action from a vote — a judgement about the answer, made
   by one of two people — so it gets its own end of the row, its own icon and
   its own colour rather than sitting beside "Helpful" as its twin. */
.courseglade-reply__choose {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  padding: 4px 10px;
  border: 1px solid var(--courseglade-border);
  border-radius: var(--courseglade-radius-pill);
  background: var(--courseglade-surface-lowest);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--courseglade-on-surface-muted);
  white-space: nowrap;
  cursor: pointer;
}

.courseglade-reply__choose:hover,
.courseglade-reply__choose:focus {
  border-color: var(--courseglade-success-border);
  background: var(--courseglade-success-surface);
  color: var(--courseglade-success-text);
}

/* Already chosen: the control reads as the state it is in, so its job is to
   offer the way back rather than to invite the same click again. */
.courseglade-reply__choose.is-best {
  border-color: var(--courseglade-success-border);
  background: var(--courseglade-success-bg);
  color: var(--courseglade-success-text);
}

.courseglade-reply__choose.is-best:hover,
.courseglade-reply__choose.is-best:focus {
  border-color: var(--courseglade-border);
  background: var(--courseglade-surface-low);
  color: var(--courseglade-on-surface-secondary);
}

/* Reply box: part of the open thread, not a form you have to summon. */
.courseglade-replybox {
  display: flex;
  gap: 12px;
}

.courseglade-replybox__body {
  flex: 1;
  min-width: 0;
}

.courseglade-replybox__input {
  width: 100%;
  min-height: 76px;
  resize: vertical;
}

.courseglade-replybox__actions {
  margin-top: 10px;
}

/* ==========================================================================
   Ask box
   ========================================================================== */

/* A place to write rather than a control to find: the collapsed prompt is the
   whole row, and clicking anywhere in it opens the form.
   It carries the old button's id, so the toggle behaviour is unchanged. */
.courseglade-discussions__ask {
  display: flex;
  cursor: pointer;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--courseglade-border);
  border-radius: var(--courseglade-radius-lg);
  background: var(--courseglade-surface-lowest);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--courseglade-transition);
}

.courseglade-discussions__ask:hover,
.courseglade-discussions__ask:focus {
  background: var(--courseglade-surface-lowest);
  border-color: var(--courseglade-on-surface-muted);
}

.courseglade-discussions .courseglade-discussions__ask img.courseglade-discussions__ask-avatar,
.courseglade-discussions img.courseglade-discussions__ask-avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.courseglade-discussions__ask-placeholder {
  flex: 1;
  min-width: 0;
  font-size: 0.875rem;
  color: var(--courseglade-on-surface-muted);
}

.courseglade-discussions__ask-action {
  flex: none;
}

.courseglade-discussions__form-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 0.8125rem;
  color: var(--courseglade-on-surface-muted);
}

.courseglade-discussions__form-head b {
  color: var(--courseglade-on-surface);
}

/* ==========================================================================
   Thread card
   ========================================================================== */

/* The reply count leads: scanning the list, how much conversation a question
   already has is what decides whether to open it. */
.courseglade-discussion__main {
  display: flex;
  gap: 16px;
  padding: 20px;
}

.courseglade-discussion__count {
  flex: none;
  width: 58px;
  align-self: flex-start;
  padding: 8px 4px;
  border: 1px solid var(--courseglade-border);
  border-radius: var(--courseglade-radius-md);
  background: var(--courseglade-surface);
  text-align: center;
}

.courseglade-discussion__count b {
  display: block;
  font-size: 1.125rem;
  font-weight: 800;
  line-height: 1;
  color: var(--courseglade-on-surface);
}

.courseglade-discussion__count span {
  font-size: 0.6875rem;
  color: var(--courseglade-on-surface-muted);
}

.courseglade-discussion__body {
  flex: 1;
  min-width: 0;
}

.courseglade-discussion__body .courseglade-discussion__title {
  margin: 0 0 4px;
  font-size: 1rem;
}

.courseglade-discussion__body .courseglade-discussion__content {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

.courseglade-discussion__body .courseglade-discussion__footer {
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  font-size: 0.75rem;
}

.courseglade-discussion__body .courseglade-discussion__author,
.courseglade-discussion__body .courseglade-discussion__time {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--courseglade-on-surface-muted);
}

.courseglade-discussion__status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--courseglade-on-surface-muted);
}

.courseglade-discussion__dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: currentColor;
}

.courseglade-discussion__status--answered {
  color: var(--courseglade-success);
}

.courseglade-discussion__status--waiting {
  color: var(--courseglade-warning);
}

/* Pushed to the end of the row so every card's action sits in one column. */
.courseglade-discussion__open {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  padding: 4px 2px;
  border: 0;
  border-radius: var(--courseglade-radius-sm);
  background: none;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--courseglade-primary);
  white-space: nowrap;
  cursor: pointer;
}

.courseglade-discussion__open:hover,
.courseglade-discussion__open:focus {
  background: none;
  color: var(--courseglade-primary-dark);
}

.courseglade-discussion__open svg {
  transition: transform 0.12s ease;
}

.courseglade-discussion__open:hover svg {
  transform: translateX(2px);
}

/* Open: the arrow turns to point down at what it revealed. */
.courseglade-discussion__open.is-open svg {
  transform: rotate(90deg);
}

.courseglade-discussion__open.is-open:hover svg {
  transform: rotate(90deg) translateX(2px);
}

@media (prefers-reduced-motion: reduce) {
  .courseglade-discussions__ask,
  .courseglade-discussion__open svg {
    transition: none;
  }
}

@media (max-width: 600px) {
  /* The count tile is the widest thing that is not the question itself. */
  .courseglade-discussion__count {
    display: none;
  }

  .courseglade-discussions__ask-placeholder {
    display: none;
  }

  .courseglade-discussions__ask-action {
    flex: 1;
    justify-content: center;
  }
}

/* ==========================================================================
   In a tab
   ========================================================================== */

/* The tab strip already says "Q&A", so repeating it as a heading says the same
   thing twice. Set by the caller — single-lesson.php — rather than inferred
   from a parent selector: the heading still earns its place on the quiz and
   assignment screens, which have no tabs, and a component should not restyle
   itself because of what it was nested inside. */
.courseglade-discussions--tabbed {
  margin-top: 0;
}

.courseglade-discussions--tabbed .courseglade-discussions__header {
  display: none;
}
