/* Chat Bubble */
.chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    background-color: var(--primary);
    border-radius: 50%;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255,255,255,0.1);
}

.chat-bubble:hover {
    transform: scale(1.1);
    background-color: var(--primary-hover);
}

.chat-bubble svg {
    width: 32px;
    height: 32px;
    fill: #fff;
}

/* Chat Window */
.chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 320px;
    height: 480px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    overflow: hidden;
    display: none; /* Hidden by default */
}

.chat-window.open {
    display: flex;
}

.chat-header {
    background-color: var(--bg-surface-2);
    color: var(--text-main);
    padding: 1rem;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.chat-header .close-btn {
    cursor: pointer;
    background: none;
    border: none;
    font-size: 1.5rem;
    font-weight: 400;
    padding: 0 0.5rem;
    line-height: 1;
    color: var(--text-muted);
    transition: color 0.2s;
}

.chat-header .close-btn:hover {
    color: var(--text-main);
}

.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--bg-surface);
}

.message {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    word-wrap: break-word;
    line-height: 1.4;
}

.message.sent {
    align-self: flex-end;
    background-color: var(--primary);
    color: #fff;
    border-bottom-right-radius: 2px;
}

.message.received {
    align-self: flex-start;
    background-color: var(--bg-surface-2);
    color: var(--text-main);
    border-bottom-left-radius: 2px;
}

.message .sender {
    font-size: 0.75rem;
    opacity: 0.8;
    margin-bottom: 0.25rem;
    display: block;
    font-weight: 500;
}

.chat-input-area {
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    background-color: var(--bg-surface);
}

.chat-input-area input {
    flex: 1;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background-color: var(--bg-body);
    color: var(--text-main);
}

.chat-input-area input:focus {
    border-color: var(--primary);
}

.chat-input-area button {
    padding: 0.75rem 1rem;
    background-color: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s;
}

.chat-input-area button:hover {
    background-color: var(--primary-hover);
}

/* Name prompt overlay */
.chat-name-prompt {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 2rem;
    text-align: center;
    backdrop-filter: blur(4px);
}

.chat-name-prompt h3 {
    margin-top: 0;
    color: var(--text-main);
}

.chat-name-prompt input {
    margin: 1rem 0;
    padding: 0.75rem;
    width: 100%;
    max-width: 200px;
}

/* Admin Sessions List (Moved from inline) */
.chat-sessions-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.session-card {
    background: var(--bg-surface-2);
    padding: 1rem;
    border: 1px solid var(--border);
    cursor: pointer;
    border-radius: var(--radius-md);
    position: relative;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.session-card:hover {
    background: #475569; /* Slightly lighter */
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.session-card h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.session-card p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-card .unread-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    border: 2px solid var(--bg-body);
}


/* Admin Floating Windows */
.admin-chat-container {
    position: fixed;
    bottom: 0;
    right: 0;
    display: flex;
    flex-direction: row-reverse;
    gap: 1rem;
    padding: 1rem;
    pointer-events: none; /* Let clicks pass through empty space */
    z-index: 2000;
}

.admin-chat-window {
    width: 320px;
    height: 400px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
}

.admin-chat-window .chat-header {
    background-color: var(--bg-surface-2);
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.admin-chat-window .chat-header.has-unread {
    background-color: var(--danger);
    color: #fff;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    /* Listener Chat Window */
    .chat-window {
        width: 100%;
        height: 60vh;
        right: 0;
        bottom: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
    }
    
    .chat-bubble {
        bottom: 16px;
        right: 16px;
    }

    /* Admin Chat Windows */
    .admin-chat-container {
        width: 100%;
        padding: 0;
        right: 0;
        bottom: 0;
        flex-direction: column;
    }

    .admin-chat-window {
        width: 100%;
        height: 60vh; /* Taller on mobile for better usability */
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
    }

    .chat-input-area input, 
    .chat-input-area button {
        font-size: 16px; /* Prevent iOS zoom */
        padding: 12px;
    }
    
    .chat-messages {
        font-size: 16px; /* Better readability */
    }
}

/* Mobile Optimization */
@media (max-width: 640px) {
    .chat-bubble {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
    }
    
    .chat-bubble svg {
        width: 28px;
        height: 28px;
    }

    .chat-window {
        bottom: 90px;
        right: 20px;
        left: 20px; /* Stretch across */
        width: auto;
        height: 50vh; /* Fixed percentage of screen height */
        max-height: 500px;
    }
}

