
@font-face {
    font-family: 'Nunito';
    src: url('/fonts/Nunito-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
  }
  
  @font-face {
    font-family: 'Nunito';
    src: url('/fonts/Nunito-Italic-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    font-style: italic;
    font-display: swap;
  }
  :root {
    /* == Brand & Interactive Colors == */
    --primary-color: #4F46E5; /* Modern indigo */
    --primary-color-hover: #3B37C8;
    --primary-color-focus-shadow: rgba(79, 70, 229, 0.25);

    /* == Text Colors == */
    --text-color: #111827;              /* Rich dark for better readability */
    --text-color-light: #ffffff;
    --text-color-muted: #6B7280;        /* Balanced grey */
    --text-color-subtle: #9CA3AF;
    --text-color-inverted: #ffffff;
    --text-color-inverted-muted: rgba(255, 255, 255, 0.75);

    /* == Background Colors == */
    --bg-body: #F9FAFB;                  /* Softer background */
    --bg-surface: #FFFFFF;
    --bg-sidebar: #F8FAFC;              /* Subtle blue-grey tint */
    --bg-hover: #F3F4F6;               /* Warmer hover */
    --bg-disabled: #E5E7EB;
    
    /* == Modern Design System == */
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    --sent-bubble-bg: #4F46E5;      /* Rich indigo background */
    --sent-avatar-bg: #4F46E5; /* Primary brand color */
    --sent-bubble-text: #FFFFFF;     /* White text for high contrast */
    --sent-meta-text: #E0E7FF;       /* Light indigo for timestamps */

    /* Received Messages (Sage Green) */
    --received-bubble-bg: #ECFDF5; /* Light mint */
    --received-avatar-bg: #10B981;   /* Emerald green */
    --received-bubble-text: #064E3B; /* Dark green for contrast */
    --received-sender-name: #047857; /* Rich green */
    --received-meta-text: #059669;   /* Medium green */
    /* --- End New Chat Colors --- */

    /* == Other colors... (Keep as is) == */
    --border-color: #dee2e6;
    --border-color-subtle: #f0f0f0;
    --danger-color: #dc3545;
    --danger-color-hover: #c82333;
    --success-color: #28a745;
    --notification-color: #d9534f;
    --placeholder-text: #aaa;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --scrollbar-track-bg: #e0e0e0;
    --scrollbar-thumb-bg: var(--primary-color);
    --scrollbar-thumb-hover-bg: var(--primary-color-hover);
    --font-family: 'Nunito', sans-serif;
}


/* ----------------------------------------------------- */
/* --- REPLACE THE VARIABLES IN YOUR body.dark-theme --- */
/* ----------------------------------------------------- */
body.dark-theme {
    /* == Brand & Interactive Colors == */
    --primary-color: #388BFF; /* Brighter blue for dark mode */
    --primary-color-hover: #4C9BFF;
    --primary-color-focus-shadow: rgba(56, 139, 255, 0.3);

    /* == Text Colors == */
    --text-color: #E4E6EB;
    --text-color-light: #E4E6EB;
    --text-color-muted: #B0B3B8;
    --text-color-subtle: #8A8D91;
    --text-color-inverted: #FFFFFF;
    --text-color-inverted-muted: rgba(255, 255, 255, 0.7);

    /* == Background Colors == */
    --bg-body: #18191a;
    --bg-surface: #242526;
    --bg-sidebar: #1f2021;
    --bg-hover: #3A3B3C;
    --bg-disabled: #4A4A4A;
    
    /* Remove background pattern in dark theme */
    background: var(--bg-body) !important;
    background-image: none !important;

    /* === NEW CHAT COLORS (Dark Theme) === */
    --sent-bubble-bg: darkslategrey;   /* A deep, saturated blue */
    --sent-avatar-bg: darkslategrey;
    --sent-bubble-text: #FFFFFF;
    --sent-meta-text: rgba(255, 255, 255, 0.7);

    /* Received Messages (Green) */
    --received-bubble-bg: dimgrey;  /* A dark, modern teal */
    --received-avatar-bg: dimgrey;
    --received-bubble-text: #E4E6EB;
    --received-sender-name: #7DD2B8; /* A light, readable mint */
    --received-meta-text: #8A9A9F;
    /* --- End New Chat Colors --- */

    /* == Other colors... (Keep as is) == */
    --border-color: #3a3b3c;
    --border-color-subtle: #2a2a2a;
    --danger-color: #e57373;
    --danger-color-hover: #ef5350;
    --success-color: #4caf50;
    --notification-color: #ef5350;
    --placeholder-text: #d4cece;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --scrollbar-track-bg: #2a2a2a;
    --scrollbar-thumb-bg: var(--primary-color);
    --scrollbar-thumb-hover-bg: var(--primary-color-hover);
}
/* --- 2. Theme Toggle Button Styling --- */
.theme-toggle-button {
    background: none;
    border: none;
    color: var(--text-color-muted);
    font-size: 1.6rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    line-height: 1;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.controls .theme-toggle-button {
    font-size: 1.2rem;
}

.theme-toggle-button:hover {
    color: var(--primary-color);
    background-color: var(--light-grey);
}

/* In dark mode, the button in the header should be lighter */
body.dark-theme .controls .theme-toggle-button {
    color: #a8a8a8;
}
body.dark-theme .controls .theme-toggle-button:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.1);
}

body {
    font-family: 'Nunito', sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-color);
    /* Enhanced background with subtle pattern */
    background: var(--bg-body);
    background-image: 
        radial-gradient(circle at 25px 25px, rgba(79, 70, 229, 0.02) 2%, transparent 0%), 
        radial-gradient(circle at 75px 75px, rgba(79, 70, 229, 0.02) 2%, transparent 0%);
    background-size: 100px 100px;
    margin: 0; /* Ensure no body margin */
    padding: 0; /* Ensure no body padding */
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: 1.2;
}

