/* ──────────────────────────────────────────────
   CREW COMMUNICATION CHANNEL — Chat Component
   ────────────────────────────────────────────── */

/* Chat content container — fills the window body, height from parent */
.chat-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Root wrapper — flex column filling the chat-content */
.crew-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    /* Anchor for absolute-positioned settings panel */
    position: relative;
}

/* ── SETTINGS GEAR — absolute top-right inside crew-chat ── */

.chat-settings-btn {
    background: rgba(0, 0, 0, 0.5);
    border: var(--border-thin) solid var(--window-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: var(--space-xs);
    /* Flex centering keeps the icon perfectly centered in the button */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.chat-settings-btn .chat-icon {
    /* Larger icon for better visibility in the gear button */
    height: 1.1em;
    width: auto;
    opacity: 0.85;
    transition: opacity var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
    .chat-settings-btn:hover {
        background: rgba(116, 255, 149, 0.1);
        border-color: var(--theme-primary);
    }
    .chat-settings-btn:hover .chat-icon {
        /* Green tint matching --theme-primary */
        filter: brightness(0) saturate(100%) invert(82%) sepia(45%) saturate(600%) hue-rotate(85deg) brightness(1.1);
        opacity: 1;
    }
}

/* ── HEADER ACTIONS — wrapper for mute + settings buttons, top-right corner ── */

.chat-header-actions {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    z-index: 2;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

/* Mute toggle — inline SVG speaker icon, matches settings gear dimensions */
.chat-mute-btn {
    background: rgba(0, 0, 0, 0.5);
    border: var(--border-thin) solid var(--window-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: var(--space-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    color: var(--text-muted);
}

/* SVG icon inside mute button — sized to match .chat-icon */
.chat-mute-icon {
    width: 1.1em;
    height: 1.1em;
    display: block;
}

@media (hover: hover) and (pointer: fine) {
    .chat-mute-btn:hover {
        background: rgba(116, 255, 149, 0.1);
        border-color: var(--theme-primary);
        color: var(--theme-primary);
    }
}

/* ── HEADER ACTION BUTTONS — uniform sizing across all buttons ── */

.chat-header-actions button {
    /* Uniform square base for all header action buttons */
    width: 1.75rem;
    height: 1.75rem;
    box-sizing: border-box;
}

/* ── OPERATOR COUNT BUTTON — shows connected crew count with floating badge ── */

.chat-operator-btn {
    background: rgba(0, 0, 0, 0.5);
    border: var(--border-thin) solid var(--window-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    color: var(--text-muted);
    position: relative;
}

.chat-operator-btn .chat-icon {
    height: 1.1em;
    width: auto;
    opacity: 0.85;
    transition: opacity var(--transition-fast);
}

/* Floating badge — top-right corner pastille */
.chat-operator-badge {
    position: absolute;
    top: -0.35rem;
    right: -0.35rem;
    background: var(--theme-primary);
    color: #000d1a;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.55rem;
    font-weight: bold;
    line-height: 1;
    min-width: 0.9rem;
    height: 0.9rem;
    padding: 0 0.2rem;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    box-shadow: 0 0 4px rgba(116, 255, 149, 0.4);
}

@media (hover: hover) and (pointer: fine) {
    .chat-operator-btn:hover {
        background: rgba(116, 255, 149, 0.1);
        border-color: var(--theme-primary);
    }
    .chat-operator-btn:hover .chat-icon {
        filter: brightness(0) saturate(100%) invert(82%) sepia(45%) saturate(600%) hue-rotate(85deg) brightness(1.1);
        opacity: 1;
    }
}

/* ── OPERATOR LIST PANEL — slide-in overlay matching settings panel pattern ── */

.chat-operator-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: min(100%, 16rem);
    z-index: 3;
    background: rgba(0, 13, 26, 0.92);
    border-left: var(--border-thin) solid var(--window-border);
    border-bottom: var(--border-thin) solid var(--window-border);
    border-radius: 0 0 0 var(--radius-sm);
    box-shadow: -4px 4px 12px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Cap height to avoid overflowing the chat container */
    max-height: 60%;
}

.chat-operator-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-bottom: var(--border-thin) solid var(--window-border);
    /* Prevent header from shrinking when list is long */
    flex-shrink: 0;
}

/* Scrollable body for the operator entries */
.chat-operator-panel-body {
    overflow-y: auto;
    padding: var(--space-sm) var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

/* Individual operator row — avatar, name, flag, badge */
.chat-operator-entry {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) 0;
}

/* Avatar inside operator list — small circle */
.chat-operator-avatar {
    width: 1.5rem;
    height: 1.5rem;
    min-width: 1.5rem;
    border-radius: 50%;
    object-fit: cover;
}

/* Default avatar fallback — initial letter */
.chat-operator-avatar-default {
    width: 1.5rem;
    height: 1.5rem;
    min-width: 1.5rem;
    border-radius: 50%;
    background: rgba(116, 255, 149, 0.08);
    border: var(--border-thin) solid var(--window-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xxs);
    color: var(--text-muted);
}

/* Operator name — truncated to prevent overflow */
.chat-operator-name {
    font-family: 'VT323', monospace;
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Let name fill remaining space */
    flex: 1;
    min-width: 0;
}

/* Country flag emoji next to name */
.chat-operator-flag {
    font-size: var(--font-size-xs);
    line-height: 1;
    flex-shrink: 0;
}

/* Flag image from CDN — replaces Unicode emoji for cross-platform support */
.chat-flag-img {
    display: inline-block;
    vertical-align: middle;
    width: 16px;
    height: 12px;
}

/* Empty state message */
.chat-operator-empty {
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    padding: var(--space-sm) 0;
    text-align: center;
}

/* ── SETTINGS PANEL — slide-in overlay, terminal aesthetic ── */

.chat-settings-panel {
    position: absolute;
    top: 0;
    right: 0;
    /* Responsive width — full on small containers, capped on larger ones */
    width: min(100%, 18rem);
    z-index: 3;
    /* Near-opaque background so text stays readable over chat content */
    background: rgba(0, 13, 26, 0.92);
    border-left: var(--border-thin) solid var(--window-border);
    border-bottom: var(--border-thin) solid var(--window-border);
    border-radius: 0 0 0 var(--radius-sm);
    box-shadow: -4px 4px 12px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Panel header — label + close button on one line */
.chat-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-bottom: var(--border-thin) solid var(--window-border);
}

/* Close button — monospace × */
.chat-settings-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-sm);
    cursor: pointer;
    padding: var(--space-xs);
    line-height: 1;
    transition: color var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
    .chat-settings-close:hover {
        color: var(--theme-error);
    }
}

/* Panel body — stacked fields with consistent spacing */
.chat-settings-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-md);
}

