/**
 * Chat Control Styles
 * Discord-inspired dark theme
 */

/* Discord Color Variables */
:root {
    --discord-bg-primary: #1a1a1e;
    --discord-bg-secondary: #121214;
    --discord-bg-tertiary: #121214;
    --discord-bg-floating: #0e0e10;
    --discord-bg-hover: #242428;
    --discord-bg-active: #242428;
    --discord-text-normal: #dbdee1;
    --discord-text-muted: #949ba4;
    --discord-text-link: #00a8fc;
    --discord-channel-default: #80848e;
    --discord-channel-hover: #dbdee1;
    --discord-brand-red: #f23f43;
    --discord-brand-green: #23a55a;
    --discord-input-bg: #222327;
    --discord-divider: #3f4147;
}

/* Container */
.chat-control {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--discord-bg-primary);
    overflow: hidden;
}

/* Header - Discord style */
.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--discord-bg-primary);
    border-bottom: 1px solid var(--discord-bg-tertiary);
    height: 48px;
    box-sizing: border-box;
}

.chat-menu-toggle,
.chat-users-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--discord-text-muted);
    font-size: 18px;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
}

@media (hover: hover) {
    .chat-menu-toggle:hover,
    .chat-users-toggle:hover {
        color: var(--discord-text-normal);
        background: var(--discord-bg-hover, rgba(255,255,255,0.06));
    }
}

.chat-menu-toggle.active,
.chat-users-toggle.active {
    color: var(--discord-blurple, #5865f2);
}

.chat-header-hash {
    color: var(--discord-channel-default);
    font-size: 24px;
    font-weight: 400;
}

.chat-header-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-title {
    font-weight: 600;
    color: var(--discord-text-normal);
    font-size: 16px;
}

.chat-header-rename {
    display: none;
    background: none;
    border: none;
    color: var(--discord-text-muted);
    cursor: pointer;
    padding: 4px 6px;
    font-size: 12px;
    opacity: 0.7;
}

@media (hover: hover) {
    .chat-header-info:hover .chat-header-rename {
        display: inline-flex;
    }
}

.chat-header-rename:hover {
    color: var(--discord-text-normal);
    opacity: 1;
}

.chat-header-divider {
    width: 1px;
    height: 24px;
    background: var(--discord-divider);
    margin: 0 8px;
}

.chat-header-description {
    font-size: 14px;
    color: var(--discord-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.chat-admin-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    color: var(--discord-text-muted);
    text-decoration: none;
}

.chat-admin-link:hover {
    color: #5865f2;
    background: var(--discord-bg-hover);
}

/* Messages Container */
.chat-messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: var(--discord-bg-primary);
    min-height: 0;
}

.chat-control .chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    overflow-anchor: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 0;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--discord-bg-secondary);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--discord-bg-tertiary);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #1a1b1e;
}

/* Empty/Loading States */
.chat-loading,
.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--discord-text-muted);
    gap: 12px;
}

.chat-empty i {
    font-size: 48px;
    opacity: 0.5;
}

.chat-empty p {
    margin: 0;
}

/* Message - Discord flat style (NO bubbles) */
.chat-control .chat-message {
    display: flex;
    padding: 2px 48px 2px 16px;
    margin-top: 4px;
    position: relative;
    min-height: auto;
    box-sizing: border-box;
    background: none;
    border-radius: 0;
}

/* Remove top margin from first message */
.chat-control .chat-message:first-child {
    margin-top: 0;
}

.chat-control .chat-message:hover {
    background: var(--discord-bg-hover);
}

.chat-control .chat-message.chat-message-highlight {
    background: rgba(88, 101, 242, 0.2);
}

.chat-control .chat-message.consecutive {
    margin-top: 0;
    min-height: auto;
    padding: 0 48px 0 72px;
}

.chat-control .chat-message.consecutive .chat-message-avatar {
    display: none;
}

.chat-control .chat-message.consecutive .chat-message-header {
    display: none;
}

.chat-message.system {
    justify-content: center;
    color: var(--discord-text-muted);
    font-size: 13px;
    padding: 8px 16px;
    margin-top: 8px;
}

.chat-message.system i {
    font-size: 14px;
    margin-right: 8px;
}

/* Avatar */
.chat-message-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    margin-right: 16px;
    cursor: pointer;
}

.chat-message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-avatar-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #5865f2;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    font-weight: 500;
}

/* Message Body */
.chat-control .chat-message-body {
    flex: 1;
    min-width: 0;
    display: block;
}

.chat-message-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    line-height: 1.375;
}

.chat-message-sender {
    font-weight: 600;
    font-size: 0.875rem;
    color: #7289da;
    cursor: pointer;
    letter-spacing: 0.02em;
}

.chat-message-sender:hover {
    text-decoration: underline;
    color: #8ea1e1;
}

.chat-message-time {
    font-size: 12px;
    color: var(--discord-text-muted);
    font-weight: 400;
}

.chat-message-content {
    color: var(--discord-text-normal);
    font-size: 1rem;
    line-height: 1.375rem;
    word-wrap: break-word;
    white-space: pre-wrap;
    /* NO background, NO padding - Discord style */
}

/* Text shadow modes (Inferno-style) */
body.text-shadow-subtle .chat-message-content,
body.text-shadow-subtle .chat-message-text {
    text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
}

body.text-shadow-medium .chat-message-content,
body.text-shadow-medium .chat-message-text {
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5), 2px 2px 3px rgba(0, 0, 0, 0.2);
}

body.text-shadow-intense .chat-message-content,
body.text-shadow-intense .chat-message-text {
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7), 2px 2px 4px rgba(0, 0, 0, 0.4), 3px 3px 6px rgba(0, 0, 0, 0.2);
}

/* Font family options */
.font-system, body.chat-font-system .chat-message-content, body.chat-font-system .chat-message-text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.font-roboto, body.chat-font-roboto .chat-message-content, body.chat-font-roboto .chat-message-text {
    font-family: 'Roboto', sans-serif;
}

.font-opensans, body.chat-font-opensans .chat-message-content, body.chat-font-opensans .chat-message-text {
    font-family: 'Open Sans', sans-serif;
}

.font-lato, body.chat-font-lato .chat-message-content, body.chat-font-lato .chat-message-text {
    font-family: 'Lato', sans-serif;
}

.font-mono, body.chat-font-mono .chat-message-content, body.chat-font-mono .chat-message-text {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* Font size options */
.size-xsmall, body.chat-size-xsmall .chat-message-content, body.chat-size-xsmall .chat-message-text {
    font-size: 12px;
}

.size-small, body.chat-size-small .chat-message-content, body.chat-size-small .chat-message-text {
    font-size: 14px;
}

.size-large, body.chat-size-large .chat-message-content, body.chat-size-large .chat-message-text {
    font-size: 18px;
}

.size-xlarge, body.chat-size-xlarge .chat-message-content, body.chat-size-xlarge .chat-message-text {
    font-size: 20px;
}

/* Chat Settings Preview */
.chat-preview {
    background: var(--discord-bg-primary, #1a1a1e);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-preview-message {
    display: flex;
    gap: 12px;
}

.chat-preview-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #5865f2;
}

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

.chat-preview-sender {
    font-weight: 600;
    color: #7289da;
    font-size: 0.875rem;
}

.chat-preview-time {
    font-size: 12px;
    color: var(--discord-text-muted, #949ba4);
}

.chat-preview-text {
    color: var(--discord-text-normal, #dbdee1);
    line-height: 1.375;
}

/* Preview size overrides */
.chat-preview-text.size-xsmall { font-size: 12px; }
.chat-preview-text.size-small { font-size: 14px; }
.chat-preview-text.size-large { font-size: 18px; }
.chat-preview-text.size-xlarge { font-size: 20px; }

/* Preview-specific shadow classes */
.shadow-subtle { text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3); }
.shadow-medium { text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5), 2px 2px 3px rgba(0, 0, 0, 0.2); }
.shadow-intense { text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7), 2px 2px 4px rgba(0, 0, 0, 0.4), 3px 3px 6px rgba(0, 0, 0, 0.2); }

/* Links in messages */
.chat-message-content a {
    color: var(--discord-text-link);
    text-decoration: none;
    word-break: break-all;
    padding: 0 2px;
    margin: 0 -2px;
    border-radius: 3px;
}

