/* ═══════════════════════════════════════════════════════════════════
   Shared comment section (sgc-*) — used by blog posts and /learn pages.
   Self-contained: defines its own --sgc-* tokens so it renders identically
   on any page regardless of that page's own CSS variables. Light theme to
   match the /learn pages; dark overrides apply only when a page opts in via
   html[data-theme="dark"] (blog), never on the always-light learn pages.
   ═══════════════════════════════════════════════════════════════════ */
.sgc-section {
  --sgc-bg2:     #f9fafb;
  --sgc-surface: #ffffff;
  --sgc-bg:      #ffffff;
  --sgc-bg3:     #f3f4f6;
  --sgc-border:  #e5e7eb;
  --sgc-text:    #111827;
  --sgc-text2:   #374151;
  --sgc-muted:   #9ca3af;
  --sgc-primary: #4f46e5;
  --sgc-grad:    linear-gradient(135deg, #2563eb, #4f46e5);
  --sgc-r:       14px;
  --sgc-r-sm:    8px;
  --sgc-shadow:  0 8px 26px rgba(17, 24, 39, .06);

  background: var(--sgc-bg2);
  border-top: 1px solid var(--sgc-border);
  padding: 64px 0 72px;
}
html[data-theme="dark"] .sgc-section {
  --sgc-bg2:     #12141c;
  --sgc-surface: #1a1d27;
  --sgc-bg:      #12141c;
  --sgc-bg3:     #22252f;
  --sgc-border:  #2b2f3a;
  --sgc-text:    #f3f4f6;
  --sgc-text2:   #cbd2dd;
  --sgc-muted:   #8b93a3;
}
.sgc-inner { max-width: 760px; margin: 0 auto; padding: 0 24px; }
.sgc-heading { display: flex; align-items: center; gap: 12px; margin: 0 0 32px; }
.sgc-heading h2 { font-size: 1.35rem; font-weight: 800; color: var(--sgc-text); margin: 0; }
.sgc-count {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--sgc-primary); color: #fff; font-size: .72rem; font-weight: 700;
  border-radius: 50px; padding: 2px 9px; min-width: 24px;
}

/* Auth gate */
.sgc-auth-gate {
  display: flex; align-items: center; gap: 16px;
  background: var(--sgc-surface); border: 1px solid var(--sgc-border);
  border-radius: var(--sgc-r); padding: 20px 24px; margin-bottom: 32px;
}
.sgc-auth-gate p { flex: 1; margin: 0; color: var(--sgc-text2); font-size: .9rem; }
.sgc-auth-gate p strong { color: var(--sgc-text); }
.sgc-gate-btn {
  display: inline-flex; align-items: center; gap: 8px; background: #fff;
  border: 1px solid #dadce0; border-radius: 50px; padding: 8px 18px;
  font-size: .84rem; font-weight: 600; color: #3c4043; cursor: pointer;
  white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.2); font-family: inherit;
  transition: box-shadow .15s; flex-shrink: 0;
}
.sgc-gate-btn:hover { box-shadow: 0 2px 8px rgba(0,0,0,.28); }