/* Individual field group — label above input row */
.chat-settings-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

/* Field labels — reuse section-label visual language */
.chat-settings-label {
    color: var(--theme-primary);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xxs);
    letter-spacing: 0.1em;
    opacity: 0.5;
}

/* Input + save button on one row, underlined */
.chat-settings-input-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    border-bottom: var(--border-thin) solid var(--window-border);
    padding-bottom: var(--space-xs);
}

/* Text inputs inside settings — same family as chat inputs */
.chat-settings-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'VT323', monospace;
    font-size: var(--font-size-terminal);
    line-height: var(--line-height-terminal);
    outline: none;
    padding: var(--space-xs) 0;
    min-width: 0;
}

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

/* Save buttons inside settings — green primary, warm on hover */
.chat-settings-save {
    color: var(--theme-primary);
    flex-shrink: 0;
}

@media (hover: hover) and (pointer: fine) {
    .chat-settings-save:hover {
        color: var(--theme-warning);
    }
}

/* Status feedback line (success/error) */
.chat-settings-status {
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xxs);
    color: var(--theme-primary);
    opacity: 0.8;
    min-height: 1.2em;
    line-height: 1.2;
    transition: color var(--transition-fast);
}

/* Error state — red text for immediate visibility */
.chat-settings-status.is-error {
    color: var(--theme-error, #ff4444);
    opacity: 1;
}

/* ── AVATAR UPLOAD — preview + button row ── */

/* Row layout — preview circle, upload button, hint text */
.chat-avatar-upload-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

/* Square preview container — clickable, holds avatar + upload overlay */
.chat-avatar-preview {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-sm);
    border: var(--border-thin) solid var(--window-border);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    position: relative;
    cursor: pointer;
}

/* Avatar image inside the preview — absolute fill to bypass flex sizing */
.chat-avatar-preview-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

/* Fallback letter when no avatar is set */
.chat-avatar-preview-placeholder {
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-base);
    color: var(--theme-primary);
    opacity: 0.6;
}

/* Upload overlay — covers the entire preview area, above the avatar image */
.chat-avatar-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity var(--transition-fast), background var(--transition-fast);
    cursor: pointer;
}

/* When no avatar exists — no dark background, icon is the main visual */
.chat-avatar-preview:not(.has-avatar) .chat-avatar-overlay {
    opacity: 1;
    background: transparent;
}

/* When an avatar exists — dark scrim, hidden until hover */
.chat-avatar-preview.has-avatar .chat-avatar-overlay {
    opacity: 0;
    background: rgba(0, 0, 0, 0.55);
}

@media (hover: hover) and (pointer: fine) {
    .chat-avatar-preview.has-avatar:hover .chat-avatar-overlay {
        opacity: 1;
    }
}

/* On touch devices, always show a subtle hint over existing avatars */
@media (hover: none) {
    .chat-avatar-preview.has-avatar .chat-avatar-overlay {
        opacity: 0.4;
    }
}

/* Upload icon inside the overlay — forced white via invert for any icon color */
.chat-avatar-overlay-icon {
    width: 1.25rem;
    height: 1.25rem;
    filter: brightness(0) invert(1);
    opacity: 0.85;
}

/* When no avatar, tint the icon green to match theme */
.chat-avatar-preview:not(.has-avatar) .chat-avatar-overlay-icon {
    filter: brightness(0) invert(1) sepia(1) saturate(5) hue-rotate(85deg);
    opacity: 0.6;
}

/* Delete avatar button — small destructive action next to preview */
.chat-avatar-delete-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    color: var(--theme-primary);
    opacity: 0.6;
    padding: 0.125rem 0.375rem;
}

/* Override generic .chat-auth-btn:hover — higher specificity via chained class */
@media (hover: hover) and (pointer: fine) {
    .chat-auth-btn.chat-avatar-delete-btn:hover {
        color: var(--theme-error, #ff4444);
        opacity: 1;
    }
}

/* File size hint — subtle secondary info */
.chat-avatar-hint {
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xxs);
    color: var(--text-muted);
    opacity: 0.5;
}

/* ── MESSAGE LIST (always visible) ── */

.chat-messages {
    overflow-anchor: none;
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    padding-right: 1.4375rem;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-color) var(--bg-terminal);
}

.chat-messages::-webkit-scrollbar {
    width: 0.5rem;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-color);
    border-radius: var(--radius-sm);
}

/* Load-more button — terminal-styled prompt at the top of the message list */
.chat-load-more {
    display: block;
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    margin-bottom: var(--space-sm);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xs);
    cursor: pointer;
    text-align: center;
    letter-spacing: 0.05em;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.chat-load-more:hover:not(:disabled) {
    color: var(--theme-primary);
    border-color: var(--theme-primary);
}

.chat-load-more:disabled {
    cursor: default;
    opacity: 0.5;
    animation: chat-scanning 1.2s ease-in-out infinite;
}

@keyframes chat-scanning {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.8; }
}

/* Individual message row — modern messenger spacing */
.chat-message {
    display: flex;
    /* Comfortable gap between avatar and message body */
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    align-items: flex-start;
    border-radius: 6px;
    margin-bottom: 2px;
    transition: background var(--transition-fast);
    /* Anchor for the absolute-positioned delete button */
    position: relative;
}

