.comments-root {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.comments-heading,
.comments-actions,
.comments-meta,
.comments-composer,
.comments-composer-footer {
  display: flex;
  align-items: center;
}

.comments-heading {
  justify-content: space-between;
  margin-bottom: 1rem;
}

.comments-title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  color: var(--text);
  font-size: 1.125rem;
}

.comments-count {
  font-size: 0.875rem;
  color: var(--muted);
  font-weight: 500;
}

.comments-composer {
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.comments-composer--reply {
  margin: 0.5rem 0 0.75rem 3rem;
  padding-left: 1rem;
  border-left: 0.125rem solid var(--border);
}

.comments-composer.is-guest {
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.comments-login-copy {
  color: var(--muted);
  font-size: 0.875rem;
}

.comments-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: 0 0 2.25rem;
  overflow: hidden;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-active);
  font-size: 0.875rem;
  font-weight: 700;
}

.comments-avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.comments-composer-body,
.comments-item-content {
  min-width: 0;
  flex: 1;
}

/* One consistent rounded-rectangle shape idle and active (like X / Instagram /
   LinkedIn). No pill → no shape morph → no glitch on focus. Focusing only
   reveals the footer row and shows the focus ring. */
.comments-input-shell {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.comments-input-shell:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 0.1875rem var(--primary-light);
}

.comments-input {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  max-height: 8rem;
  field-sizing: content;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 0.75rem 0.875rem 0.375rem;
  font: inherit;
  line-height: 1.5;
}

.comments-input::placeholder {
  color: var(--muted);
}

.comments-composer-footer {
  justify-content: flex-end;
  gap: 0.625rem;
  min-height: 2.5rem;
  padding: 0.25rem 0.375rem 0.375rem 0.875rem;
  /* Reveal by animating open, not by popping in from display:none (which used
     to jump the box height). max-height is a safe over-estimate of one row. */
  overflow: hidden;
  max-height: 4rem;
  opacity: 1;
  transition:
    max-height 160ms ease,
    opacity 120ms ease,
    padding 160ms ease;
}

.comments-input-shell.is-collapsed .comments-composer-footer {
  /* min-height would otherwise win over max-height and keep the row visible. */
  min-height: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  pointer-events: none;
}

.comments-composer-footer[hidden] {
  display: none;
}

.comments-keyboard-hint {
  margin-right: auto;
  color: var(--muted);
  font-size: 0.6875rem;
}

.comments-counter {
  color: var(--muted);
  font-size: 0.6875rem;
}

.comments-submit,
.comments-login,
.comments-dialog-submit {
  min-height: 2.25rem;
  border: 0;
  border-radius: calc(var(--radius) / 1.5);
  background: var(--primary);
  color: var(--surface);
  cursor: pointer;
  padding: 0.5rem 0.875rem;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
}

.comments-submit:hover,
.comments-login:hover,
.comments-dialog-submit:hover {
  background: var(--primary-hover);
}

.comments-submit:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: default;
}

.comments-reply-context {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.comments-reply-context-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comments-reply-cancel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  flex: 0 0 2.5rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 1.125rem;
  line-height: 1;
}

.comments-reply-cancel:hover {
  background: var(--bg);
  color: var(--text);
}

