/* messages.css */
body {
  overflow: hidden;
}
.mainmid {
  user-select: none;
  height: 100%;
  position: absolute;
  margin-bottom: 5rem;
}
#messages-table {
  width: 100%;
  border-collapse: collapse;
}

.message-row td {
  border: none; /* remove default borders */
}

.message-bubble {
  display: block;
  max-width: 60%;
  word-wrap: break-word;
  font-family: sans-serif;
  font-size: 14px;
  line-height: 1.4;
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 15px;
  word-break: break-word; /* <--- important */
  position: relative;
}

.message-bubble img {
  max-width: 300px;         /* never wider than the bubble */
  max-height: 100%;       /* optional: cap the height */
  border-radius: 15px;     /* optional: match bubble corners */
  object-fit: contain;     /* scales but keeps aspect ratio */
  display: block;          /* remove inline gaps */
  box-sizing: border-box;
  transform: scale(1.004);
}


.message-row.them td {
  display: flex;
  align-items: flex-end;
  flex-direction: row;
}

.message-row.me .message-bubble {
  background-color: #0084ff;
  color: #fff;
  margin-left: auto; /* push to right */
  margin-right: 0;
  float: right;
  text-align: right;
}

/* reserve padding space on 'them' rows */
.message-row.them td {
  position: relative;
  padding-left: 38px; /* reserve space for portrait */
}

/* remove padding on the td that actually has the portrait */
.message-row.them td.has-avatar {
  padding-left: 0;
}

/* keep the avatar aligned bottom-left */
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  align-self: flex-end;
}


.message-row.them .message-bubble {
  background-color: #e5e5ea;
  color: #000;
  text-align: left;
  border-radius: 18px;
  padding: 8px 12px;
  max-width: 75%;
  word-wrap: break-word;
}


#messages-container {
  border: none;
  overflow-y: auto;
  padding: 8px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column-reverse;
}

/* remove table border so bubbles look nicer */
#messages-container table {
  border-collapse: collapse;
  width: 100%;
}

#messages-container th {
  position: sticky;
  top: 0;
  background: #f7f7f7;
}



#send-btn {
  background-color: #0084ff;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  transition: background 0.2s ease-in-out;
  align-self: stretch; /* match textarea height */
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

#send-btn:hover {
  background-color: #006fd1;
}



#contacts-container h1 {
  font-size: 16px;
  margin: 0;
  padding: 8px;
  background: #f7f7f7;
  border-bottom: 1px solid #ccc;
}

#contacts-container table {
  width: 100%;
  border-collapse: collapse;
}

#contacts-container th, 
#contacts-container td {
  border: none;
  padding: 6px;
  text-align: left;
  cursor: pointer;
}

#contacts-container tr:hover {
  background: #f0f0f0;
}

#contacts-container {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 100%;
  background: #f8f8f8;
  border: 1px solid #ccc;
  max-height: 300px;
  overflow-y: auto;
  background: 0;
  border: none;
}

/* Flex container */
#contacts-list {
  display: flex;
  flex-direction: row;   /* 👈 horizontal layout */
  flex-wrap: wrap;       /* wrap onto multiple rows */
  gap: 8px;
  padding-left: 1rem;
  padding-right: 1rem;
  user-select: none;
}

/* Contact tiles */
.contact-item {
  flex: 1 1 45%; /* 45% width -> two columns */
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 15px;
  padding: 6px;
  text-align: center;
  cursor: pointer;
  font-size: 14px;
  box-sizing: border-box;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  max-width: 10rem;
}

.contact-item:hover {
  background: #007bff;
  color: #fff;
}


#message-popup {
  position: absolute; /* anchor near the clicked contact */
  width: 320px;
  height: 70vh;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 15px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  z-index: 2000;
  transition: transform 0.3s ease, opacity 0.3s ease;
  will-change: transform, opacity;
  /* animation baseline */
  transform: translateY(20px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  will-change: transform, opacity;
}

#message-popup.visible {
  transform: translateY(0);
  opacity: 1;
}

.hidden {
  display: none;
}

#popup-input {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid #ccc;

}






