/*
 * InfiChat v2 Design Tokens
 * Slack-inspired design system
 *
 * These tokens override the legacy :root variables and add new ones.
 * The branding system (brandingManager.js) dynamically overrides:
 *   --primary-color, --accent-color, --header-bg-color,
 *   --sidebar-bg-color, --active-room-color
 * So those names are preserved for compatibility.
 */

:root {
    /* ========================================
     * COLOR PALETTE
     * ======================================== */

    /* Primary brand (overridden by branding system per-client) */
    --primary-color: #5865F2;
    --primary-hover: #4752C4;
    --primary-light: rgba(88, 101, 242, 0.12);
    --accent-color: #5865F2;
    --message-accent-color: #5865F2;
    --button-primary-color: #5865F2;
    --active-room-color: #5865F2;

    /* Surfaces — layered dark backgrounds */
    --surface-base: #1a1d21;
    --surface-raised: #1e2228;
    --surface-overlay: #232529;
    --surface-sunken: #141618;
    --surface-hover: rgba(255, 255, 255, 0.04);
    --surface-active: rgba(255, 255, 255, 0.06);

    /* Legacy surface mappings (keep for backward compat) */
    --background-dark: var(--surface-base);
    --background-medium: var(--surface-raised);
    --background-light: var(--surface-overlay);
    --secondary-color: var(--surface-raised);
    --header-bg-color: var(--surface-raised);
    --sidebar-bg-color: #19171D;

    /* Text */
    --text-primary: #E8E8ED;
    --text-secondary: #B0B0B8;
    --text-muted: #7A7A85;
    --text-link: #5E97F6;
    --text-link-hover: #7EAFF8;
    --text-on-primary: #FFFFFF;
    --text-on-surface: #E8E8ED;

    /* Borders */
    --border-color: rgba(255, 255, 255, 0.08);
    --border-subtle: rgba(255, 255, 255, 0.05);
    --border-strong: rgba(255, 255, 255, 0.14);

    /* Status / semantic */
    --success-color: #2BAC76;
    --warning-color: #E8A427;
    --error-color: #E53E3E;
    --info-color: #5E97F6;

    /* Presence */
    --presence-online: #2BAC76;
    --presence-away: #E8A427;
    --presence-dnd: #E53E3E;
    --presence-offline: #7A7A85;

    /* Unread / badges */
    --badge-bg: #E53E3E;
    --badge-text: #FFFFFF;
    --unread-bar: #5865F2;

    /* ========================================
     * TYPOGRAPHY
     * ======================================== */

    --font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    --font-mono: 'Menlo', 'Monaco', 'Courier New', monospace;

    /* Scale */
    --font-size-xs: 11px;
    --font-size-sm: 12px;
    --font-size-base: 14px;
    --font-size-md: 15px;
    --font-size-lg: 18px;
    --font-size-xl: 22px;
    --font-size-2xl: 28px;

    /* Weight */
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    --font-weight-black: 900;

    /* Line heights */
    --line-height-tight: 1.2;
    --line-height-normal: 1.46;
    --line-height-relaxed: 1.6;

    /* ========================================
     * SPACING
     * ======================================== */

    --space-0: 0;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-7: 32px;
    --space-8: 40px;
    --space-9: 48px;
    --space-10: 64px;

    /* ========================================
     * BORDERS & RADIUS
     * ======================================== */

    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-full: 9999px;

    /* Legacy mapping */
    --border-radius: var(--radius-md);

    /* ========================================
     * SHADOWS
     * ======================================== */

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-popup: 0 4px 24px rgba(0, 0, 0, 0.5);

    /* Legacy mapping */
    --shadow-standard: var(--shadow-md);

    /* ========================================
     * TRANSITIONS
     * ======================================== */

    --transition-fast: 0.15s ease;
    --transition-standard: 0.25s ease;
    --transition-slow: 0.4s ease;

    /* ========================================
     * LAYOUT
     * ======================================== */

    --sidebar-width: 260px;
    --sidebar-width-collapsed: 68px;
    --header-height: 50px;
    --composer-min-height: 44px;
    --thread-panel-width: 400px;
    --avatar-size-sm: 20px;
    --avatar-size-md: 36px;
    --avatar-size-lg: 48px;

    /* ========================================
     * Z-INDEX SCALE
     * ======================================== */

    --z-base: 0;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-overlay: 300;
    --z-modal: 400;
    --z-popover: 500;
    --z-toast: 600;
    --z-tooltip: 700;
}
/*
 * InfiChat v2 — Shell Layout
 * Three-panel layout: sidebar | main chat | thread panel
 */

/* -- App shell -- */

html {
    overscroll-behavior: none;
}

body {
    font-family: var(--font-family);
    background: var(--surface-base);
    color: var(--text-primary);
    font-size: var(--font-size-md);
    line-height: var(--line-height-normal);
    overscroll-behavior: none;
}

.chat-container {
    display: flex;
    height: calc(var(--vh, 1vh) * 100);
    flex-direction: row;
    background: var(--surface-base);
}

/* -- Main chat area -- */

.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: calc(var(--vh, 1vh) * 100);
    min-width: 0;
    background: var(--surface-base);
    position: relative;
}

/* -- Thread panel -- */

.thread-panel {
    width: var(--thread-panel-width);
    max-width: 50%;
    border-left: 1px solid var(--border-color);
    background: var(--surface-raised);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.thread-panel-header {
    height: var(--header-height);
    padding: 0 var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.thread-panel-header h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
}

.thread-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-lg);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.thread-close-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.chat-container.thread-open {
    display: flex;
}

.chat-container.thread-open .main-chat {
    flex: 1;
    min-width: 0;
}

/* -- Login page -- */

.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: calc(var(--vh, 1vh) * 100);
    background: var(--surface-base);
}

.login-box {
    background: var(--surface-raised);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    width: 400px;
    max-width: 90vw;
    box-shadow: var(--shadow-xl);
}

.login-box h2 {
    color: var(--text-primary);
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--space-6);
    text-align: center;
}

.login-box input {
    width: 100%;
    padding: var(--space-3);
    background: var(--surface-base);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--font-size-md);
    font-family: var(--font-family);
    margin-bottom: var(--space-4);
    transition: border-color var(--transition-fast);
}

.login-box input:focus {
    border-color: var(--primary-color);
    outline: none;
}

.login-box input::placeholder {
    color: var(--text-muted);
}

.login-box button {
    width: 100%;
    padding: var(--space-3);
    background: var(--primary-color);
    color: var(--text-on-primary);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    font-family: var(--font-family);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.login-box button:hover {
    background: var(--primary-hover);
}

/* -- Modals -- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--surface-overlay);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 600px;
    width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    padding: var(--space-6);
}

.modal-content h2,
.modal-content h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-4);
}

/* -- Toast / notification -- */

.toast {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    background: var(--surface-overlay);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-5);
    box-shadow: var(--shadow-popup);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    z-index: var(--z-toast);
    animation: slideInUp 0.2s ease-out;
}