small {
    font-size: 0.8rem;
}


/* Chat Screen */
#chat-screen {
    display: flex;
    width: 100%;
     /* 2. A very thin solid border to define the "light tube" */
 
     /* 3. A more subtle, layered box-shadow for the glow */
     /* We use smaller blur values for a tighter, thinner glow */

}

/* Modifications to #chat-area */
#chat-area {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    background: var(--bg-surface);
    border-radius: 0 12px 12px 0; /* Rounded right corners */
    margin-top: 4px; /* Align with sidebar */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

/* Chat Messages */
#chat-messages {
    display: flex;
    flex-direction: column;
    padding: 20px 18px; /* Better padding for breathing room */
    gap: 0; /* Remove gap since we use margin-bottom on messages for better control */
    background-color: var(--bg-surface); /* Use solid background color */
    /* Only prevent horizontal overflow at the main container level */
    overflow-x: hidden;
    width: 100%;
    box-sizing: border-box;
}

@keyframes fade-in-slide-up {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
/* --- The Message Row Container --- */
.message {
    display: block; /* Changed from flex to block for proper stacking */
    max-width: 85%; /* Slightly wider for better use of space */
    /* This container MUST be transparent */
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
    /* This overrides an inline style from your old JS */
    padding-bottom: 0 !important; 
    animation: fade-in-slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 12px; /* Better spacing for readability */
    /* Remove all overflow settings to prevent scrollbars */
    box-sizing: border-box;
}

/* Message content wrapper (avatar + bubble) */
.message-content {
    display: flex;
    align-items: flex-end;
    gap: 12px; /* Slightly more space between avatar and bubble */
}

.message.sent .message-content {
    align-self: flex-end;
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.message.received .message-content {
    align-self: flex-start;
}

.message.sent {
    align-self: flex-end;
}
.message.received {
    align-self: flex-start;
}

/* --- The Circular Avatar --- */
.message-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--text-color-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}
.message.sent .message-avatar {
    background-color: var(--sent-avatar-bg);
}
.message.received .message-avatar {
    background-color: var(--received-avatar-bg);
    color: var(--received-bubble-text);
}
.message-avatar i.fas.fa-user {
    margin: 0;
}

/* --- The Message Bubble --- */
.message-bubble {
    padding: 10px 14px;
    line-height: 1.4;
    word-wrap: break-word;
    display: block; /* Ensures correct stacking in all browsers */
    overflow: hidden;
    position: relative; /* For mobile hint pseudo-element */
}
.message.received .message-bubble {
    background-color: var(--received-bubble-bg);
    border-radius: 4px 18px 18px 18px;
}
.message.sent .message-bubble {
    background-color: var(--sent-avatar-bg); 
    border-radius: 18px 4px 18px 18px;
}

/* --- Bubble Header (Name + Timestamp) --- */
.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    overflow: hidden;
}
.message-sender {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--primary-color);
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.message-timestamp {
    font-size: 0.55rem;
    margin-left: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}
