/* ================================================================
   Full-page chat app (Pages/Chat.razor), ported from the Dashboard's
   Pages/Chat.razor.css.

   Every selector is SCOPED under .chat-page-container (the page's root
   element). The Dashboard shipped these rules globally, which is safe there
   because chat is most of that app — but in the portal 16 of the 41 class
   names already exist (.chat-input, .people-list, .connection-status, .dot …),
   some in map.css and some in unrelated pages such as AdminTax and Alerts.
   Unscoped, this file would restyle them.

   Keyframe bodies are left alone; only rule selectors are prefixed.
   ================================================================ */

﻿/* Main container */
/* ⚠ min-height: 0 on every link in this flex chain, or the input will not stay at the bottom.

   A flex child defaults to min-height:auto, which means it REFUSES to shrink below its own
   content. A chat window taller than the viewport therefore grows instead of scrolling, and the
   input bar - correctly flex:0 0 auto - ends up below the fold, at the bottom of the CONVERSATION
   rather than at the bottom of the PAGE. .chat-content and .chat-messages already had it; the two
   containers around them did not, which was enough to break the whole chain. */
.chat-page-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
    min-height: 0; /* see the note above */
    flex: 1; /* Take up all available space */
}

/* And update chat-header to account for MainLayout's top-row */
.chat-page-container .chat-header {
    flex: 0 0 60px;
    background-color: #2c3e50;
    color: white;
    display: flex;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Main content area with split view */
.chat-page-container .chat-content {
    flex: 1;
    display: flex;
    min-height: 0; /* Important for flex child */
}

/* Left sidebar - people list */
.chat-page-container .people-sidebar {
    flex: 0 0 300px;
    border-right: 1px solid #e1e4e8;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Search bar */
.chat-page-container .search-container {
    padding: 10px;
    border-bottom: 1px solid #e1e4e8;
}

.chat-page-container .search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* People list */
.chat-page-container .people-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    margin: 0;
    list-style-type: none;
}

.chat-page-container .person-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #f1f1f1;
    cursor: pointer;
    transition: background-color 0.2s;
}

.chat-page-container .person-item:hover {
        background-color: #f9f9f9;
    }

.chat-page-container .person-item.active {
        background-color: #e6f7ff;
        border-right: 3px solid #1890ff;
    }

.chat-page-container .person-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #1890ff;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-right: 12px;
    flex-shrink: 0;
}

.chat-page-container .person-info {
    flex: 1;
    min-width: 0;
}

.chat-page-container .person-name {
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-page-container .message-preview {
    font-size: 0.85rem;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-page-container .message-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 45px;
}

.chat-page-container .message-time {
    font-size: 0.75rem;
    color: #999;
    margin-bottom: 5px;
}

.chat-page-container .message-badge {
    background-color: #1890ff;
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.chat-page-container .person-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 10px;
}

.chat-page-container .status-online {
    background-color: #52c41a;
}

.chat-page-container .status-offline {
    background-color: #d9d9d9;
}

.chat-page-container .status-sos {
    background-color: #f5222d;
}

/* Right side - chat window */
.chat-page-container .chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #f7f9fa;
    height: 100%; /* Ensure it takes full height */
    min-height: 0; /* without this the window grows and pushes the input off-screen */
}

.chat-page-container .chat-window-header {
    flex: 0 0 60px; /* Fixed height, won't grow or shrink */
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid #e1e4e8;
    background-color: white;
    z-index: 1; /* Keep header above scrollable content */
}

.chat-page-container .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    min-height: 0; /* Critical for proper scrolling in flex container */
}

/* Helper class to auto-scroll to bottom */
.chat-page-container .scroll-to-bottom {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    max-height: 100%;
    scroll-behavior: smooth;
}

.chat-page-container .scroll-to-bottom:after {
        content: "";
        height: 1px;
        margin-top: auto;
    }

.chat-page-container .message {
    max-width: 70%;
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 18px;
    position: relative;
    word-break: break-word;
}

.chat-page-container .message-received {
    align-self: flex-start;
    background-color: white;
    border: 1px solid #e1e4e8;
    border-bottom-left-radius: 4px;
}

.chat-page-container .message-sent {
    align-self: flex-end;
    background-color: #1890ff;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-page-container .message-time-stamp {
    font-size: 0.7rem;
    color: #999;
    margin-top: 5px;
    text-align: right;
}

.chat-page-container .message-received .message-time-stamp {
    text-align: left;
}

.chat-page-container .chat-input {
    flex: 0 0 auto; /* This prevents the input from shrinking */
    display: flex;
    padding: 15px;
    background-color: white;
    border-top: 1px solid #e1e4e8;
    z-index: 1; /* Keep input above scrollable content */
}

.chat-page-container .message-input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    resize: none;
    max-height: 120px; /* Limit the height of textarea */
    min-height: 44px; /* Match the send button height */
}

/* Send button styling */
.chat-page-container .send-button {
    margin-left: 10px;
    background-color: #1890ff;
    color: white;
    border: none;
    border-radius: 50%; /* Make it circular */
    width: 44px; /* Fixed width */
    height: 44px; /* Fixed height */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 0; /* Remove padding */
}

.chat-page-container .send-button:hover {
        background-color: #40a9ff;
    }

.chat-page-container .send-button:disabled {
        background-color: #d9d9d9;
        cursor: not-allowed;
    }

.chat-page-container .send-button svg {
        color: white; /* Ensure icon is white */
    }

.chat-page-container .empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #999;
    padding: 20px;
    text-align: center;
}

.chat-page-container .empty-icon {
    font-size: 4rem;
    margin-bottom: 20px;
}

.chat-page-container .connection-status {
    display: flex;
    align-items: center;
    margin-left: auto;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.chat-page-container .connection-status .indicator {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        margin-right: 5px;
    }

.chat-page-container .connected .indicator {
    background-color: #52c41a;
}

.chat-page-container .disconnected .indicator {
    background-color: #f5222d;
}

/* Loading indicator */
.chat-page-container .loading-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.chat-page-container .loading-dots {
    display: flex;
}

.chat-page-container .dot {
    width: 10px;
    height: 10px;
    margin: 0 5px;
    border-radius: 50%;
    background-color: #1890ff;
}

/* Message date separator */
.chat-page-container .message-date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0;
}

.chat-page-container .message-date-separator span {
        background-color: #f1f1f1;
        padding: 5px 10px;
        border-radius: 15px;
        font-size: 0.75rem;
        color: #666;
    }

.chat-page-container .message-content {
    word-break: break-word;
}

/* Latest message styling - helps with auto-scrolling */
.chat-page-container .latest-message {
    scroll-margin-bottom: 20px;
}

/* Make sure new messages come into view */
@keyframes highlight-new {
    0% {
        background-color: rgba(24, 144, 255, 0.1);
    }

    100% {
        background-color: transparent;
    }
}

.chat-page-container .latest-message {
    animation: highlight-new 1.5s ease-out;
}