@keyframes slideInUp {
    from { transform: translateY(16px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ======================================
 * RESPONSIVE — Mobile
 * ====================================== */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        /* Must outrank legacy .mobile-overlay (z-index: 9998), or the
         * backdrop captures every channel-row click and closes the drawer
         * instead of switching rooms. v2's --z-overlay (300) was too low. */
        z-index: 9999;
        transform: translateX(-100%);
        transition: transform var(--transition-standard);
        width: 85vw;
        max-width: 320px;
    }

    /* Match the legacy JS class (.mobile-open) and keep .open as an alias
     * so future refactors using the cleaner name still work. Without this,
     * the hamburger toggles .mobile-open but v2's translateX(-100%) shadows
     * legacy's left:-100% and the drawer never slides in. Backdrop is the
     * legacy `.mobile-overlay.active` element from styles.css, so v2's
     * `.sidebar-backdrop` rules were dead code and have been removed. */
    .sidebar.mobile-open,
    .sidebar.open {
        transform: translateX(0);
    }

    .main-chat {
        width: 100%;
        /* Use dvh on mobile so the layout shrinks instantly when the
         * keyboard opens, with no JS lag. --vh fallback for older
         * browsers that don't support dvh. */
        min-height: calc(var(--vh, 1vh) * 100);
        min-height: 100dvh;
        height: calc(var(--vh, 1vh) * 100);
        height: 100dvh;
        max-height: 100dvh;
        /* Allow internal flex children (the messages list) to shrink */
        overflow: hidden;
    }

    /* Same for the parent shell so it can't be taller than the visible
     * viewport — prevents iOS Safari from scrolling the page when the
     * input is focused. */
    .chat-container {
        height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
    }

    /* And body — same reason. */
    html, body {
        height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
    }

    /* Thread panel as full-screen overlay on mobile */
    .thread-panel {
        position: fixed;
        top: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        z-index: var(--z-overlay);
        border-left: none;
    }

    .chat-container.thread-open .main-chat {
        /* Don't shrink on mobile — panel overlays */
    }

    /* Tighter spacing on mobile */
    .message {
        padding: var(--space-2) var(--space-3);
    }

    .message-input-container {
        padding: 0 var(--space-3) var(--space-3);
    }
}

/* ======================================
 * UTILITY CLASSES
 * ====================================== */

.hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =============================================================================
   FONT SIZE PREFERENCE — scoped to message timeline + sidebar room rows only
   body.font-size-large / body.font-size-xl override --font-size-base and
   --font-size-md on the two containers that contain chat content.
   UI chrome (headers, modals, dropdowns) is intentionally unaffected.
   ============================================================================= */

body.font-size-large .messages,
body.font-size-large .rooms-container {
    --font-size-base: 16px;
    --font-size-md: 17px;
    --font-size-sm: 13px;
}

body.font-size-xl .messages,
body.font-size-xl .rooms-container {
    --font-size-base: 19px;
    --font-size-md: 21px;
    --font-size-sm: 15px;
}
/*
 * InfiChat v2 — Sidebar
 * Slack-style sidebar with collapsible sections
 */

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg-color, #19171D);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    min-height: calc(var(--vh, 1vh) * 100);
    font-family: var(--font-family);
}

/* -- Header -- */

.sidebar-header {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-2);
    height: var(--header-height);
}

/* Each block wraps a trigger + its dropdown menu, providing the
 * positioned ancestor the absolute-positioned menu anchors against. */
.sidebar-header .workspace-block {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}
.sidebar-header .user-block {
    position: relative;
    flex-shrink: 0;
}

/* Workspace trigger (left side of header). Click → workspaceMenu. */
.workspace-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-bold);
    letter-spacing: -0.02em;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    text-align: left;
}

.workspace-trigger:hover {
    background: var(--surface-hover);
}

.workspace-trigger:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.workspace-trigger[aria-expanded="true"] {
    background: var(--surface-active);
    border-color: var(--border-subtle);
}

.workspace-trigger .sidebar-logo {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    object-fit: contain;
}

.workspace-trigger .workspace-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-trigger .workspace-chevron {
    color: var(--text-muted);
    font-size: 10px;
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.workspace-trigger[aria-expanded="true"] .workspace-chevron {
    transform: rotate(180deg);
}

/* User menu trigger (right side of header). Click → userMenu. */
.user-menu-trigger {
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-menu-trigger:hover {
    background: var(--surface-hover);
}

.user-menu-trigger:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.user-menu-trigger[aria-expanded="true"] {
    box-shadow: 0 0 0 2px var(--accent-color);
}

.user-avatar-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.user-avatar-wrap .user-avatar {
    width: var(--avatar-size-md);
    height: var(--avatar-size-md);
    border-radius: var(--radius-md);
    background: var(--primary-color);
    color: var(--text-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-sm);
    object-fit: cover;
}

/* Presence dot — bottom-right of avatar, Slack pattern */
.user-avatar-wrap .presence-dot {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--presence-online, #2BAC76);
    border: 2px solid var(--sidebar-bg-color, #19171D);
    box-sizing: content-box;
}

/* -- Dropdown menus (workspace + user) -- */

.dropdown-menu {
    position: absolute;
    z-index: var(--z-dropdown);
    min-width: 220px;
    max-width: 280px;
    background: var(--surface-overlay);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-popup);
    padding: var(--space-1) 0;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
}

.workspace-menu {
    top: calc(100% - 4px);
    left: 0;
    min-width: 240px;
}

.user-menu {
    top: calc(100% - 4px);
    right: 0;
    min-width: 220px;
}

.dropdown-section-label {
    padding: var(--space-2) var(--space-4) var(--space-1);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-1) 0;
}

.dropdown-item {
    display: flex;
    width: 100%;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-normal);
    text-align: left;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.dropdown-item:hover,
.dropdown-item:focus-visible {
    background: var(--surface-hover);
    outline: none;
}

.dropdown-item-icon {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
}

.dropdown-item-danger {
    color: var(--error-color);
}

.dropdown-item-danger:hover,
.dropdown-item-danger:focus-visible {
    background: rgba(229, 62, 62, 0.10);
}

/* Sort options inside workspace menu — radio + label div, not a button */
.dropdown-item.sort-option {
    cursor: pointer;
    display: flex !important;
    width: 100%;
    box-sizing: border-box;
    align-items: center;
    gap: 8px !important;
    padding: 8px 12px !important;
}

.dropdown-item.sort-option input[type="radio"] {
    accent-color: var(--accent-color);
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    cursor: pointer;
    margin: 0 !important;
}

.dropdown-item.sort-option label {
    flex: 1;
    cursor: pointer;
    user-select: none;
    color: var(--text-primary) !important;
    display: flex !important;
    align-items: center;
    gap: 6px;
    font-size: var(--font-size-base);
    min-width: 0;
    margin: 0 !important;
    padding: 0 !important;
}

/* User-menu header (name + role above divider) */
.user-menu-header {
    padding: var(--space-2) var(--space-4);
    border-radius: 0;
}

.user-menu-header .user-name {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu-header .user-role {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-transform: capitalize;
}

/* Channels-header "+ Room" button — small icon button on the right */
.room-section-header.channels-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.room-section-header.channels-header .section-label {
    flex: 1;
}

/* "Add" chips in section headers (Channels +, Direct Messages +). Both use
 * the same neutral surface-active bg + border so they read as consistent
 * action buttons that match the divider/header color, not as competing
 * accent-colored circles. Accent-color appears only on hover.
 * Channels version (admin/mod-only via JS .hidden toggle on #createRoomBtn). */
.room-section-header.channels-header #createRoomBtn,
.room-section-header.dm-header .start-dm-btn {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    padding: 0;
    line-height: 1;
    background: var(--surface-active);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 18px;
    font-weight: var(--font-weight-bold);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.room-section-header.channels-header #createRoomBtn:hover,
.room-section-header.dm-header .start-dm-btn:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: var(--text-on-primary);
    transform: scale(1.06);
}

.room-section-header.channels-header #createRoomBtn:focus-visible,
.room-section-header.dm-header .start-dm-btn:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* -- Room search -- */

.room-search-container {
    padding: var(--space-2) var(--space-3);
}

.room-search-container input {
    width: 100%;
    padding: var(--space-1) var(--space-3);
    background: var(--surface-hover);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    transition: border-color var(--transition-fast), background var(--transition-fast);
    height: 28px;
}

.room-search-container input::placeholder {
    color: var(--text-muted);
}

.room-search-container input:focus {
    background: var(--surface-base);
    border-color: var(--primary-color);
    outline: none;
}

/* -- Section headers -- */

.rooms-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.room-section-header {
    display: flex;
    align-items: center;
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    user-select: none;
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    transition: color var(--transition-fast);
    gap: var(--space-1);
}

.room-section-header:hover {
    color: var(--text-secondary);
}

.room-section-header .section-toggle {
    font-size: 10px;
    transition: transform var(--transition-fast);
    flex-shrink: 0;
    width: 12px;
}

.room-section-header .section-label {
    flex: 1;
}

.room-section-header.collapsed .section-toggle {
    transform: rotate(-90deg);
}

/* -- Room items -- */

.room-item {
    display: flex;
    align-items: center;
    /* Override legacy `justify-content: space-between`, which (combined with
     * the room-name's intrinsic min-content sizing) was pushing the room
     * name to the right edge with a huge gap on mobile. We want icon and
     * name flush-left with a normal flex gap. */
    justify-content: flex-start;
    padding: 4px var(--space-4) 4px var(--space-4);
    margin: 1px var(--space-2);
    cursor: pointer;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--font-size-md);
    transition: background var(--transition-fast), color var(--transition-fast);
    min-height: 30px;
    text-decoration: none;
    gap: var(--space-2);
    position: relative;
    min-width: 0;
}

.room-item:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.room-item.active {
    background: var(--active-room-color, var(--primary-color));
    color: var(--text-on-primary);
}

.room-item.active:hover {
    background: var(--primary-hover);
}

/* Channel prefix icon */
.room-item .room-icon {
    font-size: var(--font-size-sm);
    opacity: 0.6;
    flex-shrink: 0;
    width: 10px;
    text-align: center;
    margin-right: 0;
}

.room-item .room-name {
    flex: 1 1 0%;
    /* min-width: 0 lets the flex item shrink below its min-content (the
     * full text width) so the ellipsis truncation actually works AND
     * flex-grow can fill remaining space without being capped by content. */
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: var(--font-weight-normal);
}

/* Unread styling */
.room-item.has-unread .room-name {
    color: var(--text-primary);
    font-weight: var(--font-weight-bold);
}

.room-item .unread-badge,
.room-item .notification-badge {
    background: var(--badge-bg);
    color: var(--badge-text);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    min-width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.room-item.active .unread-badge,
.room-item.active .notification-badge {
    background: rgba(255, 255, 255, 0.3);
}

/* -- Presence dots for DM items (legacy fallback path) -- */

.room-item .presence-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    margin-right: 1px;
}

.room-item .presence-dot.online { background: var(--presence-online); }
.room-item .presence-dot.away { background: var(--presence-away); }
.room-item .presence-dot.offline {
    background: transparent;
    border: 1.5px solid var(--text-muted);
}

/* =========================================================
 * DM avatar chip (Slack-style)
 *
 * Reuses .room-icon slot for both initial render and the live presence
 * updater (updateDMOnlineIndicators in app.js, which appends/removes a
 * .dm-online-indicator child of .room-icon). For DMs, .room-icon also gets
 * .dm-avatar so we can override sizing/styling without touching channels.
 * Single-user DM: 2-char initials. Multi-person DM: "+N".
 * ========================================================= */

.room-item .room-icon.dm-avatar {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    padding: 0;
    margin-right: 0;
    background: var(--surface-active);
    color: var(--text-primary);
    font-size: 10px;
    font-weight: var(--font-weight-bold);
    letter-spacing: -0.3px;
    text-align: center;
    border-radius: var(--radius-sm);
    /* Beat the legacy .room-item .room-icon { opacity: 0.6 } so initials are
     * legible. Channels keep the muted look via the bare .room-icon rule. */
    opacity: 1;
}

.room-item.active .room-icon.dm-avatar {
    background: rgba(255, 255, 255, 0.18);
    color: var(--text-on-primary);
}

/* Override the legacy .dm-online-indicator at styles.css:1712 (which uses
 * border: 1.5px solid #2a2a2a) so the ring matches the v2 sidebar bg. */
.room-item .room-icon.dm-avatar .dm-online-indicator {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--presence-online);
    border: 2px solid var(--sidebar-bg-color);
    box-sizing: content-box;
    z-index: 1;
}