/* First message in a group block — only round the top corners */
.chat-message:has(+ .chat-message.grouped) {
    border-radius: 6px 6px 0 0;
    margin-bottom: 0;
}

/* Middle messages in a group block — no rounded corners, no gap */
.chat-message.grouped:has(+ .chat-message.grouped) {
    border-radius: 0;
    margin-bottom: 0;
}

/* Last message in a group block — only round the bottom corners */
.chat-message.grouped:not(:has(+ .chat-message.grouped)) {
    border-radius: 0 0 6px 6px;
}

/* Alternating backgrounds — two distinct tints for clear user separation */
/* Parity 0: cool blue-grey tint — opaque enough to always stand out against terminal bg */
.chat-message[data-user-parity="0"] {
    background: rgba(130, 170, 235, 0.18);
}

/* Parity 1: warm green tint — matches theme-primary, strong solid presence */
.chat-message[data-user-parity="1"] {
    background: rgba(116, 255, 149, 0.22);
}

/* Hover highlight on messages — intensifies the existing tint */
@media (hover: hover) and (pointer: fine) {
    .chat-message[data-user-parity="0"]:hover {
        background: rgba(130, 170, 235, 0.26);
    }
    .chat-message[data-user-parity="1"]:hover {
        background: rgba(116, 255, 149, 0.30);
    }
}

/* Grouped message (same user, consecutive) — no avatar, no header */
.chat-message.grouped {
    padding-top: 0;
    /* Left padding = parent horizontal padding + avatar width + gap to align text */
    padding-left: calc(var(--space-md) + 1.5rem + var(--space-md));
    /* No gap between grouped messages — forms a single visual block */
    margin-top: 0;
}

/* Hide avatar and header on grouped messages */
.chat-message.grouped .chat-avatar,
.chat-message.grouped .chat-avatar-default,
.chat-message.grouped .chat-msg-header {
    display: none;
}

/* Avatar (image or fallback initial) */
.chat-avatar {
    width: 1.5rem;
    height: 1.5rem;
    min-width: 1.5rem;
    min-height: 1.5rem;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    object-fit: cover;
    display: block;
}

/* Default avatar — first letter of username */
.chat-avatar-default {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(116, 255, 149, 0.15);
    color: var(--theme-primary);
    font-family: 'Neuropol X', sans-serif;
    font-size: var(--font-size-xs);
    font-weight: bold;
}

/* Clickable avatar — hover animation indicates mention-on-click affordance */
.chat-avatar-clickable {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

@media (hover: hover) and (pointer: fine) {
    .chat-avatar-clickable:hover {
        transform: scale(1.15);
        box-shadow: 0 0 6px rgba(116, 255, 149, 0.5);
        filter: brightness(1.2);
    }
}

/* Subtle pulse feedback on touch devices when tapped */
.chat-avatar-clickable:active {
    transform: scale(0.95);
}

/* Message body (header + text) */
.chat-msg-body {
    flex: 1;
    min-width: 0;
}

/* Message header line (flag, name, badge, time, delete) */
.chat-msg-header {
    display: flex;
    align-items: center;
    /* Slightly airy gap between header elements for readability */
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.chat-flag {
    font-size: var(--font-size-xs);
    line-height: 1;
}

.chat-msg-username {
    font-family: 'Neuropol X', sans-serif;
    font-size: var(--font-size-xs);
    font-weight: bold;
}

.chat-badge {
    color: var(--theme-warning);
    font-size: 0.5rem;
    line-height: 1;
}

.chat-badge-admin {
    color: var(--message-info);
}

.chat-msg-time {
    color: var(--text-muted);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xxs);
    margin-left: auto;
}

/* Text + delete button row — keeps delete aligned with text, not header */
.chat-msg-row {
    display: flex;
    align-items: flex-start;
}

.chat-msg-text {
    color: var(--text-primary);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    word-break: break-word;
    /* Fill available space so delete button sits at the right edge */
    flex: 1;
    min-width: 0;
}

/* ── HYPERLINKS — inline URLs converted to clickable links ── */

.chat-link {
    color: var(--theme-primary);
    font-family: 'Share Tech Mono', monospace;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}

@media (hover: hover) and (pointer: fine) {
    .chat-link:hover {
        opacity: 0.75;
    }
}

/* ── @MENTION HIGHLIGHTS — inline styled spans inside message text ── */

/* Standard mention — subtle signal tint matching operator comm aesthetic */
.chat-mention {
    font-family: 'Share Tech Mono', monospace;
    color: var(--theme-primary);
    font-weight: bold;
    cursor: default;
}

/* Self-mention — stronger highlight so the recipient notices immediately */
.chat-mention-self {
    color: var(--theme-warning);
    background: rgba(255, 204, 0, 0.08);
    padding: 0 2px;
    border-radius: 2px;
}

/* ── @MENTION AUTOCOMPLETE DROPDOWN — positioned above the input bar ── */

.chat-mention-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    z-index: 5;
    background: rgba(0, 13, 26, 0.95);
    border: var(--border-thin) solid var(--window-border);
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    max-height: 12rem;
    overflow-y: auto;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.4);
}

/* Each autocomplete entry — avatar + colored username */
.chat-mention-option {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
    .chat-mention-option:hover {
        background: rgba(116, 255, 149, 0.1);
    }
}

/* Active option — keyboard-selected highlight */
.chat-mention-option.active {
    background: rgba(116, 255, 149, 0.15);
}

/* Mini avatar inside mention dropdown entries */
.chat-mention-avatar {
    width: 1.25rem;
    height: 1.25rem;
    min-width: 1.25rem;
    border-radius: var(--radius-sm);
    object-fit: cover;
    display: block;
}

/* Default avatar fallback inside dropdown — first letter initial */
.chat-mention-avatar-default {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(116, 255, 149, 0.15);
    color: var(--theme-primary);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xxs);
    font-weight: bold;
}

