/**
 * Global Chat Styles
 * Simple, raw theme - lets user cosmetics stand out
 */

/* Page Container */
.chat-page {
    height: 100%;
    width: 100%;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 0;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
}

/* Hide mobile fullscreen toggle on desktop */
.mobile-fullscreen-toggle {
    display: none;
}

/* Main Chat Container */
.chat-container {
    width: 100%;
    max-width: 100%;
    height: 85vh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;

    /* Simple, raw styling */
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    overflow: hidden;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    background: #222;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    /* Prevent shrinking */
}

.chat-online {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: #9ca3af;
}

.online-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    }

    50% {
        opacity: 0.8;
        transform: scale(1.1);
        box-shadow: 0 0 0 4px rgba(34, 197, 94, 0);
    }
}

/* Messages Container */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    /* Critical for flex scrolling */
    padding: 1rem;
    padding-bottom: 120px;
    /* Space for absolute input */
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: #444 transparent;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}

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

/* Welcome Screen */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: #9ca3af;
}

.chat-welcome-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.chat-welcome h3 {
    color: #e5e7eb;
    margin: 0 0 0.5rem;
    font-weight: 600;
}

.chat-welcome p {
    margin: 0;
}

/* Individual Messages */
.chat-message {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 12px;
    padding: 6px 12px;
    margin-bottom: 2px;
    border-radius: 4px;
    transition: background 0.1s ease;
}

.chat-message.no-anim {
    animation: none !important;
}

.chat-message.no-anim .loot-crate-card {
    animation: none !important;
}

.message-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #4b5563;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 20px;
    flex-shrink: 0;
    user-select: none;
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-avatar:hover {
    opacity: 0.8;
}

.chat-message.guest .message-avatar {
    background-color: #374151;
}

.message-col {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

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

.chat-message:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Message Name */
.message-name {
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
}

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

.message-name.user-name {
    color: #e5e7eb;
}

.message-name.guest-name {
    color: #6b7280;
}

/* Message Content */
.message-content {
    color: #d1d5db;
    word-break: break-word;
    line-height: 1.5;
    font-size: 15px;
    margin-top: 2px;
}

/* Message Content Group (for Discord-style message grouping) */
.message-content-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.message-content.grouped {
    margin-top: 4px;
    padding-left: 0;
}

.mention {
    color: #c4b5fd;
    font-weight: 600;
    background: rgba(167, 139, 250, 0.15);
    padding: 0px 4px;
    border-radius: 4px;
}

/* Message Timestamp */
.message-time {
    font-size: 11px;
    color: #6b7280;
    margin-left: 0;
    flex-shrink: 0;
}

/* Message Reply Button */
.message-reply-btn {
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 6px;
    margin-left: 4px;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.15s;
}

.chat-message:hover .message-reply-btn {
    opacity: 1;
}

.message-reply-btn:hover {
    background: rgba(6, 182, 212, 0.2);
    color: var(--accent-cyan);
}

/* Message Actions Container */
.message-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.15s;
}

.chat-message:hover .message-actions {
    opacity: 1;
}

/* Message React Buttons */
.message-react-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    transition: all 0.15s;
    opacity: 0.6;
}

.message-react-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    opacity: 1;
    transform: scale(1.2);
}

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

.message-reactions:empty {
    display: none;
}

/* Reaction Badge */
.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    cursor: default;
    transition: all 0.15s;
}

.reaction-badge:hover {
    background: rgba(255, 255, 255, 0.12);
}

.reaction-badge.pulse {
    animation: reactionPulse 0.3s ease-out;
}

@keyframes reactionPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

.reaction-count {
    font-size: 11px;
    color: #9ca3af;
}

/* Event Cards (Loot Crate) - Condensed */
.event-loot-crate {
    width: 100%;
    padding: 0;
    margin: 0.5rem 0;
    background: transparent;
}

.loot-crate-card {
    width: 100%;
    background: #222;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    overflow: hidden;
}

.loot-crate-icon {
    font-size: 2rem;
    animation: excited-bounce 3s ease-in-out infinite;
}

@keyframes excited-bounce {

    0%,
    100% {
        transform: translateY(0) scale(1);
    }

    10% {
        transform: translateY(-8px) scale(1.1) rotate(-5deg);
    }

    20% {
        transform: translateY(0) scale(0.95) rotate(3deg);
    }

    30% {
        transform: translateY(-4px) scale(1.05) rotate(-3deg);
    }

    40% {
        transform: translateY(0) scale(1) rotate(0);
    }
}

