/* ============================================
   Chat.P.t.P - استایل کامل (بهبودیافته)
   ============================================ */

:root {
  --ptp-primary: #800000;
  --ptp-primary-hover: #a00020;
  --ptp-dark: #1a1a2e;
  --ptp-gray-light: #f4f6f9;
  --ptp-white: #ffffff;
  --ptp-danger: #c0392b;
  --ptp-success: #27ae60;
  --ptp-radius: 14px;
  --ptp-shadow: 0 10px 35px rgba(0, 0, 0, 0.4);
}

/* ========== فونت ========== */
#ptp-chat-modal,
#ptp-chat-floating,
.ptp-notification,
#ptp-chat-modal input,
#ptp-chat-modal textarea,
#ptp-chat-modal button {
  font-family: inherit !important;
}

/* ========== آیکون شناور ========== */
#ptp-chat-floating {
  position: fixed !important;
  bottom: 20px !important;
  right: 20px !important;
  left: auto !important;
  width: 56px !important;
  height: 56px !important;
  background: linear-gradient(145deg, var(--ptp-primary), var(--ptp-primary-hover)) !important;
  border-radius: 50% !important;
  cursor: pointer !important;
  z-index: 999998 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow: 0 4px 15px rgba(128, 0, 0, 0.4) !important;
  animation: ptp-rotate 10s ease-in-out infinite !important;
  transition: transform 0.3s ease, box-shadow 0.3s ease !important;
}
#ptp-chat-floating.ptp-left {
  right: auto !important;
  left: 20px !important;
}
#ptp-chat-floating img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}
@keyframes ptp-rotate {
  0%, 100% { transform: perspective(500px) rotateY(0deg) scale(1); }
  15%     { transform: perspective(500px) rotateY(360deg) scale(1.12); }
  30%     { transform: perspective(500px) rotateY(360deg) scale(1); }
}
#ptp-chat-floating:hover {
  animation-play-state: paused;
  transform: perspective(500px) rotateY(8deg) scale(1.1) !important;
  box-shadow: 0 8px 25px rgba(128, 0, 0, 0.7) !important;
}

/* ========== overlay ========== */
#ptp-chat-modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.25);
  z-index: 999999;
}
#ptp-chat-modal-overlay.active {
  display: flex;
}
#ptp-chat-modal-overlay.ptp-right {
    justify-content: flex-end;
    align-items: flex-end;
    padding: 0 20px 76px 0;  /* 56px آیکون + 20px فاصله از پایین */
}
#ptp-chat-modal-overlay.ptp-left {
    justify-content: flex-start;
    align-items: flex-end;
    padding: 0 0 76px 20px;
}

/* ========== مودال اصلی ========== */
#ptp-chat-modal {
  width: 370px;
  max-width: 92vw;
  height: 480px;
  max-height: 70vh;
  background: var(--ptp-white);
  border-radius: var(--ptp-radius);
  box-shadow: var(--ptp-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.3s ease;
  position: relative;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ========== هدر ========== */
.ptp-modal-header {
  background: var(--ptp-white);
  color: var(--ptp-dark);
  padding: 10px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  font-size: 13px;
  border-bottom: 2px solid var(--ptp-primary);
  flex-shrink: 0;
}
.ptp-modal-header span:first-child {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ptp-close {
  font-size: 24px;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--ptp-primary);
  padding: 0 4px;
  line-height: 1;
  transition: color 0.2s;
}
.ptp-close:hover {
  color: var(--ptp-primary-hover);
}

/* ========== بخش ورود/تایید ========== */
.ptp-auth-section {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  background: var(--ptp-gray-light);
}
.ptp-auth-section h4 {
  color: var(--ptp-primary);
  text-align: center;
  margin-bottom: 15px;
  font-size: 14px;
  font-weight: bold;
}
.ptp-form-control {
  width: 100%;
  padding: 12px 15px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 14px;
  box-sizing: border-box;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
  background: var(--ptp-white);
}
.ptp-form-control:focus {
  border-color: var(--ptp-primary);
  box-shadow: 0 0 0 3px rgba(128, 0, 0, 0.1);
  outline: none;
}
.ptp-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 15px;
}

/* ========== کد OTP ========== */
.ptp-otp-inputs {
  display: flex;
  justify-content: center;
  gap: 8px;
  direction: ltr;
}
.ptp-otp-box {
  width: 42px;
  height: 50px;
  font-size: 24px;
  text-align: center;
  border: 2px solid #ccc;
  border-radius: 10px;
  background: var(--ptp-white);
  color: var(--ptp-dark);
  font-weight: bold;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  outline: none;
  box-sizing: border-box;
}
.ptp-otp-box:focus {
  border-color: var(--ptp-primary);
  box-shadow: 0 0 0 3px rgba(128, 0, 0, 0.15);
}
.ptp-otp-box.filled {
  border-color: var(--ptp-primary);
  background: #fff9e6;
}

/* ========== محیط چت ========== */
.ptp-chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--ptp-gray-light);
}

/* بخش پیام‌ها با اسکرول سفارشی */
.ptp-messages {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  background: #eef0f5;
  min-height: 0;
  scroll-behavior: smooth;
}
.ptp-messages::-webkit-scrollbar {
  width: 5px;
}
.ptp-messages::-webkit-scrollbar-track {
  background: transparent;
}
.ptp-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 5px;
}
.ptp-messages::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* حباب‌های پیام */
.ptp-msg {
  margin: 8px 0;
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 80%;
  word-wrap: break-word;
  clear: both;
  font-size: 13px;
  line-height: 1.6;
  position: relative;
}

