/* Custom styles for ChatJemee */

/* Layout */
body {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Tech Support (and other simple pages): normal flow, breadcrumb on top */
body.tech-support-page {
    height: auto;
    min-height: 100vh;
}
body.tech-support-page main.tech-support-main {
    display: block;
    flex: none;
    overflow: visible;
    min-height: 0;
    width: 100%;
    max-width: 100%;
}
body.tech-support-page .tech-support-breadcrumb {
    width: 100%;
    margin-bottom: var(--pico-spacing);
}
body.tech-support-page .tech-support-breadcrumb ul {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
}

main.container {
    flex: 1;
    min-height: 0; /* Allow shrinking so content doesn't push input off screen */
    overflow: hidden;
    max-width: none;
}

main > .grid {
    height: 100%;
    min-height: 0; /* Allow grid to shrink so chat area doesn't push input off */
    grid-template-rows: 1fr;
}

.sidebar-left {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.logout-section {
    margin-top: auto;
}

.chat-area {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0; /* Allow shrinking so input stays visible */
    padding: 0;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* Crucial for flexbox scrolling bug */
    display: flex;
    flex-direction: column;
    gap: 0; /* Removed gap */
    padding: var(--pico-spacing); /* Add padding here */
}

/* Main chat input: always visible at bottom, sticky; modal stays on top when open */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: var(--pico-spacing);
    padding: var(--pico-spacing);
    border-top: 1px solid var(--pico-card-border-color);
    background: var(--pico-background-color);
    flex-shrink: 0; /* Never shrink or get pushed out */
    position: sticky;
    bottom: 0;
    z-index: 1; /* Below dialogs (e.g. private message modal) */
}

#message-input {
    flex: 1; /* Allow the input to grow and fill space */
    margin-bottom: 0; /* Override PicoCSS default margin */
}

.sidebar-right {
    display: flex; /* Use flexbox for layout */
    flex-direction: column; /* Stack children vertically */
    height: 100%;
}

.sidebar-right .user-list {
    height: 100%;
    overflow-y: auto; /* Allow sidebar to scroll if content overflows */
}

/* User List Avatar */
.user-list li {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--pico-border-radius);
    transition: background-color 0.2s ease;
    position: relative; /* Needed for positioning the unread indicator */
}

.user-list li:hover {
    background-color: var(--pico-muted-background-color);
}

.unread-indicator {
    position: absolute;
    left: 0; /* Position to the left of the avatar */
    top: 0; /* Position to the top of the avatar */
    width: 20px; /* Make it a circle */
    height: 20px;
    background-color: rgba(255,0,0,1) !important;
    color: white;
    font-size: 11px;
    font-weight: bold;
    border-radius: 50%;
    border: 2px solid var(--pico-card-background-color);
    display: none; /* Hidden by default */
    /* Use flexbox to center the number inside */
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}

.total-unread-indicator {
    position: absolute;
    top: 2px; /* Fine-tune position */
    right: 2px; /* Fine-tune position */
    background-color: rgba(255,0,0,1) !important; /* Use !important to override any conflicting styles */
    color: white;
    font-size: 10px;
    font-weight: bold;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    border: 2px solid var(--pico-primary-background-color);
    box-shadow: 0 0 5px rgba(0,0,0,0.3);
}

/* Header for the User List Pane */
.user-list-header {
    padding: var(--pico-spacing);
    font-weight: bold;
    border-bottom: 1px solid var(--pico-card-border-color);
    background-color: var(--pico-background-color);
    text-align: center;
}

/* Positioning fix for the unread indicator on the Users button */
/* This needs to apply to the button in both desktop and mobile nav contexts */
#toggle-right-sidebar,
.mobile-nav #toggle-right-sidebar {
    position: relative; /* This is the anchor for the absolute positioned indicator */
    padding-left: 20px; /* Make the button wider */
    padding-right: 20px; /* Make the button wider */
}

.user-list .user-list-item {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--pico-border-radius);
    transition: background-color 0.2s ease;
    position: relative; /* Needed for positioning the unread indicator */
}

.user-list .user-list-item:hover {
    background-color: var(--pico-muted-background-color);
}

/* PM partners list: name grows, remove button on the right */
#pm-partners-list .pm-partner-item .pm-partner-name {
    flex: 1;
    min-width: 0;
}