.loot-crate-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.loot-crate-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
    flex-shrink: 0;
}

.loot-crate-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #e5e7eb;
}

.loot-crate-reward {
    font-size: 0.8rem;
    color: #9ca3af;
    font-weight: 500;
}

.loot-crate-right button {
    background: #444;
    border: 1px solid #555;
    padding: 0.4rem 1rem;
    border-radius: 6px;
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

/* Active (green) button */
.loot-crate-right button.active {
    background: #22c55e;
    border-color: #16a34a;
}

.loot-crate-right button.active:hover:not(:disabled) {
    background: #16a34a;
    border-color: #15803d;
}

/* Disabled (gray) button */
.loot-crate-right button:disabled {
    background: #444;
    border-color: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

.loot-crate-timer {
    width: 120px;
    height: 3px;
    background: #333;
    border-radius: 2px;
    overflow: hidden;
}

.timer-bar {
    height: 100%;
    background: #666;
    border-radius: 2px;
    width: 100%;
}

.loot-crate-countdown {
    font-size: 0.75rem;
    color: #9ca3af;
    margin: 0.25rem 0;
}

/* Expired state */
.event-loot-crate.expired .loot-crate-card {
    opacity: 0.5;
    border-color: #333;
}

.event-loot-crate.expired .loot-crate-timer,
.event-loot-crate.expired .loot-crate-countdown {
    display: none;
}

.event-loot-crate.expired .loot-crate-icon {
    animation: none;
    position: relative;
}

.event-loot-crate.expired .loot-crate-icon::after {
    content: "❌";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    opacity: 0.9;
}

/* Claimed state */
.event-loot-crate.claimed .loot-crate-card {
    opacity: 0.5;
    border-color: #333;
}

.event-loot-crate.claimed .loot-crate-action button {
    background: #22c55e !important;
    border-color: #16a34a !important;
    color: white !important;
    cursor: default;
}

.event-loot-crate.claimed .loot-crate-timer,
.event-loot-crate.claimed .loot-crate-countdown {
    display: none;
}

.event-loot-crate.claimed .loot-crate-icon {
    animation: none;
    position: relative;
}

.event-loot-crate.claimed .loot-crate-icon::after {
    content: "❌";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    opacity: 0.9;
}

/* Shared Event Card Styles */
.event-card {
    width: 100%;
    background: #222;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    overflow: hidden;
}

.event-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.event-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.event-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #e5e7eb;
}

.event-phrase {
    font-size: 0.95rem;
    color: #c4b5fd;
    font-weight: 600;
    font-family: monospace;
}

.event-reward {
    font-size: 0.75rem;
    color: #9ca3af;
}

.event-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
    flex-shrink: 0;
}

/* Horizontal row layout for event actions */
.event-right.event-right-row {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
}

.event-timer-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.15rem;
}

.event-countdown {
    font-size: 0.75rem;
    color: #9ca3af;
}

.event-timer {
    width: 80px;
    height: 3px;
    background: #333;
    border-radius: 2px;
    overflow: hidden;
}

/* Speed Type wrapper */
.event-speed-type {
    width: 100%;
    padding: 0;
    margin: 0.5rem 0;
    background: transparent;
}

/* Speed Type specific */
.speed-type-card {
    border-color: #8b5cf6;
}

/* Lucky Number wrapper */
.event-lucky-number {
    width: 100%;
    padding: 0;
    margin: 0.5rem 0;
    background: transparent;
}

/* Lucky Number specific */
.lucky-number-card {
    border-color: #f59e0b;
}

/* Expired/Claimed states for new event types */
.event-speed-type.expired .event-card,
.event-speed-type.claimed .event-card,
.event-lucky-number.expired .event-card,
.event-lucky-number.claimed .event-card {
    opacity: 0.5;
    border-color: #333;
}

.event-speed-type.expired .event-timer,
.event-speed-type.expired .event-countdown,
.event-speed-type.claimed .event-timer,
.event-speed-type.claimed .event-countdown,
.event-lucky-number.expired .event-timer,
.event-lucky-number.expired .event-countdown,
.event-lucky-number.claimed .event-timer,
.event-lucky-number.claimed .event-countdown {
    display: none;
}

