:root {
  --accent: #ff9500;
  --accent2: #ffb300;
  --bg1: #1a1a1a;
  --bg2: #0b0b0f;
  --panel: #141414;
  --panel2: #1b1b1b;
  --line: #2b2b2b;
  --text: #ffffff;
  --muted: #cfcfcf;
  --bubble-me-text: #111111;
}

body.theme-blue {
  --accent: #4da3ff;
  --accent2: #7fc0ff;
  --bg1: #101827;
  --bg2: #060b14;
  --panel: #0f1724;
  --panel2: #182235;
  --line: #2a3954;
  --text: #f5f9ff;
  --muted: #ced8e8;
  --bubble-me-text: #07111f;
}

body.theme-green {
  --accent: #29c46d;
  --accent2: #62e49a;
  --bg1: #0e1711;
  --bg2: #060b07;
  --panel: #101710;
  --panel2: #172419;
  --line: #28412d;
  --text: #f3fff6;
  --muted: #cde9d3;
  --bubble-me-text: #07110b;
}

body.theme-purple {
  --accent: #a76bff;
  --accent2: #c69cff;
  --bg1: #17111f;
  --bg2: #09060f;
  --panel: #14101a;
  --panel2: #21192d;
  --line: #3b2c56;
  --text: #fbf7ff;
  --muted: #ddd0ee;
  --bubble-me-text: #12091d;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: Arial, sans-serif;
}

body {
  background: radial-gradient(circle at top, var(--bg1) 0%, var(--bg2) 45%, #000 100%);
  color: var(--text);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

body:not(.logged-in)::before {
  content: "";
  position: fixed;
  top: 50%;
  left: 50%;
  width: 180vmax;
  height: 180vmax;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(255, 149, 0, 0.07) 60deg,
    rgba(255, 179, 0, 0.10) 120deg,
    transparent 180deg,
    rgba(255, 149, 0, 0.05) 240deg,
    transparent 360deg
  );
  animation: rotateBgReverse 12s linear infinite;
  z-index: 0;
  pointer-events: none;
}


.topbar {
  height: 64px;
  background: linear-gradient(to bottom, #191919, #0c0c0c);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 18px;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.logo {
  font-size: 20px;
  font-weight: 700;
}

.logo span {
  background: linear-gradient(to bottom, var(--accent2), var(--accent));
  color: #111;
  padding: 3px 8px;
  border-radius: 8px;
}

.profile-container {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.profileIcon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--accent);
  object-fit: cover;
  background: #111;
}

.user-id {
  font-size: 13px;
  color: var(--muted);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gear-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 26px;
  line-height: 40px;
}

.profileMenu {
  position: absolute;
  top: 58px;
  right: 0;
  width: 270px;
  background: linear-gradient(to bottom, #1a1a1a, #101010);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  display: none;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
}

.menu-title {
  color: var(--accent2);
  font-weight: 700;
  margin-bottom: 4px;
}

.menu-label {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.search-wrapper {
  position: relative;
}

.search-menu {
  left: auto;
  right: auto;
  transform: translateX(-40%);
  width: 280px;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  margin-top: 4px;
}

.search-result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 10px;
  transition: 0.15s ease;
}

.search-result-row:hover {
  border-color: var(--accent);
}

.search-result-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent);
  flex-shrink: 0;
}

.search-result-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-id {
  font-size: 11px;
  color: var(--muted);
}

.search-add-btn {
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  font-size: 16px;
  line-height: 28px;
  text-align: center;
  flex-shrink: 0;
}

.search-result-row.already-friend .search-add-btn {
  background: #2a2a2a;
  color: var(--muted);
  cursor: default;
}

.menu-select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #303030;
  border-radius: 999px;
  background: #f4f4f4;
  color: #111;
  outline: none;
}

@keyframes rotateBg {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes rotateBgReverse {
  0%   { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(-360deg); }
}

.center {
  width: 100%;
  max-width: 420px;
  margin: 90px auto 0;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 28px 22px;
  background: linear-gradient(to bottom, rgba(26,26,26,0.95), rgba(10,10,10,0.96));
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.45);
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.center::before {
  content: "";
  position: absolute;
  inset: -60%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(255, 149, 0, 0.18) 60deg,
    rgba(255, 179, 0, 0.22) 120deg,
    transparent 180deg,
    rgba(255, 149, 0, 0.10) 240deg,
    transparent 360deg
  );
  animation: rotateBg 6s linear infinite;
  z-index: -1;
  border-radius: 50%;
}

.center h2 {
  text-align: center;
  color: var(--accent2);
  font-size: 22px;
  margin: 4px 0 2px;
}

