/* =========================================================
   コンポーネント
   カード / 投稿 / スレッド一覧 / フォーム / ボタン
   ========================================================= */

/* --- カード --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
}

.card--narrow {
  width: 100%;
  max-width: 460px;
}

@media (max-width: 599px) {
  .card { padding: var(--sp-4); }
}

/* --- ページ見出し --- */
.page-head {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}

.page-head__text { flex: 1 1 260px; min-width: 0; }

.page-head h1 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.4;
  word-break: break-word;
}

.page-head__desc {
  margin: var(--sp-1) 0 0;
  color: var(--text-muted);
  font-size: 0.9375rem;
  word-break: break-word;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
  flex-wrap: wrap;
}

.breadcrumb a { color: var(--text-muted); }

/* --- スレッド一覧 --- */
.thread-list {
  display: grid;
  gap: var(--sp-2);
  list-style: none;
  margin: 0;
  padding: 0;
}

.thread-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.12s, background 0.12s;
}

.thread-item:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.thread-item__link {
  display: block;
  padding: var(--sp-4);
  color: inherit;
  text-decoration: none;
}

.thread-item__head {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.thread-item__title {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.5;
  word-break: break-word;
  flex: 1 1 auto;
  min-width: 0;
}

.thread-item__excerpt {
  margin: var(--sp-2) 0 0;
  color: var(--text-muted);
  font-size: 0.9375rem;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.thread-item__meta {
  margin-top: var(--sp-3);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  font-size: 0.8125rem;
  color: var(--text-faint);
}

/* --- 投稿 --- */
.post-list {
  display: grid;
  gap: var(--sp-3);
  margin: 0 0 var(--sp-5);
  padding: 0;
  list-style: none;
}

.post {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
}

.post--deleted {
  background: var(--surface-2);
  border-style: dashed;
}

.post--pending { opacity: 0.55; }

.post--failed { border-color: var(--error); }

.post__head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  flex-wrap: wrap;
}

.post__author {
  font-weight: 600;
  font-size: 0.9375rem;
  word-break: break-word;
}

.post__author--deleted {
  color: var(--text-faint);
  font-weight: 500;
  font-style: italic;
}

.post__time {
  font-size: 0.8125rem;
  color: var(--text-faint);
}

.post__edited {
  font-size: 0.75rem;
  color: var(--text-faint);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline dotted;
}

.post__menu { margin-left: auto; position: relative; }

.post__body {
  font-size: 0.9375rem;
  line-height: 1.8;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* --- 投稿本文の中身（サーバーでサニタイズ済みの HTML） --- */
.post__body > :first-child { margin-top: 0; }
.post__body > :last-child { margin-bottom: 0; }

.post__body p { margin: 0 0 var(--sp-3); }

.post__body h1, .post__body h2, .post__body h3 {
  margin: var(--sp-5) 0 var(--sp-2);
  line-height: 1.4;
}
.post__body h1 { font-size: 1.25rem; }
.post__body h2 { font-size: 1.125rem; }
.post__body h3 { font-size: 1rem; }

.post__body ul, .post__body ol { margin: 0 0 var(--sp-3); padding-left: 1.5em; }
.post__body li { margin-bottom: var(--sp-1); }

.post__body blockquote {
  margin: 0 0 var(--sp-3);
  padding: var(--sp-1) var(--sp-4);
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}

.post__body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--surface-2);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.post__body pre {
  margin: 0 0 var(--sp-3);
  padding: var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto; /* 横スクロールはコードブロックの中だけに閉じ込める */
}

.post__body pre code {
  background: none;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1.6;
}

.post__body a { color: var(--accent); }

/* 幅の広い表は本文をはみ出させず、表の中だけをスクロールさせる */
.post__body table {
  border-collapse: collapse;
  margin: 0 0 var(--sp-3);
  font-size: 0.875rem;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

.post__body th, .post__body td {
  border: 1px solid var(--border);
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
}

.post__body th { background: var(--surface-2); font-weight: 600; }

.post__body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-4) 0;
}

.mention {
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-weight: 600;
}

/* --- 検索ボックス --- */
.search-box { display: flex; min-width: 0; }

.search-box input {
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: var(--sp-1) var(--sp-4);
  min-height: 36px;
  width: 200px;
  max-width: 100%;
}

.search-box input:focus-visible { border-color: var(--accent); }

