body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f0f2f5;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}
.chat-container {
    width: 100%;
    max-width: 600px;
    height: 80vh;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    position: relative;
}
.chat-header {
    padding: 1rem;
    border-bottom: 1px solid #ddd;
    background-color: #f7f7f7;
    border-radius: 8px 8px 0 0;
}
.chat-header h2 { margin: 0; font-size: 1.2rem; }
#status { font-size: 0.9rem; color: #666; }
#typing-status { font-size: 0.8rem; color: #007bff; height: 1.2em; font-style: italic; }
.chat-messages {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.message {
    margin-bottom: 1rem;
    padding: 0.5rem 0.8rem;
    border-radius: 18px;
    max-width: 80%;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
    display: flex;
    flex-direction: column;
}
.message.sent {
    background-color: #0084ff;
    color: white;
    align-self: flex-end;
    border-radius: 18px 18px 5px 18px;
}
.message.received {
    background-color: #e4e6eb;
    color: #050505;
    align-self: flex-start;
    border-radius: 18px 18px 18px 5px;
}
.message.system {
    align-self: center;
    background-color: #f0f0f0;
    color: #555;
    font-size: 0.85rem;
    font-style: italic;
    width: auto;
    max-width: 80%;
    text-align: center;
}
.message-content {
    /* <<< 修改：減少 padding-bottom，因為不再需要為已讀標記留空間 >>> */
    padding-bottom: 0.8em; 
}
.message-content a {
    color: inherit;
    text-decoration: underline;
}
.message.sent .message-content a { color: #fff; }
.timestamp {
    font-size: 0.7em;
    color: #a0a0a0;
    position: absolute;
    bottom: 5px;
    right: 12px;
}
.message.sent .timestamp { color: #e0e0e0; }

/* <<< 移除 .read-receipt 的所有樣式 >>> */

.chat-input { padding: 1rem; border-top: 1px solid #ddd; display: flex; gap: 10px; }
#message-input { flex-grow: 1; border: 1px solid #ccc; border-radius: 20px; padding: 0.75rem; font-size: 1rem; }
#message-input:disabled { background-color: #f5f5f5; }
button { padding: 0.75rem 1.5rem; border: none; background-color: #0084ff; color: white; border-radius: 20px; cursor: pointer; font-size: 1rem; transition: background-color 0.2s; white-space: nowrap; }
button:hover { background-color: #0073e6; }
button:disabled { background-color: #a0c0e0; cursor: not-allowed; }
#disconnect-btn { background-color: #e42626; }
#disconnect-btn:hover { background-color: #c01f1f; }
.link-preview {
    margin-top: 8px;
    background-color: rgba(0,0,0,0.05);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    font-size: 0.85em;
    max-width: 320px;
    border: 1px solid rgba(0,0,0,0.08);
}
.message.sent .link-preview { background-color: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.2); }
.link-preview img {
    width: 65px;
    height: 65px;
    object-fit: cover;
    flex-shrink: 0;
    border-right: 1px solid rgba(0,0,0,0.08);
}
.message.sent .link-preview img { border-right: 1px solid rgba(255,255,255,0.2); }
.preview-content { padding: 8px 12px; flex: 1; overflow: hidden; }
.preview-title { font-weight: bold; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.preview-description {
    font-size: 0.9em;
    opacity: 0.8;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}