.room-item.active .room-icon.dm-avatar .dm-online-indicator {
    /* When the row is active (primary-color bg), ring becomes that color
     * so the dot still looks "popped out" of the surface. */
    border-color: var(--active-room-color, var(--primary-color));
}

/* (Old .sidebar-footer styles removed — markup deleted in v2 redesign.
 *  All workspace/user controls now live in dropdown menus from the header.) */

/* -- Scrollbar -- */

.rooms-container::-webkit-scrollbar {
    width: 4px;
}

.rooms-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
}

.rooms-container::-webkit-scrollbar-track {
    background: transparent;
}
/*
 * InfiChat v2 — Messages & Conversation Area
 * Slack-style flat messages with avatar layout
 */

/* -- Chat header -- */

.chat-header {
    height: var(--header-height);
    padding: 0 var(--space-4);
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-raised);
    flex-shrink: 0;
    gap: var(--space-3);
}

.chat-header .room-name-display {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header .room-topic {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin-left: var(--space-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header .header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.chat-header .header-action-btn {
    padding: var(--space-1) var(--space-2);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-base);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.chat-header .header-action-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

/* =========================================================
 * v2 — Compact chat header (Slack-style)
 *
 * Hides the row of large blue room buttons (Manage / Delete / Admin Panel)
 * and the secondary icon buttons (📌 / 🔖) on desktop, demoting them into
 * the existing #mobileHeaderDropdown kebab. Keeps the members chip and a
 * single icon-only search visible.
 *
 * Pairs with a JS change so the kebab is visible for ALL users (the legacy
 * showRoleBasedButtons() previously hid it for non-moderators because it
 * only contained admin actions; now it carries pinned/saved/search/etc).
 * ========================================================= */

/* Kebab BUTTON visual treatment — applies at ALL sizes. The legacy mobile
 * button paints a red ☰ on a dark-gray pill (left over from the v1 accent),
 * which clashes with the v2 palette. We always want a neutral gray ⋮.
 * (Dropdown positioning and menu-item layout STAY desktop-only below —
 * legacy styles.css already provides mobile-appropriate dropdown geometry.) */
.chat-header .mobile-header-menu-btn {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent !important;
    border: 1px solid transparent !important;
    border-radius: var(--radius-sm);
    color: var(--text-muted) !important;
    line-height: 1;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    margin-left: var(--space-1);
    /* font-size: 0 hides the in-DOM "☰" glyph so only the ::before "⋮" shows. */
    font-size: 0 !important;
}
.chat-header .mobile-header-menu-btn::before {
    content: "⋮";
    font-size: 20px;
    font-weight: 700;
}
.chat-header .mobile-header-menu-btn:hover,
.chat-header .mobile-header-menu-btn:active {
    background: var(--surface-hover) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-subtle) !important;
}
.chat-header .mobile-header-menu-btn.hidden {
    display: none !important;
}

/* Desktop: also un-do legacy's left:-9999px / display:none / position:absolute
 * for the kebab so it shows in the desktop chat-header. (Mobile already shows
 * it via legacy mobile rules.) */
@media (min-width: 769px) {
    .chat-header .mobile-header-menu-btn {
        position: static !important;
        left: auto !important;
    }
}

/* On desktop, hide the bloat icon/text buttons in .room-info — their
 * functionality lives inside the overflow menu instead. */
@media (min-width: 769px) {
    .room-info #pinnedMessagesBtn,
    .room-info #bookmarksBtn,
    .room-info #manageCurrentRoomBtn,
    .room-info #deleteCurrentRoomBtn,
    .room-info #adminPanelBtn {
        display: none !important;
    }

    /* Search button: collapse to icon-only.
     * font-size: 0 hides the in-DOM "🔍 Search" text (kept for screen readers
     * via aria-label); ::before renders a single visible icon at 16px. */
    .room-info #headerSearchBtn {
        font-size: 0 !important;
        padding: 6px 8px !important;
        background: transparent !important;
        border: 1px solid transparent !important;
        border-radius: var(--radius-sm) !important;
        color: var(--text-muted) !important;
        cursor: pointer;
        line-height: 1 !important;
        gap: 0 !important;
        transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    }
    .room-info #headerSearchBtn::before {
        content: "🔍";
        font-size: 16px;
    }
    .room-info #headerSearchBtn:hover {
        background: var(--surface-hover) !important;
        color: var(--text-primary) !important;
        border-color: var(--border-subtle) !important;
    }

    /* Members chip: smaller, neutral, Slack-y pill */
    .room-info .room-members-count {
        background: var(--surface-hover);
        color: var(--text-secondary);
        border: 1px solid transparent;
        border-radius: var(--radius-full);
        padding: 4px 10px;
        font-size: var(--font-size-sm);
        font-weight: var(--font-weight-medium);
        cursor: pointer;
        transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    }
    .room-info .room-members-count:hover {
        background: var(--surface-active);
        color: var(--text-primary);
        border-color: var(--border-subtle);
    }

    /* Compact gap inside .room-info */
    .room-info {
        gap: var(--space-1);
    }

    /* Overflow dropdown — desktop popover (mobileUI.js sets inline display:block). */
    .chat-header #mobileHeaderDropdown {
        position: absolute;
        top: calc(var(--header-height) - 4px);
        right: var(--space-4);
        min-width: 220px;
        max-width: 280px;
        background: var(--surface-overlay);
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-popup);
        padding: var(--space-1) 0;
        z-index: var(--z-dropdown);
        font-family: var(--font-family);
    }
    /* Default state hidden; mobileUI.js inline-styles display:block when opened */
    .chat-header #mobileHeaderDropdown:not(.show) {
        display: none !important;
    }
    .chat-header #mobileHeaderDropdown.show {
        display: block !important;
    }

    .chat-header .mobile-header-menu-item {
        display: flex !important;
        width: 100%;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-4) !important;
        background: transparent;
        border: none;
        color: var(--text-primary);
        font-family: var(--font-family);
        font-size: var(--font-size-base);
        text-align: left;
        cursor: pointer;
        transition: background var(--transition-fast);
        line-height: 1.4;
    }
    .chat-header .mobile-header-menu-item:hover,
    .chat-header .mobile-header-menu-item:focus-visible {
        background: var(--surface-hover);
        outline: none;
    }
    .chat-header .mobile-header-menu-item.delete {
        color: var(--error-color);
    }
    .chat-header .mobile-header-menu-item.delete:hover {
        background: rgba(229, 62, 62, 0.10);
    }
    .chat-header .mobile-header-menu-item.hidden {
        display: none !important;
    }

    /* The .chat-header needs position:relative so the dropdown anchors here */
    .chat-header {
        position: relative;
    }
}