@media (max-width: 899px) {
  .search-box input { width: 130px; }
}

@media (max-width: 599px) {
  /* スマホではヘッダが狭いので検索は隠す（ボード画面から辿れる） */
  .search-box { display: none; }
}

/* --- タブ --- */
.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-4);
  overflow-x: auto;
}

.tab {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-muted);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.section-title {
  font-size: 1rem;
  margin: var(--sp-5) 0 var(--sp-3);
}

/* カードの先頭に置く見出し（上の余白を詰める） */
.section-title--first { margin-top: 0; }

/* 続けて並べるカード */
.card--stacked { margin-top: var(--sp-4); }

/* --- 折りたたみ（端末ごとの手順など、普段は畳んでおきたい説明） --- */
.disclosure {
  margin-top: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 0 var(--sp-3);
}

.disclosure > summary {
  cursor: pointer;
  padding: var(--sp-3) 0;
  font-size: 0.9375rem;
  font-weight: 600;
  /* 指で押せる大きさを確保する */
  min-height: 44px;
  display: flex;
  align-items: center;
}

.disclosure[open] > summary {
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-3);
}

.disclosure > *:last-child { padding-bottom: var(--sp-3); }

/* --- 表 --- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.data-table th,
.data-table td {
  padding: var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  background: var(--surface-2);
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text-muted);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table td.wrap { white-space: normal; word-break: break-word; }
.data-table .row-actions { display: flex; gap: var(--sp-2); }

.field-row {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.field-row .field { flex: 1 1 160px; }

/* --- 添付ファイル --- */
.attach-tray {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: 220px;
  padding: var(--sp-1) var(--sp-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
}

.attach-chip--loading { color: var(--text-muted); }

.attach-chip__thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
  flex: none;
}

.attach-chip__type {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px var(--sp-1);
  border-radius: 3px;
  flex: none;
}

.attach-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-chip__remove {
  appearance: none;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: var(--sp-1);
  flex: none;
}

.attach-chip__remove:hover { color: var(--error); }