/* Popup header bar */
#popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #007bff;          /* blue header */
  color: #fff;
  padding: .5rem .5rem;
  padding-left: 1rem;
  font-weight: bold;
  font-family: sans-serif;
  border-bottom: 1px solid #005fc5;
  border-top-left-radius: 8px;  /* match popup corners */
  border-top-right-radius: 8px;
  height: 1.5rem;
  user-select: none;         /* Standard */
  -webkit-user-select: none; /* Safari/Chrome */
  -moz-user-select: none;    /* Firefox */
  -ms-user-select: none;     /* IE/Edge */
  border-radius: 15px;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  cursor: grab;
}

#popup-header:active {
  cursor: grabbing;
}

/* Centered drag handle pill */
#popup-header::before {
  content: "";
  position: absolute;
  top: 4px;                 /* distance from the top */
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 2px;
  background: rgba(255,255,255,0.7);
  border-radius: 2px;
}
.drag-handle {
  position: absolute;
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 1px;
  background: rgba(255,255,255,0.7);
  border-radius: 2px;
}


#popup-header #popup-contact-name {
  font-size: 14px;
}

#popup-header #popup-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}
#popup-header #popup-close:hover {
  color: #ffdddd;
}







#gif-popup {
  position: absolute;
  top: 10rem;
  left: 50%;
  transform: translateX(-50%);
  width: 350px;
  height: 400px;
  background: #fff;
  border-radius: 15px;
  box-shadow: 0 8px 25px rgba(0,0,0,.2);
  display: flex;
  flex-direction: column;
  transition: transform .3s ease, opacity .3s ease;

    z-index: 9999;
}
#gif-btn {
  width: 3rem;
  background: #dca2ff;
  color: #fff;
  border-radius: 20px;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}
#gif-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #dca2ff;
  color: #fff;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  cursor: grab;
  user-select: none;
  padding-left: 1rem;
  padding-right: 1rem;
}

#gif-header span {
  margin-top: 4px;
}

#gif-header:active {
  cursor: grabbing;
}

#gif-header #gif-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  position: absolute;
  right: 7px;
}
#gif-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill,minmax(100px,1fr));
  gap: 6px;
}
#gif-results img {
  width: 100%;
  border-radius: 6px;
  cursor: pointer;
}


/* hidden state */
#gif-popup.hidden {
  display: none;
}

/* search bar at the top */
#gif-search {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  border: none;
  border-bottom: 1px solid #ddd;
  font-size: 14px;
  outline: none;
}

#gif-results img:hover {
  transform: scale(1.05);
}


.message-input-wrapper {
  position: sticky;   /* or fixed inside popup */
  bottom: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 5px;
  background: #f5f5f5;
  border-top: 1px solid #ddd;
  height: auto;
  box-sizing: border-box;

}

.new-message-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-grow: 1;
  border-radius: 20px;
  border: 1px solid #ccc;
  padding: 5px;
  background: white;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 4px;

}
.new-message-wrapper textarea {
  height: 1rem;
  min-height: 1rem;
  width: 100%;
  font-size: 12px;
  outline: none;
  max-height: 10rem;       /* allow unlimited growth */
  overflow: hidden;       /* 🔹 prevent internal scrollbars */
  resize: none;           /* disable manual drag resize */
  border-radius: 20px;
  /* border: 1px, solid, black; */
  border: none;
  padding: 4px;
  
}

/* Target the placeholder inside your textarea */
#new-message::placeholder {
  color: #b3b3b3; /* optional to tweak the color */
  font-weight: 500;
  padding-top: 1px;
  padding-left: 4px;
}
/* Actions row under textarea */
.message-actions {
  display: flex;
  justify-content: space-between; /* space GIF and Send apart */
  gap: 2px;
  user-select: none;
}

/* GIF button chip style */
.gif-chip {
  background-color: #e0e0e0;
  color: #333;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background-color .2s ease;
}

.gif-chip:hover {
  background-color: #d5d5d5;
}


body.noscroll {
  overflow: hidden; /* stop the document from scrolling */
  position: fixed;  /* iOS fix */
  width: 100%;
}


.message-bubble .reaction-btn {
  display: none;
  cursor: pointer;
  font-size: 14px;
}

