/**
 * 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;
}

.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;
}

.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;
    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: 0;
    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;
}

/* =====================
   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;
}

/* 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:hover {
    background: var(--discord-bg-hover);
    color: var(--discord-text-normal);
}

/* Mobile: fixed position so it stays visible */
@media (max-width: 768px) {
    .chat-scroll-bottom {
        position: fixed;
        bottom: 130px;
        right: 16px;
        z-index: 100;
    }
}

/* 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);
}

.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);
}

.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) {
    .chat-control {
        display: block;
        height: auto;
        overflow: visible;
    }

    .chat-control .chat-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 60;
        background: var(--discord-bg-primary);
    }

    .chat-control .chat-messages-container {
        overflow: visible;
        height: auto;
        margin-top: 48px;
    }

    .chat-control .chat-messages {
        overflow: visible;
        height: auto;
        padding-bottom: 70px;
    }

    /* 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;
    }

    .chat-control .chat-composer {
        position: fixed;
        bottom: 50px;
        left: 0;
        right: 0;
        padding: 6px 12px;
        background: var(--discord-bg-primary);
        border-top: 1px solid var(--discord-bg-tertiary);
        z-index: 50;
    }

    .chat-control .chat-typing-indicator {
        position: fixed;
        bottom: 115px;
        left: 0;
        right: 0;
        z-index: 51;
        padding: 2px 12px;
        height: auto;
        font-size: 11px;
        background: transparent;
        border: 1px solid red;
    }

    .chat-control .chat-new-messages {
        position: fixed;
        bottom: 120px;
        z-index: 51;
    }
}

/* 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 1s linear infinite;
}

.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-text {
    font-size: 10px;
    color: var(--discord-text-muted);
    margin-top: 4px;
    text-align: right;
}

.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 Carousel */
.workflow-widget-carousel {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 100%;
    overflow: hidden;
    background: #0d0e10;
    border-radius: 6px;
    margin-top: 6px;
}

.workflow-carousel-track {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-wrap: nowrap;
    will-change: transform;
}

.workflow-carousel-slide {
    min-width: 100%;
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.workflow-carousel-slide img,
.workflow-carousel-slide video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.workflow-carousel-slide:hover {
    cursor: pointer;
}

/* Carousel Navigation */
.workflow-carousel-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    cursor: pointer;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
}

.workflow-carousel-nav:hover {
    background: rgba(0, 0, 0, 0.7);
}

.workflow-carousel-nav .material-icons {
    font-size: 20px;
    color: #fff;
}

.workflow-carousel-prev {
    left: 6px;
}

.workflow-carousel-next {
    right: 6px;
}

/* Carousel Counter */
.workflow-carousel-counter {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: rgba(255, 255, 255, 0.9);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    z-index: 3;
}

/* Workflow Widget - Touch-friendly and Mobile Responsive */
.workflow-widget {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

.workflow-widget-carousel {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y pinch-zoom;
}

.workflow-carousel-track {
    -webkit-user-select: none;
    user-select: none;
}

/* 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 {
        margin: 0 12px 6px;
    }

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

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

    .workflow-widget-carousel {
        border-radius: 0;
        margin-top: 0;
    }

    .workflow-carousel-slide img,
    .workflow-carousel-slide video {
        object-fit: contain;
    }

    .workflow-carousel-nav {
        width: 40px;
        height: 40px;
    }

    .workflow-carousel-nav .material-icons {
        font-size: 24px;
    }

    .workflow-carousel-prev {
        left: 8px;
    }

    .workflow-carousel-next {
        right: 8px;
    }

    .workflow-carousel-counter {
        bottom: 10px;
        padding: 4px 10px;
        font-size: 12px;
    }
}

/* ============================================
   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-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-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;
}

/* =====================
 * 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: 14px !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;
}