/* Username text inside dropdown option — matches .chat-msg-text for consistency */
.chat-mention-name {
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-sm);
    color: var(--theme-primary);
}

/* ── IMAGE MESSAGES — inline image with lightbox on click ── */

/* Image wrapper inside message body — constrains dimensions, rounded corners */
.chat-msg-image,
.chat-url-image {
    max-width: min(100%, 20rem);
    margin-top: var(--space-xs);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    border: var(--border-thin) solid var(--window-border);
    transition: border-color var(--transition-fast);
    line-height: 0;
}

@media (hover: hover) and (pointer: fine) {
    .chat-msg-image:hover,
    .chat-url-image:hover {
        border-color: var(--theme-primary);
    }
}

/* Image element fills the wrapper, height constrained to avoid chat flood */
.chat-msg-image img,
.chat-url-image img {
    width: 100%;
    max-height: 18rem;
    object-fit: contain;
    background: rgba(0, 0, 0, 0.3);
    display: block;
}

/* Fullscreen lightbox — covers viewport, click-to-dismiss */
.chat-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Lightbox image — fills viewport with padding, preserves aspect ratio */
.chat-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}

/* ── IMAGE UPLOAD BUTTON — in the input bar ── */

/* Clip/attach button — matches send/leave icon buttons, same bottom alignment */
.chat-attach-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-xs);
    padding-bottom: calc(var(--space-xs) * 2);
    line-height: 1;
    transition: opacity var(--transition-fast);
}

.chat-attach-btn .chat-icon {
    opacity: 0.5;
}

@media (hover: hover) and (pointer: fine) {
    .chat-attach-btn:hover .chat-icon {
        /* Green tint matching --theme-primary */
        filter: brightness(0) saturate(100%) invert(82%) sepia(45%) saturate(600%) hue-rotate(85deg) brightness(1.1);
        opacity: 1;
    }
}

/* Upload progress bar — thin line below the input row */
.chat-upload-progress {
    height: 2px;
    background: var(--window-border);
    overflow: hidden;
    display: none;
}

.chat-upload-progress.active {
    display: block;
}

.chat-upload-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--theme-primary);
    transition: width 0.3s ease;
}

/* ── DRAG AND DROP OVERLAY — visual feedback when dragging a file over chat ── */

.chat-drop-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    background: rgba(116, 255, 149, 0.08);
    border: 2px dashed var(--theme-primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

/* Active state — shown when a file is dragged over the chat area */
.chat-drop-overlay.active {
    opacity: 1;
}

.chat-drop-overlay-text {
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-sm);
    color: var(--theme-primary);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    opacity: 0.9;
}

/* ── MESSAGE ACTION BAR — floating toolbar above the message top-right edge ── */

/* Positioned with negative top so it protrudes above the message boundary,
   sitting in the 2px gap between messages — overlaps nothing inside */
.chat-msg-actions {
    position: absolute;
    /* Anchored to bottom-right edge of every message */
    bottom: -0.6rem;
    right: var(--space-md);
    display: flex;
    gap: 2px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    z-index: 2;
}

/* Show action bar on message hover (desktop with pointer device only) */
@media (hover: hover) and (pointer: fine) {
    .chat-message:hover .chat-msg-actions {
        opacity: 1;
        pointer-events: auto;
    }
}

.chat-action-btn {
    background: rgba(0, 13, 26, 0.85);
    border: var(--border-thin) solid var(--window-border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    /* Scaled up from --font-size-xxs for better readability on large screens */
    font-size: var(--font-size-xs);
    cursor: pointer;
    /* Wider padding to match the larger font size */
    padding: 3px 8px;
    line-height: 1.2;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
    .chat-action-btn:hover {
        background: rgba(116, 255, 149, 0.15);
        color: var(--theme-primary);
        border-color: var(--theme-primary);
    }

    /* Delete action in the toolbar — red destructive tint on hover */
    .chat-action-delete-btn:hover {
        background: rgba(255, 68, 68, 0.15);
        color: var(--theme-error);
        border-color: var(--theme-error);
    }
}

/* On touch devices, always show delete button */
@media (hover: none) {
    .chat-delete-btn {
        opacity: 0.5;
    }
}

/* System messages (join/leave/errors) */
.chat-system-msg {
    color: var(--text-muted);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xs);
    padding: var(--space-sm) 0;
    opacity: 0.7;
}

/* ── BOTTOM BAR — shared base for login and input bars ── */
/* Matches .terminal-input dimensions exactly (same padding, font, line-height) */

.chat-bottom-bar {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    background: var(--bg-terminal);
    border-top: var(--border-thin) solid var(--window-border);
    font-size: var(--font-size-terminal);
    line-height: var(--line-height-terminal);
    flex-shrink: 0;
    /* Anchor for the @mention autocomplete dropdown positioned above */
    position: relative;
}

/* ── LOGIN BAR (before joining) ── */

/* Top row: label + username input + join button — compact, matches terminal-input */
.chat-login-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm);
}

/* ── GUEST SECTION — label + name input + join, all on one line ── */

.chat-guest-section {
    padding: 0;
}

/* ── AUTH SECTION — wraps toggle row and expandable auth form ── */

.chat-auth-section {
    display: flex;
    flex-direction: column;
    gap: 0;
    /* Subtle separator between guest and auth zones */
    border-top: var(--border-thin) solid var(--window-border);
}

/* Section labels ("GUEST", "ACCOUNT") — inline tag style */
.chat-section-label {
    color: var(--theme-primary);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xxs);
    letter-spacing: 0.1em;
    opacity: 0.5;
    white-space: nowrap;
    flex-shrink: 0;
    /* Extra right margin so the label breathes from the input */
    margin-right: var(--space-xs);
}

/* Toggle row — ACCOUNT label + icon buttons for login/register */
.chat-auth-toggle-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
}