/* Red X overlay for Speed Type expired/claimed */
.event-speed-type.expired .event-icon,
.event-speed-type.claimed .event-icon {
    position: relative;
}

.event-speed-type.expired .event-icon::after,
.event-speed-type.claimed .event-icon::after {
    content: "❌";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    opacity: 0.9;
}

/* Red X overlay for Lucky Number expired/claimed */
.event-lucky-number.expired .event-icon,
.event-lucky-number.claimed .event-icon {
    position: relative;
}

.event-lucky-number.expired .event-icon::after,
.event-lucky-number.claimed .event-icon::after {
    content: "❌";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    opacity: 0.9;
}

/* System Messages */
.chat-message.system {
    justify-content: center;
}

.message-system {
    color: #9ca3af;
    font-size: 0.875rem;
    text-align: center;
    padding: 0.25rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

/* Action Messages (/me) */
.chat-message.action {
    font-style: italic;
}

.message-action {
    color: #a78bfa;
}

/* Error Messages */
.chat-message.error .message-error {
    color: #f87171;
    font-size: 0.875rem;
    background: rgba(248, 113, 113, 0.1);
    padding: 0.25rem 0.75rem;
    border-radius: 8px;
    border: 1px solid rgba(248, 113, 113, 0.2);
}

/* Input Area */
.chat-input-area {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background: #1a1a1a;
    border-top: 1px solid #333;
    flex-shrink: 0;
    /* Prevent shrinking */
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    /* Safe area */
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    box-sizing: border-box;
    z-index: 50;
}

.chat-input {
    flex: 1;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 0.75rem 1.25rem;
    color: #fff;
    font-size: 0.9375rem;
    font-family: inherit;
    outline: none;
    transition: all 0.2s ease;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    overflow-y: hidden;
    line-height: 1.4;
}

.chat-input::placeholder {
    color: #6b7280;
}

.chat-input:focus {
    border-color: #555;
    background: #252525;
}

.chat-send-btn {
    display: none;
    /* Hidden by default on desktop */
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: #22c55e;
    border: 1px solid #16a34a;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: #16a34a;
    border-color: #15803d;
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn svg {
    margin-left: 2px;
}

/* Mobile: Show send button when there's content */
@media (max-width: 768px) {
    .chat-send-btn {
        display: none;
        /* Still hidden by default */
        width: 0;
        padding: 0;
        border: none;
        overflow: hidden;
        transition: all 0.2s ease;
    }

    .chat-send-btn.has-content {
        display: flex;
        width: 44px;
        padding: 0;
        border: 1px solid #16a34a;
    }
}

/* Emoji Picker Button */
.chat-emoji-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: #333;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-emoji-btn:hover {
    background: #444;
    border-color: #555;
    transform: scale(1.05);
}

/* Emoji Picker Popup */
.emoji-picker {
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 12px;
    padding: 0.75rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 9999;
}

.emoji-picker.hidden {
    display: none;
}

.emoji-picker-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
}

.emoji-option {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.emoji-option:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.2);
}

/* User Profile Card */
.chat-profile-card {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 12px;
    padding: 1.5rem;
    min-width: 320px;
    max-width: 400px;
    z-index: 1000;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.chat-profile-card.hidden {
    display: none;
}

.profile-card-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
}

.profile-card-overlay.hidden {
    display: none;
}

.profile-card-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #333;
}

.profile-card-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #4b5563;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 28px;
    flex-shrink: 0;
}

.profile-card-info {
    flex: 1;
}

.profile-card-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: #e5e7eb;
    margin: 0 0 0.25rem;
}

.profile-card-type {
    font-size: 0.875rem;
    color: #9ca3af;
}

.profile-card-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 1rem;
}

.profile-stat {
    background: #222;
    padding: 0.75rem;
    border-radius: 8px;
    text-align: center;
}

.profile-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #e5e7eb;
    display: block;
}

.profile-stat-label {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.25rem;
    display: block;
}

.profile-card-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    color: #9ca3af;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.profile-card-close:hover {
    color: #e5e7eb;
}

.profile-card-actions {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #333;
}

.profile-view-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    background: #374151;
    border: 1px solid #4b5563;
    border-radius: 8px;
    color: #e5e7eb;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.profile-view-btn:hover {
    background: #4b5563;
    border-color: #6b7280;
}