.message.received .message-timestamp {
    color: var(--received-meta-text);
}
.message.sent .message-timestamp {
    color: var(--sent-meta-text);
}

.message.received .message-sender {
    color: var(--received-sender-name);
}
.message.sent .message-sender {
    color: var(--sent-bubble-text);
}

/* --- Bubble Body (The Text) --- */
.message-body {
    font-size: 0.95rem;
    overflow-wrap: break-word;
    /* A more aggressive property for maximum browser compatibility */
    word-break: break-all;
}
.message.received .message-body {
    color: var(--received-bubble-text);
}
.message.sent .message-body {
    color: var(--sent-bubble-text);
}
.message-body p {
    margin: 0;
}
.message-body p:not(:last-child) {
    margin-bottom: 0.25em;
}

/* Message Input Area */
#message-input-area {
    padding: 16px 18px;
    background-color: var(--bg-sidebar);  /* A clean, light grey background */
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 12px 0; /* Match chat area radius */
}
.input-row-wrapper {
    display: flex;
    align-items: center; /* Aligns items to the bottom */
    gap: 12px; /* More space between editor and controls */
}
#editor-container {
    flex-grow: 1; /* Take up all available space */
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px; /* A softer radius */
    overflow: hidden; /* Important for containing the toolbar */
    display: flex;
    min-width: 0;
    flex-direction: column;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

#editor-container .ql-toolbar.ql-snow {
    padding: 6px 8px;
    border: none;
    border-bottom: 1px solid var(--border-color-subtle); 
    background-color: var(--bg-sidebar);
}
#editor-container .ql-container {
    min-height: 40px;
    max-height: 150px;
    font-size: 1rem;
    border: none;
}
#editor-container .ql-toolbar .ql-stroke {
    stroke: var(--text-color-muted);
}
#editor-container .ql-toolbar button:hover .ql-stroke {
    stroke: var(--primary-color);
}
#editor-container .ql-toolbar .ql-active .ql-stroke {
    stroke: var(--primary-color);
}
#editor-container .ql-container.ql-snow {
    border: none;
    min-height: 44px; /* Adjust height */
    max-height: 120px;
    font-size: 0.95rem;
}
#editor-container .ql-editor {
    padding: 10px 12px;
}



#editor,
#ql-editor #ql-blank {
  min-height: 45px;
  max-height: 75px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  padding: 10px;
  border-radius: 6px;
  background: var(--bg-surface);
  font-size: 14px;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 8px;
  display: block;
}

#send-button {
    padding: 0;
    width: 68px; height: 68px;
    border-radius: 50%; /* Full circle for modern look */
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary-color), #6366F1);
    color: var(--text-color-light);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

#send-button:hover {
    background: linear-gradient(135deg, var(--primary-color-hover), #5B5BD6);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
}
#send-button i {
    margin: 0;
    transform: translateX(1px); /* Slight visual adjustment for arrow */
}