/* Comment form */
.sgc-form {
  display: none; background: var(--sgc-surface); border: 1px solid var(--sgc-border);
  border-radius: var(--sgc-r); padding: 20px 22px; margin-bottom: 32px; box-shadow: var(--sgc-shadow);
}
.sgc-form-row { display: flex; gap: 14px; align-items: flex-start; }
.sgc-form-avatar {
  width: 38px; height: 38px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: var(--sgc-primary); display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .9rem;
}
.sgc-form-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sgc-form-right { flex: 1; min-width: 0; }
.sgc-textarea {
  width: 100%; border: 1.5px solid var(--sgc-border); border-radius: var(--sgc-r-sm);
  background: var(--sgc-bg); color: var(--sgc-text); font-size: .9rem; font-family: inherit;
  padding: 11px 14px; resize: vertical; min-height: 88px; outline: none;
  transition: border-color .15s, box-shadow .15s; box-sizing: border-box;
}
.sgc-textarea:focus { border-color: var(--sgc-primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.sgc-textarea::placeholder { color: var(--sgc-muted); }
.sgc-form-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.sgc-char { font-size: .77rem; color: var(--sgc-muted); }
.sgc-char.sgc-char-warn { color: #f59e0b; }
.sgc-char.sgc-char-over { color: #ef4444; }
.sgc-submit {
  background: var(--sgc-grad); color: #fff; border: none; border-radius: 50px;
  padding: 8px 22px; font-size: .85rem; font-weight: 700; cursor: pointer; font-family: inherit;
  transition: opacity .15s, transform .1s;
}
.sgc-submit:hover { opacity: .88; }
.sgc-submit:active { transform: scale(.97); }
.sgc-submit:disabled { opacity: .5; cursor: default; }

/* Comment list */
.sgc-list { display: flex; flex-direction: column; gap: 0; }
.sgc-comment {
  display: flex; gap: 14px; padding: 20px 0; border-bottom: 1px solid var(--sgc-border);
  animation: sgcFadeIn .3s ease both;
}
.sgc-comment:last-child { border-bottom: none; }
@keyframes sgcFadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.sgc-avatar {
  width: 36px; height: 36px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: var(--sgc-primary); display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .82rem;
}
.sgc-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sgc-comment-body { flex: 1; min-width: 0; }
.sgc-comment-meta { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.sgc-comment-name { font-weight: 700; font-size: .88rem; color: var(--sgc-text); }
.sgc-comment-date { font-size: .77rem; color: var(--sgc-muted); }
.sgc-comment-text {
  font-size: .9rem; color: var(--sgc-text2); line-height: 1.7;
  white-space: pre-wrap; word-break: break-word; margin: 0;
}
/* Action buttons (reply / edit / delete) */
.sgc-comment-actions { display: flex; gap: 4px; align-items: center; margin-left: auto; flex-shrink: 0; }
.sgc-action-btn {
  background: none; border: none; font-size: .72rem; color: var(--sgc-muted); cursor: pointer;
  padding: 2px 7px; border-radius: 4px; font-family: inherit;
  transition: background .12s, color .12s; white-space: nowrap;
}
.sgc-action-btn:hover     { background: var(--sgc-bg3); color: var(--sgc-primary); }
.sgc-action-btn-del:hover { background: rgba(239,68,68,.1); color: #ef4444; }

/* Replies */
.sgc-replies { margin-top: 4px; padding-left: 18px; border-left: 2px solid var(--sgc-border); }
.sgc-reply { gap: 10px; padding: 12px 0; }
.sgc-reply .sgc-avatar { width: 28px; height: 28px; font-size: .72rem; }
.sgc-reply:last-child { border-bottom: none; }

/* Inline reply / edit form */
.sgc-inline-form { margin: 8px 0 8px 50px; display: flex; gap: 10px; align-items: flex-start; }
.sgc-inline-form.sgc-edit-form { margin-left: 0; margin-top: 6px; }
.sgc-inline-form-right { flex: 1; min-width: 0; }
.sgc-textarea-sm { min-height: 64px; font-size: .86rem; }
.sgc-form-footer-sm { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.sgc-btn-cancel {
  background: none; border: 1px solid var(--sgc-border); border-radius: 50px; padding: 5px 13px;
  font-size: .78rem; color: var(--sgc-text2); cursor: pointer; font-family: inherit; transition: background .12s;
}
.sgc-btn-cancel:hover { background: var(--sgc-bg3); }
.sgc-submit-sm { padding: 5px 16px; font-size: .8rem; }

/* Skeleton */
.sgc-skel { display: flex; flex-direction: column; gap: 0; }
.sgc-skel-item { display: flex; gap: 14px; padding: 20px 0; border-bottom: 1px solid var(--sgc-border); }
.sgc-skel-circle {
  width: 36px; height: 36px; border-radius: 50%; background: var(--sgc-border);
  flex-shrink: 0; animation: sgcPulse 1.4s ease-in-out infinite;
}
.sgc-skel-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.sgc-skel-line { height: 12px; border-radius: 6px; background: var(--sgc-border); animation: sgcPulse 1.4s ease-in-out infinite; }
.sgc-skel-line:nth-child(1) { width: 40%; animation-delay: .1s; }
.sgc-skel-line:nth-child(2) { width: 85%; animation-delay: .2s; }
.sgc-skel-line:nth-child(3) { width: 65%; animation-delay: .3s; }
@keyframes sgcPulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* Empty state */
.sgc-empty { text-align: center; padding: 40px 0 24px; color: var(--sgc-muted); font-size: .9rem; }
.sgc-empty svg { margin-bottom: 12px; opacity: .4; }

/* Error toast */
.sgc-error {
  background: rgba(239,68,68,.1); color: #dc2626; border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--sgc-r-sm); padding: 10px 14px; font-size: .85rem; margin-bottom: 16px; display: none;
}

@media (max-width: 640px) {
  .sgc-section { padding: 48px 0 56px; }
  .sgc-inner   { padding: 0 16px; }
  .sgc-auth-gate { flex-direction: column; align-items: flex-start; gap: 12px; }
  .sgc-gate-btn  { width: 100%; justify-content: center; }
}
