/*
 * Matte Black
 * By: @s1lv3r:wolfgirl.pet
 *
 * Largely based and expanded upon https://css.gomuks.app/theme/cinnytheme by @katja:conduwuit.ctucx.de,
 * other parts are commented where relevant.
 */

:root {
  --text-color: #ebebeb;
  --background-color: #141414;
  --border-color: #404040;

  --message-bubble-background-color: #202020;
  --message-mention-background-color: var(--background-color);
  --message-mention-background-color-hover: #303030;

  --space-list-background-overlay: #1a1a1a;
  --room-list-background-overlay: #1a1a1a;

  --composer-background-color: #333;

  --timeline-vertical-padding: 0.25rem;
  --timeline-message-gap-same-sender: 0;
  --timeline-sender-name-content-gap: 0.3rem;
  --timeline-hover-bg-color: #171717;   /* Background behind message bubbles when hovered */
  --timeline-highlight-bg-color: #3312; /* Messages mentioning you */
  --timeline-highlight-hover-bg-color: #3315;

  --message-font: "JetBrains Mono", "Sauce Code Pro NFM", monospace;
  --monospace-font-stack: var(--message-font);
}

/* Show back button on mobile and small screens */
@media (min-width: 721px) {
  button.back {
    display: none;
  }
}

/* Make all text follow the --message-font (monospace) */
*,
*::placeholder,
*::-moz-placeholder {
  font-family: var(--message-font) !important;
}

/* Prettier avatars */
img.avatar {
  border-radius: 20%;
}

/* Various layout changes and improvements on the left side */
div.room-list-wrapper {
  grid-template:
    "spacebar search" var(--window-top-margin)
    "spacebar roomlist" 3.5rem
    "spacebar roomlist" 1fr
    "profile profile" /
    3rem 1fr;
  grid-template-rows: 3.5rem 2fr;
  grid-template-columns: 3.9rem 1fr;
}
div.room-search-wrapper {
  height: unset;
}
div.room-list-wrapper,
div.space-bar {
  border-right: 1px solid var(--border-color);
}
div.room-header,
div.room-search-wrapper {
  border-bottom: 1px solid var(--border-color);
}
div.space-entry,
div.message-composer {
  border: 1px solid var(--border-color);
  padding: 0.35rem;
}
div.profile-switcher {
  border-top: 1px solid var(--border-color);
  padding: 0.35rem;
}
div.room-entry {
  width: unset;
  padding: 0.35rem;
}
div.space-entry {
  margin: 0.6rem !important;
}
div.space-entry[data-target-space] {
  border: 1px solid transparent;
}
div.message-composer {
  box-shadow: none;
}


/* Ensure tables scroll when overflowing */
div.html-body {
  overflow: scroll;
}

/*
 * Better tables
 * https://css.gomuks.app/theme/better-tables 
 */
.html-body {
  table {
    border-collapse: collapse;
    display: table;
    border-spacing: 0;
  }

  table th {
    border: 2px solid var(--border-color);
  }

  table tr {
    background-color: var(--timeline-hover-bg-color);
  }

  table tr:nth-child(2n) {
    background-color: var(--background-color);
  }

  table td {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
  }
}

/*
 * Bubble messages
 * Modified from original: https://css.gomuks.app/theme/bubblemuks
 */
.timeline-event {
  &.small-event {
    color: #888;
    font-size: 0.8rem;

    .sender-avatar {
      height: 100% !important;
      width: 100% !important;
    }

    .event-time-only {
      max-height: 1.1rem;
    }
  }

  /* Spacing around sender time */
  .event-sender-and-time .event-time {
    margin-left: 0.2rem;
    margin-right: 0.3rem;
  }

  /* Time on left of message hidden unless hover */

  &:hover:not(.small-event) > .event-time-only {
    display: flex !important;
  }

  &:not(.small-event) {
    padding-top: 2px;
    padding-bottom: 2px;
  
    .event-time-only {
      display: none !important;    
    }

    /* Multiple bubbles after each other, first one: */
    &:has(+ .same-sender) .event-content {
      border-bottom-left-radius: 0;
    }
    /* Second and following */
    &.same-sender .event-content {
      border-top-left-radius: 0;
    }

    .event-content {
      width: 90%;
      max-width: max-content;
      border-radius: 1.25rem;

      padding: 0.5rem 0.75rem;
      background: var(--message-bubble-background-color);
    }
  }

  /* Spacing around reactions */
  .event-reactions {
    margin-bottom: 0;
    margin-top: 0.6rem;
  }

}


/* Add background to user and room mentions to make them stand out more */
.hicli-matrix-uri-user,
.hicli-matrix-uri-user-id,
.hicli-matrix-uri-room-alias,
.hicli-matrix-uri-room-id {
  background-color: var(--message-mention-background-color) !important;
  transition: background 80ms ease;
  max-width: 15rem !important;
  overflow: hidden;
  text-overflow: ellipsis !important;
  border-radius: 1rem !important;
  padding: 0 0.5rem !important;
  text-decoration: none !important;
  color: currentColor;

  &:hover {
      background-color: var(--message-mention-background-color-hover) !important;
  }
}

/* Some extra padding for code blocks - Theme should be set in gomuks settings */
.timeline-event .event-content .message-text pre {
  padding-top: 0.3rem;
  margin-top: 0.6rem !important;
  margin-bottom: 0.6rem !important;
}

/* Always show ID in member list */
.member-list .member {
  grid-template: "avatar  displayname" 1.75rem "avatar  userid" 1.25rem / 2.5rem 1fr !important;
  div.displayname {
    align-self: end !important;
  }
  div.user-id {
    display: block !important;
    align-self: start;
  }
}

/* Bottom "XXX is typing" padding */
.room-view .typing-notifications {
  margin-top: 2px;
  margin-bottom: 2px;
}