/* =========================
   Base & Resets
========================= */
:root {
  --sidebar-w: 340px;
  --bg-dark: #0b1526;
  --bubble-dark: #0e1b2b;
  --bubble-light: #ffffff;
  --text-dark: #0b1220;
  --shadow-dark: 0 8px 24px rgba(14, 27, 43, 0.25);
  --shadow-light: 0 8px 24px rgba(0, 0, 0, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
}

body {
  margin: 0;
  background: #ffffff;
  color: #0f172a; /* slate-900-ish */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* =========================
   Scrollbars (subtle)
========================= */
.thin-scroll {
  scrollbar-width: thin;
  scrollbar-color: #243141 transparent;
}
.thin-scroll::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.thin-scroll::-webkit-scrollbar-thumb {
  background: #243141;
  border-radius: 8px;
}

/* =========================
   Layout
========================= */
aside {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  min-height: 0;
  background: var(--bg-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
}

.sidebar-groups {
  flex: 0 0 auto;
  padding: 0.55rem 0.75rem 0.7rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.25rem 0.35rem 0.55rem;
  color: rgba(226, 232, 240, 0.82);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.015em;
}

.sidebar-section-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #a5b4fc;
}

.sidebar-count {
  display: inline-flex;
  min-width: 1.25rem;
  height: 1.25rem;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(226, 232, 240, 0.7);
  font-size: 0.65rem;
  font-weight: 600;
}

.sidebar-create-group {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-height: 2rem;
  padding: 0 0.65rem;
  border: 1px solid rgba(129, 140, 248, 0.32);
  border-radius: 0.65rem;
  background: rgba(99, 102, 241, 0.14);
  color: #c7d2fe;
  font-size: 0.7rem;
  font-weight: 650;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.sidebar-create-group:hover,
.sidebar-create-group:focus-visible {
  border-color: rgba(165, 180, 252, 0.65);
  background: rgba(99, 102, 241, 0.28);
  outline: none;
}

.sidebar-group-list {
  display: grid;
  max-height: min(32vh, 16rem);
  gap: 0.25rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-group-item {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 0.8rem;
  background: transparent;
  color: #f8fafc;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.sidebar-group-item:hover,
.sidebar-group-item:focus-visible {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.065);
  outline: none;
}

.sidebar-group-item.is-active {
  border-color: rgba(129, 140, 248, 0.28);
  background: rgba(99, 102, 241, 0.18);
}

.sidebar-group-avatar {
  display: flex;
  width: 2.65rem;
  height: 2.65rem;
  flex: 0 0 2.65rem;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(145deg, #6366f1, #8b5cf6);
  color: white;
  font-size: 0.88rem;
  font-weight: 700;
}

.sidebar-group-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar-group-copy {
  display: block;
  min-width: 0;
  flex: 1;
}

.sidebar-group-name,
.sidebar-group-members {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-group-name {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2rem;
}

.sidebar-group-members {
  margin-top: 0.1rem;
  color: rgba(203, 213, 225, 0.58);
  font-size: 0.68rem;
}

.sidebar-groups-empty {
  padding: 0.4rem 0.55rem 0.55rem;
  color: rgba(203, 213, 225, 0.55);
  font-size: 0.72rem;
}

.group-modal {
  position: fixed;
  inset: 0;
  box-sizing: border-box;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

.group-modal:not(.hidden) {
  display: flex;
}

.group-modal-panel {
  flex: 0 1 42rem;
  max-height: calc(100vh - 1.5rem);
  max-height: calc(100dvh - 1.5rem);
  min-height: 0;
  margin: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #475569 transparent;
}

#createGroupModal .group-modal-panel {
  flex-basis: 32rem;
}

#groupSettingsMembersList,
#groupMemberPicker {
  max-height: min(30vh, 15rem);
}

.group-modal-panel > .border-t {
  flex-wrap: wrap;
}

.chatingSection {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0; /* allow shrinking */
  transition: transform 0.4s ease, opacity 0.4s ease;
}

/* ensure the SVG and Canvas backgrounds sit behind content */
/* .chatingSection svg.absolute,
#bg.absolute {
  inset: 0;
  z-index: 0; */
/* } */

/* messages area should sit above background layers */
#messagesPanel,
.messages {
  position: relative;
  z-index: 100;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1.5rem; /* px-6 */
  gap: 1.5rem; /* space-y-6 */
  background: transparent;
  min-height: 73%;
  scroll-behavior: smooth;
  height: 73vh;
}

/* header and input bar layering */
.chatingSection > .glass,
.chatingSection > .bg-white,
.chatingSection > div[aria-label="Send"] {
  position: relative;
  z-index: 2;
}

/* separator line */
.sep {
  background: linear-gradient(
    to right,
    transparent,
    rgba(0, 0, 0, 0.08),
    transparent
  );
  height: 1px;
  position: relative;
  z-index: 2;
}

/* =========================
   Bubbles
========================= */
.bubble-dark {
  background: var(--bubble-dark);
  color: #fff;
  box-shadow: var(--shadow-dark);
  position: relative;
}
.bubble-light {
  background: var(--bubble-light);
  color: var(--text-dark);
  box-shadow: var(--shadow-light);
  position: relative;
}

/* tails */
.bubble-dark:after {
  content: "";
  position: absolute;
  left: -10px;
  bottom: 0;
  width: 14px;
  height: 14px;
  background: var(--bubble-dark);
  border-bottom-right-radius: 12px;
  clip-path: path("M0,0 C10,10 10,14 14,14 L0,14 Z");
  filter: drop-shadow(0 6px 10px rgba(14, 27, 43, 0.25));
}

.bubble-light:after {
  content: "";
  position: absolute;
  right: -10px;
  bottom: 0;
  width: 14px;
  height: 14px;
  background: var(--bubble-light); /* fixed from red to white */
  border-bottom-left-radius: 12px;
  clip-path: path("M14,0 C4,10 4,14 0,14 L14,14 Z");
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.08));
}

/* =========================
   Message animations
========================= */
.msg-enter {
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: all 0.22s ease;
}
.msg-enter.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.msg-enter.show .bubble {
  animation: pop 0.22s ease forwards;
}

.msg-enter.show .bubble {
  animation: pop 0.22s ease forwards;
}

/* =========================
   Typing dots
========================= */
.typing span {
  width: 6px;
  height: 6px;
  background: #fff;
  border-radius: 999px;
  display: inline-block;
  margin-right: 4px;
  opacity: 0.3;
  bottom: 0;
  position: absolute;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}

/* =========================
   Canvas sizing
========================= */
#bg {
  width: 100%;
  height: 100%;
  display: block;
}

/* =========================
   Sidebar list items
========================= */
.allLogger .group {
  transition: background 0.2s ease, transform 0.2s ease;
}
.allLogger .group:hover {
  background: rgba(255, 255, 255, 0.05);
}
.allLogger [data-chat-id].is-active {
  background: rgba(99, 102, 241, 0.18);
}
.sidebar-chat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem 0.55rem;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sidebar-chat-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0.45rem;
  padding: 0.65rem 0.7rem;
  border: 1px solid transparent;
  border-radius: 0.85rem;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.sidebar-chat-item:hover {
  background: rgba(255, 255, 255, 0.06);
}
.sidebar-chat-item.is-active {
  border-color: rgba(99, 102, 241, 0.28);
  background: rgba(99, 102, 241, 0.13);
}
.sidebar-chat-avatar {
  width: 2.8rem;
  height: 2.8rem;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.08);
}
.sidebar-chat-content {
  min-width: 0;
  flex: 1;
}
.sidebar-chat-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.sidebar-chat-name {
  overflow: hidden;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-chat-status {
  flex: 0 0 auto;
  color: rgba(255, 255, 255, 0.42);
  font-size: 0.65rem;
}
.sidebar-chat-status.is-online {
  color: #4ade80;
}
.sidebar-chat-preview {
  overflow: hidden;
  margin-top: 0.2rem;
  color: rgba(255, 255, 255, 0.58);
  font-size: 0.75rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-chat-empty {
  padding: 1.25rem 1rem;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.8rem;
  line-height: 1.5;
  text-align: center;
}
.sidebar-chat-empty.is-error {
  color: #fca5a5;
}

/* =========================
   Input bar
========================= */
#msgInput {
  min-height: 44px;
}

.attach-option,
.location-option {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.75rem;
  border-radius: 0.75rem;
  padding: 0.7rem 0.8rem;
  text-align: left;
  transition: background 0.15s ease;
}

.attach-option:hover,
.attach-option:focus-visible,
.location-option:hover,
.location-option:focus-visible {
  background: #f1f5f9;
  outline: none;
}

.location-option > span {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.location-option small {
  color: #64748b;
  font-size: 0.75rem;
}

#locationMap {
  min-height: 280px;
  width: 100%;
}

.live-location-card {
  width: min(20rem, 72vw);
  overflow: hidden;
}

.profile-photo {
  cursor: zoom-in;
}

.profile-photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 20000;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(2, 6, 23, 0.88);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.profile-photo-viewer.flex {
  display: flex;
}

.profile-photo-viewer > img {
  display: block;
  max-width: min(92vw, 1100px);
  max-height: 88vh;
  max-height: 88dvh;
  border-radius: 0.75rem;
  object-fit: contain;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

#closeProfilePhotoViewer {
  position: absolute;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  display: flex;
  width: 2.75rem;
  height: 2.75rem;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 9999px;
  background: rgba(15, 23, 42, 0.7);
  color: white;
  font-size: 1.75rem;
  line-height: 1;
}

.photo-viewer-open {
  overflow: hidden;
}

.location-map-preview {
  display: block;
  width: 100%;
  height: 10rem;
  margin-top: 0.6rem;
  border: 0;
  border-radius: 0.75rem;
  background: #e2e8f0;
}

#filePreviewDialog {
  position: fixed;
  inset: 0;
  z-index: 1500;
  box-sizing: border-box;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 1rem;
}

#filePreviewDialog > div {
  display: flex;
  flex: 0 1 32rem;
  flex-direction: column;
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  min-height: 0;
}

