:root {
            --chat-bg: #1a1a1a;
            --chat-sidebar-bg: #242424;
            --chat-input-bg: #2d2d2d;
            --chat-message-user: #007bff;
            --chat-message-bot: #3a3a3a;
            --chat-border: #3a3a3a;
            --safe-top: env(safe-area-inset-top, 0px);
            --safe-right: env(safe-area-inset-right, 0px);
            --safe-bottom: env(safe-area-inset-bottom, 0px);
            --safe-left: env(safe-area-inset-left, 0px);
            --effective-safe-bottom: var(--safe-bottom);
            /* --app-height is the dynamic VISIBLE height (shrinks when keyboard is open) */
            --app-height: 100dvh;
            /* --body-height is the dynamic FULL window height (stays large when keyboard is open) */
            --body-height: 100dvh;
}

.icon-16 {
    font-size: 16px;
}

.icon-16.material-icons {
    font-size: 16px;
}

.icon-18 {
    font-size: 18px;
}

.icon-48 {
    font-size: 48px;
}

.va-middle {
    vertical-align: middle;
}

.text-muted-666 {
    color: #666;
}

        * {
            box-sizing: border-box;
        }

        body {
            background-color: var(--chat-bg);
            color: #e0e0e0;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            margin: 0;
            padding: 0;
            /* Use body-height (full window) for the body to avoid reveal of black space outside it */
            height: var(--body-height);
            min-height: var(--body-height);
            overflow: hidden;
            /* Ensure it stays at top */
            position: relative;
        }

        .chat-container {
            display: flex;
            height: var(--app-height);
            min-height: var(--app-height);
            max-width: 1400px;
            margin: 0 auto;
            padding-top: var(--safe-top);
            padding-right: var(--safe-right);
            padding-left: var(--safe-left);
            /* Use absolute positioning to follow the visual viewport offset on mobile Safari */
            position: absolute;
            top: var(--visual-top, 0);
            left: 0;
            right: 0;
            z-index: 10;
        }

        .channel-sidebar {
            width: 280px;
            background: var(--chat-sidebar-bg);
            border-right: 1px solid var(--chat-border);
            display: flex;
            flex-direction: column;
            flex-shrink: 0;
            height: 100%;
            overflow: hidden;
        }

        .sidebar-header {
            padding: 1rem;
            border-bottom: 1px solid var(--chat-border);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .sidebar-header h6 {
            margin: 0;
            font-weight: 600;
        }

        .section {
            padding: 0.5rem;
        }

        .sidebar-content {
            flex: 1;
            min-height: 0;
            overflow-y: auto;
            overflow-x: hidden;
            -webkit-overflow-scrolling: touch;
        }

        .section-title {
            font-size: 0.7rem;
            font-weight: 600;
            text-transform: uppercase;
            color: #888;
            padding: 0.5rem;
            margin-bottom: 0.25rem;
        }

        .channel-list {
            display: flex;
            flex-direction: column;
            gap: 0.125rem;
        }

        .channel-item {
            padding: 0.6rem 0.75rem;
            background: transparent;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 0.75rem;
            transition: background-color 0.15s;
            color: #ccc;
        }

        .unread-badge {
            min-width: 18px;
            height: 18px;
            border-radius: 999px;
            background: #ff4d4f;
            color: #fff;
            font-size: 0.68rem;
            font-weight: 700;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0 5px;
            margin-left: 8px;
            flex-shrink: 0;
            line-height: 1;
        }

        .channel-item:hover {
            background: rgba(255, 255, 255, 0.05);
        }

        .channel-item.active {
            background: rgba(0, 123, 255, 0.2);
            color: #fff;
        }

        .channel-icon {
            width: 32px;
            height: 32px;
            border-radius: 6px;
            background: #3a3a3a;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.9rem;
        }

        .channel-icon img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            border-radius: 6px;
        }

        .channel-info {
            flex: 1;
            min-width: 0;
        }

        .channel-info .channel-name {
            font-weight: 500;
            font-size: 0.9rem;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            display: flex;
            align-items: center;
            gap: 0.35rem;
        }

        .channel-pinned-icon {
            color: #f4c542;
            flex-shrink: 0;
        }

        .channel-bot-only-icon {
            color: #6ecbff;
            flex-shrink: 0;
        }

        .channel-stats {
            font-size: 0.75rem;
            color: #888;
        }

        .chat-area {
            flex: 1;
            display: flex;
            flex-direction: column;
            min-width: 0;
        }

        .loading-placeholder {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            color: #888;
        }

        .active-chat {
            flex: 1;
            display: flex;
            flex-direction: column;
            height: 100%;
        }

        .chat-header {
            padding: 0.75rem 1rem;
            background: var(--chat-sidebar-bg);
            border-bottom: 1px solid var(--chat-border);
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 0.75rem;
            flex-wrap: nowrap;
        }

        .chat-header .channel-info {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            flex: 1;
            min-width: 0;
        }

        .chat-header .channel-info > div:last-child {
            min-width: 0;
        }

        .chat-connection-status {
            margin-top: 0.2rem;
            font-size: 0.75rem;
            line-height: 1.3;
            color: #ffcc80;
        }

        .chat-connection-status.state-connected {
            color: #7bd88f;
        }

        .chat-connection-status.state-reconnecting,
        .chat-connection-status.state-connecting,
        .chat-connection-status.state-resyncing {
            color: #ffcc80;
        }

        .chat-connection-status.state-disconnected,
        .chat-connection-status.state-degraded {
            color: #ff8a80;
        }

        .channel-actions {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            gap: 0.5rem;
            margin-left: auto;
            flex-shrink: 0;
        }

        .chat-header .channel-name {
            font-weight: 600;
            margin: 0;
        }

        .chat-header .channel-description {
            font-size: 0.8rem;
            color: #888;
            margin: 0;
        }

        .messages-wrapper {
            flex: 1;
            position: relative;
            display: flex;
            flex-direction: column;
            min-height: 0;
            overflow: hidden;
        }

        .messages-container {
            flex: 1;
            overflow-y: auto;
            padding: 1rem;
        }

        /* Jump to Bottom Button */
        .jump-to-bottom-btn {
            position: absolute;
            bottom: 15px;
            right: 25px;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: rgba(0, 123, 255, 0.85);
            color: white;
            border: none;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 100;
            transition: all 0.2s ease;
            opacity: 1;
            transform: scale(1);
        }

        .jump-to-bottom-btn:hover {
            background: rgba(0, 123, 255, 1);
            transform: scale(1.1);
            box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
        }

        .jump-to-bottom-btn.d-none {
            display: none !important;
            opacity: 0;
            transform: scale(0.5);
        }

        .jump-to-bottom-btn .unread-dot {
            position: absolute;
            top: 2px;
            right: 2px;
            width: 10px;
            height: 10px;
            background: #ff4d4f;
            border-radius: 50%;
            border: 2px solid #fff;
        }

        #older-messages-loading {
            text-align: center;
            padding: 0.5rem 1rem;
            font-size: 0.8rem;
            color: #888;
            font-style: italic;
        }

        #beginning-of-conversation {
            text-align: center;
            padding: 0.75rem 1rem;
            font-size: 0.8rem;
            color: #888;
            border-bottom: 1px solid #3a3a4a;
            margin-bottom: 0.75rem;
        }

        .message {
            margin-bottom: 1rem;
            display: flex;
            flex-direction: column;
            max-width: 70%;
            position: relative;
        }

        .message.user {
            margin-left: auto;
            align-items: flex-end;
        }

        .message.bot {
            margin-right: auto;
            align-items: flex-start;
        }

        .message-sender {
            font-size: 0.7rem;
            color: #888;
            margin-bottom: 0.25rem;
        }

        .message-content {
            padding: 0.6rem 0.9rem;
            border-radius: 16px;
            word-wrap: break-word;
            overflow-wrap: anywhere;
            line-height: 1.4;
        }

        .message-content > :first-child {
            margin-top: 0;
        }

        .message-content > :last-child {
            margin-bottom: 0;
        }

        .message-content p {
            margin: 0.3rem 0;
        }

        .message-content ul,
        .message-content ol {
            margin: 0.3rem 0;
            padding-left: 1.2rem;
        }

        .message-content blockquote {
            margin: 0.35rem 0;
            padding: 0 0 0 0.7rem;
            border-left: 3px solid rgba(255, 255, 255, 0.25);
            opacity: 0.95;
        }

        .message-content code {
            font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
            font-size: 0.82em;
            padding: 0.08rem 0.35rem;
            border-radius: 4px;
            background: rgba(0, 0, 0, 0.3);
            word-break: break-word;
        }

        .message-content pre {
            margin: 0.4rem 0;
            padding: 0.55rem 0.65rem;
            border-radius: 8px;
            background: rgba(0, 0, 0, 0.35);
            overflow-x: auto;
        }

        .message-content pre code {
            background: transparent;
            padding: 0;
            border-radius: 0;
            word-break: normal;
            white-space: pre;
        }

        .message-content a {
            color: #8ecbff;
            text-decoration: underline;
            text-underline-offset: 2px;
            word-break: break-word;
        }

        .discord-underline {
            text-decoration: underline;
            text-underline-offset: 2px;
        }

        .discord-mention {
            display: inline-block;
            padding: 0.02rem 0.3rem;
            border-radius: 5px;
            font-weight: 600;
            background: rgba(88, 101, 242, 0.25);
            color: #d6dcff;
        }

        .discord-mention-channel {
            background: rgba(68, 170, 255, 0.2);
            color: #b8e2ff;
        }

        .discord-mention-role {
            background: rgba(249, 168, 37, 0.2);
            color: #ffd483;
        }

        .discord-mention-command {
            background: rgba(46, 204, 113, 0.18);
            color: #b9f0cb;
        }

        .discord-mention-broadcast {
            background: rgba(255, 140, 0, 0.25);
            color: #ffd3a1;
        }

        .discord-timestamp {
            opacity: 0.9;
            border-bottom: 1px dotted rgba(255, 255, 255, 0.35);
            cursor: default;
        }

        .discord-subtext {
            display: inline-block;
            font-size: 0.82em;
            opacity: 0.5;
            line-height: 1.25;
        }

        .discord-spoiler {
            border-radius: 4px;
            background: rgba(20, 20, 20, 0.9);
            color: transparent;
            cursor: pointer;
            transition: color 0.15s ease, background-color 0.15s ease;
        }

        .discord-spoiler * {
            color: inherit;
        }

        .discord-spoiler.revealed {
            color: inherit;
            background: rgba(20, 20, 20, 0.45);
        }

        .discord-spoiler:focus-visible {
            outline: 2px solid rgba(142, 203, 255, 0.75);
            outline-offset: 1px;
        }

        .message.user .message-content {
            background: var(--chat-message-user);
            color: white;
            border-bottom-right-radius: 4px;
        }

        .message.bot .message-content {
            background: var(--chat-message-bot);
            color: #e0e0e0;
            border-bottom-left-radius: 4px;
        }

        .message-time {
            font-size: 0.65rem;
            color: #666;
            margin-top: 0.25rem;
        }

        .typing-indicator {
            padding: 0.5rem 1rem;
            font-size: 0.8rem;
            color: #888;
            font-style: italic;
        }

        .input-area {
            padding: 0.75rem 1rem calc(0.75rem + var(--effective-safe-bottom));
            background: var(--chat-sidebar-bg);
            border-top: 1px solid var(--chat-border);
        }

        .input-area textarea,
        #message-input {
            width: 100%;
            background: var(--chat-input-bg);
            border: 1px solid var(--chat-border);
            border-radius: 8px;
            color: #e0e0e0;
            padding: 0.6rem 0.9rem;
            resize: none;
            /* iOS Safari zooms focused inputs below 16px */
            font-size: 16px;
            line-height: 1.4;
        }

        .input-area textarea:focus {
            outline: none;
            border-color: #007bff;
        }

        .input-actions {
            display: flex;
            justify-content: flex-end;
            align-items: center;
            gap: 0.5rem;
            margin-top: 0.5rem;
        }

        .llm-processing-indicator {
            display: none;
            align-items: center;
            gap: 0.45rem;
            color: #9ec6ff;
            font-size: 0.78rem;
            margin-bottom: 0.45rem;
        }

        .llm-processing-indicator.active {
            display: inline-flex;
        }

        .llm-processing-dot {
            width: 8px;
            height: 8px;
            border-radius: 999px;
            background: #5aa8ff;
            animation: llm-processing-pulse 1.1s ease-in-out infinite;
        }

        @keyframes llm-processing-pulse {
            0%, 100% { opacity: 0.35; transform: scale(0.9); }
            50% { opacity: 1; transform: scale(1.1); }
        }

        @media (prefers-reduced-motion: reduce) {
            .llm-processing-dot {
                animation: none;
            }
        }

        .mobile-hint {
            display: none;
            color: #888;
            font-size: 0.75rem;
            margin-right: auto;
        }

        .btn-icon {
            background: transparent;
            border: 1px solid var(--chat-border);
            color: #888;
            padding: 0.4rem 0.75rem;
            border-radius: 6px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 0.25rem;
            font-size: 0.85rem;
        }

        .btn-icon:hover {
            background: rgba(255, 255, 255, 0.05);
            color: #e0e0e0;
        }

        .btn-icon:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            pointer-events: none;
        }

        .btn-primary {
            background: #007bff;
            border: none;
            color: white;
            padding: 0.4rem 1rem;
            border-radius: 6px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 0.25rem;
            font-size: 0.85rem;
        }

        .btn-primary:hover {
            background: #0069d9;
        }

        .btn-primary:disabled {
            background: #444;
            cursor: not-allowed;
        }

        /* User area at bottom of sidebar */
        .user-area {
            padding: 0.75rem 0.75rem calc(0.75rem + var(--effective-safe-bottom));
            border-top: 1px solid var(--chat-border);
            background: rgba(0, 0, 0, 0.2);
            flex-shrink: 0;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background: #007bff;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 600;
            font-size: 0.9rem;
        }

        .user-details {
            flex: 1;
            min-width: 0;
        }

        .user-name {
            font-size: 0.85rem;
            font-weight: 500;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .user-status {
            font-size: 0.7rem;
            color: #28a745;
        }

        /* Login/Register pages */
        .auth-container {
            min-height: var(--app-height);
            height: var(--app-height);
            display: flex;
            /* Use 'safe center' to prevent content cutoff on iOS Safari when content overflows.
               Falls back to 'start' alignment if centering would cause data loss at the top. */
            align-items: safe center;
            justify-content: center;
            padding: calc(2rem + var(--safe-top)) calc(2rem + var(--safe-right)) calc(2rem + var(--effective-safe-bottom)) calc(2rem + var(--safe-left));
            overflow-y: auto;
            overflow-x: hidden;
            -webkit-overflow-scrolling: touch;
            /* Follow visual viewport on mobile */
            position: absolute;
            top: var(--visual-top, 0);
            left: 0;
            right: 0;
            z-index: 10;
        }

        .auth-card {
            background: var(--chat-sidebar-bg);
            border: 1px solid var(--chat-border);
            border-radius: 12px;
            padding: 2rem;
            width: 100%;
            max-width: 400px;
        }

        .auth-card-narrow {
            max-width: 500px;
        }

        .auth-page-scrollable {
            min-height: 100%;
            padding: calc(2rem + var(--safe-top)) calc(1rem + var(--safe-right)) calc(2rem + var(--effective-safe-bottom)) calc(1rem + var(--safe-left));
            align-items: flex-start;
        }

        .auth-header {
            text-align: center;
            margin-bottom: 1.5rem;
        }

        .auth-header .material-icons {
            font-size: 48px;
            color: #007bff;
        }

        .auth-header h4 {
            margin-top: 0.5rem;
            margin-bottom: 0.25rem;
        }

        .auth-header p {
            color: #888;
            margin: 0;
        }

        .form-control {
            background: var(--chat-input-bg);
            border: 1px solid var(--chat-border);
            color: #e0e0e0;
        }

        .form-control:focus {
            background: var(--chat-input-bg);
            border-color: #007bff;
            color: #e0e0e0;
            box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
        }

        /* Override Safari/WebKit autofill yellow background.
           Safari ignores background-color on autofilled inputs; the only reliable
           override is an inset box-shadow. -webkit-text-fill-color ensures
           consistent text colour regardless of whether autocomplete is new-password
           or current-password (which Safari handles differently by default). */
        input:-webkit-autofill,
        input:-webkit-autofill:hover,
        input:-webkit-autofill:focus,
        input:-webkit-autofill:active {
            -webkit-text-fill-color: #e0e0e0;
            -webkit-box-shadow: 0 0 0px 1000px var(--chat-input-bg) inset;
            transition: background-color 5000s ease-in-out 0s;
        }

        .form-label {
            color: #ccc;
        }

        .form-text {
            color: #888;
        }

        .alert {
            border-radius: 8px;
        }

        .login-prompt {
            text-align: center;
            padding: 1rem;
            background: rgba(0, 123, 255, 0.1);
            border-radius: 8px;
            margin-bottom: 1rem;
        }

        .login-prompt a {
            color: #007bff;
            text-decoration: none;
            font-weight: 500;
        }

        .login-prompt a:hover {
            text-decoration: underline;
        }

        /* Registration disabled page */
        .error-container {
            min-height: var(--app-height);
            height: var(--app-height);
            display: flex;
            /* Use 'safe center' to prevent content cutoff on iOS Safari when content overflows.
               Falls back to 'start' alignment if centering would cause data loss at the top. */
            align-items: safe center;
            justify-content: center;
            padding: calc(2rem + var(--safe-top)) calc(2rem + var(--safe-right)) calc(2rem + var(--effective-safe-bottom)) calc(2rem + var(--safe-left));
            text-align: center;
            overflow-y: auto;
            overflow-x: hidden;
            -webkit-overflow-scrolling: touch;
            /* Follow visual viewport on mobile */
            position: absolute;
            top: var(--visual-top, 0);
            left: 0;
            right: 0;
            z-index: 10;
        }

        .error-icon {
            font-size: 64px;
            color: #ffc107;
        }

        .error-title {
            margin-top: 1rem;
            font-size: 1.5rem;
        }

        .error-message {
            color: #888;
            margin-top: 0.5rem;
        }

        @media (max-width: 768px) {
            body {
                overflow: hidden;
            }

            .chat-container {
                max-width: 100%;
            }

            .chat-container.mobile-layout .channel-sidebar,
            .chat-container.mobile-layout .chat-area {
                width: 100%;
                border-right: none;
            }

            .chat-container.mobile-layout .channel-sidebar {
                height: var(--app-height);
            }

            .chat-container.mobile-layout .channel-sidebar {
                display: none;
            }

            .chat-container.mobile-layout .chat-area {
                display: none;
            }

            .chat-container.mobile-layout.mobile-show-sidebar .channel-sidebar {
                display: flex;
            }

            .chat-container.mobile-layout.mobile-show-chat .chat-area {
                display: flex;
            }

            .chat-container.mobile-layout.mobile-show-chat .loading-placeholder {
                display: none !important;
            }

            .mobile-back-btn {
                display: inline-flex !important;
                margin-right: 0.5rem;
            }

            .chat-header {
                padding-top: 0.75rem;
                padding-right: 0.75rem;
                padding-bottom: 0.7rem;
                padding-left: 0.75rem;
            }

            .messages-container {
                padding: 0.75rem;
            }

            .input-area {
                padding-top: 0.65rem;
                padding-right: 0.75rem;
                padding-bottom: calc(0.65rem + var(--effective-safe-bottom));
                padding-left: 0.75rem;
            }

            .user-area {
                padding-right: 0.75rem;
                padding-bottom: calc(0.75rem + var(--effective-safe-bottom));
                padding-left: 0.75rem;
            }
        }

.mobile-back-btn { display: none; }

.mobile-back-btn {
    position: relative;
}

.mobile-back-unread-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff4d4f;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

#dmSection {
    display: none;
}

