.chat-page {
  margin: 0;
  min-height: 100svh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #eef2f7;
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-right: calc(12px + env(safe-area-inset-right));
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  padding-left: calc(12px + env(safe-area-inset-left));
}

.chat-page .chat-container {
  width: min(900px, 100%);
  min-height: min(100svh - 24px, 860px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.12);
  padding: 14px;
}

.chat-page .chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e5e7eb;
}

.chat-page .header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-page .settings-link {
  text-decoration: none;
  color: #065f46;
  font-size: 0.88rem;
  background: #d1fae5;
  border-radius: 10px;
  padding: 8px 12px;
}

.chat-page .chat-header h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2.2vw, 1.4rem);
  color: #111827;
}

.chat-page .logout-button,
.chat-page #send-button {
  border: none;
  border-radius: 12px;
  height: 44px;
  min-height: 44px;
  padding: 0 14px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.chat-page #send-button {
  background: #16a34a;
  color: #fff;
}

.chat-page .logout-button {
  background: #ef4444;
  color: #fff;
}

.chat-page .chat-box {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #f9fafb;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-page .message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-page .message-row.mine {
  justify-content: flex-start;
}

.chat-page .message-row.other {
  justify-content: flex-end;
}

.chat-page .avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #d1d5db;
  color: #111827;
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: 0 0 34px;
}

.chat-page .message {
  max-width: 80%;
  border-radius: 14px;
  padding: 10px 12px;
  line-height: 1.45;
  font-size: 0.95rem;
  word-wrap: break-word;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.chat-page .message.sent {
  background: #22c55e;
  color: #fff;
}

.chat-page .message.received {
  background: #fff;
  color: #111827;
  border: 1px solid #e5e7eb;
}

.chat-page .message-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-page .message .sender-name {
  font-weight: 700;
  font-size: 0.83rem;
  margin-bottom: 4px;
  opacity: 0.9;
}

.chat-page .message-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chat-page .action-btn {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 8px;
}

.chat-page .timestamp {
  margin-top: 6px;
  font-size: 0.72rem;
  opacity: 0.78;
  text-align: end;
}

.chat-page .read-status {
  margin-top: 3px;
  font-size: 0.7rem;
  opacity: 0.85;
}

.chat-page .pending-label {
  font-size: 0.78rem;
  margin-top: 6px;
  opacity: 0.9;
}

.chat-page .message.pending {
  opacity: 0.9;
}

.chat-page .message.failed {
  border: 1px dashed #ef4444;
}

.chat-page .retry-btn {
  margin-top: 6px;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  background: #111827;
  color: #fff;
  cursor: pointer;
}


.chat-page .chat-error-banner {
  display: none;
  padding: 8px 10px;
  border-radius: 10px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 0.85rem;
}

.chat-page .typing-indicator {
  min-height: 18px;
  color: #4b5563;
  font-size: 0.82rem;
  padding: 0 4px;
}

.chat-page .composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat-page #message-input {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  max-height: 120px;
  resize: none;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: #fff;
  padding: 12px 14px;
  font-size: 16px;
  line-height: 1.3;
}

.chat-page #message-input:focus {
  outline: none;
  border-color: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}

.chat-page .edit-wrap {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-page .edit-input {
  flex: 1 1 180px;
  min-width: 0;
  min-height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 16px;
}

.chat-page .edit-btn {
  border: none;
  height: 40px;
  border-radius: 10px;
  padding: 0 12px;
  cursor: pointer;
  font-size: 0.86rem;
}

.chat-page .edit-btn.save {
  background: #166534;
  color: #fff;
}

.chat-page .edit-btn.cancel {
  background: #374151;
  color: #fff;
}

[dir="rtl"] .chat-page #message-input,
[dir="rtl"] .chat-page #message-input::placeholder,
[dir="rtl"] .chat-page .edit-input,
[dir="rtl"] .chat-page .edit-input::placeholder {
  text-align: right;
}

@media (max-width: 480px) {
  .chat-page {
    padding: 8px;
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-right: calc(8px + env(safe-area-inset-right));
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    padding-left: calc(8px + env(safe-area-inset-left));
  }

  .chat-page .chat-container {
    min-height: calc(100svh - 16px);
    border-radius: 14px;
    padding: 10px;
    gap: 10px;
  }

  .chat-page .header-actions {
    gap: 6px;
  }

  .chat-page .settings-link {
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .chat-page .message {
    max-width: 92%;
    font-size: 0.92rem;
  }

  .chat-page .composer {
    flex-wrap: wrap;
  }

  .chat-page #message-input,
  .chat-page #send-button,
  .chat-page .edit-input,
  .chat-page .edit-btn {
    width: 100%;
  }
}

@media (min-width: 481px) and (max-width: 900px) {
  .chat-page .chat-container {
    min-height: min(95svh, 820px);
    padding: 14px;
  }

  .chat-page .message {
    max-width: 86%;
  }
}

@media (min-width: 901px) {
  .chat-page .chat-container {
    min-height: min(88svh, 860px);
    padding: 18px;
  }
}