.messages {
    flex: 1;
    /* Anchor messages to the BOTTOM of the container when there are fewer
     * messages than fit. Without this, sparse rooms render the message at
     * the top of the scrollable area with a giant empty gap above the
     * composer. The `> :first-child { margin-top: auto }` pattern pushes
     * everything to the bottom only when there's free space — it does NOT
     * clip overflow when content is taller than the container, unlike the
     * `justify-content: flex-end` alternative. */
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: none;
    padding: var(--space-2) 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.messages > :first-child {
    margin-top: auto;
}

.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-full);
}

.messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* -- Individual message -- */

.message {
    margin: 0;
    padding: var(--space-2) var(--space-5);
    padding-left: 72px;
    background: transparent;
    border-radius: 0;
    border-left: none;
    position: relative;
    transition: background var(--transition-fast);
    font-family: var(--font-family);
}

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

/* -- Avatar -- */

.message-avatar {
    position: absolute;
    left: var(--space-5);
    top: var(--space-2);
    width: var(--avatar-size-md);
    height: var(--avatar-size-md);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    color: #fff;
    flex-shrink: 0;
    user-select: none;
}

.message-body {
    min-width: 0;
}

/* Mobile message layout — restore the avatar gutter that legacy
 * styles.css line 4901 wipes out with `padding: 12px`. Without this,
 * the absolutely-positioned avatar overlaps the sender-name text on
 * every viewport ≤768px. Tighter gutter than desktop (60px vs 72px)
 * to give back ~12px of content width on phones.
 *
 * Right padding bumped to 36px so the absolutely-positioned kebab
 * (.message-hover-actions on mobile) has its own gutter and doesn't
 * overlap the timestamp / read-receipts in the .sender row. */
@media (max-width: 768px) {
    .message {
        padding: var(--space-2) var(--space-3) !important;
        padding-left: 60px !important;
        padding-right: 36px !important;
        margin: 0 !important;
        border-radius: 0 !important;
        border-left: none !important;
    }
    .message-avatar {
        left: var(--space-3);
        top: var(--space-2);
        width: 32px;
        height: 32px;
    }
    /* Continuation messages (no avatar repeat) match the same gutter. */
    .message.grouped {
        padding-top: 1px !important;
    }
}

/* Message with avatar layout */
.message .sender {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    margin-bottom: 2px;
    position: relative;
}

.message .sender-name {
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-md);
    color: var(--text-primary);
    cursor: default;
}

.message .sender-name.clickable-username {
    cursor: pointer;
}

.message .sender-name.clickable-username:hover {
    text-decoration: underline;
}

.message .time {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-weight: var(--font-weight-normal);
}

.message .content {
    font-size: var(--font-size-md);
    line-height: var(--line-height-normal);
    color: var(--text-on-surface);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message .content p {
    margin: 0;
}

/* -- Grouped messages (same sender, short time gap) -- */

.message.grouped {
    margin-top: 0;
    padding-top: 1px;
    padding-bottom: 1px;
}

.message.grouped .message-avatar,
.message.grouped .sender {
    display: none;
}

/* Show time on hover for grouped messages */
.message.grouped:hover::before {
    content: attr(data-short-time);
    position: absolute;
    left: var(--space-4);
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    color: var(--text-muted);
}

.message.group-start {
    margin-bottom: 0;
    padding-bottom: 1px;
}

.message.group-middle {
    margin: 0;
    padding-top: 1px;
    padding-bottom: 1px;
    border-left: none;
}

.message.group-end {
    margin-top: 0;
    padding-top: 1px;
}

/* -- Edited indicator -- */

.message.message-edited .content::after {
    content: '(edited)';
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-left: var(--space-1);
    font-style: normal;
}

/* =========================================================
 * Mentions — Slack-style subtle pills + self-mention highlight
 *
 * Overrides the legacy saturated-color pills in styles.css. Specificity is
 * boosted via .message ancestor (one class higher than legacy .mention rules),
 * so v2 wins via cascade order without !important.
 *
 * The runtime self-mention rule lives in app.js (injected once after login)
 * and targets .mention.user-mention[data-user-id="<currentUser.id>"].
 * data-user-id is emitted by richTextProcessor.processMentions().
 * ========================================================= */

.message .mention,
.message-content .mention {
    display: inline;
    padding: 0 4px;
    border-radius: var(--radius-sm);
    font-size: inherit;
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    /* Kill legacy .mention:hover { transform: scale(1.05); } pill bounce */
    transform: none;
    margin: 0;
    background: transparent;
    color: inherit;
}

/* Plain @user mention — subtle blue tint, link-colored text */
.message .mention.user-mention,
.message-content .mention.user-mention {
    color: var(--text-link);
    background: rgba(94, 151, 246, 0.12);
}

.message .mention.user-mention:hover,
.message-content .mention.user-mention:hover {
    background: rgba(94, 151, 246, 0.20);
    color: var(--text-link-hover);
    transform: none;
}

/* @all (and equivalents) — amber tint, "this pings everyone" */
.message .mention.all-mention,
.message-content .mention.all-mention {
    color: var(--warning-color);
    background: rgba(232, 164, 39, 0.16);
    font-weight: var(--font-weight-semibold);
}

.message .mention.all-mention:hover,
.message-content .mention.all-mention:hover {
    background: rgba(232, 164, 39, 0.26);
    color: var(--warning-color);
    transform: none;
}

/* Self-mention message-row treatment: Slack uses a soft warm bg + warm
 * left accent (instead of the previous primary-blue tint). The .has-mention
 * class is added by app.js when MentionDetector.isUserMentioned matches. */
.message.has-mention {
    background: rgba(232, 164, 39, 0.06);
    border-left: 3px solid var(--warning-color);
}

.message.has-mention:hover {
    background: rgba(232, 164, 39, 0.10);
}

/* -- Date separator -- */

.date-separator {
    display: flex;
    align-items: center;
    padding: var(--space-4) var(--space-5);
    gap: var(--space-4);
}

.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.date-separator span {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    color: var(--text-muted);
    white-space: nowrap;
    padding: var(--space-1) var(--space-3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: var(--surface-raised);
}

/* -- Message menu (kebab) -- */

.message-menu-container {
    display: inline-block;
    position: relative;
}

.message-menu-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-base);
    opacity: 0;
    transition: opacity var(--transition-fast), background var(--transition-fast);
}

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

.message-menu-btn:hover {
    opacity: 1 !important;
    background: var(--surface-active);
}

/* Mobile: always show menu button */
@media (hover: none), (max-width: 768px) {
    .message-menu-btn {
        opacity: 0.5;
    }
}

.message-menu-dropdown {
    position: absolute;
    top: 0;
    right: var(--space-5);
    background: var(--surface-overlay);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: var(--space-1);
    min-width: 200px;
    box-shadow: var(--shadow-popup);
    z-index: var(--z-popover);
}

/* Flip-up: anchor the dropdown ABOVE the kebab when it would otherwise
 * overflow the viewport bottom (last message in the room). JS sets
 * .flip-up after measuring; CSS just provides the alternate position. */
.message-menu-dropdown.flip-up {
    top: auto;
    bottom: 100%;
    margin-bottom: 6px;
}

.message-menu-dropdown button {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    transition: background var(--transition-fast);
}

.message-menu-dropdown button:hover {
    background: var(--surface-hover);
}

.message-menu-dropdown button.danger-action {
    color: var(--error-color);
}

.message-menu-dropdown button.danger-action:hover {
    background: rgba(229, 62, 62, 0.12);
}

/* -- Hover action bar (Slack-style floating toolbar) -- */

