/* =================================================================
   Comments widget — shared by Feed, Blog, Gallery photos/uploads,
   Forum, and Downloads. Built on shared design tokens (see
   themes/*/style.css). Composer sits inline after the comment list.
   ================================================================= */

.cm-section {
    margin-top: 1rem; padding: .5rem .55rem .55rem;
    background: color-mix(in srgb, var(--indigo) 5%, var(--paper)); border: 1px solid color-mix(in srgb, var(--indigo) 16%, var(--border));
    border-radius: 10px;
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,.05));
}
.cm-heading-row {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: var(--shadow); padding: .45rem .7rem; margin-bottom: .4rem;
}
.cm-heading-row:has(+ .cm-empty-card), .cm-heading-row:has(+ .cm-list) { border-bottom: none; border-radius: 8px 8px 0 0; margin-bottom: 0; }
.cm-heading { display: flex; align-items: center; gap: .4rem; margin: 0; font-size: .9rem; font-weight: 800; }
.cm-heading-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 6px; font-size: .72rem;
    background: color-mix(in srgb, var(--indigo) 10%, transparent); color: var(--indigo);
}
.cm-heading-count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 18px; padding: 0 .35rem;
    background: var(--paper); color: var(--ink-soft); border-radius: 999px;
    font-size: .72rem; font-weight: 800;
}

/* ---------- Empty state ------------------------------------------- */
.cm-empty-card {
    background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 8px 8px;
    padding: 1.5rem 1rem; text-align: center;
}
.cm-empty-icon { font-size: 2rem; opacity: .3; display: block; margin-bottom: .35rem; filter: grayscale(1); }
.cm-empty-text { font-size: .86rem; font-weight: 700; color: var(--ink-soft); }

.cm-list {
    display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 8px 8px;
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,.04));
    margin-bottom: .45rem; overflow: hidden;
}
.cm-thread {
    display: flex; flex-direction: column;
    padding: .45rem .65rem;
    border-bottom: 1px solid var(--border);
}
.cm-thread:last-child { border-bottom: none; }

.cm-item { display: flex; gap: .5rem; align-items: flex-start; }
.cm-item-avatar-col { flex-shrink: 0; }
.cm-item-main { flex: 1; min-width: 0; }

.cm-avatar-ring {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.cm-avatar {
    display: flex; width: 100%; height: 100%; border-radius: 50%; overflow: hidden;
    background: var(--indigo); color: #fff; align-items: center; justify-content: center;
    font-weight: 700; font-size: .76rem; text-decoration: none;
}
.cm-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.cm-bubble { max-width: 100%; }
.cm-meta { display: flex; align-items: center; gap: .35rem; }

/* Kebab menu — Reply / Edit / Delete, pushed to the far right of the header row */
.cm-menu { position: relative; margin-left: auto; flex-shrink: 0; }
.cm-menu-btn {
    width: 26px; height: 26px; border-radius: 50%; border: none; background: none;
    color: var(--ink-soft); font-size: 1rem; font-weight: 800; line-height: 1;
    cursor: pointer; transition: background .12s ease, color .12s ease;
}
.cm-menu-btn:hover, .cm-menu.is-open .cm-menu-btn { background: var(--paper); color: var(--ink); }
.cm-menu-dropdown {
    position: absolute; top: calc(100% + 4px); right: 0; z-index: 60;
    min-width: 140px; padding: .3rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 10px 28px -12px rgba(0,0,0,.25);
}
.cm-menu-dropdown button, .cm-menu-dropdown form { display: block; width: 100%; margin: 0; }
.cm-menu-dropdown button {
    padding: .5rem .6rem; border-radius: 5px; border: none; background: none;
    font-family: inherit; font-size: .86rem; font-weight: 600; text-align: left;
    color: var(--ink); cursor: pointer;
}
.cm-menu-dropdown button:hover { background: var(--paper); }
.cm-menu-danger { color: var(--danger) !important; }
.cm-menu-danger:hover { background: rgba(214,69,90,.1) !important; }
.cm-author { font-size: .86rem; font-weight: 800; color: var(--indigo); text-decoration: none; text-transform: none; }
.cm-author:hover { text-decoration: underline; }
.cm-text { margin: .2rem 0 0; white-space: pre-wrap; font-size: .86rem; line-height: 1.42; color: var(--ink); }

.cm-attachment {
    display: block; margin-top: .5rem; border-radius: 8px; overflow: hidden;
    max-width: 260px; background: var(--paper); border: 1px solid var(--border);
}
.cm-attachment img { width: 100%; display: block; max-height: 320px; object-fit: contain; }

/* Bottom row: time (left) · like+count / reply-toggle (right) */
.cm-foot-row { display: flex; align-items: center; justify-content: space-between; margin-top: .3rem; gap: .5rem; }
.cm-time { font-size: .74rem; color: var(--ink-soft); }
.cm-foot-actions { display: flex; align-items: center; gap: .65rem; }
.cm-like-btn {
    display: inline-flex; align-items: center; gap: .28rem; background: none; border: none;
    padding: 0; font-family: inherit; font-size: .78rem; font-weight: 700; color: var(--ink-soft); cursor: pointer;
    transition: color .12s ease;
}
.cm-like-btn:hover { color: var(--ink); }
.cm-like-btn.is-liked { color: var(--indigo); }
.cm-toggle-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border);
    background: var(--surface); color: var(--ink-soft); cursor: pointer; font-size: .74rem;
    transition: transform .15s ease, background .12s ease;
}
.cm-toggle-btn.is-collapsed { transform: rotate(180deg); }
.cm-toggle-btn:hover { background: var(--paper); }