/* ドラッグ中の目印 */
.is-dragover {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

/* --- 投稿内の添付 --- */
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.attachment {
  display: inline-flex;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.attachment--image {
  border: 1px solid var(--border);
  max-width: min(320px, 100%);
}

.attachment--image img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 260px;
  object-fit: contain;
  background: var(--surface-2);
}

.attachment--file {
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  max-width: 100%;
}

.attachment--file:hover { border-color: var(--accent); }

.attachment__type {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: var(--sp-1) var(--sp-2);
  border-radius: 3px;
  flex: none;
}

.attachment__text {
  display: grid;
  min-width: 0;
}

.attachment__name {
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment__size {
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* --- 通知 --- */
.notif-btn { position: relative; text-decoration: none; }

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--error);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.notif-list {
  display: grid;
  gap: var(--sp-2);
  list-style: none;
  margin: 0;
  padding: 0;
}

.notif-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.notif-item--unread { border-left: 3px solid var(--accent); }

.notif-item__link {
  display: block;
  padding: var(--sp-4);
  color: inherit;
  text-decoration: none;
}

.notif-item__link:hover { background: var(--surface-2); }

.notif-item__head {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: var(--sp-1);
}

.notif-item__kind {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 2px var(--sp-2);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.notif-item__title { font-weight: 600; }

.notif-item__meta {
  font-size: 0.8125rem;
  color: var(--text-faint);
}

/* --- サイドバーの未読バッジ --- */
.board-nav__unread {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  flex: none;
}

.thread-item__unread {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 0 var(--sp-2);
  font-size: 0.6875rem;
  font-weight: 700;
}

/* --- バッジ --- */
.badge {
  font-size: 0.75rem;
  padding: 2px var(--sp-2);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge--pin { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge--closed { background: var(--surface-3); color: var(--text-muted); border-color: transparent; }
.badge--lock { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.pill {
  display: inline-block;
  padding: 2px var(--sp-3);
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
}

/* --- 接続状態（リアルタイム同期）--- */
.conn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.conn__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}

.conn[data-state="online"] .conn__dot { background: var(--ok); }
.conn[data-state="connecting"] .conn__dot {
  background: var(--warn);
  animation: pulse 1.2s ease-in-out infinite;
}
.conn[data-state="offline"] .conn__dot { background: var(--error); }

/* 正常時はラベルを出さない（点だけで十分） */
.conn[data-state="online"] .conn__label { display: none; }

/* スマホでは点だけにして横幅を空ける */
@media (max-width: 599px) {
  .conn__label { display: none; }
}

/* 新しく届いた投稿を一瞬だけ光らせる */
.post--fresh {
  animation: fresh 1.6s ease-out;
}

@keyframes fresh {
  0% { background: var(--accent-soft); }
  100% { background: var(--surface); }
}

.pill--wait  { background: var(--surface-2); color: var(--text-muted); }
.pill--ok    { background: var(--ok-bg);     color: var(--ok); }
.pill--warn  { background: var(--warn-bg);   color: var(--warn); }
.pill--error { background: var(--error-bg);  color: var(--error); }

/* --- ボタン --- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 44px; /* 指で押せる大きさを確保 */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--block { width: 100%; }
.btn--sm { min-height: 36px; padding: var(--sp-1) var(--sp-3); font-size: 0.875rem; }

.btn--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn--icon {
  min-height: 40px;
  min-width: 40px;
  padding: 0;
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  font-size: 1.125rem;
}
.btn--icon:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn--danger { background: var(--error); color: #fff; }

/* --- フォーム --- */
.form { display: grid; gap: var(--sp-4); margin-top: var(--sp-5); }

.field { display: grid; gap: var(--sp-1); }

.field__label { font-weight: 600; font-size: 0.9375rem; }

.field__hint {
  color: var(--text-muted);
  font-size: 0.8125rem;
  line-height: 1.6;
}

.field input,
.field textarea,
.field select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-3);
  min-height: 44px;
  width: 100%;
  /* iOS で入力時に画面が拡大されるのを防ぐ（16px 未満だと拡大される） */
  font-size: 16px;
}

.field input:focus-visible,
.field textarea:focus-visible { border-color: var(--accent); }

textarea {
  resize: vertical;
  line-height: 1.7;
  min-height: 96px;
  font-family: var(--font);
}

.copy-field {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  width: 100%;
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

/* --- 投稿フォーム --- */
.composer__row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
}

.composer textarea {
  flex: 1;
  /* textarea は既定の桁数ぶんの最小幅を持つ。min-width を 0 にしないと
     flex の自動最小サイズがそれに張り付き、送信ボタンを画面外へ押し出す。 */
  min-width: 0;
  min-height: 44px;
  max-height: 40vh;
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  resize: none;
  overflow-y: auto;
}

.composer__hint {
  margin: var(--sp-2) 0 0;
  font-size: 0.75rem;
  color: var(--text-faint);
}

@media (max-width: 599px) {
  .composer__hint { display: none; }
}

/* --- 通知・空状態 --- */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  margin: 0;
}

.alert--error { background: var(--error-bg); color: var(--error); }
.alert--ok    { background: var(--ok-bg);    color: var(--ok); }
.alert--warn  { background: var(--warn-bg);  color: var(--warn); }

.empty {
  text-align: center;
  padding: var(--sp-7) var(--sp-4);
  color: var(--text-muted);
}

.empty__title { font-weight: 600; color: var(--text); margin: 0 0 var(--sp-2); }

/* --- メニュー --- */
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 15;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  padding: var(--sp-1);
  display: grid;
  gap: 2px;
}

.menu__item {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  color: var(--text);
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  border-radius: 4px;
  cursor: pointer;
  min-height: 40px;
}

.menu__item:hover { background: var(--surface-2); }
.menu__item--danger { color: var(--error); }

/* --- その他 --- */
.actions {
  margin-top: var(--sp-5);
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.actions--center { justify-content: center; }

/* 投稿の編集フォーム（カード内に埋め込むので上の余白を詰める） */
.form--inline { margin-top: 0; }

.invite-result { margin-top: var(--sp-5); display: grid; gap: var(--sp-3); }

.status-list { margin: var(--sp-5) 0; padding: 0; display: grid; gap: var(--sp-1); }

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}

.status-row:last-child { border-bottom: none; }
.status-row dt { font-weight: 600; }
.status-row dd { margin: 0; }

@media (max-width: 599px) {
  .status-row { flex-direction: column; align-items: flex-start; gap: var(--sp-1); }
}

.load-more { display: flex; justify-content: center; margin: var(--sp-4) 0; }

.skeleton {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  height: 1em;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