/* Picture Upload Button Styles */
.picture-upload-btn {
    padding: 0;
    width: 56px; 
    height: 56px;
    border-radius: 50%;
    display: flex; 
    align-items: center; 
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    background: linear-gradient(135deg, #10B981, #059669);
    color: white;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
    margin-bottom: 8px;
    /* Mobile touch optimization */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.picture-upload-btn:hover {
    background: linear-gradient(135deg, #059669, #047857);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 5px 15px rgba(16, 185, 129, 0.4);
}

.picture-upload-btn i {
    margin: 0;
}

/* DM Picture Upload Button - smaller for compact layouts */
.dm-picture-upload-btn {
    width: 40px;
    height: 40px;
    font-size: 0.9rem;
    margin-right: 8px;
    margin-bottom: 0;
    /* Mobile touch optimization */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Custom Room Picture Upload Button */
.custom-room-picture-upload-btn {
    width: 50px;
    height: 50px;
    font-size: 1rem;
    margin-bottom: 6px;
}

/* Unified input container adjustments for DM */
.unified-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Picture Message Styles */
.picture-message-content {
    position: relative;
    display: inline-block;
    max-width: 250px;
}

.chat-picture {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
    border: 1px solid #ddd;
    transition: opacity 0.2s ease;
}

.chat-picture:hover {
    opacity: 0.9;
}

.picture-actions {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    padding: 2px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.picture-message-content:hover .picture-actions {
    opacity: 1;
}

.picture-actions button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px 6px;
    font-size: 12px;
    border-radius: 2px;
    margin: 0 1px;
    transition: background-color 0.2s ease;
}

.picture-actions button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.picture-caption {
    margin-top: 8px;
    font-size: 0.9em;
    color: var(--text-color);
    font-style: italic;
}

/* Picture Modal with Zoom Functionality */
.picture-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

/* Prevent any report buttons from escaping modal context */
.picture-modal * {
    position: relative !important;
}

/* Ensure no floating/fixed report elements */
button[id*="report" i], 
button[class*="report" i],
*[data-action*="report" i] {
    position: relative !important;
    z-index: auto !important;
}

.picture-modal-content {
    background: var(--bg-color);
    border-radius: 12px;
    max-width: 90vw;
    max-height: 90vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative; /* Ensure proper positioning context */
    z-index: 10001; /* Higher than modal backdrop */
    contain: layout style; /* CSS containment to prevent overflow */
}

.picture-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    gap: 15px;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.picture-modal-header h3 {
    margin: 0;
    color: var(--text-color);
    font-size: 1.2rem;
    font-weight: 600;
}

.picture-modal-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--input-bg);
    border-radius: 8px;
    padding: 4px;
}

.zoom-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.zoom-btn:hover {
    background: var(--hover-bg);
    transform: scale(1.05);
}

.zoom-btn:active {
    transform: scale(0.98);
}

.zoom-level {
    font-size: 12px;
    color: var(--text-color-secondary);
    font-weight: 600;
    min-width: 45px;
    text-align: center;
    background: var(--primary-color);
    color: var(--text-color-light);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: monospace;
}

.picture-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-color-secondary);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: all 0.2s ease;
    border-radius: 4px;
}

.picture-modal-close:hover {
    color: var(--text-color);
    background: var(--hover-bg);
    transform: scale(1.1);
}

.picture-modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* Allow flex item to shrink below content size */
}

.picture-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background: var(--input-bg);
    min-height: 300px; /* Reduced from 400px to leave more room for actions */
    position: relative;
}

.zoomable-picture {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    user-select: none;
    -webkit-user-drag: none;
}

/* Quill Editor Image Styling - Make images appear as thumbnails in editor */
.ql-editor img {
    max-width: 200px !important;
    max-height: 150px !important;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: block;
    margin: 5px 0;
    cursor: pointer;
    object-fit: cover;
}

.ql-editor img:hover {
    opacity: 0.8;
    transform: scale(1.02);
    transition: all 0.2s ease;
}

/* Picture actions within the picture modal - more specific selector */
.picture-modal .picture-actions {
    padding: 16px 20px;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    position: static !important; /* Override the absolute positioning from chat picture actions */
    z-index: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 1 !important; /* Override the opacity: 0 from chat picture actions */
    top: auto !important; /* Reset absolute positioning */
    right: auto !important; /* Reset absolute positioning */
    flex-shrink: 0; /* Prevent actions from being cut off */
    min-height: 60px; /* Ensure minimum space for buttons */
}

