:root {
  --accent: hsl(222, 57%, 47%);
  --selected-message: rgb(163, 163, 163);
  --selected-message-accent: rgb(108, 152, 255);
  --text-color: #1e1e1e;
  --text-on-accent: #fff;
  --bg: #c8c8c8;
  --alt-bg: #dedede;
  --alt-alt-bg: #ccc;
  --alt-fg: #555;
  --border-radius: 12px;
  --border-radius-text-bubble: 12px;
  --border-radius-small: 2px;
  --reply-bg: rgba(0, 0, 0, 0.2);
  --green: green;
  --green-on-accent: rgb(102, 255, 102);
  --pre-bg: var(--reply-bg);
  accent-color: var(--accent);
}

* {
  /* margin: 0;
    padding: 0; */
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  scroll-behavior: smooth;
}

body {
  display: grid;
  grid-template-columns: auto;
  grid-template-rows: 4rem auto 6rem 0 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  line-height: 1.5rem;
  background: var(--bg);
  color: var(--text-color);
  transition: all 0.3s ease;
  margin: 0;
  padding: 0;
}

.settings-modal-backdrop {
  position: fixed;
  background: transparent;
  backdrop-filter: blur(20px);
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  top: -100vh;
}

#time-blocker[open] {
  height: 100%;
  width: 100%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  outline: 0px;
  flex-direction: column;
  border: none;
}

#time-blocker[open] h1 {
  font-weight: normal;
  font-size: 2rem;
}

#time-blocker[open] .countdown {
  margin: 2rem auto;
  padding: 0.75rem;
  border-radius: 12px;
  text-align: center;
  font-size: 1.5rem;
  font-family: monospace;
  background: var(--alt-bg);
}

.settings-modal {
  padding: 1rem;
  border-radius: var(--border-radius);
  background: var(--alt-bg);
  width: 60ch;
  max-width: 90%;
  z-index: 3;
  position: relative;
  top: -2rem;
  opacity: 0;
  transition: all 0.4s ease;
}

.settings-modal-backdrop.open {
  backdrop-filter: blur(20px);
  top: 0;
}

.settings-modal-backdrop.open .settings-modal {
  opacity: 1;
  top: 0;
}

form#settings-form {
  height: 100%;
  width: 100%;
}

#settings-form ul {
  list-style-type: none;
  width: 100%;
  padding-left: 0;
}

#settings-form input[type="checkbox"] {
  accent-color: var(--accent);
}

#settings-form .controls {
  width: 100%;
  display: flex;
  justify-content: flex-end;
}

#settings-form .controls button {
  margin: 0 0.5rem;
}

/* loading bar */

.loading-bar {
  opacity: 0;
  width: 10rem;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  height: 1rem;
  background: var(--alt-bg);
  transition: all 0.2s ease;
  border-radius: 100px;
}

.loading-bar .loaded {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.1s ease;
  border-radius: 100px;
}

#compression-progress-bar-text {
  opacity: 0;
  font-size: 0.8rem;
  transition: all 0.2s ease;
}
/*  */

nav {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--alt-bg);
  padding: 1rem;
}

.header-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  margin-left: 1rem;
}

.request-notifications {
  visibility: hidden;
}

#messages {
  overflow: auto;
}

.timestamp {
  opacity: 0.6;
}

.message {
  display: flex;
  flex-direction: column;
  width: fit-content;
  padding: 0.25rem 0.5rem 0.25rem 0.5rem;
  margin: 0.8rem;
  margin-bottom: 0.5rem;
  background: var(--alt-bg);
  border-radius: var(--border-radius-text-bubble);
  border-top-left-radius: var(--border-radius-small);
  /* transition: opacity 0.3s ease; */
  animation: message-animation 0.2s ease;
  max-width: 90%;
}

.message.from-history {
  animation: none;
}

.message.img-message {
  background: transparent;
}