.comments-status {
  margin: 0.25rem 0 0.75rem 3rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.comments-status.is-empty {
  padding: 1.25rem 0;
  text-align: center;
}

.comments-status.is-error {
  color: var(--danger, var(--brand-dark));
}

.comments-list {
  display: flow-root;
}

.comments-item {
  position: relative;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.comments-item.is-pending {
  opacity: 0.65;
}

.comments-item-layout {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.comments-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 1.75rem;
}

.comments-item--reply {
  margin: 0.25rem 0 0 3rem;
  padding: 0.625rem 0 0.625rem 1rem;
  border-bottom: 0;
  border-left: 0.125rem solid var(--border);
}

.comments-meta,
.comments-actions {
  gap: 0.625rem;
}

.comments-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.comments-author {
  color: var(--text);
  font-size: 0.8125rem;
}

.comments-time::before {
  content: "·";
  margin-right: 0.625rem;
}

.comments-body {
  margin: 0.1875rem 0 0;
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.comments-actions {
  position: relative;
  gap: 0.25rem;
  min-height: 2.5rem;
}

.comments-action,
.comments-like,
.comments-load-more,
.comments-replies-toggle,
.comments-retry {
  border: 0;
  border-radius: calc(var(--radius) / 2);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  min-height: 2.5rem;
  padding: 0.375rem 0.5rem;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
}

.comments-action:hover,
.comments-like:hover,
.comments-load-more:hover,
.comments-replies-toggle:hover,
.comments-retry:hover {
  background: var(--bg);
  color: var(--text);
}

.comments-like {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.comments-like.is-liked {
  color: var(--primary-active);
}

.comments-like:disabled {
  cursor: default;
  opacity: 0.65;
}

.comments-like-icon {
  width: 1rem;
  font-size: 1rem;
  line-height: 1;
}

.comments-like-count {
  min-width: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.comments-menu-root {
  position: relative;
  flex: 0 0 auto;
}

.comments-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  min-height: 2rem;
  padding: 0;
  border-radius: 999px;
  color: var(--muted);
  font-size: 1.125rem;
  line-height: 1;
  transition: background-color 120ms ease, color 120ms ease;
}

.comments-more:hover,
.comments-more[aria-expanded="true"] {
  background: #F1F5F9;
  color: var(--text);
}

.comments-replies-toggle {
  margin: 0.5rem 0 0 3rem;
  color: var(--primary-active);
}

.comments-menu {
  position: absolute;
  z-index: 20;
  right: 0;
  top: 2.25rem;
  min-width: 9rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform-origin: top right;
  animation: comments-menu-in 120ms ease;
}

@keyframes comments-menu-in {
  from {
    opacity: 0;
    transform: translateY(-0.25rem) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.comments-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 0.5rem 0.625rem;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
  transition: background-color 100ms ease, color 100ms ease;
}

/* --bg equals --surface (both white), so hover needs a real neutral tint. */
.comments-menu-item:hover,
.comments-menu-item:focus-visible {
  background: #F1F5F9;
}

.comments-menu-item--danger {
  color: #DC2626;
}

.comments-menu-item--danger:hover,
.comments-menu-item--danger:focus-visible {
  background: #FEF2F2;
  color: #DC2626;
}

.comments-load-more {
  display: block;
  margin: 1rem auto 0;
  color: var(--primary-active);
}

.comments-dialog {
  width: min(30rem, calc(100vw - 2rem));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
}

.comments-dialog::backdrop {
  background: color-mix(in srgb, var(--text) 50%, transparent);
}

.comments-dialog-form {
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
}

.comments-dialog-title,
.comments-dialog-copy {
  margin: 0;
}

.comments-dialog-copy {
  color: var(--muted);
}

.comments-dialog-input,
.comments-dialog-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0.75rem;
  font: inherit;
}

.comments-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.comments-pending-label {
  font-style: italic;
}

.comments-card-count {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.comments-root button:focus-visible,
.comments-root textarea:focus-visible,
.comments-root select:focus-visible {
  outline: 0.125rem solid var(--primary);
  outline-offset: 0.125rem;
}

@media (max-width: 40rem) {
  .comments-root {
    margin-top: 1rem;
    padding-top: 1rem;
  }

  .comments-keyboard-hint {
    display: none;
  }

  .comments-item--reply {
    margin-left: 1.25rem;
    padding-left: 0.75rem;
  }

  .comments-composer--reply {
    margin-left: 1.25rem;
    padding-left: 0.75rem;
  }

  .comments-replies-toggle {
    margin-left: 3rem;
  }

  .comments-status {
    margin-left: 0;
  }

  .comments-actions {
    gap: 0;
  }
}