#loginBtn {
    display: none;
}

#activeChat {
    display: none;
}

#typingIndicator {
    display: none;
}

/* Phase 5A: Message Buttons */
.message-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.message-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    max-width: 100%;
}

.message-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.message-button.primary:hover:not(:disabled) {
    background-color: #4752c4;
}

.message-button.secondary {
    background-color: #4f545c;
    color: #fff;
}

.message-button.secondary:hover:not(:disabled) {
    background-color: #5d6269;
}

.message-button.success {
    background-color: #3ba55c;
    color: #fff;
}

.message-button.success:hover:not(:disabled) {
    background-color: #2d7d46;
}

.message-button.danger {
    background-color: #ed4245;
    color: #fff;
}

.message-button.danger:hover:not(:disabled) {
    background-color: #c03537;
}

.message-button .emoji {
    font-size: 16px;
    line-height: 1;
}

.message-button .label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Phase 5A: Button Panel in Chat */
#chat-buttons-panel {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin: 8px 0;
}

#chat-buttons-panel .button-list-item {
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    margin-bottom: 4px;
}

#chat-buttons-panel .button-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

#chat-buttons-panel .button-custom-id {
    font-size: 11px;
    color: #72767d;
    background-color: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
}

/* Phase 5B: Image Attachments */
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    max-width: 100%;
}

