/* File: /assets/css/comments.css
   Module: the discussion card under an article (CH_Comments, comments.php).

   One card right under the article: the heading with the count, the composer
   (the account's picture and name once signed in), the sign-in choices a guest
   gets on Post, then the comments with one level of replies on a spine, the
   same spine the Learning Center rail uses. Tokens only, so light and dark
   follow html[data-theme]; no dark panel in light mode.

   GeneratePress paints button:hover/:focus at 0,1,1; every button here
   declares colour and background on all its states. */

/* --- The GeneratePress box around comments.php becomes a thin gap ------- */
body .comments-area.comments-area,
html[data-theme] body .comments-area.comments-area {
    max-width: none;
    margin: 1.25rem 0 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
}

/* Parts that JS shows and hides carry [hidden]; a display rule below must not
   undo it (the reply bar showed empty before this). */
.ch-discuss [hidden] {
    display: none !important;
}

/* --- Card ----------------------------------------------------------------- */
.ch-discuss {
    --cm-accent: var(--ch-cta, #10B981);
    --cm-accent-text: var(--ch-cta-text, #047857);
    padding: 2rem 2.5rem 2.25rem;
    border: 1px solid var(--ch-border);
    border-radius: 16px;
    background-color: var(--ch-bg-card);
    color: var(--ch-text-main);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 32px -18px rgba(16, 185, 129, 0.25);
}

.ch-discuss-head {
    margin-bottom: 1.25rem;
}

.ch-discuss-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 0.3rem;
    font-size: 1.45rem;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.ch-discuss-count {
    min-width: 1.9rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--cm-accent) 40%, var(--ch-border));
    font-family: 'JetBrains Mono', 'Roboto Mono', monospace;
    font-size: 0.8rem;
    font-weight: 800;
    text-align: center;
    color: var(--cm-accent-text);
}

.ch-discuss-sub {
    margin: 0;
    font-size: 0.98rem;
    color: var(--ch-text-muted);
}

/* --- Composer ------------------------------------------------------------- */
.ch-cm-form {
    position: relative;
    padding: 1rem;
    border: 1px solid var(--ch-border);
    border-radius: 14px;
    background-color: var(--ch-bg-main);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ch-cm-form:focus-within {
    border-color: color-mix(in srgb, var(--cm-accent) 55%, var(--ch-border));
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--cm-accent) 14%, transparent);
}

.ch-cm-who {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
    font-size: 0.92rem;
    color: var(--ch-text-muted);
}

.ch-cm-who b {
    color: var(--ch-text-main);
    font-weight: 700;
}

.ch-cm-replying {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
    padding: 0.45rem 0.7rem;
    border-left: 3px solid var(--cm-accent);
    border-radius: 0 8px 8px 0;
    background-color: color-mix(in srgb, var(--cm-accent) 8%, transparent);
    font-size: 0.88rem;
    color: var(--ch-text-muted);
}

.ch-cm-replying b {
    color: var(--ch-text-main);
}

.ch-discuss .ch-cm-input {
    display: block;
    width: 100%;
    min-height: 96px;
    max-height: 420px;
    margin: 0;
    padding: 0.2rem 0.1rem;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    box-shadow: none;
    font: inherit;
    font-size: 1.02rem;
    line-height: 1.6;
    color: var(--ch-text-main);
}

.ch-discuss .ch-cm-input:focus {
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--ch-text-main);
}

.ch-discuss .ch-cm-input::placeholder {
    color: var(--ch-text-muted);
    opacity: 1;
}

.ch-cm-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--ch-border);
}

.ch-cm-note {
    margin-right: auto;
    font-size: 0.88rem;
    color: var(--ch-text-muted);
}