/* Make button styles specific to the picture modal */
.picture-modal .picture-actions .btn {
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    margin-right: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    position: static !important; /* Force static positioning */
    z-index: auto !important; /* Normal z-index */
    top: auto !important; /* Override any top positioning */
    left: auto !important; /* Override any left positioning */
    right: auto !important; /* Override any right positioning */
    bottom: auto !important; /* Override any bottom positioning */
    background: transparent; /* Reset any inherited background */
    color: inherit; /* Reset any inherited color */
}

.picture-modal .picture-actions .btn-danger {
    background: #ef4444 !important;
    color: white !important;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.2);
    position: static !important; /* Prevent any positioning conflicts */
    z-index: auto !important; /* Normal z-index within modal */
}

/* Specifically target the report picture button within the modal to ensure it stays in place */
.picture-modal #reportPictureBtn {
    position: static !important;
    display: inline-flex !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
}

.picture-actions .btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(239, 68, 68, 0.3);
}

.picture-actions .btn-danger:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.2);
}

.zoom-instructions {
    color: var(--text-color-secondary);
    font-size: 12px;
    margin-top: 8px;
    text-align: center;
    opacity: 0.8;
}

/* Mobile optimizations for picture modal */
@media (max-width: 768px) {
    .picture-modal-content {
        max-width: 95vw;
        max-height: 95vh;
        margin: 10px;
    }
    
    .picture-modal-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .picture-modal-controls {
        order: 3;
        flex-basis: 100%;
        justify-content: center;
    }
    
    .zoom-btn {
        padding: 10px;
        font-size: 16px;
        min-width: 44px;
        min-height: 44px;
    }
    
    .picture-container {
        min-height: 300px;
    }
    
    .picture-actions {
        padding: 12px 16px;
    }
    
    .zoom-instructions {
        font-size: 11px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .picture-modal {
        background-color: rgba(0, 0, 0, 0.9);
    }
}

/* Animations */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.picture-modal {
    animation: modalFadeIn 0.2s ease-out;
}

/* Mobile picture message adjustments */
@media (max-width: 768px) {
    .picture-message-content {
        max-width: 200px;
    }
    
    .chat-picture {
        max-height: 150px;
    }
    
    .picture-actions {
        opacity: 1; /* Always visible on mobile */
    }
    
    .picture-actions button {
        padding: 6px 8px;
        font-size: 14px;
    }
}

#chat-dock-container {
    position: fixed;
    bottom: 0;
    right: 15px; /* Aligns the entire dock to the right of the screen */
    left: auto;  /* IMPORTANT: Allows the width to be determined by content */
    width: auto;
    max-width: calc(100% - 250px); /* Prevent it from overlapping the sidebar */

    height: auto; /* Let children define height */
    
    display: flex;
    align-items: flex-end;
    gap: 15px;
    
    pointer-events: none; /* Let clicks pass through the container itself */
}


#chat-bar {
    display: flex;
    gap: 10px;
    pointer-events: all; /* Heads inside are clickable */
    
    flex-shrink: 1;   /* Allows the bar to shrink to make space for open windows */
    min-width: 0;     /* A flexbox helper for shrinking */
    overflow: hidden; /* Hides any heads that don't fit in the shrunken bar */
}

/* --- 2. Individual Chat Heads --- */
.chat-head {
    background-color: var(--primary-color);
    color: var(--text-color-light);
    font-weight: 600;
    padding: 10px 15px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;  
    max-width: 300px;
    min-width: 200px;

    /* --- ADD THESE TWO LINES BACK --- */
    position: relative; /* Establishes a positioning context for children/pseudo-elements */
    z-index: 1;         /* Ensures it stacks correctly */
}
.chat-head span:first-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-head.visible,
.chat-head.visible-for-measure {
    display: flex; /* <<<< SHOW ONLY WHEN JS ADDS THIS CLASS */
}