.message-attachment {
    display: block;
    border-radius: 8px;
    overflow: hidden;
    max-width: 300px;
    transition: transform 0.15s ease;
}

.message-attachment:hover {
    transform: scale(1.02);
}

.attachment-image {
    display: block;
    max-width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: 8px;
    background-color: rgba(0, 0, 0, 0.2);
}

/* Phase 5B: Image Upload Area */
.chat-image-upload-area {
    padding: 4px 0;
}

#chat-image-btn {
    display: flex;
    align-items: center;
    gap: 4px;
}

#chat-image-preview {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 8px;
}

#chat-image-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.image-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background-color: var(--bg-secondary, #f8f9fa);
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-primary, #212529);
    max-width: 280px;
    transition: background-color 0.2s;
}

.image-badge:hover {
    background-color: var(--bg-hover, #e9ecef);
}

.image-badge-thumb {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg-tertiary, #e9ecef);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.image-badge-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-badge-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-badge-size {
    font-size: 11px;
    color: var(--text-muted, #6c757d);
}

.image-badge-remove {
    padding: 4px;
    border: none;
    background: transparent;
    color: var(--danger, #dc3545);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.image-badge-remove:hover {
    opacity: 1;
    background: var(--bg-hover, #e9ecef);
}

/* Message Action Menu */
.message-menu-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 4px;
    padding: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
    color: #aaa;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-menu-btn:hover {
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
}

.message:hover .message-menu-btn {
    opacity: 1;
}

.message.shared-message-target {
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.45);
    transition: box-shadow 0.2s ease;
}

/* Mobile: hide menu button, use long-press instead */
@media (hover: none) and (pointer: coarse) {
    .message-menu-btn {
        display: none;
    }

    .mobile-hint {
        display: block;
    }
}

.message-menu-btn .material-icons {
    font-size: 18px;
}

/* Message wrapper for positioning */
.message-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Message pressed state for long press feedback */
.message.pressed {
    background-color: rgba(255, 255, 255, 0.1) !important;
    transform: scale(0.98);
    transition: transform 0.1s ease, background-color 0.1s ease;
}

/* Context menu styling */
.message-context-menu {
    position: fixed;
    z-index: 1050;
    background: var(--chat-sidebar-bg, #242424);
    border: 1px solid var(--chat-border, #3a3a3a);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 150px;
    padding: 4px 0;
    animation: contextMenuFadeIn 0.15s ease-out;
}

@keyframes contextMenuFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.message-context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    color: #e0e0e0;
    font-size: 14px;
    transition: background-color 0.1s ease;
}

.message-context-menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.message-context-menu-item .material-icons {
    font-size: 18px;
    opacity: 0.8;
}

.message-context-menu-item.danger {
    color: #ed4245;
}

.message-context-menu-item.danger:hover {
    background: rgba(237, 66, 69, 0.15);
}

.message-context-menu-item.danger .material-icons {
    opacity: 1;
}

.message-context-menu-divider {
    height: 1px;
    background-color: var(--chat-border, #3a3a3a);
    margin: 4px 8px;
}

.message-context-menu-item.disabled {
    color: #666;
    cursor: default;
    font-style: italic;
}

.message-context-menu-item.disabled:hover {
    background: transparent;
}

/* Confirm Modal - match chat dark theme */
.modal {
    padding-top: var(--safe-top);
    padding-right: var(--safe-right);
    padding-bottom: var(--effective-safe-bottom);
    padding-left: var(--safe-left);
}

#confirmModal .modal-content {
    background-color: var(--chat-sidebar-bg, #242424);
    border: 1px solid var(--chat-border, #3a3a3a);
    border-radius: 12px;
}

#confirmModal .modal-header {
    border-bottom: 1px solid var(--chat-border, #3a3a3a);
    padding: 1rem 1.25rem;
}

#confirmModal .modal-title {
    color: #e0e0e0;
    font-weight: 600;
}

#confirmModal .modal-body {
    color: #ccc;
    padding: 1.25rem;
}

#confirmModal .modal-footer {
    border-top: 1px solid var(--chat-border, #3a3a3a);
    padding: 0.75rem 1.25rem;
}

#confirmModal .btn-close {
    filter: invert(1) brightness(0.8);
}

#confirmModal .btn-secondary {
    background-color: #3a3a3a;
    border-color: #3a3a3a;
    color: #e0e0e0;
}

#confirmModal .btn-secondary:hover {
    background-color: #4a4a4a;
    border-color: #4a4a4a;
}