.chat-message-content a:hover {
    text-decoration: underline;
    background: rgba(0, 168, 252, 0.1);
}

.chat-message-edited {
    font-size: 10px;
    color: var(--discord-text-muted);
    margin-left: 4px;
}

/* Translation indicator badge */
.chat-translated-badge {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    color: #888;
    font-size: 11px;
    cursor: help;
}

.chat-translated-badge i {
    font-size: 12px;
}

/* =====================
   Markdown Styles for Chat Messages
   ===================== */

/* Reset white-space for markdown content - let markdown handle line breaks */
.chat-message-text p,
.chat-message-text pre,
.chat-message-text blockquote,
.chat-message-text ul,
.chat-message-text ol,
.chat-message-text table {
    white-space: normal;
}

/* Headers - subtle sizing appropriate for chat */
.chat-message-text h1,
.chat-message-text h2,
.chat-message-text h3,
.chat-message-text h4,
.chat-message-text h5,
.chat-message-text h6 {
    color: var(--discord-text-normal);
    margin: 0.5em 0 0.25em 0;
    font-weight: 600;
    line-height: 1.3;
}

.chat-message-text h1 { font-size: 1.4em; }
.chat-message-text h2 { font-size: 1.25em; }
.chat-message-text h3 { font-size: 1.1em; }
.chat-message-text h4,
.chat-message-text h5,
.chat-message-text h6 { font-size: 1em; }

/* First element no top margin */
.chat-message-text > :first-child {
    margin-top: 0;
}

/* Last element no bottom margin */
.chat-message-text > :last-child {
    margin-bottom: 0;
}

/* Paragraphs */
.chat-message-text p {
    margin: 0.25em 0;
}

/* Hide empty paragraphs that cause extra spacing */
.chat-message-text p:empty {
    display: none;
    margin: 0;
    padding: 0;
    line-height: 0;
}

/* Bold and italic */
.chat-message-text strong {
    font-weight: 600;
    color: var(--discord-text-normal);
}

.chat-message-text em {
    font-style: italic;
}

/* Inline code */
.chat-message-text code {
    background: rgba(255, 255, 255, 0.06);
    padding: 1px 6px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    color: #e2e4e6;
}

/* Code blocks */
.chat-message-text pre {
    background: #1a1b1e;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
    max-width: 100%;
}

.chat-message-text pre code {
    background: transparent;
    padding: 0;
    font-size: 0.85em;
    line-height: 1.5;
    white-space: pre;
    display: block;
}

/* Blockquotes */
.chat-message-text blockquote {
    border-left: 3px solid #5865f2;
    margin: 8px 0;
    padding: 4px 0 4px 12px;
    color: var(--discord-text-muted);
    background: rgba(88, 101, 242, 0.05);
    border-radius: 0 4px 4px 0;
}

.chat-message-text blockquote p {
    margin: 0;
}

/* Lists */
.chat-message-text ul,
.chat-message-text ol {
    margin: 4px 0;
    padding-left: 24px;
}

.chat-message-text li {
    margin: 2px 0;
}

.chat-message-text ul {
    list-style-type: disc;
}

.chat-message-text ol {
    list-style-type: decimal;
}

/* Nested lists */
.chat-message-text ul ul,
.chat-message-text ol ol,
.chat-message-text ul ol,
.chat-message-text ol ul {
    margin: 2px 0;
}

/* Horizontal rule */
.chat-message-text hr {
    border: none;
    height: 1px;
    background: var(--discord-divider);
    margin: 12px 0;
}

/* Tables - Scrollable wrapper like code blocks */
.chat-message-text .table-scroll-wrapper {
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    background: #1a1b1e;
}

.chat-message-text table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
    table-layout: auto;
    margin: 0;
}

.chat-message-text th,
.chat-message-text td {
    border: 1px solid var(--discord-divider);
    padding: 8px 12px;
    text-align: left;
    white-space: nowrap;
}

/* Allow text wrapping in cells with long content */
.chat-message-text td {
    white-space: normal;
    min-width: 80px;
    max-width: 300px;
    word-wrap: break-word;
}

.chat-message-text th {
    background: rgba(255, 255, 255, 0.08);
    font-weight: 600;
    white-space: nowrap;
}

.chat-message-text tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.chat-message-text tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

/* Strikethrough */
.chat-message-text del,
.chat-message-text s {
    text-decoration: line-through;
    color: var(--discord-text-muted);
}

/* Ensure markdown links still work */
.chat-message-text a {
    color: var(--discord-text-link);
    text-decoration: none;
}

.chat-message-text a:hover {
    text-decoration: underline;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .chat-message-text pre {
        padding: 10px;
        font-size: 12px;
    }

    .chat-message-text pre code {
        font-size: 0.8em;
    }

    .chat-message-text table {
        font-size: 13px;
    }
}

/* Reply Preview in Message - Discord style */
/* The reply sits above the avatar/message row */
.chat-control .chat-message.has-reply {
    display: block;
}

.chat-control .chat-message.has-reply .chat-message-avatar {
    position: absolute;
    left: 16px;
    top: auto;
}

.chat-control .chat-message.has-reply .chat-message-body {
    margin-left: 56px;
}

.chat-message-reply-preview {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 0;
    margin-left: 56px;
    padding-bottom: 4px;
    font-size: 0.875rem;
    color: var(--discord-text-muted);
    cursor: pointer;
    white-space: nowrap;
    position: relative;
}

.chat-message-reply-preview > span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-reply-spine {
    position: absolute;
    left: -36px;
    bottom: 0;
    width: 32px;
    height: 14px;
    border-left: 2px solid #5c5e66;
    border-top: 2px solid #5c5e66;
    border-radius: 6px 0 0 0;
    box-sizing: border-box;
}

.chat-message-reply-preview:hover .chat-reply-spine {
    border-color: #82848e;
}

.chat-message-reply-preview:hover {
    color: var(--discord-text-normal);
}

.chat-reply-avatar {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}

.chat-reply-avatar-placeholder {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #5865f2;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-reply-author {
    font-weight: 500;
    color: var(--discord-text-normal);
    flex-shrink: 0;
    opacity: 0.85;
}

.chat-reply-author:hover {
    text-decoration: underline;
}

