/* ai-room スタイル
   方針: 明るい基調＋アクセント1色（ティールグリーン）。色の役割は固定し、増やさない。
   サイズは5段（見出し20／小見出し16／本文15／補足13／最小12、バッジ内数字11）。
   余白は 4/8/12/16/24px の段だけ。角丸は カード12／吹き出し16／ボタン10／入力欄20。
   手本: 一覧と通知は LINE と Instagram、発言まわりは Slack、軽さとアバターは Telegram、
   全体の温度は Chatwork。 */

:root {
  --accent: #0e7c6b;
  --accent-dark: #0a6657;
  --accent-soft: #e7f3f0;
  --bg: #f4f6f7;
  --panel: #ffffff;
  --border: #e2e6ea;
  --border-strong: #c6ccd3;
  --text: #1d2126;
  --muted: #68707a;
  --ai: #5f2ea6;
  --ai-soft: #f0eafd;
  --danger: #b3261e;
  --danger-soft: #fdeeee;
  --badge: #e5484d;
  --warn-soft: #fff7e0;
  --warn-border: #ecd28a;
  --ok: #0a6b45;
  --ok-soft: #e9f7ee;
  --radius: 12px;
  --header-h: 52px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent-dark); }
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ===== ヘッダー ===== */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: none;
  position: relative;
  z-index: 30;
}
.topbar-inner {
  height: var(--header-h);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex: none;
}
.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  white-space: nowrap;
}
.topnav a {
  color: var(--text);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
}
.topnav a:hover { background: var(--bg); }
.topnav .who { color: var(--muted); padding: 0 4px; }
.inline-form { display: inline; }
.linklike {
  background: none;
  border: none;
  color: var(--accent-dark);
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
  padding: 8px 6px;
  text-decoration: none;
  min-height: 0;
}
.linklike:hover { text-decoration: underline; }
.linklike.link-danger { color: var(--danger); }

