/* ── カラーパレット ── */
:root {
  --color-primary:    #7986CB;
  --color-primary-dk: #5c6bc0;
  --color-secondary:  #80CBC4;
  --color-surface:    #F5F5F5;
  --color-background: #FAFAFA;
  --color-on-primary: #FFFFFF;
  --color-error:      #EF9A9A;
  --color-text:       #424242;
  --color-text-sub:   #757575;
  --border-radius:    8px;
  --shadow-sm:        0 1px 3px rgba(0,0,0,.12);
  --shadow-md:        0 2px 8px rgba(0,0,0,.16);
  --sidebar-width:    260px;
}

/* ── リセット ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--color-background);
  color: var(--color-text);
  height: 100dvh;
  overflow: hidden;
}

[v-cloak] { display: none; }

/* ── 認証画面 ── */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  background: linear-gradient(135deg, #e8eaf6 0%, #e0f2f1 100%);
}

.auth-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo .material-symbols-outlined {
  font-size: 48px;
  color: var(--color-primary);
}

.auth-logo h1 {
  font-size: 1.5rem;
  color: var(--color-primary);
  margin-top: 8px;
}

.auth-card label {
  display: block;
  font-size: .8rem;
  color: var(--color-text-sub);
  margin-bottom: 4px;
  margin-top: 16px;
}

.auth-card input[type="text"],
.auth-card input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #e0e0e0;
  border-radius: var(--border-radius);
  font-size: .95rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
}

.auth-card input:focus { border-color: var(--color-primary); }

.btn-primary {
  display: block;
  width: 100%;
  margin-top: 24px;
  padding: 12px;
  background: var(--color-primary);
  color: var(--color-on-primary);
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  transition: background .2s;
}

.btn-primary:hover { background: var(--color-primary-dk); }

.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: .85rem;
  color: var(--color-text-sub);
}

.auth-switch a {
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: none;
}

.auth-switch a:hover { text-decoration: underline; }

.error-msg {
  background: #fff3f3;
  border: 1px solid var(--color-error);
  border-radius: var(--border-radius);
  color: #c62828;
  font-size: .85rem;
  padding: 8px 12px;
  margin-top: 12px;
}

/* ── チャット画面全体 ── */
.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── アプリヘッダー ── */
.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 56px;
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 10;
}

.app-header .logo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
}

.app-header .logo .material-symbols-outlined { font-size: 24px; }

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: rgba(255,255,255,.2);
  border: none;
  border-radius: 20px;
  color: #fff;
  font-size: .8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background .2s;
}

.btn-logout:hover { background: rgba(255,255,255,.35); }

/* ── チャットレイアウト ── */
.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── サイドバー ── */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-title {
  padding: 14px 16px 10px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--color-text-sub);
  text-transform: uppercase;
  letter-spacing: .08em;
  border-bottom: 1px solid #f0f0f0;
}

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

.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background .15s;
  border-bottom: 1px solid #f5f5f5;
}

.user-item:hover { background: #f5f5f5; }
.user-item.active { background: #e8eaf6; }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
}

.avatar-sm {
  width: 32px;
  height: 32px;
  font-size: .85rem;
}

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

.user-name {
  font-weight: 500;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-preview {
  font-size: .78rem;
  color: var(--color-text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* ── メインチャットエリア ── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-surface);
}

.no-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--color-text-sub);
  gap: 12px;
}

.no-chat .material-symbols-outlined { font-size: 64px; opacity: .4; }
.no-chat p { font-size: .95rem; }

/* ── チャットヘッダー ── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.chat-header .chat-partner-name {
  font-weight: 600;
  font-size: 1rem;
}

/* ── メッセージエリア ── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

/* 日付セパレーター */
.date-separator {
  text-align: center;
  margin: 12px 0 4px;
}

.date-separator span {
  display: inline-block;
  background: rgba(0,0,0,.1);
  color: var(--color-text-sub);
  font-size: .72rem;
  padding: 2px 10px;
  border-radius: 12px;
}