.chat-reply-content {
    color: var(--discord-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Message Meta - hidden in Discord style, timestamp in header */
.chat-message-meta {
    display: none;
}

/* Attachments */
.chat-attachments-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
    max-width: 550px;
}

/* Media card container - fixed size, never resizes */
.chat-media-card {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: #1a1a1a;
    cursor: pointer;
}

/* Card with known dimensions - uses inline aspect-ratio */
.chat-media-card.has-dimensions {
    width: 100%;
    min-width: 150px;
    max-width: 400px;
}

/* Card without dimensions - fixed default size */
.chat-media-card.no-dimensions {
    width: 300px;
    height: 225px; /* 4:3 aspect ratio */
    max-width: 100%;
}

/* Media inside card - fills and maintains aspect ratio */
.chat-media-card img,
.chat-media-card video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Video card spacing */
.chat-media-card.video {
    margin-top: 8px;
}

/* Video controls - don't use pointer cursor */
.chat-media-card.video {
    cursor: default;
}

/* Pending review attachments */
.chat-media-card.pending-review {
    position: relative;
}

.chat-media-card.pending-review img,
.chat-media-card.pending-review video {
    opacity: 0.5;
}

.chat-attachment-pending {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(245, 158, 11, 0.9);
    color: #000;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

/* Reactions */
.chat-message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.chat-reaction {
    background: var(--discord-bg-secondary);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--discord-text-normal);
}

.chat-reaction:hover {
    background: var(--discord-bg-hover);
    border-color: var(--discord-divider);
}

.chat-reaction.active {
    background: rgba(88, 101, 242, 0.3);
    border-color: #5865f2;
}

.chat-reaction-count {
    font-size: 13px;
    color: var(--discord-text-muted);
}

/* Message Actions - positioned absolute over content on right */
.chat-message-content {
    position: relative;
}

.chat-message-actions {
    display: none;
    position: absolute;
    top: 0;
    right: -8px;
    gap: 0;
    background: var(--discord-bg-floating);
    border-radius: 4px;
    box-shadow: 0 0 0 1px rgba(0,0,0,.15), 0 4px 8px rgba(0,0,0,.2);
    z-index: 1;
}

/* Show actions only via JS class (delayed hover or tap) */
.chat-control .chat-message.hover .chat-message-actions,
.chat-control .chat-message.show-actions .chat-message-actions {
    display: inline-flex;
}

.chat-action-btn {
    background: none;
    border: none;
    padding: 8px 10px;
    color: var(--discord-text-muted);
    cursor: pointer;
    font-size: 16px;
}

.chat-action-btn:hover {
    background: var(--discord-bg-hover);
    color: var(--discord-text-normal);
}

.chat-action-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.chat-action-btn:last-child {
    border-radius: 0 4px 4px 0;
}

/* Reaction Picker */
.chat-reaction-picker {
    background: var(--discord-bg-floating);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    gap: 2px;
    z-index: 1000;
    box-shadow: 0 0 0 1px rgba(0,0,0,.15), 0 8px 16px rgba(0,0,0,.3);
}

.reaction-option {
    background: none;
    border: none;
    padding: 8px;
    font-size: 22px;
    cursor: pointer;
    border-radius: 4px;
}

.reaction-option:hover {
    background: var(--discord-bg-hover);
}

/* New Messages Indicator - Discord style bar */
.chat-new-messages {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--discord-brand-red);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.chat-new-messages:hover {
    background: #d93439;
}

.chat-new-messages i {
    font-size: 12px;
}

/* Scroll to Bottom Button */
.chat-scroll-bottom {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    background: var(--discord-bg-floating);
    border: 1px solid var(--discord-divider);
    border-radius: 50%;
    color: var(--discord-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.chat-scroll-bottom.dimmed {
    opacity: 0.3;
}

.chat-scroll-bottom:focus {
    outline: none;
}

.chat-scroll-bottom:hover {
    background: var(--discord-bg-hover);
    color: var(--discord-text-normal);
    opacity: 1;
}

/* Mobile: keep absolute inside messages container (moves with keyboard) */
@media (max-width: 768px) {
    .chat-scroll-bottom {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Typing Indicator */
.chat-typing-indicator {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--discord-text-muted);
    background: var(--discord-bg-primary);
    height: 29px;
    box-sizing: border-box;
    visibility: hidden;
}

.chat-typing-indicator.visible {
    visibility: visible;
}

.typing-dots {
    display: inline-flex;
    gap: 2px;
    margin-right: 4px;
}

/* Composer - Discord style */
.chat-composer {
    padding: 0 16px 8px 16px;
    background: var(--discord-bg-primary);
    position: relative;
}

.chat-command-popup {
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    background: #2b2d31;
    border: 1px solid #3f4147;
    border-radius: 8px;
    padding: 8px 0;
    z-index: 10;
    max-height: 240px;
    overflow-y: auto;
}

.chat-command-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-command-item:hover,
.chat-command-item.selected {
    background: #36373d;
}

.chat-command-name {
    color: #fff;
    font-weight: 500;
    white-space: nowrap;
}

.chat-command-args {
    color: #949ba4;
    font-weight: 400;
}

.chat-command-desc {
    color: #949ba4;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-command-result {
    padding: 6px 16px;
    color: #949ba4;
    font-size: 13px;
    font-style: italic;
}

/* Bot command styling in command popup */
.chat-command-item.bot-command {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-command-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-command-avatar-placeholder {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #5865f2;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    flex-shrink: 0;
}

.chat-command-content {
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden;
}

/* @ Mention popup */
.chat-mention-popup {
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    background: #2b2d31;
    border: 1px solid #1e1f22;
    border-radius: 8px;
    margin-bottom: 4px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
}

.chat-mention-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-mention-item:hover,
.chat-mention-item.selected {
    background: #36373d;
}

.chat-mention-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-mention-avatar-placeholder {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #5865f2;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    flex-shrink: 0;
}

.chat-mention-name {
    color: #fff;
    font-weight: 500;
}

.chat-mention-badge {
    background: #5865f2;
    color: #fff;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    margin-left: auto;
}

/* @mention styling in message content */
.chat-mention-link {
    color: #7289da;
    background: rgba(114, 137, 218, 0.1);
    padding: 0 4px;
    border-radius: 3px;
    cursor: pointer;
    font-weight: 500;
}

.chat-mention-link:hover {
    background: rgba(114, 137, 218, 0.2);
    text-decoration: underline;
}

/* User profile popup */
.user-profile-popup {
    position: fixed;
    background: #111214;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    min-width: 200px;
    max-width: 280px;
    z-index: 10000; /* High z-index to be above mobile fixed elements */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.user-profile-popup-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.user-profile-popup-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.user-profile-popup-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-profile-popup-avatar-placeholder {
    width: 48px;
    height: 48px;
    background: #5865f2;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 500;
    border-radius: 50%;
}

.user-profile-popup-info {
    flex: 1;
    min-width: 0;
}

.user-profile-popup-name {
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-profile-popup-bot-badge {
    background: #5865f2;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 3px;
    margin-left: 6px;
    vertical-align: middle;
}

.user-profile-popup-status {
    color: #949ba4;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.user-profile-popup-status .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.user-profile-popup-status .status-dot.online {
    background: #23a55a;
}

.user-profile-popup-status .status-dot.offline {
    background: #80848e;
}

.user-profile-popup-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.user-profile-popup-btn {
    background: #2b2d31;
    border: none;
    color: #e0e0e0;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-profile-popup-btn:hover {
    background: #36373d;
}

.user-profile-popup-btn i {
    width: 16px;
    text-align: center;
    color: #949ba4;
}

.user-profile-popup-btn:active {
    background: #404249;
}

/* Mobile-friendly popup styles */
@media (max-width: 768px) {
    .user-profile-popup {
        min-width: 260px;
        padding: 16px;
    }

    .user-profile-popup-btn {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
    }
}

.chat-reply-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--discord-bg-secondary);
    padding: 8px 12px;
    border-radius: 8px 8px 0 0;
    font-size: 13px;
    margin-bottom: 0;
}

.chat-reply-label {
    color: var(--discord-text-muted);
}

.chat-reply-name {
    color: var(--discord-text-link);
    font-weight: 500;
}

.chat-reply-text {
    color: var(--discord-text-muted);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-reply-cancel {
    background: none;
    border: none;
    color: var(--discord-text-muted);
    cursor: pointer;
    padding: 4px;
}

.chat-reply-cancel:hover {
    color: var(--discord-text-normal);
}

/* Attachments Preview */
.chat-attachments-preview {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    padding-bottom: 12px;
    background: var(--discord-bg-secondary);
    border-radius: 8px 8px 0 0;
}

.chat-attachments-preview:not(:empty) {
    display: flex;
}

.chat-attachment-preview {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 4px;
    overflow: hidden;
}

.chat-attachment-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-attachment-preview.dragging {
    opacity: 0.5;
}

.chat-attachment-preview {
    cursor: grab;
}

.chat-attachment-preview:active {
    cursor: grabbing;
}

.chat-attachment-preview .video-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 10px;
}

.chat-attachment-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
}

/* Input Row - Discord style */
.chat-input-row {
    display: flex;
    align-items: flex-end;
    background: var(--discord-input-bg);
    border-radius: 8px;
    padding: 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-attach-btn {
    background: none;
    border: none;
    width: 40px;
    height: 44px;
    color: var(--discord-channel-default);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 4px;
}

.chat-attach-btn:hover {
    color: var(--discord-text-normal);
}

/* Preset Button (Quick Actions) */
.chat-preset-btn {
    background: none;
    border: none;
    width: 40px;
    height: 44px;
    color: var(--discord-channel-default);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 4px;
}

.chat-preset-btn:hover {
    color: #fbbf24;
}

/* Action Menu Dropdown */
.chat-action-menu {
    background: var(--discord-bg-floating);
    border-radius: 8px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24);
    min-width: 220px;
    padding: 6px;
    z-index: 1000;
}

.chat-action-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 4px;
    color: var(--discord-interactive-normal);
    cursor: pointer;
    font-size: 14px;
}

.chat-action-menu-item:hover {
    background: var(--discord-bg-modifier-hover);
    color: var(--discord-text-normal);
}

.chat-action-menu-item i {
    font-size: 14px;
    color: #fbbf24;
    width: 16px;
    text-align: center;
}

.chat-input {
    flex: 1;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 11px 8px;
    color: var(--discord-text-normal);
    font-size: 16px;
    resize: none;
    min-height: 44px;
    max-height: 400px;
    line-height: 1.375;
}

.chat-input:focus {
    outline: none;
}

.chat-input::placeholder {
    color: var(--discord-text-muted);
}

.chat-control .chat-send-btn {
    background: none !important;
    border: none !important;
    width: 32px !important;
    height: 44px !important;
    color: var(--discord-text-muted) !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 8px;
    border-radius: 0 !important;
}

.chat-control .chat-send-btn:hover {
    color: var(--discord-text-normal) !important;
    background: none !important;
}

.chat-control .chat-send-btn:disabled {
    color: var(--discord-text-muted) !important;
    opacity: 0.3;
    cursor: not-allowed;
}

/* Loading Spinner */
.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--discord-bg-tertiary);
    border-top-color: #5865f2;
    border-radius: 50%;
}

/* Responsive */
@media (max-width: 768px) {
    /* Contained scroll: chat-control stays as flex column, only chat-messages scrolls */
    /* Desktop flex layout (flex-direction: column, height: 100%, overflow: hidden) carries through */

    /* Mobile: Hide avatars and maximize message width */
    .chat-control .chat-message-avatar {
        display: none;
    }

    .chat-control .chat-message {
        padding: 2px 8px 2px 8px;
    }

    .chat-control .chat-message.consecutive {
        padding: 0 8px 0 8px;
    }

    .chat-control .chat-message.has-reply .chat-message-body {
        margin-left: 0;
    }

    .chat-control .chat-message-reply-preview {
        margin-left: 0;
    }

    .chat-control .chat-reply-spine {
        display: none;
    }

    /* Actions positioned absolute, shown on tap */
    .chat-control .chat-message-actions {
        background: var(--discord-bg-floating);
        right: -24px;
    }

    .chat-control .chat-message .chat-action-btn {
        padding: 4px 8px;
        font-size: 14px;
    }

    /* Composer in flex flow (not fixed) */
    .chat-control .chat-composer {
        flex-shrink: 0;
        padding: 6px 12px;
        background: var(--discord-bg-primary);
        border-top: 1px solid var(--discord-bg-tertiary);
    }

    .chat-control .chat-typing-indicator {
        padding: 2px 12px;
        font-size: 11px;
    }
}

/* Image Lightbox */
.chat-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-lightbox-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
}