/* Cosmetic placeholder classes for future customization */
/* .message-name[data-cosmetic-name] - Future: name effects, glow, gradients */
/* .message-avatar[data-cosmetic-avatar] - Future: custom borders, animations */
/* .chat-message[data-cosmetic-bubble] - Future: custom message backgrounds */

/* Mobile Responsive */
@media (max-width: 640px) {
    .chat-page {
        padding: 0;
        height: 100%;
        overflow: hidden;
    }

    .chat-container {
        border-radius: 0;
        border: none;
        height: 100%;
        max-height: 100%;
        overflow: hidden;
    }

    .chat-header {
        padding: 0.875rem 1rem;
    }

    .chat-title {
        font-size: 1.125rem;
    }

    .chat-input-area {
        padding: 0.75rem 1rem;
    }

    .chat-input {
        padding: 0.75rem 1rem;
        font-size: 1rem;
        min-height: 46px;
        display: flex;
        align-items: center;
    }

    .chat-profile-card {
        min-width: 90%;
        max-width: 90%;
    }

    .loot-crate-card {
        flex-wrap: wrap;
        position: relative;
    }

    .loot-crate-icon {
        font-size: 1.75rem;
    }

    .loot-crate-countdown {
        position: absolute;
        top: 0.75rem;
        right: 1rem;
        font-size: 0.7rem;
    }

    .loot-crate-right {
        width: 100%;
        align-items: stretch;
        margin-top: 0.5rem;
    }

    .loot-crate-timer {
        width: 100%;
    }

    /* Mobile Fullscreen Toggle Button */
    .mobile-fullscreen-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.15);
        border-radius: 8px;
        color: #e0e0e0;
        cursor: pointer;
        transition: all 0.2s;
        margin-left: auto;
        margin-right: 8px;
    }

    .mobile-fullscreen-toggle:hover {
        background: rgba(6, 182, 212, 0.2);
        border-color: rgba(6, 182, 212, 0.4);
        color: var(--accent-cyan);
    }

    /* Fullscreen Mode */
    .chat-page.fullscreen {
        position: fixed;
        top: 56px;
        /* Offset for topbar */
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        padding: 0;
        margin: 0;
    }

    .chat-page.fullscreen .chat-container {
        height: 100%;
        /* Fill remaining space */
        max-height: 100%;
        border-radius: 0;
        border: none;
    }

    .chat-page.fullscreen .chat-sidebar {
        display: none;
    }
}

/* Scrollbar for mobile */
@supports (-webkit-touch-callout: none) {
    .chat-messages {
        -webkit-overflow-scrolling: touch;
    }
}

/* Chat Links */
.chat-link {
    color: #60a5fa;
    /* Blue-400 */
    text-decoration: none;
    cursor: pointer;
}

.chat-link:hover {
    text-decoration: underline;
    color: #3b82f6;
    /* Blue-500 */
}

/* Chat Particles */
.chat-particle {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    position: fixed;
    pointer-events: none;
    z-index: 9999;
}

.loot-claim-btn.success {
    background: #22c55e;
    border-color: #16a34a;
    color: white;
}

/* Chat Body - Flex container for messages and sidebar */
/* Chat Layout Row - Wrapper for Main Column + Sidebar */
.chat-layout-row {
    display: flex;
    flex-direction: row;
    flex: 1;
    height: 100%;
    min-height: 0;
    /* Important for nested flex scrolling */
    overflow: hidden;
}

.chat-main-column {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
    /* Critical for flex scrolling */
    height: 100%;
    position: relative;
    /* Anchor for absolute input */
}

/* Chat Body - Fallback/Legacy if needed, but replaced by layout-row logic */
.chat-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Chat Sidebar */
.chat-sidebar {
    width: 200px;
    min-width: 200px;
    background: #1a1a1a;
    border-left: 1px solid #333;
    display: flex;
    flex-direction: column;
    overflow: visible;
    /* Allows toggle button to float outside if needed, but primarily for collapsed state visibility */
    transition: all 0.2s ease;
    position: relative;
    z-index: 20;
}

.sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    gap: 0;
}

.chat-sidebar .sidebar-header {
    height: 34px;
    padding: 0 8px;
    /* Horizontal padding only */
    border-bottom: 1px solid #2a2a2a;
    background: #1e1e1e;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1;
}