.chat-head:hover {
    background-color: var(--primary-color-hover);
    transform: translateY(-3px);
}
.chat-head .chat-head-close {
    font-size: 1.1rem; /* Bolder 'x' */
    font-weight: bold;
    color: rgba(255,255,255,0.7);
    margin-left: 5px;
    padding: 0 4px;
    border-radius: 50%;
    margin-left: auto;
}
.chat-head .chat-head-close:hover {
    background-color: rgba(0,0,0,0.2);
    color: var(--text-color-light);
}
.chat-head.new-message-head {
    background-color: var(--notification-color); /* A red color to indicate a new message */
    position: relative; /* Required for the pseudo-element */
    z-index: 1; /* Ensure it's above other elements */
}
.chat-head.new-message-head::after {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 12px; /* Match the parent's border-radius */
    border: 2px solid var(--notification-color);
    animation: new-pulse 1.5s infinite;
    pointer-events: none; /* Make sure the ring doesn't block clicks */
}
/* Character count container */
.dm-char-count {
    color: var(--text-color-muted);
    font-size: 0.8rem;
    margin-right: 10px; /* Space to the right if button is also right */
}
/* --- Central Chat Container Layout Adjustment --- */
#chat-container {
        border-radius: 10px;
    box-shadow: 0 0.5rem 1rem var(--shadow-color);
    overflow: hidden;
    flex-grow: 1; /* Takes the central space */
    display: flex; /* Use flex to manage login/chat switching */
    flex-direction: column; /* Stack login/chat and disclaimer */
    /* REMOVE any width/margin from original rules */
    width: auto !important;
    margin: 0 !important;
    /* Keep existing background/border-radius/box-shadow if desired */
    background-color: var(--bg-surface);
    /* border-radius: 10px; */
    /* box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1); */
    position: relative;
}

#chat-container > #chat-screen {
   flex-grow: 1; /* Allow chat screen to fill remaining vertical space */
   width: 100%;
   /* Remove height: 100% */
   overflow: hidden; /* Keep hidden here to contain internal chat elements */
   display: none; /* Keep hidden initially */
   /* display: flex; will be added by JS */
}


/* Ensure chat screen uses flex for internal layout */
#chat-screen {
     display: none; /* Hidden initially */
     /* Add display: flex from JS */
}
/* Keep original #sidebar, #chat-area, #chat-messages etc styles */
/* They should function correctly inside the resized #chat-container */

/* Keep disclaimer style, ensure it's at bottom */
#chat-container > #disclaimer {
     flex-shrink: 0;
     /* Keep original padding, text-align, font-size, color, border-top, background-color */
     padding: 10px; text-align: center; font-size: 0.8em; color: var(--text-color);
     border-top: 1px solid var(--border-color); background-color: var(--secondary-color);
     margin-top: auto; /* Pushes it down if chat-container uses flex column */
}


.message.system {
    background-color: transparent; /* Current: No background */
    box-shadow: none;              /* Current: No shadow */
    text-align: center;            /* Current: Centered */
    font-style: italic;            /* Current: Italic */
    color: var(--text-color-muted);/* Current: Muted color */
    font-size: 0.9rem;             /* Current: Slightly smaller */
    max-width: 100%;               /* Current: Full width */
    align-self: center;            /* Current: Centered horizontally */
    padding: 5px;                  /* Current: Smaller padding */
    margin: 10px 0;                /* Current: Vertical margin */
}
.message.system strong { display: none; } /* Hides "System:" prefix */

.ql-tooltip a.ql-action,
.ql-tooltip a.ql-remove {
    display: none !important;
}

/* --- Collapse Visually Empty Paragraphs in Messages --- */

.message p:empty,
.message p:has(> br:only-child) {
  margin: 0;
  padding: 0;
  font-size: 0;
  line-height: 0;
  border: none;
}

/* --- Apply specifically to message containers --- */
/* Ensure these rules apply with enough specificity */

#chat-messages .message p:empty,
#chat-messages .message p:has(> br:only-child),
#mobile-dm-view .view-content .message p:empty,
#mobile-dm-view .view-content .message p:has(> br:only-child) {
    margin: 0 !important; /* Use !important if absolutely necessary */
    padding: 0 !important;
    font-size: 0 !important;
    line-height: 0 !important;
    border: none !important;
    display: none !important; /* Try display:none with !important if needed */
}