#filePreviewList {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

#mapLocationDialog {
  position: fixed;
  inset: 0;
  z-index: 1400;
  box-sizing: border-box;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 0.75rem;
}

#mapLocationDialog > div {
  max-height: calc(100vh - 1.5rem);
  max-height: calc(100dvh - 1.5rem);
}

.chat-image-gallery {
  display: grid;
  width: min(22rem, 70vw);
  max-height: 24rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  overflow: hidden;
  border-radius: 0.85rem;
}

.chat-image-gallery a {
  display: block;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #e2e8f0;
  aspect-ratio: 1;
}

.chat-image-gallery.single a {
  grid-column: span 2;
  aspect-ratio: auto;
}

.chat-image-gallery img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 20rem;
  object-fit: cover;
}

.chat-image-gallery.single img {
  object-fit: contain;
}

/* Make the send button feel clickable */
#sendBtn {
  transform: translateZ(0);
  transition: transform 0.06s ease, opacity 0.2s ease;
}
#sendBtn:active {
  transform: scale(0.98);
}

.chatingSection.active {
  transform: translateY(120%);
  opacity: 0;
}

/* =========================
   Responsive
========================= */

/* Large tablets and below */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: 300px;
  }
  aside {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
  }
}

/* Tablets */
@media (max-width: 900px) {
  :root {
    --sidebar-w: 260px;
  }
  aside {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
  }
  #messagesPanel,
  .messages {
    padding: 1rem;
    gap: 1rem;
  }
}

