/* ========================================
   LINE風トーク画面 - スタイル定義
   ======================================== */

:root {
  /* カラーパレット */
  --bg-chat: #7494C0;
  --bg-my-msg: #8CE248;
  --bg-other-msg: #FFFFFF;
  --text-primary: #111111;
  --text-secondary: #888888;
  --text-time: rgba(255,255,255,0.7);
  --header-bg: #5B7A99;
  --header-text: #FFFFFF;
  --date-bg: rgba(0,0,0,0.15);
  --date-text: #FFFFFF;
  --system-text: rgba(255,255,255,0.6);
  --shadow: 0 1px 2px rgba(0,0,0,0.08);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Hiragino Sans', sans-serif;
  font-size: 15px;
  color: var(--text-primary);
  background: #000;
}

#app {
  max-width: 430px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  position: relative;
  overflow: hidden;
}

/* ヘッダー */
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px;
  padding-top: max(env(safe-area-inset-top, 10px), 10px);
  background: var(--header-bg);
  color: var(--header-text);
  flex-shrink: 0;
  z-index: 10;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: center;
}

.header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B9D, #C44DFF);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.header-name {
  font-size: 17px;
  font-weight: 700;
}

.header-btn {
  background: none;
  border: none;
  color: var(--header-text);
  padding: 6px;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.2s;
}

.header-btn:hover {
  background: rgba(255,255,255,0.15);
}

/* チャットエリア */
#chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* 日付セパレーター */
.date-group {
  display: flex;
  flex-direction: column;
}

.date-separator {
  position: sticky;
  top: 10px;
  z-index: 5;
  display: flex;
  justify-content: center;
  margin: 16px 0 12px;
}

.date-btn {
  background: var(--date-bg);
  color: var(--date-text);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 16px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: transform 0.1s, background 0.2s;
}

.date-btn:active {
  transform: scale(0.96);
  background: rgba(0,0,0,0.25);
}

/* メッセージ行 */
.message-row {
  display: flex;
  align-items: flex-end;
  margin-bottom: 4px;
  gap: 6px;
  animation: fadeInUp 0.15s ease-out;
}

.message-row.mine {
  flex-direction: row-reverse;
}

/* アバター */
.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B9D, #C44DFF);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  align-self: flex-start;
  margin-top: 2px;
}

.msg-avatar.invisible {
  visibility: hidden;
}

/* メッセージコンテンツ */
.msg-content {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

.msg-sender {
  font-size: 12px;
  color: rgba(255,255,255,0.75);
  margin-bottom: 2px;
  padding-left: 4px;
}

/* バブル */
.msg-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.mine .msg-bubble-wrap {
  flex-direction: row-reverse;
}

.msg-bubble {
  padding: 9px 13px;
  border-radius: 18px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow);
  font-size: 14.5px;
}

.other .msg-bubble {
  background: var(--bg-other-msg);
  color: var(--text-primary);
  border-top-left-radius: 4px;
}

.mine .msg-bubble {
  background: var(--bg-my-msg);
  color: var(--text-primary);
  border-top-right-radius: 4px;
}

/* 連続メッセージの角丸調整 */
.other.consecutive .msg-bubble {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}
.other.consecutive-last .msg-bubble {
  border-top-left-radius: 4px;
}
.mine.consecutive .msg-bubble {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}
.mine.consecutive-last .msg-bubble {
  border-top-right-radius: 4px;
}

/* 時刻 */
.msg-time {
  font-size: 11px;
  color: var(--text-time);
  white-space: nowrap;
  flex-shrink: 0;
  padding-bottom: 2px;
}

/* システムメッセージ */
.system-message {
  text-align: center;
  margin: 8px 0;
}

.system-message span {
  font-size: 12px;
  color: var(--system-text);
  background: rgba(0,0,0,0.08);
  padding: 3px 12px;
  border-radius: 12px;
}

/* スタンプ */
.msg-bubble.stamp {
  background: transparent !important;
  box-shadow: none;
  padding: 4px;
}

.stamp-placeholder {
  width: 120px;
  height: 120px;
  background: linear-gradient(135deg, rgba(255,255,255,0.2), rgba(255,255,255,0.05));
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  gap: 8px;
  color: rgba(255,255,255,0.8);
  border: 2px dashed rgba(255,255,255,0.25);
}

.stamp-placeholder .icon {
  font-size: 40px;
  opacity: 0.9;
}

/* 写真・動画 */
.msg-bubble.media {
  background: transparent !important;
  box-shadow: none;
  padding: 2px;
}

.media-placeholder {
  width: 180px;
  height: 130px;
  background: linear-gradient(135deg, rgba(0,0,0,0.15), rgba(0,0,0,0.05));
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  border: 1px solid rgba(255,255,255,0.15);
}

.media-placeholder .icon {
  font-size: 28px;
  opacity: 0.6;
}

/* 通話 */
.msg-bubble.call {
  background: rgba(255,255,255,0.15) !important;
  border: 1px solid rgba(255,255,255,0.2);
}

.call-content {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255,255,255,0.85);
  font-size: 13px;
}

.call-content .call-icon {
  font-size: 18px;
}

/* 既読 */
.msg-read {
  font-size: 11px;
  color: var(--text-time);
  white-space: nowrap;
  flex-shrink: 0;
}

/* スクロールバー */
#chat-area::-webkit-scrollbar {
  width: 4px;
}
#chat-area::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.3);
  border-radius: 4px;
}

/* アニメーション */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* レスポンシブ */
@media (max-width: 430px) {
  #app {
    max-width: 100%;
  }
}

/* コントロールバー */
#controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid rgba(0,0,0,0.1);
  z-index: 10;
  flex-shrink: 0;
}

.perspective-toggle {
  display: flex;
  gap: 12px;
  font-size: 13px;
  font-weight: 500;
}

.perspective-toggle label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
}

#search-input {
  padding: 5px 10px;
  border: 1px solid #ccc;
  border-radius: 12px;
  font-size: 13px;
  width: 140px;
  outline: none;
}

#search-count {
  font-size: 11px;
  color: #666;
}

.search-btn {
  background: #eee;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 3px 6px;
  cursor: pointer;
  font-size: 12px;
}

.search-btn:active {
  background: #ddd;
}

.d-none {
  display: none !important;
}

/* 検索ハイライト */
.highlight {
  background-color: #ffd54f;
  color: #000;
  border-radius: 2px;
}
.highlight.active {
  background-color: #ff9800;
  color: #fff;
  font-weight: bold;
}

/* カレンダーモーダル */
.modal-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.2s;
  backdrop-filter: blur(2px);
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.calendar-content {
  background: #fff;
  width: 85%;
  max-width: 320px;
  max-height: 70%;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  transform: translateY(0);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden .calendar-content {
  transform: translateY(20px);
}

.calendar-header {
  padding: 16px 20px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f9fa;
}

.calendar-header h3 {
  font-size: 16px;
  color: #333;
  font-weight: 700;
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  color: #888;
  cursor: pointer;
  line-height: 1;
}

#calendar-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.calendar-month {
  margin-bottom: 20px;
}

.calendar-month h4 {
  font-size: 14px;
  color: #666;
  margin-bottom: 10px;
  border-bottom: 2px solid #eee;
  padding-bottom: 4px;
}

.calendar-days {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cal-day-btn {
  background: #f0f4f8;
  color: #333;
  border: 1px solid #e1e8ed;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.cal-day-btn:hover {
  background: #e1e8ed;
  border-color: #cbd5e1;
}

.cal-day-btn:active {
  background: #cbd5e1;
  transform: scale(0.95);
}
