/* Keep existing styles from your previous file */
body {
    font-family: sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #f0f0f0;
    margin: 0;
}

#chat-container {
    width: 90%;
    max-width: 800px;
    height: 90vh;
    max-height: 900px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent content spillover */
}

h1 {
    text-align: center;
    color: #333;
    margin: 15px 0;
    font-size: 1.5em;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

#status {
    padding: 5px 15px;
    font-size: 0.8em;
    color: #888;
    text-align: center;
    border-bottom: 1px solid #eee;
    min-height: 1.2em; /* Prevent layout shift */
}

#messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px; /* Space between messages */
}

.message {
    padding: 8px 12px;
    border-radius: 15px;
    max-width: 75%;
    word-wrap: break-word; /* Allow long words/links to wrap */
    position: relative; /* Needed for potential absolute elements inside */
    display: flex; /* Use flex for better internal alignment */
    flex-direction: column; /* Stack sender/content vertically */
}

.message.sent {
    background-color: #007bff;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

.message.received {
    background-color: #e9e9eb;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
}

.message .sender {
    /* display: block; No longer needed with flex column */
    font-size: 0.75em;
    font-weight: bold;
    margin-bottom: 4px;
    color: inherit; /* Inherit color from parent */
    opacity: 0.8;
}
.message.received .sender {
    color: #555; /* Slightly darker sender name for received */
}

.message-content {
    font-size: 0.95em;
    line-height: 1.4;
}

/* Styling for Markdown content within messages */
.message-content p {
    margin: 0 0 5px 0; /* Adjust paragraph spacing */
}
.message-content p:last-child {
    margin-bottom: 0;
}
.message-content a {
    color: inherit; /* Use message text color */
    text-decoration: underline;
}
.message.sent a {
     color: #bee3ff; /* Lighter blue for links in sent messages */
}
.message.received a {
     color: #0056b3; /* Darker blue for links in received messages */
}
.message-content code {
    background-color: rgba(0, 0, 0, 0.08);
    padding: 2px 5px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
}
.message-content pre {
    background-color: rgba(0, 0, 0, 0.08);
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto; /* Allow horizontal scrolling for code blocks */
    margin: 5px 0;
}
.message-content pre code {
    background-color: transparent; /* Don't double background */
    padding: 0;
    border-radius: 0;
}
.message-content blockquote {
    border-left: 3px solid rgba(0, 0, 0, 0.2);
    padding-left: 10px;
    margin: 5px 0 5px 5px;
    font-style: italic;
    color: #555;
}
.message.sent .message-content blockquote {
    border-left-color: rgba(255, 255, 255, 0.5);
    color: #eee;
}

.message .warning {
    font-size: 0.75em;
    font-style: italic;
    opacity: 0.8;
    margin-left: 5px;
}

.message.system {
    align-self: center;
    background-color: #f8f9fa;
    color: #6c757d;
    font-size: 0.8em;
    font-style: italic;
    max-width: 90%;
    text-align: center;
}

/* Staged Files Display Area */
#staged-files-display {
    padding: 10px 15px; /* Consistent padding */
    max-height: 120px; /* Increased height for previews */
    overflow-y: auto; /* Allow scrolling if many files */
    background-color: #f8f9fa; /* Match input area background */
    border-top: 1px solid #eee; /* Separator line */
    display: flex; /* Use flexbox for layout */
    flex-wrap: nowrap; /* Prevent wrapping, allow horizontal scroll */
    overflow-x: auto; /* Horizontal scroll for many files */
    gap: 10px; /* Space between items */
}

.staged-file-item {
    background-color: #e9ecef;
    padding: 5px;
    border-radius: 8px; /* Slightly less rounded */
    font-size: 0.8em;
    display: flex;
    flex-direction: column; /* Stack preview and info */
    align-items: center;
    gap: 4px;
    width: 70px; /* Fixed width for consistency */
    flex-shrink: 0; /* Prevent items from shrinking */
    border: 1px solid #ddd;
    position: relative; /* For remove button positioning */
}

.staged-preview {
    width: 50px;
    height: 50px;
    background-color: #ccc; /* Placeholder background */
    border-radius: 4px;
    overflow: hidden; /* Clip content to square */
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #bbb;
}

.staged-preview img,
.staged-preview video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover; /* Scale and crop to fill square */
}

.staged-preview .file-icon {
    font-size: 2em; /* Larger icon */
    color: #666;
}

.staged-file-info {
    font-size: 0.85em;
    text-align: center;
    width: 100%; /* Take full width */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 3px; /* Small side padding */
    color: #333;
}

.staged-file-item button.remove-staged {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: rgba(255, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 12px;
    line-height: 16px; /* Center the 'x' */
    text-align: center;
    cursor: pointer;
    padding: 0;
    transition: background-color 0.2s;
}
.staged-file-item button.remove-staged:hover {
    background-color: rgba(255, 0, 0, 1);
}


#input-area {
    display: flex;
    padding: 10px;
    /* border-top: 1px solid #eee; Removed, moved to staged files display */
    background-color: #f8f9fa;
    position: relative; /* Needed for absolute positioning of upload button */
}