/* Reset margins for paragraphs that DO contain text */
.message p:not(:empty):not(:has(> br:only-child)) {
     /* Apply your desired default paragraph margin, or let it inherit */
     /* margin-bottom: 0.5em; */ /* Example */
     margin: 0; /* Start with no margin unless needed */
}

.input-controls {
    display: flex;
    flex-direction: column; /* <<< THIS IS THE FIX: Stack items vertically */
    align-items: center;    /* Center them horizontally */
    flex-shrink: 0;
    /* Optional: fine-tune vertical alignment if needed */
    padding-bottom: 2px; 
}




/* Default state (visible when logged out or before login) */





body,
body html {
    /* Prevent the main page scrollbar when logged in */
    overflow: hidden;
    height: 100vh; /* Force html/body to viewport height */
    scrollbar-color: var(--scrollbar-thumb-bg) var(--scrollbar-track-bg);
}

body #app-wrapper {
    /* Ensure wrapper strictly adheres to viewport height */
    height: 100vh;
    min-height: 100vh; /* Keep min-height too */
    overflow: hidden; /* Prevent wrapper overflow */
    display: flex; /* Keep flex */
    flex-direction: column; /* Keep column */
}

body #main-header {
    /* Header is already flex-shrink: 0 */
    position: sticky; /* Make header sticky */
    top: 0;
    z-index: 1050; /* Ensure it's above content */
}

body #content-area {
    flex-grow: 1; /* Takes space between header/footer */
    height: 0; /* Works with flex-grow to fill space reliably */
    overflow: hidden; /* Contain its children */
    display: flex; /* Keep row layout */
    width: 100%;
}

body #chat-container {
    flex-grow: 1; /* Takes central space */
    height: 100%; /* Fill parent (#content-area) vertically */
    overflow: hidden; /* Contain chat screen */
    display: flex; /* Keep flex */
    flex-direction: column; /* Keep column */
    background-color: var(--bg-surface); /* Ensure background */
}

body #chat-screen #chat-container {
    display: flex !important; /* Ensure chat screen is visible (overrides display: none) */
    flex-grow: 1; /* Takes space above disclaimer */
    height: 100%; /* Fill chat-container */
    overflow: hidden; /* Contain sidebar/chat-area */
    width: 100%;
}

/* --- Enable Internal Scrolling for Components --- */

body #chat-screen {
    height: 100%; /* Fill chat screen vertically */
    display: flex; /* Needed for internal flex layout */
    overflow: hidden; /* Hide overall sidebar overflow */
    /* Keep width/flex-shrink */
    width: 20%;
    flex-shrink: 0;
}

body #chat-screen #sidebar #user-list {
    flex-grow: 1; /* Allow list to take space within sidebar */
    overflow-y: auto; /* << ENABLE SCROLLING FOR USER LIST >> */
    min-height: 0; /* Flex calculation helper */
}


body #chat-screen #chat-area {
    height: 100%; /* Fill chat screen vertically */
    display: flex; /* Needed for internal flex layout */
    flex-direction: column;
    overflow: hidden; /* Contain messages/input */
    width: 100%; /* Ensure it takes remaining width */
}

body #chat-screen #chat-area #chat-messages {
    flex-grow: 1; /* Take space above input */
    overflow-y: auto; /* << ENABLE SCROLLING FOR MESSAGES >> */
    min-height: 0; /* Flex calculation helper */
    /* Keep padding, background etc. */
    padding: 1.5rem;
    background-color: var(--bg-surface);
}

body #chat-screen #chat-area #message-input-area {
    flex-shrink: 0; /* Prevent input area from shrinking */
    /* Keep other styles */
    border-top: 1px solid var(--border-color);
    background-color: var(--light-grey);
}

/* Ensure disclaimer is not affecting chat screen height */
body #chat-container > #disclaimer {
    flex-shrink: 0;
    /* margin-top: auto; -- This might not be needed if chat-screen has flex-grow */
}