@media (max-width: 768px) {
  .flex.h-full.w-full {
    /* flex-direction: column; */
    height: 100%;
  }
  aside {
    width: 100%;
    min-width: 100%;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }
  /* make chat section fill remaining height */
  .chatingSection {
    min-height: 0;
    width: 100%;
  }

  .chatingSection {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    background: var(--bubble-light);
    color: var(--text-dark);
    height: 100%;
  }
}

/* Small phones */
@media (max-width: 480px) {
  #messagesPanel,
  .messages {
    padding: 0.75rem;
    gap: 0.75rem;
  }
  .bubble-light,
  .bubble-dark {
    border-radius: 16px;
  }
  .allLogger .group {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

/* =========================
   Utilities (non-breaking)
========================= */
/* Glass header support (your .glass class kept) */
.glass {
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

/* Ensure any absolute children inside chat do not block input */
.chatingSection > .absolute {
  pointer-events: none;
}

.menu-dropdown {
  backdrop-filter: none;
}

.account-menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  color: #334155;
  font-size: 0.875rem;
  text-align: left;
  transition: background-color 120ms ease, color 120ms ease;
}

.account-menu-item:hover,
.account-menu-item:focus-visible {
  background: #f1f5f9;
  color: #0f172a;
  outline: none;
}

.account-menu-item svg {
  width: 1.15rem;
  height: 1.15rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.account-menu-danger {
  color: #b91c1c;
}

.account-menu-danger:hover,
.account-menu-danger:focus-visible {
  background: #fef2f2;
  color: #991b1b;
}

.account-panel {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.48);
}

.account-panel.hidden {
  display: none;
}

.account-panel-card {
  width: min(100%, 28rem);
  max-height: min(85vh, 40rem);
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 1rem;
  background: #fff;
  color: #0f172a;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
}

.account-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e2e8f0;
  padding: 1rem 1.25rem;
}

.account-panel-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

.account-panel-close {
  display: grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  border-radius: 999px;
  color: #64748b;
  font-size: 1.5rem;
}

.account-panel-close:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.account-panel-content {
  padding: 1.25rem;
}

.account-panel-description {
  margin: 0 0 1rem;
  color: #64748b;
  font-size: 0.875rem;
}

.account-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid #e2e8f0;
  padding: 1rem 0;
  cursor: pointer;
}