.message-hover-actions {
    position: absolute;
    top: -14px;
    right: var(--space-5);
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 4px;
    background: var(--surface-overlay);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    z-index: var(--z-dropdown);
}

.message:hover .message-hover-actions {
    opacity: 1;
    pointer-events: auto;
}

/* Mobile: hide emoji + thread buttons (their actions live in the kebab
 * dropdown), keep ONLY the kebab visible always. Mirrors Slack/Discord
 * mobile patterns — one tap target per message, never three.
 * Anchor the kebab into the dedicated 36px right gutter we reserved
 * on .message above, so it never collides with the timestamp / ✓✓. */
@media (hover: none), (max-width: 768px) {
    .message-hover-actions {
        opacity: 1 !important;
        pointer-events: auto !important;
        position: absolute;
        top: 6px;
        right: 4px;
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
        gap: 0;
        z-index: 5;
    }
    /* Hide every action button EXCEPT the kebab on mobile. */
    .message-hover-actions .message-action-btn:not([data-action="toggle-msg-menu"]) {
        display: none !important;
    }
    .message-hover-actions .message-action-btn[data-action="toggle-msg-menu"] {
        min-width: 28px;
        min-height: 28px;
        padding: 4px 6px;
        font-size: 18px;
        font-weight: 700;
        line-height: 1;
        color: var(--text-muted);
        background: transparent;
        border: 1px solid transparent;
        border-radius: var(--radius-sm);
    }
    .message-hover-actions .message-action-btn[data-action="toggle-msg-menu"]:hover,
    .message-hover-actions .message-action-btn[data-action="toggle-msg-menu"]:active {
        background: var(--surface-hover);
        color: var(--text-primary);
        border-color: var(--border-subtle);
    }
}

.message-action-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    transition: background var(--transition-fast), color var(--transition-fast);
    line-height: 1;
}

.message-action-btn:hover {
    background: var(--surface-active);
    color: var(--text-primary);
}

/* Legacy .message-actions — hide on v2 (replaced by hover bar + dropdown) */
.message-actions {
    display: none;
}

/* -- Reactions -- */

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin-top: var(--space-1);
}

.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--surface-hover);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: var(--font-size-sm);
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.reaction-badge:hover {
    background: var(--surface-active);
    border-color: var(--border-color);
}

.reaction-badge.user-reacted {
    background: var(--primary-light);
    border-color: var(--primary-color);
}

/* -- Thread indicator -- */

.thread-indicator {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    color: var(--text-link);
    font-size: var(--font-size-sm);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
    margin-top: var(--space-1);
}

.thread-indicator:hover {
    background: var(--surface-hover);
    text-decoration: underline;
}

/* -- Quoted messages -- */

.quoted-message {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-1);
    border-radius: var(--radius-md);
    background: var(--surface-hover);
    cursor: pointer;
    font-size: var(--font-size-sm);
    max-width: 480px;
}

.quoted-message-bar {
    width: 3px;
    border-radius: var(--radius-full);
    background: var(--primary-color);
    flex-shrink: 0;
}

.quoted-message-author {
    font-weight: var(--font-weight-bold);
    color: var(--text-secondary);
    margin-right: var(--space-1);
}

.quoted-message-text {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* -- Scroll to bottom button -- */

.scroll-bottom-btn {
    position: absolute;
    bottom: 80px;
    right: var(--space-5);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--surface-overlay);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: background var(--transition-fast), color var(--transition-fast);
    z-index: var(--z-sticky);
}

.scroll-bottom-btn:hover {
    background: var(--surface-active);
    color: var(--text-primary);
}

/* =========================================================
 * Clickable message avatar — visual hint that clicking opens a profile.
 * ========================================================= */
.message-avatar.clickable-avatar {
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.message-avatar.clickable-avatar:hover {
    transform: scale(1.06);
    box-shadow: 0 0 0 2px var(--surface-active);
}
.message-avatar.clickable-avatar:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* =========================================================
 * User profile popover (v2)
 *
 * Anchored next to the avatar on desktop; reflows to a centered modal sheet
 * on mobile (≤768px) so the popover doesn't clip off-screen on small viewports.
 * Populated dynamically by showUserProfilePopover() in app.js.
 * ========================================================= */
.user-profile-popover {
    position: fixed;
    z-index: var(--z-popover, 500);
    width: 280px;
    max-width: calc(100vw - 24px);
    background: var(--surface-overlay);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-popup);
    padding: var(--space-4);
    color: var(--text-primary);
    font-family: var(--font-family);
}

.user-profile-popover[hidden] {
    display: none;
}

.user-profile-popover .profile-popover-close {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.user-profile-popover .profile-popover-close:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.user-profile-popover .profile-popover-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
    padding-right: 28px;
}

.user-profile-popover .profile-popover-avatar {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    font-size: 20px;
    flex-shrink: 0;
}

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