#pm-partners-list .pm-partner-remove {
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    margin-left: 0.25rem;
    border: none;
    border-radius: var(--pico-border-radius);
    background: transparent;
    color: var(--pico-muted-color);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease, background-color 0.2s ease;
}

#pm-partners-list .pm-partner-remove:hover {
    color: var(--pico-color);
    background-color: var(--pico-muted-background-color);
}

/* Style for the current user's entry in the list */
.user-list .current-user {
    opacity: 0.7;
    cursor: default;
}
.user-list .current-user:hover {
    background-color: transparent; /* Prevent hover effect */
}

/* Add a separator between the Online and Offline sections */
#offline-section {
    border-top: 1px solid var(--pico-card-border-color);
    margin-top: var(--pico-spacing);
}

/* Channels list (under user list) */
#channels-section {
    border-top: 1px solid var(--pico-card-border-color);
    margin-top: var(--pico-spacing);
}
.channel-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.channel-list-item {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--pico-border-radius);
    transition: background-color 0.2s ease;
    gap: 0.5rem;
}
.channel-list-item:hover {
    background-color: var(--pico-muted-background-color);
}
.channel-list-item.active {
    background-color: var(--pico-primary-background-color);
    color: var(--pico-primary-color);
}
.channel-list-item .channel-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--pico-border-radius);
    object-fit: cover;
    background: var(--pico-muted-background-color);
}
.channel-intro {
    padding: var(--pico-spacing);
    margin-bottom: var(--pico-spacing);
    background: var(--pico-muted-background-color);
    border-radius: var(--pico-border-radius);
    border-left: 6px solid #CC0000;
    background-color: #eec6c6;
}
.channel-intro:empty {
    display: none;
}

/* Style for offline users in the list to appear greyed out */
.user-list .user-offline {
    opacity: 0.6;
    font-style: italic;
}

.user-list-item .user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 10px;
    border: 2px solid var(--pico-muted-border-color);
}

/* Gender border colors: male = blue, female = pink (used on user list and message avatars) */
.avatar-male {
    border-color: var(--pico-primary) !important;
}

.avatar-female {
    border-color: #ff69b4 !important; /* hot pink */
}

.user-list-item .user-avatar.avatar-male {
    border: 2px solid var(--pico-primary) !important;
}

.user-list-item .user-avatar.avatar-female {
    border: 2px solid #ff69b4 !important;
}

/* Chat Bubbles */
.message {
    padding: calc(var(--pico-typography-spacing-vertical) / 4) 0;
    display: flex; /* Use flexbox for avatar and content */
    align-items: flex-start; /* Align avatar to the top */
    gap: calc(var(--pico-spacing) / 2); /* Reduced gap */
    /* The properties below are removed for the new table-like layout */
    /* border-radius: var(--pico-border-radius); */
    /* max-width: 70%; */
    /* width: fit-content; */
}

.message .user-avatar {
    margin-right: 0; /* Remove margin for message avatars */
}

.message:nth-child(even) .message-content {
    background-color: var(--pico-muted-background-color);
}

.message:nth-child(odd) .message-content {
    background-color: var(--pico-background-color);
}

.message-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 2px solid var(--pico-muted-border-color);
}

/* Main chat and private message window: gender border on avatar (blue = male, pink = female) */
.message-avatar.avatar-male {
    border: 2px solid var(--pico-primary) !important;
}

.message-avatar.avatar-female {
    border: 2px solid #ff69b4 !important;
}

/* Channel loading modal progress bar (CSS-animated, GPU-friendly) */
#channel-loading-modal .channel-loading-progress {
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: var(--pico-muted-background-color);
    overflow: hidden;
    margin-top: var(--pico-spacing);
}

#channel-loading-modal .channel-loading-progress-bar {
    width: 100%;
    height: 100%;
    background: var(--pico-primary);
    transform-origin: left center;
    transform: scaleX(0);
}

#channel-loading-modal .channel-loading-progress-bar.is-animating {
    animation: channel-loading-fill 2s ease-out forwards;
}

@keyframes channel-loading-fill {
    from {
        transform: scaleX(0);
    }
    to {
        transform: scaleX(1);
    }
}

