/**
 * Chat-Style Comments
 * Contained chat-style design, list + chat view
 */

.chat-comments {
    margin-top: 2rem;
    padding: 1.25rem;
    font-size: 14px;
    background: #f8f9fa;
    border: 1px solid #e8e9ea;
    border-radius: 12px;
}

.chat-comments-closed {
    color: #666;
    font-style: italic;
}

.chat-comments-list {
    list-style: none;
    margin: 0 0 1.25rem 0;
    padding: 0;
}

/* List view (inbox): thread rows */
.chat-comment--root .chat-comment-list-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #e8e9ea;
    cursor: default;
}

.chat-comment--root .chat-comment-list-row:last-child {
    border-bottom: none;
}

.chat-comment-list-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-comment-list-preview {
    font-size: 13px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-comment-list-meta {
    font-size: 11px;
    color: #999;
}

.chat-comment-join-link--list {
    flex-shrink: 0;
    font-size: 13px;
    color: #007bff;
    text-decoration: none;
    cursor: pointer;
}

.chat-comment-join-link--list:hover {
    text-decoration: underline;
}

/* In list view: hide full chat for roots */
.chat-comment--root:not(.chat-comments-active-thread) .chat-comment-inner,
.chat-comment--root:not(.chat-comments-active-thread) .chat-comment-replies-section {
    display: none !important;
}

/* In chat view: HIDE all roots except the active one - messaging pane only */
.chat-comments--thread-active .chat-comment--root:not(.chat-comments-active-thread) {
    display: none !important;
}

/* In chat view: hide list row for active thread */
.chat-comments--thread-active .chat-comments-active-thread .chat-comment-list-row {
    display: none !important;
}

/* Hide Leave Chat in chat area - we use the banner below */
.chat-comments--thread-active .chat-comment-join-link--in-section {
    display: none !important;
}

.chat-comment {
    margin-bottom: 0;
}

.chat-comment:last-child {
    margin-bottom: 0;
}

.chat-comment-inner {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    width: fit-content;
    max-width: 85%;
}

.chat-comments--thread-active .chat-comment-inner {
    margin-bottom: 12px;
}

.chat-comment-avatar {
    flex-shrink: 0;
}

.chat-comment-avatar-img {
    border-radius: 50%;
    display: block;
}

.chat-comment-body {
    flex: 1 1 auto;
    min-width: 0;
}

.chat-comment-bubble {
    display: inline-block;
    max-width: 100%;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Their messages: avatar + bubble together on the LEFT */
.chat-comment:not(.chat-comment--mine) > .chat-comment-inner {
    margin-right: auto;
}

/* My messages: [bubble] [avatar] on the RIGHT, like SMS - avatar to the right of the message */
.chat-comment--mine > .chat-comment-inner {
    margin-left: auto;
    margin-right: 0;
    flex-direction: row-reverse;
}

.chat-comment--mine > .chat-comment-inner .chat-comment-body {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.chat-comment--mine > .chat-comment-inner .chat-comment-bubble {
    border-color: #e0e0e0;
}

.chat-comment-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}

.chat-comment-author {
    font-weight: 600;
    color: #333;
}

.chat-comment-time {
    font-size: 12px;
    color: #999;
}

.chat-comment-content {
    line-height: 1.5;
}

.chat-comment-content pre {
    margin: 8px 0;
    padding: 12px;
    background: #f5f5f5;
    border-radius: 6px;
    overflow-x: auto;
    text-align: left;
    max-width: 100%;
}

.chat-comment-content code {
    font-family: ui-monospace, monospace;
    font-size: 13px;
}

.chat-comment-actions {
    margin-top: 6px;
    padding-top: 4px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.chat-comment-like {
    background: none !important;
    border: none;
    cursor: pointer;
    font-size: 15px;
    color: #666;
    padding: 2px 6px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 28px;
}

.chat-comment-like:hover:not(:disabled):not(.chat-comment-like--disabled),
.chat-comment-like:active {
    color: #333;
    background: none !important;
}

.chat-comment-like--disabled {
    cursor: default;
    opacity: 0.7;
}

.chat-comment-like--liked {
    color: #007bff;
}

.chat-comment-replies-section {
    margin-top: 8px;
    padding-top: 8px;
}

.chat-comment-join-link--in-section {
    display: inline-block;
    font-size: 13px;
    color: #007bff;
    text-decoration: none;
    cursor: pointer;
    margin-bottom: 8px;
}

.chat-comment-join-link--in-section:hover {
    text-decoration: underline;
}

.chat-comments-children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chat-comments-children--collapsed {
    display: none !important;
}

.chat-comments-children .chat-comment {
    margin-bottom: 12px;
}

.chat-comments-children .chat-comment:last-child {
    margin-bottom: 0;
}

.chat-comments--thread-active .chat-comments-children .chat-comment-inner {
    margin-bottom: 0;
}

/* Messaging pane: full-width chat when joined */
.chat-comments--thread-active .chat-comments-list {
    margin-bottom: 0;
    padding: 0;
}

.chat-comments--thread-active .chat-comments-active-thread {
    display: block !important;
}

.chat-comments--thread-active .chat-comments-active-thread .chat-comment-replies-section {
    display: block !important;
}

.chat-comments--thread-active .chat-comments-active-thread .chat-comment-replies-section {
    margin-left: 0;
}

.chat-comments--thread-active .chat-comments-active-thread .chat-comments-children {
    display: block !important;
}

/* Active chat banner - above the input */
.chat-comments--thread-active .chat-comments-form-wrap {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e8e9ea;
}

.chat-comments-active-banner {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 12px;
    background: #e8f4fd;
    border: 1px solid #b8daff;
    border-radius: 8px;
}

.chat-comments--thread-active .chat-comments-active-banner {
    display: flex !important;
}

.chat-comments-active-banner-text {
    font-size: 14px;
    color: #333;
}

.chat-comment-leave-group-btn {
    flex-shrink: 0;
    font-size: 13px;
    color: #007bff;
    text-decoration: none;
    cursor: pointer;
}

.chat-comment-leave-group-btn:hover {
    text-decoration: underline;
}

/* Form */
.chat-comments-fields {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-comment-author-input,
.chat-comment-email-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
}

.chat-comments-toolbar-wrap {
    position: relative;
}

.chat-comments-toolbar {
    display: flex;
    gap: 4px;
}

.chat-comment-emoji-btn-icon {
    display: block;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.chat-comment-toolbar-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #666;
    background: transparent !important;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
}

.chat-comment-toolbar-btn:hover,
.chat-comment-toolbar-btn:active {
    color: #333;
    background: transparent !important;
}

.chat-comments-emoji-picker {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 4px;
    z-index: 1000;
    min-width: 260px;
    max-height: 260px;
    overflow-y: auto;
    padding: 12px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    font-size: 24px;
}

.chat-comments-emoji-picker--open {
    display: grid !important;
}

.chat-comment-emoji-item {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-family: apple-color-emoji, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twitter Color Emoji", sans-serif;
    font-variant-emoji: emoji;
    color: inherit;
    line-height: 1;
    background: none !important;
    border: none;
    border-radius: 0;
    cursor: pointer;
    padding: 2px;
}

.chat-comment-emoji-item:hover,
.chat-comment-emoji-item:active {
    background: none !important;
}

.chat-comment-emoji-char {
    font-family: apple-color-emoji, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twitter Color Emoji", sans-serif;
    font-size: inherit;
    line-height: 1;
    font-variant-emoji: emoji;
}

.chat-comments-input-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: flex-start;
}

.chat-comments-input-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.chat-comment-content-input {
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    resize: vertical;
    min-height: 40px;
    max-height: 120px;
}

.chat-comments-code-block-wrap {
    display: none;
    flex-direction: column;
    gap: 4px;
}

.chat-comments-code-block-wrap[aria-hidden="false"] {
    display: flex !important;
}

.chat-comments-code-block-label {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.chat-comment-code-block-input {
    font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
    padding: 10px 12px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    resize: vertical;
    min-height: 80px;
    max-height: 200px;
}

.chat-comments-submit {
    padding: 8px 16px;
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
}

.chat-comments-submit:hover,
.chat-comments-submit:active {
    background: #0069d9;
}

.chat-comments-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-comments-notice {
    margin-top: 8px;
    font-size: 13px;
}

.chat-comments-notice--error {
    color: #dc3545;
}

.chat-comments-notice--success {
    color: #28a745;
}

.chat-comments-login {
    margin-top: 1rem;
    color: #666;
}

/* Dark mode */
.dark-mode .chat-comments {
    background: var(--dark-bg-secondary, #1e1e1e);
    border-color: var(--dark-border, #333);
}

.dark-mode .chat-comment-bubble {
    background: var(--dark-bg-tertiary, #2a2a2a);
    border-color: var(--dark-border, #333);
}

.dark-mode .chat-comment-author {
    color: var(--dark-text-primary, #fff);
}

.dark-mode .chat-comment-time {
    color: var(--dark-text-secondary, #999);
}

.dark-mode .chat-comment-like,
.dark-mode .chat-comment-like:hover:not(:disabled):not(.chat-comment-like--disabled),
.dark-mode .chat-comment-like:active {
    color: var(--dark-accent);
    background: transparent !important;
}

.dark-mode .chat-comment-like .chat-comment-like-count {
    color: var(--dark-accent);
}

.dark-mode .chat-comment-like--liked {
    color: var(--dark-accent);
}

.dark-mode .chat-comment-toolbar-btn {
    color: var(--dark-accent);
    border-color: var(--dark-border);
    background: transparent !important;
}

.dark-mode .chat-comment-toolbar-btn:hover,
.dark-mode .chat-comment-toolbar-btn:active {
    color: var(--dark-accent);
    background: transparent !important;
}

.dark-mode .chat-comments-emoji-picker {
    background: var(--dark-bg-secondary);
    border-color: var(--dark-border);
}

.dark-mode .chat-comment-emoji-item:hover,
.dark-mode .chat-comment-emoji-item:active {
    background: none !important;
}

.dark-mode .chat-comment-content pre {
    background-color: var(--dark-bg-tertiary);
}

.dark-mode .chat-comments-code-block-label {
    color: var(--dark-text-secondary);
}

.dark-mode .chat-comment-code-block-input {
    background: var(--dark-bg-tertiary);
    border-color: var(--dark-border);
    color: var(--dark-text-primary);
}

.dark-mode .chat-comments--thread-active .chat-comments-form-wrap {
    border-top-color: var(--dark-border);
}

.dark-mode .chat-comments-active-banner {
    background: rgba(255, 193, 7, 0.15);
    border-color: var(--dark-accent);
}

.dark-mode .chat-comments-active-banner-text {
    color: var(--dark-text-primary);
}

.dark-mode .chat-comment-leave-group-btn {
    color: var(--dark-accent);
}