@keyframes message-animation {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.message:target {
  background: var(--selected-message);
}

.own-message:target {
  background: var(--selected-message-accent);
}

.message:last-of-type {
  margin-bottom: 1rem;
}

.message-header {
  font-size: 0.7rem;
  line-height: 1rem;
  display: inline-flex;
  justify-content: left;
  flex-direction: row;
}

.message-header .spacer {
  width: 0.7rem;
}

.message-content {
  padding: 0 0.2rem 0.2rem 0.2rem;
  width: 100%;
  max-width: 60ch;
  line-height: 150%;
  overflow: auto;
}

.own-message {
  background: var(--accent);
  color: var(--text-on-accent);
}

.own-message + .own-message {
  padding-top: 0.1rem;
  margin-top: 0;
}

.own-message + .own-message .message-header,
.own-message + .info + .own-message .message-header
/*,.not-own-message + .not-own-message .message-header,
.not-own-message + .info + .not-own-message .message-header*/ {
  display: none;
}

.message h1,
.message h2,
.message h3 {
  line-height: 150%;
}

.message ul,
.message ol {
  padding-left: 1rem;
}

p {
  margin: auto;
}

/* .message p:not(:last-of-type),
.message li {
    margin: 0.3rem 0 0.3rem 0;
} */

.message pre {
  font-size: 1rem;
  max-width: 100%;
  background: var(--pre-bg);
  overflow: auto;
  padding: 0.5rem;
  border-radius: var(--border-radius-small);
}

li::marker {
  opacity: 0.8;
}

blockquote {
  color: var(--green);
  margin: 0;
}

blockquote p::before {
  content: "> ";
  color: var(--green);
}

.own-message blockquote {
  color: var(--green-on-accent);
}

.reply-section {
  width: 100%;
  background: var(--reply-bg);
  border-left: 2px solid var(--text-color);
  border-radius: 0 var(--border-radius-small) var(--border-radius-small) 0;
  font-size: 0.8rem;
  padding: 0 0.5rem;
  margin: 0.2rem 0;
  transform: translateY(1px);
  color: var(--text-color);
}

.own-message .reply-section {
  border-color: var(--text-on-accent);
}

.reply-section > a {
  text-decoration: none;
}

.reply-section .sender {
  font-size: 0.6rem;
  color: var(--text-color);
  font-weight: bold;
}

.reply-section .content {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  color: var(--text-color);
  overflow: hidden;
  /* max-height: 5rem; */
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.own-message .reply-section .sender,
.own-message .reply-section .content {
  color: var(--text-on-accent);
}

img.message-content {
  padding: 0;
  max-width: 600px;
  max-height: 70vh;
  border-radius: var(--border-radius);
}

.message-content.emoji {
  margin: 1rem 1rem;
  font-size: 3.5rem;
  background: transparent;
}

.audio-wrapper {
  padding-bottom: 0;
  padding-top: 0.75rem;
}

.message audio::-webkit-media-controls-enclosure {
  padding-bottom: 0.2rem;
  background: var(--alt-bg);
  color: var(--accent);
}

.message.own-message audio::-webkit-media-controls-enclosure {
  background: var(--accent);
}

.message.reply-message {
  min-width: 10ch;
}

.message.info {
  flex-direction: row;
  justify-content: center;
  align-items: center;
  font-size: 0.8rem;
  opacity: 0.7;
  padding: 0;
  width: 95%; /*100% causes overflow*/
  background: transparent;
}

.message.info .message-content {
  background: transparent;
  padding: 0.1rem 0.8rem 0.1rem 0.8rem;
  text-align: center;
}

.indicators {
  width: fit-content;
  padding-right: 1rem;
}

.indicator-typing,
.indicator-recording-audio {
  opacity: 0;
  font-size: 0;
  color: var(--text-color);
  transition: all 0.2s;
  transform: translateY(-2rem);
  font-size: 0.8rem;
}

.indicator-typing.visible,
.indicator-recording-audio.visible {
  opacity: 1;
  font-size: 0.8rem;
}

.indicator-typing.visible {
  transform: translateY(0.75rem);
}

.indicator-recording-audio.visible {
  transform: translateY(-0.75rem);
}

.replying-to {
  position: fixed;
  bottom: 5rem;
  font-size: 0.8rem;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: start;
  transition: transform 0.2s ease, opacity 0.2s linear;
  background: var(--alt-bg);
  width: 100%;
  border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.replying-to.hidden {
  transform: translateY(100%);
  opacity: 0;
  visibility: hidden;
}

.replying-to .header {
  width: 100%;
  display: flex;
  align-items: center;
  position: relative;
  top: 0.75rem;
  height: 0;
  right: 0;
  justify-content: flex-end;
}

.replying-to button {
  border-radius: 999px;
  font-size: 1.2rem;
  background: transparent;
  cursor: pointer;
  border: none;
  font-weight: bold;
  padding: 0.5rem;
  margin-left: 0.3rem;
  display: flex;
  align-items: center;
}

.replying-to button .text {
  font-size: 0.8rem;
  padding-left: 0.5rem;
}

/* .replying-to .left {
    max-height: 5rem;
} */

.msg-preview {
  overflow: auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 6rem;
  border-left: 2px solid var(--text-color);
  padding: 0.2rem 0.5rem;
  border-radius: var(--border-radius-small);
  background: var(--reply-bg);
}

.msg-preview .sender {
  font-weight: bold;
  font-size: 0.6rem;
}

#message-form {
  display: grid;
  grid-template-columns: auto 4rem 4rem 4rem;
  background: var(--alt-bg);
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  height: 100%;
  transition: all 0.2s ease;
  overflow: clip; /* Fixes border radius for buttons on the left side */
}

#message-input {
  background: transparent;
  color: var(--text-color);
  border: none;
  font-size: 1rem;
  padding: 0.8rem;
  resize: none;
  border-radius: var(--border-radius) 0 0 0;
  width: 100%;
  margin: auto;
  height: fit-content;
  overflow: auto;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

#message-input.monospace-editor {
  font-family: monospace;
  height: 100%;
}

#message-input:focus {
  outline: none;
}