/* ベル（通知）: 共通ヘッダーと部屋ヘッダーで共用。バッジは印の赤だけ */
.bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 6px;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
}
.bell:hover { background: var(--bg); }
.bell-badge {
  position: absolute;
  top: 1px;
  right: 0;
  background: var(--badge);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ===== 通常ページ ===== */
.main-page {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}
.main-page h1 { font-size: 20px; margin: 4px 0 16px; overflow-wrap: anywhere; }
.main-page h2 { font-size: 16px; margin: 24px 0 10px; }
.main-page h3 { font-size: 15px; margin: 20px 0 8px; }

/* ===== 共通の部品 ===== */
.error {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 10px 14px;
  border-radius: 10px;
  margin: 0 0 14px;
}
.error-band {
  background: var(--warn-soft);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 10px;
  margin: 0 0 12px;
  font-size: 14px;
}
.notice {
  color: var(--ok);
  background: var(--ok-soft);
  padding: 10px 14px;
  border-radius: 10px;
  margin: 0 0 14px;
}
.empty { color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; }

label { display: block; margin: 10px 0; font-size: 14px; }
input[type="text"], input[type="password"], select, textarea {
  font-size: 16px; /* iOSの自動ズーム防止 */
  font-family: inherit;
  color: var(--text);
  padding: 10px 12px;
  margin-top: 4px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  max-width: 100%;
}
button {
  font-family: inherit;
  font-size: 15px;
  min-height: 40px;
  padding: 8px 18px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
button:hover { background: var(--bg); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
  min-height: 48px;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-block { width: 100%; }
.btn-sub {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 18px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
}
.btn-sub:hover { background: var(--bg); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 12px;
}
.card h2 {
  font-size: 16px;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.card h3 { font-size: 15px; margin: 16px 0 8px; }
.card-alert { background: var(--warn-soft); border-color: var(--warn-border); }

/* 畳んだ発行フォーム（部屋の情報ページ） */
.fold {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 8px 0 12px;
}
.fold summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 0;
}

.stack-form input[type="text"],
.stack-form input[type="password"],
.stack-form select,
.stack-form textarea { width: 100%; }
.stack-form button { margin-top: 8px; }
/* カード内の入力欄は高さ48pxにそろえる */
.card .stack-form input[type="text"],
.card .stack-form input[type="password"] { height: 48px; }

/* ログインのブランド表示 */
.brand-block { text-align: center; margin: 16px 0 18px; }
.brand-mark-lg {
  width: 56px; height: 56px;
  border-radius: 16px;
  font-size: 27px;
}
.brand-name { font-size: 20px; font-weight: 700; margin-top: 10px; }
.brand-tagline { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

/* ログイン・初期設定：迷わないよう中央のカード1枚に */
.auth-form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  max-width: 420px;
  margin: 8px auto 0;
}
.auth-form input[type="text"],
.auth-form input[type="password"] { height: 48px; }
.auth-form .btn-primary { margin-top: 14px; min-height: 48px; font-size: 16px; }
.auth-lead { color: var(--muted); font-size: 14px; margin: 0 0 6px; }

.badge-ai {
  background: var(--ai-soft);
  color: var(--ai);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  vertical-align: middle;
  white-space: nowrap;
}

.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: hsl(var(--h, 210) 55% 88%);
  color: hsl(var(--h, 210) 45% 30%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex: none;
  user-select: none;
}
.avatar-sm { width: 30px; height: 30px; font-size: 13px; }
.avatar-room { width: 48px; height: 48px; font-size: 19px; }
.avatar-lg { width: 56px; height: 56px; font-size: 23px; }
.avatar-notice { width: 32px; height: 32px; font-size: 14px; }
.avatar-spacer { visibility: hidden; }

/* 件数バッジ（申請=赤、未読=緑）。一覧の行と情報ページで共用 */
.rbadge {
  flex: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}
.rbadge-req { background: var(--badge); }
.rbadge-unread { background: var(--accent); }

/* ===== 部屋一覧（LINEのトーク一覧の平坦さ） ===== */
.list-head { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.list-head .btn-primary { min-height: 44px; }
.room-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  border-top: 1px solid var(--border);
}
.room-list li { border-bottom: 1px solid var(--border); }
.room-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 10px 2px;
  text-decoration: none;
  color: var(--text);
}
.room-row:hover { background: #fafcfc; }
.room-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.room-row-top { display: flex; align-items: baseline; gap: 8px; }
.room-row-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-row-time { color: var(--muted); font-size: 13px; flex: none; }
.room-row-sub { display: flex; align-items: center; gap: 8px; }
.room-row-preview {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-row-preview.has-unread { color: var(--text); font-weight: 700; }

/* ===== 通知一覧（Instagramのアクティビティの形） ===== */
.notice-list { list-style: none; margin: 0; padding: 0; }
.notice-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
}
.notice-row.unseen { background: #eef6f4; }
.notice-body { flex: 1; min-width: 0; font-size: 15px; line-height: 1.55; text-wrap: pretty; }
.notice-body strong {
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}
.notice-side {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.notice-time { color: var(--muted); font-size: 13px; white-space: nowrap; }
.notice-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--badge);
}

/* ===== 管理画面 ===== */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.list-table { border-collapse: collapse; width: 100%; background: var(--panel); }
.list-table th, .list-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  overflow-wrap: anywhere;
  font-size: 14px;
  vertical-align: middle;
}
.list-table th { background: var(--bg); }
code.token {
  display: inline-block;
  background: #22262b;
  color: #d6ffd6;
  padding: 8px 12px;
  border-radius: 8px;
  overflow-wrap: anywhere;
  word-break: break-all;
  font-size: 13px;
}
/* AI用招待の案内ページで、手順の窓口のアドレスをそのまま写せる形で出す欄 */
.join-info-url { width: 100%; font-size: 13px; }

/* ===== 参加ページ（招待カード） ===== */
.join-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.join-head-text { min-width: 0; }
.join-room { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.join-from { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.join-points { margin: 8px 0; padding-left: 20px; font-size: 15px; line-height: 1.6; }
.join-points li { margin: 2px 0; }

/* ===== 部屋画面（チャット） ===== */
/* 高さを画面に固定し、伸びるのは発言エリアの内側だけにする（ページ全体は伸ばさない） */
.main-chat {
  flex: none;
  display: flex;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
}
/* 共通ヘッダーを畳んだ部屋画面では、画面いっぱいを使う */
.main-chat-full { height: 100vh; height: 100dvh; }
.chat-shell { flex: 1; display: flex; min-height: 0; width: 100%; position: relative; }

/* サイドバー */
.sidebar {
  width: 288px;
  flex: none;
  background: #fafbfc;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 12px 24px;
}
.side-head { display: none; }
.side-section { margin-bottom: 22px; }
.side-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .06em;
  margin: 0 6px 8px;
}
.side-rooms { list-style: none; margin: 0; padding: 0; }
.side-room {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}
.side-room:hover { background: #eef1f3; }
.side-room.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; }
.room-hash { color: var(--muted); font-weight: 700; flex: none; }
.side-room.active .room-hash { color: var(--accent-dark); }
.side-room-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.side-room-count { color: var(--muted); font-size: 12px; flex: none; }
.side-foot-link {
  display: block;
  padding: 10px;
  font-size: 14px;
  text-decoration: none;
}
.side-foot-link:hover { text-decoration: underline; }

.member-list { list-style: none; margin: 0; padding: 0; }
.member {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 4px 8px;
}
.member-name { overflow-wrap: anywhere; }

.file-list { list-style: none; margin: 0 0 8px; padding: 0; font-size: 14px; }
.file-list li { padding: 6px 8px; overflow-wrap: anywhere; }

.sidebar label { font-size: 13px; margin: 8px 0; }
.sidebar input[type="file"] { width: 100%; font-size: 13px; }
.sidebar select, .sidebar input[type="text"] { width: 100%; }
.sidebar form button { min-height: 40px; padding: 6px 14px; font-size: 14px; }

/* 発言エリア */
.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  position: relative;
}
.chat-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.chat-head .room-hash { font-size: 18px; }
.chat-back {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 40px;
  font-size: 24px;
  line-height: 1;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
}
.chat-back:hover { background: var(--bg); }
.chat-title {
  font-size: 16px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.chat-title-link {
  color: var(--text);
  text-decoration: none;
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
}
.chat-title-link:hover .chat-title { color: var(--accent-dark); text-decoration: underline; }
.chat-count { color: var(--muted); font-size: 12px; white-space: nowrap; flex: none; }
.chat-paused {
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex: none;
}
.chat-bell { margin-left: auto; flex: none; display: inline-flex; }
.btn-invite {
  flex: none;
  min-height: 40px;
  padding: 6px 16px;
  font-weight: 700;
  color: var(--accent-dark);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.btn-invite:hover { background: #d8eae6; }
.nav-toggle {
  display: none;
  min-height: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 19px;
  align-items: center;
  justify-content: center;
}
.error-bar { margin: 10px 16px 0; }

/* 発言エリアの包み：「新しい発言へ」ボタンの基準位置にする。
   入力欄まわり（プレビュー帯など）の高さが変わっても、ボタンはこの中だけで位置が決まる */
.messages-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
/* ボタンが出ている間は、最後の発言がボタンの下に隠れないよう末尾に余白を持つ */
.messages-wrap.has-newmsg .messages { padding-bottom: 60px; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 8px;
  background: var(--bg);
}

/* 吹き出し: 他人は左・白、自分の発言は右・淡い緑 */
.msg {
  display: flex;
  gap: 8px;
  padding: 6px 8px 0;
  max-width: 860px;
}
.msg.grouped { padding-top: 2px; }
.msg-main {
  flex: 1;
  min-width: 0;
  max-width: 86%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.msg.own { justify-content: flex-end; margin-left: auto; }
.msg.own .msg-main { align-items: flex-end; }
.msg-head { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; margin-bottom: 2px; }
.msg-author { font-weight: 700; font-size: 15px; }
.msg.ai .msg-author { color: var(--ai); }
.msg-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 8px 12px;
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  max-width: 100%;
}
.msg.ai .bubble { border-left: 2px solid var(--ai); }
/* 吹き出し内の画像：本文の上に置く。大きさは上限つきで、比率は保つ（切り抜かない） */
.msg-figure { margin-bottom: 6px; }
.msg-figure:last-child { margin-bottom: 0; }
.msg-image {
  display: block;
  max-width: 240px;
  max-height: 320px;
  width: auto;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
}
.msg-image-failed { font-size: 13px; color: var(--muted); }
.bubble-row { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.bubble-row .msg-time { padding-bottom: 2px; }
.msg.own .bubble {
  background: var(--accent-soft);
  border-color: #cfe4df;
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 16px;
}
.empty-chat { text-align: center; padding: 40px 16px; }

/* 日付の区切り（中央に小さなピル） */
.date-divider { text-align: center; margin: 12px 0 4px; }
.date-divider span {
  display: inline-block;
  background: #dde3e7;
  color: var(--muted);
  font-size: 12px;
  padding: 2px 12px;
  border-radius: 999px;
}
/* 未読の境目 */
.new-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 8px 2px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}
.new-divider::before, .new-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--accent);
  opacity: .5;
}

/* 既読：自分の発言のうち、最後に読まれた位置の1件だけに出る */
.readby { margin-top: 3px; font-size: 12px; color: var(--muted); }

/* リアクション：付いた物だけチップで出す */
.reactions { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 4px; }
.msg.own .reactions { justify-content: flex-end; }
.rchip {
  min-height: 32px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: #fff;
  font-size: 13px;
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.rchip .rcount { font-size: 12px; color: var(--muted); }
.rchip.mine { background: var(--accent-soft); border-color: var(--accent); }
.rchip.mine .rcount { color: var(--accent-dark); font-weight: 700; }

/* リアクション追加のポップオーバー（発言タップで出す） */
.react-pop {
  position: fixed;
  z-index: 55;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
  padding: 6px 8px;
  max-width: calc(100vw - 16px);
}
.react-pop[hidden] { display: none; }
.react-pop-row { display: flex; gap: 2px; }
.react-pop .rpick {
  min-height: 40px;
  min-width: 40px;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  font-size: 19px;
  line-height: 1;
}
.react-pop .rpick:hover { background: var(--bg); }
.react-pop-readers {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 4px 2px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  overflow-wrap: anywhere;
}

/* 画像の拡大表示：画面全体の重ね表示（部屋画面の部品の中で最前面） */
.lightbox {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 70;
  background: rgba(20, 24, 28, .88);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }
.lightbox-img {
  max-width: 94vw;
  max-height: 88dvh;
  border-radius: 8px;
  background: var(--bg);
}
.lightbox-failed { color: #fff; font-size: 14px; margin: 0; }
.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 22px;
  line-height: 1;
}

/* 「新しい発言へ」ボタン：読み返し中に新着が来た時だけ出す。
   置き場所は発言エリア（.messages-wrap）の中の右下で、入力欄まわりとは領域を取り合わない */
.btn-newmsg {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 6;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
.btn-newmsg[hidden] { display: none; }
.btn-newmsg:hover { background: var(--accent-dark); }

/* 入力中バー：投稿欄の上に小さく出す。点は順番に明滅する */
.typing-bar {
  flex: none;
  padding: 3px 18px;
  font-size: 13px;
  color: var(--muted);
  background: var(--bg);
}
.tdots i {
  font-style: normal;
  animation: tdots-blink 1.2s infinite;
}
.tdots i:nth-child(2) { animation-delay: .2s; }
.tdots i:nth-child(3) { animation-delay: .4s; }
@keyframes tdots-blink {
  0%, 60%, 100% { opacity: .2; }
  30% { opacity: 1; }
}

/* 投稿欄：上にプレビュー帯、下に入力の行、の縦積み。
   常に画面の下に固定し、送る操作はボタンだけ（Enter送信なし） */
.composer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.composer-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  width: 100%;
}
.composer-inputs {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.composer textarea {
  flex: 1;
  width: 100%;
  margin: 0;
  resize: none;
  max-height: 130px;
  line-height: 1.5;
  border-radius: 20px;
  padding: 10px 14px;
}
.btn-send {
  width: 48px;
  height: 48px;
  min-height: 48px;
  border-radius: 50%;
  padding: 0;
  flex: none;
  /* 中の送信アイコン（SVG）を、ボタンの真ん中に置く */
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-attach {
  width: 44px;
  height: 44px;
  min-height: 44px;
  border-radius: 50%;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  flex: none;
}
/* 画像のプレビュー帯：選んだ画像を、入力欄の真上に小さく出す（送信は送信ボタン1つ） */
.preview-strip {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  width: 100%;
}
.preview-strip[hidden] { display: none; }
.preview-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  flex: none;
}
.preview-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 2px;
}
.preview-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-note { font-size: 12px; color: var(--muted); }
.preview-guide { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 4px 0 0; }
.preview-clear {
  flex: none;
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
}

/* JSが効かない環境向け：生のファイル入力をそのまま見せる行（JSが効く環境では隠す） */
.attach-input-row { padding-bottom: 6px; }
.attach-input-row[hidden] { display: none; }
.attach-input-row label { display: block; margin: 0; font-size: 13px; color: var(--muted); }
.attach-input-row input[type="file"] { font-size: 13px; color: var(--muted); max-width: 100%; margin-top: 2px; }
/* ファイル選択ボタンだけ、標準ボタンの見た目に寄せる（入力そのものは標準のまま） */
.attach-input-row input[type="file"]::file-selector-button {
  font: inherit;
  font-size: 14px;
  min-height: 40px;
  padding: 8px 14px;
  margin-right: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.attach-input-row input[type="file"]::file-selector-button:hover { background: var(--bg); }

.scrim { display: none; }

/* ===== 招待（発行直後の表示・一覧） ===== */
.side-subtitle {
  font-size: 13px;
  font-weight: 700;
  margin: 16px 6px 8px;
}
.invite-flash {
  background: var(--ok-soft);
  border: 1px solid #bfe3cd;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
}
.invite-flash label { margin: 6px 0; }
.invite-note { font-size: 12px; color: var(--muted); margin: 6px 0; overflow-wrap: anywhere; }
.invite-flash .invite-note { color: var(--text); }
.invite-link-row { display: flex; gap: 6px; margin-top: 4px; }
.invite-link-row input[type="text"] {
  flex: 1;
  min-width: 0;
  margin-top: 0;
  font-size: 13px;
}
.invite-link-row button { flex: none; min-height: 40px; padding: 6px 12px; font-size: 14px; }
.invite-qr {
  display: block;
  width: 176px;
  height: 176px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  margin: 8px 0;
}
.invite-copy-status { font-size: 13px; color: var(--ok); margin: 6px 0 0; min-height: 1.3em; }
.invite-copy-status.is-error { color: var(--danger); }
.invite-list, .req-list { list-style: none; margin: 12px 0 0; padding: 0; }
.invite-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--panel);
}
.invite-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.invite-mode { font-weight: 700; font-size: 14px; }
.invite-state { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.invite-state.state-ok { background: var(--ok-soft); color: var(--ok); }
.invite-state.state-revoked, .invite-state.state-expired, .invite-state.state-used { background: var(--bg); color: var(--muted); }
/* 招待の種別（人間用／AI用）をはっきり分けるための印 */
.invite-kind { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #e8ecf3; color: #3c4a63; }
.invite-kind.kind-ai { background: #efe9fb; color: #6d28d9; }
/* 発行直後表示の中の「そのまま送れる紹介文」 */
.invite-intro { margin-top: 12px; }
.invite-intro textarea {
  width: 100%;
  font-size: 13px;
  line-height: 1.6;
  margin-top: 4px;
}
.invite-intro .js-intro-copy { min-height: 40px; padding: 6px 12px; font-size: 14px; margin-top: 6px; }
.invite-actions { margin-top: 2px; }
.invite-actions .linklike { padding: 4px 6px; font-size: 13px; }

/* 申請の行：顔＋名前＋補足、ボタンは下段に44pxでそろえる */
.req-item {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--panel);
}
.req-main { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 2px; }
.req-name { font-weight: 700; font-size: 15px; overflow-wrap: anywhere; }
.req-actions { display: flex; gap: 8px; width: 100%; margin-top: 2px; }
.req-actions button { min-height: 44px; padding: 6px 14px; font-size: 14px; flex: 1; }

/* ===== 部屋の情報ページ・申請ページ ===== */
.manage-roomline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  font-size: 17px;
}
.manage-back { margin-left: auto; font-size: 14px; white-space: nowrap; }
.manage-linkrow {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 0 0 12px;
}
.btn-link-primary {
  display: inline-flex;
  align-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  padding: 10px 18px;
  border-radius: 10px;
  min-height: 48px;
}
.btn-link-primary:hover { background: var(--accent-dark); }

/* 申請バー：承認待ちがある時だけ、発言エリアの上に出る */
.req-banner {
  flex: none;
  display: block;
  margin: 10px 16px 0;
  padding: 10px 14px;
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  border-radius: 10px;
  color: #6b5510;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
}
.req-banner:hover { background: #ffefbd; }

/* 承認待ち件数のバッジ（サイドバーの部屋名の横） */
.badge-count {
  background: var(--badge);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

/* ===== 招待シート（部屋画面のオーバーレイ） ===== */
.sheet-backdrop {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(20, 24, 28, .5);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  background: var(--panel);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -6px 32px rgba(0, 0, 0, .25);
}
.sheet-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 4px;
}
.sheet-head h2 { font-size: 18px; margin: 0; }
.sheet-close { min-height: 44px; min-width: 44px; padding: 0; font-size: 18px; border: none; }
.sheet-tabs {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 8px 16px 0;
}
.sheet-tab {
  flex: 1;
  min-height: 44px;
  font-weight: 700;
  border-radius: 10px 10px 0 0;
  border-bottom: none;
  background: var(--bg);
  color: var(--muted);
}
.sheet-tab.active {
  background: var(--panel);
  color: var(--accent-dark);
  border-color: var(--accent);
  box-shadow: inset 0 -3px 0 var(--accent);
}
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.sheet-ai-note {
  font-size: 13px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 0 0 10px;
}
/* 読み込み中の仮表示（スケルトン） */
.sheet-loading-text { color: var(--muted); text-align: center; margin: 10px 0 4px; }
.skel {
  background: #e8ecee;
  border-radius: 10px;
  animation: skel-pulse 1.2s ease-in-out infinite;
}
.skel-qr { width: 200px; height: 200px; margin: 4px auto 10px; }
.skel-line { height: 14px; margin: 10px 0; }
.skel-line.short { width: 55%; }
@keyframes skel-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}
.sheet-error { margin: 8px 0; }
.sheet-retry { width: 100%; min-height: 44px; margin: 4px 0 8px; }
.sheet-qr {
  display: block;
  width: 200px;
  max-width: 100%;
  height: auto;
  margin: 4px auto 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}
.sheet-body label { margin: 8px 0; }
.sheet .invite-link-row input[type="text"] { font-size: 13px; }
.sheet .invite-link-row button { min-height: 44px; padding: 6px 18px; }
.sheet .invite-intro textarea {
  width: 100%;
  font-size: 16px;
  line-height: 1.6;
  margin-top: 4px;
  height: 110px;
  resize: none;
}
.sheet-body .invite-intro button { width: 100%; min-height: 44px; padding: 6px 12px; font-size: 14px; margin-top: 6px; }

/* ===== スマホ（900px未満）：1カラム＋サイドバーは引き出し式 ===== */
@media (max-width: 899px) {
  .topbar-inner { padding: 0 8px; }
  .topnav a { padding: 8px 5px; }
  .topnav .linklike { padding: 8px 4px; }
  .topnav .bell { padding: 6px; }
  .topnav .who { display: none; }
  .main-page { padding: 16px 16px 40px; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(320px, 84vw);
    z-index: 40;
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
    box-shadow: none;
    padding-top: 10px;
  }
  .chat-shell.nav-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform .22s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .18);
  }
  .side-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    padding: 0 6px 8px;
  }
  .side-close { min-height: 44px; min-width: 44px; padding: 0; font-size: 18px; }
  .scrim {
    position: fixed;
    inset: 0;
    background: rgba(20, 24, 28, .45);
    z-index: 35;
  }
  .chat-shell.nav-open .scrim { display: block; }

  .nav-toggle { display: inline-flex; }
  .chat-head { padding: 8px 10px; gap: 6px; }
  .chat-back { min-width: 30px; }
  .req-banner { margin: 8px 8px 0; }
  .messages { padding: 10px 2px 8px; }
  .msg { padding: 6px 6px 0; }
  .msg-main { max-width: 88%; }
}
