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

/* iOSズーム防止: 全入力欄を16px以上に統一（タップ時に画面が拡大しないように） */
input, textarea, select { font-size: 16px !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic', sans-serif;
  background: #e8f5e9;
  color: #212121;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: #2e7d32; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== ヘッダー ===== */
.site-header {
  background: #2e7d32;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
}
.site-header .logo { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.site-header .logo img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.site-header nav { display: flex; align-items: center; gap: 12px; }
.site-header nav a { color: rgba(255,255,255,.85); font-size: 13px; }
.site-header nav a:hover { color: white; text-decoration: none; }
.header-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,.5); }
.unread-badge {
  background: #ef5350; color: white; border-radius: 10px;
  font-size: 11px; padding: 1px 5px; margin-left: 4px;
}

/* ===== 認証フォーム ===== */
.auth-wrap {
  display: flex;
  /* 中央寄せは .auth-card の margin:auto にやらせる。
     ここで align-items:center にすると、カードが画面より高いときに
     上へはみ出した分がスクロールで届かなくなる（登録画面の上が切れる原因だった）。
     スマホでキーボードが出て画面が縮むと、入力中の欄まで画面の外に出てしまう。 */
  align-items: flex-start;
  justify-content: center;
  min-height: calc(100dvh - 52px);
  padding: 24px 16px;
}
.auth-card {
  margin: auto;          /* 収まるときは中央。はみ出すときは上から並ぶ（切れない） */
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
  padding: 32px 28px;
  width: 100%;
  max-width: 420px;
}
.auth-card h2 { font-size: 20px; margin-bottom: 6px; color: #2e7d32; }
.auth-card .sub { font-size: 13px; color: #757575; margin-bottom: 24px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: #424242; margin-bottom: 4px; font-weight: 600; }
.form-group input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  transition: border-color .2s;
}
.form-group input:focus { border-color: #2e7d32; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  text-decoration: none;
}
.btn:hover { opacity: .85; text-decoration: none; }
.btn-primary { background: #2e7d32; color: white; }
.btn-secondary { background: #e8f5e9; color: #2e7d32; }
.btn-danger { background: #ef5350; color: white; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

.alert { padding: 12px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.alert-danger  { background: #ffebee; color: #c62828; border: 1px solid #ffcdd2; }
.alert-info    { background: #e3f2fd; color: #1565c0; border: 1px solid #bbdefb; }

.spam-note {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: #f57f17;
  margin-top: 12px;
}

/* ===== チャットレイアウト ===== */
.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100dvh - 52px);
}

/* サイドバー */
.chat-sidebar {
  width: 240px;
  background: #1b5e20;
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-section { padding: 12px 8px 4px; font-size: 11px; color: rgba(255,255,255,.5); font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.sidebar-room {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  margin: 2px 6px;
  cursor: pointer;
  font-size: 14px;
  color: rgba(255,255,255,.8);
  text-decoration: none;
}
.sidebar-room:hover, .sidebar-room.active { background: rgba(255,255,255,.15); color: white; text-decoration: none; }
.sidebar-room .room-icon { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.sidebar-bottom {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-bottom .my-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.sidebar-bottom .my-name { font-size: 13px; color: rgba(255,255,255,.9); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* メインチャットエリア */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--chat-bg, #f1f8e9);
}
.chat-room-header {
  background: white;
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.chat-room-header .room-name { font-size: 15px; font-weight: 700; }
.chat-room-header .room-desc { font-size: 12px; color: #757575; }

/* メッセージリスト */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.msg-group {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 10px;
}
.msg-group.mine { flex-direction: row-reverse; }
.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: #c8e6c9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #2e7d32;
  font-weight: 700;
}
.msg-body { max-width: 72%; }
.msg-meta { font-size: 11px; color: #9e9e9e; margin-bottom: 3px; }
.msg-group.mine .msg-meta { text-align: right; }
.msg-bubble {
  background: white;
  border-radius: 0 12px 12px 12px;
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-group.mine .msg-bubble {
  background: #b9f6ca;
  border-radius: 12px 0 12px 12px;
}
/* ===== 通常チャット添付専用CSS（出品カードと完全分離）===== */
/* コンテナ: 余白・背景・line-heightを完全にゼロに。imgのbaselineギャップをdisplay:blockで消す */
.chat-media-only {
  background: transparent;
  padding: 0;
  margin: 4px 0 0 0;
  line-height: 0;
  overflow: hidden;
  border-radius: 12px;
  display: block;
  max-width: 260px;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
/* 自分の投稿: 右寄せのため幅をmsg-bodyに合わせる */
.msg-group.mine .chat-media-only {
  max-width: 260px;
}
/* テキスト直後の添付: 吹き出しと繋げるため上角丸を消す */
.msg-bubble + .chat-media-only {
  margin-top: 2px;
  border-radius: 0 0 12px 12px;
}
.msg-group.mine .msg-bubble + .chat-media-only {
  border-radius: 0 0 12px 12px;
}
/* img/video: display:blockでbaselineを消す。width:100%でコンテナに追従 */
.chat-media-img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chat-media-video {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
}
.msg-time { font-size: 11px; color: #bdbdbd; margin-top: 2px; text-align: right; }
.msg-group:not(.mine) .msg-time { text-align: left; }

/* 入力エリア */
.chat-input-area {
  background: white;
  border-top: 1px solid #e0e0e0;
  padding: 10px 12px;
  flex-shrink: 0;
}
.file-previews {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.file-preview {
  position: relative;
  width: 64px;
  height: 64px;
}
.file-preview img, .file-preview video {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}
.file-preview .remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ef5350;
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.input-row textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #e0e0e0;
  border-radius: 20px;
  font-size: 16px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
}
.input-row textarea:focus { border-color: #2e7d32; }
.attach-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 22px;
  padding: 4px;
  color: #9e9e9e;
  flex-shrink: 0;
}
.attach-btn:hover { color: #2e7d32; }
.send-btn {
  background: #2e7d32;
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.send-btn:hover { background: #1b5e20; }

/* ===== DM ===== */
.dm-layout { display: flex; flex: 1; overflow: hidden; height: calc(100dvh - 52px); }
.dm-sidebar { width: 240px; background: white; border-right: 1px solid #e0e0e0; overflow-y: auto; }
.dm-sidebar-header { padding: 14px 16px; font-size: 15px; font-weight: 700; border-bottom: 1px solid #e0e0e0; color: #2e7d32; }
.dm-item { display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid #f5f5f5; text-decoration: none; color: inherit; }
.dm-item:hover, .dm-item.active { background: #e8f5e9; }
.dm-item img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.dm-item .dm-name { font-size: 14px; font-weight: 600; }
.dm-item .dm-preview { font-size: 12px; color: #9e9e9e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-unread { background: #ef5350; color: white; border-radius: 10px; font-size: 11px; padding: 1px 6px; margin-left: auto; flex-shrink: 0; }

/* ===== 管理画面 ===== */
.admin-wrap { display: flex; min-height: 100vh; }
.admin-sidebar { width: 220px; background: #1b5e20; color: white; flex-shrink: 0; display: flex; flex-direction: column; }
.admin-sidebar .logo { padding: 20px 16px; font-size: 15px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,.1); flex-shrink: 0; }
.admin-nav { display: flex; flex-direction: column; flex: 1; }
.admin-nav a { display: flex; align-items: center; gap: 10px; padding: 12px 16px; color: rgba(255,255,255,.8); font-size: 14px; text-decoration: none; }
.admin-nav a:hover, .admin-nav a.active { background: rgba(255,255,255,.15); color: white; }
.admin-main { flex: 1; display: flex; flex-direction: column; background: #f5f5f5; }
.admin-topbar { background: white; padding: 14px 24px; border-bottom: 1px solid #e0e0e0; font-size: 18px; font-weight: 700; color: #2e7d32; }
.admin-content { padding: 24px; }
/* PC表示：サイドバーは画面に固定し、中央のコンテンツだけをスクロールさせる */
@media (min-width: 681px) {
  .admin-wrap { height: 100vh; }
  .admin-sidebar { height: 100vh; overflow-y: auto; }
  .admin-main { overflow-y: auto; min-height: 0; }
}
.admin-card { background: white; border-radius: 12px; padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.admin-card h3 { font-size: 15px; margin-bottom: 16px; color: #2e7d32; padding-bottom: 10px; border-bottom: 1px solid #e8f5e9; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #f5f5f5; font-size: 13px; }
th { background: #f5f5f5; font-weight: 700; color: #424242; }
tr:hover td { background: #fafafa; }

/* ===== レスポンシブ ===== */
.sidebar-toggle { display: none; background: none; border: none; color: white; font-size: 22px; cursor: pointer; }
#adminMenuBtn { display: none; }
@media (max-width: 680px) {
  .chat-sidebar { display: none; position: fixed; left: 0; top: 52px; bottom: 0; z-index: 100; width: 240px; }
  .chat-sidebar.open { display: flex; }
  .sidebar-toggle { display: block; }
  /* 管理画面サイドバー: オフキャンバス */
  .admin-sidebar { position: fixed; left: -240px; top: 0; bottom: 0; z-index: 200; width: 240px; transition: left .25s; }
  .admin-sidebar.open { left: 0; }
  .admin-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 199; }
  .admin-overlay.open { display: block; }
  #adminMenuBtn { display: inline-flex; align-items: center; background: none; border: none; font-size: 22px; cursor: pointer; color: #2e7d32; padding: 0; margin-right: 10px; }
  .admin-topbar { display: flex; align-items: center; }
  .admin-content { padding: 12px; }
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* 管理テーブルの列幅最小値（スマホでも読めるように） */
  table th, table td { white-space: nowrap; }
  .admin-table-nickname { min-width: 100px; }
  .admin-table-email { min-width: 160px; }
  .admin-table-status { min-width: 60px; }
  .admin-table-date { min-width: 90px; }
  .admin-table-action { min-width: 80px; }
}

/* ===== 画像モーダル ===== */
.img-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 1000; align-items: center; justify-content: center; cursor: pointer; }
.img-modal.open { display: flex; }
.img-modal img { max-width: 95vw; max-height: 92vh; border-radius: 8px; }

/* ===== 招待コードバナー ===== */
.invite-banner {
  background: linear-gradient(135deg, #1b5e20, #2e7d32);
  color: white;
  border-radius: 12px;
  padding: 16px 20px;
  margin: 0 16px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 14px;
}
.invite-banner:hover { opacity: .9; }