#message-form:focus-within {
  border-bottom: 4px solid var(--accent);
}

#file-input {
  opacity: 0;
  position: fixed;
  top: -100;
  width: 0;
}

#message-send-button.hidden {
  position: fixed;
  bottom: -100vh;
}

#message-form[data-buttons="2"] {
  grid-template-columns: auto 4rem 4rem;
}

#message-form[data-buttons="3"] {
  grid-template-columns: auto 4rem 4rem 4rem;
}

.action-button {
  border: none;
  background: var(--alt-bg);
  color: var(--alt-fg);
  padding: 0.6rem 1rem;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.action-button label {
  height: 100%;
  width: 100%;
}

.action-button.highlighted {
  background: var(--accent);
  color: var(--text-on-accent);
}

.action-button:hover {
  background: var(--alt-alt-bg);
}

#recording-button.is-recording {
  background: rgb(42, 128, 42);
  color: var(--text-on-accent);
  animation: pulse-red linear 6s infinite;
}

@keyframes pulse-red {
  0% {
    background: rgb(42, 128, 42);
  }
  25% {
    background: rgb(72, 228, 72);
  }
  50% {
    background: rgb(42, 128, 42);
  }
  75% {
    background: rgb(72, 228, 72);
  }
  100% {
    background: rgb(42, 128, 42);
  }
}

#message-form .button-next-to-text-input {
  border-radius: 0;
}

.img-preview-modal {
  height: 100vh;
  width: 100vw;
  z-index: 2;
  background: rgba(0, 0, 0, 0.6);
  position: fixed;
  top: -100vh;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  transition: all 0.4s ease;
  backdrop-filter: blur(10px);
}

.img-preview-modal .loading-spinner {
  position: fixed;
  top: 45%;
  left: 45%;
  z-index: 3;
}

.img-preview-modal img {
  position: relative;
  z-index: 4;
}

.img-preview-modal label {
  text-align: center;
  cursor: pointer;
}

.img-preview-modal button {
  margin: 1rem 0.5rem;
}

.horizontal-btn-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#login-dialog {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: var(--bg);
  z-index: 2;
  transition: all 0.2s ease;
}

#login-dialog h1 {
  color: var(--alt-fg);
  font-size: 3rem;
  line-height: 6rem;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

#login-dialog input {
  border: 1px solid var(--alt-bg);
  background: var(--alt-bg);
  border-radius: var(--border-radius);
  padding: 0.5rem 1rem;
  font-size: 1rem;
  color: var(--text-color);
  margin: 0.5rem;
}

#login-dialog button[type="submit"] {
  margin: 1rem auto;
  width: 80%;
}

#login-dialog.closed {
  top: -100%;
  visibility: hidden;
}

@media screen and (prefers-color-scheme: dark) {
  :root {
    --accent: hsl(222, 68%, 32%);
    --text-color: #dedede;
    --alt-bg: #1e1e1e;
    --alt-alt-bg: #333;
    --alt-fg: #dedede;
    --bg: #000;
    --selected-message: rgb(163, 163, 163);
    --selected-message-accent: rgb(108, 152, 255);
    --green: var(--green-on-accent);

    color-scheme: dark;
  }
  .action-button img,
  .header-btn img {
    filter: invert(100%);
  }
  /* .message audio::-webkit-media-controls-enclosure {
    filter: invert(1);
  } */
}

@media screen and (max-width: 600px) {
  .message.own-message {
    align-items: flex-end;
    margin-left: auto;
  }

  .own-message {
    border-top-right-radius: var(--border-radius-small);
    border-top-left-radius: var(--border-radius-text-bubble);
  }

  .own-message .message-header {
    flex-direction: row-reverse;
  }

  /* .own-message .reply-section {
        border-left: none;
        border-right: 2px solid var(--accent);
        border-top-right-radius: var(--border-radius);
    } */

  #message-input {
    resize: none;
  }

  img.message-content {
    max-width: 100%;
  }

  #login-dialog {
    padding: 3rem 0 3rem 0;
    justify-content: space-between;
  }
}