/* Icon-only auth action buttons (login, register) */
.chat-auth-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-sm);
    line-height: 1;
    transition: opacity var(--transition-fast);
    display: inline-flex;
    align-items: center;
}

/* Auth icon images — slightly larger than default .chat-icon for better visibility */
.chat-auth-icon-btn .chat-icon {
    height: 1.1em;
}

.chat-auth-icon-btn .chat-icon {
    opacity: 0.5;
}

@media (hover: hover) and (pointer: fine) {
    /* Login icon — cyan/primary tint on hover */
    .chat-btn-show-login:hover .chat-icon {
        filter: brightness(0) saturate(100%) invert(82%) sepia(45%) saturate(600%) hue-rotate(85deg) brightness(1.1);
        opacity: 1;
    }
    /* Register icon — warm/warning tint on hover */
    .chat-btn-show-register:hover .chat-icon {
        filter: brightness(0) saturate(100%) invert(85%) sepia(30%) saturate(500%) hue-rotate(5deg) brightness(1.1);
        opacity: 1;
    }
}

/* Auth form — stacked fields + action buttons, hidden by default */
.chat-auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md) var(--space-md);
}

/* Username and password stacked vertically */
.chat-auth-fields {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Thin line separating username and password fields */
.chat-auth-separator-line {
    height: 1px;
    background: var(--window-border);
    opacity: 0.4;
    margin: var(--space-xs) 0;
}

/* Submit + cancel side by side */
.chat-auth-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* Auth username input — matches guest input styling */
.chat-username-input-auth {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'VT323', monospace;
    font-size: inherit;
    line-height: inherit;
    outline: none;
    padding: var(--space-xs) 0;
    min-width: 0;
}

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

/* Shared hidden state — collapses any section/row completely */
.chat-auth-hidden {
    display: none;
}

/* Cancel button — uses logout icon */
.chat-btn-cancel {
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-xs);
    line-height: 1;
    transition: opacity var(--transition-fast);
}

.chat-btn-cancel .chat-icon {
    opacity: 0.5;
}

@media (hover: hover) and (pointer: fine) {
    .chat-btn-cancel:hover .chat-icon {
        /* Red tint matching --theme-error on hover */
        filter: brightness(0) saturate(100%) invert(30%) sepia(95%) saturate(5000%) hue-rotate(350deg) brightness(1);
        opacity: 1;
    }
}

/* All inputs in login bar match terminal-input input exactly */
.chat-login-bar input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'VT323', monospace;
    font-size: inherit;
    line-height: inherit;
    outline: none;
    padding: var(--space-xs) 0;
    min-width: 0;
}

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

/* Join button (anonymous guest) */
.chat-join-btn {
    background: none;
    border: none;
    color: var(--theme-primary);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xs);
    cursor: pointer;
    padding: var(--space-xs) var(--space-sm);
    white-space: nowrap;
    transition: color var(--transition-fast);
    /* Vertically align icon with text */
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
}

.chat-join-btn .chat-icon {
    /* Green tint matching the button text */
    filter: brightness(0) saturate(100%) invert(82%) sepia(45%) saturate(600%) hue-rotate(85deg) brightness(1.1);
    opacity: 0.9;
}

@media (hover: hover) and (pointer: fine) {
    .chat-join-btn:hover {
        color: var(--theme-warning);
    }
    .chat-join-btn:hover .chat-icon {
        filter: brightness(0) saturate(100%) invert(85%) sepia(30%) saturate(500%) hue-rotate(5deg) brightness(1.1);
        opacity: 1;
    }
}

/* Auth buttons (log in / register) */
.chat-auth-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xxs);
    cursor: pointer;
    padding: var(--space-xs);
    white-space: nowrap;
    transition: color var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
    .chat-auth-btn:hover {
        color: var(--theme-primary);
    }
}

/* ── MESSAGE INPUT BAR (after joining) ── */

/* Input row — buttons anchored to bottom when textarea grows */
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    padding: var(--space-sm);
}

/* Prompt symbol matching terminal .prompt — bottom-padded to align with textarea text */
.chat-prompt {
    color: var(--theme-primary);
    font-weight: bold;
    animation: pulse 2s infinite;
    padding-bottom: var(--space-xs);
}

/* Message text input — textarea that auto-grows with content like Messenger */
.chat-msg-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'VT323', monospace;
    font-size: inherit;
    line-height: inherit;
    width: 100%;
    outline: none;
    padding: var(--space-xs) 0;
    /* Prevent manual resize, height controlled by JS auto-grow */
    resize: none;
    /* Hide scrollbar until max height is reached */
    overflow: hidden;
    /* Single row by default, grows up to ~6 lines */
    min-height: 1.5em;
    max-height: 8em;
    /* Reset default textarea appearance */
    display: block;
    box-sizing: border-box;
}

/* Show scrollbar once content exceeds max height */
.chat-msg-input.scrollable {
    overflow-y: auto;
}

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

/* Inline icon used inside buttons (enter, logout) */
.chat-icon {
    height: 0.85em;
    width: auto;
    vertical-align: middle;
    /* Tint the icon to match surrounding text color */
    filter: brightness(0) invert(1);
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

/* Send button — extra bottom padding to stay level with textarea text */
.chat-send-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-xs);
    padding-bottom: calc(var(--space-xs) * 2);
    line-height: 1;
    transition: opacity var(--transition-fast);
}

.chat-send-btn .chat-icon {
    /* Green tint matching --theme-primary */
    filter: brightness(0) saturate(100%) invert(82%) sepia(45%) saturate(600%) hue-rotate(85deg) brightness(1.1);
    opacity: 0.9;
}

@media (hover: hover) and (pointer: fine) {
    .chat-send-btn:hover .chat-icon {
        /* Warm tint matching --theme-warning on hover */
        filter: brightness(0) saturate(100%) invert(85%) sepia(30%) saturate(500%) hue-rotate(5deg) brightness(1.1);
        opacity: 1;
    }
}

.chat-send-btn:active {
    transform: scale(0.9);
    transition: transform 0.1s ease;
}