.message-content {
    flex: 1; /* Allow content to take up remaining space */
    display: flex;
    flex-direction: column;
    padding: calc(var(--pico-typography-spacing-vertical) / 4) var(--pico-typography-spacing-horizontal);
    border-radius: var(--pico-border-radius);
}

.message-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.message-body {
    word-break: break-word; /* Prevent long strings from overflowing */
}

.message-timestamp {
    font-size: 0.75em;
    color: var(--pico-muted-color);
    margin-left: auto; /* Push to the right */
}

.message-report-flag {
    font-size: 0.9em;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.2s ease-in-out;
}

.message-report-flag:hover {
    opacity: 1;
}

/* Use distinct styles for sent and received messages for clarity and robustness */
.message-sent .message-content {
    background-color: var(--pico-muted-background-color);
    border: 1px solid transparent; /* Keep layout consistent */
}

.message-received .message-content {
    background-color: var(--pico-card-background-color);
    /* border: 1px solid var(--pico-card-border-color); */ /* Border removed as requested */
}

.message strong {
    display: block;
    font-size: 0.9em;
    margin-bottom: 0; /* Remove space below name */
}

.message-sent {
    /* align-self: flex-end; */ /* Removed for full-width layout */
    background-color: transparent; /* Use alternating colors instead */
    color: var(--pico-font-color); /* Reset color */
}

.message-received {
    /* align-self: flex-start; */ /* Removed for full-width layout */
    /* background-color: var(--pico-card-background-color); */ /* Use alternating colors instead */
    /* border: 1px solid var(--pico-card-border-color); */ /* Border removed */
}

/* Server system messages in private chat (e.g. "User has left the chat") */
.message-system {
    justify-content: center;
    margin: 0.5rem 0;
}
.message-system .message-content {
    background-color: var(--pico-muted-background-color);
    font-size: 0.9em;
    opacity: 0.9;
}
.message-system .message-header strong {
    color: var(--pico-muted-color);
}

/* PM modal header with bio */
.pm-modal-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.pm-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 10px;
}

.pm-modal-header-main {
    flex: 1;
    min-width: 0;
}

.pm-recipient-bio {
    margin: 0.1rem 0 0;
    font-size: 0.85em;
    color: var(--pico-muted-color);
    word-wrap: break-word;
}

.pm-header-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.pm-header-actions .pm-block-btn {
    font-size: 0.85rem;
    padding: 0.25rem 0.6rem;
    line-height: 1.1;
}

/* Mobile-First Layout Adjustments */
.mobile-nav {
    display: none; /* Hidden by default on desktop */
}

/* Profile avatar in header */
#profile-avatar {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--pico-muted-border-color);
    cursor: pointer;
}

#profile-avatar.avatar-male {
    border-color: var(--pico-primary) !important;
}

#profile-avatar.avatar-female {
    border-color: #ff69b4 !important;
}

/* Profile modal avatar */
#profile-modal-avatar {
    width: 128px;
    height: 128px;
    max-width: 128px;
    max-height: 128px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--pico-muted-border-color);
    display: block;
    cursor: pointer;
}

#profile-modal-avatar.avatar-male {
    border-color: var(--pico-primary) !important;
}

#profile-modal-avatar.avatar-female {
    border-color: #ff69b4 !important;
}

.profile-section {
    margin-bottom: 0.5rem;
}

/* Animate open/close of profile sections inside the modal */
#profile-modal details.profile-section > div {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.25s ease;
}

#profile-modal details.profile-section[open] > div {
    max-height: 400px; /* large enough for content; animation target */
}

.vip-options-section {
    margin-top: 1rem;
}

.vip-options-section textarea#profile-bio {
    width: 100%;
    resize: vertical;
    min-height: 3rem;
    max-height: 8rem;
}

.vip-badge {
    margin-left: 0.4rem;
    padding: 0.05rem 0.35rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    background-color: #fdd835;
    color: #000;
    text-transform: uppercase;
}

