/* ===========================================
   Message Components
   =========================================== */

/* Message List */
.msg-list {
    display: flex;
    flex-direction: column;
}

.msg-list.with-dividers .msg-item {
    border-bottom: 1px solid var(--border-light);
}

.msg-list.with-dividers .msg-item:last-child {
    border-bottom: none;
}

/* Message Item */
.msg-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.35rem 0.75rem;
    border-radius: 0px;
    transition: background 0.15s;
    position: relative;
    cursor: pointer;
}

.msg-item:hover {
    background: var(--surface);
}

.msg-item.compact {
    padding: 0.4rem 0.5rem;
    gap: 0.5rem;
}

.msg-item.clickable {
    /* cursor: pointer inherited from .msg-item */
}

/* Status styles */
.msg-item.deleted {
    background: var(--c-danger-ghost);
    border-left: 3px solid var(--c-danger);
}

.msg-item.deleted.has-incident {
    background: var(--c-warning-ghost);
    border-left: 3px solid var(--c-warning);
}

/* Avatar */
.msg-avatar-link {
    text-decoration: none;
    flex-shrink: 0;
}

.msg-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: var(--c-secondary);
    color: var(--c-text-on-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    text-decoration: none;
    transition: filter 0.15s;
}

img.msg-avatar {
    object-fit: cover;
}

/* ===========================================
   Canonical user-identity cluster (user_cluster macro)
   The ONE way to render a user: avatar + name + @handle + platform icon.
   =========================================== */
.user-cluster {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    vertical-align: middle;
}

.user-cluster-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.user-cluster-link:hover .user-cluster-name {
    color: var(--c-secondary);
}

.user-cluster-avatar {
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--c-secondary);
    color: var(--c-text-on-dark);
    font-weight: 600;
    line-height: 1;
}

.user-cluster-link:hover .user-cluster-avatar {
    filter: brightness(1.2);
}

.user-cluster-meta {
    display: inline-flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.2;
}

.user-cluster-name {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-cluster-handle {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-cluster-sm .user-cluster-avatar { width: 24px; height: 24px; font-size: 0.65rem; }
.user-cluster-sm .user-cluster-name { font-size: 0.8rem; }
.user-cluster-md .user-cluster-avatar { width: 32px; height: 32px; font-size: 0.8rem; }
.user-cluster-md .user-cluster-name { font-size: 0.875rem; }
.user-cluster-lg .user-cluster-avatar { width: 40px; height: 40px; font-size: 0.95rem; }
.user-cluster-lg .user-cluster-name { font-size: 1rem; }

.user-cluster .platform-icon-inline {
    flex-shrink: 0;
    margin-left: 0.15rem;
}

.msg-avatar:hover,
.msg-avatar-link:hover .msg-avatar {
    filter: brightness(1.2);
}

.msg-item.compact .msg-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 0.75rem;
}

/* Platform Icon - positioned at right corner */
.msg-platform {
    display: flex;
    align-items: flex-start;
    padding-top: 0.25rem;
    margin-left: auto;
    flex-shrink: 0;
}

.platform-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    opacity: 0.6;
}

.msg-item:hover .platform-icon {
    opacity: 1;
}

.platform-icon.telegram {
    fill: var(--platform-telegram);
}

.platform-icon.discord {
    fill: var(--platform-discord);
}

.platform-icon-inline {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    opacity: 0.85;
}

.msg-item.compact .platform-icon {
    width: 24px;
    height: 24px;
}

/* Body */
.msg-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

/* Header */
.msg-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.msg-user {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
    text-decoration: none;
}

.msg-user:hover {
    color: var(--c-secondary);
}