/* Disconnect button — extra bottom padding to stay level with textarea text */
.chat-leave-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-xs);
    padding-bottom: calc(var(--space-xs) * 2);
    line-height: 1;
    transition: opacity var(--transition-fast);
}

.chat-leave-btn .chat-icon {
    opacity: 0.5;
}

@media (hover: hover) and (pointer: fine) {
    .chat-leave-btn:hover .chat-icon {
        /* Red tint matching --theme-error on hover */
        filter: brightness(0) saturate(100%) invert(30%) sepia(95%) saturate(5000%) hue-rotate(350deg) brightness(1);
        opacity: 1;
    }
}

/* ── REPLY QUOTE BLOCK — compact reference to parent message inside message body ── */

/* Soft violet tint — third color that stands apart from both parity backgrounds
   (parity 0 = blue rgba(130,170,235), parity 1 = green rgba(116,255,149))
   without looking like a warning or error state */
.chat-reply-quote {
    display: flex;
    /* Wrap so reply text flows to its own line below indicator + author */
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-xs);
    padding: 2px var(--space-sm);
    margin-bottom: var(--space-xs);
    border-left: 2px solid rgba(180, 140, 255, 0.6);
    background: rgba(180, 140, 255, 0.08);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    cursor: pointer;
    transition: background var(--transition-fast);
    max-width: 100%;
    overflow: hidden;
}

@media (hover: hover) and (pointer: fine) {
    .chat-reply-quote:hover {
        background: rgba(180, 140, 255, 0.16);
    }
}

/* Arrow indicator matches the violet quote border */
.chat-reply-indicator {
    color: rgba(180, 140, 255, 0.8);
    font-size: var(--font-size-xxs);
    flex-shrink: 0;
}

.chat-reply-author {
    font-family: 'Neuropol X', sans-serif;
    font-size: var(--font-size-xxs);
    font-weight: bold;
    flex-shrink: 0;
}

.chat-reply-text {
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xxs);
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Force text onto its own line, full width of the quote block */
    flex-basis: 100%;
    min-width: 0;
}

/* ── REPLY PREVIEW BAR — shown above message input when replying ── */

.chat-reply-preview {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    background: rgba(116, 255, 149, 0.08);
    border-bottom: var(--border-thin) solid var(--window-border);
    font-family: 'Share Tech Mono', monospace;
    font-size: var(--font-size-xxs);
    color: var(--text-muted);
    min-height: 0;
    overflow: hidden;
}

.chat-reply-preview-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-reply-preview-author {
    color: var(--theme-primary);
    font-weight: bold;
    margin-right: var(--space-xs);
}

.chat-reply-cancel {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    cursor: pointer;
    padding: 0 var(--space-xs);
    opacity: 0.5;
    transition: opacity var(--transition-fast), color var(--transition-fast);
    flex-shrink: 0;
}

@media (hover: hover) and (pointer: fine) {
    .chat-reply-cancel:hover {
        opacity: 1;
        color: var(--theme-error);
    }
}

/* ── HIGHLIGHT FLASH — brief pulse when scrolling to a referenced message ── */

@keyframes msg-highlight-flash {
    0% { box-shadow: inset 0 0 0 1px var(--theme-primary); }
    100% { box-shadow: inset 0 0 0 1px transparent; }
}

.chat-msg-highlight {
    animation: msg-highlight-flash 1.5s ease-out;
}

/* ── REACTION PICKER — inline bar of reaction options ── */

.chat-reaction-picker {
    display: flex;
    /* Wrap emoji buttons to next line instead of overflowing the container */
    flex-wrap: wrap;
    gap: 2px;
    padding: var(--space-xs) 0;
    /* Constrain picker width to its parent (.chat-msg-body) */
    max-width: 100%;
}

.chat-reaction-option {
    background: rgba(0, 0, 0, 0.4);
    border: var(--border-thin) solid var(--window-border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: 'Share Tech Mono', monospace;
    /* Scaled up from --font-size-xs for easier selection on desktop */
    font-size: var(--font-size-sm);
    cursor: pointer;
    /* Larger hit area to match the bigger emoji */
    padding: 4px 8px;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
    .chat-reaction-option:hover {
        background: rgba(116, 255, 149, 0.15);
        color: var(--theme-primary);
        border-color: var(--theme-primary);
    }
}

/* ── REACTION BADGES — displayed below message text ── */

.chat-msg-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    /* Only take space when badges are present */
    min-height: 0;
}

/* Add top margin only when reactions container has children */
.chat-msg-reactions:not(:empty) {
    margin-top: var(--space-xs);
}

.chat-reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    position: relative;
    background: rgba(255, 255, 255, 0.05);
    border: var(--border-thin) solid var(--window-border);
    border-radius: var(--radius-sm);
    /* Larger padding for comfortable click area on desktop */
    padding: 4px 9px;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    font-family: 'Share Tech Mono', monospace;
}