/* Desktop: show top bar and allow collapsing menu/user list */
@media (min-width: 769px) {
    .mobile-nav {
        display: block;
        padding: 0.25rem var(--pico-spacing);
        border-bottom: 1px solid var(--pico-card-border-color);
        background: var(--pico-background-color);
    }
    .mobile-nav nav {
        display: flex;
        justify-content: space-between;
        align-items: center;
        max-width: none;
    }
    .mobile-nav nav ul {
        margin: 0;
    }
    .mobile-nav .logo-mobile {
        font-size: 1rem;
        margin: 0;
    }

    /* Grid: chat takes remaining space (1fr), right sidebar sizes to content */
    main.container > .grid {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: 1fr;
        width: 100%;
        min-width: 0;
    }

    .chat-area {
        min-width: 0; /* Allow flex/grid item to shrink below content size */
    }

    /* Sidebars: max 260px when open, 0 when closed; chat expands into freed space */
    .sidebar-left,
    .sidebar-right {
        width: 260px;
        max-width: 260px;
        min-width: 0;
        overflow: hidden;
        transition: width 0.25s ease, min-width 0.25s ease;
    }
    .sidebar-left:not(.visible),
    .sidebar-right:not(.visible) {
        width: 0;
        max-width: 0;
        min-width: 0;
        padding: 0;
        margin: 0;
        border: none;
        box-shadow: none;
    }
}

@media (max-width: 768px) {
    body {
        overflow: hidden; /* Prevent body itself from scrolling */
    }

    .sidebar-left, .sidebar-right {
        /* display: none; */ /* Replaced by the transform below */
        position: fixed;
        top: 0;
        height: 100%;
        z-index: 1000;
        background: var(--pico-card-background-color);
        padding: var(--pico-spacing);
        box-shadow: 0 0 15px rgba(0,0,0,0.2);
        width: 280px;
        box-sizing: border-box; /* Include padding in the width */
        transform: translateX(-100%); /* Use percentage to fully hide */
        transition: transform 0.3s ease-in-out;
    }

    .sidebar-left {
        left: 0; /* Anchor so translateX(-100%) fully hides it */
    }

    .sidebar-right {
        right: 0;
        transform: translateX(100%); /* Use percentage to fully hide */
    }

    .sidebar-left:not(.visible),
    .sidebar-right:not(.visible) {
        box-shadow: none; /* No shadow when closed so no sliver visible */
        overflow: hidden;
    }

    .sidebar-left.visible, .sidebar-right.visible {
        display: flex; /* Make it visible */
        transform: translateX(0);
        box-shadow: 0 0 15px rgba(0,0,0,0.2);
        overflow: visible;
    }

    .mobile-nav {
        display: block;
        padding: 0 var(--pico-spacing);
        border-bottom: 1px solid var(--pico-card-border-color);
        /* No longer fixed, will be part of the flex flow */
    }
    
    .mobile-nav .logo-mobile {
        font-size: 1.2rem;
        margin: 0;
    }
    
    main.container {
        flex: 1; /* Allow main to grow and fill remaining space */
        padding-top: 0; /* No longer needed */
        display: flex; /* Ensure it's a flex container for its children */
        min-height: 0; /* Add min-height to ensure it can shrink if needed */
    }

    body.tech-support-page main.tech-support-main {
        display: block;
    }

    main.container > .grid {
        width: 100%; /* Ensure grid takes full width */
        display: flex; /* Override the display: grid */
        flex: 1; /* Make the grid container fill the main container */
    }

    .chat-area {
        flex: 1; /* Make the chat area fill the grid container */
    }

    .chat-input-area {
        gap: calc(var(--pico-spacing) / 2); /* Reduce gap on mobile */
        padding: calc(var(--pico-spacing) / 2); /* Reduce padding on mobile */
    }

    .chat-input-area button {
        --pico-form-element-spacing-horizontal: 0.5rem; /* Reduce button padding */
    }

    #upload-button svg {
        width: 20px; /* Reduce icon size */
        height: 20px;
    }
}

/* The context menu CSS has been removed as it is no longer needed. */

/* Private Message Modal */
#private-message-modal {
    /* Let Pico.css control the modal card width so
       the header, body and footer stay perfectly aligned.
       We only remove default padding/border and keep the shadow. */
    padding: 0; /* Remove padding from the dialog itself */
    border: none; /* Remove the default dialog border */
    border-radius: var(--pico-border-radius);
    box-shadow: var(--pico-card-box-shadow);
}

#private-message-modal article {
    display: flex;
    flex-direction: column;
    height: 90vh; /* Use more of the vertical viewport height */
    max-height: 1200px;
    padding: 0; 
    overflow: hidden;
}