#output {
  text-align: center;
  color: #fff3b8;
  min-height: 20px;
  margin-top: 4px;
  font-size: 14px;
}

input,
button {
  font-size: 14px;
}

input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #303030;
  border-radius: 999px;
  background: #f4f4f4;
  color: #111;
  outline: none;
  transition: 0.2s ease;
}

input:focus,
.menu-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,191,31,0.16);
}

button {
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(to bottom, var(--accent2), var(--accent));
  color: #111;
  font-weight: 800;
  cursor: pointer;
}

.main-app {
  display: flex;
  height: calc(100vh - 64px);
}

.sidebar {
  width: 220px;
  min-width: 220px;
  background: linear-gradient(to bottom, var(--panel), #0d0d0d);
  border-right: 1px solid var(--line);
  padding: 14px;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 10px;
}

.sidebar-header h3 {
  color: var(--accent2);
  font-size: 20px;
  margin: 0;
}

.sidebar-dots-btn {
  position: absolute;
  right: 0;
  width: 30px;
  min-width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  line-height: 28px;
  background: transparent;
  color: var(--muted);
  border: none;
}

.sidebar-dots-btn:hover {
  background: var(--panel2);
  color: var(--text);
}

.friends-dropdown {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.sidebar h3 {
  color: var(--accent2);
  margin-bottom: 10px;
  text-align: center;
  font-size: 20px;
}

.sidebar-btn {
  margin-bottom: 10px;
}

#friendsList {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.friend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 18px;
  transition: 0.18s ease;
}

.friend-row:hover {
  border-color: var(--accent);
  background: #232323;
}

.friend-name {
  flex: 1;
  cursor: pointer;
  word-break: break-word;
}

.trash-btn {
  width: 26px;
  min-width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  background: linear-gradient(to bottom, #ff4d4d, #c91f1f);
  color: white;
  font-size: 13px;
  line-height: 26px;
  text-align: center;
}

.unread-dot {
  width: 10px;
  height: 10px;
  background: red;
  border-radius: 50%;
  display: none;
}

.chatContainer {
  flex: 1;
  padding: 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background-color: #111;
  background-image: url("../images/background.png");
  background-size: 320px auto;
  background-repeat: repeat;
  background-position: center;
}

.chatContainer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.7);
  pointer-events: none;
  z-index: 0;
}

.chatContainer > * {
  position: relative;
  z-index: 1;
}

.chat-top,
.friend-tools {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.chat-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 16px 14px;
  display: none;
  flex-direction: column;
  gap: 6px;
}

.chat-footer.visible {
  display: flex;
}

.message-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.message-row #messageInput {
  background: rgba(18, 18, 18, 0.55);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 149, 0, 0.28);
  color: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,0.35);
  max-width: calc(100% - 90px);
}

.message-row #messageInput::placeholder {
  color: rgba(255,255,255,0.35);
}

.message-row #messageInput:focus {
  border-color: rgba(255, 149, 0, 0.7);
  box-shadow: 0 0 0 3px rgba(255, 149, 0, 0.12), 0 4px 24px rgba(0,0,0,0.35);
}

.chat-top input,
.friend-tools input,
.message-row input {
  flex: 1;
}

.chat-top button,
.friend-tools button {
  width: 170px;
}

.send-btn,
.message-row .send-btn {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-header {
  color: var(--accent2);
  font-weight: 700;
  margin-bottom: 10px;
  min-height: 20px;
}

.chatBox {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 14px 140px 14px;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 149, 0, 0.5) transparent;
}

.chatBox::-webkit-scrollbar {
  width: 4px;
}

.chatBox::-webkit-scrollbar-track {
  background: transparent;
}

.chatBox::-webkit-scrollbar-thumb {
  background: rgba(255, 149, 0, 0.5);
  border-radius: 999px;
}

.chatBox::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 149, 0, 0.85);
}

.chatBox > * {
  position: relative;
  z-index: 1;
}

.chat-placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255,255,255,0.15);
  font-size: 18px;
  text-align: center;
  pointer-events: none;
  user-select: none;
}

.message {
  padding: 10px 14px;
  margin: 6px 0;
  border-radius: 16px;
  max-width: 72%;
  word-wrap: break-word;
  position: relative;
}

.message.me {
  background: var(--accent);
  color: var(--bubble-me-text);
  margin-left: auto;
}

.message.other {
  background: #2a2a2a;
  color: white;
}

.reply-chip {
  font-size: 12px;
  opacity: 0.9;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.message.me .reply-chip {
  border-bottom-color: rgba(0,0,0,0.18);
}

.typingIndicator {
  color: var(--accent2);
  font-size: 13px;
  min-height: 0;
  padding-left: 6px;
}

.replyPreview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(30, 30, 30, 0.8);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 14px;
  padding: 8px 12px;
}