#confirmModal .btn-primary {
    background-color: #007bff;
    border-color: #007bff;
}

#confirmModal .btn-primary:hover {
    background-color: #0069d9;
    border-color: #0069d9;
}

/* Language Switcher Position */
.auth-lang-switcher-container {
    position: absolute;
    top: calc(1rem + var(--safe-top));
    right: calc(1rem + var(--safe-right));
    z-index: 1050;
}

.lang-select-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--chat-border, #3a3a3a);
    color: #ccc;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    cursor: pointer;
}

.lang-select-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.lang-dropdown-menu {
    background-color: var(--chat-sidebar-bg, #242424);
    border: 1px solid var(--chat-border, #3a3a3a);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    padding: 0.5rem 0;
}

.lang-dropdown-item {
    color: #ccc;
    padding: 8px 16px;
    font-size: 0.9rem;
    transition: all 0.1s;
}

.lang-dropdown-item:hover {
    background-color: rgba(255,255,255,0.1);
    color: #fff;
}

.lang-dropdown-item.active {
    background-color: #007bff;
    color: #fff;
}

.policy-page-card {
    background: var(--chat-sidebar-bg);
    border-color: var(--chat-border);
    color: #e0e0e0;
}

.policy-highlight-box,
.policy-info-card,
.policy-table .policy-table-label,
.policy-table thead th {
    background: rgba(255, 255, 255, 0.06);
}

.policy-info-card,
.policy-table td,
.policy-table th,
.policy-table thead th {
    border-color: var(--chat-border);
    color: inherit;
}

.policy-table {
    --bs-table-bg: transparent;
    --bs-table-color: #e0e0e0;
    --bs-table-border-color: var(--chat-border);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-striped-color: #e0e0e0;
    --bs-table-hover-bg: rgba(255, 255, 255, 0.04);
    --bs-table-hover-color: #e0e0e0;
}

.policy-accent-title {
    color: #8ecbff;
}

.policy-page-card .text-muted,
.policy-page-card .text-body-secondary {
    color: #adb5bd !important;
}
