html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: Arial, sans-serif;
  background-color: #f0f0f0;
  margin-top: -20px;
  padding: 0;
  direction: rtl;
}

.chat-container {
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  background-color: #fff;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
}

.chat-box {
  direction: rtl;
  text-align: right;
  height: 60dvh;
  overflow-y: auto;
  margin-top: -30px;
  margin-bottom: 10px;
  border: 1px solid #ccc;
  padding: 10px;
  border-radius: 5px;
  flex: 1 1 auto;
  min-height: 0;
}

.message-bubble {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  background-color: #e0e0e0;
  padding: 10px;
  font-size: 17px;
  margin-bottom: 5px;
  border-radius: 10px;
  text-align: right;
  word-break: break-word;
  white-space: pre-wrap;
  direction: rtl;
}

.message-bubble.user1 {
  background-color: #dcf8c6;
  align-items: flex-start;
  margin-left: 120px;
}

.message-bubble.user2 {
  background-color: #ffe0b3;
  align-items: flex-start;
  margin-right: 120px;
}

.message-bubble.user2 {
  background-color: #ffe0b3;
  align-items: flex-start;
  margin-right: 90px;
}

.message-bubble span {
  color: #999;
  font-size: 0.8em;
  margin-left: 10px;
}

.message-bubble div {
  margin-bottom: 5px;
}

.message-bubble img {
  max-width: 200px;
  border-radius: 5px;
}

.header {
  display: flex;
  flex: 0 0 auto;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  margin-top: -5px;
}

.logout-btn {
  background-color: #f44336;
  color: white;
  padding: 8px 12px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
}

.users-btn {
  background-color: #1976d2;
  color: white;
  padding: 8px 12px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
}

.users-btn:hover { background-color: #1565c0; }

.clear-btn {
  background-color: #ffba00;
  color: white;
  padding: 8px 12px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
}

.logout-btn:hover {
  background-color: #d32f2f;
}

.input-group {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 8px;
}

.compose-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  direction: rtl;
}

.compose-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
  order: 0;
}

#messageInput {
  order: 1;
}

.compose-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  padding: 0;
  cursor: pointer;
  background: #4CAF50;
  color: #fff;
  border: none;
  box-sizing: border-box;
  text-decoration: none;
  direction: ltr;
}

.compose-icon-btn:hover {
  background: #45a049;
}

#filePickBtn {
  background: #607d8b;
}

#filePickBtn:hover {
  background: #546e7a;
}

.compose-icon-btn.cancel-mode {
  background: #f44336;
}

.compose-icon-btn.cancel-mode:hover {
  background: #d32f2f;
}

#filePickBtn.hidden-when-file-selected {
  display: none;
}

form {
  display: flex;
  flex-direction: column;
}

input[type="text"],
input[type="password"],
input[type="file"] {
  margin-bottom: 10px;
  padding: 10px;
  font-size: 16px;
}

textarea {
  padding: 10px;
  font-family: Arial;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 12px;
  min-height: 76px;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
}

button {
  padding: 10px;
  font-size: 16px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background-color: #45a049;
}

.msg-head {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  width: 100%;
  gap: 10px;
}

.msg-user {
  color: #2e7d32;
}

.msg-body { direction: rtl; }

.msg-line {
  white-space: pre-wrap;
  line-height: 1.25;
  min-height: 0.8em;
}

.msg-line.ltr-line {
  direction: ltr;
  text-align: left;
  unicode-bidi: plaintext;
}

