/* ===== ROOT ===== */
#p2p-chat-root {
  display: flex;
  flex-direction: column;
  height: 600px;
  border: 1px solid;
  overflow: hidden;
}

/* ===== AGREE ===== */
#p2p-agree {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
#p2p-agree-inner {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#p2p-agree-inner h2 { margin: 0; }
#p2p-agree-body {
  border: 1px solid;
  padding: 16px;
  max-height: 260px;
  overflow-y: auto;
  font-size: 0.9em;
  line-height: 1.7;
}
#p2p-agree-body h3 { margin: 0 0 4px; font-size: 0.95em; }
#p2p-agree-body p  { margin: 0 0 12px; }
#p2p-agree-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9em;
}
#p2p-agree-label input { cursor: pointer; }

/* ===== SETUP ===== */
#p2p-setup {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#p2p-setup-inner {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#p2p-setup-inner h2 { margin: 0; }

.p2p-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.p2p-field label {
  font-size: 0.8em;
  opacity: 0.7;
}
.p2p-field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid;
  background: inherit;
  color: inherit;
  font: inherit;
  box-sizing: border-box;
}
.p2p-myid-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px dashed;
  font-size: 0.85em;
}
#p2p-my-id {
  flex: 1;
  word-break: break-all;
  opacity: 0.8;
}
.p2p-divider {
  text-align: center;
  font-size: 0.8em;
  opacity: 0.5;
  position: relative;
}
.p2p-divider::before,
.p2p-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: currentColor;
  opacity: 0.3;
}
.p2p-divider::before { left: 0; }
.p2p-divider::after  { right: 0; }
.p2p-connect-row {
  display: flex;
  gap: 8px;
}
.p2p-connect-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid;
  background: inherit;
  color: inherit;
  font: inherit;
  box-sizing: border-box;
}
#p2p-setup-hint {
  font-size: 0.8em;
  opacity: 0.6;
  border-top: 1px solid;
  padding-top: 12px;
}

/* ===== CHAT SHELL ===== */
#p2p-chat {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
#p2p-chat.active { display: flex; }

/* ===== HEADER ===== */
#p2p-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid;
  flex-shrink: 0;
  /* ユーザが増えても折り返してボタン類を圧迫しないよう min-height のみ設定 */
  min-height: 40px;
}

/* 接続中ユーザ一覧は最大幅を制限してスクロール可能に */
#p2p-peers-wrap {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}
#p2p-peers-label {
  display: block;
  font-size: 0.8em;
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ボタン群は縮まないように固定 */
#p2p-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ===== MESSAGES ===== */
#p2p-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

/* ===== MESSAGE BUBBLE ===== */
.p2p-msg {
  max-width: 70%;
  padding: 8px 12px;
  font-size: 0.9em;
  line-height: 1.5;
  word-break: break-word;
  border: 1px solid transparent;
  position: relative;
}
.p2p-msg.me {
  align-self: flex-end;
  background-color: rgba(0, 160, 80, 0.12);
  border-color: rgba(0, 160, 80, 0.3);
}
.p2p-msg.other {
  align-self: flex-start;
  background-color: rgba(0, 100, 200, 0.10);
  border-color: rgba(0, 100, 200, 0.25);
}
.p2p-msg .p2p-sender {
  font-size: 0.75em;
  opacity: 0.5;
  margin-bottom: 3px;
}
.p2p-msg .p2p-meta {
  font-size: 0.7em;
  opacity: 0.5;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.p2p-msg.me .p2p-meta { justify-content: flex-end; }

/* ===== REPLY QUOTE ===== */
.p2p-reply-quote {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 8px;
  margin-bottom: 5px;
  border-left: 3px solid currentColor;
  opacity: 0.55;
  font-size: 0.8em;
  background: rgba(128,128,128,0.08);
}
.p2p-reply-quote-from {
  font-weight: bold;
}
.p2p-reply-quote-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== ACTION BUTTONS (reaction / reply) ===== */
.p2p-msg-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
}

/* 「反応」ボタン + ピッカーのコンテナ */
.p2p-reaction-wrap {
  position: relative;
  display: inline-flex;
}

/* 「反応」トグルボタン */
.p2p-reaction-open-btn {
  background: none;
  border: 1px solid transparent;
  padding: 1px 6px;
  cursor: pointer;
  font-size: 0.72em;
  color: inherit;
  opacity: 0.4;
  transition: opacity .15s, border-color .15s;
  white-space: nowrap;
  line-height: 1.6;
}
.p2p-reaction-open-btn:hover {
  opacity: 1;
  border-color: currentColor;
}