/* پیام کاربر (خودمان) */
.ptp-user-me { background: #1b5e20; color: #fff; float: right; }

/* پیام دیگر کاربران و پشتیبان */
.ptp-user-other, .ptp-agent { background: #1a1a2e; color: #fff; float: left; }

/* پیام سیستمی */
.ptp-system {
  text-align: center;
  color: #666;
  font-style: italic;
  clear: both;
  max-width: 100%;
  background: transparent;
  font-size: 11px;
}

/* زمان پیام */
.time {
  font-size: 10px;
  color: #ccc;
  margin-top: 4px;
  display: block;
}

/* ========== ناحیه ورودی ========== */
.ptp-input-area {
    position: relative;
    padding: 10px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
}

/* ردیف اصلی (فیلد + دکمه ارسال) */
.ptp-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.ptp-text-input {
    flex: 1;
    resize: none;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 50px 10px 15px; /* جای دکمه ارسال */
    font-size: 13px;
    min-height: 40px;
    height: 40px;
    max-height: 80px;
    outline: none;
    font-family: inherit;
}
.ptp-text-input:focus {
  border-color: var(--ptp-primary);
  box-shadow: 0 0 0 2px rgba(128, 0, 0, 0.08);
}

.ptp-send-btn {
    position: absolute;
    right: 10px;
    bottom: 12px;
    background: #800000;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
}
.ptp-send-btn:hover {
  background: var(--ptp-primary-hover);
  transform: scale(1.05);
}
.ptp-send-btn:focus-visible {
  outline: 2px solid var(--ptp-primary);
  outline-offset: 2px;
}

/* نوار ابزار (اموجی و...) */
.ptp-toolbar {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 5px 0 0;
}
.ptp-tool-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}
.ptp-tool-btn:hover { background: #f0f0f0; }

/* مخفی کردن دکمه ایموجی در صورت نیاز */
#ptp-emoji-btn {
  display: none !important;
}

/* ========== دکمه‌های عمومی ========== */
.ptp-btn {
  background: var(--ptp-primary);
  color: var(--ptp-white);
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
}
.ptp-btn:hover {
  background: var(--ptp-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(128, 0, 0, 0.2);
}
.ptp-btn:focus-visible {
  outline: 2px solid var(--ptp-primary-hover);
  outline-offset: 2px;
}
.ptp-btn-special {
  background: var(--ptp-dark);
  color: var(--ptp-white);
  font-weight: bold;
}
.ptp-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.ptp-btn-outline {
  background: var(--ptp-white);
  border: 1px solid var(--ptp-primary);
  color: var(--ptp-primary);
}
.ptp-btn-outline:hover {
  background: var(--ptp-primary);
  color: var(--ptp-white);
}

/* ========== نوتیفیکیشن ========== */
.ptp-notification {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ptp-white);
  border-right: 4px solid var(--ptp-dark);
  padding: 14px 20px;
  border-radius: 10px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.25);
  z-index: 10000000;
  font-size: 13px;
  animation: notifyIn 0.3s ease;
  min-width: 200px;
  text-align: center;
  color: var(--ptp-dark);
}
.ptp-notification.success {
  border-color: var(--ptp-success);
  color: #155724;
  background: #f0fff4;
}
.ptp-notification.error {
  border-color: var(--ptp-danger);
  color: #721c24;
  background: #fff5f5;
}
@keyframes notifyIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-15px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ========== پنل کاربری ========== */
#ptp-user-panel-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  background: var(--ptp-gray-light);
}

/* ========== مودال‌های تماس ========== */
#ptp-voice-call-modal,
#ptp-video-call-modal {
  font-family: inherit;
}
#ptp-voice-call-modal {
  bottom: 90px !important;
  right: 20px !important;
  left: auto !important;
}

/* آواتار هدر تماس */
.ptp-header-avatar {
  vertical-align: middle;
  object-fit: cover;
}

/* دکمه‌های کنترلی تماس */
.ptp-call-ctrl {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.25s;
}
.ptp-call-ctrl:hover {
  background: rgba(255, 255, 255, 0.25);
}
.ptp-call-end {
  background: var(--ptp-danger);
  border: none;
  border-radius: 50%;
  width: 54px;
  height: 54px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.25s, transform 0.25s;
}
.ptp-call-end:hover {
  background: #e74c3c;
  transform: scale(1.08);
}
.ptp-call-accept,
.ptp-call-reject {
  border-radius: 50%;
  width: 54px;
  height: 54px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  color: var(--ptp-white);
}
.ptp-call-accept {
  background: var(--ptp-success);
}
.ptp-call-reject {
  background: var(--ptp-danger);
}

/* حالت غیرفعال دکمه تماس */
.ptp-call-btn.off {
  background: rgba(255, 255, 255, 0.05);
}
.ptp-call-btn.off svg {
  opacity: 0.4;
}

/* ========== لودینگ ========== */
.ptp-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ptp-loading {
  width: 30px;
  height: 30px;
  border: 3px solid var(--ptp-primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: ptp-spin 0.8s linear infinite;
}
@keyframes ptp-spin {
  to { transform: rotate(360deg); }
}

/* ========== واکنش‌گرایی ========== */
@media (max-width: 480px) {
  #ptp-chat-modal {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
  }
  #ptp-chat-modal-overlay.ptp-right,
  #ptp-chat-modal-overlay.ptp-left {
    padding: 0 !important;
  }
  .ptp-otp-box {
    width: 36px;
    height: 44px;
    font-size: 20px;
  }
  .ptp-msg {
    max-width: 85%;
  }
}