/* Tooltip — shows list of users who reacted, on desktop hover only */
@media (hover: hover) and (pointer: fine) {
    .chat-reaction-badge[data-tooltip]::after {
        content: attr(data-tooltip);
        position: absolute;
        bottom: calc(100% + 6px);
        left: 50%;
        transform: translateX(-50%);
        background: var(--bg-secondary, #1a1a1a);
        border: var(--border-thin) solid var(--window-border);
        color: var(--text-primary);
        font-size: var(--font-size-xs);
        font-family: 'Share Tech Mono', monospace;
        padding: 3px 7px;
        border-radius: var(--radius-sm);
        white-space: nowrap;
        pointer-events: none;
        opacity: 0;
        transition: opacity var(--transition-fast);
        z-index: 10;
    }

    .chat-reaction-badge[data-tooltip]:hover::after {
        opacity: 1;
    }
}

/* Self-reacted badge — highlighted border */
.chat-reaction-badge.is-self {
    border-color: var(--theme-primary);
    background: rgba(116, 255, 149, 0.1);
}

@media (hover: hover) and (pointer: fine) {
    .chat-reaction-badge:hover {
        background: rgba(116, 255, 149, 0.15);
        border-color: var(--theme-primary);
    }
}

.chat-reaction-emoji {
    /* Halfway between --font-size-xs and --font-size-sm for balanced proportion */
    font-size: 0.8rem;
    color: var(--text-primary);
    line-height: 1;
}

.chat-reaction-count {
    /* Scaled up from --font-size-xxs to stay proportional with the emoji */
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    line-height: 1;
}

/* ── MOBILE OVERRIDES — touch-friendly sizing for crew chat on small screens ── */
@media screen and (max-width: 768px) {

    /* ── Base font scale — override the inherited desktop --font-size-terminal ── */
    .chat-bottom-bar {
        font-size: 1rem;
        line-height: 1.5;
    }

    /* ── Icons — enlarge all inline icons for touch targets ── */
    .chat-icon {
        height: 1.25em;
    }

    /* ── Header action buttons (mute, settings gear) — bigger touch area ── */
    .chat-header-actions {
        top: var(--space-md);
        right: var(--space-md);
        gap: var(--space-sm);
    }

    .chat-settings-btn,
    .chat-mute-btn {
        padding: var(--space-sm);
        min-width: 2.5rem;
        min-height: 2.5rem;
    }

    .chat-settings-btn .chat-icon,
    .chat-mute-icon {
        width: 1.4em;
        height: 1.4em;
    }

    /* ── Login bar — scale up the guest + auth sections ── */
    .chat-login-row {
        padding: var(--space-md);
        gap: var(--space-md);
    }

    .chat-section-label {
        font-size: 0.7rem;
    }

    .chat-login-bar input {
        font-size: 1rem;
        padding: var(--space-sm) 0;
    }

    .chat-join-btn {
        font-size: 0.85rem;
        padding: var(--space-sm) var(--space-md);
        min-height: 2.5rem;
    }

    /* ── Auth toggle row — larger icons + padding ── */
    .chat-auth-toggle-row {
        padding: var(--space-sm) var(--space-md);
        gap: var(--space-md);
    }

    .chat-auth-icon-btn {
        padding: var(--space-sm);
        min-width: 2.5rem;
        min-height: 2.5rem;
    }

    .chat-auth-icon-btn .chat-icon {
        height: 1.3em;
    }

    /* ── Auth form (login/register fields) ── */
    .chat-auth-form {
        padding: var(--space-md);
        gap: var(--space-md);
    }

    .chat-username-input-auth,
    .chat-password-input {
        font-size: 1rem;
        padding: var(--space-sm) 0;
    }

    .chat-auth-btn {
        font-size: 0.8rem;
        padding: var(--space-sm);
        min-height: 2.5rem;
    }

    .chat-btn-cancel {
        padding: var(--space-sm);
        min-width: 2.5rem;
        min-height: 2.5rem;
    }

    /* ── Message input bar — larger input + action buttons ── */
    .chat-input-row {
        padding: var(--space-md);
        gap: var(--space-md);
    }

    .chat-msg-input {
        font-size: 1rem;
        padding: var(--space-sm) 0;
    }

    .chat-send-btn,
    .chat-attach-btn,
    .chat-leave-btn {
        padding: var(--space-sm);
        min-width: 2.5rem;
        min-height: 2.5rem;
    }

    /* ── Message list — enlarge messages, avatars, metadata ── */
    .chat-messages {
        padding: var(--space-md);
        padding-right: var(--space-md);
    }

    .chat-message {
        padding: var(--space-md);
        gap: var(--space-md);
    }

    /* Grouped message left-padding recalculated for larger avatar + gap */
    .chat-message.grouped {
        padding-left: calc(var(--space-md) + 2.25rem + var(--space-md));
    }

    .chat-avatar,
    .chat-avatar-default {
        width: 2.25rem;
        height: 2.25rem;
        min-width: 2.25rem;
        min-height: 2.25rem;
    }

    .chat-avatar-default {
        font-size: 0.85rem;
    }

    .chat-msg-username {
        font-size: 0.8rem;
    }

    .chat-flag {
        font-size: 0.85rem;
    }

    .chat-badge {
        font-size: 0.6rem;
    }

    .chat-msg-time {
        font-size: 0.65rem;
    }

    .chat-msg-text {
        font-size: 0.85rem;
        line-height: 1.5;
    }

    .chat-msg-header {
        gap: var(--space-sm);
    }

    /* Image messages — reduced height to save vertical space on small screens */
    .chat-msg-image,
    .chat-url-image {
        max-width: min(100%, 14rem);
    }

    .chat-msg-image img,
    .chat-url-image img {
        max-height: 10rem;
    }

    /* ── System messages ── */
    .chat-system-msg {
        font-size: 0.75rem;
    }

    /* ── Settings panel — full width on mobile, scaled fields ── */
    .chat-settings-panel {
        width: 100%;
        border-left: none;
        border-radius: 0;
    }

    .chat-settings-header {
        padding: var(--space-md);
    }

    .chat-settings-close {
        font-size: 1rem;
        padding: var(--space-sm);
        min-width: 2.5rem;
        min-height: 2.5rem;
    }

    .chat-settings-body {
        padding: var(--space-md);
        gap: var(--space-lg);
    }

    .chat-settings-label {
        font-size: 0.65rem;
    }

    .chat-settings-input {
        font-size: 1rem;
        padding: var(--space-sm) 0;
    }

    .chat-settings-save {
        font-size: 0.8rem;
        padding: var(--space-sm);
        min-height: 2.5rem;
    }

    .chat-settings-status {
        font-size: 0.7rem;
    }

    /* ── Avatar upload — larger preview and icons for touch ── */
    .chat-avatar-preview {
        width: 3.5rem;
        height: 3.5rem;
    }

    .chat-avatar-overlay-icon {
        width: 1.5rem;
        height: 1.5rem;
    }

    .chat-avatar-delete-btn {
        font-size: 0.8rem;
        padding: var(--space-xs) var(--space-sm);
        min-height: 2.5rem;
    }

    .chat-avatar-hint {
        font-size: 0.65rem;
    }

    /* ── Drop overlay text — readable on mobile ── */
    .chat-drop-overlay-text {
        font-size: 0.85rem;
    }

    /* ── Upload progress bar — thicker for visibility ── */
    .chat-upload-progress {
        height: 3px;
    }

    /* ── Prompt symbol — scale with input row ── */
    .chat-prompt {
        font-size: 1.1rem;
    }

    /* ── Per-message action bar — completely hidden on mobile, replaced by bottom sheet ── */
    .chat-msg-actions {
        display: none;
    }

    /* ── Highlight the targeted message when the action sheet is open ── */
    .chat-message.chat-sheet-target {
        box-shadow: inset 0 0 0 1px var(--theme-primary);
        background: rgba(116, 255, 149, 0.05);
    }

    /* ── Action sheet backdrop — semi-transparent overlay behind the sheet ── */
    .chat-action-sheet-backdrop {
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 10;
    }

    /* ── Action sheet — slides up from the bottom of the chat container ── */
    .chat-action-sheet {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 11;
        background: rgb(0, 13, 26);
        border-top: var(--border-thin) solid var(--theme-primary);
        padding: var(--space-md);
        display: flex;
        flex-direction: column;
        gap: var(--space-sm);
        animation: chat-sheet-slide-up 0.2s ease-out;
    }

    /* Action sheet button row — horizontal layout for reply/react/delete */
    .chat-action-sheet-row {
        display: flex;
        gap: var(--space-sm);
    }

    /* Individual action button — large touch-friendly targets */
    .chat-action-sheet-btn {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-sm);
        padding: var(--space-md);
        min-height: 2.75rem;
        background: rgba(255, 255, 255, 0.05);
        border: var(--border-thin) solid var(--window-border);
        border-radius: var(--radius-sm);
        color: var(--text-muted);
        font-family: 'Share Tech Mono', monospace;
        font-size: 0.85rem;
        cursor: pointer;
        transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    }

    /* Active/tap feedback for sheet buttons */
    .chat-action-sheet-btn:active {
        background: rgba(116, 255, 149, 0.15);
        color: var(--theme-primary);
        border-color: var(--theme-primary);
    }

    /* Delete button — red destructive styling */
    .chat-action-sheet-btn.chat-sheet-delete {
        color: var(--theme-error);
        border-color: rgba(255, 68, 68, 0.3);
    }

    .chat-action-sheet-btn.chat-sheet-delete:active {
        background: rgba(255, 68, 68, 0.15);
        border-color: var(--theme-error);
    }

    /* Emoji row — shown when "React" is tapped in the sheet */
    .chat-action-sheet-reactions {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--space-sm);
        padding: var(--space-sm) 0;
    }

    /* Individual emoji button in the sheet — large touch target */
    .chat-action-sheet-emoji {
        font-size: 1.5rem;
        padding: var(--space-sm);
        min-width: 2.75rem;
        min-height: 2.75rem;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.05);
        border: var(--border-thin) solid var(--window-border);
        border-radius: var(--radius-sm);
        cursor: pointer;
        transition: background var(--transition-fast), border-color var(--transition-fast);
    }

    .chat-action-sheet-emoji:active {
        background: rgba(116, 255, 149, 0.15);
        border-color: var(--theme-primary);
    }

    /* Slide-up entrance animation for the action sheet */
    @keyframes chat-sheet-slide-up {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    /* ── Reaction picker — larger touch targets ── */
    .chat-reaction-option {
        font-size: 0.85rem;
        padding: var(--space-xs) var(--space-sm);
        min-width: 2rem;
        min-height: 1.75rem;
    }

    /* ── Reaction badges — slightly bigger for tapping ── */
    .chat-reaction-badge {
        padding: 2px 6px;
    }

    .chat-reaction-emoji,
    .chat-reaction-count {
        font-size: 0.7rem;
    }

    /* ── Reply preview — readable on small screens ── */
    .chat-reply-preview {
        font-size: 0.75rem;
        padding: var(--space-xs) var(--space-md);
    }

    .chat-reply-cancel {
        font-size: 0.85rem;
        min-width: 2rem;
        min-height: 1.75rem;
    }

    /* ── Reply quote block — slightly larger text on mobile ── */
    .chat-reply-quote {
        padding: 3px var(--space-sm);
    }

    .chat-reply-author,
    .chat-reply-text {
        font-size: 0.7rem;
    }

    /* ── Header action buttons — uniform mobile sizing ── */
    .chat-header-actions button {
        width: 2.5rem;
        height: 2.5rem;
    }

    .chat-operator-badge {
        font-size: 0.6rem;
        min-width: 1rem;
        height: 1rem;
        top: -0.3rem;
        right: -0.3rem;
    }

    /* ── Operator list panel — full width on mobile ── */
    .chat-operator-panel {
        width: 100%;
        border-left: none;
        border-radius: 0;
        max-height: 50%;
    }

    .chat-operator-panel-header {
        padding: var(--space-md);
    }

    .chat-operator-avatar,
    .chat-operator-avatar-default {
        width: 2rem;
        height: 2rem;
        min-width: 2rem;
    }

    .chat-operator-name {
        font-size: 0.85rem;
    }

    .chat-operator-entry {
        padding: var(--space-sm) 0;
    }

    /* ── @Mention dropdown — touch-friendly sizing on mobile ── */
    .chat-mention-option {
        padding: var(--space-sm) var(--space-md);
        gap: var(--space-md);
        min-height: 2.5rem;
    }

    .chat-mention-avatar,
    .chat-mention-avatar-default {
        width: 1.5rem;
        height: 1.5rem;
        min-width: 1.5rem;
    }

    .chat-mention-name {
        font-size: var(--font-size-sm);
    }
}
