/* Chat Container Layout */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 300px);
    min-height: 400px;
    gap: 8px;
}

/* Input Row */
.chat-input-row {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 8px;
    background: #f8f8f8;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.chat-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 14px;
    font-family: inherit;
}

.chat-input:focus {
    outline: 2px solid #4a90e2;
    border-color: #4a90e2;
}

.chat-btn {
    padding: 8px 14px;
    border: 1px solid #999;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.chat-btn:hover {
    background: #e8e8e8;
}

.chat-btn:active {
    background: #d0d0d0;
}

.chat-send-btn {
    background: #4a90e2;
    color: white;
    border-color: #3a7bc8;
    font-weight: bold;
}

.chat-send-btn:hover {
    background: #3a7bc8;
}

.chat-send-btn:active {
    background: #2a6bb8;
}

/* Status Indicator (4px dot) */
.chat-status-indicator {
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #ccc;
    margin-left: 4px;
    flex-shrink: 0;
}

.chat-status-indicator.blue-light {
    background: #7ec8ff;
}

.chat-status-indicator.blue {
    background: #4a90e2;
}

.chat-status-indicator.yellow-light {
    background: #ffe066;
}

.chat-status-indicator.yellow {
    background: #ffc107;
}

.chat-status-indicator.red-light {
    background: #ff9999;
}

.chat-status-indicator.red {
    background: #e74c3c;
}

/* Content Row (Messages + User List) */
.chat-content-row {
    display: flex;
    flex: 1;
    gap: 8px;
    overflow: hidden;
}

.chat-messages-col {
    flex: 1;
    overflow-y: auto;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
}

.chat-users-col {
    width: 200px;
    overflow-y: auto;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    flex-shrink: 0;
}

/* Chat Messages Table */
.chat-messages-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.chat-messages-table tbody tr {
    border-bottom: 1px solid #eee;
}

/* Alternating row colors for chat messages */
.chat-messages-table tbody tr:nth-child(odd) {
    background: #fafafa;
}

.chat-messages-table tbody tr:nth-child(even) {
    background: #ffffff;
}

.chat-messages-table td {
    padding: 6px 8px;
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Column widths for message table — fixed via <col> so colspan rows don't shift layout */
.chat-col-time    { width: 150px!important; }
.chat-col-user    { width: 120px!important; }
.chat-col-message { width: auto; }

.chat-messages-table td:nth-child(1) {
    font-size: 11px;
    color: #666;
}

.chat-messages-table td:nth-child(2) {
    font-weight: bold;
}

.chat-messages-table td:nth-child(3) {
}

/* No messages placeholder */
.chat-no-messages {
    text-align: center;
    color: #999;
    font-style: italic;
    padding: 20px !important;
}

/* /me message styling (merged columns) */
.chat-messages-table tr.me-message td {
    font-style: italic;
    color: #555;
}

.chat-messages-table tr.me-message td:nth-child(2),
.chat-messages-table tr.me-message td:nth-child(3) {
    font-weight: normal;
}

/* Deleted message styling */
.chat-messages-table tr.deleted-message td:nth-child(3) {
    font-style: italic;
    color: #999;
}

/* Shadow-banned message styling (visible only to poster/admins/mods) */
.chat-messages-table tr.shadow-message {
    opacity: 0.6;
}

.chat-messages-table tr.shadow-message td:nth-child(2)::after {
    content: " 👻";
    font-size: 10px;
}

/* User List */
.chat-user-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chat-user-list li {
    padding: 8px 12px;
    border-bottom: 1px solid #eee;
    cursor: default;
}

/* Alternating row colors for user list (different color pair) */
.chat-user-list li:nth-child(odd) {
    background: #f0f8ff;
}

.chat-user-list li:nth-child(even) {
    background: #e6f2ff;
}

/* Admin users: bold + blue */
.chat-user-list li.admin {
    font-weight: bold;
    color: #0066cc;
}

/* Moderators: bold */
.chat-user-list li.moderator {
    font-weight: bold;
}

/* Shadow-banned users: italic (visible only to admins/mods) */
.chat-user-list li.shadow-banned {
    font-style: italic;
    opacity: 0.7;
}

.chat-user-list li.shadow-banned::after {
    content: " 👻";
    font-size: 11px;
}

/* Popup Overlay */
.chat-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.chat-popup {
    background: white;
    border: 2px solid #333;
    border-radius: 6px;
    padding: 16px;
    max-width: 90%;
    max-height: 90%;
    overflow: auto;
    position: relative;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.chat-popup-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 3px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    font-weight: bold;
}

.chat-popup-close:hover {
    background: #c0392b;
}

/* Emoji Grid */
.chat-emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 8px;
}

.chat-emoji-btn-item {
    font-size: 24px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-emoji-btn-item:hover {
    background: #f0f0f0;
}

/* Gift/Command Shortcut List */
.chat-gift-list {
    list-style: none;
    margin: 0;
    padding: 8px;
}

.chat-gift-list li {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-gift-list li:hover {
    background: #f0f0f0;
}

.chat-gift-list li:last-child {
    border-bottom: none;
}

.chat-gift-cmd {
    font-weight: bold;
    color: #4a90e2;
}

.chat-gift-desc {
    font-size: 12px;
    color: #666;
    margin-left: 8px;
}

/* Desktop-only / Mobile-only visibility helpers */
.chat-desktop-only { display: inline-flex; }
.chat-mobile-only  { display: none; }

/* Users-list toggle button (fixed, bottom-right) */
.chat-users-toggle-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 20px;
    padding: 0;
    background: #4a90e2;
    color: white;
    border-color: #3a7bc8;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Floating user list panel */
.chat-users-floating {
    position: fixed;
    top: 60px;
    right: 12px;
    z-index: 200;
    width: 200px;
    max-height: 60vh;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.chat-users-floating[hidden] { display: none; }

.chat-users-floating-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: #f0f8ff;
    border-bottom: 1px solid #ccc;
    font-weight: bold;
    font-size: 13px;
}

/* Timestamp bubble (shown on message click in mobile mode) */
.chat-timestamp-bubble {
    position: fixed;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    pointer-events: none;
    z-index: 300;
    white-space: nowrap;
    animation: chat-bubble-fade 2.5s ease forwards;
}

@keyframes chat-bubble-fade {
    0%   { opacity: 1; }
    60%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ── Mobile layout (≤ 1300px) ── */
@media (max-width: 1300px) {
    .chat-desktop-only { display: none !important; }
    .chat-mobile-only  { display: inline-flex !important; }

    /* Shrink input so buttons stay visible; buttons share remaining space equally */
    .chat-input {
        flex: 0 1 55%;
        min-width: 0;
    }

    .chat-mobile-only.chat-btn,
    .chat-send-btn {
        flex: 1 1 0;
        min-width: 0;
        padding-left: 4px;
        padding-right: 4px;
    }

    /* Hide sidebar user list — replaced by floating panel */
    .chat-users-col { display: none !important; }

    /* Hide time column cells */
    .chat-col-time { display: none !important; }
    .chat-messages-table td:nth-child(1) { display: none !important; }

    /* Send button: show arrow icon */
    .chat-send-btn { font-size: 18px; }

    /* Mobile message format: single-cell "username: message" */
    .chat-messages-table.chat-mobile-mode .chat-col-user { display: none !important; }
    .chat-messages-table.chat-mobile-mode td:nth-child(2) { display: none !important; }
}