.msg-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.msg-channel {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Message text — list view (truncated) */
.msg-text {
    font-size: 0.85rem;
    color: var(--text-body);
    line-height: 1.4;
    text-decoration: none;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Message text — detail page (full) */
.message-text {
    font-size: 0.85rem;
    color: var(--text-body);
    line-height: 1.4;
    word-break: break-word;
}

.msg-text.expanded {
    -webkit-line-clamp: unset;
    display: block;
}

.msg-expand {
    display: none;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    font-size: 1.05rem;
    line-height: 1;
    width: 100%;
    text-align: center;
}

.msg-expand:hover {
    color: var(--text-primary);
    background: var(--surface);
    border-radius: 4px;
}

.msg-expand.visible {
    display: block;
}

.msg-text:hover {
    color: var(--text-primary);
}

.message-box summary {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.msg-text.strikethrough {
    text-decoration: line-through;
    color: var(--text-muted);
}

.message-text.empty {
    color: var(--text-muted);
    font-style: italic;
}

/* Quoted message */
.msg-quote {
    background: var(--surface-alt);
    /* border-left: 3px solid var(--border); */
    padding: 0.35rem 0.5rem;
    margin-bottom: 0.35rem;
    border-radius: 0 4px 4px 0;
    font-size: 0.8rem;
}

.msg-quote-author {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.msg-quote-text {
    color: var(--text-muted);
    margin-top: 0.15rem;
}

/* Media info */
.msg-media {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.5rem;
    background: var(--surface-hover);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.msg-media-icon {
    font-size: 0.85rem;
}

/* Action Menu (⋮ button + popover) */
.msg-action-menu {
    display: flex;
    align-items: flex-start;
    padding-top: 0.25rem;
    flex-shrink: 0;
    position: relative;
}

.action-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.4rem;
    line-height: 1;
    width: 28px;
    height: 28px;
    padding: 0;
    color: var(--text-muted);
    transition: all 0.15s;
}

.action-trigger:hover {
    background: var(--surface);
    color: var(--text-body);
}

.action-popover {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--c-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow-popover);
    z-index: 30;
    min-width: 140px;
    padding: 0.25rem 0;
}

.action-popover.show {
    display: block;
}

.action-popover-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--text-body);
    transition: background 0.1s;
}

.action-popover-btn:hover {
    background: var(--surface);
}

.action-popover-btn.delete:hover {
    background: var(--c-danger-soft);
    color: var(--c-danger-dim);
}

.action-popover-btn.mute:hover {
    background: var(--c-warning-soft);
    color: var(--c-warning-dim);
}

.action-popover-btn.ban:hover {
    background: var(--c-danger-soft);
    color: var(--c-danger-dim);
}

.action-popover-sub {
    position: relative;
}

.action-sub-options {
    display: none;
    padding-left: 0.5rem;
}

.action-sub-options.show {
    display: block;
}

.action-sub-options button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.3rem 0.75rem;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background 0.1s;
}

.action-sub-options button:hover {
    background: var(--c-warning-soft);
    color: var(--c-warning-dim);
}

/* Mute duration picker on incident detail */
.mute-picker {
    position: relative;
    display: inline-block;
}

.mute-picker-options {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 10;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    min-width: 8rem;
    padding: 0.25rem 0;
    box-shadow: var(--shadow-md);
    margin-top: 0.25rem;
}

.mute-picker-options.show {
    display: block;
}

.mute-picker-options button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--text-primary);
}

.mute-picker-options button:hover {
    background: var(--c-warning-soft);
}

/* Platform Color Tinting */
.msg-item[data-platform="telegram"] {
    background: color-mix(in srgb, var(--platform-telegram), transparent 94%);
}
.msg-item[data-platform="discord"] {
    background: color-mix(in srgb, var(--platform-discord), transparent 94%);
}
.msg-item[data-platform="telegram"]:hover {
    background: color-mix(in srgb, var(--platform-telegram), transparent 88%);
}
.msg-item[data-platform="discord"]:hover {
    background: color-mix(in srgb, var(--platform-discord), transparent 88%);
}

/* Category Squares */
.msg-categories {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    padding-top: 0.25rem;
    flex-shrink: 0;
    position: relative;
    cursor: pointer;
}

/* Category Legend Popover */
.cat-legend {
    display: none;
    position: absolute;
    right: 100%;
    top: 0;
    background: var(--c-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.5rem;
    box-shadow: var(--shadow-popover);
    white-space: nowrap;
    z-index: 20;
    margin-right: 0.35rem;
}

.msg-categories:hover .cat-legend {
    display: block;
}

.cat-legend-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--text-body);
    padding: 0.15rem 0;
}

.cat-legend-row.dim {
    opacity: 0.3;
}

/* Chat History Page - Condensed messages */
.chat-history-page .msg-item {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
}