/* 絵文字ピッカー（ドロップアップ） */
.p2p-reaction-picker {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  display: flex;
  gap: 2px;
  padding: 4px 6px;
  border: 1px solid;
  background: inherit;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* ピッカー内の絵文字ボタン */
.p2p-reaction-btn {
  background: none;
  border: 1px solid transparent;
  padding: 2px 3px;
  cursor: pointer;
  font-size: 1.1em;
  line-height: 1;
  border-radius: 3px;
  transition: background .12s, border-color .12s;
}
.p2p-reaction-btn:hover {
  border-color: currentColor;
  background: rgba(128,128,128,0.12);
}

/* 「返信」ボタン */
.p2p-reply-btn {
  background: none;
  border: 1px solid transparent;
  padding: 1px 6px;
  cursor: pointer;
  font-size: 0.72em;
  color: inherit;
  opacity: 0.4;
  transition: opacity .15s, border-color .15s;
  white-space: nowrap;
  line-height: 1.6;
}
.p2p-reply-btn:hover {
  opacity: 1;
  border-color: currentColor;
}

/* ===== REACTION BADGES ===== */
.p2p-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.p2p-reaction-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border: 1px solid;
  font-size: 0.8em;
  border-radius: 20px;
  opacity: 0.65;
}
.p2p-reaction-badge.mine {
  opacity: 1;
  background: rgba(0,160,80,0.12);
  border-color: rgba(0,160,80,0.4);
}

/* ===== SYSTEM MSG ===== */
.p2p-sys-msg {
  align-self: center;
  font-size: 0.75em;
  opacity: 0.5;
  padding: 2px 10px;
  border: 1px solid;
}

/* ===== FILE CARD ===== */
.p2p-file-card {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid;
  padding: 8px 12px;
  text-decoration: none;
  color: inherit;
}
a.p2p-file-card:hover { opacity: 0.75; }
.p2p-file-icon { font-size: 1.4em; flex-shrink: 0; }
.p2p-file-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.p2p-file-name { font-size: 0.85em; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p2p-file-size { font-size: 0.75em; opacity: 0.6; }
.p2p-file-status { font-size: 0.7em; opacity: 0.6; }
.p2p-file-status.ok  { opacity: 1; }
.p2p-file-status.err { opacity: 1; }

.p2p-progress-wrap {
  width: 100%;
  height: 3px;
  overflow: hidden;
  opacity: 0.4;
  background: currentColor;
}
.p2p-progress-bar {
  height: 100%;
  background: currentColor;
  width: 0%;
}

.p2p-file-incoming {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px dashed;
  padding: 8px 12px;
  animation: p2p-blink 1.2s ease-in-out infinite;
}
@keyframes p2p-blink { 0%,100%{opacity:1} 50%{opacity:.5} }

/* ===== INLINE IMAGE ===== */
.p2p-image-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  border: 1px solid;
  padding: 8px;
}
.p2p-image-card-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.p2p-image-link {
  display: block;
  cursor: zoom-in;
}
.p2p-image-link:hover { opacity: 0.85; }
.p2p-inline-image {
  display: block;
  max-width: 100%;
  max-height: 300px;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* ===== TYPING ===== */
#p2p-typing {
  padding: 0 12px 2px;
  font-size: 0.75em;
  opacity: 0.5;
  min-height: 18px;
  flex-shrink: 0;
}

/* ===== REPLY BAR ===== */
#p2p-reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-top: 1px solid;
  font-size: 0.8em;
  opacity: 0.75;
  flex-shrink: 0;
  background: rgba(0,0,0,0.03);
}
#p2p-reply-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#p2p-reply-cancel {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1em;
  color: inherit;
  padding: 0 4px;
  flex-shrink: 0;
  opacity: 0.6;
}
#p2p-reply-cancel:hover { opacity: 1; }

/* ===== INPUT BAR ===== */
#p2p-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid;
  flex-shrink: 0;
}
#p2p-file-btn {
  background: none;
  border: 1px solid;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 1em;
  color: inherit;
  flex-shrink: 0;
}
#p2p-msg-input {
  flex: 1;
  border: 1px solid;
  padding: 7px 10px;
  font: inherit;
  resize: none;
  min-height: 36px;
  max-height: 100px;
  overflow-y: auto;
  background: inherit;
  color: inherit;
  box-sizing: border-box;
}
#p2p-send-btn {
  border: 1px solid;
  padding: 6px 14px;
  cursor: pointer;
  font: inherit;
  background: inherit;
  color: inherit;
  flex-shrink: 0;
}
#p2p-send-btn:disabled { opacity: 0.3; cursor: default; }

/* ===== COMMON BUTTON ===== */
.p2p-btn {
  padding: 6px 12px;
  border: 1px solid;
  cursor: pointer;
  font: inherit;
  background: inherit;
  color: inherit;
  white-space: nowrap;
  flex-shrink: 0;
}
.p2p-btn:disabled { opacity: 0.35; cursor: default; }