.sidebar-users {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    margin: 0;
    margin-top: -1px;
    /* Visual tweak to ensure no sub-pixel gap */
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}

.sidebar-users::-webkit-scrollbar {
    width: 4px;
}

.sidebar-users::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 2px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 0;
    cursor: pointer;
    transition: background 0.1s;
}

.sidebar-user:hover {
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-user.typing {
    background: rgba(139, 92, 246, 0.1);
}

.sidebar-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #4b5563;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 10px;
    flex-shrink: 0;
}

.sidebar-avatar.guest {
    background: #374151;
    color: #9ca3af;
}

.sidebar-username {
    font-size: 0.8rem;
    color: #e5e7eb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    line-height: 1.2;
}

.sidebar-username.guest {
    color: #6b7280;
}

.sidebar-loading,
.sidebar-empty {
    font-size: 0.75rem;
    color: #6b7280;
    text-align: center;
    padding: 0.5rem;
}

/* Typing Dots Animation */
.typing-dots {
    display: inline-flex;
    gap: 2px;
    margin-left: auto;
    color: #8b5cf6;
}

.typing-dots span {
    animation: typingDot 1.4s infinite ease-in-out;
    font-weight: bold;
}

.typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDot {

    0%,
    60%,
    100% {
        opacity: 0.3;
    }

    30% {
        opacity: 1;
    }
}

/* Typing Status at Bottom */
.sidebar-typing {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid #333;
    min-height: 0;
}

.sidebar-typing:empty {
    display: none;
}

.typing-status {
    font-size: 0.75rem;
    color: #8b5cf6;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Toggle Button - Default State (Inside Header) */
.sidebar-toggle {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: transparent;
    border: 1px solid transparent;
    color: #777;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 4px;
    padding: 0;
    z-index: 30;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.sidebar-toggle svg {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: 14px;
    height: 14px;
}

/* Collapsed State - Zero Width, No Border, Transparent */
.chat-sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    border: none !important;
    background: transparent !important;
    overflow: visible !important;
}

.chat-sidebar.collapsed .sidebar-content {
    display: none !important;
}

.chat-sidebar.collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

/* Floating Toggle Button when Collapsed */
.chat-sidebar.collapsed .sidebar-toggle {
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    background: #2a2a2a;
    border: 1px solid #444;
    color: #aaa;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    border-radius: 50%;
    /* Circle for modern feel */
}

.chat-sidebar.collapsed .sidebar-toggle:hover {
    background: #333;
    border-color: #666;
    color: #fff;
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

/* Mobile User List Toggle */
.mobile-users-toggle {
    display: none;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    background: #333;
    border: 1px solid #444;
    border-radius: 6px;
    color: #9ca3af;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mobile-users-toggle:hover {
    background: #3a3a3a;
    color: #e5e7eb;
}

.mobile-users-toggle svg {
    transition: transform 0.2s ease;
}

.mobile-users-toggle.open svg {
    transform: rotate(180deg);
}

.mobile-users-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    width: 200px;
    max-height: 300px;
    overflow-y: auto;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 100;
    margin-top: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: #444 transparent;
}

.mobile-users-dropdown.open {
    display: block;
}

.mobile-users-dropdown .sidebar-user {
    padding: 0.5rem 0.75rem;
}

.mobile-users-dropdown .sidebar-user:first-child {
    margin-top: 0.25rem;
}

.mobile-users-dropdown .sidebar-user:last-child {
    margin-bottom: 0.25rem;
}

/* Mobile: Hide desktop sidebar, show mobile toggle */
@media (max-width: 768px) {
    .chat-page {
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        padding: 0;
        margin: 0;
    }

    .chat-sidebar {
        display: none;
    }

    /* chat-layout-row handles flex direction, sidebar hidden so main column takes full width */

    .mobile-users-toggle {
        display: flex;
    }

    .chat-container {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: auto;
        max-height: none;
        width: 100%;
        margin: 0;
        border-radius: 0;
        border: none;
    }

    .chat-input-area {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 2000;
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
        /* Raised up */
    }

    .chat-messages {
        padding-bottom: calc(160px + env(safe-area-inset-bottom));
        /* Ensure content clears fixed input */
    }

    .chat-header {
        justify-content: space-between;
        position: relative;
    }
}