/* Highlight the focused message inside Chat Context on message-detail page. */
.msg-context-focused {
    background: var(--c-info-ghost);
    border-left: 3px solid var(--c-info);
}
.msg-context-focused .msg-item { background: transparent; }

.chat-history-page .msg-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 0.75rem;
}

.chat-history-page .msg-text {
    line-height: 1.3;
}
.cat-dot {
    width: 7px;
    height: 7px;
    border-radius: 2px;
    flex-shrink: 0;
}
.cat-dot.question { background: var(--c-info); }
.cat-dot.swearing { background: var(--c-warning); }
.cat-dot.technical { background: var(--c-special); }
.cat-dot.social { background: color-mix(in srgb, var(--c-info), var(--c-muted) 50%); }
.cat-dot.meme { background:color-mix(in srgb, var(--c-success), var(--c-info) 50%); }
.cat-dot.sarcastic { background:color-mix(in srgb, var(--c-warning), var(--c-muted) 50%); }
.cat-dot.shilling { background: var(--c-secondary); }
.cat-dot.fud { background:color-mix(in srgb, var(--c-warning), var(--c-danger) 50%); }
.cat-dot.pos-positive { background: var(--c-success); }
.cat-dot.pos-neutral { background: var(--c-muted); }
.cat-dot.pos-negative { background: var(--c-danger); }

.action-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-body);
    transition: all 0.15s;
}

.action-btn:hover {
    transform: translateY(-1px);
}

.action-btn.delete:hover {
    background: var(--c-danger-soft);
    border-color: var(--c-danger);
    color: var(--c-danger-dim);
}

.action-btn.mute:hover {
    background: var(--c-warning-soft);
    border-color: var(--c-warning);
    color: var(--c-warning-dim);
}

.action-btn.ban:hover {
    background: var(--c-danger-soft);
    border-color: var(--c-danger);
    color: var(--c-danger-dim);
}

/* Deletion Info */
.deletion-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.deleted-badge {
    display: inline-block;
    background: var(--c-danger);
    color: var(--c-text-on-dark);
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-weight: bold;
}

.deleted-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* User Profile in Message */
.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-profile > .user-status {
    margin-left: auto;
    margin-top: 0;
    flex-shrink: 0;
}

.user-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--c-primary-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--c-primary-dim);
    flex-shrink: 0;
}

img.user-avatar {
    object-fit: cover;
}

.user-info h2 {
    margin: 0;
    font-size: 1.15rem;
}