.chat-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    z-index: 1;
}

.chat-lightbox-content img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    display: block;
    border-radius: 4px;
}

.chat-lightbox-buttons {
    position: absolute;
    top: -40px;
    right: 0;
    display: flex;
    gap: 8px;
}

.chat-lightbox-close,
.chat-lightbox-info {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-lightbox-close {
    font-size: 24px;
}

.chat-lightbox-close:hover,
.chat-lightbox-info:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-lightbox-info.active {
    background: rgba(79, 172, 254, 0.3);
    color: #4facfe;
}

/* Info Panel */
.chat-lightbox-info-panel {
    position: absolute;
    top: 0;
    right: -320px;
    width: 300px;
    max-height: 90vh;
    background: #1a1a2e;
    border-radius: 8px;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.chat-info-content {
    padding: 16px;
}

.chat-info-loading,
.chat-info-error {
    padding: 20px;
    text-align: center;
    color: #888;
}

.chat-info-error {
    color: #f66;
}

.chat-info-section {
    margin-bottom: 16px;
}

.chat-info-label {
    font-size: 11px;
    text-transform: uppercase;
    color: #888;
    margin-bottom: 4px;
}

.chat-info-value {
    color: #e0e0e0;
    font-size: 13px;
    line-height: 1.4;
}

.chat-info-prompt,
.chat-info-neg-prompt {
    max-height: 120px;
    overflow-y: auto;
    word-break: break-word;
}

.chat-info-neg-prompt {
    color: #f88;
}

.chat-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.chat-info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-info-item .chat-info-label {
    font-size: 10px;
}

.chat-info-item .chat-info-value {
    font-size: 12px;
    color: #fff;
}

.chat-info-view-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: rgba(79, 172, 254, 0.15);
    color: #4facfe;
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
}

.chat-info-view-link:hover {
    background: rgba(79, 172, 254, 0.25);
}

/* Responsive: stack info panel below on smaller screens */
@media (max-width: 900px) {
    .chat-lightbox-info-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 50vh;
        border-radius: 12px 12px 0 0;
    }
}

/* =====================
   MODERATION STYLES
   ===================== */

/* Report button */
.chat-report-btn {
    color: #b5bac1;
}

.chat-report-btn:hover {
    color: #f0b232;
}

/* Mod button (shield) */
.chat-mod-btn {
    color: #b5bac1;
}

.chat-mod-btn:hover {
    color: #5865f2;
}

/* Mod menu dropdown */
.chat-mod-menu {
    position: fixed;
    background: #2b2d31;
    border: 1px solid #3f4147;
    border-radius: 4px;
    min-width: 160px;
    z-index: 10001;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

.mod-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: #dcddde;
    font-size: 14px;
    cursor: pointer;
    text-align: left;
}

.mod-menu-item:hover {
    background: #404249;
}

.mod-menu-item.danger {
    color: #f23f43;
}

.mod-menu-item.danger:hover {
    background: rgba(242, 63, 67, 0.15);
}

.mod-menu-item i {
    width: 16px;
    text-align: center;
}

/* Chat Modal */
.chat-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.chat-modal {
    background: #313338;
    border-radius: 8px;
    width: 440px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.chat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #3f4147;
    font-weight: 600;
    font-size: 16px;
    color: #fff;
}

.chat-modal-close {
    background: transparent;
    border: none;
    color: #b5bac1;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.chat-modal-close:hover {
    color: #fff;
}

.chat-modal-body {
    padding: 20px;
}

.chat-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid #3f4147;
}

/* Modal warning text */
.modal-warning {
    color: #f0b232;
    margin-bottom: 16px;
    font-size: 14px;
}

/* Form elements in modals */
.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: #b5bac1;
}

.form-select,
.form-textarea,
.form-input {
    width: 100%;
    background: #1e1f22;
    border: 1px solid #3f4147;
    border-radius: 4px;
    padding: 10px 12px;
    color: #dbdee1;
    font-size: 14px;
    font-family: inherit;
}

.form-select:focus,
.form-textarea:focus,
.form-input:focus {
    outline: none;
    border-color: #5865f2;
}

.form-textarea {
    min-height: 80px;
    resize: vertical;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    border: none;
    font-family: inherit;
}

.btn-secondary {
    background: #4e5058;
    color: #fff;
}

.btn-secondary:hover {
    background: #5d5f68;
}

.btn-primary {
    background: #5865f2;
    color: #fff;
}

.btn-primary:hover {
    background: #4752c4;
}

.btn-danger {
    background: #da373c;
    color: #fff;
}

.btn-danger:hover {
    background: #c62e32;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* =====================
   Chat Widgets
   ===================== */

/* Widget Container - sits above input */
.chat-widget-area {
    padding: 0 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Base Widget Style */
.chat-widget {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--discord-bg-secondary);
    border: 1px solid var(--discord-divider);
    border-radius: 8px;
}

.chat-widget-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--discord-bg-hover);
    border-radius: 50%;
    color: var(--discord-text-muted);
    font-size: 18px;
    flex-shrink: 0;
}

.chat-widget-content {
    flex: 1;
    min-width: 0;
}

.chat-widget-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--discord-text-normal);
    margin-bottom: 2px;
}

.chat-widget-subtitle {
    font-size: 12px;
    color: var(--discord-text-muted);
}

.chat-widget-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Widget Buttons */
.chat-widget-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.chat-widget-btn.primary {
    background: #5865f2;
    color: #fff;
}

.chat-widget-btn.primary:hover {
    background: #4752c4;
}

.chat-widget-btn.secondary {
    background: var(--discord-bg-hover);
    color: var(--discord-text-normal);
}

.chat-widget-btn.secondary:hover {
    background: #35363c;
}

.chat-widget-btn i {
    font-size: 12px;
}