/* Reply thread — indented, with a connecting line on the left */
.cm-replies {
    display: flex; flex-direction: column; gap: .4rem;
    margin: .4rem 0 0 1.1rem; padding-left: .75rem;
    border-left: 2px solid var(--border);
    transition: max-height .2s ease;
}
.cm-replies.is-collapsed { display: none; }
.cm-item-reply .cm-avatar-ring { width: 26px; height: 26px; }
.cm-item-reply .cm-author { font-size: .8rem; }
.cm-item-reply .cm-text { font-size: .82rem; }

/* Reply / edit inline forms */
.cm-reply-form, .cm-edit-form {
    display: none; align-items: flex-start; gap: .5rem; margin-top: .45rem; max-width: 520px;
}
.cm-reply-form.is-open { display: flex; }
.cm-edit-form.is-open { display: flex; flex-direction: column; align-items: flex-start; }
.cm-reply-form textarea, .cm-edit-form textarea {
    flex: 1; padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 8px;
    background: var(--paper); font-family: inherit; font-size: .86rem; resize: vertical;
    transition: border-color .12s ease;
}
.cm-reply-form textarea:focus, .cm-edit-form textarea:focus {
    outline: none; border-color: var(--indigo);
}
.cm-reply-form button, .cm-edit-form button { flex-shrink: 0; }

.cm-empty { padding: 1rem 0; text-align: center; }

.cm-login-note { font-size: .82rem; color: var(--ink-soft); margin-top: .5rem; text-align: center; padding: .7rem; }
.cm-login-note a { font-weight: 600; color: var(--indigo); }

/* =================================================================
   Composer — sits inline right after the comment list, in normal
   document flow (no longer pinned/sticky to the viewport bottom).
   ================================================================= */
.cm-sticky-bar {
    margin-top: .6rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,.05));
}

.cm-sticky-content { padding: .45rem .6rem; }

.cm-attach-preview {
    display: none; align-items: center; gap: .55rem; margin-bottom: .45rem;
    background: var(--paper); border: 1px solid var(--border); border-radius: 8px;
    padding: .35rem .55rem; max-width: 260px;
}
.cm-attach-preview.is-visible { display: flex; }
.cm-attach-preview img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.cm-attach-preview-name { font-size: .76rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.cm-attach-remove {
    flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%; border: none;
    background: rgba(0,0,0,.08); color: var(--ink); cursor: pointer; font-size: .74rem;
}
.cm-attach-remove:hover { background: rgba(0,0,0,.16); }

.cm-composer-row { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.cm-composer-avatar {
    display: flex; width: 32px; height: 32px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
    background: var(--indigo); color: #fff; align-items: center; justify-content: center;
    font-weight: 700; font-size: .78rem; box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.cm-composer-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.cm-composer-field {
    flex: 1; display: flex; align-items: center; gap: .35rem;
    background: var(--paper); border: 1px solid var(--border); border-radius: 20px;
    padding: .38rem .5rem .38rem .85rem; min-width: 0;
    transition: border-color .12s ease, background .12s ease;
}
.cm-composer-field:focus-within { border-color: var(--indigo); background: var(--surface); }
.cm-composer-field textarea {
    flex: 1; min-width: 0; border: none; background: none; resize: none;
    font-family: inherit; font-size: .88rem; line-height: 1.3; padding: .22rem 0;
    max-height: 100px;
}
.cm-composer-field textarea:focus { outline: none; }
.cm-icon-btn {
    flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 50%; border: none; background: none;
    color: var(--ink-soft); cursor: pointer; font-size: 1rem; transition: background .12s ease;
}
.cm-icon-btn:hover { background: rgba(0,0,0,.06); }
.cm-attach-btn { transform: rotate(45deg); }

/* Used instead of the [hidden] attribute on #cmAttachInput specifically —
   some Chrome-on-Android versions show their own small native "selected
   file" thumbnail hint near file inputs hidden via [hidden]/display:none,
   rendered by the browser itself rather than this page. Standard
   visually-hidden technique (zero size + clipped, but not display:none)
   avoids that browser-level behavior while staying fully invisible. */
.cm-visually-hidden-input {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* The emoji picker inserts its own .emoji-trigger button into #cmEmojiSlot's
   position — restyle it here to match the pill's icon buttons instead of
   its default square/bordered look. */
.cm-composer-field .emoji-trigger {
    width: 26px; height: 26px; border: none; background: none; border-radius: 50%;
    font-size: .96rem; color: var(--ink-soft); flex-shrink: 0;
}
.cm-composer-field .emoji-trigger:hover { background: rgba(0,0,0,.06); }

.cm-send-btn {
    flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer;
    background: var(--indigo); color: #fff;
    font-size: .98rem; box-shadow: 0 3px 10px -3px color-mix(in srgb, var(--indigo) 60%, transparent);
    transition: transform .1s ease, background .12s ease;
}
.cm-send-btn:hover { background: var(--indigo-deep); transform: scale(1.06); }
.cm-send-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

@media (max-width: 480px) {
    .cm-replies { margin-left: .8rem; padding-left: .7rem; }
    .cm-sticky-content { padding: .55rem .75rem; }
    .cm-attachment { max-width: 200px; }
}
