/* ============================================================
   chat.css — 統合チャット + アバター + ドアホン + エンディング
   ============================================================ */
.chat-container {
  display: flex;
  height: 100%;
}

/* --- アバター共通 --- */
.chat-avatar {
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  text-align: center;
  flex-shrink: 0;
  letter-spacing: -0.5px;
  object-fit: cover;
}

/* --- 左パネル: トーク一覧 --- */
.chat-list {
  width: 260px;
  border-right: 1px solid var(--border);
  background: var(--bg-sidebar, var(--bg-primary));
  flex-shrink: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.chat-list-header {
  padding: 10px 14px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.chat-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
  position: relative;
  border-left: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-item:hover { background: rgba(0,0,0,0.02); }
.chat-item.active {
  background: var(--bg-secondary);
  border-left-color: var(--accent);
}
.chat-item-body {
  flex: 1;
  min-width: 0;
}
.chat-item-name {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-item-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.chat-item-tag.staff { background: var(--staff-bg); color: var(--staff-text); }
.chat-item-tag.tenant { background: var(--tenant-bg); color: var(--tenant-text); }
.chat-item-tag.unknown { background: #e74c3c; color: #fff; }
.chat-item-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.chat-item-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-time {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
  text-align: right;
}
.chat-item-badge {
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

/* --- 右パネル: トーク画面 --- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-main-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* --- プロフィールカード --- */
.chat-profile {
  padding: 12px 16px;
  background: var(--bg-sidebar, var(--bg-primary));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-profile-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.chat-profile-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}
.chat-profile-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  font-size: 12px;
  line-height: 1.5;
}
.chat-profile-label {
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.chat-profile-value {
  color: var(--text-secondary);
}

/* --- メッセージ --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--msg-bg, var(--bg-primary));
}
.chat-msg {
  max-width: 75%;
}
.chat-msg-other {
  align-self: flex-start;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.chat-msg-bubble {
  background: var(--msg-other);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  box-shadow: rgba(0,0,0,0.06) 0px 1px 3px;
  font-size: 14px;
  line-height: 1.6;
}
.chat-msg-self {
  align-self: flex-end;
  background: var(--msg-self);
  color: #fff;
  padding: 8px 12px;
  border-radius: 12px;
  border-bottom-right-radius: 4px;
  box-shadow: rgba(0,0,0,0.08) 0px 1px 3px;
  font-size: 14px;
  line-height: 1.6;
}
.chat-msg-name {
  font-size: 11px;
  font-weight: 500;
  color: #7a7a7a;
  margin-bottom: 2px;
}
.chat-msg-time {
  font-size: 10px;
  color: #999;
  margin-top: 2px;
  text-align: right;
}
.chat-msg-self .chat-msg-time { color: rgba(255,255,255,0.6); }
/* 区切り線 */
.chat-msg-divider {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  color: var(--text-muted, #999);
  font-size: 10px;
}
.chat-msg-divider::before,
.chat-msg-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-light, rgba(0,0,0,0.08));
}
.chat-msg-divider:empty::before { flex: 1; }
.chat-msg-divider:empty::after { display: none; }

.chat-msg-system {
  align-self: center;
  font-size: 11px;
  color: #fff;
  padding: 4px 12px;
  background: rgba(0,0,0,0.15);
  border-radius: 10px;
}

/* --- コピー可能メッセージ（Base64） --- */
.chat-msg-code {
  background: rgba(0,0,0,0.06);
  padding: 8px 10px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 11px;
  line-height: 1.4;
  word-break: break-all;
  margin: 6px 0;
  max-height: 120px;
  overflow-y: auto;
  user-select: all;
}
.chat-msg-copy-btn {
  display: inline-block;
  margin-top: 4px;
  padding: 4px 14px;
  border-radius: 4px;
  border: 1px solid var(--accent, #4a7fd9);
  background: rgba(74,127,217,0.1);
  color: var(--accent, #4a7fd9);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.chat-msg-copy-btn:hover {
  background: var(--accent, #4a7fd9);
  color: #fff;
}

/* --- タイピングインジケーター --- */
.chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-typing-dots {
  background: var(--msg-other);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: rgba(0,0,0,0.06) 0px 1px 3px;
}
.chat-typing-dot {
  width: 7px;
  height: 7px;
  background: #aaa;
  border-radius: 50%;
  animation: chat-typing-bounce 1.2s infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* --- 入力エリア --- */
.chat-input-area {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  min-height: 44px;
  flex-shrink: 0;
  background: #f0f1f3;
  display: flex;
  align-items: center;
}
.chat-input-placeholder {
  font-size: 13px;
  color: var(--text-muted);
}

/* --- 選択肢 --- */
.chat-choices-inline {
  align-self: flex-end;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  max-width: 85%;
}
.chat-choice-btn {
  padding: 10px 18px;
  border-radius: 8px;
  border: 1.5px solid var(--accent, #4a7fd9);
  background: rgba(74, 127, 217, 0.08);
  color: var(--accent, #4a7fd9);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  font-family: inherit;
  text-align: left;
  line-height: 1.5;
}
.chat-choice-btn:hover {
  background: var(--accent, #4a7fd9);
  color: #fff;
  border-color: var(--accent, #4a7fd9);
}
.chat-choice-btn:active {
  background: var(--accent-hover, #3a6bc0);
  color: #fff;
  border-color: var(--accent-hover, #3a6bc0);
}

/* --- 新着通知 --- */
.chat-notify-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: notify-fade-in 0.3s;
}
.chat-notify-overlay.hiding { animation: notify-fade-out 0.2s forwards; }
@keyframes notify-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes notify-fade-out { from { opacity: 1; } to { opacity: 0; } }
.chat-notify-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  min-width: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.chat-notify-title { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-top: 4px; }
.chat-notify-name { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.chat-notify-sub { font-size: 12px; color: var(--text-secondary); }
.chat-notify-btn {
  margin-top: 12px;
  padding: 8px 28px;
  border: none;
  border-radius: 8px;
  background: var(--accent, #4a7fd9);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

/* ============================================================
   ドアホンオーバーレイ
   ============================================================ */
.doorbell-overlay {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  animation: doorbell-in 0.5s;
}
.doorbell-overlay.fade-out {
  animation: doorbell-out 1s forwards;
}
@keyframes doorbell-in {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes doorbell-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
.doorbell-card {
  width: 340px;
  background: #111;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
  border: 2px solid #333;
}
.doorbell-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: #1a1a1a;
}
.doorbell-rec {
  color: #e74c3c;
  font-size: 10px;
  font-weight: 700;
  font-family: monospace;
  animation: doorbell-blink 1s infinite;
}
@keyframes doorbell-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.doorbell-time {
  color: #888;
  font-size: 10px;
  font-family: monospace;
}
.doorbell-feed {
  height: 320px;
  background: #0a0a0a;
  position: relative;
  overflow: hidden;
}
/* 高橋の写真 */
.doorbell-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 20%;
  filter: brightness(0.5) contrast(1.3) saturate(0.3);
}
/* ノイズオーバーレイ */
.doorbell-noise {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(255,255,255,0.03) 2px,
    rgba(255,255,255,0.03) 4px
  );
  pointer-events: none;
  animation: doorbell-noise 0.1s infinite;
}
@keyframes doorbell-noise {
  0% { opacity: 0.8; }
  50% { opacity: 1; }
  100% { opacity: 0.7; }
}

/* 通知バナー */
.doorbell-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #e74c3c;
  color: #fff;
  text-align: center;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 700;
  z-index: 10001;
  animation: doorbell-banner-in 0.3s, doorbell-banner-pulse 1s 0.3s infinite;
  letter-spacing: 1px;
}
.doorbell-banner.fade-out {
  animation: doorbell-out 0.5s forwards;
}
.doorbell-banner-icon {
  margin-right: 8px;
  animation: doorbell-ring 0.5s infinite;
}
@keyframes doorbell-banner-in {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}
@keyframes doorbell-banner-pulse {
  0%, 100% { background: #e74c3c; }
  50% { background: #c0392b; }
}
@keyframes doorbell-ring {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(15deg); }
  75% { transform: rotate(-15deg); }
}
.doorbell-label {
  text-align: center;
  padding: 6px;
  color: #888;
  font-size: 10px;
  font-family: monospace;
  background: #1a1a1a;
}

/* ============================================================
   通報プログラムウィンドウ
   ============================================================ */
.report-program-content {
  padding: 24px;
  text-align: center;
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.8;
}
.report-status {
  margin-bottom: 16px;
}
.report-progress {
  width: 100%;
  height: 6px;
  background: rgba(0,0,0,0.1);
  border-radius: 3px;
  overflow: hidden;
}
.report-bar {
  height: 100%;
  width: 20%;
  background: var(--accent, #4a7fd9);
  border-radius: 3px;
  transition: width 1.5s ease;
}

/* ============================================================
   エンディングオーバーレイ
   ============================================================ */
.ending-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  animation: ending-in 1s;
}
@keyframes ending-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.ending-content {
  text-align: center;
  color: #fff;
}
.ending-text {
  font-size: 18px;
  font-weight: 300;
  line-height: 2;
  letter-spacing: 1px;
  margin-bottom: 32px;
}
.ending-share-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  background: #fff;
  color: #000;
  border-radius: 30px;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.2s, transform 0.2s;
}
.ending-share-btn:hover {
  background: #e0e0e0;
  transform: scale(1.05);
}

/* ============================================================
   モバイル対応
   ============================================================ */
@media (max-width: 768px) {
  .chat-container {
    position: relative;
    overflow: hidden;
  }
  .chat-list {
    position: absolute;
    inset: 0;
    width: 100%;
    border-right: none;
    z-index: 2;
    transition: transform 0.25s ease;
  }
  .chat-container.sp-detail .chat-list {
    transform: translateX(-100%);
  }
  .chat-list-header {
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0;
  }
  .chat-item { padding: 12px 16px; }
  .chat-item-name { font-size: 14px; }
  .chat-item-sub { font-size: 12px; }
  .chat-item-preview { font-size: 13px; }

  .chat-main {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
  }
  .chat-container.sp-detail .chat-main { z-index: 3; }

  .chat-sp-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg-sidebar, var(--bg-primary));
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .chat-sp-back {
    padding: 12px 16px;
    margin: -8px;
    border: none;
    background: none;
    font-size: 18px;
    color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
    font-family: inherit;
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    touch-action: manipulation;
  }
  .chat-sp-back-badge {
    background: var(--danger, #e74c3c);
    color: #fff;
    font-size: 10px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: 700;
  }
  .chat-sp-header-info {
    flex: 1;
    min-width: 0;
  }
  .chat-sp-header-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .chat-sp-header-sub {
    font-size: 11px;
    color: var(--text-muted);
  }
  .chat-sp-profile-btn {
    flex-shrink: 0;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
  }

  .chat-profile {
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s, padding 0.3s;
    border-bottom: none;
  }
  .chat-profile.expanded {
    max-height: 400px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    overflow-y: auto;
  }

  .chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
    min-height: 0;
  }
  .chat-msg { max-width: 85%; }
  .chat-msg-bubble { font-size: 13px; }
  .chat-msg-self { font-size: 13px; }

  .chat-choices-inline { max-width: 95%; }
  .chat-choice-btn { font-size: 13px; padding: 10px 14px; }

  .chat-input-area {
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .chat-main-empty { display: none; }
  .chat-container:not(.sp-detail) .chat-main { visibility: hidden; }
  .chat-container.sp-detail .chat-main { visibility: visible; }

  /* ドアホン: モバイル */
  .doorbell-overlay {
    top: 10px;
    right: 10px;
  }
  .doorbell-card {
    width: 92vw;
    max-width: 400px;
  }
  .doorbell-feed {
    height: 100vw;
    max-height: 450px;
  }
  .doorbell-feed {
    height: 120px;
  }
}