/* Escalation Widget Specific */
.chat-widget-escalation {
    background: linear-gradient(135deg, rgba(88, 101, 242, 0.1) 0%, var(--discord-bg-secondary) 100%);
    border-color: rgba(88, 101, 242, 0.3);
}

.chat-widget-escalation .chat-widget-icon {
    background: rgba(88, 101, 242, 0.2);
    color: #5865f2;
}

/* Suggestions Widget */
.chat-widget-suggestions {
    padding: 8px 12px;
    background: transparent;
    border: none;
}

.chat-suggestions-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-suggestion-bubble {
    padding: 8px 16px;
    background: var(--discord-bg-hover);
    border: 1px solid var(--discord-divider);
    border-radius: 16px;
    color: var(--discord-text-normal);
    font-size: 13px;
    cursor: pointer;
}

.chat-suggestion-bubble:hover {
    background: #35363c;
    border-color: #5865f2;
}

/* Mobile Responsive */
@media (max-width: 600px) {
    .chat-widget {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .chat-widget-actions {
        width: 100%;
        flex-direction: column;
    }

    .chat-widget-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ===========================================
   Streaming Message Styles
   For progressive AI response display
   =========================================== */

/* Streaming cursor indicator */
.chat-message.streaming .chat-message-text::after {
    content: '▋';
    color: var(--discord-text-muted);
    animation: streaming-blink 1s steps(1) infinite;
    margin-left: 2px;
}

@keyframes streaming-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Streaming message has subtle glow to indicate activity */
.chat-message.streaming .chat-message-body {
    position: relative;
}

.chat-message.streaming .chat-message-body::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, #5865f2 0%, transparent 100%);
    border-radius: 2px;
}

/* Error state for failed streaming */
.chat-message.streaming-error .chat-message-content {
    border-left: 3px solid var(--discord-brand-red);
    padding-left: 8px;
}

.chat-message.streaming-error .chat-message-text::after {
    content: ' ⚠';
    color: var(--discord-brand-red);
}

/* Completion flash - brief highlight when streaming finishes */
.chat-message.streaming-complete .chat-message-body {
    background-color: rgba(88, 101, 242, 0.1);
}

/* Hide actions during streaming */
.chat-message.streaming .chat-message-actions {
    display: none;
}

/* =====================
   LLM Stats Popover
   ===================== */

/* Stats Popover */
.chat-stats-popover {
    background: var(--discord-bg-floating);
    border-radius: 6px;
    min-width: 180px;
    z-index: 1001;
    box-shadow: 0 0 0 1px rgba(0,0,0,.15), 0 4px 12px rgba(0,0,0,.3);
    overflow: hidden;
}

.stats-popover-header {
    padding: 6px 8px;
    font-weight: 600;
    font-size: 11px;
    color: var(--discord-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border-bottom: 1px solid var(--discord-bg-tertiary);
}

.stats-popover-body {
    padding: 4px 0;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 8px;
    font-size: 12px;
}

.stats-label {
    color: var(--discord-text-muted);
}

.stats-value {
    color: var(--discord-text-normal);
    font-weight: 500;
}

.stats-divider {
    height: 1px;
    background: var(--discord-bg-tertiary);
    margin: 3px 8px;
}

.stats-section {
    padding-bottom: 2px;
}

.stats-progress-bar {
    height: 4px;
    background: var(--discord-bg-tertiary);
    border-radius: 2px;
    margin: 2px 8px 0;
    overflow: hidden;
}

.stats-progress-fill {
    height: 100%;
    border-radius: 3px;
}

.stats-warning {
    color: #faa61a;
}

.stats-warning .stats-label,
.stats-warning .stats-value {
    color: #faa61a;
}

/* Header stats button */
.chat-header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: var(--discord-text-muted);
    cursor: pointer;
}

.chat-header-btn:hover {
    color: var(--discord-text-normal);
    background: var(--discord-bg-hover);
}

.chat-header-btn .material-icons-outlined {
    font-size: 18px;
}

.chat-header-btn.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* ========================================
   Workflow Widget Styles - Modern Card Design
   ======================================== */

.workflow-widget {
    background: #1a1b1e;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 8px;
    margin: 0;
    max-width: 360px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    display: block;
    overflow: hidden;
    white-space: normal;
    font-size: 0;
}

.workflow-widget > * {
    font-size: 14px;
}

.workflow-widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    padding-bottom: 6px;
}

.workflow-widget-info {
    display: flex;
    align-items: center;
    gap: 6px;
}

.workflow-widget-icon {
    font-size: 16px;
    color: #a78bfa;
}

.workflow-widget-title {
    font-weight: 600;
    color: #e2e5e9;
    font-size: 13px;
    letter-spacing: 0.01em;
}

.workflow-widget-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.workflow-widget-status .material-icons-outlined {
    font-size: 12px;
}

.workflow-widget-status.queued {
    color: #9ca3af;
    background: rgba(156, 163, 175, 0.15);
}

.workflow-widget-status.running {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.15);
}

.workflow-widget-status.running .spin {
    animation: spin-reverse 3s linear infinite;
}

@keyframes spin-reverse {
    from { transform: scaleX(-1) rotate(360deg); }
    to { transform: scaleX(-1) rotate(0deg); }
}

.workflow-widget-status.complete {
    color: #34d399;
    background: rgba(52, 211, 153, 0.15);
}

.workflow-widget-status.error {
    color: #f87171;
    background: rgba(248, 113, 113, 0.15);
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.workflow-widget-progress {
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    margin-top: 6px;
    overflow: hidden;
}

.workflow-widget-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #a78bfa 0%, #818cf8 100%);
    border-radius: 3px;
}

.workflow-widget-progress-section {
    padding-bottom: 8px;
}

.workflow-widget-progress-text {
    font-size: 10px;
    color: var(--discord-text-muted);
    margin-top: 4px;
    text-align: right;
}

.workflow-widget-log-status {
    font-size: 11px;
    color: var(--discord-text-muted);
    margin-top: 6px;
    padding: 0 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workflow-widget-error {
    color: #fca5a5;
    font-size: 12px;
    margin-top: 8px;
    padding: 8px 10px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 6px;
    border-left: 3px solid #ef4444;
}

/* Workflow Widget Images - Stacked Layout */
.workflow-widget-images {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
    width: 100%;
}

.workflow-widget-image {
    position: relative;
    width: 100%;
    background: #0d0e10;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    display: block;
}

.workflow-widget-image img,
.workflow-widget-image video {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

.workflow-widget-image-menu {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 2;
    opacity: 0;
}

.workflow-widget-image:hover .workflow-widget-image-menu,
.workflow-widget-image-menu:focus-visible {
    opacity: 1;
}

.workflow-widget-image-menu:hover {
    background: rgba(0, 0, 0, 0.85);
}

.workflow-widget-image-menu .material-icons {
    font-size: 20px;
}

@media (hover: none) {
    .workflow-widget-image-menu {
        opacity: 1;
    }
}

/* Per-image action popup menu */
.workflow-image-menu-popup {
    position: fixed;
    z-index: 10002;
    min-width: 200px;
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.workflow-image-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: none;
    background: transparent;
    color: #fff;
    cursor: pointer;
    border-radius: 5px;
    font: inherit;
    font-size: 0.88rem;
    text-align: left;
}

.workflow-image-menu-item:hover,
.workflow-image-menu-item:focus-visible {
    background: rgba(255, 255, 255, 0.08);
}

.workflow-image-menu-item .material-icons {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.7);
    width: 18px;
}

.workflow-image-menu-item.danger {
    color: #ff6b6b;
}

.workflow-image-menu-item.danger .material-icons {
    color: #ff6b6b;
}

.workflow-image-menu-item.danger:hover,
.workflow-image-menu-item.danger:focus-visible {
    background: rgba(255, 107, 107, 0.12);
}

/* Lightweight toast for menu actions (copy / delete) */
.workflow-image-toast-host {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10003;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.workflow-image-toast {
    background: rgba(20, 20, 22, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #fff;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.workflow-image-toast.error {
    border-color: rgba(255, 107, 107, 0.35);
    color: #ff9b9b;
}

/* Chat image attach modal */
.chat-image-attach-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overscroll-behavior: contain;
}

.chat-image-attach-modal {
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.chat-image-attach-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-image-attach-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}

.chat-image-attach-close {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.chat-image-attach-close:hover {
    color: #fff;
}

.chat-image-attach-close .material-icons {
    font-size: 20px;
}

.chat-image-attach-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-image-attach-preview img,
.chat-image-attach-preview video {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
    background: #0d0e10;
    flex-shrink: 0;
}

.chat-image-attach-id {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.04);
    padding: 4px 8px;
    border-radius: 4px;
    word-break: break-all;
}

.chat-image-attach-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px 16px;
}

.chat-image-attach-btn {
    text-align: left;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 12px 14px;
    color: #fff;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font: inherit;
}

.chat-image-attach-btn:hover:not(:disabled) {
    background: rgba(74, 158, 255, 0.12);
    border-color: rgba(74, 158, 255, 0.4);
}

.chat-image-attach-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

.chat-image-attach-btn-title {
    font-weight: 600;
    font-size: 0.92rem;
}

.chat-image-attach-btn-sub {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.55);
}