.message-bubble:hover .reaction-btn {
  display: inline-block;
}

#emoji-picker {
  position: absolute;
  background: white;
  border: 1px solid #ccc;
  padding: 4px;
  display: flex;
  gap: 4px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  z-index: 9999;
  transform: translateX(-50%);
  opacity: 0;                   /* start invisible */
  pointer-events: none;          /* don't catch clicks when hidden */
  transition: opacity 0.2s ease; /* fade transition */
  user-select: none;
}


#emoji-picker.visible {
  opacity: 1;
  pointer-events: auto;          /* re-enable clicks */
}

#emoji-picker.hidden {
  display: none;
}

#emoji-picker .emoji-option {
  cursor: pointer;
  font-size: 18px;
}


.message-bubble {
  position: relative; /* needed so absolute inside is relative to bubble */
}



/* gray round placeholder when empty */
.message-emoji:empty {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ccc;
  display: inline-flex;
  content: ""; /* not really needed but harmless */
}


.message-emoji {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: transform .12s ease;
  right: 0;
  bottom: -5px;
  position: absolute;
  z-index: 5;
}



/* Hide meta on grouped rows and tighten the seam */
tr.message-group .message-meta { display: none; }

/* optional: slightly smaller spacing between grouped rows */

/* new header row style */
.message-meta-row .message-meta-head {
  font-size: 10px;
  color: #777;
  margin-top: 10px;
  margin-bottom: 2px;
  text-align: center; /* or right for your bubbles */
  font-family: sans-serif;
  user-select: none;
  border-top: 1px solid rgb(237, 237, 237);
}

/* remove old meta from inside bubble */
.message-bubble .message-meta {
  display: none;
}

img {
  user-select: none;
}

/* --- ME bubbles (right side) --- */
.message-row.me.bubble-first .message-bubble {
  border-top-right-radius: 18px;
  border-top-left-radius: 18px;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 18px;
}
.message-row.me.bubble-middle .message-bubble {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  border-top-left-radius: 18px;
  border-bottom-left-radius: 18px;
}
.message-row.me.bubble-last .message-bubble {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 18px;
  /* flatten also the opposite top-left so it aligns */
  border-top-left-radius: 18px;
  border-bottom-left-radius: 18px;
}
.message-row.me.bubble-single .message-bubble {
  border-radius: 18px;
}

/* --- THEM bubbles (left side) --- */
.message-row.them.bubble-first .message-bubble {
  border-top-left-radius: 18px;
  border-bottom-left-radius: 4px;
  border-top-right-radius: 18px;
  border-bottom-right-radius: 18px;
}
.message-row.them.bubble-middle .message-bubble {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
  border-top-right-radius: 18px;
  border-bottom-right-radius: 18px;
}
.message-row.them.bubble-last .message-bubble {
  border-top-left-radius: 4px;   /* flatten top-left too */
  border-bottom-left-radius: 18px;
  border-top-right-radius: 18px;
  border-bottom-right-radius: 18px;
}
.message-row.them.bubble-single .message-bubble {
  border-radius: 18px;
}
/* group wrapper */
.message-group-container {
  display: inline-flex;       /* let container shrink-wrap to content width */
  flex-direction: column;
  align-items: stretch;       /* children will stretch to container width */
  max-width: 220px;           /* clamp */
  gap: 1px;
}

/* when loading, hide or overlay the container */
#messages-container.loading {
  visibility: hidden; /* simplest: just hide until ready */
}
/* or show a skeleton instead */
#messages-container.loading::before {
  content: "Loading…";
  display: block;
  text-align: center;
  padding: 1rem;
  color: #777;
  font-weight: 500;
}

/* Target the placeholder inside your textarea */
#gif-search::placeholder {
  color: #b3b3b3; /* optional to tweak the color */
  font-weight: 500;
  padding-left: 2px;
}

.hidden {
  display: none !important;
}

.visible {
  display: block; /* or flex for popup */
}

.message-bubble.no-padding {
  padding: 0;        /* remove padding around the bubble */
}

.message-bubble.no-padding img {
  display: block;
  width: 100%;
  border-radius: 15px; /* optional: make image match bubble corners */
}