.user-profile-popover .profile-popover-name {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.user-profile-popover .profile-popover-fullname {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.user-profile-popover .profile-popover-presence {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    margin-top: 4px;
}

.user-profile-popover .profile-popover-presence .presence-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}
.user-profile-popover .profile-popover-presence .presence-dot.online {
    background: var(--presence-online, #2BAC76);
}
.user-profile-popover .profile-popover-presence .presence-dot.offline {
    background: transparent;
    border: 1.5px solid var(--text-muted);
}

.user-profile-popover .profile-popover-email {
    margin-bottom: var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    word-break: break-all;
}

.user-profile-popover .profile-popover-email a {
    color: var(--text-link);
    text-decoration: none;
}
.user-profile-popover .profile-popover-email a:hover {
    text-decoration: underline;
}

.user-profile-popover .profile-popover-action {
    display: block;
    width: 100%;
    padding: 9px 14px;
    background: var(--accent-color);
    color: var(--text-on-primary);
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.user-profile-popover .profile-popover-action:hover {
    filter: brightness(1.08);
}
.user-profile-popover .profile-popover-action:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Mobile: reflow to a centered modal sheet */
@media (max-width: 768px) {
    .user-profile-popover {
        top: 50% !important;
        left: 50% !important;
        right: auto !important;
        transform: translate(-50%, -50%);
        width: calc(100vw - 32px);
        max-width: 380px;
    }
}

/* =========================================================
 * Loading + error state components (siblings to .empty-state)
 *
 * Reuses .empty-state base and adds two semantic variants:
 *   .loading-state — neutral progress feedback ("Loading messages…")
 *   .error-state   — destructive/blocking states ("Access denied", "Auth error")
 * Both share the centered stage layout from .empty-state-stage.
 * ========================================================= */
.loading-state,
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: var(--space-2);
    padding: var(--space-8) var(--space-5);
    min-height: 180px;
}

.loading-state {
    color: var(--text-secondary);
}

.loading-state-icon {
    font-size: 28px;
    opacity: 0.7;
    line-height: 1;
    animation: v2-loading-pulse 1.4s ease-in-out infinite;
}

.loading-state-title {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    font-weight: var(--font-weight-medium);
}

.loading-state-body {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

@keyframes v2-loading-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .loading-state-icon { animation: none; opacity: 0.7; }
}

.error-state {
    color: var(--error-color, #E53E3E);
    background: rgba(229, 62, 62, 0.04);
    border-radius: var(--radius-md);
    margin: var(--space-4);
}

.error-state-icon {
    font-size: 32px;
    opacity: 0.85;
    line-height: 1;
}

.error-state-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--error-color, #E53E3E);
}

.error-state-body {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    max-width: 360px;
    line-height: 1.5;
}

.error-state-action {
    margin-top: var(--space-3);
    padding: 8px 16px;
    background: var(--error-color, #E53E3E);
    color: #FFFFFF;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    cursor: pointer;
}
.error-state-action:hover { filter: brightness(1.08); }

/* =========================================================
 * Reaction pills (Slack-style chips)
 *
 * Override the legacy .reaction-button at styles.css:2379. Slack uses small
 * rounded chips with subtle border, count next to emoji. user-reacted state
 * uses the tenant accent color tint.
 * ========================================================= */
.message .reactions-container,
.message .emoji-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin-top: var(--space-1);
}

.message .reaction-button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    background: var(--surface-active);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
    line-height: 1.5;
}

.message .reaction-button:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.message .reaction-button.user-reacted {
    background: color-mix(in srgb, var(--accent-color) 15%, transparent);
    border-color: color-mix(in srgb, var(--accent-color) 40%, transparent);
    color: var(--accent-color);
}

.message .reaction-button.user-reacted:hover {
    background: color-mix(in srgb, var(--accent-color) 22%, transparent);
}

.message .reaction-emoji {
    font-size: 14px;
    line-height: 1;
}

/* =========================================================
 * Focus rings (accessibility cleanup)
 *
 * Many interactive elements in the chat shell rely on browser default
 * focus rings, which on dark backgrounds are nearly invisible. Provide
 * an accent-colored ring for keyboard nav.
 * ========================================================= */
.room-item:focus-visible,
.message-avatar.clickable-avatar:focus-visible,
.chat-header button:focus-visible,
.composer-bottom-bar button:focus-visible,
.format-btn:focus-visible,
.send-btn:focus-visible,
.start-dm-btn:focus-visible,
.create-room-btn:focus-visible,
.mobile-menu-btn:focus-visible,
.mobile-header-menu-btn:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.room-item:focus-visible {
    outline-offset: -2px; /* sit inside the row, not outside */
}

/* =========================================================
 * v2 inline-style remediation (Task 1, hybrid B+C)
 *
 * Catch-all overrides for the worst hardcoded dark/saturated colors that
 * leak through inline style="..." in modal HTML and JS-injected fragments
 * (room-manage modal sub-cards, schedule modal inputs, file-preview wrappers,
 * webhook badge colors, etc).
 *
 * Scoped under v2 shell containers (.modal-content, .modal, .message,
 * .start-dm-modal, #importModal) so we don't accidentally restyle anything
 * outside the chat. Only known offenders are mapped — no broad nukes.
 * ========================================================= */

/* Dark-surface backgrounds — remap to v2 surface tokens so inline-styled
 * sub-cards inside modals don't read pitch-black against the v2 palette. */
.modal-content [style*="background: #2a2a2a"],
.modal-content [style*="background:#2a2a2a"],
.modal-content [style*="background: #1a1a1a"],
.modal-content [style*="background:#1a1a1a"],
.modal-content [style*="background: #1e1e1e"],
.modal-content [style*="background:#1e1e1e"],
.modal-content [style*="background: #2d2d2d"],
.modal-content [style*="background:#2d2d2d"],
.modal-content [style*="background: #333"],
.modal-content [style*="background:#333"],
#importModal [style*="background: #2a2a2a"],
#importModal [style*="background:#2a2a2a"],
#importModal [style*="background: #1e1e1e"] {
    background: var(--surface-overlay, #232529) !important;
}

/* Dark form inputs inside modals — neutral surface + token border. */
.modal-content input[style*="#1a1a1a"],
.modal-content textarea[style*="#1a1a1a"],
.modal-content select[style*="#1a1a1a"],
.modal-content input[style*="#2a2a2a"],
.modal-content textarea[style*="#2a2a2a"],
.modal-content select[style*="#2a2a2a"],
.modal-content input[style*="#333"],
.modal-content select[style*="#333"] {
    background: var(--surface-base, #1a1d21) !important;
    color: var(--text-primary, #E8E8ED) !important;
    border-color: var(--border-strong, rgba(255, 255, 255, 0.16)) !important;
}

/* Inline secondary "Cancel" buttons sometimes use background: #444 / #555 */
.modal-content button[style*="background: #444"],
.modal-content button[style*="background:#444"],
.modal-content button[style*="background: #555"],
.modal-content button[style*="background:#555"] {
    background: var(--surface-active, rgba(255, 255, 255, 0.06)) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-strong) !important;
}

/* Muted text inline #888/#aaa/#ccc — remap to text-secondary/muted tokens */
.modal-content [style*="color: #888"],
.modal-content [style*="color:#888"],
.modal-content [style*="color: #aaa"],
.modal-content [style*="color:#aaa"],
.modal-content [style*="color: #ccc"],
.modal-content [style*="color:#ccc"],
.modal-content [style*="color: #666"],
.modal-content [style*="color:#666"] {
    color: var(--text-muted, #7A7A85) !important;
}

/* Webhook bot badge in messages — was hardcoded #9C27B0 purple. Remap to
 * a tenant-friendly muted purple-blue accent so it doesn't fight the
 * primary --accent-color. */
.message .sender-name[style*="#9C27B0"],
.message .sender-name[style*="#9c27b0"],
.message [style*="#9C27B0"],
.message [style*="#9c27b0"] {
    color: var(--text-link, #5E97F6) !important;
}

.message [style*="background: #9C27B0"],
.message [style*="background:#9C27B0"],
.message [style*="background: #9c27b0"],
.message [style*="background:#9c27b0"] {
    background: var(--surface-active, rgba(255, 255, 255, 0.06)) !important;
    color: var(--text-secondary, #B0B0B8) !important;
}

/* Saturated red error text inside messages (hardcoded #ff6b6b) — remap to
 * the v2 error-color so it adapts to dark/light. */
.message [style*="color: #ff6b6b"],
.message [style*="color:#ff6b6b"] {
    color: var(--error-color, #E53E3E) !important;
}

/* "(Archived)" red note in admin All Rooms list */
.admin-panel td [style*="color: #ff6b6b"] {
    color: var(--error-color, #E53E3E) !important;
}

/* =========================================================
 * Reusable empty-state component (v2)
 *
 * Replaces the inline-style empty blobs across the app. Two variants:
 *   .empty-state-stage  — full-pane (chat area, advanced search results)
 *   .empty-state-inline — small list/dropdown context (sidebar DMs,
 *                         room-search dropdown)
 * ========================================================= */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary);
    gap: var(--space-2);
    padding: var(--space-5) var(--space-4);
}

.empty-state-icon {
    font-size: 32px;
    opacity: 0.7;
    line-height: 1;
}

.empty-state-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    line-height: 1.3;
}

.empty-state-body {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    max-width: 320px;
    line-height: 1.5;
}

.empty-state-action {
    margin-top: var(--space-3);
    padding: 8px 16px;
    background: var(--accent-color);
    color: var(--text-on-primary);
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    cursor: pointer;
    transition: filter var(--transition-fast);
}

.empty-state-action:hover {
    filter: brightness(1.08);
}

.empty-state-action:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Stage variant — for full-pane contexts (empty channel, advanced search) */
.empty-state.empty-state-stage {
    min-height: 240px;
    padding: var(--space-8) var(--space-5);
    gap: var(--space-3);
}

.empty-state.empty-state-stage .empty-state-icon {
    font-size: 40px;
}

/* Inline variant — for sidebar/list/dropdown contexts (small footprint) */
.empty-state.empty-state-inline {
    padding: var(--space-3) var(--space-3);
    gap: var(--space-1);
}

.empty-state.empty-state-inline .empty-state-icon {
    font-size: 20px;
}

.empty-state.empty-state-inline .empty-state-title {
    font-size: var(--font-size-base);
}

.empty-state.empty-state-inline .empty-state-body {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.empty-state.empty-state-inline .empty-state-action {
    margin-top: var(--space-2);
    padding: 6px 12px;
    font-size: var(--font-size-xs);
}

/* =============================================================================
   MOBILE LONG-PRESS ACTION SHEET
   ============================================================================= */

/* Backdrop */
.msg-action-sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1200;
    touch-action: none;
}
.msg-action-sheet-backdrop.open {
    display: block;
}

/* Sheet container — slides up from bottom */
.msg-action-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface-overlay);
    border-top: 1px solid var(--border-strong);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 1201;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(100%);
    transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.msg-action-sheet.open {
    transform: translateY(0);
}

/* Drag handle */
.msg-action-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
    margin: 10px auto 6px;
}

/* Quick-react emoji row */
.msg-action-sheet-emojis {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}
.msg-action-sheet-emoji-btn {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    padding: 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.1s ease, background 0.1s ease;
    -webkit-tap-highlight-color: transparent;
}
.msg-action-sheet-emoji-btn:active {
    transform: scale(1.25);
    background: var(--surface-hover);
}
/* The ➕ "more" button */
.msg-action-sheet-emoji-more {
    font-size: 20px;
    color: var(--text-muted);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
    background: var(--surface-hover);
}

/* Action list */
.msg-action-sheet-actions {
    padding: var(--space-2) 0 var(--space-3);
}
.msg-action-sheet-btn {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3) var(--space-5);
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s ease;
}
.msg-action-sheet-btn:active {
    background: var(--surface-hover);
}
.msg-action-sheet-btn .sheet-btn-icon {
    font-size: 20px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}
.msg-action-sheet-btn.danger {
    color: var(--error-color);
}

/* On mobile: hide the always-visible kebab ⋮ — long-press replaces it */
@media (hover: none), (max-width: 768px) {
    .message-hover-actions {
        display: none !important;
    }
}

/* Prevent text selection highlight during long-press on mobile */
@media (hover: none), (max-width: 768px) {
    .message {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
    /* Re-enable selection inside the composer and inputs */
    .message input,
    .message textarea {
        -webkit-user-select: text;
        user-select: text;
    }
}

/* =============================================================================
   AVATAR IMAGES
   ============================================================================= */

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

.profile-popover-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
}

.profile-popover-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

/* =============================================================================
 * Jumbo emoji — messages whose entire content is 1-3 emoji get larger rendering
 * ============================================================================= */
.message-content--emoji-only {
    font-size: 2.5em;
    line-height: 1.2;
    letter-spacing: 0.04em;
}
/*
 * InfiChat v2 — Message Composer
 * Slack-style input area with integrated toolbar
 */

/* -- Composer wrapper -- */

.message-input-container {
    padding: 0 var(--space-5) var(--space-5);
    flex-shrink: 0;
}

.message-input-wrapper {
    background: var(--surface-raised);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    transition: border-color var(--transition-fast);
    overflow: hidden;
}

.message-input-wrapper:focus-within {
    border-color: var(--text-muted);
}

/* -- Bottom bar (toolbar + send) -- */

.composer-bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-1) var(--space-2);
    border-top: 1px solid var(--border-subtle);
}