.ch-cm-note.is-ok { color: var(--cm-accent-text); }
.ch-cm-note.is-err { color: #B91C1C; }
html[data-theme="dark"] .ch-cm-note.is-err { color: #FCA5A5; }

.ch-cm-chars {
    font-family: 'JetBrains Mono', 'Roboto Mono', monospace;
    font-size: 0.78rem;
    color: var(--ch-text-muted);
}

/* The one action: emerald, every state declared (GeneratePress trap) */
.ch-discuss .ch-cm-btn,
.ch-discuss .ch-cm-btn:hover,
.ch-discuss .ch-cm-btn:focus,
.ch-discuss .ch-cm-btn:active {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 44px;
    padding: 0 1.15rem;
    border: 0;
    border-radius: 10px;
    background-color: #047857;
    color: #FFFFFF;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 8px 18px -10px rgba(4, 120, 87, 0.8);
    transition: background-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.ch-discuss .ch-cm-btn:hover {
    background-color: #065F46;
    color: #FFFFFF;
    transform: translateY(-1px);
}

.ch-discuss .ch-cm-btn:focus-visible {
    outline: 2px solid var(--cm-accent);
    outline-offset: 3px;
}

.ch-discuss .ch-cm-btn:active {
    transform: translateY(0);
}

.ch-discuss .ch-cm-btn[disabled],
.ch-discuss .ch-cm-btn[disabled]:hover {
    background-color: #047857;
    color: #FFFFFF;
    opacity: 0.6;
    cursor: progress;
    transform: none;
}

/* Text-style buttons: Reply, Cancel */
.ch-discuss .ch-cm-link,
.ch-discuss .ch-cm-link:hover,
.ch-discuss .ch-cm-link:focus,
.ch-discuss .ch-cm-reply,
.ch-discuss .ch-cm-reply:hover,
.ch-discuss .ch-cm-reply:focus {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 32px;
    padding: 0.2rem 0.5rem;
    margin-left: -0.5rem;
    border: 0;
    border-radius: 8px;
    background-color: transparent;
    color: var(--ch-text-muted);
    font: inherit;
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
}

.ch-discuss .ch-cm-link:hover,
.ch-discuss .ch-cm-reply:hover {
    background-color: color-mix(in srgb, var(--cm-accent) 10%, transparent);
    color: var(--cm-accent-text);
}

.ch-discuss .ch-cm-link:focus-visible,
.ch-discuss .ch-cm-reply:focus-visible {
    outline: 2px solid var(--cm-accent);
    outline-offset: 1px;
}

.ch-discuss .ch-cm-link { margin-left: 0; }

/* --- Sign-in choices a guest gets on Post ------------------------------- */
.ch-cm-gate {
    margin-top: 0.9rem;
    padding: 1rem 1.1rem 0.9rem;
    border: 1px solid color-mix(in srgb, var(--cm-accent) 35%, var(--ch-border));
    border-radius: 12px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--cm-accent) 9%, var(--ch-bg-card)), var(--ch-bg-card));
    animation: ch-cm-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.ch-cm-gate-title {
    margin: 0 0 0.2rem;
    font-size: 1.02rem;
    font-weight: 800;
    color: var(--ch-text-main);
}

.ch-cm-gate-text {
    margin: 0 0 0.85rem;
    font-size: 0.92rem;
    color: var(--ch-text-muted);
}

.ch-cm-gate-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
}

.ch-discuss .ch-cm-provider,
.ch-discuss .ch-cm-provider:visited {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0 0.9rem;
    border: 1px solid var(--ch-border);
    border-radius: 10px;
    background-color: var(--ch-bg-card);
    color: var(--ch-text-main);
    font-size: 0.95rem;
    font-weight: 700;
    text-decoration: none;
    transition: border-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.ch-discuss .ch-cm-provider:hover,
.ch-discuss .ch-cm-provider:focus {
    border-color: color-mix(in srgb, var(--cm-accent) 60%, var(--ch-border));
    background-color: var(--ch-bg-card);
    color: var(--ch-text-main);
    transform: translateY(-1px);
    box-shadow: 0 8px 18px -12px rgba(16, 185, 129, 0.7);
}

.ch-discuss .ch-cm-provider:focus-visible {
    outline: 2px solid var(--cm-accent);
    outline-offset: 2px;
}

.ch-cm-provider .ch-oauth-gh { display: inline-flex; color: var(--ch-text-main); }

.ch-cm-gate-fine {
    margin: 0.7rem 0 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ch-text-muted);
}