.chat-image-attach-btn-cancel {
    align-items: center;
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    background: transparent;
    border-color: rgba(255, 255, 255, 0.06);
    margin-top: 4px;
}

.chat-image-attach-btn-cancel:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.workflow-widget {
    -webkit-tap-highlight-color: transparent;
}

/* Mobile Responsive - Full Width within message content */
@media (max-width: 768px) {
    .workflow-widget {
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-radius: 6px;
        border: 1px solid rgba(255, 255, 255, 0.06);
        padding: 0;
        background: var(--bg-secondary, #111111);
        box-sizing: border-box;
    }

    .workflow-widget-header {
        padding: 8px 12px 6px 12px;
    }

    .workflow-widget-progress-section {
        padding: 0 12px 8px;
    }

    .workflow-widget-progress {
        margin: 0 0 6px;
    }

    .workflow-widget-progress-text {
        padding: 0;
    }

    .workflow-widget-log-status {
        padding: 0;
    }

    .workflow-widget-error {
        margin: 0 12px 8px;
    }

    .workflow-widget-images {
        gap: 4px;
        margin-top: 0;
    }

    .workflow-widget-image {
        border-radius: 0;
    }
}

/* ============================================
   Tool Call Widget
   ============================================ */
.tool-call-widget {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 0;
    margin: 4px 0;
    max-width: 360px;
    display: inline-block;
    overflow: hidden;
    font-size: 13px;
}

.tool-call-widget.tool-call-error {
    border-color: rgba(248, 113, 113, 0.3);
}

.tool-call-widget.tool-call-loading {
    border-color: rgba(156, 163, 175, 0.3);
}

.tool-call-widget.tool-call-loading .tool-call-workflow {
    color: #9ca3af;
}

.tool-call-icon.spinning {
    animation: spin-reverse 3s linear infinite;
}

@keyframes tool-call-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.tool-call-header {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    cursor: pointer;
    gap: 5px;
    line-height: 1;
}

.tool-call-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.tool-call-widget.collapsed {
    display: inline-block;
    vertical-align: middle;
}

.tool-call-info {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.tool-call-icon {
    font-size: 12px;
    color: #a78bfa;
    flex-shrink: 0;
    line-height: 1;
}

.tool-call-workflow {
    font-size: 11px;
    color: #c9cdd3;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    line-height: 1;
}

.tool-call-format-badge {
    font-size: 9px;
    padding: 1px 4px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    line-height: 1;
}

.tool-call-format-xml {
    background: rgba(167, 139, 250, 0.2);
    color: #a78bfa;
    border: 1px solid rgba(167, 139, 250, 0.3);
}

.tool-call-format-json {
    background: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(96, 165, 250, 0.3);
}

.tool-call-toggle {
    color: #6b7280;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.tool-call-toggle .material-icons-outlined {
    font-size: 14px;
    line-height: 1;
}

.tool-call-widget.collapsed .tool-call-body {
    display: none !important;
}

.tool-call-widget.expanded {
    background: #1a1b1e;
    display: block;
}

.tool-call-widget.expanded .tool-call-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.tool-call-body {
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    gap: 6px;
}

.tool-call-widget.expanded .tool-call-body {
    display: flex;
}

/* Inline params - flex row with wrapping */
.tool-call-params-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 3px 10px;
    align-items: baseline;
}

.tool-call-param-inline {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.tool-call-param-inline .tool-call-param-key {
    font-size: 9px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-weight: 500;
}

.tool-call-param-inline .tool-call-param-value {
    font-size: 11px;
    color: #e2e5e9;
}

/* Block params - full width */
.tool-call-param-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tool-call-param-block .tool-call-param-key {
    font-size: 9px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-weight: 500;
}

.tool-call-param-block .tool-call-param-value {
    font-size: 11px;
    color: #e2e5e9;
}

.tool-call-param-multiline {
    background: rgba(0, 0, 0, 0.2);
    padding: 5px 7px;
    border-radius: 3px;
    border-left: 2px solid rgba(167, 139, 250, 0.4);
    line-height: 1.35;
    white-space: pre-wrap;
    font-size: 11px;
    color: #d1d5db;
}

.tool-call-param-object {
    font-family: monospace;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px 6px;
    border-radius: 3px;
    white-space: pre-wrap;
    color: #9ca3af;
}

.tool-call-image-thumb {
    max-width: 60px;
    max-height: 60px;
    border-radius: 3px;
    object-fit: cover;
    background: #0d0e10;
    margin-top: 2px;
}

.tool-call-no-params {
    color: #6b7280;
    font-size: 10px;
    font-style: italic;
}

.tool-call-error-message {
    color: #fca5a5;
    font-size: 10px;
    padding: 4px 8px;
    background: rgba(239, 68, 68, 0.1);
}

.tool-call-null {
    color: #6b7280;
    font-style: italic;
}

.tool-call-bool {
    color: #34d399;
}

.tool-call-number {
    color: #60a5fa;
}

/* =====================
 * Tool Result Widget Styles
 * ===================== */

.tool-result-widget {
    margin: 6px 0;
    border-radius: 6px;
    background: #1a1b1e;
    border: 1px solid rgba(52, 211, 153, 0.2);
    overflow: hidden;
    font-size: 12px;
}

.tool-result-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    cursor: pointer;
    background: rgba(52, 211, 153, 0.05);
}

.tool-result-header:hover {
    background: rgba(52, 211, 153, 0.1);
}

.tool-result-icon {
    font-size: 14px;
    color: #34d399;
}

.tool-result-title {
    font-size: 11px;
    font-weight: 500;
    color: #9ca3af;
}

.tool-result-format-badge {
    font-size: 9px;
    padding: 1px 4px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.tool-result-format-xml {
    background: rgba(52, 211, 153, 0.2);
    color: #34d399;
    border: 1px solid rgba(52, 211, 153, 0.3);
}

.tool-result-format-json {
    background: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(96, 165, 250, 0.3);
}

.tool-result-preview {
    flex: 1;
    font-size: 11px;
    color: #6b7280;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tool-result-toggle {
    display: flex;
    align-items: center;
}

.tool-result-toggle .material-icons-outlined {
    font-size: 16px;
    color: #6b7280;
}

.tool-result-widget.collapsed .tool-result-body {
    display: none;
}

.tool-result-widget.expanded .tool-result-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.tool-result-body {
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.15);
}

.tool-result-fields {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tool-result-field-inline {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.tool-result-field-inline .tool-result-field-key {
    font-size: 10px;
    color: #6b7280;
    font-weight: 500;
}

.tool-result-field-inline .tool-result-field-value {
    font-size: 11px;
    color: #e2e5e9;
}

.tool-result-field-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
}

.tool-result-field-block .tool-result-field-key {
    font-size: 10px;
    color: #6b7280;
    font-weight: 500;
}

.tool-result-field-value-block {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    border-left: 2px solid rgba(52, 211, 153, 0.4);
    overflow: auto;
    max-height: 200px;
}

.tool-result-field-value-block pre {
    margin: 0;
    padding: 6px 8px;
    font-family: monospace;
    font-size: 10px;
    color: #d1d5db;
    white-space: pre-wrap;
    word-break: break-word;
}

.tool-result-null {
    color: #6b7280;
    font-style: italic;
}

.tool-result-bool {
    font-weight: 500;
}

.tool-result-bool.tool-result-true {
    color: #34d399;
}

.tool-result-bool.tool-result-false {
    color: #f87171;
}

.tool-result-number {
    color: #60a5fa;
}

.tool-result-empty {
    color: #6b7280;
    font-size: 10px;
    font-style: italic;
}

/* =====================
 * Compaction Widget Styles
 * ===================== */

.compaction-widget {
    margin: 8px 0;
    border: 1px solid #3f4147;
    border-radius: 8px;
    background: #1e1f22;
    overflow: hidden;
}

.compaction-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    cursor: pointer;
    background: #1e1f22;
}

.compaction-header:hover {
    background: #242428;
}

.compaction-icon {
    color: #a78bfa;
    font-size: 18px;
}

.compaction-title {
    color: #dbdee1;
    font-weight: 500;
    font-size: 13px;
}

.compaction-count {
    color: #949ba4;
    font-size: 12px;
    margin-left: auto;
    padding-right: 4px;
}

.compaction-toggle {
    color: #949ba4;
    display: flex;
    align-items: center;
}

.compaction-toggle .material-icons-outlined {
    font-size: 18px;
}

.compaction-body {
    border-top: 1px solid #3f4147;
    padding: 12px;
    background: #15151a;
}

.compaction-summary {
    color: #b5bac1;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Collapsed state */
.compaction-widget.collapsed .compaction-body {
    display: none;
}

/* Expanded state */
.compaction-widget.expanded .compaction-header {
    border-bottom: 1px solid transparent;
}

/* Compaction Divider */
.chat-compaction-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
    padding: 0 16px;
}

.chat-compaction-divider-line {
    flex: 1;
    height: 1px;
    background: #3f4147;
}

.chat-compaction-divider-text {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #949ba4;
    font-size: 12px;
    white-space: nowrap;
}

.chat-compaction-divider-text .material-icons-outlined {
    font-size: 14px;
    color: #a78bfa;
}

/* LoRA Result Widget */
.lora-result-widget {
    background: #1a1b1e;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    margin: 0;
    padding: 0;
    overflow: visible;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    align-self: flex-start;
    display: block;
}

.lora-result-header {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: rgba(52, 211, 153, 0.08);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin: 0;
}

.lora-result-header .material-icons-outlined {
    font-size: 14px;
    color: #34d399;
}

.lora-result-title {
    font-weight: 600;
    color: #e2e5e9;
    font-size: 11px;
    flex: 1;
}

.lora-result-model {
    font-size: 9px;
    color: #9ca3af;
    background: rgba(255, 255, 255, 0.06);
    padding: 1px 4px;
    border-radius: 2px;
}

.lora-result-list {
    padding: 3px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    height: auto;
    min-height: 0;
}

.lora-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    padding: 6px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    height: auto;
    min-height: 0;
}