.composer-send-area {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* -- Formatting toolbar -- */

.formatting-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
}

.formatting-toolbar button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    transition: background var(--transition-fast), color var(--transition-fast);
    min-width: 28px;
    text-align: center;
}

.formatting-toolbar button:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.formatting-toolbar .separator {
    width: 1px;
    height: 20px;
    background: var(--border-subtle);
    margin: 0 var(--space-1);
}

/* -- Text input -- */

.message-input-row {
    display: flex;
    align-items: flex-end;
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
}

#messageInput,
.message-input {
    flex: 1;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    color: var(--text-primary);
    font-size: var(--font-size-md);
    font-family: var(--font-family);
    line-height: var(--line-height-normal);
    resize: none;
    min-height: var(--composer-min-height);
    max-height: 200px;
    padding: var(--space-1) 0;
    outline: none;
}

#messageInput::placeholder,
.message-input::placeholder {
    color: var(--text-muted);
}

/* -- Action buttons row -- */

.composer-actions {
    display: flex;
    align-items: center;
    padding: var(--space-1) var(--space-3) var(--space-2);
    gap: var(--space-1);
}

.composer-action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-base);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.composer-action-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

/* -- Send button -- */

.send-btn,
#sendBtn {
    background: var(--primary-color);
    color: var(--text-on-primary);
    border: none;
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    font-family: var(--font-family);
    cursor: pointer;
    transition: background var(--transition-fast);
    min-height: 32px;
}

.send-btn:hover,
#sendBtn:hover {
    background: var(--primary-hover);
}

.send-btn:disabled,
#sendBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* -- File upload button -- */

.file-upload-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    font-size: 18px;
    transition: color var(--transition-fast);
}

.file-upload-btn:hover {
    color: var(--text-primary);
}

/* -- Quote preview -- */

.quote-preview {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--surface-hover);
    border-top: 1px solid var(--border-subtle);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.quote-preview-bar {
    width: 3px;
    height: 24px;
    background: var(--primary-color);
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.quote-preview-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quote-preview-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-base);
}

.quote-preview-close:hover {
    color: var(--text-primary);
}

/* -- Typing indicator -- */

.typing-indicator {
    padding: var(--space-1) var(--space-5);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-style: italic;
    min-height: 20px;
}

/* -- File preview -- */

.file-preview {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--surface-hover);
    border-radius: var(--radius-md);
    margin: var(--space-2) var(--space-3) 0;
    font-size: var(--font-size-sm);
}

.file-preview-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
}

.file-preview-remove {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    font-size: var(--font-size-sm);
}

/* -- Mention suggestions -- */

.mention-suggestions {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--surface-overlay);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-popup);
    max-height: 240px;
    overflow-y: auto;
    z-index: var(--z-popover);
}

.mention-suggestion-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.mention-suggestion-item:hover,
.mention-suggestion-item.active {
    background: var(--surface-hover);
}

.mention-suggestion-item .mention-name {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

.mention-suggestion-item .mention-username {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

/* ======================================
 * THREAD PANEL COMPOSER
 * ====================================== */

.thread-reply-input {
    display: block;
    padding: var(--space-3);
    border-top: 1px solid var(--border-color);
    background: var(--surface-raised);
    flex-shrink: 0;
}

.thread-reply-input .message-input-wrapper {
    border-radius: var(--radius-md);
    width: 100%;
}

.thread-reply-input .message-input-row {
    padding: var(--space-2) var(--space-3);
}

.thread-reply-input .message-input {
    min-height: 36px;
    font-size: var(--font-size-base);
    width: 100%;
}

.thread-reply-input .composer-bottom-bar {
    padding: var(--space-1) var(--space-3);
}

/* Hide empty formatting toolbar in thread panel */
.thread-reply-input .formatting-toolbar:empty {
    display: none;
}

.thread-reply-input .composer-bottom-bar:has(.formatting-toolbar:empty) {
    justify-content: flex-end;
}

/* Thread message menu */
.thread-message {
    position: relative;
}

.thread-message .message-menu-btn {
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.thread-message:hover .message-menu-btn {
    opacity: 0.6;
}

/* Thread root message */
.thread-root-message {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-base);
}

/* Thread replies area */
.thread-replies {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2) 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

/* Thread divider */
.thread-replies-divider {
    display: flex;
    align-items: center;
    padding: var(--space-2) var(--space-4);
    gap: var(--space-3);
}

.thread-replies-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.thread-replies-divider span {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    color: var(--text-muted);
    white-space: nowrap;
}

/* Legacy input-controls — kept visible; HTML not yet migrated to v2 wrapper */
.input-controls {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
}

/* Hide empty file preview and quote preview */
.file-preview:empty,
#filePreview:not(.show) {
    display: none;
}

.quote-preview-bar:empty {
    display: none;
}

/* =========================================================
 * Mobile composer — collapse formatting bar behind "Aa" toggle.
 * Scoped to the main composer (#formattingToolbar) so the thread
 * composer's empty .formatting-toolbar is not affected.
 * ========================================================= */

/* Toggle button: hidden on desktop, shown only on mobile */
.format-toggle-btn {
    display: none;
}

@media (max-width: 768px) {
    /* Anchor composer in flow at the bottom of main-chat instead of
     * position:fixed. Legacy `position: fixed; bottom: <JS-calc>` was
     * unreliable across iOS Safari versions — when the keyboard opened,
     * the composer ended up floating mid-screen with a huge gap above
     * because window.innerHeight stayed constant on older iOS. With
     * static positioning the composer naturally sits at the bottom of
     * its flex parent (.main-chat), and main-chat shrinks via
     * --vh / visualViewport when the keyboard opens. No JS bottom calc
     * needed.  Negate every legacy positioning declaration. */
    .message-input-container {
        position: static !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        max-width: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        flex-shrink: 0;
        z-index: auto !important;
    }

    /* Allow the toolbar to wrap to its own row when expanded */
    .composer-bottom-bar {
        flex-wrap: wrap;
        row-gap: var(--space-2);
    }

    .format-toggle-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        width: 36px;
        height: 36px;
        padding: 0;
        background: transparent;
        border: 1px solid transparent;
        border-radius: var(--radius-sm);
        color: var(--text-muted);
        font-family: var(--font-family);
        font-size: 14px;
        font-weight: var(--font-weight-bold);
        font-style: italic;
        cursor: pointer;
        transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    }
    .format-toggle-btn:hover,
    .format-toggle-btn:focus-visible {
        background: var(--surface-hover);
        color: var(--text-primary);
        border-color: var(--border-subtle);
        outline: none;
    }
    .format-toggle-btn[aria-expanded="true"] {
        background: var(--surface-active);
        color: var(--accent-color);
        border-color: var(--border-subtle);
    }

    /* Hide the formatting toolbar by default on mobile.
     * Scoped to #formattingToolbar (main composer) so the thread
     * composer's :empty toolbar styling at line 332 stays intact. */
    #formattingToolbar {
        display: none;
        order: 99;       /* push to the wrapped line at the bottom */
        flex-basis: 100%;
        gap: var(--space-1);
    }

    #formattingToolbar.expanded {
        display: flex;
    }
}