/* --- Avatars -------------------------------------------------------------- */
.ch-cm-avatar {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.ch-cm-who .ch-cm-avatar {
    width: 36px;
    height: 36px;
}

.ch-cm-avatar-initial {
    display: inline-grid;
    place-items: center;
    background: linear-gradient(135deg, #10B981, #047857);
    color: #FFFFFF;
    font-weight: 800;
    font-size: 1rem;
}

/* --- The comments ----------------------------------------------------------- */
.ch-discuss .ch-cm-list,
.ch-discuss .ch-cm-replies {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ch-discuss .ch-cm-list {
    margin-top: 1.5rem;
}

.ch-discuss .ch-cm-list > li::before,
.ch-discuss .ch-cm-list > li::after,
.ch-discuss .ch-cm-replies > li::before,
.ch-discuss .ch-cm-replies > li::after {
    content: none;
}

.ch-discuss .ch-cm {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    column-gap: 0.85rem;
    margin: 0;
    padding: 1.1rem 0;
    font-size: 1rem;
    line-height: 1.6;
    border-top: 1px solid var(--ch-border);
}

.ch-discuss .ch-cm-list > .ch-cm:first-child {
    border-top: 0;
    padding-top: 0.25rem;
}

/* Replies hang off a spine under the parent's picture */
.ch-discuss .ch-cm-replies {
    grid-column: 1 / -1;
    position: relative;
    margin: 0.6rem 0 0 19px;
    padding-left: 1.6rem;
    border-left: 2px solid color-mix(in srgb, var(--cm-accent) 35%, var(--ch-border));
}

.ch-discuss .ch-cm.is-reply {
    grid-template-columns: 32px minmax(0, 1fr);
    padding: 0.7rem 0;
    border-top: 0;
}

.ch-discuss .ch-cm.is-reply .ch-cm-avatar {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
}

.ch-cm-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.6rem;
    margin-bottom: 0.15rem;
}

.ch-cm-name {
    font-weight: 800;
    color: var(--ch-text-main);
}

.ch-cm-badge,
.ch-cm-wait {
    padding: 0.05rem 0.5rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.ch-cm-badge {
    background-color: color-mix(in srgb, var(--cm-accent) 14%, transparent);
    color: var(--cm-accent-text);
}

.ch-cm-wait {
    background-color: rgba(245, 158, 11, 0.14);
    color: #92400E;
}

html[data-theme="dark"] .ch-cm-wait { color: #FCD34D; }

.ch-cm-time {
    font-size: 0.82rem;
    color: var(--ch-text-muted);
}

.ch-cm-text p {
    margin: 0 0 0.55rem;
    font-size: 1rem;
    overflow-wrap: anywhere;
}

.ch-cm-text p:last-child { margin-bottom: 0.25rem; }

.ch-discuss .ch-cm.is-pending .ch-cm-text { opacity: 0.8; }

.ch-discuss .ch-cm.is-new {
    animation: ch-cm-flash 1.6s ease-out;
}

.ch-cm-empty {
    margin: 1.25rem 0 0;
    font-size: 0.95rem;
    color: var(--ch-text-muted);
}

@keyframes ch-cm-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: none; }
}

@keyframes ch-cm-flash {
    0% { background-color: color-mix(in srgb, var(--cm-accent) 16%, transparent); }
    100% { background-color: transparent; }
}

/* --- Phones ------------------------------------------------------------------ */
@media (max-width: 600px) {
    .ch-discuss {
        padding: 1.4rem 1.1rem 1.5rem;
        border-radius: 14px;
    }
    .ch-discuss-title { font-size: 1.25rem; }
    .ch-cm-form { padding: 0.85rem; }
    .ch-cm-gate-row { grid-template-columns: 1fr; }
    .ch-cm-actions { flex-wrap: wrap; }
    .ch-cm-note { flex-basis: 100%; order: 2; }
    .ch-discuss .ch-cm-btn { width: 100%; justify-content: center; }
    .ch-discuss .ch-cm-replies { margin-left: 15px; padding-left: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    .ch-cm-gate,
    .ch-discuss .ch-cm.is-new { animation: none; }
    .ch-discuss .ch-cm-btn,
    .ch-discuss .ch-cm-provider { transition: none; }
    .ch-discuss .ch-cm-btn:hover,
    .ch-discuss .ch-cm-provider:hover { transform: none; }
}