.msg-footer {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.msg-reactions-summary {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow: hidden;
  min-height: 28px;
}

.msg-time {
  color: #888;
  font-size: 0.8em;
  white-space: nowrap;
  direction: ltr;
}

.reaction-chip {
  /*display: inline-flex;
  align-items: center;
  gap: 4px; */
  padding: 0px 0px;
  border-radius: 999px;
  background: rgba(255,255,255,0.75);
  font-size: 13px;
  white-space: nowrap;
  color: #333;
  border: 0px solid rgba(0,0,0,0.08);
}

.reaction-chip:hover {
  background: rgba(255,255,255,0.92);
}

.reaction-chip.active {
  background: #e3f2fd;
  border-color: #90caf9;
}

.reaction-chip-emoji {
  display: inline-flex;
  align-items: center;
  pointer-events: none;
}

.reply-bar {
  display: flex;
  flex: 0 0 auto;
  justify-content: space-between;
  align-items: center;
  border: 1px dashed #aaa;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
  background: #fafafa;
}

.reply-text { font-size: 14px; color: #333; }

.reply-cancel {
  background: #f44336;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 6px;
}

.reply-cancel:hover { background: #d32f2f; }

.reply-preview {
  width: 100%;
  background: #ffffff8a;
  border-right: 4px solid #999;
  padding: 5px 7px;
  border-radius: 6px;
  margin: 3px 0 5px 0;
  font-size: 0.82em;
  color: #444;
}

.attachments {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.attachment {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 8px;
}

.att-meta { margin-bottom: 0px; }
.att-name { font-weight: 200; color: #333; }
.att-sub { font-size: 0.85em; color: #666; }

.att-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.att-image {
  margin-top: 8px;
  max-width: 240px;
  border-radius: 8px;
  border: 1px solid #eee;
}

.upload-progress {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fafafa;
}

.hourglass { font-size: 18px; }

.progress-track {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: #e0e0e0;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #4CAF50;
}

.progress-label {
  font-size: 0.85em;
  color: #444;
  width: 48px;
  text-align: left;
  direction: ltr;
}

.mini-btn {
  color: white;
  padding: 6px 10px;
  font-size: 13px;
  background-color: #607d8b;
  border-radius: 6px;
  text-decoration: none;
}

.mini-btn:hover { background-color: #546e7a; }

/* ---------- users modal ---------- */
.users-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.users-modal {
  width: min(520px, calc(100vw - 20px));
  max-height: min(70vh, 620px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.users-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #eee;
}

.users-modal-title { font-weight: 700; }

.users-modal-close {
  background: #f44336;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.users-modal-body {
  padding: 10px 14px;
  overflow: auto;
}

.users-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed #eee;
  gap: 10px;
}

.users-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.users-name { font-weight: 600; }

.users-last {
  font-size: 12px;
  color: #666;
  direction: ltr;
  text-align: left;
}

.users-badge {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  color: #fff;
  white-space: nowrap;
}

.users-badge.online { background: #2e7d32; }
.users-badge.offline { background: #607d8b; }

/* ---------- message overlay ---------- */
.message-overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.message-overlay {
  width: min(320px, calc(100vw - 32px));
}

.message-overlay-card {
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,.28);
}

.message-overlay-actions {
  display: flex;
  flex-direction: column;
  padding: 8px;
}

.message-overlay-action {
  width: 100%;
  text-align: right;
  background: #fff;
  color: #222;
  border-radius: 12px;
  padding: 12px 14px;
  border: none;
}

.message-overlay-action:hover {
  background: #f5f5f5;
}

.message-overlay-action.danger {
  color: #d32f2f;
}

.reaction-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: #fff;
  touch-action: pan-x;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.reaction-strip.dragging {
  cursor: grabbing;
  scroll-behavior: auto;
}

.reaction-strip::-webkit-scrollbar {
  display: none;
}

.reaction-btn {
  flex: 0 0 auto;
  min-width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid #ddd;
  background: #fff;
  color: #111;
  font-size: 22px;
  line-height: 1;
  padding: 0;
}

.reaction-btn.active {
  background: #e3f2fd;
  border-color: #90caf9;
}

/* ---------- reaction stats ---------- */
.reaction-stats-card {
  padding: 0;
}

.reaction-stats-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid #eee;
}

.reaction-stats-title {
  font-weight: 700;
}

.reaction-stats-close {
  background: #607d8b;
  padding: 6px 10px;
  border-radius: 8px;
}

.reaction-stats-close:hover {
  background: #546e7a;
}

.reaction-stats-body {
  padding: 12px 14px;
  max-height: 50vh;
  overflow: auto;
}

.reaction-stats-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px dashed #eee;
}

.reaction-stats-emoji {
  font-size: 24px;
  min-width: 36px;
  text-align: center;
}

.reaction-stats-users {
  color: #333;
  line-height: 1.6;
}

@media (max-width: 720px) {
  .message-bubble.user1 {
    margin-left: 70px;
  }

  .message-bubble.user2 {
    margin-right: 70px;
  }

  .compose-icon-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  textarea {
    min-height: 64px;
  }
}

/* لینک‌ها و شماره‌های قابل کلیک در پیام‌ها */
.clickable-link {
  color: #1976d2;
  text-decoration: underline;
  cursor: pointer;
  display: inline-block;
  border-radius: 4px;
  padding: 0 2px;
}

.clickable-link:hover {
  background-color: rgba(25, 118, 210, 0.1);
}

/* منوی contextual برای لینک/شماره */
/* منوی زمینه برای لینک و شماره */
.context-menu {
  position: fixed;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  z-index: 30000;
  min-width: 180px;
  overflow: hidden;
  direction: rtl;
  padding: 8px 0;
}

.context-menu-item {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  transition: background 0.2s;
  border: none;
  background: white;
  width: 100%;
  text-align: right;
  color: #333333;
  font-weight: normal;
}

.context-menu-item:hover {
  background: #f0f0f0;
  color: #000000;
}

.context-menu-item.danger {
  color: #f44336;
}

.context-menu-item.danger:hover {
  background: #ffebee;
}

/* اطمینان از اینکه متن داخل منو خوانا است */
.context-menu-item span {
  color: inherit;
}

/* جداکننده بین آیتم‌ها (اختیاری) */
.context-menu-divider {
  height: 1px;
  background: #e0e0e0;
  margin: 4px 0;
}

@media (max-width: 520px) {
  .chat-container {
    padding-top: 7px;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    border-radius: 0;
  }

  .chat-box {
    flex: 1 1 auto;
    height: auto;
    margin-top: -35px;
  }

  .reply-bar,
  .input-group {
    flex: 0 0 auto;
  }

  .upload-progress {
    position: fixed;
    left: 10px;
    right: 10px;
    z-index: 9999;
    bottom: calc(120px + env(safe-area-inset-bottom));
    margin: 0;
  }

  body.uploading .chat-box {
    padding-bottom: 90px;
  }
}