/* ── メッセージ行 ── */
.message {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

.message.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.message.theirs {
  align-self: flex-start;
  align-items: flex-start;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

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

/* テキストバブル */
.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: .92rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.mine  .bubble {
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.theirs .bubble {
  background: #fff;
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
  border-bottom-left-radius: 4px;
}

/* スタンプ */
.stamp-display {
  font-size: 3rem;
  line-height: 1;
  padding: 4px 0;
  cursor: default;
  user-select: none;
}

/* 画像 */
.image-message img {
  max-width: 200px;
  max-height: 200px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: block;
  object-fit: cover;
}

.image-message img:hover { opacity: .9; }

/* タイムスタンプ */
.timestamp {
  font-size: .68rem;
  color: var(--color-text-sub);
  margin-top: 3px;
  padding: 0 4px;
}

/* ── スタンプピッカー ── */
.stamp-picker {
  background: #fff;
  border-top: 1px solid #e0e0e0;
  height: 200px;
  overflow-y: auto;
  padding: 8px 12px 4px;
  flex-shrink: 0;
}

.stamp-category-label {
  font-size: .72rem;
  color: var(--color-text-sub);
  font-weight: 600;
  margin: 4px 0 4px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.stamp-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.stamp-btn {
  font-size: 1.8rem;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--border-radius);
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  transition: background .15s, border-color .15s;
}

.stamp-btn:hover {
  background: #f0f0f0;
  border-color: #e0e0e0;
}

/* ── 入力エリア ── */
.input-area {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  flex-shrink: 0;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--color-text-sub);
  cursor: pointer;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}

.icon-btn:hover { background: #f0f0f0; color: var(--color-primary); }
.icon-btn.active { color: var(--color-primary); background: #e8eaf6; }
.icon-btn .material-symbols-outlined { font-size: 22px; }

.message-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  font-size: .92rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
  background: var(--color-surface);
}

.message-input:focus { border-color: var(--color-primary); }

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .2s, opacity .2s;
}

.send-btn:hover:not(:disabled) { background: var(--color-primary-dk); }
.send-btn:disabled { opacity: .4; cursor: default; }
.send-btn .material-symbols-outlined { font-size: 20px; }

/* ── 画像モーダル ── */
.image-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: zoom-out;
}

.image-modal img {
  max-width: 90vw;
  max-height: 90dvh;
  border-radius: var(--border-radius);
  box-shadow: 0 4px 32px rgba(0,0,0,.5);
  object-fit: contain;
}

/* ── ローディングスピナー ── */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-sub);
  font-size: .9rem;
  gap: 8px;
}

/* スクロールバー */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* ── 戻るボタン（デスクトップでは非表示） ── */
.back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--color-text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}
.back-btn:hover { background: rgba(0,0,0,.06); }
.back-btn .material-symbols-outlined { font-size: 22px; }

/* ══════════════════════════════════════════
   レスポンシブ（スマホ: 767px 以下）
══════════════════════════════════════════ */
@media (max-width: 767px) {

  /* 認証画面 */
  .auth-screen { padding: 16px; align-items: flex-start; padding-top: 10vh; }
  .auth-card   { padding: 28px 20px; border-radius: 12px; }

  /* アプリヘッダー */
  .app-header { height: 50px; padding: 0 12px; }
  .app-header .logo { font-size: 1rem; }
  /* ヘッダーの表示名は省略 */
  .header-user span { display: none; }
  .btn-logout { padding: 5px 10px; font-size: .75rem; }

  /* チャットレイアウト: サイドバーとチャットを全画面切り替え */
  .chat-layout { position: relative; }

  .sidebar {
    width: 100%;
    border-right: none;
  }

  /* Vue の :class で付与するクラス */
  .sidebar.mobile-hidden   { display: none; }
  .chat-main.mobile-hidden { display: none; }

  /* デスクトップ用の常時表示を上書きしない（メディアクエリ外は影響なし） */

  /* 戻るボタンを表示 */
  .back-btn { display: flex; }

  /* チャットヘッダー */
  .chat-header { padding: 8px 12px; }

  /* メッセージ */
  .message { max-width: 85%; }

  /* スタンプピッカー */
  .stamp-picker { height: 220px; }
  .stamp-btn    { font-size: 2rem; padding: 6px 8px; }

  /* 入力エリア */
  .input-area   { padding: 8px 10px; gap: 4px; }
  .message-input { font-size: .9rem; padding: 9px 12px; }
  .icon-btn     { width: 36px; height: 36px; }
  .send-btn     { width: 38px; height: 38px; }

  /* ユーザーリスト: タップ領域を大きく */
  .user-item    { padding: 14px 16px; }
  .avatar       { width: 44px; height: 44px; font-size: 1.1rem; }
}

/* タブレット（768px〜1024px）: サイドバー幅を少し縮める */
@media (min-width: 768px) and (max-width: 1024px) {
  :root { --sidebar-width: 200px; }
  .message { max-width: 78%; }
}
::-webkit-scrollbar-thumb:hover { background: #aaa; }
