/* MUTA v200.270 - 30-chat-mobile-fix.css - CHAT MOBILE PREMIUM FIX - هوشمند/پیام‌رسان style */
.muta-dm {
  display: none;
  flex-direction: column;
  gap: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  min-height: 560px;
  max-height: 80vh;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}

.muta-dm-inner {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.muta-dm-sidebar {
  width: 300px;
  min-width: 260px;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  flex-shrink: 0;
}

.muta-dm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--card);
  min-height: 0;
}

/* Conversation items */
.dm-conv {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
  border: 1px solid transparent;
  background: transparent;
}
.dm-conv:hover {
  background: var(--surface-2);
  border-color: var(--line);
  transform: translateX(-2px);
}
.dm-conv.active {
  background: var(--gold-soft);
  border-color: var(--gold-border);
}
.dm-name {
  font-weight: 700;
  font-size: .88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-last {
  font-size: .75rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.dm-badge {
  background: var(--gold);
  color: #000;
  font-size: .65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 99px;
  min-width: 18px;
  text-align: center;
}
.dm-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface-2);
  transition: all .15s ease;
}
.dm-search-item:hover {
  background: var(--gold-soft);
  border-color: var(--gold-border);
}

/* Messages */
#mutaDmMessages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: radial-gradient(ellipse at 50% 0%, rgba(212,175,55,.06), transparent 60%), var(--card);
  -webkit-overflow-scrolling: touch;
}
.dm-msg {
  max-width: 72%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: .88rem;
  line-height: 1.7;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: msgIn .25s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.dm-msg.mine {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--gold), var(--gold-2, #B8941F));
  color: #000;
  border-bottom-left-radius: 4px;
  font-weight: 500;
}
.dm-msg.theirs {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-bottom-right-radius: 4px;
}
.dm-time {
  font-size: .65rem;
  opacity: .6;
  margin-right: 8px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.dm-msg.mine .dm-time {
  color: rgba(0,0,0,.6);
}
.chat-empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

/* Back button - hidden on desktop */
.dm-back-btn {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 1rem;
  transition: all .15s ease;
}
.dm-back-btn:hover {
  background: var(--surface-3);
  border-color: var(--line-3);
}

/* ===== MOBILE FIX - v270 - پیام‌رسان/WhatsApp style ===== */
@media (max-width: 768px) {
  #view-chat .container {
    padding-left: 12px;
    padding-right: 12px;
  }
  
  .muta-dm {
    min-height: calc(100dvh - 56px - 24px);
    max-height: calc(100dvh - 56px - 12px);
    border-radius: 16px;
    margin: 0 -4px;
  }
  
  .muta-dm-inner {
    flex-direction: column;
  }
  
  .muta-dm-sidebar {
    width: 100% !important;
    min-width: 0 !important;
    border-left: none !important;
    border-bottom: none;
    flex: 1;
    max-height: 100%;
    display: flex !important;
  }
  
  .muta-dm-main {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: none !important;
  }
  
  /* Mobile states */
  .muta-dm.mobile-chat-open .muta-dm-sidebar {
    display: none !important;
  }
  .muta-dm.mobile-chat-open .muta-dm-main {
    display: flex !important;
  }
  .muta-dm:not(.mobile-chat-open) .muta-dm-sidebar {
    display: flex !important;
  }
  .muta-dm:not(.mobile-chat-open) .muta-dm-main {
    display: none !important;
  }
  
  .dm-back-btn {
    display: flex !important;
  }
  
  #mutaDmMessages {
    padding: 12px;
    gap: 8px;
  }
  
  .dm-msg {
    max-width: 84%;
    font-size: .85rem;
    padding: 9px 12px;
  }
  
  /* Input area - fixed at bottom, safe for keyboard */
  .muta-dm-main > div:last-child {
    padding: 10px !important;
    gap: 8px !important;
    background: var(--surface) !important;
    border-top: 1px solid var(--line);
    position: sticky;
    bottom: 0;
    z-index: 2;
  }
  
  #mutaDmInput {
    height: 40px !important;
    font-size: 16px !important; /* Prevent iOS zoom */
    border-radius: 12px !important;
  }
  
  #mutaDmSend {
    height: 40px !important;
    padding: 0 14px !important;
    border-radius: 12px !important;
    font-size: .85rem !important;
    flex-shrink: 0;
  }
  
  /* Header */
  #mutaDmHead {
    padding: 10px 12px !important;
    min-height: 48px !important;
    font-size: .85rem !important;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-2) !important;
  }
  
  /* Search */
  #mutaDmSearch {
    height: 40px !important;
    font-size: 16px !important;
  }
  
  /* Conversations list */
  #mutaDmConvs {
    padding: 8px !important;
    gap: 4px !important;
  }
  
  .dm-conv {
    padding: 12px !important;
    border-radius: 12px !important;
  }
  
  /* Welcome card mobile */
  .chat-welcome {
    padding: 16px !important;
    border-radius: 16px !important;
  }
  .chat-welcome-cover img {
    height: 160px !important;
    border-radius: 12px !important;
  }
  .chat-welcome-title {
    font-size: 1.05rem !important;
  }
  .chat-welcome-text {
    font-size: .82rem !important;
  }
}

/* Extra small mobile */
@media (max-width: 480px) {
  .muta-dm {
    border-radius: 12px;
    min-height: calc(100dvh - 56px - 16px);
  }
  
  .dm-msg {
    max-width: 88%;
  }
}

/* Smooth transitions */
.muta-dm-sidebar,
.muta-dm-main {
  transition: transform .25s cubic-bezier(0.4,0,0.2,1), opacity .2s ease;
}

/* Scrollbar styling */
#mutaDmConvs::-webkit-scrollbar,
#mutaDmMessages::-webkit-scrollbar {
  width: 4px;
}
#mutaDmConvs::-webkit-scrollbar-thumb,
#mutaDmMessages::-webkit-scrollbar-thumb {
  background: var(--line-3);
  border-radius: 99px;
}
#mutaDmConvs::-webkit-scrollbar-track,
#mutaDmMessages::-webkit-scrollbar-track {
  background: transparent;
}
