/* One message and everything that can be in it: formatted text, quotes,
   pictures, files, link previews, reactions, polls. */

/* Two columns: a gutter for the sender's picture, then the message. */
.msg {
    position: relative;
    display: flex;
    gap: var(--space-7);
    padding: var(--space-1) var(--space-8);
    margin-top: var(--space-7);
}

/* A message that follows another of the same sender sits close under it. */
.msg.follows {
    margin-top: 0;
}

.msg:hover {
    background: var(--color-hover);
}

.msg.highlight {
    box-shadow: inset 3px 0 var(--color-accent);
    background: var(--color-highlight);
}

.msg .gutter {
    width: var(--avatar-size-message);
    flex: none;
    text-align: right;
}

/* The time of a following message, shown when pointed at. */
.msg .gutter .time {
    visibility: hidden;
    line-height: calc(var(--line-height) * 1rem);
}

.msg:hover .gutter .time {
    visibility: visible;
}

.msg-main {
    flex: 1;
    min-width: 0;
}

.msg-head {
    display: flex;
    align-items: baseline;
    gap: var(--space-5);
}

.msg .sender {
    font-weight: 600;
}

.msg.mine .sender {
    color: var(--color-accent);
}

.msg .time, .msg .edited {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

.msg .body {
    white-space: pre-wrap;
    word-break: break-word;
}

.msg.redacted .body {
    font-style: italic;
}

/* What can be done with a message: a small toolbar over its top right
   corner, there when the message is pointed at. */
.msg .actions {
    position: absolute;
    top: calc(var(--control-size) / -2);
    right: var(--space-8);
    z-index: 1;
    visibility: hidden;
    display: flex;
    padding: var(--space-1);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-m);
}

.msg:hover .actions, .msg .actions:focus-within {
    visibility: visible;
}

/* With no pointer to hover with, a tap on the message opens them, and only
   that: what the finger last touched counts as hovered for too long. */
@media (hover: none) {
    .msg:hover {
        background: none;
    }

    .msg:hover .actions, .msg:hover .gutter .time {
        visibility: hidden;
    }

    .msg.open {
        background: var(--color-hover);
    }

    .msg.open .actions, .msg.open .gutter .time {
        visibility: visible;
    }

    .msg .actions .icon-button {
        min-width: 2.6rem;
        height: 2.6rem;
    }
}

.reply-quote {
    display: block;
    border-left: 3px solid var(--color-border);
    padding: var(--space-1) var(--space-5);
    margin: var(--space-2) 0;
    color: var(--color-text);
    font-size: var(--text-s);
}

.reply-quote .sender {
    margin-right: var(--space-4);
}

.body p {
    margin: var(--space-2) 0;
}

.body h1, .body h2, .body h3, .body h4, .body h5, .body h6 {
    margin: var(--space-4) 0 var(--space-2);
}

.body blockquote {
    border-left: 3px solid var(--color-border);
    margin: var(--space-3) 0;
    padding: var(--space-1) var(--space-6);
    color: var(--color-text-muted);
}

.body pre {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-m);
    padding: var(--space-6);
    overflow-x: auto;
}

.body code {
    font-size: .9em;
}

.body ul, .body ol {
    margin: var(--space-2) 0;
    padding-left: var(--space-9);
}

.body table {
    border-collapse: collapse;
    margin: var(--space-3) 0;
}

.body th, .body td {
    border: 1px solid var(--color-border);
    padding: var(--space-2) var(--space-5);
}

/* A mention: the name, tinted with the accent. It is no link. */
.body .mention {
    background: color-mix(in srgb, var(--color-accent) 18%, transparent);
    border-radius: var(--radius-s);
    padding: 0 var(--space-2);
    color: var(--color-accent);
    font-weight: 500;
    text-decoration: none;
    cursor: default;
}

/* A mention of you is filled; RoomView writes that rule, since it names your id. */

.body .spoiler {
    background: var(--color-text);
    color: var(--color-text);
    border-radius: var(--radius-s);
    cursor: pointer;
}

.body .spoiler:hover {
    background: transparent;
}

.body .emote, .reaction .emote, .suggest .emote, .emoji-picker .emote {
    height: 1.6em;
    vertical-align: middle;
}

.body.notice-msg {
    color: var(--color-text-muted);
}

.body.emote-msg {
    font-style: italic;
}

.picture-link img {
    max-width: min(100%, 480px);
    max-height: 360px;
    border-radius: var(--radius-l);
    display: block;
    margin: var(--space-3) 0;
}

.attachment {
    display: inline-block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-m);
    padding: var(--space-4) var(--space-6);
    margin: var(--space-2) 0;
    color: var(--color-text);
}

.link-preview {
    display: flex;
    gap: var(--space-6);
    max-width: 520px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-accent);
    border-radius: var(--radius-m);
    padding: var(--space-5);
    margin: var(--space-3) 0;
    color: var(--color-text);
}

.link-preview img {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: var(--radius-s);
    flex: none;
}

.link-preview span {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
}

.link-preview small {
    color: var(--color-text);
    font-size: var(--text-s);
}

.reactions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-2);
}

.reaction {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    padding: var(--space-1) var(--space-5);
    font-size: var(--text-s);
    display: inline-flex;
    gap: var(--space-3);
    align-items: center;
}

.reaction.mine {
    border-color: var(--color-accent);
}

.poll {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-l);
    padding: var(--space-6) var(--space-7);
    margin: var(--space-3) 0;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.poll-q {
    font-weight: 600;
}

.poll-a {
    position: relative;
    text-align: left;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    overflow: hidden;
    display: flex;
    justify-content: space-between;
}

.poll-a.mine {
    border-color: var(--color-accent);
}

.poll-a .bar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: var(--color-fill);
    opacity: .7;
    z-index: 0;
}

.poll-a .label, .poll-a .count {
    position: relative;
    z-index: 1;
}

.poll-foot {
    font-size: var(--text-xs);
    display: flex;
    gap: var(--space-5);
    align-items: center;
}

.body.undecryptable {
    font-style: italic;
}

.sealed-image img {
    max-width: min(100%, 480px);
    max-height: 360px;
    border-radius: var(--radius-m);
    display: block;
}

.sealed-preview .link-preview img {
    max-width: 120px;
    max-height: 90px;
}

.sealed-preview .preview-image img {
    max-width: min(100%, 480px);
    max-height: 360px;
    border-radius: var(--radius-m);
    display: block;
}
