/* ================================================================
   dm.css  ─  ダイレクトメッセージ ページ スタイル
================================================================ */

/* ---- レイアウト ---- */
.dm-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.dm-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---- サイドバー ---- */
.dm-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.25s;
}

.dm-sidebar-header {
  padding: 16px 18px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.dm-conv-list {
  flex: 1;
  overflow-y: auto;
}

.dm-empty-conv {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
}
.dm-empty-conv span { font-size: 2rem; }

/* 会話アイテム */
.dm-conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.dm-conv-item:hover  { background: var(--bg-elevated); }
.dm-conv-item.active { background: var(--amber-subtle); border-left: 3px solid var(--amber); }

/* アバターを小さく */
.dm-conv-item .avatar.avatar-sm {
  width: 30px !important;
  height: 30px !important;
  font-size: 0.72rem !important;
  flex-shrink: 0;
}

.dm-conv-info { flex: 1; min-width: 0; }

.dm-conv-name {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 1px;
}
.dm-conv-last {
  font-size: 0.66rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}
.dm-conv-time {
  font-size: 0.60rem;
  color: var(--text-muted);
}
.dm-conv-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--amber);
  color: var(--bg-deep);
  font-size: 0.58rem;
  font-weight: 700;
  border-radius: 8px;
}

.dm-conv-item-info { flex: 1; min-width: 0; }

.dm-conv-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 1px;
}
.dm-conv-item-name {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-conv-item-time {
  font-size: 0.60rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.dm-conv-item-last {
  font-size: 0.66rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 未読バッジ */
.dm-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--amber);
  color: var(--bg-deep);
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 9px;
  flex-shrink: 0;
}

/* ---- メイン ---- */
.dm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-dark);
}

/* 未選択状態 */
.dm-no-conv {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}
.dm-no-conv h2 { font-size: 1.3rem; color: var(--text-secondary); }
.dm-no-conv p  { font-size: 0.85rem; line-height: 1.7; }

/* ---- 会話エリア ---- */
.dm-conv-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.dm-conv-area.hidden { display: none; }

/* 会話ヘッダー */
.dm-conv-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-amber);
  flex-shrink: 0;
}
.dm-back-btn { display: none; }
.dm-partner-info { flex: 1; min-width: 0; }
.dm-partner-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}
.dm-partner-id {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: monospace;
  margin-top: 1px;
}

/* メッセージ一覧 */
.dm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.dm-messages-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100%;
  justify-content: flex-end;
}

/* 会話開始メッセージ */
.dm-start-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* メッセージ行 */
.dm-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.dm-msg-row.own { flex-direction: row-reverse; }

.dm-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 68%;
}
.dm-msg-row.own .dm-bubble-wrap { align-items: flex-end; }

.dm-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-primary);
  word-break: break-word;
}
.dm-bubble.own {
  background: rgba(244, 166, 32, 0.12);
  border-color: rgba(244, 166, 32, 0.25);
}

.dm-bubble-text { white-space: pre-wrap; }

.dm-bubble-img {
  max-width: 240px;
  max-height: 200px;
  border-radius: 10px;
  cursor: zoom-in;
  display: block;
  margin-top: 4px;
}

.dm-bubble-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  padding: 0 2px;
}
.dm-bubble-meta .avatar { flex-shrink: 0; }
.dm-bubble-meta.own { flex-direction: row-reverse; }

.dm-bubble-time {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.dm-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 2px;
  display: flex;
  align-items: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.dm-msg-row:hover .dm-delete-btn { opacity: 1; }
.dm-delete-btn:hover { color: #ef5350; }

/* ---- 入力エリア ---- */
.dm-input-area {
  padding: 12px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.dm-media-preview {
  display: none;
  margin-bottom: 10px;
  gap: 8px;
  flex-wrap: wrap;
}

.dm-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.dm-attach-btn {
  flex-shrink: 0;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.dm-attach-btn:hover { color: var(--amber); }

.dm-textarea {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 10px 14px;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.2s;
}
.dm-textarea:focus {
  outline: none;
  border-color: var(--amber-dim);
}
.dm-textarea::placeholder { color: var(--text-dim); }

.dm-send-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  margin-bottom: 2px;
}

/* ---- モバイル対応 ---- */
@media (max-width: 640px) {
  /* ヘッダー fixed 固定 */
  .app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    z-index: 200;
  }
  /* fixed ヘッダーはフローから外れるので padding-top のみで補う */
  .dm-layout {
    padding-top: 52px;
    box-sizing: border-box;
  }
  .dm-sidebar {
    position: fixed;
    left: 0; top: 52px; bottom: 0;
    z-index: 50;
    width: 100%;
    transform: translateX(0);
  }
  .dm-sidebar.dm-sidebar-hidden {
    transform: translateX(-100%);
    pointer-events: none;
  }
  .dm-main { width: 100%; }
  .dm-back-btn { display: flex; }
  .dm-conv-area:not(.hidden) { display: flex; }
}

/* ================================================================
   DM RESPONSIVE OVERHAUL
================================================================ */
@media (max-width: 600px) {
  /* サイドバー */
  .dm-sidebar { width: 100%; top: 54px; }
  .dm-sidebar-header { padding: 12px 14px; font-size: .85rem; }

  /* 会話アイテム */
  .dm-conv-item { padding: 10px 12px; }
  .dm-conv-name { font-size: .88rem; }
  .dm-conv-preview { font-size: .76rem; }

  /* メッセージエリア */
  .dm-input-area { padding: 8px 10px; gap: 6px; }
  .dm-input { font-size: 16px; padding: 8px 12px; } /* iOSズーム防止 */

  /* DM バブル */
  .dm-bubble-wrap { max-width: 70vw; }
  .dm-bubble { max-width: 100%; font-size: .85rem; }
  .dm-messages { padding: 10px; }

  /* ヘッダー */
  .dm-chat-header { padding: 0 10px; }
  .dm-chat-header h3 { font-size: .9rem; }
}