.lora-card-image-wrap {
    flex-shrink: 0;
    width: 128px;
    height: 128px;
    position: relative;
}

.lora-card-image {
    width: 128px;
    height: 128px;
    object-fit: cover;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.3);
    display: block;
}

.lora-card-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 128px;
    height: 128px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    display: none;
    align-items: center;
    justify-content: center;
    color: #4a4a4a;
}

.lora-card-image-wrap.no-img .lora-card-image {
    display: none;
}

.lora-card-image-wrap.no-img .lora-card-placeholder {
    display: flex;
}

.lora-card-placeholder .material-icons-outlined {
    font-size: 36px;
}

.lora-card-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.lora-card-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.lora-name {
    font-weight: 500;
    color: #e2e5e9;
    font-size: 12px;
    flex: 1;
    min-width: 0;
    word-break: break-word;
    line-height: 1.3;
}

.lora-hash {
    font-family: monospace;
    font-size: 10px;
    color: #a78bfa;
    background: rgba(167, 139, 250, 0.1);
    padding: 1px 5px;
    border-radius: 2px;
    cursor: pointer;
    flex-shrink: 0;
}

.lora-triggers {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.lora-trigger {
    font-size: 10px;
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.12);
    padding: 1px 5px;
    border-radius: 2px;
}

.lora-stat {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 10px;
    color: #6b7280;
    flex-shrink: 0;
}

.lora-stat .material-icons-outlined {
    font-size: 12px;
    color: #4a4a4a;
}

.lora-result-empty,
.lora-result-error {
    padding: 6px;
    text-align: center;
    color: #6b7280;
    font-size: 11px;
}

.lora-result-error {
    color: #f87171;
}

/* =========================================
   Chat Settings Panel
   ========================================= */

.chat-settings-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    background: #1a1a1a;
    border-left: 1px solid #333;
    transform: translateX(100%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-settings-panel.open {
    transform: translateX(0);
}

.chat-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #333;
    background: #222;
}

.chat-settings-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #e0e0e0;
}

.chat-settings-close {
    background: none;
    border: none;
    color: #888;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-settings-close:hover {
    color: #fff;
}

.chat-settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.chat-settings-loading {
    display: flex;
    justify-content: center;
    padding: 40px;
}

.chat-settings-error {
    text-align: center;
    padding: 20px;
    color: #888;
}

.chat-settings-error .btn-retry {
    margin-top: 10px;
    padding: 6px 12px;
    background: #333;
    border: 1px solid #444;
    color: #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
}

.chat-settings-error .btn-retry:hover {
    background: #444;
}