.user-info .username {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.user-info .user-dates,
.user-info-detail .user-dates {
    color: var(--text-muted);
    font-size: 0.75rem;
    display: block;
    margin-top: 0.15rem;
}

.user-info-detail {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name-link {
    color: var(--c-secondary);
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: 600;
}

.user-name-link:hover {
    text-decoration: underline;
}

.user-meta-row {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.user-status {
    margin-top: 0.5rem;
}

.status-expires {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 0.5rem;
}

/* Reaction Pills (message detail page) */
.reactions-display {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.reaction-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--surface-alt);
    border: 1px solid var(--border-light);
    border-radius: 999px;
    padding: 0.3rem 0.6rem;
    cursor: default;
    position: relative;
    transition: border-color 0.15s;
}

.reaction-pill:hover {
    border-color: var(--border);
}

.reaction-emoji {
    font-size: 1.15rem;
    line-height: 1;
}

.reaction-pill .reaction-count {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.reaction-users-popover {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--c-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.5rem;
    box-shadow: var(--shadow-popover);
    white-space: nowrap;
    z-index: 20;
    margin-bottom: 0.35rem;
    min-width: 100px;
}

/* Hover bridge: keeps the popover open while the cursor crosses the gap
   between the chip/pill and the popover (no flicker). */
.reaction-users-popover::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 0.45rem;
}

.reaction-pill:hover .reaction-users-popover,
.reaction-chip:hover .reaction-users-popover {
    display: block;
}

.reaction-user-row {
    padding: 0.15rem 0;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.reaction-user-row a {
    color: var(--text-primary);
    text-decoration: none;
}

.reaction-user-row a:hover {
    color: var(--c-secondary);
    text-decoration: underline;
}

/* ===========================================
   User Stat Pills (incident detail user card)
   =========================================== */

.user-stat-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.stat-pill {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.stat-pill--neutral {
    background: var(--c-neutral-soft);
    color: var(--text-secondary);
}

.stat-pill--clean {
    background: var(--c-success-soft);
    color: var(--c-success-dim);
}

.stat-pill--warn {
    background: var(--c-warning-soft);
    color: var(--c-warning-dim);
}

.stat-pill--danger {
    background: var(--c-danger-soft);
    color: var(--c-danger-dim);
}

.stat-pill--positive {
    background: var(--c-success-soft);
    color: var(--c-success-dim);
}

.stat-pill--negative {
    background: var(--c-danger-soft);
    color: var(--c-danger-dim);
}

/* TASK-241: 'forgiven' counter — calmer than warn, distinct from clean. */
.stat-pill--info {
    background: var(--c-info-soft, var(--c-neutral-soft));
    color: var(--c-info-dim, var(--text-secondary));
}

/* TASK-241: incident-state banner shown above the actions card on incident detail. */
.incident-state-banner {
    margin: 0.75rem 0;
    padding: 0.6rem 0.85rem;
    border-radius: 6px;
    font-size: 0.9rem;
    line-height: 1.4;
}
.incident-state-banner--forgiven {
    background: var(--c-success-soft);
    color: var(--c-success-dim);
}
.incident-state-banner--collony_mistake {
    background: var(--c-warning-soft);
    color: var(--c-warning-dim);
}
.incident-state-feedback {
    margin-top: 0.35rem;
    font-style: italic;
    opacity: 0.85;
}

/* ===========================================
   Sentiment Bar (incident detail user card)
   =========================================== */

.sentiment-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.sentiment-bar__label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.sentiment-bar__track {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: var(--surface-alt);
    position: relative;
}

.sentiment-bar__fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.sentiment-bar__fill--positive {
    background: var(--c-success);
}

.sentiment-bar__fill--negative {
    background: var(--c-danger);
}

.sentiment-bar__marker {
    position: absolute;
    top: -2px;
    width: 4px;
    height: 12px;
    border-radius: 2px;
    background: var(--text-primary);
    transform: translateX(-50%);
}

.sentiment-bar__value {
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    min-width: 2rem;
    text-align: right;
}

.sentiment-bar__value.positive {
    color: var(--c-success-dim);
}

.sentiment-bar__value.negative {
    color: var(--c-danger-dim);
}

/* ===========================================
   Discord Formatting
   =========================================== */

/* Mention badges (pill-shaped, Discord-style) */
.discord-mention {
    display: inline;
    padding: 0 0.2rem;
    border-radius: 3px;
    font-weight: 500;
    cursor: default;
}

.discord-mention.user {
    background: color-mix(in srgb, var(--platform-discord), transparent 75%);
    color: var(--platform-discord);
}

.discord-mention.role {
    background: var(--c-info-ghost);
    color: var(--c-info-bold);
}

.discord-mention.channel {
    background: color-mix(in srgb, var(--platform-discord), transparent 75%);
    color: var(--platform-discord);
}

/* Mentions resolved to a known user become clickable deep-links to their profile. */
a.discord-mention {
    cursor: pointer;
    text-decoration: none;
}

a.discord-mention:hover {
    text-decoration: underline;
}

/* Spoiler text — hidden until hover */
.discord-spoiler {
    background: var(--text-primary);
    color: transparent;
    border-radius: 3px;
    padding: 0 0.15rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.discord-spoiler:hover,
.discord-spoiler.revealed {
    background: rgba(255, 255, 255, 0.1);
    color: inherit;
}

/* Code blocks from Discord messages */
.msg-text pre {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 0.5rem;
    overflow-x: auto;
    margin: 0.25rem 0;
}

.msg-text code {
    background: var(--surface);
    border-radius: 3px;
    padding: 0.1rem 0.3rem;
    font-size: 0.85em;
}

.msg-text pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

/* Block quotes from Discord */
.msg-text blockquote {
    border-left: 3px solid var(--border-light);
    margin: 0.25rem 0;
    padding: 0.1rem 0.5rem;
    color: var(--text-secondary);
}