.replyPreviewText {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.replyCloseBtn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
}

/* ── Hamburger button ── */
.hamburger-btn {
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
}

/* ── Drawer overlay ── */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 900;
}

/* ── Drawer sidebar ── */
.drawer {
  transition: transform 0.28s ease;
}

@media (max-width: 900px) {
  .user-id {
    display: none;
  }

  .main-app {
    flex-direction: column;
  }

  .hamburger-btn {
    display: flex;
  }

  .sidebar.drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    min-width: 280px;
    height: 100%;
    z-index: 1000;
    border-right: 1px solid var(--line);
    border-bottom: none;
    transform: translateX(-100%);
    overflow-y: auto;
    padding-top: 70px;
  }

  .sidebar.drawer.open {
    transform: translateX(0);
  }

  .chatContainer {
    width: 100%;
  }

  .center {
    margin: 30px 14px 0;
    width: auto;
  }

  .profileMenu {
    right: -6px;
    width: 230px;
  }

  .chatContainer {
    padding: 12px 12px 0 12px;
  }

  .chat-footer {
    padding: 6px 12px 12px;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 0 12px;
  }

  .logo {
    font-size: 18px;
  }

  .profileIcon {
    width: 36px;
    height: 36px;
  }

  .chat-top,
  .friend-tools {
    flex-direction: column;
  }

  .chat-top button,
  .friend-tools button {
    width: 100%;
  }

  /* message-row always stays horizontal */
  .message-row {
    flex-direction: row;
    align-items: center;
  }

  .message {
    max-width: 88%;
  }
}

.message-row-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}

.chat-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent, #f0a500);
}

.friend-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent, #f0a500);
}
.msg-time {
  font-size: 11px;
  opacity: 0.65;
  margin-top: 6px;
  text-align: right;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
}

.msg-status {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  letter-spacing: -2px;
  flex-shrink: 0;
}

.msg-status.msg-status-read {
  color: #22c55e;
}

#usersList .friend-row {
  justify-content: space-between;
  align-items: center;
}

/* ── Groups sidebar ── */
.sidebar-divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

.group-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 18px;
  transition: 0.18s ease;
  margin-bottom: 8px;
}

.group-row:hover {
  border-color: var(--accent);
  background: #232323;
}

.group-icon {
  font-size: 18px;
  flex-shrink: 0;
}

/* ── Chat header with rename ── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rename-group-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.rename-group-row input {
  flex: 1;
}

.rename-group-row button {
  width: auto;
  padding: 10px 16px;
  flex-shrink: 0;
}

/* ── Icon buttons ── */
.icon-btn {
  width: 30px;
  min-width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  font-size: 14px;
  line-height: 30px;
  text-align: center;
}

.cancel-btn {
  background: #333;
  color: var(--text);
}

/* ── Create Group inline panel ── */
#createGroupPanel {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px 0;
}

.member-check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.member-check-row input[type="checkbox"] {
  width: 16px;
  min-width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
  padding: 0;
  border-radius: 4px;
}

/* ── Image sending ── */
.emoji-panel {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  background: rgba(22, 22, 22, 0.9);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  max-height: 170px;
  overflow-y: auto;
}

.emoji-item {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 19px;
  line-height: 34px;
  text-align: center;
  cursor: pointer;
  transition: background 0.12s;
}

.emoji-item:hover {
  background: var(--panel2);
}

.img-pick-btn,
.message-row .img-pick-btn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 22px;
  font-weight: 400;
  line-height: 36px;
  flex-shrink: 0;
}

.preview-thumb {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}

.chat-image {
  max-width: 220px;
  max-height: 220px;
  width: 100%;
  border-radius: 10px;
  display: block;
  margin-top: 4px;
  cursor: zoom-in;
  object-fit: contain;
  transition: opacity 0.15s;
}

.chat-image:hover {
  opacity: 0.85;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.lightbox-img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 14px;
  box-shadow: 0 0 60px rgba(255, 149, 0, 0.25);
  object-fit: contain;
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 22px;
  width: 42px;
  min-width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(30,30,30,0.85);
  border: 1px solid rgba(255,149,0,0.3);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  z-index: 10000;
}

/* ── Online / offline status dot ── */
.avatar-wrapper {
  position: relative;
  flex-shrink: 0;
}

.status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--panel2);
  background: #4b5563;
}

.status-dot.online {
  background: #22c55e;
}

/* ── Group chat sender label ── */
.sender-label {
  font-size: 11px;
  color: var(--accent2);
  padding-left: 38px;
  margin-bottom: 2px;
}