/* PM modal header: stacked layout for better mobile support */
#private-message-modal header.pm-modal-header {
    flex-shrink: 0;
    padding: calc(var(--pico-spacing) * 0.85) var(--pico-spacing);
    border-bottom: 1px solid var(--pico-card-border-color);
}

#private-message-modal .pm-modal-title {
    margin: 0;
    min-width: 0;
    font-size: 1rem;
    word-wrap: break-word;
}

/* Block button: subtle outline, not competing with primary actions */
#private-message-modal #pm-block-user-btn.pm-block-btn {
    flex-shrink: 0;
    padding: 0.35rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--pico-muted-border-color);
    background: transparent;
    color: var(--pico-muted-color);
    border-radius: var(--pico-border-radius);
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

#private-message-modal #pm-block-user-btn.pm-block-btn:hover {
    border-color: var(--pico-del-color, #c62828);
    color: var(--pico-del-color, #c62828);
    background-color: rgba(198, 40, 40, 0.06);
}

/* The existing .chat-messages class already defines flex: 1, overflow-y: auto etc. */
/* We just remove the problematic min-height that was pushing the footer out */
#private-message-modal .chat-messages {
    /* The problematic style is removed. No new styles needed here. */
}

#private-message-modal footer {
    /* Keep footer fixed height and let the shared .chat-input-area handle layout/padding */
    flex-shrink: 0;
    padding: 10px;
    border-top: none;
    background-color: transparent;
}

/* Make the PM input bar visually match the main chat input bar, but slightly tighter to fit the narrower modal */
#private-message-modal .chat-input-area {
    border-top: 1px solid var(--pico-card-border-color);
    background-color: var(--pico-background-color);
    position: static;   /* Override sticky positioning from main chat */
    bottom: auto;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: calc(var(--pico-spacing) / 1.5);
    gap: calc(var(--pico-spacing) / 1.5);
}

#private-message-modal .chat-input-area #pm-input {
    flex: 1;
    min-width: 0; /* Allow flexbox to shrink inside the modal without overflowing */
    margin-bottom: 0;
    min-height: 2.5rem;
}

#private-message-modal .chat-input-area #pm-send-button {
    flex-shrink: 0;
    margin-bottom: 0;
    min-height: 2.5rem;
    width: 2.5rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#private-message-modal .chat-input-area #pm-send-button svg {
    width: 20px;
    height: 20px;
}

#private-message-modal .chat-input-area #pm-upload-button {
    flex-shrink: 0;
    margin-bottom: 0;
    min-height: 2.5rem;
    width: 2.5rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Scoped Fix for Private Message Modal Message Rendering */
#private-message-modal .message-content {
    background-color: var(--pico-card-background-color) !important;
    /* border: 1px solid var(--pico-card-border-color) !important; */ /* Border removed as requested */
    color: var(--pico-color) !important; /* Explicitly set text color to ensure visibility */
}

#private-message-modal .message:nth-child(even) .message-content {
     background-color: var(--pico-muted-background-color) !important;
}

/* --- Start of Definitive PM Modal Style Fix --- */

/* First, remove/reset all previous failed attempts to prevent conflicts */
#private-message-modal .message,
#private-message-modal .message-avatar {
    position: static;
    display: block;
    min-height: initial;
    padding: 0;
}

/* 1. Redefine the message row (now a div) as a stable flex container */
#private-message-modal div.message {
    display: flex;
    align-items: flex-start; /* Align items to the top */
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    padding: 8px; /* Give the entire row some breathing room */
    /* min-height: 50px; */ /* REMOVED: This was preventing the row from expanding for images */
}

/* 2. Style the avatar, ensuring it does not shrink */
#private-message-modal div.message .message-avatar {
    flex-shrink: 0;
}

/* Gender border in PM window (same as main chat: blue = male, pink = female) */
#private-message-modal .message-avatar.avatar-male {
    border: 2px solid var(--pico-primary) !important;
}
#private-message-modal .message-avatar.avatar-female {
    border: 2px solid #ff69b4 !important;
}

/* 3. Ensure the message content area is visible and takes up the remaining space */
#private-message-modal div.message .message-content {
    flex-grow: 1;
    min-width: 0; /* A critical fix for word wrapping inside a flex item */
}


/* --- End of Definitive PM Modal Style Fix --- */