/* Style for the file upload button */
#upload-button {
    background: none;
    border: none;
    font-size: 1.5em; /* Make icon larger */
    cursor: pointer;
    padding: 0 10px; /* Add some padding */
    color: #6c757d;
    transition: color 0.2s;
    position: absolute; /* Position inside the input area */
    left: 10px;       /* Align to the left */
    top: 50%;         /* Center vertically */
    transform: translateY(-50%);
    z-index: 2;       /* Ensure it's above the text input */
}

#upload-button:hover {
    color: #343a40;
}

#message-input {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: 20px;
    padding: 10px 15px 10px 45px; /* Add left padding for the upload button */
    font-size: 1em;
    resize: none; /* Prevent manual resize if it were a textarea */
    margin-right: 10px;
    transition: border-color 0.2s;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

#message-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1), 0 0 0 2px rgba(0, 123, 255, 0.25);
}

#send-button {
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s;
}

#send-button:hover {
    background-color: #0056b3;
}

/* Styles for File Transfer Messages */
.message.file-transfer {
    /* Use existing message styles */
    gap: 8px; /* Space between elements inside */
}

/* Container for file preview and details */
.file-transfer-content {
    display: flex;
    align-items: flex-start; /* Align items to the top */
    gap: 10px;
    width: 100%; /* Take full width within message bubble */
}

.file-preview {
    width: 60px; /* Square size */
    height: 60px;
    background-color: #ccc; /* Placeholder background */
    border-radius: 4px;
    overflow: hidden; /* Clip content */
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #bbb;
    flex-shrink: 0; /* Prevent shrinking */
}
.message.sent .file-preview {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}
.message.received .file-preview {
    background-color: #ddd;
    border-color: #ccc;
}


.file-preview img,
.file-preview video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover; /* Scale and crop */
}

.file-preview .file-icon {
    font-size: 2.5em; /* Larger icon */
    color: #666;
}
.message.sent .file-preview .file-icon {
    color: rgba(255, 255, 255, 0.7);
}


/* Container for file info, progress, status, download */
.file-details {
    flex-grow: 1; /* Take remaining space */
    min-width: 0; /* Allow flex item to shrink */
    display: flex;
    flex-direction: column;
    justify-content: center; /* Vertically center content */
    gap: 4px;
}


.file-info {
    font-weight: bold;
    margin-bottom: 0; /* Adjusted spacing */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 0.85em;
    opacity: 0.9;
}
.message.sent .file-size {
    opacity: 0.8;
}


.file-progress-container {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    height: 8px; /* Slightly thinner */
    /* margin-top: 5px; */
    /* margin-bottom: 5px; */
    overflow: hidden; /* Ensure progress bar stays within bounds */
}
.message.sent .file-progress-container {
     background-color: rgba(255, 255, 255, 0.2);
}


.file-progress-bar {
    width: 0%; /* Start at 0% */
    height: 100%;
    background-color: #28a745; /* Green for progress */
    border-radius: 5px;
    transition: width 0.1s linear; /* Smooth progress update */
}

/* Hide progress bar when transfer is complete */
.message.file-transfer.transfer-complete .file-progress-container {
    display: none;
}

.file-status {
    font-size: 0.8em;
    font-style: italic;
    color: #555;
    /* margin-top: 3px; */
}
.message.sent .file-status {
    color: rgba(255, 255, 255, 0.85);
}
.message.received .file-status {
    color: #555;
}

/* NEW: Style for clickable download status */
.message.received .file-status.clickable-download {
    color: #0056b3; /* Link color */
    text-decoration: underline;
    cursor: pointer;
    font-style: normal; /* Remove italic */
    font-weight: bold;
}
.message.received .file-status.clickable-download:hover {
    color: #003d80; /* Darker hover */
}


/* REMOVED Download Link Styles (No longer needed for received) */
/* .download-link { ... } */
/* .download-link:hover { ... } */
/* .download-link[disabled] { ... } */
/* .message.sent .download-link[disabled] { ... } */


/* Responsive Adjustments */
@media (max-width: 600px) {
    #chat-container {
        width: 100%;
        height: 100vh;
        max-height: none;
        border-radius: 0;
    }
    h1 {
        font-size: 1.2em;
    }
    .message {
        max-width: 90%;
    }
    #staged-files-display {
        max-height: 100px; /* Adjust height */
        padding: 8px 10px;
    }
    .staged-file-item {
        width: 65px; /* Slightly smaller */
    }
    .staged-preview {
        width: 45px;
        height: 45px;
    }
     .staged-preview .file-icon {
        font-size: 1.8em;
    }
    .staged-file-info {
        font-size: 0.8em;
    }
    .staged-file-item button.remove-staged {
        width: 16px;
        height: 16px;
        font-size: 11px;
        line-height: 15px;
    }
    #upload-button {
        font-size: 1.3em;
        padding: 0 8px;
    }
    #message-input {
        padding-left: 40px; /* Adjust padding for smaller button */
        font-size: 0.95em;
    }
    #send-button {
        padding: 8px 15px;
        font-size: 0.95em;
    }
    .file-preview {
        width: 50px;
        height: 50px;
    }
     .file-preview .file-icon {
        font-size: 2em;
    }
}