/* ============================================================
   Dark Grid Arcade – Chat Widget & Chat Page
   ============================================================ */

.chat-widget {
    position: fixed;
    bottom: var(--space-lg, 24px);
    right: var(--space-lg, 24px);
    z-index: var(--z-modal, 1050);
}

.chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary, #00d9ff), var(--color-secondary, #6c5ce7));
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-glow, 0 0 20px rgba(0,217,255,0.3));
    transition: transform var(--transition-fast, 0.15s), box-shadow 0.3s;
    position: relative;
}

.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 0 30px rgba(0,217,255,0.5);
}

.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ff4757;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid var(--bg-primary, #0f0f1a);
    line-height: 1;
}

.chat-window {
    display: none;
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 380px;
    max-height: 500px;
    background: var(--bg-card, #1a1a2e);
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    border-radius: var(--radius-xl, 16px);
    box-shadow: var(--shadow-lg, 0 20px 60px rgba(0,0,0,0.5));
    overflow: hidden;
    flex-direction: column;
}

.chat-window.open {
    display: flex;
    animation: chatSlideUp 0.25s ease-out;
}

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

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md, 12px) var(--space-lg, 16px);
    background: var(--bg-surface, #16162a);
    border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.1));
    font-weight: 700;
    color: var(--text-primary, #e0e0e0);
    font-size: 0.95rem;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-actions button,
.chat-header-actions a {
    background: none;
    border: none;
    color: var(--text-muted, #888);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px;
    text-decoration: none;
    line-height: 1;
    transition: color 0.2s;
}

.chat-header-actions button:hover,
.chat-header-actions a:hover {
    color: var(--color-primary, #00d9ff);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md, 12px);
    max-height: 340px;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm, 8px);
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

.chat-empty {
    text-align: center;
    color: var(--text-muted, #888);
    padding: 2rem 1rem;
    font-size: 0.9rem;
    opacity: 0.7;
}

.chat-msg {
    max-width: 82%;
    padding: 8px 14px;
    border-radius: var(--radius-lg, 12px);
    font-size: var(--text-sm, 0.875rem);
    line-height: 1.5;
    animation: msgFade 0.2s ease-out;
}

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

.chat-msg.outgoing {
    align-self: flex-end;
    background: var(--color-primary, #00d9ff);
    color: #0a0a14;
    border-bottom-right-radius: 4px;
}

.chat-msg.incoming {
    align-self: flex-start;
    background: var(--bg-surface, #16162a);
    color: var(--text-primary, #e0e0e0);
    border-bottom-left-radius: 4px;
}

.chat-msg .chat-author {
    font-size: var(--text-xs, 0.75rem);
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--color-primary, #00d9ff);
}

.chat-msg.outgoing .chat-author { color: rgba(0,0,0,0.6); }

.chat-msg .chat-text {
    word-break: break-word;
}

.chat-msg .chat-time {
    font-size: 0.65rem;
    opacity: 0.5;
    margin-top: 2px;
    text-align: right;
}

.chat-msg.outgoing .chat-time { color: rgba(0,0,0,0.4); }

.chat-input {
    display: flex;
    align-items: center;
    gap: var(--space-sm, 8px);
    padding: var(--space-md, 12px);
    border-top: 1px solid var(--border-color, rgba(255,255,255,0.1));
    background: var(--bg-surface, #16162a);
}

.chat-input input {
    flex: 1;
    padding: 8px 14px;
    background: var(--bg-input, rgba(0,0,0,0.3));
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    border-radius: var(--radius-full, 50px);
    color: var(--text-primary, #e0e0e0);
    font-size: var(--text-sm, 0.875rem);
    outline: none;
    transition: border-color 0.2s;
}

.chat-input input:focus {
    border-color: var(--color-primary, #00d9ff);
}

.chat-input input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-input button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-primary, #00d9ff);
    border: none;
    color: #0a0a14;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: transform var(--transition-fast, 0.15s);
    flex-shrink: 0;
}

.chat-input button:hover {
    transform: scale(1.1);
}

/* ============================================================
   Chat Full Page
   ============================================================ */

.chat-page {
    max-width: 960px;
    margin: 0 auto;
    padding: var(--space-xl, 32px) var(--space-lg, 16px);
}

.chat-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xl, 32px);
}

.chat-page-header h1 {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-primary, #e0e0e0);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-page-header .chat-online-count {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-primary, #00d9ff);
    background: rgba(0,217,255,0.1);
    padding: 4px 12px;
    border-radius: var(--radius-full, 50px);
}

.chat-page-container {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: var(--space-lg, 16px);
    height: calc(100vh - 220px);
    min-height: 500px;
}

.chat-main {
    background: var(--bg-card, #1a1a2e);
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    border-radius: var(--radius-xl, 16px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-main .chat-messages-full {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg, 16px);
    display: flex;
    flex-direction: column;
    gap: var(--space-md, 12px);
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.chat-main .chat-input-full {
    display: flex;
    align-items: center;
    gap: var(--space-md, 12px);
    padding: var(--space-lg, 16px);
    border-top: 1px solid var(--border-color, rgba(255,255,255,0.1));
    background: var(--bg-surface, #16162a);
}

.chat-input-full input {
    flex: 1;
    padding: 12px 18px;
    background: var(--bg-input, rgba(0,0,0,0.3));
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    border-radius: var(--radius-full, 50px);
    color: var(--text-primary, #e0e0e0);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input-full input:focus {
    border-color: var(--color-primary, #00d9ff);
}

.chat-input-full button {
    padding: 10px 24px;
    background: var(--color-primary, #00d9ff);
    border: none;
    border-radius: var(--radius-full, 50px);
    color: #0a0a14;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    transition: transform 0.15s, box-shadow 0.3s;
    white-space: nowrap;
}

.chat-input-full button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(0,217,255,0.3);
}

/* Full page message variant */
.chat-msg-full {
    display: flex;
    gap: 12px;
    animation: msgFade 0.2s ease-out;
}

.chat-msg-full.is-own {
    flex-direction: row-reverse;
}

.chat-avatar-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary, #00d9ff), var(--color-secondary, #6c5ce7));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #0a0a14;
    flex-shrink: 0;
}

.chat-msg-body {
    max-width: 65%;
}

.chat-msg-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.chat-msg-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-primary, #00d9ff);
}

.chat-msg-timestamp {
    font-size: 0.75rem;
    color: var(--text-muted, #888);
}

.chat-msg-bubble {
    padding: 10px 16px;
    border-radius: 12px;
    border-top-left-radius: 4px;
    background: var(--bg-surface, #16162a);
    color: var(--text-primary, #e0e0e0);
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
}

.chat-msg-full.is-own .chat-msg-bubble {
    background: var(--color-primary, #00d9ff);
    color: #0a0a14;
    border-top-left-radius: 12px;
    border-top-right-radius: 4px;
}

.chat-msg-full.is-own .chat-msg-name {
    color: var(--text-muted, #888);
}

.chat-msg-full.is-own .chat-msg-meta {
    flex-direction: row-reverse;
}

/* Sidebar: Online Users */
.chat-sidebar {
    background: var(--bg-card, #1a1a2e);
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    border-radius: var(--radius-xl, 16px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-sidebar-header {
    padding: var(--space-md, 12px) var(--space-lg, 16px);
    border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.1));
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary, #e0e0e0);
}

.chat-online-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm, 8px);
}

.chat-online-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-md, 8px);
    transition: background 0.2s;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-primary, #e0e0e0);
}

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

.online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ed573;
    flex-shrink: 0;
}

.chat-online-name {
    font-size: 0.85rem;
    font-weight: 500;
}

.chat-login-prompt {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted, #888);
}

.chat-login-prompt p {
    margin-bottom: 1rem;
    font-size: 1rem;
}

.chat-login-prompt .btn-primary {
    display: inline-block;
    padding: 10px 24px;
    background: var(--color-primary, #00d9ff);
    color: #0a0a14;
    border-radius: var(--radius-full, 50px);
    text-decoration: none;
    font-weight: 700;
    transition: transform 0.15s;
}

.chat-login-prompt .btn-primary:hover {
    transform: translateY(-2px);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
    .chat-page-container {
        grid-template-columns: 1fr;
        height: calc(100vh - 180px);
    }

    .chat-sidebar {
        display: none;
    }

    .chat-window {
        width: calc(100vw - 32px);
        right: -8px;
        max-height: 60vh;
    }

    .chat-msg-body { max-width: 80%; }
}

@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 16px);
        right: -4px;
        bottom: 64px;
    }

    .chat-widget {
        bottom: 16px;
        right: 16px;
    }
}
