/* ========== PHONE MESSAGE APP — Dark Theme Chat Detail ========== */

/* ============================================================
   ROOT CONTAINER — FIXED: proper height containment
   ============================================================ */
.pmsg-dark {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  background: #1c1c1e;
  color: #f5f5f5;
  overflow: hidden;
}

/* ============================================================
   CHAT HEADER
   ============================================================ */
.pmsg-chat-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: #2c2c2e;
  border-bottom: 1px solid #3a3a3c;
  flex-shrink: 0;
  gap: 10px;
  min-height: 48px;
}

.pmsg-back-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.pmsg-back-btn svg {
  width: 20px;
  height: 20px;
  stroke: #0a84ff;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pmsg-chat-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.pmsg-chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #48484a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,.6);
  flex-shrink: 0;
  margin-bottom: 2px;
  overflow: hidden;
}

.pmsg-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pmsg-chat-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  line-height: 1.3;
}

.pmsg-chat-header-right {
  width: 28px;
  flex-shrink: 0;
}

/* ============================================================
   MESSAGE LIST — FIXED: min-height:0 for flex containment
   ============================================================ */
.pmsg-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  background: #1c1c1e;
}

.pmsg-chat-messages::after {
  content: "";
  display: block;
  height: 6px;
  flex-shrink: 0;
}

/* Time separator */
.pmsg-time-label {
  align-self: center;
  flex-shrink: 0;                /* ★ 防止被压缩 */
  font-size: 11px;
  font-weight: 500;
  color: rgba(255,255,255,.3);
  margin: 14px 0 8px;
  padding: 2px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
}

.pmsg-chat-messages > .pmsg-time-label:first-child {
  margin-top: 4px;
}

/* ============================================================
   MESSAGE ROW / BUBBLE
   ============================================================ */
.pmsg-msg-row {
  display: flex;
  max-width: 78%;
  margin-top: 3px;
  animation: pmsgFadeIn .2s ease;
  flex-shrink: 0;
}

.pmsg-msg-row.pmsg-group-first {
  margin-top: 12px;
}

.pmsg-msg-sent {
  align-self: flex-end;
  justify-content: flex-end;
}

.pmsg-msg-received {
  align-self: flex-start;
}

.pmsg-msg-bubble {
  padding: 9px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* User bubble — deep blue */
.pmsg-msg-sent .pmsg-msg-bubble {
  background: #0a84ff;
  color: #fff;
  border-bottom-right-radius: 6px;
}

/* NPC bubble — mid gray */
.pmsg-msg-received .pmsg-msg-bubble {
  background: #3a3a3c;
  color: #f5f5f5;
  border-bottom-left-radius: 6px;
}

/* Consecutive same-sender radius tweaks */
.pmsg-msg-sent + .pmsg-msg-sent {
  margin-top: 2px;
}
.pmsg-msg-sent + .pmsg-msg-sent .pmsg-msg-bubble {
  border-top-right-radius: 6px;
}

.pmsg-msg-received + .pmsg-msg-received {
  margin-top: 2px;
}
.pmsg-msg-received + .pmsg-msg-received .pmsg-msg-bubble {
  border-top-left-radius: 6px;
}

@keyframes pmsgFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   INPUT BAR — FIXED: stays at bottom, no overlap
   ============================================================ */
.pmsg-chat-input-bar {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: #2c2c2e;
  border-top: 1px solid #3a3a3c;
  gap: 8px;
  flex-shrink: 0;
  margin-top: auto;   /* ★ 双保险贴底 */
  z-index: 5;
}

.pmsg-chat-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: #3a3a3c;
  border-radius: 18px;
  border: 1px solid #48484a;
  overflow: hidden;
}

.pmsg-chat-input {
  width: 100%;
  background: transparent;
  border: none;
  padding: 8px 14px;
  font-size: 14px;
  color: #f5f5f5;
  outline: none;
  font-family: inherit;
}

.pmsg-chat-input::placeholder {
  color: rgba(255,255,255,.25);
}

.pmsg-chat-send-btn {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 50%;
  background: #0a84ff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .15s;
}

.pmsg-chat-send-btn:active {
  opacity: .7;
}

.pmsg-chat-send-btn svg {
  width: 14px;
  height: 14px;
}

/* ============================================================
   DICE BUTTON (in messages list header)
   ============================================================ */
.pmsg-dice-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .15s;
}

.pmsg-dice-btn:active {
  opacity: .6;
}

/* ============================================================
   EMPTY STATE (messages list)
   ============================================================ */
.pmsg-empty {
  text-align: center;
  padding: 70px 24px;
  color: rgba(255,255,255,.3);
}

.pmsg-empty svg {
  opacity: .25;
  margin-bottom: 16px;
}

.pmsg-empty-title {
  font-size: 15px;
  color: rgba(255,255,255,.4);
  margin-bottom: 6px;
}

.pmsg-empty-sub {
  font-size: 12px;
  color: rgba(255,255,255,.2);
}

/* ============================================================
   LOADING STATE
   ============================================================ */
.pmsg-loading {
  text-align: center;
  padding: 80px 24px;
  color: rgba(255,255,255,.4);
}

.pmsg-loading-dots {
  display: inline-flex;
  gap: 5px;
  margin-bottom: 16px;
}

.pmsg-loading-dots span {
  width: 8px;
  height: 8px;
  background: rgba(255,255,255,.4);
  border-radius: 50%;
  animation: blink 1.4s infinite both;
}

.pmsg-loading-dots span:nth-child(2) { animation-delay: .2s; }
.pmsg-loading-dots span:nth-child(3) { animation-delay: .4s; }

/* ============================================================
   MESSAGE INFO LINE (inside chat)
   ============================================================ */
.pmsg-info-line {
  align-self: center;
  font-size: 11px;
  font-weight: 500;
  color: rgba(255,255,255,.2);
  text-align: center;
  margin: 6px 0 2px;
  flex-shrink: 0;
}

/* ============================================================
   USER PINNED CHAT ITEM — subtle highlight
   ============================================================ */
.pmsg-chat-item {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}

.pmsg-chat-item:active {
  background: rgba(255,255,255,.04);
}

.pmsg-user-pinned {
  background: rgba(10, 132, 255, .04);
  border-bottom: 1px solid rgba(10, 132, 255, .08) !important;
}

.pmsg-avatar-user {
  background: #0a84ff !important;
  color: #fff !important;
  font-size: 16px !important;
}

.pmsg-pin-icon {
  font-size: 14px;
  flex-shrink: 0;
  margin-left: 4px;
  opacity: .6;
}