.chat-settings-empty {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.chat-settings-section {
    margin-bottom: 20px;
}

.chat-settings-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.chat-settings-section-header h4 {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-settings-section-header button {
    background: none;
    border: none;
    color: #4a9eff;
    cursor: pointer;
    padding: 4px;
    font-size: 12px;
}

.chat-settings-section-header button:hover {
    color: #6ab0ff;
}

/* Processing State Styles */
.processing-state-section {
    border-bottom: 1px solid #333;
    padding-bottom: 12px;
    margin-bottom: 4px;
}

.processing-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
}

.processing-status.status-idle {
    color: #888;
    background: #222;
}

.processing-status.status-idle i {
    font-size: 8px;
}

.processing-status.status-processing {
    color: #4a9eff;
    background: rgba(74, 158, 255, 0.15);
}

.processing-status.status-waiting {
    color: #eab308;
    background: rgba(234, 179, 8, 0.15);
}

.pending-workflows {
    margin-top: 10px;
}

.pending-workflows-header {
    font-size: 11px;
    color: #888;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pending-workflows-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pending-workflow-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #222;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
}

.pending-workflow-item .workflow-id {
    color: #ccc;
    font-family: monospace;
    font-size: 11px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pending-workflow-item .workflow-time {
    color: #666;
    font-size: 10px;
}

/* Todo List Styles */
.todo-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.todo-empty {
    color: #666;
    font-size: 12px;
    text-align: center;
    padding: 12px;
    background: #222;
    border-radius: 6px;
}

.todo-item {
    background: #222;
    border-radius: 6px;
    padding: 10px;
    border-left: 3px solid #666;
}

.todo-item.priority-low {
    border-left-color: #22c55e;
}

.todo-item.priority-medium {
    border-left-color: #eab308;
}

.todo-item.priority-high {
    border-left-color: #ef4444;
}

.todo-progress-bar {
    height: 3px;
    background: #333;
    border-radius: 2px;
    margin-bottom: 8px;
    overflow: hidden;
}

.todo-progress-fill {
    height: 100%;
    background: #4a9eff;
    border-radius: 2px;
}

.todo-item .todo-task {
    width: 100%;
    background: transparent;
    border: none;
    color: #e0e0e0;
    font-size: 13px;
    padding: 4px 0;
    margin-bottom: 6px;
    outline: none;
    resize: none;
    min-height: 24px;
    max-height: 240px;
    overflow-y: auto;
    line-height: 1.4;
    font-family: inherit;
}

.todo-item .todo-task:focus {
    border-bottom: 1px solid #4a9eff;
}

.todo-item .todo-task::placeholder {
    color: #666;
}

.todo-item .todo-priority,
.todo-item .todo-progress {
    background: #333;
    border: 1px solid #444;
    color: #e0e0e0;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 11px;
}

.todo-item .todo-priority {
    width: 60px;
    margin-right: 6px;
}

.todo-item .todo-progress {
    width: 50px;
    margin-right: 6px;
}

.todo-item .todo-delete {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 4px;
    font-size: 11px;
}

.todo-item .todo-delete:hover {
    color: #ef4444;
}

/* System Prompt Modal Overlay - override conflicting styles from other CSS */
.system-prompt-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 10001 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: rgba(0, 0, 0, 0.85) !important;
}

@media (max-width: 768px) {
    .system-prompt-overlay {
        align-items: flex-end !important;
    }
}

/* System Prompt Modal */
.system-prompt-modal {
    max-width: 700px;
    width: 90%;
    background: var(--bg-secondary, #1a1a1a);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.system-prompt-modal .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.system-prompt-modal .modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

.system-prompt-modal .modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.system-prompt-modal .modal-close:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.system-prompt-modal .modal-body {
    padding: 16px 20px;
    flex: 1;
    overflow: auto;
}

.system-prompt-modal .modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

@media (max-width: 768px) {
    .system-prompt-modal {
        width: 100% !important;
        max-width: 100% !important;
        height: 92vh !important;
        height: 92dvh !important; /* dynamic vh - resizes with keyboard */
        max-height: 92vh !important;
        max-height: 92dvh !important;
        margin: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        padding: 0 !important;
        background: #1e1e1e !important;
    }

    .system-prompt-modal .modal-header {
        padding: 16px !important;
        border-bottom: none !important;
        background: #1e1e1e !important;
    }

    .system-prompt-modal .modal-header h3 {
        font-size: 17px !important;
        font-weight: 600 !important;
    }

    .system-prompt-modal .modal-close {
        width: 28px !important;
        height: 28px !important;
        font-size: 20px !important;
        background: rgba(255,255,255,0.1) !important;
        border-radius: 50% !important;
    }

    .system-prompt-modal .modal-body {
        padding: 0 !important;
        flex: 1 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .system-prompt-modal .modal-footer {
        padding: 12px 16px 20px !important;
        border-top: none !important;
        background: #1e1e1e !important;
        gap: 12px !important;
    }

    .system-prompt-modal .modal-footer .btn {
        flex: 1 !important;
        padding: 14px 20px !important;
        border-radius: 10px !important;
        font-size: 15px !important;
        font-weight: 600 !important;
    }

    .system-prompt-modal .modal-footer .btn-primary {
        background: #5865f2 !important;
        border: none !important;
        color: #fff !important;
    }

    .system-prompt-modal .modal-footer .btn-secondary {
        background: rgba(255,255,255,0.1) !important;
        border: none !important;
        color: #fff !important;
    }

    .system-prompt-textarea {
        flex: 1 !important;
        min-height: 200px !important;
        max-height: none !important;
        font-size: 16px !important;
        padding: 16px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        background: #111 !important;
        border: none !important;
        border-radius: 0 !important;
        color: #d4d4d4 !important;
        line-height: 1.6 !important;
        resize: none !important;
    }

    .system-prompt-textarea:focus {
        outline: none !important;
    }

    /* View-only mode: single close button centered */
    .system-prompt-modal.view-only .modal-footer {
        justify-content: center !important;
    }

    .system-prompt-modal.view-only .modal-footer .btn {
        flex: none !important;
        min-width: 120px !important;
    }

    /* View-only textarea styling */
    .system-prompt-modal.view-only .system-prompt-textarea {
        background: #0a0a0a !important;
        color: #999 !important;
    }
}

/* View-only button styling */
.btn-view-prompt-full.editable i:first-child {
    color: #5865f2;
}

.system-prompt-textarea {
    width: 100%;
    min-height: 300px;
    background: #1a1a1a;
    border: 1px solid #333;
    color: #e0e0e0;
    padding: 12px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 12px;
    line-height: 1.5;
    resize: vertical;
}

.system-prompt-textarea:focus {
    outline: none;
    border-color: #4a9eff;
}

.system-prompt-textarea[readonly] {
    background: #111;
    color: #888;
}

/* Settings toggle button active state */
.chat-settings-toggle.active {
    color: #4a9eff;
}

/* Prompt buttons section - side by side */
.prompt-buttons-section {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.prompt-buttons-section .btn-terminal {
    flex: 1;
    min-width: 100px;
}

/* Full Prompt Preview Modal */
.full-prompt-preview-modal {
    max-width: 900px;
    width: 95%;
    background: var(--bg-secondary, #1a1a1a);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.full-prompt-preview-modal .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.full-prompt-preview-modal .modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

.full-prompt-preview-modal .modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.full-prompt-preview-modal .modal-close:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.full-prompt-preview-modal .modal-body {
    padding: 16px 20px;
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

.full-prompt-preview-modal .modal-footer {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

/* Loading state */
.full-prompt-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #888;
}

.full-prompt-loading p {
    margin-top: 12px;
}

/* Error state */
.full-prompt-error {
    color: #f87171;
    padding: 20px;
    text-align: center;
}

/* Metadata row */
.full-prompt-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.full-prompt-bot-name {
    font-weight: 600;
    color: #fff;
}

.full-prompt-bot-type {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(88, 101, 242, 0.2);
    color: #a5b4fc;
}

/* The prompt textarea */
.full-prompt-textarea {
    width: 100%;
    flex: 1;
    min-height: 400px;
    background: #0d0d0d;
    border: 1px solid #333;
    color: #d4d4d4;
    padding: 16px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    resize: none;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.full-prompt-textarea:focus {
    outline: none;
}

/* Stats row */
.full-prompt-stats {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    font-size: 12px;
    color: #666;
}

.full-prompt-stats span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .full-prompt-preview-modal {
        width: 100%;
        max-width: 100%;
        height: 92vh;
        max-height: 92vh;
        margin: 0;
        border-radius: 16px 16px 0 0;
    }

    .full-prompt-textarea {
        min-height: 200px;
        font-size: 13px;
    }

    .prompt-buttons-section {
        flex-direction: column;
    }

    .prompt-buttons-section .btn-terminal {
        width: 100%;
    }
}

/* ================================
   Suggested Responses Widget
   ================================ */

.suggested-responses-widget {
    /* Minimal spacing - widget often appears alone in message */
}

/* Fix: Hide empty paragraphs that cause extra spacing */
.chat-message-text p:empty {
    display: none;
}

/* Fix: Reset whitespace handling inside widgets to prevent HTML newline spacing */
.chat-message-text .suggested-responses-widget,
.chat-message-text .tool-call-widget {
    white-space: normal;
}

.suggested-responses-label {
    font-size: 12px;
    color: var(--discord-text-muted);
    margin-bottom: 8px;
}

.suggested-responses-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.suggested-response-pill {
    padding: 8px 16px;
    background: var(--discord-bg-hover);
    border: 1px solid var(--discord-divider);
    border-radius: 16px;
    color: var(--discord-text-normal);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}

@media (hover: hover) {
    .suggested-response-pill:hover {
        background: #35363c;
        border-color: #5865f2;
    }
}

.suggested-response-pill:active {
    background: #5865f2;
    color: #ffffff;
}

.suggested-response-pill.selected {
    background: #35363c;
    border-color: #5865f2;
}

.suggested-responses-widget.has-selection .suggested-response-pill:not(.selected) {
    opacity: 0.5;
    cursor: default;
}

/* Think/reasoning toggle (lightbulb icon in message header) */
.think-toggle {
    cursor: pointer;
    color: #5a5a7a;
    font-size: 0.8em;
    margin-left: 2px;
    padding: 2px 6px;
    user-select: none;
}

.think-toggle:hover {
    color: #7a7a9a;
}

.think-toggle.thinking {
    animation: think-pulse 1.5s ease-in-out infinite;
}

@keyframes think-pulse {
    0%, 100% { color: #5a5a7a; }
    50% { color: #aaaadd; }
}

/* Think/reasoning content block */
.think-block {
    margin: 0;
    padding: 0;
    font-size: 0.82em;
    border: none;
    background: none;
}

.think-collapse {
    cursor: pointer;
    color: #5a5a7a;
    font-size: 0.85em;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.think-collapse:hover {
    color: #8a8abb;
}

.think-content {
    padding: 8px 12px;
    color: #9a9abb;
    font-size: 1.15em;
    white-space: pre-wrap;
    word-break: break-word;
    border-left: 2px solid #4a4a6a;
    margin-top: 2px;
    margin-left: 2px;
    line-height: 1.5;
}