.account-setting-row strong,
.account-info-row strong {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
}

.account-setting-row small {
  display: block;
  margin-top: 0.25rem;
  color: #64748b;
  font-size: 0.75rem;
}

.account-select {
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  background: #fff;
  padding: 0.45rem 0.65rem;
  color: #0f172a;
  font-size: 0.875rem;
}

.account-primary-button {
  width: 100%;
  border-radius: 0.6rem;
  background: #0f172a;
  padding: 0.7rem 1rem;
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
}

.account-primary-button:hover {
  background: #1e293b;
}

.account-primary-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.account-info-row {
  border-bottom: 1px solid #e2e8f0;
  padding: 0.8rem 0;
}

.account-info-row:first-child {
  padding-top: 0;
}

.account-info-row p {
  margin: 0.35rem 0 0;
  color: #64748b;
  font-size: 0.875rem;
  line-height: 1.45;
}

body[data-theme="dark"] {
  background: #0f172a;
  color: #e2e8f0;
}

body[data-theme="dark"] .chatingSection {
  background-color: #0f172a;
  color: #e2e8f0;
}

body[data-theme="dark"] .chatingSection .bg-white,
body[data-theme="dark"] .chatingSection .bg-slate-50,
body[data-theme="dark"] .chatingSection .bg-gray-50 {
  background-color: #1e293b;
}

body[data-theme="dark"] .chatingSection .text-slate-900,
body[data-theme="dark"] .chatingSection .text-slate-800,
body[data-theme="dark"] .chatingSection .text-gray-900,
body[data-theme="dark"] .chatingSection .text-gray-800 {
  color: #e2e8f0;
}

body[data-theme="dark"] .chatingSection .text-slate-700,
body[data-theme="dark"] .chatingSection .text-slate-600,
body[data-theme="dark"] .chatingSection .text-gray-700,
body[data-theme="dark"] .chatingSection .text-gray-600 {
  color: #cbd5e1;
}

body[data-theme="dark"] .chatingSection .border-slate-200,
body[data-theme="dark"] .chatingSection .border-gray-200 {
  border-color: #334155;
}

body[data-theme="dark"] .chatingSection .glass {
  background: rgba(15, 23, 42, 0.9);
}

body[data-theme="dark"] .chatingSection input,
body[data-theme="dark"] .chatingSection textarea,
body[data-theme="dark"] .chatingSection select {
  border-color: #475569;
  background-color: #1e293b;
  color: #e2e8f0;
}

body[data-theme="dark"] .chatingSection input::placeholder,
body[data-theme="dark"] .chatingSection textarea::placeholder {
  color: #94a3b8;
}

body[data-theme="dark"] .bubble-light {
  --bubble-light: #1e293b;
  --text-dark: #e2e8f0;
}

@media (prefers-reduced-motion: reduce) {
  .account-menu-item {
    transition: none;
  }
}