/* =============================================================================
 * Giphy Picker
 * ============================================================================= */
.giphy-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--surface-overlay);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-popup);
    z-index: 200;
    overflow: hidden;
    max-height: 320px;
    display: flex;
    flex-direction: column;
}

.giphy-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px 8px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.giphy-picker-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.giphy-picker-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    line-height: 1;
}

.giphy-picker-close:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.giphy-picker-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}

.giphy-thumb {
    background: var(--surface-sunken);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
    overflow: hidden;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.giphy-thumb:hover {
    transform: scale(1.04);
    opacity: 0.9;
}

.giphy-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.giphy-attribution {
    font-size: 10px;
    color: var(--text-muted);
    text-align: right;
    padding: 4px 10px;
    flex-shrink: 0;
    border-top: 1px solid var(--border-subtle);
}
/*
 * InfiChat v2 — Search
 * Slack-style command palette search + results
 */

/* ======================================
 * ADVANCED SEARCH MODAL
 * ====================================== */

#advancedSearchModal .modal-content {
    background: var(--surface-overlay);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 640px;
    width: 90vw;
    padding: 0;
    overflow: hidden;
}

#advancedSearchModal .modal-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#advancedSearchModal .modal-header h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
}

#advancedSearchModal .modal-body {
    padding: var(--space-4) var(--space-5) !important;
}

/* Search form inputs */
#advancedSearchForm label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

#advancedSearchForm input,
#advancedSearchForm select {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: var(--surface-base);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    margin-bottom: var(--space-3);
    transition: border-color var(--transition-fast);
}

#advancedSearchForm input:focus,
#advancedSearchForm select:focus {
    border-color: var(--primary-color);
    outline: none;
}

#advancedSearchForm input::placeholder {
    color: var(--text-muted);
}

/* Search button */
#advancedSearchForm button[type="submit"],
.advanced-search-btn {
    background: var(--primary-color) !important;
    color: var(--text-on-primary) !important;
    border: none !important;
    border-radius: var(--radius-md) !important;
    padding: var(--space-2) var(--space-5) !important;
    font-size: var(--font-size-base) !important;
    font-weight: var(--font-weight-semibold) !important;
    font-family: var(--font-family) !important;
    cursor: pointer;
    transition: background var(--transition-fast) !important;
}

#advancedSearchForm button[type="submit"]:hover,
.advanced-search-btn:hover {
    background: var(--primary-hover) !important;
}

/* ======================================
 * SEARCH RESULTS MODAL
 * ====================================== */

.search-results-modal .modal-content,
#searchResultsModal .modal-content {
    background: var(--surface-overlay) !important;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
}

.search-results-modal .modal-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-color);
}

.search-results-modal .modal-header h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
}

/* Summary + tabs area */
.search-results-summary {
    padding: var(--space-3) var(--space-5) !important;
    border-bottom: 1px solid var(--border-color) !important;
    background: var(--surface-raised) !important;
}

.search-summary {
    color: var(--text-secondary) !important;
    font-size: var(--font-size-sm) !important;
    margin-bottom: var(--space-3) !important;
}

/* Tabs */
.search-tabs {
    display: flex;
    gap: var(--space-1);
}

.search-tab {
    background: transparent !important;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted) !important;
    padding: var(--space-2) var(--space-3) !important;
    cursor: pointer;
    border-radius: 0 !important;
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--font-size-sm) !important;
    font-weight: var(--font-weight-medium);
    font-family: var(--font-family);
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.search-tab:hover:not(.active) {
    color: var(--text-primary) !important;
    background: transparent !important;
}

.search-tab.active {
    color: var(--primary-color) !important;
    background: transparent !important;
    border-bottom-color: var(--primary-color);
}

.tab-count {
    background: var(--surface-hover) !important;
    color: var(--text-secondary) !important;
    padding: 1px 6px !important;
    border-radius: var(--radius-full) !important;
    font-size: var(--font-size-xs) !important;
    font-weight: var(--font-weight-semibold);
}

.search-tab.active .tab-count {
    background: var(--primary-light) !important;
    color: var(--primary-color) !important;
}

/* Results list */
.search-results-content-area {
    padding: var(--space-4) var(--space-5) !important;
}

.search-result {
    background: var(--surface-raised) !important;
    border: 1px solid var(--border-subtle) !important;
    border-left: 3px solid var(--primary-color) !important;
    border-radius: var(--radius-md) !important;
    padding: var(--space-3) var(--space-4) !important;
    margin-bottom: var(--space-2) !important;
    transition: background var(--transition-fast), border-color var(--transition-fast) !important;
}

.search-result:hover {
    background: var(--surface-hover) !important;
    border-color: var(--border-color) !important;
}

.search-result-header {
    margin-bottom: var(--space-1) !important;
}

.search-result-header strong,
.search-result-header .search-result-author {
    color: var(--text-primary);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-base);
}

.search-result-meta {
    color: var(--text-muted) !important;
    font-size: var(--font-size-xs) !important;
    gap: var(--space-2) !important;
}

.search-result-content {
    color: var(--text-secondary) !important;
    font-size: var(--font-size-base) !important;
    line-height: var(--line-height-normal) !important;
    margin-bottom: var(--space-2) !important;
}

.search-result-content mark {
    background: rgba(88, 101, 242, 0.25) !important;
    color: var(--text-primary) !important;
    padding: 1px 3px !important;
    border-radius: 2px !important;
}

/* Result action buttons */
.search-result-actions {
    gap: var(--space-2) !important;
}

.search-result-btn {
    background: var(--surface-hover) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    padding: var(--space-1) var(--space-3) !important;
    border-radius: var(--radius-md) !important;
    cursor: pointer;
    font-size: var(--font-size-sm) !important;
    font-family: var(--font-family);
    transition: background var(--transition-fast) !important;
}

.search-result-btn:hover {
    background: var(--surface-active) !important;
}

.search-result-btn.primary {
    background: var(--primary-color) !important;
    color: var(--text-on-primary) !important;
    border-color: var(--primary-color) !important;
}

.search-result-btn.primary:hover {
    background: var(--primary-hover) !important;
}

/* Pagination */
.search-pagination {
    padding: var(--space-3) var(--space-5) !important;
    border-top: 1px solid var(--border-color) !important;
}

/* New search button */
.search-results-controls .btn-secondary {
    background: var(--surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.search-results-controls .btn-secondary:hover {
    background: var(--surface-active);
}

/* ======================================
 * HEADER SEARCH BUTTON
 * ====================================== */

.header-search-btn {
    background: var(--surface-hover) !important;
    color: var(--text-muted) !important;
    border: 1px solid var(--border-color) !important;
    padding: var(--space-1) var(--space-3) !important;
    border-radius: var(--radius-md) !important;
    font-size: var(--font-size-sm) !important;
    font-weight: var(--font-weight-medium) !important;
    font-family: var(--font-family);
    transition: background var(--transition-fast), color var(--transition-fast) !important;
}

.header-search-btn:hover {
    background: var(--surface-active) !important;
    color: var(--text-primary) !important;
}

/* ======================================
 * SIDEBAR ROOM SEARCH
 * ====================================== */

.room-search-container {
    padding: var(--space-2) var(--space-3);
    position: relative;
}

.room-search-container input {
    width: 100%;
    padding: var(--space-1) var(--space-3);
    padding-right: 28px;
    background: var(--surface-hover);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    transition: border-color var(--transition-fast), background var(--transition-fast);
    height: 28px;
}

.room-search-container input::placeholder {
    color: var(--text-muted);
}

.room-search-container input:focus {
    background: var(--surface-base);
    border-color: var(--primary-color);
    outline: none;
}

.clear-search-btn {
    position: absolute;
    right: var(--space-4);
    top: 50%;
    transform: translateY(-50%);
    background: transparent !important;
    border: none !important;
    color: var(--text-muted);
    cursor: pointer;
    font-size: var(--font-size-sm);
    padding: 2px 4px;
    border-radius: var(--radius-sm);
}

.clear-search-btn:hover {
    color: var(--text-primary);
}

/* ======================================
 * CLOSE BUTTONS (modals)
 * ====================================== */

.modal-content .close,
.modal-close-btn {
    background: transparent !important;
    border: none !important;
    color: var(--text-muted) !important;
    font-size: var(--font-size-xl) !important;
    cursor: pointer;
    padding: var(--space-1) !important;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast);
    line-height: 1;
}

.modal-content .close:hover,
.modal-close-btn:hover {
    color: var(--text-primary) !important;
}
